BaseOrderLimit.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace common\logic\order;
  3. use common\enums\AddonsEnum;
  4. use common\models\mall\MallAddons;
  5. use common\traits\ErrorTrait;
  6. use Exception;
  7. /**
  8. * 订单限制相关处理逻辑层
  9. * @Author bing
  10. * @DateTime 2021-09-22 18:16:58
  11. * @copyright: Copyright (c) 2020 广东七件事集团
  12. */
  13. abstract class BaseOrderLimit
  14. {
  15. use ErrorTrait;
  16. abstract public function getHandlers();
  17. /**
  18. * 运行
  19. * @param $form
  20. * @param bool $isNewRecord 创建记录
  21. * @return object|bool
  22. */
  23. public function run($form, $isNewRecord = false)
  24. {
  25. try {
  26. $handlers = $this->getHandlers();
  27. array_push($handlers, ...$this->extra($form->mall_id));
  28. foreach ($handlers as $handler) {
  29. $item = $handler::compute($form);
  30. if ($item === false) throw new Exception($handler::getStaticError());
  31. }
  32. return $form;
  33. } catch (Exception $e) {
  34. $this->setError($e->getMessage(),$e->getCode());
  35. return false;
  36. }
  37. }
  38. /**
  39. * 门店是否需要加进去
  40. * @param $mall_id
  41. * @return array
  42. */
  43. protected function extra($mall_id)
  44. {
  45. $extra = [];
  46. if (MallAddons::isInstall($mall_id, AddonsEnum::ADDONS_NAME_QI_DING_DONG)) {
  47. $extra[] = \addons\QiDingDong\common\logic\OrderLimitLogic::class;
  48. }
  49. if (MallAddons::isInstall($mall_id, AddonsEnum::ADDONS_NAME_QI_SHANG_TONG)) {
  50. $extra[] = \addons\QiShangTong\common\logic\OrderLimitLogic::class;
  51. }
  52. return $extra;
  53. }
  54. }