|
@@ -230,19 +230,37 @@ class Usercenter extends Api
|
|
|
'id' => $order_id,
|
|
|
'user_id' => $this->auth->id,
|
|
|
];
|
|
|
- $lesson_order = Db::name('lesson_order')->where($map)->find();
|
|
|
+ Db::startTrans();
|
|
|
+ $lesson_order = Db::name('lesson_order')->where($map)->lock(true)->find();
|
|
|
+
|
|
|
+ //取消候补单
|
|
|
+ if($lesson_order['jointype'] == 2){
|
|
|
+
|
|
|
+ $update = [
|
|
|
+ 'order_status' => 30,
|
|
|
+ 'cancel_time' => time(),
|
|
|
+ 'cancel_reason' => __('用户主动取消'),
|
|
|
+ ];
|
|
|
+
|
|
|
+ $rs = Db::name('lesson_order')->where($map)->update($update);
|
|
|
+ Db::commit();
|
|
|
+ $this->success('取消完成');
|
|
|
|
|
|
+ }
|
|
|
+
|
|
|
+ //剩下的都是预约单
|
|
|
if($lesson_order['order_status'] != 10){
|
|
|
+ Db::rollback();
|
|
|
$this->error('此订单已无法取消');
|
|
|
}
|
|
|
|
|
|
//还有24小时上课,不能取消
|
|
|
$slot = Db::name('lesson_slot')->where('id',$lesson_order['slot_id'])->find();
|
|
|
if($slot['starttime'] - time() <= 86400){
|
|
|
+ Db::rollback();
|
|
|
$this->error('距离上课时间不足24小时,不能取消');
|
|
|
}
|
|
|
|
|
|
- Db::startTrans();
|
|
|
|
|
|
//套餐给加回去
|
|
|
if($lesson_order['paytype'] == 1){
|
|
@@ -537,7 +555,7 @@ class Usercenter extends Api
|
|
|
$order['hours'] = floatval($order['hours']);
|
|
|
|
|
|
//距离开课大于24小时可以申请取消
|
|
|
- if($order['jointype'] == 1 && $order['starttime'] - time() > 86400){
|
|
|
+ if($order['starttime'] - time() > 86400){
|
|
|
$order['can_cancel'] = 1;
|
|
|
}else{
|
|
|
$order['can_cancel'] = 0;
|
|
@@ -605,7 +623,7 @@ class Usercenter extends Api
|
|
|
$order['hours'] = floatval($order['hours']);
|
|
|
|
|
|
//24小时内可以申请取消
|
|
|
- if($order['jointype'] == 1 && $order['starttime'] - time() > 86400){
|
|
|
+ if($order['starttime'] - time() > 86400){
|
|
|
$order['can_cancel'] = 1;
|
|
|
}else{
|
|
|
$order['can_cancel'] = 0;
|