Twolevel.php 23 KB

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