post(); $this->validate(request(), [ 'curPage' => 'required|integer', 'pageSize' => 'required|integer', ]); $pageSize = ($req['curPage'] - 1) * $req['pageSize']; $user = $this->user; $doctor_id = $user['id']; $where = []; $order = ['created_at', 'desc']; $where['docter_id'] = $doctor_id; if (isset($req['appointment']) && $req['appointment'] == 1) { // 门诊预约 $where['product_type'] = 3; if (isset($req['timeSort']) && $req['timeSort'] == '0') { $order = ['order_patients.appoint_start_time', 'asc']; //预约时间正序 } if (isset($req['timeSort']) && $req['timeSort'] == '1') { $order = ['order_patients.appoint_start_time', 'desc']; //预约时间倒叙 } if (isset($req['timeSort']) && $req['timeSort'] == '2') { $order = ['created_at', 'asc']; //下单时间正序 } if (isset($req['timeSort']) && $req['timeSort'] == '3') { $order = ['created_at', 'desc']; //下单时间倒叙 } if (isset($req['comStatus']) && $req['comStatus'] == '0') { $comstatus = [ 2, 3,7]; $where[] = [function ($query) use ($comstatus) { $query->whereIn('order_status', $comstatus);//处理中 }]; } if (isset($req['comStatus']) && $req['comStatus'] == '1') { $where['order_status'] = 4; //已完成 } } else { // 图文和电话的 $ids = [1, 2]; $where[] = [function ($query) use ($ids) { $query->whereIn('product_type', $ids); }]; if (isset($req['typeAll']) && $req['typeAll'] == 1) { $where['product_type'] = 2;//图文咨询 } if (isset($req['typeAll']) && $req['typeAll'] == 2) { $where['product_type'] = 1;//电话咨询 } if (isset($req['processing']) && $req['processing'] == 0) { $status = [2, 3]; $where[] = [function ($query) use ($status) { $query->whereIn('order_status', $status);//处理中 }]; } if (isset($req['processing']) && $req['processing'] == 1) { $where['order_status'] = 4; //历史记录,已完成订单 } } // $data = Order::With(['orderPatient'=>function($query) use ($orders){ // $query->orderBy($orders[0],$orders[1]); // }])->where($where)->orderBy($order[0],$order[1])->skip($pageSize)->take($req['pageSize'])->groupBy('id')->get()->toArray(); $data = DB::table('orders') ->leftJoin('order_patients', 'order_patients.order_id', '=', 'orders.id') ->select(['orders.*', 'order_patients.birthday as obirthday', 'order_patients.appoint_start_time', 'order_patients.name as oanme']) ->where($where)->orderBy($order[0], $order[1]) ->skip($pageSize)->take($req['pageSize']) ->groupBy('id') ->get()->toArray(); // $data = Order::with('orderPatient')->where($where)->skip($pageSize)->take($req['pageSize'])->groupBy('id')->toSql(); // $data = OrderPatient::with("order")->where('id', $user['id'])->orderBy('id', 'desc')->limit($pageSize,$req['pageSize'])->get()->toarray(); $list = []; try { foreach ($data as $k => $v) { $v = get_object_vars($v); if (!$v['obirthday']) { unset($list[$k]); } else { $list[$k]['id'] = $v['id']; $list[$k]['user_id'] = $v['user_id']; $list[$k]['order_sn'] = $v['order_sn']; $list[$k]['zl'] = $v['product_type']; $list[$k]['zt'] = $v['order_status']; unset($list[$k]['order_status'], $list[$k]['product_type']); $list[$k]['created_at'] = $v['created_at']; $list[$k]['appoint_time'] = empty($v['appoint_start_time']) ? '---' : date('Y-m-d H:i:s', $v['appoint_start_time']); $list[$k]['name'] = $v['oanme']; $list[$k]['birthday'] = birthday_to_age($v['obirthday']); } } return out($list); } catch (\Exception $e) { return out($e->getFile() . '中第 ' . $e->getLine() . '行发生了 ' . $e->getMessage() . '错误'); } return out($list); } public function mzPutOrder() { } /** * @return mixed * 完成订单 * @author Yuanhang Liu & Xiaoyun Liu */ public function orderPatientok() { $req = request()->post(); $this->validate(request(), [ 'order_id|订单id' => 'required|integer', 'pathogen|病因' => 'required', 'suggest|建议' => 'required', 'patient_id|患者ID' => 'required', ]); $user = $this->user; $find = Order::where('id', '=', $req['order_id'])->first()->toArray(); if (!$find) { return out('', 500, '订单错误!'); } if ($find['order_status'] > 3) { return out('', 500, '此订单不可操作!'); } $lable = ''; switch ($find['product_type']) { case 1: $lable = '电话咨询'; break; case 2: $lable = '图文咨询'; break; case 3: $lable = '门诊预约'; break; case 4: $lable = '疫苗接种预约'; break; case 5: $lable = '儿保预约'; break; case 6: $lable = '服务包'; break; default: $lable = '参数错误!'; } $relation_id = ''; if ($find['product_type'] == 1 || $find['product_type'] == 2) { // 需要有意见单的 $suggests = Suggest::create([ 'order_id' => $find['id'], 'user_id' => $find['user_id'], 'symptoms' => $req['symptoms'], 'pathogen' => $req['pathogen'], 'suggest' => $req['suggest'], 'patient_id' => $req['patient_id'] ]); $suggests = $suggests->toArray(); $relation_id = $suggests['id']; } else { $relation_id = 0; } $status = $find['product_type']; $lab = ''; $mesid = $relation_id; if ($status == 1) { $lab = '电话咨询'; } else if ($status == 2) { $lab = '图文咨询'; } else if ($status == 3) { $mesid = $find['id']; $lab = '门诊预约'; } $order_sn = $find['order_sn']; $doctername = $user['name']; DB::beginTransaction(); try { Order::where('id', '=', $req['order_id'])->update(['order_status' => 4, 'updated_at' => date('Y-m-d H:i:s', time()), 'end_time' => time()]); Docter::where('id', '=', $user['id'])->increment('service_persons'); // 添加到用户记录中! UserMessages::create([ 'user_id' => $find['user_id'], 'docter_id' => $user['id'], 'status' => 1, 'type' => 2, 'relation_id' => $mesid, 'content' => "您的 " . $lab . " 订单,订单号" . $order_sn . ",医生" . $doctername . "已经确认完成(点击查看意见单)", ]); DB::commit(); } catch (\Exception $e) { DB::rollBack(); return out('', 500, $e->getMessage()); } catch (\PDOException $e) { DB::rollBack(); return out('', 500, $e->getMessage()); } $msg = $this->ReceivingReminderOK($find['id']); order_trace(['完成订单日志', '请求参数' => $find['id'] ?? '', '返回数据' => $msg ?? ''], 'info'); $axbwhere['docter_id'] = $user['id']; $axbwhere['user_id'] = $find['user_id']; $finds = Axb::where($axbwhere)->orderBy('id', 'desc')->first(); if ($status == 1 && $finds) { $unlok = (new Commons())->unLokPhone($finds['xphone'], $finds['subs_id']); Axb::where(['subs_id' => $finds['subs_id']])->delete(); } return out(); } /** * 门诊预约完成订单 * @return mixed * @throws \Exception */ public function mzPatientok() { $req = request()->post(); $this->validate(request(), [ 'order_id|订单id' => 'required|integer', ]); $user = $this->user; $find = Order::where('id', '=', $req['order_id'])->first()->toArray(); if (!$find) { return out('', 500, '订单错误!'); } if ($find['order_status'] > 3) { return out('', 500, '此订单不可操作!'); } $lable = ''; switch ($find['product_type']) { case 1: $lable = '电话咨询'; break; case 2: $lable = '图文咨询'; break; case 3: $lable = '门诊预约'; break; case 4: $lable = '疫苗接种预约'; break; case 5: $lable = '儿保预约'; break; case 6: $lable = '服务包'; break; default: $lable = '参数错误!'; } $relation_id = 0; $status = $find['product_type']; $lab = ''; $mesid = $relation_id; if ($status == 1) { $lab = '电话咨询'; } else if ($status == 2) { $lab = '图文咨询'; } else if ($status == 3) { $mesid = $find['id']; $lab = '门诊预约'; } $order_sn = $find['order_sn']; $doctername = $user['name']; DB::beginTransaction(); try { Order::where('id', '=', $req['order_id'])->update(['order_status' => 4, 'updated_at' => date('Y-m-d H:i:s', time()), 'end_time' => time()]); Docter::where('id', '=', $user['id'])->increment('service_persons'); // 添加到用户记录中! UserMessages::create([ 'user_id' => $find['user_id'], 'docter_id' => $user['id'], 'status' => 1, 'type' => 2, 'relation_id' => $mesid, 'content' => "您的 " . $lab . " 订单,订单号" . $order_sn . ",医生" . $doctername . "已经确认完成(点击查看订单)", ]); DB::commit(); } catch (\Exception $e) { DB::rollBack(); return out('', 500, $e->getMessage()); } catch (\PDOException $e) { DB::rollBack(); return out('', 500, $e->getMessage()); } order_trace(['门诊完成订单日志', '请求参数' => $find['id'] ?? '', '返回数据' => $msg ?? ''], 'info'); $this->ReceivingReminderOK($find['id']); return out(); } /** * @return mixed * 接单 * @author Yuanhang Liu & Xiaoyun Liu */ public function putOrderPatient() { $req = request()->post(); $this->validate(request(), [ 'order_id|订单id' => 'required|integer', ]); $user = $this->user; $find = Order::where('id', '=', $req['order_id'])->first()->toArray(); $status = $find['product_type']; $lab = ''; if ($status == 1) { $lab = '电话咨询'; } else if ($status == 2) { $lab = '图文咨询'; } else if ($status == 3) { $lab = '门诊预约'; } $order_sn = $find['order_sn']; $order_id = $find['id']; $doctername = $user['name']; if (!$find) { return out('', 500, '订单错误!'); } if ($find['order_status'] != 2) { return out('', 500, '此订单已被接单或未付款!'); } if ($find['payment_status'] >= 4) { return out('', 500, '此订单可能已完成!'); } DB::beginTransaction(); try { Order::where('id', '=', $req['order_id'])->update(['order_status' => 3, 'updated_at' => date('Y-m-d H:i:s', time()), 'receiving_time' => time()]); // 添加到用户记录中! UserMessages::create([ 'user_id' => $find['user_id'], 'docter_id' => $user['id'], 'status' => 1, 'type' => 1, 'relation_id' => $order_id, 'content' => "您的 " . $lab . " 订单,订单号" . $order_sn . ",医生" . $doctername . "已经确认接单(点击查看订单详情)", ]); DB::commit(); $msg = $this->ReceivingReminder($req['order_id']); order_trace(['接单日志', '请求参数' => $req['order_id'] ?? '', '返回数据' => $msg ?? ''], 'info'); return out(); } catch (\Exception $e) { DB::rollBack(); return out('', 500, $e->getMessage()); } catch (\PDOException $e) { DB::rollBack(); return out('', 500, $e->getMessage()); } } /** * @return mixed * 患者咨询详情 * @author Yuanhang Liu & Xiaoyun Liu */ public function orderPatientDetail() { $req = request()->post(); $this->validate(request(), [ 'patient_id' => 'required|integer', ]); $data = []; // 订单查询 $data = Order::with(['orderPatient', 'user', 'calllog'])->where('id', $req['patient_id'])->first(); // 通话记录查询 $datas = CallLog::where('order_id', $req['patient_id'])->get(); // 机构查询 $user = $this->user; $doctor_id = (new Commons)->getUserIdByDoctorId($user['phone']); // 返回数组 $res_patient = []; //电话咨询 //电话咨询 if ($data){ $data=$data->toArray(); } if ($data['product_type'] == 1) { $res_patient['patient_id'] = $data['order_patient']['id']; $res_patient['user_id'] = $data['user_id']; $res_patient['order_sn'] = $data['order_sn']; $res_patient['patient_id'] = $data['patient_id']; $res_patient['product_type'] = $data['product_type']; $res_patient['name'] = $data['order_patient']['name'];//患者姓名 $res_patient['numbirthday'] = birthday_to_age($data['order_patient']['birthday']);//年龄 $res_patient['card_number'] = $data['order_patient']['card_number'];//身份证号 $res_patient['created_at'] = $data['created_at'];//下单时间 $res_patient['nickname'] = $data['user']['nickname'];//下单用户 $res_patient['receiving_time'] = !empty($data['receiving_time']) ? date('Y-m-d H:i:s', $data['receiving_time']) : '---';//接单时间 $res_patient['order_status'] = $data['order_status'];//订单状态 $res_patient['call_list'] = [];//通话记录 $res_patient['one_call'] = ''; if ($data['calllog']) { $res_patient['one_call'] = $data['calllog'][0]['call_time']; $res_patient['secret_no'] = $data['calllog'][count($data['calllog']) - 1]['secret_no'];//X号码 foreach ($data['calllog'] as $ks => $vs) { $res_patient['call_list'][$ks]['frequency'] = '通话' . ($ks += 1);//拨打电话开始时间 $res_patient['call_list'][$ks]['start'] = $vs['call_time'];//拨打电话开始时间 $res_patient['call_list'][$ks]['end'] = $vs['ring_time'];//拨打电话结束时间 $res_patient['call_list'][$ks]['duration'] = gmdate('i:s', $vs['talk_time']);//拨打电话结束时间 } } } //图文咨询 if ($data['product_type'] == 2) { $res_patient['order_sn'] = $data['order_sn']; $res_patient['patient_id'] = $data['patient_id']; $res_patient['user_id'] = $data['user_id']; $res_patient['user_name'] = $data['user']['nickname']; $res_patient['user_avatar'] = $data['user']['avatar']; $res_patient['sex'] = $data['order_patient']['sex']; $res_patient['product_type'] = $data['product_type']; $res_patient['name'] = $data['order_patient']['name']; $res_patient['numbirthday'] = birthday_to_age($data['order_patient']['birthday']); $res_patient['card_number'] = $data['order_patient']['card_number']; $res_patient['symptoms'] = $data['order_patient']['symptoms'];//病情描述 $res_patient['medical_imgs'] = json_decode($data['order_patient']['medical_imgs'], true);//病情照片 $res_patient['created_at'] = $data['created_at'];//下单时间 $res_patient['nickname'] = $data['user']['nickname'];//下单用户 $res_patient['receiving_time'] = !empty($data['receiving_time']) ? date('Y-m-d H:i:s', $data['receiving_time']) : '---'; //接单时间 $res_patient['order_status'] = $data['order_status'];//接单时间 } //门诊预约 if ($data['product_type'] == 3) { $res_patient['order_sn'] = $data['order_sn']; $res_patient['patient_id'] = $data['patient_id']; $res_patient['product_type'] = $data['product_type']; $res_patient['name'] = $data['order_patient']['name']; // 患者 $res_patient['numbirthday'] = birthday_to_age($data['order_patient']['birthday']); //年龄 $res_patient['card_number'] = $data['order_patient']['card_number']; // 证件号 $res_patient['appoint_time'] = date('Y年m月d日 H:i', $data['order_patient']['appoint_start_time']);// 预约时间 $res_patient['order_status'] = $data['order_status'];// 订单状态 $organization = Organization::where('id', '=', $data['organization_id'])->first(); if ($organization) { $organization = $organization->toArray(); $res_patient['organization'] = $organization['name']; // 门诊机构 } else { $res_patient['organization'] = ''; // 门诊机构 } $res_patient['order_sn'] = $data['order_sn'];//订单号 $res_patient['created_at'] = $data['created_at'];//下单时间 $res_patient['nickname'] = $data['user']['nickname'];//下单用户 } return out($res_patient); } /** * 拨打电话/绑定电话 * @return \Illuminate\Http\JsonResponse * @author Liu-Yh * Create By 2020/11/24 19:19 */ public function callPhones() { $req = request()->post(); $user = $this->user; $this->validate(request(), [ 'order_id' => 'required', 'user_id' => 'required|integer', ]); $docter_id = $user['id']; $docter_phone = $user['phone']; if (!$docter_phone) { return out('', 500, '医生电话不存在!'); } $find = Order::with('orderPatient')->where('order_sn', $req['order_id'])->first()->toArray(); if (empty($find['order_patient'])) { return out('', 500, '患者电话不存在'); } $phone = $find['order_patient']['phone']; if ($docter_phone == $phone) { return out('', 500, '医生和患者电话号不能一样!'); } $wheres['docter_id'] = $docter_id; $wheres['user_id'] = $req['user_id']; $commons = new Commons(); $finds = Axb::where($wheres)->orderBy('id', 'desc')->first(); if ($finds) { $querylok = $commons->QuerySubsId($finds['xphone']); if ($querylok['Code'] == 'OK') { // 可能是数组 $new_arr = explode(',', $querylok['SubsId']); foreach ($new_arr as $v) { $queryCallStatus = $commons->QuerySubscriptionDetail($finds['xphone'], $v); if ($queryCallStatus['Code'] == "OK") { if ($queryCallStatus['SecretBindDetailDTO']['PhoneNoA'] == $docter_phone && $queryCallStatus['SecretBindDetailDTO']['PhoneNoB'] == $phone) { return out($finds['xphone']); } else { if ($phone) { Axb::where('id', $finds['id'])->delete(); return $this->createCall($phone, $docter_phone, $docter_id, $req['user_id']); } else { return out('', 500, '患者电话不存在'); } } } else { if ($phone) { Axb::where('id', $finds['id'])->delete(); return $this->createCall($phone, $docter_phone, $docter_id, $req['user_id']); } else { return out('', 500, '患者电话不存在'); } } } } else { if ($phone) { Axb::where('id', $finds['id'])->delete(); return $this->createCall($phone, $docter_phone, $docter_id, $req['user_id']); } else { return out('', 500, '患者电话不存在'); } } } else { if ($phone) { return $this->createCall($phone, $docter_phone, $docter_id, $req['user_id']); } else { return out('', 500, '患者电话不存在'); } } } /** * 创建电话 * @param $phone * @param $docter_phone * @param $docter_id * @param $user_id * @return \Illuminate\Http\JsonResponse */ protected function createCall($phone, $docter_phone, $docter_id, $user_id) { $commons = new Commons(); $callModel = $commons->BindAxb($docter_phone, $phone); if ($callModel['Code'] == "OK") { Axb::create([ 'docter_id' => $docter_id, 'user_id' => $user_id, 'xphone' => $callModel['SecretBindDTO']['SecretNo'], 'subs_id' => $callModel['SecretBindDTO']['SubsId'], 'createtime' => time(), ]); return out($callModel['SecretBindDTO']['SecretNo']); } else { return out($callModel); } } /** * 电话随访 * @return \Illuminate\Http\JsonResponse * @author Liu-Yh * Create By 2020/11/24 19:19 */ public function callPhoneSure() { $req = request()->post(); $user = $this->user; $this->validate(request(), [ 'user_id' => 'required|integer', ]); $docter_id = $user['id']; $docter_phone = $user['phone']; if (!$docter_phone) { return out('', 500, '医生电话不存在!'); } $find = User::where('id', $req['user_id'])->first()->toArray(); $phone = $find['phone']; $wheres['docter_id'] = $docter_id; $wheres['user_id'] = $find['id']; $commons = new Commons(); $finds = Axb::where($wheres)->orderBy('id', 'desc')->first(); if ($finds) { $querylok = $commons->QuerySubsId($finds['xphone']); if ($querylok['Code'] == 'OK') { $queryCallStatus = $commons->QueryCallStatus($phone, $querylok['SubsId']); if ($queryCallStatus['Code'] == 'OK') { if ($queryCallStatus['SecretCallStatusDTO'] != 4) { return out($finds['xphone']); } else { if ($phone) { $callModel = $commons->BindAxb($docter_phone, $phone); if ($callModel['Code'] == "OK") { return out($callModel['SecretBindDTO']['SecretNo']); } } else { return out('', 500, '患者电话不存在'); } } } } } else { if ($phone) { $callModel = $commons->BindAxb($docter_phone, $phone); if ($callModel['Code'] == "OK") { Axb::create([ 'docter_id' => $docter_id, 'user_id' => $req['user_id'], 'xphone' => $callModel['SecretBindDTO']['SecretNo'], 'createtime' => time(), ]); return out($callModel['SecretBindDTO']['SecretNo']); } else { return out($callModel); } } else { return out('', 500, '患者电话不存在'); } } } /** * 取消订单接口 * @throws \Illuminate\Validation\ValidationException */ public function cancelOrder() { $req = request()->post(); $this->validate(request(), [ 'order_id' => 'required|integer', ]); $order = Order::with(['orderPatient'])->where('id', $req['order_id'])->first(); if ($order['order_status'] == 2 && $order['payment_status'] == 2) { DB::beginTransaction(); try { if ($order['product_type'] == 3) { Order::where('id',$req['order_id'])->update(['order_status'=>5,'payment_status'=>5,'order_notes'=>'医生拒绝接单']); }else{ //退钱到余额 if (!empty($order['payment_amount'])) { User::changeBalance($order['user_id'], $order['payment_amount'], 4, $order['id'], '医生拒绝接单'); } Order::where('id', $req['order_id'])->update(['order_status' => 5, 'order_notes' => '医生拒绝接单', 'payment_status' => 4]); } DB::commit(); $this->CancelReminder($req['order_id']); return out('', 200, '订单取消成功'); } catch (\Exception $e) { DB::rollBack(); return out('', 500, $e->getMessage()); } catch (\PDOException $e) { DB::rollBack(); return out('', 500, $e->getMessage()); } } else { return out('', 500, '订单不可取消'); } } /** * 获取病例信息接口! * @author Liu * @return \Illuminate\Http\JsonResponse * @throws \Illuminate\Validation\ValidationException */ public function CaseAcquisition() { $req = request()->post(); $this->validate(request(), [ 'user_id' => 'required|integer', 'order_id', // 'is_showAll'=>'required|integer' ]); $user = $this->user; $docter_id = $user['id']; // 订单内点击 if (isset($req['order_id'])&&!empty($req['order_id'])){ $data = Order::with(['orderPatient','user'])->where('id',$req['order_id'])->first(); }else{ $data = Order::with(['orderPatient','user'])->where(['user_id'=>$req['user_id'],'docter_id'=>$docter_id,'product_type'=>2,'order_status'=>3])->orderBy('id','desc')->first(); } // 返回数组 $res_patient = []; // if ($req['is_showAll']==1){ // $list = Order::with(['orderPatient','user'])->where(['user_id'=>$req['user_id'],'docter_id'=>$docter_id,'product_type'=>2])->orderBy('id','asc')->get(); // if ($list){ // $list = $list->toArray(); // foreach ($list as $k=>$v){ // $res_patient['list'][$k]['order_sn'] = $v['order_sn']; // $res_patient['list'][$k]['user_id'] = $v['user_id']; // $res_patient['list'][$k]['user_name'] = $v['user']['nickname']; // $res_patient['list'][$k]['user_avatar'] = $v['user']['avatar']; // $res_patient['list'][$k]['sex'] = $v['order_patient']['sex']; // $res_patient['list'][$k]['name'] = $v['order_patient']['name']; // $res_patient['list'][$k]['numbirthday'] = numBirthday($v['order_patient']['birthday']); // $res_patient['list'][$k]['symptoms'] = $v['order_patient']['symptoms'];//病情描述 // $res_patient['list'][$k]['medical_imgs'] = json_decode($v['order_patient']['medical_imgs'], true);//病情照片 // } // } // } if ($data) { $data = $data->toArray(); $res_patient['order_sn'] = $data['order_sn']; $res_patient['user_id'] = $data['user_id']; $res_patient['user_name'] = $data['user']['nickname']; $res_patient['user_avatar'] = $data['user']['avatar']; $res_patient['sex'] = $data['order_patient']['sex']; $res_patient['name'] = $data['order_patient']['name']; $res_patient['numbirthday'] = birthday_to_age($data['order_patient']['birthday']); $res_patient['symptoms'] = $data['order_patient']['symptoms'];//病情描述 $res_patient['medical_imgs'] = json_decode($data['order_patient']['medical_imgs'], true);//病情照片 } return out($res_patient); } /** * 修改关闭状态 * $type 1=开启小程序,2=关闭小程序 * @return \Illuminate\Http\JsonResponse * @throws \Illuminate\Validation\ValidationException */ public function docter_open(){ $req = request()->post(); $this->validate(request(), [ 'type' => 'required|integer|in:1,2', ]); $user = $this->user; $docter_id = $user['id']; Docter::where('id',$docter_id)->update(['is_open'=>$req['type']]); return out(); } /** * 确认超时提醒 当天的预约订单,医生还未点击完成的订单,23:00给医生发送提醒 */ public function AppointReminder($id=''){ if (!empty($id)){ $Order = Order::with(['orderPatient','docter','user'])->where(['id'=>$id,'order_status'=>3,'payment_status'=>2])->first(); $send = send_wechatSubscription_message('appoint_reminder',[$Order['docter']['openid'], "pages/index/index",$Order['order_sn'],$Order['user']['nickname'],$Order['user']['phone'],$Order['created_at']]); }else{ $beginToday=mktime(0,0,0,date('m'),date('d'),date('Y')); $endToday=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1; $Order = Order::with(['orderPatient','docter','user'])->where(['order_status'=>3,'payment_status'=>2,'product_type'=>3])->whereBetween('receiving_time',[$beginToday,$endToday])->get(); foreach ($Order as $k=>$v){ if ($v['docter']){ if ($v['docter']['openid']){ $send = send_wechatSubscription_message('appoint_reminder',[$v['docter']['openid'], "pages/index/index",$v['order_sn'],$v['user']['nickname'],$v['user']['phone'],$v['created_at']]); } } } } } /** * 取消订单提醒 * @param $order_id * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException * @throws \GuzzleHttp\Exception\GuzzleException */ public function CancelReminder($order_id){ $Order = Order::with(['orderPatient','docter','user'])->where(['id'=>$order_id])->first(); order_trace(['类型'=>'订单医生取消','订单号'=>$order_id,'记录时间'=>date('Ymd His',time())],'info'); $type = ''; if ($Order['product_type']==1){ $type = '电话咨询'; }elseif ($Order['product_type']==2){ $type = '图文咨询 '; }elseif ($Order['product_type']==3){ $type = '门诊预约'; } if ($Order){ if ($Order['docter']['openid']){ $send = send_wechatSubscription_message('cancel_reminder',[ $Order['docter']['openid'], "pages/index/index", $Order['docter']['name'], $Order['order_sn'], $type, $Order['total_amount'], $Order['created_at'], '医生取消订单', ]); } } } /** * 咨询订单接单提醒 * @param $order_id * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException * @throws \GuzzleHttp\Exception\GuzzleException */ public function ReceivingReminder($order_id){ $Order = Order::with(['orderPatient','user'])->where(['id'=>$order_id])->first()->toArray(); order_trace(['类型'=>'咨询订单接单提醒','订单号'=>$order_id,'记录时间'=>date('Ymd His',time())],'info'); $type = ''; if ($Order['product_type']==1){ $type = '电话咨询'; }elseif ($Order['product_type']==2){ $type = '图文咨询 '; }elseif ($Order['product_type']==3){ $type = '门诊预约'; } if ($Order){ if ($Order['user']['openid']){ $send = send_wechatSubscription_message('receiving_reminder',[ $Order['user']['openid'], "pages/index/index", $Order['order_sn'], $type, date('Y-m-d H:i',$Order['receiving_time']), $Order['order_patient']['phone'], ],'wechat_small_program'); } } } /** * 排班变更提醒 * @param $docter_id 医生id * @param int $type 类型0=周排班 1=月排班 * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException * @throws \GuzzleHttp\Exception\GuzzleException */ public function ScheduleReminder($docter_id=81,$type=0){ $list = Docter::where(['id'=>$docter_id])->first(); $type = ''; $openid = $list['openid']; if ($type==0){ $type = '周排班变动'; }elseif ($type==1){ $type = '月排班变动 '; } if ($list){ if ($openid){ $send = send_wechatSubscription_message('schedule_reminder',[$openid, "pages/index/index", $type, '社区']); } } } /** * 审核认证提醒 * @param $docter_id 医生id * @param int $msg 消息 * @param $time 时间 * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException * @throws \GuzzleHttp\Exception\GuzzleException */ public function ThenReminder($docter_id,$msg='',$time){ $list = Docter::where(['id'=>$docter_id])->first(); $openid = $list['openid']; if ($list){ if ($openid){ $send = send_wechatSubscription_message('then_reminder',[$openid, "pages/index/index", $list['name'],$msg,$time]); } } } /** * 完成订单 * @param $order_id */ public function ReceivingReminderOK($order_id){ $Order = Order::with(['orderPatient','user'])->where(['id'=>$order_id])->first(); $type = ''; if ($Order['product_type']==1){ $type = '电话咨询已结束'; }elseif ($Order['product_type']==2){ $type = '图文咨询已结束 '; }elseif ($Order['product_type']==3){ $type = '门诊预约'; } order_trace(['发送微信模板消息ReceivingReminder', '请求参数' => $order_id ?? ''], 'error'); if ($Order){ if ($Order['user']['openid']){ order_trace(['订单类型'=>$type,'订单id'=>$Order->toArray(),'操作时间'=>date('Ymd His',time())],'info'); $send = send_wechatSubscription_message('receiving_reminderok',[ $Order['user']['openid'], "pages/index", $Order['order_sn'], $type, date('Y-m-d H:i:s',$Order['receiving_time']), date('Y-m-d H:i:s',time()), ],'wechat_small_program'); order_trace(['回调完成ReceivingReminderOK', '请求参数' => $send ?? ''], 'error'); } } } public function getChatRecord() { $req = request()->post(); $this->validate(request(), [ 'order_id' => 'required|integer' ]); $data = ImMessage::getChatRecord($req['order_id']); return out($data); } }