message_data = $message_data; } /** * Execute the job. * * @return void */ public function handle() { try { $ConfigViolationProductModel = new ConfigViolationProductModel(); $ViolationProductCompanyModel = new ViolationProductCompanyModel(); $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' => 'ViolationProductJobs', 'admin_id' => $admin_id,'is_admin' => $is_admin]; $executeLog_id=$ExecuteLogModel->addExecuteLog_content($insert_data); } $ConfigViolationProductModel = $ConfigViolationProductModel->leftjoin('washconfig_product_category', 'washconfig_product_category.id', '=', 'washconfig_violation_product.category_id') ->where('washconfig_violation_product.status', 0) ->select(['washconfig_violation_product.*', 'washconfig_product_category.name as category_name']); if($company_id){ $ConfigViolationProductModel = $ConfigViolationProductModel->where('washconfig_violation_product.company_id', $company_id); } $list_config_data = $ConfigViolationProductModel->with(['product_keyword'])->paginate($limit, ['*'], 'page', $page)->toarray(); $last_page = $list_config_data['last_page']; 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 = $ViolationProductCompanyModel->where('washconfig_violation_product_company.violation_product_logid', $value['id']) ->where('washconfig_violation_company.company_type', 1) ->join('washconfig_violation_company', 'washconfig_violation_company.id', '=', 'washconfig_violation_product_company.company_id') ->select(['washconfig_violation_company.id', 'washconfig_violation_company.social_credit_code', 'washconfig_violation_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'], '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, ]; // ViolationProductDataJobs::dispatch($message_data); ViolationProductDataJobs::dispatchSync($message_data); } if ($page < $last_page) { $now_message_data=$this->message_data; $now_message_data['page'] = $page + 1; $now_message_data['limit'] =$limit; $now_message_data['executeLog_id'] = $executeLog_id; ViolationProductJobs::dispatch($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->getMessage()]); } }