Sfoglia il codice sorgente

课时申请报名,before

lizhen_gitee 8 mesi fa
parent
commit
04afbd0c1a
1 ha cambiato i file con 59 aggiunte e 0 eliminazioni
  1. 59 0
      application/api/controller/Lesson.php

+ 59 - 0
application/api/controller/Lesson.php

@@ -403,6 +403,65 @@ class Lesson extends Api
         $this->success(1,$info);
     }
 
+    //课时申请报名,提前预判
+    public function slot_apply_before(){
+        $this->apiLimit();
+
+        $slot_id = input('slot_id',0,'intval');
+        $number  = input('number',1,'intval');
+
+        if($number <= 0){
+            $this->error('预约人数错误');
+        }
+
+        //课时
+        $info = Db::name('lesson_slot')->alias('slot')
+            ->field('slot.*,lesson.name,lesson.name_en,lesson.image,lesson.price')
+            ->join('lesson','slot.lesson_id = lesson.id','LEFT')
+            ->where('slot.id',$slot_id)->where('slot.status',0)->where('slot.is_show',1)->find();
+        if(empty($info)){
+            $this->error('课程可能已取消,请刷新重试');
+        }
+        if($info['endtime'] < time()){
+            $this->error('课程已经结束了,不能再进行预约');
+        }
+
+
+        //剩余空位数量
+        $pay_number = Db::name('lesson_order')->where('slot_id',$slot_id)->where('order_status',10)->sum('usernumber');
+        $num_remain = $info['num_max'] - $pay_number;
+        if($num_remain < 0){
+            $num_remain = 0;
+        }
+
+        //预约数量足够
+        if($num_remain >= $number){
+            $this->success('success',1);
+        }
+        //只要还有预约位置,就不能候补
+        if($num_remain > 0){
+            $this->error('可预约名额不足');
+        }
+
+        //剩余候补数量
+        $wait_remain = 0;
+        if($info['waitnum_max'] > 0){
+            $wait_number = Db::name('lesson_order')->where('slot_id',$info['id'])->where('jointype',2)->sum('usernumber');
+            $wait_remain = $info['waitnum_max'] - $wait_number;
+            if($wait_remain < 0){
+                $wait_remain = 0;
+            }
+        }
+
+        //候补数量足够
+        if($wait_remain >= $number){
+            $this->success('success',2);
+        }
+
+        //候补也不够了
+        $this->error('可候补名额不足');
+
+    }
     //课时申请报名
     public function slot_apply(){
         $this->apiLimit();