Todo.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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. $data = [
  70. 'bj'=>$bjCount.'/'.$bjCount2,
  71. 'bx'=>$bxCount.'/'.$bxCount2,
  72. 'yh'=>$yhCount.'/'.$yhCount2,
  73. 'ys'=>$ysCount.'/'.$ysCount2,
  74. 'ph'=>$phCount.'/'.$phCount2,
  75. ];
  76. HelpHander::success($data);
  77. }
  78. //任务数据总览
  79. public function taskList(){
  80. $mode = input('mode/d',1);
  81. if(!in_array($mode,[1,2,3,4,5])){
  82. HelpHander::error('参数错误');
  83. }
  84. $data = [];
  85. $header = ['状态', '任务类型', '始发地', '目的地', '需求时间', '执行人', '接单时间', '完成时间'];
  86. if($mode == 5){
  87. $header = ['状态', '开始时间', '结束时间', '工作天数', '创建时间'];
  88. $todo = Db::name('ph_todo')
  89. ->where('org_id',$this->orgId)
  90. // ->where('status','in',[1,2])
  91. ->order('id desc')
  92. ->limit(30)
  93. ->select();
  94. foreach ($todo as $k=>$v){
  95. $data[$k]['status'] = $v['status'];
  96. $data[$k]['start'] = date('H:i',strtotime($v['start']));
  97. $data[$k]['end'] = date('H:i',strtotime($v['end']));
  98. $data[$k]['day'] = $v['day'];
  99. $data[$k]['create_time'] = date('H:i',strtotime($v['create_time']));
  100. }
  101. }else{
  102. if($mode == 1){
  103. $header = ['状态', '执行人', '报修事项', '内容', '接单时间','完成时间'];
  104. }else if($mode == 2||$mode == 4){
  105. $header = ['状态', '执行人', '内容', '接单时间','完成时间'];
  106. }
  107. $todo = Db::name('todo')
  108. ->where('org_id',$this->orgId)
  109. ->where('work_type_mode',$mode)
  110. ->where('del',0)
  111. ->order('id desc')
  112. ->limit(30)
  113. ->field('id,order_id,to_user_id,todo_mode,create_time,confirm_time,todo_content,done_time')
  114. ->select();
  115. foreach ($todo as $k=>$v){
  116. $userName = Db::name('user')->where('id',$v['to_user_id'])->value('real_name');
  117. if($mode == 1){ // 报修
  118. $type = Db::name('order_repair')
  119. ->alias('or')
  120. ->leftJoin('order_type ot','ot.id = or.type_id')
  121. ->where('or.order_id',$v['order_id'])
  122. ->value('title');
  123. $data[$k]['todo_mode'] = $v['todo_mode'];
  124. $data[$k]['user_name'] = $userName?$userName:'';
  125. $data[$k]['type'] = $type?$type:'';
  126. $data[$k]['content'] = $v['todo_content'];
  127. $data[$k]['confirm_time'] = $v['confirm_time']?date('H:i',strtotime($v['confirm_time'])):'';
  128. $data[$k]['done_time'] = $v['done_time']?date('H:i',strtotime($v['done_time'])):'';
  129. }else if($mode == 3){ //运送
  130. $convey = Db::name('order_convey')
  131. ->alias('oc')
  132. ->join('convey_cate cc','cc.id = oc.type')
  133. ->where('oc.order_id',$v['order_id'])
  134. ->field('oc.*,cc.title as cate_title')
  135. ->find();
  136. $userName = Db::name('user')->where('id',$v['to_user_id'])->value('real_name');
  137. $start = Db::name('address')->where('id',$convey['start'])->value('title');
  138. $end = Db::name('address')->where('id',$convey['end'])->value('title');
  139. $data[$k]['todo_mode'] = $v['todo_mode'];
  140. $data[$k]['type'] = $convey?$convey['cate_title']:'';
  141. $data[$k]['start'] = $start?$start:'';
  142. $data[$k]['end'] = $end?$end:'';
  143. $data[$k]['xq_time'] = $convey?date('H:i',strtotime($convey['xq_time'])):'';
  144. $data[$k]['user_name'] = $userName?$userName:'';
  145. $data[$k]['confirm_time'] = $v['confirm_time']?date('H:i',strtotime($v['confirm_time'])):'';
  146. $data[$k]['done_time'] = $v['done_time']?date('H:i',strtotime($v['done_time'])):'';
  147. }else{ // 保洁,应急
  148. $data[$k]['todo_mode'] = $v['todo_mode'];
  149. $data[$k]['user_name'] = $userName?$userName:'';
  150. $data[$k]['content'] = $v['todo_content'];
  151. $data[$k]['confirm_time'] = $v['confirm_time']?date('H:i',strtotime($v['confirm_time'])):'';
  152. $data[$k]['done_time'] = $v['done_time']?date('H:i',strtotime($v['done_time'])):'';
  153. }
  154. }
  155. }
  156. $lists = [];
  157. if($mode == 1){
  158. foreach ($data as $k=>$v){
  159. $status = Db::name('todo_mode')->where('id',$v['todo_mode'])->value('out_content');
  160. if($v['todo_mode'] == 1){
  161. $lists[$k][] = '<span style="color:#FFDA0A;">新订单</span>';
  162. $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['user_name'].'</span>';
  163. $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['type'].'</span>';
  164. $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['content'].'</span>';
  165. $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['confirm_time'].'</span>';
  166. $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['done_time'].'</span>';
  167. }else if($v['todo_mode'] == 2){
  168. $lists[$k][] = '<span style="color:#0FC2DD;">进行中</span>';
  169. $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['user_name'].'</span>';
  170. $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['type'].'</span>';
  171. $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['content'].'</span>';
  172. $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['confirm_time'].'</span>';
  173. $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['done_time'].'</span>';
  174. }else{
  175. $lists[$k][] = $status;
  176. $lists[$k][] = $v['user_name'];
  177. $lists[$k][] = $v['type'];
  178. $lists[$k][] = $v['content'];
  179. $lists[$k][] = $v['confirm_time'];
  180. $lists[$k][] = $v['done_time'];
  181. }
  182. }
  183. }else if($mode == 2 || $mode == 4){
  184. foreach ($data as $k=>$v){
  185. $status = Db::name('todo_mode')->where('id',$v['todo_mode'])->value('out_content');
  186. if($v['todo_mode'] == 1){
  187. $lists[$k][] = '<span style="color:#FFDA0A;">新订单</span>';
  188. $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['user_name'].'</span>';
  189. $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['content'].'</span>';
  190. $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['confirm_time'].'</span>';
  191. $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['done_time'].'</span>';
  192. }else if($v['todo_mode'] == 2){
  193. $lists[$k][] = '<span style="color:#0FC2DD;">进行中</span>';
  194. $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['user_name'].'</span>';
  195. $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['content'].'</span>';
  196. $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['confirm_time'].'</span>';
  197. $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['done_time'].'</span>';
  198. }else{
  199. $lists[$k][] = $status;
  200. $lists[$k][] = $v['user_name'];
  201. $lists[$k][] = $v['content'];
  202. $lists[$k][] = $v['confirm_time'];
  203. $lists[$k][] = $v['done_time'];
  204. }
  205. }
  206. }else if($mode == 3){
  207. foreach ($data as $k=>$v){
  208. $status = Db::name('todo_mode')->where('id',$v['todo_mode'])->value('out_content');
  209. if($v['todo_mode'] == 1){
  210. $lists[$k][] = '<span style="color:#FFDA0A;">新订单</span>';
  211. $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['type'].'</span>';
  212. $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['start'].'</span>';
  213. $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['end'].'</span>';
  214. $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['xq_time'].'</span>';
  215. $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['user_name'].'</span>';
  216. $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['confirm_time'].'</span>';
  217. $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['done_time'].'</span>';
  218. }elseif($v['todo_mode'] == 2){
  219. $lists[$k][] = '<span style="color:#0FC2DD;">进行中</span>';
  220. $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['type'].'</span>';
  221. $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['start'].'</span>';
  222. $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['end'].'</span>';
  223. $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['xq_time'].'</span>';
  224. $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['user_name'].'</span>';
  225. $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['confirm_time'].'</span>';
  226. $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['done_time'].'</span>';
  227. }else{
  228. $lists[$k][] = $status;
  229. $lists[$k][] = $v['type'];
  230. $lists[$k][] = $v['start'];
  231. $lists[$k][] = $v['end'];
  232. $lists[$k][] = $v['xq_time'];
  233. $lists[$k][] = $v['user_name'];
  234. $lists[$k][] = $v['confirm_time'];
  235. $lists[$k][] = $v['done_time'];
  236. }
  237. }
  238. }else if($mode == 5){
  239. foreach ($data as $k=>$v){
  240. $status = '';
  241. if($v['status'] == 0){
  242. $status = '作废';
  243. }else if($v['status'] == 1){
  244. $status = '服务中';
  245. }else if($v['status'] == 2){
  246. $status = '已结束';
  247. }
  248. $lists[$k][] = $status;
  249. $lists[$k][] = $v['start'];
  250. $lists[$k][] = $v['end'];
  251. $lists[$k][] = $v['day'];
  252. $lists[$k][] = $v['create_time'];
  253. }
  254. }
  255. HelpHander::success(['data'=>$lists,'header'=>$header]);
  256. }
  257. //今日工单总数 //项目工单总数 //项目订单总数 //项目任务总数
  258. public function todoCountData(){
  259. $todayCount = Db::name('todo')
  260. ->where('del',0)
  261. ->where('org_id',$this->orgId)
  262. ->where('create_yyyymmdd',date('Ymd'))
  263. ->count();
  264. $todoCount = Db::name('todo')
  265. ->where('del',0)
  266. ->where('org_id',$this->orgId)
  267. ->count();
  268. $orderCount = Db::name('orders')
  269. ->where('del',0)
  270. ->where('org_id',$this->orgId)
  271. ->count();
  272. $task1 = Db::name('device_task')
  273. ->where('del',0)
  274. ->where('org_id',$this->orgId)
  275. ->count();
  276. $task2 = Db::name('patrol_task')
  277. ->where('del',0)
  278. ->where('org_id',$this->orgId)
  279. ->count();
  280. $taskCount = $task1+$task2;
  281. $data = [
  282. 'todayCount'=>$todayCount,
  283. 'todoCount'=>$todoCount,
  284. 'orderCount'=>$orderCount,
  285. 'taskCount'=>$taskCount,
  286. ];
  287. HelpHander::success($data);
  288. }
  289. public function todayTodoData(){
  290. $date = date('Ymd');
  291. $count = Db::name('todo')
  292. ->where('create_yyyymmdd',$date)
  293. ->where('del',0)
  294. ->count();
  295. $count2 = Db::name('todo')
  296. ->where('create_yyyymmdd',$date)
  297. ->where('del',0)
  298. ->where('todo_mode',3)
  299. ->count();
  300. $map[] = ['del','=',0];
  301. $map[] = ['create_yyyymmdd','=',$date];
  302. $bjCount = Db::name('todo')->where('work_type_mode',2)->where($map)->count();
  303. $bj = Db::name('todo')->where('work_type_mode',2)->where('todo_mode',3)->where($map)->count();
  304. $ysCount = Db::name('todo')->where('work_type_mode',3)->where($map)->count();
  305. $ys = Db::name('todo')->where('work_type_mode',3)->where('todo_mode',3)->where($map)->count();
  306. $bxCount = Db::name('todo')->where('work_type_mode',1)->where($map)->count();
  307. $bx = Db::name('todo')->where('work_type_mode',1)->where('todo_mode',3)->where($map)->count();
  308. $yhCount = Db::name('todo')->where('work_type_mode',4)->where($map)->count();
  309. $yh = Db::name('todo')->where('work_type_mode',4)->where('todo_mode',3)->where($map)->count();
  310. $bl = $bjBl = $ysBl = $bxBl = $yhBl = 0;
  311. if($count > 0){
  312. $bl = round($count2/$count*100,0);
  313. }
  314. if($bjCount >0){
  315. $bjBl = round($bj/$bjCount*100,0);
  316. }
  317. if($ysCount >0){
  318. $ysBl = round($ys/$ysCount*100,0);
  319. }
  320. if($bxCount >0){
  321. $bxBl = round($bx/$bxCount*100,0);
  322. }
  323. if($yhCount >0){
  324. $yhBl = round($yh/$yhCount*100,0);
  325. }
  326. $count3 = 0;
  327. if($count == 0){
  328. $count3 = 100;
  329. }else{
  330. $count3 = $count - $count2;
  331. }
  332. $data = [
  333. 'count'=>$count,
  334. 'bl'=>$bl,
  335. 'bjBl'=>$bjBl,
  336. 'bj'=>$bj,
  337. 'ysBl'=>$ysBl,
  338. 'ys'=>$ys,
  339. 'bxBl'=>$bxBl,
  340. 'bx'=>$bx,
  341. 'yhBl'=>$yhBl,
  342. 'yh'=>$yh,
  343. 'list'=>[
  344. ['value'=>$count2],
  345. ['value'=>$count3],
  346. ]
  347. ];
  348. HelpHander::success($data);
  349. }
  350. }