From 263d7b4372f861792c367d1eb9bbc7018e342a50 Mon Sep 17 00:00:00 2001 From: ctexthuang Date: Tue, 1 Apr 2025 16:08:07 +0800 Subject: [PATCH] feat : check --- app/Amqp/Consumer/OrderGoodStockConsumer.php | 2 -- app/Cache/Redis/Admin/AdminRedisKey.php | 9 +++++ .../Admin/Catering/Meal/CheckService.php | 21 +++++++++++- .../Admin/Catering/PrintTrait.php | 34 +++++++++++++++++++ app/Service/ServiceTrait/Api/OrderTrait.php | 2 ++ 5 files changed, 65 insertions(+), 3 deletions(-) diff --git a/app/Amqp/Consumer/OrderGoodStockConsumer.php b/app/Amqp/Consumer/OrderGoodStockConsumer.php index 2ac1ecb..8911da1 100644 --- a/app/Amqp/Consumer/OrderGoodStockConsumer.php +++ b/app/Amqp/Consumer/OrderGoodStockConsumer.php @@ -166,8 +166,6 @@ class OrderGoodStockConsumer extends ConsumerMessage } - - return Result::ACK; } catch (Exception $e) { if (!empty($this->rollbackStockCache)) { diff --git a/app/Cache/Redis/Admin/AdminRedisKey.php b/app/Cache/Redis/Admin/AdminRedisKey.php index 037587a..7a357f0 100644 --- a/app/Cache/Redis/Admin/AdminRedisKey.php +++ b/app/Cache/Redis/Admin/AdminRedisKey.php @@ -114,6 +114,15 @@ class AdminRedisKey return 'catering:meal:is:cycle_id:'.$cycleId; } + /** + * @param string $cycleId + * @return string + */ + public static function mealIsCateringBySkuId(string $cycleId): string + { + return 'catering:meal:sku:cycle_id:'.$cycleId; + } + /** * 套餐配餐点位顺序 diff --git a/app/Service/Admin/Catering/Meal/CheckService.php b/app/Service/Admin/Catering/Meal/CheckService.php index 734fee2..2afe144 100644 --- a/app/Service/Admin/Catering/Meal/CheckService.php +++ b/app/Service/Admin/Catering/Meal/CheckService.php @@ -17,13 +17,18 @@ use App\Model\Order; use App\Model\OrderGood; use App\Model\OrderMealCateringLog; use App\Service\Admin\Catering\CateringBaseService; +use App\Service\ServiceTrait\Admin\Catering\PrintTrait; use Exception; use Hyperf\DbConnection\Db; use Hyperf\Di\Annotation\Inject; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; class CheckService extends CateringBaseService { + use PrintTrait; + /** * @var OrderMealCateringLog */ @@ -49,6 +54,8 @@ class CheckService extends CateringBaseService /** * @return array + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ public function handle(): array { @@ -67,7 +74,7 @@ class CheckService extends CateringBaseService ->where('quantity','>',0) ->first(); - if (!empty($todayLog)) return $this->return->success(); + if (!empty($todayLog)) return $this->closeSku(); $orderIds = $this->orderModel ->where('cycle_id', $this->cycleId) @@ -88,6 +95,18 @@ class CheckService extends CateringBaseService return $this->return->success(); } + /** + * @return array + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + private function closeSku(): array + { + $this->closeMealSku((int)$this->request->input('sku_id'), $this->cycleId); + + return $this->return->success(); + } + /** * @return void */ diff --git a/app/Service/ServiceTrait/Admin/Catering/PrintTrait.php b/app/Service/ServiceTrait/Admin/Catering/PrintTrait.php index fc89578..b536885 100644 --- a/app/Service/ServiceTrait/Admin/Catering/PrintTrait.php +++ b/app/Service/ServiceTrait/Admin/Catering/PrintTrait.php @@ -342,4 +342,38 @@ trait PrintTrait return CateringCode::REDIS_FINISH_VALUE == $this->redis->hGet($this->stopMealOrderKey, (string)$siteId); } + + /** + * @param int $skuId + * @param int $cycleId + * @return void + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + protected function closeMealSku(int $skuId, int $cycleId): void + { + $key = AdminRedisKey::mealIsCateringBySkuId($cycleId); + + $hashKey = (string)$skuId; + + if (CateringCode::REDIS_FINISH_VALUE == $this->redis->hGet($key, $hashKey)) return; + + $this->redis->hSet($key, $hashKey, CateringCode::REDIS_FINISH_VALUE); + } + + /** + * @param int $skuId + * @param int $cycleId + * @return bool + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + protected function checkSkuMeal(int $skuId, int $cycleId): bool + { + $key = AdminRedisKey::mealIsCateringBySkuId($cycleId); + + $hashKey = (string)$skuId; + + return CateringCode::REDIS_FINISH_VALUE == $this->redis->hGet($key, $hashKey); + } } \ No newline at end of file diff --git a/app/Service/ServiceTrait/Api/OrderTrait.php b/app/Service/ServiceTrait/Api/OrderTrait.php index 32e4cdf..a76d3e8 100644 --- a/app/Service/ServiceTrait/Api/OrderTrait.php +++ b/app/Service/ServiceTrait/Api/OrderTrait.php @@ -112,6 +112,8 @@ trait OrderTrait if ($this->orderType != OrderCode::ORDER_TYPE_MEAL) return; if ($this->isMealCateringByCache($this->siteId, $key, $this->cycleId)) throw new ErrException('该点位的套餐'.$this->skuArr[$key]['title'].'已配餐截单,请选择其他套餐'); + + if ($this->checkSkuMeal($key, $this->cycleId)) throw new ErrException('该套餐'.$this->skuArr[$key]['title'].'已配餐截单,请选择其他套餐'); } }