'原因'] * * @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' => '' ]; } }