CityDetails.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/4/26
  6. * Time: 上午11:57
  7. */
  8. namespace common\models;
  9. class CityDetails extends Common
  10. {
  11. public function rules()
  12. {
  13. return [
  14. ['del','in','range'=>[1,2]],
  15. ['city_id','number'],
  16. [['title','introduce','thumb','background_img','pinyin','video'],'string'],
  17. ];
  18. }
  19. public function attributeLabels()
  20. {
  21. return [
  22. 'title'=>'标题',
  23. 'introduce'=>'简介',
  24. 'thumb'=>'缩略图',
  25. 'background_img'=>'图集',
  26. ];
  27. }
  28. /*
  29. * 调用里面的验证,错误返回数组,正确返回对象
  30. * */
  31. public function Authenticator($input)
  32. {
  33. $this->load($input,'');
  34. if(!$this->validate()) return $this->errors;
  35. return $this;
  36. }
  37. public function getList($input)
  38. {
  39. $query = self::find();
  40. $query->select(['pfg_category_city.city_name','pfg_city_details.title',
  41. 'pfg_city_details.id','pfg_city_details.introduce','pfg_city_details.pinyin']);
  42. $query->andWhere(['pfg_city_details.del'=>$this->setDel]);
  43. if(!empty($this->city_id))
  44. {
  45. $query->andWhere(['pfg_city_details.city_id'=>$this->city_id]);
  46. }
  47. $query->leftJoin('pfg_category_city','pfg_city_details.city_id=pfg_category_city.id');
  48. if(!empty($input['page']))
  49. {
  50. $query->limit = $input['limit'];
  51. $query->offset = ($input['page']-1 )* $input['limit'];
  52. }
  53. return $query->orderBy(['pfg_city_details.create_at'=>SORT_DESC])->asArray()->all();
  54. }
  55. public function FingById($id)
  56. {
  57. return self::findOne($id);
  58. }
  59. public function FingByName($id)
  60. {
  61. $query = self::find();
  62. $query->andWhere(['pfg_city_details.del'=>$this->setDel]);
  63. $query->andWhere(['pfg_city_details.is_view'=>1]);
  64. $query->andWhere(['pfg_city_details.id'=>$id]);
  65. $query->select(['pfg_category_city.city_name','pfg_city_details.*']);
  66. $query->leftJoin('pfg_category_city','pfg_city_details.city_id = pfg_category_city.id');
  67. return $query->asArray()->one();
  68. }
  69. public function Total()
  70. {
  71. $query = self::find();
  72. $query->andWhere(['pfg_city_details.del'=>$this->setDel]);
  73. $query->leftJoin('pfg_category_city','pfg_city_details.city_id=pfg_category_city.id');
  74. return $query->count();
  75. }
  76. public function Homegetlist()
  77. {
  78. $query = self::find();
  79. $query->andWhere(['pfg_city_details.del'=>$this->setDel]);
  80. $query->andWhere(['pfg_city_details.is_view'=>1]);
  81. $query->select(['pfg_category_city.city_name','pfg_city_details.introduce','pfg_city_details.thumb']);
  82. $query->leftJoin('pfg_category_city','pfg_city_details.city_id = pfg_category_city.id');
  83. $query->orderBy(['pfg_city_details.sort'=>SORT_ASC]);
  84. $query->limit = 5;
  85. return $query->asArray()->all();
  86. }
  87. /**
  88. * 返回区域信息
  89. */
  90. public function CityInfo()
  91. {
  92. $query = self::find();
  93. $query->andWhere(['pfg_city_details.del'=>$this->setDel]);
  94. $query->andWhere(['pfg_city_details.is_view'=>1]);
  95. $query->select(['pfg_category_city.city_name','pfg_city_details.thumb','pfg_city_details.id']);
  96. $query->leftJoin('pfg_category_city','pfg_city_details.city_id = pfg_category_city.id');
  97. $query->orderBy(['pfg_city_details.sort'=>SORT_ASC]);
  98. return $query->asArray()->all();
  99. }
  100. }