| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <?php
- namespace addons\Sudoku\common\logic\order;
- use common\enums\PreviewTypeEnum;
- use addons\Sudoku\common\logic\order\purchase\BuyNowPurchase;
- use common\traits\ErrorTrait;
- use Exception;
- /**
- * 订单数据初始化逻辑层
- * @Author ltm
- * @DateTime 2021-12-30 14:16:58
- * @copyright: Copyright (c) 2020 广东七件事集团
- */
- class OrderInitDataLogic{
- use ErrorTrait;
- public $isNewRecord = false; // 是否是新增记录
- /**
- * 下单方式
- *
- * @var array
- */
- protected $handlers = [
- PreviewTypeEnum::BUY_NOW => BuyNowPurchase::class, // 立即下单
- ];
- /**
- * @desc:执行订单初始化
- * @Author: ltm
- * @Date: 2021/12/30
- * @Time: 14:14
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param OrderFormLogic $form
- * @param $type
- * @return false|mixed
- */
- public function execute(OrderFormLogic $form, $type){
- try{
- if (!isset($this->handlers[$type])) throw new Exception('下单类型错误');
- $class = new $this->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;
- }
- }
- }
|