Convey.php 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047
  1. <?php
  2. namespace app\api\controller\screen;
  3. use app\hander\HelpHander;
  4. use app\api\controller\screen\Index;
  5. use think\Db;
  6. class Convey extends Index
  7. {
  8. public function todoNum(){
  9. $count = Db::name('todo')
  10. ->where('org_id',$this->orgId)
  11. ->where('del',0)
  12. ->where('todo_mode',3)
  13. ->where('work_type_mode',3)
  14. ->where('create_yyyymmdd',date('Ymd'))
  15. ->count();
  16. $count1 = Db::name('todo')
  17. ->where('org_id',$this->orgId)
  18. ->where('del',0)
  19. ->where('todo_mode',3)
  20. ->where('work_type_mode',3)
  21. ->where('create_yyyymm',date('Ym'))
  22. ->count();
  23. $count2 = Db::name('todo')
  24. ->where('org_id',$this->orgId)
  25. ->where('del',0)
  26. ->where('todo_mode',3)
  27. ->where('work_type_mode',3)
  28. ->where('create_yyyy',date('Y'))
  29. ->count();
  30. HelpHander::success(['count'=>$count,'count1'=>$count1,'count2'=>$count2]);
  31. }
  32. public function todoStatusNum(){
  33. $list = [
  34. ['name'=>'待接单','mode'=>1],
  35. ['name'=>'进行中','mode'=>2],
  36. ['name'=>'已完成','mode'=>3],
  37. ['name'=>'已超时','mode'=>5],
  38. ];
  39. foreach ($list as $k=>$v){
  40. $list[$k]['value'] = Db::name('todo')
  41. ->where('org_id',$this->orgId)
  42. ->where('del',0)
  43. ->where('todo_mode',$v['mode'])
  44. ->where('work_type_mode',3)
  45. ->where('create_yyyymmdd',date('Ymd'))
  46. ->count();
  47. }
  48. $todo = Db::name('todo')
  49. ->alias('t')
  50. ->field('t.done_time,oc.ywc_time')
  51. ->join('order_convey oc','oc.order_id=t.order_id')
  52. ->where('t.org_id',$this->orgId)
  53. ->where('t.del',0)
  54. ->where('t.create_yyyymmdd',date('Ymd'))
  55. ->where('t.todo_mode',3)
  56. ->select();
  57. $count = count($todo);
  58. $nums = 0; //标准时间的送达的数量
  59. foreach ($todo as $k=>$v){
  60. if($v['done_time'] < $v['ywc_time']){
  61. $nums +=1;
  62. }
  63. }
  64. $bl = '0%';
  65. if($count >0){
  66. $bl = round($nums/$count*100,1).'%';
  67. }
  68. $count1 = $bl;
  69. //平均响应时间
  70. $count2 = Db::name('todo')
  71. ->where('org_id',$this->orgId)
  72. ->where('del',0)
  73. ->where('todo_mode',3)
  74. ->where('create_yyyymmdd',date('Ymd'))
  75. ->avg('xy_time');
  76. //未派工任务数量
  77. $orders = Db::name('orders')
  78. ->where('org_id',$this->orgId)
  79. ->where('del',0)
  80. ->where('create_yyyymmdd',date('Ymd'))
  81. ->count();
  82. $ordersCount = Db::name('orders')
  83. ->where('org_id',$this->orgId)
  84. ->where('del',0)
  85. ->where('order_mode',1)
  86. ->where('create_yyyymmdd',date('Ymd'))
  87. ->count();
  88. $count3 = '0%';
  89. if($orders > 0){
  90. $count3 = round($ordersCount/$orders*100,1).'%';
  91. }
  92. $data = [
  93. 'list'=>$list,
  94. 'legend'=>['待接单','进行中','已完成','已超时'],
  95. 'count'=>[
  96. 'count1'=>$count1,
  97. 'count2'=>round($count2/360,1),
  98. 'count3'=>$count3,
  99. ],
  100. ];
  101. HelpHander::success($data);
  102. }
  103. //运送热点区域数据
  104. public function addrData(){
  105. $date = date('Ymd');
  106. $edate = date("Ymd",strtotime("-1 months",strtotime($date)));
  107. $addr = Db::name('address')
  108. ->field('id,title')
  109. ->where('del',0)
  110. ->where('enable',1)
  111. ->where('org_id',$this->orgId)
  112. ->where('','exp',Db::raw("FIND_IN_SET(2,types)"))
  113. ->limit(5)
  114. ->select();
  115. foreach ($addr as $k=>$v){
  116. $addr[$k]['nums1'] = Db::name('todo')
  117. ->alias('t')
  118. ->join('todo_convey tc','tc.todo_id=t.id')
  119. ->where('tc.start',$v['id'])
  120. ->where('t.org_id',$this->orgId)
  121. ->where('t.del',0)
  122. ->where('t.create_yyyymmdd','=',$date)
  123. ->count();
  124. $nums2 = Db::name('todo')
  125. ->alias('t')
  126. ->join('todo_convey tc','tc.todo_id=t.id')
  127. ->where('tc.start',$v['id'])
  128. ->where('t.org_id',$this->orgId)
  129. ->where('t.del',0)
  130. ->where('t.create_yyyymmdd','<=',$date)
  131. ->where('t.create_yyyymmdd','>',$edate)
  132. ->count();
  133. $addr[$k]['nums2'] = round($nums2/30,1);
  134. // $addr[$k]['nums2'] = $nums2;
  135. }
  136. $lists =array_slice(list_sort_by($addr,'nums1','desc'),0,5) ;
  137. $data1 = array_column($lists,'nums1');
  138. $data2 = array_column($lists,'nums2');
  139. $title = array_column($lists,'title');
  140. $data = [
  141. 'data1'=>$data1,
  142. 'data2'=>$data2,
  143. 'title'=>$title,
  144. ];
  145. HelpHander::success($data);
  146. }
  147. public function ysTypeUser(){
  148. $lists = model('WorkTypeMode')->getRolesUserApp(3,$this->orgId,1);
  149. $curday = date('Ymd');
  150. $users = Db::name('todo')
  151. ->alias('t')
  152. ->field('t.to_user_id')
  153. ->join('user u','u.id=t.to_user_id')
  154. ->where('t.org_id',$this->orgId)
  155. ->whereIn('t.todo_mode',[1,2])
  156. ->where('t.del',0)
  157. ->where('t.work_type_mode',3)
  158. ->where('t.create_yyyymmdd',$curday)
  159. ->where('u.work',1)
  160. ->where('u.enable',1)
  161. ->where('u.del',0)
  162. ->group('t.to_user_id')
  163. ->select();
  164. $users = $users?$users:[];
  165. $userIds = [];
  166. foreach ($users as $k=>$v){
  167. $userIds[] = $v['to_user_id'];
  168. }
  169. $nlists = $nlists2 = [];
  170. foreach ($lists as $k=>$v){
  171. if(!in_array($v['id'],$userIds)){
  172. $nlists[] = $v;
  173. }
  174. }
  175. $slist = $slist2 = [];
  176. foreach ($nlists as $k=>$v){
  177. $count = Db::name('todo')
  178. ->where('org_id',$this->orgId)
  179. ->where('to_user_id',$v['id'])
  180. ->whereIn('todo_mode',[1,2,3])
  181. ->where('del',0)
  182. ->where('create_yyyymmdd',$curday)
  183. ->count();
  184. $addr = Db::name('convey_plan_record')
  185. ->alias('cpr')
  186. ->join('address a','a.id = cpr.addr_id')
  187. ->where('cpr.user_id',$v['id'])
  188. ->where('cpr.create_yyyymmdd',$curday)
  189. ->order('cpr.id desc')
  190. ->value('a.title');
  191. if(!$addr){
  192. $addr = Db::name('todo')
  193. ->alias('t')
  194. ->join('orders o','o.id=t.order_id')
  195. ->join('order_convey oc','oc.order_id=o.id')
  196. ->join('address a','a.id=oc.start')
  197. ->where('t.to_user_id',$v['id'])
  198. ->where('t.org_id',$this->orgId)
  199. ->where('t.to_user_id',$v['id'])
  200. ->whereIn('t.todo_mode',[1,2,3])
  201. ->where('t.del',0)
  202. ->where('t.create_yyyymmdd',$curday)
  203. ->order('t.id desc')
  204. ->value('a.title');
  205. }
  206. $slist[$k][] = '<span style="color: #FFE400">'.$v['real_name'].'</span>';
  207. $slist[$k][] = '<span style="color: #FFE400">'.$count.'</span>';
  208. $slist[$k][] = '<span style="color: #FFE400">'.$addr.'</span>';
  209. }
  210. foreach ($lists as $k=>$v){
  211. if(in_array($v['id'],$userIds)){
  212. $nlists2[] = $v;
  213. }
  214. }
  215. foreach ($nlists2 as $k=>$v){
  216. $count = Db::name('todo')
  217. ->where('org_id',$this->orgId)
  218. ->where('to_user_id',$v['id'])
  219. ->whereIn('todo_mode',[1,2,3])
  220. ->where('del',0)
  221. ->where('create_yyyymmdd',$curday)
  222. ->count();
  223. $addr = Db::name('convey_plan_record')
  224. ->alias('cpr')
  225. ->join('address a','a.id = cpr.addr_id')
  226. ->where('cpr.create_yyyymmdd',$curday)
  227. ->where('cpr.user_id',$v['id'])
  228. ->order('cpr.id desc')
  229. ->value('a.title');
  230. if(!$addr){
  231. $addr = Db::name('todo')
  232. ->alias('t')
  233. ->join('orders o','o.id=t.order_id')
  234. ->join('order_convey oc','oc.order_id=o.id')
  235. ->join('address a','a.id=oc.start')
  236. ->where('t.to_user_id',$v['id'])
  237. ->where('t.org_id',$this->orgId)
  238. ->where('t.to_user_id',$v['id'])
  239. ->whereIn('t.todo_mode',[1,2,3])
  240. ->where('t.del',0)
  241. ->where('t.create_yyyymmdd',$curday)
  242. ->order('t.id desc')
  243. ->value('a.title');
  244. }
  245. $slist2[$k][] = '<span style="color: #11E799">'.$v['real_name'].'</span>';
  246. $slist2[$k][] = '<span style="color: #11E799">'.$count.'</span>';
  247. $slist2[$k][] = '<span style="color: #11E799">'.$addr?$addr:''.'</span>';
  248. }
  249. $data = [
  250. 'list1'=>[
  251. 'list'=>$slist2,
  252. 'count'=>count($slist2),
  253. ],
  254. 'list2'=>[
  255. 'list'=>$slist,
  256. 'count'=>count($slist),
  257. ],
  258. ];
  259. HelpHander::success($data);
  260. }
  261. public function ysTask(){
  262. $order = Db::name('orders')
  263. ->alias('o')
  264. ->field('o.*,oc.type,oc.start,oc.end,oc.xq_time,oc.ywc_time,oc.device_id,oc.name,oc.phone,oc.priority')
  265. ->join('order_convey oc','oc.order_id=o.id')
  266. ->where('o.create_yyyymmdd',date('Ymd'))
  267. ->where('o.work_type_mode',3)
  268. ->where('o.org_id',$this->orgId)
  269. ->where('o.del',0)
  270. ->whereIn('o.order_mode',[1,4])
  271. ->order('oc.xq_time desc')
  272. ->select();
  273. $num = $num1 =0;
  274. foreach ($order as $k=>$v){
  275. if($v['order_mode'] == 1){
  276. $num +=1;
  277. }
  278. if($v['order_mode'] == 4){
  279. $num1 +=1;
  280. }
  281. $order[$k]['xq_time'] = date('H:i',strtotime($v['xq_time']));
  282. $order[$k]['start_name'] = Db::name('address')->where('id',$v['start'])->value('title');
  283. $order[$k]['end_name'] = Db::name('address')->where('id',$v['end'])->value('title');
  284. $order[$k]['type_name'] = Db::name('convey_cate')->where('id',$v['type'])->value('title');
  285. $todo = Db::name('todo')
  286. ->alias('t')
  287. ->field('u.real_name,t.create_time,t.confirm_time')
  288. ->join('user u','u.id = t.to_user_id')
  289. ->whereIn('t.todo_mode',[1,2,3])
  290. ->where('t.del',0)
  291. ->where('t.order_id',$v['id'])
  292. ->order('t.id asc')
  293. ->select();
  294. $users = [];
  295. $confirmTime = '';
  296. foreach ($todo as $kk=>$vv){
  297. $users[] = $vv['real_name'];
  298. if(!$confirmTime && $vv['confirm_time']){
  299. $confirmTime = $vv['confirm_time'];
  300. }else if($confirmTime && $vv['confirm_time'] && $vv['confirm_time'] < $confirmTime){
  301. $confirmTime = $vv['confirm_time'];
  302. }
  303. }
  304. $send_time = $todo?$todo[0]['create_time']:'';
  305. $order[$k]['real_names'] = implode(',',$users);
  306. $order[$k]['send_time'] = !empty($send_time)?date('H:i',strtotime($send_time)):'';
  307. $order[$k]['confirm_time'] = !empty($confirmTime)?date('H:i',strtotime($confirmTime)):'';
  308. }
  309. $list = [];
  310. foreach ($order as $k=>$v) {
  311. if($v['order_mode'] == 1){
  312. $list[$k][] = '新任务';
  313. $list[$k][] = $v['type_name'];
  314. $list[$k][] = $v['start_name'];
  315. $list[$k][] = $v['end_name'];
  316. $list[$k][] = $v['xq_time'];
  317. $list[$k][] = $v['real_names'];
  318. $list[$k][] = $v['send_time'];
  319. $list[$k][] = $v['confirm_time'];
  320. } elseif($v['order_mode'] == 5 && $v['confirm_time']){
  321. $list[$k][] = '<span style="color:#0FC2DD;">已派工</span>';
  322. $list[$k][] = '<span style="color:#0FC2DD;">'.$v['type_name'].'</span>';
  323. $list[$k][] = '<span style="color:#0FC2DD;">'.$v['start_name'].'</span>';
  324. $list[$k][] = '<span style="color:#0FC2DD;">'.$v['end_name'].'</span>';
  325. $list[$k][] = '<span style="color:#0FC2DD;">'.$v['xq_time'].'</span>';
  326. $list[$k][] = '<span style="color:#0FC2DD;">'.$v['real_names'].'</span>';
  327. $list[$k][] = '<span style="color:#0FC2DD;">'.$v['send_time'].'</span>';
  328. $list[$k][] = '<span style="color:#0FC2DD;">'.$v['confirm_time'].'</span>';
  329. }else{
  330. $list[$k][] = '<span style="color:#49E9A0;">进行中</span>';
  331. $list[$k][] = '<span style="color:#49E9A0;">'.$v['type_name'].'</span>';
  332. $list[$k][] = '<span style="color:#49E9A0;">'.$v['start_name'].'</span>';
  333. $list[$k][] = '<span style="color:#49E9A0;">'.$v['end_name'].'</span>';
  334. $list[$k][] = '<span style="color:#49E9A0;">'.$v['xq_time'].'</span>';
  335. $list[$k][] = '<span style="color:#49E9A0;">'.$v['real_names'].'</span>';
  336. $list[$k][] = '<span style="color:#49E9A0;">'.$v['send_time'].'</span>';
  337. $list[$k][] = '<span style="color:#49E9A0;">'.$v['confirm_time'].'</span>';
  338. }
  339. }
  340. HelpHander::success(['list'=>$list,'num'=>$num,'num1'=>$num1]);
  341. }
  342. //标本限时服务
  343. public function conveyOrder(){
  344. // $order = Db::name('orders')
  345. // ->alias('o')
  346. // ->field('o.order_mode,oc.*')
  347. // ->join('order_convey oc','oc.order_id=o.id')
  348. // ->where('o.org_id',$this->orgId)
  349. // ->where('o.del',0)
  350. // ->where('o.create_yyyymmdd',date('Ymd'))
  351. // ->where('o.work_type_mode',3)
  352. // ->whereIn('o.order_mode',[1,4,5])
  353. // ->order('o.id desc')
  354. // ->select();
  355. //
  356. // foreach ($order as $k=>$v){
  357. // $order[$k]['status'] = '';
  358. // if($v['order_mode'] == 1){
  359. // $order[$k]['status'] = '待派发';
  360. // }elseif ($v['order_mode'] == 4){
  361. // $order[$k]['status'] = '已派发';
  362. // }elseif ($v['order_mode'] == 5){
  363. // $order[$k]['status'] = '已完成';
  364. // }
  365. // $order[$k]['cate_name'] = Db::name('convey_cate')->where('id',$v['type'])->value('title');
  366. // $order[$k]['start_name'] = Db::name('address')->where('id',$v['start'])->value('title');
  367. // }
  368. //
  369. // $list = [];
  370. // foreach ($order as $k=>$v){
  371. // $list[$k][] = $v['cate_name'];
  372. // $list[$k][] = $v['start_name'];
  373. // $list[$k][] = $v['xq_time'];
  374. // $list[$k][] = $v['status'];
  375. // }
  376. // $todo = Db::name('todo')
  377. // ->alias('t')
  378. // ->field('t.todo_mode,t.to_user_id,oc.*')
  379. // ->join('order_convey oc','t.order_id=oc.order_id')
  380. // ->where('t.org_id',$this->orgId)
  381. // ->where('t.del',0)
  382. // ->where('t.create_yyyymmdd',date('Ymd'))
  383. // ->where('t.work_type_mode',3)
  384. // ->whereIn('t.todo_mode',[1,2])
  385. // ->order('t.id desc')
  386. // ->select();
  387. // foreach ($todo as $k=>$v){
  388. // $todo[$k]['status'] = '';
  389. // if($v['todo_mode'] == 1){
  390. // $todo[$k]['status'] = '待派发';
  391. // }elseif ($v['todo_mode'] == 2){
  392. // $todo[$k]['status'] = '已派发';
  393. // }
  394. // $todo[$k]['cate_name'] = Db::name('convey_cate')->where('id',$v['type'])->value('title');
  395. // $todo[$k]['start_name'] = Db::name('address')->where('id',$v['start'])->value('title');
  396. // $todo[$k]['user_name'] = Db::name('user')->where('id',$v['to_user_id'])->value('real_name');
  397. // }
  398. //
  399. // $list = [];
  400. // foreach ($todo as $k=>$v){
  401. // $list[$k][] = $v['cate_name'];
  402. // $list[$k][] = $v['start_name'];
  403. // $list[$k][] = date('H:i:s',strtotime($v['xq_time']));
  404. // $list[$k][] = $v['status'];
  405. // $list[$k][] = $v['user_name'];
  406. // }
  407. $map[] = ['o.del', '=', 0];
  408. $map[] = ['o.org_id', '=', $this->orgId];
  409. $map[] = ['o.work_type_mode', '=', 3];
  410. $map[] = ['o.order_mode', 'in', [1, 4]];
  411. $lists = db('orders')
  412. ->alias('o')
  413. ->join('order_convey oc', 'oc.order_id=o.id')
  414. ->field('o.*,oc.type,oc.start,oc.end,oc.xq_time,oc.ywc_time,oc.device_id,oc.name,oc.phone,oc.priority')
  415. ->where($map)
  416. ->order(['o.order_mode' => 'asc', 'oc.xq_time' => 'desc'])
  417. ->select();
  418. $data = [];
  419. foreach ($lists as $k => $v) {
  420. $v = model('Orders')->formatOrder($v);
  421. $v['bed_number'] = '';
  422. $ocp = Db::name('order_convey_patient')
  423. ->where('order_id', $v['id'])
  424. ->find();
  425. $v['bed_number'] = !empty($ocp)?$ocp['bed_number']:'';
  426. $todo = Db::name('todo')
  427. ->alias('t')
  428. ->where('t.order_id', $v['id'])
  429. ->join('user u', 'u.id = t.to_user_id')
  430. ->where('t.todo_mode', 'in', [1, 2, 3, 4])
  431. ->where('t.del', 0)
  432. ->field('u.real_name,t.create_time,t.confirm_time')
  433. ->order('t.id asc')
  434. ->select();
  435. $users = [];
  436. $confirmtime = '';
  437. foreach ($todo as $kk => $vv) {
  438. $users[] = $vv['real_name'];
  439. if (!$confirmtime && $vv['confirm_time']) {
  440. $confirmtime = $vv['confirm_time'];
  441. }
  442. else {
  443. if ($confirmtime && $vv['confirm_time'] && $vv['confirm_time'] < $confirmtime) {
  444. $confirmtime = $vv['confirm_time'];
  445. }
  446. }
  447. }
  448. $v['real_names'] = $users? implode(',', $users):'';
  449. $v['confirm_time'] = $confirmtime;
  450. $last = strtotime($v['ywc_time']) - time();
  451. $v['last_time'] = $last > 0 ? round($last / 60) : 0;
  452. //是否有延时
  453. $v['delay'] = 0; // 0=未延迟 1=延迟
  454. $v['delay_diff'] = 0;
  455. $v['delay_reason'] = '';
  456. $delays = Db::name('order_delay')
  457. ->where('order_id', $v['id'])
  458. ->select();
  459. $delays = $delays ? $delays : [];
  460. foreach ($delays as $vv) {
  461. if ($vv['status'] == 0) {
  462. $v['delay'] = 1;
  463. $v['delay_reason'] = Db::name('delay_reason')->where('id',$vv['delay_reason_id'])->value('title');
  464. $vv['diff'] = time() - strtotime($vv['start_time']);
  465. }
  466. $v['delay_diff'] += $vv['diff'];
  467. }
  468. $v['delay_diff'] = round($v['delay_diff'] / 60);
  469. if ($v['delay'] == 1) {
  470. $v['status'] = 3;
  471. } else {
  472. if ($v['order_mode'] == 1) {
  473. $v['status'] = 1;
  474. } else {
  475. $v['status'] = 2;
  476. }
  477. }
  478. $convey = Db::name('convey_cate')
  479. ->alias('oc')
  480. ->join('time ot', 'ot.id = oc.time_id')
  481. ->where('oc.id', $v['type'])
  482. ->field('ot.*')
  483. ->find();
  484. $createtime = strtotime($v['create_time']);
  485. $curtime = time();
  486. $ct = round(($curtime - $createtime) / 60);
  487. if ($ct < $convey['yy_time']) {
  488. $ss = 0;
  489. }
  490. else {
  491. if ($ct >= $convey['yy_time'] && $ct < $convey['bz_time']) {
  492. $ss = 1;
  493. }
  494. else {
  495. if ($ct >= $convey['bz_time'] && $ct < $convey['jg_time']) {
  496. $ss = 2;
  497. }
  498. else {
  499. if ($ct >= $convey['jg_time'] && $ct < $convey['wjjg_time']) {
  500. $ss = 3;
  501. }
  502. else {
  503. $ss = 4;
  504. }
  505. }
  506. }
  507. }
  508. $v['ss'] = $ss;
  509. $v['xtime'] = date('H:i', strtotime($v['xq_time']));
  510. $v['stime'] = $v['send_time'] ? date('H:i', strtotime($v['send_time'])) : "";
  511. $v['ctime'] = $v['confirm_time'] ? date('H:i', strtotime($v['confirm_time'])) : "";
  512. $v['priorityName'] = isset(model('Orders')->priority[$v['priority']])?model('Orders')->priority[$v['priority']]:'';
  513. // //只取进行中的
  514. if(isset($v['status']) && $v['status'] == 2 && $v['ss'] >0){
  515. $data[] = [
  516. '<span style="color: yellow">'.$v['type_name'].'</span>',
  517. '<span style="color: yellow">'.$v['start_name'].'</span>',
  518. '<span style="color: yellow">'.$v['end_name'].'</span>',
  519. '<span style="color: yellow">进行中</span>',
  520. '<span style="color: yellow">'.$v['real_names'].'</span>',
  521. ];
  522. }
  523. }
  524. HelpHander::success($data);
  525. }
  526. public function ysOrderWeek(){
  527. // $dlist = [
  528. // date('Y-m-d',strtotime('-6 days')),
  529. // date('Y-m-d',strtotime('-5 days')),
  530. // date('Y-m-d',strtotime('-4 days')),
  531. // date('Y-m-d',strtotime('-3 days')),
  532. // date('Y-m-d',strtotime('-2 days')),
  533. // date('Y-m-d',strtotime('-1 days')),
  534. // date('Y-m-d'),
  535. // ];
  536. $dlist = [
  537. '02','04','06','08','10','12','14','16','18','20','22','24'
  538. ];
  539. $curDay = date('Y-m-d');
  540. $list = $list1 = $date = [];
  541. foreach ($dlist as $k=>$v){
  542. if($k == 0){
  543. $s = $curDay.' 00:00:00';
  544. }else{
  545. $s = $curDay.' '.$dlist[$k-1].':00:00';
  546. }
  547. $e = $curDay.' '.$v.':00:00';
  548. $count = Db::name('todo')
  549. ->where('org_id',$this->orgId)
  550. ->where('del',0)
  551. ->where('work_type_mode',3)
  552. ->where('create_time','>=',$s)
  553. ->where('create_time','<',$e)
  554. ->count();
  555. $count1 = Db::name('todo')
  556. ->where('org_id',$this->orgId)
  557. ->where('del',0)
  558. ->where('work_type_mode',3)
  559. ->where('todo_mode',3)
  560. ->where('create_time','>=',$s)
  561. ->where('create_time','<',$e)
  562. ->count();
  563. $list[$k]= $count;
  564. $list1[$k] = $count1;
  565. }
  566. $data = [
  567. 'title'=>$dlist,
  568. 'list'=>[
  569. 'list1'=>$list1,
  570. 'list2'=>$list,
  571. ]
  572. ];
  573. HelpHander::success($data);
  574. }
  575. public function conveyCateData(){
  576. $date = date('Ymd');
  577. $edate = date("Ymd",strtotime("-1 months",strtotime($date)));
  578. $cate = Db::name('convey_cate')
  579. ->field('id,title')
  580. ->where('del',0)
  581. ->where('enable',1)
  582. ->where('org_id',$this->orgId)
  583. ->select();
  584. foreach ($cate as $k=>$v){
  585. $cate[$k]['count'] = Db::name('orders')
  586. ->alias('o')
  587. ->join('order_convey oc','oc.order_id=o.id')
  588. ->whereIn('o.order_mode',[1,4,5,6])
  589. ->where('o.del',0)
  590. ->where('o.work_type_mode',3)
  591. ->where('o.create_yyyymmdd',date('Ymd'))
  592. ->where('oc.type',$v['id'])
  593. ->count();
  594. $nums2 = Db::name('orders')
  595. ->alias('o')
  596. ->join('order_convey oc','oc.order_id=o.id')
  597. ->whereIn('o.order_mode',[1,4,5,6])
  598. ->where('o.del',0)
  599. ->where('o.work_type_mode',3)
  600. ->where('o.create_yyyymmdd','<=',$date)
  601. ->where('o.create_yyyymmdd','>',$edate)
  602. ->where('oc.type',$v['id'])
  603. ->count();
  604. $cate[$k]['count1'] = round($nums2/30,1);;
  605. }
  606. $lists =array_slice(list_sort_by($cate,'count','desc'),0,6) ;
  607. $data1 = array_column($lists,'title');
  608. $data2 = array_column($lists,'count');
  609. $data3 = array_column($lists,'count1');
  610. $data = [
  611. 'title'=>$data1,
  612. 'list'=>$data2,
  613. 'list1'=>$data3,
  614. ];
  615. HelpHander::success($data);
  616. }
  617. public function ysTypeTask(){
  618. $type = input('type',0); //3=紧急 1=超时 2=常规
  619. $fontColor = input('fontColor','#fff'); //字体颜色 //默认白色
  620. $jxzColor = input('jxzColor','#49E9A0'); //进行中颜色
  621. if(!in_array($type,[1,2,3])){
  622. HelpHander::error('参数错误');
  623. }
  624. $ctlist = [];
  625. if(in_array($type,[2,3])){
  626. $order = Db::name('orders')
  627. ->alias('o')
  628. ->field('o.*,oc.type,oc.start,oc.end,oc.xq_time,oc.ywc_time,oc.device_id,oc.name,oc.phone,oc.priority')
  629. ->join('order_convey oc','oc.order_id=o.id')
  630. ->where('o.create_yyyymmdd',date('Ymd'))
  631. ->where('o.work_type_mode',3)
  632. ->where('o.org_id',$this->orgId)
  633. ->where('o.del',0)
  634. ->where('oc.priority',$type)
  635. ->whereIn('o.order_mode',[1,4])
  636. ->order('oc.xq_time desc')
  637. ->select();
  638. $num = $num1 =0;
  639. foreach ($order as $k=>$v){
  640. $order[$k]['xq_time'] = date('H:i',strtotime($v['xq_time']));
  641. $order[$k]['start_name'] = Db::name('address')->where('id',$v['start'])->value('title');
  642. $order[$k]['end_name'] = Db::name('address')->where('id',$v['end'])->value('title');
  643. $order[$k]['type_name'] = Db::name('convey_cate')->where('id',$v['type'])->value('title');
  644. $todo = Db::name('todo')
  645. ->alias('t')
  646. ->field('u.real_name,t.create_time,t.confirm_time')
  647. ->join('user u','u.id = t.to_user_id')
  648. ->whereIn('t.todo_mode',[1,2,3])
  649. ->where('t.del',0)
  650. ->where('t.order_id',$v['id'])
  651. ->order('t.id asc')
  652. ->select();
  653. $users = [];
  654. $confirmTime = '';
  655. foreach ($todo as $kk=>$vv){
  656. $users[] = $vv['real_name'];
  657. if(!$confirmTime && $vv['confirm_time']){
  658. $confirmTime = $vv['confirm_time'];
  659. }else if($confirmTime && $vv['confirm_time'] && $vv['confirm_time'] < $confirmTime){
  660. $confirmTime = $vv['confirm_time'];
  661. }
  662. }
  663. $send_time = $todo?$todo[0]['create_time']:'';
  664. $order[$k]['real_names'] = implode(',',$users);
  665. $order[$k]['send_time'] = !empty($send_time)?date('H:i',strtotime($send_time)):'';
  666. $order[$k]['confirm_time'] = !empty($confirmTime)?date('H:i',strtotime($confirmTime)):'';
  667. $convey = Db::name('convey_cate')
  668. ->alias('oc')
  669. ->join('time ot', 'ot.id = oc.time_id')
  670. ->where('oc.id', $v['type'])
  671. ->field('ot.*')
  672. ->find();
  673. $createtime = strtotime($v['create_time']);
  674. $curtime = time();
  675. $ct = round(($curtime - $createtime) / 60);
  676. if ($ct < $convey['yy_time']) {
  677. $ss = 0;
  678. }
  679. else {
  680. if ($ct >= $convey['yy_time'] && $ct < $convey['bz_time']) {
  681. $ss = 1;
  682. }
  683. else {
  684. if ($ct >= $convey['bz_time'] && $ct < $convey['jg_time']) {
  685. $ss = 2;
  686. }
  687. else {
  688. if ($ct >= $convey['jg_time'] && $ct < $convey['wjjg_time']) {
  689. $ss = 3;
  690. }
  691. else {
  692. $ss = 4;
  693. }
  694. }
  695. }
  696. }
  697. if($ss != 4){
  698. if($v['order_mode'] == 1){
  699. $num +=1;
  700. }
  701. if($v['order_mode'] == 4){
  702. $num1 +=1;
  703. }
  704. $ctlist[] = $order[$k];
  705. }
  706. }
  707. }else{
  708. $order = Db::name('orders')
  709. ->alias('o')
  710. ->field('o.*,oc.type,oc.start,oc.end,oc.xq_time,oc.ywc_time,oc.device_id,oc.name,oc.phone,oc.priority')
  711. ->join('order_convey oc','oc.order_id=o.id')
  712. ->where('o.create_yyyymmdd',date('Ymd'))
  713. ->where('o.work_type_mode',3)
  714. ->where('o.org_id',$this->orgId)
  715. ->where('o.del',0)
  716. ->whereIn('o.order_mode',[1,4])
  717. ->order('oc.xq_time desc')
  718. ->select();
  719. $num = $num1 =0;
  720. foreach ($order as $k=>$v){
  721. $order[$k]['xq_time'] = date('H:i',strtotime($v['xq_time']));
  722. $order[$k]['start_name'] = Db::name('address')->where('id',$v['start'])->value('title');
  723. $order[$k]['end_name'] = Db::name('address')->where('id',$v['end'])->value('title');
  724. $order[$k]['type_name'] = Db::name('convey_cate')->where('id',$v['type'])->value('title');
  725. $todo = Db::name('todo')
  726. ->alias('t')
  727. ->field('u.real_name,t.create_time,t.confirm_time')
  728. ->join('user u','u.id = t.to_user_id')
  729. ->whereIn('t.todo_mode',[1,2,3])
  730. ->where('t.del',0)
  731. ->where('t.order_id',$v['id'])
  732. ->order('t.id asc')
  733. ->select();
  734. $users = [];
  735. $confirmTime = '';
  736. foreach ($todo as $kk=>$vv){
  737. $users[] = $vv['real_name'];
  738. if(!$confirmTime && $vv['confirm_time']){
  739. $confirmTime = $vv['confirm_time'];
  740. }else if($confirmTime && $vv['confirm_time'] && $vv['confirm_time'] < $confirmTime){
  741. $confirmTime = $vv['confirm_time'];
  742. }
  743. }
  744. $send_time = $todo?$todo[0]['create_time']:'';
  745. $order[$k]['real_names'] = implode(',',$users);
  746. $order[$k]['send_time'] = !empty($send_time)?date('H:i',strtotime($send_time)):'';
  747. $order[$k]['confirm_time'] = !empty($confirmTime)?date('H:i',strtotime($confirmTime)):'';
  748. $convey = Db::name('convey_cate')
  749. ->alias('oc')
  750. ->join('time ot', 'ot.id = oc.time_id')
  751. ->where('oc.id', $v['type'])
  752. ->field('ot.*')
  753. ->find();
  754. $createtime = strtotime($v['create_time']);
  755. $curtime = time();
  756. $ct = round(($curtime - $createtime) / 60);
  757. if ($ct < $convey['yy_time']) {
  758. $ss = 0;
  759. }
  760. else {
  761. if ($ct >= $convey['yy_time'] && $ct < $convey['bz_time']) {
  762. $ss = 1;
  763. }
  764. else {
  765. if ($ct >= $convey['bz_time'] && $ct < $convey['jg_time']) {
  766. $ss = 2;
  767. }
  768. else {
  769. if ($ct >= $convey['jg_time'] && $ct < $convey['wjjg_time']) {
  770. $ss = 3;
  771. }
  772. else {
  773. $ss = 4;
  774. }
  775. }
  776. }
  777. }
  778. if($ss == 4){
  779. if($v['order_mode'] == 1){
  780. $num +=1;
  781. }
  782. if($v['order_mode'] == 4){
  783. $num1 +=1;
  784. }
  785. $ctlist[] = $order[$k];
  786. }
  787. }
  788. }
  789. $list = [];
  790. foreach ($ctlist as $k=>$v) {
  791. if($v['order_mode'] == 1){
  792. $list[$k][] = '新任务';
  793. $list[$k][] = '<span style="color:'.$fontColor.'">'.$v['type_name'].'</span>';
  794. $list[$k][] = '<span style="color:'.$fontColor.'">'.$v['start_name'].'</span>';
  795. $list[$k][] = '<span style="color:'.$fontColor.'">'.$v['end_name'].'</span>';
  796. $list[$k][] = '<span style="color:'.$fontColor.'">'.$v['xq_time'].'</span>';
  797. $list[$k][] = '<span style="color:'.$fontColor.'">'.$v['real_names'].'</span>';
  798. $list[$k][] = '<span style="color:'.$fontColor.'">'.$v['send_time'].'</span>';
  799. $list[$k][] = '<span style="color:'.$fontColor.'">'.$v['confirm_time'].'</span>';
  800. } elseif($v['order_mode'] == 5 && $v['confirm_time']){
  801. $list[$k][] = '<span style="color:#0FC2DD;">已派工</span>';
  802. $list[$k][] = '<span style="color:#0FC2DD;">'.$v['type_name'].'</span>';
  803. $list[$k][] = '<span style="color:#0FC2DD;">'.$v['start_name'].'</span>';
  804. $list[$k][] = '<span style="color:#0FC2DD;">'.$v['end_name'].'</span>';
  805. $list[$k][] = '<span style="color:#0FC2DD;">'.$v['xq_time'].'</span>';
  806. $list[$k][] = '<span style="color:#0FC2DD;">'.$v['real_names'].'</span>';
  807. $list[$k][] = '<span style="color:#0FC2DD;">'.$v['send_time'].'</span>';
  808. $list[$k][] = '<span style="color:#0FC2DD;">'.$v['confirm_time'].'</span>';
  809. }else{
  810. $list[$k][] = '<span style="color:'.$jxzColor.'">进行中</span>';
  811. $list[$k][] = '<span style="color:'.$jxzColor.'">'.$v['type_name'].'</span>';
  812. $list[$k][] = '<span style="color:'.$jxzColor.'">'.$v['start_name'].'</span>';
  813. $list[$k][] = '<span style="color:'.$jxzColor.'">'.$v['end_name'].'</span>';
  814. $list[$k][] = '<span style="color:'.$jxzColor.'">'.$v['xq_time'].'</span>';
  815. $list[$k][] = '<span style="color:'.$jxzColor.'">'.$v['real_names'].'</span>';
  816. $list[$k][] = '<span style="color:'.$jxzColor.'">'.$v['send_time'].'</span>';
  817. $list[$k][] = '<span style="color:'.$jxzColor.'">'.$v['confirm_time'].'</span>';
  818. }
  819. }
  820. HelpHander::success(['list'=>$list,'num'=>$num,'num1'=>$num1]);
  821. }
  822. public function ysTypeUserAll(){
  823. $dmColor = input('dmColor','#FFE400'); //待命运送员颜色 默认黄色
  824. $lists = model('WorkTypeMode')->getRolesUserApp(3,$this->orgId,1);
  825. $curday = date('Ymd');
  826. $userIds = Db::name('todo')
  827. ->alias('t')
  828. ->field('t.to_user_id')
  829. ->join('user u','u.id=t.to_user_id')
  830. ->where('t.org_id',$this->orgId)
  831. ->whereIn('t.todo_mode',[1,2])
  832. ->where('t.del',0)
  833. ->where('t.work_type_mode',3)
  834. // ->where('t.create_yyyymmdd',$curday) //去掉时间限制
  835. ->where('u.work',1)
  836. ->where('u.enable',1)
  837. ->where('u.del',0)
  838. ->group('t.to_user_id')
  839. ->column('t.to_user_id');
  840. // $users = $users?$users:[];
  841. // $userIds = [];
  842. // foreach ($users as $k=>$v){
  843. // $userIds[] = $v['to_user_id'];
  844. // }
  845. $nlists = $nlists2 = [];
  846. foreach ($lists as $k=>$v){
  847. if(!in_array($v['id'],$userIds)){
  848. $nlists[] = $v;
  849. }
  850. }
  851. $slist = $slist2 = [];
  852. foreach ($nlists as $k=>$v){
  853. $count = Db::name('todo')
  854. ->where('org_id',$this->orgId)
  855. ->where('to_user_id',$v['id'])
  856. ->whereIn('todo_mode',[1,2,3])
  857. ->where('del',0)
  858. ->where('create_yyyymmdd',$curday)
  859. ->count();
  860. $addr = Db::name('convey_plan_record')
  861. ->alias('cpr')
  862. ->join('address a','a.id = cpr.addr_id')
  863. ->where('cpr.user_id',$v['id'])
  864. ->where('cpr.create_yyyymmdd',$curday)
  865. ->order('cpr.id desc')
  866. ->value('a.title');
  867. if(!$addr){
  868. $addr = Db::name('todo')
  869. ->alias('t')
  870. ->join('orders o','o.id=t.order_id')
  871. ->join('order_convey oc','oc.order_id=o.id')
  872. ->join('address a','a.id=oc.start')
  873. ->where('t.to_user_id',$v['id'])
  874. ->where('t.org_id',$this->orgId)
  875. ->where('t.to_user_id',$v['id'])
  876. ->whereIn('t.todo_mode',[1,2,3])
  877. ->where('t.del',0)
  878. ->where('t.create_yyyymmdd',$curday)
  879. ->order('t.id desc')
  880. ->value('a.title');
  881. }
  882. $slist[$k][] = '<text style="color:'.$dmColor.'">'.$v['real_name'].'</text>';
  883. $slist[$k][] = '<text style="color: '.$dmColor.'">'.$count.'</text>';
  884. $slist[$k][] = '<text style="color: '.$dmColor.'">'.$addr.'</text>';
  885. }
  886. foreach ($lists as $k=>$v){
  887. if(in_array($v['id'],$userIds)){
  888. $nlists2[] = $v;
  889. }
  890. }
  891. foreach ($nlists2 as $k=>$v){
  892. $count = Db::name('todo')
  893. ->where('org_id',$this->orgId)
  894. ->where('to_user_id',$v['id'])
  895. ->whereIn('todo_mode',[1,2,3])
  896. ->where('del',0)
  897. ->where('create_yyyymmdd',$curday)
  898. ->count();
  899. $addr = Db::name('convey_plan_record')
  900. ->alias('cpr')
  901. ->join('address a','a.id = cpr.addr_id')
  902. ->where('cpr.create_yyyymmdd',$curday)
  903. ->where('cpr.user_id',$v['id'])
  904. ->order('cpr.id desc')
  905. ->value('a.title');
  906. if(!$addr){
  907. $addr = Db::name('todo')
  908. ->alias('t')
  909. ->join('orders o','o.id=t.order_id')
  910. ->join('order_convey oc','oc.order_id=o.id')
  911. ->join('address a','a.id=oc.start')
  912. ->where('t.to_user_id',$v['id'])
  913. ->where('t.org_id',$this->orgId)
  914. ->where('t.to_user_id',$v['id'])
  915. ->whereIn('t.todo_mode',[1,2,3])
  916. ->where('t.del',0)
  917. ->where('t.create_yyyymmdd',$curday)
  918. ->order('t.id desc')
  919. ->value('a.title');
  920. }
  921. $slist2[$k][] = '<text style="color: #11E799!important;">'.$v['real_name'].'</text>';
  922. $slist2[$k][] = '<text style="color: #11E799!important;">'.$count.'</text>';
  923. $slist2[$k][] = '<text style="color: #11E799!important;">'.$addr.'</text>';
  924. }
  925. $data = [
  926. 'count'=>count($slist2),
  927. 'count1'=>count($slist),
  928. 'list'=>array_merge($slist2,$slist),
  929. ];
  930. HelpHander::success($data);
  931. }
  932. }