Explorar el Código

feat: EK-2806: 会员端Promo和banner图增加分国家设置.

kevin hace 3 meses
padre
commit
173067c810

+ 41 - 7
backendApi/modules/v1/controllers/AdController.php

@@ -8,12 +8,14 @@
 namespace backendApi\modules\v1\controllers;
 
 use backendApi\modules\v1\models\Admin;
+use backendApi\modules\v1\models\AdminCountry;
 use common\helpers\Cache;
 use common\helpers\Form;
 use common\helpers\Log;
 use common\models\Ad;
 use common\models\AdLocation;
 use common\models\Article;
+use common\models\Countries;
 use common\models\forms\AdForm;
 use common\models\forms\UploadForm;
 use Yii;
@@ -52,21 +54,53 @@ class AdController extends BaseController
      * @return mixed
      * @throws \yii\web\HttpException
      */
-    public function actionList(){
+    public function actionList()
+    {
         $lid = Yii::$app->request->get('lid');
-        $condition = ' AND AD.LID=:LID';
+
+        // 如果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',
+        ]);
+        $condition = $filter['condition'];
+        $params = $filter['params'];
+
+        $condition .= ' AND AD.LID=:LID';
         $params[':LID']=$lid;
         $data = Ad::lists($condition, $params, [
-            'select' => 'AD.*,ADMC.ADMIN_NAME CREATE_ADMIN_NAME,ADMU.ADMIN_NAME UPDATE_ADMIN_NAME',
+            'select' => 'AD.*,ADC.NAME AS COUNTRY_NAME, ADC.CODE AS COUNTRY_CODE',
             'from' => Ad::tableName().' AS AD',
             'join' => [
-                ['LEFT JOIN', Admin::tableName() . ' AS ADMC', 'ADMC.ID=AD.CREATE_ADMIN'],
-                ['LEFT JOIN', Admin::tableName() . ' AS ADMU', 'ADMU.ID=AD.UPDATE_ADMIN'],
+                ['INNER JOIN', Countries::tableName() . ' AS ADC', 'ADC.ID=AD.COUNTRY_ID'],
             ],
-            'orderBy' => 'AD.SORT DESC,AD.CREATED_AT ASC',
+            'orderBy' => 'AD.STATUS DESC,AD.SORT DESC,AD.CREATED_AT ASC',
         ]);
+
         $data['allLocation'] = AdLocation::getAllLocation();
-        $data['allArticle'] = Article::find()->select('ID,TITLE')->asArray()->all();
+        $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();
 
         return static::notice($data);
     }

+ 28 - 9
backendApi/modules/v1/controllers/ArticleController.php

@@ -11,6 +11,7 @@ use common\helpers\Cache;
 use common\helpers\Form;
 use common\models\Article;
 use common\models\ArticleCategory;
+use common\models\Countries;
 use common\models\forms\ArticleCategoryForm;
 use common\models\forms\ArticleForm;
 use common\models\forms\UploadForm;
@@ -43,8 +44,9 @@ class ArticleController extends BaseController
      * @return mixed
      * @throws \yii\web\HttpException
      */
