浏览代码

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

kevin 1 年之前
父节点
当前提交
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]);