Todo.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. <?php
  2. namespace app\api\controller\screen;
  3. use app\api\controller\screen\Index;
  4. use app\hander\HelpHander;
  5. use think\Db;
  6. use think\helper\Time;
  7. class Todo extends Index
  8. {
  9. //各类型当天工单总数
  10. public function cateTodoCount(){
  11. //保洁
  12. $bjCount = Db::name('todo')
  13. ->where('del',0)
  14. ->where('create_yyyymmdd',date('Ymd'))
  15. ->where('work_type_mode',2)
  16. ->count();
  17. $bjCount2 = Db::name('todo')
  18. ->where('del',0)
  19. ->where('todo_mode',3)
  20. ->where('create_yyyymmdd',date('Ymd'))
  21. ->where('work_type_mode',2)
  22. ->count();
  23. //报修
  24. $bxCount = Db::name('todo')
  25. ->where('del',0)
  26. ->where('create_yyyymmdd',date('Ymd'))
  27. ->where('work_type_mode',1)
  28. ->count();
  29. $bxCount2 = Db::name('todo')
  30. ->where('del',0)
  31. ->where('todo_mode',3)
  32. ->where('create_yyyymmdd',date('Ymd'))
  33. ->where('work_type_mode',1)
  34. ->count();
  35. //隐患
  36. $yhCount = Db::name('todo')
  37. ->where('del',0)
  38. ->where('create_yyyymmdd',date('Ymd'))
  39. ->where('work_type_mode',4)
  40. ->count();
  41. $yhCount2 = Db::name('todo')
  42. ->where('del',0)
  43. ->where('todo_mode',3)
  44. ->where('create_yyyymmdd',date('Ymd'))
  45. ->where('work_type_mode',4)
  46. ->count();
  47. //运送
  48. $ysCount = Db::name('todo')
  49. ->where('del',0)
  50. ->where('create_yyyymmdd',date('Ymd'))
  51. ->where('work_type_mode',3)
  52. ->count();
  53. $ysCount2 = Db::name('todo')
  54. ->where('del',0)
  55. ->where('todo_mode',3)
  56. ->where('create_yyyymmdd',date('Ymd'))
  57. ->where('work_type_mode',3)
  58. ->count();
  59. //陪护
  60. $phCount = Db::name('ph_todo')
  61. ->where('create_time','>=',date('Y-m-d').' 00:00:00')
  62. ->where('create_time','<=',date('Y-m-d').' 23:59:59')
  63. ->count();
  64. $phCount2 = Db::name('ph_todo')
  65. ->where('create_time','>=',date('Y-m-d').' 00:00:00')
  66. ->where('create_time','<=',date('Y-m-d').' 23:59:59')
  67. ->where('status',2)
  68. ->count();
  69. $dailyCount = Db::name('daily_record')->where('org_id',$this->orgId)->count();
  70. $xjCount = Db::name('patrol_record')->where('patrol_mode',4)->where('org_id',$this->orgId)->count();
  71. $yfCount = Db::name('waste_record')->where('org_id',$this->orgId)->where('del',0)->sum('weight');
  72. $w = '25471.5';
  73. if($this->orgId == 19){
  74. $kg = round($yfCount/1000+$w,1);
  75. }else{
  76. $kg = round($yfCount/1000,1);
  77. }
  78. $data = [
  79. 'bj'=>$bjCount.'/'.$bjCount2,
  80. 'bx'=>$bxCount.'/'.$bxCount2,
  81. 'yh'=>$yhCount.'/'.$yhCount2,
  82. 'ys'=>$ysCount.'/'.$ysCount2,
  83. 'ph'=>$phCount.'/'.$phCount2,
  84. 'daily'=>$dailyCount,
  85. 'patrol'=>$xjCount,
  86. 'waste'=>$kg,
  87. ];
  88. HelpHander::success($data);
  89. }
  90. //任务数据总览
  91. public function taskList(){
  92. $mode = input('mode/d',1);
  93. if(!in_array($mode,[1,2,3,4,5])){
  94. HelpHander::error('参数错误');
  95. }
  96. $data = [];
  97. $header = ['状态', '任务类型', '始发地', '目的地', '需求时间', '执行人', '接单时间', '完成时间'];
  98. if($mode == 5){
  99. $header = ['状态', '开始时间', '结束时间', '工作天数', '创建时间'];
  100. $todo = Db::name('ph_todo')
  101. ->where('org_id',$this->orgId)
  102. // ->where('status','in',[1,2])
  103. ->order('id desc')
  104. ->limit(30)
  105. ->select();
  106. foreach ($todo as $k=>$v){
  107. $data[$k]['status'] = $v['status'];
  108. $data[$k]['start'] = date('H:i',strtotime($v['start']));
  109. $data[$k]['end'] = date('H:i',strtotime($v['end']));
  110. $data[$k]['day'] = $v['day'];
  111. $data[$k]['create_time'] = date('H:i',strtotime($v['create_time']));
  112. }
  113. }else{
  114. if($mode == 1){
  115. $header = ['状态', '执行人', '报修事项', '内容', '接单时间','完成时间'];
  116. }else if($mode == 2||$mode == 4){
  117. $header = ['状态', '执行人', '内容', '接单时间','完成时间'];
  118. }
  119. $todo = Db::name('todo')
  120. ->where('org_id',$this->orgId)
  121. ->where('work_type_mode',$mode)
  122. ->where('del',0)
  123. ->order('id desc')
  124. ->limit(30)
  125. ->field('id,order_id,to_user_id,todo_mode,create_time,confirm_time,todo_content,done_time')
  126. ->select();
  127. foreach ($todo as $k=>$v){
  128. $userName = Db::name('user')->where('id',$v['to_user_id'])->value('real_name');
  129. if($mode == 1){ // 报修
  130. $type = Db::name('order_repair')
  131. ->alias('or')
  132. ->leftJoin('order_type ot','ot.id = or.type_id')
  133. ->where('or.order_id',$v['order_id'])
  134. ->value('title');
  135. $data[$k]['todo_mode'] = $v['todo_mode'];
  136. $data[$k]['user_name'] = $userName?$userName:'';
  137. $data[$k]['type'] = $type?$type:'';
  138. $data[$k]['content'] = $v['todo_content'];
  139. $data[$k]['confirm_time'] = $v['confirm_time']?date('H:i',strtotime($v['confirm_time'])):'';
  140. $data[$k]['done_time'] = $v['done_time']?date('H:i',strtotime($v['done_time'])):'';
  141. }else if($mode == 3){ //运送
  142. $convey = Db::name('order_convey')
  143. ->alias('oc')
  144. ->join('convey_cate cc','cc.id = oc.type')
  145. ->where('oc.order_id',$v['order_id'])
  146. ->field('oc.*,cc.title as cate_title')
  147. ->find();
  148. $userName = Db::name('user')->where('id',$v['to_user_id'])->value('real_name');
  149. $start = Db::name('address')->where('id',$convey['start'])->value('title');
  150. $end = Db::name('address')->where('id',$convey['end'])->value('title');
  151. $data[$k]['todo_mode'] = $v['todo_mode'];
  152. $data[$k]['type'] = $convey?$convey['cate_title']:'';
  153. $data[$k]['start'] = $start?$start:'';
  154. $data[$k]['end'] = $end?$end:'';
  155. $data[$k]['xq_time'] = $convey?date('H:i',strtotime($convey['xq_time'])):'';
  156. $data[$k]['user_name'] = $userName?$userName:'';
  157. $data[$k]['confirm_time'] = $v['confirm_time']?date('H:i',strtotime($v['confirm_time'])):'';
  158. $data[$k]['done_time'] = $v['done_time']?date('H:i',strtotime($v['done_time'])):'';
  159. }else{ // 保洁,安保
  160. $data[$k]['todo_mode'] = $v['todo_mode'];
  161. $data[$k]['user_name'] = $userName?$userName:'';
  162. $data[$k]['content'] = $v['todo_content'];
  163. $data[$k]['confirm_time'] = $v['confirm_time']?date('H:i',strtotime($v['confirm_time'])):'';
  164. $data[$k]['done_time'] = $v['done_time']?date('H:i',strtotime($v['done_time'])):'';
  165. }
  166. }
  167. }
  168. $lists = [];
  169. if($mode == 1){
  170. foreach ($data as $k=>$v){
  171. $status = Db::name('todo_mode')->where('id',$v['todo_mode'])->value('out_content');
  172. if($v['todo_mode'] == 1){
  173. $lists[$k][] = '<span style="color:#FFDA0A;">新订单</span>';
  174. $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['user_name'].'</span>';
  175. $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['type'].'</span>';
  176. $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['content'].'</span>';
  177. $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['confirm_time'].'</span>';
  178. $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['done_time'].'</span>';
  179. }else if($v['todo_mode'] == 2){
  180. $lists[$k][] = '<span style="color:#0FC2DD;">进行中</span>';
  181. $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['user_name'].'</span>';
  182. $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['type'].'</span>';
  183. $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['content'].'</span>';
  184. $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['confirm_time'].'</span>';
  185. $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['done_time'].'</span>';
  186. }else{
  187. $lists[$k][] = $status;
  188. $lists[$k][] = $v['user_name'];
  189. $lists[$k][] = $v['type'];
  190. $lists[$k][] = $v['content'];
  191. $lists[$k][] = $v['confirm_time'];
  192. $lists[$k][] = $v['done_time'];
  193. }
  194. }
  195. }else if($mode == 2 || $mode == 4){
  196. foreach ($data as $k=>$v){
  197. $status = Db::name('todo_mode')->where('id',$v['todo_mode'])->value('out_content');
  198. if($v['todo_mode'] == 1){
  199. $lists[$k][] = '<span style="color:#FFDA0A;">新订单</span>';
  200. $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['user_name'].'</span>';
  201. $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['content'].'</span>';
  202. $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['confirm_time'].'</span>';
  203. $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['done_time'].'</span>';
  204. }else if($v['todo_mode'] == 2){
  205. $lists[$k][] = '<span style="color:#0FC2DD;">进行中</span>';
  206. $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['user_name'].'</span>';
  207. $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['content'].'</span>';
  208. $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['confirm_time'].'</span>';
  209. $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['done_time'].'</span>';
  210. }else{
  211. $lists[$k][] = $status;
  212. $lists[$k][] = $v['user_name'];
  213. $lists[$k][] = $v['content'];
  214. $lists[$k][] = $v['confirm_time'];
  215. $lists[$k][] = $v['done_time'];
  216. }
  217. }
  218. }else if($mode == 3){
  219. foreach ($data as $k=>$v){
  220. $status = Db::name('todo_mode')->where('id',$v['todo_mode'])->value('out_content');
  221. if($v['todo_mode'] == 1){
  222. $lists[$k][] = '<span style="color:#FFDA0A;">新订单</span>';
  223. $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['type'].'</span>';
  224. $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['start'].'</span>';
  225. $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['end'].'</span>';
  226. $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['xq_time'].'</span>';
  227. $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['user_name'].'</span>';
  228. $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['confirm_time'].'</span>';
  229. $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['done_time'].'</span>';
  230. }elseif($v['todo_mode'] == 2){
  231. $lists[$k][] = '<span style="color:#0FC2DD;">进行中</span>';
  232. $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['type'].'</span>';
  233. $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['start'].'</span>';
  234. $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['end'].'</span>';
  235. $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['xq_time'].'</span>';
  236. $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['user_name'].'</span>';
  237. $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['confirm_time'].'</span>';
  238. $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['done_time'].'</span>';
  239. }else{
  240. $lists[$k][] = $status;
  241. $lists[$k][] = $v['type'];
  242. $lists[$k][] = $v['start'];
  243. $lists[$k][] = $v['end'];
  244. $lists[$k][] = $v['xq_time'];
  245. $lists[$k][] = $v['user_name'];
  246. $lists[$k][] = $v['confirm_time'];
  247. $lists[$k][] = $v['done_time'];
  248. }
  249. }
  250. }else if($mode == 5){
  251. foreach ($data as $k=>$v){
  252. $status = '';
  253. if($v['status'] == 0){
  254. $status = '作废';
  255. }else if($v['status'] == 1){
  256. $status = '服务中';
  257. }else if($v['status'] == 2){
  258. $status = '已结束';
  259. }
  260. $lists[$k][] = $status;
  261. $lists[$k][] = $v['start'];
  262. $lists[$k][] = $v['end'];
  263. $lists[$k][] = $v['day'];
  264. $lists[$k][] = $v['create_time'];
  265. }
  266. }
  267. HelpHander::success(['data'=>$lists,'header'=>$header]);
  268. }
  269. //今日工单总数 //项目工单总数 //项目订单总数 //项目任务总数
  270. public function todoCountData(){
  271. $todayCount = Db::name('todo')
  272. ->where('del',0)
  273. ->where('org_id',$this->orgId)
  274. ->where('create_yyyymmdd',date('Ymd'))
  275. ->count();
  276. $todoCount = Db::name('todo')
  277. ->where('del',0)
  278. ->where('org_id',$this->orgId)
  279. ->count();
  280. $orderCount = Db::name('orders')
  281. ->where('del',0)
  282. ->where('org_id',$this->orgId)
  283. ->count();
  284. $task1 = Db::name('device_task')
  285. ->where('del',0)
  286. ->where('org_id',$this->orgId)
  287. ->count();
  288. $task2 = Db::name('patrol_task')
  289. ->where('del',0)
  290. ->where('org_id',$this->orgId)
  291. ->count();
  292. $taskCount = $task1+$task2;
  293. $data = [
  294. 'todayCount'=>$todayCount,
  295. 'todoCount'=>$todoCount,
  296. 'orderCount'=>$orderCount,
  297. 'taskCount'=>$taskCount,
  298. ];
  299. HelpHander::success($data);
  300. }
  301. public function todayTodoData(){
  302. $date = date('Ymd');
  303. $count = Db::name('todo')
  304. ->where('create_yyyymmdd',$date)
  305. ->where('del',0)
  306. ->count();
  307. $count2 = Db::name('todo')
  308. ->where('create_yyyymmdd',$date)
  309. ->where('del',0)
  310. ->where('todo_mode',3)
  311. ->count();
  312. $map[] = ['del','=',0];
  313. $map[] = ['create_yyyymmdd','=',$date];
  314. $bjCount = Db::name('todo')->where('work_type_mode',2)->where($map)->count();
  315. $bj = Db::name('todo')->where('work_type_mode',2)->where('todo_mode',3)->where($map)->count();
  316. $ysCount = Db::name('todo')->where('work_type_mode',3)->where($map)->count();
  317. $ys = Db::name('todo')->where('work_type_mode',3)->where('todo_mode',3)->where($map)->count();
  318. $bxCount = Db::name('todo')->where('work_type_mode',1)->where($map)->count();
  319. $bx = Db::name('todo')->where('work_type_mode',1)->where('todo_mode',3)->where($map)->count();
  320. $yhCount = Db::name('todo')->where('work_type_mode',4)->where($map)->count();
  321. $yh = Db::name('todo')->where('work_type_mode',4)->where('todo_mode',3)->where($map)->count();
  322. $bl = $bjBl = $ysBl = $bxBl = $yhBl = 0;
  323. if($count > 0){
  324. $bl = round($count2/$count*100,0);
  325. }
  326. if($bjCount >0){
  327. $bjBl = round($bj/$bjCount*100,0);
  328. }
  329. if($ysCount >0){
  330. $ysBl = round($ys/$ysCount*100,0);
  331. }
  332. if($bxCount >0){
  333. $bxBl = round($bx/$bxCount*100,0);
  334. }
  335. if($yhCount >0){
  336. $yhBl = round($yh/$yhCount*100,0);
  337. }
  338. $count3 = 0;
  339. if($count == 0){
  340. $count3 = 100;
  341. }else{
  342. $count3 = $count - $count2;
  343. }
  344. $data = [
  345. 'count'=>$count,
  346. 'bl'=>$bl,
  347. 'bjBl'=>$bjBl,
  348. 'bj'=>$bj,
  349. 'ysBl'=>$ysBl,
  350. 'ys'=>$ys,
  351. 'bxBl'=>$bxBl,
  352. 'bx'=>$bx,
  353. 'yhBl'=>$yhBl,
  354. 'yh'=>$yh,
  355. 'list'=>[
  356. ['value'=>$count2],
  357. ['value'=>$count3],
  358. ]
  359. ];
  360. HelpHander::success($data);
  361. }
  362. }