DoctorController.php 97 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Yuanhang Liu & Xiaoyun Liu
  5. * Date: 20-10-14
  6. * Time: 下午2:50
  7. */
  8. namespace App\Http\Controllers\Api\V2;
  9. use App\Http\Controllers\Api\V1\AuthController;
  10. use App\Models\Docter;
  11. use App\Models\Office;
  12. use App\Models\Order;
  13. use App\Models\OrderPack;
  14. use App\Models\OrderPatient;
  15. use App\Models\Patient;
  16. use App\Models\Qualification;
  17. use App\Models\Suggest;
  18. use App\Models\Areas;
  19. use App\Models\Collection as Collections;
  20. use App\Models\Organization;
  21. use App\Models\DocterTimes;
  22. use App\Models\DocterOrganization;
  23. use App\Http\Controllers\Api\V2\CommonController as Commons;
  24. use App\Models\Team;
  25. use App\Models\User;
  26. use Illuminate\Support\Facades\DB;
  27. use MongoDB\BSON\ObjectId;
  28. use PhpParser\Comment\Doc;
  29. use App\Models\DocterUser;
  30. use App\Models\Schedule;
  31. use App\Models\TimePeriod;
  32. use App\Models\SchedulePeriod;
  33. use App\Models\DocterMessage;
  34. use App\Models\Evaluate;
  35. use App\Models\UserDocter;
  36. use App\Models\ServiceApply;
  37. use App\Models\SystemConfig;
  38. use App\Models\WeekSchedule;
  39. use App\Models\SelfSchedule;
  40. use App\Models\DocterSetting;
  41. use App\Models\DocterServiceTimes;
  42. use App\Models\CallLog;
  43. use App\Models\ImMessage;
  44. use App\Models\DocterLable;
  45. use App\Models\SchedueFlags as Sflag;
  46. /**
  47. * 医生相关类
  48. * Auth Yuanhang Liu
  49. * Date 2020/10/14 15:06
  50. * Class DoctorController
  51. * @package App\Http\Controllers\Api\V2
  52. */
  53. class DoctorController extends AuthController
  54. {
  55. /**service_schedule
  56. * @return \Illuminate\Http\JsonResponse
  57. * 首页医生个人信息接口
  58. */
  59. public function doctorInfor()
  60. {
  61. $req = $this->user;
  62. $data = Docter::where('phone', $req['phone'])->first(['id', 'name', 'avatar', 'label', 'sign', 'intro', 'service_days', 'service_persons','password', 'eva_num', 'score', 'is_then', 'created_at']);
  63. if (!empty($data)) {
  64. // 获取标签
  65. $LabFind = [];
  66. if ($data['label']!='无'){
  67. if(count($data['label'])!=0){
  68. $labstr = $data['label'];
  69. $LabFind = DocterLable::whereIn('id',$labstr)->where('status',1)->select('label_name')->get();
  70. }
  71. }
  72. $data['label'] = $LabFind;
  73. // $counts = Evaluate::where('docter_id', '=', $req['id'])->count();
  74. $evalList = Evaluate::where('docter_id', '=', $req['id'])->get();
  75. $counts = count($evalList);
  76. $data['eva_num'] = $counts;
  77. $soc = 0;
  78. if ($counts != 0) {
  79. $evalList = $evalList->toArray();
  80. foreach ($evalList as $k => $v) {
  81. $soc += $v['score'];
  82. }
  83. $data['score'] = upDecimal($soc / $counts, 1);
  84. }
  85. $data['service_days'] = numDays(date('Y-m-d', strtotime($data['created_at'])));
  86. return out($data);
  87. } else {
  88. return exit_out($data, 1, '参数错误,数据不存在');
  89. }
  90. }
  91. /**
  92. * 医生端个人信息修改
  93. * @return mixed
  94. */
  95. public function doctorInfoEdit()
  96. {
  97. $user = $this->user;
  98. $doctor_id = $user['id'];
  99. if (request()->isMethod('post')) {
  100. $req = request()->post();
  101. $this->validate(request(), [
  102. 'avatar' => 'string',
  103. 'sign' => 'max:255',
  104. // 'phone|手机号不正确' => 'regex:/^1[3456789][0-9]{9}$/',
  105. 'intro' => 'max:2555'
  106. ]);
  107. $data = [];
  108. if (isset($req['avatar']) && !empty($req['avatar'])) {
  109. $data['avatar'] = $req['avatar'];
  110. }
  111. if (isset($req['sign']) && !empty($req['sign'])) {
  112. $data['sign'] = $req['sign'];
  113. }
  114. if (isset($req['intro']) && !empty($req['intro'])) {
  115. $data['intro'] = $req['intro'];
  116. }
  117. if (empty($data)) {
  118. return out();
  119. }
  120. if ($doctor_id) {
  121. $save = Docter::where('id', $doctor_id)->update($data);
  122. return out();
  123. }
  124. } else {
  125. // get提交哈
  126. $list = Docter::where('id', '=', $doctor_id)->first()->toArray();
  127. // 头像,个人标签,服务简介展示
  128. $data = [
  129. 'avatar' => !empty($list['avatar'])?$list['avatar']:'',
  130. 'sign' => !empty($list['sign'])?$list['sign']:'',
  131. 'intro' => !empty($list['intro'])?$list['intro']:'',
  132. ];
  133. return out($data);
  134. }
  135. }
  136. /**
  137. * 修改密码
  138. * @return \Illuminate\Http\JsonResponse
  139. * @author Liu-Yh
  140. * Create By 2020/11/4 18:19
  141. */
  142. public function passwordEdit()
  143. {
  144. $user = $this->user;
  145. $doctor_id = $user['id'];
  146. $req = request()->post();
  147. $this->validate(request(), [
  148. 'lis:原密码' => 'string',
  149. 'newpassword:新密码' => 'string',
  150. ]);
  151. $data = [];
  152. $data = Docter::where('id', '=', $doctor_id)->first()->toArray();
  153. $password = md5(md5(md5($req['newpassword'])));
  154. if ($data['password'] == '' || !$data['password']) {
  155. // 说明第一次直接跳过
  156. $save = Docter::where('id', $doctor_id)->update(['password' => $password]);
  157. return out();
  158. } else {
  159. if(isset($req['lis'])&&!empty($req['lis'])){
  160. $oldpassword = md5(md5(md5($req['lis'])));
  161. if ($oldpassword != $data['password']) {
  162. return out('', '401', '旧密码错误');
  163. } else {
  164. $save = Docter::where('id', $doctor_id)->update(['password' => $password]);
  165. return out();
  166. }
  167. }else{
  168. return out('', '401', '请输入旧密码');
  169. }
  170. }
  171. }
  172. /**
  173. * 获取基本设置
  174. * @return mixed
  175. */
  176. public function getSettingBase(){
  177. $user = $this->user;
  178. $doctor_id = (new Commons)->getUserIdByDoctorId($user['phone']);
  179. $finds = Docter::select(['is_chat', 'is_phone', 'is_appoint'])->where('id', $doctor_id)->first()->toArray();
  180. $finds['is_chat'] = $finds['is_chat'] == 0 ? false : true;
  181. $finds['is_phone'] = $finds['is_phone'] == 0 ? false : true;
  182. $finds['is_appoint'] = $finds['is_appoint'] == 0 ? false : true;
  183. $finds['is_chat_status'] = $this->getStyStatus(1);
  184. $finds['is_phone_status'] = $this->getStyStatus(2);
  185. $finds['is_appoint_status'] = $this->getStyStatus(3);
  186. return out($finds);
  187. }
  188. /**
  189. * 获取图文设置
  190. * @return mixed
  191. */
  192. public function getSettingChat(){
  193. $user = $this->user;
  194. $doctor_id = $user['id'];
  195. (array)$list = [];
  196. $finds = Docter::select(['is_chat', 'is_phone', 'is_appoint'])->where('id', $doctor_id)->first()->toArray();
  197. $list['is_chat'] = $finds['is_chat'] == 0 ? false : true;
  198. // 图文咨询时间
  199. $pic_fins = DocterTimes::where(['docter_id' => $doctor_id, 'type' => 2])->first();
  200. if ($pic_fins) {
  201. $pic_fins = $pic_fins->toArray();
  202. $pic_fins['service_time'] = json_decode($pic_fins['service_time']);
  203. } else {
  204. $pic_fins = [];
  205. }
  206. $list['list'] = $pic_fins;
  207. return out($list);
  208. }
  209. /**
  210. * 获取电话的设置
  211. * @return mixed
  212. */
  213. public function getSettingPhone(){
  214. $user = $this->user;
  215. $doctor_id = $user['id'];
  216. (array)$list = [];
  217. $finds = Docter::select(['is_chat', 'is_phone', 'is_appoint'])->where('id', $doctor_id)->first()->toArray();
  218. $list['is_phone'] = $finds['is_phone'] == 0 ? false : true;
  219. // 图文咨询时间
  220. $phone_fins = DocterTimes::where(['docter_id' => $doctor_id, 'type' => 1])->first();
  221. if ($phone_fins) {
  222. $phone_fins = $phone_fins->toArray();
  223. $phone_fins['service_time'] = json_decode($phone_fins['service_time']);
  224. } else {
  225. $phone_fins = [];
  226. }
  227. $list['list'] = $phone_fins;
  228. return out($list);
  229. }
  230. /**
  231. * 获取门诊的设置
  232. * @return mixed
  233. */
  234. public function getSettingSchedule(){
  235. $user = $this->user;
  236. $doctor_id = $user['id'];
  237. (array)$list = [];
  238. $finds = Docter::select(['is_chat', 'is_phone', 'is_appoint'])->where('id', $doctor_id)->first()->toArray();
  239. $list['is_schedule'] = $finds['is_appoint'] == 0 ? false : true;
  240. $newLists=[];
  241. $men_fins = DocterSetting::where(['docter_id' => $doctor_id, 'type' => 1])->orderBy('org_id','asc')->get();
  242. $org = DocterOrganization::with('organization')->where(['docter_id'=>$doctor_id,'state'=>1])->orderBy('organization_id','asc')->get();
  243. if ($org) {
  244. $org = $org->toArray();
  245. foreach ($org as $k => $v) {
  246. $org_pre[$k]['id'] = $v['organization']['id'];
  247. $org_pre[$k]['name'] = $v['organization']['name'];
  248. }
  249. }
  250. if ($men_fins) {
  251. $men_fins = $men_fins->toArray();
  252. foreach ($men_fins as $k => $v) {
  253. $men_fins[$k]['service_time'] = json_decode($v['service_time'],true);
  254. }
  255. $org_list=[];
  256. foreach ($org as $k=>$v){
  257. $org_list[$k]['docter_id'] = $doctor_id;
  258. $org_list[$k]['type'] = 1;
  259. $org_list[$k]['status'] = 2;
  260. $org_list[$k]['show_days'] = '';
  261. $org_list[$k]['service_times'] = '';
  262. $org_list[$k]['service_num'] = '';
  263. $org_list[$k]['org_id'] = $v['organization']['id'];
  264. $org_list[$k]['org_name'] = $v['organization']['name'];
  265. $org_list[$k]['appoint_price'] = '';
  266. $org_list[$k]['service_time'] = [
  267. 1=>['amStartTime'=>'','amEndTime'=>'','amPerson'=>''],
  268. 2=>['pmStartTime'=>'','pmEndTime'=>'','pmPerson'=>''],
  269. 3=>['nightStartTime'=>'','nightEndTime'=>'','nightPerson'=>''],
  270. ];
  271. }
  272. foreach ($org_list as $k=>$v){
  273. foreach ($men_fins as $kk=>$vv){
  274. if ($v['org_id']==$vv['org_id']){
  275. $org_list[$k]['docter_id'] = $doctor_id;
  276. $org_list[$k]['type'] = 1;
  277. $org_list[$k]['status'] = 2;
  278. $org_list[$k]['show_days'] = $vv['show_days'];
  279. $org_list[$k]['service_times'] = $vv['service_times'];
  280. $org_list[$k]['service_num'] = $vv['service_num'];
  281. $org_list[$k]['org_id'] = $vv['org_id'];
  282. $org_list[$k]['org_name'] = $v['org_name'];
  283. $org_list[$k]['appoint_price'] = $vv['appoint_price'];
  284. $org_list[$k]['service_time'] = [
  285. 1=>['amStartTime'=>$vv['service_time'][1]['amStartTime'],'amEndTime'=>$vv['service_time'][1]['amEndTime'],'amPerson'=>$vv['service_time'][1]['amPerson']],
  286. 2=>['pmStartTime'=>$vv['service_time'][2]['pmStartTime'],'pmEndTime'=>$vv['service_time'][2]['pmEndTime'],'pmPerson'=>$vv['service_time'][2]['pmPerson']],
  287. 3=>['nightStartTime'=>$vv['service_time'][3]['nightStartTime'],'nightEndTime'=>$vv['service_time'][3]['nightEndTime'],'nightPerson'=>$vv['service_time'][3]['nightPerson']],
  288. ];
  289. }
  290. }
  291. }
  292. $newLists = $org_list;
  293. } else {
  294. $men_fins = [];
  295. foreach ($org as $k=>$v){
  296. $newLists[$k]['docter_id'] = $doctor_id;
  297. $newLists[$k]['type'] = 1;
  298. $newLists[$k]['status'] = 2;
  299. $newLists[$k]['show_days'] = '';
  300. $newLists[$k]['service_times'] = '';
  301. $newLists[$k]['service_num'] = '';
  302. $newLists[$k]['org_id'] = $v['organization']['id'];
  303. $newLists[$k]['org_name'] = $v['organization']['name'];
  304. $newLists[$k]['appoint_price'] = '';
  305. $newLists[$k]['service_time'] = [
  306. 1=>['amStartTime'=>'','amEndTime'=>'','amPerson'=>''],
  307. 2=>['pmStartTime'=>'','pmEndTime'=>'','pmPerson'=>''],
  308. 3=>['nightStartTime'=>'','nightEndTime'=>'','nightPerson'=>''],
  309. ];
  310. }
  311. }
  312. $list['list'] = $newLists;
  313. return out($list);
  314. }
  315. /**
  316. * 获取审核状态
  317. * @param $type
  318. * @return bool
  319. */
  320. public function getStyStatus($type)
  321. {
  322. $user = $this->user;
  323. $doctor_id = $user['id'];
  324. $where['docter_id'] = $doctor_id;
  325. $where['service_type'] = $type;
  326. $statusD = ServiceApply::where($where)->first();
  327. if ($statusD) {
  328. return $statusD;
  329. } else {
  330. return false;
  331. }
  332. }
  333. /**
  334. * 修改基本设置
  335. * @return mixed
  336. */
  337. public function saveSettingBase(){
  338. $req = request()->post();
  339. $data = json_decode($req['data'], true);
  340. $user = $this->user;
  341. $doctor_id = $user['id'];
  342. $list = [];
  343. isset($data['is_chat']) ? $data['is_chat'] == true ? $list['is_chat'] = 1 : $list['is_chat'] = 0 : '';
  344. isset($data['is_phone']) ? $data['is_phone'] == true ? $list['is_phone'] = 1 : $list['is_phone'] = 0 : '';
  345. isset($data['is_appoint']) ? $data['is_appoint'] == true ? $list['is_appoint'] = 1 : $list['is_appoint'] = 0 : '';
  346. Docter::where('id', $doctor_id)->update($list);
  347. return out();
  348. }
  349. /**
  350. * 修改图文设置
  351. */
  352. public function saveSettingChat(){
  353. $req = request()->post();
  354. $data = json_decode($req['data'], true);
  355. $user = $this->user;
  356. $doctor_id = $user['id'];
  357. $finds = Docter::select(['is_chat', 'is_phone', 'is_appoint'])->where('id', $doctor_id)->first();
  358. Db::beginTransaction();
  359. try {
  360. // 修改更多信息
  361. if ($finds['is_chat'] == 0) {
  362. if (isset($data['is_chat']) && !empty($data['is_chat'])) {
  363. return out('', 500, '您未开启图文');
  364. unset($data['is_chat']);
  365. }
  366. } else {
  367. if (isset($data['is_chat']) && !empty($data['is_chat'])) {
  368. DocterServiceTimes::where(['docter_id'=>$doctor_id,'type'=>2])->delete();
  369. $save_data = $data['is_chat'];
  370. $newData = [];
  371. $serviceData = [];
  372. $newData['base_price'] = $save_data['base_price'];
  373. $newData['step_price'] = $save_data['step_price'];
  374. $serviceData[0]['docter_id']=$doctor_id;
  375. $serviceData[0]['type']=2;
  376. $serviceData[0]['start_time_period']=$save_data['amStartTime'];
  377. $serviceData[0]['end_time_period']=$save_data['amEndTime'];
  378. $serviceData[0]['start_time_line']=str_replace(':','',$save_data['amStartTime']);
  379. $serviceData[0]['end_time_line']=str_replace(':','',$save_data['amEndTime']);
  380. $serviceData[1]['docter_id']=$doctor_id;
  381. $serviceData[1]['type']=2;
  382. $serviceData[1]['start_time_period']=$save_data['pmStartTime'];
  383. $serviceData[1]['end_time_period']=$save_data['pmEndTime'];
  384. $serviceData[1]['start_time_line']=str_replace(':','',$save_data['pmStartTime']);
  385. $serviceData[1]['end_time_line']=str_replace(':','',$save_data['pmEndTime']);
  386. $serviceData[2]['docter_id']=$doctor_id;
  387. $serviceData[2]['type']=2;
  388. $serviceData[2]['start_time_period']=$save_data['nightStartTime'];
  389. $serviceData[2]['end_time_period']=$save_data['nightEndTime'];
  390. $serviceData[2]['start_time_line']=str_replace(':','',$save_data['nightStartTime']);
  391. $serviceData[2]['end_time_line']=str_replace(':','',$save_data['nightEndTime']);
  392. $service_times = [
  393. 1 => ['amStartTime' => $save_data['amStartTime'], 'amEndTime' => $save_data['amEndTime']],
  394. 2 => ['pmStartTime' => $save_data['pmStartTime'], 'pmEndTime' => $save_data['pmEndTime']],
  395. 3 => ['nightStartTime' => $save_data['nightStartTime'], 'nightEndTime' => $save_data['nightEndTime']],
  396. ];
  397. $newData['service_time'] = json_encode($service_times, JSON_UNESCAPED_UNICODE);
  398. $newData['person'] = $save_data['person'];
  399. $newData['type'] = $save_data['type'];
  400. $pic_fins = DocterTimes::where(['docter_id' => $doctor_id, 'type' => 2])->first();
  401. DocterServiceTimes::insert($serviceData);
  402. if (empty($pic_fins)) {
  403. $newData['docter_id'] = $doctor_id;
  404. DocterTimes::create($newData);
  405. } else {
  406. $pic_fins = $pic_fins->toArray();
  407. DocterTimes::where(['id' => $pic_fins['id']])->update($newData);
  408. }
  409. }
  410. }
  411. DB::commit();
  412. return out();
  413. } catch (\Exception $e) {
  414. DB::rollBack();
  415. return out('', 500, $e->getMessage());
  416. } catch (\PDOException $e) {
  417. DB::rollBack();
  418. return out('', 500, $e->getMessage());
  419. }
  420. }
  421. /**
  422. * 电话设置修改
  423. * @return mixed
  424. * @throws \Exception
  425. */
  426. public function saveSettingPhone(){
  427. $req = request()->post();
  428. $data = json_decode($req['data'], true);
  429. $user = $this->user;
  430. $doctor_id = $user['id'];
  431. $finds = Docter::select(['is_chat', 'is_phone', 'is_appoint'])->where('id', $doctor_id)->first();
  432. Db::beginTransaction();
  433. try {
  434. if ($finds['is_phone'] == 0) {
  435. if (isset($data['is_phone']) && !empty($data['is_phone'])) {
  436. return out('', 500, '您未开启电话');
  437. unset($data['is_phone']);
  438. }
  439. } else {
  440. if (isset($data['is_phone']) && !empty($data['is_phone'])) {
  441. // 存入状态为1的操作
  442. DocterServiceTimes::where(['docter_id'=>$doctor_id,'type'=>1])->delete();
  443. $save_data = $data['is_phone'];
  444. $newData = [];
  445. $serviceData = [];
  446. $newData['base_price'] = $save_data['base_price'];
  447. $newData['step_price'] = $save_data['step_price'];
  448. $serviceData[0]['docter_id']=$doctor_id;
  449. $serviceData[0]['type']=1;
  450. $serviceData[0]['start_time_period']=$save_data['amStartTime'];
  451. $serviceData[0]['end_time_period']=$save_data['amEndTime'];
  452. $serviceData[0]['start_time_line']=str_replace(':','',$save_data['amStartTime']);
  453. $serviceData[0]['end_time_line']=str_replace(':','',$save_data['amEndTime']);
  454. $serviceData[1]['docter_id']=$doctor_id;
  455. $serviceData[1]['type']=1;
  456. $serviceData[1]['start_time_period']=$save_data['pmStartTime'];
  457. $serviceData[1]['end_time_period']=$save_data['pmEndTime'];
  458. $serviceData[1]['start_time_line']=str_replace(':','',$save_data['pmStartTime']);
  459. $serviceData[1]['end_time_line']=str_replace(':','',$save_data['pmEndTime']);
  460. $serviceData[2]['docter_id']=$doctor_id;
  461. $serviceData[2]['type']=1;
  462. $serviceData[2]['start_time_period']=$save_data['nightStartTime'];
  463. $serviceData[2]['end_time_period']=$save_data['nightEndTime'];
  464. $serviceData[2]['start_time_line']=str_replace(':','',$save_data['nightStartTime']);
  465. $serviceData[2]['end_time_line']=str_replace(':','',$save_data['nightEndTime']);
  466. $service_times = [
  467. 1 => ['amStartTime' => $save_data['amStartTime'], 'amEndTime' => $save_data['amEndTime']],
  468. 2 => ['pmStartTime' => $save_data['pmStartTime'], 'pmEndTime' => $save_data['pmEndTime']],
  469. 3 => ['nightStartTime' => $save_data['nightStartTime'], 'nightEndTime' => $save_data['nightEndTime']],
  470. ];
  471. $newData['service_time'] = json_encode($service_times, JSON_UNESCAPED_UNICODE);
  472. $newData['person'] = $save_data['person'];
  473. $newData['type'] = $save_data['type'];
  474. // 图文咨询时间
  475. $phone_fins = DocterTimes::where(['docter_id' => $doctor_id, 'type' => 1])->first();
  476. DocterServiceTimes::insert($serviceData);
  477. if (empty($phone_fins)) {
  478. $newData['docter_id'] = $doctor_id;
  479. DocterTimes::create($newData);
  480. } else {
  481. $phone_fins = $phone_fins->toArray();
  482. DocterTimes::where(['id' => $phone_fins['id']])->update($newData);
  483. }
  484. }
  485. }
  486. DB::commit();
  487. return out();
  488. } catch (\Exception $e) {
  489. DB::rollBack();
  490. return out('', 500, $e->getMessage());
  491. } catch (\PDOException $e) {
  492. DB::rollBack();
  493. return out('', 500, $e->getMessage());
  494. }
  495. }
  496. /**
  497. * 门诊设置修改
  498. * @return mixed
  499. * @throws \Exception
  500. */
  501. public function saveSettingSchedule(){
  502. $req = request()->post();
  503. $data = json_decode($req['data'], true);
  504. $user = $this->user;
  505. $doctor_id = $user['id'];
  506. $finds = Docter::select(['is_chat', 'is_phone', 'is_appoint'])->where('id', $doctor_id)->first();
  507. $flag = false;
  508. Db::beginTransaction();
  509. try {
  510. if ($finds['is_appoint'] == 0) {
  511. if (isset($data['is_appoint']) && !empty($data['is_appoint'])) {
  512. return out('', 500, '您未开启门诊');
  513. unset($data['is_appoint']);
  514. }
  515. } else {
  516. // 此时可能有两个医院,为一个数组,一个一个入库
  517. if (isset($data['is_appoint']) && !empty($data['is_appoint'])) {
  518. $save_data = $data['is_appoint'];
  519. $setting_data = [];
  520. $times_data = [];
  521. // 查询除本地来
  522. $edutime = DocterSetting::where(['docter_id' => $doctor_id, 'type' => 1])->get();
  523. if ($edutime) {
  524. $newedu = [];
  525. foreach ($edutime as $k => $v) {
  526. $newedu[$k]['org_id'] = $v['org_id'];
  527. $newedu[$k]['service_times'] = $v['service_times'];
  528. }
  529. $flag_arr = [];
  530. foreach ($newedu as $k => $v) {
  531. foreach ($save_data as $kk => $vv) {
  532. if ($v['org_id'] == $vv['org_id']) {
  533. if ($v['service_times'] != $vv['service_times']) {
  534. $flag_arr[] = $vv['org_id'];
  535. }
  536. }
  537. }
  538. }
  539. $flag = !empty($flag_arr) ? $flag_arr : false;
  540. }
  541. foreach ($save_data as $k => $v) {
  542. if (!isset($v['service_times'])||empty($v['service_times'])){
  543. unset($save_data[$k]);
  544. }else{
  545. DocterSetting::where('docter_id', '=', $doctor_id)->where('org_id', $v['org_id'])->delete();
  546. TimePeriod::where('docter_id', '=', $doctor_id)->where('org_id', $v['org_id'])->delete();
  547. $setting_data[$k]['docter_id'] = $doctor_id;
  548. $setting_data[$k]['type'] = 1;
  549. $setting_data[$k]['status'] = 2;
  550. $setting_data[$k]['appoint_price'] = $v['base_price'];
  551. $setting_data[$k]['show_days'] = $v['show_days'];
  552. $setting_data[$k]['service_times'] = $v['service_times'];
  553. $setting_data[$k]['service_num'] = $v['service_num'];
  554. $setting_data[$k]['org_id'] = $v['org_id'];
  555. $service_times = [
  556. 1 => ['amStartTime' => $v['amStartTime'], 'amEndTime' => $v['amEndTime'], 'amPerson' => $v['amPerson']],
  557. 2 => ['pmStartTime' => $v['pmStartTime'], 'pmEndTime' => $v['pmEndTime'], 'pmPerson' => $v['pmPerson']],
  558. 3 => ['nightStartTime' => $v['nightStartTime'], 'nightEndTime' => $v['nightEndTime'], 'nightPerson' => $v['nightPerson']],
  559. ];
  560. $setting_data[$k]['service_time'] = json_encode($service_times, JSON_UNESCAPED_UNICODE);
  561. $setting_data[$k]['created_at'] = date('Y-m-d H:i:s', time());
  562. $setting_data[$k]['updated_at'] = date('Y-m-d H:i:s', time());
  563. // 第二步, 根据时长去生成24小时的时间段,也要存id
  564. $timeList = $this->getTimeHoures($v['service_times']);
  565. foreach ($timeList as $kk => $vv) {
  566. $times_data[$k][$kk]['type'] = 1;
  567. $times_data[$k][$kk]['docter_id'] = $doctor_id;
  568. $times_data[$k][$kk]['start_time_period'] = $vv[0];
  569. $times_data[$k][$kk]['end_time_period'] = $vv[1];
  570. $times_data[$k][$kk]['org_id'] = $v['org_id'];
  571. }
  572. }
  573. }
  574. if($times_data&&$setting_data){
  575. foreach ($times_data as $k => $v) {
  576. TimePeriod::insert($v);
  577. }
  578. DocterSetting::insert($setting_data);
  579. }
  580. }
  581. }
  582. DB::commit();
  583. } catch (\Exception $e) {
  584. DB::rollBack();
  585. return out('', 500, $e->getMessage());
  586. } catch (\PDOException $e) {
  587. DB::rollBack();
  588. return out('', 500, $e->getMessage());
  589. }
  590. if ($finds['is_appoint'] != 0 && isset($data['is_appoint']) && !empty($data['is_appoint'])) {
  591. /*去重新更新,自定义排班表,和排班详情表,因为时间段id发生了变化!*/
  592. if ($flag != false) {
  593. Db::beginTransaction();
  594. try {
  595. $weekList = WeekSchedule::where('docter_id', $doctor_id)->get();
  596. $moth_date = $this->date_bool();
  597. $Wheres['schedule_type'] = 1;
  598. $Wheres['docter_id'] = $doctor_id;
  599. $counts = Schedule::where($Wheres)->whereBetween('schedule_date',[date('Y-m-d',time()),end($moth_date)['date']])->get();
  600. if ($weekList && $counts) {
  601. $wheres['docter_id'] = $doctor_id;
  602. $wheres['schedule_type'] = 1;
  603. $wheres[] = ['schedule_date','>=',date('Y-m-d',time())];
  604. $list = SchedulePeriod::where($wheres)->whereIn('organization_id', $flag)->orderBy('schedule_date','asc')->get();
  605. SchedulePeriod::where($wheres)->delete();
  606. if ($list) {
  607. $list = $list->toArray();
  608. $selfList = [];
  609. foreach ($list as $k => $v) {
  610. if (!isset($selfList[$v['schedule_date']])) {
  611. $selfList[$v['schedule_date']] = $v;
  612. if ($v['type'] == 1) {
  613. $selfList[$v['schedule_date']]['ident']['zao_id'] = $v['organization_id'];
  614. $selfList[$v['schedule_date']]['ident']['xia_id'] = 0;
  615. $selfList[$v['schedule_date']]['ident']['wan_id'] = 0;
  616. } else if ($v['type'] == 2) {
  617. $selfList[$v['schedule_date']]['ident']['zao_id'] = 0;
  618. $selfList[$v['schedule_date']]['ident']['xia_id'] = $v['organization_id'];
  619. $selfList[$v['schedule_date']]['ident']['wan_id'] = 0;
  620. } else {
  621. $selfList[$v['schedule_date']]['ident']['zao_id'] = 0;
  622. $selfList[$v['schedule_date']]['ident']['xia_id'] = 0;
  623. $selfList[$v['schedule_date']]['ident']['wan_id'] = $v['organization_id'];
  624. }
  625. } else {
  626. if ($v['type'] == 1) {
  627. $selfList[$v['schedule_date']]['ident']['zao_id'] = $v['organization_id'];
  628. } else if ($v['type'] == 2) {
  629. $selfList[$v['schedule_date']]['ident']['xia_id'] = $v['organization_id'];
  630. } else {
  631. $selfList[$v['schedule_date']]['ident']['wan_id'] = $v['organization_id'];
  632. }
  633. }
  634. }
  635. // 占用效率
  636. $scheduleLists = [];
  637. foreach ($counts as $kk => $vv) {
  638. foreach ($selfList as $k => $v) {
  639. if ($vv['schedule_date'] == $v['schedule_date']) {
  640. if ($v['ident']['zao_id']) {
  641. $times = $this->num_time($v['ident']['zao_id'], 1);
  642. if (!$times) {
  643. return out('', 500, "请先在排班设置中填写本机构的时间段");
  644. }
  645. $maf = $this->getMaf($vv['id'], $times, ['organization_id' => $v['ident']['zao_id'],'me_sure'=>$v['me_sure'],'schedule_date' => $v['schedule_date'], 'type' => 1], $doctor_id);
  646. if ($maf) {
  647. foreach ($maf as $os) {
  648. $scheduleLists[] = $os;
  649. }
  650. }
  651. }
  652. if ($v['ident']['xia_id']) {
  653. $times = $this->num_time($v['ident']['xia_id'], 2);
  654. if (!$times) {
  655. return out('', 500, "请先在排班设置中填写本机构的时间段");
  656. }
  657. $maf = $this->getMaf($vv['id'], $times, ['organization_id' => $v['ident']['xia_id'],'me_sure'=>$v['me_sure'],'schedule_date' => $v['schedule_date'], 'type' => 2], $doctor_id);
  658. if ($maf) {
  659. foreach ($maf as $os) {
  660. $scheduleLists[] = $os;
  661. }
  662. }
  663. }
  664. if ($v['ident']['wan_id']) {
  665. $times = $this->num_time($v['ident']['wan_id'], 3);
  666. if (!$times) {
  667. return out('', 500, "请先在排班设置中填写本机构的时间段");
  668. }
  669. $maf = $this->getMaf($vv['id'], $times, ['organization_id' => $v['ident']['wan_id'], 'me_sure'=>$v['me_sure'],'schedule_date' => $v['schedule_date'], 'type' => 3], $doctor_id);
  670. if ($maf) {
  671. foreach ($maf as $os) {
  672. $scheduleLists[] = $os;
  673. }
  674. }
  675. }
  676. }
  677. }
  678. }
  679. SchedulePeriod::insert($scheduleLists);
  680. }
  681. }
  682. DB::commit();
  683. } catch (\Exception $e) {
  684. DB::rollBack();
  685. return out('', 500, '2' . $$e->getMessage());
  686. } catch (\PDOException $e) {
  687. DB::rollBack();
  688. return out('', 500, '2' . $e->getMessage());
  689. }
  690. }
  691. }
  692. return out();
  693. }
  694. /**
  695. * 计算24小时的时间区间段
  696. * @param $minute 分钟比如:15
  697. * @return array
  698. */
  699. public function getTimeHoures($minute)
  700. {
  701. // 可选10分钟,15分钟,20分钟,30分钟,1个小时
  702. $start = strtotime(date("Y-m-d 00:00:00"));
  703. $end = strtotime(date("Y-m-d 23:59:59"));
  704. $returnArr = [];
  705. for ($time = $start; $time <= $end; $time = $time + $minute * 60) {
  706. array_push($returnArr, date("H:i", $time));
  707. }
  708. $newList = [];
  709. // for($i=0;$i<count($returnArr)-1;$i++){
  710. // $newList[$i]['start']=$returnArr[$i];
  711. // $newList[$i]['end']=$returnArr[$i+1];
  712. // }
  713. $k = 0;
  714. for ($i = 0; $i < (count($returnArr) * 2) - 1; $i++) {
  715. if ($i % 2 != 0) {
  716. if ($i != 0) {
  717. $k++;
  718. $newList[$k][0] = $returnArr[$k];
  719. }
  720. } else {
  721. if ($i != 0) {
  722. $newList[$k - 1][1] = $returnArr[$k];
  723. } else {
  724. $newList[$k][0] = $returnArr[$k];
  725. }
  726. }
  727. }
  728. $newList[count($newList) - 1][1] = $returnArr[0];
  729. return $newList;
  730. }
  731. /**
  732. * 提交认证
  733. * Auth:Yuanhang-Liu
  734. * Date:2020/10/14 15:08 *
  735. * @return \Illuminate\Http\JsonResponse
  736. */
  737. public function addthen()
  738. {
  739. $req = request()->post();
  740. $this->validate(request(), [
  741. 'name|医生姓名' => 'required|max:50',
  742. 'sex|性别' => 'required|in:男,女',
  743. 'ID|身份证号' => 'required|min:16|max:18',
  744. 'works|医院信息' => 'required',
  745. 'certificate|医生照片和执业证书' => 'required|string',
  746. 'idPhoto|身份证正反面' => 'required|string',
  747. 'doctorQualification|照片和资格证书' => 'required|string',
  748. ]);
  749. if ($req['sex'] == '男') {
  750. $req['sex'] = 1;
  751. } else {
  752. $req['sex'] = 2;
  753. }
  754. // 首先获取医生姓名,性别,身份证号,照片,身份证,资格证去补全医生表
  755. // 入库organization_ids这个数据是一条字符串,先分割成数组,如果只有一条则医生只选择了一个医院,机构id和医生id入库docter_organization(医生机构关联表)
  756. $user = $this->user;
  757. $doctor_id = $user['id'];
  758. if (!$doctor_id) {
  759. return out(null, 500, '医生信息错误!');
  760. }
  761. $data = [];
  762. $data['name'] = $req['name'];
  763. $data['sex'] = $req['sex'];
  764. $data['card_id'] = $req['ID'];
  765. $data['practice'] = $req['certificate'];
  766. $data['card_photo'] = $req['idPhoto'];
  767. $data['is_quail'] = $req['doctorQualification'];
  768. //处理医院机构id
  769. $work = json_decode($req['works'], true);
  770. if (!$work) {
  771. return out('', '', '缺少医院');
  772. }
  773. $off_then = DocterOrganization::where('docter_id', '=', $doctor_id)->get('id')->toArray();
  774. $is_del = false;
  775. if ($off_then) {
  776. $newids = [];
  777. foreach ($off_then as $k => $v) {
  778. $newids[$k] = $v['id'];
  779. }
  780. $is_del = true;
  781. }
  782. $org_list = [];
  783. foreach ($work as $k => $v) {
  784. if ($v['hospital']) {
  785. $org_list[$k]['docter_id'] = $doctor_id;
  786. $org_list[$k]['organization_id'] = $v['hospital'];
  787. $org_list[$k]['offices_id'] = $v['department'];
  788. $org_list[$k]['qualifications_id'] = $v['qualifications'];
  789. $org_list[$k]['state'] = $v['state'];
  790. }
  791. }
  792. DB::beginTransaction();//开启事务
  793. try {
  794. //补全医生表
  795. Docter::where('id', $doctor_id)->update($data);
  796. if ($is_del) {
  797. foreach ($newids as $k => $v) {
  798. DocterOrganization::where('id', $v)->delete();
  799. }
  800. }
  801. // 提交消息;
  802. DocterMessage::create([
  803. 'docter_id' => $doctor_id,
  804. 'status' => 1,
  805. 'type' => 8,
  806. 'content' => '您已提交医生资质认证审核材料 '
  807. ]);
  808. DocterOrganization::insertOrIgnore($org_list);
  809. DB::commit();//提交至数据库
  810. return out();
  811. } catch (\Exception $e) {
  812. DB::rollback();
  813. return out(null, 500, $e->getMessage());
  814. }
  815. }
  816. /**
  817. * Auth:Yuanhang-Liu
  818. * Date:2020/10/14 17:17 *
  819. * @return \Illuminate\Http\JsonResponse
  820. */
  821. public function get_city_id()
  822. {
  823. // 查询机构!
  824. $req = request()->post();
  825. $this->validate(request(), [
  826. 'level_type' => 'required|in:4',
  827. 'province|省或直辖市id' => 'required_if:level_type,==,4',
  828. 'city|市' => 'required_if:level_type,==,4',
  829. 'area|区' => 'required_if:level_type,==,4',
  830. ]);
  831. // 查找下医院
  832. // $ids_string = explode(',',$req['organizations_ids']);
  833. $province = trim($req['province']);
  834. $city = trim($req['city']);
  835. $area = trim($req['area']);
  836. $where['province_id'] = $province;
  837. $where['city_id'] = $city;
  838. $where['area_id'] = $area;
  839. $where['type'] = 1;
  840. $Organization = Organization::with('offices')->where($where)->get()->toArray();
  841. $qulire = Qualification::where('status', 1)->get();
  842. $newList = [];
  843. if ($Organization) {
  844. foreach ($Organization as $k => $v) {
  845. $newList[$k]['value'] = $v['id'];
  846. $newList[$k]['label'] = $v['name'];
  847. if ($v['offices']) {
  848. foreach ($v['offices'] as $kk => $vv) {
  849. $newList[$k]['children'][$kk]['value'] = $vv['id'];
  850. $newList[$k]['children'][$kk]['label'] = $vv['name'];
  851. if ($qulire) {
  852. foreach ($qulire as $p => $c) {
  853. $newList[$k]['children'][$kk]['children'][$p]['value'] = $c['id'];
  854. $newList[$k]['children'][$kk]['children'][$p]['label'] = $c['name'];
  855. }
  856. } else {
  857. unset($Organization[$k], $newList[$k]);
  858. }
  859. }
  860. } else {
  861. unset($Organization[$k], $newList[$k]);
  862. }
  863. }
  864. }
  865. return out($newList);
  866. }
  867. /**
  868. * 获取城市联动
  869. * @return \Illuminate\Http\JsonResponse
  870. * @author Liu-Yh
  871. * Create By 2020/11/4 19:35
  872. */
  873. public function getCityList()
  874. {
  875. // 查询机构!
  876. $req = request()->post();
  877. $where['status'] = 1;
  878. $data = Areas::where($where)->get(['id', 'name', 'level', 'parent_id'])->toArray();
  879. $newData = [];
  880. foreach ($data as $k => $v) {
  881. $newData[$k]['value'] = $v['id'];
  882. $newData[$k]['label'] = $v['name'];
  883. $newData[$k]['pid'] = $v['parent_id'];
  884. }
  885. $list = $this->getTrees($newData);
  886. $list = $this->getTree($list);
  887. return out($list);
  888. }
  889. /**
  890. * 获取城市树
  891. * @param $data
  892. * @return array
  893. */
  894. protected function getTrees($arr, $pid = 0)
  895. {
  896. static $list = [];
  897. foreach ($arr as $key => $value) {
  898. if ($value["pid"] == $pid) {
  899. $list[] = $value;
  900. unset($arr[$key]); //删除已经排好的数据为了减少遍历的次数,当然递归本身就很费神就是了
  901. $this->getTrees($arr, $value["value"]);
  902. }
  903. }
  904. return $list;
  905. }
  906. /**
  907. * 整合树🌲
  908. * @param $data
  909. * @param $pId
  910. * @return string
  911. */
  912. protected function getTree($data, $pId = 0)
  913. {
  914. $tree = [];
  915. foreach ($data as $k => $v) {
  916. if ($v['pid'] == $pId) { //父亲找到儿子
  917. $chid = $this->getTree($data, $v['value']);
  918. if ($chid) {
  919. $v['children'] = $chid;
  920. }
  921. $tree[] = $v;
  922. unset($data[$k]);
  923. } else {
  924. unset($data[$k]);
  925. }
  926. }
  927. return $tree;
  928. }
  929. /**
  930. * 获取科室和资质
  931. * @return mixed
  932. */
  933. public function getOfferList()
  934. {
  935. // 查询机构!
  936. $req = request()->post();
  937. $this->validate(request(), [
  938. 'type' => 'required|in:1,2',
  939. ]);//1=科室,2=资质
  940. $type = $req['type'];
  941. if ($type == 1) {
  942. $List = Office::get(['id', 'name'])->toArray();
  943. } else if ($type == 2) {
  944. $List = Qualification::get(['id', 'name'])->toArray();
  945. } else {
  946. return out('', '', '错误请求');
  947. }
  948. return out($List);
  949. }
  950. /**
  951. * 获取我的患者列表
  952. * Auth:Yuanhang-Liu
  953. * Date:2020/10/17 13:21
  954. * @return \Illuminate\Http\JsonResponse
  955. */
  956. public function userList()
  957. {
  958. $req = request()->post();
  959. $this->validate(request(), [
  960. 'userId' => 'integer',
  961. 'userType|用户类型' => 'integer|in:1,2,3,4,5,6,7',
  962. ]);
  963. $user = $this->user;
  964. $doctor_id = $user['id'];
  965. if (!$doctor_id) {
  966. return out(null, 500, '医生信息错误!');
  967. }
  968. $returnList = [];
  969. $orderList = Order::with(['user'])->where('docter_id', '=', $doctor_id)->groupBy('id', 'product_type', 'user_id')->get()->toArray();
  970. $collections = DocterUser::with('user')->where('docter_id', '=', $doctor_id)->groupBy('user_id')->get()->toArray();
  971. $newList = [];
  972. foreach ($orderList as $k => $v) {
  973. $newList[$k]['order_id'] = $v['id'];
  974. $newList[$k]['user_id'] = $v['user_id'];
  975. $newList[$k]['order_sn'] = $v['order_sn'];
  976. $newList[$k]['nickname'] = $v['user']['nickname'];
  977. $save = UserDocter::where('user_id', '=', $v['user']['id'])->first();
  978. if ($save) {
  979. $newList[$k]['remark'] = $save['remark'];
  980. } else {
  981. $newList[$k]['remark'] = '';
  982. }
  983. $newList[$k]['avatar'] = $v['user']['avatar'];
  984. $newList[$k]['product_type'] = $v['product_type'];
  985. }
  986. $newcoll = [];
  987. foreach ($collections as $k => $v) {
  988. $newcoll[$k]['id'] = $v['id'];
  989. $newcoll[$k]['user_id'] = $v['user_id'];
  990. $newcoll[$k]['nickname'] = $v['user']['nickname'];
  991. $save = UserDocter::where('user_id', '=', $v['user_id'])->first();
  992. if ($save) {
  993. $newList[$k]['remark'] = $save['remark'];
  994. } else {
  995. $newList[$k]['remark'] = '';
  996. }
  997. $newcoll[$k]['avatar'] = $v['user']['avatar'];
  998. }
  999. $user_pic = [];
  1000. $user_relation = [];
  1001. $user_vaccines = [];
  1002. $user_guar = [];
  1003. $user_pack = [];
  1004. foreach ($newList as $k => $v) {
  1005. if ($v['product_type'] == 1 || $v['product_type'] == 2) {
  1006. // 咨询患者
  1007. if (!$this->putusers($user_pic, $v['user_id'])) {
  1008. array_push($user_pic, $v);
  1009. }
  1010. }
  1011. if ($v['product_type'] == 3) {
  1012. // 门诊患者
  1013. if (!$this->putusers($user_relation, $v['user_id'])) {
  1014. array_push($user_relation, $v);
  1015. }
  1016. }
  1017. if ($v['product_type'] == 4) {
  1018. // 疫苗患者
  1019. if (!$this->putusers($user_vaccines, $v['user_id'])) {
  1020. array_push($user_vaccines, $v);
  1021. }
  1022. }
  1023. if ($v['product_type'] == 5) {
  1024. // 儿保预约
  1025. if (!$this->putusers($user_guar, $v['user_id'])) {
  1026. array_push($user_guar, $v);
  1027. }
  1028. }
  1029. if ($v['product_type'] == 6) {
  1030. // 服务包
  1031. $OrderPacks = OrderPack::where('order_id', '=', $v['order_id'])->first();
  1032. if ($OrderPacks) {
  1033. $teams = Team::with('docter')->where('id', '=', $OrderPacks['team_id'])->first();
  1034. if ($teams) {
  1035. $teams = $teams->toArray();
  1036. if ($teams['docter']) {
  1037. foreach ($teams['docter'] as $kk => $vv) {
  1038. if ($vv['id'] == $doctor_id) {
  1039. array_push($user_pack, $v);
  1040. }
  1041. }
  1042. }
  1043. }
  1044. }
  1045. }
  1046. }
  1047. $returnList['user_pic']['data'] = $user_pic;
  1048. $returnList['user_relation']['data'] = $user_relation;
  1049. $returnList['user_vaccines']['data'] = $user_vaccines;
  1050. $returnList['user_guar']['data'] = $user_guar;
  1051. $returnList['user_pack']['data'] = $user_pack;
  1052. if (empty($newcoll)) {
  1053. // 关注患者
  1054. $returnList['user_collection']['data'] = [];
  1055. } else {
  1056. $returnList['user_collection']['data'] = $newcoll;
  1057. }
  1058. $returnList['user_pic']['count'] = count($user_pic);
  1059. $returnList['user_relation']['count'] = count($user_relation);
  1060. $returnList['user_vaccines']['count'] = count($user_vaccines);
  1061. $returnList['user_guar']['count'] = count($user_guar);
  1062. $returnList['user_pack']['count'] = count($user_pack);
  1063. $returnList['user_collection']['count'] = count($returnList['user_collection']['data']);
  1064. return out($returnList);
  1065. }
  1066. /**
  1067. * 升级版 in_array
  1068. * @param $data1
  1069. * @param $data2
  1070. * @return bool
  1071. * @author Liu-Yh
  1072. * Create By 2020/11/27 16:18
  1073. */
  1074. protected function putusers($data1, $data2)
  1075. {
  1076. if (empty($data1)) {
  1077. return false;
  1078. }
  1079. $list = [];
  1080. foreach ($data1 as $k => $v) {
  1081. array_push($list, $v['user_id']);
  1082. }
  1083. if (in_array($data2, $list)) {
  1084. return true;
  1085. } else {
  1086. return false;
  1087. }
  1088. }
  1089. /**
  1090. * 上备注
  1091. * @return \Illuminate\Http\JsonResponse
  1092. * @author Liu-Yh
  1093. * Create By 2020/11/27 16:16
  1094. */
  1095. public function remacks()
  1096. {
  1097. $req = request()->post();
  1098. $this->validate(request(), [
  1099. 'remak|备注' => 'required',
  1100. 'id|id' => 'required',
  1101. ]);
  1102. $user = $this->user;
  1103. $user_id = $user['id'];
  1104. $wheres['docter_id'] = $user_id;
  1105. $wheres['user_id'] = $req['id'];
  1106. $save = UserDocter::where($wheres)->first();
  1107. if ($save) {
  1108. UserDocter::where('id', '=', $save['id'])->update([
  1109. 'remark' => $req['remak']
  1110. ]);
  1111. } else {
  1112. UserDocter::create([
  1113. 'docter_id' => $user_id,
  1114. 'user_id' => $req['id'],
  1115. 'remark' => $req['remak']
  1116. ]);
  1117. }
  1118. return out([]);
  1119. }
  1120. /**
  1121. * 评价列表
  1122. * @return \Illuminate\Http\JsonResponse
  1123. * @author Liu-Yh
  1124. * Create By 2020/11/17 17:41
  1125. */
  1126. public function evaluate()
  1127. {
  1128. $req = request()->post();
  1129. $this->validate(request(), [
  1130. 'curPage' => 'required|integer',
  1131. 'pageSize' => 'required|integer',
  1132. ]);
  1133. $pageSize = ($req['curPage'] - 1) * $req['pageSize'];
  1134. $user = $this->user;
  1135. $doctor_id = $user['id'];
  1136. $wheres['docter_id'] = $doctor_id;
  1137. $wheres['status'] = 2;
  1138. $data = Evaluate::with(['order', 'user'])->where($wheres)->skip($pageSize)->take($req['pageSize'])->groupBy('id')->get()->toArray();;
  1139. if ($data) {
  1140. $newList = [];
  1141. foreach ($data as $k => $v) {
  1142. $newList[$k]['order_id'] = $v['order']['order_sn'];
  1143. $newList[$k]['user'] = $v['user']['nickname'];
  1144. $newList[$k]['lv'] = $v['score'];
  1145. $newList[$k]['time'] = $v['created_at'];
  1146. $newList[$k]['evaluate'] = $v['content'];
  1147. }
  1148. return out($newList);
  1149. } else {
  1150. return out([]);
  1151. }
  1152. }
  1153. /**
  1154. * 我的列表进入详情
  1155. * Auth:Yuanhang-Liu
  1156. * Date:2020/10/18 15:21
  1157. * @return \Illuminate\Http\JsonResponse
  1158. */
  1159. public function userListDetile()
  1160. {
  1161. $req = request()->post();
  1162. $this->validate(request(), [
  1163. 'user_id|用户ID' => 'required|integer',
  1164. 'userType|用户类型' => 'integer|in:1,2,3,4,5,6,7',
  1165. ]);
  1166. $user = $this->user;
  1167. // 查询详情;
  1168. $finds_patient = User::with('patients')->where('id', '=', $req['user_id'])->first();
  1169. $remarks = UserDocter::where('user_id', '=', $req['user_id'])->first();
  1170. $finds_order = Order::with('orderPatient')->where('user_id', '=', $req['user_id'])->orderBy('created_at', 'desc')->limit(3)->get();
  1171. if ($finds_order) {
  1172. $finds_order = $finds_order->toArray();
  1173. }
  1174. $userArr = $patientsArr = $orderArr = $fuwArr = [];
  1175. $patientsArr = [];
  1176. $ws['user_id'] = $req['user_id'];
  1177. $ws['product_type'] = 6;
  1178. $fuw_order = Order::with('orderPack')->where($ws)->orderBy('created_at', 'desc')->get();
  1179. if ($fuw_order) {
  1180. $fuw_order = $fuw_order->toArray();
  1181. // var_dump($fuw_order);
  1182. foreach ($fuw_order as $kk => $vv) {
  1183. $fuwArr[$kk]['order_id'] = $vv['id'];
  1184. if ($vv['order_pack']) {
  1185. // foreach ($vv['order_pack'] as $k => $v) {
  1186. $fuwArr[$kk]['id'] = $vv['order_pack']['id'];
  1187. $fuwArr[$kk]['pack_name'] = $vv['order_pack']['pack_name'];
  1188. $fuwArr[$kk]['pack_intro'] = $vv['order_pack']['pack_intro'];
  1189. $fuwArr[$kk]['pack_price'] = $vv['order_pack']['pack_price'];
  1190. $fuwArr[$kk]['effective_days'] = $vv['order_pack']['effective_days'];
  1191. $fuwArr[$kk]['start_time'] = date('Y-m-d,H:i', $vv['order_pack']['start_time']);
  1192. $fuwArr[$kk]['end_time'] = date('Y-m-d,H:i', $vv['order_pack']['end_time']);
  1193. // }
  1194. }
  1195. }
  1196. }
  1197. if ($finds_patient) {
  1198. $finds_patient = $finds_patient->toArray();
  1199. $userArr['id'] = $finds_patient['id'];
  1200. if ($remarks) {
  1201. $userArr['remark'] = $remarks['remark']; //用户备注
  1202. } else {
  1203. $userArr['remark'] = ''; //用户备注
  1204. }
  1205. $userArr['nickname'] = $finds_patient['nickname'];
  1206. $userArr['avatar'] = $finds_patient['avatar'];
  1207. if ($finds_patient['patients']) {
  1208. foreach ($finds_patient['patients'] as $kk => $vv) {
  1209. $patientsArr[$kk]['id'] = $vv['id'];
  1210. $patientsArr[$kk]['avatar'] = $vv['avatar'];
  1211. $patientsArr[$kk]['name'] = $vv['name'];
  1212. if ($vv['sex'] == 0) {
  1213. $patientsArr[$kk]['sex'] = '未知';
  1214. } elseif ($vv['sex'] == 1) {
  1215. $patientsArr[$kk]['sex'] = '男';
  1216. } else {
  1217. $patientsArr[$kk]['sex'] = '女';
  1218. }
  1219. $patientsArr[$kk]['age'] = numBirthday($vv['birthday']);
  1220. }
  1221. }
  1222. }
  1223. if ($finds_order) {
  1224. foreach ($finds_order as $k => $v) {
  1225. $orderArr[$k]['id'] = $v['id'];
  1226. $orderArr[$k]['order_sn'] = $v['order_sn'];
  1227. if ($v['order_status'] >= 4) {
  1228. $orderArr[$k]['receiving_time'] = date('Y-m-d H:i', $v['receiving_time']);
  1229. $orderArr[$k]['outtime'] = date('Y-m-d H:i', $v['end_time']);
  1230. } else {
  1231. $orderArr[$k]['receiving_time'] = '';
  1232. $orderArr[$k]['outtime'] = '';
  1233. }
  1234. $orderArr[$k]['order_status'] = $v['order_status'];
  1235. $orderArr[$k]['product_type'] = $v['product_type'];
  1236. $orderArr[$k]['created_at'] = $v['created_at'];
  1237. $orderArr[$k]['name'] = $v['order_patient']['name'];
  1238. $orderArr[$k]['birthday'] = numBirthday($v['order_patient']['birthday']);
  1239. }
  1240. }
  1241. // 拼接服务消息
  1242. $wh['user_id'] = $req['user_id'];
  1243. $wh['order_status'] = ['>', 3];
  1244. $wh['product_type'] = 6;
  1245. $fuwuList = [];
  1246. $fuwuInfo = Order::where($wh)->get();
  1247. $fuwuList['fuwu_num'] = count($fuwuInfo);
  1248. $whs['user_id'] = $req['user_id'];
  1249. $whs['order_status'] = ['>', 3];
  1250. $order_nums = Order::where($whs)->get();
  1251. $fuwuList['order_num'] = count($order_nums);
  1252. $pati_nums = Patient::where('user_id', '=', $req['user_id'])->get();
  1253. $fuwuList['pati_num'] = count($pati_nums);
  1254. $returnArr = [
  1255. 'user_arr' => $userArr,
  1256. 'patients_arr' => $patientsArr,//患者档案
  1257. 'order_arr' => $orderArr, //历史问诊
  1258. 'fuwu_arr' => $fuwArr, //已购服务
  1259. 'nums' => $fuwuList,
  1260. ];
  1261. return out($returnArr);
  1262. }
  1263. /**
  1264. * 我的列表进入详情
  1265. * Auth:Yuanhang-Liu
  1266. * Date:2020/10/20 23:21
  1267. * @return \Illuminate\Http\JsonResponse
  1268. */
  1269. public function patientsDetile()
  1270. {
  1271. $req = request()->post();
  1272. $this->validate(request(), [
  1273. 'patient_id|患者ID' => 'required|integer',
  1274. ]);
  1275. $user = $this->user;
  1276. $finds = Patient::where('id', '=', $req['patient_id'])->first();
  1277. if ($finds) {
  1278. $finds = $finds->toArray();
  1279. }
  1280. if ($finds['sex'] == 0) {
  1281. $finds['sex'] = '中性';
  1282. } elseif ($finds['sex'] == 1) {
  1283. $finds['sex'] = '男';
  1284. } else {
  1285. $finds['sex'] = '女';
  1286. }
  1287. switch ($finds['relationship_type']) {
  1288. case 1:
  1289. $finds['relationship_type'] = '父亲';
  1290. break;
  1291. case 2:
  1292. $finds['relationship_type'] = '母亲';
  1293. break;
  1294. case 3:
  1295. $finds['relationship_type'] = '祖父';
  1296. break;
  1297. case 4:
  1298. $finds['relationship_type'] = '祖母';
  1299. break;
  1300. case 5:
  1301. $finds['relationship_type'] = '外祖父';
  1302. break;
  1303. case 6:
  1304. $finds['relationship_type'] = '外祖母';
  1305. break;
  1306. case 7:
  1307. $finds['relationship_type'] = '叔侄';
  1308. break;
  1309. default:
  1310. $finds['relationship_type'] = '其他';
  1311. }
  1312. $finds['age'] = numBirthday($finds['birthday']);
  1313. // 患者单子
  1314. $patient_list = OrderPatient::with('order')->where('patient_id', '=', $req['patient_id'])->groupBy('id', 'order_id')->get();
  1315. $patient_arr = [];
  1316. if ($patient_list) {
  1317. $patient_list = $patient_list->toArray();
  1318. foreach ($patient_list as $k => $v) {
  1319. switch ($v['order']['product_type']) {
  1320. case 1:
  1321. $patient_arr[$k]['product_type'] = '电话咨询';
  1322. break;
  1323. case 2:
  1324. $patient_arr[$k]['product_type'] = '图文咨询';
  1325. break;
  1326. case 3:
  1327. $patient_arr[$k]['product_type'] = '门诊';
  1328. break;
  1329. case 4:
  1330. $patient_arr[$k]['product_type'] = '疫苗接种预约';
  1331. break;
  1332. case 5:
  1333. $patient_arr[$k]['product_type'] = '儿保预约';
  1334. break;
  1335. case 6:
  1336. $patient_arr[$k]['product_type'] = '服务包';
  1337. break;
  1338. case 7:
  1339. $patient_arr[$k]['product_type'] = '充值';
  1340. break;
  1341. default:
  1342. $patient_arr[$k]['product_type'] = '错误';
  1343. }
  1344. switch ($v['order']['order_status']) {
  1345. case 1:
  1346. $patient_arr[$k]['order_status'] = '未支付';
  1347. break;
  1348. case 2:
  1349. $patient_arr[$k]['order_status'] = '待接单';
  1350. break;
  1351. case 3:
  1352. $patient_arr[$k]['order_status'] = '进行中';
  1353. break;
  1354. case 4:
  1355. $patient_arr[$k]['order_status'] = '已完成';
  1356. break;
  1357. case 5:
  1358. $patient_arr[$k]['order_status'] = '已取消';
  1359. break;
  1360. default:
  1361. $patient_arr[$k]['order_status'] = '未知';
  1362. }
  1363. $patient_arr[$k]['created_at'] = $v['created_at'];
  1364. }
  1365. }
  1366. $returnArr = [
  1367. 'patient' => $finds,
  1368. 'patientOrder' => $patient_arr,
  1369. ];
  1370. return out($returnArr);
  1371. }
  1372. /**
  1373. * 关注用户
  1374. * Auth:Yuanhang-Liu
  1375. * Date:2020/10/21 00:21
  1376. * @return \Illuminate\Http\JsonResponse
  1377. */
  1378. public function userFollow()
  1379. {
  1380. $req = request()->post();
  1381. $this->validate(request(), [
  1382. 'user_id|用户ID' => 'required|integer',
  1383. 'is_ley' => 'required',
  1384. ]);
  1385. // 如果ley==false说明要取消关注,反之添加关注
  1386. $user = $this->user;
  1387. $docter_id = $user['id'];
  1388. if ($req['is_ley'] == 1) {
  1389. DocterUser::where('user_id', '=', $req['user_id'])->delete();
  1390. } else {
  1391. DocterUser::create([
  1392. 'user_id' => $req['user_id'],
  1393. 'docter_id' => $user['id'],
  1394. ]);
  1395. }
  1396. return out();
  1397. }
  1398. /**
  1399. * 是否关注用户
  1400. * Auth:Yuanhang-Liu
  1401. * Date:2020/10/21 00:21
  1402. * @return \Illuminate\Http\JsonResponse
  1403. */
  1404. public function getFollows()
  1405. {
  1406. $req = request()->post();
  1407. $this->validate(request(), [
  1408. 'user_id|用户ID' => 'required|integer',
  1409. ]);
  1410. $user = $this->user;
  1411. $docter_id = $user['id'];
  1412. $where['docter_id'] = $docter_id;
  1413. $where['user_id'] = $req['user_id'];
  1414. $find = DocterUser::where($where)->first();
  1415. if ($find) {
  1416. $find = $find->toArray();
  1417. return out(true);
  1418. } else {
  1419. return out(false);
  1420. }
  1421. }
  1422. /**
  1423. * 获取医生所在机构列表
  1424. * Auth:Yuanhang-Liu
  1425. * Date:2020/10/21 00:21
  1426. * @return \Illuminate\Http\JsonResponse
  1427. */
  1428. public function organizationList()
  1429. {
  1430. $user = $this->user;
  1431. $doctor_id = $user['id'];
  1432. $where['docter_id'] = $doctor_id;
  1433. $where['state'] = 1;
  1434. $orgList = DocterOrganization::with('organization')->where($where)->get()->toArray();
  1435. $newList = [];
  1436. foreach ($orgList as $k => $v) {
  1437. $newList[$k]['value'] = $v['organization']['id'];
  1438. $newList[$k]['label'] = $v['organization']['name'];
  1439. }
  1440. return out($newList);
  1441. }
  1442. /**
  1443. * 获取医院的服务时间
  1444. * @return mixed
  1445. */
  1446. public function getOrgTimes()
  1447. {
  1448. $req = request()->post();
  1449. $this->validate(request(), [
  1450. 'org_id|医院id' => 'required',
  1451. ]);
  1452. $user = $this->user;
  1453. $doctor_id = $user['id'];
  1454. $where['docter_id'] = $doctor_id;
  1455. $orgList = DocterSetting::where(['docter_id'=>$doctor_id,'type'=>1,'org_id'=>$req['org_id']])->first();
  1456. $newList = [];
  1457. if($orgList){
  1458. $time = json_decode($orgList['service_time'],true);
  1459. $newList['zao']['amStartTime'] = isset($time[1])?$time[1]['amStartTime']:'';
  1460. $newList['zao']['amEndTime'] = isset($time[1])?$time[1]['amEndTime']:'';
  1461. $newList['zao']['amPerson'] = isset($time[1])?$time[1]['amPerson']:'';
  1462. $newList['zhong']['pmStartTime'] = isset($time[2])?$time[2]['pmStartTime']:'';
  1463. $newList['zhong']['pmEndTime'] = isset($time[2])?$time[2]['pmEndTime']:'';
  1464. $newList['zhong']['pmPerson'] = isset($time[2])?$time[2]['pmPerson']:'';
  1465. $newList['wan']['nightStartTime'] = isset($time[3])?$time[3]['nightStartTime']:'';
  1466. $newList['wan']['nightEndTime'] = isset($time[3])?$time[3]['nightEndTime']:'';
  1467. $newList['wan']['nightPerson'] = isset($time[3])?$time[3]['nightPerson']:'';
  1468. }
  1469. return out($newList);
  1470. }
  1471. /**
  1472. * 获取历史排班时间列表
  1473. */
  1474. public function getLinsList()
  1475. {
  1476. $user = $this->user;
  1477. $doctor_id = $user['id'];
  1478. $newData = [];
  1479. $strim = date('Y-m-d', (time() + (7 - (date('w') == 0 ? 7 : date('w'))) * 24 * 3600));
  1480. $wheres['docter_id'] = $doctor_id;
  1481. $data = Schedule::select(['id', 'schedule_date'])->where($wheres)->whereDate('schedule_date', '>', $strim)->orderBy('schedule_date', 'desc')->get();
  1482. if ($data) {
  1483. $data = $data->toArray();
  1484. } else {
  1485. return out($newData);
  1486. }
  1487. $newData = array_values($data);
  1488. $lab = [];
  1489. $p = 0;
  1490. for ($i = count($newData); $i > 0; $i--) {
  1491. // if ($i%7==0||$i==1){
  1492. //
  1493. // if ($p>=1){
  1494. // $lab[$p-1]['end_time'] = $arr[$i-1];
  1495. // $lab[$p]['start_time'] = $arr[$i-1];
  1496. // if(isset($arr[$i-7])){
  1497. // $lab[$p]['end_time'] = isset($arr[$i-7])?$arr[$i-7]:'error';
  1498. //
  1499. // }else{
  1500. // unset($lab[$p]);
  1501. // }
  1502. //// $lab[$p]['end_time'] = isset($arr[$i-7])?$arr[$i-7]:'error';
  1503. // }else{
  1504. // $lab[$p]['start_time'] = $arr[$i-1];
  1505. // }
  1506. // ++$p;
  1507. // }else{
  1508. // continue;
  1509. // }
  1510. if ($i % 7 == 0 || $i == 1) {
  1511. if ($p >= 1) {
  1512. $lab[$p - 1]['end_time'] = $newData[$i - 1];
  1513. if (isset($newData[$i - 7])) {
  1514. $lab[$p]['start_time'] = $newData[$i - 1];
  1515. $lab[$p]['end_time'] = $newData[$i - 7];
  1516. } else {
  1517. unset($lab[$p]);
  1518. }
  1519. } else {
  1520. $lab[$p]['start_time'] = $newData[$i - 1];
  1521. }
  1522. ++$p;
  1523. } else {
  1524. continue;
  1525. }
  1526. }
  1527. // 审核通过时间拿出来
  1528. $wh['docter_id'] = $doctor_id;
  1529. $wh['service_type'] = 3;
  1530. $wh['status'] = 2;
  1531. $service = ServiceApply::where($wh)->first();
  1532. if ($service) {
  1533. $service = $service;
  1534. } else {
  1535. $service = 0;
  1536. }
  1537. $rtuenList = [
  1538. 'list' => $lab,
  1539. 'service' => $service,
  1540. ];
  1541. return out($rtuenList);
  1542. }
  1543. /**
  1544. * 获取周模板详情
  1545. * @return \Illuminate\Http\JsonResponse
  1546. * @author Liu-Yh
  1547. * Create By 2020/12/16 12:09
  1548. */
  1549. public function getLinsDetailnew($flag = false)
  1550. {
  1551. $user = $this->user;
  1552. $doctor_id = $user['id'];
  1553. $newData = [];
  1554. $data = WeekSchedule::with('organization')->where('docter_id', '=', $doctor_id)->groupBy('type', 'week')->orderBy('week', 'asc')->get();
  1555. if ($data) {
  1556. $data = $data->toArray();
  1557. } else {
  1558. return out($newData);
  1559. }
  1560. $lab = [];
  1561. foreach ($data as $k => $v) {
  1562. $lab[$k]['id'] = $v['id'];
  1563. $lab[$k]['type'] = $v['type']; // 1=早上,2=下午,3=晚上
  1564. $lab[$k]['organization_id'] = $v['organization_id']; // 1=早上,2=下午,3=晚上
  1565. $lab[$k]['flag'] = $v['week'];
  1566. switch ($v['week']) {
  1567. case "7":
  1568. $lab[$k]['week'] = '周日';
  1569. break;
  1570. case "1":
  1571. $lab[$k]['week'] = '周一';
  1572. break;
  1573. case "2":
  1574. $lab[$k]['week'] = '周二';
  1575. break;
  1576. case "3":
  1577. $lab[$k]['week'] = '周三';
  1578. break;
  1579. case "4":
  1580. $lab[$k]['week'] = '周四';
  1581. break;
  1582. case "5":
  1583. $lab[$k]['week'] = '周五';
  1584. break;
  1585. default:
  1586. $lab[$k]['week'] = '周六';
  1587. }
  1588. $lab[$k]['name'] = $v['organization']; // 所在医院
  1589. }
  1590. $weekList = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'];
  1591. try {
  1592. $newReturn = [];
  1593. foreach ($lab as $k => $v) {
  1594. if (!isset($newReturn[$v['flag']])) {
  1595. $newReturn[$v['flag']] = $v;
  1596. if ($v['type'] == 1) {
  1597. $newReturn[$v['flag']]['ident']['zao_id'] = $v['name']['id'];
  1598. $newReturn[$v['flag']]['ident']['xia_id'] = 0;
  1599. $newReturn[$v['flag']]['ident']['wan_id'] = 0;
  1600. } else if ($v['type'] == 2) {
  1601. $newReturn[$v['flag']]['ident']['zao_id'] = 0;
  1602. $newReturn[$v['flag']]['ident']['xia_id'] = $v['name']['id'];
  1603. $newReturn[$v['flag']]['ident']['wan_id'] = 0;
  1604. } else {
  1605. $newReturn[$v['flag']]['ident']['zao_id'] = 0;
  1606. $newReturn[$v['flag']]['ident']['xia_id'] = 0;
  1607. $newReturn[$v['flag']]['ident']['wan_id'] = $v['name']['id'];
  1608. }
  1609. $newReturn[$v['flag']]['week'] = $v['week'];
  1610. $newReturn[$v['flag']]['name'] = $v['name'];
  1611. } else {
  1612. if ($v['type'] == 1) {
  1613. $newReturn[$v['flag']]['ident']['zao_id'] = $v['name']['id'];
  1614. } else if ($v['type'] == 2) {
  1615. $newReturn[$v['flag']]['ident']['xia_id'] = $v['name']['id'];
  1616. } else {
  1617. $newReturn[$v['flag']]['ident']['wan_id'] = $v['name']['id'];
  1618. }
  1619. }
  1620. unset($newReturn[$v['flag']]['name']);
  1621. }
  1622. } catch (\Exception $e) {
  1623. var_dump($e->getMessage() . $e->getFile() . $e->getLine());
  1624. }
  1625. $returnLists['list'] = array_values($newReturn);
  1626. return out($returnLists);
  1627. }
  1628. /**
  1629. * 生成时间段
  1630. * @param int $org_id 机构id
  1631. * @param int $type 时间段,1=早上,2=下午,3=晚上
  1632. * @return array|bool
  1633. * @author Liu-Yh
  1634. * Create By 2020/12/15 18:47
  1635. */
  1636. protected function num_time($org_id = 0, $type = 1)
  1637. {
  1638. $user = $this->user;
  1639. $doctor_id = $user['id'];
  1640. $zaoTimes = [];
  1641. $zhongTimes = [];
  1642. $wanTimes = [];
  1643. $where['docter_id'] = $doctor_id;
  1644. $where['type'] = 1;
  1645. $where['org_id'] = $org_id;
  1646. $configs = DocterSetting::where($where)->first();
  1647. if ($configs) {
  1648. $list = json_decode($configs['service_time'], true);
  1649. if (isset($list[1]['amStartTime']) && !empty($list[1]['amStartTime'])) {
  1650. $zaoTimes[0] = $list[1]['amStartTime'];
  1651. } else {
  1652. $zaoTimes[0] = "08:00";
  1653. }
  1654. if (isset($list[1]['amEndTime']) && !empty($list[1]['amEndTime'])) {
  1655. $zaoTimes[1] = $list[1]['amEndTime'];
  1656. } else {
  1657. $zaoTimes[1] = "12:00";
  1658. }
  1659. if (isset($list[2]['pmStartTime']) && !empty($list[2]['pmStartTime'])) {
  1660. $zhongTimes[0] = $list[2]['pmStartTime'];
  1661. } else {
  1662. $zhongTimes[0] = "13:00";
  1663. }
  1664. if (isset($list[2]['pmEndTime']) && !empty($list[2]['pmEndTime'])) {
  1665. $zhongTimes[1] = $list[2]['pmEndTime'];
  1666. } else {
  1667. $zhongTimes[1] = "18:00";
  1668. }
  1669. if (isset($list[3]['nightStartTime']) && !empty($list[3]['nightStartTime'])) {
  1670. $wanTimes[0] = $list[3]['nightStartTime'];
  1671. } else {
  1672. $wanTimes[0] = "19:00";
  1673. }
  1674. if (isset($list[3]['nightEndTime']) && !empty($list[3]['nightEndTime'])) {
  1675. $wanTimes[1] = $list[3]['nightEndTime'];
  1676. } else {
  1677. $wanTimes[1] = "21:00";
  1678. }
  1679. } else {
  1680. return false;
  1681. }
  1682. if ($type == 1) {
  1683. $morningWhere[] = ['start_time_period', '>=', $zaoTimes[0]];
  1684. $morningWhere[] = ['end_time_period', '<=', $zaoTimes[1]];
  1685. $morningWhere['docter_id'] = $doctor_id;
  1686. $morningWhere['org_id'] = $org_id;
  1687. $morningd = TimePeriod::where($morningWhere)->get()->toArray();
  1688. if (count($morningd)>1){
  1689. array_pop($morningd);
  1690. }
  1691. $morning = array_column($morningd, 'id');
  1692. return $morning;
  1693. } elseif ($type == 2) {
  1694. $afternoondWhere[] = ['start_time_period', '>=', $zhongTimes[0]];
  1695. $afternoondWhere[] = ['end_time_period', '<=', $zhongTimes[1]];
  1696. $afternoondWhere['docter_id'] = $doctor_id;
  1697. $afternoondWhere['org_id'] = $org_id;
  1698. $afternoond = TimePeriod::where($afternoondWhere)->get()->toArray();
  1699. if (count($afternoond)>1){
  1700. array_pop($afternoond);
  1701. }
  1702. $afternoon = array_column($afternoond, 'id');
  1703. return $afternoon;
  1704. } elseif ($type == 3) {
  1705. $nightWhere[] = ['start_time_period', '>=', $wanTimes[0]];
  1706. $nightWhere[] = ['end_time_period', '<=', $wanTimes[1]];
  1707. $nightWhere['docter_id'] = $doctor_id;
  1708. $nightWhere['org_id'] = $org_id;
  1709. $nightd = TimePeriod::where($nightWhere)->get()->toArray();
  1710. if (count($nightd)>1){
  1711. array_pop($nightd);
  1712. }
  1713. $night = array_column($nightd, 'id');
  1714. return $night;
  1715. } else {
  1716. $morningWhere[] = ['start_time_period', '>=', $zaoTimes[0]];
  1717. $morningWhere[] = ['end_time_period', '<=', $zaoTimes[1]];
  1718. $morningWhere['docter_id'] = $doctor_id;
  1719. $morningWhere['org_id'] = $org_id;
  1720. $morningd = TimePeriod::where($morningWhere)->get()->toArray();
  1721. if (count($morningd)>1){
  1722. array_pop($morningd);
  1723. }
  1724. $morning = array_column($morningd, 'id');
  1725. $afternoondWhere[] = ['start_time_period', '>=', $zhongTimes[0]];
  1726. $afternoondWhere[] = ['end_time_period', '<=', $zhongTimes[1]];
  1727. $afternoondWhere['docter_id'] = $doctor_id;
  1728. $afternoondWhere['org_id'] = $org_id;
  1729. $afternoond = TimePeriod::where($afternoondWhere)->get()->toArray();
  1730. if (count($afternoond)>1){
  1731. array_pop($afternoond);
  1732. }
  1733. $afternoon = array_column($afternoond, 'id');
  1734. $nightWhere[] = ['start_time_period', '>=', $wanTimes[0]];
  1735. $nightWhere[] = ['end_time_period', '<=', $wanTimes[1]];
  1736. $nightWhere['docter_id'] = $doctor_id;
  1737. $nightWhere['org_id'] = $org_id;
  1738. $nightd = TimePeriod::where($nightWhere)->get()->toArray();
  1739. if (count($nightd)>1){
  1740. array_pop($nightd);
  1741. }
  1742. $night = array_column($nightd, 'id');
  1743. return [$morning, $afternoon, $night];
  1744. }
  1745. }
  1746. /**
  1747. * 获取俩月日期
  1748. * @return array
  1749. */
  1750. protected function date_bool($start_time = false, $end_time = false)
  1751. {
  1752. $weekarray = array(7, 1, 2, 3, 4, 5, 6);
  1753. $monthDays = [];
  1754. if ($start_time && $end_time) {
  1755. $firstDay = $start_time;
  1756. $lastDay = $end_time;
  1757. } else {
  1758. $firstDay = date('Y-m-01', time());
  1759. $lastDay = date('Y-m-d', strtotime("$firstDay +2 month -1 day"));
  1760. }
  1761. $i = 0;
  1762. while (date('Y-m-d', strtotime("$firstDay +$i days")) <= $lastDay) {
  1763. $monthDays[$i]['date'] = date('Y-m-d', strtotime("$firstDay +$i days"));
  1764. $monthDays[$i]['week'] = $weekarray[date("w", strtotime("$firstDay +$i days"))];
  1765. $i++;
  1766. }
  1767. return $monthDays;
  1768. }
  1769. /**
  1770. * 新版门诊排班(排班周模板)
  1771. * @return mixed
  1772. * @throws \Exception
  1773. */
  1774. public function week_scheduling()
  1775. {
  1776. $req = request()->post();
  1777. $this->validate(request(), [
  1778. 'data|数据' => 'required',
  1779. ]);
  1780. $user = $this->user;
  1781. $doctor_id = $user['id'];
  1782. $data = json_decode($req['data'], true);
  1783. // 查询自定义排班
  1784. $Wheres['docter_id'] = $doctor_id;
  1785. $Wheres['me_sure'] = 1;
  1786. $Wheres['schedule_type'] = 1;
  1787. $Wheres[] = ['schedule_date','>=',date('Y-m-d',time())];
  1788. $meSureList = SchedulePeriod::where($Wheres)->get();
  1789. $moth_date = $this->date_bool();
  1790. $delDate = [];
  1791. $delDate2 = [];
  1792. $schedule_ids = [];
  1793. $schedule = [];
  1794. foreach ($data as $k=>$v){
  1795. if ($v['identifi']['zao']==0&&$v['identifi']['zhong']==0&&$v['identifi']['wan']==0){
  1796. $delDate[] = $v['week'];
  1797. }
  1798. }
  1799. if ($meSureList){
  1800. foreach ($meSureList as $k=>$v){
  1801. $delDate2[] = $v['schedule_date'];
  1802. }
  1803. }
  1804. foreach ($moth_date as $k=>$v){
  1805. if (in_array($v['week'],$delDate)){
  1806. unset($moth_date[$k]);
  1807. }
  1808. if (in_array($v['date'],$delDate2)){
  1809. unset($moth_date[$k]);
  1810. }
  1811. }
  1812. DB::beginTransaction();
  1813. try {
  1814. WeekSchedule::where('docter_id', '=', $doctor_id)->where('schedule_type', '=', 1)->delete();
  1815. $delWhere['docter_id'] = $doctor_id;
  1816. $delWhere['me_sure'] = 0;
  1817. $delWhere['schedule_type'] = 1;
  1818. $delWhere[] = ['schedule_date','>=',date('Y-m-d',time())];
  1819. SchedulePeriod::where($delWhere)->delete();
  1820. Schedule::where('docter_id', '=', $doctor_id)->whereNotIn('schedule_date',$delDate2)->delete();
  1821. foreach ($moth_date as $kk => $vv) {
  1822. $schedule[$kk]['schedule_type'] = 1;
  1823. $schedule[$kk]['schedule_date'] = $vv['date'];
  1824. $schedule[$kk]['schedule_day'] = str_replace('-', '', $vv['date']);
  1825. $schedule[$kk]['docter_id'] = $doctor_id;
  1826. $schedule[$kk]['organization_id'] = 0;
  1827. $schedule[$kk]['week'] = $vv['week'];
  1828. $schedule[$kk]['per_time_num'] = 0;
  1829. $schedule_ids[$kk] = Schedule::insertGetId($schedule[$kk]);
  1830. }
  1831. foreach ($data as $k => $v) {
  1832. // 插入详情
  1833. if ($v['identifi']['zao']!=0) {
  1834. $maf[$k]['schedule_type'] = 1;
  1835. $maf[$k]['docter_id'] = $doctor_id;
  1836. $maf[$k]['week'] = $v['week'];
  1837. $maf[$k]['type'] = 1;
  1838. $maf[$k]['organization_id'] = $v['identifi']['zao'];
  1839. $weekList[] = $maf[$k];
  1840. }
  1841. if ($v['identifi']['zhong']!=0) {
  1842. $maf[$k]['schedule_type'] = 1;
  1843. $maf[$k]['docter_id'] = $doctor_id;
  1844. $maf[$k]['week'] = $v['week'];
  1845. $maf[$k]['type'] = 2;
  1846. $maf[$k]['organization_id'] = $v['identifi']['zhong'];
  1847. $weekList[] = $maf[$k];
  1848. }
  1849. if ($v['identifi']['wan']!=0) {
  1850. $maf[$k]['schedule_type'] = 1;
  1851. $maf[$k]['docter_id'] = $doctor_id;
  1852. $maf[$k]['week'] = $v['week'];
  1853. $maf[$k]['type'] = 3;
  1854. $maf[$k]['organization_id'] = $v['identifi']['wan'];
  1855. $weekList[] = $maf[$k];
  1856. }
  1857. }
  1858. $scheduleLists = [];
  1859. foreach ($schedule_ids as $kk => $vv) {
  1860. foreach ($data as $k => $v) {
  1861. if ($schedule[$kk]['week'] == $v['week']) {
  1862. //检查有没有设置时间
  1863. if ($v['identifi']['zao']) {
  1864. $times = $this->num_time($v['identifi']['zao'], 1);
  1865. if (!$times) {
  1866. return out('', 500, "请先在排班设置中填写本机构的早上时间段");
  1867. }
  1868. $maf = $this->getMaf($vv, $times, ['organization_id' => $v['identifi']['zao'],'me_sure'=>0, 'schedule_date' => $schedule[$kk]['schedule_date'], 'type' => 1], $doctor_id);
  1869. if ($maf) {
  1870. foreach ($maf as $os) {
  1871. $scheduleLists[] = $os;
  1872. }
  1873. }
  1874. }
  1875. if ($v['identifi']['zhong']) {
  1876. $times = $this->num_time($v['identifi']['zhong'], 2);
  1877. if (!$times) {
  1878. return out('', 500, "请先在排班设置中填写本机构的下午时间段");
  1879. }
  1880. $maf = $this->getMaf($vv, $times, ['organization_id' => $v['identifi']['zhong'],'me_sure'=>0, 'schedule_date' => $schedule[$kk]['schedule_date'], 'type' => 2], $doctor_id);
  1881. if ($maf) {
  1882. foreach ($maf as $os) {
  1883. $scheduleLists[] = $os;
  1884. }
  1885. }
  1886. }
  1887. if ($v['identifi']['wan']) {
  1888. $times = $this->num_time($v['identifi']['wan'], 3);
  1889. if (!$times) {
  1890. return out('', 500, "请先在排班设置中填写本机构的晚上时间段");
  1891. }
  1892. $maf = $this->getMaf($vv, $times, ['organization_id' => $v['identifi']['wan'],'me_sure'=>0, 'schedule_date' => $schedule[$kk]['schedule_date'], 'type' => 3], $doctor_id);
  1893. if ($maf) {
  1894. foreach ($maf as $os) {
  1895. $scheduleLists[] = $os;
  1896. }
  1897. }
  1898. }
  1899. }
  1900. }
  1901. }
  1902. SchedulePeriod::insert($scheduleLists);
  1903. WeekSchedule::insert($weekList);
  1904. DB::commit();
  1905. return out();
  1906. } catch (\Exception $e) {
  1907. DB::rollBack();
  1908. return out('', 500, $e->getFile() . '中的第:' . $e->getLine() . '行报错:' . $e->getCode(), $e->getMessage());
  1909. } catch (\PDOException $e) {
  1910. DB::rollBack();
  1911. return out('', 500, $e->getFile() . '中的第:' . $e->getLine() . '行报错:' . $e->getCode(), $e->getMessage());
  1912. }
  1913. }
  1914. /**
  1915. * 修改某一天的数据
  1916. * @author Liu-Yh
  1917. * Create By 2020/12/16 18:46
  1918. */
  1919. public function saveDay($data = [])
  1920. {
  1921. $flag = false;
  1922. if (empty($data)) {
  1923. $req = request()->post();
  1924. $this->validate(request(), [
  1925. 'schedule_date|日期' => 'required',
  1926. 'week|周' => 'required',
  1927. 'type|类型' => 'required',
  1928. 'organization_id|日期' => 'required',
  1929. ]);
  1930. $req['schedule_date'] = date('Y-m-d',strtotime($req['schedule_date']));
  1931. } else {
  1932. $flag = true;
  1933. $req = $data;
  1934. }
  1935. $user = $this->user;
  1936. $doctor_id = $user['id'];
  1937. $save_data = [];
  1938. DB::beginTransaction();
  1939. try {
  1940. $type_data = json_decode($req['type'],true);
  1941. $where = [];
  1942. $where['schedule_date'] = $req['schedule_date'];
  1943. $where['docter_id'] = $doctor_id;
  1944. $where['schedule_type'] = 1;
  1945. $where['organization_id'] = $req['organization_id'];
  1946. if ($type_data['mon']==0&&$type_data['aft']==0&&$type_data['nig']==0){
  1947. // 进行删除
  1948. unset($where['organization_id']);
  1949. SchedulePeriod::where($where)->delete();
  1950. Schedule::where($where)->delete();
  1951. return out();
  1952. }
  1953. SchedulePeriod::where($where)->delete();
  1954. $save_data=[];
  1955. if($type_data['mon']!=0) {
  1956. $mon_times = $this->num_time($type_data['mon'], 1);
  1957. $mf1 = $this->arrangeDay($mon_times, ['organization_id' => $type_data['mon'], 'week' => $req['week'], 'schedule_date' => $req['schedule_date'], 'type' => 1], $doctor_id);
  1958. if($mf1){
  1959. foreach ($mf1 as $v){
  1960. $save_data[] = $v;
  1961. }
  1962. }
  1963. }
  1964. if($type_data['aft']!=0){
  1965. $aft_times = $this->num_time($type_data['aft'], 2);
  1966. $mf2 = $this->arrangeDay($aft_times, ['organization_id' => $type_data['aft'], 'week' => $req['week'], 'schedule_date' => $req['schedule_date'], 'type' => 2], $doctor_id);
  1967. if($mf2){
  1968. foreach ($mf2 as $v){
  1969. $save_data[] = $v;
  1970. }
  1971. }
  1972. }
  1973. if($type_data['nig']!=0) {
  1974. $nig_times = $this->num_time($type_data['nig'], 3);
  1975. $mf3 = $this->arrangeDay($nig_times, ['organization_id' => $type_data['nig'], 'week' => $req['week'], 'schedule_date' => $req['schedule_date'], 'type' => 3], $doctor_id);
  1976. if($mf3){
  1977. foreach ($mf3 as $v){
  1978. $save_data[] = $v;
  1979. }
  1980. }
  1981. }
  1982. if (!$flag){
  1983. $lists = Schedule::where(['docter_id'=>$doctor_id,'schedule_date'=>$req['schedule_date']])->first();
  1984. if($lists){
  1985. if($save_data){
  1986. $chong = [];
  1987. foreach ($save_data as $k => $v) {
  1988. $chong[$k]['schedule_id'] = $lists['id'];
  1989. $chong[$k]['docter_id'] = $v['docter_id'];
  1990. $chong[$k]['order_num'] = 0;
  1991. $chong[$k]['organization_id'] = $v['organization_id'];
  1992. $chong[$k]['time_period_id'] = $v['time_period_id'];
  1993. $chong[$k]['type'] = $v['type'];
  1994. $chong[$k]['me_sure'] = 1;
  1995. $chong[$k]['schedule_date'] = $v['schedule_date'];
  1996. }
  1997. SchedulePeriod::insert($chong);
  1998. }
  1999. }
  2000. }
  2001. DB::commit();
  2002. if ($flag) {
  2003. return true;
  2004. } else {
  2005. return out();
  2006. }
  2007. } catch (\Exception $e) {
  2008. DB::rollBack();
  2009. if ($flag) {
  2010. return false;
  2011. } else {
  2012. return out('', 500, $e->getFile() . '中的第:' . $e->getLine() . '行报错:' . $e->getCode(), $e->getMessage());
  2013. }
  2014. } catch (\PDOException $e) {
  2015. DB::rollBack();
  2016. if ($flag) {
  2017. return false;
  2018. } else {
  2019. return out('', 500, $e->getFile() . '中的第:' . $e->getLine() . '行报错:' . $e->getCode(), $e->getMessage());
  2020. }
  2021. }
  2022. }
  2023. /**
  2024. * 整理单个修改排班的数据
  2025. * @param $time
  2026. * @param $req
  2027. * @param $doctor_id
  2028. * @return array
  2029. * @author Liu-Yh
  2030. * Create By 2020/12/16 19:00
  2031. */
  2032. protected function arrangeDay($time, $req, $doctor_id)
  2033. {
  2034. $save_data = [];
  2035. foreach ($time as $k => $v) {
  2036. $save_data[$k]['schedule_date'] = $req['schedule_date'];
  2037. $save_data[$k]['week'] = $req['week'];
  2038. $save_data[$k]['schedule_type'] = 1;
  2039. $save_data[$k]['type'] = $req['type'];
  2040. $save_data[$k]['organization_id'] = $req['organization_id'];
  2041. $save_data[$k]['docter_id'] = $doctor_id;
  2042. $save_data[$k]['time_period_id'] = $v;
  2043. }
  2044. return $save_data;
  2045. }
  2046. /**
  2047. * 查看月视图
  2048. * @author Liu-Yh
  2049. * Create By 2020/12/16 19:20
  2050. */
  2051. public function monthDetail()
  2052. {
  2053. $req = request()->post();
  2054. $this->validate(request(), [
  2055. 'start_day|日期' => 'required',
  2056. 'end_day|日期' => 'required',
  2057. ]);
  2058. //格式化日期
  2059. $req['start_day'] = date('Y-m-d',strtotime($req['start_day']));
  2060. $req['end_day'] = date('Y-m-d',strtotime($req['end_day']));
  2061. $user = $this->user;
  2062. $doctor_id = $user['id'];
  2063. $Wheres['docter_id'] = $doctor_id;
  2064. $Wheres['schedule_type'] = 1;
  2065. $list = SchedulePeriod::where($Wheres)->whereBetween('schedule_date',[$req['start_day'],$req['end_day']])->select(['schedule_date','id','organization_id','type'])->orderBy('schedule_date','asc')->get();
  2066. // 定义数组整合数据
  2067. if ($list){
  2068. $list = $list->toArray();
  2069. }else{
  2070. return out([]);
  2071. }
  2072. $dateFlag = [];
  2073. foreach ($list as $k=>$v){
  2074. if (!isset($dateFlag[$v['schedule_date']])) {
  2075. $dateFlag[$v['schedule_date']] = $v;
  2076. if ($v['type'] == 1) {
  2077. $dateFlag[$v['schedule_date']]['ident']['zao'] = $v['organization_id'];
  2078. $dateFlag[$v['schedule_date']]['ident']['xia'] = 0;
  2079. $dateFlag[$v['schedule_date']]['ident']['wan'] = 0;
  2080. } else if ($v['type'] == 2) {
  2081. $dateFlag[$v['schedule_date']]['ident']['zao'] = 0;
  2082. $dateFlag[$v['schedule_date']]['ident']['xia'] = $v['organization_id'];
  2083. $dateFlag[$v['schedule_date']]['ident']['wan'] = 0;
  2084. } else {
  2085. $dateFlag[$v['schedule_date']]['ident']['zao'] = 0;
  2086. $dateFlag[$v['schedule_date']]['ident']['xia'] = 0;
  2087. $dateFlag[$v['schedule_date']]['ident']['wan'] = $v['organization_id'];
  2088. }
  2089. $dateFlag[$v['schedule_date']]['date'] = $v['schedule_date'];
  2090. } else {
  2091. if ($v['type'] == 1) {
  2092. $dateFlag[$v['schedule_date']]['ident']['zao'] = $v['organization_id'];
  2093. }
  2094. if ($v['type'] == 2) {
  2095. $dateFlag[$v['schedule_date']]['ident']['xia'] = $v['organization_id'];
  2096. }
  2097. if ($v['type'] == 3){
  2098. $dateFlag[$v['schedule_date']]['ident']['wan'] = $v['organization_id'];
  2099. }
  2100. }
  2101. }
  2102. return out(array_values($dateFlag));
  2103. }
  2104. /**
  2105. * 获取早中下午的id
  2106. * @param $sid
  2107. * @param $time
  2108. * @param $req
  2109. * @param $doctor_id
  2110. * @return array
  2111. * @author Liu-Yh
  2112. * Create By 2020/11/6 16:27
  2113. */
  2114. protected function getMaf($sid, $time, $req, $doctor_id)
  2115. {
  2116. $maf = [];
  2117. foreach ($time as $k => $v) {
  2118. $maf[$k]['schedule_id'] = $sid;
  2119. $maf[$k]['organization_id'] = $req['organization_id'];
  2120. $maf[$k]['time_period_id'] = $v;
  2121. $maf[$k]['schedule_date'] = $req['schedule_date'];
  2122. $maf[$k]['docter_id'] = $doctor_id;
  2123. $maf[$k]['type'] = $req['type'];
  2124. $maf[$k]['order_num'] = 0;
  2125. $maf[$k]['me_sure'] = $req['me_sure'];
  2126. }
  2127. return $maf;
  2128. }
  2129. /**
  2130. * 周模板添加数据
  2131. * @param $time
  2132. * @param $req
  2133. * @param $doctor_id
  2134. * @return array
  2135. */
  2136. protected function week_getMaf($time, $req, $doctor_id)
  2137. {
  2138. $maf = [];
  2139. foreach ($time as $k => $v) {
  2140. // $maf[$k]['schedule_id']=$sid;
  2141. // $maf[$k]['schedule_date']=$req['schedule_date'];
  2142. $maf[$k]['type'] = $req['type'];
  2143. $maf[$k]['schedule_type'] = 1;
  2144. $maf[$k]['organization_id'] = $req['organization_id'];
  2145. $maf[$k]['docter_id'] = $doctor_id;
  2146. $maf[$k]['time_period_id'] = $v;
  2147. $maf[$k]['week'] = $req['week'];
  2148. }
  2149. return $maf;
  2150. }
  2151. /**
  2152. * 获取会话列表
  2153. * @return \Illuminate\Http\JsonResponse
  2154. * @author Liu-Yh
  2155. * Create By 2020/11/6 17:11
  2156. */
  2157. public function getUserListMsg()
  2158. {
  2159. $req = request()->post();
  2160. $user = $this->user;
  2161. $doctor_id = $user['id'];
  2162. $where[] = ['product_type', 2];
  2163. $where[] = ['order_status', '>', 2];
  2164. $where[] = ['payment_status', 2];
  2165. $where[] = ['docter_id', $doctor_id];
  2166. $list = Order::with('user')->where($where)->orderBy('receiving_time', 'desc')->get();
  2167. $newList = [];
  2168. if ($list) {
  2169. $list = $list->toArray();
  2170. foreach ($list as $k => $v) {
  2171. $messages = ImMessage::where(['senderId'=>'doctor_'.$doctor_id,'receiverId'=>'member_'.$v['user_id']])->orWhere(function ($query) use ($req,$doctor_id,$v){
  2172. $query->where(['senderId'=>'member_'.$v['user_id'],'receiverId'=>'doctor_'.$doctor_id]);
  2173. })->orderBy('id','desc')->first();
  2174. if($messages){
  2175. if($messages['type']=='text'){
  2176. $newList[$v['user_id']]['out_message'] = $messages['payload'];
  2177. }else if ($messages['type'] == 'audio'){
  2178. $newList[$v['user_id']]['out_message'] = "[语音消息]";
  2179. }else{
  2180. $newList[$v['user_id']]['out_message'] = "[图片消息]";
  2181. }
  2182. if (empty($messages['create_time'])){
  2183. $newList[$v['user_id']]['out_time'] = "";
  2184. }else{
  2185. $newList[$v['user_id']]['out_time'] = date('m-d',$messages['create_time']);
  2186. }
  2187. }else{
  2188. $newList[$v['user_id']]['out_message'] = '';
  2189. $newList[$v['user_id']]['out_time'] = '';
  2190. }
  2191. $newList[$v['user_id']]['flag'] = 'member_' . $v['user_id'];
  2192. $newList[$v['user_id']]['order_status'] = $v['order_status'];
  2193. $newList[$v['user_id']]['nickname'] = $v['user']['nickname'];
  2194. $newList[$v['user_id']]['avatar'] = $v['user']['avatar'];
  2195. $newList[$v['user_id']]['remark'] = !empty($v['user']['remark'])?$v['user']['remark']:'';
  2196. }
  2197. $newList = array_values($newList);
  2198. }
  2199. return out($newList);
  2200. }
  2201. /**
  2202. * 获取认证信息
  2203. * @return mixed
  2204. */
  2205. public function getRenInfo()
  2206. {
  2207. $req = request()->post();
  2208. $user = $this->user;
  2209. $doctor_id = $user['id'];
  2210. // 获取本人认证信息
  2211. $returnRes = [];
  2212. $docter = Docter::where('id', '=', $doctor_id)->first();
  2213. if ($docter) {
  2214. $docter = $docter->toArray();
  2215. } else {
  2216. return $docter;
  2217. }
  2218. $returnRes['info'] = $docter;
  2219. // 获取申请的认证机构
  2220. $org = DocterOrganization::with(['organization'])->where('docter_id', '=', $doctor_id)->get();
  2221. $oqf = DocterOrganization::with(['office', 'qualification'])->where('docter_id', '=', $doctor_id)->get();
  2222. foreach ($org as $k => $v) {
  2223. $org[$k]['province'] = Areas::where('id', '=', $v['organization']['province_id'])->select('name')->first()['name'];
  2224. $org[$k]['city'] = Areas::where('id', '=', $v['organization']['city_id'])->select('name')->first()['name'];
  2225. $org[$k]['area'] = Areas::where('id', '=', $v['organization']['area_id'])->select('name')->first()['name'];
  2226. $org[$k]['name'] = $v['organization']['name'];
  2227. }
  2228. $returnRes['orgList'] = $org;
  2229. $returnRes['oqf'] = $oqf;
  2230. return out($returnRes);
  2231. }
  2232. /**
  2233. * 获取通话记录
  2234. * @return mixed
  2235. */
  2236. public function callLog(){
  2237. $req = request()->post();
  2238. $user = $this->user;
  2239. $doctor_id = $user['id'];
  2240. $where =[];
  2241. if(isset($req['order_id'])&&!empty($req['order_id'])){
  2242. $where['order_id'] = $req['order_id'];
  2243. }
  2244. $where['docter_id'] = $doctor_id;
  2245. $list = CallLog::where($where)->get();
  2246. return out($list);
  2247. }
  2248. /**
  2249. * 通话列表
  2250. * @return mixed
  2251. */
  2252. public function user_call(){
  2253. $req = request()->post();
  2254. $user = $this->user;
  2255. $doctor_id = $user['id'];
  2256. $list=[];
  2257. // var_dump($doctor_id);
  2258. //die();
  2259. if(isset($req['user_id'])&&!empty($req['user_id'])){
  2260. $ids = [];
  2261. $orderList = Order::where(['user_id'=>$req['user_id'],'product_type'=>1,'payment_status'=>2])->select('id')->get();
  2262. if($orderList){
  2263. foreach ($orderList as $k=>$v){
  2264. $ids[$k] = $v['id'];
  2265. }
  2266. }
  2267. $lists = CallLog::with('orders')->whereIn('order_id',$ids)->orderBy('call_time', 'desc')->get();
  2268. if ($lists){
  2269. foreach ($lists as $k=>$v){
  2270. $list[$k]['time'] = $v['call_time'];
  2271. $list[$k]['talk_time'] = $v['talk_time'];
  2272. $list[$k]['order_sn'] = $v['orders']['order_sn'];
  2273. }
  2274. }
  2275. }else{
  2276. $orderList = Order::with(['user','calllog'])->where(['docter_id'=>$doctor_id,'product_type'=>1,'payment_status'=>2])->groupBy(['user_id'])->get();
  2277. if ($orderList){
  2278. foreach ($orderList as $k=>$v){
  2279. $list[$k]['user'] = $v['user'];
  2280. $calls = CallLog::where('docter_id',$doctor_id)->orderBy('id','desc')->first();
  2281. if ($calls){
  2282. $list[$k]['user']['dates'] = $calls['call_time'];
  2283. }else{
  2284. $list[$k]['user']['dates'] = '无';
  2285. }
  2286. $save = UserDocter::where(['user_id'=>$v['user']['id'],'docter_id'=>$doctor_id])->first();
  2287. if ($save) {
  2288. $list[$k]['user']['remark'] = $save['remark'];
  2289. } else {
  2290. $list[$k]['user']['remark'] = '';
  2291. }
  2292. $list[$k]['user']['log'] = $v['calllog'];
  2293. // $list[$k]['log']['date'] = date('m/d',strtotime(end($v['calllog'])['call_time']));
  2294. }
  2295. }
  2296. }
  2297. return out($list);
  2298. }
  2299. /**
  2300. * 获取聊天记录
  2301. * @return mixed
  2302. */
  2303. public function getImList(){
  2304. $req = request()->post();
  2305. $user = $this->user;
  2306. $doctor_id = $user['id'];
  2307. $where =[];
  2308. if(!isset($req['flag'])||empty($req['flag'])){
  2309. return out("",500,'用户flag不能为空');
  2310. }
  2311. $list = ImMessage::where(['senderId'=>'doctor_'.$doctor_id,'receiverId'=>$req['flag']])->orWhere(function ($query) use ($req,$doctor_id){
  2312. $query->where(['senderId'=>$req['flag'],'receiverId'=>'doctor_'.$doctor_id]);
  2313. })->get();
  2314. $newList=[];
  2315. if ($list){
  2316. foreach ($list as $k=>$v){
  2317. $decode = json_decode($v['text'],true);
  2318. // $newList[$k]['id']=$decode['id'];
  2319. $newList[$k]['messageId']=$decode[0]['messageId'];
  2320. $newList[$k]['type']=$decode[0]['type'];
  2321. $newList[$k]['senderId']=$decode[0]['senderId'];
  2322. $newList[$k]['receiverId']=$decode[0]['receiverId'];
  2323. $newList[$k]['timestamp']=$decode[0]['timestamp'];
  2324. $newList[$k]['payload']= json_decode($decode[0]['payload'],true);
  2325. }
  2326. }
  2327. return out($newList);
  2328. }
  2329. }