508 lines
23 KiB
PHP
508 lines
23 KiB
PHP
<?php
|
||
|
||
/**
|
||
* @author Any
|
||
* @description KISS
|
||
* @date 2020-12-2
|
||
* @version 1.0.0
|
||
*
|
||
* _____LOG_____
|
||
*
|
||
*/
|
||
|
||
namespace app\modules\api\models;
|
||
|
||
use app\components\SiteHelper;
|
||
use app\components\sms\AliSmsMsgSender;
|
||
use app\models\Box;
|
||
use app\models\DevList;
|
||
use app\models\MsgCentre;
|
||
use app\models\OrderDetail;
|
||
use app\models\OrderSale;
|
||
use app\models\sms\SmsMsgHelper;
|
||
use app\models\sms\SmsSetting;
|
||
use app\models\sms\SmsTpl;
|
||
use app\models\Store;
|
||
use app\models\StoreUser;
|
||
use app\models\User;
|
||
use app\models\UserCoupon;
|
||
use app\modules\api\components\ApiHelper;
|
||
use function AlibabaCloud\Client\value;
|
||
use yii\data\Pagination;
|
||
|
||
|
||
class MsgCentreForm extends ApiModel
|
||
{
|
||
|
||
/**
|
||
* 创建消息
|
||
* @param $store_id int 门店id
|
||
* @param $type int 1=租赁消息2=归还消息3=售后消息4=报警消息
|
||
* @param $data array ball_mark球车型号,ball_cart球车名称,start_date开始时间,end_date结束日期,price金额,object_id订单id
|
||
* @return array|void
|
||
*/
|
||
public static function add($store_id,$type,$data)
|
||
{
|
||
$store_user_ids = StoreUser::find()->where([
|
||
'is_delete' => 0,
|
||
'status' => 0,
|
||
'store_id' => $store_id,
|
||
'user_type' => [1,2]
|
||
])->select('user_id')->column();
|
||
$store_user_ids = empty($store_user_ids) ? [] : $store_user_ids;
|
||
|
||
// $boss_ids = User::find()->where(['is_delete' => 0,'type' => User::TYPE_ADMIN_STAFF])->select('id')->column();
|
||
$boss_ids = empty($boss_ids) ? [] : $boss_ids;
|
||
$user_ids = array_merge($store_user_ids,$boss_ids);
|
||
// $user_ids = [3];
|
||
if(empty($user_ids)){
|
||
return ['code' => 0,'msg' => '无需处理消息'];
|
||
}
|
||
if($type == '1'){
|
||
$title = '球车租赁消息通知';
|
||
$content = json_encode($data,JSON_UNESCAPED_UNICODE);
|
||
}elseif ($type == '2'){
|
||
$title = '球车还车消息通知';
|
||
$content = json_encode($data,JSON_UNESCAPED_UNICODE);
|
||
}elseif ($type == '3') {
|
||
$title = '有新的待处理售后';
|
||
$content = '有一笔新的待处理售后订单需要处理 进入查看并处理退款订单';
|
||
}
|
||
$array = [];
|
||
foreach ($user_ids as $item){
|
||
array_push($array,[$type,$title,$content,$item,0,time(),$data['object_id']]);
|
||
}
|
||
$chunk = array_chunk($array,300);
|
||
$key = ['type','title','content','user_id','is_admin_send','created_at','object_id'];
|
||
foreach ($chunk as $index => $value){
|
||
\Yii::$app->db->createCommand()->batchInsert(MsgCentre::tableName(),$key, $value)->execute();
|
||
}
|
||
|
||
//判断是否在发送短信时间段
|
||
$redis_name = "api:cxaibc:send:send_time";
|
||
$send_time = \Yii::$app->redis->get($redis_name);
|
||
if(empty($send_time)){
|
||
return ['code' => 0,'msg' =>"成功发送"];
|
||
}
|
||
$send_time = explode(' - ',$send_time);
|
||
$send_time_arr0 = explode(':',$send_time[0]);
|
||
$send_time_arr1 = explode(':',$send_time[1]);
|
||
$begin=mktime($send_time_arr0[0],$send_time_arr0[1],$send_time_arr0[2],date('m'),date('d'),date('Y'));
|
||
$end = mktime($send_time_arr1[0],$send_time_arr1[1],$send_time_arr1[2],date('m'),date('d'),date('Y'));
|
||
if(time() < $begin || time() > $end){
|
||
\Yii::info(json_encode($data,JSON_UNESCAPED_UNICODE).'__不在发送短信区间','ball_sms');
|
||
return ['code' => 0,'msg' =>"不在发送短信区间"];
|
||
}
|
||
|
||
$sms_sender = SmsSetting::findOne(['cx_mch_id' => 0]);
|
||
if($type == '2' && $sms_sender->is_prod == '1' && $sms_sender->type == 0 && !empty($sms_sender->access_key_id) && !empty($sms_sender->access_secret) && !empty($sms_sender->sign_name)){
|
||
\Yii::info($data['ball_cart'].'__进入发送短信','ball_sms');
|
||
$length = 50;
|
||
$users = User::find()->where(['is_delete' => 0,'status' => 0,'id' => $user_ids])->select('real_name as name,mobile_phone')->asArray()->all();
|
||
$users_check = array_chunk($users,$length);
|
||
$tpl_type_key = SmsTpl::getTplKey(6);
|
||
$sms = SmsTpl::findOne(['key' => $tpl_type_key,'is_delete' => 0,'type' => 0]);
|
||
if($sms != null && !empty($users_check)){
|
||
\Yii::info(json_encode($users_check,JSON_UNESCAPED_UNICODE).'__存在数据','ball_sms');
|
||
$tpl_type = $sms->tpl_code;
|
||
foreach ($users_check as $index => &$item){
|
||
|
||
foreach ($item as $index2 => &$item2){
|
||
$redis_name = "api:cxaibc:gh:send_sms:{$item2['mobile_phone']}";
|
||
$get = \Yii::$app->redis->get($redis_name);
|
||
if($get == 'nosend'){
|
||
// 跳过短信发送
|
||
unset($item[$index2]);
|
||
}else{
|
||
$item2['numbers'] = $data['ball_cart'];
|
||
}
|
||
}
|
||
if(empty($item)){
|
||
continue;
|
||
}
|
||
$item = array_values($item);
|
||
$count = count($item);
|
||
$mobile_phones = array_column($item,'mobile_phone');
|
||
$sign_names = array_pad([],$count,$sms_sender->sign_name);
|
||
|
||
$sms_senders = new AliSmsMsgSender();
|
||
$sms_senders->access_key_id = $sms_sender->access_key_id;
|
||
$sms_senders->access_secret = $sms_sender->access_secret;
|
||
$sms_senders->tpl_code = $tpl_type;
|
||
$sms_senders->signname = $sign_names;
|
||
$res = $sms_senders->batchSender($mobile_phones, $sign_names,$item, 86);
|
||
if($res['code'] != 0){
|
||
\Yii::info(json_encode($mobile_phones,JSON_UNESCAPED_UNICODE).'__'.json_encode($sign_names,JSON_UNESCAPED_UNICODE).'__'.json_encode($item,JSON_UNESCAPED_UNICODE),'ball_sms');
|
||
\Yii::info($data['ball_cart'].'__'.$res['msg'],'ball_sms');
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return ['code' => 0,'msg' =>"成功发送"];
|
||
}
|
||
|
||
//小程序下单模板通知
|
||
public static function sendWxAppletLeaseMsg($user,$store,$order,$params)
|
||
{
|
||
$time5 = date('Y-m-d H:i:s',$order->created_at);
|
||
$template_id = \Yii::$app->params['wxappletmsg']['ball_lease'];
|
||
$openid = $user->bindWxmp->openid;
|
||
$args = [
|
||
'template_id' => $template_id,
|
||
'touser' => $openid,
|
||
'data' => [
|
||
'thing1' => ['value' => $store->name],
|
||
'character_string2' => ['value' => $order->order_no],
|
||
'thing3' => ['value' => $params['ball_number']],
|
||
'amount4' => ['value' => $params['price']],
|
||
'time5' => ['value' => $time5],
|
||
],
|
||
'miniprogram_state' => 'trial',//跳转小程序类型:developer为开发版;trial为体验版;formal为正式版;默认为正式版
|
||
'lang' => 'zh_CN',
|
||
];
|
||
$plugin = new \app\models\common\PluginService();
|
||
$wxmpService = $plugin->getWxmpService(0);
|
||
$accessToken = $wxmpService->getAccessToken();
|
||
$r = $wxmpService->tplMsg->sendWxAppletMsg($args,$accessToken);
|
||
if($r['errcode'] != 0){
|
||
\Yii::info($order->id.'__'.$params['ball_number'].'__'.$r['errcode'].'__'.$r['errmsg'].'__小程序下单模板通知','wx_applet_msg');
|
||
}
|
||
}
|
||
|
||
//小程序管理员确认还车模板通知
|
||
public static function sendWxAppletReturnMsg($order)
|
||
{
|
||
if($order == null){
|
||
return;
|
||
}
|
||
$order_detail = OrderDetail::findOne(['order_id' => $order->id]);
|
||
$thing1 = $order_detail != null ? $order_detail->goods_id : '球车';
|
||
$user = ApiHelper::findOneUser($order->user_id);
|
||
if($user->bindWxmp){
|
||
$template_id = \Yii::$app->params['wxappletmsg']['ball_return'];
|
||
$openid = $user->bindWxmp->openid;
|
||
$time4 = date('Y-m-d H:i:s',time());
|
||
$thing3 = ceil($order->updated_at - $order->created_at);
|
||
$thing3 = self::Sec2Time($thing3);
|
||
$args = [
|
||
'template_id' => $template_id,
|
||
'touser' => $openid,
|
||
'data' => [
|
||
'thing1' => ['value' => $thing1],
|
||
'amount2' => ['value' => $order->total_pay_price],
|
||
'thing3' => ['value' => $thing3],
|
||
'time4' => ['value' => $time4],
|
||
],
|
||
'miniprogram_state' => 'trial',//跳转小程序类型:developer为开发版;trial为体验版;formal为正式版;默认为正式版
|
||
'lang' => 'zh_CN',
|
||
];
|
||
$plugin = new \app\models\common\PluginService();
|
||
$wxmpService = $plugin->getWxmpService(0);
|
||
$accessToken = $wxmpService->getAccessToken();
|
||
$r = $wxmpService->tplMsg->sendWxAppletMsg($args,$accessToken);
|
||
if($r['errcode'] != 0){
|
||
\Yii::info($order->id.'__'.$order_detail->goods_id.'__'.$r['errcode'].'__'.$r['errmsg'].'__小程序管理员确认还车模板通知','ball_sms');
|
||
}
|
||
}
|
||
}
|
||
|
||
public static function Sec2Time($time)
|
||
{
|
||
if (is_numeric($time)) {
|
||
$value = array(
|
||
"years" => 0, "days" => 0, "hours" => 0,
|
||
"minutes" => 0, "seconds" => 0,
|
||
);
|
||
$t = '';
|
||
if ($time >= 31556926) {
|
||
$value["years"] = floor($time / 31556926);
|
||
$time = ($time % 31556926);
|
||
$t .= $value["years"] . "年";
|
||
}
|
||
if ($time >= 86400) {
|
||
$value["days"] = floor($time / 86400);
|
||
$time = ($time % 86400);
|
||
$t .= $value["days"] . "天";
|
||
}
|
||
if ($time >= 3600) {
|
||
$value["hours"] = floor($time / 3600);
|
||
$time = ($time % 3600);
|
||
$t .= $value["hours"] . "小时";
|
||
}
|
||
if ($time >= 60) {
|
||
$value["minutes"] = floor($time / 60);
|
||
$time = ($time % 60);
|
||
$t .= $value["minutes"] . "分";
|
||
}
|
||
$value["seconds"] = floor($time);
|
||
//return (array) $value;
|
||
$t .= $value["seconds"] . "秒";
|
||
return $t;
|
||
} else {
|
||
return (bool) false;
|
||
}
|
||
}
|
||
|
||
//小程序管理员确认售后用户结果通知
|
||
public static function sendWxAppletStoreSalesMsg($order,$orderSale,$name,$merchant_remark)
|
||
{
|
||
if($order == null || $orderSale == null){
|
||
return;
|
||
}
|
||
$time2 = date('Y/m/d H:i:s',$orderSale->created_at);
|
||
|
||
$user = ApiHelper::findOneUser($order->user_id);
|
||
if($user->bindWxmp){
|
||
$template_id = \Yii::$app->params['wxappletmsg']['order_sale_notarize'];
|
||
$openid = $user->bindWxmp->openid;
|
||
$args = [
|
||
'template_id' => $template_id,
|
||
'touser' => $openid,
|
||
'data' => [
|
||
'thing1' => ['value' => '退款'],
|
||
'character_string6' => ['value' => $order->order_no],
|
||
'time2' => ['value' => $time2],
|
||
'phrase4' => ['value' => $name],
|
||
'thing5' => ['value' => $merchant_remark],
|
||
],
|
||
'miniprogram_state' => 'formal',//跳转小程序类型:developer为开发版;trial为体验版;formal为正式版;默认为正式版
|
||
'lang' => 'zh_CN',
|
||
];
|
||
\Yii::info($order->id.'__'.json_encode($args,JSON_UNESCAPED_UNICODE).'__小程序管理员确认售后body数据','ball_sms');
|
||
$plugin = new \app\models\common\PluginService();
|
||
$wxmpService = $plugin->getWxmpService(0);
|
||
$accessToken = $wxmpService->getAccessToken();
|
||
$r = $wxmpService->tplMsg->sendWxAppletMsg($args,$accessToken);
|
||
if($r['errcode'] != 0){
|
||
\Yii::info($order->id.'__'.$r['errcode'].'__'.$r['errmsg'].'__小程序管理员确认售后用户结果通知','ball_sms');
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
//小程序待支付模板通知
|
||
public static function sendWxAppletTopPay($user,$store,$order)
|
||
{
|
||
$thing5 = floor((time() - $order->created_at) / 60);
|
||
$time = date('Y-m-d H:i:s',$order->created_at);
|
||
$template_id = \Yii::$app->params['wxappletmsg']['to_pay'];
|
||
$openid = $user->bindWxmp->openid;
|
||
$args = [
|
||
'template_id' => $template_id,
|
||
'touser' => $openid,
|
||
'data' => [
|
||
'character_string3' => ['value' => $order->order_no],
|
||
'amount2' => ['value' => $order->total_goods_price],
|
||
'thing1' => ['value' => $store->name],
|
||
'time7' => ['value' => $time],
|
||
'thing5' => ['value' => '订单将于提交后'.$thing5.'分钟内过期,请快去支付。'],
|
||
],
|
||
'miniprogram_state' => 'formal',//跳转小程序类型:developer为开发版;trial为体验版;formal为正式版;默认为正式版
|
||
'lang' => 'zh_CN',
|
||
];
|
||
$plugin = new \app\models\common\PluginService();
|
||
$wxmpService = $plugin->getWxmpService(0);
|
||
$accessToken = $wxmpService->getAccessToken();
|
||
$r = $wxmpService->tplMsg->sendWxAppletMsg($args,$accessToken);
|
||
if($r['errcode'] != 0){
|
||
\Yii::info('待支付通知__ORDER_ID'.$order->id.$r['errcode'].'__'.$r['errmsg'], 'wx_applet_msg');
|
||
}
|
||
return $r;
|
||
}
|
||
|
||
//小程序包厢预约开始提醒
|
||
public static function sendWxAppletBoxBookStartRemind($order)
|
||
{
|
||
$box = Box::findOne(['id' => $order->coach_id]);
|
||
$orderDetail = OrderDetail::findOne(['order_id' => $order->id]);
|
||
$store = Store::findOne(['id' => $order->store_id]);
|
||
$time = strtotime($orderDetail->start_time);
|
||
$thing5 = floor((time() - $time) / 60);
|
||
|
||
if($thing5 <= 0){
|
||
$thing5 = '您的订单已生效';
|
||
}else{
|
||
$thing5 = '您的订单将于'.$thing5.'分钟后生效。';
|
||
}
|
||
$user = User::findOne(['id' => $order->user_id]);
|
||
$template_id = \Yii::$app->params['wxappletmsg']['box_book_start_remind'];
|
||
$openid = $user->bindWxmp->openid;
|
||
$args = [
|
||
'template_id' => $template_id,
|
||
'touser' => $openid,
|
||
'data' => [
|
||
'thing1' => ['value' => $box->name],
|
||
'time2' => ['value' => $orderDetail->start_time],
|
||
'character_string10' => ['value' => $order->order_no],
|
||
'thing21' => ['value' => $store->name],
|
||
'thing9' => ['value' => $thing5],
|
||
],
|
||
'miniprogram_state' => 'formal',//跳转小程序类型:developer为开发版;trial为体验版;formal为正式版;默认为正式版
|
||
'lang' => 'zh_CN',
|
||
];
|
||
$plugin = new \app\models\common\PluginService();
|
||
$wxmpService = $plugin->getWxmpService(0);
|
||
$accessToken = $wxmpService->getAccessToken();
|
||
$r = $wxmpService->tplMsg->sendWxAppletMsg($args,$accessToken);
|
||
if($r['errcode'] != 0){
|
||
\Yii::info('预约开始提醒通知__ORDER_ID'.$order->id.$r['errcode'].'__'.$r['errmsg'], 'wx_applet_msg');
|
||
}
|
||
return $r;
|
||
}
|
||
|
||
|
||
//小程序货柜关门提醒-货柜-微信
|
||
public static function sendWxAppletGoodsContainerCloseRemind($order)
|
||
{
|
||
$redis = \Yii::$app->redis;
|
||
$redis_name = "cxgyc:api:sendWxAppletGoodsContainerCloseRemind_{$order->user_id}:{$order->id}";
|
||
$setnx = $redis->setnx($redis_name,1);
|
||
if(empty($setnx)){
|
||
return false;
|
||
}
|
||
\Yii::info('货柜关门提醒__ORDER_ID'.$order->id, 'wx_applet_msg');
|
||
$time3 = date('Y-m-d H:i:s',$order->created_at);
|
||
$time4 = date('Y-m-d H:i:s',time());
|
||
$user = User::findOne(['id' => $order->user_id]);
|
||
$thing5 = '稍后为您推送订单';
|
||
$template_id = \Yii::$app->params['wxappletmsg']['goods_container_close_remind'];
|
||
$openid = $user->bindWxmp->openid;
|
||
\Yii::info('货柜关门提醒__OPEN_ID:'.$openid, 'wx_applet_msg');
|
||
$args = [
|
||
'template_id' => $template_id,
|
||
'touser' => $openid,
|
||
'data' => [
|
||
'character_string1' => ['value' => $order->order_no],
|
||
'time3' => ['value' => $time3],
|
||
'time4' => ['value' => $time4],
|
||
'thing5' => ['value' => $thing5],
|
||
],
|
||
'miniprogram_state' => 'formal',//跳转小程序类型:developer为开发版;trial为体验版;formal为正式版;默认为正式版
|
||
'lang' => 'zh_CN',
|
||
];
|
||
\Yii::info('货柜关门提醒__ORDER_ID:'.json_encode($args,JSON_UNESCAPED_UNICODE), 'wx_applet_msg');
|
||
$plugin = new \app\models\common\PluginService();
|
||
$wxmpService = $plugin->getWxmpService(0);
|
||
$accessToken = $wxmpService->getAccessToken();
|
||
$r = $wxmpService->tplMsg->sendWxAppletMsg($args,$accessToken);
|
||
if($r['errcode'] != 0){
|
||
\Yii::info('货柜关门提醒__ORDER_ID'.$order->id.$r['errcode'].'__'.$r['errmsg'], 'wx_applet_msg');
|
||
}
|
||
$redis->expire($redis_name,600);
|
||
\Yii::info('货柜关门提醒__ORDER_ID:'.json_encode($r), 'wx_applet_msg');
|
||
return $r;
|
||
}
|
||
|
||
//货柜生成订单提醒
|
||
public static function sendWxAppletGoodsOrderPayRemind($order,$res)
|
||
{
|
||
\Yii::info('货柜生成订单提醒__ORDER_ID'.$order->id, 'wx_applet_msg');
|
||
$time4 = date('Y-m-d H:i:s',$order->created_at);
|
||
$amount7 = sprintf("%.2f",$res['data']['total_price']);
|
||
$user = User::findOne(['id' => $order->user_id]);
|
||
$thing5 = '商品订单已生成,点击进入';
|
||
$template_id = \Yii::$app->params['wxappletmsg']['goods_order_pay_remind'];
|
||
$openid = $user->bindWxmp->openid;
|
||
\Yii::info('货柜生成订单提醒__OPEN_ID:'.$openid, 'wx_applet_msg');
|
||
$args = [
|
||
'template_id' => $template_id,
|
||
'touser' => $openid,
|
||
'page' => 'subpages/order/orderDetailTwo?id='.$order->id.'&v=1',
|
||
'data' => [
|
||
'character_string6' => ['value' => $order->order_no],
|
||
'time4' => ['value' => $time4],
|
||
'amount7' => ['value' => $amount7],
|
||
'thing5' => ['value' => $thing5],
|
||
],
|
||
'miniprogram_state' => 'formal',//跳转小程序类型:developer为开发版;trial为体验版;formal为正式版;默认为正式版
|
||
'lang' => 'zh_CN',
|
||
];
|
||
\Yii::info('货柜生成订单提醒__ORDER_ID:'.json_encode($args,JSON_UNESCAPED_UNICODE), 'wx_applet_msg');
|
||
$plugin = new \app\models\common\PluginService();
|
||
$wxmpService = $plugin->getWxmpService(0);
|
||
$accessToken = $wxmpService->getAccessToken();
|
||
$r = $wxmpService->tplMsg->sendWxAppletMsg($args,$accessToken);
|
||
if($r['errcode'] != 0){
|
||
\Yii::info('货柜生成订单提醒__ORDER_ID'.$order->id.$r['errcode'].'__'.$r['errmsg'], 'wx_applet_msg');
|
||
}
|
||
\Yii::info('货柜生成订单提醒__ORDER_ID:'.json_encode($r), 'wx_applet_msg');
|
||
return $r;
|
||
}
|
||
|
||
//小程序包厢预约即将结束提醒
|
||
public static function sendWxAppletBoxBookEndRemind($order)
|
||
{
|
||
$box = Box::findOne(['id' => $order->coach_id]);
|
||
$orderDetail = OrderDetail::findOne(['order_id' => $order->id]);
|
||
$store = Store::findOne(['id' => $order->store_id]);
|
||
// $time = strtotime($orderDetail->start_time);
|
||
$thing5 = ceil(($orderDetail->end_at - time()) / 60);
|
||
$user = User::findOne(['id' => $order->user_id]);
|
||
$template_id = \Yii::$app->params['wxappletmsg']['box_book_end_remind'];
|
||
$openid = $user->bindWxmp->openid;
|
||
$args = [
|
||
'template_id' => $template_id,
|
||
'touser' => $openid,
|
||
'data' => [
|
||
'thing2' => ['value' => $store->name],
|
||
'time3' => ['value' => $orderDetail->end_time],
|
||
'number4' => ['value' =>$thing5],
|
||
'thing6' => ['value' => $box->name],
|
||
'thing5' => ['value' => '您的预约马上结束,请注意时间,或续单~'],
|
||
],
|
||
'miniprogram_state' => 'formal',//跳转小程序类型:developer为开发版;trial为体验版;formal为正式版;默认为正式版
|
||
'lang' => 'zh_CN',
|
||
];
|
||
\Yii::info('包厢预约即将结束提醒__ORDER_ID'.json_encode($args,JSON_UNESCAPED_UNICODE), 'wx_applet_msg');
|
||
$plugin = new \app\models\common\PluginService();
|
||
$wxmpService = $plugin->getWxmpService(0);
|
||
$accessToken = $wxmpService->getAccessToken();
|
||
$r = $wxmpService->tplMsg->sendWxAppletMsg($args,$accessToken);
|
||
if($r['errcode'] != 0){
|
||
\Yii::info('包厢预约即将结束提醒__ORDER_ID'.$order->id.$r['errcode'].'__'.$r['errmsg'], 'wx_applet_msg');
|
||
}
|
||
return $r;
|
||
}
|
||
|
||
//小程序货柜生成订单提醒-货柜-微信
|
||
public static function sendWxAppletGoodsOrderAddRemind($order)
|
||
{
|
||
$redis = \Yii::$app->redis;
|
||
$redis_name = "cxgyc:api:sendWxAppletGoodsOrderAddRemind_{$order->user_id}:{$order->id}";
|
||
$setnx = $redis->setnx($redis_name,1);
|
||
if(empty($setnx)){
|
||
return false;
|
||
}
|
||
\Yii::info('货柜生成订单提醒__ORDER_ID'.$order->id, 'wx_applet_msg');
|
||
$time3 = date('Y-m-d H:i:s',$order->created_at);
|
||
$user = User::findOne(['id' => $order->user_id]);
|
||
$thing5 = '订单生成中,稍后为您推送';
|
||
$template_id = \Yii::$app->params['wxappletmsg']['goods_order_add_remind'];
|
||
$openid = $user->bindWxmp->openid;
|
||
\Yii::info('货柜关门提醒__OPEN_ID:'.$openid, 'wx_applet_msg');
|
||
$args = [
|
||
'template_id' => $template_id,
|
||
'touser' => $openid,
|
||
'data' => [
|
||
'time4' => ['value' => $time3],
|
||
'phrase3' => ['value' => '生成中'],
|
||
'thing5' => ['value' => $thing5],
|
||
],
|
||
'miniprogram_state' => 'formal',//跳转小程序类型:developer为开发版;trial为体验版;formal为正式版;默认为正式版
|
||
'lang' => 'zh_CN',
|
||
];
|
||
\Yii::info('货柜生成订单提醒__ORDER_ID:'.json_encode($args,JSON_UNESCAPED_UNICODE), 'wx_applet_msg');
|
||
$plugin = new \app\models\common\PluginService();
|
||
$wxmpService = $plugin->getWxmpService(0);
|
||
$accessToken = $wxmpService->getAccessToken();
|
||
$r = $wxmpService->tplMsg->sendWxAppletMsg($args,$accessToken);
|
||
if($r['errcode'] != 0){
|
||
\Yii::info('货柜生成订单提醒__ORDER_ID'.$order->id.$r['errcode'].'__'.$r['errmsg'], 'wx_applet_msg');
|
||
}
|
||
$redis->expire($redis_name,600);
|
||
\Yii::info('货柜生成订单提醒__ORDER_ID:'.json_encode($r), 'wx_applet_msg');
|
||
return $r;
|
||
}
|
||
|
||
|
||
} |