133 lines
5.3 KiB
PHP
133 lines
5.3 KiB
PHP
<?php
|
|
|
|
namespace app\command;
|
|
|
|
use app\model\AlibabaSms;
|
|
use app\model\ShopInfo;
|
|
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 QuerySmsStatus extends Command
|
|
{
|
|
protected static $defaultName = 'querysmsstatus';
|
|
protected static $defaultDescription = 'querysmsstatus';
|
|
|
|
/**
|
|
* @return void
|
|
*/
|
|
protected function configure()
|
|
{
|
|
$this->addArgument('name', InputArgument::OPTIONAL, 'Name description');
|
|
}
|
|
|
|
/**
|
|
* 查询短信发送状态
|
|
* @param InputInterface $input
|
|
* @param OutputInterface $output
|
|
* @return int
|
|
*/
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
{
|
|
// 生日有礼
|
|
$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 = [
|
|
'PhoneNumber' => $value['phone'],
|
|
'BizId' => $value['biz_id'],
|
|
'SendDate' => date('Ymd'),
|
|
'PageSize' => 1,
|
|
'CurrentPage' => 20,
|
|
];
|
|
$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));
|
|
}
|
|
}catch (\Exception $e) {
|
|
Db::rollback();
|
|
Log::info('短信查询错误---》[ID]' . $e->getMessage());
|
|
}
|
|
|
|
sleep(1);
|
|
}
|
|
}
|
|
|
|
|
|
// 营销短信
|
|
$bir_list = Db::table('sms_push_event_record')->where(['status' => 1])->select()->toArray();
|
|
if($bir_list) {
|
|
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,
|
|
];
|
|
$res = AlibabaSms::QuerySendDetails($data);
|
|
try {
|
|
Db::startTrans();
|
|
if($res['Code'] == 'OK') {
|
|
$push_resp = $res['ErrCode'];
|
|
if($res['SmsSendDetailDTOs']['SmsSendDetailDTO'][0]['SendStatus'] == 3) {
|
|
$push_status = 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) {
|
|
$push_status = 1;
|
|
}
|
|
$update_data = [
|
|
'status' => $push_status,
|
|
'error' => $push_resp,
|
|
];
|
|
$update_status = Db::table('sms_push_event_record')->where(['id' => $value['id']])->update($update_data);
|
|
Db::commit();
|
|
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;
|
|
}
|
|
|
|
}
|