|
|
@@ -0,0 +1,162 @@
|
|
|
+<?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\Facades\Servers\Logs\Log;
|
|
|
+use App\Servers\Email\VerifyCode as EmailVerifyCode;
|
|
|
+use App\Models\Manager\Process\LowPriceGoodsMember as LowPriceGoodsMemberModel;
|
|
|
+use App\Models\Manager\Process\LowPriceGoods as LowPriceGoodsModel;
|
|
|
+use App\Models\Manager\Process\ViolationProductMember as ViolationProductMemberModel;
|
|
|
+use App\Models\Manager\Process\ViolationProduct as ViolationProductModel;
|
|
|
+use Illuminate\Support\Carbon;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * 订阅邮件通知
|
|
|
+ * @author 唐远望
|
|
|
+ * @version 1.0
|
|
|
+ * @date 2026-03-30
|
|
|
+ */
|
|
|
+class SubEmailJobs implements ShouldQueue
|
|
|
+{
|
|
|
+ use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
+ 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 {
|
|
|
+ $notice_type = $this->message_data['notice_type'];
|
|
|
+ switch ($notice_type) {
|
|
|
+ case 'low_price_goods':
|
|
|
+ $this->send_low_price_goods_notice();
|
|
|
+ break;
|
|
|
+ case 'violation_product':
|
|
|
+ $this->send_violation_product();
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ } 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-03-04
|
|
|
+ */
|
|
|
+ private function send_low_price_goods_notice()
|
|
|
+ {
|
|
|
+ $EmailVerifyCode = new EmailVerifyCode();
|
|
|
+ $LowPriceGoodsMemberModel = new LowPriceGoodsMemberModel();
|
|
|
+ $LowPriceGoodsModel = new LowPriceGoodsModel();
|
|
|
+ //获取今日待处理的商品记录
|
|
|
+ $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
|
|
|
+ $todayEnd = Carbon::today()->endOfDay()->getTimestamp(); // 今天结束时间 23:59:59
|
|
|
+ $lowprice_ids = $LowPriceGoodsModel->where([['insert_time', '>=', $todayStart], ['insert_time', '<=', $todayEnd]])->pluck('id')->toArray();
|
|
|
+ if (empty($lowprice_ids)) return true;
|
|
|
+ //获取开启了通知服务的用户
|
|
|
+ $usert_list = $LowPriceGoodsMemberModel
|
|
|
+ ->whereIn('low_price_goods_id', $lowprice_ids)
|
|
|
+ ->join('personnel_employee', 'process_lowprice_product_member.employee_id', '=', 'personnel_employee.id')
|
|
|
+ ->where('personnel_employee.notice_status', 1)
|
|
|
+ ->where([['personnel_employee.email', '!=', ''], ['personnel_employee.email', '!=', null]])
|
|
|
+ ->get()->toArray();
|
|
|
+ if (empty($usert_list)) return true;
|
|
|
+ //按用户统计待处理的商品数量
|
|
|
+ $user_data = [];
|
|
|
+ foreach ($usert_list as $key => $value) {
|
|
|
+ $user_id = $value['employee_id'];
|
|
|
+ if (!isset($user_data[$user_id])) {
|
|
|
+ $user_data[$user_id]['email'] = $value['email'];
|
|
|
+ $user_data[$user_id]['log_ids'] = [];
|
|
|
+ } else {
|
|
|
+ $user_data[$user_id]['log_ids'][] = $value['low_price_goods_id'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //发送邮件
|
|
|
+ foreach ($user_data as $key => $value) {
|
|
|
+ $email_to = $value['email'];
|
|
|
+ $totle_number = count($value['log_ids']);
|
|
|
+ $email_title = '商品提醒';
|
|
|
+ $email_content = '今日待处理商品共【' . $totle_number . '】条,请及时登录系统处理。';
|
|
|
+ $EmailVerifyCode->sendSmtpEmail($email_to, $email_title, $email_content);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 邮件消息消息订阅推送(禁止挂网)
|
|
|
+ * @author 唐远望
|
|
|
+ * @version 1.0
|
|
|
+ * @date 2026-03-04
|
|
|
+ */
|
|
|
+ private function send_violation_product()
|
|
|
+ {
|
|
|
+ $EmailVerifyCode = new EmailVerifyCode();
|
|
|
+ $ViolationProductMemberModel = new ViolationProductMemberModel();
|
|
|
+ $ViolationProductModel = new ViolationProductModel();
|
|
|
+ //获取今日待处理的商品记录
|
|
|
+ $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
|
|
|
+ $todayEnd = Carbon::today()->endOfDay()->getTimestamp(); // 今天结束时间 23:59:59
|
|
|
+ $violation_price_ids = $ViolationProductModel->where([['insert_time', '>=', $todayStart], ['insert_time', '<=', $todayEnd]])->pluck('id')->toArray();
|
|
|
+ if (empty($violation_price_ids)) return true;
|
|
|
+ //获取开启了通知服务的用户
|
|
|
+ $usert_list = $ViolationProductMemberModel
|
|
|
+ ->whereIn('violation_product_logid', $violation_price_ids)
|
|
|
+ ->join('personnel_employee', 'process_lowprice_product_member.employee_id', '=', 'personnel_employee.id')
|
|
|
+ ->where('personnel_employee.notice_status', 1)
|
|
|
+ ->where([['personnel_employee.email', '!=', ''], ['personnel_employee.email', '!=', null]])
|
|
|
+ ->get()->toArray();
|
|
|
+ if (empty($usert_list)) return true;
|
|
|
+ //按用户统计待处理的商品数量
|
|
|
+ $user_data = [];
|
|
|
+ foreach ($usert_list as $key => $value) {
|
|
|
+ $user_id = $value['employee_id'];
|
|
|
+ if (!isset($user_data[$user_id])) {
|
|
|
+ $user_data[$user_id]['email'] = $value['email'];
|
|
|
+ $user_data[$user_id]['log_ids'] = [];
|
|
|
+ } else {
|
|
|
+ $user_data[$user_id]['log_ids'][] = $value['violation_product_logid'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //发送邮件
|
|
|
+ foreach ($user_data as $key => $value) {
|
|
|
+ $email_to = $value['email'];
|
|
|
+ $totle_number = count($value['log_ids']);
|
|
|
+ $email_title = '禁止挂网商品提醒';
|
|
|
+ $email_content = '今日待处理禁止挂网商品共【' . $totle_number . '】条,请及时登录系统处理。';
|
|
|
+ $EmailVerifyCode->sendSmtpEmail($email_to, $email_title, $email_content);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public function failed(\Throwable $exception)
|
|
|
+ {
|
|
|
+ Log::info('job_error', '订阅邮件通知推送队列完全失败', ['data' => $this->message_data, 'error' => $exception]);
|
|
|
+ }
|
|
|
+}
|