PushHouserecommend.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace common\models;
  3. class PushHouserecommend extends Common
  4. {
  5. public function rules()
  6. {
  7. return [
  8. ['hid', 'unique', 'targetClass' => 'common\models\PushHouserecommend','on'=>['add'],'message'=>'该楼盘已存在','filter'=>function($query){
  9. $query->andWhere(['del'=>$this->setDel]);
  10. return $query->andWhere(['cat_id'=>$this->cat_id]);
  11. }],
  12. ['hid','number','message'=>'请选择楼盘'],
  13. ['city','number'],
  14. ['sort','number','message'=>'排序只能是数字'],
  15. ['sort','number','max'=>10000],
  16. ['cat_id','number'],
  17. ];
  18. }
  19. public function attributeLabels()
  20. {
  21. return [
  22. 'hid'=>'楼盘名称',
  23. 'city'=>'区域',
  24. ];
  25. }
  26. public function Authenticator($input)
  27. {
  28. $this->load($input,'');
  29. if(!$this->validate()) return $this->errors;
  30. return $this;
  31. }
  32. public function FindById($id)
  33. {
  34. return self::findOne($id);
  35. }
  36. public function getList($input)
  37. {
  38. $query = self::find();
  39. $query->select(['pfg_house.name','pfg_house.thumb','pfg_push_houserecommend.id','pfg_push_houserecommend.hid','pfg_house.sale_price','pfg_house.characteristic','pfg_house_detail.price_unit','pfg_house_detail.main_units','pfg_push_houserecommend.cat_id','pfg_push_houserecommend.create_at','pfg_category_city.city_name']);
  40. $query->andWhere(['pfg_push_houserecommend.del'=>$this->setDel]);
  41. // $query->andWhere(['pfg_push_houserecommend.cat_id'=>$input['cat_id']]);
  42. if(isset($input['city'])){
  43. $query->andFilterWhere(['pfg_category_city.id'=>$input['city']]);
  44. }
  45. if(!empty($input['house_name']))
  46. {
  47. $query->andFilterWhere(['like', 'pfg_house.name', trim($input['house_name']," ")]);
  48. }
  49. $query->leftJoin('pfg_house','pfg_push_houserecommend.hid=pfg_house.id');
  50. $query->leftJoin('pfg_house_detail','pfg_push_houserecommend.hid=pfg_house_detail.hid');
  51. $query->leftJoin('pfg_category_city','pfg_house.city=pfg_category_city.id');
  52. $query->limit = 7;
  53. return $query->orderBy(['pfg_push_houserecommend.sort'=>SORT_DESC])->asArray()->all();
  54. }
  55. public function getHouseList($input)
  56. {
  57. $query = self::find();
  58. $query->select(['pfg_house.name','pfg_house.thumb','pfg_push_houserecommend.id','pfg_push_houserecommend.sort','pfg_push_houserecommend.hid','pfg_house.sale_price','pfg_house.characteristic','pfg_house_detail.price_unit','pfg_house_detail.main_units','pfg_push_houserecommend.cat_id','pfg_push_houserecommend.create_at','pfg_category_city.city_name']);
  59. $query->andWhere(['pfg_push_houserecommend.del'=>$this->setDel]);
  60. $query->andWhere(['pfg_push_houserecommend.city'=>$input['cat_id']]);
  61. if(isset($input['city'])){
  62. $query->andFilterWhere(['pfg_push_houserecommend.city'=>$input['city']]);
  63. }
  64. if(!empty($input['house_name']))
  65. {
  66. $query->andFilterWhere(['like', 'pfg_house.name', trim($input['house_name']," ")]);
  67. }
  68. $query->leftJoin('pfg_house','pfg_push_houserecommend.hid=pfg_house.id');
  69. $query->leftJoin('pfg_house_detail','pfg_push_houserecommend.hid=pfg_house_detail.hid');
  70. $query->leftJoin('pfg_category_city','pfg_house.city=pfg_category_city.id');
  71. if(!empty($input['page']))
  72. {
  73. $query->offset = ($input['page'] - 1) * $input['limit'];
  74. $query->limit = $input['limit'];
  75. }
  76. return $query->orderBy(['pfg_push_houserecommend.sort'=>SORT_DESC])->asArray()->all();
  77. }
  78. public function WhereColumn($query)
  79. {
  80. }
  81. public function Total($input)
  82. {
  83. $query = self::find();
  84. if(!empty($input['house_name']))
  85. {
  86. $query->andFilterWhere(['like', 'pfg_house.name', trim($input['house_name']," ")]);
  87. }
  88. $query->andWhere(['pfg_push_houserecommend.del'=>$this->setDel]);
  89. $query->andWhere(['pfg_push_houserecommend.city'=>$input['cat_id']]);
  90. $query->leftJoin('pfg_house','pfg_push_houserecommend.hid=pfg_house.id');
  91. return $query->count();
  92. }
  93. public function Homegetlist($limit)
  94. {
  95. $query = self::find();
  96. $query->select(['pfg_category_city.city_name','pfg_house.name','pfg_house.sale_price','pfg_house_detail.price_unit','pfg_house.characteristic','pfg_house_detail.main_units','pfg_house.id','pfg_house.thumb']);
  97. $query->andWhere(['pfg_push_houserecommend.del'=>$this->setDel]);
  98. $query->andWhere(['pfg_push_houserecommend.is_show'=>1]);
  99. $query->andWhere(['pfg_push_houserecommend.cat_id'=>$this->cat_id]);
  100. $query->andFilterWhere(['pfg_push_houserecommend.city'=>$this->city]);
  101. $query->leftJoin('pfg_house','pfg_push_houserecommend.hid=pfg_house.id');
  102. $query->leftJoin('pfg_category_city','pfg_house.city=pfg_category_city.id');
  103. $query->leftJoin('pfg_house_detail','pfg_house.id=pfg_house_detail.hid');
  104. $query->orderBy(['pfg_push_houserecommend.sort'=>SORT_ASC]);
  105. $query->limit = $limit;
  106. return $query->asArray()->all();
  107. }
  108. }