DoctorController.php 98 KB

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