| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364 | 
							- <?php
 
- namespace app\admin\controller;
 
- use think\App;
 
- use think\Db;
 
- use think\Exception;
 
- class CleanPlanRecord extends Auth
 
- {
 
-     public function __construct(App $app = null) {
 
-         parent::__construct($app);
 
-         $this->model= new \app\common\model\CleanPlanRecord();
 
-         $this->table= $this->model->table;
 
-     }
 
-     public function index($id=0){
 
-         if(request()->isAjax()){
 
-             //分页参数
 
-             $length = input('rows',10,'intval');   //每页条数
 
-             $page = input('page',1,'intval');      //第几页
 
-             $start = ($page - 1) * $length;     //分页开始位置
 
-             //排序
 
-             $sortRow = input('sidx','id','trim');      //排序列
 
-             $sort = input('sord','desc','trim');        //排序方式
 
-             $order = $sortRow.' '.$sort;
 
-             $title = input('title','','trim');
 
-             if($title){
 
-                 $map[] = ['title','like','%'.$title.'%'];
 
-             }
 
-             $enable = input('enable','','trim');
 
-             if($enable != ''){
 
-                 $map[] = ['enable','=',$enable];
 
-             }
 
-             $formId = input('formId','','trim');
 
-             if($formId != ''){
 
-                 $map[] = ['form_id','=',$formId];
 
-             }
 
-             $addrId = input('addrId','','trim');
 
-             if($addrId != ''){
 
-                 $map[] = ['address_id','=',$addrId];
 
-             }
 
-             $map[] = ['del','=',0];
 
-             $map[] = ['org_id','=',$this->orgId];
 
-             $map[] = ['plan_id','=',$id];
 
-             $map= empty($map) ? true: $map;
 
-             //数据查询
 
-             $lists = db($this->table)->where($map)->limit($start,$length)->order($order)->select();
 
-             foreach ($lists as $k=>$v){
 
-                 $ftitle = Db::name('clean_type')->where('id',$v['form_id'])->value('title');
 
-                 $atitle = Db::name('address')->where('id','in',explode(',',$v['address_id']))->select();
 
-                 $lists[$k]['form_title'] = $ftitle;
 
-                 $lists[$k]['addr_title'] = $atitle?implode(',',array_column($atitle,'title')):"";
 
-             }
 
-             //数据返回
 
-             $totalCount = db($this->table)->where($map)->count();
 
-             $totalPage = ceil($totalCount/$length);
 
-             $result['page'] = $page;
 
-             $result['total'] = $totalPage;
 
-             $result['records'] = $totalCount;
 
-             $result['rows'] = $lists;
 
-             return json($result);
 
-         }else{
 
-             $pinfo = Db::name('clean_plan')->where('id',$id)->find();
 
-             $this->assign('pinfo',$pinfo);
 
-             $ptitle = Db::name('clean_plan')->where('id',$pinfo['pid'])->value('title');
 
-             $this->assign('m_name','['.$ptitle.']'.$pinfo['month'].'日计划');
 
-             $forms = $pinfo['forms']?explode(',',$pinfo['forms']):[];
 
-             $addrs = $pinfo['addrs']?explode(',',$pinfo['addrs']):[];
 
-             $typs = (new \app\common\model\CleanType())->getList();
 
-             $address = (new \app\common\model\Address())->getListByType(8);
 
-             foreach ($typs as $k=>$v){
 
-                 if(!in_array($v['id'],$forms)){
 
-                     unset($typs[$k]);
 
-                 }
 
-             }
 
-             foreach ($address as $k=>$v){
 
-                 if(!in_array($v['id'],$addrs)){
 
-                     unset($address[$k]);
 
-                 }
 
-             }
 
-             $this->assign('type',$typs?$typs:[]);
 
-             $this->assign('address',$address?$address:[]);
 
-             return $this->fetch();
 
-         }
 
-     }
 
-     /**
 
-      * 新增
 
-      */
 
-     public function add($id=0,$plan_id=0){
 
-         if(request()->isPost()){
 
-             $res = $this->model->addSave();
 
-             if($res){
 
-                 $this->success('操作成功',url('index'));
 
-             }else{
 
-                 $this->error($this->model->getError());
 
-             }
 
-         }else{
 
-             $pinfo = Db::name('clean_plan')->where('id',$plan_id)->find();
 
-             if($id > 0){
 
-                 $info = Db::name($this->table)->where('id',$id)->find();
 
-                 if($info){
 
-                     $plan_id = $info['plan_id'];
 
-                 }
 
-             }else{
 
-                 $info['start'] = $pinfo['month'].'-01';
 
-                 $info['end'] = $pinfo['month'].'-01';
 
-             }
 
-             $this->assign('info',$info);
 
-             $this->assign('plan_id',$plan_id);
 
-             $forms = $pinfo['forms']?explode(',',$pinfo['forms']):[];
 
-             $addrs = $pinfo['addrs']?explode(',',$pinfo['addrs']):[];
 
-             $uids = $pinfo['user']?explode(',',$pinfo['user']):[];
 
-             $typs = (new \app\common\model\CleanType())->getList();
 
-             $address = (new \app\common\model\Address())->getListByType(8);
 
-             foreach ($typs as $k=>$v){
 
-                 if(!in_array($v['id'],$forms)){
 
-                     unset($typs[$k]);
 
-                 }
 
-             }
 
-             foreach ($address as $k=>$v){
 
-                 if(!in_array($v['id'],$addrs)){
 
-                     unset($address[$k]);
 
-                 }
 
-             }
 
-             $users = (new \app\common\model\User())->getCleanWorker();
 
-             $nuser = [];
 
-             foreach ($users as $k=>$v){
 
-                 if(in_array($v['id'],$uids)){
 
-                     $nuser[] = $v;
 
-                 }
 
-             }
 
-             $this->assign('user',$nuser);
 
-             $this->assign('type',$typs?$typs:[]);
 
-             $this->assign('address',$address?$address:[]);
 
-             return $this->fetch();
 
-         }
 
-     }
 
-     /**
 
-      * 新增
 
-      */
 
-     public function edit($id=0){
 
-         if(request()->isPost()){
 
-             $res = $this->model->editSave();
 
-             if($res){
 
-                 $this->success('操作成功',url('index'));
 
-             }else{
 
-                 $this->error($this->model->getError());
 
-             }
 
-         }else{
 
-             if($id > 0){
 
-                 $info = Db::name($this->table)->where('id',$id)->find();
 
-                 if($info){
 
-                     $plan_id = $info['plan_id'];
 
-                     $uids = Db::name('clean_plan_user')->where('record_id',$info['id'])->column('user_id');
 
-                     $info['user'] = $uids?$uids:[];
 
-                     $info['address_id'] = $info['address_id']?explode(',',$info['address_id']):[];
 
-                 }
 
-                 $this->assign('info',$info);
 
-             }
 
-             $this->assign('plan_id',$plan_id);
 
-             $pinfo = Db::name('clean_plan')->where('id',$plan_id)->find();
 
-             $forms = $pinfo['forms']?explode(',',$pinfo['forms']):[];
 
-             $addrs = $pinfo['addrs']?explode(',',$pinfo['addrs']):[];
 
-             $uids = $pinfo['user']?explode(',',$pinfo['user']):[];
 
-             $typs = (new \app\common\model\CleanType())->getList();
 
-             $address = (new \app\common\model\Address())->getListByType(8);
 
-             foreach ($typs as $k=>$v){
 
-                 if(!in_array($v['id'],$forms)){
 
-                     unset($typs[$k]);
 
-                 }
 
-             }
 
-             foreach ($address as $k=>$v){
 
-                 if(!in_array($v['id'],$addrs)){
 
-                     unset($address[$k]);
 
-                 }
 
-             }
 
-             $users = (new \app\common\model\User())->getCleanWorker();
 
-             $nuser = [];
 
-             foreach ($users as $k=>$v){
 
-                 if(in_array($v['id'],$uids)){
 
-                     $nuser[] = $v;
 
-                 }
 
-             }
 
-             $this->assign('user',$nuser);
 
-             $this->assign('type',$typs?$typs:[]);
 
-             $this->assign('address',$address?$address:[]);
 
-             return $this->fetch();
 
-         }
 
-     }
 
-     /**
 
-      * 删除记录
 
-      * @param int $id
 
-      */
 
-     public function del($id=0){
 
-         if(!$id){
 
-             $this->error('参数错误');
 
-         }
 
-         $res = db($this->table)->where('id',$id)->setField('del',1);
 
-         if($res){
 
-             $this->success('删除成功');
 
-         }else{
 
-             $this->error('删除失败');
 
-         }
 
-     }
 
-     /**
 
-      * 改变字段值
 
-      * @param int $fv
 
-      * @param string $fn
 
-      * @param int $fv
 
-      */
 
-     public function changeField($id=0,$fn='',$fv=0){
 
-         if(!$fn||!$id){
 
-             $this->error('参数错误');
 
-         }
 
-         $res = db($this->table)->where('id',$id)->setField($fn,$fv);
 
-         if($res){
 
-             $this->success('操作成功');
 
-         }else{
 
-             $this->error('操作失败');
 
-         }
 
-     }
 
-     public function calendar(){
 
-         $m = input('month','');
 
-         $curMonth = input('month',date('Y-m'));
 
-         $this->assign('curMonth',$curMonth);
 
-         $back = 0;
 
-         $year = '';
 
-         if($m){
 
-             $back = 1;
 
-             list($year,$y1) = explode('-',$m);
 
-         }
 
-         $this->assign('back',$back);
 
-         $this->assign('year',$year);
 
-         return $this->fetch();
 
-     }
 
-     public function calendardata(){
 
-         $start = input('start');
 
-         $end = input('end');
 
-         $data = array();
 
-         if(!$start||!$end||$start>$end){
 
-             header('Content-Type:application/json; charset=utf-8');
 
-             exit(json_encode($data));
 
-         }
 
-         $start = date('Y-m-d H:i:s',strtotime($start));
 
-         $end = date('Y-m-d H:i:s',strtotime($end));
 
-         $map[] = [''];
 
-         $list = (new \app\common\model\CleanPlanRecord())->get_list_by_time($this->orgId,$start,$end);
 
-         foreach ($list as $k=>$v){
 
-             $arr = array(
 
-                 'taskid' => $v['id'],
 
-                 'title' => "任务项:{$v['ftitle']}<br>地点:{$v['atitle']}<br>开始时间:{$v['start']}<br>结束时间:{$v['end']}<br>",
 
-                 'status' => $v['enable'],
 
-                 'start' => $v['start'].' 00:00:00',
 
-                 'end' => $v['end'].' 23:59:59'
 
-             );
 
-             if($v['enable'] == 0){
 
-                 $arr['color'] = '#478fca';
 
-             }else{
 
-                 $arr['color'] = '#69aa46';
 
-             }
 
- //            if($v['status'] == 0){
 
- //                $arr['color'] = '#777777';
 
- //            }else if($v['status'] == 1){
 
- //                $arr['color'] = '#478fca';
 
- //            }else if($v['status'] == 2){
 
- //                $arr['color'] = '#69aa46';
 
- //            }else if($v['status'] == 3){
 
- //                $arr['color'] = '#dd5a43';
 
- //            }else if($v['status'] == 5){
 
- //                $arr['color'] = '#53a2a7';
 
- //            }else{
 
- //                $arr['color'] = '#5b53a7';
 
- //            }
 
-             $data[] = $arr;
 
-         }
 
-         header('Content-Type:application/json; charset=utf-8');
 
-         exit(json_encode($data));
 
-     }
 
-     public function year(){
 
-         $year = input('year',date('Y'));
 
-         $month = [];
 
-         for ($i=1;$i<=12;$i++){
 
-             if($i>10){
 
-                 $a = $i;
 
-             }else{
 
-                 $a='0'.$i;
 
-             }
 
-             $month[] = $year.'-'.$a;
 
-         }
 
-         $list = [];
 
-         foreach ($month as $k=>$v){
 
-             $c = $c1 = $c2 = 0;
 
-             $plan =Db::name('clean_plan')
 
-                 ->where('del',0)
 
-                 ->where('enable',1)
 
-                 ->where('org_id',$this->orgId)
 
-                 ->where('month',$v)
 
-                 ->find();
 
-             if($plan){
 
-                 $c = Db::name('clean_plan_record')
 
-                     ->where('plan_id',$plan['id'])
 
-                     ->where('del',0)->count();
 
-                 $c1 = Db::name('clean_plan_record')
 
-                     ->where('plan_id',$plan['id'])
 
-                     ->where('del',0)
 
-                     ->where('enable',0)
 
-                     ->count();
 
-                 $c2 = Db::name('clean_plan_record')
 
-                     ->where('plan_id',$plan['id'])
 
-                     ->where('del',0)
 
-                     ->where('enable',1)
 
-                     ->count();
 
-             }
 
-             $list[] = [
 
-                 'title'=>$v,
 
-                 'count'=>$c,
 
-                 'count1'=>$c1,
 
-                 'count2'=>$c2,
 
-             ];
 
-         }
 
-         $this->assign('lists',$list);
 
-         $this->assign('last',$year+1);
 
-         $this->assign('prv',$year-1);
 
-         return $this->fetch();
 
-     }
 
-     public function detail($id = 0){
 
-         $info = $this->model->detail($id,$this->orgId);
 
-         if($info){
 
-             $info['imgs'] = $info['imgs']?explode(',',$info['imgs']):[];
 
-         }
 
-         $this->assign('info',$info);
 
-         return $this->fetch();
 
-     }
 
- }
 
 
  |