123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- <?php
- namespace common\models;
- use Yii;
- /**
- * This is the model class for table "{{%aboutwe}}".
- *
- * @property string $id
- * @property string $address
- * @property string $tell
- * @property string $content
- * @property string $time
- * @property integer $email
- * @property integer $updated_at
- * @property integer $created_at
- */
- class Area extends \yii\db\ActiveRecord
- {
- const DISPLAY_NO = 1;
- const DISPLAY_YES = 10;
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%area}}';
- }
- /**
- * @inheritdoc
- */
- public static function queryCity($city)
- {
- $city = Area::findOne(['area_id'=>$city]);
- return $city['area'];
- }
- /**
- * 获取省份列表
- */
- public static function queryAdminProvinces()
- {
- $cacheKey = "AdminProvincesCache";
- $list = Yii::$app->cache->get($cacheKey);
- if(empty($list)){
- $list = Area::find()->where(['type'=>1])->select('area,area_id')->all();
- if(!empty($list))
- Yii::$app->cache->set($cacheKey,$list);
- }
- return $list;
- }
- /**
- * 获取城市列表
- */
- public static function queryAdminCitys()
- {
- $cacheKey = "AdminCitysCache";
- $list = Yii::$app->cache->get($cacheKey);
- if(empty($list)){
- $list = Area::find()->where(['type'=>2])->select('area,area_id')->orderBy("ishot DESC")->all();
- if(!empty($list))
- Yii::$app->cache->set($cacheKey,$list);
- }
- return $list;
- }
- /**
- * 获取城市列表,带英文字母
- */
- public static function queryAdminCitysLetter()
- {
- $name = "AdminCitysLetterCache";
- $cache =Yii::$app->cache->get($name);
- if(!empty($cache))
- {
- $lists = Yii::$app->cache->get($name);
- }else{
- $list = Area::find()->where(['type'=>2])->select('area,area_id,letter')->orderBy('letter ASC')->asArray()->all();
- $lists = array();
- if(!empty($list))
- {
- foreach ($list as $key => $val) {
- if(empty($lists[$val['letter']]))
- $lists[$val['letter']]['letter'] = $val['letter'];
- $lists[$val['letter']]['city'][] = $val;
- }
- unset($list);
- $lists = array_values($lists);
- Yii::$app->cache->set($name,$lists);
- }
- }
- return $lists;
- }
- /**
- * 获取省名称
- * @param $area_id
- * @return string
- */
- public static function queryAdminProvinceName($area_id)
- {
- $cacheKey = "AdminProvinceNameCache";
- $list = Yii::$app->cache->get($cacheKey);
- if(empty($list)){
- $lists = Area::find()->where(['type'=>1])->select('area,area_id')->orderBy("ishot DESC")->all();
- if(!empty($lists))
- {
- foreach ($lists as $val)
- {
- $list[$val->area_id] =$val->area;
- }
- Yii::$app->cache->set($cacheKey,$list);
- }
- }
- if(!empty($list[$area_id]))
- return $list[$area_id];
- else
- return "";
- }
- /**
- * 获取市名称
- * @param $area_id
- * @return string
- */
- public static function queryAdminCityName($area_id)
- {
- $cacheKey = "AdminCityNameCache";
- $list = Yii::$app->cache->get($cacheKey);
- if(empty($list)){
- $lists = Area::find()->where(['type'=>2])->select('area,area_id')->orderBy("ishot DESC")->all();
- if(!empty($lists))
- {
- foreach ($lists as $val)
- {
- $list[$val->area_id] =$val->area;
- }
- Yii::$app->cache->set($cacheKey,$list);
- }
- }
- if(!empty($list[$area_id]))
- return $list[$area_id];
- else
- return "";
- }
- /**
- * 获取市详情名称
- * @param $area_id
- * @return string
- */
- public static function queryAdminCityInfo($area_id)
- {
- $cacheKey = "AdminCityInfoCache";
- $list = Yii::$app->cache->get($cacheKey);
- if(empty($list)){
- $lists = Area::find()->where(['type'=>2])->select('area,area_id,father_area_id')->orderBy("ishot DESC")->all();
- if(!empty($lists))
- {
- foreach ($lists as $val)
- {
- $list[$val->area_id] =array('area'=>$val->area,'area_id'=>$val->area_id,'father_area_id'=>$val->father_area_id);
- }
- Yii::$app->cache->set($cacheKey,$list);
- }
- }
- if(!empty($list[$area_id]))
- return $list[$area_id];
- else
- return "";
- }
- public function getCitys(){
- return $this->hasMany($this::className(),['father_area_id'=>'area_id'])->select('area,area_id');
- }
- }
|