This commit is contained in:
ASUS 2025-10-17 15:39:51 +08:00
parent 67d912fe49
commit 70be9f3275
5 changed files with 41 additions and 12 deletions

View File

@ -2,16 +2,11 @@
namespace app\command;
use app\common\model\MqLog;
use app\common\model\OrderInfo;
use app\common\model\RabbitMqConfig;
use app\model\ShopInfo;
use ba\Random;
use PhpAmqpLib\Connection\AMQPStreamConnection;
use support\think\Db;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;
use support\Log;
@ -38,6 +33,12 @@ class ApplySmsTemp extends Command
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
// $user['nick_name'] = 1;
// $a = saveJson_arr('{"时间":"15:39","用户昵称":"某某某"}', '{"username":"用户昵称","time":"时间"}', $user);
// p($a);
//
//
// $str = '亲爱的${用户昵称}您好,${店铺名称}祝您生日快乐!感谢您一直的陪伴。为您准备了${数量}张超值优惠券已放入账户愿我们的礼物能为您增添一份喜悦。拒收请回复R';
// $templateContent_arr = ShopInfo::handleSmsTemplates($str);
// $a = '{"店铺名称":"火锅店","用户昵称":"嘿嘿","数量":"123"}';
@ -80,7 +81,8 @@ class ApplySmsTemp extends Command
$type = $arr[2];
if($type == 'applySmsTemp') {
// 发给队列 短信模版审核
Redis::send('apply.sms.temp', $data);
$a = Redis::send('apply.sms.temp', $data);
Log::info('消息队列投递结果----》' . $a);
}elseif ($type == 'sendMarkSms') {
// 发给队列 营销短信发送
Redis::send('send.mark.sms', $data);

View File

@ -136,6 +136,32 @@ if (!function_exists('handldollerstr')) {
}
}
// 处理${}字符串
if (!function_exists('saveJson_arr')) {
function saveJson_arr($th_json, $cont_json, $user)
{
$th_json_arr = json_decode($th_json, true);
$cont_json_arr = json_decode($cont_json, true);
$new_arr = [];
foreach ($th_json_arr as $k => $v) {
foreach ($cont_json_arr as $k1 => $v1) {
if($k == $v1) {
if($k1 == 'username') {
$new_arr[$k1] = $user['nick_name'];
}else {
$new_arr[$k1] = $v;
}
}
}
}
return $new_arr;
}
}
if (!function_exists('replace_placeholder_keys')) {
function replace_placeholder_keys($str, $replaceArray)
{

View File

@ -23,7 +23,7 @@ class ApplySmsTemp implements Consumer
$shop_template_id = $arr[1];
}else {
Log::info('apply.sms.temp数据格式错误');
return false;
return true;
}
try {
// 查询没有提交审核的模版
@ -63,6 +63,7 @@ class ApplySmsTemp implements Consumer
'status' => $status,
'template_code' => $template_code,
'content_json' => $templateContent_json,
'reple_json' => json_encode($templateContent_arr),
'fail_msg' => $fail_msg,
'order_id' => $order_id,
'update_time' => date('Y-m-d H:i:s'),
@ -89,6 +90,7 @@ class ApplySmsTemp implements Consumer
$update_data = [
'status' => $status,
'content_json' => $templateContent_json,
'reple_json' => json_encode($templateContent_arr),
'fail_msg' => $fail_msg,
'update_time' => date('Y-m-d H:i:s'),
];

View File

@ -38,7 +38,7 @@ class BirthdayGiftSms implements Consumer
if($shop_money) {
// 余额计算
if($shop_money['money'] > $sms_price) {
$templateParam = replace_json_keys($record['template_content'], $y_temp['content_json'], $user);
$templateParam = saveJson_arr($record['template_content'], $y_temp['reple_json'], $user);
$data = [
'templateCode' => $record['template_code'],
'templateParam' => $templateParam,

View File

@ -39,7 +39,6 @@ class SendMarkSms implements Consumer
$sms_price = $sms_price[0];
}
if($data) {
Log::info('$data');
// 发送任务
// $record = Db::table('sms_push_event')->where(['id' => $sms_push_event_id, 'push_type' => 2])->find();
$record = Db::table('sms_push_event')->where(['id' => $sms_push_event_id])->find();
@ -48,8 +47,8 @@ class SendMarkSms implements Consumer
if($record['send_type'] == 2 && $record['send_time'] > date('Y-m-d H:i:s')) {
// 推给redis
$stortime = strtotime($record['send_time']);
Redis::setEx('expired:sms:'.$record['id'], $stortime - time(), 1);
Log::info($record . ' 定时发送已存入redis, 过期时间->>>' .$record['send_time'] . '/' . $stortime - time());
$a = Redis::setEx('expired:sms:'.$record['id'], $stortime - time(), 1);
Log::info(' 定时发送已存入redis, 过期时间->>>' .$record['send_time'] . '/' . $stortime - time() . '保存结果' . $a);
}else {
// 待发送
if($record['status'] == 0) {
@ -82,7 +81,7 @@ class SendMarkSms implements Consumer
if($shop_money) {
// 余额计算
if($shop_money['money'] > $sms_price) {
$templateParam = replace_json_keys($record['json'], $y_temp['content_json'], $v);
$templateParam = saveJson_arr($record['json'], $y_temp['reple_json'], $v);
$data = [
'templateCode' => $y_temp['template_code'],
'templateParam' => $templateParam,