| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321 | <?phpnamespace app\common\model;use app\common\util\AppMsg;use think\Db;class MeetingApply extends Base{    public function agree(){        $data = request()->post();        $data['apply_time'] = date('Y-m-d H:i:s');        $data['status'] = 1;        $id = $data['id'];//        $userIds = $data['user_id'];        unset($data['id']);//        unset($data['user_id']);//        if(!$data['apply_remark']){//            $this->error = '审批意见不能为空';//            return  false;//        }        $ret = $this->allowField(true)->save($data,['id'=>$id]);        $apply = Db::name('meeting_apply')->where('id',$id)->find();        if($apply['user_id']){            send_jpush([$apply['user_id']],AppMsg::PUSH_CUSTOM,'您预约的会议室审批已通过');        }        $room = Db::name('meeting_room')->where('id',$apply['meeting_room_id'])->find();        if($room['waiter'] > 0 && $room['is_notice_waiter'] == 1){            $time = $apply['start_time'].'-'.$apply['end_time'];            $msg = '请在'.$time.'进行会议服务';            send_jpush([$room['waiter']],AppMsg::PUSH_CUSTOM,$msg);        }//        $ids = isset($userIds) && !empty($userIds)?explode(',',$userIds):[];//        if(count($ids)>0){//            foreach ($ids as $k=>$v){//                $mData = [//                    'user_id'=>$v,//                    'meetapply_id'=>$id,//                ];//                 $add = Db::name('meet_service')->insert($mData);//                 if(!$add){//                     $this->error = '操作失败';//                     return false;//                 }//            }//        }        if(!$ret){            $this->error = '操作失败';            return false;        }        return true;    }    public function refuse(){        $data = request()->post();        $data['apply_time'] = date('Y-m-d H:i:s');        $data['status'] = 2;        $id = $data['id'];        unset($data['id']);        if(!$data['apply_remark']){            $this->error = '审批意见不能为空';            return  false;        }        $ret = $this->allowField(true)->save($data,['id'=>$id]);        if(!$ret){            $this->error = '操作失败';            return false;        }        $userId = Db::name('meeting_apply')->where('id',$id)->value('user_id');        if($userId){            send_jpush([$userId],AppMsg::PUSH_CUSTOM,'您预约的会议室审批未通过');        }        return true;    }    //app接口    public function lists($page,$size,$userId,$orgId){        $ret = db('meeting_apply')            ->alias('ma')            ->field('ma.id,ma.start_time,ma.end_time,ma.status,u.real_name,mr.title,mr.waiter')            ->leftJoin('meeting_room mr','mr.id=ma.meeting_room_id')            ->leftJoin('user u','u.id=ma.user_id')            ->where([                'ma.status'=>0,                'ma.del'=>0,                'ma.org_id'=>$orgId,                'ma.approver'=>$userId,            ])            ->order('ma.id desc')            ->page($page,$size)            ->select();        return $ret?$ret:[];    }    public function blist($page,$size,$title,$userId,$orgId){        if($title){            $map[] = ['u.real_name|ma.theme','like','%'.$title.'%'];        }        $map[] = ['ma.del','=',0];        $map[] = ['ma.org_id','=',$orgId];        $map[] = ['ma.approver','=',$userId];        $ret = db('meeting_apply')            ->alias('ma')            ->field('ma.id,ma.start_time,ma.end_time,ma.status,u.real_name,mr.title,mr.waiter')            ->join('meeting_room mr','mr.id=ma.meeting_room_id')            ->join('user u','u.id=ma.user_id')            ->where($map)            ->order('ma.id desc')            ->page($page,$size)            ->select();        return $ret?$ret:[];    }    public function searchs($page,$size,$title,$userId,$orgId){        $ret = db('meeting_apply')            ->alias('ma')            ->field('ma.id,ma.start_time,ma.end_time,ma.status,u.real_name,mr.title,mr.waiter')            ->join('meeting_room mr','mr.id=ma.meeting_room_id')            ->join('user u','u.id=ma.user_id')            ->where([                'ma.del'=>0,                'ma.org_id'=>$orgId,                'ma.approver'=>$userId,            ])            ->whereIn('ma.status',[1,2,3])            ->where(function ($query) use($title){                $query->where('u.real_name','like','%.'.$title.'%')                    ->whereOr('ma.theme','like','%'.$title.'%');            })            ->order('ma.id desc')            ->page($page,$size)            ->select();        return $ret?$ret:[];    }    public function details($id){        $info = db('meeting_apply')->where('id',$id)->where('del',0)->find();        if($info){            //发起人            $info['user_name'] = db('user')->where('id',$info['user_id'])->value('real_name');            //会议室名称            $info['meeting_room_title'] = db('meeting_room')->where('id',$info['meeting_room_id'])->value('title');            //参会人员            $userIds = $info['user_ids'] ? explode(',',$info['user_ids']):[];            $info['meeting_user'] = db('user')->field('real_name,head_image')->whereIn('id',$userIds)->select();            //设备            $info['device'] = db('meeting_device')->field('title')->whereIn('id',$info['meeting_devices'])->select();            //审批人            $applyUser = db('user')->where('id',$info['approver'])->find();            $info['approver_user'] = $applyUser?$applyUser['real_name']:'';            $info['approver_head_img'] = $applyUser?$applyUser['head_image']:'';            //会议室服务人员            $info['waiter'] = db('meeting_room')->where('id',$info['meeting_room_id'])->value('waiter');            //使用部门            $info['dep_name'] = Db::name('dep')->where('id',$info['dep_id'])->value('title');        }        return $info?$info:[];    }    public function confirms($id,$content,$serviceId){        $info = db('meeting_apply')->where('del',0)->where('id',$id)->find();        if(!$info){            $this->error = '记录不存在';            return false;        }        if($info['status'] != 0){            $this->error = '已处理,无法审核';            return false;        }        $data=[            'status'=>1,            'apply_remark'=>$content,            'apply_time'=>date('Y-m-d H:i:s')        ];        $save = db('meeting_apply')->where('id',$id)->update($data);        if($save > 0){//            send_push_meeting(11,[$info['USER_ID']],['id' => $info['ID']]);            if(!empty($serviceId)){                $sid = explode(',',$serviceId);                foreach ($sid as $v){                   db('meet_service')->insert(['meetapply_id'=>$id,'user_id'=>$v]);                }//                send_push_meeting(15,$sid,['id' => $info['ID']]);            }        }else{            $this->error = '操作失败';            return false;        }        return $save;    }    public function rejects($id,$content){        $info = db('meeting_apply')->where('del',0)->where('id',$id)->find();        if(!$info){            $this->error = '记录不存在';            return false;        }        if($info['status'] != 0){            $this->error = '已处理,无法审核';            return false;        }        $data=[            'status'=>2,            'apply_remark'=>$content,            'apply_time'=>date('Y-m-d H:i:s')        ];        $save = db('meeting_apply')->where('id',$id)->update($data);        if($save){//            send_push_meeting(12,[$info['USER_ID']],['id' => $info['ID']]);        }else{            $this->error = '操作失败';            return false;        }        return $save;    }    public function myReserves($page,$size,$userId,$orgId){        $ret = db('meeting_apply')            ->alias('ma')            ->field('ma.id,ma.start_time,ma.end_time,ma.status,mr.title,mr.address')            ->join('meeting_room mr','mr.id=ma.meeting_room_id')            ->where([                'ma.del'=>0,                'ma.org_id'=>$orgId,                'ma.USER_ID'=>$userId,            ])            ->order('ma.id desc')            ->page($page,$size)            ->select();        foreach ($ret as $k=>$v){            $newstarttime=date('Y-m-d H:i',strtotime($v['start_time']));            $newendtime=date('H:i',strtotime($v['end_time']));            $ret[$k]['meeting_time']=$newstarttime.'~'.$newendtime;        }        return $ret?$ret:[];    }    public function cancelReserves($id){        $data=[            'cancel_time'=>date('Y-m-d H:i:s'),            'status'=>3        ];        $ret = db('meeting_apply')->where('id',$id)->update($data);        return $ret;    }    public function reserveDetails($id){        $info = db('meeting_apply')            ->field('id,meeting_room_id,start_time,end_time,status,nums,user_ids,meeting_devices,banner,theme,approver,dep_id')            ->where('id',$id)            ->where('del',0)            ->find();        if($info){            //会议室名称/人数/地址/设备            $meeting_room = db('meeting_room')->where('id',$info['meeting_room_id'])->find();            $info['meeting_room_title']=$meeting_room?$meeting_room['title']:'';            $info['meeting_room_content']=$meeting_room?$meeting_room['content']:'';            $info['meeting_room_limit']=$meeting_room?$meeting_room['limit']:'';            $info['meeting_room_address']=$meeting_room?$meeting_room['address']:'';            //会议室设备            $meeting_room_device = db('meeting_device')->field('title')->whereIn('id',$meeting_room['meeting_device_ids'])->select();            if($meeting_room_device){                foreach ($meeting_room_device as $k=>$v){                    $roomdevice[$k]=$v['title'];                }                $info['meeting_room_device']=$roomdevice?implode('/',$roomdevice):'';            }else{                $info['meeting_room_device']='';            }            //参会人员            $info['meeting_user'] = db('user')->field('real_name,head_image')->whereIn('id',$info['user_ids'])->select();            //审批单设备            $device= db('meeting_device')->field('title')->whereIn('id',$info['meeting_devices'])->select();            if($device){                foreach ($device as $k=>$v){                    $applydevice[$k]=$v['title'];                }                $info['meeting_apply_device']=$applydevice?implode('、',$applydevice):'';            }else{                $info['meeting_apply_device']='';            }            //会议室名称            $info['meeting_room_title'] = db('meeting_room')->where('id',$info['meeting_room_id'])->value('title');            //审批人            $applyUser = db('user')->field('real_name,head_image')->where('id',$info['approver'])->find();            $info['approver_user'] = $applyUser?$applyUser['real_name']:'';            $info['approver_head_img'] = $applyUser?$applyUser['head_image']:'';            $info['dep_name'] = Db::name('dep')->where('id',$info['dep_id'])->value('title');            unset($info['user_ids'],$info['approver'],$info['meeting_devices'],$info['meeting_room_id']);        }        return $info?$info:[];    }}
 |