From 64ffb05d744cc648056ff52fe106d604e8f0eadd Mon Sep 17 00:00:00 2001 From: yanzai Date: Fri, 18 Oct 2024 22:18:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8C=89=E7=A7=91=E5=AE=A4=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E6=95=B0=E9=87=8F=EF=BC=88=E6=96=B9=E6=B3=95?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/Http/Controllers/TestController.php | 3 + Laravel/app/Services/OrderService.php | 72 +++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 Laravel/app/Services/OrderService.php diff --git a/Laravel/app/Http/Controllers/TestController.php b/Laravel/app/Http/Controllers/TestController.php index bcc5f87..2ebfa92 100644 --- a/Laravel/app/Http/Controllers/TestController.php +++ b/Laravel/app/Http/Controllers/TestController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use App\Services\OrderService; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; @@ -9,6 +10,8 @@ class TestController extends Controller { public function DBtest(){ echo DB::table('users')->count(); + // $order= new OrderService(); + // $order->DepartmentItemCount(33); } public function ApiTest(){ diff --git a/Laravel/app/Services/OrderService.php b/Laravel/app/Services/OrderService.php new file mode 100644 index 0000000..8a5d37c --- /dev/null +++ b/Laravel/app/Services/OrderService.php @@ -0,0 +1,72 @@ +where('id',$id)->first(); + if(!$order) return ['status'=>false,'msg'=>'订单不存在']; + $buy_info=json_decode($order->buy_info,true); + $list=[]; + if($buy_info['combo']['id']<>0){ + $combo_items=DB::table('combo_items')->where(['combo_id'=>$buy_info['combo']['id'],'status'=>1])->get(); + foreach($combo_items as $item){ + $list[]=[ + 'item_id'=>$item->item_id, + 'keshi_name'=>$item->keshi_name, + 'keshi_id'=>$item->keshi_id, + ]; + } + } + if(count($buy_info['items'])>0){ + $item_ids=[]; + foreach($buy_info['items'] as $item){ + $item_ids[]=$item['id']; + } + $itemsInfo=DB::table('items')->whereIn('item_id',$item_ids)->get(); + foreach($itemsInfo as $item){ + $list[]=[ + 'item_id'=>$item->item_id, + 'keshi_name'=>$item->keshi_name, + 'keshi_id'=>$item->keshi_id, + ]; + } + } + if($buy_info['group']['id']<>''){ + $item_ids=[]; + foreach($buy_info['group']['items'] as $item){ + $item_ids[]=$item['id']; + } + $itemsInfo=DB::table('items')->whereIn('item_id',$item_ids)->get(); + foreach($itemsInfo as $item){ + $list[]=[ + 'item_id'=>$item->item_id, + 'keshi_name'=>$item->keshi_name, + 'keshi_id'=>$item->keshi_id, + ]; + } + } + $groupedData = []; + foreach ($list as $key => $item) { + $keshiName = $item['keshi_name']; + if (!isset($groupedData[$keshiName])) { + $groupedData[$keshiName] = []; + } + $groupedData[$keshiName][] = $item; + } + $de_list=[]; + foreach ($groupedData as $key => $item) { + $de_list[]=[ + 'name'=>$key, + 'count'=>count($item), + ]; + } + return ['department_list'=>$de_list,'wait_day'=>"10"]; + + } +}