| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 | 
							- <?php
 
- namespace app\common\model;
 
- use think\Db;
 
- class Address extends Base
 
- {
 
-     public function updates(){
 
-         $data = request()->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,$conveyCateId=0,$start=0){
 
-         if($orgId >0){
 
-             $map[] = ['org_id','=',$orgId];
 
-         }else{
 
-             $map[] = ['org_id','=',cur_org_id()];
 
-         }
 
-         if($conveyCateId > 0){
 
-             $conveyCate = Db::name("convey_cate")
 
-                 ->where('id',$conveyCateId)
 
-                 ->find();
 
-             $addrs = [];
 
-             if($conveyCate){
 
-                 if($start == 1){
 
-                     $addrs = $conveyCate['starts']?explode(',',$conveyCate['starts']):[];
 
-                 }else{
 
-                     $addrs = $conveyCate['ends']?explode(',',$conveyCate['ends']):[];
 
-                 }
 
-             }
 
-             if($addrs){
 
-                 $map[] = ['id','in',$addrs];
 
-             }
 
-         }
 
-         $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,dep_id')
 
-             ->select();
 
-         return $lists?$lists:[];
 
-     }
 
-     public function getListByTypes($maps,$type,$orgId=0){
 
-         if($orgId >0){
 
-             $map[] = ['org_id','=',$orgId];
 
-         }else{
 
-             $map[] = ['org_id','=',cur_org_id()];
 
-         }
 
-         $map[] = ['del','=',0];
 
-         $map[] = ['enable','=',1];
 
-         if(!empty($maps)){
 
-             $map[] = ['id','in',$maps];
 
-         }
 
-         $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;
 
-     }
 
- }
 
 
  |