ListHouse.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/3/4
  6. * Time: 上午9:41
  7. */
  8. namespace common\models;
  9. //use yii\db\ActiveRecord;
  10. class ListHouse extends Common
  11. {
  12. public function rules()
  13. {
  14. return [
  15. ['list_id', 'in', 'range' => [10, 11, 12, 101, 102, 103]],
  16. ['hid', 'required', 'message' => '楼盘不能为空'],
  17. [['sort', 'state', 'information'], 'safe']
  18. ];
  19. /**
  20. * list_id:[
  21. * 10:pc端首页VR全景看房推送
  22. * 11:pc端首页航拍视频看房推送
  23. * 12:M端首页热榜楼盘推送位
  24. * 101,102,103:国庆中秋专题
  25. * ]
  26. */
  27. }
  28. /***********************************后台数据*******************************************/
  29. //获取品质新房数据
  30. public function GetCharachterForm($input)
  31. {
  32. $query = self::find();
  33. $query->select(['pfg_list_house.*', 'pfg_house.name']);
  34. $query->where(['pfg_list_house.list_id' => $input['type_id']]);
  35. $count = $query->count();
  36. $query->leftJoin('pfg_house', 'pfg_house.id = pfg_list_house.hid');
  37. if (!empty($input['page'])) {
  38. $query->offset(--$input['page'] * $input['limit']);
  39. }
  40. if (!empty($input['limit'])) {
  41. $query->limit($input['limit']);
  42. }
  43. $data = $query->orderBy(['pfg_list_house.state' => SORT_ASC, 'pfg_list_house.sort' => SORT_DESC])->asArray()->all();
  44. foreach ($data as &$val) {
  45. $val['create_at'] = date('Y-m-d H:i:s', $val['create_at']);
  46. }
  47. return ['msg' => '获取数据完成', 'count' => $count, 'data' => $data];
  48. }
  49. //获取数据列表
  50. public function getList($input)
  51. {
  52. $query = self::find();
  53. $query->select(['pfg_list_house.*', 'pfg_house.name']);
  54. $query->where(['pfg_list_house.list_id' => $input['list_id']]);
  55. $count = $query->count();
  56. $query->leftJoin('pfg_house', 'pfg_house.id = pfg_list_house.hid');
  57. if (!empty($input['page'])) {
  58. $query->offset(--$input['page'] * $input['limit']);
  59. }
  60. if (!empty($input['limit'])) {
  61. $query->limit($input['limit']);
  62. }
  63. $data = $query->orderBy(['pfg_list_house.state' => SORT_ASC, 'pfg_list_house.sort' => SORT_DESC])->asArray()->all();
  64. foreach ($data as &$val) {
  65. $val['create_at'] = date('Y-m-d H:i:s', $val['create_at']);
  66. }
  67. return ['msg' => '获取数据完成', 'count' => $count, 'data' => $data];
  68. }
  69. /**
  70. * 获取一条数据
  71. * */
  72. public function getFindOne($id)
  73. {
  74. $query = self::find();
  75. $query->select(['pfg_list_house.*', 'pfg_house.name']);
  76. $query->where(['pfg_list_house.id' => $id]);
  77. $query->leftJoin('pfg_house', 'pfg_house.id = pfg_list_house.hid');
  78. return $query->asArray()->one();
  79. }
  80. /*
  81. * 检测数据是否存在
  82. * */
  83. public function listExists($where)
  84. {
  85. return self::find()->where($where)->exists();
  86. }
  87. /***************************************** pc端数据 ********************************************/
  88. //获取中秋专题数据
  89. public function zhongQiuGuoQing($list_id, $limit = null)
  90. {
  91. $select = [
  92. 'pfg_house.id',
  93. 'pfg_house.name',
  94. 'pfg_house.thumb',
  95. 'pfg_house.city',
  96. 'pfg_house.sale_price',
  97. 'pfg_house_detail.price_unit',
  98. 'pfg_house_detail.address',
  99. 'pfg_house_detail.preferential',
  100. 'pfg_category_city.city_name'
  101. ];
  102. $query = self::find();
  103. $query->select($select);
  104. $query->where(['pfg_list_house.list_id' => $list_id, 'pfg_list_house.state' => 1, 'pfg_house.del' => 1, 'pfg_house.is_view' => 1]);
  105. $query->leftJoin('pfg_house', 'pfg_house.id = pfg_list_house.hid');
  106. $query->leftJoin('pfg_house_detail', 'pfg_house.id = pfg_house_detail.hid');
  107. $query->leftJoin('pfg_category_city', 'pfg_category_city.id = pfg_house.city');
  108. if (!empty($limit)) {
  109. $query->limit($limit);
  110. }
  111. return $query->orderBy(['pfg_list_house.sort' => SORT_DESC])->asArray()->all();
  112. }
  113. //获取指定楼盘推送数据列表
  114. public function getIndexPushHouse($list_id, $limit = null)
  115. {
  116. $select = [
  117. 'pfg_house.id',
  118. 'pfg_house.name',
  119. 'pfg_house.thumb',
  120. 'pfg_category_city.city_name',
  121. 'pfg_house_detail.panorama_img',
  122. 'pfg_house_detail.video_img'
  123. ];
  124. $query = self::find();
  125. $query->select($select);
  126. $query->where(['pfg_list_house.list_id' => $list_id, 'pfg_list_house.state' => 1, 'pfg_house.del' => 1, 'pfg_house.is_view' => 1]);
  127. $query->leftJoin('pfg_house', 'pfg_house.id = pfg_list_house.hid');
  128. $query->leftJoin('pfg_house_detail', 'pfg_house.id = pfg_house_detail.hid');
  129. $query->leftJoin('pfg_category_city', 'pfg_category_city.id = pfg_house.city');
  130. if (!empty($limit)) {
  131. $query->limit($limit);
  132. }
  133. return $query->orderBy(['pfg_list_house.sort' => SORT_DESC])->asArray()->all();
  134. }
  135. //获取指定楼盘推送数据列表详细信息
  136. public function getIndexPushHouseDetail($list_id, $limit = null)
  137. {
  138. $select = [
  139. 'pfg_house.id',
  140. 'pfg_house.name',
  141. 'pfg_house.thumb',
  142. 'pfg_house.state',
  143. 'pfg_house.sale_price',
  144. 'pfg_house.is_tel',
  145. 'pfg_house.city',
  146. 'pfg_house_detail.price_unit',
  147. 'pfg_house_detail.preferential',
  148. 'pfg_house_detail.video_url',
  149. 'pfg_category_city.city_name'
  150. ];
  151. $query = self::find();
  152. $query->select($select);
  153. $query->where(['pfg_list_house.list_id' => $list_id, 'pfg_list_house.state' => 1, 'pfg_house.del' => 1, 'pfg_house.is_view' => 1]);
  154. $query->leftJoin('pfg_house', 'pfg_house.id = pfg_list_house.hid');
  155. $query->leftJoin('pfg_house_detail', 'pfg_house.id = pfg_house_detail.hid');
  156. $query->leftJoin('pfg_category_city', 'pfg_category_city.id = pfg_house.city');
  157. if (!empty($limit)) {
  158. $query->limit($limit);
  159. }
  160. return $query->orderBy(['pfg_list_house.sort' => SORT_DESC])->asArray()->all();
  161. }
  162. }