MiniRotation.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. namespace common\models;
  3. class MiniRotation extends Common
  4. {
  5. public function rules()
  6. {
  7. return [
  8. // ['url', 'url', 'defaultScheme' => 'https','message'=>'请输入正确的地址'],
  9. ['url','string','max'=>255],
  10. ['title','string','max'=>50],
  11. ['img','string','max'=>50],
  12. ['hid','number','message'=>'请选择楼盘'],
  13. ['sort','number','message'=>'排序只能是数字'],
  14. ['city','default','value'=>0],
  15. ['city','number'],
  16. ['sort','number','max'=>10000],
  17. ['type','number'],
  18. ['expiration_date','string'],
  19. ];
  20. }
  21. public function attributeLabels()
  22. {
  23. return [
  24. 'hid'=>'楼盘名称',
  25. 'url'=>'地址',
  26. 'title'=>'标题',
  27. 'city'=>'区域',
  28. ];
  29. }
  30. public function Authenticator($input)
  31. {
  32. $this->load($input,'');
  33. if(!$this->validate()) return $this->errors;
  34. return $this;
  35. }
  36. public function FindById($id)
  37. {
  38. return self::findOne($id);
  39. }
  40. public function getList($input)
  41. {
  42. $query = self::find();
  43. $query->select(['pfg_category_city.city_name','pfg_house.name','pfg_mini_rotation.id','pfg_mini_rotation.hid',
  44. 'pfg_mini_rotation.img','pfg_mini_rotation.url','pfg_mini_rotation.title','pfg_mini_rotation.create_at',
  45. 'pfg_mini_rotation.is_show','pfg_mini_rotation.expiration_date']);
  46. $query->andWhere(['pfg_mini_rotation.del'=>$this->setDel]);
  47. $query->leftJoin('pfg_house','pfg_mini_rotation.hid=pfg_house.id');
  48. $query->leftJoin('pfg_category_city','pfg_mini_rotation.city=pfg_category_city.id');
  49. if (!empty($input['type'])) {
  50. $query->andWhere(['pfg_mini_rotation.type'=>$input['type']]);
  51. }
  52. if(!empty($input['city']))
  53. {
  54. $query->andFilterWhere(['pfg_mini_rotation.city'=>$input['city']]);
  55. }
  56. if(!empty($input['page']))
  57. {
  58. $query->limit = $input['limit'];
  59. $query->offset = ($input['page']-1 )* $input['limit'];
  60. }
  61. return $query->orderBy(['pfg_mini_rotation.is_show'=>SORT_ASC,'pfg_mini_rotation.sort'=>SORT_DESC,'pfg_mini_rotation.create_at'=>SORT_DESC])->asArray()->all();
  62. }
  63. public function WhereColumn($query)
  64. {
  65. }
  66. public function Total($input)
  67. {
  68. $query = self::find();
  69. $query->andWhere(['pfg_mini_rotation.del'=>$this->setDel]);
  70. if (!empty($input['type'])) {
  71. $query->andWhere(['pfg_mini_rotation.type'=>$input['type']]);
  72. }
  73. if(!empty($input['city']))
  74. {
  75. $query->andFilterWhere(['pfg_mini_rotation.city'=>$input['city']]);
  76. }
  77. $query->leftJoin('pfg_house','pfg_mini_rotation.hid=pfg_house.id');
  78. return $query->count();
  79. }
  80. public function HomeGetList()
  81. {
  82. $query = self::find();
  83. $query->select(['img','url','title']);
  84. $query->andWhere(['del'=>$this->setDel]);
  85. $query->andFilterWhere(['city'=>$this->city]);
  86. $query->andWhere(['is_show'=>1,'type'=>1]);
  87. $query->orderBy(['sort'=>SORT_DESC]);
  88. $query->limit = 5;
  89. return $query->all();
  90. }
  91. /**不分地区读取全部*/
  92. public function GetAllList()
  93. {
  94. $query = self::find();
  95. $query->select(['img','url','title']);
  96. $query->andWhere(['del'=>$this->setDel]);
  97. $query->andWhere(['is_show'=>1,'type'=>1]);
  98. $query->orderBy(['sort'=>SORT_DESC]);
  99. $query->limit = 5;
  100. return $query->all();
  101. }
  102. public function getAll($limit,$type)
  103. {
  104. $query = self::find();
  105. $query->select(['img','url','title','expiration_date']);
  106. $query->andWhere(['del'=>$this->setDel]);
  107. $query->andWhere(['is_show'=>1,'type'=>$type]);
  108. $query->orderBy(['sort'=>SORT_DESC]);
  109. $query->limit = $limit;
  110. return $query->asArray()->all();
  111. }
  112. }