HouseType.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/3/25
  6. * Time: 上午10:06
  7. */
  8. namespace common\models;
  9. class HouseType extends Common
  10. {
  11. public function rules()
  12. {
  13. return [
  14. [['hid', 'type_id'], 'required', 'message' => '{attribute}不能为空'],
  15. [['sort', 'hid', 'hot'], 'number'],
  16. [['img'], 'string', 'max' => 50],
  17. ['title', 'each', 'rule' => ['string', 'max' => 50], 'message' => '最多输入50个字符'], //验证
  18. ['area', 'each', 'rule' => ['string', 'max' => 50], 'message' => '最多输入50个字符'], //验证
  19. ['indoor_info', 'each', 'rule' => ['string', 'max' => 50], 'message' => '最多输入50个字符'], //验证
  20. [['del', 'hot'], 'in', 'range' => [1, 2]],
  21. [['del', 'hot'], 'default', 'value' => 1]
  22. ];
  23. }
  24. public function attributeLabels()
  25. {
  26. return [
  27. 'type_id' => '所属户型',
  28. 'title' => '户型描述',
  29. 'area' => '建筑面积',
  30. 'indoor_info' => '厅卫厨',
  31. ];
  32. }
  33. public function Authenticator($input)
  34. {
  35. $this->load($input, '');
  36. if (!$this->validate()) return $this->errors;
  37. return $this;
  38. }
  39. public function FindById($id)
  40. {
  41. return self::findOne($id);
  42. }
  43. //随机返回
  44. public function RandList($select = null, $limit)
  45. {
  46. $query = $this->QueryFind();
  47. $query = $this->QueryFindWhere($query);
  48. if ($select != null) {
  49. $query->select($select);
  50. }
  51. $query->limit = $limit;
  52. return $query->orderBy('RAND()')->asArray()->all();
  53. }
  54. //分组
  55. public function TypeGroup()
  56. {
  57. $query = self::find();
  58. $query->andWhere(['pfg_category_housetype.state' => 1]);
  59. $query->andWhere(['pfg_house_type.del' => $this->setDel]);
  60. $query->andFilterWhere(['pfg_house_type.hid' => $this->hid]);
  61. $query->select(['pfg_category_housetype.huxing_name', 'pfg_house_type.type_id', 'pfg_house_type.hid', 'pfg_house_type.state', "count('type_id') as num"]);
  62. $query->leftJoin('pfg_category_housetype', 'pfg_house_type.type_id = pfg_category_housetype.id');
  63. $query->orderBy(['pfg_category_housetype.sort' => SORT_ASC]);
  64. return $query->groupBy('type_id')->asArray()->all();
  65. }
  66. public function getList($select = null)
  67. {
  68. $query = self::find();
  69. $query->select($select);
  70. $query = $this->QueryFindWhere($query);
  71. // $query->andWhere(['del'=>$this->setDel]);
  72. // $query->andFilterWhere(['hid'=>$this->hid]);
  73. // $query->andFilterWhere(['type_id'=>$this->type_id]);
  74. return $query->asArray()->all();
  75. }
  76. public function QgetList($limit = null)
  77. {
  78. $query = $this->QueryFind();
  79. $query = $this->QueryFindWhere($query);
  80. $query->limit($limit);
  81. return $query->asArray()->all();
  82. }
  83. //楼盘分组查询统计
  84. public function HidTotal()
  85. {
  86. $query = self::find();
  87. $query->select(["count('hid') as num", 'hid']);
  88. $query->andFilterWhere(['hid' => $this->hid]);
  89. $query->andWhere(['del' => $this->setDel]);
  90. $query->andWhere(['NOT', ['img' => '']]);
  91. return $query->groupBy('hid')->asArray()->all();
  92. }
  93. //移动端调用
  94. public function MgetList($limit, $select = null)
  95. {
  96. $query = $this->QueryFind();
  97. $query->select($select);
  98. $query = $this->QueryFindWhere($query);
  99. $query->limit($limit);
  100. return $query->asArray()->all();
  101. }
  102. public function getListByHid($select = null)
  103. {
  104. $query = $this->QueryFind();
  105. $query->select($select);
  106. $query = $this->QueryFindWhere($query);
  107. return $query->asArray()->all();
  108. }
  109. protected function QueryFind()
  110. {
  111. return self::find();
  112. }
  113. protected function QueryFindWhere($query)
  114. {
  115. $query->andWhere(['del' => $this->setDel]);
  116. $query->andFilterWhere(['hid' => $this->hid]);
  117. $query->andFilterWhere(['type_id' => $this->type_id]);
  118. return $query;
  119. }
  120. public function getHouseTypeName()
  121. {
  122. return $this->hasOne(CategoryHousetype::className(), ['id' => 'type_id']);
  123. }
  124. }