|
@@ -388,6 +388,7 @@ class Lessonslot extends Backend
|
|
|
$this->error('当前课程不能取消');
|
|
|
}
|
|
|
|
|
|
+ //更新订单
|
|
|
$update = [
|
|
|
'status' => 30,
|
|
|
'remark' => $remark,
|
|
@@ -402,6 +403,9 @@ class Lessonslot extends Backend
|
|
|
$this->error('取消失败,请刷新重试');
|
|
|
}
|
|
|
|
|
|
+ //发送通知
|
|
|
+ $this->auto_lesson_slot_cancel($id);
|
|
|
+
|
|
|
//找到所有的已候补订单
|
|
|
$update = [
|
|
|
'order_status' => 30,
|
|
@@ -480,6 +484,94 @@ class Lessonslot extends Backend
|
|
|
return $this->view->fetch();
|
|
|
}
|
|
|
|
|
|
+ //课程取消,通知。计划任务5分钟执行一次
|
|
|
+ private function auto_lesson_slot_cancel($slot_id){
|
|
|
+ $map = [
|
|
|
+ 'slot.id' => $slot_id,
|
|
|
+ ];
|
|
|
+
|
|
|
+ $slot = Db::name('lesson_slot')->alias('slot')
|
|
|
+ ->field('slot.*,coach.nickname as coach_nickname,coach.email as coach_email,coach.whatsapp as coach_whatsapp,lesson.name_en as lesson_name_en')
|
|
|
+ ->join('coach','slot.coach_ids = coach.id','LEFT')
|
|
|
+ ->join('lesson','slot.lesson_id = lesson.id','LEFT')
|
|
|
+ ->where($map)->order('slot.starttime asc')->find();
|
|
|
+
|
|
|
+ //找出这节课时的预约单
|
|
|
+ $map = [
|
|
|
+ 'order.slot_id' => $slot['id'],
|
|
|
+ ];
|
|
|
+
|
|
|
+ $order_list = Db::name('lesson_order')->alias('order')
|
|
|
+ ->field('user.firstname,user.lastname,user.email,user.whatsapp')
|
|
|
+ ->join('user','order.user_id = user.id','LEFT')
|
|
|
+ ->where('(order.jointype = 1 and order.order_status = 10) or (order.jointype = 2 and order.order_status = 0)') //已支付的 或 候补单
|
|
|
+ ->where($map)->order('order.id asc')->select();
|
|
|
+ //把教练也加入到发送列表里
|
|
|
+ $coach_sender = [
|
|
|
+ 'firstname' => $slot['coach_nickname'],
|
|
|
+ 'lastname' => '',
|
|
|
+ 'email' => $slot['coach_email'],
|
|
|
+ 'whatsapp' => $slot['coach_whatsapp'],
|
|
|
+ ];
|
|
|
+ $order_list[] = $coach_sender;
|
|
|
+
|
|
|
+ if(empty($order_list)){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ //给这些预约单的用户发邮件
|
|
|
+ try {
|
|
|
+ $obj = new Email();
|
|
|
+ foreach($order_list as $order){
|
|
|
+
|
|
|
+ $message =
|
|
|
+ 'Hi,'.$order['firstname']. ' ' .$order['lastname'].'!<br/>
|
|
|
+ We regret to inform you that the following class has been cancelled.<br/>
|
|
|
+ Class:'.$slot['lesson_name_en'].'<br/>
|
|
|
+ Date: '.date('d F Y',$slot['starttime']).'<br/>
|
|
|
+ Time: '.date('H:i a',$slot['starttime']).'<br/>
|
|
|
+ Thank you for your kind understanding and look forward to seeing you in our studio soon!❤<br/>
|
|
|
+ Best Regards,<br/>
|
|
|
+ Elin Dance Studio<br/>
|
|
|
+ <img src="'.config('website_url').'/assets/img/logo3.png" style="width:136px;height:115px">
|
|
|
+ ';
|
|
|
+
|
|
|
+ if(!empty($order['email'])){
|
|
|
+ $result = $obj
|
|
|
+ ->to($order['email'])
|
|
|
+ ->subject('Class is Cancelled!')
|
|
|
+ ->message($message)
|
|
|
+ ->send();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //发whatsapp
|
|
|
+ $parameters = [
|
|
|
+ [
|
|
|
+ 'type' => 'text',
|
|
|
+ 'text' => $order['firstname'].' '.$order['lastname'],
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ 'type' => 'text',
|
|
|
+ 'text' => $slot['lesson_name_en'],
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ 'type' => 'text',
|
|
|
+ 'text' => date('D l Y',$slot['starttime']) .' at '.date('H:i a',$slot['starttime']),
|
|
|
+ ],
|
|
|
+ ];
|
|
|
+ if(!empty($order['whatsapp'])){
|
|
|
+ $this->whatapp($order['whatsapp'],'class_cancelled','en_US',$parameters);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception $e) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 复制本周的课程表
|
|
|
*/
|