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]); // $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; } 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') ->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){ $ret = db('meeting_apply') ->alias('ma') ->field('ma.id,ma.start_time,ma.end_time,ma.status,u.real_name,mr.title') ->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, ]) ->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 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') ->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'); //参会人员 $info['meeting_user'] = db('user')->field('real_name,head_image')->whereIn('id',$info['user_id'])->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']:''; } 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')->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']:''; unset($info['user_ids'],$info['approver'],$info['meeting_devices'],$info['meeting_room_id']); } return $info?$info:[]; } }