mirror of
https://github.com/crmeb/CRMEB.git
synced 2026-10-28 13:31:04 +00:00
fix(余额通知): 变动类型改为中文标题,避免模板与金额重复展示
通过 UserMoneyServices 映射 type 标识为中文,未命中时回退「余额变动」。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
315541d558
commit
2cb4c258cd
@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
namespace app\listener\user;
|
||||
|
||||
use app\services\message\Notice;
|
||||
use app\services\user\UserMoneyServices;
|
||||
|
||||
/**
|
||||
* 用户余额变更通知监听器
|
||||
@ -19,11 +20,19 @@ class UserBalanceChangeNoticeListener
|
||||
$uid = (int)$uid;
|
||||
if (!$uid) return;
|
||||
|
||||
// type 落库值为英文标识(如 pay_product_refund),站内信模板 {type} 需展示中文标题
|
||||
$typeCode = trim(is_string($type) ? $type : (string)$type);
|
||||
$typeTitle = app()->make(UserMoneyServices::class)->getTypeTitle($typeCode);
|
||||
// 未命中映射时不要回退到含金额的 mark,否则会与模板中的 {extract_number} 重复
|
||||
if ($typeTitle === '' || $typeTitle === $typeCode) {
|
||||
$typeTitle = '余额变动';
|
||||
}
|
||||
|
||||
// 场景:余额充值、提现、退款回账等引起账户余额变动时,通知用户
|
||||
// 扁平业务数据:各渠道模板直接用业务变量名,新增渠道无需改监听器
|
||||
Notice::to($uid)->sendMsg('user_balance_change', '余额变更', [
|
||||
'extract_number' => (string)($number ?: 0), // 变动金额(正为增加,负为扣减)
|
||||
'type' => $type, // 变动类型(如提现、退款回账)
|
||||
'type' => $typeTitle, // 变动类型中文(如商品退款)
|
||||
'mark' => $mark, // 变动备注标识
|
||||
'link' => '/pages/users/user_bill/index', // 账单明细页链接
|
||||
]);
|
||||
|
||||
@ -129,6 +129,45 @@ class UserMoneyServices extends BaseService
|
||||
{
|
||||
$this->dao = $dao;
|
||||
}
|
||||
|
||||
/**
|
||||
* 余额流水类型 → 中文标题(按 incomeData 的 type 字段匹配,兼容按配置键查找)
|
||||
* @param string $type
|
||||
* @return string
|
||||
*/
|
||||
public function getTypeTitle(string $type): string
|
||||
{
|
||||
$type = trim($type);
|
||||
if ($type === '') {
|
||||
return '';
|
||||
}
|
||||
foreach ($this->incomeData as $key => $item) {
|
||||
if (($item['type'] ?? '') === $type || (string)$key === $type) {
|
||||
return (string)($item['title'] ?? $type);
|
||||
}
|
||||
}
|
||||
return $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* 全部余额类型中文映射(type => title)
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function getTypeTitleMap(): array
|
||||
{
|
||||
$map = [];
|
||||
foreach ($this->incomeData as $key => $item) {
|
||||
$title = (string)($item['title'] ?? '');
|
||||
if ($title === '') {
|
||||
continue;
|
||||
}
|
||||
$map[(string)$key] = $title;
|
||||
if (!empty($item['type'])) {
|
||||
$map[(string)$item['type']] = $title;
|
||||
}
|
||||
}
|
||||
return $map;
|
||||
}
|
||||
/**
|
||||
* 写入用户记录
|
||||
* @param string $type 写入类型
|
||||
|
||||
@ -2,7 +2,7 @@ INSERT INTO `eb_notice_config` (`id`, `mark`, `owner_plugin_id`, `name`, `title`
|
||||
(32, 'verify_code', 'core', '短信验证码', '注册、登录等验证手机号时发送验证码', 1, '{code}验证码,{time}有效时间(分钟)', 0),
|
||||
(33, 'bind_spread_uid', 'core', '绑定推广关系通知', '新用户绑定上下级后提醒推广人', 1, '{nickname}新用户昵称,{uid}新用户ID,{spread_uid}推广人UID,{spread_time}绑定时间,{user_type}用户来源', 0),
|
||||
(34, 'order_pay_false', 'core', '未支付订单提醒', '订单创建后超时未支付提醒用户', 1, '{order_id}订单号,{pay_price}支付金额,{link}订单链接', 0),
|
||||
(35, 'user_balance_change', 'core', '余额变更', '账户余额变动后通知用户', 1, '{extract_number}变动金额,{type}变动类型,{mark}变动备注,{link}账单链接', 0),
|
||||
(35, 'user_balance_change', 'core', '余额变更', '账户余额变动后通知用户', 1, '{extract_number}变动金额,{type}变动类型中文标题,{mark}变动备注,{link}账单链接', 0),
|
||||
(36, 'revenue_received', 'core', '收益通知', '收益到账后通知用户', 1, '{amount}收益金额,{order_id}关联订单号,{type}收益说明,{link}账单链接', 0),
|
||||
(37, 'user_integral_change', 'core', '积分变更', '积分变动后通知用户', 1, '{give_integral}变动积分,{integral}剩余积分,{order_id}关联订单号,{store_title}来源,{link}详情链接', 0),
|
||||
(38, 'order_create', 'module:product:normal', '下单成功', '订单提交后提醒用户付款', 1, '{order_id}订单号,{pay_price}应付金额,{store_name}商品,{user_phone}联系电话', 0),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user