日志修改

This commit is contained in:
2025-10-16 15:00:42 +08:00
parent c26095df31
commit e5015f1981
7 changed files with 161 additions and 99 deletions

View File

@@ -38,12 +38,12 @@ class ApplySmsTemp extends Command
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$str = '亲爱的${用户昵称}您好,${店铺名称}祝您生日快乐!感谢您一直的陪伴。为您准备了${数量}张超值优惠券已放入账户愿我们的礼物能为您增添一份喜悦。拒收请回复R';
$templateContent_arr = ShopInfo::handleSmsTemplates($str);
$a = '{"店铺名称":"火锅店","用户昵称":"嘿嘿","数量":"123"}';
p(replace_json_keys($a, json_encode($templateContent_arr, 256), []));
$t_str = replace_placeholder_keys($str, $templateContent_arr);
p($templateContent_arr, $t_str);
// $str = '亲爱的${用户昵称}您好,${店铺名称}祝您生日快乐!感谢您一直的陪伴。为您准备了${数量}张超值优惠券已放入账户愿我们的礼物能为您增添一份喜悦。拒收请回复R';
// $templateContent_arr = ShopInfo::handleSmsTemplates($str);
// $a = '{"店铺名称":"火锅店","用户昵称":"嘿嘿","数量":"123"}';
// p(replace_json_keys($a, json_encode($templateContent_arr, 256), []));
// $t_str = replace_placeholder_keys($str, $templateContent_arr);
// p($templateContent_arr, $t_str);
$host = RabbitMqConfig::$host;

View File

