| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281 | 
							- <?php
 
- namespace app\h5\controller;
 
- use app\common\model\WorkTypeMode;
 
- use app\hander\HelpHander;
 
- use think\App;
 
- use think\Controller;
 
- use think\Db;
 
- use think\helper\Time;
 
- class Statistics extends Controller
 
- {
 
-     private $orgId = 0;
 
-     public function initialize()
 
-     {
 
-         parent::initialize();
 
-         $this->orgId = input('orgId/d',0);
 
- //        halt($this->orgId);
 
-         if($this->orgId <= 0){
 
-             $this->redirect(url('index/errorPage'));
 
-         }
 
-     }
 
-     protected function checkToken(){
 
-         $token = input('token','','trim');
 
-         if(!$token){
 
-             if(request()->isAjax()){
 
-                 $this->error('登录信息失效');
 
-             }else{
 
-                 $this->redirect(url('index/errorPage'));
 
-             }
 
-         }
 
-         $user = Db::name('token')->where('token',$token)->find();
 
-         if(!$user) {
 
-             if(request()->isAjax()){
 
-                 $this->error('登录信息失效');
 
-             }else{
 
-                 $this->redirect(url('index/errorPage'));
 
-             }
 
-         }
 
-         return $user['user_id'];
 
-     }
 
-     public function orders(){
 
-         $type = input('type/d',1);
 
-         $mode = input('mode/d',1);
 
-         if($mode == 1){
 
-             $list = [
 
-                 ['id' => [5],'type'=>'已完成订单'],
 
-                 ['id' => [1],'type'=>'待处理订单'],
 
-                 ['id' => [4],'type'=>'已派发订单'],
 
-                 ['id' => [2,3],'type'=>'已取消订单'],
 
-                 ['id' => [6],'type'=>'已评价订单'],
 
-                 ['id' => [-1],'type'=>'挂起订单'],
 
-             ];
 
-         }else{
 
-             $list = [
 
-                 ['id' => [5],'type'=>'已完成订单'],
 
-                 ['id' => [1],'type'=>'待处理订单'],
 
-                 ['id' => [4],'type'=>'已派发订单'],
 
-                 ['id' => [2,3],'type'=>'已取消订单'],
 
-                 ['id' => [6],'type'=>'已评价订单'],
 
-             ];
 
-         }
 
-         $map[] = ['del','=',0];
 
-         $map[] = ['org_id','=',$this->orgId];
 
-         $map[] = ['work_type_mode','=',$mode];
 
-         if($type == 1){ //日统计
 
-             $map[] = ['create_yyyymmdd','=',date('Ymd')];
 
-         }else if($type == 2){ //月统计
 
-             $map[] = ['create_yyyymm','=',date('Ym')];
 
-         }
 
-         $allcount = 0;
 
-         if($mode == 1){
 
-             foreach ($list as $k=>$v){
 
-                 if(in_array(4,$v['id'])){
 
-                     $a1 = 0;
 
-                     $order =  Db::name('orders')->where($map)->where('order_mode','in',$v['id'])->select();
 
-                     foreach ($order as $kk=>$vv){
 
-                         $todo = Db::name('todo')->where('order_id',$vv['id'])->where('pause',1)->where('todo_mode',2)->where('del',0)->find();
 
-                         if($todo){
 
-                             $a1 +=1;
 
-                         }
 
-                     }
 
-                     $cost = count($order)-$a1;
 
-                 }elseif(in_array(-1,$v['id'])){
 
-                     $a2 = 0;
 
-                     $order =  Db::name('orders')->where($map)->where('order_mode',4)->select();
 
-                     foreach ($order as $kk=>$vv){
 
-                         $todo = Db::name('todo')->where('order_id',$vv['id'])->where('del',0)->where('todo_mode',2)->where('pause',1)->find();
 
-                         if($todo){
 
-                             $a2 +=1;
 
-                         }
 
-                     }
 
-                     $cost = $a2;
 
-                 }else{
 
-                     $cost =  Db::name('orders')->where($map)->where('order_mode','in',$v['id'])->count();
 
-                 }
 
-                 $list[$k]['cost'] = $cost;
 
-                 $list[$k]['a'] = '1';
 
-                 $allcount += $list[$k]['cost'];
 
-             }
 
-         }else{
 
-             foreach ($list as $k=>$v){
 
-                 $list[$k]['cost'] =  Db::name('orders')->where($map)->where('order_mode','in',$v['id'])->count();
 
-                 $list[$k]['a'] = '1';
 
-                 $allcount += $list[$k]['cost'];
 
-             }
 
-         }
 
-         $this->assign('list',$list);
 
-         $this->assign('allcount',$allcount);
 
-         $this->assign('orgId',$this->orgId);
 
-         $this->assign('type',$type);
 
-         $this->assign('mode',$mode);
 
-         return $this->fetch();
 
-     }
 
-     public function users() {
 
-         $lists = Db::name('roles')->where('id','in',(new WorkTypeMode())->workerRoles)->field('id,name')->select();
 
-         $lists = $lists?$lists:[];
 
-         $allcount = 0;
 
-         foreach ($lists as $k=>$v){
 
-             $lists[$k]['color'] = '#325699';
 
-             $roleIds = model('Roles')->getRoleIds($v['id'],$this->orgId);
 
-             $map = [];
 
-             $map[] = ['u.del','=',0];
 
-             $map[] = ['u.enable','=',1];
 
-             if($roleIds){
 
-                 $map[] = ['ur.roles_id','in',$roleIds];
 
-             }else{
 
-                 $map[] = ['ur.roles_id','=',-1];
 
-             }
 
-             $count = Db::name('user_roles')
 
-                 ->alias('ur')
 
-                 ->join('user u','u.id = ur.user_id')
 
-                 ->where($map)
 
-                 ->count();
 
-             $lists[$k]['cost'] = $count;
 
-             $lists[$k]['a'] = '1';
 
-             $allcount += $count;
 
-         }
 
-         $this->assign('list',$lists);
 
-         $this->assign('orgId',$this->orgId);
 
-         $this->assign('allcount',$allcount);
 
-         return $this->fetch();
 
-     }
 
-     public function comment() {
 
-         $type = input('type/d',1);
 
-         if($type == 1){ //日统计
 
-             $map[] =['c.create_yyyymmdd','=',date('Ymd')];
 
-         }else if($type == 2){ //月统计
 
-             $map[] =['c.create_yyyymm','=',date('Ym')];
 
-         }
 
-         $map[] = ['c.org_id','=',$this->orgId];
 
-         $tlist = [
 
-             ['work_type_mode'=> 0,'name'=>'一键呼叫'],
 
-             ['work_type_mode'=> 1,'name'=>'报修'],
 
-             ['work_type_mode'=> 2,'name'=>'保洁'],
 
-             ['work_type_mode'=> 3,'name'=>'运送'],
 
-             ['work_type_mode'=> 4,'name'=>'应急'],
 
-             ['work_type_mode'=> 15,'name'=>'品质整改']
 
-         ];
 
-         $list = [];
 
-         foreach ($tlist as $k=>$v){
 
-             $ss = Db::name('comment')
 
-                 ->alias('c')
 
-                 ->join('orders o','o.id = c.from_id')
 
-                 ->where('c.type',$v['work_type_mode'])
 
-                 ->where('o.del',0)
 
-                 ->where($map)
 
-                 ->field('count(*) as count,sum(score) as score,c.type')
 
-                 ->find();
 
-             $list[] = array(
 
-                 'year' => $v['name'],
 
-                 'sales' => $ss&&$ss['count']>0?round($ss['score']/$ss['count'],1):0,
 
-                 'count' => $ss['count'],
 
-                 'work_type_mode'=>$ss['type']?$ss['type']:$v['work_type_mode'],
 
-             );
 
-         }
 
-         $this->assign('list',$list);
 
-         $this->assign('orgId',$this->orgId);
 
-         $this->assign('type',$type);
 
-         return $this->fetch();
 
-     }
 
-     public function daily() {
 
-         $type = input('type/d',0);
 
-         $map[] = ['org_id','=',$this->orgId];
 
-         if($type == 0){ //日统计
 
-             $map[] = ['create_yyyymmdd','=',date('Ymd')];
 
-         } else if($type == 1){ //月统计
 
-             $map[] = ['create_yyyymm','=',date('Ym')];
 
-         }
 
-         $alladdr = Db::name('daily_record')->where($map)->group('daily_id')->count();
 
-         $allcount = Db::name('daily_record')->where($map)->count();
 
-         $this->assign('allcount',$allcount);
 
-         $this->assign('alladdr',$alladdr);
 
-         $this->assign('orgId',$this->orgId);
 
-         $this->assign('type',$type);
 
-         return $this->fetch();
 
-     }
 
-     public function device() {
 
-         $type = input('type/d',0);
 
-         $map[] = ['org_id','=',$this->orgId];
 
-         if($type == 0){ //日统计
 
-             $map[] = ['create_yyyymmdd','=',date('Ymd')];
 
-         } else if($type == 1){ //月统计
 
-             $map[] = ['create_yyyymm','=',date('Ym')];
 
-         }
 
-         $device = Db::name('device_record')->where($map)->group('device_id')->count();
 
-         $allcount = Db::name('device_record')->where($map)->count();
 
-         $this->assign('allcount',$allcount);
 
-         $this->assign('device',$device);
 
-         $this->assign('orgId',$this->orgId);
 
-         $this->assign('type',$type);
 
-         return $this->fetch();
 
-     }
 
-     public function patrol() {
 
-         $type = input('type/d',0);
 
-         $mode = input('mode/d',1);
 
-         $map[] = ['org_id','=',$this->orgId];
 
-         $map[] = ['del','=',0];
 
-         $map[] = ['patrol_mode','=',$mode];
 
-         if($type == 0){ //日统计
 
-             $map[] = ['create_yyyymmdd','=',date('Ymd')];
 
-         } else if($type == 1){ //月统计
 
-             $map[] = ['create_yyyymm','=',date('Ym')];
 
-         }
 
-         $tt = 3;
 
-         if($mode == 2){
 
-             $tt = 4;
 
-         }else if($mode == 3){
 
-             $tt = 5;
 
-         }else if($mode == 4){
 
-             $tt = 6;
 
-         }
 
-         $bluetooth = model('Address')->getListByTypeCount($tt,$this->orgId);
 
-         $complete = Db::name('patrol_task')->where($map)->where('status', 2)->count();
 
-         $incomplete = Db::name('patrol_task')->where($map)->where('status', 3)->count();
 
-         $allcount = Db::name('patrol_task')->where($map)->count();
 
-         $ratio = 0;
 
-         if($allcount > 0) {
 
-             $ratio = round($complete / $allcount*100,2);
 
-         }
 
-         $mode_name = Db::name('patrol_mode')->where('id', $mode)->field('name')->find();
 
-         $this->assign('allcount',$allcount);
 
-         $this->assign('bluetooth',$bluetooth);
 
-         $this->assign('complete',$complete);
 
-         $this->assign('incomplete',$incomplete);
 
-         $this->assign('orgId',$this->orgId);
 
-         $this->assign('type',$type);
 
-         $this->assign('ratio',$ratio);
 
-         $this->assign('mode',$mode);
 
-         $this->assign('mode_name',$mode_name);
 
-         return $this->fetch();
 
-     }
 
-     public function ordersList(){
 
-         $page = input('page',1);
 
-         $size = input('size',20);
 
-         $type = input('type',-1);//订单状态
 
-         $mode = input('mode',0);//订单类型
 
-         $day = input('day',0);//日,月,总计
 
-         //全部订单
 
-         if($type == -1){
 
-             $where[]=['order_mode','in',[1,2,3,4,5,6]];
 
-         }
 
-         //已完成订单
 
-         if($type == 0){
 
-             $where[]=['order_mode','in',[5]];
 
-         }
 
-         //待处理订单
 
-         if($type == 1){
 
-             $where[]=['order_mode','in',[1]];
 
-         }
 
-         //已派发订单
 
-         if($type == 2){
 
-             $where[]=['order_mode','in',[4]];
 
-         }
 
-         //已取消订单
 
-         if($type == 3){
 
-             $where[]=['order_mode','in',[2,3]];
 
-         }
 
-         //已评价订单
 
-         if($type == 4){
 
-             $where[]=['order_mode','in',[6]];
 
-         }
 
-         if($type == 5){ //挂起订单
 
-             $where[]=['order_mode','in',[4]];
 
-         }
 
-         if($day == 1){    //日订单
 
-             $where[] = ['create_yyyymmdd','=',date('Ymd')];
 
-         }else if($day == 2){  //月订单
 
-             $where[] = ['create_yyyymm','=',date('Ym')];
 
-         }
 
-         //订单类型
 
-         if(in_array($mode,array(1,2,3,4))){
 
-             $where[] = ['work_type_mode','=',$mode];
 
-         }else{
 
-             $where[] = ['work_type_mode','>',0];
 
-         }
 
-         $andWhere = array(
 
-             'del' => 0,
 
-             'org_id' => $this->orgId
 
-         );
 
-         if($page > 1){
 
-             $list = Db::name('orders')
 
-                 ->field('id,dep_id,work_type_mode,order_mode,user_id,create_time,org_id')
 
-                 ->where($where)
 
-                 ->where($andWhere)
 
-                 ->page($page,$size)
 
-                 ->order('id desc')
 
-                 ->select();
 
-             foreach ($list as $k=>$v){
 
-                 if($type == 2 && $v['order_mode'] == 4){
 
-                     $list[$k]['out_content'] = Db::name('order_mode')->where('id',$v['order_mode'])->value('out_content');
 
-                     $list[$k]['user_name'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');
 
-                     $dep = Db::name('dep')->where('id',$v['dep_id'])->value('title');
 
-                     $list[$k]['dep_name'] = $dep?$dep :'' ;
 
-                     $todo = Db::name('todo')->where('order_id',$v['id'])->where('del',0)->where('todo_mode',2)->where('pause',1)->find();
 
-                     if($todo){
 
-                         unset($list[$k]);
 
-                     }
 
-                 }elseif($type == 5 && $v['order_mode'] == 4){
 
-                     $list[$k]['user_name'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');
 
-                     $dep = Db::name('dep')->where('id',$v['dep_id'])->value('title');
 
-                     $list[$k]['dep_name'] = $dep?$dep :'' ;
 
-                     $list[$k]['out_content'] = '挂起';
 
-                     $todo = Db::name('todo')->where('order_id',$v['id'])->where('del',0)->where('todo_mode',2)->where('pause',1)->find();
 
-                     if(!$todo){
 
-                         unset($list[$k]);
 
-                     }
 
-                 }else if($type == -1){
 
-                     if($v['order_mode'] == 4){
 
-                         $todo = Db::name('todo')->where('order_id',$v['id'])->where('del',0)->where('todo_mode',2)->where('pause',1)->find();
 
-                         $list[$k]['out_content'] = $todo ? '挂起': Db::name('order_mode')->where('id',$v['order_mode'])->value('out_content');
 
-                     }else{
 
-                         $list[$k]['out_content'] = Db::name('order_mode')->where('id',$v['order_mode'])->value('out_content');
 
-                     }
 
-                     $list[$k]['user_name'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');
 
-                     $dep = Db::name('dep')->where('id',$v['dep_id'])->value('title');
 
-                     $list[$k]['dep_name'] = $dep?$dep :'' ;
 
-                 }else{
 
-                     $list[$k]['out_content'] = Db::name('order_mode')->where('id',$v['order_mode'])->value('out_content');
 
-                     $list[$k]['user_name'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');
 
-                     $dep = Db::name('dep')->where('id',$v['dep_id'])->value('title');
 
-                     $list[$k]['dep_name'] = $dep?$dep :'' ;
 
-                 }
 
-             }
 
-             $this->success('','',array_values($list));
 
-         }else{
 
-             $list = Db::name('orders')
 
-                 ->field('id,dep_id,work_type_mode,order_mode,user_id,create_time,org_id')
 
-                 ->where($where)
 
-                 ->where($andWhere)
 
-                 ->page($page,$size)
 
-                 ->order('id desc')
 
-                 ->select();
 
-             foreach ($list as $k=>$v){
 
-                 if($type == 2 && $v['order_mode'] == 4){
 
-                     $list[$k]['out_content'] = Db::name('order_mode')->where('id',$v['order_mode'])->value('out_content');
 
-                     $list[$k]['user_name'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');
 
-                     $dep = Db::name('dep')->where('id',$v['dep_id'])->value('title');
 
-                     $list[$k]['dep_name'] = $dep?$dep :'' ;
 
-                     $todo = Db::name('todo')->where('order_id',$v['id'])->where('del',0)->where('todo_mode',2)->where('pause',1)->find();
 
-                     if($todo){
 
-                         unset($list[$k]);
 
-                     }
 
-                 }elseif($type == 5 && $v['order_mode'] == 4){
 
-                     $list[$k]['user_name'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');
 
-                     $dep = Db::name('dep')->where('id',$v['dep_id'])->value('title');
 
-                     $list[$k]['dep_name'] = $dep?$dep :'' ;
 
-                     $list[$k]['out_content'] = '挂起';
 
-                     $todo = Db::name('todo')->where('order_id',$v['id'])->where('del',0)->where('todo_mode',2)->where('pause',1)->find();
 
-                     if(!$todo){
 
-                         unset($list[$k]);
 
-                     }
 
-                 }else if($type == -1){
 
-                     if($v['order_mode'] == 4){
 
-                         $todo = Db::name('todo')->where('order_id',$v['id'])->where('del',0)->where('todo_mode',2)->where('pause',1)->find();
 
-                         $list[$k]['out_content'] = $todo ? '挂起': Db::name('order_mode')->where('id',$v['order_mode'])->value('out_content');
 
-                     }else{
 
-                         $list[$k]['out_content'] = Db::name('order_mode')->where('id',$v['order_mode'])->value('out_content');
 
-                     }
 
-                     $list[$k]['user_name'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');
 
-                     $dep = Db::name('dep')->where('id',$v['dep_id'])->value('title');
 
-                     $list[$k]['dep_name'] = $dep?$dep :'' ;
 
-                 }else{
 
-                     $list[$k]['out_content'] = Db::name('order_mode')->where('id',$v['order_mode'])->value('out_content');
 
-                     $list[$k]['user_name'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');
 
-                     $dep = Db::name('dep')->where('id',$v['dep_id'])->value('title');
 
-                     $list[$k]['dep_name'] = $dep?$dep :'' ;
 
-                 }
 
-             }
 
-             $this->assign('mode',$mode);
 
-             $this->assign('orgId',$this->orgId);
 
-             $this->assign('type',$type);
 
-             $this->assign('day',$day);
 
-             $this->assign('list',array_values($list));
 
-             return $this->fetch();
 
-         }
 
-     }
 
-     public function ordersDetails(){
 
-         $id = input('id',0);
 
-         $info = model('Orders')->detail($id);
 
-         $info['create_time'] = date('Y-m-d H:i',strtotime($info['create_time']));
 
-         $info['images'] = $info['images']?explode(',',$info['images']):[];
 
-         $info['videos'] = $info['videos']?explode(',',$info['videos']):[];
 
-         $this->assign('info',$info);
 
-         return $this->fetch();
 
-     }
 
-     public function ordersSubDetails(){
 
-         $id = input('id',0);
 
-         $info = Db::name('todo')->where('id',$id)->find();
 
-         $info['sign'] = $info['sign']?explode(',',$info['sign']):[];
 
-         $info['cons'] = [];
 
-         if ($info['work_type_mode'] == 1) {
 
-             $todo_mate = Db::name('todo_mate')
 
-                 ->where('order_id',$info['order_id'])
 
-                 ->select();
 
-             if(!empty($todo_mate)){
 
-                 $cons = Db::name('todo_mate_item')
 
-                     ->alias('a')
 
-                     ->join('mate_goods b','b.id = a.items_id')
 
-                     ->where('a.todo_mate_id','in',array_column($todo_mate,'id'))
 
-                     ->field('a.*,b.title')
 
-                     ->select();
 
-                 foreach ($cons as $k1=>$v1){
 
-                     $pInfo = Db::name('mate_goods')
 
-                         ->where('id',$v1['pid'])
 
-                         ->find();
 
-                     $info['cons'][] = [
 
-                         'title' =>$v1['title'],
 
-                         'total' =>$v1['total'],
 
-                         'money' =>$v1['money'],
 
-                         'total_money' =>$v1['total_money'],
 
-                     ];
 
-                 }
 
-             }
 
-         }
 
-         $this->assign('info',$info);
 
-         return $this->fetch();
 
-     }
 
-     public function videoPlay(){
 
-         $src = input('url');
 
-         $this->assign('url',$src);
 
-         return $this->fetch();
 
-     }
 
-     //巡更任务列表
 
-     public function patrolList() {
 
-         $page = input('page',1);
 
-         $size = input('size',20);
 
-         $type = input('type',0);//巡更状态
 
-         $mode = input('mode',0);//巡更类型
 
-         $day = input('day',0);//日,月,总计
 
-         if($type==2){
 
-             $where[] = ['status','=',2];
 
-         }
 
-         if($type==3){
 
-             $where[] = ['status','=',3];
 
-         }
 
-         $where[] = ['org_id','=',$this->orgId];
 
-         $where[] = ['del','=',0];
 
-         if($day == 0){    //日订单
 
-             $where[] = ['create_yyyymmdd','=',date('Ymd')];
 
-         }else if($day == 1){  //月订单
 
-             $where[] = ['create_yyyymm','=',date('Ym')];
 
-         }else if($day == 2){  //总订单
 
-         }
 
-         //订单类型
 
-         if(in_array($mode,array(1,2,3,4))){
 
-             $where[] = ['patrol_mode','=',$mode];
 
-         }else{
 
-             $where[] = ['patrol_mode','>',0];
 
-         }
 
-         if($page > 1){
 
-             $list = Db::name('patrol_task')
 
-                 ->field('id,title,start_time,end_time,status,patrol_mode,org_id')
 
-                 ->where($where)
 
-                 ->order('id desc')
 
-                 ->page($page,$size)
 
-                 ->select();
 
-             foreach ($list as $k=>$v){
 
-                 $user = Db::name('patrol_task_user')
 
-                     ->alias('ptu')
 
-                     ->join('user u','u.id=ptu.user_id')
 
-                     ->where('ptu.patrol_task_id',$v['id'])
 
-                     ->column('u.real_name');
 
-                 $list[$k]['real_name']=$user?implode(',',$user):'';
 
-                 $dep = Db::name('patrol_task_user')
 
-                     ->alias('ptu')
 
-                     ->join('user_dep ud','ud.user_id=ptu.user_id')
 
-                     ->join('dep d','d.id=ud.dep_id')
 
-                     ->where('ptu.patrol_task_id',$v['id'])
 
-                     ->column('d.title');
 
-                 $list[$k]['dep']=$dep?implode(',',$dep):'';
 
-             }
 
-             HelpHander::success($list);
 
-         }else{
 
-             $list = Db::name('patrol_task')
 
-                 ->field('id,title,start_time,end_time,status,patrol_mode,org_id')
 
-                 ->where($where)
 
-                 ->order('id desc')
 
-                 ->page($page,$size)
 
-                 ->select();
 
-             foreach ($list as $k=>$v){
 
-                 $user = Db::name('patrol_task_user')
 
-                     ->alias('ptu')
 
-                     ->join('user u','u.id=ptu.user_id')
 
-                     ->where('ptu.patrol_task_id',$v['id'])
 
-                     ->column('u.real_name');
 
-                 $list[$k]['real_name']=$user?implode(',',$user):'';
 
-                 $dep = Db::name('patrol_task_user')
 
-                     ->alias('ptu')
 
-                     ->join('user_dep ud','ud.user_id=ptu.user_id')
 
-                     ->join('dep d','d.id=ud.dep_id')
 
-                     ->where('ptu.patrol_task_id',$v['id'])
 
-                     ->column('d.title');
 
-                 $list[$k]['dep']=$dep?implode(',',$dep):'';
 
-             }
 
-             $this->assign('list',$list);
 
-             $this->assign('mode',$mode);
 
-             $this->assign('type',$type);
 
-             $this->assign('day',$day);
 
-             $this->assign('orgId',$this->orgId);
 
-             return $this->fetch();
 
-         }
 
-     }
 
-     public function patrolDetails(){
 
-         $id = input('id',0);
 
-         $info = Db::name('patrol_task')
 
-             ->where('id',$id)
 
-             ->where('del',0)
 
-             ->find();
 
-         $info['interrupt_img']= $info['interrupt_img']?explode(',',$info['interrupt_img']):[];
 
-         $info['patrol_type']= Db::name('patrol_mode')->where('id',$info['patrol_mode'])->value('name');
 
-         //巡更人员
 
-         $taskUser= Db::name('patrol_task_user')
 
-             ->alias('ptu')
 
-             ->join('user u','u.id=ptu.user_id')
 
-             ->where('ptu.patrol_task_id',$info['id'])
 
-             ->column('u.real_name');
 
-         $info['patrol_user']=$taskUser?implode(',',$taskUser):'';
 
-         //巡更地点
 
-         $address = Db::name('patrol_task_addr')
 
-             ->alias('pta')
 
-             ->field('a.id,a.title,pta.id as patrol_form_id,pta.patrol_task_id')
 
- //            ->join('patrol_addr_form paf','paf.id=pta.patrol_form_id')
 
-             ->join('address a','a.id=pta.address_id')
 
-             ->where('pta.patrol_task_id',$id)
 
-             ->select();
 
-         foreach ($address as $kk=>$vv){
 
-             $record = Db::name('patrol_record')
 
-                 ->where('patrol_task_id',$vv['patrol_task_id'])
 
-                 ->where('patrol_addr_id',$vv['id'])
 
-                 ->where('patrol_addr_form_id',$vv['patrol_form_id'])
 
-                 ->find();
 
-             $address[$kk]['status'] = $record?1:0;
 
-         }
 
-         $info['patrol_address']=$address?$address:[];
 
-         $this->assign('info',$info);
 
-         return $this->fetch();
 
-     }
 
-     public function patrolSonDetails(){
 
-         $addrFormId = input('addrFormId',0);
 
-         $id = input('id',0);
 
-         $task = Db::name('patrol_task')
 
-             ->field('end_time,patrol_mode')
 
-             ->where('id',$id)
 
-             ->where('del',0)
 
-             ->find();
 
-         //巡更人员
 
-         $taskUser = Db::name('patrol_task_user')
 
-             ->alias('ptu')
 
-             ->join('user u','u.id=ptu.user_id')
 
-             ->where('ptu.patrol_task_id',$id)
 
-             ->column('u.real_name');
 
-         $info = Db::name('patrol_record')
 
-             ->field('images,content,check_json')
 
-             ->where('patrol_task_id',$id)
 
-             ->where('patrol_addr_form_id',$addrFormId)
 
-             ->find();
 
-         $info['img'] = $info['images']?explode(',',$info['images']):[];
 
-         $info['forms'] =$info['check_json']?json_decode($info['check_json'],true):[];
 
-         $info['patrol_user']=$taskUser?implode(',',$taskUser):'';
 
-         $info['patrol_time']=$task['end_time'];
 
-         $info['patrol_type']= Db::name('patrol_mode')->where('id',$task['patrol_mode'])->value('name');
 
-         $this->assign('info',$info);
 
-         return $this->fetch();
 
-     }
 
-     //用户列表
 
-     public function userList(){
 
-         $page = input('page',1);
 
-         $size = input('size',10);
 
-         $rolesId = input('rolesId',0);
 
-         if($page > 1){
 
-             if($rolesId == 0){
 
-                 $rolesIds =  Db::name('roles')
 
-                     ->whereIn('parent_id',[4,5,6,7,8,9,10,11])
 
-                     ->where('org_id',$this->orgId)
 
-                     ->where('del',0)
 
-                     ->where('enable',1)
 
-                     ->column('id');
 
-                 $list = Db::name('user')
 
-                     ->alias('u')
 
-                     ->field('u.id,u.real_name,u.head_image,u.create_time,u.mobile')
 
-                     ->join('user_roles ur','ur.user_id=u.id')
 
-                     ->where('u.del',0)
 
-                     ->where('u.enable',1)
 
-                     ->whereIn('ur.roles_id',$rolesIds)
 
-                     ->order('u.id desc')
 
-                     ->page($page,$size)
 
-                     ->select();
 
-             }else{
 
-                 $rolesIds =  Db::name('roles')
 
-                     ->where('parent_id',$rolesId)
 
-                     ->where('org_id',$this->orgId)
 
-                     ->where('del',0)
 
-                     ->where('enable',1)
 
-                     ->column('id');
 
-                 $list = Db::name('user')
 
-                     ->alias('u')
 
-                     ->field('u.id,u.real_name,u.head_image,u.create_time,u.mobile')
 
-                     ->join('user_roles ur','ur.user_id=u.id')
 
-                     ->where('u.del',0)
 
-                     ->where('u.enable',1)
 
-                     ->whereIn('ur.roles_id',$rolesIds)
 
-                     ->order('u.id desc')
 
-                     ->page($page,$size)
 
-                     ->select();
 
-             }
 
-             HelpHander::success($list);
 
-         }else{
 
-             if($rolesId == 0){
 
-                 $rolesIds =  Db::name('roles')
 
-                     ->whereIn('parent_id',[4,5,6,7,8,9,10,11])
 
-                     ->where('org_id',$this->orgId)
 
-                     ->where('del',0)
 
-                     ->where('enable',1)
 
-                     ->column('id');
 
-                 $list = Db::name('user')
 
-                     ->alias('u')
 
-                     ->field('u.id,u.real_name,u.head_image,u.create_time,u.mobile')
 
-                     ->join('user_roles ur','ur.user_id=u.id')
 
-                     ->where('u.del',0)
 
-                     ->where('u.enable',1)
 
-                     ->whereIn('ur.roles_id',$rolesIds)
 
-                     ->order('u.id desc')
 
-                     ->page($page,$size)
 
-                     ->select();
 
-             }else{
 
-                 $rolesIds =  Db::name('roles')
 
-                     ->where('parent_id',$rolesId)
 
-                     ->where('org_id',$this->orgId)
 
-                     ->where('del',0)
 
-                     ->where('enable',1)
 
-                     ->column('id');
 
-                 $list = Db::name('user')
 
-                     ->alias('u')
 
-                     ->field('u.id,u.real_name,u.head_image,u.create_time,u.mobile')
 
-                     ->join('user_roles ur','ur.user_id=u.id')
 
-                     ->where('u.del',0)
 
-                     ->where('u.enable',1)
 
-                     ->whereIn('ur.roles_id',$rolesIds)
 
-                     ->order('u.id desc')
 
-                     ->page($page,$size)
 
-                     ->select();
 
-             }
 
-         }
 
-         $this->assign('rolesId',$rolesId);
 
-         $this->assign('orgId',$this->orgId);
 
-         $this->assign('list',$list);
 
-         return $this->fetch();
 
-     }
 
-     public function commentList() {
 
-         $page = input('page',1);
 
-         $size = input('size',20);
 
-         $day = input('day',1);//日,月,总计
 
-         $mode = input('mode',0);
 
-         $where[] = ['o.del','=',0];
 
-         $where[] = ['o.org_id','=',$this->orgId];
 
-         $where[] = ['c.type','=',$mode];
 
-         if($day == 1){    //日订单
 
-             $where[] = ['c.create_yyyymmdd','=',date('Ymd')];
 
-         }else if($day == 2){  //月订单
 
-             $where[] = ['c.create_yyyymm','=',date('Ym')];
 
-         }
 
-         if($page > 1){
 
-             $list = Db::name('comment')
 
-                 ->alias('c')
 
-                 ->field('c.*')
 
-                 ->join('orders o','o.id=c.from_id')
 
-                 ->where($where)
 
-                 ->order('c.id desc')
 
-                 ->page($page,$size)
 
-                 ->select();
 
-             foreach ($list as $k=>$v){
 
-                 $list[$k]['user_name']= Db::name('user')->where('id',$v['user_id'])->value('real_name');
 
-             }
 
-             HelpHander::success($list);
 
-         }else{
 
-             $list = Db::name('comment')
 
-                 ->alias('c')
 
-                 ->field('c.*')
 
-                 ->join('orders o','o.id=c.from_id')
 
-                 ->where($where)
 
-                 ->order('c.id desc')
 
-                 ->page($page,$size)
 
-                 ->select();
 
-             foreach ($list as $k=>$v){
 
-                 $list[$k]['user_name']= Db::name('user')->where('id',$v['user_id'])->value('real_name');
 
-             }
 
-         }
 
-         $this->assign('list',$list);
 
-         $this->assign('day',$day);
 
-         $this->assign('mode',$mode);
 
-         $this->assign('orgId',$this->orgId);
 
-         return $this->fetch();
 
-     }
 
-     public function commentDetails(){
 
-         $id = input('id',0);
 
-         $info = Db::name('comment')->where('id',$id)->find();
 
-         $info['user_name'] = Db::name('user')->where('id',$info['user_id'])->value('real_name');
 
-         $this->assign('info',$info);
 
-         return $this->fetch();
 
-     }
 
-     //日常工作统计
 
-     public function dailyList() {
 
-         $page = input('page',1);
 
-         $size = input('size',20);
 
-         $day = input('day',0);//日,月,总计
 
-         if($day == 0){    //日订单
 
-             $where[] = ['create_yyyymmdd','=',date('Ymd')];
 
-         }else if($day == 1){  //月订单
 
-             $where[] = ['create_yyyymm','=',date('Ym')];
 
-         }
 
-         $where[] = ['org_id','=',$this->orgId];
 
-         $dailyIds = Db::name('daily_record')->where($where)->group('daily_id')->column('daily_id');
 
-         if($dailyIds){
 
-             $map[] = ['id','in',$dailyIds];
 
-         }else{
 
-             $map[] = ['id','in',[0]];
 
-         }
 
-         if($page>1){
 
-             $list = Db::name('daily')
 
-                 ->field('id,title,enable')
 
-                 ->where('org_id',$this->orgId)
 
-                 ->where($map)
 
-                 ->order('id desc')
 
-                 ->page($page,$size)
 
-                 ->select();
 
-             foreach ($list as $k=>$v){
 
-                 $user =  Db::name('daily_user')
 
-                     ->alias('du')
 
-                     ->join('user u','u.id=du.user_id')
 
-                     ->where('du.daily_id',$v['id'])
 
-                     ->where('u.del',0)
 
-                     ->where('u.enable',1)
 
-                     ->column('u.real_name');
 
-                 $list[$k]['work_user']=$user?implode(',',$user):'';
 
-             }
 
-             HelpHander::success($list);
 
-         }else{
 
-             $list = Db::name('daily')
 
-                 ->field('id,title,enable')
 
-                 ->where('org_id',$this->orgId)
 
-                 ->where($map)
 
-                 ->order('id desc')
 
-                 ->page($page,$size)
 
-                 ->select();
 
-             foreach ($list as $k=>$v){
 
-                 $user =  Db::name('daily_user')
 
-                     ->alias('du')
 
-                     ->join('user u','u.id=du.user_id')
 
-                     ->where('du.daily_id',$v['id'])
 
-                     ->where('u.del',0)
 
-                     ->where('u.enable',1)
 
-                     ->column('u.real_name');
 
-                 $list[$k]['work_user']=$user?implode(',',$user):'';
 
-             }
 
-         }
 
-         $this->assign('list',$list);
 
-         $this->assign('day',$day);
 
-         $this->assign('orgId',$this->orgId);
 
-         return $this->fetch();
 
-     }
 
-     public function dailyRecordList() {
 
-         $page = input('page',1);
 
-         $size = input('size',20);
 
-         $day = input('day',0);//日,月,总计
 
-         if($day == 0){    //日订单
 
-             $where[] = ['create_yyyymmdd','=',date('Ymd')];
 
-         }else if($day == 1){  //月订单
 
-             $where[] = ['create_yyyymm','=',date('Ym')];
 
-         }
 
-         $where[] = ['org_id','=',$this->orgId];
 
-         if($page>1){
 
-             $list = Db::name('daily_record')
 
-                 ->field('id,user_id,create_time,org_id')
 
-                 ->where($where)
 
-                 ->order('id desc')
 
-                 ->page($page,$size)
 
-                 ->select();
 
-             foreach ($list as $k=>$v){
 
-                 $list[$k]['user_name'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');
 
-             }
 
-             HelpHander::success($list);
 
-         }else{
 
-             $list = Db::name('daily_record')
 
-                 ->field('id,user_id,create_time,org_id')
 
-                 ->where($where)
 
-                 ->order('id desc')
 
-                 ->page($page,$size)
 
-                 ->select();
 
-             foreach ($list as $k=>$v){
 
-                 $list[$k]['user_name'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');
 
-             }
 
-         }
 
-         $this->assign('list',$list);
 
-         $this->assign('day',$day);
 
-         $this->assign('orgId',$this->orgId);
 
-         return $this->fetch();
 
-     }
 
-     public function dailyRecordDetails(){
 
-         $id = input('id',0);
 
-         $info = Db::name('daily_record')->where('id',$id)->find();
 
-         $info['img'] = $info['images']?explode(',',$info['images']):[];
 
-         //任务内容
 
-         $daily = Db::name('daily')->where('id',$info['daily_id'])->find();
 
-         $info['daily_content'] = $daily['content'] ? $daily['content']:'';
 
-         $info['daily_title'] = $daily['title'] ? $daily['title']:'';
 
-         $info['user_name'] = Db::name('user')->where('id',$info['user_id'])->value('real_name');
 
-         $info['forms'] = json_decode($info['check_json'],true);
 
-         $this->assign('info',$info);
 
-         return $this->fetch();
 
-     }
 
-     //设备台账统计
 
-     public function deviceList() {
 
-         $page = input('page',1);
 
-         $size = input('size',20);
 
-         $day = input('day',0);//日,月,总计
 
-         if($day == 0){    //日订单
 
-             $where[] = ['create_yyyymmdd','=',date('Ymd')];
 
-         }else if($day == 1){  //月订单
 
-             $where[] = ['create_yyyymm','=',date('Ym')];
 
-         }
 
-         $where[] = ['org_id','=',$this->orgId];
 
-         $deviceIds = Db::name('device_record')->where($where)->group('device_id')->column('device_id');
 
-         if($deviceIds){
 
-             $map[] = ['id','in',$deviceIds];
 
-         }else{
 
-             $map[] = ['id','in',[0]];
 
-         }
 
-         if($page>1){
 
-             $list = Db::name('device')
 
-                 ->field('id,title,enable')
 
-                 ->where('org_id',$this->orgId)
 
-                 ->where($map)
 
-                 ->order('id desc')
 
-                 ->page($page,$size)
 
-                 ->select();
 
-             foreach ($list as $k=>$v){
 
-                 $user =  Db::name('device_user')
 
-                     ->alias('du')
 
-                     ->join('user u','u.id=du.user_id')
 
-                     ->where('du.device_id',$v['id'])
 
-                     ->where('u.del',0)
 
-                     ->where('u.enable',1)
 
-                     ->column('u.real_name');
 
-                 $list[$k]['work_user']=$user?implode(',',$user):'';
 
-             }
 
-             HelpHander::success($list);
 
-         }else{
 
-             $list = Db::name('device')
 
-                 ->field('id,title,enable')
 
-                 ->where('org_id',$this->orgId)
 
-                 ->where($map)
 
-                 ->order('id desc')
 
-                 ->page($page,$size)
 
-                 ->select();
 
-             foreach ($list as $k=>$v){
 
-                 $user =  Db::name('device_user')
 
-                     ->alias('du')
 
-                     ->join('user u','u.id=du.user_id')
 
-                     ->where('du.device_id',$v['id'])
 
-                     ->where('u.del',0)
 
-                     ->where('u.enable',1)
 
-                     ->column('u.real_name');
 
-                 $list[$k]['work_user']=$user?implode(',',$user):'';
 
-             }
 
-         }
 
-         $this->assign('list',$list);
 
-         $this->assign('day',$day);
 
-         $this->assign('orgId',$this->orgId);
 
-         return $this->fetch();
 
-     }
 
-     public function deviceRecordList() {
 
-         $page = input('page',1);
 
-         $size = input('size',20);
 
-         $day = input('day',0);//日,月,总计
 
-         if($day == 0){    //日订单
 
-             $where[] = ['create_yyyymmdd','=',date('Ymd')];
 
-         }else if($day == 1){  //月订单
 
-             $where[] = ['create_yyyymm','=',date('Ym')];
 
-         }
 
-         $where[] = ['org_id','=',$this->orgId];
 
-         if($page>1){
 
-             $list = Db::name('device_record')
 
-                 ->field('id,user_id,create_time,org_id')
 
-                 ->where($where)
 
-                 ->order('id desc')
 
-                 ->page($page,$size)
 
-                 ->select();
 
-             foreach ($list as $k=>$v){
 
-                 $list[$k]['user_name'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');
 
-             }
 
-             HelpHander::success($list);
 
-         }else{
 
-             $list = Db::name('device_record')
 
-                 ->field('id,user_id,create_time,org_id')
 
-                 ->where($where)
 
-                 ->order('id desc')
 
-                 ->page($page,$size)
 
-                 ->select();
 
-             foreach ($list as $k=>$v){
 
-                 $list[$k]['user_name'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');
 
-             }
 
-         }
 
-         $this->assign('list',$list);
 
-         $this->assign('day',$day);
 
-         $this->assign('orgId',$this->orgId);
 
-         return $this->fetch();
 
-     }
 
-     public function deviceRecordDetails(){
 
-         $id = input('id',0);
 
-         $info = Db::name('device_record')->where('id',$id)->find();
 
-         $info['img'] = $info['images']?explode(',',$info['images']):[];
 
-         //任务内容
 
-         $daily = Db::name('device')->where('id',$info['device_id'])->find();
 
-         $info['device_content'] = $daily['content'] ? $daily['content']:'';
 
-         $info['device_title'] = $daily['title'] ? $daily['title']:'';
 
-         $info['user_name'] = Db::name('user')->where('id',$info['user_id'])->value('real_name');
 
-         $info['forms'] = json_decode($info['check_json'],true);
 
-         $this->assign('info',$info);
 
-         return $this->fetch();
 
-     }
 
-     public function complain(){
 
-         $type = input('type',0);
 
-         $week = Time::week();
 
-         $sw = date('Ymd',$week[0]);
 
-         $ew = date('Ymd',$week[1]);
 
-         if($type == 0){
 
-             $map[] = ['create_yyyymmdd','>=',$sw];
 
-             $map[] = ['create_yyyymmdd','<=',$ew];
 
-         }elseif ($type == 1){
 
-             $map[] = ['create_yyyymm','=',date('Ym')];
 
-         }
 
-         $map[] = ['org_id','=',$this->orgId];
 
-         $map[] = ['del','=',0];
 
-         $data = [
 
-             ['name'=>'已处理','status'=>2],
 
-             ['name'=>'处理中','status'=>1],
 
-             ['name'=>'待处理','status'=>0],
 
-         ];
 
-         foreach ($data as $k=>$v){
 
-             $count = 0;
 
-             if($v['status'] == 2){
 
-                 $complain =  Db::name('complain')->where($map)->select();
 
-                 foreach ($complain as $kk=>$vv){
 
-                     if($vv['status'] == 1 && $vv['order_id'] > 0){
 
-                         $order = Db::name('orders')->where('id',$vv['order_id'])->find();
 
-                         if(in_array($order['order_mode'],[3,5,6])){
 
-                             $count +=1;
 
-                         }
 
-                     }elseif ($vv['status'] == 1 && $vv['order_id'] == 0){
 
-                            $count +=1;
 
-                     }
 
-                 }
 
-             }elseif ($v['status'] == 1){
 
-                 $complain =  Db::name('complain')->where($map)->select();
 
-                 foreach ($complain as $kk=>$vv){
 
-                     if($vv['status'] == 1 && $vv['order_id'] > 0){
 
-                         $order = Db::name('orders')->where('id',$vv['order_id'])->find();
 
-                         if(!in_array($order['order_mode'],[3,5,6])){
 
-                             $count +=1;
 
-                         }
 
-                     }
 
-                 }
 
-             }elseif ($v['status'] == 0){
 
-                 $count =  Db::name('complain')->where($map)->where('status',0)->count();
 
-             }
 
-             $data[$k]['cost'] = $count;
 
-         }
 
-         $count =  Db::name('complain')->where($map)->count();
 
-         $this->assign('list',$data);
 
-         $this->assign('count',$count);
 
-         $this->assign('orgId',$this->orgId);
 
-         $this->assign('type',$type);
 
-         return $this->fetch();
 
-     }
 
-     public function complainList(){
 
-         $type = input('type/d',0);
 
-         $status= input('status',-1);
 
-         $week = Time::week();
 
-         $sw = date('Ymd',$week[0]);
 
-         $ew = date('Ymd',$week[1]);
 
-         if($type == 0){
 
-             $map[] = ['create_yyyymmdd','>=',$sw];
 
-             $map[] = ['create_yyyymmdd','<=',$ew];
 
-         }elseif ($type == 1){
 
-             $map[] = ['create_yyyymm','=',date('Ym')];
 
-         }
 
-         $map[] = ['org_id','=',$this->orgId];
 
-         $map[] = ['del','=',0];
 
-         $list = [];
 
-         if($status == 0){
 
-             $list =  Db::name('complain')->where($map)->where('status',0)->order('id desc')->select();
 
-             foreach ($list as $k=>$v){
 
-                 $list[$k]['statusTxt'] = '待处理';
 
-             }
 
-         }elseif ($status == -1){
 
-             $list = Db::name('complain')->where($map)->order('id desc')->select();
 
-             foreach ($list as $k=>$v){
 
-                 $statusTxt = '';
 
-                 if($v['status'] == 1 && $v['order_id'] == 0){
 
-                     $statusTxt = '已处理';
 
-                 }elseif($v['status'] == 1 && $v['order_id'] > 0){
 
-                     $order = Db::name('orders')->where('id',$v['order_id'])->find();
 
-                     if(in_array($order['order_mode'],[3,5,6])){
 
-                         $statusTxt = '已处理';
 
-                     }else{
 
-                         $statusTxt = '处理中';
 
-                     }
 
-                 }elseif($v['status'] == 0){
 
-                     $statusTxt = '待处理';
 
-                 }
 
-                 $list[$k]['statusTxt'] = $statusTxt;
 
-             }
 
-         } else{
 
-             $complain =  Db::name('complain')->where($map)->select();
 
-             foreach ($complain as $k=>$v){
 
-                 $statusTxt = '';
 
-                 if($v['status'] == 1 && $v['order_id'] == 0){
 
-                     $statusTxt = '已处理';
 
-                 }else if($v['status'] == 1 && $v['order_id'] > 0){
 
-                     $order = Db::name('orders')->where('id',$v['order_id'])->find();
 
-                     if(in_array($order['order_mode'],[3,5,6])){
 
-                         $statusTxt = '已处理';
 
-                     }else{
 
-                         $statusTxt = '处理中';
 
-                     }
 
-                 }elseif($v['status'] == 0){
 
-                     $statusTxt = '待处理';
 
-                 }
 
-                 $complain[$k]['statusTxt'] = $statusTxt;
 
-             }
 
-             foreach ($complain as $k=>$v){
 
-                 if($status == 2){
 
-                     if($v['status'] == 1 && $v['order_id'] > 0){
 
-                         $order = Db::name('orders')->where('id',$v['order_id'])->find();
 
-                         if(in_array($order['order_mode'],[3,5,6])){
 
-                             $list[$k] = $v;
 
-                         }
 
-                     }elseif($v['status'] == 1 && $v['order_id'] == 0){
 
-                         $list[$k] = $v;
 
-                     }
 
-                 }elseif ($status == 1){
 
-                     if($v['status'] == 1 && $v['order_id'] > 0){
 
-                         $order = Db::name('orders')->where('id',$v['order_id'])->find();
 
-                         if(!in_array($order['order_mode'],[3,5,6])){
 
-                             $list[$k] = $v;
 
-                         }
 
-                     }
 
-                 }
 
-             }
 
-         }
 
-         foreach ($list as $k=>$v){
 
-             if($v['hide'] == 1){
 
-                 $list[$k]['user_name'] = '匿名';
 
-             }else{
 
-                 $list[$k]['user_name'] = Db::name('user')->where('id',$v['create_user_id'])->value('real_name');
 
-             }
 
-         }
 
-         $this->assign('list',$list);
 
-         $this->assign('orgId',$this->orgId);
 
-         $this->assign('type',$type);
 
-         return $this->fetch();
 
-     }
 
-     public function complainDetail(){
 
-         $id = input('id',0);
 
-         $info = Db::name('complain')->where('id',$id)->find();
 
-         $info['images'] = !empty($info['images'])?explode(',',$info['images']):[];
 
-         $info['create_time'] = date('Y-m-d H:i',strtotime($info['create_time']));
 
-         $statusTxt = '';
 
-         if($info['status'] == 1 && $info['order_id'] == 0){
 
-             $statusTxt = '已处理';
 
-         }elseif($info['status'] == 1 && $info['order_id'] > 0){
 
-             $order = Db::name('orders')->where('id',$info['order_id'])->find();
 
-             if(in_array($order['order_mode'],[3,5,6])){
 
-                 $statusTxt = '已处理';
 
-             }else{
 
-                 $statusTxt = '处理中';
 
-             }
 
-         }elseif($info['status'] == 0){
 
-             $statusTxt = '待处理';
 
-         }
 
-         $info['statusTxt'] = $statusTxt;
 
-         if($info['hide'] == 1){
 
-             $info['user_name'] = '匿名';
 
-             $info['mobile'] = '';
 
-         }else{
 
-             $info['user_name'] = Db::name('user')->where('id',$info['create_user_id'])->value('real_name');
 
-             $info['mobile'] = Db::name('user')->where('id',$info['create_user_id'])->value('mobile');
 
-         }
 
-         $info['dep_name'] = db('dep')->where('id',$info['dep_id'])->value('title');
 
-         $this->assign('info',$info);
 
-         return $this->fetch();
 
-     }
 
-     public function waste() {
 
-         $type = input('type/d',0);
 
-         $map[] = ['org_id','=',$this->orgId];
 
-         if($type == 0){ //日统计
 
-             $map[] = ['create_yyyymmdd','=',date('Ymd')];
 
-         } else if($type == 1){ //月统计
 
-             $map[] = ['create_yyyymm','=',date('Ym')];
 
-         }
 
-         $map[] = ['del','=',0];
 
-         $wasteTypes = model("WasteType")->list1($this->orgId);
 
-         foreach ($wasteTypes as $k=>$v){
 
-             $count = Db::name('waste_record')->where($map)->where('cateid',$v['waste_id'])->sum('weight');
 
-             $wasteTypes[$k]['count'] = round($count/1000,2)."kg";
 
-             if($v['type'] == 1){
 
-                 $count = Db::name('waste_record')->where($map)->where('cateid',$v['waste_id'])->sum('num');
 
-                 $wasteTypes[$k]['count'] = round($count/1000,2)."kg".'('.$count.$v['unit'].')';
 
-             }
 
-         }
 
-         $this->assign('wasteTypes',$wasteTypes);
 
-         $this->assign('orgId',$this->orgId);
 
-         $this->assign('type',$type);
 
-         return $this->fetch();
 
-     }
 
- }
 
 
  |