Browse Source

用户选择排班,下单检查排班

lizhen_gitee 9 tháng trước cách đây
mục cha
commit
4445aac976
2 tập tin đã thay đổi với 62 bổ sung2 xóa
  1. 29 0
      application/api/controller/Index.php
  2. 33 2
      application/api/controller/Wenzhen.php

+ 29 - 0
application/api/controller/Index.php

@@ -116,7 +116,36 @@ class Index extends Api
         $this->success(1,$info);
     }
 
+    //医生排班
+    public function doctor_paiban(){
+        $doctor_id = input('doctor_id',0);
+
+        $list = Db::name('doctor_paiban')->where('doctor_id',$doctor_id)->where('active',1)->where('activetime','gt',time()+7200)->order('activetime asc')->select();
+
+        $result = [];
+        if(!empty($list)){
+            //排除接满4单的
+            $newlist = [];
+            foreach($list as $key => $val){
+                $date = date('Y-m-d',$val['activetime']);
+                if(!isset($newlist[$date])){
+                    $newlist[$date] = [];
+                }
+
+                $val['activetime_text'] = date('H:i',$val['activetime']);
+                $newlist[$date][] = $val;
+            }
 
+            foreach($newlist as $k => $v){
+                $result[] = [
+                    'date'=>$k,
+                    'child' => $v,
+                ];
+            }
+        }
+
+        $this->success(1,$result);
+    }
 
 
 }

+ 33 - 2
application/api/controller/Wenzhen.php

@@ -65,6 +65,37 @@ class Wenzhen extends Api
             $this->error('价格为零');
         }
 
+        //排班判断
+        if($ordertype == 1){
+            $book_time = 0;
+        }
+        if($ordertype == 2){
+            //检查
+            if($book_time < time() + 7200){
+                $this->error('最早只能预约'.date('m-d H:00',time() + 10800)); //最早预约两个小时后的一个整点
+            }
+            //排班状态
+            $doctor_paiban = Db::name('doctor_paiban')->where('doctor_id',$doctor_id)->where('activetime',$book_time)->find();
+            if(empty($doctor_paiban)){
+                $this->error('您预约的时间该医生无法接诊');
+            }
+            if($doctor_paiban['active'] != 1){
+                $this->error('您预约的时间该医生无法接诊');
+            }
+            //是否排满
+            $map = [
+                'doctor_id' => $doctor_id,
+                'book_time' => $book_time,
+                'ordertype' => 2,
+                'status'    => ['IN','10,20,25,30'],
+            ];
+            $order_count = Db::name('wenzhen_order')->where($map)->count();
+            if($order_count >= 4){
+                $this->error('该时间点已排满');
+            }
+
+        }
+
          //订单数据
         $order_data = [
             'order_no'   => $order_no,
@@ -73,7 +104,7 @@ class Wenzhen extends Api
             'doctor_id'  => $doctor_id,
             'ordertype'  => $ordertype,
             'total_fee'  => $price,
-            'book_time'  => strtotime($book_time),
+            'book_time'  => $book_time,
             'createtime' => time(),
             'status'     => 0,//订单状态enum
         ];
@@ -157,7 +188,7 @@ class Wenzhen extends Api
                     'name' => '待接单',
                     'status' => '10',
                     'id' => (string)$order_id,
-                    'content' => '已通知医生尽快接诊,超时自动取消订单并退款',
+                    'content' => '已通知医生尽快接诊,超时未接诊的将自动取消订单并退款',
                 ];
                 $rs = $tenim->sendCustomMessageToUser('user'.$this->auth->id,'doctor'.$wenzhen_order['doctor_id'],$message);
             }