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

Merge branch 'feature/2806-1'

# Conflicts:
#	backendApi/modules/v1/controllers/AdController.php
#	backendApi/modules/v1/controllers/ArticleController.php
#	frontendApi/config/params.php
#	frontendApi/modules/v1/controllers/ArticleController.php
#	frontendApi/modules/v1/controllers/DashboardController.php
ryan 1 день назад
Родитель
Сommit
a8fdac08d3

+ 2 - 0
backendApi/config/params.php

@@ -14,6 +14,7 @@ return [
         'v1/site/send-notify',
         'v1/site/languages',
         'v1/ad/sort',
+        'v1/article/sort',
         'v1/article/detail',
         'v1/admin/change-language',
         'v1/bonus/auto-calc',
@@ -83,6 +84,7 @@ return [
         'article/upload',
         'site/send-notice',
         'ad/sort',
+        'article/sort',
         'demo/payments',
         'demo/ipayments',
         'article/detail',

+ 2 - 0
backendApi/config/urlManagerRules.php

@@ -542,6 +542,7 @@ return [
             'GET category-sort' => 'category-sort',
             'POST upload' => 'upload',
             'GET sort' => 'sort',
+            'GET country' => 'country',
         ],
     ],
     [
@@ -559,6 +560,7 @@ return [
             'GET sort' => 'sort',
             'GET status' => 'status',
             'POST upload' => 'upload',
+            'GET country' => 'country',
         ],
     ],
     [

+ 110 - 18
backendApi/modules/v1/controllers/AdController.php

@@ -7,11 +7,13 @@
  */
 namespace backendApi\modules\v1\controllers;
 
+
 use backendApi\modules\v1\models\Admin;
 use backendApi\modules\v1\models\AdminCountry;
+use backendApi\modules\v1\models\lists\ad\AdIndexList;
 use common\helpers\Cache;
 use common\helpers\Form;
-use common\helpers\Log;
+use common\helpers\LoggerTool;
 use common\models\Ad;
 use common\models\AdLocation;
 use common\models\Article;
@@ -56,7 +58,11 @@ class AdController extends BaseController
      */
     public function actionList()
     {
-        $lid = Yii::$app->request->get('lid');
+        // 获取位置ID
+        $lid = Yii::$app->request->get('lid', 0);
+        if (empty($lid)) {
+            throw new \yii\web\HttpException(400, Yii::t('ctx', 'paramError'));
+        }
 
         // 如果admin不是超管,只允许查询自己关联的国家
         $admin = Admin::findOne(Yii::$app->user->id);
@@ -75,29 +81,37 @@ class AdController extends BaseController
         }
 
         $filter = $this->filterCondition([
-            'TITLE' => 'TITLE',
-            'COUNTRY_ID' => 'COUNTRY_ID',
+            'TITLE' => 'AD.TITLE',
+            'COUNTRY_ID' => 'AD.COUNTRY_ID',
+            'STATUS' => 'AD.STATUS',
         ]);
         $condition = $filter['condition'];
         $params = $filter['params'];
 
         $condition .= ' AND AD.LID=:LID';
-        $params[':LID']=$lid;
-        $data = Ad::lists($condition, $params, [
-            'select' => 'AD.*,ADC.NAME AS COUNTRY_NAME, ADC.CODE AS COUNTRY_CODE',
-            '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',
-        ]);
+        $params[':LID'] = $lid;
+
+        $countryIds = array_column($countries, 'ID');
+        if (!empty($countryIds)) {
+            $placeholders = [];
+            foreach ($countryIds as $key => $id) {
+                $paramName = ':countryId_' . $key;
+                $placeholders[] = $paramName;
+                $params[$paramName] = $id;
+            }
+            $condition .= ' AND AD.COUNTRY_ID IN (' . implode(',', $placeholders) . ')';
+        }
+
+        $obj = new AdIndexList();
+        // 直接获取完整的数据,包括columnsShow和filterTypes
+        $data = $obj->getList(['condition' => $condition, 'params' => $params]);
 
+        // 添加额外数据
         $data['allLocation'] = AdLocation::getAllLocation();
         $data['countries'] = $countries;
         $data['allArticle'] = Article::find()
             ->from(['ART' => Article::tableName()])
             ->select('ART.ID,ART.TITLE')
-            ->where(['ART.STATUS' => 1])
             ->andFilterWhere(['ART.COUNTRY_ID' => array_column($countries, 'ID')])
             ->asArray()
             ->all();
@@ -119,9 +133,37 @@ class AdController extends BaseController
         }
         // 获取全部分类
         $allLocation = AdLocation::getAllLocation();
-        $allArticle = Article::findAllAsArray();
+        
+        // 管理员关联国家的文章
+        $admin = Admin::findOne(Yii::$app->user->id);
+        $roleId = $admin->ROLE_ID;
+        if ($roleId == \Yii::$app->params['superAdminRoleId']) {
+            $countries = Countries::find()->asArray()->all();
+        } else {
+            // 关联国家
+            $countries = Countries::find()
+                ->select('COU.ID, COU.CODE, COU.NAME')
+                ->from(['COU' => Countries::tableName()])
+                ->join('INNER JOIN', AdminCountry::tableName() . ' AS ADL', 'ADL.COUNTRY_ID = COU.ID')
+                ->where(['ADL.ADMIN_ID' => $admin->ID])
+                ->asArray()
+                ->all();
+        }
 
-        return static::notice(['allLocation'=>$allLocation, 'allArticle' => $allArticle]);
+        // 关联文章,关联国家表
+        $allArticle = Article::find()
+            ->from(['ART' => Article::tableName()])
+            ->leftJoin(['COU' => Countries::tableName()], 'COU.ID = ART.COUNTRY_ID')
+            ->select('ART.ID,ART.TITLE,ART.COUNTRY_ID,COU.NAME AS COUNTRY_NAME')
+            ->andFilterWhere(['ART.COUNTRY_ID' => array_column($countries, 'ID')])
+            ->asArray()
+            ->all();
+
+        return static::notice([
+            'allLocation'=>$allLocation, 
+            'allArticle' => $allArticle,
+            'countries' => $countries,
+        ]);
     }
 
     /**
@@ -140,8 +182,38 @@ class AdController extends BaseController
         $oneData = Ad::findOneAsArray(['ID'=>$id]);
         // 获取全部分类
         $allLocation = AdLocation::getAllLocation();
-        $allArticle = Article::findAllAsArray();
-        return static::notice(['oneData'=>$oneData, 'allLocation'=>$allLocation, 'allArticle' => $allArticle]);
+
+        // 管理员关联国家的文章
+        $admin = Admin::findOne(Yii::$app->user->id);
+        $roleId = $admin->ROLE_ID;
+        if ($roleId == \Yii::$app->params['superAdminRoleId']) {
+            $countries = Countries::find()->asArray()->all();
+        } else {
+            // 关联国家
+            $countries = Countries::find()
+                ->select('COU.ID, COU.CODE, COU.NAME')
+                ->from(['COU' => Countries::tableName()])
+                ->join('INNER JOIN', AdminCountry::tableName() . ' AS ADL', 'ADL.COUNTRY_ID = COU.ID')
+                ->where(['ADL.ADMIN_ID' => $admin->ID])
+                ->asArray()
+                ->all();
+        }
+
+        // 关联文章,关联国家表
+        $allArticle = Article::find()
+            ->from(['ART' => Article::tableName()])
+            ->leftJoin(['COU' => Countries::tableName()], 'COU.ID = ART.COUNTRY_ID')
+            ->select('ART.ID,ART.TITLE,ART.COUNTRY_ID,COU.NAME AS COUNTRY_NAME')
+            ->andFilterWhere(['ART.COUNTRY_ID' => array_column($countries, 'ID')])
+            ->asArray()
+            ->all();
+
+        return static::notice([
+            'oneData' => $oneData, 
+            'allLocation' => $allLocation, 
+            'allArticle' => $allArticle,
+            'countries' => $countries,
+        ]);
     }
 
     /**
@@ -244,4 +316,24 @@ class AdController extends BaseController
             return static::notice($token);
         }
     }
+
+    public function actionCountry()
+    {
+        $admin = Admin::findOne(Yii::$app->user->id);
+        $roleId = $admin->ROLE_ID;
+        if ($roleId == \Yii::$app->params['superAdminRoleId']) {
+            $countries = Countries::find()->asArray()->all();
+        } else {
+            // 关联国家
+            $countries = Countries::find()
+                ->select('COU.ID, COU.CODE, COU.NAME')
+                ->from(['COU' => Countries::tableName()])
+                ->join('INNER JOIN', AdminCountry::tableName() . ' AS ADL', 'ADL.COUNTRY_ID = COU.ID')
+                ->where(['ADL.ADMIN_ID' => $admin->ID])
+                ->asArray()
+                ->all();
+        }
+
+        return static::notice($countries);
+    }
 }

+ 104 - 10
backendApi/modules/v1/controllers/ArticleController.php

@@ -7,6 +7,9 @@
  */
 namespace backendApi\modules\v1\controllers;
 
