PhOrders.php 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337
  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. ->order(['id'=>'desc'])
  726. ->select();
  727. return $todo;
  728. }
  729. //取消订单
  730. public function cancelOrder($id,$note,$userId){
  731. if(!$note){
  732. $this->error = '未填写作废原因';
  733. return false;
  734. }
  735. $info = Db::name('ph_orders')
  736. ->where('id',$id)->find();
  737. if(!$info){
  738. $this->error = '订单不存在';
  739. return false;
  740. }
  741. if($info['status'] == 3||$info['status'] == 4){
  742. $this->error = '订单已作废或已结算';
  743. return false;
  744. }
  745. $off = model('Config')->getConfig('ph_order_cancel_time',cur_org_id());
  746. if($off){
  747. $info = Db::name('ph_orders')->where('id',$id)->find();
  748. $start = strtotime($info['create_time']) + $off*60*60;
  749. $end = strtotime(date('Y-m-d H:i:s'));
  750. if($start < $end){
  751. $this->error = '该订单已超过作废时间';
  752. return false;
  753. }
  754. }
  755. Db::startTrans();
  756. try{
  757. $res =Db::name('ph_orders')
  758. ->where('id',$id)
  759. ->update([
  760. 'status'=>3,
  761. 'cancel_reason'=>$note,
  762. 'cancel_time'=>getTime(),
  763. 'cancel_user_id'=>$userId
  764. ]);
  765. if(!$res){
  766. \exception('操作失败');
  767. }
  768. Db::name('ph_todo')->where('order_id',$id)->update(['status' => 0]);
  769. Db::commit();
  770. }catch (Exception $e){
  771. Db::rollback();
  772. \think\facade\Log::write($e->getMessage(), 'info');
  773. $this->error = '操作失败';
  774. return false;
  775. }
  776. return true;
  777. }
  778. //用户护工删除订单
  779. public function delOrder($id,$userId,$type=0){
  780. $info = $this->getOrderDetail($id,$userId,$type);
  781. if(!in_array($info['status'],[3,4,5])) HelpHander::error('当前订单状态不能删除');
  782. if($type==0){
  783. $params = ['user_del'=>1,'user_del_time'=>getTime()];
  784. }else{
  785. $params = ['worker_del'=>1,'worker_del_time'=>getTime()];
  786. }
  787. $res = $this->where('id',$id)
  788. ->update($params);
  789. return $res;
  790. }
  791. //用户发起退款
  792. public function orderRefund($id,$amount,$reason,$desc,$userId){
  793. $info = $this->getOrderDetail($id,$userId);
  794. if($info['amount'] < $amount) HelpHander::error('退款金额不能大于订单金额');
  795. if($info['refund_status']==1) HelpHander::error('当前订单已申请过退款');
  796. if(!in_array($info['status'],[1,2])) HelpHander::error('当前订单状态不能退款');
  797. $refundModel = new OrderRefund();
  798. Db::startTrans();
  799. try{
  800. $params = [
  801. 'sn'=>get_unique_id(),
  802. 'order_id'=>$id,
  803. 'user_id'=>$userId,
  804. 'amount'=>$amount,
  805. 'reason'=>$reason,
  806. 'desc'=>$desc,
  807. 'is_cx'=>0,
  808. 'create_time'=>getTime(),
  809. ];
  810. if($refundModel->info($id)){
  811. if(!$refundModel->where('order_id',$id)->save($params)) exception('保存退款单失败');
  812. }else{
  813. if(!$refundModel->save($params)) exception('保存退款单失败');
  814. }
  815. if(!$this->where('id',$id)->update(['refund_status'=>1])){
  816. exception('更新订单失败');
  817. }
  818. $om = new \app\model\OrderMessage();
  819. $om->saveMassage($userId,'发起退款申请');
  820. Db::commit();
  821. return true;
  822. }catch (Exception $e){
  823. HelpHander::error($e->getMessage());
  824. Db::rollback();
  825. }
  826. }
  827. public function getOrderDetail($id,$userId,$type=0){
  828. if($type==0){
  829. $map[] = ['user_id','=',$userId];
  830. $map[] = ['user_del','=',0];
  831. }else{
  832. $map[] = ['worker_id','=',$userId];
  833. $map[] = ['worker_del','=',0];
  834. }
  835. $info = $this
  836. ->where('id',$id)
  837. ->where($map)
  838. ->find();
  839. if(empty($info)) HelpHander::error('订单信息不存在');
  840. return $info;
  841. }
  842. //护工领取订单
  843. public function orderReceive($workerId,$id){
  844. $info = $this->getOrderDetail($id,$workerId,1);
  845. if($info['status']!=1) HelpHander::error('当前订单已领取');
  846. $ret = $this->where('id',$id)
  847. ->save(['status'=>2,'receive_time'=>getTime()]);
  848. return $ret;
  849. }
  850. //撤销退款
  851. public function cxOrder($id){
  852. $info = (new OrderRefund())->info($id);
  853. if($info['status']!=0) HelpHander::error('当前订单不能撤销');
  854. Db::startTrans();
  855. try{
  856. $ret = $this->where('id',$id)
  857. ->save(['refund_status'=>0,'refund_amount'=>0]);
  858. if(!$ret) exception('更新订单失败');
  859. $ret = (new OrderRefund())->where('order_id',$id)
  860. ->save(['is_cx'=>1,'cx_time'=>getTime()]);
  861. if(!$ret) exception('退款单更新失败');
  862. Db::commit();
  863. return true;
  864. }catch (Exception $e){
  865. HelpHander::error($e->getMessage());
  866. Db::rollback();
  867. }
  868. return $ret;
  869. }
  870. // 用户正在进行的最新的陪护单
  871. public function latestOrder($userId){
  872. $map[] = ['user_id','=',$userId];
  873. $map[] = ['user_del','=','0'];
  874. $map[] = ['refund_status','=','0'];
  875. $map[] = ['status','=','2'];
  876. $info = Db::name('ph_orders')->where($map)->order('id desc')->find();
  877. if($info){
  878. $worker = Db::name('worker')->where('id',$info['worker_id'])->value('name');
  879. $info['worker_name'] = $worker?$worker:'';
  880. }
  881. return $info?$info:null;
  882. }
  883. //获取护工已预订日期
  884. public function bookDateList($workerId){
  885. $curday = date('Y-m-d');
  886. $lists = Db::name('ph_orders')
  887. ->where('end','>=',$curday)
  888. ->where('worker_id',$workerId)
  889. ->where('status','in',[1,2])
  890. ->where('refund_status',0)
  891. ->order('id asc')
  892. ->field('id,start,end,cate_id')
  893. ->select();
  894. foreach ($lists as $k=>$v){
  895. $lists[$k]['cate_name'] = Db::name('cate')->where('id',$v['cate_id'])->value('title');
  896. }
  897. return $lists?$lists:[];
  898. }
  899. //支付
  900. public function pay($orderId){
  901. $params = $this->where('id',$orderId)
  902. ->find();
  903. $workerModel = new Worker();
  904. $cateInfo = (new Cate())->info($params['cate_id']);
  905. if(!$workerModel->checkServiceNum($params['worker_id'],$cateInfo['nums'],$params['start'],$params['end'],$params['addr_id'],$msg)){
  906. HelpHander::error($msg);
  907. }
  908. $openid = Db::name('user_oauth')->where('user_id',$params['user_id'])->value('openid');
  909. $config = config('app.wx_config');
  910. $app = \EasyWeChat\Factory::payment($config);
  911. $result = $app->order->unify([
  912. 'body' => '订单-'.$params['sn'],
  913. 'out_trade_no' => $params['sn'],
  914. 'total_fee' => $params['amount']*100,
  915. 'spbill_create_ip' => request()->ip(), // 可选,如不传该参数,SDK 将会自动获取相应 IP 地址
  916. 'notify_url' => (string)url('api/Notify/wxorder',[],false,true), // 支付结果通知网址,如果不设置则会使用配置里的默认地址
  917. 'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型
  918. 'openid' => $openid,
  919. ]);
  920. tplog($result);
  921. if($result['return_code'] != 'SUCCESS' || $result['result_code'] != 'SUCCESS'){
  922. HelpHander::error('下单失败1');
  923. }
  924. $jssdk = $app->jssdk;
  925. $json = $jssdk->bridgeConfig($result['prepay_id'],false);
  926. $json['order_id'] = $orderId;
  927. return $json;
  928. }
  929. //结算订单
  930. public function js($orderId=[],$web_bl,$web_deduct,$org){
  931. $succ = [];
  932. $error = [];
  933. foreach ($orderId as $k=>$v){
  934. Db::startTrans();
  935. try{
  936. $info = $this->where('id',$v)->find()->toArray();
  937. $total = $info['amount'];
  938. $money1 = ($total-$web_deduct)*$web_bl;
  939. if($money1 > 0){
  940. $ph_todo = Db::name('ph_todo')
  941. ->where('order_id',$v)
  942. ->where('status','<>',0)
  943. ->select();
  944. $days = Db::name('ph_todo')
  945. ->where('order_id',$v)
  946. ->where('status','<>',0)
  947. ->sum('day');
  948. if($days >0){
  949. $avgPrice = round($money1/$days,2);
  950. if(!empty($ph_todo)){
  951. foreach ($ph_todo as $k1=>$v1){
  952. $workerMoney = Db::name('worker')
  953. ->where('id',$v1['worker_id'])->value('balance');
  954. $money = $avgPrice*$v1['day'];
  955. if($money >0){
  956. $newMoney = $workerMoney+$money;
  957. $res = Db::name('worker')
  958. ->where('id',$v1['worker_id'])
  959. ->update(['balance'=>$newMoney]);
  960. if(!$res) \exception('订单id:'.$v.'余额更新失败');
  961. $res = Db::name('worker')
  962. ->where('id',$v1['worker_id'])
  963. ->inc('cumulative_money',$money);
  964. if(!$res) \exception('订单id:'.$v.'累计收入更新失败');
  965. $res = Db::name('worker_balance')->insert([
  966. 'worker_id'=>$v1['worker_id'],
  967. 'org_id'=>$org,
  968. 'user_id'=>is_login(),
  969. 'money'=>$money,
  970. 'from_id'=>$v,
  971. 'type'=>1,
  972. 'remark'=>'id:'.$v.'订单结算('.$info['sn'].')',
  973. 'create_time'=>date('Y-m-d H:i:s')
  974. ]);
  975. if(!$res) \exception('订单id:'.$v.' 结算记录添加失败');
  976. $cc = [
  977. 'settlement_money'=>$money
  978. ];
  979. $res= Db::name('ph_todo')
  980. ->where('id',$v1['id'])
  981. ->update($cc);
  982. if(!$res) \exception('订单id:'.$v.' 更新ph_todo 失败');
  983. }
  984. }
  985. }
  986. }
  987. }
  988. $res = $this->where('id',$v)
  989. ->update([
  990. 'status'=>4,
  991. 'settlement_money'=>$money1 >0?$money1:0,
  992. 'settlement_use_id'=>is_login(),
  993. 'settlement_time'=>date('Y-m-d H:i:s'),
  994. ]);
  995. if(!$res) \exception('订单id:'.$v.'更新失败');
  996. Db::commit();
  997. $succ[] = $v;
  998. }catch (Exception $e){
  999. $error[] = $e->getMessage();;
  1000. Db::rollback();
  1001. }
  1002. }
  1003. $msg = '';
  1004. if(count($error) > 0){
  1005. $msg = '结算成功:'.count($succ).',失败:'.count($error).',失败订单:'.implode(',',$error);
  1006. $a = ['code'=>0,'msg'=>$msg];
  1007. }else{
  1008. $msg = '结算成功:'.count($succ).',失败:'.count($error);
  1009. $a = ['code'=>1,'msg'=>$msg];
  1010. }
  1011. return $a;
  1012. }
  1013. //用户完成
  1014. public function finish($orderId){
  1015. $params = $this->where('id',$orderId)->find();
  1016. if(!$params){
  1017. HelpHander::error('订单不存在');
  1018. }
  1019. if($params['refund_status'] == 1){
  1020. HelpHander::error('退款中不能完成');
  1021. }
  1022. if($params['status'] != 2){
  1023. HelpHander::error('该状态不能完成');
  1024. }
  1025. if($params['add_amount'] > 0){ // 追加大于0,支付
  1026. $openid = Db::name('user_oauth')->where('user_id',$params['user_id'])->value('openid');
  1027. $config = config('app.wx_config');
  1028. $app = \EasyWeChat\Factory::payment($config);
  1029. $result = $app->order->unify([
  1030. 'body' => '订单-'.$params['sn'],
  1031. 'out_trade_no' => $params['sn'].mt_rand(100,999),
  1032. 'total_fee' => $params['add_amount']*100,
  1033. 'spbill_create_ip' => request()->ip(), // 可选,如不传该参数,SDK 将会自动获取相应 IP 地址
  1034. 'notify_url' => (string)url('api/Notify/wxaddorder',[],false,true), // 支付结果通知网址,如果不设置则会使用配置里的默认地址
  1035. 'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型
  1036. 'openid' => $openid,
  1037. 'attach' => $orderId
  1038. ]);
  1039. tplog($result);
  1040. if($result['return_code'] != 'SUCCESS' || $result['result_code'] != 'SUCCESS'){
  1041. HelpHander::error('操作失败');
  1042. }
  1043. $jssdk = $app->jssdk;
  1044. $json = $jssdk->bridgeConfig($result['prepay_id'],false);
  1045. $json['type'] = 1;
  1046. return $json;
  1047. }else{ //直接完成
  1048. $sdata = [
  1049. 'status' => 3,
  1050. 'finish_time' => date('Y-m-d H:i:s'),
  1051. ];
  1052. if($params['completion'] == 0){
  1053. $sdata['completion'] = 1;
  1054. $sdata['completion_time'] = date('Y-m-d H:i:s');
  1055. }
  1056. $ret = Db::name('ph_orders')->where('id',$orderId)->update($sdata);
  1057. if(!$ret){
  1058. HelpHander::error('操作失败');
  1059. }
  1060. return ['type' => 0];
  1061. }
  1062. }
  1063. //护工追加金额
  1064. public function orderAdd($data,$orderId){
  1065. $total = 0;
  1066. $arr = [];
  1067. foreach ($data as $k=>$v){
  1068. $total+=floatval($v);
  1069. if(!empty($v) && $v > 0){
  1070. $arr[] = [
  1071. 'order_id'=>$orderId,
  1072. 'amount'=>$v,
  1073. 'options_id'=>$k,
  1074. ];
  1075. }
  1076. }
  1077. if($total==0){
  1078. $this->error = '追加项目必选选择一个';
  1079. return false;
  1080. }
  1081. Db::startTrans();
  1082. try {
  1083. Db::name('order_add')
  1084. ->where('order_id',$orderId)
  1085. ->delete();
  1086. $ret = Db::name('order_add')
  1087. ->insertAll($arr);
  1088. if(!$ret) \exception('追加项目添加失败');
  1089. $ret = $this->where('id',$orderId)
  1090. ->save(['add_amount'=>$total,'update_time'=>getTime()]);
  1091. if(!$ret) \exception('订单更新失败');
  1092. Db::commit();
  1093. return true;
  1094. }catch (Exception $e){
  1095. $this->error = $e->getMessage();
  1096. Db::rollback();
  1097. return false;
  1098. }
  1099. }
  1100. //护工操作完工
  1101. public function completion($orderId){
  1102. $info = $this->where('id',$orderId)
  1103. ->find();
  1104. if($info['completion'] !=0){
  1105. $this->error = '当前订单已完工';
  1106. return false;
  1107. }
  1108. $ret = $this->where('id',$orderId)
  1109. ->save([
  1110. "completion"=>1,
  1111. "completion_time"=>getTime(),
  1112. ]);
  1113. if(!$ret){
  1114. $this->error = '订单更新失败';
  1115. return false;
  1116. }
  1117. return $ret;
  1118. }
  1119. public function makeAccount($ids,$title,$remark){
  1120. $this->startTrans();
  1121. try{
  1122. $amount = $this->where('id','in',$ids)
  1123. ->sum('amount');
  1124. $addAmount = $this->where('id','in',$ids)
  1125. ->sum('add_amount');
  1126. $refund_amount = $this->where('id','in',$ids)
  1127. ->sum('refund_amount');
  1128. $settlement_money = $this->where('id','in',$ids)
  1129. ->sum('settlement_money');
  1130. $data = [
  1131. 'title'=>$title,
  1132. 'remark'=>$remark,
  1133. 'amount'=>$amount+$addAmount-$refund_amount,
  1134. 'settlement_money'=>$settlement_money,
  1135. 'income_money'=>$amount+$addAmount-$refund_amount-$settlement_money,
  1136. 'create_time'=>getTime()
  1137. ];
  1138. $ret = Db::name('make_account')
  1139. ->insertGetId($data);
  1140. if(!$ret) {
  1141. \exception('保存做账记录失败');
  1142. }
  1143. $ret = $this->where('id','in',$ids)
  1144. ->update([
  1145. 'is_make_account'=>1,
  1146. 'make_account_id'=>$ret,
  1147. ]);
  1148. if(!$ret) {
  1149. \exception('更新订单失败');
  1150. }
  1151. $this->commit();
  1152. return true;
  1153. }catch (Exception $e){
  1154. $this->error = $e->getMessage();
  1155. $this->rollback();
  1156. return false;
  1157. }
  1158. }
  1159. //护工工单详情
  1160. public function todoDetail($id){
  1161. $todo = Db::name('ph_todo')
  1162. ->where('id',$id)
  1163. ->find();
  1164. $todo['end'] = $todo['end']?$todo['end']:'';
  1165. $todo['user_name'] = Db::name('user')
  1166. ->where('id',$todo['user_id'])
  1167. ->value('real_name');
  1168. $user_id = Db::name('worker')
  1169. ->where('id',$todo['worker_id'])
  1170. ->value('user_id');
  1171. $todo['worker_name'] = Db::name('user')
  1172. ->where('id',$user_id)
  1173. ->value('real_name');
  1174. $orderInfo = $this->getInfo($todo['order_id']);
  1175. unset($orderInfo['todo']);
  1176. $orderInfo['todo'][] = $todo;
  1177. return $orderInfo;
  1178. }
  1179. function compareDate($arr,$start){
  1180. array_multisort(array_column($arr, 'start'), SORT_ASC, $arr);
  1181. foreach ($arr as $k => $v){
  1182. if($v['end'] && $start > $v['start'] && $start < $v['end']){
  1183. return false;
  1184. }
  1185. }
  1186. return true;
  1187. }
  1188. /**
  1189. * PHP计算两个时间段是否有交集(边界重叠不算)
  1190. *
  1191. * @param string $beginTime1 开始时间1
  1192. * @param string $endTime1 结束时间1
  1193. * @param string $beginTime2 开始时间2
  1194. * @param string $endTime2 结束时间2
  1195. * @return bool
  1196. */
  1197. function is_time_cross($beginTime1 = '', $endTime1 = '', $beginTime2 = '', $endTime2 = '') {
  1198. $status = strtotime($beginTime2) - strtotime($beginTime1);
  1199. if($beginTime1 == $beginTime2 && $endTime1 == $endTime2){
  1200. return false;
  1201. }
  1202. if(!$endTime2){
  1203. return false;
  1204. }
  1205. if ($status > 0) {
  1206. $status2 = strtotime($beginTime2) - strtotime($endTime1);
  1207. if ($status2 >= 0) {
  1208. return false;
  1209. } else {
  1210. return true;
  1211. }
  1212. } else {
  1213. $status2 = strtotime($endTime2) - strtotime($beginTime1);
  1214. if ($status2 > 0) {
  1215. return true;
  1216. } else {
  1217. return false;
  1218. }
  1219. }
  1220. }
  1221. }