PushmHouse.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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 PushmHouse extends Common
  10. {
  11. public function rules()
  12. {
  13. return [
  14. ['hid', 'unique', 'targetClass' => 'common\models\PushmHouse','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. ['developers_id','number','message'=>'开发商'],
  20. ['sort','number','message'=>'排序只能是数字'],
  21. ['sort','number','max'=>10000],
  22. ['type','number'],
  23. ];
  24. }
  25. public function attributeLabels()
  26. {
  27. return [
  28. 'hid'=>'楼盘名称',
  29. 'type'=>'类型' //6=开发商调用
  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. //hai
  43. public function getCitygroupby($input)
  44. {
  45. $query = self::find();
  46. $query->select(['pfg_category_city.pid','pfg_category_city.abroad','pfg_pushm_house.is_show']);
  47. $query->andWhere(['pfg_pushm_house.del'=>$this->setDel]);
  48. if(!empty($input['house_name']))
  49. {
  50. $query->andWhere(['like','pfg_house.name',$input['house_name']]);
  51. }
  52. $query->andWhere(['pfg_pushm_house.type'=>4]);//$input['type']
  53. $query->leftJoin('pfg_house','pfg_pushm_house.hid=pfg_house.id');
  54. $query->leftJoin('pfg_category_city','pfg_house.city = pfg_category_city.id');
  55. if(!empty($input['page']))
  56. {
  57. $query->limit = $input['limit'];
  58. $query->offset = ( $input['page'] - 1 )* $input['limit'];
  59. }
  60. // return $query->orderBy(['pfg_pushm_house.create_at'=>SORT_DESC])->asArray()->all();
  61. return $query->orderBy(['pfg_pushm_house.create_at'=>SORT_DESC])->groupBy('pfg_category_city.pid')->asArray()->all();
  62. }
  63. //
  64. public function getList($input)
  65. {
  66. $query = self::find();
  67. $query->select(['pfg_category_city.city_name','pfg_house.name','pfg_pushm_house.id','pfg_pushm_house.hid','pfg_pushm_house.create_at','pfg_pushm_house.is_show','pfg_pushm_house.sort','pfg_category_city.pid']);
  68. $query->andWhere(['pfg_pushm_house.del'=>$this->setDel]);
  69. if(!empty($input['house_name']))
  70. {
  71. $query->andWhere(['like','pfg_house.name',$input['house_name']]);
  72. }
  73. if (!empty($input['city_id']))
  74. {
  75. $query->andWhere(['pfg_house.city'=>$input['city_id']]);
  76. }
  77. $query->andWhere(['pfg_pushm_house.type'=>$input['type']]);
  78. $query->leftJoin('pfg_house','pfg_pushm_house.hid=pfg_house.id');
  79. $query->leftJoin('pfg_category_city','pfg_house.city = pfg_category_city.id');
  80. if(!empty($input['page']))
  81. {
  82. $query->limit = $input['limit'];
  83. $query->offset = ( $input['page'] - 1 )* $input['limit'];
  84. }
  85. return $query->orderBy(['pfg_pushm_house.create_at'=>SORT_DESC])->asArray()->all();
  86. // return $query->orderBy(['pfg_pushm_house.create_at'=>SORT_DESC])->groupBy('pfg_category_city.pid')->asArray()->all();
  87. }
  88. public function getList_v1($input)
  89. {
  90. $query = self::find();
  91. $query->select(['pfg_category_city.city_name','pfg_house.name','pfg_pushm_house.id','pfg_pushm_house.hid','pfg_pushm_house.create_at','pfg_pushm_house.is_show','pfg_pushm_house.sort']);
  92. if(!empty($input['house_name']))
  93. {
  94. $query->andWhere(['like','pfg_house.name',$input['house_name']]);
  95. }
  96. if(!empty($input['city']))
  97. {
  98. $query->andWhere(['pfg_house.city'=>$input['city']]);
  99. }
  100. if(!empty($input['developers_id']))
  101. {
  102. $query->andWhere(['pfg_pushm_house.developers_id'=>$input['developers_id']]);
  103. }
  104. $query->andWhere(['pfg_pushm_house.type'=>$input['type']]);
  105. $query->leftJoin('pfg_house','pfg_pushm_house.hid=pfg_house.id');
  106. $query->leftJoin('pfg_category_city','pfg_house.city = pfg_category_city.id');
  107. if(!empty($input['page']))
  108. {
  109. $count = clone $query;
  110. $arr['total'] = $count->count();
  111. $query->limit = $input['limit'];
  112. $query->offset = ( $input['page'] - 1 )* $input['limit'];
  113. }
  114. $arr['data'] = $query->orderBy(['pfg_pushm_house.sort'=>SORT_DESC,'pfg_pushm_house.create_at'=>SORT_DESC])->asArray()->all();
  115. return $arr;
  116. }
  117. public function Total()
  118. {
  119. $query = self::find();
  120. $query->andWhere(['pfg_pushm_house.del'=>$this->setDel]);
  121. $query->leftJoin('pfg_house','pfg_pushm_house.hid=pfg_house.id');
  122. return $query->count();
  123. }
  124. //重写
  125. public function Totalhotsalefeng($input)
  126. {
  127. $query = self::find();
  128. $query->andWhere(['pfg_pushm_house.del'=>$this->setDel]);
  129. if (!empty($input['city_id']))
  130. {
  131. $query->andWhere(['pfg_house.city'=>$input['city_id']]);
  132. }
  133. if(!empty($input['house_name']))
  134. {
  135. $query->andWhere(['like','pfg_house.name',$input['house_name']]);
  136. }
  137. $query->andWhere(['pfg_pushm_house.type'=>$input['type']]);
  138. $query->leftJoin('pfg_house','pfg_pushm_house.hid=pfg_house.id');
  139. return $query->count();
  140. }
  141. //废弃
  142. public function Totalhotsale()
  143. {
  144. $query = self::find();
  145. $query->andWhere(['pfg_pushm_house.del'=>$this->setDel]);
  146. $query->andWhere(['pfg_pushm_house.type'=>4]);
  147. $query->leftJoin('pfg_house','pfg_pushm_house.hid=pfg_house.id');
  148. return $query->count();
  149. }
  150. public function Homegetlist($limit,$rand = null)
  151. {
  152. $query = self::find();
  153. $query->select(['pfg_category_city.id as cid','pfg_category_city.city_name','pfg_house.name','pfg_house.sale_price','pfg_house_detail.price_unit','pfg_house_detail.preferential','pfg_house.characteristic','pfg_house.id','pfg_house.thumb','pfg_house.click_num','pfg_house.state']);
  154. $query->andWhere(['pfg_pushm_house.del'=>$this->setDel]);
  155. $query->andWhere(['pfg_pushm_house.is_show'=>1]);
  156. $query->andWhere(['pfg_pushm_house.type'=>$this->type]);
  157. $query->leftJoin('pfg_house','pfg_pushm_house.hid=pfg_house.id');
  158. $query->leftJoin('pfg_category_city','pfg_house.city=pfg_category_city.id');
  159. $query->leftJoin('pfg_house_detail','pfg_house.id=pfg_house_detail.hid');
  160. if($rand != null)
  161. {
  162. $query->orderBy('RAND()');
  163. }
  164. else
  165. {
  166. $query->orderBy(['pfg_pushm_house.sort'=>SORT_ASC]);
  167. }
  168. $query->limit = $limit;
  169. return $query->asArray()->all();
  170. }
  171. public function CityGetHome($input)
  172. {
  173. $query = self::find();
  174. $query->select(['pfg_category_city.id as cid','pfg_category_city.city_name','pfg_house.name','pfg_house.sale_price','pfg_house_detail.price_unit','pfg_house_detail.preferential','pfg_house.characteristic','pfg_house.id','pfg_house.thumb','pfg_house.click_num','pfg_house.state']);
  175. $query->andWhere(['pfg_pushm_house.del'=>$this->setDel]);
  176. $query->andWhere(['pfg_pushm_house.is_show'=>1]);
  177. $query->andWhere(['pfg_pushm_house.type'=>$this->type]);
  178. $query->andWhere(['IN','pfg_house.city',$input]);
  179. $query->leftJoin('pfg_house','pfg_pushm_house.hid=pfg_house.id');
  180. $query->leftJoin('pfg_category_city','pfg_house.city=pfg_category_city.id');
  181. $query->leftJoin('pfg_house_detail','pfg_house.id=pfg_house_detail.hid');
  182. $query->orderBy(['pfg_pushm_house.sort'=>SORT_ASC]);
  183. $query->limit = 5;
  184. return $query->asArray()->all();
  185. }
  186. //分组统计 目前用于 开发商-楼盘
  187. public function getListGroup()
  188. {
  189. $query = self::find();
  190. $query->select(['count(*) as total','developers_id']);
  191. $query->andFilterWhere(['developers_id'=>$this->developers_id]);
  192. return $query->groupBy(['developers_id'])->asArray()->all();
  193. }
  194. //分组统计 目前用于 开发商-楼盘
  195. //
  196. // public function getListGroup()
  197. // {
  198. // $query = self::find();
  199. // $query->select(['count(*) as total','developers_id']);
  200. // $query->andFilterWhere(['developers_id'=>$this->developers_id]);
  201. // return $query->groupBy(['developers_id'])->asArray()->all();
  202. // }
  203. //移动端品牌馆
  204. public function GetHouse()
  205. {
  206. $query = self::find();
  207. $query->select(['pfg_house.id','pfg_house.name','pfg_house.sale_price','pfg_house.city','pfg_house.characteristic','pfg_house.thumb','pfg_house.is_tel',
  208. 'pfg_house_detail.price_unit','pfg_category_city.city_name','pfg_house.state']);
  209. $query->andWhere(['pfg_pushm_house.type'=>$this->type]);
  210. $query->andWhere(['pfg_pushm_house.developers_id'=>$this->developers_id]);
  211. $query->andWhere(['pfg_house.is_view'=>1]);
  212. $query->andWhere(['pfg_house.del'=>1]);
  213. $query->andWhere(['pfg_category_city.state'=>1]); //陈晓锋添加
  214. // $query->andFilterWhere(['pfg_house.is_push'=>1]); //陈晓锋注释--为什么要加这个条件
  215. $query->leftJoin('pfg_developers','pfg_pushm_house.developers_id = pfg_developers.id');
  216. $query->leftJoin('pfg_house','pfg_pushm_house.hid = pfg_house.id');
  217. $query->leftJoin('pfg_house_detail','pfg_house.id = pfg_house_detail.hid');
  218. $query->leftJoin('pfg_category_city','pfg_house.city = pfg_category_city.id');
  219. $query->orderBy(['pfg_pushm_house.sort'=>SORT_DESC,'pfg_pushm_house.id'=>SORT_DESC]);
  220. return $query->asArray()->all();
  221. }
  222. }