Todo.php 17 KB

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