1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150 |
- <?php
- namespace app\admin\controller;
- use app\common\model\Task;
- use app\common\model\User;
- use app\common\util\ExcelUtil;
- use think\App;
- use think\Db;
- use think\Exception;
- class PatrolTask extends Auth
- {
- public function index($mode){
- if(request()->isAjax()){
- //分页参数
- $length = input('rows',10,'intval'); //每页条数
- $page = input('page',1,'intval'); //第几页
- $start = ($page - 1) * $length; //分页开始位置
- //排序
- $sortRow = input('sidx','sort','trim'); //排序列
- $sort = input('sord','asc','trim'); //排序方式
- $order = $sortRow.' '.$sort.' ,id desc';
- $month= input('month','','trim');
- if($month != ''){
- $map[] = ['create_yyyymm','=',$month];
- }
- $title = input('title','','trim');
- if($title){
- $map[] = ['title','like','%'.$title.'%'];
- }
- $status = input('status','','trim');
- if($status != ''){
- $map[] = ['status','=',$status];
- }
- $is_exception = input('is_exception','','trim');
- if($is_exception != ''){
- $map[] = ['is_exception','=',$is_exception];
- }
- $plan_id = input('plan_id','','trim');
- if($plan_id != ''){
- $map[] = ['plan_id','=',$plan_id];
- }
- $cate_id = input('cate_id','','trim');
- if($cate_id != ''){
- $map[] = ['cate_id','=',$cate_id];
- }
- $map[] = ['org_id','=',$this->orgId];
- $map[] =['del','=',0];
- $map[] =['patrol_mode','=',$mode];
- $map= empty($map) ? true: $map;
- //数据查询
- $lists = Db::name('patrol_task')
- ->where($map)
- ->limit($start,$length)
- ->order('start_time desc,id desc')
- // ->order($order)
- ->select();
- foreach ($lists as $k=>$v){
- $lists[$k]['start_time'] = date('Y-m-d H:i',strtotime($v['start_time']));
- $lists[$k]['end_time'] = date('Y-m-d H:i',strtotime($v['end_time']));
- $taskUser=Db::name('patrol_task_user')
- ->alias('ptu')
- ->field('u.real_name')
- ->join('user u','u.id=ptu.user_id')
- ->where('ptu.patrol_task_id',$v['id'])
- ->select();
- $userName = [];
- foreach ($taskUser as $kk=>$vv){
- $userName[$kk]=$vv['real_name'];
- }
- $lists[$k]['task_user']=implode(',',$userName);
- $lists[$k]['time'] = 0;
- $time = Db::name('patrol_record')->where('patrol_task_id',$v['id'])->where('time',1)->find();
- if($time){
- $lists[$k]['time'] = 1;
- }
- $lists[$k]['cateName'] = $v['cate_id']?implode(',',Db::name('patrol_cate')
- ->where('id','in',explode(',',$v['cate_id']))
- ->column('title')):'';
- }
- //数据返回
- $totalCount = Db::name('patrol_task')->where($map)->count();
- $totalPage = ceil($totalCount/$length);
- $result['page'] = $page;
- $result['total'] = $totalPage;
- $result['records'] = $totalCount;
- $result['rows'] = $lists;
- return json($result);
- }else{
- $plans = model('PatrolPlan')->getListByMode($this->orgId,$mode);
- $this->assign('plans',$plans);
- $this->assign('mode',$mode);
- $modeName = (new \app\common\model\PatrolAddrForm())->getModeTitle($mode);
- $this->assign('meta_title',$modeName.'任务列表');
- $cate = model('PatrolCate')->getByModeList($mode);
- $this->assign('cate',$cate);
- return $this->fetch();
- }
- }
- /**
- * 新增/编辑
- */
- public function add($id=0,$mode){
- $type = input('type');
- $isCalendar = input('isCalendar');
- if(request()->isPost()){
- $model = new \app\common\model\PatrolTask();
- $res = $model->updates($mode);
- if($res){
- if($type==1){
- if($isCalendar==1){
- $this->success('操作成功',url('calendar',['mode'=>$mode]));
- }else{
- $this->success('操作成功');
- }
- }else{
- $this->success('操作成功',url('index',['mode'=>$mode]));
- }
- }else{
- $this->error($model->getError());
- }
- }else{
- $modeName = (new \app\common\model\PatrolAddrForm())->getModeTitle($mode);
- $meta_title = '新增'.$modeName.'计划';
- if($id){
- $info = Db::name('patrol_task')->where('id',$id)->find();
- $info['start_time']=date('Y-m-d H:i',strtotime($info['start_time']));
- $info['end_time']=date('Y-m-d H:i',strtotime($info['end_time']));
- $info['lines']=$info['lines']?json_decode($info['lines'],true):[];
- $info['patrol_form'] =\db('patrol_task_addr')
- ->where('patrol_task_id',$id)
- ->column('patrol_form_id');
- $info['task_user']=\db('patrol_task_user')
- ->where('patrol_task_id',$id)
- ->column('user_id');
- // $addrForms = Db::name('patrol_task_addr')
- // ->alias('a')
- // ->join('patrol_addr_form b','a.patrol_form_id = b.id')
- // ->join('address c','c.id = a.address_id')
- // ->where('a.patrol_task_id',$info['id'])
- // ->field('a.address_id as addrId,a.patrol_form_id as formId,b.title as formTitle,c.title as addrTitle')
- // ->select();
- // $info['addrForms'] = $addrForms?$addrForms:[];
- $addrForms = Db::name('patrol_task_addr')
- ->alias('a')
- ->join('address c','c.id = a.address_id')
- ->where('a.patrol_task_id',$info['id'])
- ->field('a.address_id as addrId,a.sorts,c.title as addrTitle,a.patrol_forms')
- ->order(['a.sorts'=>'asc','a.id'=>'desc'])
- ->select();
- $addrForms = $addrForms?$addrForms:[];
- foreach ($addrForms as $k=>$v){
- $forms = [];
- if($v['patrol_forms']){
- $forms = Db::name('patrol_addr_form')->where('id','in',$v['patrol_forms'])->field('id,title')->select();
- }
- $addrForms[$k]['forms'] = $forms?$forms:[];
- }
- $info['addrForms'] = $addrForms?$addrForms:[];
- $info['cate_id'] = $info['cate_id']?explode(',',$info['cate_id']):[];
- $this->assign('info',$info);
- $meta_title = '编辑'.$modeName.'计划';
- }
- //获取任务内容
- $patrolAddrForm=(new \app\common\model\PatrolAddrForm())->getByModeList($mode);
- //获取用户
- switch ($mode){
- case 1:
- $pType=5;
- break;
- case 2:
- $pType=6;
- break;
- case 3:
- $pType=7;
- break;
- case 4:
- $pType=8;
- break;
- }
- $user=(new User())->getPatrolWorker($pType);
- $start = input('start','');
- $end = input('end','');
- $this->assign('patrolForm',$patrolAddrForm);
- $this->assign('user',$user);
- $this->assign('mode',$mode);
- $this->assign('start',$start?date('Y-m-d H:i',strtotime($start)):'');
- $this->assign('end',$end?date('Y-m-d H:i',strtotime($end)):'');
- $this->assign('meta_title',$meta_title);
- $this->assign('type',$type);
- $this->assign('isCalendar',$isCalendar);
- $this->assign('address',(new \app\common\model\Address())->getListByType($mode+2));
- $cate = model('PatrolCate')->getByModeList($mode);
- $this->assign('cateList',$cate);
- return $this->fetch();
- }
- }
- /**
- * 删除记录
- */
- public function del($id=0){
- if(!$id){
- $this->error('参数错误');
- }
- $info = Db::name('patrol_task')->where('org_id',$this->orgId)->where('id',$id)->where('del',0)->find();
- if(!$info){
- $this->error('任务不存在');
- }
- if($info['status'] != 6){
- $this->error('任务未关闭不可删除');
- }
- Db::startTrans();
- try{
- $res = Db::name('patrol_task')->where('id',$id)->update([
- 'del'=>1,
- 'del_user_id'=>is_login(),
- 'del_time'=>getTime(),
- ]);
- if(!$res){
- \exception('操作失败');
- }
- // 如果在任务栏删除任务
- Db::name('task')->where('bus_id',$id)->where('type',2)->delete();
- Db::commit();
- }catch (Exception $e){
- Db::rollback();
- $this->error('删除失败');
- }
- $this->success('删除成功');
- }
- /**
- * 关闭记录
- */
- public function close($id=0){
- if(!$id){
- $this->error('参数错误');
- }
- $info = Db::name('patrol_task')->where('org_id',$this->orgId)->where('id',$id)->where('del',0)->find();
- if(!$info){
- $this->error('任务不存在');
- }
- if($info['status'] == 6){
- $this->error('任务已关闭');
- }
- Db::startTrans();
- try{
- $res = Db::name('patrol_task')->where('id',$id)->update([
- 'status'=>6,
- 'update_time'=>getTime(),
- ]);
- if(!$res){
- \exception('操作失败');
- }
- // 如果在任务栏删除任务
- Db::name('task')->where('bus_id',$id)->where('type',2)->delete();
- Db::commit();
- }catch (Exception $e){
- Db::rollback();
- $this->error('操作失败');
- }
- $this->success('操作成功');
- }
- public function info($id=0,$mode){
- $modeName = (new \app\common\model\PatrolAddrForm())->getModeTitle($mode);
- $meta_title=$modeName.'巡视轨迹';
- if(!$id){
- $this->error('参数错误');
- }
- $info=Db::name('patrol_task')
- ->field('id,start_time,end_time,status,title,interrupt_img,interrupt_reson,in_order,cate_id')
- ->where('id',$id)->find();
- if(!$info){
- $this->error('记录不存在');
- }
- $info['start_time']=date('Y-m-d H:i',strtotime($info['start_time']));
- $info['end_time']=date('Y-m-d H:i',strtotime($info['end_time']));
- //获取执行用户
- $task_user=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['task_user']=implode(',',$task_user);
- $addrForms = Db::name('patrol_task_addr')
- ->alias('a')
- // ->join('patrol_addr_form b','a.patrol_form_id = b.id')
- ->join('address c','c.id = a.address_id')
- ->where('a.patrol_task_id',$info['id'])
- ->field('a.*,c.title as addrTitle')
- ->select();
- $addrForms = $addrForms?$addrForms:[];
- foreach ($addrForms as $k=>$v){
- $btitles = Db::name('patrol_addr_form')->where('id','in',$v['patrol_forms'])->column('title');
- $addrForms[$k]['formTitle'] = $btitles?implode(',',$btitles):'';
- $record = Db::name('patrol_record')
- ->alias('a')
- ->join('user b','a.user_id = b.id')
- ->where('a.patrol_task_id',$v['patrol_task_id'])
- ->where('a.patrol_addr_id',$v['address_id'])
- ->field('b.real_name as uname,a.*')
- ->find();
- if($record){
- $cj = $record['check_json']?json_decode($record['check_json'],true):[];
- $record['check_json'] = $cj;
- $record['img'] = $record['images']?explode(',',$record['images']):[];
- }
- $addrForms[$k]['record'] = $record?$record:[];
- }
- $info['addrForms'] = $addrForms;
- $info['cateName'] = $info['cate_id']?implode(',',Db::name('patrol_cate')
- ->where('id','in',explode(',',$info['cate_id']))
- ->column('title')):'';
- $this->assign('meta_title',$meta_title);
- $this->assign('info',$info);
- $this->assign('mode',$mode);
- $this->assign('modeName',$modeName);
- return $this->fetch();
- }
- public function calendar($mode){
- $this->assign('mode',$mode);
- return $this->fetch();
- }
- //获取正月数据
- public function taskjson(){
- $mode = (int)input('mode');
- $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\PatrolTask())->get_list_by_time($this->orgId,$mode,$start,$end);
- foreach ($list as $k=>$v){
- $arr = array(
- 'taskid' => $v['id'],
- 'title' => "{$v['title']}<br>执行人:{$v['users']}<br>开始时间:{$v['start_time']}<br>结束时间:{$v['end_time']}<br>",
- 'status' => $v['status'],
- 'start' => $v['start_time'],
- 'end' => $v['end_time']
- );
- 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 plan($mode){
- $type = input('type');
- if(request()->isPost()){
- $data = request()->post();
- if($data['from'] == $data['to']){
- $this->error('不能复制同月的任务');
- }
- $ret = (new \app\common\model\PatrolTask())->plan_data($data,$this->orgId);
- if($ret){
- if($type==1){
- $this->success('操作成功',url('index',['mode'=>$mode]));
- }else{
- $this->success('操作成功',url('calendar',['mode'=>$mode]));
- }
- }else{
- $this->error((new \app\common\model\PatrolTask())->getError());
- }
- }else{
- $from = (new \app\common\model\PatrolTask())->get_task_month($this->orgId,$mode);
- //间隔1月往后数11次
- $timenow = new \Datetime();
- $datetin = \DateInterval::createFromDateString('1 month');
- $datePer = new \DatePeriod($timenow, $datetin, 11);
- $to = [];
- foreach ($datePer as $day) {
- $m = $day->format('Y-m');
- $to[]= $m;
- }
- $this->assign('from',$from);
- $this->assign('to',$to);
- $this->assign('mode',$mode);
- $this->assign('type',$type);
- return $this->fetch();
- }
- }
- public function batch($mode){
- $type = input('type');
- if(request()->isPost()){
- $data = request()->post();
- $minmonth = date('Y-m');
- if($minmonth >= $data['from']){
- $this->error('参数错误');
- }
- $where = array(
- 'org_id' => $this->orgId,
- 'patrol_mode' => $data['mode'],
- 'del' => 0,
- 'create_yyyymm' => date('Ym',strtotime($data['from'].'-01'))
- );
- $default['del'] = 1;
- $default['del_user_id'] = $this->userId;
- $default['del_time'] = date('Y-m-d H:i:s');
- $result = Db::name('patrol_task')
- ->where($where)
- ->update($default);
- $type = (new Task())::TASK_TYPE_PATROL;
- // 检查是否存在任务栏数据中
- $dailyIds = Db::name('patrol_task_task')
- ->alias('dt')
- ->join('task t','t.bus_id = dt.id')
- ->where('t.type',$type)
- ->where('dt.org_id',$this->orgId)
- ->where('dt.del',0)
- ->where('dt.create_yyyymm',date('Ym',strtotime($data['from'].'-01')))
- ->column('dt.id');
- if($result){
- if($dailyIds){
- Db::name('task')
- ->where('bus_id', 'in',implode(',',$dailyIds))
- ->where('type', $type)
- ->delete();
- }
- if($type==1){
- $this->success('操作成功',url('index',['mode'=>$mode]));
- }else{
- $this->success('操作成功',url('calendar',['mode'=>$mode]));
- }
- }else{
- $this->error('删除失败');
- }
- }else{
- $from = (new \app\common\model\PatrolTask())->get_task_month($this->orgId,$mode);
- $minmonth = date('Y-m');
- $aa = [];
- foreach ($from as $k=>$v){
- if($minmonth < $v['create_yyyymm']){
- $aa[] = $v['create_yyyymm'];
- }
- }
- $this->assign('from',$aa);
- $this->assign('mode',$mode);
- $this->assign('type',$type);
- return $this->fetch();
- }
- }
- public function tj($mode) {
- $cur = date('Y-m-d');
- $start = input('start', date('Y-m-d', strtotime('' . $cur . ' -1 week')));
- $end = input('end', date('Y-m-d'));
- $start1 = $start . ' 00:00:00';
- $end1 = $end . ' 23:59:59';
- if(request()->isAjax()){
- //分页参数
- $length = input('rows',10,'intval'); //每页条数
- $page = input('page',1,'intval'); //第几页
- $start = ($page - 1) * $length; //分页开始位置
- //排序
- $sortRow = input('sidx','sort','trim'); //排序列
- $sort = input('sord','asc','trim'); //排序方式
- $order = $sortRow.' '.$sort.' ,id desc';
- $map1[] = ['a.start_time', '>=', $start1];
- $map1[] = ['a.start_time', '<=', $end1];
- $map1[] = ['a.org_id', '=', $this->orgId];
- $map1[] = ['a.patrol_mode', '=', $mode];
- $map1[] = ['a.del', '=', 0];
- $map2 = [];
- $title = input('title','','trim');
- if ($title !='') {
- $map2[] = ['u.real_name','like','%'.$title.'%'];
- }
- $list = Db::name('patrol_task_user')
- ->alias('b')
- ->join('patrol_task a','a.id=b.patrol_task_id')
- ->join('user u','b.user_id=u.id')
- ->where($map1)
- ->where($map2)
- ->group('b.user_id')
- ->distinct(true)
- ->field('b.user_id,u.real_name')
- ->limit($start,$length)
- ->order('a.id desc')
- ->select();
- foreach ($list as $k => $v) {
- $list[$k]['title'] = $v['real_name'];
- $list[$k]['c1'] = Db::name('patrol_task')
- ->alias('a')
- ->join('patrol_task_user b','a.id=b.patrol_task_id')
- ->where($map1)
- ->where('b.user_id',$v['user_id'])
- ->where('a.status',0)
- ->count();
- $list[$k]['c2'] = Db::name('patrol_task')
- ->alias('a')
- ->join('patrol_task_user b','a.id=b.patrol_task_id')
- ->where($map1)
- ->where('b.user_id',$v['user_id'])
- ->where('a.status',1)
- ->count();
- $list[$k]['c3'] = Db::name('patrol_task')
- ->alias('a')
- ->join('patrol_task_user b','a.id=b.patrol_task_id')
- ->where($map1)
- ->where('b.user_id',$v['user_id'])
- ->where('a.status',2)
- ->count();
- $list[$k]['c4'] = Db::name('patrol_task')
- ->alias('a')
- ->join('patrol_task_user b','a.id=b.patrol_task_id')
- ->where($map1)
- ->where('b.user_id',$v['user_id'])
- ->where('a.status',3)
- ->count();
- $list[$k]['c5'] = Db::name('patrol_task')
- ->alias('a')
- ->join('patrol_task_user b','a.id=b.patrol_task_id')
- ->where($map1)
- ->where('b.user_id',$v['user_id'])
- ->where('a.status',5)
- ->count();
- $list[$k]['c6'] = Db::name('patrol_task')
- ->alias('a')
- ->join('patrol_task_user b','a.id=b.patrol_task_id')
- ->where($map1)
- ->where('b.user_id',$v['user_id'])
- ->where('a.status',6)
- ->count();
- $list[$k]['st'] = $start1;
- $list[$k]['et'] = $end1;
- }
- //数据返回
- $totalCount = Db::name('patrol_task_user')
- ->alias('b')
- ->join('patrol_task a','a.id=b.patrol_task_id')
- ->join('user u','b.user_id=u.id')
- ->where($map1)
- ->where($map2)
- ->group('b.user_id')
- ->distinct(true)
- ->count();
- $totalPage = ceil($totalCount/$length);
- $result['page'] = $page;
- $result['total'] = $totalPage;
- $result['records'] = $totalCount;
- $result['rows'] = $list;
- return json($result);
- }else{
- $this->assign('start', $start);
- $this->assign('end', $end);
- $this->assign('mode', $mode);
- $modeName = (new \app\common\model\PatrolAddrForm())->getModeTitle($mode);
- $this->assign('meta_title',$modeName);
- return $this->fetch();
- }
- }
- public function tjData($start1, $end1, $title,$mode) {
- $map1[] = ['a.start_time', '>=', $start1];
- $map1[] = ['a.start_time', '<=', $end1];
- $map1[] = ['a.org_id', '=', $this->orgId];
- $map1[] = ['a.patrol_mode', '=', $mode];
- $map1[] = ['a.del', '=', 0];
- $map2 = [];
- if (!empty($title)) {
- $map2[] = ['u.real_name','like','%'.$title.'%'];
- }
- $list = Db::name('patrol_task_user')
- ->alias('b')
- ->join('patrol_task a','a.id=b.patrol_task_id')
- ->join('user u','b.user_id=u.id')
- ->where($map1)
- ->where($map2)
- ->group('b.user_id')
- ->distinct(true)
- ->field('b.user_id,u.real_name')
- ->select();
- foreach ($list as $k => $v) {
- $list[$k]['title'] = $v['real_name'];
- $list[$k]['c1'] = Db::name('patrol_task')
- ->alias('a')
- ->join('patrol_task_user b','a.id=b.patrol_task_id')
- ->where($map1)
- ->where('b.user_id',$v['user_id'])
- ->where('a.status',0)
- ->count();
- $list[$k]['c2'] = Db::name('patrol_task')
- ->alias('a')
- ->join('patrol_task_user b','a.id=b.patrol_task_id')
- ->where($map1)
- ->where('b.user_id',$v['user_id'])
- ->where('a.status',1)
- ->count();
- $list[$k]['c3'] = Db::name('patrol_task')
- ->alias('a')
- ->join('patrol_task_user b','a.id=b.patrol_task_id')
- ->where($map1)
- ->where('b.user_id',$v['user_id'])
- ->where('a.status',2)
- ->count();
- $list[$k]['c4'] = Db::name('patrol_task')
- ->alias('a')
- ->join('patrol_task_user b','a.id=b.patrol_task_id')
- ->where($map1)
- ->where('b.user_id',$v['user_id'])
- ->where('a.status',3)
- ->count();
- $list[$k]['c5'] = Db::name('patrol_task')
- ->alias('a')
- ->join('patrol_task_user b','a.id=b.patrol_task_id')
- ->where($map1)
- ->where('b.user_id',$v['user_id'])
- ->where('a.status',5)
- ->count();
- $list[$k]['c6'] = Db::name('patrol_task')
- ->alias('a')
- ->join('patrol_task_user b','a.id=b.patrol_task_id')
- ->where($map1)
- ->where('b.user_id',$v['user_id'])
- ->where('a.status',6)
- ->count();
- }
- return $list;
- }
- public function tjExport() {
- $cur = date('Y-m-d');
- $start = input('start', date('Y-m-d', strtotime('' . $cur . ' -1 week')));
- $end = input('end', date('Y-m-d'));
- $start1 = $start . ' 00:00:00';
- $end1 = $end . ' 23:59:59';
- $type = input('title');
- $mode = input('mode');
- $ret = $this->tjData($start1, $end1, $type,$mode);
- $modeName = (new \app\common\model\PatrolAddrForm())->getModeTitle($mode);
- $filename = $modeName.'任务统计_' . date('YmdHis', time()) . '.xls';
- $header = [
- ['title' => '编号', 'name' => 'user_id','width'=>'30'],
- ['title' => '姓名', 'name' => 'real_name','width'=>'10'],
- ['title' => '未执行', 'name' => 'c1','width'=>'10'],
- ['title' => '执行中', 'name' => 'c2','width'=>'10'],
- ['title' => '已完成', 'name' => 'c3','width'=>'10'],
- ['title' => '未完成', 'name' => 'c4','width'=>'10'],
- ['title' => '中断', 'name' => 'c5','width'=>'10'],
- ['title' => '已关闭', 'name' => 'c6','width'=>'10'],
- ];
- ExcelUtil::export($filename,$header,$ret);
- }
- public function tjList(){
- $userId = input('userId', 0);
- $status = input('status');
- $start = input('start','','trim');
- $end = input('end', '','trim');
- $start1 = $start . ' 00:00:00';
- $end1 = $end . ' 23:59:59';
- $patrol_mode = input('patrol_mode/d', 1);
- if(request()->isAjax()) {
- $month= input('month','','trim');
- if($month != ''){
- $map[] = ['a.create_yyyymm','=',$month];
- }
- $title = input('title','','trim');
- if($title){
- $map[] = ['a.title','like','%'.$title.'%'];
- }
- $is_exception = input('is_exception','','trim');
- if($is_exception != ''){
- $map[] = ['a.is_exception','=',$is_exception];
- }
- $plan_id = input('plan_id','','trim');
- if($plan_id != ''){
- $map[] = ['a.plan_id','=',$plan_id];
- }
- $map1[] = ['a.start_time', '>=', $start1];
- $map1[] = ['a.start_time', '<=', $end1];
- $map1[] = ['a.org_id', '=', $this->orgId];
- $map1[] = ['a.patrol_mode', '=', $patrol_mode];
- $map1[] = ['a.status', '=', $status];
- $map1[] = ['a.del', '=', 0];
- $length = input('rows', 10, 'intval'); //每页条数
- $page = input('page', 1, 'intval'); //第几页
- $start = ($page - 1) * $length; //分页开始位置
- $lists = Db::name('patrol_task')
- ->alias('a')
- ->join('patrol_task_user b', 'a.id=b.patrol_task_id')
- ->where($map1)
- ->where('b.user_id', $userId)
- ->field('a.*')
- ->limit($start, $length)
- ->order(['a.id' => 'desc'])
- ->select();
- foreach ($lists as $k => $v) {
- $lists[$k]['start_time'] = date('Y-m-d H:i', strtotime($v['start_time']));
- $lists[$k]['end_time'] = date('Y-m-d H:i', strtotime($v['end_time']));
- $taskUser = Db::name('patrol_task_user')
- ->alias('ptu')
- ->field('u.real_name')
- ->join('user u', 'u.id=ptu.user_id')
- ->where('ptu.patrol_task_id', $v['id'])
- ->where('ptu.user_id', $userId)
- ->find();
- $lists[$k]['task_user'] = $taskUser['real_name'];
- }
- $totalCount = Db::name('patrol_task')
- ->alias('a')
- ->join('patrol_task_user b', 'a.id=b.patrol_task_id')
- ->where($map1)
- ->where('b.user_id', $userId)
- ->count();
- $totalPage = ceil($totalCount / $length);
- $result['page'] = $page;
- $result['total'] = $totalPage;
- $result['records'] = $totalCount;
- $result['rows'] = $lists;
- return json($result);
- }else{
- $plans = model('PatrolPlan')->getListByMode($this->orgId,$patrol_mode);
- $this->assign('plans',$plans);
- $this->assign('userId',$userId);
- $this->assign('status',$status);
- $this->assign('start',$start);
- $this->assign('end',$end);
- $this->assign('patrol_mode',$patrol_mode);
- $user = Db::name('user')
- ->where('id', $userId)
- ->value('real_name');
- $this->assign('meta_title','['.$user.']任务列表');
- return $this->fetch();
- }
- }
- public function resultRecord($mode){
- if(request()->isAjax()){
- //分页参数
- $length = input('rows',10,'intval'); //每页条数
- $page = input('page',1,'intval'); //第几页
- $start = ($page - 1) * $length; //分页开始位置
- //排序
- $sortRow = input('sidx','sort','trim'); //排序列
- $sort = input('sord','asc','trim'); //排序方式
- $order = $sortRow.' '.$sort.' ,id desc';
- $addrTitle = input('addrTitle','','trim');
- if($addrTitle !=''){
- $addrIds = Db::name('address')->whereLike('title','%'.$addrTitle.'%')->column('id');
- $map[] = ['pta.address_id','in',$addrIds];
- }
- $map[] = ['pt.org_id','=',$this->orgId];
- $map[] =['pt.patrol_mode','=',$mode];
- $map= empty($map) ? true: $map;
- //数据查询
- // $lists = Db::name('patrol_record')
- // ->where($map)
- // ->limit($start,$length)
- // ->order('id desc')
- // ->group('patrol_addr_id')
- // ->select();
- $lists = Db::name('patrol_task_addr')
- ->alias('pta')
- ->join('patrol_task pt','pt.id=pta.patrol_task_id')
- ->where($map)
- ->field('pta.*,pt.patrol_mode')
- ->order('pta.id desc')
- ->limit($start,$length)
- ->group('pta.address_id')
- ->select();
- foreach ($lists as $k=>$v){
- $lists[$k]['addr'] = Db::name('address')->where('id',$v['address_id'])->value('title');
- $lists[$k]['num'] = Db::name('patrol_record')
- ->where('patrol_addr_id',$v['address_id'])
- ->where('patrol_mode',$mode)
- ->count();
- }
- $totalCount = Db::name('patrol_task_addr')
- ->alias('pta')
- ->join('patrol_task pt','pt.id=pta.patrol_task_id')
- ->where($map)
- ->field('pta.*')
- ->order('pta.id desc')
- ->group('pta.address_id')
- ->count();
- //数据返回
- // $totalCount = Db::name('patrol_record')
- // ->where($map)
- // ->limit($start,$length)
- // ->order('id desc')
- // ->group('patrol_addr_id')
- // ->count();
- $lists = list_sort_by($lists,'num','desc');
- $totalPage = ceil($totalCount/$length);
- $result['page'] = $page;
- $result['total'] = $totalPage;
- $result['records'] = $totalCount;
- $result['rows'] = $lists;
- return json($result);
- }else{
- $modeName = (new \app\common\model\PatrolAddrForm())->getModeTitle($mode);
- $this->assign('mode',$mode);
- $this->assign('meta_title',$modeName.'结果查看');
- return $this->fetch();
- }
- }
- public function resultCalendar(){
- $mode = input('mode');
- $addrId = input('addrId');
- $addrName = Db::name('address')->where('id',$addrId)->value('title');
- $this->assign('mode',$mode);
- $this->assign('addrId',$addrId);
- $this->assign('addrName',$addrName);
- return $this->fetch();
- }
- public function taskjsonResult(){
- $mode = input('mode');
- $addrId = input('addrId');
- $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));
- $list = Db::name('patrol_record')
- ->where('patrol_addr_id',$addrId)
- ->where('patrol_mode',$mode)
- ->where('org_id',$this->orgId)
- ->where('create_time','>=',$start)
- ->where('create_time','<=',$end)
- ->select();
- foreach ($list as $k=>$v){
- $name = DB::name('user')->where('id',$v['user_id'])->value('real_name');
- $time = date('H:i',strtotime($v['create_time']));
- $arr = array(
- 'id'=>$v['id'],
- 'title'=> $time.' ! '.$name,
- 'start'=>date('Y-m-d H:i',strtotime($v['create_time'])),
- );
- $data[] = $arr;
- }
- header('Content-Type:application/json; charset=utf-8');
- exit(json_encode($data));
- }
- public function addrWork($mode){
- $day = input('day',date('Y-m-d'),'trim');
- if(request()->isAjax()){
- //分页参数
- $length = input('rows',10,'intval'); //每页条数
- $page = input('page',1,'intval'); //第几页
- $start = ($page - 1) * $length; //分页开始位置
- //排序
- $sortRow = input('sidx','sort','trim'); //排序列
- $sort = input('sord','asc','trim'); //排序方式
- $order = $sortRow.' '.$sort.' ,id desc';
- $first = 1;
- $w = date('w',strtotime($day));
- $wst = date('Ymd',strtotime("$day -" . ($w ? $w - $first : 6) . ' days'));
- $wet = date('Ymd',strtotime("$day +6 days"));
- $zuo = date('Ymd',strtotime($day)-86400);
- $you = date('Ymd',strtotime($day)+86400);
- $st = $day.' 00:00:00';
- $et = $day.' 23:59:59';
- $map[] = ['pt.org_id','=',$this->orgId];
- $map[] =['pt.patrol_mode','=',$mode];
- $map[] =['pt.start_time','>=',$st];
- $map[] =['pt.start_time','<=',$et];
- $map= empty($map) ? true: $map;
- $lists = Db::name('patrol_task_addr')
- ->alias('pta')
- ->join('patrol_task pt','pt.id=pta.patrol_task_id')
- ->where($map)
- ->field('pta.*,pt.patrol_mode')
- ->limit($start,$length)
- ->order('pta.id desc')
- ->group('pta.address_id')
- ->select();
- foreach ($lists as $k=>$v){
- $lists[$k]['addr'] = Db::name('address')->where('id',$v['address_id'])->value('title');
- $taskIds = Db::name('patrol_task_addr')->where('address_id',$v['address_id'])->column('patrol_task_id');
- $lists[$k]['count'] = Db::name('patrol_task')
- ->whereIn('id',$taskIds)
- ->where('patrol_mode',$v['patrol_mode'])
- ->count();
- $lists[$k]['num'] = Db::name('patrol_task')
- ->whereIn('id',$taskIds)
- ->where('patrol_mode',$v['patrol_mode'])
- ->where('create_yyyymm',date('Ym',strtotime($day)))
- ->count();
- $lists[$k]['num1'] = Db::name('patrol_task')
- ->whereIn('id',$taskIds)
- ->where('patrol_mode',$v['patrol_mode'])
- ->where('create_yyyymmdd','>=',$wst)
- ->where('create_yyyymmdd','<=',$wet)
- ->count();
- $lists[$k]['num2'] = Db::name('patrol_task')
- ->whereIn('id',$taskIds)
- ->where('patrol_mode',$v['patrol_mode'])
- ->where('create_yyyymmdd','=',date('Ymd',strtotime($day)))
- ->count();
- $lists[$k]['num3'] = Db::name('patrol_task')
- ->whereIn('id',$taskIds)
- ->where('patrol_mode',$v['patrol_mode'])
- ->where('create_yyyymmdd','=',$zuo)
- ->where('status','in',[0,1,3,5,6])
- ->count();
- $lists[$k]['num4'] = Db::name('patrol_task')
- ->whereIn('id',$taskIds)
- ->where('patrol_mode',$v['patrol_mode'])
- ->where('create_yyyymmdd','=',date('Ymd',strtotime($day)))
- ->where('status','in',[0,1,3,5,6])
- ->count();
- }
- $totalCount = Db::name('patrol_task_addr')
- ->alias('pta')
- ->join('patrol_task pt','pt.id=pta.patrol_task_id')
- ->where($map)
- ->field('pta.*,pt.patrol_mode')
- ->order('pta.id desc')
- ->group('pta.address_id')
- ->count();
- $totalPage = ceil($totalCount/$length);
- $result['page'] = $page;
- $result['total'] = $totalPage;
- $result['records'] = $totalCount;
- $result['rows'] = $lists;
- return json($result);
- }else{
- $modeName = (new \app\common\model\PatrolAddrForm())->getModeTitle($mode);
- $this->assign('mode',$mode);
- $this->assign('day',$day);
- $this->assign('meta_title',$modeName.'地点工作量统计');
- return $this->fetch();
- }
- }
- public function addrWorkExport(){
- $day = input('day',date('Y-m-d'),'trim');
- $mode = input('mode');
- $first = 1;
- $w = date('w',strtotime($day));
- $wst = date('Ymd',strtotime("$day -" . ($w ? $w - $first : 6) . ' days'));
- $wet = date('Ymd',strtotime("$day +6 days"));
- $zuo = date('Ymd',strtotime($day)-86400);
- $you = date('Ymd',strtotime($day)+86400);
- $st = $day.' 00:00:00';
- $et = $day.' 23:59:59';
- $map[] = ['pt.org_id','=',$this->orgId];
- $map[] =['pt.patrol_mode','=',$mode];
- $map[] =['pt.start_time','>=',$st];
- $map[] =['pt.start_time','<=',$et];
- $map= empty($map) ? true: $map;
- $lists = Db::name('patrol_task_addr')
- ->alias('pta')
- ->join('patrol_task pt','pt.id=pta.patrol_task_id')
- ->where($map)
- ->field('pta.*,pt.patrol_mode')
- ->order('pta.id desc')
- ->group('pta.address_id')
- ->select();
- foreach ($lists as $k=>$v){
- $lists[$k]['addr'] = Db::name('address')->where('id',$v['address_id'])->value('title');
- $lists[$k]['count'] = Db::name('patrol_task')
- ->where('id',$v['patrol_task_id'])
- ->where('patrol_mode',$v['patrol_mode'])
- ->count();
- $lists[$k]['num'] = Db::name('patrol_task')
- ->where('id',$v['patrol_task_id'])
- ->where('patrol_mode',$v['patrol_mode'])
- ->where('create_yyyymm',date('Ym',strtotime($day)))
- ->count();
- $lists[$k]['num1'] = Db::name('patrol_task')
- ->where('id',$v['patrol_task_id'])
- ->where('patrol_mode',$v['patrol_mode'])
- ->where('create_yyyymmdd','>=',$wst)
- ->where('create_yyyymmdd','<=',$wet)
- ->count();
- $lists[$k]['num2'] = Db::name('patrol_task')
- ->where('id',$v['patrol_task_id'])
- ->where('patrol_mode',$v['patrol_mode'])
- ->where('create_yyyymmdd','=',date('Ymd',strtotime($day)))
- ->count();
- $lists[$k]['num3'] = Db::name('patrol_task')
- ->where('id',$v['patrol_task_id'])
- ->where('patrol_mode',$v['patrol_mode'])
- ->where('create_yyyymmdd','=',$zuo)
- ->where('status','in',[0,1,3,5,6])
- ->count();
- $lists[$k]['num4'] = Db::name('patrol_task')
- ->where('id',$v['patrol_task_id'])
- ->where('patrol_mode',$v['patrol_mode'])
- ->where('create_yyyymmdd','=',date('Ymd',strtotime($day)))
- ->where('status','in',[0,1,3,5,6])
- ->count();
- }
- $modeName = (new \app\common\model\PatrolAddrForm())->getModeTitle($mode);
- $filename = $modeName.'地点工作量统计_' . date('YmdHis', time()) . '.xls';
- $header = [
- ['title' => '地点', 'name' => 'addr','width'=>'10'],
- ['title' => '总数', 'name' => 'count','width'=>'10'],
- ['title' => '本月', 'name' => 'num','width'=>'10'],
- ['title' => '本周', 'name' => 'num1','width'=>'10'],
- ['title' => '今天', 'name' => 'num2','width'=>'10'],
- ['title' => '昨日未完成', 'name' => 'num3','width'=>'10'],
- ['title' => '今日未完成', 'name' => 'num4','width'=>'10'],
- ];
- ExcelUtil::export($filename,$header,$lists);
- }
- public function delCloseTask(){
- $mode = input('mode');
- $map[] = ['patrol_mode','=',$mode];
- $map[] = ['status','=',6];
- $map[] = ['del','=',0];
- $map[] = ['org_id','=',$this->orgId];
- Db::name('patrol_task')
- ->where($map)
- ->update([
- 'del'=>1,
- 'del_user_id'=>$this->userId,
- 'del_time'=>date('Y-m-d H:i:s')
- ]);
- $this->success('操作成功');
- }
- }
|