32], [['REGION_NAME'], 'string', 'max' => 128], [['AREA_CODE'], 'string', 'max' => 6], [['UPDATER', 'ADM_NAME'], 'string', 'max' => 16], [['REGION_CODE'], 'unique'], [['ID'], 'unique'], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'ID' => 'ID', 'REGION_CODE' => '编码', 'DEEP' => '深度', 'REGION_NAME' => '名称', 'PID' => '父级id', 'AREA_CODE' => '区号', 'CREATED_AT' => '创建时间', 'UPDATED_AT' => '更新时间', 'UPDATER' => '更新人', 'ADM_NAME' => '操作人', ]; } /** * 获取中文的地区名称 * @param $regionCode * @return string */ public static function getCnName($regionCode){ $allData = self::getFromCache(); return $allData[$regionCode]['REGION_NAME'] ?? ''; } /** * 获取全部配置,把育成津贴奖金比例解成数组 * @return array|\yii\db\ActiveRecord[] */ public static function getAllData(){ return static::find()->where('1=1')->orderBy('CREATED_AT ASC')->indexBy('REGION_CODE')->asArray()->all(); } /** * 从缓存获取信息 * @return array|mixed|\yii\db\ActiveRecord[] */ public static function getFromCache(){ $data = Yii::$app->cache->get(Cache::REGION_CONFIG_KEY); if(!$data){ // 获取信息 $data = self::getAllData(); Yii::$app->cache->set(Cache::REGION_CONFIG_KEY, $data); } return $data; } /** * 更新缓存 * @return array|\yii\db\ActiveRecord[] */ public static function updateToCache(){ // 获取配置 $data = self::getAllData(); Yii::$app->cache->set(Cache::REGION_CONFIG_KEY, $data); return $data; } /** * 根据省编码获取仓库 * @param $regionCode * @return string */ public static function getWarehouseByCode($regionCode){ //'540000','710000','810000','820000' $ZoningArr = [ '01'=>['110000','120000','130000','370000','140000','210000','310000','320000','330000','340000','410000','150000','220000','230000','500000','510000','610000','620000','640000','630000','650000'], '02'=>['440000','350000','360000','420000','430000','450000','460000','520000','530000'] ]; $zoning = ''; foreach ($ZoningArr as $key=>$val){ if(in_array($regionCode,$val)){ $zoning = $key; break; } } return $zoning; } }