+use backendApi\modules\v1\models\Admin;
+use backendApi\modules\v1\models\AdminCountry;
+use backendApi\modules\v1\models\lists\article\IndexList;
 use common\helpers\Cache;
 use common\helpers\Form;
 use common\models\Article;
@@ -86,17 +89,43 @@ class ArticleController extends BaseController
      */
     public function actionIndex()
     {
+        // 如果admin不是超管,只允许查询自己关联的国家
+        $admin = Admin::findOne(Yii::$app->user->id);
+        $roleId = $admin->ROLE_ID;
+        if ($roleId == \Yii::$app->params['superAdminRoleId']) {
+            $countries = Countries::find()->asArray()->all();
+        } else {
+            // 关联国家
+            $countries = Countries::find()
+                ->select('COU.ID, COU.CODE, COU.NAME')
+                ->from(['COU' => Countries::tableName()])
+                ->join('INNER JOIN', AdminCountry::tableName() . ' AS ADL', 'ADL.COUNTRY_ID = COU.ID')
+                ->where(['ADL.ADMIN_ID' => $admin->ID])
+                ->asArray()
+                ->all();
+        }
+
         $filter = $this->filterCondition([
-            'TITLE' => 'TITLE',
-            'COUNTRY_ID' => 'COUNTRY_ID',
+            'TITLE' => 'ART.TITLE',
+            'COUNTRY_ID' => 'ART.COUNTRY_ID',
+            'STATUS' => 'ART.STATUS',
         ]);
         $condition = $filter['condition'];
         $params = $filter['params'];
 
-        $data = Article::lists($condition, $params, [
-            'select' => 'ID,TITLE,CID,COUNTRY_ID,STATUS,SORT,CREATED_AT',
-            'orderBy' => 'SORT ASC,CREATED_AT DESC',
-        ]);
+        $countryIds = array_column($countries, 'ID');
+        if (!empty($countryIds)) {
+            $placeholders = [];
+            foreach ($countryIds as $key => $id) {
+                $paramName = ':countryId_' . $key;
+                $placeholders[] = $paramName;
+                $params[$paramName] = $id;
+            }
+            $condition .= ' AND ART.COUNTRY_ID IN (' . implode(',', $placeholders) . ')';
+        }
+
+        $obj = new IndexList();
+        $data = $obj->getList(['condition' => $condition, 'params' => $params]);
 
         // 全部分类
         $data['allCategory'] = ArticleCategory::getAllCategory();
@@ -118,7 +147,26 @@ class ArticleController extends BaseController
         // 获取全部分类
         $allCategory = ArticleCategory::find()->where('STATUS=1')->asArray()->all();
 
-        return static::notice(['allCategory'=>$allCategory]);
+        // 管理员关联国家
+        $admin = Admin::findOne(Yii::$app->user->id);
+        $roleId = $admin->ROLE_ID;
+        if ($roleId == \Yii::$app->params['superAdminRoleId']) {
+            $countries = Countries::find()->asArray()->all();
+        } else {
+            // 关联国家
+            $countries = Countries::find()
+                ->select('COU.ID, COU.CODE, COU.NAME')
+                ->from(['COU' => Countries::tableName()])
+                ->join('INNER JOIN', AdminCountry::tableName() . ' AS ADL', 'ADL.COUNTRY_ID = COU.ID')
+                ->where(['ADL.ADMIN_ID' => $admin->ID])
+                ->asArray()
+                ->all();
+        }
+
+        return static::notice([
+            'allCategory' => $allCategory,
+            'countries' => $countries,
+        ]);
     }
 
     /**
@@ -145,7 +193,28 @@ class ArticleController extends BaseController
         }
         // 获取全部分类
         $allCategory = ArticleCategory::getAllCategory();
-        return static::notice(['oneData'=>$oneData, 'allCategory'=>$allCategory]);
+        
+        // 管理员关联国家
+        $admin = Admin::findOne(Yii::$app->user->id);
+        $roleId = $admin->ROLE_ID;
+        if ($roleId == \Yii::$app->params['superAdminRoleId']) {
+            $countries = Countries::find()->asArray()->all();
+        } else {
+            // 关联国家
+            $countries = Countries::find()
+                ->select('COU.ID, COU.CODE, COU.NAME')
+                ->from(['COU' => Countries::tableName()])
+                ->join('INNER JOIN', AdminCountry::tableName() . ' AS ADL', 'ADL.COUNTRY_ID = COU.ID')
+                ->where(['ADL.ADMIN_ID' => $admin->ID])
+                ->asArray()
+                ->all();
+        }
+        
+        return static::notice([
+            'oneData' => $oneData, 
+            'allCategory' => $allCategory, 
+            'countries' => $countries
+        ]);
     }
 
     /**
@@ -228,8 +297,13 @@ class ArticleController extends BaseController
             $formModel->scenario = 'article';
             $formModel->file = UploadedFile::getInstanceByName('file');
             $formModel->token = \Yii::$app->request->request('uploadToken');;
-            if($formModel->file && $uploader = $formModel->upload()){
-                return static::notice($uploader->FILE_NAME);
+            if($formModel->file && ($uploader = $formModel->upload()) !== false){
+                if (is_object($uploader) && isset($uploader->FILE_NAME)) {
+                    return static::notice($uploader->FILE_NAME);
+                } else {
+                    // 处理非对象返回值的情况
+                    return static::notice('Upload successful');
+                }
             } else {
                 return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
             }
@@ -256,4 +330,24 @@ class ArticleController extends BaseController
             }
         }
     }
+
+    public function actionCountry()
+    {
+        $admin = Admin::findOne(Yii::$app->user->id);
+        $roleId = $admin->ROLE_ID;
+        if ($roleId == \Yii::$app->params['superAdminRoleId']) {
+            $countries = Countries::find()->asArray()->all();
+        } else {
+            // 关联国家
+            $countries = Countries::find()
+                ->select('COU.ID, COU.CODE, COU.NAME')
+                ->from(['COU' => Countries::tableName()])
+                ->join('INNER JOIN', AdminCountry::tableName() . ' AS ADL', 'ADL.COUNTRY_ID = COU.ID')
+                ->where(['ADL.ADMIN_ID' => $admin->ID])
+                ->asArray()
+                ->all();
+        }
+
+        return static::notice($countries);
+    }
 }

+ 136 - 0
backendApi/modules/v1/models/lists/ad/AdIndexList.php

@@ -0,0 +1,136 @@
+<?php
+namespace backendApi\modules\v1\models\lists\ad;
+
+use backendApi\modules\v1\models\Admin;
+use backendApi\modules\v1\models\AdminCountry;
+use common\helpers\LoggerTool;
+use common\libs\dataList\DataListInterface;
+use common\models\Ad;
+use common\models\AdLocation;
+use common\models\Countries;
+use common\libs\dataList\column\DateTime;
+use Yii;
+
+class AdIndexList extends \common\libs\dataList\DataList implements DataListInterface
+{
+    /**
+     * 列表名称
+     * @return string
+     */
+    public function getListName(){
+        return '广告列表';
+    }
+
+    public function dataHandle()
+    {
+        $this->condition .= '';
+        $this->listData = Ad::lists($this->condition, $this->params, [
+            'select' => 'AD.*,ADC.NAME AS COUNTRY_NAME, ADC.CODE AS COUNTRY_CODE',
+            '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 DESC',
+        ]);
+    }
+
+    public function getColumn(){
+        if(!$this->columns){
+            $this->columns = [
+                'ID' => null,
+                'TITLE' => [
+                    'header' => Yii::t('ctx', 'title'),
+                ],
+                'COUNTRY_ID' => [
+                    'header' => Yii::t('ctx', 'country'),
+                    'headerOther' => ['width' => '150'],
+                ],
+                'COUNTRY_NAME' => null,
+                'COUNTRY_CODE' => null,
+                'LID' => [
+                    'header' => '广告位',
+                    'value' => function($row){
+                        $adLocation = AdLocation::findOneAsArray('ID=:ID', [':ID'=>$row['LID']], 'LOCATION_NAME');
+                        return $adLocation['LOCATION_NAME'];
+                    },
+                    'headerOther' => ['width' => '180'],
+                ],
+                'STATUS' => [
+                    'header' => Yii::t('ctx', 'status'),
+                    'headerOther' => ['width' => '100'],
+                ],
+                'CONTENT' => [
+                    'header' => Yii::t('ctx', 'content'),
+                ],
+                'TYPE' => null,
+                'SORT' => null,
+                'CREATED_AT' => [
+                    'header' => Yii::t('ctx', 'createTime'),
+                    'value' => function($row) {
+                        return (new DateTime([
+                            'value' => $row['CREATED_AT'],
+                        ]))->result();
+                    },
+                    'headerOther' => ['width' => '180'],
+                ],
+            ];
+        }
+
+        return $this->columns;
+    }
+
+    /**
+     * 前台用于筛选的类型集合
+     * @return mixed
+     */
+    public function getFilterTypes()
+    {
+        if (!$this->filterTypes) {
+            $this->filterTypes = [
+                'TITLE'=> ['name'=> Yii::t('ctx', 'title')],
+                // 'CONTENT' => ['name'=> Yii::t('ctx', 'content')],
+                'COUNTRY_ID'=> [
+                    'name'=> \Yii::t('ctx', 'country'),
+                    'other'=> 'select',
+                    'selectData'=> self::getCountry()
+                ],
+                'STATUS'=> [
+                    'name'=> Yii::t('ctx', 'status'),
+                    'other'=> 'select',
+                    'selectData'=> [
+                        ['id'=> 0, 'name'=> Yii::t('ctx', 'Hide')],
+                        ['id'=> 1, 'name'=> Yii::t('ctx', 'Show')]
+                    ]
+                ],
+            ];
+        }
+        return $this->filterTypes;
+    }
+
+    public function getCountry()
+    {
+        $admin = Admin::findOne(Yii::$app->user->id);
+        $roleId = $admin->ROLE_ID;
+        if ($roleId == \Yii::$app->params['superAdminRoleId']) {
+            $countries = Countries::find()->asArray()->all();
+        } else {
+            $countries = Countries::find()
+                ->select('COU.ID, COU.CODE, COU.NAME')
+                ->from(['COU' => Countries::tableName()])
+                ->join('INNER JOIN', AdminCountry::tableName() . ' AS ADL', 'ADL.COUNTRY_ID = COU.ID')
+                ->where(['ADL.ADMIN_ID' => $admin->ID])
+                ->asArray()
+                ->all();
+        }
+
+        $data = [];
+        foreach ($countries as $country) {
+            $data[] = [
+                'id' => $country['ID'],
+                'name' => $country['NAME'],
+            ];
+        }
+
+        return $data;
+    }
+}

