| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- namespace addons\UpgradeGift\common\logic\order;
- use common\enums\PreviewTypeEnum;
- use addons\UpgradeGift\common\logic\order\purchase\BuyNowPurchase;
- use addons\UpgradeGift\common\logic\order\purchase\CartPurchase;
- use addons\UpgradeGift\common\logic\order\purchase\BasePurchase;
- use common\traits\ErrorTrait;
- use Exception;
- /**
- * 订单数据初始化逻辑层
- * @Author bing
- * @DateTime 2021-09-22 18:16:58
- * @copyright: Copyright (c) 2020 广东七件事集团
- */
- abstract class BaseOrderInitData
- {
- use ErrorTrait;
- public $isNewRecord = false; // 是否是新增记录
- abstract public function getHandlers();
- /**
- * 执行订单初始化
- * @Author bing
- * @DateTime 2021-09-22 20:51:26
- * @copyright: Copyright (c) 2020 广东七件事集团
- * @param $form
- * @param [type] $type
- * @return object|bool
- */
- public function execute($form, $type)
- {
- try{
- $handlers = $this->getHandlers();
- if (!isset($handlers[$type])) throw new Exception('下单类型错误');
- /** @var BasePurchase $class */
- $class = new $handlers[$type]();
- $class->isNewRecord = $this->isNewRecord;
- $form = $class->execute($form);
- if($form === false) throw new Exception($class->getError());
- if (!$form->order_goods) throw new Exception('该下单的产品不存在或者已经删除');
- $form = $class->afterExecute($form, $class::getType());
- if($form === false) throw new Exception($class->getError());
- return $form;
- } catch (Exception $e) {
- $this->setError($e->getMessage());
- return false;
- }
- }
- }
|