|
@@ -0,0 +1,120 @@
|
|
|
|
|
+<?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\LowPriceGoods as LowPriceGoodsModel;
|
|
|
|
|
+use App\Models\Manager\Personnel\Employee as EmployeeModel;
|
|
|
|
|
+use App\Models\Api\Process\ExecuteLog as ExecuteLogModel;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 数据清洗-低价挂网商品队列
|
|
|
|
|
+ * @author 唐远望
|
|
|
|
|
+ * @version 1.0
|
|
|
|
|
+ * @date 2025-12-10
|
|
|
|
|
+ */
|
|
|
|
|
+class LowPriceGoodsDataJobs 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->getLowPriceGoodsData($this->message_data);
|
|
|
|
|
+ } catch (\Exception $e) {
|
|
|
|
|
+ Log::info('job_error', '数据清洗-低价挂网商品队列失败', ['data' => $this->message_data, 'error' => $e->getMessage()]);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 采集商品数据清洗
|
|
|
|
|
+ * @author 唐远望
|
|
|
|
|
+ * @version 1.0
|
|
|
|
|
+ * @date 2025-12-10
|
|
|
|
|
+ */
|
|
|
|
|
+ public function getLowPriceGoodsData($message_data)
|
|
|
|
|
+ {
|
|
|
|
|
+ $EmployeeModel = new EmployeeModel();
|
|
|
|
|
+ $LowPriceGoodsModel = new LowPriceGoodsModel();
|
|
|
|
|
+ $platform = $message_data['platform'];//多个平台配置
|
|
|
|
|
+ $product_name = $message_data['product_name'];//商品名称
|
|
|
|
|
+ $product_specs = $message_data['product_specs'];//商品规格
|
|
|
|
|
+ $suggested_price = $message_data['suggested_price'];//指导价格
|
|
|
|
|
+ $store_scope = $message_data['store_scope'];//店铺范围(为空时全部)
|
|
|
|
|
+ $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'],
|
|
|
|
|
+ 'product_name' => $product_data['product_name'],
|
|
|
|
|
+ 'product_specs' => $product_data['product_specs'],
|
|
|
|
|
+ 'suggested_price' => $product_data['suggested_price'],
|
|
|
|
|
+ 'online_posting_price' => $product_data['online_posting_price'],
|
|
|
|
|
+ 'online_posting_cunt' => $product_data['online_posting_cunt'],
|
|
|
|
|
+ '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;
|
|
|
|
|
+ //插入数据
|
|
|
|
|
+ $LowPriceGoodsModel->addLowPriceGoods($insert_product_data);
|
|
|
|
|
+ }
|
|
|
|
|
+ //继续执行下一页
|
|
|
|
|
+ $message_data['page'] = $page + 1;
|
|
|
|
|
+ $message_data['limit'] = $limit;
|
|
|
|
|
+ LowPriceGoodsDataJobs::dispatch($message_data);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ public function failed(\Throwable $exception)
|
|
|
|
|
+ {
|
|
|
|
|
+ Log::info('job_error', '数据清洗-低价挂网商品队列完全失败', ['data' => $this->message_data, 'error' => $exception]);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|