+ 123 - 0
backendApi/modules/v1/models/lists/article/IndexList.php

@@ -0,0 +1,123 @@
+<?php
+namespace backendApi\modules\v1\models\lists\article;
+
+use backendApi\modules\v1\models\Admin;
+use backendApi\modules\v1\models\AdminCountry;
+use common\libs\dataList\DataListInterface;
+use common\models\Article;
+use common\models\Countries;
+use common\libs\dataList\column\DateTime;
+use Yii;
+
+class IndexList extends \common\libs\dataList\DataList implements DataListInterface
+{
+    /**
+     * 列表名称
+     * @return string
+     */
+    public function getListName(){
+        return '文章列表';
+    }
+
+    public function dataHandle()
+    {
+        $this->condition .= '';
+        $this->listData = Article::lists($this->condition, $this->params, [
+            'select' => 'ART.ID,ART.TITLE,ART.CID,ART.COUNTRY_ID,ART.STATUS,ART.SORT,ART.CREATED_AT,,ADC.NAME AS COUNTRY_NAME, ADC.CODE AS COUNTRY_CODE',
+            'from' => Article::tableName().' AS ART',
+            'join' => [
+                ['INNER JOIN', Countries::tableName() . ' AS ADC', 'ADC.ID=ART.COUNTRY_ID'],
+            ],
+            'orderBy' => 'ART.STATUS DESC, ART.SORT DESC, ART.CREATED_AT DESC',
+        ]);
+    }
+
+    public function getColumn(){
+        if(!$this->columns){
+            $this->columns = [
+                'ID' => null,
+                'TITLE' => [
+                    'header' => Yii::t('ctx', 'title'),
+                ],
+                'CID' => [
+                    'header' => Yii::t('ctx', 'category'),
+                    'headerOther' => ['width' => '150'],
+                ],
+                'COUNTRY_ID' => [
+                    'header' => Yii::t('ctx', 'country'),
+                    'headerOther' => ['width' => '150'],
+                ],
+                'COUNTRY_NAME' => null,
+                'STATUS' => [
+                    'header' => Yii::t('ctx', 'status'),
+                    'headerOther' => ['width' => '100'],
+                ],
+                'SORT' => null,
+                'CREATED_AT' => [
+                    'header' => Yii::t('ctx', 'createTime'),
+                    'value' => function($row) {
+                        return (new DateTime([
+                            'value' => $row['CREATED_AT'],
+                        ]))->result();
+                    },
+                    'headerOther' => ['width' => '180'],
+                ],
+            ];
+        }
+        return $this->columns;
+    }
+
+    /**
+     * 前台用于筛选的类型集合
+     * @return mixed
+     */
+    public function getFilterTypes()
+    {
+        if (!$this->filterTypes) {
+            $this->filterTypes = [
+                'TITLE'=> ['name'=> Yii::t('ctx', 'title')],
+                'COUNTRY_ID'=> [
+                    'name'=> \Yii::t('ctx', 'country'),
+                    'other'=> 'select',
+                    'selectData'=> self::getCountry()
+                ],
+                'STATUS'=> [
+                    'name'=> Yii::t('ctx', 'status'),
+                    'other'=> 'select',
+                    'selectData'=> [
+                        ['id'=> 0, 'name'=> Yii::t('ctx', 'Hide')],
+                        ['id'=> 1, 'name'=> Yii::t('ctx', 'Show')]
+                    ]
+                ],
+            ];
+        }
+        return $this->filterTypes;
+    }
+
+    public function getCountry()
+    {
+        $admin = Admin::findOne(Yii::$app->user->id);
+        $roleId = $admin->ROLE_ID;
+        if ($roleId == \Yii::$app->params['superAdminRoleId']) {
+            $countries = Countries::find()->asArray()->all();
+        } else {
+            $countries = Countries::find()
+                ->select('COU.ID, COU.CODE, COU.NAME')
+                ->from(['COU' => Countries::tableName()])
+                ->join('INNER JOIN', AdminCountry::tableName() . ' AS ADL', 'ADL.COUNTRY_ID = COU.ID')
+                ->where(['ADL.ADMIN_ID' => $admin->ID])
+                ->asArray()
+                ->all();
+        }
+
+        $data = [];
+        foreach ($countries as $country) {
+            $data[] = [
+                'id' => $country['ID'],
+                'name' => $country['NAME'],
+            ];
+        }
+
+        return $data;
+    }
+}

