diff --git a/Laravel/app/Http/Controllers/API/Admin/YeWu/PlanController.php b/Laravel/app/Http/Controllers/API/Admin/YeWu/PlanController.php index 14ddfe9..525daf1 100644 --- a/Laravel/app/Http/Controllers/API/Admin/YeWu/PlanController.php +++ b/Laravel/app/Http/Controllers/API/Admin/YeWu/PlanController.php @@ -33,32 +33,33 @@ class PlanController extends Controller } $model = DB::table('plan_model as a')->where(['a.id' => $params['model_id'], 'a.is_del' => 0, 'a.status' => 1])->first(); if (!$model) return \Yz::echoError1('模板不可用'); - $planType = DB::table('plan_type as a')->where(['a.id' => $model->plan_type, 'a.is_del' => 0, 'a.status' => 1])->first(); - if (!$planType) return \Yz::echoError1('号源类型不可用'); +// $planType = DB::table('plan_type as a')->where(['a.id' => $model->plan_type, 'a.is_del' => 0, 'a.status' => 1])->first(); +// if (!$planType) return \Yz::echoError1('号源类型不可用'); //查询此时间段内是否有已经生成的号源 - $cha=DB::table('plans')->whereBetween('date',$Info['dateRange'])->get(); - if(count($cha)>0){ - return \Yz::return(false,'号源重复',['list'=>$cha]); + $cha = DB::table('plans')->whereBetween('date', $Info['dateRange'])->get(); + if (count($cha) > 0) { + return \Yz::return(false, '号源重复', ['list' => $cha]); } //获取模板的全部时间点 - $s=new TimeService(); - $timelist=$s->TimePointsArr($model->start_time,$model->end_time,$model->interval_time); - if(count($timelist)<1) return \Yz::echoError1('模板时间点不能为空'); +// $s=new TimeService(); +// $timelist=$s->TimePointsArr($model->start_time,$model->end_time,$model->interval_time); + $timelist = DB::table('plan_model_time')->where(['model_id' => $params['model_id']])->get(); + if (count($timelist) < 1) return \Yz::echoError1('模板时间点不能为空'); $startDate = new DateTime($Info['dateRange'][0]); $endDate = new DateTime($Info['dateRange'][1]); $currentDate = $startDate; - $success_count=0; + $success_count = 0; while ($currentDate <= $endDate) { //循环生成 - $date_ymd=$currentDate->format('Y-m-d'); + $date_ymd = $currentDate->format('Y-m-d'); //判断节假日是否生成 - $s_day=DB::table('plan_holiday')->select('*','type as tp')->where(['date'=>$date_ymd])->first(); - if(!!$s_day){ - if($s_day->tp==1 and $params['workday_create']===0){ + $s_day = DB::table('plan_holiday')->select('*', 'type as tp')->where(['date' => $date_ymd])->first(); + if (!!$s_day) { + if ($s_day->tp == 1 and $params['workday_create'] === 0) { $currentDate->modify('+1 day'); continue; } - if($s_day->tp==2 and $params['holiday_create']===0){ + if ($s_day->tp == 2 and $params['holiday_create'] === 0) { $currentDate->modify('+1 day'); continue; } @@ -67,95 +68,145 @@ class PlanController extends Controller //获取星期几 星期1=1 星期日=7 $dayOfWeek = $currentDate->format('N'); //如果星期匹配上了 - if(in_array($dayOfWeek, $params['week'])) { - foreach ($timelist as $key=>$time){ - $type=1; //正常 - if(in_array($key,json_decode($model->y_number,true))){ - $type=0;//预留 - } - $data=[ - 'model_id'=>$model->id, - 'date'=>$date_ymd, - 'week'=>$dayOfWeek, - 'time'=>$time, - 'type'=>$type, - 'plan_number'=>implode('', explode(':', $time)), - 'is_vip'=>$planType->is_vip, - 'use_type'=>$planType->use_type, - 'sex'=>$planType->sex, - 'checkup_type_id'=>$planType->checkup_type_id, - 'amount_limit1'=>$planType->amount_limit1, - 'amount_limit2'=>$planType->amount_limit2, - 'hospital_id'=>$model->hospital_id, - 'status'=>1, - 'is_del'=>0 + if (in_array($dayOfWeek, $params['week'])) { + foreach ($timelist as $key => $time) { + $planType=null; + if(isset( $time->plan_type_id)){ + $planType = DB::table('plan_type as a')->where(['a.id' => $time->plan_type_id, 'a.is_del' => 0, 'a.status' => 1])->first(); + if (!$planType) return \Yz::echoError1('号源类型不可用'); + } - ]; - $i=DB::table('plans')->insert($data); - if($i){ - $success_count++; - } - } + $data = [ + 'model_id' => $model->id, + 'date' => $date_ymd, + 'week' => $dayOfWeek, + 'time' => $time->time, + 'type' => $time->type, + 'plan_number' => implode('', explode(':', $time->time)), + 'is_vip' => empty($planType)?null: $planType->is_vip, + 'use_type' => empty($planType)?null:$planType->use_type, + 'sex' => empty($planType)?null:$planType->sex, + 'checkup_type_id' => empty($planType)?null:$planType->checkup_type_id, + 'amount_limit1' =>empty($planType)?null: $planType->amount_limit1, + 'amount_limit2' =>empty($planType)?null: $planType->amount_limit2, + 'hospital_id' => $model->hospital_id, + 'status' => 1, + 'is_del' => 0 + + ]; + $i = DB::table('plans')->insert($data); + if ($i) { + $success_count++; + } + } } // 日期加一天 $currentDate->modify('+1 day'); } - if($success_count>0){ - return \Yz::Return(true,'',['success_count'=>$success_count]); - }else{ - return \Yz::echoError1('没有计划被创建'); - } + if ($success_count > 0) { + return \Yz::Return(true, '', ['success_count' => $success_count]); + } else { + return \Yz::echoError1('没有计划被创建'); + } } + public function GetList() { - $page =request('page'); - $pageSize =request('pageSize'); - $searchInfo=request('searchInfo'); - $list=DB::table('plans as a') - // ->leftJoin('plan_type as b','a.plan_type','=','b.id') - // ->select('a.*','b.name as plan_type_name') - ->where(['a.is_del'=>0]); - if(!isset($searchInfo['date'])){ - $searchInfo['date']=date('Y-m-d'); + $page = request('page'); + $pageSize = request('pageSize'); + $searchInfo = request('searchInfo'); + $list = DB::table('plans as a') + // ->leftJoin('plan_type as b','a.plan_type','=','b.id') + // ->select('a.*','b.name as plan_type_name') + ->where(['a.is_del' => 0]); + if (!isset($searchInfo['date'])) { + $searchInfo['date'] = date('Y-m-d'); } - $list=$list->where(['a.date'=>$searchInfo['date']]); - $count=$list->count(); - $list=$list ->orderBy('a.id', 'asc')->get(); - return \Yz::Return(true,'查询完成',['list'=>$list,'count'=>$count,'date'=> $searchInfo['date']]); + $list = $list->where(['a.date' => $searchInfo['date']]); + $count = $list->count(); + $list = $list->orderBy('a.id', 'asc')->get(); + return \Yz::Return(true, '查询完成', ['list' => $list, 'count' => $count, 'date' => $searchInfo['date']]); } + public function GetDetail() { - $id =request('id'); - $info=DB::table('plans')->where(['id'=>$id])->first(); - if(!!$info){ - $info->checkup_type_id=json_decode($info->checkup_type_id,true); - return \Yz::Return(true,'查询完成',['info'=>$info]); - }else{ + $id = request('id'); + $info = DB::table('plans')->where(['id' => $id])->first(); + if (!!$info) { + if(empty($info->checkup_type_id)){ + $info->checkup_type_id='[]'; + } + $info->checkup_type_id = json_decode($info->checkup_type_id, true); + return \Yz::Return(true, '查询完成', ['info' => $info]); + } else { return \Yz::echoError1('查询失败'); } } + //更新保存 public function Save() { - $info =request('info'); - if(isset($info['id'])){ - $info['checkup_type_id']= isset($Info['checkup_type_id']) ? json_encode($Info['checkup_type_id']) : null; - $u=DB::table('plans')->where(['id'=>$info['id']])->update([ + $info = request('info'); + if (isset($info['id'])) { + $info['checkup_type_id'] = isset($info['checkup_type_id']) ? json_encode($info['checkup_type_id']) : null; + + $u = DB::table('plans')->where(['id' => $info['id']])->update([ + 'is_vip' => $info['is_vip'], + 'use_type' => $info['use_type'], + 'sex' => $info['sex'], + 'checkup_type_id' => $info['checkup_type_id'], + 'amount_limit1' => $info['amount_limit1'], + 'amount_limit2' => $info['amount_limit2'], + 'status' => $info['status'], + ]); + if ($u) { + return \Yz::Return(true, '保存成功', []); + } else { + return \Yz::echoError1('操作失败'); + } + } + } + //批量更新号源类型 + public function BatchUpdatePlanType(){ + $ids = request('ids'); + $type = request('type'); + $info = request('info'); + + $cha =DB::table('plans')->whereIn('id', $ids)->where(['status'=>2])->get(); + if(count($cha) >0){ + return \Yz::echoError1('有号源被占用,不能执行此操作'); + } + if($type==0){ + $data=[ + 'is_vip'=>null, + 'use_type'=>null, + 'sex'=>null, + 'checkup_type_id'=>[], + 'amount_limit1'=>null, + 'amount_limit2'=>null, + 'type'=>0, + ]; + } + if($type==1){ + if(empty($info['checkup_type_id'])) return \Yz::echoError1('体检类型不能为空'); + $data=[ 'is_vip'=>$info['is_vip'], 'use_type'=>$info['use_type'], 'sex'=>$info['sex'], 'checkup_type_id'=>$info['checkup_type_id'], - 'amount_limit1'=>$info['amount_limit1'], - 'amount_limit2'=>$info['amount_limit2'], - 'status'=>$info['status'], - ]); - if($u){ - return \Yz::Return(true,'保存成功',[]); - }else{ - return \Yz::echoError1('操作失败'); - } + 'amount_limit1'=>isset($info['amount_limit1'])?$info['amount_limit1']:0, + 'amount_limit2'=>isset($info['amount_limit2'])?$info['amount_limit2']:0, + 'type'=>1, + ]; } + $u=DB::table('plans')->whereIn('id', $ids)->update($data); + if ($u){ + return \Yz::Return(true, '操作成功', []); + }else{ + return \Yz::echoError1('操作失败'); + } + } } diff --git a/Laravel/app/Http/Controllers/API/Admin/YeWu/PlanModelController.php b/Laravel/app/Http/Controllers/API/Admin/YeWu/PlanModelController.php index 8749b93..93e604a 100644 --- a/Laravel/app/Http/Controllers/API/Admin/YeWu/PlanModelController.php +++ b/Laravel/app/Http/Controllers/API/Admin/YeWu/PlanModelController.php @@ -46,6 +46,8 @@ class PlanModelController extends Controller public function Save() { $Info =request('Info'); + $Timelist =request('Timelist'); + $params = [ 'hospital_id' => isset($Info['hospital_id']) ? $Info['hospital_id'] :null, 'name' => isset($Info['name']) ? $Info['name'] : null, @@ -55,7 +57,7 @@ class PlanModelController extends Controller 'count' => isset($Info['count']) ? $Info['count'] : 0, 'status'=>isset($Info['status']) ? $Info['status'] : 0, ]; - $requiredFields = ['hospital_id'=>'医院','name'=>'名称','interval_time'=>'时间间隔','plan_type'=>'号源类型']; + $requiredFields = ['hospital_id'=>'医院','name'=>'名称','interval_time'=>'时间间隔']; // 判断是否为空 foreach ($requiredFields as $key=> $field) { if (!isset($params[$key]) || $params[$key] === null) { @@ -69,15 +71,34 @@ class PlanModelController extends Controller $params['end_time']=$Info['TimeRange'][1]; $do=false; $table=DB::table('plan_model'); + $table_model_time=DB::table('plan_model_time'); + DB::beginTransaction(); if($Info['id']==0){ - $do=$table->insert($params); + $model_id=$table->insertGetId($params); } if($Info['id']>0){ - $do=$table->where(['id'=>$Info['id']])->update($params); + $model_id=$Info['id']; + $table->where(['id'=>$Info['id']])->update($params); + } + $model_time_data=[]; + foreach ($Timelist as $key=>$value){ + $model_time_data[]=[ + 'type'=>isset($value['plan_type_id']) ? 1 : 0, + 'model_id'=>$model_id, + 'time'=>$value['time'], + 'type_color'=>isset($value['type_color']) ? $value['type_color'] : null, + 'plan_type_id'=>isset($value['plan_type_id']) ? $value['plan_type_id'] : null, + ]; + } + if(count($model_time_data)>0){ + DB::table('plan_model_time')->where(['model_id'=>$model_id])->delete(); + $do=$table_model_time->insert($model_time_data); } if($do){ + DB::commit(); return \Yz::Return(true,'操作成功',[]); }else{ + DB::rollBack(); return \Yz::echoError1('操作失败'); } @@ -89,6 +110,8 @@ class PlanModelController extends Controller if(!!$info){ $info->TimeRange=[$info->start_time,$info->end_time]; $info->y_number=json_decode($info->y_number,true); + $list=DB::table('plan_model_time as a')->where(['model_id'=>$id])->get(); + $info->list=$list; return \Yz::Return(true,'查询完成',$info); }else{ return \Yz::echoError1('查询失败'); diff --git a/Laravel/app/Http/Controllers/API/Admin/YeWu/PlanTypeController.php b/Laravel/app/Http/Controllers/API/Admin/YeWu/PlanTypeController.php index 85c45ca..72cfb11 100644 --- a/Laravel/app/Http/Controllers/API/Admin/YeWu/PlanTypeController.php +++ b/Laravel/app/Http/Controllers/API/Admin/YeWu/PlanTypeController.php @@ -20,8 +20,9 @@ class PlanTypeController extends Controller 'amount_limit1' => isset($Info['amount_limit1']) ? $Info['amount_limit1'] : 0, 'amount_limit2' => isset($Info['amount_limit2']) ? $Info['amount_limit2'] : 0, 'status'=>isset($Info['status']) ? $Info['status'] : 0, + 'color'=>isset($Info['color']) ? $Info['color'] : null, ]; - $requiredFields = ['name'=>'名称','is_vip'=>'vip类型','use_type'=>'个检/团检类型','checkup_type_id'=>'体检类型','status'=>'状态']; + $requiredFields = ['name'=>'名称','is_vip'=>'vip类型','use_type'=>'个检/团检类型','checkup_type_id'=>'体检类型','status'=>'状态','color'=>'颜色']; // 判断是否为空 foreach ($requiredFields as $key=> $field) { if (!isset($params[$key]) || $params[$key] === null) { diff --git a/Laravel/app/Http/Controllers/API/H5/OrderController.php b/Laravel/app/Http/Controllers/API/H5/OrderController.php index c4342c7..8ddbb81 100644 --- a/Laravel/app/Http/Controllers/API/H5/OrderController.php +++ b/Laravel/app/Http/Controllers/API/H5/OrderController.php @@ -7,6 +7,7 @@ use App\Http\Controllers\Controller; use App\Http\Controllers\API\PEISApiController; use App\Lib\Tools; use App\Services\ConfigService; +use App\Services\OrderService; use DateTime; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; @@ -19,17 +20,17 @@ class OrderController extends Controller $openid = $request->post('openid'); $user = DB::table('web_users')->where(['openid' => $openid, 'is_del' => 0])->first(); if (!$user) return \Yz::echoError1("openid对应用户不存在"); - $persons_sfz=DB::table('web_user_person')->where(['user_id' => $user->id,'is_del'=>0])->pluck('id_number')->toArray(); + $persons_sfz = DB::table('web_user_person')->where(['user_id' => $user->id, 'is_del' => 0])->pluck('id_number')->toArray(); $OrderList = DB::table('orders') ->select('id', 'title', 'status', 'name', 'appointment_time as time', 'order_number as order', DB::raw("CASE WHEN type = 1 THEN '个检' WHEN type = 2 THEN '团检' ELSE 'unknown' END as type"), 'price', 'true_price', 'pay_time', 'refund_time', 'created_at') ->where(['web_user_id' => $user->id]) - ->orWhere(function($query) use ($persons_sfz) { + ->orWhere(function ($query) use ($persons_sfz) { $query->WhereIn('id_number', $persons_sfz) ->where('person_id', 0); - })->orderBy('id','desc')->get(); + })->orderBy('id', 'desc')->get(); $WaitingPaymentTime = config('app.globals.WaitingPaymentTime');//支付等待時間 foreach ($OrderList as $key => $list) { if ($list->status == 1) { @@ -51,9 +52,9 @@ class OrderController extends Controller { $id = request('id'); $order_info = DB::table('orders')->where(['id' => $id])->first(); - if(!!$order_info){ - $order_info->buy_info=json_decode($order_info->buy_info,true); - }else{ + if (!!$order_info) { + $order_info->buy_info = json_decode($order_info->buy_info, true); + } else { return \Yz::echoError1('未找到有效订单'); } return \Yz::Return(true, '获取成功', [ @@ -72,8 +73,8 @@ class OrderController extends Controller $group_id = request('group_id');//团检id $item_ids = request('item_ids');//自选item的ids - if (count($item_ids) != 0 and $item_ids[0]=="") { - $item_ids=[]; + if (count($item_ids) != 0 and $item_ids[0] == "") { + $item_ids = []; } $duo_xuan_yi = request('duo_xuan_yi'); //多选1 @@ -81,12 +82,12 @@ class OrderController extends Controller $plan_nmr_id = request('plan_nmr_id');//核磁号源id $doctor = request('doctor');//预约的医生名字 - $jifen = request('jifen',0); //使用的积分数量 - $yucunkuan = request('yucunkuan',0);//使用的预存款数量 + $jifen = request('jifen', 0); //使用的积分数量 + $yucunkuan = request('yucunkuan', 0);//使用的预存款数量 - $wj_flag= request('wj'); //问卷标记 - if(isset($wj_flag) and $wj_flag==1){ - $wj_zhekou=config('app.globals.Wj_ZheKou');//问卷过来的折扣率 + $wj_flag = request('wj'); //问卷标记 + if (isset($wj_flag) and $wj_flag == 1) { + $wj_zhekou = config('app.globals.Wj_ZheKou');//问卷过来的折扣率 } if (!isset($hospital_id)) return \Yz::echoError1('医院id不能为空'); @@ -117,11 +118,11 @@ class OrderController extends Controller 'group' => [ 'id' => '', ], - 'nmr_list'=>[] + 'nmr_list' => [] ]; //如果是套餐 - $Nx1_arrInfo=[]; - $TJ_Leixing_id=1;//存储用体检类型 + $Nx1_arrInfo = []; + $TJ_Leixing_id = 1;//存储用体检类型 $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(); @@ -130,23 +131,23 @@ class OrderController extends Controller $checkup_type_id = $combo_info->checkup_type_id; //构建多选一数据 - if(isset($duo_xuan_yi) and !empty($duo_xuan_yi)){ - $combo_Nx1=json_decode($combo_info->duo_xuan_yi,true); - foreach ($duo_xuan_yi as $r_k=>$r_v){ - foreach ($combo_Nx1 as $k=> $n1v){ - if($r_v['zu_name'] == $n1v['组名称']){ - foreach ($n1v['包含项目'] as $k2 => $v2){ - if($v2['Id'] == $r_v['item_id']){ - if($v2['科室名称']=='影像科'){ - $buy_info['nmr_list'][]=[ + if (isset($duo_xuan_yi) and !empty($duo_xuan_yi)) { + $combo_Nx1 = json_decode($combo_info->duo_xuan_yi, true); + foreach ($duo_xuan_yi as $r_k => $r_v) { + foreach ($combo_Nx1 as $k => $n1v) { + if ($r_v['zu_name'] == $n1v['组名称']) { + foreach ($n1v['包含项目'] as $k2 => $v2) { + if ($v2['Id'] == $r_v['item_id']) { + if ($v2['科室名称'] == '影像科') { + $buy_info['nmr_list'][] = [ 'item_id' => $v2['Id'], 'name' => $v2['名称'], ]; } $Nx1_arrInfo[] = [ 'id' => $v2['Id'], - 'name' => $v2['名称'], - 'price' =>0 + 'name' => $v2['名称'], + 'price' => 0 ]; } } @@ -155,7 +156,7 @@ class OrderController extends Controller } } - $TJ_Leixing_id=$checkup_type_id; + $TJ_Leixing_id = $checkup_type_id; $price += $combo_info->price; $title = $combo_info->name; $buy_info['combo'] = [ @@ -164,10 +165,10 @@ class OrderController extends Controller 'price' => $combo_info->price, ]; //如果有影像科,则存储在nmr_list字段 - $comboItem=DB::table('combo_items')->where(['combo_id' => $combo_id, 'status' => 1,'keshi_name'=>'影像科'])->get(); - if(count($comboItem)>0){ - foreach ($comboItem as $item){ - $buy_info['nmr_list'][]=[ + $comboItem = DB::table('combo_items')->where(['combo_id' => $combo_id, 'status' => 1, 'keshi_name' => '影像科'])->get(); + if (count($comboItem) > 0) { + foreach ($comboItem as $item) { + $buy_info['nmr_list'][] = [ 'item_id' => $item->item_id, 'name' => $item->name, ]; @@ -177,12 +178,12 @@ class OrderController extends Controller //如果有自选项目 $items_list = []; - if (count($item_ids) != 0 ) { + if (count($item_ids) != 0) { $items_list = DB::table('items')->whereIn('item_id', $item_ids)->where(['status' => 1])->get(); $existingIds = []; - $item_price=0; + $item_price = 0; foreach ($items_list as $item) { - $item_price+=$item->price; + $item_price += $item->price; $existingIds[] = $item->item_id; $buy_info['items'][] = [ 'id' => $item->item_id, @@ -190,23 +191,23 @@ class OrderController extends Controller 'price' => $item->price ]; //如果有影像科,则存储在nmr_list字段 - if($item->keshi_name=='影像科'){ - $buy_info['nmr_list'][]=[ + if ($item->keshi_name == '影像科') { + $buy_info['nmr_list'][] = [ 'item_id' => $item->item_id, 'name' => $item->name, ]; } } - if(isset($wj_flag) and $wj_flag==1){ - $item_price=$item_price*$wj_zhekou; + if (isset($wj_flag) and $wj_flag == 1) { + $item_price = $item_price * $wj_zhekou; } $price += $item_price; $missingIds = array_diff($item_ids, $existingIds); if (count($missingIds) > 0) return \Yz::echoError1("部分自选项目不可用,Id:" . implode(', ', $missingIds)); } //如果有 多选一项目 - if(!empty($Nx1_arrInfo)){ - $buy_info['items']=array_merge($buy_info['items'],$Nx1_arrInfo); + if (!empty($Nx1_arrInfo)) { + $buy_info['items'] = array_merge($buy_info['items'], $Nx1_arrInfo); } $true_price = $price; @@ -229,7 +230,7 @@ class OrderController extends Controller 'items' => $group_info['items'], 'group_id' => $group_info['group_id'], ]; - $TJ_Leixing_id=$group_info['checkup_type_id']; + $TJ_Leixing_id = $group_info['checkup_type_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; @@ -239,11 +240,11 @@ class OrderController extends Controller //如果有影像科,则存储在nmr_list字段 - $all_items = DB::table('items')->where(['status' => 1,'keshi_name'=>'影像科'])->get(); + $all_items = DB::table('items')->where(['status' => 1, 'keshi_name' => '影像科'])->get(); foreach ($group_info['items'] as $item) { foreach ($all_items as $it) { if ($it->item_id == $item['id']) { - $buy_info['nmr_list'][]=[ + $buy_info['nmr_list'][] = [ 'item_id' => $item->item_id, 'name' => $item->name, ]; @@ -317,39 +318,39 @@ class OrderController extends Controller } //校验积分和预存款 - $env=config('app.globals.Env'); - $AspNet=new AspNetZhuanController(); - if($env=='pro') { //如果是正式环境, 测试环境不抵扣 - if($jifen>0) { - $all_jifen= $AspNet::GetJiFen_YuCunKuan(1,$person->ghzid); - if($jifen>$all_jifen) return \Yz::echoError1("用户剩余积分不足"); + $env = config('app.globals.Env'); + $AspNet = new AspNetZhuanController(); + if ($env == 'pro') { //如果是正式环境, 测试环境不抵扣 + if ($jifen > 0) { + $all_jifen = $AspNet::GetJiFen_YuCunKuan(1, $person->ghzid); + if ($jifen > $all_jifen) return \Yz::echoError1("用户剩余积分不足"); } - if($yucunkuan>0) { - // return \Yz::echoError1("暂不支持预存款"); - $all_yucunkuan= $AspNet::GetJiFen_YuCunKuan(2,$person->ghzid); - if($yucunkuan>$all_yucunkuan) return \Yz::echoError1("用户剩余预存款不足"); + if ($yucunkuan > 0) { + // return \Yz::echoError1("暂不支持预存款"); + $all_yucunkuan = $AspNet::GetJiFen_YuCunKuan(2, $person->ghzid); + if ($yucunkuan > $all_yucunkuan) return \Yz::echoError1("用户剩余预存款不足"); } - $true_price=$true_price-($jifen+$yucunkuan); - if($true_price<-1) return \Yz::echoError1("预抵扣金额超过订单金额,操作失败"); - if($true_price<0) $true_price=0; + $true_price = $true_price - ($jifen + $yucunkuan); + if ($true_price < -1) return \Yz::echoError1("预抵扣金额超过订单金额,操作失败"); + if ($true_price < 0) $true_price = 0; } - $now_datetime=date('Y-m-d H:i:s'); + $now_datetime = date('Y-m-d H:i:s'); //构建订单号 $order_num = $this->generateOrderNumber(); $data = [ 'title' => $title, 'type' => $type, 'web_user_id' => $user->id, - 'checkup_type_id'=>$TJ_Leixing_id, + 'checkup_type_id' => $TJ_Leixing_id, 'person_id' => $person->id, 'name' => $person->name, 'id_number' => $person->id_number, 'buy_info' => json_encode($buy_info, JSON_UNESCAPED_UNICODE), 'price' => $price, - 'true_price' =>number_format($true_price, 2, '.', ''), - 'jifen'=>$jifen, - 'yucunkuan'=>$yucunkuan, + 'true_price' => number_format($true_price, 2, '.', ''), + 'jifen' => $jifen, + 'yucunkuan' => $yucunkuan, 'order_number' => $order_num, 'status' => 1, 'appointment_date' => $plan->date, @@ -363,8 +364,8 @@ class OrderController extends Controller 'sex' => $person->sex, 'birthday' => $person->birthday, 'married' => $person->married, - 'wj_flag'=>$wj_flag, - 'created_at' =>$now_datetime, + 'wj_flag' => $wj_flag, + 'created_at' => $now_datetime, ]; DB::beginTransaction(); $insert = DB::table('orders')->insertGetId($data); @@ -372,23 +373,23 @@ class OrderController extends Controller 'status' => 2 ]); //更新问卷log表 - DB::table('questionnaires_logs')->where(['person_id'=>$person->id,'order_id'=>0])->update([ + DB::table('questionnaires_logs')->where(['person_id' => $person->id, 'order_id' => 0])->update([ 'order_id' => $insert, ]); //调用接口扣除积分和预存款 - $jifen_dikou_status=true; - $yucunkuan_dikou_status=true; - $yyid=$hospital_id; - if($yyid==1) $yyid=6; - if($env=='pro') { //如果是正式环境 - if($jifen>0) { - $jifen_dikou_status=false; - $jifen_dikou_status= $AspNet::UseJiFen($person->ghzid,-$jifen,$yyid,$insert,'tj_h5','抵扣体检H5订单',$now_datetime); + $jifen_dikou_status = true; + $yucunkuan_dikou_status = true; + $yyid = $hospital_id; + if ($yyid == 1) $yyid = 6; + if ($env == 'pro') { //如果是正式环境 + if ($jifen > 0) { + $jifen_dikou_status = false; + $jifen_dikou_status = $AspNet::UseJiFen($person->ghzid, -$jifen, $yyid, $insert, 'tj_h5', '抵扣体检H5订单', $now_datetime); } - if($yucunkuan>0) { - $yucunkuan_dikou_status=false; - $yucunkuan_dikou_status= $AspNet::UseYuCunKuan($person->ghzid,-$yucunkuan,$yyid,0,$insert,'tj_h5','抵扣体检H5订单',$now_datetime); + if ($yucunkuan > 0) { + $yucunkuan_dikou_status = false; + $yucunkuan_dikou_status = $AspNet::UseYuCunKuan($person->ghzid, -$yucunkuan, $yyid, 0, $insert, 'tj_h5', '抵扣体检H5订单', $now_datetime); } } @@ -422,36 +423,36 @@ class OrderController extends Controller $plan_id = request('planid'); $nmr_plan_id = request('nmrPlanid'); $doctor = request('doctor'); - $orderInfo=DB::table('orders')->where(['id' => $orderid,'status'=>2])->first(); - if(!$orderInfo) return \Yz::echoError1("未找到有效订单"); - $planInfo = DB::table('plans')->where(['id' => $plan_id,'status'=>1])->first(); - if(!$planInfo) return \Yz::echoError1("所选体检日期号源无效"); + $orderInfo = DB::table('orders')->where(['id' => $orderid, 'status' => 2])->first(); + if (!$orderInfo) return \Yz::echoError1("未找到有效订单"); + $planInfo = DB::table('plans')->where(['id' => $plan_id, 'status' => 1])->first(); + if (!$planInfo) return \Yz::echoError1("所选体检日期号源无效"); //判断核磁号源有效性能,日期范围是否正常,判断核磁新日期时间是否和旧的日期时间一样 //判断体检日期是否在核磁3天左右 //判断体检日期时间是否和旧的日期时间一样。一样则跳过,不一样则更新 - if(isset($plan_id) && $plan_id<>$orderInfo->plan_id){ + if (isset($plan_id) && $plan_id <> $orderInfo->plan_id) { $peis = new PEISApiController(); - $data="appointmentId=".$orderInfo->appointment_number."&appGroupId=66&appPlanId=".$plan_id."&appPlanNumber=".$planInfo->plan_number."&date=".urlencode($planInfo->date.' '.$planInfo->time); - $ch = $peis::Post2('修改用户预约时间', $peis::Api('修改用户预约时间',$data),$orderInfo->hospital_id,[]); - if($ch=='修改预约时刻保存成功'){ + $data = "appointmentId=" . $orderInfo->appointment_number . "&appGroupId=66&appPlanId=" . $plan_id . "&appPlanNumber=" . $planInfo->plan_number . "&date=" . urlencode($planInfo->date . ' ' . $planInfo->time); + $ch = $peis::Post2('修改用户预约时间', $peis::Api('修改用户预约时间', $data), $orderInfo->hospital_id, []); + if ($ch == '修改预约时刻保存成功') { //恢复旧的plans DB::table('plans')->where(['id' => $orderInfo->plan_id])->update( - ['status'=>1] + ['status' => 1] ); //使用新的plans DB::table('plans')->where(['id' => $plan_id])->update( - ['status'=>2] + ['status' => 2] ); //更新订单 DB::table('orders')->where(['id' => $orderInfo->id])->update([ - 'plan_id'=>$plan_id, - 'plan_number'=>$planInfo->plan_number, - 'appointment_date'=>$planInfo->date, - 'appointment_time'=>$planInfo->time, - 'doctor'=>isset($doctor)?$doctor:null, + 'plan_id' => $plan_id, + 'plan_number' => $planInfo->plan_number, + 'appointment_date' => $planInfo->date, + 'appointment_time' => $planInfo->time, + 'doctor' => isset($doctor) ? $doctor : null, ]); } - return \Yz::Return(true,"操作完成",[]); + return \Yz::Return(true, "操作完成", []); } return \Yz::echoError1("未更改内容,无需进行此操作"); } @@ -528,25 +529,25 @@ class OrderController extends Controller "已收费" => true, ]; - $cad2=[ + $cad2 = [ "可选项目信息" => $item_arr, "总计金额" => $order_info->price, ]; - if($order_info->wj_flag == 1){ - $temp=[]; + if ($order_info->wj_flag == 1) { + $temp = []; foreach ($item_arr as $k => $item) { - $temp[]=[ - "Id"=> $item['Id'], - "已收费"=>$item['已收费'], - "优惠方式"=>"打折", - "优惠值"=> config('app.globals.Wj_ZheKou') + $temp[] = [ + "Id" => $item['Id'], + "已收费" => $item['已收费'], + "优惠方式" => "打折", + "优惠值" => config('app.globals.Wj_ZheKou') ]; } - $cad2=[ + $cad2 = [ "可选项目信息" => $temp, ]; } - $cad=array_merge($cad,$cad2); + $cad = array_merge($cad, $cad2); } else { $cad = [ 'type' => 2, @@ -582,24 +583,48 @@ class OrderController extends Controller $peis = new PEISApiController(); $dat = [ "预约Id" => $create_appointment['data'][0][0], - "预约开始时间" => $order_info->appointment_date . ' ' . $order_info->appointment_time, - "预约截止时间" => $order_info->appointment_date . ' ' . $order_info->appointment_time, - "AppDoctor" => $order_info->appdoctor + "预约开始时间" => $order_info->appointment_date . ' ' . $order_info->appointment_time, + "预约截止时间" => $order_info->appointment_date . ' ' . $order_info->appointment_time, + "AppDoctor" => $order_info->appdoctor ]; - $info = $peis::Post('预约时段修改', $order_info->hospital_id,$dat); + $info = $peis::Post('预约时段修改', $order_info->hospital_id, $dat); } - $u=DB::table('orders')->where(['order_number' => $order_number])->update([ + $u = DB::table('orders')->where(['order_number' => $order_number])->update([ 'appointment_number' => $create_appointment['data'][0][0], 'appointment_back_info' => json_encode($appointment_info['data'][0], JSON_UNESCAPED_UNICODE) ]); - $is_sendMsg=DB::table('configs')->where(['label' => '预约完成短信通知'])->first(); - if(!!$is_sendMsg and $is_sendMsg->value==1){ - $asp=new AspNetZhuanController(); - $asp::SendMsg($cha->hospital_id,$cha->phone,$cha->name,$cha->appointment_date.' '.substr($cha->appointment_time, 0, 5)); + $is_sendMsg = DB::table('configs')->where(['label' => '预约完成短信通知'])->first(); + if (!!$is_sendMsg and $is_sendMsg->value == 1) { + $asp = new AspNetZhuanController(); + $asp::SendMsg($cha->hospital_id, $cha->phone, $cha->name, $cha->appointment_date . ' ' . substr($cha->appointment_time, 0, 5)); } return ['status' => true, 'msg' => "完成"]; } + //未支付取消订单 + public function Cancel() + { + + } + + //批量取消订单 + public function BatchCancel() + { + $WaitingPaymentTime = config('app.globals.WaitingPaymentTime');//支付等待時間 + $orderInfos = DB::table('orders')->where(['status' => 1])->get(); + foreach ($orderInfos as $k => $orderInfo) { + $person=DB::table('web_user_person')->where(['id' => $orderInfo->person_id])->first(); + $datetime = new DateTime($orderInfo->created_at); + $timestamp = $datetime->getTimestamp(); + $orderInfo->end_time = $timestamp + (60 * $WaitingPaymentTime); + if (time() > $orderInfo->end_time) { + $do=new OrderService(); + $do->Cancel($orderInfo); + } + } + return \Yz::Return(true, "批量处理完成", []); + } + public function create_appointment($hospital, $data) { $peis = new PEISApiController(); diff --git a/Laravel/app/Http/Controllers/API/H5/PayController.php b/Laravel/app/Http/Controllers/API/H5/PayController.php index 43aa931..345a5ff 100644 --- a/Laravel/app/Http/Controllers/API/H5/PayController.php +++ b/Laravel/app/Http/Controllers/API/H5/PayController.php @@ -144,13 +144,19 @@ class PayController extends Controller $yyid=$orderInfo->hospital_id; if($yyid==1) $yyid=6; if($env=='pro') { //如果是正式环境 - if($orderInfo->jifen>0) { + if($orderInfo->jifen>0 and $orderInfo->is_refund_jifen==0) { $jifen_huifu_status=false; $jifen_huifu_status= $AspNet::UseJiFen($person->ghzid,$orderInfo->jifen,$yyid,$orderInfo->id,'tj_h5','抵扣体检H5订单',$now_datetime); + if( $jifen_huifu_status===true){ + DB::table('orders')->where('id',$orderInfo->id)->update(['is_refund_jifen'=>1]); + } } - if($orderInfo->yucunkuan>0) { + if($orderInfo->yucunkuan>0 and $orderInfo->is_refund_yucunkuan==0) { $yucunkuan_huifu_status=false; $yucunkuan_huifu_status= $AspNet::UseYuCunKuan($person->ghzid,$orderInfo->yucunkuan,$yyid,0,$orderInfo->id,'tj_h5','抵扣体检H5订单',$now_datetime); + if($yucunkuan_huifu_status===true){ + DB::table('orders')->where('id',$orderInfo->id)->update(['is_refund_yucunkuan'=>1]); + } } } diff --git a/Laravel/app/Services/OrderService.php b/Laravel/app/Services/OrderService.php index b95c06d..ced4f00 100644 --- a/Laravel/app/Services/OrderService.php +++ b/Laravel/app/Services/OrderService.php @@ -1,6 +1,7 @@ $de_list,'wait_day'=>"10"]; } + public function Cancel($orderInfo) + { + $person=DB::table('web_user_person')->where(['id' => $orderInfo->person_id])->first(); + $now_datetime=date('Y-m-d H:i:s'); + //调用接口恢复积分和预存款 + $env=config('app.globals.Env'); + $AspNet=new AspNetZhuanController(); + $jifen_huifu_status=true; + $yucunkuan_huifu_status=true; + $yyid=$orderInfo->hospital_id; + if($yyid==1) $yyid=6; + if($env=='pro') { //如果是正式环境 + if($orderInfo->jifen>0 and $orderInfo->is_refund_jifen==0) { + $jifen_huifu_status=false; + $jifen_huifu_status= $AspNet::UseJiFen($person->ghzid,$orderInfo->jifen,$yyid,$orderInfo->id,'tj_h5','抵扣体检H5订单',$now_datetime); + if( $jifen_huifu_status===true){ + DB::table('orders')->where('id',$orderInfo->id)->update(['is_refund_jifen'=>1]); + } + } + if($orderInfo->yucunkuan>0 and $orderInfo->is_refund_yucunkuan==0) { + $yucunkuan_huifu_status=false; + $yucunkuan_huifu_status= $AspNet::UseYuCunKuan($person->ghzid,$orderInfo->yucunkuan,$yyid,0,$orderInfo->id,'tj_h5','抵扣体检H5订单',$now_datetime); + if($yucunkuan_huifu_status===true){ + DB::table('orders')->where('id',$orderInfo->id)->update(['is_refund_yucunkuan'=>1]); + } + } + } + + DB::table('orders')->where(['id' => $orderInfo->id,'status'=>1])->update([ + 'status' => 3 + ]); + //恢复号源 + $up_plan = DB::table('plans')->where(['id' => $orderInfo->plan_id, 'status' => 2])->update([ + 'status' => 1 + ]); + return true; + } } diff --git a/Laravel/routes/api.php b/Laravel/routes/api.php index 3295439..49bdc02 100644 --- a/Laravel/routes/api.php +++ b/Laravel/routes/api.php @@ -90,6 +90,7 @@ Route::group(['middleware' => ['checktoken', 'log'], 'prefix' => 'v1'], function Route::post('admin/PlanGetList', 'App\Http\Controllers\API\Admin\YeWu\PlanController@GetList');//号源列表 Route::post('admin/PlanGetDetail', 'App\Http\Controllers\API\Admin\YeWu\PlanController@GetDetail');//号源详情 Route::post('admin/PlanSave', 'App\Http\Controllers\API\Admin\YeWu\PlanController@Save');//保存号源详情 + Route::post('admin/PlanBatchUpdatePlanType', 'App\Http\Controllers\API\Admin\YeWu\PlanController@BatchUpdatePlanType');//保存号源详情 Route::post('admin/ComboGetList', 'App\Http\Controllers\API\Admin\YeWu\ComboController@GetList');//获取套餐列表 Route::post('admin/ComboGetDetail', 'App\Http\Controllers\API\Admin\YeWu\ComboController@GetDetail');//获取套餐详情 diff --git a/Laravel/routes/web.php b/Laravel/routes/web.php index 22c3e97..8a32fec 100644 --- a/Laravel/routes/web.php +++ b/Laravel/routes/web.php @@ -91,3 +91,5 @@ Route::group(['prefix' => 'api/Web'], function () { //对外------ Route::any('/TJPushInfo', 'App\Http\Controllers\API\Internal\SiXinPushController@PushInfo');//接收思信推送 Route::any('/TJCheck', 'App\Http\Controllers\API\Internal\OrderController@TJCheck');//到检 +Route::any('/OrderBatchCancel', 'App\Http\Controllers\API\H5\OrderController@BatchCancel');//批量取消 + diff --git a/admin/src/api/api.js b/admin/src/api/api.js index 7800388..b2cc229 100644 --- a/admin/src/api/api.js +++ b/admin/src/api/api.js @@ -171,6 +171,10 @@ export const PlanGetDetail = (data = {}) => { export const PlanSave = (data = {}) => { return axios({ url: import.meta.env.VITE_APP_API + 'v1/admin/PlanSave', data: data }) } +//号源批量更新 +export const PlanBatchUpdatePlanType = (data = {}) => { + return axios({ url: import.meta.env.VITE_APP_API + 'v1/admin/PlanBatchUpdatePlanType', data: data }) +} //获取套餐列表 export const ComboGetList = (data = {}) => { return axios({ url: import.meta.env.VITE_APP_API + 'v1/admin/ComboGetList', data: data }) diff --git a/admin/src/views/PlanMngr/Plan.vue b/admin/src/views/PlanMngr/Plan.vue index f9a5847..0301ca6 100644 --- a/admin/src/views/PlanMngr/Plan.vue +++ b/admin/src/views/PlanMngr/Plan.vue @@ -14,6 +14,8 @@ 查 询 修 改 删 除 + 设为正常号 + 设为预留号 @@ -103,7 +105,7 @@ ElMessageBox } from 'element-plus' import { - PlanGetList,PlanGetDetail,CheckUpTypeGetEnableList,PlanSave + PlanGetList,PlanGetDetail,CheckUpTypeGetEnableList,PlanSave,PlanBatchUpdatePlanType } from '@/api/api.js' let loading = ref(false) let searchInfo = ref({}) @@ -137,6 +139,8 @@ let Info=ref({}); let dialogVisible=ref(false); const Edit=()=>{ + + dotype.value='one' let selected_list=[]; list.value.forEach((v,i)=>{ if(v.selected!=undefined && v.selected==true){ @@ -179,10 +183,51 @@ } }) } + let dotype=ref('one'); const Save=()=>{ + if(dotype.value=='one'){ + loading.value = true + PlanSave({ + info: Info.value, + }).then(res => { + loading.value = false + if (res.status) { + dialogVisible.value=false + GetList() + } else { + ElMessage.error(res.msg) + } + }) + } + if(dotype.value=='batch'){ + BatchUpdateFunc(1,Info.value) + } + } + const BatchUpdate=(type)=>{ + + if(type==1){ + Info.value={} + dialogVisible.value=true + dotype.value='batch' + GetCheckUpTypeEnableList_Func() + } + if(type==0){ + BatchUpdateFunc(type) + } + + } + const BatchUpdateFunc=(type,info=null)=>{ loading.value = true - PlanSave({ - info: Info.value, + let selected_list=[] + list.value.forEach((v,i)=>{ + if(v.selected!=undefined && v.selected==true){ + selected_list.push(v.id) + } + }) + PlanBatchUpdatePlanType({ + ids: selected_list, + type:type, + info:info }).then(res => { loading.value = false if (res.status) { diff --git a/admin/src/views/PlanMngr/PlanModel.vue b/admin/src/views/PlanMngr/PlanModel.vue index 2fca7c1..04e43c6 100644 --- a/admin/src/views/PlanMngr/PlanModel.vue +++ b/admin/src/views/PlanMngr/PlanModel.vue @@ -14,7 +14,7 @@ - +