post(); $data['org_id'] = cur_org_id(); $result = validate('Address')->check($data,[],''); if(true !== $result){ $this->error = validate('Address')->getError(); return false; } $id = $data['id']; unset($data['id']); if($data['sn']){ $deviceLog = Db::name('device_log')->where('sn',$data['sn'])->where('type',2)->where('del',0)->find(); $txt = '添加'; if($id > 0){ $txt = '修改'; } if(!$deviceLog){ $this->error = '该设备无法'.$txt.',请联系管理员'; return false; } } if($id > 0){ $data['update_time'] = date('Y-m-d H:i:s'); $ret = $this->allowField(true)->save($data,['id'=>$id]); }else{ $data['create_time'] = date('Y-m-d H:i:s'); $ret = $this->allowField(true)->save($data); } if(!$ret){ $this->error = '操作失败'; return false; } return true; } /** * 根据类型获取地点列表 * @param $type */ public function getListByType($type,$orgId=0){ if($orgId >0){ $map[] = ['org_id','=',$orgId]; }else{ $map[] = ['org_id','=',cur_org_id()]; } $map[] = ['del','=',0]; $map[] = ['enable','=',1]; $map[]=['','exp',Db::raw("FIND_IN_SET($type,types)")]; $lists = Db::name('address') ->where($map) ->order('id desc') ->field('id,title,remark,sn,x,y') ->select(); return $lists?$lists:[]; } /** * 根据类型获取地点数量 * @param $type */ public function getListByTypeCount($type,$orgId=0){ if($orgId >0){ $map[] = ['org_id','=',$orgId]; }else{ $map[] = ['org_id','=',cur_org_id()]; } $map[] = ['del','=',0]; $map[] = ['enable','=',1]; $map[]=['','exp',Db::raw("FIND_IN_SET($type,types)")]; $count = Db::name('address') ->where($map) ->count(); return $count; } // 类型获取字符串 public function getTypeStr($ts){ $types = $this->getTypes(); $tstr = []; if(is_array($ts)){ foreach ($ts as $val){ $tstr[] = $types[$val]; } }else{ if(isset($types[$ts])){ $tstr[] = $types[$ts]; } } return implode(',',$tstr); } // 获取地点的类型 public function getTypes(){ return [1=>'报修',2=>'运送',3=>'安保巡更',4=>'保洁巡视',5=>'总部巡查',6=>'设备巡检',7=>'医废',8=>'专项保洁',9=>'被服管理',10=>'日常工作']; } /** * 检查地点二维码是否合法 * @param $code 二维码内容 * @param $type 地点类型 * @param int $orgId 组织 * @return array/bool false=不合法 */ public function checkAddrCode($code,$type,$orgId=0){ if(!$code){ return false; } $addrs = get_qrcode_arr($code); if(!$addrs || $addrs['ucode'] != config('app.ucode') || $addrs['type'] != 'address'){ return false; } // 检查类型 $ainfo = Db::name('address')->where('enable',1)->where('id',$addrs['id'])->where('org_id',$orgId)->where('del',0)->find(); if(!$ainfo){ return false; } $types = $ainfo['types']?explode(',',$ainfo['types']):[]; if(!$types || !in_array($type,$types)){ return false; } $addrs['title'] = $ainfo['title']; return $addrs; } }