Statistics.php 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314
  1. <?php
  2. namespace app\h5\controller;
  3. use app\common\model\WorkTypeMode;
  4. use app\hander\HelpHander;
  5. use think\App;
  6. use think\Controller;
  7. use think\Db;
  8. use think\helper\Time;
  9. class Statistics extends Controller
  10. {
  11. private $orgId = 0;
  12. public function initialize()
  13. {
  14. parent::initialize();
  15. $this->orgId = input('orgId/d',0);
  16. // halt($this->orgId);
  17. if($this->orgId <= 0){
  18. $this->redirect(url('index/errorPage'));
  19. }
  20. }
  21. protected function checkToken(){
  22. $token = input('token','','trim');
  23. if(!$token){
  24. if(request()->isAjax()){
  25. $this->error('登录信息失效');
  26. }else{
  27. $this->redirect(url('index/errorPage'));
  28. }
  29. }
  30. $user = Db::name('token')->where('token',$token)->find();
  31. if(!$user) {
  32. if(request()->isAjax()){
  33. $this->error('登录信息失效');
  34. }else{
  35. $this->redirect(url('index/errorPage'));
  36. }
  37. }
  38. return $user['user_id'];
  39. }
  40. public function orders(){
  41. $type = input('type/d',1);
  42. $mode = input('mode/d',1);
  43. if($mode == 1){
  44. $list = [
  45. ['id' => [5],'type'=>'已完成订单'],
  46. ['id' => [1],'type'=>'待处理订单'],
  47. ['id' => [4],'type'=>'已派发订单'],
  48. ['id' => [2,3],'type'=>'已取消订单'],
  49. ['id' => [6],'type'=>'已评价订单'],
  50. ['id' => [-1],'type'=>'挂起订单'],
  51. ];
  52. }else{
  53. $list = [
  54. ['id' => [5],'type'=>'已完成订单'],
  55. ['id' => [1],'type'=>'待处理订单'],
  56. ['id' => [4],'type'=>'已派发订单'],
  57. ['id' => [2,3],'type'=>'已取消订单'],
  58. ['id' => [6],'type'=>'已评价订单'],
  59. ];
  60. }
  61. $map[] = ['del','=',0];
  62. $map[] = ['org_id','=',$this->orgId];
  63. $map[] = ['work_type_mode','=',$mode];
  64. if($type == 1){ //日统计
  65. $map[] = ['create_yyyymmdd','=',date('Ymd')];
  66. }else if($type == 2){ //月统计
  67. $map[] = ['create_yyyymm','=',date('Ym')];
  68. }
  69. $allcount = 0;
  70. if($mode == 1){
  71. foreach ($list as $k=>$v){
  72. if(in_array(4,$v['id'])){
  73. $a1 = 0;
  74. $order = Db::name('orders')->where($map)->where('order_mode','in',$v['id'])->select();
  75. foreach ($order as $kk=>$vv){
  76. $todo = Db::name('todo')->where('order_id',$vv['id'])->where('pause',1)->where('todo_mode',2)->where('del',0)->find();
  77. if($todo){
  78. $a1 +=1;
  79. }
  80. }
  81. $cost = count($order)-$a1;
  82. }elseif(in_array(-1,$v['id'])){
  83. $a2 = 0;
  84. $order = Db::name('orders')->where($map)->where('order_mode',4)->select();
  85. foreach ($order as $kk=>$vv){
  86. $todo = Db::name('todo')->where('order_id',$vv['id'])->where('del',0)->where('todo_mode',2)->where('pause',1)->find();
  87. if($todo){
  88. $a2 +=1;
  89. }
  90. }
  91. $cost = $a2;
  92. }else{
  93. $cost = Db::name('orders')->where($map)->where('order_mode','in',$v['id'])->count();
  94. }
  95. $list[$k]['cost'] = $cost;
  96. $list[$k]['a'] = '1';
  97. $allcount += $list[$k]['cost'];
  98. }
  99. }else{
  100. foreach ($list as $k=>$v){
  101. $list[$k]['cost'] = Db::name('orders')->where($map)->where('order_mode','in',$v['id'])->count();
  102. $list[$k]['a'] = '1';
  103. $allcount += $list[$k]['cost'];
  104. }
  105. }
  106. $this->assign('list',$list);
  107. $this->assign('allcount',$allcount);
  108. $this->assign('orgId',$this->orgId);
  109. $this->assign('type',$type);
  110. $this->assign('mode',$mode);
  111. return $this->fetch();
  112. }
  113. public function users() {
  114. $lists = Db::name('roles')->where('id','in',(new WorkTypeMode())->workerRoles)->field('id,name')->select();
  115. $lists = $lists?$lists:[];
  116. $allcount = 0;
  117. foreach ($lists as $k=>$v){
  118. $lists[$k]['color'] = '#325699';
  119. $roleIds = model('Roles')->getRoleIds($v['id'],$this->orgId);
  120. $map = [];
  121. $map[] = ['u.del','=',0];
  122. $map[] = ['u.enable','=',1];
  123. if($roleIds){
  124. $map[] = ['ur.roles_id','in',$roleIds];
  125. }else{
  126. $map[] = ['ur.roles_id','=',-1];
  127. }
  128. $count = Db::name('user_roles')
  129. ->alias('ur')
  130. ->join('user u','u.id = ur.user_id')
  131. ->where($map)
  132. ->count();
  133. $lists[$k]['cost'] = $count;
  134. $lists[$k]['a'] = '1';
  135. $allcount += $count;
  136. }
  137. $this->assign('list',$lists);
  138. $this->assign('orgId',$this->orgId);
  139. $this->assign('allcount',$allcount);
  140. return $this->fetch();
  141. }
  142. public function comment() {
  143. $type = input('type/d',1);
  144. if($type == 1){ //日统计
  145. $map[] =['c.create_yyyymmdd','=',date('Ymd')];
  146. }else if($type == 2){ //月统计
  147. $map[] =['c.create_yyyymm','=',date('Ym')];
  148. }
  149. $map[] = ['c.org_id','=',$this->orgId];
  150. $tlist = [
  151. ['work_type_mode'=> 0,'name'=>'一键呼叫'],
  152. ['work_type_mode'=> 1,'name'=>'报修'],
  153. ['work_type_mode'=> 2,'name'=>'保洁'],
  154. ['work_type_mode'=> 3,'name'=>'运送'],
  155. ['work_type_mode'=> 4,'name'=>'应急'],
  156. ['work_type_mode'=> 15,'name'=>'品质整改']
  157. ];
  158. $list = [];
  159. foreach ($tlist as $k=>$v){
  160. $ss = Db::name('comment')
  161. ->alias('c')
  162. ->join('orders o','o.id = c.from_id')
  163. ->where('c.type',$v['work_type_mode'])
  164. ->where('o.del',0)
  165. ->where($map)
  166. ->field('count(*) as count,sum(score) as score,c.type')
  167. ->find();
  168. $list[] = array(
  169. 'year' => $v['name'],
  170. 'sales' => $ss&&$ss['count']>0?round($ss['score']/$ss['count'],1):0,
  171. 'count' => $ss['count'],
  172. 'work_type_mode'=>$ss['type']?$ss['type']:$v['work_type_mode'],
  173. );
  174. }
  175. $this->assign('list',$list);
  176. $this->assign('orgId',$this->orgId);
  177. $this->assign('type',$type);
  178. return $this->fetch();
  179. }
  180. public function daily() {
  181. $type = input('type/d',0);
  182. $map[] = ['org_id','=',$this->orgId];
  183. if($type == 0){ //日统计
  184. $map[] = ['create_yyyymmdd','=',date('Ymd')];
  185. } else if($type == 1){ //月统计
  186. $map[] = ['create_yyyymm','=',date('Ym')];
  187. }
  188. $alladdr = Db::name('daily_record')->where($map)->group('daily_id')->count();
  189. $allcount = Db::name('daily_record')->where($map)->count();
  190. $this->assign('allcount',$allcount);
  191. $this->assign('alladdr',$alladdr);
  192. $this->assign('orgId',$this->orgId);
  193. $this->assign('type',$type);
  194. return $this->fetch();
  195. }
  196. public function device() {
  197. $type = input('type/d',0);
  198. $map[] = ['org_id','=',$this->orgId];
  199. if($type == 0){ //日统计
  200. $map[] = ['create_yyyymmdd','=',date('Ymd')];
  201. } else if($type == 1){ //月统计
  202. $map[] = ['create_yyyymm','=',date('Ym')];
  203. }
  204. $device = Db::name('device_record')->where($map)->group('device_id')->count();
  205. $allcount = Db::name('device_record')->where($map)->count();
  206. $this->assign('allcount',$allcount);
  207. $this->assign('device',$device);
  208. $this->assign('orgId',$this->orgId);
  209. $this->assign('type',$type);
  210. return $this->fetch();
  211. }
  212. public function patrol() {
  213. $type = input('type/d',0);
  214. $mode = input('mode/d',1);
  215. $map[] = ['org_id','=',$this->orgId];
  216. $map[] = ['del','=',0];
  217. $map[] = ['patrol_mode','=',$mode];
  218. if($type == 0){ //日统计
  219. $map[] = ['create_yyyymmdd','=',date('Ymd')];
  220. } else if($type == 1){ //月统计
  221. $map[] = ['create_yyyymm','=',date('Ym')];
  222. }
  223. $tt = 3;
  224. if($mode == 2){
  225. $tt = 4;
  226. }else if($mode == 3){
  227. $tt = 5;
  228. }else if($mode == 4){
  229. $tt = 6;
  230. }
  231. $bluetooth = model('Address')->getListByTypeCount($tt,$this->orgId);
  232. $complete = Db::name('patrol_task')->where($map)->where('status', 2)->count();
  233. $incomplete = Db::name('patrol_task')->where($map)->where('status', 3)->count();
  234. $allcount = Db::name('patrol_task')->where($map)->count();
  235. $ratio = 0;
  236. if($allcount > 0) {
  237. $ratio = round($complete / $allcount*100,2);
  238. }
  239. $mode_name = Db::name('patrol_mode')->where('id', $mode)->field('name')->find();
  240. $this->assign('allcount',$allcount);
  241. $this->assign('bluetooth',$bluetooth);
  242. $this->assign('complete',$complete);
  243. $this->assign('incomplete',$incomplete);
  244. $this->assign('orgId',$this->orgId);
  245. $this->assign('type',$type);
  246. $this->assign('ratio',$ratio);
  247. $this->assign('mode',$mode);
  248. $this->assign('mode_name',$mode_name);
  249. return $this->fetch();
  250. }
  251. public function ordersList(){
  252. $page = input('page',1);
  253. $size = input('size',20);
  254. $type = input('type',-1);//订单状态
  255. $mode = input('mode',0);//订单类型
  256. $day = input('day',0);//日,月,总计
  257. //全部订单
  258. if($type == -1){
  259. $where[]=['order_mode','in',[1,2,3,4,5,6]];
  260. }
  261. //已完成订单
  262. if($type == 0){
  263. $where[]=['order_mode','in',[5]];
  264. }
  265. //待处理订单
  266. if($type == 1){
  267. $where[]=['order_mode','in',[1]];
  268. }
  269. //已派发订单
  270. if($type == 2){
  271. $where[]=['order_mode','in',[4]];
  272. }
  273. //已取消订单
  274. if($type == 3){
  275. $where[]=['order_mode','in',[2,3]];
  276. }
  277. //已评价订单
  278. if($type == 4){
  279. $where[]=['order_mode','in',[6]];
  280. }
  281. if($type == 5){ //挂起订单
  282. $where[]=['order_mode','in',[4]];
  283. }
  284. if($day == 1){ //日订单
  285. $where[] = ['create_yyyymmdd','=',date('Ymd')];
  286. }else if($day == 2){ //月订单
  287. $where[] = ['create_yyyymm','=',date('Ym')];
  288. }
  289. //订单类型
  290. if(in_array($mode,array(1,2,3,4))){
  291. $where[] = ['work_type_mode','=',$mode];
  292. }else{
  293. $where[] = ['work_type_mode','>',0];
  294. }
  295. $andWhere = array(
  296. 'del' => 0,
  297. 'org_id' => $this->orgId
  298. );
  299. if($page > 1){
  300. $list = Db::name('orders')
  301. ->field('id,dep_id,work_type_mode,order_mode,user_id,create_time,org_id')
  302. ->where($where)
  303. ->where($andWhere)
  304. ->page($page,$size)
  305. ->order('id desc')
  306. ->select();
  307. foreach ($list as $k=>$v){
  308. if($type == 2 && $v['order_mode'] == 4){
  309. $list[$k]['out_content'] = Db::name('order_mode')->where('id',$v['order_mode'])->value('out_content');
  310. $list[$k]['user_name'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');
  311. $dep = Db::name('dep')->where('id',$v['dep_id'])->value('title');
  312. $list[$k]['dep_name'] = $dep?$dep :'' ;
  313. $todo = Db::name('todo')->where('order_id',$v['id'])->where('del',0)->where('todo_mode',2)->where('pause',1)->find();
  314. if($todo){
  315. unset($list[$k]);
  316. }
  317. }elseif($type == 5 && $v['order_mode'] == 4){
  318. $list[$k]['user_name'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');
  319. $dep = Db::name('dep')->where('id',$v['dep_id'])->value('title');
  320. $list[$k]['dep_name'] = $dep?$dep :'' ;
  321. $list[$k]['out_content'] = '挂起';
  322. $todo = Db::name('todo')->where('order_id',$v['id'])->where('del',0)->where('todo_mode',2)->where('pause',1)->find();
  323. if(!$todo){
  324. unset($list[$k]);
  325. }
  326. }else if($type == -1){
  327. if($v['order_mode'] == 4){
  328. $todo = Db::name('todo')->where('order_id',$v['id'])->where('del',0)->where('todo_mode',2)->where('pause',1)->find();
  329. $list[$k]['out_content'] = $todo ? '挂起': Db::name('order_mode')->where('id',$v['order_mode'])->value('out_content');
  330. }else{
  331. $list[$k]['out_content'] = Db::name('order_mode')->where('id',$v['order_mode'])->value('out_content');
  332. }
  333. $list[$k]['user_name'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');
  334. $dep = Db::name('dep')->where('id',$v['dep_id'])->value('title');
  335. $list[$k]['dep_name'] = $dep?$dep :'' ;
  336. }else{
  337. $list[$k]['out_content'] = Db::name('order_mode')->where('id',$v['order_mode'])->value('out_content');
  338. $list[$k]['user_name'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');
  339. $dep = Db::name('dep')->where('id',$v['dep_id'])->value('title');
  340. $list[$k]['dep_name'] = $dep?$dep :'' ;
  341. }
  342. }
  343. $this->success('','',array_values($list));
  344. }else{
  345. $list = Db::name('orders')
  346. ->field('id,dep_id,work_type_mode,order_mode,user_id,create_time,org_id')
  347. ->where($where)
  348. ->where($andWhere)
  349. ->page($page,$size)
  350. ->order('id desc')
  351. ->select();
  352. foreach ($list as $k=>$v){
  353. if($type == 2 && $v['order_mode'] == 4){
  354. $list[$k]['out_content'] = Db::name('order_mode')->where('id',$v['order_mode'])->value('out_content');
  355. $list[$k]['user_name'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');
  356. $dep = Db::name('dep')->where('id',$v['dep_id'])->value('title');
  357. $list[$k]['dep_name'] = $dep?$dep :'' ;
  358. $todo = Db::name('todo')->where('order_id',$v['id'])->where('del',0)->where('todo_mode',2)->where('pause',1)->find();
  359. if($todo){
  360. unset($list[$k]);
  361. }
  362. }elseif($type == 5 && $v['order_mode'] == 4){
  363. $list[$k]['user_name'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');
  364. $dep = Db::name('dep')->where('id',$v['dep_id'])->value('title');
  365. $list[$k]['dep_name'] = $dep?$dep :'' ;
  366. $list[$k]['out_content'] = '挂起';
  367. $todo = Db::name('todo')->where('order_id',$v['id'])->where('del',0)->where('todo_mode',2)->where('pause',1)->find();
  368. if(!$todo){
  369. unset($list[$k]);
  370. }
  371. }else if($type == -1){
  372. if($v['order_mode'] == 4){
  373. $todo = Db::name('todo')->where('order_id',$v['id'])->where('del',0)->where('todo_mode',2)->where('pause',1)->find();
  374. $list[$k]['out_content'] = $todo ? '挂起': Db::name('order_mode')->where('id',$v['order_mode'])->value('out_content');
  375. }else{
  376. $list[$k]['out_content'] = Db::name('order_mode')->where('id',$v['order_mode'])->value('out_content');
  377. }
  378. $list[$k]['user_name'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');
  379. $dep = Db::name('dep')->where('id',$v['dep_id'])->value('title');
  380. $list[$k]['dep_name'] = $dep?$dep :'' ;
  381. }else{
  382. $list[$k]['out_content'] = Db::name('order_mode')->where('id',$v['order_mode'])->value('out_content');
  383. $list[$k]['user_name'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');
  384. $dep = Db::name('dep')->where('id',$v['dep_id'])->value('title');
  385. $list[$k]['dep_name'] = $dep?$dep :'' ;
  386. }
  387. }
  388. $this->assign('mode',$mode);
  389. $this->assign('orgId',$this->orgId);
  390. $this->assign('type',$type);
  391. $this->assign('day',$day);
  392. $this->assign('list',array_values($list));
  393. return $this->fetch();
  394. }
  395. }
  396. public function ordersDetails(){
  397. $id = input('id',0);
  398. $info = model('Orders')->detail($id);
  399. $info['create_time'] = date('Y-m-d H:i',strtotime($info['create_time']));
  400. $info['images'] = $info['images']?explode(',',$info['images']):[];
  401. $info['videos'] = $info['videos']?explode(',',$info['videos']):[];
  402. $this->assign('info',$info);
  403. return $this->fetch();
  404. }
  405. public function ordersSubDetails(){
  406. $id = input('id',0);
  407. $info = Db::name('todo')->where('id',$id)->find();
  408. $info['sign'] = $info['sign']?explode(',',$info['sign']):[];
  409. $info['cons'] = [];
  410. if ($info['work_type_mode'] == 1) {
  411. $todo_mate = Db::name('todo_mate')
  412. ->where('order_id',$info['order_id'])
  413. ->select();
  414. if(!empty($todo_mate)){
  415. $cons = Db::name('todo_mate_item')
  416. ->alias('a')
  417. ->join('mate_goods b','b.id = a.items_id')
  418. ->where('a.todo_mate_id','in',array_column($todo_mate,'id'))
  419. ->field('a.*,b.title')
  420. ->select();
  421. foreach ($cons as $k1=>$v1){
  422. $pInfo = Db::name('mate_goods')
  423. ->where('id',$v1['pid'])
  424. ->find();
  425. $info['cons'][] = [
  426. 'title' =>$v1['title'],
  427. 'total' =>$v1['total'],
  428. 'money' =>$v1['money'],
  429. 'total_money' =>$v1['total_money'],
  430. ];
  431. }
  432. }
  433. }
  434. $this->assign('info',$info);
  435. return $this->fetch();
  436. }
  437. public function videoPlay(){
  438. $src = input('url');
  439. $this->assign('url',$src);
  440. return $this->fetch();
  441. }
  442. //巡更任务列表
  443. public function patrolList() {
  444. $page = input('page',1);
  445. $size = input('size',20);
  446. $type = input('type',0);//巡更状态
  447. $mode = input('mode',0);//巡更类型
  448. $day = input('day',0);//日,月,总计
  449. if($type==2){
  450. $where[] = ['status','=',2];
  451. }
  452. if($type==3){
  453. $where[] = ['status','=',3];
  454. }
  455. $where[] = ['org_id','=',$this->orgId];
  456. $where[] = ['del','=',0];
  457. if($day == 0){ //日订单
  458. $where[] = ['create_yyyymmdd','=',date('Ymd')];
  459. }else if($day == 1){ //月订单
  460. $where[] = ['create_yyyymm','=',date('Ym')];
  461. }else if($day == 2){ //总订单
  462. }
  463. //订单类型
  464. if(in_array($mode,array(1,2,3,4))){
  465. $where[] = ['patrol_mode','=',$mode];
  466. }else{
  467. $where[] = ['patrol_mode','>',0];
  468. }
  469. if($page > 1){
  470. $list = Db::name('patrol_task')
  471. ->field('id,title,start_time,end_time,status,patrol_mode,org_id')
  472. ->where($where)
  473. ->order('id desc')
  474. ->page($page,$size)
  475. ->select();
  476. foreach ($list as $k=>$v){
  477. $user = Db::name('patrol_task_user')
  478. ->alias('ptu')
  479. ->join('user u','u.id=ptu.user_id')
  480. ->where('ptu.patrol_task_id',$v['id'])
  481. ->column('u.real_name');
  482. $list[$k]['real_name']=$user?implode(',',$user):'';
  483. $dep = Db::name('patrol_task_user')
  484. ->alias('ptu')
  485. ->join('user_dep ud','ud.user_id=ptu.user_id')
  486. ->join('dep d','d.id=ud.dep_id')
  487. ->where('ptu.patrol_task_id',$v['id'])
  488. ->column('d.title');
  489. $list[$k]['dep']=$dep?implode(',',$dep):'';
  490. }
  491. HelpHander::success($list);
  492. }else{
  493. $list = Db::name('patrol_task')
  494. ->field('id,title,start_time,end_time,status,patrol_mode,org_id')
  495. ->where($where)
  496. ->order('id desc')
  497. ->page($page,$size)
  498. ->select();
  499. foreach ($list as $k=>$v){
  500. $user = Db::name('patrol_task_user')
  501. ->alias('ptu')
  502. ->join('user u','u.id=ptu.user_id')
  503. ->where('ptu.patrol_task_id',$v['id'])
  504. ->column('u.real_name');
  505. $list[$k]['real_name']=$user?implode(',',$user):'';
  506. $dep = Db::name('patrol_task_user')
  507. ->alias('ptu')
  508. ->join('user_dep ud','ud.user_id=ptu.user_id')
  509. ->join('dep d','d.id=ud.dep_id')
  510. ->where('ptu.patrol_task_id',$v['id'])
  511. ->column('d.title');
  512. $list[$k]['dep']=$dep?implode(',',$dep):'';
  513. }
  514. $this->assign('list',$list);
  515. $this->assign('mode',$mode);
  516. $this->assign('type',$type);
  517. $this->assign('day',$day);
  518. $this->assign('orgId',$this->orgId);
  519. return $this->fetch();
  520. }
  521. }
  522. public function patrolDetails(){
  523. $id = input('id',0);
  524. $info = Db::name('patrol_task')
  525. ->where('id',$id)
  526. ->where('del',0)
  527. ->find();
  528. $info['interrupt_img']= $info['interrupt_img']?explode(',',$info['interrupt_img']):[];
  529. $info['patrol_type']= Db::name('patrol_mode')->where('id',$info['patrol_mode'])->value('name');
  530. //巡更人员
  531. $taskUser= Db::name('patrol_task_user')
  532. ->alias('ptu')
  533. ->join('user u','u.id=ptu.user_id')
  534. ->where('ptu.patrol_task_id',$info['id'])
  535. ->column('u.real_name');
  536. $info['patrol_user']=$taskUser?implode(',',$taskUser):'';
  537. //巡更地点
  538. $address = Db::name('patrol_task_addr')
  539. ->alias('pta')
  540. ->field('a.id,a.title,pta.id as patrol_form_id,pta.patrol_task_id')
  541. // ->join('patrol_addr_form paf','paf.id=pta.patrol_form_id')
  542. ->join('address a','a.id=pta.address_id')
  543. ->where('pta.patrol_task_id',$id)
  544. ->select();
  545. foreach ($address as $kk=>$vv){
  546. $record = Db::name('patrol_record')
  547. ->where('patrol_task_id',$vv['patrol_task_id'])
  548. ->where('patrol_addr_id',$vv['id'])
  549. ->where('patrol_addr_form_id',$vv['patrol_form_id'])
  550. ->find();
  551. $address[$kk]['status'] = $record?1:0;
  552. }
  553. $info['patrol_address']=$address?$address:[];
  554. $this->assign('info',$info);
  555. return $this->fetch();
  556. }
  557. public function patrolSonDetails(){
  558. $addrFormId = input('addrFormId',0);
  559. $id = input('id',0);
  560. $task = Db::name('patrol_task')
  561. ->field('end_time,patrol_mode')
  562. ->where('id',$id)
  563. ->where('del',0)
  564. ->find();
  565. //巡更人员
  566. $taskUser = Db::name('patrol_task_user')
  567. ->alias('ptu')
  568. ->join('user u','u.id=ptu.user_id')
  569. ->where('ptu.patrol_task_id',$id)
  570. ->column('u.real_name');
  571. $info = Db::name('patrol_record')
  572. ->field('images,content,check_json')
  573. ->where('patrol_task_id',$id)
  574. ->where('patrol_addr_form_id',$addrFormId)
  575. ->find();
  576. $info['img'] = $info['images']?explode(',',$info['images']):[];
  577. $info['forms'] =$info['check_json']?json_decode($info['check_json'],true):[];
  578. $info['patrol_user']=$taskUser?implode(',',$taskUser):'';
  579. $info['patrol_time']=$task['end_time'];
  580. $info['patrol_type']= Db::name('patrol_mode')->where('id',$task['patrol_mode'])->value('name');
  581. $this->assign('info',$info);
  582. return $this->fetch();
  583. }
  584. //用户列表
  585. public function userList(){
  586. $page = input('page',1);
  587. $size = input('size',10);
  588. $rolesId = input('rolesId',0);
  589. if($page > 1){
  590. if($rolesId == 0){
  591. $rolesIds = Db::name('roles')
  592. ->whereIn('parent_id',[4,5,6,7,8,9,10,11])
  593. ->where('org_id',$this->orgId)
  594. ->where('del',0)
  595. ->where('enable',1)
  596. ->column('id');
  597. $list = Db::name('user')
  598. ->alias('u')
  599. ->field('u.id,u.real_name,u.head_image,u.create_time,u.mobile')
  600. ->join('user_roles ur','ur.user_id=u.id')
  601. ->where('u.del',0)
  602. ->where('u.enable',1)
  603. ->whereIn('ur.roles_id',$rolesIds)
  604. ->order('u.id desc')
  605. ->page($page,$size)
  606. ->select();
  607. }else{
  608. $rolesIds = Db::name('roles')
  609. ->where('parent_id',$rolesId)
  610. ->where('org_id',$this->orgId)
  611. ->where('del',0)
  612. ->where('enable',1)
  613. ->column('id');
  614. $list = Db::name('user')
  615. ->alias('u')
  616. ->field('u.id,u.real_name,u.head_image,u.create_time,u.mobile')
  617. ->join('user_roles ur','ur.user_id=u.id')
  618. ->where('u.del',0)
  619. ->where('u.enable',1)
  620. ->whereIn('ur.roles_id',$rolesIds)
  621. ->order('u.id desc')
  622. ->page($page,$size)
  623. ->select();
  624. }
  625. HelpHander::success($list);
  626. }else{
  627. if($rolesId == 0){
  628. $rolesIds = Db::name('roles')
  629. ->whereIn('parent_id',[4,5,6,7,8,9,10,11])
  630. ->where('org_id',$this->orgId)
  631. ->where('del',0)
  632. ->where('enable',1)
  633. ->column('id');
  634. $list = Db::name('user')
  635. ->alias('u')
  636. ->field('u.id,u.real_name,u.head_image,u.create_time,u.mobile')
  637. ->join('user_roles ur','ur.user_id=u.id')
  638. ->where('u.del',0)
  639. ->where('u.enable',1)
  640. ->whereIn('ur.roles_id',$rolesIds)
  641. ->order('u.id desc')
  642. ->page($page,$size)
  643. ->select();
  644. }else{
  645. $rolesIds = Db::name('roles')
  646. ->where('parent_id',$rolesId)
  647. ->where('org_id',$this->orgId)
  648. ->where('del',0)
  649. ->where('enable',1)
  650. ->column('id');
  651. $list = Db::name('user')
  652. ->alias('u')
  653. ->field('u.id,u.real_name,u.head_image,u.create_time,u.mobile')
  654. ->join('user_roles ur','ur.user_id=u.id')
  655. ->where('u.del',0)
  656. ->where('u.enable',1)
  657. ->whereIn('ur.roles_id',$rolesIds)
  658. ->order('u.id desc')
  659. ->page($page,$size)
  660. ->select();
  661. }
  662. }
  663. $this->assign('rolesId',$rolesId);
  664. $this->assign('orgId',$this->orgId);
  665. $this->assign('list',$list);
  666. return $this->fetch();
  667. }
  668. public function commentList() {
  669. $page = input('page',1);
  670. $size = input('size',20);
  671. $day = input('day',1);//日,月,总计
  672. $mode = input('mode',0);
  673. $where[] = ['o.del','=',0];
  674. $where[] = ['o.org_id','=',$this->orgId];
  675. $where[] = ['c.type','=',$mode];
  676. if($day == 1){ //日订单
  677. $where[] = ['c.create_yyyymmdd','=',date('Ymd')];
  678. }else if($day == 2){ //月订单
  679. $where[] = ['c.create_yyyymm','=',date('Ym')];
  680. }
  681. if($page > 1){
  682. $list = Db::name('comment')
  683. ->alias('c')
  684. ->field('c.*')
  685. ->join('orders o','o.id=c.from_id')
  686. ->where($where)
  687. ->order('c.id desc')
  688. ->page($page,$size)
  689. ->select();
  690. foreach ($list as $k=>$v){
  691. $list[$k]['user_name']= Db::name('user')->where('id',$v['user_id'])->value('real_name');
  692. }
  693. HelpHander::success($list);
  694. }else{
  695. $list = Db::name('comment')
  696. ->alias('c')
  697. ->field('c.*')
  698. ->join('orders o','o.id=c.from_id')
  699. ->where($where)
  700. ->order('c.id desc')
  701. ->page($page,$size)
  702. ->select();
  703. foreach ($list as $k=>$v){
  704. $list[$k]['user_name']= Db::name('user')->where('id',$v['user_id'])->value('real_name');
  705. }
  706. }
  707. $this->assign('list',$list);
  708. $this->assign('day',$day);
  709. $this->assign('mode',$mode);
  710. $this->assign('orgId',$this->orgId);
  711. return $this->fetch();
  712. }
  713. public function commentDetails(){
  714. $id = input('id',0);
  715. $info = Db::name('comment')->where('id',$id)->find();
  716. $info['user_name'] = Db::name('user')->where('id',$info['user_id'])->value('real_name');
  717. $this->assign('info',$info);
  718. return $this->fetch();
  719. }
  720. //日常工作统计
  721. public function dailyList() {
  722. $page = input('page',1);
  723. $size = input('size',20);
  724. $day = input('day',0);//日,月,总计
  725. if($day == 0){ //日订单
  726. $where[] = ['create_yyyymmdd','=',date('Ymd')];
  727. }else if($day == 1){ //月订单
  728. $where[] = ['create_yyyymm','=',date('Ym')];
  729. }
  730. $where[] = ['org_id','=',$this->orgId];
  731. $dailyIds = Db::name('daily_record')->where($where)->group('daily_id')->column('daily_id');
  732. if($dailyIds){
  733. $map[] = ['id','in',$dailyIds];
  734. }else{
  735. $map[] = ['id','in',[0]];
  736. }
  737. if($page>1){
  738. $list = Db::name('daily')
  739. ->field('id,title,enable')
  740. ->where('org_id',$this->orgId)
  741. ->where($map)
  742. ->order('id desc')
  743. ->page($page,$size)
  744. ->select();
  745. foreach ($list as $k=>$v){
  746. $user = Db::name('daily_user')
  747. ->alias('du')
  748. ->join('user u','u.id=du.user_id')
  749. ->where('du.daily_id',$v['id'])
  750. ->where('u.del',0)
  751. ->where('u.enable',1)
  752. ->column('u.real_name');
  753. $list[$k]['work_user']=$user?implode(',',$user):'';
  754. }
  755. HelpHander::success($list);
  756. }else{
  757. $list = Db::name('daily')
  758. ->field('id,title,enable')
  759. ->where('org_id',$this->orgId)
  760. ->where($map)
  761. ->order('id desc')
  762. ->page($page,$size)
  763. ->select();
  764. foreach ($list as $k=>$v){
  765. $user = Db::name('daily_user')
  766. ->alias('du')
  767. ->join('user u','u.id=du.user_id')
  768. ->where('du.daily_id',$v['id'])
  769. ->where('u.del',0)
  770. ->where('u.enable',1)
  771. ->column('u.real_name');
  772. $list[$k]['work_user']=$user?implode(',',$user):'';
  773. }
  774. }
  775. $this->assign('list',$list);
  776. $this->assign('day',$day);
  777. $this->assign('orgId',$this->orgId);
  778. return $this->fetch();
  779. }
  780. public function dailyRecordList() {
  781. $page = input('page',1);
  782. $size = input('size',20);
  783. $day = input('day',0);//日,月,总计
  784. if($day == 0){ //日订单
  785. $where[] = ['create_yyyymmdd','=',date('Ymd')];
  786. }else if($day == 1){ //月订单
  787. $where[] = ['create_yyyymm','=',date('Ym')];
  788. }
  789. $where[] = ['org_id','=',$this->orgId];
  790. if($page>1){
  791. $list = Db::name('daily_record')
  792. ->field('id,user_id,create_time,org_id')
  793. ->where($where)
  794. ->order('id desc')
  795. ->page($page,$size)
  796. ->select();
  797. foreach ($list as $k=>$v){
  798. $list[$k]['user_name'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');
  799. }
  800. HelpHander::success($list);
  801. }else{
  802. $list = Db::name('daily_record')
  803. ->field('id,user_id,create_time,org_id')
  804. ->where($where)
  805. ->order('id desc')
  806. ->page($page,$size)
  807. ->select();
  808. foreach ($list as $k=>$v){
  809. $list[$k]['user_name'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');
  810. }
  811. }
  812. $this->assign('list',$list);
  813. $this->assign('day',$day);
  814. $this->assign('orgId',$this->orgId);
  815. return $this->fetch();
  816. }
  817. public function dailyRecordDetails(){
  818. $id = input('id',0);
  819. $info = Db::name('daily_record')->where('id',$id)->find();
  820. $info['img'] = $info['images']?explode(',',$info['images']):[];
  821. //任务内容
  822. $daily = Db::name('daily')->where('id',$info['daily_id'])->find();
  823. $info['daily_content'] = $daily['content'] ? $daily['content']:'';
  824. $info['daily_title'] = $daily['title'] ? $daily['title']:'';
  825. $info['user_name'] = Db::name('user')->where('id',$info['user_id'])->value('real_name');
  826. $info['forms'] = json_decode($info['check_json'],true);
  827. $this->assign('info',$info);
  828. return $this->fetch();
  829. }
  830. //设备台账统计
  831. public function deviceList() {
  832. $page = input('page',1);
  833. $size = input('size',20);
  834. $day = input('day',0);//日,月,总计
  835. if($day == 0){ //日订单
  836. $where[] = ['create_yyyymmdd','=',date('Ymd')];
  837. }else if($day == 1){ //月订单
  838. $where[] = ['create_yyyymm','=',date('Ym')];
  839. }
  840. $where[] = ['org_id','=',$this->orgId];
  841. $deviceIds = Db::name('device_record')->where($where)->group('device_id')->column('device_id');
  842. if($deviceIds){
  843. $map[] = ['id','in',$deviceIds];
  844. }else{
  845. $map[] = ['id','in',[0]];
  846. }
  847. if($page>1){
  848. $list = Db::name('device')
  849. ->field('id,title,enable')
  850. ->where('org_id',$this->orgId)
  851. ->where($map)
  852. ->order('id desc')
  853. ->page($page,$size)
  854. ->select();
  855. foreach ($list as $k=>$v){
  856. $user = Db::name('device_user')
  857. ->alias('du')
  858. ->join('user u','u.id=du.user_id')
  859. ->where('du.device_id',$v['id'])
  860. ->where('u.del',0)
  861. ->where('u.enable',1)
  862. ->column('u.real_name');
  863. $list[$k]['work_user']=$user?implode(',',$user):'';
  864. }
  865. HelpHander::success($list);
  866. }else{
  867. $list = Db::name('device')
  868. ->field('id,title,enable')
  869. ->where('org_id',$this->orgId)
  870. ->where($map)
  871. ->order('id desc')
  872. ->page($page,$size)
  873. ->select();
  874. foreach ($list as $k=>$v){
  875. $user = Db::name('device_user')
  876. ->alias('du')
  877. ->join('user u','u.id=du.user_id')
  878. ->where('du.device_id',$v['id'])
  879. ->where('u.del',0)
  880. ->where('u.enable',1)
  881. ->column('u.real_name');
  882. $list[$k]['work_user']=$user?implode(',',$user):'';
  883. }
  884. }
  885. $this->assign('list',$list);
  886. $this->assign('day',$day);
  887. $this->assign('orgId',$this->orgId);
  888. return $this->fetch();
  889. }
  890. public function deviceRecordList() {
  891. $page = input('page',1);
  892. $size = input('size',20);
  893. $day = input('day',0);//日,月,总计
  894. if($day == 0){ //日订单
  895. $where[] = ['create_yyyymmdd','=',date('Ymd')];
  896. }else if($day == 1){ //月订单
  897. $where[] = ['create_yyyymm','=',date('Ym')];
  898. }
  899. $where[] = ['org_id','=',$this->orgId];
  900. if($page>1){
  901. $list = Db::name('device_record')
  902. ->field('id,user_id,create_time,org_id')
  903. ->where($where)
  904. ->order('id desc')
  905. ->page($page,$size)
  906. ->select();
  907. foreach ($list as $k=>$v){
  908. $list[$k]['user_name'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');
  909. }
  910. HelpHander::success($list);
  911. }else{
  912. $list = Db::name('device_record')
  913. ->field('id,user_id,create_time,org_id')
  914. ->where($where)
  915. ->order('id desc')
  916. ->page($page,$size)
  917. ->select();
  918. foreach ($list as $k=>$v){
  919. $list[$k]['user_name'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');
  920. }
  921. }
  922. $this->assign('list',$list);
  923. $this->assign('day',$day);
  924. $this->assign('orgId',$this->orgId);
  925. return $this->fetch();
  926. }
  927. public function deviceRecordDetails(){
  928. $id = input('id',0);
  929. $info = Db::name('device_record')->where('id',$id)->find();
  930. $info['img'] = $info['images']?explode(',',$info['images']):[];
  931. //任务内容
  932. $daily = Db::name('device')->where('id',$info['device_id'])->find();
  933. $info['device_content'] = $daily['content'] ? $daily['content']:'';
  934. $info['device_title'] = $daily['title'] ? $daily['title']:'';
  935. $info['user_name'] = Db::name('user')->where('id',$info['user_id'])->value('real_name');
  936. $info['forms'] = json_decode($info['check_json'],true);
  937. $this->assign('info',$info);
  938. return $this->fetch();
  939. }
  940. public function complain(){
  941. $type = input('type',0);
  942. $week = Time::week();
  943. $sw = date('Ymd',$week[0]);
  944. $ew = date('Ymd',$week[1]);
  945. if($type == 0){
  946. $map[] = ['create_yyyymmdd','>=',$sw];
  947. $map[] = ['create_yyyymmdd','<=',$ew];
  948. }elseif ($type == 1){
  949. $map[] = ['create_yyyymm','=',date('Ym')];
  950. }
  951. $map[] = ['org_id','=',$this->orgId];
  952. $map[] = ['del','=',0];
  953. $data = [
  954. ['name'=>'已处理','status'=>2],
  955. ['name'=>'处理中','status'=>1],
  956. ['name'=>'待处理','status'=>0],
  957. ];
  958. foreach ($data as $k=>$v){
  959. $count = 0;
  960. if($v['status'] == 2){
  961. $complain = Db::name('complain')->where($map)->select();
  962. foreach ($complain as $kk=>$vv){
  963. if($vv['status'] == 1 && $vv['order_id'] > 0){
  964. $order = Db::name('orders')->where('id',$vv['order_id'])->find();
  965. if(in_array($order['order_mode'],[3,5,6])){
  966. $count +=1;
  967. }
  968. }elseif ($vv['status'] == 1 && $vv['order_id'] == 0){
  969. $count +=1;
  970. }
  971. }
  972. }elseif ($v['status'] == 1){
  973. $complain = Db::name('complain')->where($map)->select();
  974. foreach ($complain as $kk=>$vv){
  975. if($vv['status'] == 1 && $vv['order_id'] > 0){
  976. $order = Db::name('orders')->where('id',$vv['order_id'])->find();
  977. if(!in_array($order['order_mode'],[3,5,6])){
  978. $count +=1;
  979. }
  980. }
  981. }
  982. }elseif ($v['status'] == 0){
  983. $count = Db::name('complain')->where($map)->where('status',0)->count();
  984. }
  985. $data[$k]['cost'] = $count;
  986. }
  987. $count = Db::name('complain')->where($map)->count();
  988. $this->assign('list',$data);
  989. $this->assign('count',$count);
  990. $this->assign('orgId',$this->orgId);
  991. $this->assign('type',$type);
  992. return $this->fetch();
  993. }
  994. public function complainList(){
  995. $type = input('type/d',0);
  996. $status= input('status',-1);
  997. $week = Time::week();
  998. $sw = date('Ymd',$week[0]);
  999. $ew = date('Ymd',$week[1]);
  1000. if($type == 0){
  1001. $map[] = ['create_yyyymmdd','>=',$sw];
  1002. $map[] = ['create_yyyymmdd','<=',$ew];
  1003. }elseif ($type == 1){
  1004. $map[] = ['create_yyyymm','=',date('Ym')];
  1005. }
  1006. $map[] = ['org_id','=',$this->orgId];
  1007. $map[] = ['del','=',0];
  1008. $list = [];
  1009. if($status == 0){
  1010. $list = Db::name('complain')->where($map)->where('status',0)->order('id desc')->select();
  1011. foreach ($list as $k=>$v){
  1012. $list[$k]['statusTxt'] = '待处理';
  1013. }
  1014. }elseif ($status == -1){
  1015. $list = Db::name('complain')->where($map)->order('id desc')->select();
  1016. foreach ($list as $k=>$v){
  1017. $statusTxt = '';
  1018. if($v['status'] == 1 && $v['order_id'] == 0){
  1019. $statusTxt = '已处理';
  1020. }elseif($v['status'] == 1 && $v['order_id'] > 0){
  1021. $order = Db::name('orders')->where('id',$v['order_id'])->find();
  1022. if(in_array($order['order_mode'],[3,5,6])){
  1023. $statusTxt = '已处理';
  1024. }else{
  1025. $statusTxt = '处理中';
  1026. }
  1027. }elseif($v['status'] == 0){
  1028. $statusTxt = '待处理';
  1029. }
  1030. $list[$k]['statusTxt'] = $statusTxt;
  1031. }
  1032. } else{
  1033. $complain = Db::name('complain')->where($map)->select();
  1034. foreach ($complain as $k=>$v){
  1035. $statusTxt = '';
  1036. if($v['status'] == 1 && $v['order_id'] == 0){
  1037. $statusTxt = '已处理';
  1038. }else if($v['status'] == 1 && $v['order_id'] > 0){
  1039. $order = Db::name('orders')->where('id',$v['order_id'])->find();
  1040. if(in_array($order['order_mode'],[3,5,6])){
  1041. $statusTxt = '已处理';
  1042. }else{
  1043. $statusTxt = '处理中';
  1044. }
  1045. }elseif($v['status'] == 0){
  1046. $statusTxt = '待处理';
  1047. }
  1048. $complain[$k]['statusTxt'] = $statusTxt;
  1049. }
  1050. foreach ($complain as $k=>$v){
  1051. if($status == 2){
  1052. if($v['status'] == 1 && $v['order_id'] > 0){
  1053. $order = Db::name('orders')->where('id',$v['order_id'])->find();
  1054. if(in_array($order['order_mode'],[3,5,6])){
  1055. $list[$k] = $v;
  1056. }
  1057. }elseif($v['status'] == 1 && $v['order_id'] == 0){
  1058. $list[$k] = $v;
  1059. }
  1060. }elseif ($status == 1){
  1061. if($v['status'] == 1 && $v['order_id'] > 0){
  1062. $order = Db::name('orders')->where('id',$v['order_id'])->find();
  1063. if(!in_array($order['order_mode'],[3,5,6])){
  1064. $list[$k] = $v;
  1065. }
  1066. }
  1067. }
  1068. }
  1069. }
  1070. foreach ($list as $k=>$v){
  1071. if($v['hide'] == 1){
  1072. $list[$k]['user_name'] = '匿名';
  1073. }else{
  1074. $list[$k]['user_name'] = Db::name('user')->where('id',$v['create_user_id'])->value('real_name');
  1075. }
  1076. }
  1077. $this->assign('list',$list);
  1078. $this->assign('orgId',$this->orgId);
  1079. $this->assign('type',$type);
  1080. return $this->fetch();
  1081. }
  1082. public function complainDetail(){
  1083. $id = input('id',0);
  1084. $info = Db::name('complain')->where('id',$id)->find();
  1085. $info['images'] = !empty($info['images'])?explode(',',$info['images']):[];
  1086. $info['create_time'] = date('Y-m-d H:i',strtotime($info['create_time']));
  1087. $statusTxt = '';
  1088. if($info['status'] == 1 && $info['order_id'] == 0){
  1089. $statusTxt = '已处理';
  1090. }elseif($info['status'] == 1 && $info['order_id'] > 0){
  1091. $order = Db::name('orders')->where('id',$info['order_id'])->find();
  1092. if(in_array($order['order_mode'],[3,5,6])){
  1093. $statusTxt = '已处理';
  1094. }else{
  1095. $statusTxt = '处理中';
  1096. }
  1097. }elseif($info['status'] == 0){
  1098. $statusTxt = '待处理';
  1099. }
  1100. $info['statusTxt'] = $statusTxt;
  1101. if($info['hide'] == 1){
  1102. $info['user_name'] = '匿名';
  1103. $info['mobile'] = '';
  1104. }else{
  1105. $info['user_name'] = Db::name('user')->where('id',$info['create_user_id'])->value('real_name');
  1106. $info['mobile'] = Db::name('user')->where('id',$info['create_user_id'])->value('mobile');
  1107. }
  1108. $info['dep_name'] = db('dep')->where('id',$info['dep_id'])->value('title');
  1109. $this->assign('info',$info);
  1110. return $this->fetch();
  1111. }
  1112. public function waste() {
  1113. $type = input('type/d',0);
  1114. $map[] = ['org_id','=',$this->orgId];
  1115. if($type == 0){ //日统计
  1116. $map[] = ['create_yyyymmdd','=',date('Ymd')];
  1117. } else if($type == 1){ //月统计
  1118. $map[] = ['create_yyyymm','=',date('Ym')];
  1119. }
  1120. $map[] = ['del','=',0];
  1121. $wasteTypes = model("WasteType")->list1($this->orgId);
  1122. foreach ($wasteTypes as $k=>$v){
  1123. $count = Db::name('waste_record')->where($map)->where('cateid',$v['waste_id'])->sum('weight');
  1124. $wasteTypes[$k]['count'] = round($count/1000,2)."kg";
  1125. if($v['type'] == 1){
  1126. $count = Db::name('waste_record')->where($map)->where('cateid',$v['waste_id'])->sum('num');
  1127. $wasteTypes[$k]['count'] = round($count/1000,2)."kg".'('.$count.$v['unit'].')';
  1128. }
  1129. }
  1130. $this->assign('wasteTypes',$wasteTypes);
  1131. $this->assign('orgId',$this->orgId);
  1132. $this->assign('type',$type);
  1133. return $this->fetch();
  1134. }
  1135. public function standby()
  1136. {
  1137. $lists = model('WorkTypeMode')->getRolesUserApp(3,$this->orgId,1);
  1138. $userIds = Db::name('todo')
  1139. ->alias('t')
  1140. ->field('t.to_user_id')
  1141. ->join('user u','u.id=t.to_user_id')
  1142. ->where('t.org_id',$this->orgId)
  1143. ->whereIn('t.todo_mode',[1,2])
  1144. ->where('t.del',0)
  1145. ->where('t.work_type_mode',3)
  1146. ->where('u.work',1)
  1147. ->where('u.enable',1)
  1148. ->where('u.del',0)
  1149. ->group('t.to_user_id')
  1150. ->column('t.to_user_id');
  1151. $nlists = [];
  1152. foreach ($lists as $k=>$v){
  1153. if(!in_array($v['id'],$userIds)){
  1154. $nlists[] = $v;
  1155. }
  1156. }
  1157. $slist = [];
  1158. foreach ($nlists as $k=>$v){
  1159. $slist[$k]['name'] = $v['real_name'];
  1160. }
  1161. $count = count($slist);
  1162. $this->assign('list',$slist);
  1163. $this->assign('count',$count);
  1164. return $this->fetch();
  1165. }
  1166. }