| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- <?php
- namespace common\events\data\api;
- use common\components\BaseEvent;
- use common\enums\EventNameEnum;
- use common\logic\order\BaseOrderForm;
- use common\models\user\User;
- use Exception;
- /**
- * 供应链订单售前检测
- * @package common\events\data\backend
- */
- final class ChainOrderCheckEvent extends BaseEvent
- {
- /**
- * 触发事件名称(不可修改)
- *
- * @var string
- */
- public $name = EventNameEnum::CHAIN_ORDER_CHECK;
- /**
- * @var User|array
- */
- protected $user;
- /**
- * @var BaseOrderForm
- */
- protected $form;
- /**
- * @var boolean
- */
- protected $isNewRecord = true;
- /**
- * @var boolean
- */
- protected $isError = false;
- /**
- * @var string
- */
- protected $errorMsg;
- /**
- * @param integer $mall_id
- * @param array $list
- * @param array $user
- */
- public function __construct(int $mall_id, BaseOrderForm $form, bool $is_new_record, $user = [])
- {
- parent::__construct($mall_id);
- $this->form = $form;
- $this->isNewRecord = $is_new_record;
- $this->user = $user;
- }
- /**
- * @var BaseOrderForm
- */
- public function getForm()
- {
- return $this->form;
- }
- /**
- * @param BaseOrderForm $form
- * @return void
- */
- public function setForm(BaseOrderForm $form)
- {
- $this->form = $form;
- }
- /**
- * @return BaseOrderForm|boolean
- */
- public function getResultForm()
- {
- if ($this->isError) return false;
- return $this->form;
- }
- /**
- * @return boolean
- */
- public function isNewRecord()
- {
- return $this->isNewRecord;
- }
- /**
- * @param string $msg
- * @return void
- */
- public function setErrorMsg(string $msg)
- {
- $this->isError = true;
- $this->errorMsg = $msg;
- }
- /**
- * @return string
- */
- public function getErrorMsg()
- {
- return $this->errorMsg;
- }
- /**
- * @param string $source
- * @return boolean
- */
- public function isCurrentSource(string $source): bool
- {
- return $this->getGoodsSource() == $source;
- }
- /**
- * 获取商品的来源类型
- *
- * @return string
- */
- public function getGoodsSource()
- {
- $sources = array_unique(array_column(array_column($this->getForm()->sku, 'goods'), 'goods_source'));
- if (count($sources) > 1) throw new Exception('商品来源不一致');
- return reset($sources);
- }
- }
|