|
@@ -85,7 +85,7 @@ class Lessonslot extends Backend
|
|
|
$this->error('请刷新重试');
|
|
|
}
|
|
|
if($info['status'] != 0){
|
|
|
- $this->error('当前课程不能预约');
|
|
|
+ $this->error('当前课程不能预约');//状态:0=报名中,20=已点名,30=已取消
|
|
|
}
|
|
|
if($this->request->isPost()){
|
|
|
$user_id = input('user_id',0,'intval');
|
|
@@ -93,11 +93,19 @@ class Lessonslot extends Backend
|
|
|
$slot_id = input('slot_id',0,'intval');
|
|
|
$number = input('number',1,'intval');
|
|
|
$remark = input('remark','','trim');
|
|
|
- $paytype = 1;//支付类型:1=课程套餐,2=线上付款,3=购买套餐中,4=试课单
|
|
|
+
|
|
|
$packageorder_id = input('packageorder_id',0,'intval');
|
|
|
+ $trylessonorder_id = input('trylessonorder_id',0,'intval');
|
|
|
+
|
|
|
+ $params = $this->request->post('row/a');
|
|
|
+ $paytype = $params['paytype'];//支付类型:1=课程套餐,4=试课单
|
|
|
+
|
|
|
if($number <= 0){
|
|
|
$this->error('预约人数错误');
|
|
|
}
|
|
|
+ if($paytype == 4){
|
|
|
+ $number = 1; //试课只能选一个人
|
|
|
+ }
|
|
|
|
|
|
//课时
|
|
|
$info = Db::name('lesson_slot')->alias('slot')
|
|
@@ -208,6 +216,56 @@ class Lessonslot extends Backend
|
|
|
Db::commit();
|
|
|
$this->success('预约成功');
|
|
|
}
|
|
|
+ elseif($paytype == 4){
|
|
|
+ //使用试课单
|
|
|
+ $map = [
|
|
|
+ 'id' => $trylessonorder_id,
|
|
|
+ 'user_id' =>$user_id,
|
|
|
+ 'endtime' => ['gt',time()],
|
|
|
+ 'order_status' => 10,
|
|
|
+ ];
|
|
|
+ $trylesson_order = Db::name('trylesson_order')->where($map)->where('find_in_set(:lesson_ids,lesson_ids)', ['lesson_ids' => $info['lesson_id']])->lock(true)->find();
|
|
|
+ if(!$trylesson_order){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('未找到对应的试课');
|
|
|
+ }
|
|
|
+
|
|
|
+ //修改预约单数据
|
|
|
+ $lesson_order['order_amount'] = 0;
|
|
|
+ $lesson_order['order_status'] = 10;
|
|
|
+ $lesson_order['paytime'] = time();
|
|
|
+ $lesson_order['trylesson_order_id'] = $trylessonorder_id;
|
|
|
+
|
|
|
+ //预约单写入
|
|
|
+ $lesson_order_id = Db::name('lesson_order')->insertGetId($lesson_order);
|
|
|
+ if(!$lesson_order_id){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('预约失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ //改掉试课单状态
|
|
|
+ $update = [
|
|
|
+ 'order_status' => 20,
|
|
|
+ 'updatetime' => time(),
|
|
|
+ 'lesson_order_id' => $lesson_order_id,
|
|
|
+ ];
|
|
|
+ $rs1 = Db::name('trylesson_order')->where('id',$trylessonorder_id)->update($update);
|
|
|
+ if($rs1 === false){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('使用试课失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ //更新已预约人数
|
|
|
+ $pay_number = Db::name('lesson_order')->where('slot_id',$slot_id)->where('order_status',10)->sum('usernumber');
|
|
|
+ $rs_slot = Db::name('lesson_slot')->where('id',$slot_id)->update(['bookednum' => $pay_number]);
|
|
|
+ if($rs_slot === false){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('预约失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ Db::commit();
|
|
|
+ $this->success('预约成功');
|
|
|
+ }
|
|
|
}
|
|
|
$this->view->assign('row',$info);
|
|
|
return $this->view->fetch();
|