|
@@ -4,6 +4,7 @@ namespace app\api\controller;
|
|
|
|
|
|
use app\common\controller\Api;
|
|
|
use think\Db;
|
|
|
+use app\common\library\Email;
|
|
|
|
|
|
/**
|
|
|
* 会员中心
|
|
@@ -287,7 +288,14 @@ class Usercenter extends Api
|
|
|
//候补上位
|
|
|
private function lesson_order_wait($lesson_order,$slot){
|
|
|
//找到所有的候补单
|
|
|
- $houbu_list = Db::name('lesson_order')->where('slot_id',$lesson_order['slot_id'])->where('jointype',2)->order('id asc')->select();
|
|
|
+ $houbu_list = Db::name('lesson_order')->alias('order')
|
|
|
+ ->field('order.*,user.firstname,user.lastname,user.email,user.whatsapp,lesson.name_en')
|
|
|
+ ->join('user','order.user_id = user.id','LEFT')
|
|
|
+ ->join('lesson','order.lesson_id = lesson.id','LEFT')
|
|
|
+ ->where('order.slot_id',$lesson_order['slot_id'])->where('order.jointype',2)->order('order.id asc')->select();
|
|
|
+
|
|
|
+ $coach_name = Db::name('coach')->where('id',$slot['coach_ids'])->value('nickname');
|
|
|
+
|
|
|
if(!empty($houbu_list)){
|
|
|
|
|
|
$up_usernumber = 0; //此次循环转正的人数
|
|
@@ -305,7 +313,7 @@ class Usercenter extends Api
|
|
|
'order_status' => 1,
|
|
|
'use_status' => 1, //已激活的
|
|
|
];
|
|
|
- $package_order = Db::name('package_order')->where($map)->where('find_in_set(:lesson_ids,lesson_ids)', ['lesson_ids' => $slot['lesson_id']])->order('endtime asc')->find();
|
|
|
+ $package_order = Db::name('package_order')->where($map)->where('find_in_set(:lesson_ids,lesson_ids)', ['lesson_ids' => $slot['lesson_id']])->order('endtime asc')->lock(true)->find();
|
|
|
if(!$package_order){
|
|
|
continue;
|
|
|
}
|
|
@@ -342,6 +350,42 @@ class Usercenter extends Api
|
|
|
|
|
|
//加上本次转正的人数
|
|
|
$up_usernumber += $order['usernumber'];
|
|
|
+
|
|
|
+ //额外的通知
|
|
|
+ $obj = new Email();
|
|
|
+ try {
|
|
|
+ //给这些用户发邮件
|
|
|
+ $result = $obj
|
|
|
+ ->to($order['email'])
|
|
|
+ ->subject('Elin Dance Studio 您候补预订的课程已转为正式预约')
|
|
|
+ ->message('Hi,'.$order['firstname']. ' ' .$order['lastname'].',您候补预定的课程['.$order['name_en'].']即时起已转为正式预约,时间:'.date('Y-m-d H:i',$slot['starttime']).',请及时来上课!')
|
|
|
+ ->send();
|
|
|
+
|
|
|
+ //发whatsapp
|
|
|
+ $parameters = [
|
|
|
+ [
|
|
|
+ 'type' => 'text',
|
|
|
+ 'text' => $order['firstname'].' '.$order['lastname'],
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ 'type' => 'text',
|
|
|
+ 'text' => $order['name_en'],
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ 'type' => 'text',
|
|
|
+ 'text' => $coach_name,
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ 'type' => 'text',
|
|
|
+ 'text' => date('Y-m-d H:i',$slot['starttime']),
|
|
|
+ ],
|
|
|
+ ];
|
|
|
+ $this->whatapp($order['whatsapp'],'lessonorder_alternate_to_booking','en_US',$parameters);
|
|
|
+
|
|
|
+ } catch (Exception $e) {
|
|
|
+
|
|
|
+ }
|
|
|
+ //额外的通知
|
|
|
}else{
|
|
|
break;//跳出
|
|
|
}
|
|
@@ -350,6 +394,46 @@ class Usercenter extends Api
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ //发送whatapp消息的方法
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
//过期课程。就是过了上课时间,没签到的
|
|
|
public function lesson_order_signout(){
|
|
|
$map = [
|