field('jiance.id,jiance.bianhao,jiance.status,jiance_number,uc.projectname') ->join('user_company uc','jiance.uc_id = uc.id','LEFT') ->where('jiance.worker_id',$this->auth->id) ->where('jiance.deletetime',NULL) ->where($map) ->autopage() ->select(); $this->success(1,$list); } //详情页 public function info(){ $id = input('id',0); $info = Db::name('jiance')->field('id,bianhao,status,project_ids')->where('id',$id)->find(); //所有项目 $project = Db::name('jiance_project')->field('id,pid,title,type,info,weigh') ->where('company_id',$this->auth->company_id) ->where('deletetime',NULL) ->where('id','IN',$info['project_ids']) ->order('pid asc,type asc,weigh asc,id asc')->select(); //所有记录 $joblog = Db::name('jiance_joblog')->field('project_id,count(id) as jilunum')->where('jiance_id',$id)->group('project_id')->select(); $joblog = array_column($joblog,'jilunum','project_id'); //循环处理 $top = []; foreach($project as $key => $val){ //组合记录数 $project[$key]['jilunum'] = isset($joblog[$val['id']]) ? $joblog[$val['id']] : 0; //拿出来一级 if($val['pid'] == 0){ $top[] = $val; unset($project[$key]); } } // dump($top); // dump($project); //数据结构排序,二级结构,不需要tree foreach($top as $tk => $tv){ foreach($project as $key => $val){ if($val['pid'] == $tv['id']){ if($val['type'] == 1){ $tv['child_type1'][] = $val; }else{ $tv['child_type2'][] = $val; } } } $top[$tk] = $tv; } // dump($top); $this->success(1,$top); } //提交 public function submit(){ $id = input('id',0); Db::name('jiance')->where('id',$id)->where('company_id',$this->auth->company_id)->update(['status'=>1]); $this->success(); } //记录列表 public function job_list(){ $jiance_id = input('jiance_id',0); $project_id = input('project_id',0); $jiance = Db::name('jiance')->where('id',$jiance_id)->value('status'); $list = Db::name('jiance_joblog')->alias('joblog') ->field('joblog.*,project.title as project_title') ->join('jiance_project project','joblog.project_id = project.id','LEFT') ->where('joblog.jiance_id',$jiance_id) ->where('joblog.project_id',$project_id) ->order('joblog.id desc') ->select(); $rs = [ 'jiance_status' => $jiance, 'list' => $list, ]; $this->success(1,$rs); } //新增记录 public function job_add(){ $data = [ 'jiance_id' => input('jiance_id',0), 'project_id' => input('project_id',0), 'worker_id' => $this->auth->id, 'weizhi' => input('weizhi',''), 'number' => input('number',1), 'hege_status' => input('hege_status',1), 'result' => input('result',''), 'images' => input('images',''), 'createtime' => time(), ]; Db::name('jiance_joblog')->insertGetId($data); //检测位置历史 $this->weizhi_history($data['weizhi']); $this->success(); } //编辑详情 public function job_info(){ $id = input('id',0); $info = Db::name('jiance_joblog')->where('id',$id)->find(); $this->success(1,$info); } //编辑记录 public function job_edit(){ $id = input('id',0); $data = [ 'weizhi' => input('weizhi',''), 'number' => input('number',1), 'hege_status' => input('hege_status',1), 'result' => input('result',''), 'images' => input('images',''), ]; Db::name('jiance_joblog')->where('id',$id)->update($data); //检测位置历史 $this->weizhi_history($data['weizhi']); $this->success(); } //检测搜索历史,新增一个 private function weizhi_history($weizhi){ if(empty($weizhi)){ return true;} //查重 $check = Db::name('worker_weizhi_history')->where('worker_id',$this->auth->id)->where('weizhi',$weizhi)->find(); if($check){ return true;} //新增 $data = [ 'worker_id' => $this->auth->id, 'weizhi' => $weizhi, ]; Db::name('worker_weizhi_history')->insertGetId($data); //只留20个 $count = Db::name('worker_weizhi_history')->where('worker_id',$this->auth->id)->count(); if($count > 20){ Db::name('worker_weizhi_history')->where('worker_id',$this->auth->id)->order('id asc')->limit($count - 20)->delete(); } } //删除记录 public function job_del(){ $id = input('id',0); Db::name('jiance_joblog')->where('id',$id)->delete(); $this->success(); } //检测位置历史记录 public function history_list(){ $lists = Db::name('worker_weizhi_history')->where('worker_id',$this->auth->id)->order('id desc')->column('weizhi'); $this->success(1,$lists); } }