瀏覽代碼

取消售课的预约

lizhen_gitee 1 年之前
父節點
當前提交
8709e4391b
共有 2 個文件被更改,包括 67 次插入1 次删除
  1. 13 1
      application/api/controller/Lesson.php
  2. 54 0
      application/api/controller/Usercenter.php

+ 13 - 1
application/api/controller/Lesson.php

@@ -39,6 +39,7 @@ class Lesson extends Api
 
         $where = [
             'slot.starttime' => ['BETWEEN',[$date,$date+86399]],
+            'slot.status' => 0
         ];
         if($lesson_id){
             $where['slot.lesson_id'] = $lesson_id;
@@ -131,6 +132,8 @@ class Lesson extends Api
 
     //课时申请报名
     public function slot_apply(){
+        $this->apiLimit();
+
         $slot_id = input('slot_id',0,'intval');
         $number  = input('number',1,'intval');
         $remark  = input('remark','','trim');
@@ -147,7 +150,7 @@ class Lesson extends Api
         $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)->find();
+            ->where('slot.id',$slot_id)->where('slot.status',0)->find();
         if(empty($info)){
             $this->error('课程可能已取消,请刷新重试');
         }
@@ -155,6 +158,15 @@ class Lesson extends Api
             $this->error('课程已经结束了,不能再进行预约');
         }
 
+        //报名人数不能超限
+        if($info['num_max' > 0]){
+            $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 < $number){
+                $this->error('报名名额只剩'.$num_remain.'名');
+            }
+        }
+
         $lesson_order = [
             'order_no' => createUniqueNo('S',$this->auth->id),
             'user_id' => $this->auth->id,

+ 54 - 0
application/api/controller/Usercenter.php

@@ -149,6 +149,60 @@ class Usercenter extends Api
         $this->success(1,$list);
     }
 
+    //取消售课预约单
+    public function cancel_lesson_order(){
+        $order_id = input('order_id',0);
+
+        $map = [
+            'id' => $order_id,
+            'user_id' => $this->auth->id,
+        ];
+        $lesson_order = Db::name('lesson_order')->where($map)->find();
+
+        if($lesson_order['order_status'] != 10){
+            $this->error('此订单状态无法取消');
+        }
+
+        //还有24小时上课,不能取消
+        $slot = Db::name('lesson_slot')->where('id',$lesson_order['slot_id'])->find();
+        if($slot['starttime'] - time() <= 86400){
+            $this->error('距离上课时间不足24小时,不能取消');
+        }
+
+        Db::startTrans();
+
+        //套餐给加回去
+        if($lesson_order['paytype'] == 1){
+            $package_order = Db::name('package_order')->where('id',$lesson_order['package_order_id'])->lock(true)->find();
+            $update = [
+                'remain' => $package_order['remain'] + $lesson_order['usernumber'],
+            ];
+            $rs_remain = Db::name('package_order')->where('id',$lesson_order['package_order_id'])->update($update);
+            if($rs_remain === false){
+                Db::rollback();
+                $this->error('取消失败');
+            }
+        }
+
+        //现金支付不给退,线下处理
+
+        //取消预约单
+        $update = [
+            'order_status' => 30,
+            'cancel_time' => time(),
+            'cancel_reason' => '用户在开课24小时之前主动取消',
+        ];
+
+        $rs = Db::name('lesson_order')->where($map)->update($update);
+        if($rs === false){
+            Db::rollback();
+            $this->error('取消失败');
+        }
+
+        $this->success('取消完成');
+
+    }
+
     //过期课程。就是过了上课时间,没签到的
     public function lesson_order_signout(){
         $map = [