|
@@ -3,7 +3,8 @@
|
|
|
namespace app\admin\controller;
|
|
|
|
|
|
use app\common\controller\Backend;
|
|
|
-
|
|
|
+use think\Db;
|
|
|
+use app\common\library\Email;
|
|
|
/**
|
|
|
* 售课预约订单
|
|
|
*
|
|
@@ -76,77 +77,67 @@ class Lessonorder extends Backend
|
|
|
*/
|
|
|
public function cancel(){
|
|
|
$id = input('id');
|
|
|
- $info = Db::name('lesson_order')->where('id',$id)->where('status',0)->find();
|
|
|
+ $info = Db::name('lesson_order')->where('id',$id)->where('order_status',10)->find();
|
|
|
if(!$info){
|
|
|
$this->error('请刷新重试');
|
|
|
}
|
|
|
|
|
|
if($this->request->isPost()){
|
|
|
- $remark = input('remark','');
|
|
|
$cancel_reason = input('cancel_reason','');
|
|
|
$cancel_time = strtotime(input('cancel_time',''));
|
|
|
|
|
|
Db::startTrans();
|
|
|
- $update = [
|
|
|
- 'status' => 30,
|
|
|
- 'remark' => $remark,
|
|
|
+
|
|
|
+ //找到所有的已报名订单
|
|
|
+ $info = Db::name('lesson_order')->where('id',$id)->where('order_status',10)->lock(true)->find();
|
|
|
+ if(empty($info)){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('请刷新重试');
|
|
|
+ }
|
|
|
+
|
|
|
+ //套餐给加回去
|
|
|
+ if($info['paytype'] == 1){
|
|
|
+ $package_order = Db::name('package_order')->where('id',$info['package_order_id'])->lock(true)->find();
|
|
|
+ $update = [
|
|
|
+ 'remain' => $package_order['remain'] + $info['usernumber'],
|
|
|
+ 'updatetime' => time(),
|
|
|
+ ];
|
|
|
+ $rs_remain = Db::name('package_order')->where('id',$info['package_order_id'])->update($update);
|
|
|
+ if($rs_remain === false){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('取消失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //现金支付不给退,线下处理
|
|
|
+
|
|
|
+ //取消预约单
|
|
|
+ $update2 = [
|
|
|
+ 'order_status' => 30,
|
|
|
+ 'cancel_time' => $cancel_time,
|
|
|
'cancel_reason' => $cancel_reason,
|
|
|
- 'cancel_time' => $cancel_time
|
|
|
];
|
|
|
+ if($info['paytype'] == 1){
|
|
|
+ $update2['order_status'] = 40;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
- $rs1 = Db::name('lesson_slot')->where('id',$id)->where('status',0)->update($update);
|
|
|
- if($rs1 === false){
|
|
|
+ $rs = Db::name('lesson_order')->where('id',$info['id'])->update($update2);
|
|
|
+ if($rs === false){
|
|
|
Db::rollback();
|
|
|
- $this->error('取消失败,请刷新重试');
|
|
|
+ $this->error('取消失败');
|
|
|
}
|
|
|
|
|
|
- //找到所有的已报名订单
|
|
|
- $lesson_order_list = Db::name('lesson_order')->where('slot_id',$id)->where('order_status',10)->lock(true)->select();
|
|
|
- if(!empty($lesson_order_list)){
|
|
|
- foreach($lesson_order_list as $lesson_order){
|
|
|
- //套餐给加回去
|
|
|
- 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'],
|
|
|
- 'updatetime' => time(),
|
|
|
- ];
|
|
|
- $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' => $cancel_time,
|
|
|
- 'cancel_reason' => $cancel_reason,
|
|
|
- ];
|
|
|
- if($lesson_order['paytype'] == 1){
|
|
|
- $update['order_status'] = 40;
|
|
|
- }
|
|
|
-
|
|
|
- $rs = Db::name('lesson_order')->where('id',$lesson_order['id'])->update($update);
|
|
|
- if($rs === false){
|
|
|
- Db::rollback();
|
|
|
- $this->error('取消失败');
|
|
|
- }
|
|
|
-
|
|
|
- //给用户发通知
|
|
|
- $user_info = Db::name('user')->where('id',$lesson_order['user_id'])->find();
|
|
|
- if($user_info['notice_email'] == 1 && !empty($user_info['email'])){
|
|
|
- $obj = new Email();
|
|
|
- $result = $obj
|
|
|
- ->to($user_info['email'])
|
|
|
- ->subject('Elin Dance Studio 订单取消!')
|
|
|
- ->message('Hi,'.$user_info['firstname']. ' ' .$user_info['lastname'].',您预约的'.date('Y-m-d H:i:s',$info['starttime']).'的课程已被取消,原因:'.$cancel_reason.'!')
|
|
|
- ->send();
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
+ $slot_info = Db::name('lesson_slot')->where('id',$info['slot_id'])->find();
|
|
|
+
|
|
|
+ //给用户发通知
|
|
|
+ $user_info = Db::name('user')->where('id',$info['user_id'])->find();
|
|
|
+ if($user_info['notice_email'] == 1 && !empty($user_info['email'])){
|
|
|
+ $obj = new Email();
|
|
|
+ $result = $obj
|
|
|
+ ->to($user_info['email'])
|
|
|
+ ->subject('Elin Dance Studio 订单取消!')
|
|
|
+ ->message('Hi,'.$user_info['firstname']. ' ' .$user_info['lastname'].',您预约的'.date('Y-m-d H:i',$slot_info['starttime']).'的课程已被取消,原因:'.$cancel_reason.'!')
|
|
|
+ ->send();
|
|
|
}
|
|
|
|
|
|
Db::commit();
|