PushHousesale.php 3.9 KB

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