Onelevel.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776
  1. <?php
  2. namespace app\api\controller\screen;
  3. use app\hander\HelpHander;
  4. use think\Controller;
  5. use think\Db;
  6. use think\helper\Str;
  7. use think\Request;
  8. class Onelevel extends Controller{
  9. private $orgs = []; // 用户拥有的组织id集合,只区分大区管理员和总公司
  10. private $orgName = ''; //大区名称
  11. protected function initialize()
  12. {
  13. parent::initialize();
  14. // $token = input('token','','trim');
  15. // $token = think_decrypt($token);
  16. // if(!$token){
  17. // HelpHander::success("无权限");
  18. // }
  19. // $ts = explode('|',$token);
  20. // if($ts[1] != config('app.ucode')){
  21. // HelpHander::success("无权限");
  22. // }
  23. $map[] = ['type','=',2];
  24. $map[] = ['del','=',0];
  25. $map[] = ['enable','=',1];
  26. $orgids = Db::name('org')
  27. ->where($map)
  28. ->column('id');
  29. $this->orgs = $orgids?$orgids:[-1];
  30. }
  31. public function todayTodoInfo(){
  32. $date = date('Ymd');
  33. $map[] = ['create_yyyymmdd','=',$date];
  34. $map[] = ['del','=',0];
  35. $count = Db::name('todo')->where($map)->where('org_id','in',$this->orgs)->count();
  36. $map[] = ['todo_mode','=',3];
  37. $overCount = Db::name('todo')->where($map)->where('org_id','in',$this->orgs)->count();
  38. $list = [0,0,0,0,0,0];
  39. $overBl = 0;
  40. if($count > 0){
  41. $overBl = round($overCount/$count*100,0);
  42. $len = strlen($count);
  43. if($len == 1){
  44. $count = '00000'.$count;
  45. }elseif($len == 2){
  46. $count = '0000'.$count;
  47. }elseif($len == 3){
  48. $count = '000'.$count;
  49. }elseif($len == 4){
  50. $count = '00'.$count;
  51. }elseif($len == 5){
  52. $count = '0'.$count;
  53. }else{
  54. $count = '999999';
  55. }
  56. $list = str_split($count);
  57. }
  58. $data = [
  59. 'list'=>$list,
  60. 'bl'=>$overBl
  61. ];
  62. HelpHander::success($data);
  63. }
  64. public function todayTodoType(){
  65. $date = date('Ymd');
  66. $map[] = ['create_yyyymmdd','=',$date];
  67. $map[] = ['del','=',0];
  68. $map[] = ['create_yyyymmdd','=',$date];
  69. $map[] = ['del','=',0];
  70. $count = Db::name('todo')->where($map)->where('work_type_mode',1)->where('org_id','in',$this->orgs)->count();
  71. $count2 = Db::name('todo')->where($map)->where('work_type_mode',2)->where('org_id','in',$this->orgs)->count();
  72. $count3 = Db::name('todo')->where($map)->where('work_type_mode',3)->where('org_id','in',$this->orgs)->count();
  73. $count4 = Db::name('todo')->where($map)->where('work_type_mode',4)->where('org_id','in',$this->orgs)->count();
  74. $map[] = ['todo_mode','=',3];
  75. //保修
  76. $bxCount = Db::name('todo')->where($map)->where('work_type_mode',1)->where('org_id','in',$this->orgs)->count();
  77. //保洁
  78. $bjCount = Db::name('todo')->where($map)->where('work_type_mode',2)->where('org_id','in',$this->orgs)->count();
  79. //运送
  80. $ysCount = Db::name('todo')->where($map)->where('work_type_mode',3)->where('org_id','in',$this->orgs)->count();
  81. //隐患
  82. $yhCount = Db::name('todo')->where($map)->where('work_type_mode',4)->where('org_id','in',$this->orgs)->count();
  83. $bxBl = $bjBl = $ysBl = $yhBl =0;
  84. if($count > 0){
  85. $bxBl = round($bxCount/$count*100,0);
  86. }
  87. if($count2 >0){
  88. $bjBl = round($bjCount/$count2*100,0);
  89. }
  90. if($count3 >0){
  91. $ysBl = round($ysCount/$count3*100,0);
  92. }
  93. if($count4 >0){
  94. $yhBl = round($yhCount/$count4*100,0);
  95. }
  96. $data = [
  97. 'bx'=>['count'=>$bxCount,'bl'=>$bxBl],
  98. 'bj'=>['count'=>$bjCount,'bl'=>$bjBl],
  99. 'ys'=>['count'=>$ysCount,'bl'=>$ysBl],
  100. 'yh'=>['count'=>$yhCount,'bl'=>$yhBl],
  101. ];
  102. HelpHander::success($data);
  103. }
  104. public function moduleList(){
  105. $map[] = ['del','=',0];
  106. $map[] = ['enable','=',1];
  107. $map[] = ['type','=',2];
  108. $orgList = Db::name('org')
  109. ->field('id,name')
  110. ->where('id','in',$this->orgs)
  111. ->where($map)
  112. ->select();
  113. $bxCount = $bjCount = $ysCount = $yhCount = $pzCount = $xgCount = $phCount = 0;
  114. foreach ($orgList as $k=>$v){
  115. $bx = Db::name('todo')->where('org_id',$v['id'])->where('del',0)->where('work_type_mode',1)->find();
  116. if($bx){
  117. $bxCount += 1;
  118. }
  119. $bj = Db::name('todo')->where('org_id',$v['id'])->where('del',0)->where('work_type_mode',2)->find();
  120. if($bj){
  121. $bjCount += 1;
  122. }
  123. $ys = Db::name('todo')->where('org_id',$v['id'])->where('del',0)->where('work_type_mode',3)->find();
  124. if($ys){
  125. $ysCount += 1;
  126. }
  127. $yh = Db::name('todo')->where('org_id',$v['id'])->where('del',0)->where('work_type_mode',4)->find();
  128. if($yh){
  129. $yhCount += 1;
  130. }
  131. $pz = Db::name('todo')->where('org_id',$v['id'])->where('del',0)->where('work_type_mode',15)->find();
  132. if($pz){
  133. $pzCount += 1;
  134. }
  135. $xg = Db::name('patrol_record')->where('org_id',$v['id'])->where('patrol_mode',1)->count();
  136. if($xg){
  137. $xgCount += 1;
  138. }
  139. $ph = Db::name('ph_todo')->where('org_id',$v['id'])->count();
  140. if($ph){
  141. $phCount += 1;
  142. }
  143. }
  144. $data = [
  145. ['name'=>'保修','value'=>$bxCount],
  146. ['name'=>'保洁','value'=>$bjCount],
  147. ['name'=>'运送','value'=>$ysCount],
  148. ['name'=>'隐患预警','value'=>$yhCount],
  149. ['name'=>'品质整改','value'=>$pzCount],
  150. ['name'=>'巡更','value'=>$xgCount],
  151. ['name'=>'陪护','value'=>$phCount],
  152. ];
  153. HelpHander::success($data);
  154. }
  155. public function commentComplainList(){
  156. $date = [
  157. date('Y',strtotime('-5 years')),
  158. date('Y',strtotime('-4 years')),
  159. date('Y',strtotime('-3 years')),
  160. date('Y',strtotime('-2 years')),
  161. date('Y',strtotime('-1 years')),
  162. date('Y'),
  163. ];
  164. $list = $list2 = [];
  165. foreach ($date as $k=>$v){
  166. $list[] = Db::name('comment')->where('org_id','in',$this->orgs)->where('create_yyyy',$v)->sum('score');
  167. $list2[] = Db::name('complain')->where('org_id','in',$this->orgs)->where('create_yyyy',$v)->where('del',0)->count();
  168. }
  169. $data = [
  170. 'title'=>$date,
  171. 'list1'=>$list,
  172. 'list2'=>$list2,
  173. ];
  174. HelpHander::success($data);
  175. }
  176. public function projectCount(){
  177. $count = Db::name('org')->where('parent_id',1)->where('del',0)->where('enable',1)->where('type',1)->count();
  178. $count1 = Db::name('org')->where('del',0)->where('enable',1)->where('type',2)->count();
  179. $count2 = Db::name('user')
  180. ->alias('u')
  181. ->join('user_org uo','uo.user_id=u.id')
  182. ->join('org o','o.id=uo.org_id')
  183. ->where('u.del',0)
  184. ->where('u.type',0)
  185. ->where('o.enable',1)
  186. ->where('o.del',0)
  187. ->count();
  188. $orderCount = Db::name('orders')
  189. ->where('del',0)
  190. ->count();
  191. $todoCount = Db::name('todo')
  192. ->where('del',0)
  193. ->count();
  194. $task1 = Db::name('patrol_task')
  195. ->where('del',0)
  196. ->count();
  197. $task2 = Db::name('device_task')
  198. ->where('del',0)
  199. ->count();
  200. $taskCount = $task1 + $task2;
  201. $commentScore = Db::name('comment')->whereIn('org_id',$this->orgs)->sum('score');
  202. $data = [
  203. 'count1'=>$count,
  204. 'count2'=>$count1,
  205. 'count3'=>$count2,
  206. 'count4'=>$orderCount,
  207. 'count5'=>$todoCount,
  208. 'count6'=>$taskCount,
  209. 'count7'=>$commentScore
  210. ];
  211. HelpHander::success($data);
  212. }
  213. public function quarterScore(){
  214. $org = Db::name('org')
  215. ->field('id,name')
  216. ->where('parent_id',1)
  217. ->where('del',0)
  218. ->where('enable',1)
  219. ->where('type',1)
  220. ->select();
  221. foreach ($org as $k=>$v){
  222. $org[$k]['orgs'] = $this->getAllNextId($v['id']);
  223. }
  224. //获取当前季度
  225. $season = ceil((date('n'))/3);
  226. //当前季度开始时间戳
  227. $startTime = date('Y-m-d H:i:s', mktime(0,0,0,$season*3-3+1,1,date('Y')));
  228. //获取当前季度结束时间戳
  229. $overTime = date('Y-m-d H:i:s', mktime(23,59,59,$season*3,date('t',mktime(0,0,0,$season*3,1,date("Y"))),date('Y')));
  230. $where[] = ['create_yyyymm','>=',date('Ym',strtotime($startTime))];
  231. $where[] = ['create_yyyymm','<=',date('Ym',strtotime($overTime))];
  232. $where2[] = ['CREATE_YYYYMM','>=',date('Ym',strtotime($startTime))];
  233. $where2[] = ['CREATE_YYYYMM','<=',date('Ym',strtotime($overTime))];
  234. foreach ($org as $k=>$v){
  235. $org[$k]['score'] = Db::name('comment')->whereIn('org_id',$v['orgs'])->where($where)->sum('score');
  236. }
  237. $list = list_sort_by($org,'score','desc');
  238. $top1 = isset($list[0])?$list[0]:null;
  239. $top2 = isset($list[1])?$list[1]:null;
  240. $top3 = isset($list[2])?$list[2]:null;
  241. $top4 = isset($list[3])?$list[3]:null;
  242. $top5 = isset($list[4])?$list[4]:null;
  243. HelpHander::success(['top1'=>$top1,'top2'=>$top2,'top3'=>$top3,'top4'=>$top4,'top5'=>$top5]);
  244. }
  245. public function quarterScore2(){
  246. $map[] = ['del','=',0];
  247. $map[] = ['enable','=',1];
  248. $map[] = ['type','=',2];
  249. $org = Db::name('org')
  250. ->field('id,name')
  251. ->where('parent_id',1)
  252. ->where('del',0)
  253. ->where('enable',1)
  254. ->where('type',1)
  255. ->select();
  256. foreach ($org as $k=>$v){
  257. $org[$k]['orgs'] = $this->getAllNextId($v['id']);
  258. }
  259. //获取当前季度
  260. $season = ceil((date('n'))/3);
  261. //当前季度开始时间戳
  262. $startTime = date('Y-m-d H:i:s', mktime(0,0,0,$season*3-3+1,1,date('Y')));
  263. //获取当前季度结束时间戳
  264. $overTime = date('Y-m-d H:i:s', mktime(23,59,59,$season*3,date('t',mktime(0,0,0,$season*3,1,date("Y"))),date('Y')));
  265. $where[] = ['create_yyyymm','>=',date('Ym',strtotime($startTime))];
  266. $where[] = ['create_yyyymm','<=',date('Ym',strtotime($overTime))];
  267. foreach ($org as $k=>$v){
  268. if(in_array(3,$v['orgs']) ){
  269. $org[$k]['price'] = 5.3;
  270. }else{
  271. $org[$k]['price'] = 0;
  272. }
  273. }
  274. $list = list_sort_by($org,'score','desc');
  275. $top1 = isset($list[0])?$list[0]:null;
  276. $top2 = isset($list[1])?$list[1]:null;
  277. $top3 = isset($list[2])?$list[2]:null;
  278. $top4 = isset($list[3])?$list[3]:null;
  279. $top5 = isset($list[4])?$list[4]:null;
  280. HelpHander::success(['top1'=>$top1,'top2'=>$top2,'top3'=>$top3,'top4'=>$top4,'top5'=>$top5]);
  281. }
  282. public function fcompanyList(){
  283. $map[] = ['del','=',0];
  284. $map[] = ['enable','=',1];
  285. $map[] = ['type','=',2];
  286. $org = Db::name('org')
  287. ->field('id,name')
  288. ->where('parent_id',1)
  289. ->where('del',0)
  290. ->where('enable',1)
  291. ->where('type',1)
  292. ->select();
  293. foreach ($org as $k=>$v){
  294. $org[$k]['orgs'] = $this->getAllNextId($v['id']);
  295. }
  296. $host = request()->domain(true);
  297. foreach ($org as $k=>$v){
  298. if(in_array(3,$v['orgs'])){
  299. $org[$k]['day'] = 256;
  300. $org[$k]['nums'] = 1;
  301. $org[$k]['nums2'] = 1;
  302. $org[$k]['bl'] = 100;
  303. $org[$k]['imgs'] = [
  304. $host.'/screen/images/nh1.png',
  305. $host.'/screen/images/nh2.png',
  306. $host.'/screen/images/nh3.png',
  307. ];
  308. }else{
  309. $org[$k]['day'] = 0;
  310. $org[$k]['nums'] = 0;
  311. $org[$k]['nums2'] = 0;
  312. $org[$k]['bl'] = 0;
  313. $org[$k]['imgs'] = [];
  314. }
  315. }
  316. HelpHander::success($org);
  317. }
  318. public function nlxhList(){
  319. $org = Db::name('org')
  320. ->field('id,name')
  321. ->where('parent_id',1)
  322. ->where('del',0)
  323. ->where('enable',1)
  324. ->where('type',1)
  325. ->select();
  326. foreach ($org as $k=>$v){
  327. $org[$k]['orgs'] = $this->getAllNextId($v['id']);
  328. if(isset($k) && $k==0){
  329. $org[$k]['value'] = 556;
  330. }else if(isset($k) && $k==1){
  331. $org[$k]['value'] = 875;
  332. }else if(isset($k) && $k==2){
  333. $org[$k]['value'] = 345;
  334. }else if(isset($k) && $k==3){
  335. $org[$k]['value'] = 234;
  336. }else if(isset($k) && $k==4){
  337. $org[$k]['value'] = 797;
  338. }else if(isset($k) && $k==5) {
  339. $org[$k]['value'] = 887;
  340. }
  341. }
  342. //获取当前季度
  343. $season = ceil((date('n'))/3);
  344. //当前季度开始时间戳
  345. $startTime = date('Y-m-d H:i:s', mktime(0,0,0,$season*3-3+1,1,date('Y')));
  346. //获取当前季度结束时间戳
  347. $overTime = date('Y-m-d H:i:s', mktime(23,59,59,$season*3,date('t',mktime(0,0,0,$season*3,1,date("Y"))),date('Y')));
  348. $list = array_slice(list_sort_by($org,'value','desc'),0,5);
  349. HelpHander::success($list);
  350. }
  351. //巡查图片
  352. public function patrolImg(){
  353. $data = Db::name('patrol_record')
  354. ->where('images','<>','')
  355. ->whereIn('org_id',$this->orgs)
  356. ->limit(20)
  357. ->order('id desc')
  358. ->select();
  359. foreach ($data as $k=>$v){
  360. $img = explode(',',$v['images']);
  361. if($img){
  362. $data[$k]['images'] = $img[0];
  363. }
  364. }
  365. if(count($data)>2){
  366. $key = array_rand($data,3);
  367. $list[] = $data[$key[0]];
  368. $list[] = $data[$key[1]];
  369. $list[] = $data[$key[2]];
  370. }
  371. $eList = isset($list)?$list:$data;
  372. HelpHander::success($eList);
  373. }
  374. public function patrolRecordList(){
  375. $dlist = [
  376. date('Y-m-d',strtotime('-6 days')),
  377. date('Y-m-d',strtotime('-5 days')),
  378. date('Y-m-d',strtotime('-4 days')),
  379. date('Y-m-d',strtotime('-3 days')),
  380. date('Y-m-d',strtotime('-2 days')),
  381. date('Y-m-d',strtotime('-1 days')),
  382. date('Y-m-d'),
  383. ];
  384. $date = [];
  385. $yCount = [];
  386. $y2Count = [];
  387. $y3Count = [];
  388. $y4Count = [];
  389. foreach ($dlist as $k=>$v){
  390. $tt = date('Ymd',strtotime($v));
  391. $count = Db::name('patrol_record')
  392. ->whereIn('org_id',$this->orgs)
  393. ->where('create_yyyymmdd',$tt)
  394. ->where('patrol_mode',1)
  395. ->count();
  396. $count2 = Db::name('patrol_record')
  397. ->whereIn('org_id',$this->orgs)
  398. ->where('create_yyyymmdd',$tt)
  399. ->where('patrol_mode',2)
  400. ->count();
  401. $count3 = Db::name('patrol_record')
  402. ->whereIn('org_id',$this->orgs)
  403. ->where('create_yyyymmdd',$tt)
  404. ->where('patrol_mode',3)
  405. ->count();
  406. $count4 = Db::name('patrol_record')
  407. ->whereIn('org_id',$this->orgs)
  408. ->where('create_yyyymmdd',$tt)
  409. ->where('patrol_mode',4)
  410. ->count();
  411. $date[] = date('m-d',strtotime($v));
  412. $yCount[] = $count;
  413. $y2Count[] = $count2;
  414. $y3Count[] = $count3;
  415. $y4Count[] = $count4;
  416. }
  417. $data = [
  418. 'date'=>$date,
  419. 'count1'=>$yCount,
  420. 'count2'=>$y2Count,
  421. 'count3'=>$y3Count,
  422. 'count4'=>$y4Count,
  423. ];
  424. HelpHander::success($data);
  425. }
  426. // 获取所有下级的id集合
  427. public function getAllNextId($id,$data=[]){
  428. $pids = DB::name('org')->where('parent_id',$id)->column('id');
  429. if(count($pids)>0){
  430. foreach($pids as $v){
  431. $data[] = $v;
  432. $data = $this->getAllNextId($v,$data); //注意写$data 返回给上级
  433. }
  434. }
  435. if(count($data)>0){
  436. return $data;
  437. }else{
  438. return [];
  439. }
  440. }
  441. public function getOrgs(){
  442. $img1 = getSite().'/screen/images/hz01.png';
  443. $img2 = getSite().'/screen/images/hz02.png';
  444. $lists1 = Db::name('org')
  445. ->field('id,name as title,area_screen_img as img')
  446. ->where('del',0)
  447. ->where('enable',1)
  448. ->where('type',1)
  449. ->order('id asc')
  450. ->limit(6)
  451. ->select();
  452. foreach ($lists1 as $k=>$v){
  453. if(!$v['img']){
  454. $lists1[$k]['img'] = $img2;
  455. }
  456. }
  457. $endArea = $lists1 ? end($lists1):[];
  458. $endAreaId = $endArea ?$endArea['id']:'';
  459. $lists3 = [];
  460. if(count($lists1)== 6 && $endAreaId){
  461. $lists3 = Db::name('org')
  462. ->field('id,name as title,area_screen_img as img')
  463. ->where('del',0)
  464. ->where('enable',1)
  465. ->where('type',1)
  466. ->where('id','>',$endAreaId)
  467. ->order('id asc')
  468. ->limit(6)
  469. ->select();
  470. foreach ($lists3 as $k=>$v){
  471. if(!$v['img']){
  472. $lists3[$k]['img'] = $img2;
  473. }
  474. }
  475. }
  476. $endArea2 = $lists3 ? end($lists3):[];
  477. $endAreaId2 = $endArea2 ? $endArea2['id'] : '';
  478. $lists2 = [];
  479. if(count($lists3) == 6 && $endAreaId2){
  480. $lists2 = Db::name('org')
  481. ->field('id,name as title,area_screen_img as img')
  482. ->where('del',0)
  483. ->where('enable',1)
  484. ->where('type',1)
  485. ->where('id','>',$endAreaId2)
  486. ->order('id asc')
  487. ->limit(6)
  488. ->select();
  489. foreach ($lists2 as $k=>$v){
  490. if(!$v['img']){
  491. $lists2[$k]['img'] = $img2;
  492. }
  493. }
  494. }
  495. HelpHander::success([
  496. 'lists1'=>$lists1,
  497. 'lists2'=>$lists3,
  498. 'lists3'=>$lists2,
  499. 'lists4'=>$lists2,
  500. ]);
  501. }
  502. public function dailyData(){
  503. $lists = Db::name('org')
  504. ->field('id,name as title')
  505. ->where('enable',1)
  506. ->where('del',0)
  507. ->where('type',1)
  508. ->limit(5)
  509. ->select();
  510. $orgs = [];
  511. $pzdata = [];
  512. $rwdata = [];
  513. $max = 0;
  514. foreach ($lists as $k=>$v){
  515. $map = [];
  516. $orgs[] = $v['title'];
  517. $orgIds = $this->getAllNextId($v['id'],[]);
  518. if($orgIds){
  519. $map[] = ['org_id','in',$orgIds];
  520. }else{
  521. $map[] = ['org_id','=',-1];
  522. }
  523. $pzcount = Db::name('daily_record')->where($map)->where('order_id','>',0)->count();
  524. $pzdata[] = $pzcount;
  525. $rwcount = Db::name('daily_record')->where($map)->count();
  526. if($rwcount > $max){
  527. $max = $rwcount;
  528. }
  529. $rwdata[] = $rwcount;
  530. }
  531. HelpHander::success([
  532. 'orgs'=>$orgs,
  533. 'pzdata'=>$pzdata,
  534. 'rwdata'=>$rwdata,
  535. ]);
  536. }
  537. public function todoData(){
  538. $lists = Db::name('org')
  539. ->field('id,name as title')
  540. ->where('enable',1)
  541. ->where('del',0)
  542. ->where('type',1)
  543. ->limit(5)
  544. ->select();
  545. $orgs = [];
  546. $y1 = [];
  547. $y2 = [];
  548. $max1 = 0;
  549. $max2 = 0;
  550. foreach ($lists as $k=>$v){
  551. $map = [];
  552. $orgs[] = $v['title'];
  553. $orgIds = $this->getAllNextId($v['id'],[]);
  554. if($orgIds){
  555. $map[] = ['org_id','in',$orgIds];
  556. }else{
  557. $map[] = ['org_id','=',-1];
  558. }
  559. $pzcount = Db::name('todo')->where($map)->where('todo_mode',3)->where('del',0)->count();
  560. $xycount = Db::name('todo')->where($map)->where('todo_mode',3)->where('del',0)->sum('xy_time');
  561. $wccount = Db::name('todo')->where($map)->where('todo_mode',3)->where('del',0)->sum('wc_time');
  562. $y2c = $pzcount>0?round(($xycount/60)/$pzcount,1):0;
  563. $y2[] = $y2c;
  564. if($y2c > $max2){
  565. $max2 = $y2c;
  566. }
  567. $y1c = $pzcount>0?round(($wccount/60)/$pzcount,1):0;
  568. $y1[] = $y1c;
  569. if($y1c > $max1){
  570. $max1 = $y1c;
  571. }
  572. }
  573. HelpHander::success([
  574. 'orgs'=>$orgs,
  575. 'y1'=>$y1,
  576. 'y2'=>$y2,
  577. ]);
  578. }
  579. public function areaList(){
  580. $lists = Db::name('org')
  581. ->field('id,name')
  582. ->where('del',0)
  583. ->where('enable',1)
  584. ->where('type',1)
  585. ->order('sort asc,id asc')
  586. ->select();
  587. HelpHander::success($lists);
  588. }
  589. public function orgList(){
  590. $lists = Db::name('org')
  591. ->where('del',0)
  592. ->where('enable',1)
  593. ->where('type',2)
  594. ->select();
  595. foreach ($lists as $k=>$v){
  596. $lists[$k]['img'] = getSite().'/screen/images/maker.png';
  597. }
  598. HelpHander::success($lists);
  599. }
  600. public function mateTypeCount(){
  601. $rk = Db::name('company_dispatch')
  602. ->alias('cd')
  603. ->join('company_dispatch_goods cdg','cdg.dispatch_id = cd.id')
  604. ->where('cd.type',0)
  605. ->where('cd.status',1)
  606. ->count();
  607. $xh = Db::name('todo_mate_item')
  608. ->alias('tmi')
  609. ->join('mate_goods mi','mi.id=tmi.items_id')
  610. ->where('mi.del',0)
  611. ->sum('tmi.total');
  612. $cz = Db::name('mate_goods_log')
  613. ->where('type',1)
  614. ->sum('nums');
  615. $orderxh = Db::name('todo_mate')
  616. ->alias('tm')
  617. ->join('todo_mate_item tmi','tmi.todo_mate_id=tm.id')
  618. ->sum('tmi.total');
  619. $data = [
  620. 'rk'=>$rk,
  621. 'xh'=>$xh,
  622. 'cz'=>$cz,
  623. 'orderxh'=>$orderxh,
  624. ];
  625. HelpHander::success($data);
  626. }
  627. public function deviceTaskList(){
  628. $list = [];
  629. for ($i=1;$i<=12;$i++){
  630. $list[] = $i;
  631. }
  632. $x = $y = $y1 = [];
  633. foreach ($list as $k=>$v){
  634. $month = $v;
  635. if($month < 10){
  636. $month = '0'.$v;
  637. }
  638. $x[] = $v.'月';
  639. $y[] = Db::name('device_task')
  640. ->where('del',0)
  641. ->where('create_yyyymm',date('Y').$month)
  642. ->count();
  643. $y1[] = Db::name('device_task_delay')
  644. ->where('create_time','>=',date('Y').'-'.$month.'-01 00:00:00')
  645. ->where('create_time','<=',date('Y').'-'.$month.'-31 23:59:59')
  646. ->where('status',1)
  647. ->count();
  648. }
  649. HelpHander::success(['x'=>$x,'y'=>$y,'y1'=>$y1]);
  650. }
  651. }