-    public function actionCategoryAdd(){
-        if(Yii::$app->request->isPost) {
+    public function actionCategoryAdd()
+    {
+        if (Yii::$app->request->isPost) {
             return parent::edit(ArticleCategoryForm::class, Yii::t('ctx', 'successfully'));
         }
     }
@@ -82,13 +84,23 @@ class ArticleController extends BaseController
      * @return mixed
      * @throws \yii\web\HttpException
      */
-    public function actionIndex(){
-        $data = Article::lists('', [], [
-            'select' => 'ID,TITLE,CID,STATUS,SORT,CREATED_AT',
+    public function actionIndex()
+    {
+        $filter = $this->filterCondition([
+            'TITLE' => 'TITLE',
+            'COUNTRY_ID' => 'COUNTRY_ID',
+        ]);
+        $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',
         ]);
+
         // 全部分类
         $data['allCategory'] = ArticleCategory::getAllCategory();
+
         return static::notice($data);
     }
 
@@ -97,12 +109,15 @@ class ArticleController extends BaseController
      * @return mixed
      * @throws \yii\web\HttpException
      */
-    public function actionAdd(){
-        if(Yii::$app->request->isPost) {
+    public function actionAdd()
+    {
+        if (Yii::$app->request->isPost) {
             return parent::edit(ArticleForm::class, Yii::t('ctx', 'successfully'));
         }
+
         // 获取全部分类
         $allCategory = ArticleCategory::find()->where('STATUS=1')->asArray()->all();
+
         return static::notice(['allCategory'=>$allCategory]);
     }
 
@@ -119,6 +134,8 @@ class ArticleController extends BaseController
         }
         $oneData = Article::findOneAsArray(['ID'=>$id]);
         $oneData['CONTENT'] = is_resource($oneData['CONTENT']) ? stream_get_contents($oneData['CONTENT']) : '';
+        // 国家
+        $oneData['COUNTRY'] = Countries::getCountry($oneData['COUNTRY_ID']);
         // 暂时先从文件中取内容
         $path = \Yii::getAlias('@common/runtime/articleContent/').$oneData['ID'];
         if(!file_exists($path)){
@@ -180,11 +197,13 @@ class ArticleController extends BaseController
         $id = \Yii::$app->request->get('id');
         $data = null;
         if($id){
-            $data = Article::findOneAsArray('ID=:ID AND STATUS=1', [':ID'=>$id], 'ID,TITLE,CID,SORT,CREATED_AT');
+            $data = Article::findOneAsArray('ID=:ID AND STATUS=1', [':ID'=>$id], 'ID,COUNTRY_ID,TITLE,CID,SORT,CREATED_AT');
+            // 国家
+            $data['COUNTRY'] = Countries::getCountry($data['COUNTRY_ID']);
         }
         if($data){
             // 暂时先从文件中取内容
-            $path = \Yii::getAlias('@common/runtime/articleContent/').$data['ID'];
+            $path = \Yii::getAlias('@common/runtime/articleContent/') . $data['ID'];
             if(!file_exists($path)){
                 $data['CONTENT'] = '';
             } else {

+ 6 - 2
backendApi/modules/v1/models/AdminCountry.php

@@ -10,6 +10,8 @@ use common\components\ActiveRecord;
  * @property string $ID
  * @property string $ADMIN_ID 管理ID
  * @property string $COUNTRY_ID 国家ID
+ * @property int $CREATED_AT 创建时间
+ * @property int $UPDATED_AT 更新时间
  */
 class AdminCountry extends ActiveRecord
 {
@@ -27,8 +29,8 @@ class AdminCountry extends ActiveRecord
     public function rules()
     {
         return [
-            [['ADMIN_ID', 'COUNTRY_ID',], 'required'],
-            [['ID', 'COUNTRY_ID'], 'string', 'max' => 32],
+            [['ADMIN_ID', 'COUNTRY_ID'], 'required'],
+            [['ID', 'ADMIN_ID', 'COUNTRY_ID'], 'string', 'max' => 50],
             [['ID'], 'unique'],
         ];
     }
@@ -42,6 +44,8 @@ class AdminCountry extends ActiveRecord
             'ID' => 'ID',
             'ADMIN_ID' => '管理ID',
             'COUNTRY_ID' => '国家ID',
+            'CREATED_AT' => '创建时间',
+            'UPDATED_AT' => '更新时间',
         ];
     }
 

+ 2 - 1
common/models/Ad.php

@@ -41,7 +41,7 @@ class Ad extends \common\components\ActiveRecord
     public function rules()
     {
         return [
-            [['TITLE', 'IMAGE', 'TYPE', 'LID', 'CREATE_ADMIN', 'CREATED_AT'], 'required'],
+            [['TITLE', 'IMAGE', 'TYPE', 'LID', 'CREATE_ADMIN', 'CREATED_AT', 'COUNTRY_ID'], 'required'],
             [['TYPE', 'SORT', 'STATUS', 'CREATED_AT', 'UPDATED_AT'], 'integer'],
             [['ID', 'LID', 'CREATE_ADMIN', 'UPDATE_ADMIN'], 'string', 'max' => 32],
             [['TITLE'], 'string', 'max' => 48],
@@ -59,6 +59,7 @@ class Ad extends \common\components\ActiveRecord
         return [
             'ID' => 'ID',
             'TITLE' => '标题',
+            'COUNTRY_ID' => '国家ID',
             'IMAGE' => '图片地址',
             'TYPE' => '类型',
             'LID' => '广告位ID',

+ 4 - 1
common/models/Article.php

@@ -8,6 +8,7 @@ use Yii;
  * This is the model class for table "{{%ARTICLE}}".
  *
  * @property string $ID
+ * @property string $COUNTRY_ID 国家ID
  * @property string $TITLE 标题
  * @property string $CID 分类ID
  * @property string $CONTENT 内容
@@ -31,7 +32,8 @@ class Article extends \common\components\ActiveRecord
     public function rules()
     {
         return [
-            [['CID', 'CREATED_AT'], 'required'],
+            [['CID', 'CREATED_AT', 'COUNTRY_ID'], 'required'],
+            [['COUNTRY_ID'], 'string'],
             [['STATUS', 'CREATED_AT', 'SORT'], 'integer'],
             [['ID', 'CID'], 'string', 'max' => 32],
             [['TITLE'], 'string', 'max' => 255],
@@ -49,6 +51,7 @@ class Article extends \common\components\ActiveRecord
         return [
             'ID' => 'ID',
             'TITLE' => Yii::t('app', 'title'),
+            'COUNTRY_ID' => Yii::t('app', 'country'),
             'CID' => Yii::t('app', 'category'),
             'CONTENT' => Yii::t('app', 'content'),
             'STATUS' => Yii::t('app', 'state'),

+ 6 - 0
common/models/Countries.php

@@ -133,4 +133,10 @@ class Countries extends \common\components\ActiveRecord
         $record = self::findOneAsArray('ID=:ID', [':ID' => $id]);
         return $record['LOCAL_CURRENCY_ID'] ?? 0;
     }
+
+    public static function getCountry(string $id)
+    {
+        $record = self::findOneAsArray('ID=:ID', [':ID' => $id]);
+        return $record['NAME'] ?? '';
+    }
 }

+ 11 - 5
common/models/forms/ArticleForm.php

@@ -18,6 +18,7 @@ class ArticleForm extends Model
     public $cid;
     public $sort;
     public $content;
+    public $countryId;
 
     /**
      * @inheritdoc
@@ -26,8 +27,8 @@ class ArticleForm extends Model
     {
         return [
             [['id', 'title', 'cid', 'content'], 'trim'],
-            [['id', 'title', 'cid', 'content'], 'required'],
-            //[['title'], 'unique', 'targetClass'=>Article::class, 'targetAttribute'=>'TITLE'],
+            [['id', 'title', 'cid', 'content', 'countryId'], 'required'],
+            [['countryId'], 'string'],
             [['id'], 'exist', 'targetClass'=>Article::class, 'targetAttribute'=>'ID'],
             [['cid'], 'exist', 'targetClass'=>ArticleCategory::class, 'targetAttribute'=>'ID'],
         ];
@@ -41,6 +42,7 @@ class ArticleForm extends Model
             'cid' => 'Type', // 分类
             'content' => 'Content', // 内容
             'sort' => 'Sort', // 排序
+            'countryId' => 'Country', // 国家
         ];
     }
 
@@ -52,8 +54,8 @@ class ArticleForm extends Model
     {
         $parentScenarios =  parent::scenarios();
         $customScenarios = [
-            'add' => ['title', 'cid', 'content', 'sort'],
-            'edit' => ['id','title', 'cid', 'content', 'sort'],
+            'add' => ['title', 'cid', 'content', 'sort', 'countryId'],
+            'edit' => ['id','title', 'cid', 'content', 'sort', 'countryId'],
             'sort' => ['id', 'sort'],
         ];
         return array_merge($parentScenarios, $customScenarios);
@@ -64,10 +66,12 @@ class ArticleForm extends Model
      * @return Article|null
      * @throws \yii\db\Exception
      */
-    public function edit(){
+    public function edit()
+    {
         if(!$this->validate()){
             return null;
         }
+
         $db = \Yii::$app->db;
         $transaction = $db->beginTransaction();
         try {
@@ -87,9 +91,11 @@ class ArticleForm extends Model
             $model->CONTENT = '';
             $model->STATUS = 1;
             $model->SORT = $this->sort;
+            $model->COUNTRY_ID = $this->countryId;
             if(!$model->save()){
                 throw new Exception(Form::formatErrorsForApi($model->getErrors()));
             }
+
             // 暂时把内容写入到文件中
             $path = \Yii::getAlias('@common/runtime/articleContent/').$model->ID;
             file_put_contents($path, $this->content);

+ 2 - 1
common/models/forms/DeclarationForm.php

@@ -134,7 +134,7 @@ class DeclarationForm extends Model
     {
         return [
             [['type','decLv','decWay','packageId', 'insertUserName', 'realName',/* 'insertUserIdCard',*/ 'mobile', 'address', 'openBank', 'bankAddress', 'bankNo','bankProvince','bankCity','bankCounty','consignee','acceptMobile','province','city','county','cityName','lgaName','decUserName', 'conUserName', 'bottomUser ', 'recUserName', 'location'], 'trim'],
-            [['type','decLv','decWay','insertUserName',/* 'insertUserIdCard',*/'password','payPassword'], 'required'],
+            [['type','decLv','decWay','insertUserName','decUserName',/* 'insertUserIdCard',*/'password','payPassword'], 'required'],
             [['type'], 'isType', 'on'=>['userDec', 'canDec']],
             [['insertUserName'], 'isCanAddUser'],
             [['decUserName'], 'issetDec'],
@@ -942,6 +942,7 @@ class DeclarationForm extends Model
         $orderModel->PAY_AMOUNT_STANDARD = $this->_standardAmount;
         $orderModel->EXCHANGE_RATE = $userCurrencyRate;
         $orderModel->COUNTRY_ID = $userCountryId;
+        $orderModel->DEC_USER_ID = $this->decUserName;
         $orderModel->CURRENCY_ID = $userCountry['LOCAL_CURRENCY_ID'] ?? 0;
         $orderModel->DEC_USER_ID = Info::getUserNameByUserId($this->_decId);
         if($this->province==1){

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

@@ -9,6 +9,7 @@ namespace frontendApi\modules\v1\controllers;
 
 use common\models\Article;
 use common\models\ArticleCategory;
+use common\models\User;
 use Yii;
 
 class ArticleController extends BaseController
@@ -20,10 +21,17 @@ class ArticleController extends BaseController
      * @return mixed
      * @throws \yii\web\HttpException
      */
-    public function actionIndex(){
+    public function actionIndex()
+    {
         $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',[':CID'=>$value['ID']])->orderBy('CREATED_AT DESC')->limit(5)->asArray()->all();
+            $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')
+                ->limit(5)
+                ->asArray()
+                ->all();
         }
         return static::notice($news);
     }
@@ -52,10 +60,13 @@ class ArticleController extends BaseController
      * @return mixed
      * @throws \yii\web\HttpException
      */
-    public function actionList(){
+    public function actionList()
+    {
+        $userInfo = User::getEnCodeInfo(\Yii::$app->user->id);
+
         $cid = \Yii::$app->request->get('cid');
-        $condition = ' AND A.STATUS=1';
-        $params = [];
+        $condition = ' AND A.STATUS=1 AND A.COUNTRY_ID=:COUNTRY_ID';
+        $params = [':COUNTRY_ID' => $userInfo['COUNTRY_ID']];
         if($cid){
             $condition .= ' AND CID=:CID';
             $params[':CID'] = $cid;

+ 19 - 4
frontendApi/modules/v1/controllers/DashboardController.php

@@ -44,13 +44,21 @@ class DashboardController extends BaseController
         $nowTime = Date::nowTime();
         $baseInfo=Info::baseInfoZh(\Yii::$app->user->id);
         $news=ArticleCategory::find()->select('ID,CATE_NAME')->orderBy('SORT ASC')->asArray()->all();
-        $where = ' CID=:CID AND STATUS=1';
+        $where = ' CID=:CID AND STATUS=1 AND COUNTRY_ID=:COUNTRY_ID';
         foreach ($news as &$value){
             $params = [
-                ':CID'=>$value['ID'],
+                ':CID' => $value['ID'],
+                ':COUNTRY_ID' => $baseInfo['COUNTRY_ID'],
             ];
-            $value['LISTS']=Article::find()->select('ID,TITLE,CID,CREATED_AT')->where($where,$params)->orderBy('CREATED_AT DESC')->limit(6)->asArray()->all();
+            $value['LISTS'] = Article::find()
+                ->select('ID,TITLE,CID,CREATED_AT')
+                ->where($where,$params)
+                ->orderBy('CREATED_AT DESC')
+                ->limit(6)
+                ->asArray()
+                ->all();
         }
+
         $empLv = $baseInfo['EMP_LV'];
         $empLvName = $baseInfo['EMP_LV_NAME'];
         if($baseInfo['SHOW_EMP_LV']){
@@ -121,6 +129,13 @@ class DashboardController extends BaseController
         $activeEndStr = $activeEndStr. " + $remainMonth months";
         $activeEnd = date("Y-m-d H:i:s", strtotime($activeEndStr));
 
+        $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')
+            ->asArray()
+            ->all();
+
         return static::notice([
             'nowTime' => $nowTime,
             'empLv'=>$empLv,
@@ -129,7 +144,7 @@ class DashboardController extends BaseController
             'decLvName'=>$decLvName,
             'eliteLv'=>$eliteLv,
             'eliteLvName'=>$eliteLvName,
-            'slides'=>Ad::findUseSlaves()->select('ID,IMAGE,LID,TITLE,CONTENT,TYPE')->where('LID=:LID AND STATUS=1', [':LID'=>'7EFF6260A16C3CC7E053693418AC03E4'])->orderBy('SORT ASC')->asArray()->all(),
+            'slides'=> $sliders,
             'news'=>$news,
             'periodNum'=>$periodNum . ', ' . $wkrd . ' '. Yii::t('app', 'pcOf') . ' '. $monthArray[$curYM['CALC_MONTH']],
             'myRemainPv'=>$totalRemainPv,