| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?php
- namespace addons\ValetOrder\common\logic\order;
- use addons\ValetOrder\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;
- }
-
- }
-
- }
|