|
@@ -75,6 +75,144 @@ class Lessonslot extends Backend
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 预约
|
|
|
+ */
|
|
|
+ public function booking(){
|
|
|
+ $id = input('id');
|
|
|
+ $info = Db::name('lesson_slot')->where('id',$id)->find();
|
|
|
+ if(!$info){
|
|
|
+ $this->error('请刷新重试');
|
|
|
+ }
|
|
|
+ if($info['status'] != 0){
|
|
|
+ $this->error('当前课程不能预约');
|
|
|
+ }
|
|
|
+ if($this->request->isPost()){
|
|
|
+ $user_id = input('user_id',0,'intval');
|
|
|
+ //来自接口
|
|
|
+ $slot_id = $id;
|
|
|
+ $number = input('number',1,'intval');
|
|
|
+ $remark = input('remark','','trim');
|
|
|
+ $paytype = 1;//支付类型:1=课程套餐,2=线上付款,3=购买套餐中,4=试课单
|
|
|
+ $packageorder_id = input('packageorder_id',0,'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)->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->error(__('预约名额只剩N名',['number'=>$num_remain]));
|
|
|
+ }
|
|
|
+
|
|
|
+ $number_hours = bcmul($number,$info['hours'],1);//每日课时按小时扣
|
|
|
+ $lesson_order = [
|
|
|
+ 'order_no' => createUniqueNo('S',$user_id),
|
|
|
+ 'user_id' => $user_id,
|
|
|
+ 'slot_id' => $slot_id,
|
|
|
+ 'lesson_id' => $info['lesson_id'],
|
|
|
+ 'order_amount' => bcmul($info['price'],$number,2),
|
|
|
+ 'order_status' => 0,
|
|
|
+ 'paytype' => $paytype, //支付类型:1=课程套餐,2=线上付款,3=购买套餐中,4=试课单
|
|
|
+ 'paytime' => 0,
|
|
|
+ 'createtime' => time(),
|
|
|
+// 'updatetime' => ,
|
|
|
+// 'finishtime' => ,
|
|
|
+ 'usernumber' => $number,
|
|
|
+ 'usernumber_hours' => $number_hours,
|
|
|
+ 'userremark' => $remark,
|
|
|
+ 'package_order_id' => 0,
|
|
|
+ 'package_remark' => '',// 比如:5/30,5-7/30
|
|
|
+ ];
|
|
|
+
|
|
|
+ //
|
|
|
+ Db::startTrans();
|
|
|
+ if($paytype == 1){
|
|
|
+ //检查已选择套餐
|
|
|
+ $map = [
|
|
|
+ 'user_id' =>$user_id,
|
|
|
+
|
|
|
+ 'endtime' => ['gt',time()],
|
|
|
+ 'remain' => ['gt',0],
|
|
|
+ 'order_status' => 1,
|
|
|
+// 'use_status' => 1, //已激活的
|
|
|
+ 'id' => $packageorder_id,
|
|
|
+ ];
|
|
|
+ $package_order = Db::name('package_order')->where($map)->where('find_in_set(:lesson_ids,lesson_ids)', ['lesson_ids' => $info['lesson_id']])->lock(true)->find();
|
|
|
+ if(!$package_order){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('配套信息不正确,请刷新重试');
|
|
|
+ }
|
|
|
+
|
|
|
+ //课时不足支撑报名人数
|
|
|
+ if($package_order['remain'] < $number_hours){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('该配套余额不足,可以使用其他配套');
|
|
|
+ }
|
|
|
+ if($package_order['use_status'] != 1){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('该配套尚未激活');
|
|
|
+ }
|
|
|
+
|
|
|
+ //扣除一节
|
|
|
+ $update = [
|
|
|
+ 'remain' => bcsub($package_order['remain'],$number_hours,1),
|
|
|
+ 'updatetime' => time(),
|
|
|
+ ];
|
|
|
+ $rs1 = Db::name('package_order')->where('id',$packageorder_id)->update($update);
|
|
|
+ if($rs1 === false){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('扣除套餐余额失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ //修改预约单数据
|
|
|
+ $lesson_order['order_amount'] = 0;
|
|
|
+ $lesson_order['order_status'] = 10;
|
|
|
+ $lesson_order['paytime'] = time();
|
|
|
+ $lesson_order['package_order_id'] = $packageorder_id;
|
|
|
+
|
|
|
+ $lesson_order['package_remark'] = ($package_order['sessions'] - $package_order['remain']) . '-' . ($package_order['sessions'] - $package_order['remain'] + $number_hours) .'/'. $package_order['sessions'];
|
|
|
+
|
|
|
+
|
|
|
+ //预约单写入
|
|
|
+ $lesson_order_id = Db::name('lesson_order')->insertGetId($lesson_order);
|
|
|
+ if(!$lesson_order_id){
|
|
|
+ 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('预约成功',['returntype'=>1]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $this->view->assign('row',$info);
|
|
|
+ return $this->view->fetch();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 取消
|
|
|
*/
|
|
|
public function cancel(){
|
|
@@ -84,7 +222,7 @@ class Lessonslot extends Backend
|
|
|
$this->error('请刷新重试');
|
|
|
}
|
|
|
if($info['status'] != 0){
|
|
|
- $this->error('当前订单不能取消');
|
|
|
+ $this->error('当前课程不能取消');
|
|
|
}
|
|
|
|
|
|
if($this->request->isPost()){
|
|
@@ -107,7 +245,7 @@ class Lessonslot extends Backend
|
|
|
$this->error('取消失败,请刷新重试');
|
|
|
}
|
|
|
|
|
|
- $lesson_info = Db::name('lesson')->where('id',$info['lesson_id'])->find();
|
|
|
+// $lesson_info = Db::name('lesson')->where('id',$info['lesson_id'])->find();
|
|
|
|
|
|
//找到所有的已报名订单
|
|
|
$lesson_order_list = Db::name('lesson_order')->where('slot_id',$id)->where('order_status',10)->lock(true)->select();
|