Project.php 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000
  1. <?php
  2. namespace app\api\controller\screen;
  3. use app\hander\HelpHander;
  4. use app\api\controller\screen\Index;
  5. use think\Controller;
  6. use think\Db;
  7. class Project extends Controller
  8. {
  9. public function __construct()
  10. {
  11. parent::__construct();
  12. $this->orgId = input('orgid')?input('orgid'):0;
  13. }
  14. /**
  15. * 获取用户数
  16. * @param $orgid 组织id
  17. * @param $roles 角色id
  18. * @return mixed
  19. */
  20. private function get_user_count($orgid,$roles){
  21. $count = $this->db
  22. ->join('user_roles','user.USER_ID = user_roles.USER_ID')
  23. ->join('user_org','user.USER_ID = user_org.USER_ID')
  24. ->where_in('user_roles.ROLES_ID',$roles)
  25. ->where('user.DEL_REF',0)
  26. ->where('user.ENABLE',1)
  27. ->where('user_org.ORG_TYPE',0)
  28. ->where('user_org.ORG_ID',$orgid)
  29. ->from('user')
  30. ->count_all_results();
  31. return $count;
  32. }
  33. // 各类人员占比接口
  34. public function user(){
  35. $this->load->model(array('OrgModel','RolesModel'));
  36. $info = $this->OrgModel->show_one(array('ORG_ID'=>$this->orgId,'TYPE'=>'2'));
  37. if(!$info||$info->ENABLE != 1||$info->DEL_REF != 0){
  38. $this->error('项目不存在');
  39. }
  40. // 1=客户人员 2=综合人员 3=运送人员 4=维修人员 5=保洁人员 6=保安人员 7=调度人员 8=监管人员
  41. $arr = array(
  42. array('type' => 5),
  43. array('type' => 3),
  44. array('type' => 4),
  45. array('type' => 6),
  46. );
  47. $allcount = 0;
  48. foreach ($arr as $k=>$v){
  49. $roles = $this->RolesModel->get_roles_type($this->orgId,$v['type']);
  50. $arr[$k]['name'] = $roles['name'];
  51. $arr[$k]['value'] = $this->get_user_count($this->orgId,$roles['roles']);
  52. $allcount += $arr[$k]['value'];
  53. }
  54. $data = array(
  55. array('value'=>$arr[0]['value'],'name'=>'保洁人员','name2'=>'保洁','bl'=>$allcount>0?round($arr[0]['value']*100/$allcount):0),
  56. array('value'=>$arr[1]['value'],'name'=>'运送人员','name2'=>'运送','bl'=>$allcount>0?round($arr[1]['value']*100/$allcount):0),
  57. array('value'=>$arr[2]['value'],'name'=>'维修人员','name2'=>'维修','bl'=>$allcount>0?round($arr[2]['value']*100/$allcount):0),
  58. array('value'=>$arr[3]['value'],'name'=>'保安人员','name2'=>'保安','bl'=>$allcount>0?round($arr[3]['value']*100/$allcount):0),
  59. );
  60. $this->success('成功',['count' => $allcount,'list' => $data]);
  61. }
  62. public function todostis(){
  63. $count1 = Db::name('orders')
  64. ->where('org_id',$this->orgId)
  65. ->where('del',0)
  66. ->where('work_type_mode',3)
  67. ->where('create_yyyymmdd',date('Ymd'))
  68. ->where('order_mode','in',[5,6])
  69. ->count();
  70. $count2 = Db::name('orders')
  71. ->where('org_id',$this->orgId)
  72. ->where('del',0)
  73. ->where('work_type_mode',1)
  74. ->where('create_yyyymmdd',date('Ymd'))
  75. ->where('order_mode','in',[5,6])
  76. ->count();
  77. $count3 = Db::name('daily_record')
  78. ->where('org_id',$this->orgId)
  79. ->where('create_yyyymmdd',date('Ymd'))
  80. ->count();
  81. $arr = [
  82. [
  83. 'name' => '运送任务',
  84. 'count' => $count1
  85. ],
  86. [
  87. 'name' => '维修任务',
  88. 'count' => $count2
  89. ],
  90. [
  91. 'name' => '日常任务',
  92. 'count' => $count3
  93. ]
  94. ];
  95. HelpHander::success($arr,'成功');
  96. }
  97. public function ysuser(){
  98. $lists = model('User')->getYsUser($this->orgId,1);
  99. $nlists = [];
  100. if(count($lists) > 4){
  101. $arr = array_rand($lists,4);
  102. foreach ($arr as $k=>$v){
  103. $nlists[] = $lists[$v];
  104. }
  105. }else{
  106. $nlists = $lists;
  107. }
  108. foreach ($nlists as $k=>$v){
  109. $count = Db::name('todo')
  110. ->alias('a')
  111. ->join('orders b','a.order_id=b.id')
  112. ->where('a.create_yyyymmdd',date('Ymd'))
  113. ->where('a.to_user_id',$v['id'])
  114. ->where('a.todo_mode',3)
  115. ->where('a.del',0)
  116. ->where('a.org_id',$this->orgId)
  117. ->count();
  118. $nlists[$k]['count'] = $count;
  119. // $addr = Db::name('user_convey_addr')
  120. // ->alias('uca')
  121. // ->join('convey_addr ca','ca.id = uca.ADDR_ID')
  122. // ->where('uca.USER_ID',$v['USER_ID'])
  123. // ->order_by('uca.CREATE_TIME DESC')
  124. // ->select('ca.TITLE')
  125. // ->get('user_convey_addr as uca')
  126. // ->row_array();
  127. $addr = [];
  128. $nlists[$k]['addr_title'] = $addr?$addr['TITLE']:'';
  129. }
  130. HelpHander::success($nlists,'成功');
  131. }
  132. // 热点区域
  133. public function hotaddr(){
  134. //SELECT count(a.START) as COUNT,a.START FROM order_convey as a JOIN orders as o ON o.ORDER_ID = a.ORDER_ID GROUP BY a.`START` LIMIT 10
  135. $curDay = date('Ymd');
  136. $oldDay = date('Ymd',time() - 29*24*60*60);
  137. $lists = Db::name('order_convey')
  138. ->alias('oc')
  139. ->join('orders o','o.id = oc.order_id')
  140. ->where('o.org_id',$this->orgId)
  141. ->where('o.create_yyyymmdd',$curDay)
  142. ->where('o.work_type_mode',3)
  143. ->where('o.del',0)
  144. ->where('o.order_mode','in',[5,6])
  145. ->field('COUNT(oc.start) as count,oc.start')
  146. ->group('oc.start')
  147. ->order('count','desc')
  148. ->limit(10)
  149. ->select();
  150. $x = [];
  151. $y1 = [];
  152. $y2 = [];
  153. foreach ($lists as $k=>$v){
  154. $addr = Db::name('address')
  155. ->where('id',$v['start'])
  156. ->find();
  157. $x[] = $addr?$addr['title']:'';
  158. $y1[] = $v['count'];
  159. $count = Db::name('order_convey')
  160. ->alias('oc')
  161. ->join('orders o','o.id = oc.order_id')
  162. ->where('o.org_id',$this->orgId)
  163. ->where('o.work_type_mode',3)
  164. ->where('o.create_yyyymmdd','<=',$curDay)
  165. ->where('o.create_yyyymmdd','>=',$oldDay)
  166. ->where('o.order_mode','in',[5,6])
  167. ->where('oc.start',$v['start'])
  168. ->where('o.del',0)
  169. ->count();
  170. $y2[] = round($count/30,2);
  171. }
  172. $data = [
  173. 'x' => $x,
  174. 'y1' => $y1,
  175. 'y2' => $y2
  176. ];
  177. HelpHander::success($data,'成功');
  178. }
  179. public function yscount(){
  180. $curDay = date('Ymd');
  181. $tcount = Db::name('orders')
  182. ->where('org_id',$this->orgId)
  183. ->where('work_type_mode',3)
  184. ->where('create_yyyymmdd',$curDay)
  185. ->where('order_mode','in',[5,6])
  186. ->where('del',0)
  187. ->count();
  188. $fcount = Db::name('order_convey')
  189. ->alias('oc')
  190. ->join('orders o','o.id = oc.order_id')
  191. ->where('o.org_id',$this->orgId)
  192. ->where('o.work_type_mode',3)
  193. ->where('o.create_yyyymmdd',$curDay)
  194. ->whereRaw("TIMESTAMPDIFF(second,o.finish_time,oc.ywc_time) >=0")
  195. ->where('o.order_mode','in',[5,6])
  196. ->where('o.del',0)
  197. ->count();
  198. $bl1 = $tcount>0?round($fcount/$tcount,3)*100:0;
  199. $wcount = Db::name('orders')
  200. ->where('org_id',$this->orgId)
  201. ->where('del',0)
  202. ->where('work_type_mode',3)
  203. ->where('create_yyyymmdd',$curDay)
  204. ->where('order_mode','in',[1])
  205. ->count();
  206. $jxcount = Db::name('orders')
  207. ->where('org_id',$this->orgId)
  208. ->where('del',0)
  209. ->where('work_type_mode',3)
  210. ->where('create_yyyymmdd',$curDay)
  211. ->where('order_mode','in',[5])
  212. ->count();
  213. $bhcount = Db::name('todo')
  214. ->alias('a')
  215. ->join('todo b','a.order_id=b.id')
  216. ->where('a.org_id',$this->orgId)
  217. ->where('b.del',0)
  218. ->where('a.work_type_mode',3)
  219. ->where('a.create_yyyymmdd',$curDay)
  220. ->where('a.todo_mode','in',[4])
  221. ->count();
  222. $flist = Db::name('orders')
  223. ->field('(TIMESTAMPDIFF(minute,create_time,send_time)) as minute')
  224. ->where('org_id',$this->orgId)
  225. ->where('work_type_mode',3)
  226. ->where('create_yyyymmdd',$curDay)
  227. ->where('del',0)
  228. ->where('order_mode','in',[4,5,6])
  229. ->select();
  230. $flist = $flist?$flist:[];
  231. $c = count($flist);
  232. $minu = 0;
  233. foreach ($flist as $k=>$v){
  234. if($v['minute']){
  235. $minu += $v['minute'];
  236. }
  237. }
  238. $avg = $c > 0?round($minu/$c,1):0;
  239. $data = [
  240. 'count1' => $bl1."%",
  241. 'count2' => $avg,
  242. 'count3' => $wcount,
  243. 'count4' => $jxcount,
  244. 'count5' => $tcount,
  245. 'count6' => $bhcount
  246. ];
  247. HelpHander::success($data,'成功');
  248. }
  249. // 隐患预警数据统计
  250. public function yinhuan(){
  251. $list = [
  252. ['标题', '隐患数量', '转任务量'],
  253. // ['报修', $bxwc, $bxxy],
  254. // ['保洁', $bjwc, $bjxy],
  255. // ['运送', $yswc, $ysxy],
  256. // ['隐患预警', $yhwc, $yhxy],
  257. ];
  258. $dlist = [
  259. date('Y-m-d',strtotime('-6 days')),
  260. date('Y-m-d',strtotime('-5 days')),
  261. date('Y-m-d',strtotime('-4 days')),
  262. date('Y-m-d',strtotime('-3 days')),
  263. date('Y-m-d',strtotime('-2 days')),
  264. date('Y-m-d',strtotime('-1 days')),
  265. date('Y-m-d'),
  266. ];
  267. foreach ($dlist as $v){
  268. $tt = date('Ymd',strtotime($v));
  269. $count = Db::name('orders')
  270. ->where('org_id',$this->orgId)
  271. ->where('create_yyyymmdd',$tt)
  272. ->where('del',0)
  273. ->where('work_type_mode',4)
  274. ->count();
  275. $count1 = Db::name('todo')
  276. ->alias('a')
  277. ->join('orders b','a.order_id=b.id')
  278. ->where('a.org_id',$this->orgId)
  279. ->where('a.create_yyyymmdd',$tt)
  280. ->where('a.del',0)
  281. ->where('a.work_type_mode',4)
  282. ->where('b.del',0)
  283. ->group('a.order_id')
  284. ->count();
  285. $list[] = [date('m-d',strtotime($v)),$count,$count1];
  286. }
  287. $data = [
  288. 'list' => $list
  289. ];
  290. HelpHander::success($data,'成功');
  291. }
  292. // 运送数据统计
  293. public function yusong(){
  294. $list = [
  295. ['标题', '工单总量', '完成工单量'],
  296. ];
  297. $dlist = [
  298. date('Y-m-d',strtotime('-6 days')),
  299. date('Y-m-d',strtotime('-5 days')),
  300. date('Y-m-d',strtotime('-4 days')),
  301. date('Y-m-d',strtotime('-3 days')),
  302. date('Y-m-d',strtotime('-2 days')),
  303. date('Y-m-d',strtotime('-1 days')),
  304. date('Y-m-d'),
  305. ];
  306. foreach ($dlist as $v){
  307. $tt = date('Ymd',strtotime($v));
  308. $count = $this->db
  309. ->where('ORG_ID',$this->orgId)
  310. ->where('CREATE_YYYYMMDD',$tt)
  311. ->where('DEL_REF',0)
  312. ->where('WORK_TYPE_MODE',3)
  313. ->from('orders')
  314. ->count_all_results();
  315. $count1 = $this->db
  316. ->where('ORG_ID',$this->orgId)
  317. ->where('CREATE_YYYYMMDD',$tt)
  318. ->where('DEL_REF',0)
  319. ->where('WORK_TYPE_MODE',3)
  320. ->where_in('CURR_ORDER_MODE',[9,11])
  321. ->from('orders')
  322. ->count_all_results();
  323. $list[] = [date('m-d',strtotime($v)),$count,$count1];
  324. }
  325. $data = [
  326. 'list' => $list
  327. ];
  328. $this->success('成功',$data);
  329. }
  330. // 今日运送完成工单总量
  331. public function yscounttoday(){
  332. $curDay = date('Ymd');
  333. $tcount = $this->db
  334. ->where('ORG_ID',$this->orgId)
  335. ->where('WORK_TYPE_MODE',3)
  336. ->where('CREATE_YYYYMMDD',$curDay)
  337. ->where_in('CURR_ORDER_MODE',[9,11])
  338. ->from('orders')
  339. ->count_all_results();
  340. $data = [
  341. 'count' => $tcount
  342. ];
  343. $this->success('成功',$data);
  344. }
  345. // 医废
  346. public function waste(){
  347. $dlist = [
  348. date('Y-m-d',strtotime('-6 days')),
  349. date('Y-m-d',strtotime('-5 days')),
  350. date('Y-m-d',strtotime('-4 days')),
  351. date('Y-m-d',strtotime('-3 days')),
  352. date('Y-m-d',strtotime('-2 days')),
  353. date('Y-m-d',strtotime('-1 days')),
  354. date('Y-m-d'),
  355. ];
  356. $xdata = [];
  357. $ydata = [];
  358. foreach ($dlist as $v){
  359. $tt = date('Ymd',strtotime($v));
  360. // $count = $this->db
  361. //// ->where('ORG_ID',$this->orgId)
  362. //// ->where('CREATE_YYYYMMDD',$tt)
  363. //// ->where('DEL_REF',0)
  364. //// ->from('waste_record')
  365. //// ->count_all_results();
  366. ///
  367. $ret = Db::name('waste_record')
  368. ->where('org_id',$this->orgId)
  369. ->where('create_yyyymmdd',$tt)
  370. ->where('del',0)
  371. ->select();
  372. $total = 0;
  373. foreach ($ret as $kk=>$vv){
  374. $total += $vv['weight'];
  375. }
  376. $ydata[] = $total/1000;
  377. $xdata[] = date('m-d',strtotime($v));
  378. }
  379. $data = [
  380. 'xdata' => $xdata,
  381. 'ydata' => $ydata
  382. ];
  383. HelpHander::success($data,'成功');
  384. }
  385. public function ystask(){
  386. $size = input('size')?input('size'):20;
  387. $data = model('Orders')->get_cur_day_lists($this->orgId,$size);
  388. foreach ($data as $k=>$v){
  389. $data[$k]['create_time'] = date('H:i',strtotime($v['create_time']));
  390. $data[$k]['send_time'] = $v['send_time']?date('H:i',strtotime($v['send_time'])):'';
  391. $data[$k]['confirm_time'] = $v['confirm_time']?date('H:i',strtotime($v['confirm_time'])):'';
  392. }
  393. HelpHander::success($data,'成功');
  394. }
  395. public function ystask_bak(){
  396. $size = input('size')?input('size'):5;
  397. $data = model('Orders')->get_cur_day_lists($this->orgId,$size);
  398. foreach ($data as $k=>$v){
  399. $data[$k]['xq_time'] = date('H:i',strtotime($v['xq_time']));
  400. $data[$k]['send_time'] = $v['send_time']?date('H:i',strtotime($v['send_time'])):'';
  401. $data[$k]['confirm_time'] = $v['confirm_time']?date('H:i',strtotime($v['confirm_time'])):'';
  402. }
  403. HelpHander::success($data,'成功');
  404. }
  405. public function ystaskcount(){
  406. $this->load->model('OrdersModel');
  407. $data = $this->OrdersModel->get_cur_day_count($this->orgId);
  408. $this->success('成功',['count' => $data]);
  409. }
  410. public function daily(){
  411. $lists = Db::name('daily_record')
  412. ->alias('dr')
  413. ->join('daily d','d.id = dr.daily_id')
  414. ->where('dr.org_id',$this->orgId)
  415. ->where('dr.create_yyyymmdd',date('Ymd'))
  416. ->limit(9)
  417. ->field('d.title,d.content,dr.user_id,dr.create_time')
  418. ->order('dr.id','desc')
  419. ->select();
  420. foreach ($lists as $k=>$v){
  421. $user = Db::name('user')
  422. ->where('id',$v['user_id'])
  423. ->find();
  424. $lists[$k]['real_name'] = $user?$user['real_name']:'';
  425. $lists[$k]['create_time'] = date('m-d H:i',strtotime($v['create_time']));
  426. }
  427. HelpHander::success($lists,'成功');
  428. }
  429. public function patrolList(){
  430. $lists = Db::name('patrol_record')
  431. ->alias('pr')
  432. ->join('address pa','pa.id = pr.patrol_addr_id')
  433. ->join('patrol_task pt','pt.id = pr.patrol_task_id')
  434. ->join('user u','u.id = pr.user_id')
  435. ->where('pr.org_id',$this->orgId)
  436. ->where('pr.create_yyyymmdd',date('Ymd'))
  437. ->limit(4)
  438. ->field('pa.title,pt.title as task_title,u.real_name,pr.create_time')
  439. ->order('pr.id','DESC')
  440. ->select();
  441. foreach ($lists as $k=>$v){
  442. $lists[$k]['create_time'] = date('m-d H:i',strtotime($v['create_time']));
  443. }
  444. HelpHander::success($lists,'成功');
  445. }
  446. public function patrolImg(){
  447. $lists = Db::name('patrol_record')
  448. ->alias('pr')
  449. ->join('patrol_task pt','pt.id = pr.patrol_task_id')
  450. ->where('pr.org_id',$this->orgId)
  451. ->where('pr.images','<>','null')
  452. ->where('pr.create_yyyymmdd',date('Ymd'))
  453. ->limit(9)
  454. ->field('pt.title as task_title,pr.images')
  455. ->order('pr.id','DESC')
  456. ->select();
  457. foreach ($lists as $k=>$v){
  458. $imgs = explode(',',$v['images']);
  459. $lists[$k]['images'] = $imgs[0];
  460. }
  461. HelpHander::success($lists?$lists:[],'成功');
  462. }
  463. // 评论,满意度
  464. public function comment(){
  465. $scores = [
  466. ['score'=>1,'name'=>'一星','value'=>0],
  467. ['score'=>2,'name'=>'二星','value'=>0],
  468. ['score'=>3,'name'=>'三星','value'=>0],
  469. ['score'=>4,'name'=>'四星','value'=>0],
  470. ['score'=>5,'name'=>'五星','value'=>0],
  471. ];
  472. foreach ($scores as $k=>$v){
  473. $count = $this->db
  474. ->where('ORG_ID',$this->orgId)
  475. ->where('SCORE',$v['score'])
  476. ->from('comment')
  477. ->count_all_results();
  478. $scores[$k]['value'] = $count?$count:0;
  479. unset($scores[$k]['score']);
  480. }
  481. $user = $this->db
  482. ->select('sum(SCORE) as SCORE,TO_USER_ID')
  483. ->where('ORG_ID',$this->orgId)
  484. ->group_by('TO_USER_ID')
  485. ->distinct()
  486. ->get('comment_reply')
  487. ->result_array();
  488. foreach ($user as $k=>$v){
  489. $count = $this->db
  490. ->where('ORG_ID',$this->orgId)
  491. ->where('TO_USER_ID',$v['TO_USER_ID'])
  492. ->from('comment_reply')
  493. ->count_all_results();
  494. $score = round($v['SCORE']/$count,1);
  495. $user[$k]['SCORE'] = $score;
  496. $info = $this->db
  497. ->join('user_org uo','uo.USER_ID = u.USER_ID')
  498. ->join('org o','uo.ORG_ID = o.ORG_ID')
  499. ->where('uo.ORG_TYPE',1)
  500. ->where('u.USER_ID',$v['TO_USER_ID'])
  501. ->select('u.REAL_NAME,o.NAME as DEP_NAME')
  502. ->get('user u')
  503. ->row_array();
  504. $user[$k]['REAL_NAME'] = $info['REAL_NAME'];
  505. $user[$k]['DEP_NAME'] = $info['DEP_NAME'];
  506. }
  507. // 获取排名前5的人
  508. $user = list_sort_by($user,'SCORE', 'desc');
  509. $lists = [];
  510. foreach ($user as $k=>$v){
  511. if($k >= 5){
  512. continue;
  513. }
  514. $lists[] = $v;
  515. }
  516. $this->success('成功',['count'=>$scores,'list' => $lists]);
  517. }
  518. // 工单统计
  519. public function todo(){
  520. $start = date('Y-m-d').' 00:00:00';
  521. $end = date('Y-m-d').' 23:59:59';
  522. $fininsh = $this->db
  523. ->where('ORG_ID',$this->orgId)
  524. ->where('DEL_REF',0)
  525. ->where('TODO_MODE',3)
  526. ->where('DONE_TIME >=',$start)
  527. ->where('DONE_TIME <=',$end)
  528. ->from('todo')
  529. ->count_all_results();
  530. $unfininsh = $this->db
  531. ->where('ORG_ID',$this->orgId)
  532. ->where('DEL_REF',0)
  533. ->where_in('TODO_MODE',[1,2])
  534. ->where('DONE_TIME >=',$start)
  535. ->where('DONE_TIME <=',$end)
  536. ->from('todo')
  537. ->count_all_results();
  538. $undeal = $this->db
  539. ->where('ORG_ID',$this->orgId)
  540. ->where('DEL_REF',0)
  541. ->where_in('CURR_ORDER_MODE',1)
  542. ->where('CREATTE_TIME >=',$start)
  543. ->where('CREATTE_TIME <=',$end)
  544. ->from('orders')
  545. ->count_all_results();
  546. $total = $this->db
  547. ->where('ORG_ID',$this->orgId)
  548. ->where('DEL_REF',0)
  549. ->where_in('TODO_MODE',[1,2,3,4,5])
  550. ->from('todo')
  551. ->count_all_results();
  552. $today = $this->db
  553. ->where('ORG_ID',$this->orgId)
  554. ->where('DEL_REF',0)
  555. ->where_in('TODO_MODE',[1,2,3,4,5])
  556. ->where('CREATE_TIME >=',$start)
  557. ->where('CREATE_TIME <=',$end)
  558. ->from('todo')
  559. ->count_all_results();
  560. $commentcount = $this->db
  561. ->where('ORG_ID',$this->orgId)
  562. ->from('comment')
  563. ->count_all_results();
  564. $comment = $this->db
  565. ->where('ORG_ID',$this->orgId)
  566. ->select_sum('SCORE')
  567. ->get('comment')
  568. ->row_array();
  569. $data = [
  570. 'total' => $total,
  571. 'today' => $today,
  572. 'finish' => $fininsh,
  573. 'unfinish' => $unfininsh,
  574. 'undeal' => $undeal,
  575. 'comment' => $commentcount&&$comment?round($comment['SCORE']/$commentcount,1):0
  576. ];
  577. $this->success('成功',$data);
  578. }
  579. // 获取今日最新5条中的随机一条
  580. public function patrol(){
  581. $lists = $this->db
  582. ->select('u.REAL_NAME,pa.TITLE,pr.IMAGES,pt.TITLE as CONTENT,pr.CREATE_TIME')
  583. ->join('user u','u.USER_ID = pr.USER_ID')
  584. ->join('patrol_addr pa','pa.PATROL_ADDR_ID = pr.PATROL_ADDR_ID')
  585. ->join('patrol_task pt','pt.PATROL_TASK_ID = pr.PATROL_TASK_ID')
  586. ->where('pr.ORG_ID',$this->orgId)
  587. ->where('pr.CREATE_YYYYMMDD',date('Ymd'))
  588. ->limit(5)
  589. ->order_by('pr.PATROL_RECORD_ID DESC')
  590. ->get('patrol_record pr')
  591. ->result_array();
  592. $info = null;
  593. if($lists){
  594. $info = $lists[array_rand($lists,1)];
  595. }
  596. if($info){
  597. $imgs = $info['IMAGES']?explode(',',$info['IMAGES']):[];
  598. $info['IMAGES'] = $imgs?$imgs[0]:'';
  599. $info['CREATE_TIME'] = date('Y-m-d',strtotime($info['CREATE_TIME']));
  600. $this->success('成功',$info);
  601. }else{
  602. $this->error('失败');
  603. }
  604. }
  605. // 工单指数数据统计
  606. public function todotime(){
  607. $bxcount = $this->db
  608. ->where('ORG_ID',$this->orgId)
  609. ->where('DEL_REF',0)
  610. ->where('TODO_MODE',3)
  611. ->where('WORK_TYPE_MODE',1)
  612. ->from('todo')
  613. ->count_all_results();
  614. $bjcount = $this->db
  615. ->where('ORG_ID',$this->orgId)
  616. ->where('DEL_REF',0)
  617. ->where('TODO_MODE',3)
  618. ->where('WORK_TYPE_MODE',2)
  619. ->from('todo')
  620. ->count_all_results();
  621. $yscount = $this->db
  622. ->where('ORG_ID',$this->orgId)
  623. ->where('DEL_REF',0)
  624. ->where('TODO_MODE',3)
  625. ->where('WORK_TYPE_MODE',3)
  626. ->from('todo')
  627. ->count_all_results();
  628. $yhcount = $this->db
  629. ->where('ORG_ID',$this->orgId)
  630. ->where('DEL_REF',0)
  631. ->where('TODO_MODE',3)
  632. ->where('WORK_TYPE_MODE',4)
  633. ->from('todo')
  634. ->count_all_results();
  635. $bxinfo = $this->db
  636. ->select_sum('XY_TIME')
  637. ->select_sum('WC_TIME')
  638. ->where('ORG_ID',$this->orgId)
  639. ->where('DEL_REF',0)
  640. ->where('TODO_MODE',3)
  641. ->where('WORK_TYPE_MODE',1)
  642. ->get('todo')
  643. ->row_array();
  644. $bxinfo = $bxinfo?$bxinfo:['XY_TIME'=>0,'WC_TIME'=>0];
  645. $bjinfo = $this->db
  646. ->select_sum('XY_TIME')
  647. ->select_sum('WC_TIME')
  648. ->where('ORG_ID',$this->orgId)
  649. ->where('DEL_REF',0)
  650. ->where('TODO_MODE',3)
  651. ->where('WORK_TYPE_MODE',2)
  652. ->get('todo')
  653. ->row_array();
  654. $bjinfo = $bjinfo?$bjinfo:['XY_TIME'=>0,'WC_TIME'=>0];
  655. $ysinfo = $this->db
  656. ->select_sum('XY_TIME')
  657. ->select_sum('WC_TIME')
  658. ->where('ORG_ID',$this->orgId)
  659. ->where('DEL_REF',0)
  660. ->where('TODO_MODE',3)
  661. ->where('WORK_TYPE_MODE',3)
  662. ->get('todo')
  663. ->row_array();
  664. $ysinfo = $ysinfo?$ysinfo:['XY_TIME'=>0,'WC_TIME'=>0];
  665. $yhinfo = $this->db
  666. ->select_sum('XY_TIME')
  667. ->select_sum('WC_TIME')
  668. ->where('ORG_ID',$this->orgId)
  669. ->where('DEL_REF',0)
  670. ->where('TODO_MODE',3)
  671. ->where('WORK_TYPE_MODE',4)
  672. ->get('todo')
  673. ->row_array();
  674. $yhinfo = $yhinfo?$yhinfo:['XY_TIME'=>0,'WC_TIME'=>0];
  675. $bxwc = $bxcount?round($bxinfo['WC_TIME']/$bxcount/60,1):0;
  676. $bxxy = $bxcount?round($bxinfo['XY_TIME']/$bxcount/60,1):0;
  677. $bjwc = $bjcount?round($bjinfo['WC_TIME']/$bjcount/60,1):0;
  678. $bjxy = $bjcount?round($bjinfo['XY_TIME']/$bjcount/60,1):0;
  679. $yswc = $yscount?round($ysinfo['WC_TIME']/$yscount/60,1):0;
  680. $ysxy = $yscount?round($ysinfo['XY_TIME']/$yscount/60,1):0;
  681. $yhwc = $yhcount?round($yhinfo['WC_TIME']/$yhcount/60,1):0;
  682. $yhxy = $yhcount?round($yhinfo['XY_TIME']/$yhcount/60,1):0;
  683. $list = [
  684. ['标题', '平均完成时', '响应时长'],
  685. ['报修', $bxwc, $bxxy],
  686. ['保洁', $bjwc, $bjxy],
  687. ['运送', $yswc, $ysxy],
  688. ['隐患预警', $yhwc, $yhxy],
  689. ];
  690. $data = [
  691. 'bx' => $bxcount,
  692. 'bj' => $bjcount,
  693. 'ys' => $yscount,
  694. 'yh' => $yhcount,
  695. 'list' => $list
  696. ];
  697. $this->success('成功',$data);
  698. }
  699. // 设备维检
  700. public function device(){
  701. $dcount = $this->db
  702. ->where('ORG_ID',$this->orgId)
  703. ->where('DEL_REF',0)
  704. ->where('ENABLE',1)
  705. ->from('device')
  706. ->count_all_results();
  707. $rcount = $this->db
  708. ->where('ORG_ID',$this->orgId)
  709. ->from('device_record')
  710. ->count_all_results();
  711. $cur = date('Y-m');
  712. $curTime = strtotime($cur.'-01');
  713. $month = [];
  714. for ($i=5;$i>0;$i--){
  715. $date = strtotime("-".$i." month",$curTime);
  716. $month[] = date('Y-m',$date);
  717. }
  718. $month[] = $cur;
  719. $list = [];
  720. foreach ($month as $k=>$v){
  721. $list[] = $this->db
  722. ->where('ORG_ID',$this->orgId)
  723. ->where('CREATE_YYYYMM',str_ireplace('-','',$v))
  724. ->from('device_record')
  725. ->count_all_results();
  726. }
  727. $data = [
  728. 'dcount' => $dcount,
  729. 'rcount' => $rcount,
  730. 'list' => $list,
  731. 'month' => $month
  732. ];
  733. $this->success('成功',$data);
  734. }
  735. // 24小时内记录
  736. public function patrolRecord(){
  737. $day = date('Ymd');
  738. $time = strtotime(date('Y-m-d'));
  739. $hours = [];
  740. $plist1 = $plist2 = $plist3 = $plist4 = [];
  741. for ($i=0;$i<24;$i++){
  742. $hours[] = $i;
  743. $stime = date('Y-m-d H:i:s',$time + $i*60*60);
  744. $etime = date('Y-m-d H:i:s',$time + ($i+1)*60*60);
  745. $plist1[] = $this->db
  746. ->where('ORG_ID',$this->orgId)
  747. ->where('PATROL_MODE',1)
  748. ->where('CREATE_TIME >=',$stime)
  749. ->where('CREATE_TIME <',$etime)
  750. ->where('CREATE_YYYYMMDD',$day)
  751. ->from('patrol_record')
  752. ->count_all_results();
  753. $plist2[] = $this->db
  754. ->where('ORG_ID',$this->orgId)
  755. ->where('PATROL_MODE',2)
  756. ->where('CREATE_TIME >=',$stime)
  757. ->where('CREATE_TIME <',$etime)
  758. ->where('CREATE_YYYYMMDD',$day)
  759. ->from('patrol_record')
  760. ->count_all_results();
  761. $plist3[] = $this->db
  762. ->where('ORG_ID',$this->orgId)
  763. ->where('PATROL_MODE',3)
  764. ->where('CREATE_TIME >=',$stime)
  765. ->where('CREATE_TIME <',$etime)
  766. ->where('CREATE_YYYYMMDD',$day)
  767. ->from('patrol_record')
  768. ->count_all_results();
  769. $plist4[] = $this->db
  770. ->where('ORG_ID',$this->orgId)
  771. ->where('PATROL_MODE',4)
  772. ->where('CREATE_TIME >=',$stime)
  773. ->where('CREATE_TIME <',$etime)
  774. ->where('CREATE_YYYYMMDD',$day)
  775. ->from('patrol_record')
  776. ->count_all_results();
  777. }
  778. $data = [
  779. 'hour' => $hours,
  780. 'plist1' => $plist1,
  781. 'plist2' => $plist2,
  782. 'plist3' => $plist3,
  783. 'plist4' => $plist4
  784. ];
  785. $this->success('成功',$data);
  786. }
  787. // 报修工单
  788. public function repair(){
  789. $dlist = [
  790. date('Y-m-d',strtotime('-6 days')),
  791. date('Y-m-d',strtotime('-5 days')),
  792. date('Y-m-d',strtotime('-4 days')),
  793. date('Y-m-d',strtotime('-3 days')),
  794. date('Y-m-d',strtotime('-2 days')),
  795. date('Y-m-d',strtotime('-1 days')),
  796. date('Y-m-d'),
  797. ];
  798. $names = [];
  799. $counts = [];
  800. foreach ($dlist as $v){
  801. $names[] = date('m-d',strtotime($v));
  802. $tt = date('Ymd',strtotime($v));
  803. $count = Db::name('todo')
  804. ->alias('a')
  805. ->join('orders b','a.order_id=b.id')
  806. ->where('a.del',0)
  807. ->where('a.org_id',$this->orgId)
  808. ->where('a.todo_mode',3)
  809. ->where('a.work_type_mode',1)
  810. ->where('a.create_yyyymmdd',$tt)
  811. ->group('a.order_id')
  812. ->count();
  813. $counts[] = $count;
  814. }
  815. HelpHander::success(['names'=>$names,'counts' => $counts],'成功');
  816. }
  817. public function ystypeuser(){
  818. $this->load->model('UserModel');
  819. $lists = $this->UserModel->getYsUser($this->orgId,1);
  820. $lists = $lists?$lists:[];
  821. $curday = date('Ymd');
  822. $users = $this->db
  823. ->where('ORG_ID',$this->orgId)
  824. ->where_in('TODO_MODE',[1,2])
  825. ->where('DEL_REF',0)
  826. ->where('CREATE_YYYYMMDD',$curday)
  827. ->select('TO_USER_ID')
  828. ->group_by('TO_USER_ID')
  829. ->get('todo')
  830. ->result_array();
  831. $users = $users?$users:[];
  832. $userIds = [];
  833. foreach ($users as $k=>$v){
  834. $userIds[] = $v['TO_USER_ID'];
  835. }
  836. $data = [
  837. 'list1' => [],
  838. 'list2' => []
  839. ];
  840. $nlists = [];
  841. foreach ($lists as $k=>$v){
  842. if(!in_array($v['USER_ID'],$userIds)){
  843. $nlists[] = $v;
  844. }
  845. }
  846. $slist = [];
  847. if(count($nlists) > 10){
  848. $keys = array_rand($nlists,10);
  849. foreach ($nlists as $k=>$v){
  850. if(in_array($k,$keys)){
  851. $slist[] = $v;
  852. }
  853. }
  854. }else{
  855. $slist = $nlists;
  856. }
  857. foreach ($slist as $k=>$v){
  858. $count = $this->db
  859. ->where('ORG_ID',$this->orgId)
  860. ->where('TO_USER_ID',$v['USER_ID'])
  861. ->where_in('TODO_MODE',[1,2,3])
  862. ->where('DEL_REF',0)
  863. ->where('CREATE_YYYYMMDD',$curday)
  864. ->from('todo')
  865. ->count_all_results();
  866. $slist[$k]['COUNT'] = $count;
  867. $addr = $this->db
  868. ->join('convey_addr ca','ca.CONVEY_ADDR_ID = cpr.ADDR_ID')
  869. ->select('ca.TITLE,cpr.CREATE_TIME')
  870. ->where('USER_ID',$v['USER_ID'])
  871. ->order_by('cpr.ID desc')
  872. ->get('convey_plan_record cpr')
  873. ->row_array();
  874. $slist[$k]['TITLE'] = $addr?$addr['TITLE']:'';;
  875. }
  876. $nlists2 = [];
  877. foreach ($lists as $k=>$v){
  878. if(in_array($v['USER_ID'],$userIds)){
  879. $nlists2[] = $v;
  880. }
  881. }
  882. $slist2 = [];
  883. if(count($nlists2) > 9){
  884. $keys2 = array_rand($nlists2,9);
  885. foreach ($nlists2 as $k=>$v){
  886. if(in_array($k,$keys2)){
  887. $slist2[] = $v;
  888. }
  889. }
  890. }else{
  891. $slist2 = $nlists2;
  892. }
  893. foreach ($slist2 as $k=>$v){
  894. $count = $this->db
  895. ->where('ORG_ID',$this->orgId)
  896. ->where('TO_USER_ID',$v['USER_ID'])
  897. ->where_in('TODO_MODE',[1,2,3])
  898. ->where('DEL_REF',0)
  899. ->where('CREATE_YYYYMMDD',$curday)
  900. ->from('todo')
  901. ->count_all_results();
  902. $slist2[$k]['COUNT'] = $count;
  903. $addr = $this->db
  904. ->join('convey_addr ca','ca.CONVEY_ADDR_ID = cpr.ADDR_ID')
  905. ->select('ca.TITLE,cpr.CREATE_TIME')
  906. ->where('USER_ID',$v['USER_ID'])
  907. ->order_by('cpr.ID desc')
  908. ->get('convey_plan_record cpr')
  909. ->row_array();
  910. $slist2[$k]['TITLE'] = $addr?$addr['TITLE']:'';
  911. }
  912. $data['list1'] = $slist; // 待命人员
  913. $data['list2'] = $slist2; // 行动人员
  914. $this->success('成功',$data);
  915. }
  916. }