| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?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\WashConfig\LowPriceGoods as ConfigLowPriceGoodsModel;
- use App\Models\Api\Process\ExecuteLog as ExecuteLogModel;
- use App\Jobs\Manager\Process\LowPriceGoodsDataJobs;
- use App\Models\Manager\WashConfig\ViolationStore as ViolationStoreModel;
- use App\Models\Manager\WashConfig\LowPriceGoodsCompany as LowPriceGoodsCompanyModel;
- /**
- * 数据清洗-低价挂网商品配置队列
- * @author 唐远望
- * @version 1.0
- * @date 2025-12-10
- */
- class LowPriceGoodsJobs 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 {
- $ConfigLowPriceGoodsModel = new ConfigLowPriceGoodsModel();
- $LowPriceGoodsCompanyModel = new LowPriceGoodsCompanyModel();
- $limit = isset($this->message_data['limit']) ? $this->message_data['limit'] : 50;
- $page = isset($this->message_data['page']) ? $this->message_data['page'] : 1;
- $executeLog_id = isset($this->message_data['executeLog_id']) ? $this->message_data['executeLog_id'] : 0;
- $admin_id = isset($this->message_data['admin_id']) ? $this->message_data['admin_id'] : 0;
- if ($page == 1) {
- $ExecuteLogModel = new ExecuteLogModel();
- $insert_data = ['name' => '低价挂网商品', 'code' => 'LowPriceGoodsJobs', 'admin_id' => $admin_id];
- $executeLog_id = $ExecuteLogModel->addExecuteLog_content($insert_data);
- }
- $list_config_data = $ConfigLowPriceGoodsModel->where('status', 0)->paginate($limit, ['*'], 'page', $page)->toarray();
- if (!$list_config_data || empty($list_config_data['data'])) {
- return true;
- }
- $list_data = $list_config_data['data'];
- foreach ($list_data as $key => $value) {
- $company_data = $LowPriceGoodsCompanyModel->where('washconfig_lowprice_product_company.lowprice_product_logid', $value['id'])
- ->where('washconfig_violation_store.store_type', 1)
- ->join('washconfig_violation_store', 'washconfig_violation_store.id', '=', 'washconfig_lowprice_product_company.company_id')
- ->select(['washconfig_violation_store.id', 'washconfig_violation_store.social_credit_code', 'washconfig_lowprice_product_company.company_id'])->get()->toArray();
- $social_credit_code = !empty($company_data) ? array_column($company_data, 'social_credit_code') : '';
- $message_data = [
- 'id' => $value['id'],
- 'platform' => $value['platform'],
- 'product_name' => $value['product_name'],
- 'product_specs' => $value['product_specs'],
- 'suggested_price' => $value['suggested_price'],
- 'store_scope' => $value['store_scope'],
- 'company_scope' => $value['company_scope'],
- 'social_credit_code' => $social_credit_code,
- 'executeLog_id' => $executeLog_id,
- ];
- LowPriceGoodsDataJobs::dispatch($message_data);
- // LowPriceGoodsDataJobs::dispatchSync($message_data);
- }
- $now_message_data = [
- 'limit' => $limit,
- 'page' => $page + 1,
- 'executeLog_id' => $executeLog_id,
- ];
- $this->dispatchSync($now_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]);
- }
- }
|