|
@@ -9,7 +9,145 @@ use think\Db;
|
|
|
|
|
|
class Patrol extends Index
|
|
|
{
|
|
|
+ public function patrolDeviceData(){
|
|
|
+ $currentYear = date('Y');
|
|
|
+ $currentMonth = date('m');
|
|
|
+ $dates = [];
|
|
|
+ $dates2 = [];
|
|
|
+ $startDate = new \DateTime("$currentYear-$currentMonth-01");
|
|
|
+
|
|
|
+ while ($startDate->format('m') == $currentMonth) {
|
|
|
+ $dates[] = $startDate->format('m-d');
|
|
|
+ $dates2[] = $startDate->format('Ymd');
|
|
|
+ $startDate->add(new \DateInterval('P1D'));
|
|
|
+ }
|
|
|
+ $list = [];
|
|
|
+ foreach ($dates as $k=>$v){
|
|
|
+ $count = $lists = Db::name('device_record')
|
|
|
+ ->alias('dr')
|
|
|
+ ->join('device d', 'd.id=dr.device_id')
|
|
|
+ ->field('dr.*,d.title as device_name,d.content as device_details')
|
|
|
+ ->where('dr.org_id',$this->orgId)
|
|
|
+ ->where('cate_id','in',[22,23])
|
|
|
+ ->where('create_yyyymmdd',$dates2[$k])
|
|
|
+ ->count();
|
|
|
+ $list[$k] = $count>0 ? $count : 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = [
|
|
|
+ 'date' =>$dates,
|
|
|
+ 'list'=>$list
|
|
|
+ ];
|
|
|
+ HelpHander::success($data);
|
|
|
+ }
|
|
|
+ public function patrolImg4(){
|
|
|
+ $data = Db::name('device_record')
|
|
|
+ ->alias('dr')
|
|
|
+ ->join('device d', 'd.id=dr.device_id')
|
|
|
+ ->field('dr.*,d.title as device_name,d.content as device_details')
|
|
|
+ ->where('dr.org_id',$this->orgId)
|
|
|
+ ->where('cate_id','in',[22,23])
|
|
|
+ ->order('dr.id desc')
|
|
|
+ ->limit(30)
|
|
|
+ ->select();
|
|
|
|
|
|
+ foreach ($data as $k=>$v){
|
|
|
+ $img = explode(',',$v['images']);
|
|
|
+ if($img){
|
|
|
+ $data[$k]['images'] = $img[0];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(count($data)>12){
|
|
|
+ $key = array_rand($data,12);
|
|
|
+ for ($i = 0; $i < 12; $i++) {
|
|
|
+ $list[] = $data[$key[$i]];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $eList = isset($list)?$list:$data;
|
|
|
+ HelpHander::success($eList);
|
|
|
+ }
|
|
|
+ public function patrolDevice(){
|
|
|
+ $lists = Db::name('device_record')
|
|
|
+ ->alias('dr')
|
|
|
+ ->join('device d', 'd.id=dr.device_id')
|
|
|
+ ->field('dr.*,d.title as device_name,d.content as device_details')
|
|
|
+ ->where('dr.org_id',$this->orgId)
|
|
|
+ ->where('cate_id','in',[22,23])
|
|
|
+ ->order('dr.id desc')
|
|
|
+ ->limit(30)
|
|
|
+ ->select();
|
|
|
+ $data = [];
|
|
|
+ foreach ($lists as $k => $v) {
|
|
|
+ $user = Db::name('user')->where('id', $v['user_id'])->value('real_name');
|
|
|
+ $checkJson = json_decode($v['check_json'],true);
|
|
|
+ $content = '';
|
|
|
+ for ($i =0;$i<count($checkJson);$i++) {
|
|
|
+ $content .= $checkJson[$i]['title'].'/';
|
|
|
+ }
|
|
|
+ $check_Content = rtrim($content, '/');
|
|
|
+ $data[$k][] = $v['id'];
|
|
|
+ $data[$k][] = $v['device_name'];
|
|
|
+ $data[$k][] = $check_Content;
|
|
|
+ $data[$k][] = $user;
|
|
|
+ }
|
|
|
+ HelpHander::success($data);
|
|
|
+ }
|
|
|
+ public function newData(){
|
|
|
+ $count1 = Db::name('address')
|
|
|
+ ->where('org_id',$this->orgId)
|
|
|
+ ->where('enable',1)
|
|
|
+ ->where('','exp',Db::raw("FIND_IN_SET(3,types)"))
|
|
|
+ ->count();
|
|
|
+ $count2 = Db::name('patrol_task')
|
|
|
+ ->alias('pr')
|
|
|
+ ->leftJoin('patrol_task_addr b','pr.id=b.patrol_task_id')
|
|
|
+ ->where('pr.org_id',$this->orgId)
|
|
|
+ ->where('pr.del',0)
|
|
|
+ ->where('pr.patrol_mode',1)
|
|
|
+ ->where('pr.create_yyyymmdd',date('Ymd'))
|
|
|
+ ->group('b.address_id')
|
|
|
+ ->count();
|
|
|
+ $count3 = Db::name('user')
|
|
|
+ ->alias('u')
|
|
|
+ ->join('user_roles ur','u.id=ur.user_id')
|
|
|
+ ->where('u.del',0)
|
|
|
+ ->where('ur.roles_id','in',[464,465,466])
|
|
|
+ ->count();
|
|
|
+ $count4 = Db::name('user')
|
|
|
+ ->alias('u')
|
|
|
+ ->join('user_roles ur','u.id=ur.user_id')
|
|
|
+ ->where('u.del',0)
|
|
|
+ ->where('work',1)
|
|
|
+ ->where('ur.roles_id','in',[464,465,466])
|
|
|
+ ->count();
|
|
|
+ $task = Db::name('patrol_task')
|
|
|
+ ->where('org_id',$this->orgId)
|
|
|
+ ->where('del',0)
|
|
|
+ ->where('patrol_mode',1)
|
|
|
+ ->where('create_yyyymmdd',date('Ymd'))
|
|
|
+ ->count();
|
|
|
+
|
|
|
+ $task1 = Db::name('patrol_task')
|
|
|
+ ->where('org_id',$this->orgId)
|
|
|
+ ->where('del',0)
|
|
|
+ ->where('patrol_mode',1)
|
|
|
+ ->where('create_yyyymmdd',date('Ymd'))
|
|
|
+ ->where('status',2)
|
|
|
+ ->count();
|
|
|
+ $count5 = 0;
|
|
|
+ if($task > 0 ){
|
|
|
+ $count5 = round($task1/$task*100,1);
|
|
|
+ }
|
|
|
+ $data = [
|
|
|
+ 'count1' => $count1,
|
|
|
+ 'count2' => $count2,
|
|
|
+ 'count3' => $count3,
|
|
|
+ 'count4' => $count4,
|
|
|
+ 'count5' => $count5,
|
|
|
+ ];
|
|
|
+
|
|
|
+ HelpHander::success($data);
|
|
|
+ }
|
|
|
public function patrolImg3(){
|
|
|
$data = Db::name('patrol_record')
|
|
|
->field('images,patrol_addr_id')
|
|
@@ -30,7 +168,7 @@ class Patrol extends Index
|
|
|
if(count($data)>12){
|
|
|
$key = array_rand($data,12);
|
|
|
for ($i = 0; $i < 12; $i++) {
|
|
|
- $list[] = $data[$key[$i]];
|
|
|
+ $list[] = $data[$key[$i]];
|
|
|
}
|
|
|
}
|
|
|
$eList = isset($list)?$list:$data;
|
|
@@ -52,16 +190,26 @@ class Patrol extends Index
|
|
|
];
|
|
|
}, $title);
|
|
|
|
|
|
- HelpHander::success(array_reverse($mappedArray));
|
|
|
+ HelpHander::success(array_reverse($mappedArray));
|
|
|
}
|
|
|
- public function getInfo($item='',$param=''){
|
|
|
- $map[] = ['pr.create_yyyymmdd','=',date('Ymd')];
|
|
|
- $map[] = ['pr.org_id','=',$this->orgId];
|
|
|
- $map[] = ['pr.patrol_mode', '=',1];
|
|
|
- if ($item) {
|
|
|
- $map[] = ['pa.title','=',$item];
|
|
|
- }
|
|
|
- if ($param) {
|
|
|
+ public function getInfo($item='',$param=''){
|
|
|
+ $map[] = ['pr.create_yyyymmdd','=',date('Ymd')];
|
|
|
+ $map[] = ['pr.org_id','=',$this->orgId];
|
|
|
+ $map[] = ['pr.patrol_mode', '=',1];
|
|
|
+ if ($item) {
|
|
|
+ $map[] = ['pa.title','=',$item];
|
|
|
+ }
|
|
|
+ if ($param) {
|
|
|
+ $lists = Db::name('patrol_record')
|
|
|
+ ->alias('pr')
|
|
|
+ ->field('pr.id,pr.user_id,pr.order_id,pr.create_time,pa.title,pt.title as task_title')
|
|
|
+ ->join('patrol_task pt','pt.id = pr.patrol_task_id')
|
|
|
+ ->Leftjoin('address pa', 'pa.id=pr.patrol_addr_id')
|
|
|
+ ->where($map)
|
|
|
+ ->order('pr.create_time','desc')
|
|
|
+ ->limit(1)
|
|
|
+ ->select();
|
|
|
+ }
|
|
|
$lists = Db::name('patrol_record')
|
|
|
->alias('pr')
|
|
|
->field('pr.id,pr.user_id,pr.order_id,pr.create_time,pa.title,pt.title as task_title')
|
|
@@ -69,38 +217,28 @@ class Patrol extends Index
|
|
|
->Leftjoin('address pa', 'pa.id=pr.patrol_addr_id')
|
|
|
->where($map)
|
|
|
->order('pr.create_time','desc')
|
|
|
- ->limit(1)
|
|
|
->select();
|
|
|
- }
|
|
|
- $lists = Db::name('patrol_record')
|
|
|
- ->alias('pr')
|
|
|
- ->field('pr.id,pr.user_id,pr.order_id,pr.create_time,pa.title,pt.title as task_title')
|
|
|
- ->join('patrol_task pt','pt.id = pr.patrol_task_id')
|
|
|
- ->Leftjoin('address pa', 'pa.id=pr.patrol_addr_id')
|
|
|
- ->where($map)
|
|
|
- ->order('pr.create_time','desc')
|
|
|
- ->select();
|
|
|
- foreach ($lists as $k => $v) {
|
|
|
- $lists[$k]['task_user'] = Db::name('user')
|
|
|
- ->where('id', $v['user_id'])->value('real_name');
|
|
|
- $status = 0;
|
|
|
- if($v['order_id'] > 0 ){
|
|
|
- $order = Db::name('orders')
|
|
|
- ->where('id',$v['order_id'])
|
|
|
- ->where('quality_type',$v['patrol_mode']+1)
|
|
|
- ->whereIn('order_mode',[5,6])->where('del',0)->find();
|
|
|
-
|
|
|
- if($order){
|
|
|
- $status = 2;
|
|
|
- }else{
|
|
|
- $status = 1;
|
|
|
+ foreach ($lists as $k => $v) {
|
|
|
+ $lists[$k]['task_user'] = Db::name('user')
|
|
|
+ ->where('id', $v['user_id'])->value('real_name');
|
|
|
+ $status = 0;
|
|
|
+ if($v['order_id'] > 0 ){
|
|
|
+ $order = Db::name('orders')
|
|
|
+ ->where('id',$v['order_id'])
|
|
|
+ ->where('quality_type',$v['patrol_mode']+1)
|
|
|
+ ->whereIn('order_mode',[5,6])->where('del',0)->find();
|
|
|
+
|
|
|
+ if($order){
|
|
|
+ $status = 2;
|
|
|
+ }else{
|
|
|
+ $status = 1;
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- $lists[$k]['zg_type'] = $status;
|
|
|
-
|
|
|
- $lists[$k]['exception'] = 1;
|
|
|
- }
|
|
|
+ $lists[$k]['zg_type'] = $status;
|
|
|
|
|
|
+ $lists[$k]['exception'] = 1;
|
|
|
+ }
|
|
|
+
|
|
|
return $lists;
|
|
|
}
|
|
|
|
|
@@ -163,7 +301,6 @@ class Patrol extends Index
|
|
|
->where('pt.status',1)
|
|
|
->order('pr.id desc')
|
|
|
->find();
|
|
|
- $addrList =[];
|
|
|
if(isset($record) && !empty($record)){
|
|
|
$record['addr'] = Db::name('address')->where('id',$record['patrol_addr_id'])->value('title');
|
|
|
|
|
@@ -171,43 +308,39 @@ class Patrol extends Index
|
|
|
|
|
|
$record['task'] = Db::name('patrol_task')->where('id',$record['patrol_task_id'])->value('title');
|
|
|
|
|
|
-
|
|
|
- $addrList = Db::name('patrol_task_addr')
|
|
|
- ->alias('pta')
|
|
|
- ->field('a.id,a.title')
|
|
|
- ->join('patrol_addr_form paf','paf.id=pta.patrol_form_id')
|
|
|
- ->join('address a','a.id=paf.patrol_addr_id')
|
|
|
- ->where('pta.patrol_task_id',$record['patrol_task_id'])
|
|
|
- ->where('a.del',0)
|
|
|
- ->select();
|
|
|
- if($addrList){
|
|
|
- foreach ($addrList as $k=>$v){
|
|
|
- $addrList[$k]['nums'] = Db::name('patrol_record')
|
|
|
- ->where('org_id',$this->orgId)
|
|
|
- ->where('patrol_addr_id',$v['id'])
|
|
|
- ->count();
|
|
|
- $active = 0;
|
|
|
- if($v['id'] == $record['patrol_addr_id']){
|
|
|
- $active = 1;
|
|
|
- }
|
|
|
- $addrList[$k]['active'] = $active;
|
|
|
- $times = Db::name('patrol_record')
|
|
|
- ->field('create_time')
|
|
|
- ->where('org_id',$this->orgId)
|
|
|
- ->where('patrol_addr_id',$v['id'])
|
|
|
- ->select();
|
|
|
- $eDate = '无';
|
|
|
- foreach ($times as $kk=>$vv){
|
|
|
- $date = isset($times[1]['create_time'])&&!empty($times[1]['create_time'])?$times[1]['create_time']:'';
|
|
|
- $eDate = !empty($date)?date('H:i',strtotime($date)):'无';
|
|
|
- }
|
|
|
- $addrList[$k]['time'] = $eDate;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
}
|
|
|
|
|
|
+ $addrList = Db::name('patrol_task_addr')
|
|
|
+ ->alias('pta')
|
|
|
+ ->field('a.id,a.title')
|
|
|
+ ->join('patrol_addr_form paf','paf.id=pta.patrol_form_id')
|
|
|
+ ->join('address a','a.id=paf.patrol_addr_id')
|
|
|
+ ->where('pta.patrol_task_id',$record['patrol_task_id'])
|
|
|
+ ->where('a.del',0)
|
|
|
+ ->select();
|
|
|
|
|
|
+ foreach ($addrList as $k=>$v){
|
|
|
+ $addrList[$k]['nums'] = Db::name('patrol_record')
|
|
|
+ ->where('org_id',$this->orgId)
|
|
|
+ ->where('patrol_addr_id',$v['id'])
|
|
|
+ ->count();
|
|
|
+ $active = 0;
|
|
|
+ if($v['id'] == $record['patrol_addr_id']){
|
|
|
+ $active = 1;
|
|
|
+ }
|
|
|
+ $addrList[$k]['active'] = $active;
|
|
|
+ $times = Db::name('patrol_record')
|
|
|
+ ->field('create_time')
|
|
|
+ ->where('org_id',$this->orgId)
|
|
|
+ ->where('patrol_addr_id',$v['id'])
|
|
|
+ ->select();
|
|
|
+ $eDate = '无';
|
|
|
+ foreach ($times as $kk=>$vv){
|
|
|
+ $date = isset($times[1]['create_time'])&&!empty($times[1]['create_time'])?$times[1]['create_time']:'';
|
|
|
+ $eDate = !empty($date)?date('H:i',strtotime($date)):'无';
|
|
|
+ }
|
|
|
+ $addrList[$k]['time'] = $eDate;
|
|
|
+ }
|
|
|
$data = [
|
|
|
'record' => $record,
|
|
|
'addrList' => $addrList,
|