格式化代码,调整模板消息发送类型

This commit is contained in:
liaofei 2019-11-19 17:52:35 +08:00
parent 1067d7e776
commit 2762c576b1
2 changed files with 67 additions and 62 deletions

View File

@ -1,5 +1,6 @@
<?php
namespace app\models\routine;
namespace app\models\routine;
use crmeb\utils\Template;
use app\models\store\StoreOrder;
@ -36,21 +37,21 @@ class RoutineTemplate
* @param int $isGive
* @return bool
*/
public static function sendOrderPostage($order,$isGive=0)
public static function sendOrderPostage($order, $isGive = 0)
{
if($isGive){
$data['keyword1'] = $order['order_id'];
$data['keyword2'] = $order['delivery_name'];
$data['keyword3'] = $order['delivery_id'];
$data['keyword4'] = date('Y-m-d H:i:s',time());
$data['keyword5'] = '您的商品已经发货请注意查收';
return self::sendOut('ORDER_POSTAGE_SUCCESS',$order['uid'],$data);
}else{
$data['keyword1'] = $order['order_id'];
$data['keyword2'] = $order['delivery_name'];
$data['keyword3'] = $order['delivery_id'];
$data['keyword4'] = date('Y-m-d H:i:s',time());
return self::sendOut('ORDER_DELIVER_SUCCESS',$order['uid'],$data);
if ($isGive) {
$data['keyword1'] = $order['order_id'];
$data['keyword2'] = $order['delivery_name'];
$data['keyword3'] = $order['delivery_id'];
$data['keyword4'] = date('Y-m-d H:i:s', time());
$data['keyword5'] = '您的商品已经发货请注意查收';
return self::sendOut('ORDER_POSTAGE_SUCCESS', $order['uid'], $data);
} else {
$data['keyword1'] = $order['order_id'];
$data['keyword2'] = $order['delivery_name'];
$data['keyword3'] = $order['delivery_id'];
$data['keyword4'] = date('Y-m-d H:i:s', time());
return self::sendOut('ORDER_DELIVER_SUCCESS', $order['uid'], $data);
}
}
@ -61,30 +62,32 @@ class RoutineTemplate
*/
public static function sendOrderRefundSuccess($order = array())
{
if(!$order) return false;
$data['keyword1'] = $order['order_id'];
$data['keyword2'] = date('Y-m-d H:i:s',time());
$data['keyword3'] = $order['pay_price'];
if($order['pay_type'] == 'yue') $data['keyword4'] = '余额支付';
else if($order['pay_type'] == 'weixin') $data['keyword4'] = '微信支付';
else if($order['pay_type'] == 'offline') $data['keyword4'] = '线下支付';
if (!$order) return false;
$data['keyword1'] = $order['order_id'];
$data['keyword2'] = date('Y-m-d H:i:s', time());
$data['keyword3'] = $order['pay_price'];
if ($order['pay_type'] == 'yue') $data['keyword4'] = '余额支付';
else if ($order['pay_type'] == 'weixin') $data['keyword4'] = '微信支付';
else if ($order['pay_type'] == 'offline') $data['keyword4'] = '线下支付';
$data['keyword5']['value'] = '已成功退款';
return self::sendOut('ORDER_REFUND_SUCCESS',$order['uid'],$data);
return self::sendOut('ORDER_REFUND_SUCCESS', $order['uid'], $data);
}
/**
* 用户申请退款给管理员发送消息
* @param array $order
* @param string $refundReasonWap
* @param array $adminList
*/
public static function sendOrderRefundStatus($order = array(),$refundReasonWap = '',$adminList = array()){
$data['keyword1'] = $order['order_id'];
$data['keyword2'] = $refundReasonWap;
$data['keyword3'] = date('Y-m-d H:i:s',time());
$data['keyword4'] = $order['pay_price'];
$data['keyword5'] = '原路返回';
foreach ($adminList as $uid){
self::sendOut('ORDER_REFUND_STATUS',$uid,$data);
public static function sendOrderRefundStatus($order = array(), $refundReasonWap = '', $adminList = array())
{
$data['keyword1'] = $order['order_id'];
$data['keyword2'] = $refundReasonWap;
$data['keyword3'] = date('Y-m-d H:i:s', time());
$data['keyword4'] = $order['pay_price'];
$data['keyword5'] = '原路返回';
foreach ($adminList as $uid) {
self::sendOut('ORDER_REFUND_STATUS', $uid, $data);
}
}
@ -95,14 +98,15 @@ class RoutineTemplate
* @param int $bargainUserId
* @return bool
*/
public static function sendBargainSuccess($bargain = array(),$bargainUser = array(),$bargainUserId = 0){
$data['keyword1'] = $bargain['title'];
$data['keyword2'] = $bargainUser['bargain_price'];
$data['keyword3'] = $bargainUser['bargain_price_min'];
$data['keyword4'] = $bargainUser['price'];
$data['keyword5'] = $bargainUser['bargain_price_min'];
$data['keyword6'] = '恭喜您,已经砍到最低价了';
return self::sendOut('BARGAIN_SUCCESS',$bargainUser['uid'],$data);
public static function sendBargainSuccess($bargain = array(), $bargainUser = array(), $bargainUserId = 0)
{
$data['keyword1'] = $bargain['title'];
$data['keyword2'] = $bargainUser['bargain_price'];
$data['keyword3'] = $bargainUser['bargain_price_min'];
$data['keyword4'] = $bargainUser['price'];
$data['keyword5'] = $bargainUser['bargain_price_min'];
$data['keyword6'] = '恭喜您,已经砍到最低价了';
return self::sendOut('BARGAIN_SUCCESS', $bargainUser['uid'], $data);
}
/**
@ -114,42 +118,43 @@ class RoutineTemplate
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public static function sendOrderSuccess($formId = '',$orderId = ''){
if($orderId == '') return ;
$order = StoreOrder::where('order_id',$orderId)->find();
$data['keyword1'] = $orderId;
$data['keyword2'] = date('Y-m-d H:i:s',time());
$data['keyword3'] = '已支付';
$data['keyword4'] = $order['pay_price'];
if($order['pay_type'] == 'yue') $data['keyword5'] = '余额支付';
else if($order['pay_type'] == 'weixin') $data['keyword5'] = '微信支付';
return self::sendOut('ORDER_PAY_SUCCESS',$order['uid'],$data,$formId,'/pages/order_details/index?order_id='.$orderId);
public static function sendOrderSuccess($formId = '', $orderId = '')
{
if ($orderId == '') return;
$order = StoreOrder::where('order_id', $orderId)->find();
$data['keyword1'] = $orderId;
$data['keyword2'] = date('Y-m-d H:i:s', time());
$data['keyword3'] = '已支付';
$data['keyword4'] = $order['pay_price'];
if ($order['pay_type'] == 'yue') $data['keyword5'] = '余额支付';
else if ($order['pay_type'] == 'weixin') $data['keyword5'] = '微信支付';
return self::sendOut('ORDER_PAY_SUCCESS', $order['uid'], $data, $formId, '/pages/order_details/index?order_id=' . $orderId);
}
/**
* 发送模板消息
* @param string $TempCode 模板消息常量名称
* @param string $TempCode 模板消息常量名称
* @param int $uid 用户uid
* @param array $data 模板内容
* @param string $formId formId
* @param string $link 跳转链接
* @return bool
*/
public static function sendOut($TempCode,$uid=null,$data=null,$formId = '',$link='')
public static function sendOut($TempCode, $uid = null, $data = null, $formId = '', $link = '')
{
try{
try {
$openid = WechatUser::uidToOpenid($uid);
if(!$openid) return false;
if(!$formId){
$form= RoutineFormId::getFormIdOne($uid,true);
if(!$form) return false;
if(isset($form['id'])) RoutineFormId::where('id',$form['id'])->delete();
}else{
$form['form_id']=$formId;
if (!$openid) return false;
if (!$formId) {
$form = RoutineFormId::getFormIdOne($uid, true);
if (!$form) return false;
if (isset($form['id'])) RoutineFormId::where('id', $form['id'])->delete();
} else {
$form['form_id'] = $formId;
}
return Template::instance()->routine()->setTemplateUrl($link)->setTemplateOpenId($openid)
->setTemplateData($data)->setTemplateFormId($form['form_id'])->setTemplateCode($TempCode)->send();
}catch (\Exception $e){
} catch (\Exception $e) {
return false;
}
}

View File

@ -34,7 +34,7 @@ class NoticeRepositories
$openid = $wechatUser['openid'];
$routineOpenid = $wechatUser['routine_openid'];
try {
if ($openid) {//公众号发送模板消息
if ($openid && in_array($order['is_channel'],[0,2])) {//公众号发送模板消息
WechatTemplateService::sendTemplate($openid, WechatTemplateService::ORDER_PAY_SUCCESS, [
'first' => '亲,您购买的商品已支付成功',
'keyword1' => $order['order_id'],
@ -51,7 +51,7 @@ class NoticeRepositories
]);
//订单支付成功后给客服发送客服消息
CustomerRepository::sendOrderPaySuccessCustomerService($order, 1);
} else if ($routineOpenid) {//小程序发送模板消息
} else if ($routineOpenid && in_array($order['is_channel'],[1,2])) {//小程序发送模板消息
RoutineTemplate::sendOrderSuccess($formId, $order['order_id']);
//订单支付成功后给客服发送客服消息
CustomerRepository::sendOrderPaySuccessCustomerService($order, 0);