| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- namespace common\logic\order;
- use common\enums\AddonsEnum;
- use common\models\mall\MallAddons;
- use common\traits\ErrorTrait;
- use Exception;
- /**
- * 订单限制相关处理逻辑层
- * @Author bing
- * @DateTime 2021-09-22 18:16:58
- * @copyright: Copyright (c) 2020 广东七件事集团
- */
- abstract class BaseOrderLimit
- {
- use ErrorTrait;
- abstract public function getHandlers();
- /**
- * 运行
- * @param $form
- * @param bool $isNewRecord 创建记录
- * @return object|bool
- */
- public function run($form, $isNewRecord = false)
- {
- try {
- $handlers = $this->getHandlers();
- array_push($handlers, ...$this->extra($form->mall_id));
- foreach ($handlers as $handler) {
- $item = $handler::compute($form);
- if ($item === false) throw new Exception($handler::getStaticError());
- }
- return $form;
- } catch (Exception $e) {
- $this->setError($e->getMessage(),$e->getCode());
- return false;
- }
- }
- /**
- * 门店是否需要加进去
- * @param $mall_id
- * @return array
- */
- protected function extra($mall_id)
- {
- $extra = [];
- if (MallAddons::isInstall($mall_id, AddonsEnum::ADDONS_NAME_QI_DING_DONG)) {
- $extra[] = \addons\QiDingDong\common\logic\OrderLimitLogic::class;
- }
- if (MallAddons::isInstall($mall_id, AddonsEnum::ADDONS_NAME_QI_SHANG_TONG)) {
- $extra[] = \addons\QiShangTong\common\logic\OrderLimitLogic::class;
- }
- return $extra;
- }
- }
|