12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109 |
- <?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;
- use think\helper\Time;
- 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 != ''){
- $month = date('Ym',strtotime($month.'-01'));
- $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];
- }
- $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($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();
- // foreach ($taskUser as $kk=>$vv){
- // $userName[$kk]=$vv['real_name'];
- // }
- $lists[$k]['task_user']=implode(',',array_column($taskUser,'real_name'));
- }
- //数据返回
- $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.'任务列表');
- 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['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();
- $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,c.title as addrTitle,a.patrol_forms')
- ->order(['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:[];
- $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));
- 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('任务未关闭不可删除');
- }
- $res = Db::name('patrol_task')->where('id',$id)->update([
- 'del'=>1,
- 'del_user_id'=>is_login(),
- 'del_time'=>getTime(),
- ]);
- if(!$res){
- $this->error('删除失败');
- }
- // 如果在任务栏删除任务
- Db::name('task')->where('bus_id',$id)->where('type',2)->delete();
- $title = db('patrol_mode')->where('id',$info['patrol_mode'])->value('name');
- $content = $title.'任务管理:删除';
- // model('ActionLog')->addlog(is_login(),44,$content,['id' => $id],cur_org_id());
- $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();
- $title = Db::name('patrol_mode')->where('id',$info['patrol_mode'])->value('name');
- $content = $title.'任务管理:关闭';
- // model('ActionLog')->addlog(is_login(),44,$content,['id' => $id],cur_org_id());
- Db::commit();
- $this->success('操作成功');
- }catch (Exception $e){
- Db::rollback();
- $this->error('操作失败');
- }
- }
- 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')
- ->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;
- }
- $addrForms[$k]['record'] = $record?$record:[];
- }
- $info['addrForms'] = $addrForms;
- $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();
- $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);
- }
- }
|