Przeglądaj źródła

feat: EK-2086: Member Portal : Dashboard Article and Ad only show self country.

kevin 3 miesięcy temu
rodzic
commit
6e0b9f1bf9

+ 1 - 0
backendApi/modules/v1/controllers/ArticleController.php

@@ -174,6 +174,7 @@ class ArticleController extends BaseController
         }
         // 获取全部分类
         $allCategory = ArticleCategory::getAllCategory();
+        
         return static::notice(['oneData'=>$oneData, 'allCategory'=>$allCategory]);
     }
 

+ 16 - 5
backendApi/modules/v1/models/lists/ad/AdIndexList.php

@@ -24,13 +24,24 @@ class AdIndexList extends \common\libs\dataList\DataList implements DataListInte
     {
         $this->condition .= '';
         $this->listData = Ad::lists($this->condition, $this->params, [
-            'select' => 'AD.*,ADC.NAME AS COUNTRY_NAME, ADC.CODE AS COUNTRY_CODE',
+            'select' => 'AD.*',
             'from' => Ad::tableName().' AS AD',
-            'join' => [
-                ['INNER JOIN', Countries::tableName() . ' AS ADC', 'ADC.ID=AD.COUNTRY_ID'],
-            ],
             'orderBy' => 'AD.STATUS DESC,AD.SORT DESC,AD.CREATED_AT ASC',
         ]);
+
+        // COUNTRY_ID是逗号分割的ID,需要提取国家名称、CODE
+        foreach($this->listData as $key => $row){
+            $countryIds = explode(',', $row['COUNTRY_ID']);
+            $countryNames = [];
+            $countryCodes = [];
+            foreach($countryIds as $countryId){
+                $country = Countries::findOneAsArray('ID=:ID', [':ID'=>$countryId], 'NAME,CODE');
+                $countryNames[] = $country['NAME'];
+                $countryCodes[] = $country['CODE'];
+            }
+            $this->listData[$key]['COUNTRY_NAME'] = implode(',', $countryNames);
+            $this->listData[$key]['COUNTRY_CODE'] = implode(',', $countryCodes);
+        }
     }
 
     public function getColumn(){
@@ -43,6 +54,7 @@ class AdIndexList extends \common\libs\dataList\DataList implements DataListInte
                     'headerOther' => ['width' => '150'],
                 ],
                 'COUNTRY_NAME' => null,
+                'COUNTRY_CODE' => null,
                 'LID' => [
                     'header' => '广告位',
                     'value' => function($row){
@@ -83,7 +95,6 @@ class AdIndexList extends \common\libs\dataList\DataList implements DataListInte
             $this->filterTypes = [
                 'TITLE'=> ['name'=> Yii::t('ctx', 'title')],
                 'CONTENT' => ['name'=> Yii::t('ctx', 'content')],
-                // 确保这里的键名与getColumn()方法中的列名一致
                 'COUNTRY'=> [
                     'name'=> \Yii::t('ctx', 'country'),
                     'other'=> 'select',

+ 1 - 0
common/models/Ad.php

@@ -15,6 +15,7 @@ use common\libs\logging\operate\valueType\Config as ValueTypeConfig;
  * @property int $TYPE 类型
  * @property string $LID 广告位ID
  * @property string $CONTENT 内容
+ * @property string $COUNTRY_ID 国家ID
  * @property int $SORT 排序
  * @property int $STATUS 状态
  * @property string $CREATE_ADMIN 创建管理员

+ 4 - 2
common/models/forms/AdForm.php

@@ -25,6 +25,7 @@ class AdForm extends Model
     public $content;
     public $sort;
     public $status;
+    public $countries;
 
     private $_adModel;
 
@@ -41,8 +42,8 @@ class AdForm extends Model
     public function rules()
     {
         return [
-            [['id', 'title', 'image', 'type', 'lid', 'content', 'sort', 'status'], 'trim'],
-            [['id', 'title', 'image', 'type', 'lid', 'content', 'sort', 'status'], 'required'],
+            [['id', 'title', 'image', 'type', 'lid', 'content', 'sort', 'status', 'countries'], 'trim'],
+            [['id', 'title', 'image', 'type', 'lid', 'content', 'sort', 'status', 'countries'], 'required'],
 //            [['image'], 'url'],
             [['id'], 'exist', 'targetClass'=>Ad::class, 'targetAttribute'=>'ID'],
             [['id'], 'initModel'],
@@ -140,6 +141,7 @@ class AdForm extends Model
             $model->TYPE = $this->type;
             $model->LID = $this->lid;
             $model->CONTENT = $this->content;
+            $model->COUNTRIES = $this->countries;
             $model->STATUS = 1;
             if(!$model->save()){
                 throw new Exception(Form::formatErrorsForApi($model->getErrors()));

+ 7 - 7
common/models/forms/ArticleForm.php

@@ -18,7 +18,7 @@ class ArticleForm extends Model
     public $cid;
     public $sort;
     public $content;
-    public $countryId;
+    public $countries;
 
     /**
      * @inheritdoc
@@ -27,8 +27,8 @@ class ArticleForm extends Model
     {
         return [
             [['id', 'title', 'cid', 'content'], 'trim'],
-            [['id', 'title', 'cid', 'content', 'countryId'], 'required'],
-            [['countryId'], 'string'],
+            [['id', 'title', 'cid', 'content', 'countries'], 'required'],
+            [['countries'], 'string'],
             [['id'], 'exist', 'targetClass'=>Article::class, 'targetAttribute'=>'ID'],
             [['cid'], 'exist', 'targetClass'=>ArticleCategory::class, 'targetAttribute'=>'ID'],
         ];
@@ -42,7 +42,7 @@ class ArticleForm extends Model
             'cid' => 'Type', // 分类
             'content' => 'Content', // 内容
             'sort' => 'Sort', // 排序
-            'countryId' => 'Country', // 国家
+            'countries' => 'Country', // 国家
         ];
     }
 
@@ -54,8 +54,8 @@ class ArticleForm extends Model
     {
         $parentScenarios =  parent::scenarios();
         $customScenarios = [
-            'add' => ['title', 'cid', 'content', 'sort', 'countryId'],
-            'edit' => ['id','title', 'cid', 'content', 'sort', 'countryId'],
+            'add' => ['title', 'cid', 'content', 'sort', 'countries'],
+            'edit' => ['id','title', 'cid', 'content', 'sort', 'countries'],
             'sort' => ['id', 'sort'],
         ];
         return array_merge($parentScenarios, $customScenarios);
@@ -91,7 +91,7 @@ class ArticleForm extends Model
             $model->CONTENT = '';
             $model->STATUS = 1;
             $model->SORT = $this->sort;
-            $model->COUNTRY_ID = $this->countryId;
+            $model->COUNTRY_ID = $this->countries;
             if(!$model->save()){
                 throw new Exception(Form::formatErrorsForApi($model->getErrors()));
             }