PatientController.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Yuanhang Liu
  5. * Date: 20-10-15
  6. * Time: 下午8:46
  7. */
  8. namespace App\Http\Controllers\Api\V2;
  9. use App\Models\Docter;
  10. use App\Models\Order;
  11. use App\Models\Patient;
  12. use App\Models\CallLog;
  13. use App\Models\OrderPatient;
  14. use App\Models\DocterOrganization;
  15. use App\Models\Suggest;
  16. use App\Models\User;
  17. use App\Models\UserMessages;
  18. use App\Models\Organization;
  19. use App\Http\Controllers\Api\V2\CommonController as Commons;
  20. use Illuminate\Support\Facades\DB;
  21. use App\Models\Axb;
  22. use App\Models\CallPhone;
  23. /**
  24. * 咨询订单用户类
  25. * Class PatientController
  26. * @package App\Http\Controllers\Api\V2
  27. */
  28. class PatientController extends AuthController
  29. {
  30. protected $relationSearch = true;
  31. /**
  32. * @return mixed
  33. * 患者咨询列表
  34. * @author Yuanhang Liu & Xiaoyun Liu
  35. */
  36. public function orderPatientList()
  37. {
  38. $req = request()->post();
  39. $this->validate(request(), [
  40. 'curPage' => 'required|integer',
  41. 'pageSize' => 'required|integer',
  42. ]);
  43. $pageSize = ($req['curPage']-1)*$req['pageSize'];
  44. $user = $this->user;
  45. $doctor_id = $user['id'];
  46. $where = [];
  47. $order=['created_at','desc'];
  48. $where['docter_id'] = $doctor_id;
  49. if (isset($req['appointment']) && $req['appointment']==1){
  50. // 门诊预约
  51. $where['product_type'] = 3;
  52. if (isset($req['timeSort']) && $req['timeSort']=='0') {
  53. $order = ['order_patients.appoint_start_time','asc']; //预约时间正序
  54. }
  55. if (isset($req['timeSort']) && $req['timeSort']=='1') {
  56. $order= ['order_patients.appoint_start_time','desc']; //预约时间倒叙
  57. }
  58. if (isset($req['timeSort']) && $req['timeSort']=='2') {
  59. $order = ['created_at','asc']; //下单时间正序
  60. }
  61. if (isset($req['timeSort']) && $req['timeSort']=='3') {
  62. $order = ['created_at','desc']; //下单时间倒叙
  63. }
  64. if (isset($req['comStatus']) && $req['comStatus']=='0') {
  65. $comstatus = [1,2,3];
  66. $where[] = [function($query) use ($comstatus){
  67. $query->whereIn('order_status', $comstatus);//处理中
  68. }];
  69. }
  70. if (isset($req['comStatus']) && $req['comStatus']=='1') {
  71. $where['order_status'] = 4; //已完成
  72. }
  73. }else{
  74. // 图文和电话的
  75. $ids = [1,2];
  76. $where[] = [function($query) use ($ids){
  77. $query->whereIn('product_type', $ids);
  78. }];
  79. if(isset($req['typeAll']) && $req['typeAll']==1){
  80. $where['product_type']=2;//图文咨询
  81. }
  82. if(isset($req['typeAll']) && $req['typeAll']==2){
  83. $where['product_type']=1;//电话咨询
  84. }
  85. if(isset($req['processing']) && $req['processing']==0){
  86. $status = [1,2,3];
  87. $where[] = [function($query) use ($status){
  88. $query->whereIn('order_status', $status);//处理中
  89. }];
  90. }
  91. if(isset($req['processing']) && $req['processing']==1){
  92. $where['order_status'] = 4; //历史记录,已完成订单
  93. }
  94. }
  95. // $data = Order::With(['orderPatient'=>function($query) use ($orders){
  96. // $query->orderBy($orders[0],$orders[1]);
  97. // }])->where($where)->orderBy($order[0],$order[1])->skip($pageSize)->take($req['pageSize'])->groupBy('id')->get()->toArray();
  98. $data = DB::table('orders')
  99. ->leftJoin('order_patients','order_patients.order_id','=','orders.id')
  100. ->select(['orders.*','order_patients.birthday as obirthday','order_patients.appoint_start_time','order_patients.name as oanme'])
  101. ->where($where)->orderBy($order[0],$order[1])
  102. ->skip($pageSize)->take($req['pageSize'])
  103. ->groupBy('id')
  104. ->get()->toArray();
  105. // $data = Order::with('orderPatient')->where($where)->skip($pageSize)->take($req['pageSize'])->groupBy('id')->toSql();
  106. // $data = OrderPatient::with("order")->where('id', $user['id'])->orderBy('id', 'desc')->limit($pageSize,$req['pageSize'])->get()->toarray();
  107. $list = [];
  108. try {
  109. foreach ($data as $k=>$v){
  110. $v = get_object_vars($v);
  111. if (!$v['obirthday']){
  112. unset($list[$k]);
  113. }else{
  114. $list[$k]['id'] = $v['id'];
  115. $list[$k]['user_id'] = $v['user_id'];
  116. $list[$k]['order_sn'] = $v['order_sn'];
  117. $list[$k]['zl'] = $v['product_type'];
  118. $list[$k]['zt'] = $v['order_status'];
  119. unset($list[$k]['order_status'],$list[$k]['product_type']);
  120. $list[$k]['created_at'] = $v['created_at'];
  121. $list[$k]['appoint_time'] = empty($v['appoint_start_time'])?'---':date('Y-m-d H:i:s',$v['appoint_start_time']);
  122. $list[$k]['name'] = $v['oanme'];
  123. $list[$k]['birthday'] = numBirthday($v['obirthday']);
  124. }
  125. }
  126. return out($list);
  127. }catch (\Exception $e){
  128. return out($e->getFile().'中第 '.$e->getLine().'行发生了 '.$e->getMessage().'错误');
  129. }
  130. return out($list);
  131. }
  132. public function mzPutOrder(){
  133. }
  134. /**
  135. * @return mixed
  136. * 完成订单
  137. * @author Yuanhang Liu & Xiaoyun Liu
  138. */
  139. public function orderPatientok(){
  140. $req = request()->post();
  141. $this->validate(request(), [
  142. 'order_id|订单id' => 'required|integer',
  143. 'pathogen|病因' => 'required',
  144. 'suggest|建议' => 'required',
  145. 'patient_id|患者ID' => 'required',
  146. ]);
  147. $user = $this->user;
  148. $find = Order::where('id','=',$req['order_id'])->first()->toArray();
  149. if (!$find){
  150. return out('',500,'订单错误!');
  151. }
  152. if ($find['order_status']>3){
  153. return out('',500,'此订单不可操作!');
  154. }
  155. $lable = '';
  156. switch ($find['product_type']){
  157. case 1:
  158. $lable = '电话咨询';
  159. break;
  160. case 2:
  161. $lable = '图文咨询';
  162. break;
  163. case 3:
  164. $lable = '门诊预约';
  165. break;
  166. case 4:
  167. $lable = '疫苗接种预约';
  168. break;
  169. case 5:
  170. $lable = '儿保预约';
  171. break;
  172. case 6:
  173. $lable = '服务包';
  174. break;
  175. default:
  176. $lable ='参数错误!';
  177. }
  178. $relation_id = '';
  179. if ($find['product_type']==1 || $find['product_type']==2){
  180. // 需要有意见单的
  181. $suggests = Suggest::create([
  182. 'order_id'=> $find['id'],
  183. 'user_id'=> $find['user_id'],
  184. 'symptoms'=> $req['symptoms'],
  185. 'pathogen'=> $req['pathogen'],
  186. 'suggest'=> $req['suggest'],
  187. 'patient_id'=> $req['patient_id']
  188. ]);
  189. $suggests = $suggests->toArray();
  190. $relation_id= $suggests['id'];
  191. }else{
  192. $relation_id= 0;
  193. }
  194. $status = $find['product_type'];
  195. $lab='';
  196. $mesid = $relation_id;
  197. if ($status==1){
  198. $lab = '电话咨询';
  199. }else if ($status==2){
  200. $lab = '图文咨询';
  201. }else if($status==3){
  202. $mesid = $find['id'];
  203. $lab = '门诊预约';
  204. }
  205. $order_sn = $find['order_sn'];
  206. $doctername = $user['name'];
  207. DB::beginTransaction();
  208. try {
  209. Order::where('id','=',$req['order_id'])->update(['order_status'=>4,'updated_at'=>date('Y-m-d H:i:s',time()),'end_time'=>time()]);
  210. Docter::where('id','=',$user['id'])->increment('service_persons');
  211. // 添加到用户记录中!
  212. UserMessages::create([
  213. 'user_id'=>$find['user_id'],
  214. 'docter_id'=>$user['id'],
  215. 'status'=>1,
  216. 'type'=>2,
  217. 'relation_id'=>$mesid,
  218. 'content'=>"您的 ".$lab." 订单,订单号".$order_sn.",医生".$doctername."已经确认完成(点击查看意见单)",
  219. ]);
  220. DB::commit();
  221. }catch (\Exception $e){
  222. DB::rollBack();
  223. return out('',500,$e->getMessage());
  224. }catch (\PDOException $e){
  225. DB::rollBack();
  226. return out('',500,$e->getMessage());
  227. }
  228. $axbwhere['docter_id'] = $user['id'];
  229. $axbwhere['user_id'] = $req['user_id'];
  230. $finds = Axb::where($axbwhere)->orderBy('id','desc')->first();
  231. if ($status==1 && $finds){
  232. $unlok = (new Commons())->unLokPhone($finds['xphone']);
  233. Axb::where($axbwhere)->delete();
  234. }
  235. return out();
  236. }
  237. /**
  238. * 门诊预约完成订单
  239. * @return mixed
  240. * @throws \Exception
  241. */
  242. public function mzPatientok(){
  243. $req = request()->post();
  244. $this->validate(request(), [
  245. 'order_id|订单id' => 'required|integer',
  246. ]);
  247. $user = $this->user;
  248. $find = Order::where('id','=',$req['order_id'])->first()->toArray();
  249. if (!$find){
  250. return out('',500,'订单错误!');
  251. }
  252. if ($find['order_status']>3){
  253. return out('',500,'此订单不可操作!');
  254. }
  255. $lable = '';
  256. switch ($find['product_type']){
  257. case 1:
  258. $lable = '电话咨询';
  259. break;
  260. case 2:
  261. $lable = '图文咨询';
  262. break;
  263. case 3:
  264. $lable = '门诊预约';
  265. break;
  266. case 4:
  267. $lable = '疫苗接种预约';
  268. break;
  269. case 5:
  270. $lable = '儿保预约';
  271. break;
  272. case 6:
  273. $lable = '服务包';
  274. break;
  275. default:
  276. $lable ='参数错误!';
  277. }
  278. $relation_id= 0;
  279. $status = $find['product_type'];
  280. $lab='';
  281. $mesid = $relation_id;
  282. if ($status==1){
  283. $lab = '电话咨询';
  284. }else if ($status==2){
  285. $lab = '图文咨询';
  286. }else if($status==3){
  287. $mesid = $find['id'];
  288. $lab = '门诊预约';
  289. }
  290. $order_sn = $find['order_sn'];
  291. $doctername = $user['name'];
  292. DB::beginTransaction();
  293. try {
  294. Order::where('id','=',$req['order_id'])->update(['order_status'=>4,'updated_at'=>date('Y-m-d H:i:s',time()),'end_time'=>time()]);
  295. Docter::where('id','=',$user['id'])->increment('service_persons');
  296. // 添加到用户记录中!
  297. UserMessages::create([
  298. 'user_id'=>$find['user_id'],
  299. 'docter_id'=>$user['id'],
  300. 'status'=>1,
  301. 'type'=>2,
  302. 'relation_id'=>$mesid,
  303. 'content'=>"您的 ".$lab." 订单,订单号".$order_sn.",医生".$doctername."已经确认完成(点击查看订单)",
  304. ]);
  305. DB::commit();
  306. }catch (\Exception $e){
  307. DB::rollBack();
  308. return out('',500,$e->getMessage());
  309. }catch (\PDOException $e){
  310. DB::rollBack();
  311. return out('',500,$e->getMessage());
  312. }
  313. return out();
  314. }
  315. /**
  316. * @return mixed
  317. * 接单
  318. * @author Yuanhang Liu & Xiaoyun Liu
  319. */
  320. public function putOrderPatient(){
  321. $req = request()->post();
  322. $this->validate(request(), [
  323. 'order_id|订单id' => 'required|integer',
  324. ]);
  325. $user = $this->user;
  326. $find = Order::where('id','=',$req['order_id'])->first()->toArray();
  327. $status = $find['product_type'];
  328. $lab='';
  329. if ($status==1){
  330. $lab = '电话咨询';
  331. }else if ($status==2){
  332. $lab = '图文咨询';
  333. }else if($status==3){
  334. $lab = '门诊预约';
  335. }
  336. $order_sn = $find['order_sn'];
  337. $order_id = $find['id'];
  338. $doctername = $user['name'];
  339. // 1.电话咨询 2.图文咨询 3.门诊预约 4.疫苗接种预约 5.儿保预约 6.服务包 7.充值
  340. if (!$find){
  341. return out('',500,'订单错误!');
  342. }
  343. if ($find['order_status']!=2){
  344. return out('',500,'此订单已被接单或未付款!');
  345. }
  346. if ($find['payment_status']>=4){
  347. return out('',500,'此订单可能已完成!');
  348. }
  349. DB::beginTransaction();
  350. try {
  351. Order::where('id','=',$req['order_id'])->update(['order_status'=>3,'updated_at'=>date('Y-m-d H:i:s',time()),'receiving_time'=>time()]);
  352. // 添加到用户记录中!
  353. UserMessages::create([
  354. 'user_id'=>$find['user_id'],
  355. 'docter_id'=>$user['id'],
  356. 'status'=>1,
  357. 'type'=>1,
  358. 'relation_id'=>$order_id,
  359. 'content'=> "您的 ".$lab." 订单,订单号".$order_sn.",医生".$doctername."已经确认接单(点击查看订单详情)",
  360. ]);
  361. DB::commit();
  362. return out();
  363. }catch (\Exception $e){
  364. DB::rollBack();
  365. return out('',500,$e->getMessage());
  366. }catch (\PDOException $e){
  367. DB::rollBack();
  368. return out('',500,$e->getMessage());
  369. }
  370. }
  371. /**
  372. * @return mixed
  373. * 患者咨询详情
  374. * @author Yuanhang Liu & Xiaoyun Liu
  375. */
  376. public function orderPatientDetail()
  377. {
  378. $req = request()->post();
  379. $this->validate(request(), [
  380. 'patient_id' => 'required|integer',
  381. ]);
  382. $data = [];
  383. // 订单查询
  384. $data = Order::with(['orderPatient','user','calllog'])->where('id', $req['patient_id'])->first()->toArray();
  385. // 通话记录查询
  386. $datas = CallLog::where('order_id', $req['patient_id'])->get();
  387. // 机构查询
  388. $user = $this->user;
  389. $doctor_id = (new Commons)->getUserIdByDoctorId($user['phone']);
  390. // 返回数组
  391. $res_patient = [];
  392. //电话咨询
  393. if($data['product_type']==1){
  394. $res_patient['patient_id'] = $data['order_patient']['id'];
  395. $res_patient['user_id'] = $data['user_id'];
  396. $res_patient['order_sn'] = $data['order_sn'];
  397. $res_patient['patient_id'] = $data['patient_id'];
  398. $res_patient['product_type'] = $data['product_type'];
  399. $res_patient['name']=$data['order_patient']['name'];//患者姓名
  400. $res_patient['numbirthday']=numBirthday($data['order_patient']['birthday']);//年龄
  401. $res_patient['card_number']=$data['order_patient']['card_number'];//身份证号
  402. $res_patient['created_at']=$data['created_at'];//下单时间
  403. $res_patient['nickname']=$data['user']['nickname'];//下单用户
  404. $res_patient['receiving_time']=!empty($data['receiving_time'])?date('Y-m-d H:i:s',$data['receiving_time']):'---';//接单时间
  405. $res_patient['order_status']=$data['order_status'];//订单状态
  406. $res_patient['call_list']=[];//通话记录
  407. $res_patient['one_call'] = '';
  408. if ($data['calllog']){
  409. $res_patient['one_call'] = $data['calllog'][0]['call_time'];
  410. $res_patient['secret_no']=$data['calllog'][count($data['calllog'])-1]['secret_no'];//X号码
  411. foreach ($data['calllog'] as $ks=>$vs){
  412. $res_patient['call_list'][$ks]['frequency']='通话'.($ks+=1);//拨打电话开始时间
  413. $res_patient['call_list'][$ks]['start']=$vs['call_time'];//拨打电话开始时间
  414. $res_patient['call_list'][$ks]['end']=$vs['ring_time'];//拨打电话结束时间
  415. $res_patient['call_list'][$ks]['duration']=gmdate('i:s',$vs['talk_time']);//拨打电话结束时间
  416. }
  417. }
  418. }
  419. //图文咨询
  420. if($data['product_type']==2){
  421. $res_patient['order_sn'] = $data['order_sn'];
  422. $res_patient['patient_id'] = $data['patient_id'];
  423. $res_patient['user_id'] = $data['user_id'];
  424. $res_patient['user_name'] = $data['user']['nickname'];
  425. $res_patient['user_avatar'] = $data['user']['avatar'];
  426. $res_patient['product_type'] = $data['product_type'];
  427. $res_patient['name']=$data['order_patient']['name'];
  428. $res_patient['numbirthday']=numBirthday($data['order_patient']['birthday']);
  429. $res_patient['card_number']=$data['order_patient']['card_number'];
  430. $res_patient['symptoms']=$data['order_patient']['symptoms'];//病情描述
  431. $res_patient['medical_imgs']=json_decode($data['order_patient']['medical_imgs'],true);//病情照片
  432. $res_patient['created_at']=$data['created_at'];//下单时间
  433. $res_patient['nickname']=$data['user']['nickname'];//下单用户
  434. $res_patient['receiving_time']=!empty($data['receiving_time'])?date('Y-m-d H:i:s',$data['receiving_time']):'---'; //接单时间
  435. $res_patient['order_status']=$data['order_status'];//接单时间
  436. }
  437. //门诊预约
  438. if($data['product_type']==3){
  439. $res_patient['order_sn'] = $data['order_sn'];
  440. $res_patient['patient_id'] = $data['patient_id'];
  441. $res_patient['product_type'] =$data['product_type'];
  442. $res_patient['name']=$data['order_patient']['name']; // 患者
  443. $res_patient['numbirthday']=numBirthday($data['order_patient']['birthday']); //年龄
  444. $res_patient['card_number']=$data['order_patient']['card_number']; // 证件号
  445. $res_patient['appoint_time'] = date('Y年m月d日 H:i',$data['order_patient']['appoint_start_time']);// 预约时间
  446. $res_patient['order_status'] = $data['order_status'];// 订单状态
  447. $organization = Organization::where('id','=',$data['organization_id'])->first();
  448. if($organization){
  449. $organization = $organization->toArray();
  450. $res_patient['organization']= $organization['name']; // 门诊机构
  451. }else{
  452. $res_patient['organization']= ''; // 门诊机构
  453. }
  454. $res_patient['order_sn']=$data['order_sn'];//订单号
  455. $res_patient['created_at']=$data['created_at'];//下单时间
  456. $res_patient['nickname']=$data['user']['nickname'];//下单用户
  457. }
  458. return out($res_patient);
  459. }
  460. /**
  461. * 拨打电话/绑定电话
  462. * @return \Illuminate\Http\JsonResponse
  463. * @author Liu-Yh
  464. * Create By 2020/11/24 19:19
  465. */
  466. public function callPhones(){
  467. $req = request()->post();
  468. $user = $this->user;
  469. $this->validate(request(), [
  470. 'order_id' => 'required',
  471. 'user_id' => 'required|integer',
  472. ]);
  473. $docter_id = $user['id'];
  474. $docter_phone = $user['phone'];
  475. if(!$docter_phone){
  476. return out('',500,'医生电话不存在!');
  477. }
  478. $find = Order::with('orderPatient')->where('order_sn',$req['order_id'])->first()->toArray();
  479. if (empty($find['order_patient'])){
  480. return out('',500,'患者电话不存在');
  481. }
  482. $phone = $find['order_patient']['phone'];
  483. if($docter_phone==$phone){
  484. return out('',500,'医生和患者电话号不能一样!');
  485. }
  486. $wheres['docter_id'] = $docter_id;
  487. $wheres['user_id'] = $req['user_id'];
  488. $commons = new Commons();
  489. $finds = Axb::where($wheres)->orderBy('id','desc')->first();
  490. if ($finds){
  491. $querylok = $commons->QuerySubsId($finds['xphone']);
  492. if ($querylok['Code']=='OK'){
  493. // 可能是数组
  494. $new_arr = explode(',',$querylok['SubsId']);
  495. foreach ($new_arr as $v){
  496. $queryCallStatus = $commons->QuerySubscriptionDetail($finds['xphone'],$v);
  497. if ($queryCallStatus['Code']=='OK'){
  498. if ($queryCallStatus['Code']=="OK"){
  499. if ($queryCallStatus['SecretBindDetailDTO']['PhoneNoA']==$docter_phone&&$queryCallStatus['SecretBindDetailDTO']['PhoneNoB']==$phone){
  500. return out($finds['xphone']);
  501. }else{
  502. if ($phone){
  503. $callModel = $commons->BindAxb($docter_phone,$phone);
  504. if ($callModel['Code']=="OK"){
  505. Axb::create([
  506. 'docter_id'=>$docter_id,
  507. 'user_id'=>$req['user_id'],
  508. 'xphone'=>$callModel['SecretBindDTO']['SecretNo'],
  509. 'subs_id'=>$callModel['SecretBindDTO']['SubsId'],
  510. 'createtime'=>time(),
  511. ]);
  512. return out($callModel['SecretBindDTO']['SecretNo']);
  513. }
  514. }else{
  515. return out('',500,'患者电话不存在');
  516. }
  517. }
  518. }else{
  519. if ($phone){
  520. $callModel = $commons->BindAxb($docter_phone,$phone);
  521. if ($callModel['Code']=="OK"){
  522. Axb::create([
  523. 'docter_id'=>$docter_id,
  524. 'user_id'=>$req['user_id'],
  525. 'xphone'=>$callModel['SecretBindDTO']['SecretNo'],
  526. 'subs_id'=>$callModel['SecretBindDTO']['SubsId'],
  527. 'createtime'=>time(),
  528. ]);
  529. return out($callModel['SecretBindDTO']['SecretNo']);
  530. }
  531. }else{
  532. return out('',500,'患者电话不存在');
  533. }
  534. }
  535. }
  536. }
  537. }
  538. }else{
  539. if ($phone){
  540. $callModel = $commons->BindAxb($docter_phone,$phone);
  541. if ($callModel['Code']=="OK"){
  542. Axb::create([
  543. 'docter_id'=>$docter_id,
  544. 'user_id'=>$req['user_id'],
  545. 'xphone'=>$callModel['SecretBindDTO']['SecretNo'],
  546. 'subs_id'=>$callModel['SecretBindDTO']['SubsId'],
  547. 'createtime'=>time(),
  548. ]);
  549. return out($callModel['SecretBindDTO']['SecretNo']);
  550. }else{
  551. return out($callModel);
  552. }
  553. }else{
  554. return out('',500,'患者电话不存在');
  555. }
  556. }
  557. }
  558. /**
  559. * 电话随访
  560. * @return \Illuminate\Http\JsonResponse
  561. * @author Liu-Yh
  562. * Create By 2020/11/24 19:19
  563. */
  564. public function callPhoneSure(){
  565. $req = request()->post();
  566. $user = $this->user;
  567. $this->validate(request(), [
  568. 'user_id' => 'required|integer',
  569. ]);
  570. $docter_id = $user['id'];
  571. $docter_phone = $user['phone'];
  572. if(!$docter_phone){
  573. return out('',500,'医生电话不存在!');
  574. }
  575. $find = User::where('id',$req['user_id'])->first()->toArray();
  576. $phone = $find['phone'];
  577. $wheres['docter_id'] = $docter_id;
  578. $wheres['user_id'] = $find['id'];
  579. $commons = new Commons();
  580. $finds = Axb::where($wheres)->orderBy('id','desc')->first();
  581. if ($finds){
  582. $querylok = $commons->QuerySubsId($finds['xphone']);
  583. if ($querylok['Code']=='OK'){
  584. $queryCallStatus = $commons->QueryCallStatus($phone,$querylok['SubsId']);
  585. if ($queryCallStatus['Code']=='OK'){
  586. if ($queryCallStatus['SecretCallStatusDTO']!=4){
  587. return out($finds['xphone']);
  588. }else{
  589. if ($phone){
  590. $callModel = $commons->BindAxb($docter_phone,$phone);
  591. if ($callModel['Code']=="OK"){
  592. return out($callModel['SecretBindDTO']['SecretNo']);
  593. }
  594. }else{
  595. return out('',500,'患者电话不存在');
  596. }
  597. }
  598. }
  599. }
  600. }else{
  601. if ($phone){
  602. $callModel = $commons->BindAxb($docter_phone,$phone);
  603. if ($callModel['Code']=="OK"){
  604. Axb::create([
  605. 'docter_id'=>$docter_id,
  606. 'user_id'=>$req['user_id'],
  607. 'xphone'=>$callModel['SecretBindDTO']['SecretNo'],
  608. 'createtime'=>time(),
  609. ]);
  610. return out($callModel['SecretBindDTO']['SecretNo']);
  611. }else{
  612. return out($callModel);
  613. }
  614. }else{
  615. return out('',500,'患者电话不存在');
  616. }
  617. }
  618. }
  619. }