123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- <?php
- namespace app\common\model;
- use think\Db;
- class MeetingRoom extends Base
- {
- protected $createTime = 'create_time';
- public function updates(){
- $data = request()->post();
- $data['org_id'] = cur_org_id();
- $result = validate('MeetingRoom')->check($data,[],'');
- if(true !== $result){
- $this->error = validate('MeetingRoom')->getError();
- return false;
- }
- $id = $data['id'];
- unset($data['id']);
- 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;
- }
- //app接口
- public function checkApprover($userId,$orgId){
- $info = db('meeting_room')->where('enable',1)->where('del',0)->where('approver',$userId)->where('org_id',$orgId)->find();
- if(!$info){
- $this->error = '不是会议室审批人';
- return false;
- }
- $undeal = db('meeting_apply')->where('status',0)->where('del',0)->where('approver',$userId)->where('org_id',$orgId)->count();
- return ['count' => $undeal];
- }
- public function getRoomByDay($day,$orgId){
- $lists = db('meeting_room')
- ->field('id,title,content,address,img,limit')
- ->where('enable',1)
- ->where('del',0)
- ->where('org_id',$orgId)
- ->order(['sort'=>'desc','id'=>'desc'])
- ->select();
- $lists = $lists?$lists:[];
- // 获取48个时间段
- $times = $this->getTimesDay($day);
- foreach ($lists as $k=>$v){
- $stime = $times;
- foreach ($stime as $kk=>$vv){
- $ret = db('meeting_apply')
- ->whereIn('status',[0,1])
- ->where('del',0)
- ->where('org_id',$orgId)
- ->where('start_time','<',$vv['etime'])
- ->where('end_time','>',$vv['stime'])
- ->where('meeting_room_id',$v['id'])
- ->find();
- if($ret){
- if($vv['status'] == 0){
- $stime[$kk]['status'] = 3;
- }else{
- $stime[$kk]['status'] = 2;
- }
- }
- }
- $lists[$k]['times'] = $stime;
- }
- return $lists;
- }
- private function getTimesDay($day){
- $times = [];
- $curTime = date('Y-m-d H:i:s');
- $nextday = date('Y-m-d',strtotime($day)+24*60*60);
- for ($i=0;$i<24;$i++){
- if($i == 23){
- $a = [
- 'stime' => $day.' '.$i.':00:00',
- 'etime' => $day.' '.$i.':30:00',
- 'status' => 0 // 0=白色 1=灰色 2=黄色(历史预订) 3=蓝色(已预订)
- ];
- $b = [
- 'stime' => $day.' '.$i.':30:00',
- 'etime' => $nextday.' '.'00:00:00',
- 'status' => 0 // 0=白色 1=灰色 2=黄色(历史预订) 3=蓝色(已预订)
- ];
- }else if($i>9&&$i<23){
- $a = [
- 'stime' => $day.' '.$i.':00:00',
- 'etime' => $day.' '.$i.':30:00',
- 'status' => 0 // 0=白色 1=灰色 2=黄色(历史预订) 3=蓝色(已预订)
- ];
- $b = [
- 'stime' => $day.' '.$i.':30:00',
- 'etime' => $day.' '.($i+1).':00:00',
- 'status' => 0 // 0=白色 1=灰色 2=黄色(历史预订) 3=蓝色(已预订)
- ];
- }else if($i == 9){
- $a = [
- 'stime' => $day.' 0'.$i.':00:00',
- 'etime' => $day.' 0'.$i.':30:00',
- 'status' => 0 // 0=白色 1=灰色 2=黄色(历史预订) 3=蓝色(已预订)
- ];
- $b = [
- 'stime' => $day.' 0'.$i.':30:00',
- 'etime' => $day.' '.'10:00:00',
- 'status' => 0 // 0=白色 1=灰色 2=黄色(历史预订) 3=蓝色(已预订)
- ];
- }else{
- $a = [
- 'stime' => $day.' 0'.$i.':00:00',
- 'etime' => $day.' 0'.$i.':30:00',
- 'status' => 0 // 0=白色 1=灰色 2=黄色(历史预订) 3=蓝色(已预订)
- ];
- $b = [
- 'stime' => $day.' 0'.$i.':30:00',
- 'etime' => $day.' 0'.($i+1).':00:00',
- 'status' => 0 // 0=白色 1=灰色 2=黄色(历史预订) 3=蓝色(已预订)
- ];
- }
- if($curTime > $a['stime']){
- $a['status'] = 1;
- }
- if($curTime > $b['stime']){
- $b['status'] = 1;
- }
- $times[] = $a;
- $times[] = $b;
- }
- return $times;
- }
- public function details($id,$time,$orgId){
- $info = db('meeting_room')
- ->field('id,title,content,address,img,approver,meeting_device_ids,limit')
- ->where('enable',1)
- ->where('del',0)
- ->where('org_id',$orgId)
- ->where('id',$id)
- ->find();
- if(!$info){
- $this->error = '记录不存在';
- return false;
- }
- $info['devices'] = db('meeting_device')
- ->field('id,title')
- ->whereIn('id',$info['meeting_device_ids'])
- ->select();
- $day = $time;
- $times = $this->getTimesDay($day);
- $newtimes = [];
- foreach ($times as $k=>$v){
- if($v['status'] == 0){
- $status = 0;
- $ret = db('meeting_apply')
- ->whereIn('status',[0,1])
- ->where('del',0)
- ->where('org_id',$orgId)
- ->where('start_time','<',$v['etime'])
- ->where('end_time','>',$v['stime'])
- ->where('meeting_room_id',$info['id'])
- ->find();
- if($ret){
- $status = 1;
- }
- $newtimes[] = [
- 'status' => $status,
- 'stime' => $v['stime'],
- 'etime' => $v['etime'],
- 'stimetext' => date('H:i',strtotime($v['stime'])),
- 'etimetext' => date('H:i',strtotime($v['etime']))
- ];
- }
- }
- $info['times'] = $newtimes;
- $approver = db('user')->where('id',$info['approver'])->field('head_image,real_name')->find();
- $info['approver_img'] =$approver?$approver['head_image']:'';
- $info['approver_name'] =$approver?$approver['real_name']:'';
- return $info;
- }
- // 保存会议室预定
- public function saveBook($data){
- Db::startTrans();
- try{
- $approver = db('meeting_room')->where('id',$data['meeting_room_id'])->value('approver');
- $data['approver'] = $approver;
- $data['create_time'] = getTime();
- $roomInfo = db('meeting_room')->where('id',$data['meeting_room_id'])->find();
- if($roomInfo['is_check'] == 0){
- $data['status'] = 1;
- $data['approver'] = 0;//不需要审核
- $data['apply_time'] = getTime();
- }
- //添加
- $applyId = db('meeting_apply')->insertGetId($data);
- if($applyId < 1){
- exception('操作失败');
- }
- //通知审批人员
- send_jpush([$approver],19,['id' => $applyId]);
- Db::commit();
- }catch (\Exception $e){
- Db::rollback();
- $this->error = $e->getMessage();
- return false;
- }
- return true;
- }
- }
|