Эх сурвалжийг харах

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

zhangl 1 жил өмнө
parent
commit
591e2117a7

+ 10 - 0
common/helpers/Cache.php

@@ -14,6 +14,7 @@ use common\models\Countries;
 use common\models\Currency;
 use common\models\DealType;
 use common\models\DecRole;
+use common\models\EliteLevel;
 use common\models\Language;
 use common\models\OcrApi;
 use common\models\DeclarationLevel;
@@ -38,6 +39,7 @@ class Cache
     const DEC_ROLE_CONFIG_KEY = 'sys:decRole';
     const EMP_LEVEL_CONFIG_KEY = 'sys:empLevel';
     const CROWN_LEVEL_CONFIG_KEY = 'sys:crownLevel';
+    const ELITE_LEVEL_CONFIG_KEY = 'sys:eliteLevel';
     const ADMIN_ROLE_KEY = 'sys:adminRole';
     const SMS_TEMPLATE_DEC_KEY = 'sys:smsTemplateDec';
     const SMS_TEMPLATE_EMP_KEY = 'sys:smsTemplateEmp';
@@ -128,6 +130,14 @@ class Cache
         return DeclarationLevel::getFromCache();
     }
 
+    /**
+     * 获取报单级别
+     * @return array|mixed|\yii\db\ActiveRecord[]
+     */
+    public static function getEliteLevelConfig(){
+        return EliteLevel::getFromCache();
+    }
+
     /**
      * 获取国家列表
      * @return array|mixed|\yii\db\ActiveRecord[]

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

@@ -704,6 +704,11 @@ return [
     'dbEmployLevel5StarDirector'  => '5-Star Director',
     'dbEmployLevel6StarDirector'  => '6-Star Director',
     'dbEmployLevel7StarDirector'  => '7-Star Director',
+    # Elite级别
+    'dbEliteLevelNa' => 'NA',
+    'dbEliteLevelElite' => 'Elite',
+    'dbEliteLevelProElite' => 'Pro Elite',
+    'dbEliteLevelSuperElite' => 'Supper Elite',
     # 皇冠星级
     'dbCrownLevel0StarCrown' => '0-Star Crown',
     'dbCrownLevel1StarCrown' => '1-Star Crown',

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

@@ -708,6 +708,11 @@ return [
     'dbEmployLevel5StarDirector'  => '5星管理',
     'dbEmployLevel6StarDirector'  => '6星管理',
     'dbEmployLevel7StarDirector'  => '7星管理',
+    # Elite级别
+    'dbEliteLevelNa' => 'NA',
+    'dbEliteLevelElite' => 'Elite',
+    'dbEliteLevelProElite' => 'Pro Elite',
+    'dbEliteLevelSuperElite' => 'Supper Elite',
     # 皇冠星级
     'dbCrownLevel0StarCrown'	=> '无',
     'dbCrownLevel1StarCrown'	=> '1星皇冠',

+ 204 - 0
common/models/EliteLevel.php

@@ -0,0 +1,204 @@
+<?php
+
+namespace common\models;
+
+use common\helpers\Cache;
+use common\helpers\LoggerTool;
+use Yii;
+
+/**
+ * This is the model class for table "{{%CROWN_LEVEL}}".
+ *
+ * @property string $ID
+ * @property string $LEVEL_NAME 级别名称
+ * @property int $ICON_TYPE 图标类型
+ * @property int $ICON_NUM 图标个数
+ * @property int $RX_PERCENT 图标个数
+ * @property string $MIN_LEVEL_ID 上级ID
+ * @property string $LEVEL_SCORE 级别分数
+ * @property string $UPGRADE_SCORE 升级分数
+ * @property string $TOURISM_PERCENT 旅游奖比例
+ * @property string $GARAGE_PERCENT 车房奖比例
+ * @property int $SORT 排序
+ * @property int $CREATED_AT 创建时间
+ * @property int $UPDATED_AT 更新时间
+ * @property string $CREATE_ADMIN 创建人
+ * @property string $UPDATE_ADMIN 更新人
+ */
+class EliteLevel extends \common\components\ActiveRecord
+{
+    const NO_LEVEL_ID = 'N0RI23JKCP4OBLZ6GAXYWH9D1QS8NA7V';
+
+    /**
+     * @inheritdoc
+     */
+    public static function tableName()
+    {
+        return '{{%CROWN_LEVEL}}';
+    }
+
+    /**
+     * @inheritdoc
+     */
+    public function rules()
+    {
+        return [
+            [['LEVEL_NAME', 'CREATED_AT', 'CREATE_ADMIN'], 'required'],
+            [['SORT', 'CREATED_AT', 'UPDATED_AT'], 'integer'],
+            [['ID', 'CREATE_ADMIN', 'UPDATE_ADMIN'], 'string', 'max' => 32],
+            [['LEVEL_NAME'], 'string', 'max' => 20],
+            [['LEVEL_NAME'], 'unique'],
+            [['ID'], 'unique'],
+        ];
+    }
+
+    /**
+     * @inheritdoc
+     */
+    public function attributeLabels()
+    {
+        return [
+            'ID' => 'ID',
+            'LEVEL_NAME' => '级别名称',
+            'SORT' => '排序',
+            'CREATED_AT' => '创建时间',
+            'UPDATED_AT' => '更新时间',
+            'CREATE_ADMIN' => '创建人',
+            'UPDATE_ADMIN' => '更新人',
+        ];
+    }
+
+    /**
+     * 获取全部级别以数字索引的方式展现
+     * @return array|\yii\db\ActiveRecord[]
+     */
+    public static function getAllDataWithNumIndex()
+    {
+        return static::find()->where('1=1')->orderBy('SORT ASC, CREATED_AT ASC')->indexBy('SORT')->asArray()->all();
+    }
+
+    /**
+     * 获取全部配置
+     * @return array|\yii\db\ActiveRecord[]
+     */
+    public static function getAllData()
+    {
+        return static::find()->where('1=1')->orderBy('SORT ASC, CREATED_AT ASC')->indexBy('ID')->asArray()->all();
+    }
+
+    // 获取级别配置一维度数组,id为键,级别等级为值
+    public static function getIdConvertLevelSort()
+    {
+        $ret = [];
+        $allData = static::find()->where('1=1')->orderBy('SORT ASC, CREATED_AT ASC')->indexBy('ID')->asArray()->all();
+        foreach($allData as $data) {
+            $ret[$data['ID']] = $data['SORT'];
+        }
+        return $ret;
+    }
+
+    /**
+     * 从缓存获取信息
+     * @return array|mixed|\yii\db\ActiveRecord[]
+     */
+    public static function getIdConvertLevelSortCache()
+    {
+        $key = Cache::ELITE_LEVEL_CONFIG_KEY . ':idsort';
+        $data = Yii::$app->cache->get($key);
+        if(!$data){
+            // 获取信息
+            $data = self::getIdConvertLevelSort();
+            Yii::$app->cache->set($key, $data);
+        }
+
+        return $data;
+    }
+
+    /**
+     * 从缓存获取信息
+     * @return array|mixed|\yii\db\ActiveRecord[]
+     */
+    public static function getFromCache()
+    {
+        $data = Yii::$app->cache->get(Cache::ELITE_LEVEL_CONFIG_KEY);
+        if(!$data){
+            // 获取信息
+            $data = self::getAllData();
+            Yii::$app->cache->set(Cache::ELITE_LEVEL_CONFIG_KEY, $data);
+        }
+        // i18n转换
+        foreach ($data as &$item) {
+            $item['LEVEL_NAME'] = Yii::t('ctx', $item['LANGUAGE_KEY']);
+        }
+        return $data;
+    }
+
+    /**
+     *  更新缓存
+     * @return array|\yii\db\ActiveRecord[]
+     */
+    public static function updateToCache()
+    {
+        // 获取配置
+        $data = self::getAllData();
+        Yii::$app->cache->set(Cache::ELITE_LEVEL_CONFIG_KEY, $data);
+        return $data;
+    }
+
+    /**
+     * 通过排序获取级别
+     * @param int $sort
+     * @return mixed
+     */
+    public static function getLevelFromSort(int $sort)
+    {
+        static $crownLevels;
+        if(!$crownLevels){
+            $crownLevels = self::getFromCache();
+            $crownLevels = array_column($crownLevels, null, 'sort');
+        }
+        return $crownLevels[$sort];
+    }
+
+    /**
+     * 通过排序获取ID
+     * @param int $sort
+     * @return mixed
+     */
+    public static function getIdFromSort(int $sort)
+    {
+        $level = self::getLevelFromSort($sort);
+        return $level['ID'];
+    }
+
+    /**
+     * 获取默认级别
+     * @return mixed
+     */
+    public static function getDefaultLevelId()
+    {
+        return self::NO_LEVEL_ID;
+    }
+
+    /**
+     * 获取星级的排序
+     * @param $id
+     * @return mixed
+     */
+    public static function getSortById($id)
+    {
+        $crownLevels = self::getFromCache();
+        return $crownLevels[$id]['SORT'] ?? 0;
+    }
+
+    /**
+     * 通过ID获取星级名称
+     * @param $levelId
+     * @return mixed'
+     */
+    public static function getNameById($levelId)
+    {
+        return self::findOneAsArray('ID = :ID', [':ID' => $levelId])['LEVEL_NAME'] ?? '';
+    }
+
+}