From d9f52ac75579e9b718cc8cce145fc876c9cf0c07 Mon Sep 17 00:00:00 2001 From: ctexthuang Date: Tue, 11 Mar 2025 10:16:18 +0800 Subject: [PATCH] feat : catering --- app/Controller/Admin/CateringController.php | 15 +++++++++++ app/Model/OrderOptionCateringLog.php | 10 +++++--- .../Admin/Catering/CateringBaseService.php | 8 ++++++ .../Admin/Catering/Meal/CycleListService.php | 17 +++++++++++++ .../Catering/Option/CycleListService.php | 2 ++ .../Admin/CouponDispenseTrait.php | 4 +-- app/Service/ServiceTrait/CateringTrait.php | 25 ++++++++++++++----- 7 files changed, 69 insertions(+), 12 deletions(-) diff --git a/app/Controller/Admin/CateringController.php b/app/Controller/Admin/CateringController.php index b6ffd49..237ca42 100644 --- a/app/Controller/Admin/CateringController.php +++ b/app/Controller/Admin/CateringController.php @@ -45,4 +45,19 @@ class CateringController { return (new OptionCycleListService)->remainCount(); } + + public function getMealGoodsList() + { + return (new MealCycleListService)->skuList(); + } + + public function mealCatering() + { + + } + + public function optionCatering() + { + + } } diff --git a/app/Model/OrderOptionCateringLog.php b/app/Model/OrderOptionCateringLog.php index 9d79e9a..a443ba1 100644 --- a/app/Model/OrderOptionCateringLog.php +++ b/app/Model/OrderOptionCateringLog.php @@ -9,7 +9,8 @@ use Hyperf\DbConnection\Model\Model; /** * @property int $id - * @property int $cycle_id + * @property int $cycle_id + * @property int $kitchen_id * @property int $site_id * @property int $quantity * @property int $add_staple_food_num @@ -32,15 +33,16 @@ class OrderOptionCateringLog extends Model /** * The attributes that should be cast to native types. */ - protected array $casts = ['id' => 'integer', 'cycle_id' => 'integer', 'site_id' => 'integer', 'quantity' => 'integer', 'add_staple_food_num' => 'integer', 'status' => 'integer']; + protected array $casts = ['id' => 'integer', 'cycle_id' => 'integer', 'kitchen_id' => 'integer', 'site_id' => 'integer', 'quantity' => 'integer', 'add_staple_food_num' => 'integer', 'status' => 'integer']; /** * @param int $siteId * @param int $cycleId + * @param int $kitchenId * @return Builder|\Hyperf\Database\Model\Model|null */ - public function getInfoBySiteIdAndCycleId(int $siteId, int $cycleId): \Hyperf\Database\Model\Model|Builder|null + public function getInfoBySiteIdAndCycleIdAndSiteId(int $siteId, int $cycleId, int $kitchenId): \Hyperf\Database\Model\Model|Builder|null { - return $this->where('site_id', $siteId)->where('cycle_id', $cycleId)->first(); + return $this->where('site_id', $siteId)->where('cycle_id', $cycleId)->where('kitchen_id',$kitchenId)->first(); } } diff --git a/app/Service/Admin/Catering/CateringBaseService.php b/app/Service/Admin/Catering/CateringBaseService.php index cb7ddcd..d78a054 100644 --- a/app/Service/Admin/Catering/CateringBaseService.php +++ b/app/Service/Admin/Catering/CateringBaseService.php @@ -67,6 +67,8 @@ abstract class CateringBaseService extends BaseService $this->checkRole(); $this->getCycleId(); + + $this->getKitchenId(); } /** @@ -96,6 +98,12 @@ abstract class CateringBaseService extends BaseService $this->cycleId = (int)$cycleId; } + private function getKitchenId(): void + { + //todo 自选配餐员工要绑定厨房 套餐配餐员工要绑定每日套餐 + $this->kitchenId = 1; + } + /** * @param array $data * @return array diff --git a/app/Service/Admin/Catering/Meal/CycleListService.php b/app/Service/Admin/Catering/Meal/CycleListService.php index 505d796..a613e46 100644 --- a/app/Service/Admin/Catering/Meal/CycleListService.php +++ b/app/Service/Admin/Catering/Meal/CycleListService.php @@ -69,4 +69,21 @@ class CycleListService extends CateringBaseService return $this->return->success('success',['count' => $count]); } + + public function skuList() + { + $res = [ + [ + 'id' => 1, + 'name' => 'spu_name' + ], + [ + 'id' => 2, + 'name' => 'spu2_name' + ] + ]; + + return $this->return->success('success',$res); + } + } \ No newline at end of file diff --git a/app/Service/Admin/Catering/Option/CycleListService.php b/app/Service/Admin/Catering/Option/CycleListService.php index 1419ad3..ff57605 100644 --- a/app/Service/Admin/Catering/Option/CycleListService.php +++ b/app/Service/Admin/Catering/Option/CycleListService.php @@ -34,6 +34,7 @@ class CycleListService extends CateringBaseService { $cycleCateringLogs = $this->orderOptionCateringLogModel ->where('cycle_id',$this->cycleId) + ->where('kitchen_id',$this->kitchenId) ->select(['site_id','quantity','status','id']) ->get(); @@ -51,6 +52,7 @@ class CycleListService extends CateringBaseService { $count = $this->orderOptionCateringLogModel ->where('cycle_id',$this->cycleId) + ->where('kitchen_id',$this->kitchenId) ->sum('quantity') ?? 0; return $this->return->success('success',['count' => $count]); diff --git a/app/Service/ServiceTrait/Admin/CouponDispenseTrait.php b/app/Service/ServiceTrait/Admin/CouponDispenseTrait.php index e29dea5..2d7a405 100644 --- a/app/Service/ServiceTrait/Admin/CouponDispenseTrait.php +++ b/app/Service/ServiceTrait/Admin/CouponDispenseTrait.php @@ -25,7 +25,7 @@ trait CouponDispenseTrait $this->cycleId = $cycleInfo->id; - $appointValue = json_encode($this->request->input('appoint_value')); + $appointValue = $this->request->input('appoint_value'); // if ($this->groupType == CouponCode::DISPENSE_APPOINT_GROUP_DESIGNATED_SITES_AND_GOODS) { // $this->appointValue = [ // 'site' => explode(',', $appointValue['site']), @@ -152,7 +152,7 @@ trait CouponDispenseTrait { $this->checkAppointValue(); - $appointValue = json_encode($this->request->input('appoint_value')); + $appointValue = $this->request->input('appoint_value'); return explode(',', $appointValue['user_ids']); } diff --git a/app/Service/ServiceTrait/CateringTrait.php b/app/Service/ServiceTrait/CateringTrait.php index 5b81f8a..f63aa2d 100644 --- a/app/Service/ServiceTrait/CateringTrait.php +++ b/app/Service/ServiceTrait/CateringTrait.php @@ -2,6 +2,7 @@ namespace App\Service\ServiceTrait; +use App\Cache\Redis\Api\SiteCache; use App\Constants\Common\OrderCode; use App\Model\OrderMealCateringLog; use App\Model\OrderOptionCateringLog; @@ -23,8 +24,16 @@ trait CateringTrait #[Inject] protected OrderMealCateringLog $orderMealCateringLogModel; + /** + * @var SiteCache + */ + #[Inject] + protected SiteCache $siteCache; + /** * @return bool 添加失败需要退款 + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ private function manageAddCateringLog(): bool { @@ -46,8 +55,6 @@ trait CateringTrait OrderCode::ORDER_TYPE_MEAL => $this->manageSubMealCateringLog(), OrderCode::ORDER_TYPE_OPTIONAL => $this->manageSubOptionCateringLog(), }; - - } /** @@ -60,8 +67,10 @@ trait CateringTrait // todo 减少可以不减少根据订单 cycle_id 获取加一碗米饭 的数量 减少查询压力 // $addStapleFoodNum = 0; - //todo 需要绑定一个 kitchen_id - $logInfo = $this->orderOptionCateringLogModel->getInfoBySiteIdAndCycleId($this->orderInfo->site_id, $this->orderInfo->cycle_id); + $siteInfo = $this->siteCache->getSiteInfo($this->orderInfo->site_id); + + //需要绑定一个 kitchen_id + $logInfo = $this->orderOptionCateringLogModel->getInfoBySiteIdAndCycleIdAndSiteId($this->orderInfo->site_id, $this->orderInfo->cycle_id, (int)$siteInfo['kitchen_id']); if (empty($logInfo)) { $this->log->error(__CLASS__.':Function:refundCallBackHandle:manageSubOptionCateringLog:订单套餐配餐记录不存在,订单信息:'.json_encode($this->orderInfo->toArray())); @@ -114,20 +123,24 @@ trait CateringTrait /** * 添加自选配餐数据 * @return bool + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ private function manageAddOptionCateringLog(): bool { //todo 根据订单 cycle_id 获取加一碗米饭 的数量 $addStapleFoodNum = 0; - //todo 需要绑定一个 kitchen_id - $logInfo = $this->orderOptionCateringLogModel->getInfoBySiteIdAndCycleId($this->orderInfo->site_id, $this->orderInfo->cycle_id); + $siteInfo = $this->siteCache->getSiteInfo($this->orderInfo->site_id); + //需要绑定一个 kitchen_id + $logInfo = $this->orderOptionCateringLogModel->getInfoBySiteIdAndCycleIdAndSiteId($this->orderInfo->site_id, $this->orderInfo->cycle_id,(int)$siteInfo['kitchen_id']); if (empty($logInfo)) { $logInfo = new OrderOptionCateringLog(); $logInfo->site_id = $this->orderInfo->site_id; $logInfo->cycle_id = $this->orderInfo->cycle_id; + $logInfo->kitchen_id = (int)$siteInfo['kitchen_id']; $logInfo->quantity = 0; $logInfo->add_staple_food_num = 0; $logInfo->status = 1;