|
|
@@ -0,0 +1,160 @@
|
|
|
+<?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\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;
|
|
|
+use App\Facades\Servers\Sms\VerifyCode as Sms;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * 订阅短信通知
|
|
|
+ * @author 唐远望
|
|
|
+ * @version 1.0
|
|
|
+ * @date 2026-03-30
|
|
|
+ */
|
|
|
+class SubSmsJobs 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) {
|
|
|
+ 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()
|
|
|
+ {
|
|
|
+ $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('lowprice_product_logid', $lowprice_ids)
|
|
|
+ ->join('personnel_employee', 'process_lowprice_product_member.employee_id', '=', 'personnel_employee.id')
|
|
|
+ ->where('personnel_employee.open_notice', 0)
|
|
|
+ ->where([['personnel_employee.mobile', '!=', ''], ['personnel_employee.mobile', '!=', null]])
|
|
|
+ ->select(['process_lowprice_product_member.*', 'personnel_employee.mobile'])
|
|
|
+ ->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]['employee_id'] = $user_id;
|
|
|
+ $user_data[$user_id]['mobile'] = $value['mobile'];
|
|
|
+ $user_data[$user_id]['log_ids'][] = $value['lowprice_product_logid'];
|
|
|
+ } else {
|
|
|
+ $user_data[$user_id]['log_ids'][] = $value['lowprice_product_logid'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $sms_tpl_id = config('verifycode.aliyun_process_lowprice_product.sms_tpl');
|
|
|
+ //发送短信
|
|
|
+ foreach ($user_data as $key => $value) {
|
|
|
+ $phone = $value['mobile'];
|
|
|
+ $totle_number = count($value['log_ids']);
|
|
|
+ Sms::sendContent($phone, ['totle_number' => $totle_number], $sms_tpl_id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 短信消息消息订阅推送(禁止挂网)
|
|
|
+ * @author 唐远望
|
|
|
+ * @version 1.0
|
|
|
+ * @date 2026-03-04
|
|
|
+ */
|
|
|
+ private function send_violation_product()
|
|
|
+ {
|
|
|
+ $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_violation_product_member.employee_id', '=', 'personnel_employee.id')
|
|
|
+ ->where('personnel_employee.open_notice', 0)
|
|
|
+ ->where([['personnel_employee.mobile', '!=', ''], ['personnel_employee.mobile', '!=', null]])
|
|
|
+ ->select(['process_violation_product_member.*', 'personnel_employee.mobile'])
|
|
|
+ ->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]['employee_id'] = $user_id;
|
|
|
+ $user_data[$user_id]['mobile'] = $value['mobile'];
|
|
|
+ $user_data[$user_id]['log_ids'][] = $value['violation_product_logid'];
|
|
|
+ } else {
|
|
|
+ $user_data[$user_id]['log_ids'][] = $value['violation_product_logid'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $sms_tpl_id = config('verifycode.aliyun_process_process_violation_product.sms_tpl');
|
|
|
+ //发送短信
|
|
|
+ foreach ($user_data as $key => $value) {
|
|
|
+ $phone = $value['mobile'];
|
|
|
+ $totle_number = count($value['log_ids']);
|
|
|
+ Sms::sendContent($phone, ['totle_number' => $totle_number], $sms_tpl_id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public function failed(\Throwable $exception)
|
|
|
+ {
|
|
|
+ Log::info('job_error', '订阅短信通知推送队列完全失败', ['data' => $this->message_data, 'error' => $exception]);
|
|
|
+ }
|
|
|
+}
|