@@ -37,7 +37,7 @@ class QuerySmsStatus extends Command
protected function execute(InputInterface $input, OutputInterface $output): int
{
// 生日有礼
$bir_list = Db::table('mk_birthday_gift_record')->where(['status' => 'await_push'])->select()->toArray();
$bir_list = Db::table('mk_birthday_gift_record')->where(['push_status' => 'await_push'])->select()->toArray();
if($bir_list) {
Log::info('生日有礼短信发送状态查询开始->' . json_encode($bir_list));
foreach ($bir_list as $k => $value) {
@@ -86,21 +86,22 @@ class QuerySmsStatus extends Command
Log::info('营销短信发送状态查询开始->' . json_encode($bir_list));
foreach ($bir_list as $k => $value) {
$data = [
'PhoneNumber' => $value['user_phone'],
'BizId' => $value['biz_id'],
'SendDate' => date('Ymd'),
'PageSize' => 1,
'CurrentPage' => 20,
'bizId' => $value['biz_id'],
'phoneNumber' => $value['user_phone'],
'sendDate' => date('Ymd'),
'pageSize' => 10,
'currentPage' => 1,
];
Log::info('12312312312312' . json_encode($data));
$res = AlibabaSms::QuerySendDetails($data);
try {
Db::startTrans();
if($res['Code'] == 'OK') {
$push_resp = $res['ErrCode'];
$push_resp = $res['SmsSendDetailDTOs']['SmsSendDetailDTO'][0]['ErrCode'];
if($res['SmsSendDetailDTOs']['SmsSendDetailDTO'][0]['SendStatus'] == 3) {
$push_status = 2;
// 扣掉余额
ShopInfo::moeny(config('cons.sms_price'), $value['main_shop_id'], 2, );
ShopInfo::moeny(config('cons.sms_price'), $value['main_shop_id'], 2);
}elseif ($res['SmsSendDetailDTOs']['SmsSendDetailDTO'][0]['SendStatus'] == 2) {
$push_status = -1;
}elseif ($res['SmsSendDetailDTOs']['SmsSendDetailDTO'][0]['SendStatus'] == 1) {

View File

@@ -102,7 +102,7 @@ if (!function_exists('curl_post')) {
{
$postData = json_encode($params, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
if(!empty($params['shopId'])) {
Log::write('耗材预警提交json' . $postData);
\support\Log::info('curl_post--->' . $postData);
}
$opts = array(
CURLOPT_TIMEOUT => 30,
@@ -120,6 +120,7 @@ if (!function_exists('curl_post')) {
$responsedata = curl_exec($ch);
$error = curl_error($ch);
curl_close($ch);
\support\Log::info('curl_post_结果--->' . $responsedata);
return $responsedata;
}
}
@@ -159,11 +160,8 @@ if (!function_exists('replace_json_keys')) {
{
$originalData = json_decode($originalJson, true);
$mapData = json_decode($mapJson, true);
$reverseMap = array_flip($mapData);
$newData = [];
foreach ($originalData as $oldKey => $value) {
// 如果原始键在映射中存在,则替换为对应的新键;否则保留原键
$newKey = $reverseMap[$oldKey] ?? $oldKey;

View File

@@ -45,6 +45,7 @@ class AlibabaSms extends Model
*/
public static function main($args){
Log::info('最终发送短信--' . json_encode($args, 256));
$client = self::createClient();
$sendSmsRequest = new SendSmsRequest($args);
$runtime = new RuntimeOptions([]);
@@ -68,6 +69,7 @@ class AlibabaSms extends Model
// 申请新短信模版
public static function CreateSmsTemplate($data)
{
Log::info('最终发送短信模版--' . json_encode($data, 256));
$client = self::createClient();
$createSmsTemplateRequest = new CreateSmsTemplateRequest($data);
$runtime = new RuntimeOptions([]);
@@ -110,6 +112,8 @@ class AlibabaSms extends Model
// 修改模版
public static function UpdateSmsTemplate($data)
{
Log::info('最终修改发送短信模版--' . json_encode($data));
return true;
$client = self::createClient();
$updateSmsTemplateRequest = new UpdateSmsTemplateRequest($data);
$runtime = new RuntimeOptions([]);
@@ -159,7 +163,7 @@ class AlibabaSms extends Model
/**
* 查询短信发送结果
*/
public function QuerySendDetails($data)
public static function QuerySendDetails($data)
{
$client = self::createClient();
$querySendDetailsRequest = new QuerySendDetailsRequest($data);

View File

@@ -69,7 +69,7 @@ class ShopInfo
if($data_arr['data']['totalPage'] > 1) {
for ($i = 2; $i <= $data_arr['data']['totalPage']; $i++) {
$data_arr = self::javaGetUserList($k_user_params, $i, $size);
if($data_arr['code'] == 0) {
if($data_arr['code'] == 200) {
if(empty($for_user_list)) {
$for_user_list = self::evnuserlist($data_arr['data']['records']);
}else {
@@ -80,10 +80,10 @@ class ShopInfo
}
$user_list = array_merge($user_list, $for_user_list);
}
return $user_list;
}else {
Log::info('获取用户列表时出错' . json_encode($data_arr));
}
return $user_list;
}
public static function evnuserlist($data)
@@ -92,7 +92,7 @@ class ShopInfo
$push_user[] = [
'user_id' => $user['id'],
'phone' => $user['phone'],
'nick_name' => $user['nickName'],
'nick_name' => $user['nick_name'],
];
}
return $push_user;
@@ -103,25 +103,25 @@ class ShopInfo
{
return [
'用户昵称' => [
'username', '用户昵称'
'username', '用户昵称', 'user_nick'
],
'店铺名称' => [
'shopname', '店铺名称'
'shopname', '店铺名称', 'name'
],
'活动名称' => [
'activityname', '活动名称',
'activityname', '活动名称', 'name'
],
'活动时间' => [
'activitytime', '活动时间',
'activitytime', '活动时间', 'time'
],
'数量' => [
'num', '数量',
'num', '数量', 'money'
],
'金额' => [
'money', '金额',
'money', '金额', 'money'
],
'时间' => [
'time', '时间',
'time', '时间', 'time',
],
];
}
@@ -156,6 +156,38 @@ class ShopInfo
return $new_arr;
}
public static function handleSmsTemplatesrule($content)
{
$arr = handldollerstr($content);
$x_arr = self::getTempDineList();
$new_arr = [];
$item_new_arr = [];
if($arr) {
$i = 1;
foreach ($arr as $k => $v) {
if(isset($x_arr[$v])) {
$k_str = $x_arr[$v][0];
$v_str = $x_arr[$v][2];
$new_arr[$k_str] = $v_str;
}else {
$item = 'item' . $i;
$item_new_arr[$item] = 'name';
$i++;
}
}
if($new_arr && $item_new_arr) {
$new_arr = array_merge($new_arr, $item_new_arr);
}
if(!$new_arr && $item_new_arr) {
$new_arr = $item_new_arr;
}
}
return $new_arr;
}
// 处理发送短信时短信模版替换内容
public static function handlesendSmsTemplates($content)
{

View File

@@ -31,17 +31,17 @@ class ApplySmsTemp implements Consumer
if($temp) {
// 处理替换内容
$templateContent_arr = ShopInfo::handleSmsTemplates($temp['content']);
$templateContent_json = json_encode($templateContent_arr);
$templateContent_json = json_encode(ShopInfo::handleSmsTemplatesrule($temp['content']), 256);
$content = replace_placeholder_keys($temp['content'], $templateContent_arr);
// 待申请
if($temp['status'] == 0) {
$data = [
'TemplateName' => $temp['title'],
'TemplateContent' => $content,
'TemplateRule' => $templateContent_json,
'Remark' => !empty($temp['scene_detail']) ? $temp['scene_detail'] : '',
'TemplateType' => 2,
'RelatedSignName' => config('cons.sms_sign'),
'templateName' => $temp['title'],
'templateContent' => $content,
'templateRule' => $templateContent_json,
'remark' => !empty($temp['scene_detail']) ? $temp['scene_detail'] : '',
'templateType' => 2,
'relatedSignName' => config('cons.sms_sign'),
];
// 调用接口
$res = AlibabaSms::CreateSmsTemplate($data);

View File

@@ -5,6 +5,7 @@ namespace app\queue\redis;
use app\model\AlibabaSms;
use app\model\ShopInfo;
use ba\Exception;
use support\Log;
use support\think\Db;
use Webman\RedisQueue\Consumer;
@@ -17,77 +18,103 @@ class SendMarkSms implements Consumer
public function consume($data)
{
Log::info('消息队列【发送营销短信】接收到消息' . $data);
if($data) {
// 发送任务
$record = Db::table('sms_push_event')->where(['id' => $data, 'push_type' => 2])->find();
if($record) {
// 待发送
if($record['status'] == 0) {
// 范围用户
if($record['user_type'] == 2) {
$k_user_params = Db::table('sms_push_event_user')->where(['event_id' => $record['id']])->find();
if($k_user_params) {
$user_list = ShopInfo::getUserList($k_user_params);
}else {
Log::info('范围用户查找出错');
return false;
}
}elseif ($record['status'] == 1) {
// 全部用户
$user_list = Db::table('tb_shop_user')->whereNotNull('phone')->select();
$user_list = ShopInfo::evnuserlist($user_list);
}
$y_temp = Db::table('sms_shop_template')->where(['id' => $record['push_event_id']])->find();
if($user_list && $y_temp) {
foreach ($user_list as $k => $v) {
// 检测余额
$shop_money = Db::table('sms_shop_money')->where(['shop_id' => $record['shop_id']])->find();
if($shop_money) {
// 余额计算
if($shop_money['money'] > config('cons.sms_price')) {
$templateParam = replace_json_keys($record['json'], $y_temp['content_json']);
$data = [
'templateCode' => $y_temp['template_code'],
'templateParam' => $templateParam,
'phoneNumbers' => $user_list['phone'],
'signName' => config('cons.sms_sign'),
];
$res = AlibabaSms::main($data);
Db::table('sms_push_event')->where(['id' => $record['id']])->update([
'status' => '1',
'update_time' => date('Y-m-d H:i:s'),
'send_time' => date('Y-m-d H:i:s'),
]);
if($res['Code'] == 'OK') {
Db::table('sms_push_event_record')->insert([
'shop_id' => $record['shop_id'],
'event_id' => $record['id'],
'user_id' => $v['user_id'],
'user_phone' => $v['phone'],
'biz_id' => $res['BizId'],
'send_time' => date('Y-m-d H:i:s'),
'create_time' => date('Y-m-d H:i:s'),
'status' => 1,
]);
}
}else {
Log::info('商户【' . $record['main_shop_id'] . '】余额不足');
try {
Db::startTrans();
Log::info('消息队列【发送营销短信】接收到消息' . $data);
// 区分数据
$arr = explode(',', $data);
if(is_array($arr)) {
$shop_id = $arr[0];
$sms_push_event_id = $arr[1];
}else {
Log::info('send.mark.sms数据格式错误');
return false;
}
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();
if($record) {
Log::info('$record');
// 待发送
if($record['status'] == 0) {
Log::info('待发送');
// 范围用户
if($record['user_type'] == 2) {
Log::info('范围用户');
$k_user_params = Db::table('sms_push_event_user')->where(['event_id' => $record['id']])->find();
if($k_user_params) {
$user_list = ShopInfo::getUserList($k_user_params);
if(!$user_list) {
return false;
}
}else {
Log::info('商户【' . $record['main_shop_id'] . '】余额为空');
return false;
Log::info('范围用户查找出错');
return false;
}
}elseif ($record['user_type'] == 1) {
Log::info('全部用户');
// 全部用户
$user_list = Db::table('tb_shop_user')->whereNotNull('phone')->field('id,phone,nick_name')->select();
$user_list = ShopInfo::evnuserlist($user_list);
}
$y_temp = Db::table('sms_shop_template')->where(['id' => $record['push_event_id']])->find();
Log::info('用户列表' . json_encode($user_list));
if($user_list && $y_temp) {
foreach ($user_list as $k => $v) {
// 检测余额
$shop_money = Db::table('sms_shop_money')->where(['shop_id' => $record['shop_id']])->find();
if($shop_money) {
// 余额计算
if($shop_money['money'] > config('cons.sms_price')) {
$templateParam = replace_json_keys($record['json'], $y_temp['content_json'], $v);
$data = [
'templateCode' => $y_temp['template_code'],
'templateParam' => $templateParam,
'phoneNumbers' => $v['phone'],
'signName' => config('cons.sms_sign'),
];
$res = AlibabaSms::main($data);
Db::table('sms_push_event')->where(['id' => $record['id']])->update([
'status' => '1',
'update_time' => date('Y-m-d H:i:s'),
'send_time' => date('Y-m-d H:i:s'),
]);
if($res['Code'] == 'OK') {
Db::table('sms_push_event_record')->insert([
'shop_id' => $record['shop_id'],
'event_id' => $record['id'],
'user_id' => $v['user_id'],
'user_phone' => $v['phone'],
'biz_id' => $res['BizId'],
'send_time' => date('Y-m-d H:i:s'),
'create_time' => date('Y-m-d H:i:s'),
'status' => 1,
]);
Db::commit();
}
}else {
Log::info('商户【' . $record['shop_id'] . '】余额不足');
return false;
}
}else {
Log::info('商户【' . $record['shop_id'] . '】余额为空');
return false;
}
sleep(1);
}
}else {
Log::info('【发送营销短信】无目标用户---》' . $record['user_id']);
}
}else {
Log::info('【发送营销短信】无目标用户---》' . $record['user_id']);
}
}else {
Log::info('发送营销短信未查询到');
}
}else {
Log::info('发送营销短信未查询到');
}
}catch (Exception $e) {
Log::error($e->getMessage());
}
}
}