|
|
@@ -0,0 +1,116 @@
|
|
|
+<?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\ViolationStore as ViolationStoreModel;
|
|
|
+use App\Models\Manager\Personnel\Employee as EmployeeModel;
|
|
|
+use App\Models\Api\Process\ExecuteLog as ExecuteLogModel;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 数据清洗-违规店铺清洗数据队列
|
|
|
+ * @author 唐远望
|
|
|
+ * @version 1.0
|
|
|
+ * @date 2025-12-11
|
|
|
+ */
|
|
|
+class ViolationStoreDataJobs 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 {
|
|
|
+ $this->getViolationStoreData($this->message_data);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Log::info('job_error', '数据清洗-违规店铺清洗数据队列失败', ['data' => $this->message_data, 'error' => $e->getMessage()]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 采集商品数据清洗
|
|
|
+ * @author 唐远望
|
|
|
+ * @version 1.0
|
|
|
+ * @date 2025-12-11
|
|
|
+ */
|
|
|
+ public function getViolationStoreData($message_data)
|
|
|
+ {
|
|
|
+ $EmployeeModel = new EmployeeModel();
|
|
|
+ $ViolationStoreModel = new ViolationStoreModel();
|
|
|
+ $platform = $message_data['platform']; ////多个平台配置
|
|
|
+ $store_name = $message_data['store_name']; //店铺名称
|
|
|
+ $company_name = $message_data['company_name']; //公司名称
|
|
|
+ $social_credit_code = $message_data['social_credit_code']; //信用代码
|
|
|
+ $store_type = $message_data['store_type']; //店铺类型:1=黑名单2=白名单
|
|
|
+ $executeLog_id = $message_data['executeLog_id'];
|
|
|
+ $limit = isset($message_data['limit']) ? $message_data['limit'] : 50;
|
|
|
+ $page = isset($message_data['page']) ? $message_data['page'] : 1;
|
|
|
+
|
|
|
+ $product_datas = []; //商品数据
|
|
|
+ if (empty($product_datas)) {
|
|
|
+ (new ExecuteLogModel())->where('id', $executeLog_id)->update(['status' => 0]);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ foreach ($product_datas as $product_data) {
|
|
|
+ $insert_product_data = [
|
|
|
+ 'platform' => $product_data['platform'],
|
|
|
+ 'company_name' => $product_data['company_name'],
|
|
|
+ 'social_credit_code' => $product_data['social_credit_code'],
|
|
|
+ 'store_name' => $product_data['store_name'],
|
|
|
+ 'link_url' => $product_data['link_url'],
|
|
|
+ 'store_name' => $product_data['store_name'],
|
|
|
+ ];
|
|
|
+ //查询配置的第一责任人
|
|
|
+ $where_query1[] = ['city_ids', 'like', '%,' . $product_data['city_id'] . ',%'];
|
|
|
+ $where_query1[] = ['status', '=', 1];
|
|
|
+ $where_query1[] = ['duty_type', 'in', 1]; //责任类型1=第一责任人,2=责任人
|
|
|
+ $first_responsible_person = $EmployeeModel->where($where_query1)->pluck('id')->implode(',');
|
|
|
+ $insert_product_data['first_responsible_person'] = $first_responsible_person;
|
|
|
+ //查询配置的责任人
|
|
|
+ $where_query2[] = ['city_ids', 'like', '%,' . $product_data['city_id'] . ',%'];
|
|
|
+ $where_query2[] = ['status', '=', 1];
|
|
|
+ $where_query2[] = ['duty_type', 'in', 2]; //责任类型1=第一责任人,2=责任人
|
|
|
+ $responsible_person = $EmployeeModel->where($where_query2)->pluck('id')->implode(',');
|
|
|
+ $insert_product_data['responsible_person'] = $responsible_person;
|
|
|
+ //溯源责任人
|
|
|
+ $source_responsible_person = '';
|
|
|
+ if ($first_responsible_person && $responsible_person) {
|
|
|
+ $source_responsible_person = $first_responsible_person . ',' . $responsible_person;
|
|
|
+ }
|
|
|
+ $insert_product_data['source_responsible_person'] = $source_responsible_person;
|
|
|
+ //插入数据
|
|
|
+ $ViolationStoreModel->addViolationStore($insert_product_data);
|
|
|
+ }
|
|
|
+ //继续执行下一页
|
|
|
+ $message_data['page'] = $page + 1;
|
|
|
+ $message_data['limit'] = $limit;
|
|
|
+ ViolationStoreDataJobs::dispatch($message_data);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public function failed(\Throwable $exception)
|
|
|
+ {
|
|
|
+ Log::info('job_error', '数据清洗-违规店铺清洗数据队列完全失败', ['data' => $this->message_data, 'error' => $exception]);
|
|
|
+ }
|
|
|
+}
|