From 4fcc5286a1381bbac6ed6543d99afaa214ad2fa6 Mon Sep 17 00:00:00 2001 From: ctexthuang Date: Mon, 24 Mar 2025 15:44:57 +0800 Subject: [PATCH] feat : add_staple_food --- app/Service/Api/Order/OrderInfoService.php | 26 ++++++++++++++++++++- app/Service/Api/Order/OrderListService.php | 22 +++++++++++++++++ app/Service/ServiceTrait/Api/OrderTrait.php | 16 +++++++++---- 3 files changed, 58 insertions(+), 6 deletions(-) diff --git a/app/Service/Api/Order/OrderInfoService.php b/app/Service/Api/Order/OrderInfoService.php index dbb26fc..3ed87be 100644 --- a/app/Service/Api/Order/OrderInfoService.php +++ b/app/Service/Api/Order/OrderInfoService.php @@ -11,6 +11,8 @@ declare(strict_types=1); namespace App\Service\Api\Order; use App\Cache\Redis\Api\SiteCache; +use App\Constants\Common\GoodCode; +use App\Constants\Common\OrderCode; use App\Exception\ErrException; use App\Model\AdminUser; use App\Model\Chef; @@ -121,13 +123,25 @@ class OrderInfoService extends BaseService $chefList = array_column($chefList, null,'id'); $orderCopiesList = []; - for ($i = 1; $i <= ($orderInfo['copies'] ?? 0); $i++) { + $addStapleFood = []; + if ($orderInfo['type'] == OrderCode::ORDER_TYPE_MEAL) { + $addStapleFood = [ + 'total_price' => '0.00', + 'total_quantity' => 0, + 'sku_list' => [], + 'take_food_code' => '', //取餐码 + 'url' => '', + 'is_add_staple_food' => GoodCode::IS_ADD_STAPLE_FOOD, + ]; + } + for ($i = 1; $i <= ($orderInfo['copies'] ?? 0); $i++) { $oneCopiesInfo = [ 'total_price' => '0.00', 'total_quantity' => 0, 'sku_list' => [], 'take_food_code' => '', //todo 取餐码 + 'is_add_staple_food' => GoodCode::IS_NOT_ADD_STAPLE_FOOD, ]; foreach ($newOrderSkuList[$i] as $item) { @@ -135,6 +149,15 @@ class OrderInfoService extends BaseService $skuInfo = $skuList[$item['sku_id']] ?? []; $imageId = !empty($skuInfo) && !empty(explode(',',$skuInfo['image_ids'])[0]) ? explode(',',$skuInfo['image_ids'])[0] : []; + + if ($skuInfo['is_staple_food'] == GoodCode::IS_ADD_STAPLE_FOOD) { + $addStapleFood['total_price'] = bcadd((string)$oneCopiesInfo['total_price'], bcmul((string)$item['unit_price'],(string)$item['quantity'],2), 2); + $addStapleFood['total_quantity'] += $item['quantity']; + $addStapleFood['url'] = $imageList[$imageId]['url'] ?? ''; + continue; + } + + // $skuInfo['url'] = $imageList[$imageId]['url'] ?? ''; // $oneCopiesInfo['image_list'][] = $imageList[$imageId] ?? []; @@ -153,6 +176,7 @@ class OrderInfoService extends BaseService $orderCopiesList[] = $oneCopiesInfo; } + if (!empty($addStapleFood)) $orderCopiesList[] = $addStapleFood; $orderInfo['copies_list'] = $orderCopiesList; $orderInfo['site'] = $this->siteCache->getSiteInfo($orderInfo['site_id']); } diff --git a/app/Service/Api/Order/OrderListService.php b/app/Service/Api/Order/OrderListService.php index cd4f522..c475d43 100644 --- a/app/Service/Api/Order/OrderListService.php +++ b/app/Service/Api/Order/OrderListService.php @@ -11,6 +11,8 @@ declare(strict_types=1); namespace App\Service\Api\Order; use App\Cache\Redis\Api\SiteCache; +use App\Constants\Common\GoodCode; +use App\Constants\Common\OrderCode; use App\Model\Order; use App\Model\OrderGood; use App\Model\Sku; @@ -124,6 +126,17 @@ class OrderListService extends BaseService foreach ($orderList as &$order) { $orderCopiesList = []; + $addStapleFood = []; + if ($order['type'] == OrderCode::ORDER_TYPE_MEAL) { + $addStapleFood = [ + 'total_price' => '0.00', + 'total_quantity' => 0, + 'sku_list' => [], + 'take_food_code' => '', //取餐码 + 'is_add_staple_food' => GoodCode::IS_ADD_STAPLE_FOOD, + ]; + } + for ($i = 1; $i <= ($order['copies'] ?? 0); $i++) { $oneCopiesInfo = [ @@ -140,6 +153,14 @@ class OrderListService extends BaseService $skuInfo = $skuList[$item['sku_id']] ?? []; $imageId = !empty($skuInfo) && !empty(explode(',',$skuInfo['image_ids'])[0]) ? explode(',',$skuInfo['image_ids'])[0] : []; + + if ($skuInfo['is_staple_food'] == GoodCode::IS_ADD_STAPLE_FOOD) { + $addStapleFood['total_price'] = bcadd((string)$oneCopiesInfo['total_price'], bcmul((string)$item['unit_price'],(string)$item['quantity'],2), 2); + $addStapleFood['total_quantity'] += $item['quantity']; + $addStapleFood['url'] = $imageList[$imageId]['url'] ?? ''; + continue; + } + $oneCopiesInfo['total_price'] = bcadd($oneCopiesInfo['total_price'], bcmul($item['unit_price'],(string)$item['quantity'],2), 2); $oneCopiesInfo['total_quantity'] += $item['quantity']; // $oneCopiesInfo['sku_list'][] = []; @@ -158,6 +179,7 @@ class OrderListService extends BaseService // $oneCopiesInfo['image_list'][] = $imageList[$imageId] ?? []; // } + if (!empty($addStapleFood)) $oneCopiesInfo[] = $addStapleFood; $orderCopiesList[] = $oneCopiesInfo; } diff --git a/app/Service/ServiceTrait/Api/OrderTrait.php b/app/Service/ServiceTrait/Api/OrderTrait.php index 5d1ed52..a5b4165 100644 --- a/app/Service/ServiceTrait/Api/OrderTrait.php +++ b/app/Service/ServiceTrait/Api/OrderTrait.php @@ -248,6 +248,7 @@ trait OrderTrait 'id' => $key, 'spu_id' => $this->skuArr[$key]['spu_id'], 'is_add_staple_food' => $this->skuArr[$key]['is_add_staple_food'], + 'meal_copies' => $this->skuArr[$key]['is_add_staple_food'] == GoodCode::IS_ADD_STAPLE_FOOD ? 0 : 1, ]; } else { $oneCopiesGoodInfo[$key]['num'] += $oneGood; @@ -265,11 +266,16 @@ trait OrderTrait 'price' => $oneCopiesTotalPrice, ]; -// if ($copiesType == 1) { -// $this->orderRes['optional_copies']++; -// } else { - $this->orderRes['copies']++; -// } + // 加一份米饭不算份数 + switch ($this->orderType) { + case OrderCode::ORDER_TYPE_OPTIONAL: + $this->orderRes['copies']++; + break; + case OrderCode::ORDER_TYPE_MEAL: + $this->orderRes['copies'] = $this->orderRes['copies'] + array_sum(array_column($oneCopiesGoodInfo,'meal_copies')); + break; + } +// if ($this->skuArr[$key]['is_add_staple_food'] != GoodCode::IS_ADD_STAPLE_FOOD) $this->orderRes['copies']++; $this->orderRes['total_good_price'] = bcadd($this->orderRes['total_good_price'],$oneCopiesTotalPrice,2); }