services->rabbitMq->push(RabbitMqEnum::EXCHANGE_ORDER, RabbitMqEnum::ORDER_QUEUE, ['mall_id' => $mall_id], self::class, 'async'); } catch (\Exception $e) { return $e->getMessage(); } return true; } /** * @param array $params * @return bool */ public function async(array $params) { try { $mall_id = $params['mall_id']; $page = 1; while (true) { $resp = $this->req($mall_id, $page); if (!empty($resp['list']) && is_array($resp)) { $brand_ids = array_column($resp['list'], 'id'); $local_ids = QiDingDongBrand::find() ->where(['mall_id' => $mall_id]) ->andWhere(['brand_id' => $brand_ids]) ->andWhere(['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]) ->select('brand_id') ->column(); $total = count($resp['list']); foreach ($resp['list'] as $key => &$item) { if (in_array($item['id'], $local_ids)) { unset($resp['list'][$key]); continue; } $item['created_at'] = time(); $item['updated_at'] = time(); $item['mall_id'] = $mall_id; $item['brand_id'] = $item['id']; unset($item['id']); } if (!empty($resp['list'])) { QiDingDongBrand::find()->createCommand()->batchInsert(QiDingDongBrand::tableName(), array_keys($resp['list'][0]), $resp['list'])->execute(); } if ($total == 100) { $page++; } else { break; } } else { break; } } } catch (\Exception $e) { \Yii::error(FormatHelper::exception($e, __METHOD__)); return false; } return true; } /** * @param int $mall_id * @param int $page * @return array|int|string * @throws \Exception */ public function req(int $mall_id, int $page) { $contentModel = RequestHelper::contentModelInstance($mall_id); $contentModel->content->data = new BrandModel(); $contentModel->content->data->device = QiDingDongEnums::REQUEST_PARAMS_DEVICE; // 固定值 $contentModel->content->data->page = $page; // 固定值 $contentModel->content->data->page_size = 100; // 固定值 return RequestHelper::send(new BrandRequest(), RequestHelper::enCrypto($contentModel, $mall_id), $mall_id); } }