| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php
- namespace common\events\order;
- use common\components\BaseEvent;
- use common\enums\EventNameEnum;
- class ShippingValidateEvent extends BaseEvent
- {
- /**
- * 触发事件名称(不可修改)
- *
- * @var string
- */
- public $name = EventNameEnum::SHIPPING_VALIDATE;
- /**
- * 不允许发货的订单id["id" => '原因']
- *
- * @var array $notAllowedShippingMap
- */
- private $notAllowedShippingMap = [];
- /**
- * 需要验证的订单id
- *
- * @var array $orderIds
- */
- private $orderIds = [];
- public function __construct(int $mall_id)
- {
- $this->mall_id = $mall_id;
- }
- /**
- * 获取待检查的订单id
- *
- * @param bool $excludeCheckedIds 如果订单id已经不允许发货的,下一个监听者是否还返回此订单id
- *
- * @return array
- */
- public function getOrderIds(bool $excludeCheckedIds = true): array
- {
- if (!$excludeCheckedIds) {
- return $this->orderIds;
- }
- return array_diff($this->orderIds, array_keys($this->notAllowedShippingMap));
- }
- /**
- * @param array $orderIds
- *
- * @return void
- */
- public function setOrderIds(array $orderIds)
- {
- $this->orderIds = $orderIds;
- }
- /**
- * @param int $orderId
- * @param string $reason
- *
- * @return void
- */
- public function setNotAllow(int $orderId, string $reason)
- {
- if (isset($this->notAllowedShippingMap[$orderId])) {
- return;
- }
- $this->notAllowedShippingMap[$orderId] = $reason;
- }
- /**
- * 返回是否允许
- *
- * @param int $orderId
- *
- * @return array
- */
- public function getIsAllow(int $orderId): array
- {
- if (isset($this->notAllowedShippingMap[$orderId])) {
- return [
- 'isAllow' => false,
- 'reason' => $this->notAllowedShippingMap[$orderId]
- ];
- }
- return [
- 'isAllow' => true,
- 'reason' => ''
- ];
- }
- }
|