You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
2.2 KiB
PHP
75 lines
2.2 KiB
PHP
<?php
|
|
namespace App\Services;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class OrderService
|
|
{
|
|
|
|
//订单项目按科室分类
|
|
public function DepartmentItemCount($id)
|
|
{
|
|
$order=DB::table('orders')->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,
|
|
'keshi_id'=>$item[0]['keshi_id'],
|
|
'count'=>count($item),
|
|
];
|
|
}
|
|
return ['department_list'=>$de_list,'wait_day'=>"10"];
|
|
|
|
}
|
|
}
|