diff --git a/app/command/ApplySmsTemp.php b/app/command/ApplySmsTemp.php index c718c37..40c263d 100644 --- a/app/command/ApplySmsTemp.php +++ b/app/command/ApplySmsTemp.php @@ -41,7 +41,7 @@ class ApplySmsTemp extends Command $str = '亲爱的${用户昵称}您好,${店铺名称}祝您生日快乐!感谢您一直的陪伴。为您准备了${数量}张超值优惠券,已放入账户,愿我们的礼物能为您增添一份喜悦。拒收请回复R'; $templateContent_arr = ShopInfo::handleSmsTemplates($str); $a = '{"店铺名称":"火锅店","用户昵称":"嘿嘿","数量":"123"}'; - p(replace_json_keys($a, json_encode($templateContent_arr, 256))); + p(replace_json_keys($a, json_encode($templateContent_arr, 256), [])); $t_str = replace_placeholder_keys($str, $templateContent_arr); p($templateContent_arr, $t_str); diff --git a/app/functions.php b/app/functions.php index a3e932f..589b85f 100644 --- a/app/functions.php +++ b/app/functions.php @@ -155,7 +155,7 @@ if (!function_exists('replace_placeholder_keys')) { if (!function_exists('replace_json_keys')) { - function replace_json_keys($originalJson, $mapJson) + function replace_json_keys($originalJson, $mapJson, $user) { $originalData = json_decode($originalJson, true); $mapData = json_decode($mapJson, true); @@ -168,6 +168,9 @@ if (!function_exists('replace_json_keys')) { // 如果原始键在映射中存在,则替换为对应的新键;否则保留原键 $newKey = $reverseMap[$oldKey] ?? $oldKey; $newData[$newKey] = $value; + if($newKey == 'username') { + $newData[$newKey] = $user['nick_name']; + } } $newJson = json_encode($newData, JSON_UNESCAPED_UNICODE); return $newJson; diff --git a/app/model/ShopInfo.php b/app/model/ShopInfo.php index 258afb9..c951756 100644 --- a/app/model/ShopInfo.php +++ b/app/model/ShopInfo.php @@ -92,7 +92,7 @@ class ShopInfo $push_user[] = [ 'user_id' => $user['id'], 'phone' => $user['phone'], - 'nickName' => $user['nickName'], + 'nick_name' => $user['nickName'], ]; } return $push_user; diff --git a/app/queue/redis/BirthdayGiftSms.php b/app/queue/redis/BirthdayGiftSms.php index 8e8bebd..907d29c 100644 --- a/app/queue/redis/BirthdayGiftSms.php +++ b/app/queue/redis/BirthdayGiftSms.php @@ -23,15 +23,18 @@ class BirthdayGiftSms implements Consumer // 待发送 if($record['push_status'] == 'wait_push') { $user = Db::table('tb_shop_user')->where(['id' => $record['user_id']])->find(); + // 张松 需要加主模版ID + $y_temp = Db::table('sms_shop_template')->where(['id' => $record['push_event_id']])->find(); if($user && !empty($user['phone'])) { // 检测余额 $shop_money = Db::table('sms_shop_money')->where(['shop_id' => $record['main_shop_id']])->find(); if($shop_money) { // 余额计算 if($shop_money['money'] > config('cons.sms_price')) { + $templateParam = replace_json_keys($record['template_content'], $y_temp['content_json'], $user); $data = [ 'templateCode' => $record['template_code'], - 'templateParam' => $record['template_content'], + 'templateParam' => $templateParam, 'phoneNumbers' => $user['phone'], 'signName' => config('cons.sms_sign'), ]; diff --git a/app/queue/redis/SendMarkSms.php b/app/queue/redis/SendMarkSms.php index cad3e52..b48215f 100644 --- a/app/queue/redis/SendMarkSms.php +++ b/app/queue/redis/SendMarkSms.php @@ -48,7 +48,7 @@ class SendMarkSms implements Consumer if($shop_money['money'] > config('cons.sms_price')) { $templateParam = replace_json_keys($record['json'], $y_temp['content_json']); $data = [ - 'templateCode' => $record['template_code'], + 'templateCode' => $y_temp['template_code'], 'templateParam' => $templateParam, 'phoneNumbers' => $user_list['phone'], 'signName' => config('cons.sms_sign'),