Просмотр исходного кода

feat: NG-15: 新会员注册时增加国家与语言选项.

kevin 1 год назад
Родитель
Сommit
e8e22e77e0
1 измененных файлов с 9 добавлено и 4 удалено
  1. 9 4
      backendApi/modules/v1/controllers/TransportationController.php

+ 9 - 4
backendApi/modules/v1/controllers/TransportationController.php

@@ -14,8 +14,9 @@ use yii\web\HttpException;
 
 class TransportationController extends BaseController
 {
-    public $countiesModelClass = Countries::class;
     public $modelClass = FreeTemplate::class;
+    public $countiesModelClass = Countries::class;
+    public $currencyModelClass = Currency::class;
 
     public function actionTransportation()
     {
@@ -24,11 +25,15 @@ class TransportationController extends BaseController
         // 运费列表
         $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['country_id']]['freight'] ?? 0;
-            $country['free_shipping'] = $transportation[$country['country_id']]['free_shipping'] ?? 0;
-            $country['currency_id'] = $transportation[$country['country_id']]['currency_id'] ?? 0;
+            $country['freight'] = $transportation[$country['ID']]['freight'] ?? 0;
+            $country['free_shipping'] = $transportation[$country['ID']]['free_shipping'] ?? 0;
+            $country['currency_id'] = $transportation[$country['ID']]['currency_id'] ?? 0;
+            $country['currency'] = $currencies[$transportation[$country['ID']]['currency_id']]['NAME'] ?? '';
         }
 
         return static::notice(['data' => $countries]);