PhOrders.php 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336
  1. <?php
  2. namespace app\common\model;
  3. use app\common\util\AppMsg;
  4. use app\hander\HelpHander;
  5. use think\Db;
  6. use think\Exception;
  7. use think\Log;
  8. use tools\Hwsms;
  9. class PhOrders extends Base
  10. {
  11. protected $table = 'ph_orders';
  12. public $status = [ //0=待分配 1=进行中 2=已完成 3=已作废 4=已结算
  13. 0=>'待分配',
  14. 1=>'进行中',
  15. 2=>'已完成',
  16. 3=>'已作废',
  17. 4=>'已结算',
  18. ];
  19. // 前端预约单
  20. public function bookOrder(){
  21. $data = [
  22. 'user_id' => input('userId/d',0),
  23. 'org_id' => input('orgId/d',0),
  24. 'contact' => input('contact','','trim'),
  25. 'phone' => input('phone','','trim'),
  26. 'name' => input('name','','trim'),
  27. 'gender' => input('gender/d',1),
  28. 'age' => input('age/d',0),
  29. 'bed' => input('bed','','trim'),
  30. 'ill' => input('ill','','trim'),
  31. 'start' => input('start',null,'trim'),
  32. 'remark' => input('remark','','trim'),
  33. 'dep_id' => input('depId/d',0),
  34. 'sn' => get_unique_id(),
  35. 'form' => 1,
  36. ];
  37. $validate = new \app\common\validate\PhOrders();
  38. $result = $validate->scene('book')->check($data,[]);
  39. if(true !== $result){
  40. $this->error = $validate->getError();
  41. return false;
  42. }
  43. Db::startTrans();
  44. try{
  45. $data['status'] = 0;
  46. $data['create_time'] = date('Y-m-d H:i:s');
  47. $orderId = Db::name('ph_orders')->insertGetId($data);
  48. if(!$orderId){
  49. \exception('创建订单失败');
  50. }
  51. Db::commit();
  52. }catch (Exception $e){
  53. Db::rollback();
  54. \think\facade\Log::write($e->getMessage(), 'info');
  55. $this->error = $e->getMessage();
  56. return false;
  57. }
  58. $this->sendSmsDispatch($data['name'],$data['phone'],$data['org_id'],$orderId);
  59. return true;
  60. }
  61. // 给调度短信发消息
  62. private function sendSmsDispatch($contact,$phone,$orgId,$fromId=0){
  63. $users = (new User())->get_ph_dispatch_user($orgId);
  64. foreach ($users as $k=>$v){
  65. if($v['mobile']){
  66. // 添加短信队列
  67. $content = AppMsg::getSmsMsg(AppMsg::SMS_PH_DISPATCH,[
  68. 'name' => $v['real_name'],
  69. 'contact' => $contact,
  70. 'phone' => $phone
  71. ]);
  72. $json = [
  73. 'orgId' => $orgId,
  74. 'mobiles' => [$v['mobile']],
  75. 'msg' => $content,
  76. 'fromId' => $fromId,
  77. 'type' => 2
  78. ];
  79. queue_push(json_encode($json),1);
  80. }
  81. // 添加推送队列 例:{"users":[1,2,3],"type":1,"msg":"有新订单需要你的处理","extra"=>[]}
  82. $json = [
  83. 'users' => [$v['id']],
  84. 'msg' => $content,
  85. 'extra' => [],
  86. 'type' => AppMsg::PUSH_PH_DISPATCH
  87. ];
  88. queue_push(json_encode($json),0);
  89. }
  90. }
  91. // 添加订单
  92. public function addSave($userId,$orgId,$type=0){ // type 1=调度端发单 0=后台发单
  93. $data = request()->post();
  94. $cate = isset($data['cateId'])?$data['cateId']:0;
  95. unset($data['cateId']);
  96. $data['dep_id'] =isset($data['depId'])?$data['depId']:0;
  97. $data['cate_id'] = $cate;
  98. $data['pre_money'] =isset($data['preMoney'])?$data['preMoney']:0;
  99. $data['org_id'] = $orgId;
  100. $data['user_id'] = $userId;
  101. $data['sn'] = get_unique_id();
  102. if(isset($data['userId'])){
  103. unset($data['userId'],$data['token'],$data['orgId']);
  104. }
  105. unset($data['depId'],$data['preMoney']);
  106. $validate = new \app\common\validate\PhOrders();
  107. $scene = 'add';
  108. if($type == 1){
  109. $scene = 'qadd';
  110. }
  111. $result = $validate->scene($scene)->check($data,[]);
  112. if(true !== $result){
  113. $this->error = $validate->getError();
  114. return false;
  115. }
  116. $data['start'] = $data['start']?$data['start']:null;
  117. $uids = $data['uids']?explode(',',$data['uids']):[];
  118. unset($data['uids']);
  119. if($uids && !$data['start']){
  120. $this->error = '未选择开始时间';
  121. return false;
  122. }
  123. Db::startTrans();
  124. try{
  125. $data['status'] = 0;
  126. $data['create_time'] = date('Y-m-d H:i:s');
  127. if($uids){
  128. $data['status'] = 1;
  129. }
  130. $ret = $this->insertGetId($data);
  131. if(!$ret){
  132. \exception('创建订单失败');
  133. }
  134. $orderId = $ret;
  135. if($uids){ // 创建工单
  136. $ph_todos = [];
  137. foreach ($uids as $k=>$v){
  138. $ph_todos[] = [
  139. 'org_id' => $data['org_id'],
  140. 'order_id' => $orderId,
  141. 'user_id' => $userId,
  142. 'worker_id' => $v,
  143. 'start' => $data['start'],
  144. 'create_time' => date('Y-m-d H:i:s'),
  145. 'status' => 1
  146. ];
  147. }
  148. $ret = Db::name('ph_todo')->insertAll($ph_todos);
  149. if($ret != count($ph_todos)){
  150. \exception('创建订单失败');
  151. }
  152. }
  153. Db::commit();
  154. return true;
  155. }catch (Exception $e){
  156. Db::rollback();
  157. \think\facade\Log::write($e->getMessage(), 'info');
  158. $this->error = $e->getMessage();
  159. return false;
  160. }
  161. }
  162. public function editSave($userId,$orgId){
  163. $data = request()->post();
  164. $validate = new \app\common\validate\PhOrders();
  165. $result = $validate->scene('edit')->check($data,[]);
  166. if(true !== $result){
  167. $this->error = $validate->getError();
  168. return false;
  169. }
  170. $data['start'] = $data['start']?$data['start']:null;
  171. $data['end'] = $data['end']?$data['end']:null;
  172. $old = Db::name('ph_orders')
  173. ->where('id',$data['id'])->find();
  174. if(!$old){
  175. $this->error = '订单不存在';
  176. return false;
  177. }
  178. if($old['status'] == 4){
  179. $this->error = '已结算的订单不能修改';
  180. return false;
  181. }
  182. Db::startTrans();
  183. try{
  184. $data['update_time'] = date('Y-m-d H:i:s');
  185. $orderId = Db::name('ph_orders')
  186. ->where('id',$data['id'])->update($data);
  187. if(!$orderId){
  188. \exception('创建订单失败');
  189. }
  190. Db::commit();
  191. $this->saveLog($userId,$orgId,$data['id'],1,$old);// 订单修改日志
  192. return true;
  193. }catch (Exception $e){
  194. Db::rollback();
  195. \think\facade\Log::write($e->getMessage(), 'info');
  196. $this->error = $e->getMessage();
  197. return false;
  198. }
  199. }
  200. // 派单
  201. public function sendSave($userId,$orgId){
  202. $data = [
  203. 'id' => input('id/d',0),
  204. // 'cate_id' => input('cate_id/d',0),
  205. // 'price' => input('price/f',0),
  206. 'uids' => input('uids','','trim'),
  207. 'start' => input('start',null,'trim'),
  208. 'remark' => input('remark','','trim'),
  209. ];
  210. // $cateId = input('cateId');
  211. //
  212. // $data['cate_id'] = $cateId?$cateId:$data['cate_id'];
  213. $uids = $data['uids']?explode(',',$data['uids']):[];
  214. if(!$uids){
  215. $this->error ='请选择执行护工';
  216. return false;
  217. }
  218. unset($data['uids']);
  219. if(!$data['start']){
  220. $this->error = '未选择开始时间';
  221. return false;
  222. }
  223. if($uids){
  224. $ph_todo = Db::name('ph_todo')
  225. ->where('order_id',$data['id'])
  226. ->where('status',1)
  227. ->where('user_id','in',$uids)
  228. ->find();
  229. if($ph_todo){
  230. $this->error = '此订单正在服务中';
  231. return false;
  232. }
  233. }
  234. $info = Db::name('ph_orders')
  235. ->where('id',$data['id'])->find();
  236. if(!$info){
  237. $this->error = '订单不存在';
  238. return false;
  239. }
  240. if(!in_array($info['status'],[0,1])){
  241. $this->error = '订单该状态无法派单';
  242. return false;
  243. }
  244. if($data['start'] && $info['start'] && $data['start'] < $info['start']){
  245. $this->error = '开始时间不能小于订单的开始时间';
  246. return false;
  247. }
  248. Db::startTrans();
  249. try{
  250. if($uids){
  251. foreach ($uids as $k=>$v){
  252. $todoList = Db::name('ph_todo')->where('order_id',$data['id'])->where('worker_id',$v)->whereIn('status',[1,2])->select();
  253. if(count($todoList) >= 1){
  254. $arr = $this->compareDate($todoList,$data['start']);
  255. if(!$arr){
  256. $this->error = '该护工在此时间段工单未完成,不能派单';
  257. return false;
  258. }
  259. }
  260. }
  261. }
  262. $sdata['update_time'] = date('Y-m-d H:i:s');
  263. $sdata['status'] = 1;
  264. // $sdata['cate_id'] = $data['cate_id'];
  265. // $sdata['price'] = $data['price'];
  266. if($info['status'] == 0){
  267. $orderId = Db::name('ph_orders')
  268. ->where('id',$data['id'])->update($sdata);
  269. if(!$orderId){
  270. \exception('订单修改失败');
  271. }
  272. }
  273. if($uids){ // 创建工单
  274. $todos = [];
  275. foreach ($uids as $k=>$v){
  276. $todos[] = [
  277. 'org_id' => $orgId,
  278. 'order_id' => $data['id'],
  279. 'user_id' => $userId,
  280. 'worker_id' => $v,
  281. 'start' => $data['start'],
  282. 'remark' => $data['remark'],
  283. 'create_time' => date('Y-m-d H:i:s'),
  284. 'status' => 1
  285. ];
  286. }
  287. $ret = Db::name('ph_todo')->insertAll($todos);
  288. if($ret != count($todos)){
  289. \exception('创建订单失败');
  290. }
  291. }
  292. Db::commit();
  293. return true;
  294. }catch (Exception $e){
  295. Db::rollback();
  296. \think\facade\Log::write($e->getMessage(), 'info');
  297. $this->error = $e->getMessage();
  298. return false;
  299. }
  300. }
  301. // 完成订单
  302. public function finishSave($userId,$orgId){
  303. $data = [
  304. 'id' => input('id/d',0),
  305. 'end' => input('end',null,'trim'),
  306. 'amount' => input('amount/f',0)
  307. ];
  308. if($data['amount'] <= 0){
  309. $this->error = '收费金额不能小于0';
  310. return false;
  311. }
  312. if(!$data['end']){
  313. $this->error = '未选择服务结束日期';
  314. return false;
  315. }
  316. $info = Db::name('ph_orders')->where('id',$data['id'])->find();
  317. if(!$info){
  318. $this->error = '订单不存在';
  319. return false;
  320. }
  321. if($info['status'] != 1){
  322. $this->error = '订单该状态无法完成';
  323. return false;
  324. }
  325. if($data['end'] && $info['start'] && $data['end'] < $info['start']){
  326. $this->error = '结束时间不能小于订单的开始时间';
  327. return false;
  328. }
  329. if($data['amount'] != $info['pre_money']){
  330. $this->error = '收费金额与预收金不一致,不能完成';
  331. return false;
  332. }
  333. Db::startTrans();
  334. try{
  335. $sdata['update_time'] = date('Y-m-d H:i:s');
  336. $sdata['status'] = 2;
  337. $sdata['amount'] = $data['amount'];
  338. $sdata['end'] = $data['end'];
  339. $orderId = Db::name('ph_orders')->where('id',$data['id'])->update($sdata);
  340. if(!$orderId){
  341. \exception('订单修改失败');
  342. }
  343. $ph_todos = Db::name('ph_todo')
  344. ->where('order_id',$data['id'])
  345. ->where('status',1)->select();
  346. foreach ($ph_todos as $k=>$v){
  347. Db::name('ph_todo')->where('id',$v['id'])->update([
  348. 'update_time' => date('Y-m-d H:i:s'),
  349. 'status' => 2,
  350. 'end' => $data['end'],
  351. 'day' => $this->getWorkerDay($v['start'],$data['end'])
  352. ]);
  353. }
  354. Db::commit();
  355. return true;
  356. }catch (Exception $e){
  357. Db::rollback();
  358. \think\facade\Log::write($e->getMessage(), 'info');
  359. $this->error = $e->getMessage();
  360. return false;
  361. }
  362. }
  363. // 修改工单
  364. public function edit_todo($userId,$orgId){
  365. $data = [
  366. 'id' => input('id/d',0),
  367. 'start' => input('start',null,'trim'),
  368. 'end' => input('end',null,'trim'),
  369. 'remark' => input('remark','','trim'),
  370. 'status' => input('status/d',0),
  371. 'day' => input('day/f',0)
  372. ];
  373. $ph_todo = Db::name('ph_todo')->where('id',$data['id'])->find();
  374. if(!$ph_todo){
  375. $this->error = '工单不存在';
  376. return false;
  377. }
  378. $info = Db::name('ph_orders')->where('id',$ph_todo['order_id'])->find();
  379. if(!$info){
  380. $this->error = '订单不存在';
  381. return false;
  382. }
  383. if($info['status'] == 3||$info['status'] == 4){
  384. $this->error = '订单该状态无法修改工单';
  385. return false;
  386. }
  387. if(!$data['start'] || !$data['end']){
  388. $this->error = '未选择开始时间或结束时间';
  389. return false;
  390. }
  391. if($data['end'] && $info['start'] && $data['end'] < $info['start']){
  392. $this->error = '结束时间不能小于订单的开始时间';
  393. return false;
  394. }
  395. $todoList = Db::name('ph_todo')
  396. ->where('order_id',$info['id'])
  397. ->group('user_id')
  398. ->select();
  399. foreach ($todoList as $k=>$v){
  400. $todos = Db::name('ph_todo')
  401. ->where('order_id',$v['order_id'])
  402. ->where('user_id',$v['user_id'])
  403. ->where('id','<>',$data['id'])
  404. ->select();
  405. if(count($todos) >=1){
  406. foreach ($todos as $kk=>$vv){
  407. $ret = $this->is_time_cross($data['start'],$data['end'],$vv['start'],$vv['end']);
  408. if($ret){
  409. $this->error = '该时间段有未完成的工单,不能修改';
  410. return false;
  411. }
  412. }
  413. }
  414. }
  415. Db::startTrans();
  416. try{
  417. $data['update_time'] = date('Y-m-d H:i:s');
  418. if($data['day'] <= 0){
  419. $data['day'] = $this->getWorkerDay($data['start'],$data['end']);
  420. }
  421. $ret = Db::name('ph_todo')->where('id',$data['id'])->update($data);
  422. if(!$ret){
  423. \exception('工单修改失败');
  424. }
  425. Db::commit();
  426. $this->saveLog($userId,$orgId,$data['id'],2,$ph_todo);// 工单修改日志
  427. return true;
  428. }catch (Exception $e){
  429. Db::rollback();
  430. \think\facade\Log::write($e->getMessage(), 'info');
  431. $this->error = $e->getMessage();
  432. return false;
  433. }
  434. }
  435. // 计算工期
  436. public function getWorkerDay($start,$end){
  437. if($end <= $start||!$start||!$end){
  438. return 0;
  439. }
  440. $day1 = date('Y-m-d',strtotime($start));
  441. $day2 = date('Y-m-d',strtotime($end));
  442. $day = 0;
  443. if($day1 == $day2){ // 当天
  444. if($start < $day1.' 12:00:00' && $end < $day1.' 12:00:00'){
  445. $day = 0.5;
  446. }else if($start < $day1.' 12:00:00' && $end < $day1.' 12:00:00'){
  447. $day = 0.5;
  448. }else {
  449. $day = 1;
  450. }
  451. }else{ // 跨天
  452. if($start < $day1.' 12:00:00'){
  453. $day = 1;
  454. }else{
  455. $day = 0.5;
  456. }
  457. $i = 1;
  458. while (true){
  459. $dd = date('Y-m-d',strtotime($start) + $i*24*60*60);
  460. if($dd == $day2){
  461. if($end != $day2.' 00:00:00'){
  462. if($end > $day2.' 00:00:00'&&$end <= $day2.' 12:00:00'){
  463. $day += 0.5;
  464. }else{
  465. $day += 1;
  466. }
  467. }
  468. break;
  469. }else{
  470. $day += 1;
  471. $i++;
  472. }
  473. }
  474. }
  475. return $day;
  476. }
  477. public function saveLog($userId,$orgId,$id,$type,$old){
  478. if($type == 1){ // 修改订单
  479. $new = Db::name('ph_orders')
  480. ->where('id',$id)->find();
  481. }else{
  482. $new = Db::name('ph_todo')->where('id',$id)->find();
  483. }
  484. $data = [
  485. 'org_id' => $orgId,
  486. 'user_id' => $userId,
  487. 'type' => $type,
  488. 'bus_id' => $id,
  489. 'old_data' => json_encode($old,JSON_UNESCAPED_UNICODE),
  490. 'new_data' => json_encode($new,JSON_UNESCAPED_UNICODE),
  491. 'create_time' => date('Y-m-d H:i:s')
  492. ];
  493. Db::name('ph_orders_log')->insert($data);
  494. }
  495. public function getInfo($id){
  496. $info = $this->where('id',$id)->find()->toArray();
  497. $off = model('Config')->getConfig('ph_order_cancel_time',cur_org_id());
  498. $info['is_zf'] = 0;
  499. if($off){
  500. $start = strtotime($info['create_time']) + $off*60*60;
  501. $end = strtotime(date('Y-m-d H:i:s'));
  502. if($start < $end){
  503. $info['is_zf'] = 1;
  504. }
  505. }
  506. $info['end'] = $info['end']? $info['end']:'';
  507. $info['cancel_time'] = $info['cancel_time']? $info['cancel_time']:'';
  508. $info['update_time'] = $info['update_time']? $info['update_time']:'';
  509. $info['settlementUseId'] = $info['settlement_use_id']? $info['settlement_use_id']:0;
  510. $info['settlement_time'] = $info['settlement_time']? $info['settlement_time']:"";
  511. if($info){
  512. $info['cate_name'] = '';
  513. if($info['cate_id'] > 0){
  514. $info['cate_name'] = Db::name('cate')
  515. ->where('id',$info['cate_id'])
  516. ->value('title');
  517. }
  518. $info['dep_name'] = '';
  519. if($info['dep_id'] > 0){
  520. $info['dep_name'] = Db::name('dep')
  521. ->where('id',$info['dep_id'])
  522. ->value('title');
  523. }
  524. $info['user_name'] = '';
  525. if($info['user_id'] > 0){
  526. $info['user_name'] = Db::name('user')
  527. ->where('id',$info['user_id'])
  528. ->value('real_name');
  529. if(empty($info['user_name'])){
  530. $info['user_name'] = Db::name('wxuser')
  531. ->where('id',$info['user_id'])
  532. ->value('nickname');
  533. }
  534. }
  535. $info['cancel_user_name'] = '';
  536. if($info['cancel_user_id'] > 0){
  537. $info['cancel_user_name'] = Db::name('user')
  538. ->where('id',$info['cancel_user_id'])
  539. ->value('real_name');
  540. }
  541. $info['settlement_use_name'] = '';
  542. if($info['settlement_use_id'] > 0){
  543. $info['settlement_use_name'] = Db::name('user')
  544. ->where('id',$info['settlement_use_id'])
  545. ->value('real_name');
  546. }
  547. $todos = Db::name('ph_todo')
  548. ->where('order_id',$id)->select();
  549. foreach ($todos as $k=>$v){
  550. $todos[$k]['user_name'] = Db::name('user')
  551. ->where('id',$v['user_id'])
  552. ->value('real_name');
  553. $user_id = Db::name('worker')
  554. ->where('id',$v['worker_id'])
  555. ->value('user_id');
  556. $todos[$k]['worker_name'] = Db::name('user')
  557. ->where('id',$user_id)
  558. ->value('real_name');
  559. $todos[$k]['end'] = $v['end']? $info['end']:"";
  560. }
  561. $info['todo'] = $todos;
  562. // 获取缴费记录
  563. $pays = Db::name('ph_order_pay')->where('status',1)->where('order_id',$id)->select();
  564. $pays = $pays?$pays:[];
  565. $info['pays'] = $pays;
  566. // 获取退款记录
  567. $refunds = Db::name('ph_order_refund')->where('order_id',$id)->select();
  568. $refunds = $refunds?$refunds:[];
  569. $info['refunds'] = $refunds;
  570. }
  571. return $info;
  572. }
  573. public function orderTotal($start,$end,$price){
  574. $day = diffBetweenTwoDays($start,$end);
  575. $day = $day > 0?$day:1;
  576. return $day*$price;
  577. }
  578. //验证用户是否有待支付追加金额的订单
  579. public function checkAddAmount($userId){
  580. $ret = $this
  581. ->where('user_id',$userId)
  582. ->where('status',2)
  583. ->where('completion',0)
  584. ->where('end','<',date('Y-m-d'))
  585. ->where('add_amount','>',0)
  586. ->find();
  587. return $ret?false:true;
  588. }
  589. //订单详情
  590. public function orderDetail($id,$type=0){
  591. $map = [];
  592. if($type==0){
  593. $map[] = ['user_del','=',0];
  594. }elseif ($type==1){
  595. $map[] = ['worker_del','=',0];
  596. }
  597. $info = $this->where('id',$id)->where($map)
  598. ->find()->toArray();
  599. if(empty($info)) HelpHander::error('订单信息不存在');
  600. $info['start'] = date('Y/m/d',strtotime($info['start']));
  601. $info['end'] = date('Y/m/d',strtotime($info['end']));
  602. $info['orgName'] = Db::name('org')
  603. ->where('id',$info['org_id'])->value('title');
  604. $info['addrTitle'] = (new Worker())->getAddressName($info['addr_id']);
  605. $info['userInfo'] = (new User())->getUserInfo($info['user_id']);
  606. $info['workerInfo'] = (new Worker())->workerDetail($info['worker_id'],$info['org_id'],$info['user_id']);
  607. $info['cateInfo'] = (new Cate())->info($info['cate_id']);
  608. $info['selfcareInfo'] = Db::name('options')->where('id',$info['selfcare'])
  609. ->where('type',1)->value('title');
  610. $info['refundInfo'] = [];
  611. if($info['refund_status']==1){//退款明细
  612. $info['refundInfo'] = (new OrderRefund())->info($info['id']);
  613. $info['statusName'] =(new OrderRefund())->status[$info['refundInfo']['status']];
  614. }else{
  615. $info['statusName'] = $this->status[$info['status']];
  616. }
  617. $cancelName = '';
  618. $cancelType = '';
  619. if($info['status']==5){
  620. if($info['cancel_type']==3){
  621. $cancelName =$cancelType= '系统取消';
  622. }
  623. if($info['cancel_type']==2){
  624. $cancelName = Db::name('user')->
  625. where('id',$info['cancel_user_id'])
  626. ->value('nickname');
  627. $cancelType = '用户取消';
  628. }
  629. if($info['cancel_type']==1){
  630. $cancelName = Db::name('worker')->
  631. where('id',$info['cancel_user_id'])
  632. ->value('name');
  633. $cancelType = '护工取消';
  634. }
  635. }
  636. $info['cancelName'] = $cancelName;
  637. $info['cancelType'] = $cancelType;
  638. $info['cancelTypeId'] = $info['cancel_type'];
  639. // 添加订单评价信息
  640. $info['comment'] = null;
  641. if($info['status'] == 5){
  642. $comment = Db::name('comment')->where('order_id',$id)->find();
  643. $info['comment'] = $comment;
  644. }
  645. $info['addOrderInfo'] = [];
  646. if($info['add_amount']>0){//追加金额明细
  647. $addOrder = Db::name('order_add')
  648. ->alias('a')
  649. ->join('options b','a.options_id=b.id')
  650. ->where('a.order_id',$info['id'])
  651. ->field('a.*,b.title')
  652. ->select()
  653. ->toArray();
  654. $info['addOrderInfo'] = $addOrder;
  655. }
  656. return $info;
  657. }
  658. //订单列表
  659. public function orderList($orgId,$status,$page,$size,$userId=0){
  660. $start = ($page - 1) * $size;
  661. if($status >= 0){
  662. if($userId >0){
  663. if($status==2){
  664. $map[] = ['status','in',[2,4]];
  665. }else{
  666. $map[] = ['status','=',$status];
  667. }
  668. }
  669. }
  670. if($userId > 0){
  671. $map[] = ['user_id','=',$userId];
  672. $map[] = ['form','=',1];
  673. }
  674. $map[] = ['org_id', '=', $orgId];
  675. $list = $this->where($map)
  676. ->limit($start,$size)
  677. ->order('id','desc')
  678. ->select();
  679. $list = $list?$list->toArray():[];
  680. foreach ($list as $k=>$v){
  681. }
  682. return $list;
  683. }
  684. //调度订单列表
  685. public function orderList1($orgId,$status,$page,$size){
  686. $start = ($page - 1) * $size;
  687. if($status >= 0){
  688. if($status==2){
  689. $map[] = ['status','in',[2,4]];
  690. }else{
  691. $map[] = ['status','=',$status];
  692. }
  693. }
  694. $map[] = ['org_id', '=', $orgId];
  695. $list = $this->where($map)
  696. ->limit($start,$size)
  697. ->field('id,sn,contact,phone,start,create_time')
  698. ->order('id','desc')
  699. ->select();
  700. $list = $list?$list->toArray():[];
  701. foreach ($list as $k=>$v){
  702. }
  703. return $list;
  704. }
  705. //订单列表
  706. public function workerOrderList($orgId,$status,$page,$size,$userId=0){
  707. $start = ($page - 1) * $size;
  708. if($status >= 0){
  709. $map[] = ['status','=',$status];
  710. }else{
  711. $map[] = ['status','>',0];
  712. }
  713. $worker = Db::name('worker')
  714. ->where('user_id',$userId)
  715. ->find();
  716. if(empty($worker)){
  717. return [];
  718. }
  719. $map[] = ['org_id', '=', $orgId];
  720. $map[] = ['worker_id', '=', $worker['id']];
  721. $todo = Db::name('ph_todo')
  722. ->where($map)
  723. ->field('id,start,day,status,create_time')
  724. ->limit($start,$size)
  725. ->select();
  726. return $todo;
  727. }
  728. //取消订单
  729. public function cancelOrder($id,$note,$userId){
  730. if(!$note){
  731. $this->error = '未填写作废原因';
  732. return false;
  733. }
  734. $info = Db::name('ph_orders')
  735. ->where('id',$id)->find();
  736. if(!$info){
  737. $this->error = '订单不存在';
  738. return false;
  739. }
  740. if($info['status'] == 3||$info['status'] == 4){
  741. $this->error = '订单已作废或已结算';
  742. return false;
  743. }
  744. $off = model('Config')->getConfig('ph_order_cancel_time',cur_org_id());
  745. if($off){
  746. $info = Db::name('ph_orders')->where('id',$id)->find();
  747. $start = strtotime($info['create_time']) + $off*60*60;
  748. $end = strtotime(date('Y-m-d H:i:s'));
  749. if($start < $end){
  750. $this->error = '该订单已超过作废时间';
  751. return false;
  752. }
  753. }
  754. Db::startTrans();
  755. try{
  756. $res =Db::name('ph_orders')
  757. ->where('id',$id)
  758. ->update([
  759. 'status'=>3,
  760. 'cancel_reason'=>$note,
  761. 'cancel_time'=>getTime(),
  762. 'cancel_user_id'=>$userId
  763. ]);
  764. if(!$res){
  765. \exception('操作失败');
  766. }
  767. Db::name('ph_todo')->where('order_id',$id)->update(['status' => 0]);
  768. Db::commit();
  769. }catch (Exception $e){
  770. Db::rollback();
  771. \think\facade\Log::write($e->getMessage(), 'info');
  772. $this->error = '操作失败';
  773. return false;
  774. }
  775. return true;
  776. }
  777. //用户护工删除订单
  778. public function delOrder($id,$userId,$type=0){
  779. $info = $this->getOrderDetail($id,$userId,$type);
  780. if(!in_array($info['status'],[3,4,5])) HelpHander::error('当前订单状态不能删除');
  781. if($type==0){
  782. $params = ['user_del'=>1,'user_del_time'=>getTime()];
  783. }else{
  784. $params = ['worker_del'=>1,'worker_del_time'=>getTime()];
  785. }
  786. $res = $this->where('id',$id)
  787. ->update($params);
  788. return $res;
  789. }
  790. //用户发起退款
  791. public function orderRefund($id,$amount,$reason,$desc,$userId){
  792. $info = $this->getOrderDetail($id,$userId);
  793. if($info['amount'] < $amount) HelpHander::error('退款金额不能大于订单金额');
  794. if($info['refund_status']==1) HelpHander::error('当前订单已申请过退款');
  795. if(!in_array($info['status'],[1,2])) HelpHander::error('当前订单状态不能退款');
  796. $refundModel = new OrderRefund();
  797. Db::startTrans();
  798. try{
  799. $params = [
  800. 'sn'=>get_unique_id(),
  801. 'order_id'=>$id,
  802. 'user_id'=>$userId,
  803. 'amount'=>$amount,
  804. 'reason'=>$reason,
  805. 'desc'=>$desc,
  806. 'is_cx'=>0,
  807. 'create_time'=>getTime(),
  808. ];
  809. if($refundModel->info($id)){
  810. if(!$refundModel->where('order_id',$id)->save($params)) exception('保存退款单失败');
  811. }else{
  812. if(!$refundModel->save($params)) exception('保存退款单失败');
  813. }
  814. if(!$this->where('id',$id)->update(['refund_status'=>1])){
  815. exception('更新订单失败');
  816. }
  817. $om = new \app\model\OrderMessage();
  818. $om->saveMassage($userId,'发起退款申请');
  819. Db::commit();
  820. return true;
  821. }catch (Exception $e){
  822. HelpHander::error($e->getMessage());
  823. Db::rollback();
  824. }
  825. }
  826. public function getOrderDetail($id,$userId,$type=0){
  827. if($type==0){
  828. $map[] = ['user_id','=',$userId];
  829. $map[] = ['user_del','=',0];
  830. }else{
  831. $map[] = ['worker_id','=',$userId];
  832. $map[] = ['worker_del','=',0];
  833. }
  834. $info = $this
  835. ->where('id',$id)
  836. ->where($map)
  837. ->find();
  838. if(empty($info)) HelpHander::error('订单信息不存在');
  839. return $info;
  840. }
  841. //护工领取订单
  842. public function orderReceive($workerId,$id){
  843. $info = $this->getOrderDetail($id,$workerId,1);
  844. if($info['status']!=1) HelpHander::error('当前订单已领取');
  845. $ret = $this->where('id',$id)
  846. ->save(['status'=>2,'receive_time'=>getTime()]);
  847. return $ret;
  848. }
  849. //撤销退款
  850. public function cxOrder($id){
  851. $info = (new OrderRefund())->info($id);
  852. if($info['status']!=0) HelpHander::error('当前订单不能撤销');
  853. Db::startTrans();
  854. try{
  855. $ret = $this->where('id',$id)
  856. ->save(['refund_status'=>0,'refund_amount'=>0]);
  857. if(!$ret) exception('更新订单失败');
  858. $ret = (new OrderRefund())->where('order_id',$id)
  859. ->save(['is_cx'=>1,'cx_time'=>getTime()]);
  860. if(!$ret) exception('退款单更新失败');
  861. Db::commit();
  862. return true;
  863. }catch (Exception $e){
  864. HelpHander::error($e->getMessage());
  865. Db::rollback();
  866. }
  867. return $ret;
  868. }
  869. // 用户正在进行的最新的陪护单
  870. public function latestOrder($userId){
  871. $map[] = ['user_id','=',$userId];
  872. $map[] = ['user_del','=','0'];
  873. $map[] = ['refund_status','=','0'];
  874. $map[] = ['status','=','2'];
  875. $info = Db::name('ph_orders')->where($map)->order('id desc')->find();
  876. if($info){
  877. $worker = Db::name('worker')->where('id',$info['worker_id'])->value('name');
  878. $info['worker_name'] = $worker?$worker:'';
  879. }
  880. return $info?$info:null;
  881. }
  882. //获取护工已预订日期
  883. public function bookDateList($workerId){
  884. $curday = date('Y-m-d');
  885. $lists = Db::name('ph_orders')
  886. ->where('end','>=',$curday)
  887. ->where('worker_id',$workerId)
  888. ->where('status','in',[1,2])
  889. ->where('refund_status',0)
  890. ->order('id asc')
  891. ->field('id,start,end,cate_id')
  892. ->select();
  893. foreach ($lists as $k=>$v){
  894. $lists[$k]['cate_name'] = Db::name('cate')->where('id',$v['cate_id'])->value('title');
  895. }
  896. return $lists?$lists:[];
  897. }
  898. //支付
  899. public function pay($orderId){
  900. $params = $this->where('id',$orderId)
  901. ->find();
  902. $workerModel = new Worker();
  903. $cateInfo = (new Cate())->info($params['cate_id']);
  904. if(!$workerModel->checkServiceNum($params['worker_id'],$cateInfo['nums'],$params['start'],$params['end'],$params['addr_id'],$msg)){
  905. HelpHander::error($msg);
  906. }
  907. $openid = Db::name('user_oauth')->where('user_id',$params['user_id'])->value('openid');
  908. $config = config('app.wx_config');
  909. $app = \EasyWeChat\Factory::payment($config);
  910. $result = $app->order->unify([
  911. 'body' => '订单-'.$params['sn'],
  912. 'out_trade_no' => $params['sn'],
  913. 'total_fee' => $params['amount']*100,
  914. 'spbill_create_ip' => request()->ip(), // 可选,如不传该参数,SDK 将会自动获取相应 IP 地址
  915. 'notify_url' => (string)url('api/Notify/wxorder',[],false,true), // 支付结果通知网址,如果不设置则会使用配置里的默认地址
  916. 'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型
  917. 'openid' => $openid,
  918. ]);
  919. tplog($result);
  920. if($result['return_code'] != 'SUCCESS' || $result['result_code'] != 'SUCCESS'){
  921. HelpHander::error('下单失败1');
  922. }
  923. $jssdk = $app->jssdk;
  924. $json = $jssdk->bridgeConfig($result['prepay_id'],false);
  925. $json['order_id'] = $orderId;
  926. return $json;
  927. }
  928. //结算订单
  929. public function js($orderId=[],$web_bl,$web_deduct,$org){
  930. $succ = [];
  931. $error = [];
  932. foreach ($orderId as $k=>$v){
  933. Db::startTrans();
  934. try{
  935. $info = $this->where('id',$v)->find()->toArray();
  936. $total = $info['amount'];
  937. $money1 = ($total-$web_deduct)*$web_bl;
  938. if($money1 > 0){
  939. $ph_todo = Db::name('ph_todo')
  940. ->where('order_id',$v)
  941. ->where('status','<>',0)
  942. ->select();
  943. $days = Db::name('ph_todo')
  944. ->where('order_id',$v)
  945. ->where('status','<>',0)
  946. ->sum('day');
  947. if($days >0){
  948. $avgPrice = round($money1/$days,2);
  949. if(!empty($ph_todo)){
  950. foreach ($ph_todo as $k1=>$v1){
  951. $workerMoney = Db::name('worker')
  952. ->where('id',$v1['worker_id'])->value('balance');
  953. $money = $avgPrice*$v1['day'];
  954. if($money >0){
  955. $newMoney = $workerMoney+$money;
  956. $res = Db::name('worker')
  957. ->where('id',$v1['worker_id'])
  958. ->update(['balance'=>$newMoney]);
  959. if(!$res) \exception('订单id:'.$v.'余额更新失败');
  960. $res = Db::name('worker')
  961. ->where('id',$v1['worker_id'])
  962. ->inc('cumulative_money',$money);
  963. if(!$res) \exception('订单id:'.$v.'累计收入更新失败');
  964. $res = Db::name('worker_balance')->insert([
  965. 'worker_id'=>$v1['worker_id'],
  966. 'org_id'=>$org,
  967. 'user_id'=>is_login(),
  968. 'money'=>$money,
  969. 'from_id'=>$v,
  970. 'type'=>1,
  971. 'remark'=>'id:'.$v.'订单结算('.$info['sn'].')',
  972. 'create_time'=>date('Y-m-d H:i:s')
  973. ]);
  974. if(!$res) \exception('订单id:'.$v.' 结算记录添加失败');
  975. $cc = [
  976. 'settlement_money'=>$money
  977. ];
  978. $res= Db::name('ph_todo')
  979. ->where('id',$v1['id'])
  980. ->update($cc);
  981. if(!$res) \exception('订单id:'.$v.' 更新ph_todo 失败');
  982. }
  983. }
  984. }
  985. }
  986. }
  987. $res = $this->where('id',$v)
  988. ->update([
  989. 'status'=>4,
  990. 'settlement_money'=>$money1 >0?$money1:0,
  991. 'settlement_use_id'=>is_login(),
  992. 'settlement_time'=>date('Y-m-d H:i:s'),
  993. ]);
  994. if(!$res) \exception('订单id:'.$v.'更新失败');
  995. Db::commit();
  996. $succ[] = $v;
  997. }catch (Exception $e){
  998. $error[] = $e->getMessage();;
  999. Db::rollback();
  1000. }
  1001. }
  1002. $msg = '';
  1003. if(count($error) > 0){
  1004. $msg = '结算成功:'.count($succ).',失败:'.count($error).',失败订单:'.implode(',',$error);
  1005. $a = ['code'=>0,'msg'=>$msg];
  1006. }else{
  1007. $msg = '结算成功:'.count($succ).',失败:'.count($error);
  1008. $a = ['code'=>1,'msg'=>$msg];
  1009. }
  1010. return $a;
  1011. }
  1012. //用户完成
  1013. public function finish($orderId){
  1014. $params = $this->where('id',$orderId)->find();
  1015. if(!$params){
  1016. HelpHander::error('订单不存在');
  1017. }
  1018. if($params['refund_status'] == 1){
  1019. HelpHander::error('退款中不能完成');
  1020. }
  1021. if($params['status'] != 2){
  1022. HelpHander::error('该状态不能完成');
  1023. }
  1024. if($params['add_amount'] > 0){ // 追加大于0,支付
  1025. $openid = Db::name('user_oauth')->where('user_id',$params['user_id'])->value('openid');
  1026. $config = config('app.wx_config');
  1027. $app = \EasyWeChat\Factory::payment($config);
  1028. $result = $app->order->unify([
  1029. 'body' => '订单-'.$params['sn'],
  1030. 'out_trade_no' => $params['sn'].mt_rand(100,999),
  1031. 'total_fee' => $params['add_amount']*100,
  1032. 'spbill_create_ip' => request()->ip(), // 可选,如不传该参数,SDK 将会自动获取相应 IP 地址
  1033. 'notify_url' => (string)url('api/Notify/wxaddorder',[],false,true), // 支付结果通知网址,如果不设置则会使用配置里的默认地址
  1034. 'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型
  1035. 'openid' => $openid,
  1036. 'attach' => $orderId
  1037. ]);
  1038. tplog($result);
  1039. if($result['return_code'] != 'SUCCESS' || $result['result_code'] != 'SUCCESS'){
  1040. HelpHander::error('操作失败');
  1041. }
  1042. $jssdk = $app->jssdk;
  1043. $json = $jssdk->bridgeConfig($result['prepay_id'],false);
  1044. $json['type'] = 1;
  1045. return $json;
  1046. }else{ //直接完成
  1047. $sdata = [
  1048. 'status' => 3,
  1049. 'finish_time' => date('Y-m-d H:i:s'),
  1050. ];
  1051. if($params['completion'] == 0){
  1052. $sdata['completion'] = 1;
  1053. $sdata['completion_time'] = date('Y-m-d H:i:s');
  1054. }
  1055. $ret = Db::name('ph_orders')->where('id',$orderId)->update($sdata);
  1056. if(!$ret){
  1057. HelpHander::error('操作失败');
  1058. }
  1059. return ['type' => 0];
  1060. }
  1061. }
  1062. //护工追加金额
  1063. public function orderAdd($data,$orderId){
  1064. $total = 0;
  1065. $arr = [];
  1066. foreach ($data as $k=>$v){
  1067. $total+=floatval($v);
  1068. if(!empty($v) && $v > 0){
  1069. $arr[] = [
  1070. 'order_id'=>$orderId,
  1071. 'amount'=>$v,
  1072. 'options_id'=>$k,
  1073. ];
  1074. }
  1075. }
  1076. if($total==0){
  1077. $this->error = '追加项目必选选择一个';
  1078. return false;
  1079. }
  1080. Db::startTrans();
  1081. try {
  1082. Db::name('order_add')
  1083. ->where('order_id',$orderId)
  1084. ->delete();
  1085. $ret = Db::name('order_add')
  1086. ->insertAll($arr);
  1087. if(!$ret) \exception('追加项目添加失败');
  1088. $ret = $this->where('id',$orderId)
  1089. ->save(['add_amount'=>$total,'update_time'=>getTime()]);
  1090. if(!$ret) \exception('订单更新失败');
  1091. Db::commit();
  1092. return true;
  1093. }catch (Exception $e){
  1094. $this->error = $e->getMessage();
  1095. Db::rollback();
  1096. return false;
  1097. }
  1098. }
  1099. //护工操作完工
  1100. public function completion($orderId){
  1101. $info = $this->where('id',$orderId)
  1102. ->find();
  1103. if($info['completion'] !=0){
  1104. $this->error = '当前订单已完工';
  1105. return false;
  1106. }
  1107. $ret = $this->where('id',$orderId)
  1108. ->save([
  1109. "completion"=>1,
  1110. "completion_time"=>getTime(),
  1111. ]);
  1112. if(!$ret){
  1113. $this->error = '订单更新失败';
  1114. return false;
  1115. }
  1116. return $ret;
  1117. }
  1118. public function makeAccount($ids,$title,$remark){
  1119. $this->startTrans();
  1120. try{
  1121. $amount = $this->where('id','in',$ids)
  1122. ->sum('amount');
  1123. $addAmount = $this->where('id','in',$ids)
  1124. ->sum('add_amount');
  1125. $refund_amount = $this->where('id','in',$ids)
  1126. ->sum('refund_amount');
  1127. $settlement_money = $this->where('id','in',$ids)
  1128. ->sum('settlement_money');
  1129. $data = [
  1130. 'title'=>$title,
  1131. 'remark'=>$remark,
  1132. 'amount'=>$amount+$addAmount-$refund_amount,
  1133. 'settlement_money'=>$settlement_money,
  1134. 'income_money'=>$amount+$addAmount-$refund_amount-$settlement_money,
  1135. 'create_time'=>getTime()
  1136. ];
  1137. $ret = Db::name('make_account')
  1138. ->insertGetId($data);
  1139. if(!$ret) {
  1140. \exception('保存做账记录失败');
  1141. }
  1142. $ret = $this->where('id','in',$ids)
  1143. ->update([
  1144. 'is_make_account'=>1,
  1145. 'make_account_id'=>$ret,
  1146. ]);
  1147. if(!$ret) {
  1148. \exception('更新订单失败');
  1149. }
  1150. $this->commit();
  1151. return true;
  1152. }catch (Exception $e){
  1153. $this->error = $e->getMessage();
  1154. $this->rollback();
  1155. return false;
  1156. }
  1157. }
  1158. //护工工单详情
  1159. public function todoDetail($id){
  1160. $todo = Db::name('ph_todo')
  1161. ->where('id',$id)
  1162. ->find();
  1163. $todo['end'] = $todo['end']?$todo['end']:'';
  1164. $todo['user_name'] = Db::name('user')
  1165. ->where('id',$todo['user_id'])
  1166. ->value('real_name');
  1167. $user_id = Db::name('worker')
  1168. ->where('id',$todo['worker_id'])
  1169. ->value('user_id');
  1170. $todo['worker_name'] = Db::name('user')
  1171. ->where('id',$user_id)
  1172. ->value('real_name');
  1173. $orderInfo = $this->getInfo($todo['order_id']);
  1174. unset($orderInfo['todo']);
  1175. $orderInfo['todo'][] = $todo;
  1176. return $orderInfo;
  1177. }
  1178. function compareDate($arr,$start){
  1179. array_multisort(array_column($arr, 'start'), SORT_ASC, $arr);
  1180. foreach ($arr as $k => $v){
  1181. if($v['end'] && $start > $v['start'] && $start < $v['end']){
  1182. return false;
  1183. }
  1184. }
  1185. return true;
  1186. }
  1187. /**
  1188. * PHP计算两个时间段是否有交集(边界重叠不算)
  1189. *
  1190. * @param string $beginTime1 开始时间1
  1191. * @param string $endTime1 结束时间1
  1192. * @param string $beginTime2 开始时间2
  1193. * @param string $endTime2 结束时间2
  1194. * @return bool
  1195. */
  1196. function is_time_cross($beginTime1 = '', $endTime1 = '', $beginTime2 = '', $endTime2 = '') {
  1197. $status = strtotime($beginTime2) - strtotime($beginTime1);
  1198. if($beginTime1 == $beginTime2 && $endTime1 == $endTime2){
  1199. return false;
  1200. }
  1201. if(!$endTime2){
  1202. return false;
  1203. }
  1204. if ($status > 0) {
  1205. $status2 = strtotime($beginTime2) - strtotime($endTime1);
  1206. if ($status2 >= 0) {
  1207. return false;
  1208. } else {
  1209. return true;
  1210. }
  1211. } else {
  1212. $status2 = strtotime($endTime2) - strtotime($beginTime1);
  1213. if ($status2 > 0) {
  1214. return true;
  1215. } else {
  1216. return false;
  1217. }
  1218. }
  1219. }
  1220. }