countiesModelClass::getFromCache(); // 运费列表 $transportation = $this->modelClass::getFromCache(); $transportation = array_column($transportation, NULL, 'country_id'); // 货币列表 $currencies = $this->currencyModelClass::getFromCache(); $currencies = array_column($currencies, NULL, 'ID'); foreach ($countries as &$country) { $country['freight'] = $transportation[$country['ID']]['freight'] ?? 0; $country['free_shipping'] = $transportation[$country['ID']]['free_shipping'] ?? 0; $country['currency'] = $this->currencyModelClass::getById($country['LOCAL_CURRENCY_ID']); } return static::notice(['data' => $countries]); } public function actionSetTransportation() { if (\Yii::$app->request->isPost) { $formModel = new FreeTemplateForm(); $formModel->scenario = 'setTransportation'; if ($formModel->load(\Yii::$app->request->post(), '') && $formModel->setTransportation()) { // 更新缓存 $this->modelClass::updateToCache(); return static::notice(\Yii::t('ctx', 'successfully')); } else { return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400); } } return static::notice(\Yii::t('ctx', 'illegalRequest')); } }