From 7a1b5a7659bff0df938f285189a1e4e4e063531b Mon Sep 17 00:00:00 2001 From: yanzai Date: Sun, 6 Oct 2024 08:40:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8C=BB=E7=94=9F=E7=AB=AF=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/API/H5/ReportController.php | 48 ++--- .../Controllers/API/Web/ComboController.php | 174 +++++++++++++++ .../Controllers/API/Web/OrderController.php | 203 ++++++++++++++++++ Laravel/routes/web.php | 2 + 4 files changed, 403 insertions(+), 24 deletions(-) create mode 100644 Laravel/app/Http/Controllers/API/Web/OrderController.php diff --git a/Laravel/app/Http/Controllers/API/H5/ReportController.php b/Laravel/app/Http/Controllers/API/H5/ReportController.php index 53d1859..f2105cc 100644 --- a/Laravel/app/Http/Controllers/API/H5/ReportController.php +++ b/Laravel/app/Http/Controllers/API/H5/ReportController.php @@ -374,7 +374,7 @@ class ReportController extends Controller $id_number = $request->post('id_number'); $date = $request->post('date'); $hospital = $request->post('hospital'); - $analysis_type = DB::table('analysis_types')->where('id', $id)->get(); + $analysis_type = DB::table('analysis_types')->where('id', $id)->first(); $mark = $analysis_type->mark; $value = 0; $unit = ''; @@ -395,33 +395,33 @@ class ReportController extends Controller $date_list = []; $datetime = ''; foreach ($reports as $item) { - $datetime=explode('T', $item['登记时间'])[0]; - $jc_item=DB::table('report_l2_items as a')->leftJoin(['report_l3_base_items as b','a.id','=','b.report_l2_id'])->where(['a.reprort_l1_id'=>$item->id])->get(); + $datetime=explode('T', $item->登记时间); + $jc_item=DB::table('report_l2_items as a')->leftJoin('report_l3_base_items as b','a.id','=','b.report_l2_id')->where(['a.reprort_l1_id'=>$item->id])->get(); foreach ($jc_item as $i) { - if ($i['基础项目代码'] == $mark) { - if ($i['结果类型'] == '数值' && !!$i['结果值范围']) { + if ($i->基础项目代码 == $mark) { + if ($i->结果类型 == '数值' && !!$i->结果值范围) { $date_list[] = $datetime; $result = '正常'; - if ($i['异常标识'] == '↑') $result = '偏高'; - if ($i['异常标识'] == '↓') $result = '偏低'; - $range_str = $i['结果值范围']; + if ($i->异常标识 == '↑') $result = '偏高'; + if ($i->异常标识 == '↓') $result = '偏低'; + $range_str = $i->结果值范围; if (strtotime($datetime) > $time) { $info['result'] = $result; - $info['value'] = $i['异常标识'] . $i['结果值'] . $i['结果值单位']; - $value = $i['结果值']; + $info['value'] = $i->异常标识 . $i->结果值 . $i->结果值单位; + $value = $i->结果值; $data_arr[] = [ 'value' => $value, 'datetime' => $datetime, ]; - $unit = $i['结果值单位']; + $unit = $i->结果值单位; $info['date'] = $datetime; $time = strtotime($datetime); } - $info['name'] = $i['基础项目名称']; - $info['table']['name'] = $i['基础项目名称']; + $info['name'] = $i->基础项目名称; + $info['table']['name'] = $i->基础项目名称; $info['table']['list'][] = [ 'date' => $datetime, - 'value' => $i['异常标识'] . $i['结果值'], + 'value' => $i->异常标识 . $i->结果值, 'assess' => $result, ]; } @@ -431,23 +431,23 @@ class ReportController extends Controller if ($date == '') $date = $datetime; $rc = 0; foreach ($reports as $item) { - $datetime=explode('T', $item['登记时间'])[0]; - $jc_item=DB::table('report_l2_items as a')->leftJoin(['report_l3_base_items as b','a.id','=','b.report_l2_id'])->where(['a.reprort_l1_id'=>$item->id])->get(); + $datetime=explode('T', $item->登记时间); + $jc_item=DB::table('report_l2_items as a')->leftJoin('report_l3_base_items as b','a.id','=','b.report_l2_id')->where(['a.reprort_l1_id'=>$item->id])->get(); foreach ($jc_item as $i) { - if ($i['基础项目代码'] == $mark) { + if ($i->基础项目代码 == $mark) { $result = '正常'; - if ($i['异常标识'] == '↑') $result = '偏高'; - if ($i['异常标识'] == '↓') $result = '偏低'; + if ($i->异常标识 == '↑') $result = '偏高'; + if ($i->异常标识 == '↓') $result = '偏低'; if ($datetime == $date) { $info['result'] = $result; - $info['value'] = $i['异常标识'] . $i['结果值'] . $i['结果值单位']; - $value = $i['结果值']; - $unit = $i['结果值单位']; + $info['value'] = $i->异常标识 . $i->结果值 . $i->结果值单位; + $value = $i->结果值; + $unit = $i->结果值单位; $info['date'] = $datetime; $rc++; } - $info['name'] = $i['基础项目名称']; - $info['table']['name'] = $i['基础项目名称']; + $info['name'] = $i->基础项目名称; + $info['table']['name'] = $i->基础项目名称; } } } diff --git a/Laravel/app/Http/Controllers/API/Web/ComboController.php b/Laravel/app/Http/Controllers/API/Web/ComboController.php index 2122ac9..d8d18bb 100644 --- a/Laravel/app/Http/Controllers/API/Web/ComboController.php +++ b/Laravel/app/Http/Controllers/API/Web/ComboController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers\API\Web; +use App\Http\Controllers\API\H5\PersonController; use App\Http\Controllers\Controller; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; @@ -94,4 +95,177 @@ select combo_id as c_id,count(*) as count from orders where status in(2,4) group 'hospital' => $hospital_info ]); } + //医生端网页打开页面获取购买详情内容(详情页信息) + public function BuyInfo() + { + $hospital_id = request('hospital'); + $combo_id = request('combo_id'); //购买的套餐id + $item_ids = request('item_ids'); //自选项目ids + $group_id = request('group_id'); //团检登记id + if (!isset($hospital_id)) return \Yz::echoError1("医院id不能为空"); + $hospital = DB::table('hospitals')->where(['id' => 1, 'status' => 1, 'is_del' => 0])->first(); + $combo_info = false;//套餐信息 + $pay_item_count = 0;//需自费项目个数 + $all_original_price = 0; + $true_price = 0; + if (isset($combo_id) and $combo_id != 0) { + // $combo=DB::table('combos')->where(['hospital_id'=>$hospital_id,'combo_id'=>$combo_id,'status'=>1])->first(); + $combo = DB::select("select a.*,b.*,c.name as crowd_name from combos as a LEFT JOIN ( +select combo_id as c_id,count(*) as sale_count from orders where status in(2,4) group by combo_id +) as b on a.combo_id=b.c_id left join combo_crowd as c on a.crowd_id=c.id where a.combo_id=? and a.status=1 ", [$combo_id]); + + if (!$combo) return \Yz::echoError1("套餐不存在"); + $combo = $combo[0]; + $combo_info['hospital_name'] = $hospital->name; + $combo_info['combo_name'] = $combo->name; + $combo_info['crowd_name'] = $combo->crowd_name; + $combo_info['img'] = $combo->cover; + $combo_info['sale_count'] = $combo->sale_count==null?0:$combo->sale_count; + $tags = json_decode($combo->tags, true); + $combo->tags2 = json_decode($combo->tags2, true); + foreach ($tags as $k => $tag) { + $tags[$k] = ['text' => $tag, + 'text_color' => '#47ABD8', + 'color' => '#EBF5FC' + ]; + } + $combo->tag = $tags; + $combo->tag[] = [ + 'text' => $combo->item_count . '个项目', + 'text_color' => '#34C292', + 'color' => '#E9F8F3', + ]; + $combo_info['tags'] = $combo->tag; + $combo_info['tags2'] = $combo->tags2; + $combo_info['price'] = $combo->price; + $combo_info['original_price'] = $combo->original_price; + $all_original_price += $combo_info['original_price']; + $combo_items = json_decode($combo->items, true); + $groupedData = []; + foreach ($combo_items as $item) { + $keshiName = $item['keshi_name']; + if (!isset($groupedData[$keshiName])) { + $groupedData[$keshiName] = []; + } + $groupedData[$keshiName][] = $item; + } + foreach ($groupedData as $keshiName => $children) { + $combo_info['items'][] = [ + 'keshi_name' => $keshiName, + 'children' => $children + ]; + } + $pay_item_count += $combo->item_count; + $true_price += $combo_info['price']; + } + $items_info = false;//自选项目信息 + if (isset($item_ids) and !empty($item_ids)) { + $price = 0; + $items_original_price = 0; + $items = DB::table('items')->whereIn('item_id', $item_ids)->where(['status' => 1])->get(); + $groupedData = []; + foreach ($items as $item) { + // $price=$price+$item->price; + $price = bcadd($price, $item->price, 2); + // $all_original_price+=$item->original_price; + $all_original_price = bcadd($all_original_price, $item->original_price, 2); + // $items_original_price+=$item->original_price; + $items_original_price = bcadd($items_original_price, $item->original_price, 2); + $keshiName = $item->keshi_name; + if (!isset($groupedData[$keshiName])) { + $groupedData[$keshiName] = []; + } + $groupedData[$keshiName][] = ['desc' => $item->jianjie, 'name' => $item->name,'price'=>$item->price]; + } + $items_info['price'] = $price; + $items_info['original_price'] = $items_original_price; + foreach ($groupedData as $keshiName => $children) { + $items_info['items'][] = [ + 'keshi_name' => $keshiName, + 'children' => $children + ]; + } + $pay_item_count += count($items); + $true_price += $items_info['price']; + } + //调用his接口查询用户积分和预存款,计算可以抵扣的金额 + $integral_money = 90;//积分抵扣金额 + $save_money = 150;//预存款抵扣金额 + $coupon_money = 50;//优惠券抵扣金额 + + //用户真实支付价格,应减去抵扣(二期实现) + + + $group_info = false; + $lose_price=0; + if (!!$group_id) { + $P = new PersonController(); + $data = [ + '电话号码' => null, + '证件号码' => null, + '预约Id' => $group_id + ]; + + $group_info = $P->group_info($hospital_id, $data); + if(count($group_info)==0) return \Yz::echoError1("获取团检登记信息失败"); + + //如果是团检,统收限额大于0,并且没有自带项目,则判断剩余金额 + if($group_info[0]['tongshou_xiane']>0 and count($group_info[0]['items'])==0){ + $lose_price=$group_info[0]['tongshou_xiane']- $true_price; + if($lose_price<0) $lose_price=0; + } + $true_price = $true_price + $group_info[0]['sixi_zong_ji_jin_e']; + $true_price = ($true_price - $group_info[0]['tongshou_xiane']) > 0 ? $true_price - $group_info[0]['tongshou_xiane'] : 0; + + $all_items = DB::table('items')->where(['status' => 1])->get(); + $item_new = []; + foreach ($group_info[0]['items'] as $item) { + $item['keshi_name'] = '其他'; + $item['desc'] = ''; + foreach ($all_items as $it) { + if ($it->item_id == $item['id']) { + $item['keshi_name'] = $it->keshi_name; + $item['desc'] = $it->jianjie; + break; + } + } + $item_new[] = $item; + } + $groupedData = []; + foreach ($item_new as $item) { + $keshiName = $item['keshi_name']; + if (!isset($groupedData[$keshiName])) { + $groupedData[$keshiName] = []; + + } + $groupedData[$keshiName][] = ['desc' => $item['desc'], 'name' => $item['name'], 'id' => $item['id'], 'keshi_name' => $item['keshi_name']]; + } + $group_info[0]['items'] = [];//清空原来的item + foreach ($groupedData as $keshiName => $children) { + $group_info[0]['items'][] = [ + 'keshi_name' => $keshiName, + 'children' => $children + ]; + } + + } + + $data = [ + 'group_info' => $group_info, + 'combo_info' => $combo_info, + 'items_info' => $items_info, + 'integral_money' => number_format($integral_money, 2, '.', ''), + 'save_money' =>number_format($save_money, 2, '.', ''), + 'coupon_money' => number_format($coupon_money, 2, '.', ''), + 'true_price' =>number_format($true_price, 2, '.', ''),//需要用户支付的金的 + 'original_price' =>number_format($all_original_price, 2, '.', '') ,//总原价 + 'pay_item_count' => $pay_item_count,//需要付费的项目数量 + 'lose_price'=>number_format($lose_price, 2, '.', ''),//剩余的不用就会浪费的金额 + 'nmr_list' => [[ + 'item_id' => "1", + "name" => "磁共振平扫(腰椎)" + ]]//核磁项目列表 + ]; + return \Yz::Return(true, "查询成功", $data); + } } diff --git a/Laravel/app/Http/Controllers/API/Web/OrderController.php b/Laravel/app/Http/Controllers/API/Web/OrderController.php new file mode 100644 index 0000000..ee3158f --- /dev/null +++ b/Laravel/app/Http/Controllers/API/Web/OrderController.php @@ -0,0 +1,203 @@ + [ + 'id' => 0, + 'name' => $title, + 'price' => 0, + ], + 'items' => [], + 'group' => [ + 'id' => '', + ], + ]; + //如果是套餐 + $checkup_type_id = false; //体检类型id + if (isset($combo_id) and $combo_id <> 0) { + $combo_info = DB::table('combos')->where(['combo_id' => $combo_id, 'status' => 1])->first(); + if (!$combo_info) return \Yz::echoError1("套餐不存在"); + if (!isset($combo_info->checkup_type_id)) return \Yz::echoError1("套餐未关联体检类型"); + $checkup_type_id = $combo_info->checkup_type_id; + $price += $combo_info->price; + $title = $combo_info->name; + $buy_info['combo'] = [ + 'id' => $combo_info->combo_id, + 'name' => $combo_info->name, + 'price' => $combo_info->price, + ]; + } + + //如果有自选项目 + $items_list = []; + if (count($item_ids) != 0) { + $items_list = DB::table('items')->whereIn('item_id', $item_ids)->where(['status' => 1])->get(); + $existingIds = []; + foreach ($items_list as $item) { + $price += $item->price; + $existingIds[] = $item->item_id; + $buy_info['items'][] = [ + 'id' => $item->item_id, + 'name' => $item->name, + 'price' => $item->price + ]; + } + $missingIds = array_diff($item_ids, $existingIds); + if (count($missingIds) > 0) return \Yz::echoError1("部分自选项目不可用,Id:" . implode(', ', $missingIds)); + } + $true_price = $price; + //如果是团检 + $group_info = false; + if ($type == 2) { + $P = new PersonController(); + $data = [ + '电话号码' => null, + '证件号码' => null, + '预约Id' => $group_id + ]; + $group_info = $P->group_info($hospital_id, $data); + $group_info = $group_info[0]; + $buy_info['group'] = [ + 'id' => $group_id, + 'combo_name' => $group_info['combo_name'], + 'combo_id' => $group_info['combo_id'], + 'group_name' => $group_info['group_name'], + 'items' => $group_info['items'], + 'group_id' => $group_info['group_id'], + ]; + $title = "单位团检" . $group_info['combo_name']; + $price = $price + $group_info['sixi_zong_ji_jin_e']; + $need_pay = ($price - $group_info['tongshou_xiane']) > 0 ? $price - $group_info['tongshou_xiane'] : 0; + //团检订单金额为减去统收后的金的 + $price = $need_pay; + $true_price = $need_pay; + } + + //调用思信接口判断各个项目是否可用 + $check_items = []; + foreach ($item_ids as $item_id) { + $check_items[] = ['Id' => $item_id]; + } + if ((isset($combo_id) and $combo_id <> 0) || count($check_items) != 0) { + $item_check = self::item_check($hospital_id, [ + '人员信息列表' => [[ + "序号" => 0, + "性别" => $person['sex'] == 1 ? '男' : '女', + "年龄" => floor((time() - strtotime($person['birthday'])) / 86400 / 360), + "婚姻状态" => $person['married']== 1 ? '已婚' : '未婚', + ]], + '套餐Id' => $combo_id == 0 ? null : $combo_id, + '可选项目信息' => $check_items, + ]); + if (count($item_check['data']) != 1) { + return \Yz::echoError1("体检系统提示:" . $item_check['message']); + } + } + + //检查号源是否可用 + $plan = new PlanController(); + $plan_check = $plan->CheckPlan($plan_id, $hospital_id, $type, $person['sex'], $price, $checkup_type_id); + if ($plan_check['status'] === false) return \Yz::echoError1($plan_check['msg']); + $plan = $plan_check['plan']; + + + //如果是团检 判断号源在 团检登记人的有效时间范围内 + $plan_datetime = $plan->date . ' ' . $plan->time; + if (!!$group_info) { + if (!($plan_datetime > $group_info['start_time'] . ' 00:00:00' and $plan_datetime < $group_info['end_time'] . ' 23:59:59')) { + return \Yz::echoError1("预约日期不在单位有效时间范围内,请重新选择"); + } + } + + + //构建订单号 + $order_num = $this->generateOrderNumber(); + $data = [ + 'title' => $title, + 'type' => $type, + 'web_user_id' =>0, + 'person_id' => 0, + 'name' => $person['name'], + 'id_number' => $person['id_number'], + 'buy_info' => json_encode($buy_info, JSON_UNESCAPED_UNICODE), + 'price' => $price, + 'true_price' => $true_price, + 'order_number' => $order_num, + 'status' => 1, + 'appointment_date' => $plan->date, + 'appointment_time' => $plan->time, + 'plan_id' => $plan->id, + 'plan_number' => $plan->plan_number, + 'combo_id' => $combo_id, + 'hospital_id' => $hospital_id, + 'doctor' => $doctor, + 'phone' => $person['phone'], + 'sex' => $person['sex'], + 'birthday' => $person['birthday'], + 'married' => $person['married'], + ]; + DB::beginTransaction(); + $insert = DB::table('orders')->insertGetId($data); + $up_plan = DB::table('plans')->where(['id' => $plan->id, 'status' => 1])->update([ + 'status' => 2 + ]); + if ($insert and $up_plan) { + DB::commit(); + $action=false; + if($true_price===0){ + //如果是免费的,直接去预约 + $yuyue= self::Finish($order_num); + if($yuyue['status']===true){ + return \Yz::return(true, "操作成功", ['action' => $action,'orderid'=>$insert]); + }else{ + return \Yz::echoError1($yuyue['msg']); + } + } + if($true_price>0){ + //如果大于0则提示前端去支付 + $action="pay"; + } + return \Yz::return(true, "操作成功", ['action' => $action,'orderid'=>$insert]); + } else { + DB::rollBack(); + return \Yz::echoError1('操作失败'); + } + } + +} diff --git a/Laravel/routes/web.php b/Laravel/routes/web.php index 10b6896..dcbdc8d 100644 --- a/Laravel/routes/web.php +++ b/Laravel/routes/web.php @@ -65,6 +65,7 @@ Route::group(['prefix' => 'api/H5'], function () { Route::post('/Refund', 'App\Http\Controllers\API\H5\PayController@Refund');//退款 Route::post('/GetOrderDetail', 'App\Http\Controllers\API\H5\OrderController@GetDetail');//获取订单详情 Route::post('/ReportContrast', 'App\Http\Controllers\API\H5\ReportController@contrast');//报告对比 + Route::post('/ReportAnalysis', 'App\Http\Controllers\API\H5\ReportController@Analysis');//报告趋势 Route::post('/AnalysisTypeGetList', 'App\Http\Controllers\API\H5\AnalysisTypeController@GetList');//趋势分析项目列表 @@ -78,6 +79,7 @@ Route::group(['prefix' => 'api/H5'], function () { Route::group(['prefix' => 'api/Web'], function () { Route::post('/ComboGetList', 'App\Http\Controllers\API\Web\ComboController@GetList');//Web套餐列表 + Route::post('/BuyInfo', 'App\Http\Controllers\API\Web\ComboController@BuyInfo');//Web购买详情 Route::post('/ItemGetList', 'App\Http\Controllers\API\Web\ItemController@GetList');//Web套餐列表 });