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'] : 1000; $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; $is_admin = isset($this->message_data['is_admin']) ? $this->message_data['is_admin'] : 0; $company_id = isset($this->message_data['company_id']) ? $this->message_data['company_id'] : 0; $product_data = isset($this->message_data['product_data']) ? $this->message_data['product_data'] : []; $index_number = isset($this->message_data['index_number']) ? $this->message_data['index_number'] : 0; $data_totle = isset($this->message_data['data_totle']) ? $this->message_data['data_totle'] : 0; if ($page == 1) { $ExecuteLogModel = new ExecuteLogModel(); $insert_data = ['company_id' => $company_id, 'name' => '低价挂网商品', 'code' => 'LowPriceGoodsJobs', 'admin_id' => $admin_id, 'is_admin' => $is_admin]; $executeLog_id = $ExecuteLogModel->addExecuteLog_content($insert_data); } $ConfigLowPriceGoodsModel = $ConfigLowPriceGoodsModel->leftjoin('washconfig_product_category', 'washconfig_product_category.id', '=', 'washconfig_lowprice_product.category_id') ->where(['washconfig_lowprice_product.status' => 0]) ->select(['washconfig_lowprice_product.*', 'washconfig_product_category.name as category_name']); if ($company_id) { $ConfigLowPriceGoodsModel = $ConfigLowPriceGoodsModel->where('washconfig_lowprice_product.company_id', $company_id); } $list_config_data = $ConfigLowPriceGoodsModel->with(['product_keyword'])->paginate($limit, ['*'], 'page', $page)->toarray(); if (!$list_config_data || empty($list_config_data['data'])) { if ($page == 1 && $executeLog_id) { $ExecuteLogModel->where('id', $executeLog_id)->update(['status' => 0, 'update_time' => time()]); } 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_company.company_type', 1) ->join('washconfig_violation_company', 'washconfig_violation_company.id', '=', 'washconfig_lowprice_product_company.company_id') ->select(['washconfig_violation_company.id', 'washconfig_violation_company.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 = [ 'company_id' => $value['company_id'], 'id' => $value['id'], 'platform' => $value['platform'], 'product_name' => $value['product_name'], 'enable_full_quantity' => $value['enable_full_quantity'], 'product_specs' => $value['product_specs'], 'suggested_price' => $value['suggested_price'], 'ultra_low_price' => $value['ultra_low_price'], 'store_scope' => $value['store_scope'], 'company_scope' => $value['company_scope'], 'social_credit_code' => $social_credit_code, 'executeLog_id' => $executeLog_id, 'category_name' => $value['category_name'] ? $value['category_name'] : '', 'specify_responsible_person' => $value['specify_responsible_person'], 'product_brand' => $value['product_brand'], 'product_keyword' => $value['product_keyword'], 'product_data' => $product_data, 'index_number' => $index_number, 'data_totle' => $data_totle, ]; LowPriceGoodsDataJobs::dispatch($message_data); // LowPriceGoodsDataJobs::dispatchSync($message_data); } $now_message_data = [ 'limit' => $limit, 'page' => $page + 1, 'executeLog_id' => $executeLog_id, ]; LowPriceGoodsJobs::dispatch($now_message_data)->delay(now()->addSeconds(1)); } 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->getMessage()]); } }