PushHothouse.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. namespace common\models;
  3. use common\fm\HouseHandle;
  4. use common\fm\Opencc;
  5. use common\models\Common;
  6. class PushHothouse extends Common
  7. {
  8. public function rules()
  9. {
  10. return [
  11. ['hid', 'unique', 'targetClass' => 'common\models\china\PushHothouse', 'on' => ['add'], 'message' => '该楼盘已存在', 'filter' => function ($query) {
  12. return $query->andWhere(['type' => $this->type]);
  13. }],
  14. ['hid', 'number', 'message' => '请选择楼盘'],
  15. ['city', 'number'],
  16. ['sort', 'number', 'message' => '排序只能是数字'],
  17. ['sort', 'number', 'max' => 10000],
  18. ['type', 'number'],
  19. [['state'], 'number'],
  20. [['state'], 'default', 'value' => 1],
  21. [['state'], 'in', 'range' => [1, 2]],
  22. ];
  23. }
  24. public function attributeLabels()
  25. {
  26. return [
  27. 'hid' => '楼盘名称',
  28. 'city' => '区域',
  29. ];
  30. }
  31. public function FindById($id)
  32. {
  33. return self::findOne($id);
  34. }
  35. /**
  36. * 后台查询数据
  37. * @param $input
  38. * @return array|\yii\db\ActiveRecord[]
  39. */
  40. public function getList($input)
  41. {
  42. $query = self::find();
  43. $query->select(['pfg_house.name', 'pfg_push_hothouse.id', 'pfg_push_hothouse.hid', 'pfg_push_hothouse.create_at', 'pfg_push_hothouse.state', 'pfg_push_hothouse.sort']);
  44. if (!empty($input['name'])) {
  45. $query->andWhere(['like', 'pfg_house.name', $input['name']]);
  46. }
  47. $query->andWhere(['pfg_push_hothouse.type' => $input['type']]);
  48. $query->leftJoin('pfg_house', 'pfg_push_hothouse.hid = pfg_house.id');
  49. if (!empty($input['page'])) {
  50. $query->limit = $input['limit'];
  51. $query->offset = ($input['page'] - 1) * $input['limit'];
  52. }
  53. return $query->orderBy(['pfg_push_hothouse.sort' => SORT_DESC, 'pfg_push_hothouse.id' => SORT_DESC])->asArray()->all();
  54. }
  55. /**
  56. * 后台查询数据统计条数
  57. * @param $input
  58. * @return int|string
  59. */
  60. public function Total($input)
  61. {
  62. $query = self::find();
  63. if (!empty($input['name'])) {
  64. $query->andWhere(['like', 'pfg_house.name', $input['name']]);
  65. }
  66. $query->andWhere(['pfg_push_hothouse.type' => $input['type']]);
  67. $query->leftJoin('pfg_house', 'pfg_push_hothouse.hid = pfg_house.id');
  68. return $query->count();
  69. }
  70. /**
  71. * 获取推送的热门楼盘
  72. * @param $type 区分类型
  73. * @param $labellimit 返回标签的数量
  74. * @param $sort 排序
  75. * @param $limit
  76. * @return array|\yii\db\ActiveRecord[]
  77. */
  78. public function getHotHouse($type, $limit, $sort = '')
  79. {
  80. $query = self::find();
  81. $query->andWhere(['pfg_push_hothouse.state' => 1]);
  82. $query->andWhere(['pfg_push_hothouse.type' => $type]);
  83. $query->select(['pfg_house.id', 'pfg_house.name', 'pfg_house.thumb', 'pfg_house.sale_price',
  84. 'pfg_house.city', 'pfg_house_detail.price_unit', 'pfg_house.characteristic', 'pfg_category_city.city_name','pfg_house_detail.preferential']);
  85. $query->leftJoin('pfg_house', 'pfg_push_hothouse.hid = pfg_house.id');
  86. $query->leftJoin('pfg_category_city', 'pfg_house.city = pfg_category_city.id');
  87. $query->leftJoin('pfg_house_detail', 'pfg_house.id = pfg_house_detail.hid');
  88. $query->limit = $limit;
  89. $query->orderBy(['pfg_push_hothouse.sort' => SORT_DESC, 'pfg_push_hothouse.id' => SORT_DESC]);
  90. if (!empty($sort) && $sort == 'rand') {
  91. $query->orderBy('RAND()');
  92. }
  93. $data = $query->asArray()->all();
  94. if (!empty($data)) {
  95. foreach ($data as &$val) {
  96. $val['name'] = Opencc::Convert($val['name']);
  97. $val['city_name'] = Opencc::Convert($val['city_name']);
  98. $val['price_unit'] = Opencc::Convert($val['price_unit']);
  99. $val['thumb'] = \Yii::$app->params['httpImg']['hosts'] . \Yii::$app->params['httpImg']['houses'] . $val['thumb'] . '/same';
  100. $val['tel'] = HouseHandle::RandTel($val['city']);
  101. $val['label'] = HouseHandle::Subject(json_decode($val['characteristic']), 3);
  102. if (!empty($val['label'])) {
  103. foreach ($val['label'] as &$v) {
  104. $v = Opencc::Convert($v);
  105. }
  106. }
  107. }
  108. return $data;
  109. }
  110. return '';
  111. }
  112. public function HomeListRand($limit, $type)
  113. {
  114. $query = self::find();
  115. $query->select(['pfg_house.name', 'pfg_house.thumb', 'pfg_house.id', 'pfg_house.characteristic']);
  116. $query->andWhere(['pfg_push_hothouse.state' => 1]);
  117. $query->andWhere(['pfg_push_hothouse.type' => $type]);
  118. $query->leftJoin('pfg_house', 'pfg_push_hothouse.hid = pfg_house.id');
  119. $query->limit = $limit;
  120. $query->orderBy('RAND()');
  121. return $query->asArray()->all();
  122. }
  123. }