| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
- namespace App\Jobs\Manager\Process;
- use Illuminate\Bus\Queueable;
- use Illuminate\Contracts\Queue\ShouldBeUnique;
- use Illuminate\Contracts\Queue\ShouldQueue;
- use Illuminate\Foundation\Bus\Dispatchable;
- use Illuminate\Queue\InteractsWithQueue;
- use Illuminate\Queue\SerializesModels;
- use App\Models\Manager\Process\LowPriceGoods as LowPriceGoodsModel;
- use App\Models\Manager\Process\ViolationProduct as ViolationProductModel;
- use App\Models\Manager\Process\ViolationStore as ProcessViolationStoreModel;
- use App\Models\manager\Collect\CollectWarningNotice as CollectWarningNoticeModel;
- use App\Jobs\Manager\Process\SendEmailJobs;
- use App\Facades\Servers\Logs\Log;
- use Illuminate\Support\Carbon;
- /**
- * 数据清洗-城市为空预警通知队列
- * @author 唐远望
- * @version 1.0
- * @date 2026-05-20
- */
- class CityWarningNoticeJobs implements ShouldQueue
- {
- use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
- public $tries = 3; // 限制重试次数
- public $timeout = 600; // 10分钟超时
- protected $message_data;
- /**
- * Create a new job instance.
- *
- * @return void
- */
- public function __construct(array $message_data)
- {
- $this->message_data = $message_data;
- }
- /**
- * Execute the job.
- *
- * @return void
- */
- public function handle()
- {
- try {
- $LowPriceGoodsModel = new LowPriceGoodsModel();
- $ViolationProductModel = new ViolationProductModel();
- $ProcessViolationStoreModel = new ProcessViolationStoreModel();
- $CollectWarningNoticeModel = new CollectWarningNoticeModel();
- //获取已经开启邮箱通知的用户
- $email_notice_list = $CollectWarningNoticeModel->where([['email', '!=', '']])->where('status', 0)->get()->toarray();
- if (empty($email_notice_list)) return true;
- $start_time = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
- // $end_time = Carbon::today()->endOfDay()->getTimestamp(); // 今天结束时间 23:59:59
- $end_time = time();
- //获取低价商品省份城市为空或者未知的数据
- $map = [];
- $map[] = ['insert_time', '>=', $start_time];
- $map[] = ['insert_time', '<=', $end_time];
- //获取低价商品省份城市为空或者未知的数据
- $low_price_goods_count = $LowPriceGoodsModel->where(function ($query) {
- $query->orWhere('province_id', '0')->orWhere('province_name', '未知')->orWhere('province_name', '');
- })->where(function ($query) {
- $query->orWhere('city_id', '0')->orWhere('city_name', '未知')->orWhere('city_name', '');
- })->where($map)->count();
- //获取违规商品省份城市为空或者未知的数据
- $violation_product_count = $ViolationProductModel->where(function ($query) {
- $query->orWhere('province_id', '0')->orWhere('province_name', '未知')->orWhere('province_name', '');
- })->where(function ($query) {
- $query->orWhere('city_id', '0')->orWhere('city_name', '未知')->orWhere('city_name', '');
- })->where($map)->count();
- //获取违规门店省份城市为空或者未知的数据
- $violation_store_count = $ProcessViolationStoreModel->where(function ($query) {
- $query->orWhere('province_id', '0')->orWhere('province_name', '未知')->orWhere('province_name', '');
- })->where(function ($query) {
- $query->orWhere('city_id', '0')->orWhere('city_name', '未知')->orWhere('city_name', '');
- })->where($map)->count();
- if ($low_price_goods_count == 0 && $violation_product_count == 0 && $violation_store_count == 0) {
- return true;
- };
- //发送预警通知
- if ($low_price_goods_count > 0 || $violation_product_count > 0 || $violation_store_count > 0) {
- $email_titl = "数据清洗-城市为空预警通知";
- $email_content = "数据查询时间:" . date('Y-m-d H:i:s', $start_time) . " - " . date('Y-m-d H:i:s', $end_time).
- " 低价商品省份城市为空或者未知数据数量:" . $low_price_goods_count.'条,'.
- " 禁止商品省份城市为空或者未知数据数量:" . $violation_product_count.'条,'.
- " 违规店铺省份城市为空或者未知数据数量:" . $violation_store_count.'条';
- //发送预警通知
- foreach ($email_notice_list as $email_notice) {
- $message_data = [
- 'email' => $email_notice['email'],
- 'email_content' => json_encode(['title' => $email_titl,'content' => $email_content]),
- ];
- SendEmailJobs::dispatch(['notice_data_info' => $message_data]);
- }
- }
- } catch (\Exception $e) {
- Log::info('job_error', '数据清洗-城市为空预警通知队列失败', ['data' => $this->message_data, 'error' => $e->getMessage()]);
- }
- }
- public function failed(\Throwable $exception)
- {
- Log::info('job_error', '数据清洗-城市为空预警通知队列完全失败', ['data' => $this->message_data, 'error' => $exception->getMessage()]);
- }
- }
|