Forráskód Böngészése

后台个人课程取消

lizhen_gitee 9 hónapja
szülő
commit
90260edc22

+ 89 - 8
application/admin/controller/Lessonorder.php

@@ -109,6 +109,18 @@ class Lessonorder extends Backend
                     $this->error('取消失败');
                 }
             }
+            if($info['paytype'] == 4){
+                $update = [
+                    'order_status' => 10,
+                    'lesson_order_id' => 0,
+                    'updatetime' => time(),
+                ];
+                $rs_remain = Db::name('trylesson_order')->where('id',$info['trylesson_order_id'])->update($update);
+                if($rs_remain === false){
+                    Db::rollback();
+                    $this->error('取消失败');
+                }
+            }
             //现金支付不给退,线下处理
 
             //取消预约单
@@ -117,7 +129,7 @@ class Lessonorder extends Backend
                 'cancel_time' => $cancel_time,
                 'cancel_reason' => $cancel_reason,
             ];
-            if($info['paytype'] == 1){
+            if($info['paytype'] == 1 || $info['paytype'] == 4){
                 $update2['order_status'] = 40;
             }
 
@@ -129,16 +141,46 @@ class Lessonorder extends Backend
             }
 
             $slot_info = Db::name('lesson_slot')->where('id',$info['slot_id'])->find();
+            $lesson_info = Db::name('lesson')->where('id',$slot_info['lesson_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();
+            if(!empty($user_info['email'])){
+
+                try {
+                    $obj = new Email();
+                    $result = $obj
+                        ->to($user_info['email'])
+                        ->subject('Class is Cancelled!')
+                        ->message('Hi,'.$user_info['firstname']. ' ' .$user_info['lastname'].',您预约的'.$lesson_info['name'].'已取消')
+                        ->send();
+
+                    $coach_name = Db::name('coach')->where('id',$slot_info['coach_ids'])->value('nickname');
+
+                    //发whatsapp
+                    $parameters = [
+                        [
+                            'type' => 'text',
+                            'text' => $user_info['firstname'].' '.$user_info['lastname'],
+                        ],
+                        [
+                            'type' => 'text',
+                            'text' => $lesson_info['name_en'],
+                        ],
+                        [
+                            'type' => 'text',
+                            'text' => $coach_name,
+                        ],
+                        [
+                            'type' => 'text',
+                            'text' => date('Y-m-d H:i',$slot_info['starttime']),
+                        ],
+                    ];
+                    $this->whatapp($user_info['whatsapp'],'class_cancelled','en_US',$parameters);
+
+                } catch (Exception $e) {
+
+                }
             }
 
             Db::commit();
@@ -150,6 +192,45 @@ class Lessonorder extends Backend
         return $this->view->fetch();
     }
 
+    private function whatapp($receive_mobile,$template,$code,$parameters){
+        if(empty($receive_mobile)){return true;}
+
+        $token = config('site.whatsapp_token');
+
+        //发送者
+        $mobile_id = '337736419413019'; //Elin Dance Stuido 2:+65 8015 4154  ,  WhatsApp Business Account ID: 336509229537586
+
+        //发送
+        $url = 'https://graph.facebook.com/v19.0/'.$mobile_id.'/messages';
+        $header = [
+            'Authorization: Bearer ' . $token,
+            'Content-Type: application/json',
+        ];
+        $body = [
+            'messaging_product' => 'whatsapp',
+            'recipient_type' => 'individual',
+            'to' => $receive_mobile,
+            'type' => 'template',
+            'template' => [
+                'name' => $template,
+                'language' => [
+                    'code' => $code
+                ],
+                'components' => [
+                    [
+                        'type' => 'body',
+                        'parameters' => $parameters
+                    ]
+
+                ],
+            ],
+        ];
+        $body = json_encode($body);
+
+        $rs = curl_post($url,$body,$header);
+        return true;
+    }
+
 
 
 }

+ 1 - 1
application/admin/controller/Lessonslot.php

@@ -138,7 +138,7 @@ class Lessonslot extends Backend
                         'cancel_time' => $cancel_time,
                         'cancel_reason' => $cancel_reason,
                     ];
-                    if($lesson_order['paytype'] == 1){
+                    if($lesson_order['paytype'] == 1 || $lesson_order['paytype'] == 4){
                         $update['order_status'] = 40;
                     }
 

+ 1 - 1
application/index/controller/Plantask.php

@@ -130,7 +130,7 @@ class Plantask extends Controller
                     $result = $obj
                         ->to($order['email'])
                         ->subject('Class is Cancelled!')
-                        ->message('Hi,'.$order['firstname']. ' ' .$order['lastname'].',您预约的['.$order['name'].']将于'.date('Y-m-d H:i:s',$slot['starttime']).'开课,请合理安排时间,准时来上课哦!')
+                        ->message('Hi,'.$order['firstname']. ' ' .$order['lastname'].',您预约的['.$order['name'].']已取消')
                         ->send();
 
                     $coach_name = Db::name('coach')->where('id',$slot['coach_ids'])->value('nickname');