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']; $resp = RequestHelper::send(new BrandRequest(), new BrandModel(), $mall_id); if (!empty($resp) && is_array($resp)) { $brand_ids = array_column($resp, 'id'); $local_ids = QiShangTongBrand::find() ->where(['mall_id' => $mall_id]) ->andWhere(['brand_id' => $brand_ids]) ->andWhere(['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]) ->select('brand_id') ->column(); foreach ($resp as $key => &$item) { if (in_array($item['id'], $local_ids)) { unset($resp[$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)) { QiShangTongBrand::find()->createCommand()->batchInsert(QiShangTongBrand::tableName(), array_keys($resp[0]), $resp)->execute(); } } } catch (\Exception $e) { \Yii::error(FormatHelper::exception($e, __METHOD__)); return false; } return true; } }