diff --git a/backend/app/listener/user/UserBalanceChangeNoticeListener.php b/backend/app/listener/user/UserBalanceChangeNoticeListener.php index 530d8652d..d1558ba1c 100644 --- a/backend/app/listener/user/UserBalanceChangeNoticeListener.php +++ b/backend/app/listener/user/UserBalanceChangeNoticeListener.php @@ -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', // 账单明细页链接 ]); diff --git a/backend/app/services/user/UserMoneyServices.php b/backend/app/services/user/UserMoneyServices.php index 8c7d9bb6a..2c6bc905b 100644 --- a/backend/app/services/user/UserMoneyServices.php +++ b/backend/app/services/user/UserMoneyServices.php @@ -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 + */ + 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 写入类型 diff --git a/backend/public/install/data/notice_config_data.sql b/backend/public/install/data/notice_config_data.sql index fdc362ead..a51d41add 100755 --- a/backend/public/install/data/notice_config_data.sql +++ b/backend/public/install/data/notice_config_data.sql @@ -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),