0
0

Convey.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  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. ->count();
  15. HelpHander::success($count);
  16. }
  17. public function todoStatusNum(){
  18. $list = [
  19. ['name'=>'待派工','mode'=>1],
  20. ['name'=>'进行中','mode'=>2],
  21. ['name'=>'已完成','mode'=>3],
  22. ['name'=>'已超时','mode'=>5],
  23. ];
  24. foreach ($list as $k=>$v){
  25. $list[$k]['value'] = Db::name('todo')
  26. ->where('org_id',$this->orgId)
  27. ->where('del',0)
  28. ->where('todo_mode',$v['mode'])
  29. ->where('work_type_mode',3)
  30. ->count();
  31. }
  32. $todo = Db::name('todo')
  33. ->alias('t')
  34. ->field('t.done_time,oc.ywc_time')
  35. ->join('order_convey oc','oc.order_id=t.order_id')
  36. ->where('t.org_id',$this->orgId)
  37. ->where('t.del',0)
  38. ->where('t.todo_mode',3)
  39. ->select();
  40. $count = count($todo);
  41. $nums = 0; //标准时间的送达的数量
  42. foreach ($todo as $k=>$v){
  43. if($v['done_time'] < $v['ywc_time']){
  44. $nums +=1;
  45. }
  46. }
  47. $bl = '0%';
  48. if($count >0){
  49. $bl = round($nums/$count*100,1).'%';
  50. }
  51. $count1 = $bl;
  52. //平均响应时间
  53. $count2 = Db::name('todo')
  54. ->where('org_id',$this->orgId)
  55. ->where('del',0)
  56. ->where('todo_mode',3)
  57. ->avg('xy_time');
  58. //未派工任务数量
  59. $orders = Db::name('orders')
  60. ->where('org_id',$this->orgId)
  61. ->where('del',0)
  62. ->count();
  63. $ordersCount = Db::name('orders')
  64. ->where('org_id',$this->orgId)
  65. ->where('del',0)
  66. ->where('order_mode',1)
  67. ->count();
  68. $count3 = '0%';
  69. if($orders > 0){
  70. $count3 = round($ordersCount/$orders*100,1).'%';
  71. }
  72. $data = [
  73. 'list'=>$list,
  74. 'legend'=>['待派工','进行中','已完成','已超时'],
  75. 'count'=>[
  76. 'count1'=>$count1,
  77. 'count2'=>round($count2/360,1),
  78. 'count3'=>$count3,
  79. ],
  80. ];
  81. HelpHander::success($data);
  82. }
  83. //运送热点区域数据
  84. public function addrData(){
  85. $date = date('Ymd');
  86. $edate = date("Ymd",strtotime("-1 months",strtotime($date)));
  87. $addr = Db::name('address')
  88. ->field('id,title')
  89. ->where('del',0)
  90. ->where('enable',1)
  91. ->where('org_id',$this->orgId)
  92. ->where('','exp',Db::raw("FIND_IN_SET(2,types)"))
  93. ->select();
  94. foreach ($addr as $k=>$v){
  95. $addr[$k]['nums1'] = Db::name('todo')
  96. ->alias('t')
  97. ->join('todo_convey tc','tc.todo_id=t.id')
  98. ->where('tc.start',$v['id'])
  99. ->where('t.org_id',$this->orgId)
  100. ->where('t.del',0)
  101. ->where('t.create_yyyymmdd','=',$date)
  102. ->count();
  103. $nums2 = Db::name('todo')
  104. ->alias('t')
  105. ->join('todo_convey tc','tc.todo_id=t.id')
  106. ->where('tc.start',$v['id'])
  107. ->where('t.org_id',$this->orgId)
  108. ->where('t.del',0)
  109. ->where('t.create_yyyymmdd','<=',$date)
  110. ->where('t.create_yyyymmdd','>',$edate)
  111. ->count();
  112. $addr[$k]['nums2'] = round($nums2/30,1);
  113. // $addr[$k]['nums2'] = $nums2;
  114. }
  115. $lists =array_slice(list_sort_by($addr,'nums1','desc'),0,5) ;
  116. $data1 = array_column($lists,'nums1');
  117. $data2 = array_column($lists,'nums2');
  118. $title = array_column($lists,'title');
  119. $data = [
  120. 'data1'=>$data1,
  121. 'data2'=>$data2,
  122. 'title'=>$title,
  123. ];
  124. HelpHander::success($data);
  125. }
  126. public function ysTypeUser(){
  127. $lists = model('WorkTypeMode')->getRolesUserApp(3,$this->orgId);
  128. $curday = date('Ymd');
  129. $users = Db::name('todo')
  130. ->field('to_user_id')
  131. ->where('org_id',$this->orgId)
  132. ->whereIn('todo_mode',[1,2])
  133. ->where('del',0)
  134. ->where('work_type_mode',3)
  135. ->where('create_yyyymmdd',$curday)
  136. ->group('to_user_id')
  137. ->select();
  138. $users = $users?$users:[];
  139. $userIds = [];
  140. foreach ($users as $k=>$v){
  141. $userIds[] = $v['to_user_id'];
  142. }
  143. $nlists = $nlists2 = [];
  144. foreach ($lists as $k=>$v){
  145. if(!in_array($v['id'],$userIds)){
  146. $nlists[] = $v;
  147. }
  148. }
  149. $slist = $slist2 = [];
  150. foreach ($nlists as $k=>$v){
  151. $count = Db::name('todo')
  152. ->where('org_id',$this->orgId)
  153. ->where('to_user_id',$v['id'])
  154. ->whereIn('todo_mode',[1,2,3])
  155. ->where('del',0)
  156. ->where('create_yyyymmdd',$curday)
  157. ->count();
  158. $addr = Db::name('convey_plan_record')
  159. ->alias('cpr')
  160. ->join('address a','a.id = cpr.addr_id')
  161. ->where('cpr.user_id',$v['id'])
  162. ->where('cpr.create_yyyymmdd',$curday)
  163. ->order('cpr.id desc')
  164. ->value('a.title');
  165. $slist[$k][] = '<span style="color: #FFE400">'.$v['real_name'].'</span>';
  166. $slist[$k][] = '<span style="color: #FFE400">'.$count.'</span>';
  167. $slist[$k][] = '<span style="color: #FFE400">'.$addr.'</span>';
  168. }
  169. foreach ($lists as $k=>$v){
  170. if(in_array($v['id'],$userIds)){
  171. $nlists2[] = $v;
  172. }
  173. }
  174. foreach ($nlists2 as $k=>$v){
  175. $count = Db::name('todo')
  176. ->where('org_id',$this->orgId)
  177. ->where('to_user_id',$v['id'])
  178. ->whereIn('todo_mode',[1,2,3])
  179. ->where('del',0)
  180. ->where('create_yyyymmdd',$curday)
  181. ->count();
  182. $addr = Db::name('convey_plan_record')
  183. ->alias('cpr')
  184. ->join('address a','a.id = cpr.addr_id')
  185. ->where('cpr.create_yyyymmdd',$curday)
  186. ->where('cpr.user_id',$v['id'])
  187. ->order('cpr.id desc')
  188. ->value('a.title');
  189. $slist2[$k][] = '<span style="color: #11E799">'.$v['real_name'].'</span>';
  190. $slist2[$k][] = '<span style="color: #11E799">'.$count.'</span>';
  191. $slist2[$k][] = '<span style="color: #11E799">'.$addr?$addr:''.'</span>';
  192. }
  193. $data = [
  194. 'list1'=>[
  195. 'list'=>$slist2,
  196. 'count'=>count($slist2),
  197. ],
  198. 'list2'=>[
  199. 'list'=>$slist,
  200. 'count'=>count($slist),
  201. ],
  202. ];
  203. HelpHander::success($data);
  204. }
  205. public function ysTask(){
  206. $order = Db::name('orders')
  207. ->alias('o')
  208. ->field('o.*,oc.type,oc.start,oc.end,oc.xq_time,oc.ywc_time,oc.device_id,oc.name,oc.phone,oc.priority')
  209. ->join('order_convey oc','oc.order_id=o.id')
  210. ->where('o.create_yyyymmdd',date('Ymd'))
  211. ->where('o.work_type_mode',3)
  212. ->where('o.org_id',$this->orgId)
  213. ->where('o.del',0)
  214. ->whereIn('o.order_mode',[1,4,5])
  215. ->order('oc.xq_time')
  216. ->select();
  217. foreach ($order as $k=>$v){
  218. $order[$k]['xq_time'] = date('H:i',strtotime($v['xq_time']));
  219. $order[$k]['start_name'] = Db::name('address')->where('id',$v['start'])->value('title');
  220. $order[$k]['end_name'] = Db::name('address')->where('id',$v['end'])->value('title');
  221. $order[$k]['type_name'] = Db::name('convey_cate')->where('id',$v['type'])->value('title');
  222. $todo = Db::name('todo')
  223. ->alias('t')
  224. ->field('u.real_name,t.create_time,t.confirm_time')
  225. ->join('user u','u.id = t.to_user_id')
  226. ->whereIn('t.todo_mode',[1,2,3])
  227. ->where('t.del',0)
  228. ->where('t.order_id',$v['id'])
  229. ->order('t.id asc')
  230. ->select();
  231. $users = [];
  232. $confirmTime = '';
  233. foreach ($todo as $kk=>$vv){
  234. $users[] = $vv['real_name'];
  235. if(!$confirmTime && $vv['confirm_time']){
  236. $confirmTime = $vv['confirm_time'];
  237. }else if($confirmTime && $vv['confirm_time'] && $vv['confirm_time'] < $confirmTime){
  238. $confirmTime = $vv['confirm_time'];
  239. }
  240. }
  241. $send_time = $todo?$todo[0]['create_time']:'';
  242. $order[$k]['real_names'] = implode(',',$users);
  243. $order[$k]['send_time'] = !empty($send_time)?date('H:i',strtotime($send_time)):'';
  244. $order[$k]['confirm_time'] = !empty($confirmTime)?date('H:i',strtotime($confirmTime)):'';
  245. }
  246. $list = [];
  247. foreach ($order as $k=>$v) {
  248. if($v['order_mode'] == 1){
  249. $list[$k][] = '新任务';
  250. $list[$k][] = $v['type_name'];
  251. $list[$k][] = $v['start_name'];
  252. $list[$k][] = $v['end_name'];
  253. $list[$k][] = $v['xq_time'];
  254. $list[$k][] = $v['real_names'];
  255. $list[$k][] = $v['send_time'];
  256. $list[$k][] = $v['confirm_time'];
  257. } elseif($v['order_mode'] == 5 && $v['confirm_time']){
  258. $list[$k][] = '<span style="color:#0FC2DD;">已派工</span>';
  259. $list[$k][] = '<span style="color:#0FC2DD;">'.$v['type_name'].'</span>';
  260. $list[$k][] = '<span style="color:#0FC2DD;">'.$v['start_name'].'</span>';
  261. $list[$k][] = '<span style="color:#0FC2DD;">'.$v['end_name'].'</span>';
  262. $list[$k][] = '<span style="color:#0FC2DD;">'.$v['xq_time'].'</span>';
  263. $list[$k][] = '<span style="color:#0FC2DD;">'.$v['real_names'].'</span>';
  264. $list[$k][] = '<span style="color:#0FC2DD;">'.$v['send_time'].'</span>';
  265. $list[$k][] = '<span style="color:#0FC2DD;">'.$v['confirm_time'].'</span>';
  266. }else{
  267. $list[$k][] = '<span style="color:#49E9A0;">进行中</span>';
  268. $list[$k][] = '<span style="color:#49E9A0;">'.$v['type_name'].'</span>';
  269. $list[$k][] = '<span style="color:#49E9A0;">'.$v['start_name'].'</span>';
  270. $list[$k][] = '<span style="color:#49E9A0;">'.$v['end_name'].'</span>';
  271. $list[$k][] = '<span style="color:#49E9A0;">'.$v['xq_time'].'</span>';
  272. $list[$k][] = '<span style="color:#49E9A0;">'.$v['real_names'].'</span>';
  273. $list[$k][] = '<span style="color:#49E9A0;">'.$v['send_time'].'</span>';
  274. $list[$k][] = '<span style="color:#49E9A0;">'.$v['confirm_time'].'</span>';
  275. }
  276. }
  277. HelpHander::success($list);
  278. }
  279. //标本限时服务
  280. public function conveyOrder(){
  281. $order = Db::name('orders')
  282. ->alias('o')
  283. ->field('o.order_mode,oc.*')
  284. ->join('order_convey oc','oc.order_id=o.id')
  285. ->where('o.org_id',$this->orgId)
  286. ->where('o.del',0)
  287. ->where('o.create_yyyymmdd',date('Ymd'))
  288. ->where('o.work_type_mode',3)
  289. ->whereIn('o.order_mode',[1,4,5])
  290. ->order('o.id desc')
  291. ->select();
  292. foreach ($order as $k=>$v){
  293. $order[$k]['status'] = '';
  294. if($v['order_mode'] == 1){
  295. $order[$k]['status'] = '待派发';
  296. }elseif ($v['order_mode'] == 4){
  297. $order[$k]['status'] = '已派发';
  298. }elseif ($v['order_mode'] == 5){
  299. $order[$k]['status'] = '已完成';
  300. }
  301. $order[$k]['cate_name'] = Db::name('convey_cate')->where('id',$v['type'])->value('title');
  302. $order[$k]['start_name'] = Db::name('address')->where('id',$v['start'])->value('title');
  303. }
  304. $list = [];
  305. foreach ($order as $k=>$v){
  306. $list[$k][] = $v['cate_name'];
  307. $list[$k][] = $v['start_name'];
  308. $list[$k][] = $v['xq_time'];
  309. $list[$k][] = $v['status'];
  310. }
  311. HelpHander::success($list);
  312. }
  313. public function ysOrderWeek(){
  314. $dlist = [
  315. date('Y-m-d',strtotime('-6 days')),
  316. date('Y-m-d',strtotime('-5 days')),
  317. date('Y-m-d',strtotime('-4 days')),
  318. date('Y-m-d',strtotime('-3 days')),
  319. date('Y-m-d',strtotime('-2 days')),
  320. date('Y-m-d',strtotime('-1 days')),
  321. date('Y-m-d'),
  322. ];
  323. $list = $list1 = $date = [];
  324. foreach ($dlist as $k=>$v){
  325. $data[] = date('m-d',strtotime($v));
  326. $tt = date('Ymd',strtotime($v));
  327. $count = Db::name('todo')
  328. ->where('org_id',$this->orgId)
  329. ->where('create_yyyymmdd',$tt)
  330. ->where('del',0)
  331. ->where('work_type_mode',3)
  332. ->count();
  333. $count1 = Db::name('todo')
  334. ->where('org_id',$this->orgId)
  335. ->where('create_yyyymmdd',$tt)
  336. ->where('del',0)
  337. ->where('work_type_mode',3)
  338. ->where('todo_mode',3)
  339. ->count();
  340. $list[$k]= $count;
  341. $list1[$k] = $count1;
  342. }
  343. $data = [
  344. 'title'=>$data,
  345. 'list'=>[
  346. 'list1'=>$list,
  347. 'list2'=>$list1,
  348. ]
  349. ];
  350. HelpHander::success($data);
  351. }
  352. public function conveyCateData(){
  353. $cate = Db::name('convey_cate')
  354. ->field('id,title')
  355. ->where('del',0)
  356. ->where('enable',1)
  357. ->where('org_id',$this->orgId)
  358. ->select();
  359. foreach ($cate as $k=>$v){
  360. $cate[$k]['count'] = Db::name('orders')
  361. ->alias('o')
  362. ->join('order_convey oc','oc.order_id=o.id')
  363. ->whereIn('o.order_mode',[1,4,5,6])
  364. ->where('o.del',0)
  365. ->where('o.work_type_mode',3)
  366. ->where('oc.type',$v['id'])
  367. ->count();
  368. }
  369. $lists =array_slice(list_sort_by($cate,'count','desc'),0,6) ;
  370. $data1 = array_column($lists,'title');
  371. $data2 = array_column($lists,'count');
  372. $data = [
  373. 'title'=>$data1,
  374. 'list'=>$data2,
  375. ];
  376. HelpHander::success($data);
  377. }
  378. }