From 87a5b2f9e1b1a82db74146d43feabf79409f80f5 Mon Sep 17 00:00:00 2001 From: ctexthuang Date: Sun, 23 Mar 2025 19:07:29 +0800 Subject: [PATCH] feat: config --- app/Model/Order.php | 17 ++++++++++++++++- app/Model/Sku.php | 2 +- app/Model/Spu.php | 16 ++++++++++++++++ app/Service/Api/Order/OrderInfoService.php | 18 +++++++++++++++++- app/Service/Api/Order/PlaceOrderService.php | 2 ++ 5 files changed, 52 insertions(+), 3 deletions(-) diff --git a/app/Model/Order.php b/app/Model/Order.php index 25986c2..c6d8903 100644 --- a/app/Model/Order.php +++ b/app/Model/Order.php @@ -24,6 +24,8 @@ use Hyperf\DbConnection\Model\Model; * @property string $total_price * @property string $actual_price * @property string $discount_price + * @property string $append_price + * @property int $append_copies * @property int $status * @property int $is_refund_all * @property string $cancel_time @@ -53,7 +55,20 @@ class Order extends Model /** * The attributes that should be cast to native types. */ - protected array $casts = ['id' => 'integer', 'user_id' => 'integer', 'cycle_id' => 'integer', 'site_id' => 'integer', 'city_id' => 'integer', 'coupon_id' => 'integer', 'meal_copies' => 'integer', 'optional_copies' => 'integer', 'status' => 'integer', 'is_refund_all' => 'integer','kitchen_id' => 'integer']; + protected array $casts = [ + 'id' => 'integer', + 'user_id' => 'integer', + 'cycle_id' => 'integer', + 'site_id' => 'integer', + 'city_id' => 'integer', + 'coupon_id' => 'integer', + 'meal_copies' => 'integer', + 'optional_copies' => 'integer', + 'status' => 'integer', + 'is_refund_all' => 'integer', + 'kitchen_id' => 'integer', + 'append_copies' => 'integer' + ]; const string CREATED_AT = 'create_time'; diff --git a/app/Model/Sku.php b/app/Model/Sku.php index 3ad02c5..527f24b 100644 --- a/app/Model/Sku.php +++ b/app/Model/Sku.php @@ -88,7 +88,7 @@ class Sku extends Model ->orderBy('sort') ->get(); - if (empty($res)) return []; + if ($res->isEmpty()) return []; return $res->toArray(); } diff --git a/app/Model/Spu.php b/app/Model/Spu.php index 77eb3fd..4d43042 100644 --- a/app/Model/Spu.php +++ b/app/Model/Spu.php @@ -86,4 +86,20 @@ class Spu extends Model ->select(['id','cycle_id','chef_id','title','title','sub_title','category_id']) ->get(); } + + /** + * @param array $ids + * @return array + */ + public function getDataArrByIds(array $ids): array + { + $res = $this + ->whereIn('id',$ids) + ->orderBy('sort') + ->get(); + + if ($res->isEmpty()) return []; + + return $res->toArray(); + } } diff --git a/app/Service/Api/Order/OrderInfoService.php b/app/Service/Api/Order/OrderInfoService.php index 4c47da4..446bac1 100644 --- a/app/Service/Api/Order/OrderInfoService.php +++ b/app/Service/Api/Order/OrderInfoService.php @@ -104,6 +104,12 @@ class OrderInfoService extends BaseService $skuList = array_column($skuList, null,'id'); $imageList = $this->getOssObjects(array_column($skuList,'image_ids')); + $spuIds = array_unique(array_column($skuList,'spu_id')); + $spuList = $this->spuModel->getDataArrByIds($spuIds); + $spuList = array_column($skuList, null,'id'); + + $chefId = array_unique(array_column($spuList,'chef_id')); + $orderCopiesList = []; for ($i = 1; $i <= ($orderInfo['copies'] ?? 0); $i++) { @@ -123,7 +129,15 @@ class OrderInfoService extends BaseService $skuInfo['url'] = $imageList[$imageId]['url'] ?? ''; $oneCopiesInfo['image_list'][] = $imageList[$imageId] ?? []; - $oneCopiesInfo['sku_list'][] = $skuInfo; + $oneCopiesInfo['sku_list'][] = [ + 'url' => $imageList[$imageId]['url'] ?? '', + 'title' => $skuList[$item['sku_id']]['title'] ?? '', + 'unit_price' => $item['unit_price'], + 'quantity' => $item['quantity'], + 'price' => bcmul($item['unit_price'], $item['quantity'], 2), + 'chef_name' => '123', + 'spu_title' => $spuList[$skuList[$item['sku_id']]['spu_id']]['title'] ?? '', + ]; $oneCopiesInfo['total_price'] = bcadd($oneCopiesInfo['total_price'], bcmul($item['unit_price'],(string)$item['quantity'],2), 2); $oneCopiesInfo['total_quantity'] += $item['quantity']; } @@ -133,5 +147,7 @@ class OrderInfoService extends BaseService $orderInfo['copies_list'] = $orderCopiesList; $orderInfo['site'] = $this->siteCache->getSiteInfo($orderInfo['site_id']); + + //todo coupon } } \ No newline at end of file diff --git a/app/Service/Api/Order/PlaceOrderService.php b/app/Service/Api/Order/PlaceOrderService.php index 70ebb0e..5c3d510 100644 --- a/app/Service/Api/Order/PlaceOrderService.php +++ b/app/Service/Api/Order/PlaceOrderService.php @@ -201,6 +201,8 @@ class PlaceOrderService extends BaseOrderService $orderInsertModel->total_price = $this->orderRes['total_price']; $orderInsertModel->actual_price = max($this->orderRes['actual_price'], 0); $orderInsertModel->discount_price = $this->orderRes['favorable_sundry_price'] + $this->orderRes['favorable_good_price']; + $orderInsertModel->append_price = $this->orderRes['sundry_price']; + $orderInsertModel->append_copies = $this->orderRes['sundry_num']; $orderInsertModel->status = OrderCode::WAIT_PAY; $orderInsertModel->is_refund_all = OrderCode::REFUND_NULL; $orderInsertModel->order_json = json_encode($this->orderRes);