营销短信查询统计记录
This commit is contained in:
@@ -91,7 +91,7 @@ class QuerySmsStatus extends Command
|
||||
}
|
||||
|
||||
|
||||
// 营销短信
|
||||
// 营销短信发送结果查询
|
||||
$bir_list = Db::table('sms_push_event_record')->where(['status' => 1])->select()->toArray();
|
||||
if($bir_list) {
|
||||
Log::info('营销短信发送状态查询开始->' . json_encode($bir_list));
|
||||
@@ -122,10 +122,6 @@ class QuerySmsStatus extends Command
|
||||
'error' => $push_resp,
|
||||
];
|
||||
$update_status = Db::table('sms_push_event_record')->where(['id' => $value['id']])->update($update_data);
|
||||
// 只要有一个发送成功的就更改状态发送成功
|
||||
if($push_status == 2) {
|
||||
Db::table('sms_push_event')->where(['id' => $value['event_id']])->update(['status' => 2]);
|
||||
}
|
||||
Log::info('营销短信查询完毕数据库更新结果---》[ID]' . $value['id'] . '更新结果-->' . $update_status . '-->更新数据 . ' . json_encode($update_data));
|
||||
}
|
||||
Db::commit();
|
||||
@@ -133,12 +129,42 @@ class QuerySmsStatus extends Command
|
||||
Db::rollback();
|
||||
Log::info('短信查询错误---》[ID]' . $e->getMessage());
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
}else {
|
||||
Log::info('没有营销短信状态查询的数据');
|
||||
}
|
||||
|
||||
// 营销短信发送失败成功统计
|
||||
$sms_push_event_list = Db::name('sms_push_event')->where(['status' => 1])->select()->toArray();
|
||||
if($sms_push_event_list) {
|
||||
Log::info('营销短信发送失败成功统计开始->' . json_encode($sms_push_event_list));
|
||||
foreach ($sms_push_event_list as $k => $v) {
|
||||
$result = Db::table('sms_push_event_record')
|
||||
->where('event_id', $v['id']) // 统一筛选 event_id=2 的数据
|
||||
->field([
|
||||
// 1. event_id=2 的实际人数
|
||||
'COUNT(*) AS total_count',
|
||||
// 成功人数
|
||||
'COUNT(CASE WHEN status = 1 THEN 1 END) AS success_count',
|
||||
// 失败人数
|
||||
'COUNT(CASE WHEN status = -1 THEN 1 END) AS fail_count'
|
||||
])
|
||||
->find(); // 单条结果(返回关联数组)
|
||||
// 如果成功人数和失败人数等于实际人数,代表发送任务已经完成
|
||||
if(($result['success_count'] + $result['fail_count']) >= $result['total_count']) {
|
||||
Log::info('发送任务【' .$v['id']. '】已经完成-> 成功' . $result['success_count'] . ' 失败' . $result['fail_count']);
|
||||
$update = [
|
||||
'status' => 2,
|
||||
'actual_num' => $result['total_count'],
|
||||
'success_num' => $result['success_count'],
|
||||
];
|
||||
Db::name('sms_push_event')->where(['id' => $v['id']])->update($update);
|
||||
}
|
||||
}
|
||||
}else {
|
||||
Log::info('没有营销短信发送统计数据');
|
||||
}
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user