Area.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php
  2. namespace common\models;
  3. use Yii;
  4. /**
  5. * This is the model class for table "{{%aboutwe}}".
  6. *
  7. * @property string $id
  8. * @property string $address
  9. * @property string $tell
  10. * @property string $content
  11. * @property string $time
  12. * @property integer $email
  13. * @property integer $updated_at
  14. * @property integer $created_at
  15. */
  16. class Area extends \yii\db\ActiveRecord
  17. {
  18. const DISPLAY_NO = 1;
  19. const DISPLAY_YES = 10;
  20. /**
  21. * @inheritdoc
  22. */
  23. public static function tableName()
  24. {
  25. return '{{%area}}';
  26. }
  27. /**
  28. * @inheritdoc
  29. */
  30. public static function queryCity($city)
  31. {
  32. $city = Area::findOne(['area_id'=>$city]);
  33. return $city['area'];
  34. }
  35. /**
  36. * 获取省份列表
  37. */
  38. public static function queryAdminProvinces()
  39. {
  40. $cacheKey = "AdminProvincesCache";
  41. $list = Yii::$app->cache->get($cacheKey);
  42. if(empty($list)){
  43. $list = Area::find()->where(['type'=>1])->select('area,area_id')->all();
  44. if(!empty($list))
  45. Yii::$app->cache->set($cacheKey,$list);
  46. }
  47. return $list;
  48. }
  49. /**
  50. * 获取城市列表
  51. */
  52. public static function queryAdminCitys()
  53. {
  54. $cacheKey = "AdminCitysCache";
  55. $list = Yii::$app->cache->get($cacheKey);
  56. if(empty($list)){
  57. $list = Area::find()->where(['type'=>2])->select('area,area_id')->orderBy("ishot DESC")->all();
  58. if(!empty($list))
  59. Yii::$app->cache->set($cacheKey,$list);
  60. }
  61. return $list;
  62. }
  63. /**
  64. * 获取城市列表,带英文字母
  65. */
  66. public static function queryAdminCitysLetter()
  67. {
  68. $name = "AdminCitysLetterCache";
  69. $cache =Yii::$app->cache->get($name);
  70. if(!empty($cache))
  71. {
  72. $lists = Yii::$app->cache->get($name);
  73. }else{
  74. $list = Area::find()->where(['type'=>2])->select('area,area_id,letter')->orderBy('letter ASC')->asArray()->all();
  75. $lists = array();
  76. if(!empty($list))
  77. {
  78. foreach ($list as $key => $val) {
  79. if(empty($lists[$val['letter']]))
  80. $lists[$val['letter']]['letter'] = $val['letter'];
  81. $lists[$val['letter']]['city'][] = $val;
  82. }
  83. unset($list);
  84. $lists = array_values($lists);
  85. Yii::$app->cache->set($name,$lists);
  86. }
  87. }
  88. return $lists;
  89. }
  90. /**
  91. * 获取省名称
  92. * @param $area_id
  93. * @return string
  94. */
  95. public static function queryAdminProvinceName($area_id)
  96. {
  97. $cacheKey = "AdminProvinceNameCache";
  98. $list = Yii::$app->cache->get($cacheKey);
  99. if(empty($list)){
  100. $lists = Area::find()->where(['type'=>1])->select('area,area_id')->orderBy("ishot DESC")->all();
  101. if(!empty($lists))
  102. {
  103. foreach ($lists as $val)
  104. {
  105. $list[$val->area_id] =$val->area;
  106. }
  107. Yii::$app->cache->set($cacheKey,$list);
  108. }
  109. }
  110. if(!empty($list[$area_id]))
  111. return $list[$area_id];
  112. else
  113. return "";
  114. }
  115. /**
  116. * 获取市名称
  117. * @param $area_id
  118. * @return string
  119. */
  120. public static function queryAdminCityName($area_id)
  121. {
  122. $cacheKey = "AdminCityNameCache";
  123. $list = Yii::$app->cache->get($cacheKey);
  124. if(empty($list)){
  125. $lists = Area::find()->where(['type'=>2])->select('area,area_id')->orderBy("ishot DESC")->all();
  126. if(!empty($lists))
  127. {
  128. foreach ($lists as $val)
  129. {
  130. $list[$val->area_id] =$val->area;
  131. }
  132. Yii::$app->cache->set($cacheKey,$list);
  133. }
  134. }
  135. if(!empty($list[$area_id]))
  136. return $list[$area_id];
  137. else
  138. return "";
  139. }
  140. /**
  141. * 获取市详情名称
  142. * @param $area_id
  143. * @return string
  144. */
  145. public static function queryAdminCityInfo($area_id)
  146. {
  147. $cacheKey = "AdminCityInfoCache";
  148. $list = Yii::$app->cache->get($cacheKey);
  149. if(empty($list)){
  150. $lists = Area::find()->where(['type'=>2])->select('area,area_id,father_area_id')->orderBy("ishot DESC")->all();
  151. if(!empty($lists))
  152. {
  153. foreach ($lists as $val)
  154. {
  155. $list[$val->area_id] =array('area'=>$val->area,'area_id'=>$val->area_id,'father_area_id'=>$val->father_area_id);
  156. }
  157. Yii::$app->cache->set($cacheKey,$list);
  158. }
  159. }
  160. if(!empty($list[$area_id]))
  161. return $list[$area_id];
  162. else
  163. return "";
  164. }
  165. public function getCitys(){
  166. return $this->hasMany($this::className(),['father_area_id'=>'area_id'])->select('area,area_id');
  167. }
  168. }