|
|
@@ -18,7 +18,8 @@ use App\Models\Manager\Process\ViolationStoreMember as ViolationStoreMemberModel
|
|
|
use Illuminate\Support\Carbon;
|
|
|
use App\Facades\Servers\Sms\VerifyCode as Sms;
|
|
|
use App\Servers\Email\VerifyCode as EmailVerifyCode;
|
|
|
-
|
|
|
+use App\Models\Manager\Personnel\NoticeConfig as NoticeConfigModel;
|
|
|
+use App\Models\Manager\Process\SubNoticeLog as SubNoticeLogModel;
|
|
|
|
|
|
/**
|
|
|
* 订阅通知
|
|
|
@@ -49,13 +50,23 @@ class SubNoticeJobs implements ShouldQueue
|
|
|
public function handle()
|
|
|
{
|
|
|
try {
|
|
|
+ $notice_config_data = $this->get_statistics_time_rule($this->message_data['company_id']);
|
|
|
+ if ($notice_config_data['statistics_start_time'] == '' || $notice_config_data['statistics_end_time'] == '' || $notice_config_data['statistics_day'] == 0) {
|
|
|
+ //记录日志
|
|
|
+ Log::info('job_info', '订阅未设置,不进行推送', ['data' => $this->message_data, 'notice_config_data' => $notice_config_data]);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ $statistics_start_time = $notice_config_data['statistics_start_time'];
|
|
|
+ $statistics_end_time = $notice_config_data['statistics_end_time'];
|
|
|
+ $push_time = $notice_config_data['push_time'];
|
|
|
$EmailVerifyCode = new EmailVerifyCode();
|
|
|
$sms_tpl_id = config('verifycode.aliyun_process_merge_notice.sms_tpl');
|
|
|
$company_id = $this->message_data['company_id'];
|
|
|
- $action_one = $this->send_low_price_goods_notice($company_id);
|
|
|
- $action_two = $this->send_violation_product($company_id);
|
|
|
- $action_three = $this->send_violation_store($company_id);
|
|
|
+ $action_one = $this->send_low_price_goods_notice($company_id, $statistics_start_time, $statistics_end_time);
|
|
|
+ $action_two = $this->send_violation_product($company_id, $statistics_start_time, $statistics_end_time);
|
|
|
+ $action_three = $this->send_violation_store($company_id, $statistics_start_time, $statistics_end_time);
|
|
|
if (empty($this->user_data)) return true;
|
|
|
+ $SubNoticeLogModel = new SubNoticeLogModel();
|
|
|
if ($action_one && $action_two && $action_three) {
|
|
|
foreach ($this->user_data as $key => $value) {
|
|
|
$mobile = $value['mobile'];
|
|
|
@@ -65,36 +76,163 @@ class SubNoticeJobs implements ShouldQueue
|
|
|
$number3 = isset($this->user_data[$key]['violation_store_logids']) ? count($this->user_data[$key]['violation_store_logids']) : 0;
|
|
|
//统计总条数
|
|
|
$totle_number = $number1 + $number2 + $number3;
|
|
|
+ $sms_config_data =[];
|
|
|
if (trim($mobile) != '') {
|
|
|
- $res_msg = Sms::sendContent($mobile, ['totle_number' => $totle_number, 'number1' => $number1, 'number2' => $number2, 'number3' => $number3], $sms_tpl_id);
|
|
|
- Log::info('job_send_sms', '订阅短信通知推送队列记录', ['email' => $mobile, 'sms_tpl_id' => $sms_tpl_id, 'msg' => $res_msg]);
|
|
|
+ $sms_config_data =['parameter'=> ['totle_number' => $totle_number, 'number1' => $number1, 'number2' => $number2, 'number3' => $number3],'sms_tpl_id'=> $sms_tpl_id];
|
|
|
+ // $res_msg = Sms::sendContent($mobile, ['totle_number' => $totle_number, 'number1' => $number1, 'number2' => $number2, 'number3' => $number3], $sms_tpl_id);
|
|
|
+ // Log::info('job_send_sms', '订阅短信通知推送队列记录', ['email' => $mobile, 'sms_tpl_id' => $sms_tpl_id, 'msg' => $res_msg]);
|
|
|
}
|
|
|
+ $email_title ='';
|
|
|
+ $email_content = '';
|
|
|
if (trim($email_to) != '') {
|
|
|
$email_title = '智价云违规数据通知提醒';
|
|
|
- $email_content = "智价云提醒:本次采集总数据共". $totle_number ."条,其中低价挂网商品共". $number1 ."条、禁止挂网商品共". $number2 ."条、违规挂网店铺共". $number3 ."条。";
|
|
|
- $res_msg = $EmailVerifyCode->sendSmtpEmail($email_to, $email_title, $email_content);
|
|
|
- Log::info('job_send_email', '订阅邮件通知推送队列记录', ['email' => $email_to, 'email_content' => $email_content, 'msg' => $res_msg]);
|
|
|
+ $email_content = "智价云提醒:本次采集总数据共" . $totle_number . "条,其中低价挂网商品共" . $number1 . "条、禁止挂网商品共" . $number2 . "条、违规挂网店铺共" . $number3 . "条。";
|
|
|
+ // $res_msg = $EmailVerifyCode->sendSmtpEmail($email_to, $email_title, $email_content);
|
|
|
+ // Log::info('job_send_email', '订阅邮件通知推送队列记录', ['email' => $email_to, 'email_content' => $email_content, 'msg' => $res_msg]);
|
|
|
}
|
|
|
+ $ext_data = [
|
|
|
+ 'company_id' => $company_id,
|
|
|
+ 'lowprice_product_number' => $number1,
|
|
|
+ 'violation_product_number' => $number2,
|
|
|
+ 'violation_store_number' => $number3,
|
|
|
+ 'statistics_start_time' => $statistics_start_time,
|
|
|
+ 'statistics_end_time' => $statistics_end_time,
|
|
|
+ ];
|
|
|
+ // 增加就订阅日志
|
|
|
+ $insert_data = [
|
|
|
+ 'company_id' => $company_id,
|
|
|
+ 'email' => $email_to,
|
|
|
+ 'mobile' => $mobile,
|
|
|
+ 'email_content' => trim($email_to) != '' ? json_encode(['title' => $email_title, 'content' => $email_content]): '',
|
|
|
+ 'mobile_content' => trim($mobile) != '' ? json_encode($sms_config_data): '',
|
|
|
+ 'push_time' => $push_time,
|
|
|
+ 'ext_data' => json_encode($ext_data),
|
|
|
+ 'insert_time' => time(),
|
|
|
+ ];
|
|
|
+ $SubNoticeLogModel->insert($insert_data);
|
|
|
}
|
|
|
}
|
|
|
} catch (\Exception $e) {
|
|
|
+ print_r($e->getMessage());
|
|
|
+ exit;
|
|
|
Log::info('job_error', '订阅短信通知推送队列失败', ['data' => $this->message_data, 'error' => $e->getMessage()]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取统计时间规则
|
|
|
+ * @author 唐远望
|
|
|
+ * @version 1.0
|
|
|
+ * @date 2026-04-11
|
|
|
+ */
|
|
|
+ private function get_statistics_time_rule($company_id)
|
|
|
+ {
|
|
|
+ // 获取当时时间是星期几
|
|
|
+ $now_week = date('w');
|
|
|
+ // $now_week = 1;//调试星期
|
|
|
+ $NoticeConfigModel = new NoticeConfigModel();
|
|
|
+ $data = $NoticeConfigModel->where(['company_id' => $company_id])->first();
|
|
|
+ if (!$data) return ['now_week' => $now_week, 'statistics_day' => 0, 'statistics_start_time' => '', 'statistics_end_time' => '','push_time'=> '', 'notice_week_config' => ''];
|
|
|
+
|
|
|
+ //校验这个星期是否需要进行推送
|
|
|
+ $notice_week_config = json_decode($data->notice_week_config, true);
|
|
|
+ $is_open = 0;
|
|
|
+ $now_week_day = 'week_' . $now_week;
|
|
|
+ if ($notice_week_config[$now_week_day] == 0) {
|
|
|
+ $is_open = 1;
|
|
|
+ }
|
|
|
+ if ($is_open == 0) {
|
|
|
+ return ['now_week' => $now_week, 'statistics_day' => 0, 'statistics_start_time' => '', 'statistics_end_time' => '','push_time'=> '', 'notice_week_config' => $notice_week_config];
|
|
|
+ }
|
|
|
+ //是否每天都推送
|
|
|
+ $is_day_day_push = 0;
|
|
|
+ for ($i = 7; $i >= 1; $i--) {
|
|
|
+ $week_string = 'week_' . $i;
|
|
|
+ if ($notice_week_config[$week_string] == 0) {
|
|
|
+ $is_day_day_push = $is_day_day_push + 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($is_day_day_push == 7) {
|
|
|
+ $statistics_day = 1;
|
|
|
+ } else {
|
|
|
+ $statistics_day = 0;
|
|
|
+ //判断当时时间是否是星期一
|
|
|
+ if ($now_week == 1) {
|
|
|
+ for ($i = 7; $i >= 1; $i--) {
|
|
|
+ //校验前一天是否推送
|
|
|
+ $week_string = 'week_7';
|
|
|
+ if ($notice_week_config[$week_string] == 0) { // 如果前一天没有开启推送则统计,状态 0=开启 1=关闭
|
|
|
+ $statistics_day = $statistics_day + 1;
|
|
|
+ break;
|
|
|
+ } else {
|
|
|
+ $week_oth_string = 'week_' . $i;
|
|
|
+ if ($notice_week_config[$week_oth_string] == '1') { // 如果前一天没有开启推送则统计,状态 0=开启 1=关闭
|
|
|
+ $statistics_day = $statistics_day + 1;
|
|
|
+ } else {
|
|
|
+ $statistics_day = $statistics_day + 1;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $statistics_day = 0;
|
|
|
+ //如果当前$now_week星期,往前推,当遇到开启的日期时,停止往前推,最大为7天
|
|
|
+ for ($i = $now_week; $i >= 1; $i--) {
|
|
|
+ //校验前一天是否推送
|
|
|
+ $yesterday_week = $now_week - 1;
|
|
|
+ if ($yesterday_week < 1) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $week_string = 'week_' . $yesterday_week;
|
|
|
+ //校验前一天是否开启了推送
|
|
|
+ if ($i == $now_week && $notice_week_config[$week_string] == '0') {
|
|
|
+ $statistics_day = $statistics_day + 1;
|
|
|
+ break;
|
|
|
+ } else {
|
|
|
+ $i_index = $i - 1; //往前推一天
|
|
|
+ if ($i_index < 1) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $week_oth_string = 'week_' . $i_index;
|
|
|
+ if ($notice_week_config[$week_oth_string] == '1') {
|
|
|
+ $statistics_day = $statistics_day + 1;
|
|
|
+ } else {
|
|
|
+ $statistics_day = $statistics_day + 1;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($statistics_day < 1) {
|
|
|
+ return ['now_week' => $now_week, 'statistics_day' => $statistics_day, 'statistics_start_time' => '', 'statistics_end_time' => '','push_time'=> '', 'notice_week_config' => $notice_week_config];
|
|
|
+ }
|
|
|
+ //获取统计开始时间
|
|
|
+ $statistics_start_time = Carbon::today()->subDays($statistics_day)->startOfDay()->toDateTimeString();
|
|
|
+ //获取昨日结束时间
|
|
|
+ $statistics_end_time = Carbon::today()->subDays(1)->endOfDay()->toDateTimeString();
|
|
|
+ return ['now_week' => $now_week, 'statistics_day' => $statistics_day, 'statistics_start_time' => $statistics_start_time, 'statistics_end_time' => $statistics_end_time,'push_time'=> $data->push_time, 'notice_week_config' => $notice_week_config];
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 短信消息消息订阅推送(低价挂网)
|
|
|
* @author 唐远望
|
|
|
* @version 1.0
|
|
|
* @date 2026-03-04
|
|
|
*/
|
|
|
- private function send_low_price_goods_notice($company_id)
|
|
|
+ private function send_low_price_goods_notice($company_id, $statistics_start_time, $statistics_end_time)
|
|
|
{
|
|
|
$LowPriceGoodsMemberModel = new LowPriceGoodsMemberModel();
|
|
|
$LowPriceGoodsModel = new LowPriceGoodsModel();
|
|
|
//获取今日待处理的商品记录
|
|
|
- $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
|
|
|
- $todayEnd = Carbon::today()->endOfDay()->getTimestamp(); // 今天结束时间 23:59:59
|
|
|
+ $todayStart = strtotime($statistics_start_time); // 统计开始时间
|
|
|
+ $todayEnd = strtotime($statistics_end_time); // 统计结束时间
|
|
|
$lowprice_ids = $LowPriceGoodsModel->where([['insert_time', '>=', $todayStart], ['insert_time', '<=', $todayEnd], ['company_id', '=', $company_id]])->pluck('id')->toArray();
|
|
|
if (empty($lowprice_ids)) return true;
|
|
|
//获取开启了通知服务的用户
|
|
|
@@ -127,13 +265,13 @@ class SubNoticeJobs implements ShouldQueue
|
|
|
* @version 1.0
|
|
|
* @date 2026-03-04
|
|
|
*/
|
|
|
- private function send_violation_product($company_id)
|
|
|
+ private function send_violation_product($company_id, $statistics_start_time, $statistics_end_time)
|
|
|
{
|
|
|
$ViolationProductMemberModel = new ViolationProductMemberModel();
|
|
|
$ViolationProductModel = new ViolationProductModel();
|
|
|
//获取今日待处理的商品记录
|
|
|
- $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
|
|
|
- $todayEnd = Carbon::today()->endOfDay()->getTimestamp(); // 今天结束时间 23:59:59
|
|
|
+ $todayStart = strtotime($statistics_start_time); // 统计开始时间
|
|
|
+ $todayEnd = strtotime($statistics_end_time); // 统计结束时间
|
|
|
$violation_price_ids = $ViolationProductModel->where([['insert_time', '>=', $todayStart], ['insert_time', '<=', $todayEnd], ['company_id', '=', $company_id]])->pluck('id')->toArray();
|
|
|
if (empty($violation_price_ids)) return true;
|
|
|
//获取开启了通知服务的用户
|
|
|
@@ -166,13 +304,13 @@ class SubNoticeJobs implements ShouldQueue
|
|
|
* @version 1.0
|
|
|
* @date 2026-03-04
|
|
|
*/
|
|
|
- private function send_violation_store($company_id)
|
|
|
+ private function send_violation_store($company_id, $statistics_start_time, $statistics_end_time)
|
|
|
{
|
|
|
$ViolationStoreMemberModel = new ViolationStoreMemberModel();
|
|
|
$ViolationStoreModel = new ViolationStoreModel();
|
|
|
//获取今日待处理的店铺记录
|
|
|
- $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
|
|
|
- $todayEnd = Carbon::today()->endOfDay()->getTimestamp(); // 今天结束时间 23:59:59
|
|
|
+ $todayStart = strtotime($statistics_start_time); // 统计开始时间
|
|
|
+ $todayEnd = strtotime($statistics_end_time); // 统计结束时间
|
|
|
$violation_price_ids = $ViolationStoreModel->where([['insert_time', '>=', $todayStart], ['insert_time', '<=', $todayEnd], ['company_id', '=', $company_id]])->pluck('id')->toArray();
|
|
|
if (empty($violation_price_ids)) return true;
|
|
|
//获取开启了通知服务的用户
|