+ 3 - 1
common/libs/dataList/DataList.php

@@ -4,6 +4,7 @@ namespace common\libs\dataList;
 use backendApi\modules\v1\models\Admin;
 use backendApi\modules\v1\models\AdminRole;
 use common\components\Model;
+use common\helpers\LoggerTool;
 use common\helpers\Tool;
 use yii\base\Exception;
 
@@ -125,6 +126,7 @@ class DataList extends Model
         if(!$this->isExport){
             $this->getFilterTypes();
         }
+
         // 利用权限处理掉不需要的字段(只需要从$this->columns中去掉就可以)
         $userId = isset($params['userId']) && $params['userId'] ? $params['userId'] : null;
         $this->permissionColumn($userId);
@@ -419,7 +421,7 @@ class DataList extends Model
      * @throws Exception
      */
     protected function permissionColumn($userId = null){
-        return ;
+        return;
         $allRole = AdminRole::getFromCache();
         if($userId === null){
             $roleId = \Yii::$app->user->userInfo['roleId'];

+ 6 - 0
common/messages/en-US/ctx.php

@@ -414,9 +414,15 @@ return [
     #Ad
     'AdAddedSuccessfully' => 'Ad added successfully',
     'EditAdSuccessfully' => 'Ad edited successfully',
+    'Hide' => 'Hide',
+    'Show' => 'Show',
+    'Article' => 'Article',
+    'ExternalLink' => 'External Link',
+    'AdType' => 'Type',
 
     #Article
     'articleNotExists'  => 'Article does not exist',
+    'title' => 'Title',
 
     #File
     'mallManagement'    => 'Mall Management',

+ 6 - 0
common/messages/zh-CN/ctx.php

@@ -412,9 +412,15 @@ return [
     #Ad
     'AdAddedSuccessfully' => '广告添加成功',
     'EditAdSuccessfully' => '广告编辑成功',
+    'Hide' => '隐藏',
+    'Show' => '展示',
+    'Article' => '文章',
+    'ExternalLink' => '外链',
+    'AdType' => '类型',
 
     #Article
     'articleNotExists'  => '文章不存在',
+    'title' => '标题',
 
     #File
     'mallManagement'    => '商城管理',

+ 2 - 1
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 创建管理员
@@ -85,7 +86,7 @@ class Ad extends \common\components\ActiveRecord
                 'label' => '类型',
                 'type' => function($data){
                     $value = $data['value'];
-                    return $value==1?'外链':'文章';
+                    return $value==1 ? '外链' : '文章';
                 },
             ],
             'LID' => [

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

@@ -25,6 +25,7 @@ class AdForm extends Model
     public $content;
     public $sort;
     public $status;
+    public $countryId;
 
     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', 'countryId'], 'trim'],
+            [['id', 'title', 'image', 'type', 'lid', 'content', 'sort', 'status', 'countryId'], 'required'],
 //            [['image'], 'url'],
             [['id'], 'exist', 'targetClass'=>Ad::class, 'targetAttribute'=>'ID'],
             [['id'], 'initModel'],
@@ -63,6 +64,7 @@ class AdForm extends Model
             'content' => 'External link or article ID', // 链接地址或文章ID
             'sort' => 'Order', // 排序
             'status' => 'State', // 状态
+            'countryId' => 'Country', // 国家
         ];
     }
 
@@ -74,8 +76,8 @@ class AdForm extends Model
     {
         $parentScenarios =  parent::scenarios();
         $customScenarios = [
-            'add' => ['title', 'image', 'type', 'lid', 'content'],
-            'edit' => ['id', 'title', 'image', 'type', 'lid', 'content'],
+            'add' => ['title', 'image', 'type', 'lid', 'content', 'countryId'],
+            'edit' => ['id', 'title', 'image', 'type', 'lid', 'content', 'countryId'],
             'sort' => ['id','sort'],
             'status' => ['id','status'],
         ];
@@ -140,6 +142,7 @@ class AdForm extends Model
             $model->TYPE = $this->type;
             $model->LID = $this->lid;
             $model->CONTENT = $this->content;
+            $model->COUNTRY_ID = $this->countryId;
             $model->STATUS = 1;
             if(!$model->save()){
                 throw new Exception(Form::formatErrorsForApi($model->getErrors()));

+ 2 - 2
frontendApi/config/params.php

@@ -22,7 +22,7 @@ return [
         'v1/site/languages',
 //        'v1/site/countries',
         'v1/bonus/period',
-        'v1/bonus/sent-user-performance',
-        ],
+        'v1/article/detail',
+    ],
     'noCheckPermissionActions' => [],
 ];

+ 5 - 4
frontendApi/modules/v1/controllers/ArticleController.php

@@ -23,12 +23,13 @@ class ArticleController extends BaseController
      */
     public function actionIndex()
     {
-        $news=ArticleCategory::find()->select('ID,CATE_NAME')->asArray()->all();
+        $userInfo = User::getEnCodeInfo(Yii::$app->user->id);
+        $news = ArticleCategory::find()->select('ID,CATE_NAME')->asArray()->all();
         foreach ($news as &$value){
             $value['LISTS']=Article::find()
                 ->select('ID,TITLE,CID,CREATED_AT')
-                ->where('CID=:CID AND STATUS=1 AND COUNTRY_ID=:COUNTRY_ID', [':CID'=>$value['ID'], ':COUNTRY_ID'=>$baseInfo['COUNTRY_ID']])
-                ->orderBy('CREATED_AT DESC')
+                ->where('CID=:CID AND STATUS=1 AND COUNTRY_ID=:COUNTRY_ID', [':CID'=>$value['ID'], ':COUNTRY_ID'=>$userInfo['COUNTRY_ID']])
+                ->orderBy('SORT DESC, CREATED_AT DESC')
                 ->limit(5)
                 ->asArray()
                 ->all();
@@ -77,7 +78,7 @@ class ArticleController extends BaseController
             'join' => [
                 ['LEFT JOIN', ArticleCategory::tableName() . ' AS C', 'A.CID = C.ID'],
             ],
-            'orderBy' => 'A.CREATED_AT DESC',
+            'orderBy' => 'A.SORT DESC, A.CREATED_AT DESC',
             'useSlaves' => true,
         ]);
 

+ 10 - 5
frontendApi/modules/v1/controllers/DashboardController.php

@@ -42,8 +42,13 @@ class DashboardController extends BaseController
      */
     public function actionIndex(){
         $nowTime = Date::nowTime();
-        $baseInfo=Info::baseInfoZh(\Yii::$app->user->id);
-        $news=ArticleCategory::find()->select('ID,CATE_NAME')->orderBy('SORT ASC')->asArray()->all();
+        $baseInfo = Info::baseInfoZh(\Yii::$app->user->id);
+        $news = ArticleCategory::find()
+            ->select('ID,CATE_NAME')
+            ->orderBy('CREATED_AT DESC')
+            ->asArray()
+            ->all();
+
         $where = ' CID=:CID AND STATUS=1 AND COUNTRY_ID=:COUNTRY_ID';
         foreach ($news as &$value){
             $params = [
@@ -52,8 +57,8 @@ class DashboardController extends BaseController
             ];
             $value['LISTS'] = Article::find()
                 ->select('ID,TITLE,CID,CREATED_AT')
-                ->where($where,$params)
-                ->orderBy('CREATED_AT DESC')
+                ->where($where, $params)
+                ->orderBy('SORT DESC, CREATED_AT DESC')
                 ->limit(6)
                 ->asArray()
                 ->all();
@@ -132,7 +137,7 @@ class DashboardController extends BaseController
         $sliders = Ad::findUseSlaves()
             ->select('ID,IMAGE,LID,TITLE,CONTENT,TYPE')
             ->where('LID=:LID AND STATUS=1 AND COUNTRY_ID=:COUNTRY_ID', [':LID'=>'7EFF6260A16C3CC7E053693418AC03E4', ':COUNTRY_ID'=>$baseInfo['COUNTRY_ID']])
-            ->orderBy('SORT ASC')
+            ->orderBy('SORT DESC, CREATED_AT DESC')
             ->asArray()
             ->all();