| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 | 
							- <?php
 
- namespace app\api\controller\h5;
 
- use app\hander\HelpHander;
 
- use think\facade\Request;
 
- use think\Db;
 
- class VisitorOrder extends Base
 
- {
 
-     // 获取我的预约记录
 
-     public function list(){
 
-         $lists = Db::name('visitor_order')
 
-             ->field('id,org_id,status,service_id,service_time_id,name,phone')
 
-             ->where('user_id',$this->userId)
 
-             ->where('del',0)
 
-             ->whereIn('type',[1,2])
 
-             ->select();
 
-         foreach ($lists as $k=>$v){
 
-             $lists[$k]['org_name'] = Db::name('org')->where('id',$v['org_id'])->value('name');
 
-             $lists[$k]['title'] = '';
 
-             $lists[$k]['day'] = '';
 
-             $lists[$k]['start'] = '';
 
-             $lists[$k]['end'] = '';
 
-             if($v['service_time_id'] > 0){
 
-                 $time = Db::name('service_time')->where('id',$v['service_time_id'])->find();
 
-                 $lists[$k]['day'] = $time?$time['day']:'';
 
-                 $lists[$k]['start'] = date('H:i',strtotime($time['day'].' '.$time['start']));
 
-                 $lists[$k]['end'] = date('H:i',strtotime($time['day'].' '.$time['end']));
 
-                 $lists[$k]['title'] = Db::name('service')->where('id',$v['service_id'])->value('title');
 
-                 $v = $this->autoCheck($v,$time);
 
-                 $lists[$k]['status'] = $v['status'];
 
-             }
 
-             $lists[$k]['qrcode'] = Request::domain().'/admin/Qrcode/qrcode?code='.get_qrcode_str('visitor',$v['id']);
 
-         }
 
-         HelpHander::success($lists);
 
-     }
 
-     // 获取我的预约记录--小程序
 
-     public function list2(){
 
-         $type = input('type/d',0);
 
-         if(!in_array($type,[0,1,2])){
 
-             HelpHander::error('参数错误');
 
-         }
 
-         $map[] = ['del','=',0];
 
-         $map[] = ['user_id','=',$this->userId];
 
-         if($type==1){
 
-             $map[] = ['status','=',0];
 
-         }else if($type==2){
 
-             $map[] = ['status','in',[1,4]];
 
-         }
 
-         $lists = Db::name('visitor_order')->where($map)->select();
 
-         $lists = $lists?$lists:[];
 
-         foreach ($lists as $k=>$v){
 
-             $lists[$k]['org_name'] = Db::name('org')->where('id',$v['org_id'])->value('name');
 
-             $lists[$k]['from_user_name'] = Db::name('user')->where('id',$v['from_user_id'])->value('real_name');
 
-             $lists[$k]['qrcode'] = Request::domain().'/admin/Qrcode/qrcode?code='.get_qrcode_str('visitor',$v['id']);
 
-         }
 
-         HelpHander::success($lists);
 
-     }
 
-     // 提交确认
 
-     public function order(){
 
-         $type = input('type');
 
-         $serviceTimeId = input('serviceTimeId',0);
 
-         $name = input('name','','trim');
 
-         $phone = input('phone','','trim');
 
-         if(!in_array($type,[1,2])){
 
-            HelpHander::error('参数错误');
 
-         }
 
-         if($type == 1 && $serviceTimeId <= 0){
 
-             HelpHander::error('未选择预约时间');
 
-         }
 
-         if(!$name){
 
-           HelpHander::error('请填写姓名');
 
-         }
 
-         if(!check_mobile($phone)){
 
-            HelpHander::error('手机号格式不正确');
 
-         }
 
-         $data = [
 
-             'name' => $name,
 
-             'phone' => $phone,
 
-             'org_id' => $this->orgId,
 
-             'user_id' => $this->userId,
 
-             'status' => 0,
 
-             'type' => $type,
 
-             'create_time' => date('Y-m-d H:i:s')
 
-         ];
 
-         if($type == 1){
 
-             $service = Db::name('service_time')
 
-                 ->alias('st')
 
-                 ->join('service s','s.id = st.service_id')
 
-                 ->where('st.id',$serviceTimeId)
 
-                 ->where('s.enable',1)
 
-                 ->where('s.del',0)
 
-                 ->where('st.enable',1)
 
-                 ->where('st.del',0)
 
-                 ->find();
 
-             if(!$service){
 
-                 HelpHander::error('该服务已关闭');
 
-             }
 
-             // 检查时间段是否已过
 
-             $endTime = strtotime($service['day'].' '.$service['end']);
 
-             if(time() >= $endTime){
 
-                  HelpHander::error('该时间段已过,无法预约');
 
-             }
 
-             // 检查是否还有名额
 
-             $count = Db::name('visitor_order')
 
-                 ->where('service_time_id',$serviceTimeId)
 
-                 ->whereIn('status',[0,1,2,3])
 
-                 ->where('del',0)
 
-                 ->count();
 
-             if($service['limit'] <= $count){
 
-                 HelpHander::error('该时间段已无预约名额');
 
-             }
 
-             // 检查用户是否已预约改时间段
 
-             $ret = Db::name('visitor_order')
 
-                 ->where('user_id',$this->userId)
 
-                 ->where('service_time_id',$serviceTimeId)
 
-                 ->whereIn('status',[0,1,2,3])
 
-                 ->where('del',0)
 
-                 ->find();
 
-             if($ret){
 
-                 HelpHander::error('已预约该时段,无重复预约');
 
-             }
 
-             $data['service_id'] = $service['service_id'];
 
-             $data['service_time_id'] = $serviceTimeId;
 
-         }
 
-         $add = Db::name('visitor_order')->insert($data);
 
-         if ($add) {
 
-             HelpHander::success([],'提交成功');
 
-         }else{
 
-             HelpHander::error('提交失败');
 
-         }
 
-     }
 
-     // 提交确认--小程序
 
-     public function order2(){
 
-         $type = 3;
 
-         $company = input('company','','trim');
 
-         $name = input('name','','trim');
 
-         $phone = input('phone','','trim');
 
-         $plateSn = input('plateSn','','trim');
 
-         $bookTime = input('bookTime','','trim');
 
-         $content = input('content','','trim');
 
-         $fromUserId = input('fromUserId/d',0);
 
-         if(!$fromUserId){
 
-             HelpHander::error('参数错误');
 
-         }
 
-         if($fromUserId == $this->userId){
 
-             HelpHander::error('不能填写自己分享的预约单');
 
-         }
 
-         if(!$company){
 
-             HelpHander::error('请填写单位');
 
-         }
 
-         if(!$name){
 
-             HelpHander::error('请填写姓名');
 
-         }
 
-         if(!check_mobile($phone)){
 
-             HelpHander::error('手机号格式不正确');
 
-         }
 
-         if(!$bookTime){
 
-             HelpHander::error('请选择到访时间');
 
-         }
 
-         if(!$content){
 
-             HelpHander::error('请填写到访事由');
 
-         }
 
-         $data = [
 
-             'name' => $name,
 
-             'phone' => $phone,
 
-             'org_id' => $this->orgId,
 
-             'user_id' => $this->userId,
 
-             'from_user_id' => $fromUserId,
 
-             'status' => 0,
 
-             'type' => $type,
 
-             'create_time' => date('Y-m-d H:i:s'),
 
-             'book_time' => $bookTime,
 
-             'plate_sn' => $plateSn,
 
-             'company' => $company,
 
-             'content' => $content
 
-         ];
 
-         $ret = Db::name('visitor_order')->insert($data);
 
-         if ($ret) {
 
-             HelpHander::success([],'提交成功');
 
-         }else{
 
-             HelpHander::error('提交失败');
 
-         }
 
-     }
 
-     public function detail(){
 
-         $id = input('id/d',0);
 
-         $info = Db::name('visitor_order')->where('id',$id)->where('del',0)->find();
 
-         if($info){
 
-             $info['ORG_NAME'] = Db::name('org')->where('id',$info['org_id'])->value('name');
 
-             $info['from_user_name'] = Db::name('user')->where('id',$info['from_user_id'])->value('real_name');
 
-             $info['qrcode'] = Request::domain().'/admin/Qrcode/qrcode?code='.get_qrcode_str('visitor',$info['id']);
 
-         }else{
 
-             HelpHander::error('记录不存在');
 
-         }
 
-         HelpHander::success($info);
 
-     }
 
-     // 自动检测预约已失效
 
-     private function autoCheck($info,$time){
 
-         if($info['status'] == 1){
 
-             $curTime = time();
 
-             $endTime = strtotime($time['day'].' '.$time['end']);
 
-             if($curTime >= $endTime){
 
-                 Db::name('visitor_order')->where('id',$info['id'])->update(['status'=>3]);
 
-                 $info['status'] = 3;
 
-             }
 
-         }
 
-         return $info;
 
-     }
 
- }
 
 
  |