mall_id, $order_id); if (empty($order)) return true; $store_id = $order->store_id; // 是否自提订单 if (!$order->isPuckup()) return true; // 查看店铺是否开启 if (!$this->isOpenPickup($store_id)) return true; $code = $this->getPickupCode($store_id); if ( StoreOrderPickup::addPickup( $this->mall_id, $store_id, $order_id, $mall_order_id, $this->getStage(), $code ) ) { return true; } return false; } /** * 店铺是否开启自提码 * * @param integer $store_id * @return boolean */ public function isOpenPickup(int $store_id) { $key = sprintf('pickup_setting:%s', $store_id); if ($pickup = Yii::$app->redis->get($key)) { $pickup = json_decode($pickup, true); } else { $pickup = Store::getStorePickup($store_id); Yii::$app->redis->setex($key, 5, json_encode($pickup)); } if (empty($pickup)) return false; return ($pickup['status'] ?? 0) == 1; } /** * 获取自提号 * * @param integer $store_id * @return string */ protected function getPickupCode(int $store_id) : string { $stage = $this->getStage(); /* $count = StoreOrderPickup::getStoreCount($store_id, $stage); return static::PREFIX . ($count <= static::MAX ? str_pad(++$count, strlen(static::MAX), '0', STR_PAD_LEFT) : ++$count); */ // 使用redis自增 $key = sprintf('getPickupCode:%s:%s', $store_id, $stage); Yii::$app->redis->incr($key); $count = Yii::$app->redis->get($key); return static::PREFIX . ($count <= static::MAX ? str_pad($count, strlen(static::MAX), '0', STR_PAD_LEFT) : $count); } /** * 获取期数 * * @return string */ protected function getStage() :string { return $this->stage ?? $this->stage = date('Ymd'); } }