init
- 框架初始化 - 安装插件 - 修复PHP8.4报错
This commit is contained in:
113
addons/shopro/notification/CustomeNotice.php
Normal file
113
addons/shopro/notification/CustomeNotice.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace addons\shopro\notification;
|
||||
|
||||
use addons\shopro\channel\Database;
|
||||
use addons\shopro\channel\Websocket;
|
||||
use addons\shopro\notification\traits\Notification as NotificationTrait;
|
||||
|
||||
/**
|
||||
* 自定义通知
|
||||
*/
|
||||
class CustomeNotice extends Notification
|
||||
{
|
||||
use NotificationTrait;
|
||||
|
||||
// 队列延迟时间,必须继承 ShouldQueue 接口
|
||||
public $delay = 0;
|
||||
|
||||
public $receiver_type = 'admin';
|
||||
|
||||
// 消息类型 Notification::$notificationType
|
||||
public $notification_type = 'system';
|
||||
|
||||
// 发送类型
|
||||
public $event = 'custom';
|
||||
|
||||
// 额外发送渠道
|
||||
public $channels = [];
|
||||
|
||||
// 额外数据
|
||||
public $data = [];
|
||||
|
||||
public $template = [
|
||||
'MessageDefaultContent' => '',
|
||||
];
|
||||
|
||||
// 返回的字段列表
|
||||
public $returnField = [];
|
||||
|
||||
|
||||
|
||||
public function __construct($params = [], $data = [])
|
||||
{
|
||||
$this->receiver_type = $params['receiver_type'] ?? 'admin';
|
||||
$this->notification_type = $params['notification_type'] ?? 'system';
|
||||
$this->channels = $params['channels'] ?? [];
|
||||
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function channels($notifiable)
|
||||
{
|
||||
// 默认发送渠道
|
||||
$channels = [Database::class, Websocket::class];
|
||||
|
||||
return array_merge($channels, $this->channels);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 数据库通知数据
|
||||
*
|
||||
* @param \think\Model $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function toDatabase($notifiable)
|
||||
{
|
||||
$params = $this->getArray();
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* socket 通知数据
|
||||
*
|
||||
* @param \think\Model $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function toWebsocket($notifiable)
|
||||
{
|
||||
$params = $this->getArray();
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 组合数据参数
|
||||
*
|
||||
* @param \think\Model $notifiable
|
||||
* @return array
|
||||
*/
|
||||
protected function getArray()
|
||||
{
|
||||
$params['data'] = [
|
||||
'jump_url' => $this->data['jump_url'] ?? ''
|
||||
];
|
||||
|
||||
$params['message_type'] = 'notification';
|
||||
$params['class_name'] = static::class;
|
||||
$params['message_text'] = $this->data['message_text'] ?? '';
|
||||
$params['message_title'] = $this->data['message_title'] ?? '';
|
||||
|
||||
$this->template['MessageDefaultContent'] = $this->data['message_title'] ?? '';
|
||||
|
||||
// 统一跳转地址
|
||||
return $params;
|
||||
}
|
||||
}
|
||||
192
addons/shopro/notification/Notification.php
Normal file
192
addons/shopro/notification/Notification.php
Normal file
@@ -0,0 +1,192 @@
|
||||
<?php
|
||||
|
||||
namespace addons\shopro\notification;
|
||||
|
||||
use think\queue\ShouldQueue;
|
||||
use addons\shopro\channel\Database;
|
||||
use addons\shopro\channel\Websocket;
|
||||
use addons\shopro\channel\Sms;
|
||||
use addons\shopro\channel\WechatMiniProgram;
|
||||
use addons\shopro\channel\WechatOfficialAccount;
|
||||
use addons\shopro\channel\WechatOfficialAccountBizsend;
|
||||
use addons\shopro\channel\Email;
|
||||
use app\admin\model\shopro\notification\Config;
|
||||
|
||||
/**
|
||||
* 消息通知基类
|
||||
*/
|
||||
class Notification implements ShouldQueue
|
||||
{
|
||||
// 队列名称,必须继承 ShouldQueue 接口
|
||||
|
||||
protected $config = null;
|
||||
|
||||
|
||||
public function initConfig()
|
||||
{
|
||||
// 缓存 5 分钟
|
||||
$config = Config::where('event', $this->event)->select();
|
||||
|
||||
$this->config = array_column($config, null, 'channel');
|
||||
}
|
||||
|
||||
|
||||
// 返回发送方式
|
||||
public function channels($notifiable)
|
||||
{
|
||||
$channels = [Database::class, Websocket::class];
|
||||
|
||||
if (isset($this->config['Sms']) && $this->config['Sms']['status'] == 'enable') {
|
||||
$channels[] = Sms::class;
|
||||
}
|
||||
|
||||
if (isset($this->config['Email']) && $this->config['Email']['status'] == 'enable') {
|
||||
$channels[] = Email::class;
|
||||
}
|
||||
|
||||
if (isset($this->config['WechatOfficialAccount']) && $this->config['WechatOfficialAccount']['status'] == 'enable') {
|
||||
$channels[] = WechatOfficialAccount::class;
|
||||
}
|
||||
|
||||
if (isset($this->config['WechatMiniProgram']) && $this->config['WechatMiniProgram']['status'] == 'enable') {
|
||||
$channels[] = WechatMiniProgram::class;
|
||||
}
|
||||
|
||||
return $channels;
|
||||
}
|
||||
|
||||
|
||||
// 格式化模板数据
|
||||
public function formatParams($params, $type)
|
||||
{
|
||||
$paramsData = $params['data'] ?? [];
|
||||
|
||||
$config = $this->config[$type] ?? [];
|
||||
|
||||
if (!$config) {
|
||||
// 不能发送
|
||||
return $params;
|
||||
}
|
||||
|
||||
$newData = [];
|
||||
if ($type == 'Email') {
|
||||
$newContent = $config['content'];
|
||||
if (preg_match_all("/(?<=(p:{)).+?(?=})/", $config['content'], $matches)) {
|
||||
foreach ($matches[0] as $k => $field) {
|
||||
$fieldVal = $paramsData[$field] ?? '';
|
||||
$newContent = str_replace("p:{" . $field . "}", $fieldVal, $newContent);
|
||||
}
|
||||
}
|
||||
|
||||
$params['content'] = $newContent;
|
||||
} else {
|
||||
$content_arr = $config['content'];
|
||||
|
||||
if (isset($content_arr['template_id']) && isset($content_arr['fields'])) {
|
||||
if (in_array($type, ['WechatOfficialAccountBizsend', 'WechatOfficialAccount', 'WechatMiniProgram', 'Sms'])) {
|
||||
$params['template_id'] = $content_arr['template_id'];
|
||||
}
|
||||
|
||||
foreach ($content_arr['fields'] as $key => $data) {
|
||||
// 用户填写了才处理,没填的字段直接 pass
|
||||
if (isset($data['template_field']) && $data['template_field']) {
|
||||
if (isset($data['field'])) {
|
||||
$value = $paramsData[$data['field']] ?? '-';
|
||||
} else {
|
||||
$value = $data['value'];
|
||||
}
|
||||
$value = $value ?: '-';
|
||||
|
||||
$value = $this->substrParams($data['template_field'], $value, $type);
|
||||
|
||||
if (in_array($type, ['WechatMiniProgram', 'WechatOfficialAccountBizsend'])) {
|
||||
$newData[$data['template_field']] = ['value' => $value];
|
||||
} else {
|
||||
$newData[$data['template_field']] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$params['data'] = $newData;
|
||||
}
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
|
||||
// 字符串截取
|
||||
public function substrParams($key, $value, $type)
|
||||
{
|
||||
if ($type == 'sms') {
|
||||
$value = mb_substr($value, 0, 18);
|
||||
} else if (in_array($type, ['WechatMiniProgram', 'WechatOfficialAccount', 'WechatOfficialAccountBizsend'])) {
|
||||
$value = $this->substrMiniParams($key, $value);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
||||
// 小程序裁剪参数
|
||||
private function substrMiniParams($key, $value)
|
||||
{
|
||||
switch(true) {
|
||||
case strpos($key, 'thing') !== false; // 事物
|
||||
$value = mb_substr($value, 0, 20);
|
||||
break;
|
||||
case strpos((string)$key, 'number') !== false; // 数字
|
||||
$value = mb_substr((string)$value, 0, 32);
|
||||
break;
|
||||
case strpos($key, 'letter') !== false; // 字母
|
||||
$value = mb_substr($value, 0, 32);
|
||||
break;
|
||||
case strpos($key, 'symbol') !== false; // 符号
|
||||
$value = mb_substr($value, 0, 5);
|
||||
break;
|
||||
case strpos($key, 'character_string') !== false;// 字符串
|
||||
$value = mb_substr($value, 0, 32);
|
||||
break;
|
||||
case strpos($key, 'phone_number') !== false; // 电话
|
||||
$value = mb_substr($value, 0, 17);
|
||||
break;
|
||||
case strpos($key, 'car_number') !== false; // 车牌
|
||||
$value = mb_substr($value, 0, 8);
|
||||
break;
|
||||
case strpos($key, 'name') !== false; // 姓名
|
||||
$value = mb_substr($value, 0, 10);
|
||||
break;
|
||||
case strpos($key, 'phrase') !== false; // 汉字
|
||||
$value = mb_substr($value, 0, 5);
|
||||
break;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 发送成功
|
||||
*/
|
||||
public function sendOk($channel) {
|
||||
// 更新发送条数
|
||||
Config::where('event', $this->event)->where('channel', $channel)->setInc('send_num');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置延迟时间
|
||||
*/
|
||||
public function delay($second = 0) {
|
||||
if (!($this instanceof ShouldQueue)) {
|
||||
error_stop("该消息类型不支持队列,请先继承队列");
|
||||
}
|
||||
$this->delay = $second;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
180
addons/shopro/notification/activity/GrouponFail.php
Normal file
180
addons/shopro/notification/activity/GrouponFail.php
Normal file
@@ -0,0 +1,180 @@
|
||||
<?php
|
||||
|
||||
namespace addons\shopro\notification\activity;
|
||||
|
||||
use addons\shopro\notification\Notification;
|
||||
use addons\shopro\notification\traits\Notification as NotificationTrait;
|
||||
use app\admin\model\shopro\order\Order as OrderModel;
|
||||
|
||||
/**
|
||||
* 拼团失败
|
||||
*/
|
||||
class GrouponFail extends Notification
|
||||
{
|
||||
use NotificationTrait;
|
||||
|
||||
// 队列延迟时间,必须继承 ShouldQueue 接口
|
||||
public $delay = 0;
|
||||
|
||||
public $receiver_type = 'user'; // 接收人:user=用户
|
||||
|
||||
// 消息类型 Notification::$notificationType
|
||||
public $notification_type = 'shop';
|
||||
|
||||
// 发送类型
|
||||
public $event = 'groupon_fail';
|
||||
|
||||
// 额外数据
|
||||
public $data = [];
|
||||
|
||||
public $template = [
|
||||
'MessageDefaultContent' => '您的拼团未成功,商品:{goods_title},将全额退款,请注意查收',
|
||||
// 'WechatOfficialAccount' => [
|
||||
// 'temp_no' => 'OPENTM401113750',
|
||||
// 'fields' => [
|
||||
// // 'first' => '您的拼团未成功',
|
||||
// // 'keyword1' => 'goods_title', // 拼团商品
|
||||
// // 'keyword2' => 'groupon_price', // 商品金额
|
||||
// // 'keyword3' => 'pay_fee', // 退款金额
|
||||
// // 'remark' => '您的拼团未成功,将全额退款,请注意查收',
|
||||
// [
|
||||
// "template_field" => "first",
|
||||
// "value" => '您的拼团未成功',
|
||||
// ],
|
||||
// [
|
||||
// "name" => "拼团商品",
|
||||
// "field" => "goods_title",
|
||||
// "template_field" => "keyword1",
|
||||
// ],
|
||||
// [
|
||||
// "name" => "商品金额",
|
||||
// "field" => "groupon_price",
|
||||
// "template_field" => "keyword2",
|
||||
// ],
|
||||
// [
|
||||
// "name" => "退款金额",
|
||||
// "field" => "pay_fee",
|
||||
// "template_field" => "keyword3",
|
||||
// ],
|
||||
// [
|
||||
// "template_field" => "remark",
|
||||
// "value" => '您的拼团未成功,将全额退款,请注意查收',
|
||||
// ]
|
||||
// ],
|
||||
// ],
|
||||
'WechatOfficialAccount' => [
|
||||
'temp_no' => false, // 目前公众号类目模板库,找不到符合条件模板
|
||||
'keywords' => [],
|
||||
'fields' => [],
|
||||
],
|
||||
'WechatMiniProgram' => [
|
||||
'category_id' => 670,
|
||||
'tid' => '4534',
|
||||
'kid' => [1,2,8,5], // 商品名称,参团人数,商品金额,退款金额
|
||||
'scene_desc' => '当拼团失败时通知用户', // 申请模板场景描述
|
||||
'fields' => [
|
||||
// 'thing1' => 'goods_title', // 商品名称
|
||||
// 'number2' => 'groupon_current_num', // 参团人数
|
||||
// 'amount8' => 'groupon_price', // 商品金额
|
||||
// 'amount5' => 'pay_fee', // 退款金额
|
||||
[
|
||||
"name" => "商品名称",
|
||||
"field" => "goods_title",
|
||||
"template_field" => "thing1",
|
||||
],
|
||||
[
|
||||
"name" => "参团人数",
|
||||
"field" => "groupon_current_num",
|
||||
"template_field" => "number2",
|
||||
],
|
||||
[
|
||||
"name" => "商品金额",
|
||||
"field" => "groupon_price",
|
||||
"template_field" => "amount8",
|
||||
],
|
||||
[
|
||||
"name" => "退款金额",
|
||||
"field" => "groupon_start_date",
|
||||
"template_field" => "pay_fee",
|
||||
],
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
// 返回的字段列表
|
||||
public $returnField = [
|
||||
'name' => '拼团失败通知',
|
||||
'channels' => ['Sms', 'Email', 'WechatOfficialAccount', 'WechatMiniProgram'],
|
||||
'fields' => [
|
||||
['name' => '消息名称', 'field' => 'template'],
|
||||
['name' => '团ID', 'field' => 'groupon_id'],
|
||||
['name' => '商品名称', 'field' => 'goods_title'],
|
||||
['name' => '拼团用户', 'field' => 'groupon_user'],
|
||||
['name' => '用户手机', 'field' => 'groupon_mobile'],
|
||||
['name' => '团长', 'field' => 'groupon_leader_nickname'],
|
||||
['name' => '团长手机', 'field' => 'groupon_leader_mobile'],
|
||||
['name' => '商品金额', 'field' => 'groupon_price'],
|
||||
['name' => '开团时间', 'field' => 'groupon_start_date'],
|
||||
['name' => '参团人数', 'field' => 'groupon_current_num'],
|
||||
['name' => '成团人数', 'field' => 'groupon_num'],
|
||||
['name' => '订单ID', 'field' => 'order_id'],
|
||||
['name' => '订单号', 'field' => 'order_sn'],
|
||||
['name' => '订单金额', 'field' => 'order_amount'],
|
||||
['name' => '支付金额', 'field' => 'pay_fee'],
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 组合数据参数
|
||||
*
|
||||
* @param \think\Model $notifiable
|
||||
* @return array
|
||||
*/
|
||||
protected function getData($notifiable)
|
||||
{
|
||||
$groupon = $this->data['groupon'];
|
||||
$grouponLogs = $this->data['groupon_logs'];
|
||||
$grouponLogs = $grouponLogs instanceof \think\Collection ? $grouponLogs : collection($grouponLogs); // 转为 collection
|
||||
$grouponLeader = $this->data['groupon_leader'];
|
||||
$goods = $this->data['goods'];
|
||||
|
||||
// 当前订单
|
||||
$order = $this->getCurrentOrder($notifiable, $groupon, $grouponLogs);
|
||||
$data['template'] = $this->returnField['name']; // 模板名称
|
||||
$data['groupon_id'] = $groupon['id'];
|
||||
$data['goods_title'] = $goods['title'];
|
||||
$data['groupon_user'] = $notifiable['nickname'];
|
||||
$data['groupon_mobile'] = $notifiable['mobile'];
|
||||
$data['groupon_leader_nickname'] = $grouponLeader['nickname'] ?? '';
|
||||
$data['groupon_leader_mobile'] = $grouponLeader['mobile'] ?? '';
|
||||
$data['groupon_price'] = $order ? '¥' . $order['goods_amount'] : '';
|
||||
$data['groupon_start_date'] = $groupon['createtime'];
|
||||
$data['groupon_current_num'] = $groupon['current_num'];
|
||||
$data['groupon_num'] = $groupon['num'];
|
||||
$data['order_id'] = $order['id'] ?? '';
|
||||
$data['order_sn'] = $order['order_sn'] ?? '';
|
||||
$data['order_amount'] = '¥' . $order['order_amount'] ?? '';
|
||||
$data['pay_fee'] = '¥' . $order['pay_fee'] ?? '';
|
||||
|
||||
// 统一跳转地址
|
||||
$data['jump_url'] = "/pages/activity/groupon/detail?id=" . $groupon['id'];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
// 获取当前订单
|
||||
private function getCurrentOrder($notifiable, $groupon, $grouponLogs)
|
||||
{
|
||||
$grouponLogs = $grouponLogs->column(null, 'user_id');
|
||||
$currentLog = $grouponLogs[$notifiable['id']] ?? null;
|
||||
|
||||
if ($currentLog) {
|
||||
$order = OrderModel::where('id', $currentLog['order_id'])->find();
|
||||
}
|
||||
|
||||
return $order ?? null;
|
||||
}
|
||||
}
|
||||
194
addons/shopro/notification/activity/GrouponFinish.php
Normal file
194
addons/shopro/notification/activity/GrouponFinish.php
Normal file
@@ -0,0 +1,194 @@
|
||||
<?php
|
||||
|
||||
namespace addons\shopro\notification\activity;
|
||||
|
||||
use addons\shopro\notification\Notification;
|
||||
use addons\shopro\notification\traits\Notification as NotificationTrait;
|
||||
use app\admin\model\shopro\order\Order as OrderModel;
|
||||
|
||||
/**
|
||||
* 拼团完成
|
||||
*/
|
||||
class GrouponFinish extends Notification
|
||||
{
|
||||
use NotificationTrait;
|
||||
|
||||
// 队列延迟时间,必须继承 ShouldQueue 接口
|
||||
public $delay = 0;
|
||||
|
||||
public $receiver_type = 'user'; // 接收人:user=用户
|
||||
|
||||
// 消息类型 Notification::$notificationType
|
||||
public $notification_type = 'shop';
|
||||
|
||||
// 发送类型
|
||||
public $event = 'groupon_finish';
|
||||
|
||||
// 额外数据
|
||||
public $data = [];
|
||||
|
||||
public $template = [
|
||||
'MessageDefaultContent' => '您的拼团已成功,商品:{goods_title},成团人数:{groupon_num},请注意查收',
|
||||
// 'WechatOfficialAccount' => [
|
||||
// 'temp_no' => 'OPENTM400932513',
|
||||
// 'fields' => [
|
||||
// // 'first' => '您的拼团已成功',
|
||||
// // 'keyword1' => 'goods_title', // 商品名称
|
||||
// // 'keyword2' => 'groupon_leader_nickname', // 团长
|
||||
// // 'keyword3' => 'groupon_num', // 成团人数
|
||||
// // 'remark' => '您的拼团已成功,点击查看详情',
|
||||
// [
|
||||
// "template_field" => "first",
|
||||
// "value" => '您的拼团已成功',
|
||||
// ],
|
||||
// [
|
||||
// "name" => "商品名称",
|
||||
// "field" => "goods_title",
|
||||
// "template_field" => "keyword1",
|
||||
// ],
|
||||
// [
|
||||
// "name" => "团长",
|
||||
// "field" => "groupon_leader_nickname",
|
||||
// "template_field" => "keyword2",
|
||||
// ],
|
||||
// [
|
||||
// "name" => "成团人数",
|
||||
// "field" => "groupon_num",
|
||||
// "template_field" => "keyword3",
|
||||
// ],
|
||||
// [
|
||||
// "template_field" => "remark",
|
||||
// "value" => '您的拼团已成功,点击查看详情',
|
||||
// ]
|
||||
// ],
|
||||
// ],
|
||||
'WechatOfficialAccount' => [
|
||||
'temp_no' => false, // 目前公众号类目模板库,找不到符合条件模板
|
||||
'keywords' => [],
|
||||
'fields' => [],
|
||||
// 'temp_no' => '44579',
|
||||
// 'keywords' => ['商品名称', '拼单时间'],
|
||||
// 'fields' => [
|
||||
// [
|
||||
// "name" => "商品名称",
|
||||
// "field" => "goods_title",
|
||||
// "template_field" => "thing2",
|
||||
// ],
|
||||
// [
|
||||
// "name" => "拼单时间",
|
||||
// "field" => "groupon_start_date",
|
||||
// "template_field" => "time4",
|
||||
// ]
|
||||
// ],
|
||||
],
|
||||
'WechatMiniProgram' => [
|
||||
'category_id' => 670,
|
||||
'tid' => '3098',
|
||||
'kid' => [7,3,2,5], // 商品名称,团长,成团人数,开团时间
|
||||
'scene_desc' => '当拼团成功时通知用户', // 申请模板场景描述
|
||||
'fields' => [
|
||||
// 'thing7' => 'goods_title', // 商品名称
|
||||
// 'name3' => 'groupon_leader_nickname', // 团长
|
||||
// 'number2' => 'groupon_num', // 成团人数
|
||||
// 'date5' => 'groupon_start_date', // 开团时间
|
||||
[
|
||||
"name" => "商品名称",
|
||||
"field" => "goods_title",
|
||||
"template_field" => "thing7",
|
||||
],
|
||||
[
|
||||
"name" => "团长",
|
||||
"field" => "groupon_leader_nickname",
|
||||
"template_field" => "name3",
|
||||
],
|
||||
[
|
||||
"name" => "成团人数",
|
||||
"field" => "groupon_num",
|
||||
"template_field" => "number2",
|
||||
],
|
||||
[
|
||||
"name" => "开团时间",
|
||||
"field" => "groupon_start_date",
|
||||
"template_field" => "date5",
|
||||
],
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
// 返回的字段列表
|
||||
public $returnField = [
|
||||
'name' => '拼团成功通知',
|
||||
'channels' => ['Sms', 'Email', 'WechatOfficialAccount', 'WechatMiniProgram'],
|
||||
'fields' => [
|
||||
['name' => '消息名称', 'field' => 'template'],
|
||||
['name' => '团ID', 'field' => 'groupon_id'],
|
||||
['name' => '商品名称', 'field' => 'goods_title'],
|
||||
['name' => '拼团用户', 'field' => 'groupon_user'],
|
||||
['name' => '用户手机', 'field' => 'groupon_mobile'],
|
||||
['name' => '团长', 'field' => 'groupon_leader_nickname'],
|
||||
['name' => '团长手机', 'field' => 'groupon_leader_mobile'],
|
||||
['name' => '商品金额', 'field' => 'groupon_price'],
|
||||
['name' => '开团时间', 'field' => 'groupon_start_date'],
|
||||
['name' => '成团时间', 'field' => 'groupon_finish_date'],
|
||||
['name' => '成团人数', 'field' => 'groupon_num'],
|
||||
['name' => '订单ID', 'field' => 'order_id'],
|
||||
['name' => '订单号', 'field' => 'order_sn'],
|
||||
['name' => '订单金额', 'field' => 'order_amount'],
|
||||
['name' => '支付金额', 'field' => 'pay_fee'],
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 组合数据参数
|
||||
*
|
||||
* @param \think\Model $notifiable
|
||||
* @return array
|
||||
*/
|
||||
protected function getData($notifiable)
|
||||
{
|
||||
$groupon = $this->data['groupon'];
|
||||
$grouponLogs = $this->data['groupon_logs'];
|
||||
$grouponLogs = $grouponLogs instanceof \think\Collection ? $grouponLogs : collection($grouponLogs); // 转为 collection
|
||||
$grouponLeader = $this->data['groupon_leader'];
|
||||
$goods = $this->data['goods'];
|
||||
|
||||
// 当前订单
|
||||
$order = $this->getCurrentOrder($notifiable, $groupon, $grouponLogs);
|
||||
$data['template'] = $this->returnField['name']; // 模板名称
|
||||
$data['groupon_id'] = $groupon['id'];
|
||||
$data['goods_title'] = $goods['title'];
|
||||
$data['groupon_user'] = $notifiable['nickname'];
|
||||
$data['groupon_mobile'] = $notifiable['mobile'];
|
||||
$data['groupon_leader_nickname'] = $grouponLeader['nickname'] ?? '';
|
||||
$data['groupon_leader_mobile'] = $grouponLeader['mobile'] ?? '';
|
||||
$data['groupon_price'] = $order ? '¥' . $order['goods_amount'] : '';
|
||||
$data['groupon_start_date'] = $groupon['createtime'];
|
||||
$data['groupon_finish_date'] = $groupon['finish_time'];
|
||||
$data['groupon_num'] = $groupon['num'];
|
||||
$data['order_id'] = $order['id'] ?? '';
|
||||
$data['order_sn'] = $order['order_sn'] ?? '';
|
||||
$data['order_amount'] = '¥' . $order['order_amount'] ?? '';
|
||||
$data['pay_fee'] = '¥' . $order['pay_fee'] ?? '';
|
||||
|
||||
// 统一跳转地址
|
||||
$data['jump_url'] = "/pages/activity/groupon/detail?id=" . $groupon['id'];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
// 获取当前订单
|
||||
private function getCurrentOrder($notifiable, $groupon, $grouponLogs)
|
||||
{
|
||||
$grouponLogs = $grouponLogs->column(null, 'user_id');
|
||||
$currentLog = $grouponLogs[$notifiable['id']] ?? null;
|
||||
|
||||
if ($currentLog) {
|
||||
$order = OrderModel::where('id', $currentLog['order_id'])->find();
|
||||
}
|
||||
|
||||
return $order ?? null;
|
||||
}
|
||||
}
|
||||
130
addons/shopro/notification/goods/StockWarning.php
Normal file
130
addons/shopro/notification/goods/StockWarning.php
Normal file
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
namespace addons\shopro\notification\goods;
|
||||
|
||||
use addons\shopro\notification\Notification;
|
||||
use addons\shopro\notification\traits\Notification as NotificationTrait;
|
||||
|
||||
/**
|
||||
* 库存预警提醒
|
||||
*/
|
||||
class StockWarning extends Notification
|
||||
{
|
||||
use NotificationTrait;
|
||||
|
||||
// 队列延迟时间,必须继承 ShouldQueue 接口
|
||||
public $delay = 0;
|
||||
|
||||
public $receiver_type = 'admin'; // 接收人:user=用户
|
||||
|
||||
// 消息类型 Notification::$notificationType
|
||||
public $notification_type = 'shop';
|
||||
|
||||
// 发送类型
|
||||
public $event = 'stock_warning';
|
||||
|
||||
// 额外数据
|
||||
public $data = [];
|
||||
|
||||
public $template = [
|
||||
'MessageDefaultContent' => '商品 {goods_name} 库存不足,请及时补货',
|
||||
// 'WechatOfficialAccount' => [
|
||||
// 'temp_no' => 'OPENTM415437052',
|
||||
// 'fields' => [
|
||||
// // 'first' => '您的积分发生变动,请及时查看',
|
||||
// // 'keyword1' => 'event_name', // 交易类型
|
||||
// // 'keyword2' => 'amount', // 交易金额
|
||||
// // 'keyword3' => 'create_date', // 交易时间
|
||||
// // 'keyword4' => 'score', // 账户余额
|
||||
// // 'remark' => '您的积分发生变动,请及时查看',
|
||||
// [
|
||||
// "template_field" => "first",
|
||||
// "value" => '您的积分发生变动,请及时查看',
|
||||
// ],
|
||||
// [
|
||||
// "name" => "交易类型",
|
||||
// "field" => "event_name",
|
||||
// "template_field" => "keyword1",
|
||||
// ],
|
||||
// [
|
||||
// "name" => "交易金额",
|
||||
// "field" => "amount",
|
||||
// "template_field" => "keyword2",
|
||||
// ],
|
||||
// [
|
||||
// "name" => "交易时间",
|
||||
// "field" => "create_date",
|
||||
// "template_field" => "keyword3",
|
||||
// ],
|
||||
// [
|
||||
// "name" => "账户余额",
|
||||
// "field" => "score",
|
||||
// "template_field" => "keyword4",
|
||||
// ],
|
||||
// [
|
||||
// "template_field" => "remark",
|
||||
// "value" => '您的积分发生变动,请及时查看',
|
||||
// ]
|
||||
// ],
|
||||
// ],
|
||||
'WechatMiniProgram' => [
|
||||
'category_id' => 670,
|
||||
'tid' => '2105',
|
||||
'kid' => [1, 4], // 商品名称,备注
|
||||
'scene_desc' => '当库存不足时通知管理员', // 申请模板场景描述
|
||||
'fields' => [
|
||||
// 'thing1' => 'event_name', // 商品名称
|
||||
// 'thing4' => 'amount', // 备注
|
||||
[
|
||||
"name" => "商品名称",
|
||||
"field" => "goods_name",
|
||||
"template_field" => "thing1",
|
||||
],
|
||||
[
|
||||
"name" => "备注",
|
||||
"field" => "description",
|
||||
"template_field" => "thing4",
|
||||
],
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
// 返回的字段列表
|
||||
public $returnField = [
|
||||
'name' => '商品补货通知',
|
||||
'channels' => ['Sms', 'Email'],
|
||||
'fields' => [
|
||||
['name' => '消息名称', 'field' => 'template'],
|
||||
['name' => '商品名称', 'field' => 'goods_name'],
|
||||
['name' => '当前库存', 'field' => 'stock'],
|
||||
['name' => '预警值', 'field' => 'stock_warning'],
|
||||
['name' => '说明', 'field' => 'description'],
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 组合数据参数
|
||||
*
|
||||
* @param \think\Model $notifiable
|
||||
* @return array
|
||||
*/
|
||||
protected function getData($notifiable)
|
||||
{
|
||||
$goods = $this->data['goods'];
|
||||
$goodsSkuPrice = $this->data['goodsSkuPrice'];
|
||||
$stock_warning = $this->data['stock_warning'];
|
||||
|
||||
$data['template'] = $this->returnField['name']; // 模板名称
|
||||
$data['goods_name'] = ($goodsSkuPrice['goods_sku_text'] ? join(',', $goodsSkuPrice['goods_sku_text']) . '-' : '') . ($goods ? $goods['title'] : '');
|
||||
$data['stock'] = $goodsSkuPrice['stock'];
|
||||
$data['stock_warning'] = $stock_warning;
|
||||
$data['description'] = '当前商品剩余库存' . $goodsSkuPrice['stock'] . ',低于预警阈值' . $stock_warning . ',请及时补货';
|
||||
|
||||
// 统一跳转地址(先不跳)
|
||||
// $data['jump_url'] = "/pages/order/detail?id=" . $goods['id'];
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
151
addons/shopro/notification/order/OrderApplyRefund.php
Normal file
151
addons/shopro/notification/order/OrderApplyRefund.php
Normal file
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
namespace addons\shopro\notification\order;
|
||||
|
||||
use addons\shopro\notification\Notification;
|
||||
use addons\shopro\notification\traits\Notification as NotificationTrait;
|
||||
|
||||
/**
|
||||
* 订单申请全额退款通知
|
||||
*/
|
||||
class OrderApplyRefund extends Notification
|
||||
{
|
||||
use NotificationTrait;
|
||||
|
||||
// 队列延迟时间,必须继承 ShouldQueue 接口
|
||||
public $delay = 0;
|
||||
|
||||
public $receiver_type = 'admin'; // 接收人:admin=管理员
|
||||
|
||||
// 消息类型 Notification::$notificationType
|
||||
public $notification_type = 'shop';
|
||||
|
||||
// 发送类型
|
||||
public $event = 'order_apply_refund';
|
||||
|
||||
// 额外数据
|
||||
public $data = [];
|
||||
|
||||
public $template = [
|
||||
'MessageDefaultContent' => '您有订单申请全额退款,下单用户:{nickname},订单号:{order_sn},支付金额:{pay_fee},{refund_status}',
|
||||
// 'WechatOfficialAccount' => [
|
||||
// 'temp_no' => 'TM00004',
|
||||
// 'fields' => [
|
||||
// // 'first' => '您有订单申请全额退款,请及时处理',
|
||||
// // 'reason' => 'reason', // 退款原因
|
||||
// // 'refund' => 'pay_fee', // 退款金额
|
||||
// // 'remark' => '您有订单申请全额退款,请及时处理',
|
||||
// [
|
||||
// "template_field" => "first",
|
||||
// "value" => '您有订单申请全额退款,请及时处理',
|
||||
// ],
|
||||
// [
|
||||
// "name" => "退款原因",
|
||||
// "field" => "reason",
|
||||
// "template_field" => "reason",
|
||||
// ],
|
||||
// [
|
||||
// "name" => "退款金额",
|
||||
// "field" => "pay_fee",
|
||||
// "template_field" => "refund",
|
||||
// ],
|
||||
// [
|
||||
// "template_field" => "remark",
|
||||
// "value" => '您有订单申请全额退款,请及时处理',
|
||||
// ]
|
||||
// ],
|
||||
// ],
|
||||
'WechatOfficialAccount' => [
|
||||
'temp_no' => '46044',
|
||||
'keywords' => ['订单编号', '退款金额', '申请时间'],
|
||||
'fields' => [
|
||||
[
|
||||
"name" => "订单编号",
|
||||
"field" => "order_sn",
|
||||
"template_field" => "character_string12",
|
||||
],
|
||||
[
|
||||
"name" => "退款金额",
|
||||
"field" => "pay_fee",
|
||||
"template_field" => "amount4",
|
||||
],
|
||||
[
|
||||
"name" => "申请时间",
|
||||
"field" => "apply_date",
|
||||
"template_field" => "time3",
|
||||
]
|
||||
],
|
||||
],
|
||||
'WechatMiniProgram' => [
|
||||
'category_id' => 670,
|
||||
'tid' => '1468',
|
||||
'kid' => [9,10], // 退款金额, 退款原因
|
||||
'scene_desc' => '当有用户申请退款时,通知管理员', // 申请模板场景描述
|
||||
'fields' => [
|
||||
// 'amount9' => 'pay_fee', // 退款金额
|
||||
// 'thing10' => 'reason', // 退款原因
|
||||
[
|
||||
"name" => "退款金额",
|
||||
"field" => "pay_fee",
|
||||
"template_field" => "amount9",
|
||||
],
|
||||
[
|
||||
"name" => "退款原因",
|
||||
"field" => "reason",
|
||||
"template_field" => "thing10",
|
||||
]
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
// 返回的字段列表
|
||||
public $returnField = [
|
||||
'name' => '订单退款申请',
|
||||
'channels' => ['Sms', 'Email', 'WechatOfficialAccount'],
|
||||
'fields' => [
|
||||
['name' => '消息名称', 'field' => 'template'],
|
||||
['name' => '订单ID', 'field' => 'order_id'],
|
||||
['name' => '订单号', 'field' => 'order_sn'],
|
||||
['name' => '下单用户', 'field' => 'nickname'],
|
||||
['name' => '用户手机', 'field' => 'mobile'],
|
||||
['name' => '退款金额', 'field' => 'pay_fee'],
|
||||
['name' => '下单时间', 'field' => 'create_date'],
|
||||
['name' => '支付时间', 'field' => 'paid_date'],
|
||||
['name' => '退款原因', 'field' => 'reason'],
|
||||
['name' => '退款状态', 'field' => 'refund_status'],
|
||||
['name' => '申请时间', 'field' => 'apply_date']
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 组合数据参数
|
||||
*
|
||||
* @param \think\Model $notifiable
|
||||
* @return array
|
||||
*/
|
||||
protected function getData($notifiable)
|
||||
{
|
||||
$order = $this->data['order'];
|
||||
$ext = $order['ext'] ?? [];
|
||||
$user = $this->data['user'];
|
||||
$auto_refund = $this->data['auto_refund'];
|
||||
|
||||
$data['template'] = $this->returnField['name']; // 模板名称
|
||||
$data['order_id'] = $order['id'];
|
||||
$data['order_sn'] = $order['order_sn'];
|
||||
$data['nickname'] = $user['nickname'] ?? '';
|
||||
$data['mobile'] = $user['mobile'] ?? '';
|
||||
$data['pay_fee'] = '¥' . $order['pay_fee'];
|
||||
$data['create_date'] = $order['createtime'];
|
||||
$data['paid_date'] = $order['paid_time'];
|
||||
$data['reason'] = '订单申请全额退款' . ($auto_refund ? ',已自动退款,请及时查看' : ',请及时处理');
|
||||
$data['refund_status'] = $auto_refund ? '已自动退款,请及时查看' : '请及时处理';
|
||||
$data['apply_date'] = $ext['apply_refund_date'] ?? date('Y-m-d H:i:s');
|
||||
|
||||
// 统一跳转地址
|
||||
$data['jump_url'] = "";
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
189
addons/shopro/notification/order/OrderDispatched.php
Normal file
189
addons/shopro/notification/order/OrderDispatched.php
Normal file
@@ -0,0 +1,189 @@
|
||||
<?php
|
||||
|
||||
namespace addons\shopro\notification\order;
|
||||
|
||||
use addons\shopro\notification\Notification;
|
||||
use addons\shopro\notification\traits\Notification as NotificationTrait;
|
||||
use app\admin\model\shopro\order\Address as OrderAddressModel;
|
||||
|
||||
/**
|
||||
* 订单通知
|
||||
*/
|
||||
class OrderDispatched extends Notification
|
||||
{
|
||||
use NotificationTrait;
|
||||
|
||||
// 队列延迟时间,必须继承 ShouldQueue 接口
|
||||
public $delay = 0;
|
||||
|
||||
public $receiver_type = 'user'; // 接收人:user=用户
|
||||
|
||||
// 消息类型 Notification::$notificationType
|
||||
public $notification_type = 'shop';
|
||||
|
||||
// 发送类型
|
||||
public $event = 'order_dispatched';
|
||||
|
||||
// 额外数据
|
||||
public $data = [];
|
||||
|
||||
public $template = [
|
||||
'MessageDefaultContent' => '您的订单已发货,物流公司:{express_name},运单号:{express_no},请注意查收',
|
||||
// 'WechatOfficialAccount' => [
|
||||
// 'temp_no' => 'OPENTM418033200',
|
||||
// 'fields' => [
|
||||
// // 'first' => '您的订单已发货,请注意查收',
|
||||
// // 'keyword1' => 'order_sn', // 订单编号
|
||||
// // 'keyword2' => 'dispatch_date', // 发货时间
|
||||
// // 'keyword3' => 'express_name', // 物流公司
|
||||
// // 'keyword4' => 'express_no', // 快递单号
|
||||
// // 'remark' => '',
|
||||
// [
|
||||
// "template_field" => "first",
|
||||
// "value" => '您的订单已发货,请注意查收',
|
||||
// ],
|
||||
// [
|
||||
// "name" => "订单编号",
|
||||
// "field" => "order_sn",
|
||||
// "template_field" => "keyword1",
|
||||
// ],
|
||||
// [
|
||||
// "name" => "发货时间",
|
||||
// "field" => "dispatch_date",
|
||||
// "template_field" => "keyword2",
|
||||
// ],
|
||||
// [
|
||||
// "name" => "物流公司",
|
||||
// "field" => "express_name",
|
||||
// "template_field" => "keyword3",
|
||||
// ],
|
||||
// [
|
||||
// "name" => "快递单号",
|
||||
// "field" => "express_no",
|
||||
// "template_field" => "keyword4",
|
||||
// ],
|
||||
// [
|
||||
// "template_field" => "remark",
|
||||
// "value" => '您的订单已发货,请注意查收',
|
||||
// ]
|
||||
// ],
|
||||
// ],
|
||||
'WechatOfficialAccount' => [
|
||||
'temp_no' => '42984',
|
||||
'keywords' => ['订单编号', '发货时间', '快递公司', '快递单号'],
|
||||
'fields' => [
|
||||
[
|
||||
"name" => "订单编号",
|
||||
"field" => "order_sn",
|
||||
"template_field" => "character_string2",
|
||||
],
|
||||
[
|
||||
"name" => "发货时间",
|
||||
"field" => "dispatch_date",
|
||||
"template_field" => "time12",
|
||||
],
|
||||
[
|
||||
"name" => "快递公司",
|
||||
"field" => "express_name",
|
||||
"template_field" => "thing13",
|
||||
],
|
||||
[
|
||||
"name" => "快递单号",
|
||||
"field" => "express_no",
|
||||
"template_field" => "character_string14",
|
||||
]
|
||||
],
|
||||
],
|
||||
'WechatMiniProgram' => [
|
||||
'category_id' => 670,
|
||||
'tid' => '1458',
|
||||
'kid' => [7,3,1,2], // 订单编号,发货事件,快递公司,快递单号
|
||||
'scene_desc' => '当订单发货时通知用户', // 申请模板场景描述
|
||||
'fields' => [
|
||||
// 'character_string7' => 'order_sn', // 订单编号
|
||||
// 'time3' => 'dispatch_date', // 发货时间
|
||||
// 'thing1' => 'express_name', // 物流公司
|
||||
// 'character_string2' => 'express_no', // 快递单号
|
||||
[
|
||||
"name" => "订单编号",
|
||||
"field" => "order_sn",
|
||||
"template_field" => "character_string7",
|
||||
],
|
||||
[
|
||||
"name" => "发货时间",
|
||||
"field" => "dispatch_date",
|
||||
"template_field" => "time3",
|
||||
],
|
||||
[
|
||||
"name" => "物流公司",
|
||||
"field" => "express_name",
|
||||
"template_field" => "thing1",
|
||||
],
|
||||
[
|
||||
"name" => "快递单号",
|
||||
"field" => "express_no",
|
||||
"template_field" => "character_string2",
|
||||
],
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
// 返回的字段列表
|
||||
public $returnField = [
|
||||
'name' => '订单发货通知',
|
||||
'channels' => ['Sms', 'Email', 'WechatOfficialAccount', 'WechatMiniProgram'],
|
||||
'fields' => [
|
||||
['name' => '消息名称', 'field' => 'template'],
|
||||
['name' => '订单ID', 'field' => 'order_id'],
|
||||
['name' => '订单号', 'field' => 'order_sn'],
|
||||
['name' => '订单金额', 'field' => 'order_amount'],
|
||||
['name' => '发货时间', 'field' => 'dispatch_date'],
|
||||
['name' => '商品名称', 'field' => 'goods_title'],
|
||||
['name' => '购买数量', 'field' => 'goods_num'],
|
||||
['name' => '快递公司', 'field' => 'express_name'],
|
||||
['name' => '快递单号', 'field' => 'express_no'],
|
||||
['name' => '收件信息', 'field' => 'consignee'],
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 组合数据参数
|
||||
*
|
||||
* @param \think\Model $notifiable
|
||||
* @param \think\Model $order
|
||||
* @param \think\Collection $items
|
||||
* @param \think\Model $express
|
||||
* @return array
|
||||
*/
|
||||
protected function getData($notifiable)
|
||||
{
|
||||
$order = $this->data['order'];
|
||||
$items = collection($this->data['items']);
|
||||
$express = $this->data['express'] ?? null;
|
||||
|
||||
$data['template'] = $this->returnField['name']; // 模板名称
|
||||
$data['order_id'] = $order['id'];
|
||||
$data['order_sn'] = $order['order_sn'];
|
||||
$data['order_amount'] = '¥' . $order['order_amount'];
|
||||
$data['dispatch_date'] = ($order['ext'] && isset($order['ext']['send_time'])) ?
|
||||
date('Y-m-d H:i:s', $order['ext']['send_time']) : date('Y-m-d H:i:s');
|
||||
|
||||
$goods_titles = $items->column('goods_title');
|
||||
$goods_nums = $items->column('goods_num');
|
||||
$data['goods_title'] = join(',', $goods_titles);
|
||||
$data['goods_num'] = '共' . array_sum($goods_nums) . '件商品';
|
||||
$data['express_name'] = $express ? $express['express_name'] : '-';
|
||||
$data['express_no'] = $express ? $express['express_no'] : '-';
|
||||
|
||||
$address = OrderAddressModel::where('order_id', $order['id'])->find();
|
||||
$data['consignee'] = $address ? ($address['consignee'] . '-' . $address['mobile']) : '';
|
||||
|
||||
// 统一跳转地址
|
||||
$data['jump_url'] = "/pages/order/detail?id=" . $order['id'];
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
167
addons/shopro/notification/order/OrderNew.php
Normal file
167
addons/shopro/notification/order/OrderNew.php
Normal file
@@ -0,0 +1,167 @@
|
||||
<?php
|
||||
|
||||
namespace addons\shopro\notification\order;
|
||||
|
||||
use addons\shopro\notification\Notification;
|
||||
use addons\shopro\notification\traits\Notification as NotificationTrait;
|
||||
use app\admin\model\shopro\order\Address;
|
||||
|
||||
/**
|
||||
* 新订单通知
|
||||
*/
|
||||
class OrderNew extends Notification
|
||||
{
|
||||
use NotificationTrait;
|
||||
|
||||
// 队列延迟时间,必须继承 ShouldQueue 接口
|
||||
public $delay = 0;
|
||||
|
||||
public $receiver_type = 'admin'; // 接收人:user=用户
|
||||
|
||||
// 消息类型 Notification::$notificationType
|
||||
public $notification_type = 'shop';
|
||||
|
||||
// 发送类型
|
||||
public $event = 'order_new';
|
||||
|
||||
// 额外数据
|
||||
public $data = [];
|
||||
|
||||
public $template = [
|
||||
'MessageDefaultContent' => '您有新的待处理订单,下单用户:{nickname},订单号:{order_sn},订单金额:{order_amount},请及时处理',
|
||||
// 'WechatOfficialAccount' => [
|
||||
// 'temp_no' => 'OPENTM417875155',
|
||||
// 'fields' => [
|
||||
// // 'first' => '您有新的订单待处理',
|
||||
// // 'keyword1' => 'order_sn', // 订单号
|
||||
// // 'keyword2' => 'pay_fee', // 实付金额
|
||||
// // 'keyword3' => 'create_date', // 下单时间
|
||||
// // 'remark' => '您有新的订单待处理,请及时处理',
|
||||
// [
|
||||
// "template_field" => "first",
|
||||
// "value" => '您有新的订单待处理',
|
||||
// ],
|
||||
// [
|
||||
// "name" => "订单号",
|
||||
// "field" => "order_sn",
|
||||
// "template_field" => "keyword1",
|
||||
// ],
|
||||
// [
|
||||
// "name" => "实付金额",
|
||||
// "field" => "pay_fee",
|
||||
// "template_field" => "keyword2",
|
||||
// ],
|
||||
// [
|
||||
// "name" => "下单时间",
|
||||
// "field" => "create_date",
|
||||
// "template_field" => "keyword3",
|
||||
// ],
|
||||
// [
|
||||
// "template_field" => "remark",
|
||||
// "value" => '您有新的订单待处理,请及时处理',
|
||||
// ]
|
||||
// ],
|
||||
// ],
|
||||
'WechatOfficialAccount' => [
|
||||
'temp_no' => '46624',
|
||||
'keywords' => ['订单号', '订单金额', '下单时间'],
|
||||
'fields' => [
|
||||
[
|
||||
"name" => "订单号",
|
||||
"field" => "order_sn",
|
||||
"template_field" => "character_string1",
|
||||
],
|
||||
[
|
||||
"name" => "订单金额",
|
||||
"field" => "order_amount",
|
||||
"template_field" => "amount3",
|
||||
],
|
||||
[
|
||||
"name" => "下单时间",
|
||||
"field" => "create_date",
|
||||
"template_field" => "time9",
|
||||
]
|
||||
],
|
||||
],
|
||||
'WechatMiniProgram' => [
|
||||
'category_id' => 670,
|
||||
'tid' => '1476',
|
||||
'kid' => [4,12,6], // 订单编号,实付金额,订单时间
|
||||
'scene_desc' => '当有新订单时通知管理员', // 申请模板场景描述
|
||||
'fields' => [
|
||||
// 'character_string4' => 'order_sn', // 订单编号
|
||||
// 'amount12' => 'pay_fee', // 实付金额
|
||||
// 'date6' => 'create_date', // 订单时间
|
||||
[
|
||||
"name" => "订单编号",
|
||||
"field" => "order_sn",
|
||||
"template_field" => "character_string4",
|
||||
],
|
||||
[
|
||||
"name" => "实付金额",
|
||||
"field" => "pay_fee",
|
||||
"template_field" => "amount12",
|
||||
],
|
||||
[
|
||||
"name" => "订单时间",
|
||||
"field" => "create_date",
|
||||
"template_field" => "date6",
|
||||
],
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
// 返回的字段列表
|
||||
public $returnField = [
|
||||
'name' => '新订单通知',
|
||||
'channels' => ['Sms', 'Email', 'WechatOfficialAccount'],
|
||||
'fields' => [
|
||||
['name' => '消息名称', 'field' => 'template'],
|
||||
['name' => '订单ID', 'field' => 'order_id'],
|
||||
['name' => '订单号', 'field' => 'order_sn'],
|
||||
['name' => '订单金额', 'field' => 'order_amount'],
|
||||
['name' => '下单用户', 'field' => 'nickname'],
|
||||
['name' => '用户手机', 'field' => 'mobile'],
|
||||
['name' => '支付金额', 'field' => 'pay_fee'],
|
||||
['name' => '收货人', 'field' => 'consignee'],
|
||||
['name' => '收货地址', 'field' => 'address'],
|
||||
['name' => '下单时间', 'field' => 'create_date'],
|
||||
['name' => '支付时间', 'field' => 'paid_date']
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 组合数据参数
|
||||
*
|
||||
* @param \think\Model $notifiable
|
||||
* @return array
|
||||
*/
|
||||
protected function getData($notifiable)
|
||||
{
|
||||
$order = $this->data['order'];
|
||||
$user = $this->data['user'];
|
||||
$address = Address::where('order_id', $order['id'])->find();
|
||||
if ($address) {
|
||||
$consignee = $address['consignee'] . '-' . $address['mobile'];
|
||||
$address_info = $address['province_name'] . '/' . $address['city_name'] . '/' . $address['district_name'] . '/' . $address['address'];
|
||||
}
|
||||
|
||||
$data['template'] = $this->returnField['name']; // 模板名称
|
||||
$data['order_id'] = $order['id'];
|
||||
$data['order_sn'] = $order['order_sn'];
|
||||
$data['order_amount'] = '¥' . $order['order_amount'];
|
||||
$data['nickname'] = $user['nickname'] ?? '';
|
||||
$data['mobile'] = $user['mobile'] ?? '';
|
||||
$data['pay_fee'] = '¥' . $order['pay_fee'];
|
||||
$data['consignee'] = $consignee ?? '';
|
||||
$data['address'] = $address_info ?? '';
|
||||
$data['create_date'] = $order['createtime'];
|
||||
$data['paid_date'] = $order['paid_time'];
|
||||
|
||||
// 统一跳转地址(先不跳)
|
||||
// $data['jump_url'] = "/pages/order/detail?id=" . $order['id'];
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
179
addons/shopro/notification/order/OrderRefund.php
Normal file
179
addons/shopro/notification/order/OrderRefund.php
Normal file
@@ -0,0 +1,179 @@
|
||||
<?php
|
||||
|
||||
namespace addons\shopro\notification\order;
|
||||
|
||||
use addons\shopro\notification\Notification;
|
||||
use addons\shopro\notification\traits\Notification as NotificationTrait;
|
||||
use app\admin\model\shopro\Refund;
|
||||
|
||||
/**
|
||||
* 订单退款通知
|
||||
*/
|
||||
class OrderRefund extends Notification
|
||||
{
|
||||
use NotificationTrait;
|
||||
|
||||
// 队列延迟时间,必须继承 ShouldQueue 接口
|
||||
public $delay = 0;
|
||||
|
||||
public $receiver_type = 'user'; // 接收人:user=用户
|
||||
|
||||
// 消息类型 Notification::$notificationType
|
||||
public $notification_type = 'shop';
|
||||
|
||||
// 发送类型
|
||||
public $event = 'order_refund';
|
||||
|
||||
// 额外数据
|
||||
public $data = [];
|
||||
|
||||
public $template = [
|
||||
'MessageDefaultContent' => '您的订单已退款,订单号:{order_sn},退款金额:{refund_money},请注意查收',
|
||||
// 'WechatOfficialAccount' => [
|
||||
// 'temp_no' => 'OPENTM413279802',
|
||||
// 'fields' => [
|
||||
// // 'first' => '您的订单已退款,点击查看详情',
|
||||
// // 'keyword1' => 'order_sn', // 订单编号
|
||||
// // 'keyword2' => 'goods_title', // 商品名称
|
||||
// // 'keyword3' => 'refund_money', // 退款金额
|
||||
// // 'remark' => '您的订单已退款,点击查看详情',
|
||||
// [
|
||||
// "template_field" => "first",
|
||||
// "value" => '您的订单已退款,点击查看详情',
|
||||
// ],
|
||||
// [
|
||||
// "name" => "订单编号",
|
||||
// "field" => "order_sn",
|
||||
// "template_field" => "keyword1",
|
||||
// ],
|
||||
// [
|
||||
// "name" => "商品名称",
|
||||
// "field" => "goods_title",
|
||||
// "template_field" => "keyword2",
|
||||
// ],
|
||||
// [
|
||||
// "name" => "退款金额",
|
||||
// "field" => "refund_money",
|
||||
// "template_field" => "keyword3",
|
||||
// ],
|
||||
// [
|
||||
// "template_field" => "remark",
|
||||
// "value" => '您的订单已退款,点击查看详情',
|
||||
// ]
|
||||
// ],
|
||||
// ],
|
||||
'WechatOfficialAccount' => [
|
||||
'temp_no' => '45762',
|
||||
'keywords' => ['订单编号', '商品名称', '退款金额'],
|
||||
'fields' => [
|
||||
[
|
||||
"name" => "订单编号",
|
||||
"field" => "order_sn",
|
||||
"template_field" => "character_string10",
|
||||
],
|
||||
[
|
||||
"name" => "商品名称",
|
||||
"field" => "goods_title",
|
||||
"template_field" => "thing8",
|
||||
],
|
||||
[
|
||||
"name" => "退款金额",
|
||||
"field" => "refund_money",
|
||||
"template_field" => "amount2",
|
||||
]
|
||||
],
|
||||
],
|
||||
'WechatMiniProgram' => [
|
||||
'category_id' => 670,
|
||||
'tid' => '1451',
|
||||
'kid' => [7,10,3], // 订单编号,商品名称,退款金额
|
||||
'scene_desc' => '当订单发生退款时通知用户', // 申请模板场景描述
|
||||
'fields' => [
|
||||
// 'character_string7' => 'order_sn', // 订单编号
|
||||
// 'thing10' => 'goods_title', // 商品名称
|
||||
// 'amount3' => 'refund_money', // 退款金额
|
||||
[
|
||||
"name" => "订单编号",
|
||||
"field" => "order_sn",
|
||||
"template_field" => "character_string7",
|
||||
],
|
||||
[
|
||||
"name" => "商品名称",
|
||||
"field" => "goods_title",
|
||||
"template_field" => "thing10",
|
||||
],
|
||||
[
|
||||
"name" => "退款金额",
|
||||
"field" => "refund_money",
|
||||
"template_field" => "amount3",
|
||||
],
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
// 返回的字段列表
|
||||
public $returnField = [
|
||||
'name' => '订单退款成功通知',
|
||||
'channels' => ['Sms', 'Email', 'WechatOfficialAccount', 'WechatMiniProgram'],
|
||||
'fields' => [
|
||||
['name' => '消息名称', 'field' => 'template'],
|
||||
['name' => '订单ID', 'field' => 'order_id'],
|
||||
['name' => '订单号', 'field' => 'order_sn'],
|
||||
['name' => '订单金额', 'field' => 'order_amount'],
|
||||
['name' => '用户昵称', 'field' => 'nickname'],
|
||||
['name' => '用户手机', 'field' => 'mobile'],
|
||||
['name' => '商品名称', 'field' => 'goods_title'],
|
||||
['name' => '商品金额', 'field' => 'goods_amount'],
|
||||
['name' => '退款金额', 'field' => 'refund_money'],
|
||||
['name' => '退款类型', 'field' => 'refund_type'],
|
||||
['name' => '退款时间', 'field' => 'refund_date']
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 组合数据参数
|
||||
*
|
||||
* @param \think\Model $notifiable
|
||||
* @return array
|
||||
*/
|
||||
protected function getData($notifiable)
|
||||
{
|
||||
$order = $this->data['order'];
|
||||
$items = $this->data['items'];
|
||||
$refund_method = $this->data['refund_method'];
|
||||
$refund_type = $this->data['refund_type'];
|
||||
|
||||
$data['template'] = $this->returnField['name']; // 模板名称
|
||||
$data['order_id'] = $order['id'];
|
||||
$data['order_sn'] = $order['order_sn'];
|
||||
$data['order_amount'] = '¥' . $order['order_amount'];
|
||||
$data['nickname'] = $notifiable['nickname'];
|
||||
$data['mobile'] = $notifiable['mobile'];
|
||||
|
||||
if ($refund_method == 'full_refund') {
|
||||
// 全额退款
|
||||
$refund_money = $order['pay_fee'];
|
||||
$goods_title = '订单全部商品';
|
||||
$goods_amount = $order['goods_amount'];
|
||||
} else {
|
||||
$item = $items[0]; // 只有一个商品
|
||||
$refund_money = $item['refund_fee'];
|
||||
$goods_title = $item['goods_title'];
|
||||
$goods_amount = ($item['goods_price'] * $item['goods_num']);
|
||||
}
|
||||
|
||||
$refundTypeList = (new Refund)->refundTypeList();
|
||||
$data['goods_title'] = $goods_title;
|
||||
$data['goods_amount'] = '¥' . $goods_amount;
|
||||
$data['refund_money'] = '¥' . $refund_money;
|
||||
$data['refund_type'] = $refundTypeList[$refund_type] ?? '';
|
||||
$data['refund_date'] = $order['updatetime'];
|
||||
|
||||
// 统一跳转地址
|
||||
$data['jump_url'] = "/pages/order/detail?id=" . $order['id'];
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace addons\shopro\notification\order\aftersale;
|
||||
|
||||
/**
|
||||
* 售后结果通知
|
||||
*/
|
||||
class OrderAdminAftersaleChange extends OrderAftersaleChangeBase
|
||||
{
|
||||
|
||||
public $receiver_type = 'admin'; // 接收人:admin=管理员
|
||||
|
||||
// 发送类型
|
||||
public $event = 'order_admin_aftersale_change';
|
||||
|
||||
// 返回的字段列表
|
||||
public $returnField = [
|
||||
'name' => '售后结果通知',
|
||||
'channels' => ['Sms', 'Email', 'WechatOfficialAccount'],
|
||||
'fields' => [
|
||||
['name' => '消息名称', 'field' => 'template'],
|
||||
['name' => '售后单ID', 'field' => 'aftersale_id'],
|
||||
['name' => '售后单号', 'field' => 'aftersale_sn'],
|
||||
['name' => '申请时间', 'field' => 'apply_date'],
|
||||
['name' => '订单ID', 'field' => 'order_id'],
|
||||
['name' => '订单号', 'field' => 'order_sn'],
|
||||
['name' => '订单金额', 'field' => 'order_amount'],
|
||||
['name' => '下单时间', 'field' => 'create_date'],
|
||||
['name' => '申请用户', 'field' => 'nickname'],
|
||||
['name' => '用户手机', 'field' => 'mobile'],
|
||||
['name' => '支付金额', 'field' => 'pay_fee'],
|
||||
['name' => '售后类型', 'field' => 'aftersale_type'],
|
||||
['name' => '联系电话', 'field' => 'aftersale_mobile'],
|
||||
['name' => '商品名称', 'field' => 'goods_title'],
|
||||
['name' => '商品规格', 'field' => 'goods_sku_text'],
|
||||
['name' => '商品原价', 'field' => 'goods_original_price'],
|
||||
['name' => '商品价格', 'field' => 'goods_price'],
|
||||
['name' => '购买数量', 'field' => 'goods_num'],
|
||||
['name' => '优惠金额', 'field' => 'discount_fee'],
|
||||
['name' => '售后状态', 'field' => 'aftersale_status_text'],
|
||||
['name' => '退款状态', 'field' => 'refund_status_text'],
|
||||
['name' => '退款金额', 'field' => 'refund_fee'],
|
||||
['name' => '变动内容', 'field' => 'content'],
|
||||
['name' => '处理时间', 'field' => 'oper_date'],
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 组合数据参数
|
||||
*
|
||||
* @param \think\Model $notifiable
|
||||
* @return array
|
||||
*/
|
||||
protected function getData($notifiable)
|
||||
{
|
||||
$data = parent::getData($notifiable);
|
||||
$data['jump_url'] = ''; // 管理员消息不予跳转
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace addons\shopro\notification\order\aftersale;
|
||||
|
||||
/**
|
||||
* 售后结果通知
|
||||
*/
|
||||
class OrderAftersaleChange extends OrderAftersaleChangeBase
|
||||
{
|
||||
|
||||
public $receiver_type = 'user'; // 接收人:user=用户
|
||||
|
||||
|
||||
// 发送类型
|
||||
public $event = 'order_aftersale_change';
|
||||
}
|
||||
@@ -0,0 +1,214 @@
|
||||
<?php
|
||||
|
||||
namespace addons\shopro\notification\order\aftersale;
|
||||
|
||||
use addons\shopro\notification\Notification;
|
||||
use addons\shopro\notification\traits\Notification as NotificationTrait;
|
||||
|
||||
/**
|
||||
* 售后结果通知
|
||||
*/
|
||||
class OrderAftersaleChangeBase extends Notification
|
||||
{
|
||||
use NotificationTrait;
|
||||
|
||||
// 队列延迟时间,必须继承 ShouldQueue 接口
|
||||
public $delay = 0;
|
||||
|
||||
// 消息类型 Notification::$notificationType
|
||||
public $notification_type = 'shop';
|
||||
|
||||
// 发送类型
|
||||
public $event = 'order_aftersale_change';
|
||||
|
||||
// 额外数据
|
||||
public $data = [];
|
||||
|
||||
public $template = [
|
||||
'MessageDefaultContent' => '您的售后申请有新的变化,售后单号:{aftersale_sn},变动内容:{content},请及时处理',
|
||||
// 'WechatOfficialAccount' => [
|
||||
// 'temp_no' => 'OPENTM417005336',
|
||||
// 'fields' => [
|
||||
// // 'first' => '您的售后申请有新的变化',
|
||||
// // 'keyword1' => 'aftersale_sn', // 售后编号
|
||||
// // 'keyword2' => 'goods_title', // 商品名称
|
||||
// // 'keyword3' => 'aftersale_status_text', // 状态
|
||||
// // 'keyword4' => 'oper_date', // 时间
|
||||
// // 'remark' => '您的售后申请有新的变化,点击立即处理',
|
||||
// [
|
||||
// "template_field" => "first",
|
||||
// "value" => '您的售后申请有新的变化',
|
||||
// ],
|
||||
// [
|
||||
// "name" => "售后编号",
|
||||
// "field" => "aftersale_sn",
|
||||
// "template_field" => "keyword1",
|
||||
// ],
|
||||
// [
|
||||
// "name" => "商品名称",
|
||||
// "field" => "goods_title",
|
||||
// "template_field" => "keyword2",
|
||||
// ],
|
||||
// [
|
||||
// "name" => "状态",
|
||||
// "field" => "aftersale_status_text",
|
||||
// "template_field" => "keyword3",
|
||||
// ],
|
||||
// [
|
||||
// "name" => "时间",
|
||||
// "field" => "oper_date",
|
||||
// "template_field" => "keyword4",
|
||||
// ],
|
||||
// [
|
||||
// "template_field" => "remark",
|
||||
// "value" => '您的售后申请有新的变化,点击立即处理',
|
||||
// ]
|
||||
// ],
|
||||
// ],
|
||||
'WechatOfficialAccount' => [
|
||||
'temp_no' => '46232',
|
||||
'keywords' => ['订单编号', '退款商品', '退款金额', '处理结果'],
|
||||
'fields' => [
|
||||
[
|
||||
"name" => "订单编号",
|
||||
"field" => "order_sn",
|
||||
"template_field" => "character_string8",
|
||||
],
|
||||
[
|
||||
"name" => "退款商品",
|
||||
"field" => "goods_title",
|
||||
"template_field" => "thing4",
|
||||
],
|
||||
[
|
||||
"name" => "退款金额",
|
||||
"field" => "refund_fee",
|
||||
"template_field" => "amount5",
|
||||
],
|
||||
[
|
||||
"name" => "处理结果",
|
||||
"field" => "aftersale_status_text",
|
||||
"template_field" => "thing6",
|
||||
]
|
||||
],
|
||||
],
|
||||
'WechatMiniProgram' => [
|
||||
'category_id' => 670,
|
||||
'tid' => '5334',
|
||||
'kid' => [2,9,7,1,3], // 售后单号,订单编号,商品名称
|
||||
'scene_desc' => '当售后状态改变时通知用户', // 申请模板场景描述
|
||||
'fields' => [
|
||||
// 'character_string2' => 'aftersale_sn', // 售后单号
|
||||
// 'character_string9' => 'order_sn', // 订单编号
|
||||
// 'thing7' => 'goods_title', // 商品名称
|
||||
// 'phrase1' => 'aftersale_status_text', // 售后状态
|
||||
// 'date3' => 'apply_date', // 申请时间
|
||||
[
|
||||
"name" => "售后单号",
|
||||
"field" => "aftersale_sn",
|
||||
"template_field" => "character_string2",
|
||||
],
|
||||
[
|
||||
"name" => "订单编号",
|
||||
"field" => "order_sn",
|
||||
"template_field" => "character_string9",
|
||||
],
|
||||
[
|
||||
"name" => "商品名称",
|
||||
"field" => "goods_title",
|
||||
"template_field" => "thing7",
|
||||
],
|
||||
[
|
||||
"name" => "售后状态",
|
||||
"field" => "aftersale_status_text",
|
||||
"template_field" => "phrase1",
|
||||
],
|
||||
[
|
||||
"name" => "申请时间",
|
||||
"field" => "apply_date",
|
||||
"template_field" => "date3",
|
||||
],
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
// 返回的字段列表
|
||||
public $returnField = [
|
||||
'name' => '售后结果通知',
|
||||
'channels' => ['Sms', 'Email', 'WechatOfficialAccount', 'WechatMiniProgram'],
|
||||
'fields' => [
|
||||
['name' => '消息名称', 'field' => 'template'],
|
||||
['name' => '售后单ID', 'field' => 'aftersale_id'],
|
||||
['name' => '售后单号', 'field' => 'aftersale_sn'],
|
||||
['name' => '申请时间', 'field' => 'apply_date'],
|
||||
['name' => '订单ID', 'field' => 'order_id'],
|
||||
['name' => '订单号', 'field' => 'order_sn'],
|
||||
['name' => '订单金额', 'field' => 'order_amount'],
|
||||
['name' => '下单时间', 'field' => 'create_date'],
|
||||
['name' => '申请用户', 'field' => 'nickname'],
|
||||
['name' => '用户手机', 'field' => 'mobile'],
|
||||
['name' => '支付金额', 'field' => 'pay_fee'],
|
||||
['name' => '售后类型', 'field' => 'aftersale_type'],
|
||||
['name' => '联系电话', 'field' => 'aftersale_mobile'],
|
||||
['name' => '商品名称', 'field' => 'goods_title'],
|
||||
['name' => '商品规格', 'field' => 'goods_sku_text'],
|
||||
['name' => '商品原价', 'field' => 'goods_original_price'],
|
||||
['name' => '商品价格', 'field' => 'goods_price'],
|
||||
['name' => '购买数量', 'field' => 'goods_num'],
|
||||
['name' => '优惠金额', 'field' => 'discount_fee'],
|
||||
['name' => '售后状态', 'field' => 'aftersale_status_text'],
|
||||
['name' => '退款状态', 'field' => 'refund_status_text'],
|
||||
['name' => '退款金额', 'field' => 'refund_fee'],
|
||||
['name' => '变动内容', 'field' => 'content'],
|
||||
['name' => '处理时间', 'field' => 'oper_date'],
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 组合数据参数
|
||||
*
|
||||
* @param \think\Model $notifiable
|
||||
* @return array
|
||||
*/
|
||||
protected function getData($notifiable)
|
||||
{
|
||||
$aftersale = $this->data['aftersale'];
|
||||
$order = $this->data['order'];
|
||||
$aftersaleLog = $this->data['aftersaleLog'];
|
||||
|
||||
$data['template'] = $this->returnField['name']; // 模板名称
|
||||
$data['aftersale_id'] = $aftersale['id'];
|
||||
$data['aftersale_sn'] = $aftersale['aftersale_sn'];
|
||||
$data['apply_date'] = $aftersale['createtime'];
|
||||
$data['order_id'] = $order['id'];
|
||||
$data['order_sn'] = $order['order_sn'];
|
||||
$data['order_amount'] = '¥' . $order['order_amount'];
|
||||
$data['create_date'] = $order['createtime'];
|
||||
$data['nickname'] = $notifiable['nickname'];
|
||||
$data['mobile'] = $notifiable['mobile'];
|
||||
$data['pay_fee'] = '¥' . $order['pay_fee'];
|
||||
$data['aftersale_type'] = $aftersale['type_text'];
|
||||
$data['aftersale_mobile'] = $aftersale['mobile'];
|
||||
$data['goods_title'] = $aftersale['goods_title'];
|
||||
$data['goods_sku_text'] = $aftersale['goods_sku_text'];
|
||||
$data['goods_original_price'] = '¥' . $aftersale['goods_original_price'];
|
||||
$data['goods_price'] = '¥' . $aftersale['goods_price'];
|
||||
$data['goods_num'] = $aftersale['goods_num'];
|
||||
$data['discount_fee'] = '¥' . $aftersale['discount_fee'];
|
||||
$data['aftersale_status_text'] = $aftersale['aftersale_status_text'];
|
||||
$data['refund_status_text'] = $aftersale['refund_status_text'];
|
||||
if ($aftersale['refund_fee']) {
|
||||
$data['refund_fee'] = '¥' . $aftersale['refund_fee'];
|
||||
} else {
|
||||
$data['refund_fee'] = '暂未退款';
|
||||
}
|
||||
$data['content'] = $aftersaleLog['content'] ? strip_tags($aftersaleLog['content']) : '-';
|
||||
$data['oper_date'] = $aftersaleLog['createtime'];
|
||||
|
||||
// 统一跳转地址
|
||||
$data['jump_url'] = "/pages/order/aftersale/detail?id=" . $aftersale['id'];
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
235
addons/shopro/notification/traits/Notification.php
Normal file
235
addons/shopro/notification/traits/Notification.php
Normal file
@@ -0,0 +1,235 @@
|
||||
<?php
|
||||
|
||||
namespace addons\shopro\notification\traits;
|
||||
|
||||
use app\admin\model\shopro\Config;
|
||||
|
||||
/**
|
||||
* 消息通知,额外方法
|
||||
*/
|
||||
trait Notification
|
||||
{
|
||||
|
||||
public function __construct($data = [])
|
||||
{
|
||||
$this->data = $data;
|
||||
$this->initConfig();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 组合发送参数
|
||||
*
|
||||
* @param \think\Model $notifiable
|
||||
* @param string $type
|
||||
* @param \Closure|null $callback
|
||||
* @return array
|
||||
*/
|
||||
protected function getParams($notifiable, $type, ?\Closure $callback = null)
|
||||
{
|
||||
$params = [];
|
||||
$params['data'] = $this->getData($notifiable);
|
||||
|
||||
if ($callback) {
|
||||
$params = $callback($params);
|
||||
}
|
||||
|
||||
$params = $this->formatParams($params, $type);
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 数据库通知数据
|
||||
*
|
||||
* @param \think\Model $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function toDatabase($notifiable)
|
||||
{
|
||||
$type = str_replace('to', '', __FUNCTION__);
|
||||
$params = $this->getParams($notifiable, $type);
|
||||
$params['message_type'] = 'notification';
|
||||
$params['class_name'] = static::class;
|
||||
$params['message_text'] = $this->strReplace($this->template['MessageDefaultContent'], $params['data']);
|
||||
$params['message_title'] = $this->returnField['name'];
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 短信通知数据
|
||||
*
|
||||
* @param \think\Model $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function toSms($notifiable)
|
||||
{
|
||||
$type = str_replace('to', '', __FUNCTION__);
|
||||
$params = $this->getParams($notifiable, $type, function ($params) use ($notifiable) {
|
||||
$params['mobile'] = $notifiable['mobile'] ? $notifiable['mobile'] : '';
|
||||
$this->template['MessageDefaultContent'] = $this->strReplace($this->template['MessageDefaultContent'], $params['data']);
|
||||
return $params;
|
||||
});
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 邮件通知数据
|
||||
*
|
||||
* @param \think\Model $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function toEmail($notifiable)
|
||||
{
|
||||
$type = str_replace('to', '', __FUNCTION__);
|
||||
|
||||
$params = $this->getParams($notifiable, $type);
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* socket 通知数据
|
||||
*
|
||||
* @param \think\Model $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function toWebsocket($notifiable)
|
||||
{
|
||||
$type = str_replace('to', '', __FUNCTION__);
|
||||
$params = $this->getParams($notifiable, $type);
|
||||
$params['message_type'] = 'notification';
|
||||
$params['class_name'] = static::class;
|
||||
$params['message_text'] = $this->strReplace($this->template['MessageDefaultContent'], $params['data']);
|
||||
$params['message_title'] = $this->returnField['name'];
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 微信公众号通知数据
|
||||
*
|
||||
* @param \think\Model $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function toWechatOfficialAccount($notifiable)
|
||||
{
|
||||
$type = str_replace('to', '', __FUNCTION__);
|
||||
$params = $this->getParams($notifiable, $type, function ($params) use ($notifiable) {
|
||||
if ($oauth = $this->getWxOauth($notifiable, 'WechatOfficialAccount')) {
|
||||
// 公众号跳转地址,订单详情
|
||||
$path = $params['data']['h5_url'] ?? ($params['data']['jump_url'] ?? '');
|
||||
|
||||
// 获取 h5 域名
|
||||
$url = $this->getH5DomainUrl($path);
|
||||
|
||||
$params['openid'] = $oauth->openid;
|
||||
$params['url'] = $url;
|
||||
}
|
||||
|
||||
return $params;
|
||||
});
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 微信小程序通知数据
|
||||
*
|
||||
* @param \think\Model $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function toWechatMiniProgram($notifiable)
|
||||
{
|
||||
$type = str_replace('to', '', __FUNCTION__);
|
||||
$params = $this->getParams($notifiable, $type, function ($params) use ($notifiable) {
|
||||
if ($oauth = $this->getWxOauth($notifiable, 'WechatMiniProgram')) {
|
||||
// 小程序跳转地址,订单详情
|
||||
$path = $params['data']['mini_url'] ?? ($params['data']['jump_url'] ?? '');
|
||||
|
||||
// 获取小程序完整路径
|
||||
$page = $this->getMiniDomainPage($path);
|
||||
|
||||
$params['openid'] = $oauth->openid;
|
||||
$params['page'] = $page;
|
||||
}
|
||||
|
||||
return $params;
|
||||
});
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* 替换字符串中的标识
|
||||
*
|
||||
* @param [type] $content
|
||||
* @param [type] $data
|
||||
* @return void
|
||||
*/
|
||||
protected function strReplace($content, $data)
|
||||
{
|
||||
foreach ($data as $key => $value) {
|
||||
$content = str_replace('{' . $key . '}', (string)$value, $content);
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取微信授权 oauth
|
||||
*/
|
||||
protected function getWxOauth($notifiable, $platform)
|
||||
{
|
||||
if ($this->receiver_type == 'admin') { // 后台管理员绑定的都是公众号,但是在 thirdOauth 中存的是 admin
|
||||
$platform = 'admin';
|
||||
} else {
|
||||
$platform = lcfirst(str_replace('Wechat', '', $platform));
|
||||
}
|
||||
|
||||
$oauth = \app\admin\model\shopro\ThirdOauth::where($this->receiver_type . '_id', $notifiable['id'])
|
||||
->where('provider', 'Wechat')
|
||||
->where('platform', $platform)->find();
|
||||
|
||||
if ($oauth && $oauth->openid) {
|
||||
return $oauth;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取拼接域名的地址
|
||||
*/
|
||||
protected function getH5DomainUrl($path)
|
||||
{
|
||||
$url = $path;
|
||||
$domain = Config::getConfigField('shop.basic.domain');
|
||||
if ($domain) {
|
||||
$domain = rtrim($domain, '/');
|
||||
$url = $domain . "/?page=" . urlencode($path);
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取拼接的小程序地址
|
||||
*/
|
||||
protected function getMiniDomainPage($path)
|
||||
{
|
||||
return "pages/index/index?page=" . urlencode($path);
|
||||
}
|
||||
}
|
||||
156
addons/shopro/notification/wallet/CommissionChange.php
Normal file
156
addons/shopro/notification/wallet/CommissionChange.php
Normal file
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
|
||||
namespace addons\shopro\notification\wallet;
|
||||
|
||||
use addons\shopro\notification\Notification;
|
||||
use addons\shopro\notification\traits\Notification as NotificationTrait;
|
||||
|
||||
/**
|
||||
* 佣金变动通知
|
||||
*/
|
||||
class CommissionChange extends Notification
|
||||
{
|
||||
use NotificationTrait;
|
||||
|
||||
// 队列延迟时间,必须继承 ShouldQueue 接口
|
||||
public $delay = 0;
|
||||
|
||||
public $receiver_type = 'user'; // 接收人:user=用户
|
||||
|
||||
// 消息类型 Notification::$notificationType
|
||||
public $notification_type = 'shop';
|
||||
|
||||
// 发送类型
|
||||
public $event = 'commission_change';
|
||||
|
||||
// 额外数据
|
||||
public $data = [];
|
||||
|
||||
public $template = [
|
||||
'MessageDefaultContent' => '您的佣金发生变化,变动类型:{event_name},变动金额:{amount},请及时查看',
|
||||
// 'WechatOfficialAccount' => [
|
||||
// 'temp_no' => 'OPENTM415437052',
|
||||
// 'fields' => [
|
||||
// // 'first' => '您的佣金发生变动,请及时查看',
|
||||
// // 'keyword1' => 'event_name', // 交易类型
|
||||
// // 'keyword2' => 'amount', // 交易金额
|
||||
// // 'keyword3' => 'create_date', // 交易时间
|
||||
// // 'keyword4' => 'commission', // 账户余额
|
||||
// // 'remark' => '您的佣金发生变动,请及时查看',
|
||||
// [
|
||||
// "template_field" => "first",
|
||||
// "value" => '您的佣金发生变动,请及时查看',
|
||||
// ],
|
||||
// [
|
||||
// "name" => "交易类型",
|
||||
// "field" => "event_name",
|
||||
// "template_field" => "keyword1",
|
||||
// ],
|
||||
// [
|
||||
// "name" => "交易金额",
|
||||
// "field" => "amount",
|
||||
// "template_field" => "keyword2",
|
||||
// ],
|
||||
// [
|
||||
// "name" => "交易时间",
|
||||
// "field" => "create_date",
|
||||
// "template_field" => "keyword3",
|
||||
// ],
|
||||
// [
|
||||
// "name" => "账户余额",
|
||||
// "field" => "commission",
|
||||
// "template_field" => "keyword4",
|
||||
// ],
|
||||
// [
|
||||
// "template_field" => "remark",
|
||||
// "value" => '您的佣金发生变动,请及时查看',
|
||||
// ]
|
||||
// ],
|
||||
// ],
|
||||
'WechatOfficialAccount' => [
|
||||
'temp_no' => false, // 目前公众号类目模板库,找不到符合条件模板
|
||||
'keywords' => [],
|
||||
'fields' => [],
|
||||
],
|
||||
'WechatMiniProgram' => [
|
||||
'category_id' => 670,
|
||||
'tid' => '4221',
|
||||
'kid' => [1,2,4,5], // 类型,金额,时间,备注
|
||||
'scene_desc' => '当佣金发生改变时通知用户', // 申请模板场景描述
|
||||
'fields' => [
|
||||
// 'phrase1' => 'event_name', // 类型
|
||||
// 'amount2' => 'amount', // 金额
|
||||
// 'time4' => 'create_date', // 时间
|
||||
// 'thing5' => 'memo', // 备注
|
||||
[
|
||||
"name" => "类型",
|
||||
"field" => "event_name",
|
||||
"template_field" => "phrase1",
|
||||
],
|
||||
[
|
||||
"name" => "金额",
|
||||
"field" => "amount",
|
||||
"template_field" => "amount2",
|
||||
],
|
||||
[
|
||||
"name" => "时间",
|
||||
"field" => "create_date",
|
||||
"template_field" => "time4",
|
||||
],
|
||||
[
|
||||
"name" => "备注",
|
||||
"field" => "memo",
|
||||
"template_field" => "thing5",
|
||||
],
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
// 返回的字段列表
|
||||
public $returnField = [
|
||||
'name' => '佣金变动通知',
|
||||
'channels' => ['Sms', 'Email', 'WechatOfficialAccount', 'WechatMiniProgram'],
|
||||
'fields' => [
|
||||
['name' => '消息名称', 'field' => 'template'],
|
||||
['name' => '变动用户', 'field' => 'nickname'],
|
||||
['name' => '用户手机', 'field' => 'mobile'],
|
||||
['name' => '变动类型', 'field' => 'event_name'],
|
||||
['name' => '变动数量', 'field' => 'amount'],
|
||||
['name' => '变动前', 'field' => 'before'],
|
||||
['name' => '变动后', 'field' => 'after'],
|
||||
['name' => '当前佣金', 'field' => 'commission'],
|
||||
['name' => '备注信息', 'field' => 'memo'],
|
||||
['name' => '变动时间', 'field' => 'create_date'],
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 组合数据参数
|
||||
*
|
||||
* @param \think\Model $notifiable
|
||||
* @return array
|
||||
*/
|
||||
protected function getData($notifiable)
|
||||
{
|
||||
$walletLog = $this->data['walletLog'];
|
||||
$type = $this->data['type'];
|
||||
|
||||
$data['template'] = $this->returnField['name']; // 模板名称
|
||||
$data['nickname'] = $notifiable['nickname'];
|
||||
$data['mobile'] = $notifiable['mobile'];
|
||||
$data['event_name'] = '佣金变动';
|
||||
$data['amount'] = '¥' . $walletLog['amount'];
|
||||
$data['before'] = '¥' . $walletLog['before'];
|
||||
$data['after'] = '¥' . $walletLog['after'];
|
||||
$data['commission'] = '¥' . $walletLog['after'];
|
||||
$data['memo'] = $walletLog['event_text'] . ($walletLog['memo'] ? ('-' . $walletLog['memo']) : '');
|
||||
$data['create_date'] = $walletLog['createtime'];
|
||||
|
||||
// 统一跳转地址
|
||||
$data['jump_url'] = "/pages/user/wallet/commission";
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
162
addons/shopro/notification/wallet/MoneyChange.php
Normal file
162
addons/shopro/notification/wallet/MoneyChange.php
Normal file
@@ -0,0 +1,162 @@
|
||||
<?php
|
||||
|
||||
namespace addons\shopro\notification\wallet;
|
||||
|
||||
use addons\shopro\notification\Notification;
|
||||
use addons\shopro\notification\traits\Notification as NotificationTrait;
|
||||
|
||||
/**
|
||||
* 余额变动通知
|
||||
*/
|
||||
class MoneyChange extends Notification
|
||||
{
|
||||
use NotificationTrait;
|
||||
|
||||
// 队列延迟时间,必须继承 ShouldQueue 接口
|
||||
public $delay = 0;
|
||||
|
||||
public $receiver_type = 'user'; // 接收人:user=用户
|
||||
|
||||
// 消息类型 Notification::$notificationType
|
||||
public $notification_type = 'shop';
|
||||
|
||||
// 发送类型
|
||||
public $event = 'money_change';
|
||||
|
||||
// 额外数据
|
||||
public $data = [];
|
||||
|
||||
public $template = [
|
||||
'MessageDefaultContent' => '您的余额发生变化,变动类型:{event_name},变动金额:{amount},请及时查看',
|
||||
// 'WechatOfficialAccount' => [
|
||||
// 'temp_no' => 'OPENTM401833445',
|
||||
// 'fields' => [
|
||||
// // 'first' => '您的余额发生变动,请及时查看',
|
||||
// // 'keyword1' => 'create_date', // 变动时间
|
||||
// // 'keyword2' => 'event_name', // 变动类型
|
||||
// // 'keyword3' => 'amount', // 变动金额
|
||||
// // 'keyword4' => 'money', // 当前余额
|
||||
// // 'remark' => '您的余额发生变动,请及时查看',
|
||||
// [
|
||||
// "template_field" => "first",
|
||||
// "value" => '您的余额发生变动,请及时查看',
|
||||
// ],
|
||||
// [
|
||||
// "name" => "变动时间",
|
||||
// "field" => "create_date",
|
||||
// "template_field" => "keyword1",
|
||||
// ],
|
||||
// [
|
||||
// "name" => "变动类型",
|
||||
// "field" => "event_name",
|
||||
// "template_field" => "keyword2",
|
||||
// ],
|
||||
// [
|
||||
// "name" => "变动金额",
|
||||
// "field" => "amount",
|
||||
// "template_field" => "keyword3",
|
||||
// ],
|
||||
// [
|
||||
// "name" => "当前余额",
|
||||
// "field" => "money",
|
||||
// "template_field" => "keyword4",
|
||||
// ],
|
||||
// [
|
||||
// "template_field" => "remark",
|
||||
// "value" => '您的余额发生变动,请及时查看',
|
||||
// ]
|
||||
// ],
|
||||
// ],
|
||||
'WechatOfficialAccount' => [
|
||||
'temp_no' => false, // 目前公众号类目模板库,找不到符合条件模板
|
||||
'keywords' => [],
|
||||
'fields' => [],
|
||||
],
|
||||
'WechatMiniProgram' => [
|
||||
'category_id' => 670,
|
||||
'tid' => '4148',
|
||||
'kid' => [8,1,2,4,5], // 变动类型,变动金额,账户余额,时间,备注
|
||||
'scene_desc' => '当余额发生变化时通知用户', // 申请模板场景描述
|
||||
'fields' => [
|
||||
// 'thing8' => 'event_name', // 变动类型
|
||||
// 'amount1' => 'amount', // 变动金额
|
||||
// 'amount2' => 'money', // 账户余额
|
||||
// 'date' => 'create_date', // 时间
|
||||
// 'thing5' => 'memo', // 备注
|
||||
[
|
||||
"name" => "变动类型",
|
||||
"field" => "event_name",
|
||||
"template_field" => "thing8",
|
||||
],
|
||||
[
|
||||
"name" => "变动金额",
|
||||
"field" => "amount",
|
||||
"template_field" => "amount1",
|
||||
],
|
||||
[
|
||||
"name" => "账户余额",
|
||||
"field" => "money",
|
||||
"template_field" => "amount2",
|
||||
],
|
||||
[
|
||||
"name" => "时间",
|
||||
"field" => "create_date",
|
||||
"template_field" => "date4",
|
||||
],
|
||||
[
|
||||
"name" => "备注",
|
||||
"field" => "memo",
|
||||
"template_field" => "thing5",
|
||||
],
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
// 返回的字段列表
|
||||
public $returnField = [
|
||||
'name' => '余额变动通知',
|
||||
'channels' => ['Sms', 'Email', 'WechatOfficialAccount', 'WechatMiniProgram'],
|
||||
'fields' => [
|
||||
['name' => '消息名称', 'field' => 'template'],
|
||||
['name' => '变动用户', 'field' => 'nickname'],
|
||||
['name' => '用户手机', 'field' => 'mobile'],
|
||||
['name' => '变动类型', 'field' => 'event_name'],
|
||||
['name' => '变动金额', 'field' => 'amount'],
|
||||
['name' => '变动前', 'field' => 'before'],
|
||||
['name' => '变动后', 'field' => 'after'],
|
||||
['name' => '当前余额', 'field' => 'money'],
|
||||
['name' => '备注信息', 'field' => 'memo'],
|
||||
['name' => '变动时间', 'field' => 'create_date'],
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 组合数据参数
|
||||
*
|
||||
* @param \think\Model $notifiable
|
||||
* @return array
|
||||
*/
|
||||
protected function getData($notifiable)
|
||||
{
|
||||
$walletLog = $this->data['walletLog'];
|
||||
$type = $this->data['type'];
|
||||
|
||||
$data['template'] = $this->returnField['name']; // 模板名称
|
||||
$data['nickname'] = $notifiable['nickname'];
|
||||
$data['mobile'] = $notifiable['mobile'];
|
||||
$data['event_name'] = '余额变动';
|
||||
$data['amount'] = '¥' . $walletLog['amount'];
|
||||
$data['before'] = '¥' . $walletLog['before'];
|
||||
$data['after'] = '¥' . $walletLog['after'];
|
||||
$data['money'] = '¥' . $walletLog['after'];
|
||||
$data['memo'] = $walletLog['event_text'] . ($walletLog['memo'] ? ('-' . $walletLog['memo']) : '');
|
||||
$data['create_date'] = $walletLog['createtime'];
|
||||
|
||||
// 统一跳转地址
|
||||
$data['jump_url'] = "/pages/user/wallet/money";
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
156
addons/shopro/notification/wallet/ScoreChange.php
Normal file
156
addons/shopro/notification/wallet/ScoreChange.php
Normal file
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
|
||||
namespace addons\shopro\notification\wallet;
|
||||
|
||||
use addons\shopro\notification\Notification;
|
||||
use addons\shopro\notification\traits\Notification as NotificationTrait;
|
||||
|
||||
/**
|
||||
* 积分变动通知
|
||||
*/
|
||||
class ScoreChange extends Notification
|
||||
{
|
||||
use NotificationTrait;
|
||||
|
||||
// 队列延迟时间,必须继承 ShouldQueue 接口
|
||||
public $delay = 0;
|
||||
|
||||
public $receiver_type = 'user'; // 接收人:user=用户
|
||||
|
||||
// 消息类型 Notification::$notificationType
|
||||
public $notification_type = 'shop';
|
||||
|
||||
// 发送类型
|
||||
public $event = 'score_change';
|
||||
|
||||
// 额外数据
|
||||
public $data = [];
|
||||
|
||||
public $template = [
|
||||
'MessageDefaultContent' => '您的积分发生变化,变动类型:{event_name},变动数量:{amount},请及时查看',
|
||||
// 'WechatOfficialAccount' => [
|
||||
// 'temp_no' => 'OPENTM415437052',
|
||||
// 'fields' => [
|
||||
// // 'first' => '您的积分发生变动,请及时查看',
|
||||
// // 'keyword1' => 'event_name', // 交易类型
|
||||
// // 'keyword2' => 'amount', // 交易金额
|
||||
// // 'keyword3' => 'create_date', // 交易时间
|
||||
// // 'keyword4' => 'score', // 账户余额
|
||||
// // 'remark' => '您的积分发生变动,请及时查看',
|
||||
// [
|
||||
// "template_field" => "first",
|
||||
// "value" => '您的积分发生变动,请及时查看',
|
||||
// ],
|
||||
// [
|
||||
// "name" => "交易类型",
|
||||
// "field" => "event_name",
|
||||
// "template_field" => "keyword1",
|
||||
// ],
|
||||
// [
|
||||
// "name" => "交易金额",
|
||||
// "field" => "amount",
|
||||
// "template_field" => "keyword2",
|
||||
// ],
|
||||
// [
|
||||
// "name" => "交易时间",
|
||||
// "field" => "create_date",
|
||||
// "template_field" => "keyword3",
|
||||
// ],
|
||||
// [
|
||||
// "name" => "账户余额",
|
||||
// "field" => "score",
|
||||
// "template_field" => "keyword4",
|
||||
// ],
|
||||
// [
|
||||
// "template_field" => "remark",
|
||||
// "value" => '您的积分发生变动,请及时查看',
|
||||
// ]
|
||||
// ],
|
||||
// ],
|
||||
'WechatOfficialAccount' => [
|
||||
'temp_no' => false, // 目前公众号类目模板库,找不到符合条件模板
|
||||
'keywords' => [],
|
||||
'fields' => [],
|
||||
],
|
||||
'WechatMiniProgram' => [
|
||||
'category_id' => 670,
|
||||
'tid' => '3613',
|
||||
'kid' => [8,15,6,7], // 变动原因,积分变动,积分总额,变动时间
|
||||
'scene_desc' => '当积分发生变化时通知用户', // 申请模板场景描述
|
||||
'fields' => [
|
||||
// 'thing8' => 'event_name', // 变动原因
|
||||
// 'number1' => 'amount', // 积分变动
|
||||
// 'number6' => 'score', // 积分总额
|
||||
// 'time7' => 'create_date', // 变动时间
|
||||
[
|
||||
"name" => "变动原因",
|
||||
"field" => "event_name",
|
||||
"template_field" => "thing8",
|
||||
],
|
||||
[
|
||||
"name" => "积分变动值",
|
||||
"field" => "amount",
|
||||
"template_field" => "character_string15",
|
||||
],
|
||||
[
|
||||
"name" => "积分总额",
|
||||
"field" => "score",
|
||||
"template_field" => "number6",
|
||||
],
|
||||
[
|
||||
"name" => "变动时间",
|
||||
"field" => "create_date",
|
||||
"template_field" => "time7",
|
||||
],
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
// 返回的字段列表
|
||||
public $returnField = [
|
||||
'name' => '积分变动通知',
|
||||
'channels' => ['Sms', 'Email', 'WechatOfficialAccount', 'WechatMiniProgram'],
|
||||
'fields' => [
|
||||
['name' => '消息名称', 'field' => 'template'],
|
||||
['name' => '变动用户', 'field' => 'nickname'],
|
||||
['name' => '用户手机', 'field' => 'mobile'],
|
||||
['name' => '变动类型', 'field' => 'event_name'],
|
||||
['name' => '变动数量', 'field' => 'amount'],
|
||||
['name' => '变动前', 'field' => 'before'],
|
||||
['name' => '变动后', 'field' => 'after'],
|
||||
['name' => '当前积分', 'field' => 'score'],
|
||||
['name' => '备注信息', 'field' => 'memo'],
|
||||
['name' => '变动时间', 'field' => 'create_date'],
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 组合数据参数
|
||||
*
|
||||
* @param \think\Model $notifiable
|
||||
* @return array
|
||||
*/
|
||||
protected function getData($notifiable)
|
||||
{
|
||||
$walletLog = $this->data['walletLog'];
|
||||
$type = $this->data['type'];
|
||||
|
||||
$data['template'] = $this->returnField['name']; // 模板名称
|
||||
$data['nickname'] = $notifiable['nickname'];
|
||||
$data['mobile'] = $notifiable['mobile'];
|
||||
$data['event_name'] = '积分变动';
|
||||
$data['amount'] = $walletLog['amount'];
|
||||
$data['before'] = $walletLog['before'];
|
||||
$data['after'] = $walletLog['after'];
|
||||
$data['score'] = $walletLog['after'];
|
||||
$data['memo'] = $walletLog['event_text'] . ($walletLog['memo'] ? ('-' . $walletLog['memo']) : '');
|
||||
$data['create_date'] = $walletLog['createtime'];
|
||||
|
||||
// 统一跳转地址
|
||||
$data['jump_url'] = "/pages/user/wallet/score";
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user