leftJoin('web_user_person as b' ,'a.id','=','b.user_id') ->where(['openid'=>$openid,'b.is_del'=>0,'b.is_default'=>1]) ->first(); if(!$person) return \Yz::echoError1("就诊人信息不存在"); //查询所有可以自选的项目 $items=DB::table('items')->where(['is_choose'=>1,'status'=>1])->get(); $search= request('search'); $list = []; $group_arr = []; $group_list = []; $items= $this->KeShiPaiXu($items); foreach ($items as $item) { $item->price=number_format($item->price * config('app.globals.ZiXuan_ZheKou'), 2, '.', '') ; if($item->sex <> $person->sex and $item->sex<>0){ continue; } $push_type = false; if ($search == '') { $push_type = true; } else { $check_name = $item->name; if (strpos($check_name, $search) !== false) { $push_type = true; } $check_py = $item->pinyin; if (strpos($check_py, mb_strtoupper($search)) !== false) { $push_type = true; } $check_group = $item->keshi_name; if (strpos($check_group, $search) !== false) { $push_type = true; } } if ($push_type) { if (!in_array($item->keshi_id, $group_arr)) { $group_list["科室{$item->keshi_id}"] = [ 'id' => $item->keshi_id, 'title' => $item->keshi_name, 'head_img'=>'/storage/20240822/banner1.png', 'children' => [], ]; $group_arr[] = $item->keshi_id; } $group_list["科室{$item->keshi_id}"]['children'][] = [ 'id' => $item->item_id, 'title' => $item->name, 'price' =>$item->price, 'original_price'=>$item->original_price, 'pinyin' => $item->pinyin, 'desc'=>$item->beizhu ]; } } return \Yz::Return(true,"查询成功",['list'=>$group_list]); } public function KeShiPaiXu($data){ $sortOrder =config('app.globals.KeShiPaiXu'); // 创建一个映射,用于快速查找每个科室名称在排序数组中的位置 $sortMap = array_flip($sortOrder); // 使用 sortBy 方法进行排序 $sortedData = $data->sortBy(function ($data) use ($sortMap) { // 如果科室名称存在于映射中,则返回其位置;否则返回一个很大的数字,使其排在最后 return isset($sortMap[$data->keshi_name]) ? $sortMap[$data->keshi_name] : PHP_INT_MAX; }); return $sortedData; } }