进一步完成
This commit is contained in:
@@ -5,6 +5,7 @@ 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;
|
||||
@@ -37,6 +38,13 @@ 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);
|
||||
|
||||
|
||||
$host = RabbitMqConfig::$host;
|
||||
$port = RabbitMqConfig::$port;
|
||||
@@ -59,7 +67,7 @@ class ApplySmsTemp extends Command
|
||||
);
|
||||
$rabbit_channel = $connection->channel();
|
||||
$rabbit_channel->queue_declare($queue, false, true, false, false, false, [
|
||||
'x-message-ttl' => ['I', 180000]
|
||||
// 'x-message-ttl' => ['I', 180000]
|
||||
]);
|
||||
|
||||
$callback = function ($msg) use ($queue){
|
||||
|
||||
@@ -59,7 +59,7 @@ class BirthdayGiftSms extends Command
|
||||
);
|
||||
$rabbit_channel = $connection->channel();
|
||||
$rabbit_channel->queue_declare($queue, false, true, false, false, false, [
|
||||
'x-message-ttl' => ['I', 180000]
|
||||
// 'x-message-ttl' => ['I', 180000]
|
||||
]);
|
||||
|
||||
$callback = function ($msg) use ($queue){
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace app\command;
|
||||
|
||||
use app\model\AlibabaSms;
|
||||
use app\model\ShopInfo;
|
||||
use support\Log;
|
||||
use support\think\Db;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
@@ -28,44 +29,63 @@ class QuerySmsStatus extends Command
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询模版审核状态 1小时执行一次
|
||||
* 查询短信发送状态
|
||||
* @param InputInterface $input
|
||||
* @param OutputInterface $output
|
||||
* @return int
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$list = Db::table('sms_shop_template')->where(['status' => 1])->select()->toArray();
|
||||
Log::info('短信模版审核查询开始->' . json_encode($list));
|
||||
if($list) {
|
||||
foreach ($list as $k => $value) {
|
||||
// 生日有礼
|
||||
$bir_list = Db::table('mk_birthday_gift_record')->where(['status' => 'await_push'])->select()->toArray();
|
||||
if($bir_list) {
|
||||
Log::info('生日有礼短信发送状态查询开始->' . json_encode($bir_list));
|
||||
foreach ($bir_list as $k => $value) {
|
||||
$data = [
|
||||
'TemplateCode' => $value['template_code']
|
||||
'TemplateCode' => $value['template_code'],
|
||||
'BizId' => $value['biz_id'],
|
||||
'SendDate' => date('Ymd'),
|
||||
'PageSize' => 1,
|
||||
'CurrentPage' => 20,
|
||||
];
|
||||
$res = AlibabaSms::GetSmsTemplate($data);
|
||||
if($res['Code'] == 'OK') {
|
||||
$msg = '';
|
||||
if($res['TemplateStatus'] == 0) {
|
||||
$status = 1;
|
||||
}elseif ($res['TemplateStatus'] == 1) {
|
||||
$status = 2;
|
||||
}elseif ($res['TemplateStatus'] == 2) {
|
||||
$status = -1;
|
||||
$msg = $res['AuditInfo']['RejectInfo'];
|
||||
}elseif ($res['TemplateStatus'] == 10) {
|
||||
$status = -1;
|
||||
$msg = '取消审核';
|
||||
$res = AlibabaSms::QuerySendDetails($data);
|
||||
try {
|
||||
Db::startTrans();
|
||||
if($res['Code'] == 'OK') {
|
||||
$push_resp = $res['ErrCode'];
|
||||
if($res['SmsSendDetailDTOs']['SmsSendDetailDTO'][0]['SendStatus'] == 3) {
|
||||
$push_status = 'success';
|
||||
// 扣掉余额
|
||||
ShopInfo::moeny(config('cons.sms_price'), $value['main_shop_id'], 2, );
|
||||
}elseif ($res['SmsSendDetailDTOs']['SmsSendDetailDTO'][0]['SendStatus'] == 2) {
|
||||
$push_status = 'failed';
|
||||
}elseif ($res['SmsSendDetailDTOs']['SmsSendDetailDTO'][0]['SendStatus'] == 1) {
|
||||
$push_status = 'await_push';
|
||||
}
|
||||
$update_data = [
|
||||
'status' => $push_status,
|
||||
'push_resp' => $push_resp,
|
||||
];
|
||||
$update_status = Db::table('mk_birthday_gift_record')->where(['id' => $value['id']])->update($update_data);
|
||||
Db::commit();
|
||||
Log::info('短信查询完毕数据库更新结果---》[ID]' . $value['id'] . '更新结果-->' . $update_status . '-->更新数据 . ' . json_encode($update_data));
|
||||
}
|
||||
$update_data = [
|
||||
'status' => $status,
|
||||
'fail_msg' => $msg?:$msg,
|
||||
];
|
||||
$update_status = Db::table('sms_shop_template')->where(['id' => $value['id']])->update($update_data);
|
||||
Log::info('模版查询完毕数据库更新结果---》[ID]' . $value['id'] . '更新结果-->' . $update_status . '-->更新数据 . ' . json_encode($update_data));
|
||||
}catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
Log::info('短信查询错误---》[ID]' . $e->getMessage());
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 活动开始
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
72
app/command/QuerySmsTempStatus.php
Normal file
72
app/command/QuerySmsTempStatus.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace app\command;
|
||||
|
||||
use app\model\AlibabaSms;
|
||||
use support\Log;
|
||||
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 ZipArchive;
|
||||
|
||||
|
||||
// 查询短信模版审核状态
|
||||
class QuerySmsTempStatus extends Command
|
||||
{
|
||||
protected static $defaultName = 'querysmstempstatus';
|
||||
protected static $defaultDescription = 'querysmstempstatus';
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this->addArgument('name', InputArgument::OPTIONAL, 'Name description');
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询模版审核状态 1小时执行一次
|
||||
* @param InputInterface $input
|
||||
* @param OutputInterface $output
|
||||
* @return int
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$list = Db::table('sms_shop_template')->where(['status' => 1])->select()->toArray();
|
||||
Log::info('短信模版审核查询开始->' . json_encode($list));
|
||||
if($list) {
|
||||
foreach ($list as $k => $value) {
|
||||
$data = [
|
||||
'TemplateCode' => $value['template_code']
|
||||
];
|
||||
$res = AlibabaSms::GetSmsTemplate($data);
|
||||
if($res['Code'] == 'OK') {
|
||||
$msg = '';
|
||||
if($res['TemplateStatus'] == 0) {
|
||||
$status = 1;
|
||||
}elseif ($res['TemplateStatus'] == 1) {
|
||||
$status = 2;
|
||||
}elseif ($res['TemplateStatus'] == 2) {
|
||||
$status = -1;
|
||||
$msg = $res['AuditInfo']['RejectInfo'];
|
||||
}elseif ($res['TemplateStatus'] == 10) {
|
||||
$status = -1;
|
||||
$msg = '取消审核';
|
||||
}
|
||||
$update_data = [
|
||||
'status' => $status,
|
||||
'fail_msg' => $msg?:$msg,
|
||||
];
|
||||
$update_status = Db::table('sms_shop_template')->where(['id' => $value['id']])->update($update_data);
|
||||
Log::info('模版查询完毕数据库更新结果---》[ID]' . $value['id'] . '更新结果-->' . $update_status . '-->更新数据 . ' . json_encode($update_data));
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -59,7 +59,7 @@ class SendMarkSms extends Command
|
||||
);
|
||||
$rabbit_channel = $connection->channel();
|
||||
$rabbit_channel->queue_declare($queue, false, true, false, false, false, [
|
||||
'x-message-ttl' => ['I', 180000]
|
||||
// 'x-message-ttl' => ['I', 180000]
|
||||
]);
|
||||
|
||||
$callback = function ($msg) use ($queue){
|
||||
|
||||
@@ -59,7 +59,7 @@ class SendWechatTemp extends Command
|
||||
);
|
||||
$rabbit_channel = $connection->channel();
|
||||
$rabbit_channel->queue_declare($queue, false, true, false, false, false, [
|
||||
'x-message-ttl' => ['I', 180000]
|
||||
// 'x-message-ttl' => ['I', 180000]
|
||||
]);
|
||||
|
||||
$callback = function ($msg) use ($queue){
|
||||
|
||||
Reference in New Issue
Block a user