House.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/3/4
  6. * Time: 上午9:33
  7. */
  8. namespace common\models;
  9. use yii\data\Pagination;
  10. class House extends Common
  11. {
  12. public $typeHouse; //户型搜索条件
  13. public function rules()
  14. {
  15. // apartment 保留户型
  16. // return [
  17. // [['name','pinyin','state'],'required','message'=>'{attribute}不能为空'],
  18. // ['name', 'unique', 'targetClass' => 'common\models\House','on'=>'add','message'=>'楼盘名称已经存在'],
  19. // ['state','in','range'=>[1,2,3,4]],
  20. // [['sort','sale_price'],'number'],
  21. // [['name'],'trim'],
  22. //// [['type','city','price','characteristic'],'string','max'=>100],
  23. // [['city','price','alias_name'],'string','max'=>100],
  24. // ['type','each','rule'=>['integer'],'message'=>'aaaa'], //验证
  25. // ['characteristic','each','rule'=>['integer'],'message'=>'aaaa'],
  26. // ['architecture_type','each','rule'=>['integer'],'message'=>'aaaa'],
  27. // ['thumb','string','links','max'=>200],
  28. // ['del','in','range'=>[1,2]],
  29. // ['is_push','in','range'=>[1,2]],
  30. // ['is_push','default','value'=>1],
  31. // ];
  32. return [
  33. [['name', 'pinyin', 'state', 'city'], 'required', 'message' => '{attribute}不能为空'],
  34. ['name', 'unique', 'targetClass' => 'common\models\House', 'on' => ['add', 'edit'], 'message' => '楼盘名称已经存在', 'filter' => function ($query) {
  35. return $query->andWhere(['del' => $this->setDel]);
  36. }],
  37. ['state', 'in', 'range' => [1, 2, 3, 4]],
  38. [['sort', 'sale_price', 'province', 'area'], 'number'],
  39. [['name'], 'trim'],
  40. // [['type','city','price','characteristic'],'string','max'=>100],
  41. [['city', 'price', 'alias_name'], 'string', 'max' => 100],
  42. ['type', 'each', 'rule' => ['integer'], 'message' => '物业类型必填'], //验证
  43. ['characteristic', 'each', 'rule' => ['integer'], 'message' => '特色主题必填'],
  44. ['architecture_type', 'each', 'rule' => ['integer'], 'message' => '建筑类别必填'],
  45. ['thumb', 'string', 'max' => 200],
  46. ['del', 'in', 'range' => [1, 2]],
  47. ['is_push', 'in', 'range' => [1, 2]],
  48. ['is_push', 'default', 'value' => 1],
  49. ['sale_price', 'default', 'value' => 0],
  50. ['is_view', 'default', 'value' => 2],
  51. ['is_tel', 'string', 'max' => 20],
  52. ['links', 'string'],
  53. ['prohibit_city', 'string', 'max' => 255],
  54. ['prohibit_city', 'default', 'value' => ''],
  55. ['customer_service', 'string']
  56. ];
  57. }
  58. public function attributeLabels()
  59. {
  60. return [
  61. 'name' => '楼盘名称',
  62. 'pinyin' => '楼盘拼音不能为空',
  63. 'type' => '物业类型',
  64. 'city' => '区域',
  65. 'price' => '价格区间',
  66. 'characteristic' => '特色主题',
  67. 'thumb' => '图片',
  68. 'state' => '销售状态',
  69. 'sale_price' => '均价',
  70. 'architecture_type' => '建筑类别',
  71. 'alias_name' => '楼盘别名',
  72. 'is_push' => '主推楼盘',
  73. 'is_tel' => '电话',
  74. 'prohibit_city' => '禁售区域',
  75. ];
  76. }
  77. public function Authenticator($input)
  78. {
  79. $this->load($input, '');
  80. if (!$this->validate()) return $this->errors;
  81. return $this;
  82. }
  83. public function getList($page)
  84. {
  85. $query = self::find();
  86. $query->andWhere(['pfg_house.del' => $this->setDel,'pfg_category_city.del'=>1]);
  87. if (!empty($page['id'])) {
  88. $query->andFilterWhere(['pfg_house.id' => $page['id']]);
  89. }
  90. if (!empty($page['city'])) {
  91. $query->andFilterWhere(['pfg_house.city' => $page['city']]);
  92. }
  93. if (!empty($page['start_time'])) {
  94. $query->andFilterWhere(['>=', 'pfg_house.create_at', strtotime($page['start_time'] . ' 00:00:00')]);
  95. }
  96. if (!empty($page['end_time'])) {
  97. $query->andFilterWhere(['<=', 'pfg_house.create_at', strtotime($page['end_time'] . ' 23:59:59')]);
  98. }
  99. if (!empty($page['name'])) {
  100. $query->andFilterWhere(['like', 'pfg_house.name', trim($page['name'], " ")]);
  101. }
  102. if (!empty($page['pinyin'])) {
  103. $query->andFilterWhere(['like', 'pfg_house.pinyin', $page['pinyin']]);
  104. }
  105. if (!empty($page['characteristic'])) {
  106. $query->andFilterWhere(['like', 'pfg_house.characteristic', $page['characteristic']]);
  107. }
  108. if (!empty($page['price'])) {
  109. $query->andFilterWhere(['pfg_house.price' => $page['price']]);
  110. }
  111. if (!empty($page['is_view'])) {
  112. $query->andWhere(['pfg_house.is_view' => $page['is_view']]);
  113. }
  114. if (!empty($page['price_unit']) && $page['price_unit'] == 'price_unit') {
  115. $query->andWhere(['NOT', ['pfg_house.sale_price' => '']]);
  116. $query->andWhere(['pfg_house_detail.price_unit' => '']);
  117. }
  118. if (!empty($page['price_unit']) && $page['price_unit'] == 'is_permit') {
  119. $s = HousePermit::find()->select(['hid'])->groupBy('hid')->asArray()->all();
  120. $query->andWhere(['not in', 'pfg_house.id', array_column($s, 'hid')]);
  121. }
  122. if (!empty($page['price_unit']) && $page['price_unit'] == 'discount') {
  123. $query->andWhere(['pfg_house_detail.preferential' => '']);
  124. }
  125. if (!empty($page['price_unit']) && $page['price_unit'] == 'discounts') {
  126. $query->andWhere(['NOT', ['pfg_house_detail.preferential' => '']]);
  127. }
  128. if (!empty($page['sort'])) {
  129. if ($page['sort'] == 'sort') {
  130. $query->orderBy(['pfg_house.sort' => SORT_DESC, 'pfg_house.id' => SORT_DESC]);
  131. }
  132. if ($page['sort'] == 'map') {
  133. $query->orderBy(['pfg_house.is_push'=>SORT_DESC,'pfg_house.sort' => SORT_DESC, 'pfg_house.id' => SORT_DESC]);
  134. }
  135. if ($page['sort'] == 'regionsort') {
  136. $query->orderBy(['pfg_house_detail.regionsort' => SORT_DESC, 'pfg_house.id' => SORT_DESC]);
  137. }
  138. if ($page['sort'] == 'allsort') {
  139. $query->orderBy(['pfg_house_detail.allsort' => SORT_DESC, 'pfg_house.id' => SORT_DESC]);
  140. }
  141. }
  142. if (!empty($page['is_push'])) {
  143. $query->andWhere(['pfg_house.is_push' => $page['is_push']]);
  144. $query->orderBy(['pfg_house.create_at' => SORT_DESC]);
  145. }
  146. $query->leftJoin('pfg_category_city', 'pfg_house.city=pfg_category_city.id');
  147. $query->leftJoin('pfg_house_detail', 'pfg_house.id=pfg_house_detail.hid');
  148. $query->leftJoin('pfg_user_house', 'pfg_house.id=pfg_user_house.hid');
  149. $query->leftJoin('pfg_user', 'pfg_user_house.uid=pfg_user.uid');
  150. $query->select(['pfg_house.create_at', 'pfg_user.name as user_name', 'pfg_category_city.city_name', 'pfg_house.id', 'pfg_house.name', 'pfg_house.sort', 'pfg_house.click_num', 'pfg_house.is_view', 'pfg_house.sale_price', 'pfg_house.thumb', 'pfg_house.is_push', 'pfg_house_detail.evaluating', 'pfg_house_detail.longitude_latitude', 'pfg_house.characteristic', 'pfg_house_detail.main_units', 'pfg_house_detail.price_unit', 'pfg_house.sale_price', 'pfg_house_detail.allsort', 'pfg_house_detail.regionsort']);
  151. if (!empty($page['page'])) {
  152. $query->offset = ($page['page'] - 1) * $page['limit'];
  153. $query->limit = $page['limit'];
  154. }
  155. return $query->asArray()->all();
  156. }
  157. public function getListTotal($page)
  158. {
  159. $query = self::find();
  160. $query->andWhere(['pfg_house.del' => $this->setDel]);
  161. if (!empty($page['id'])) {
  162. $query->andFilterWhere(['pfg_house.id' => $page['id']]);
  163. } else if (!empty($page['city'])) {
  164. $query->andFilterWhere(['pfg_house.city' => $page['city']]);
  165. } else if (!empty($page['name'])) {
  166. $query->andFilterWhere(['like', 'pfg_house.name', trim($page['name'], "")]);
  167. }
  168. if (!empty($page['characteristic'])) {
  169. $query->andFilterWhere(['like', 'pfg_house.characteristic', $page['characteristic']]);
  170. }
  171. if (!empty($page['price'])) {
  172. $query->andFilterWhere(['pfg_house.price' => $page['price']]);
  173. }
  174. if (!empty($page['is_view'])) {
  175. $query->andWhere(['pfg_house.is_view' => $page['is_view']]);
  176. }
  177. if (!empty($page['start_time'])) {
  178. $query->andFilterWhere(['>=', 'pfg_house.create_at', strtotime($page['start_time'] . ' 00:00:00')]);
  179. }
  180. if (!empty($page['end_time'])) {
  181. $query->andFilterWhere(['<=', 'pfg_house.create_at', strtotime($page['end_time'] . ' 23:59:59')]);
  182. }
  183. if (!empty($page['price_unit']) && $page['price_unit'] == 'price_unit') {
  184. $query->andWhere(['NOT', ['pfg_house.sale_price' => '']]);
  185. $query->andWhere(['pfg_house_detail.price_unit' => '']);
  186. }
  187. if (!empty($page['price_unit']) && $page['price_unit'] == 'discount') {
  188. $query->andWhere(['pfg_house_detail.preferential' => '']);
  189. }
  190. if (!empty($page['price_unit']) && $page['price_unit'] == 'discounts') {
  191. $query->andWhere(['NOT', ['pfg_house_detail.preferential' => '']]);
  192. }
  193. if (!empty($page['is_push'])) {
  194. $query->andWhere(['pfg_house.is_push' => $page['is_push']]);
  195. }
  196. if (!empty($page['price_unit']) && $page['price_unit'] == 'is_permit') {
  197. $s = HousePermit::find()->select(['hid'])->groupBy('hid')->asArray()->all();
  198. // $a = self::find();
  199. // $a->select(['pfg_house_permit.hid']);
  200. // $a->leftJoin('pfg_house_permit','pfg_house.id = pfg_house_permit.hid');
  201. // $a->asArray();
  202. // $s = $a->all();
  203. $query->andWhere(['not in', 'pfg_house.id', array_column($s, 'hid')]);
  204. }
  205. $query->leftJoin('pfg_category_city', 'pfg_house.city=pfg_category_city.id');
  206. $query->leftJoin('pfg_house_detail', 'pfg_house.id=pfg_house_detail.hid');
  207. $query->leftJoin('pfg_user_house', 'pfg_house.id=pfg_user_house.hid');
  208. $query->leftJoin('pfg_user', 'pfg_user_house.uid=pfg_user.uid');
  209. return $query->count();
  210. }
  211. public function HousesAll()
  212. {
  213. $query = self::find();
  214. $query->andWhere(['pfg_house.id' => $this->id]);
  215. $query->andWhere(['pfg_house.del' => $this->setDel]);
  216. $query->select(['pfg_house.*', 'pfg_house_detail.*']);
  217. $query->leftJoin('pfg_house_detail', 'pfg_house.id=pfg_house_detail.hid');
  218. return $query->asArray()->one();
  219. }
  220. private function WhereColumn($query)
  221. {
  222. $query->andFilterWhere(['name' => $this->name]);
  223. $query->andFilterWhere(['id' => $this->id]);
  224. $query->andWhere(['del' => $this->setDel]);
  225. return $query;
  226. }
  227. public function total()
  228. {
  229. $query = $this->QueryFind();
  230. $query = $this->WhereColumn($query);
  231. return $query->count();
  232. }
  233. //楼盘和楼盘附表信息
  234. public function QgetList($arr = null, $sort = null)
  235. {
  236. $query = $this->QueryFind();
  237. $query->select($arr);
  238. $query = $this->LeftJoin_where($query);
  239. $query = $this->LeftJoin_house_detail($query);
  240. $query = $this->LeftJoin_house_type($query);
  241. $query = $this->LeftJoin_house_city($query);
  242. $pages = new Pagination(['totalCount' => $this->PaginationTotal(), 'pageSize' => 8, 'pageSizeParam' => false, 'validatePage' => false,]);
  243. $query->offset($pages->offset)->limit($pages->limit);
  244. //
  245. // if(!isset($sort['py']) && $_SERVER['HTTP_HOST'] == $_SERVER['SERVER_NAME']){
  246. //
  247. // $query->orderBy(['pfg_house_detail.allsort'=>SORT_DESC,'pfg_house_detail.hid'=>SORT_DESC]);
  248. //
  249. //
  250. // }
  251. // else{
  252. // $query->orderBy(['pfg_house.sort'=>SORT_DESC]);
  253. //// $query->orderBy(['pfg_house_detail.regionsort'=>SORT_DESC,'pfg_house_detail.hid'=>SORT_DESC]);
  254. //
  255. // }
  256. // if(isset($sort['son']) && $sort['son'] == 'son'){
  257. //
  258. // $query->orderBy(['pfg_house.sort'=>SORT_DESC]);
  259. //
  260. // }
  261. // if (!empty($sort['renqi'])){
  262. // $query->orderBy(['pfg_house.is_push'=>SORT_DESC]);
  263. //
  264. // } else if(isset($sort['pricesort'])) {
  265. //
  266. // switch ($sort['pricesort'])
  267. // {
  268. // case 1:
  269. // $query->orderBy(['pfg_house.sale_price'=>SORT_ASC]);
  270. // break;
  271. // case 2:
  272. // $query->orderBy(['pfg_house.sale_price'=>SORT_DESC]);
  273. // break;
  274. // }
  275. //
  276. // }
  277. if (\Yii::$app->hostserver->hostId == 0) {
  278. $query->orderBy(['pfg_house_detail.allsort' => SORT_DESC, 'pfg_house.id' => SORT_DESC]);
  279. if (!empty($sort['py']) && is_array($sort['city'])) {
  280. $query->orderBy(['pfg_house_detail.regionsort' => SORT_DESC, 'pfg_house.id' => SORT_DESC]);
  281. } else if (!is_array($sort['city'])) {
  282. $query->orderBy(['pfg_house.sort' => SORT_DESC, 'pfg_house.id' => SORT_DESC]);
  283. }
  284. } else {
  285. $query->orderBy(['pfg_house_detail.regionsort' => SORT_DESC, 'pfg_house.id' => SORT_DESC]);
  286. if (!is_array($sort['city'])) {
  287. $query->orderBy(['pfg_house.sort' => SORT_DESC, 'pfg_house.id' => SORT_DESC]);
  288. }
  289. }
  290. if (!empty($sort['renqi'])) {
  291. $query->orderBy(['pfg_house.click_num' => SORT_DESC, 'pfg_house.id' => SORT_DESC]);
  292. }
  293. $models = $query->asArray()->all();
  294. $data['page'] = $pages;
  295. $data['data'] = $models;
  296. return $data;
  297. }
  298. public function MapSearch($arr)
  299. {
  300. $query = $this->QueryFind();
  301. $query->select($arr);
  302. $query = $this->LeftJoin_where($query);
  303. $query = $this->LeftJoin_house_detail($query);
  304. $query = $this->LeftJoin_house_type($query);
  305. $query = $this->LeftJoin_house_city($query);
  306. return $query->asArray()->all();
  307. }
  308. //总数
  309. public function PcHouseListTotal()
  310. {
  311. $query = $this->QueryFind();
  312. $query = $this->LeftJoin_where($query);
  313. $query = $this->LeftJoin_house_detail($query);
  314. $query = $this->LeftJoin_house_type($query);
  315. $query = $this->LeftJoin_house_city($query);
  316. return $query->count();
  317. }
  318. public function PaginationTotal()
  319. {
  320. $query = $this->QueryFind();
  321. $query = $this->LeftJoin_where($query);
  322. $query = $this->LeftJoin_house_detail($query);
  323. $query = $this->LeftJoin_house_type($query);
  324. $query = $this->LeftJoin_house_city($query);
  325. return $query->count();
  326. }
  327. //pc端楼盘列表
  328. public function PcHouseList($input, $select = null, $sort = null)
  329. {
  330. $query = $this->QueryFind();
  331. $query->select($select);
  332. $query = $this->LeftJoin_where($query);
  333. $query = $this->LeftJoin_house_detail($query);
  334. $query = $this->LeftJoin_house_type($query);
  335. $query = $this->LeftJoin_house_city($query);
  336. if (!empty($input['hao'])) {
  337. $query = $this->InnerJoin_Mansion($query);
  338. }
  339. if (!isset($sort['py']) && $_SERVER['HTTP_HOST'] == $_SERVER['SERVER_NAME']) {
  340. if (\Yii::$app->hostserver->hostId != 0) {
  341. $query->orderBy(['pfg_house_detail.regionsort' => SORT_DESC, 'pfg_house.id' => SORT_DESC]);
  342. } else {
  343. $query->orderBy(['pfg_house_detail.allsort' => SORT_DESC, 'pfg_house_detail.hid' => SORT_DESC]);
  344. }
  345. } else {
  346. if ($sort != null) {
  347. switch ($sort) {
  348. case '1':
  349. $query->orderBy(['pfg_house.sale_price' => SORT_ASC]);
  350. break;
  351. case '2':
  352. $query->orderBy(['pfg_house.sale_price' => SORT_DESC]);
  353. break;
  354. }
  355. }
  356. if (\Yii::$app->hostserver->hostId != 0) {
  357. $query->orderBy(['pfg_house_detail.regionsort' => SORT_DESC, 'pfg_house.id' => SORT_DESC]);
  358. } else {
  359. $query->orderBy(['pfg_house.sort' => SORT_DESC, 'pfg_house.id' => SORT_DESC]);
  360. }
  361. }
  362. if (!empty($input['city'])) {
  363. $query->orderBy(['pfg_house.sort' => SORT_DESC, 'pfg_house.id' => SORT_DESC]);
  364. }
  365. //加入豪宅排序
  366. if (!empty($input['hao'])) {
  367. if (!empty($input['sort'])) {
  368. if ($input['sort'] != null) {
  369. switch ($input['sort']) {
  370. case '1':
  371. $query->orderBy(['pfg_house.sale_price' => SORT_ASC, 'pfg_house.id' => SORT_DESC]);
  372. break;
  373. case '2':
  374. $query->orderBy(['pfg_house.sale_price' => SORT_DESC, 'pfg_house.id' => SORT_DESC]);
  375. break;
  376. }
  377. }
  378. } else {
  379. $query->orderBy(['pfg_house.sort' => SORT_DESC, 'pfg_house.id' => SORT_DESC]);
  380. }
  381. }
  382. if (!empty($input['page']) && !empty($input['limit']) && is_numeric($input['page'])) {
  383. $query->offset = ($input['page'] - 1) * $input['limit'];
  384. $query->limit = $input['limit'];
  385. } else {
  386. $query->limit = 10;
  387. }
  388. return $query->asArray()->all();
  389. }
  390. //前端调用
  391. public function Qdetails($sele = null)
  392. {
  393. $query = $this->QueryFind();
  394. $query->select($sele);
  395. $query->andWhere(['pfg_house.del' => $this->setDel]);
  396. $query->andWhere(['pfg_house.is_view' => 1]);//上线打开
  397. $query->andFilterWhere(['pfg_house.id' => $this->id]);
  398. $query->andFilterWhere(['pfg_category_city.state' => 1]);
  399. $query->andFilterWhere(['pfg_house.city' => $this->city]);
  400. $query->andFilterWhere(['pfg_house.price' => $this->price]);
  401. $query->andFilterWhere(['like', 'pfg_house.characteristic', $this->characteristic]);
  402. $query->andFilterWhere(['or like', 'pfg_house.name', $this->name]);
  403. $query->andFilterWhere(['or like', 'pfg_house.pinyin', $this->pinyin]);
  404. $query->andFilterWhere(['pfg_house_type.type_id' => $this->typeHouse]);
  405. $query = $this->LeftJoin_house_detail($query);
  406. $query = $this->LeftJoin_Category_city($query);
  407. return $query->asArray()->one();
  408. }
  409. //
  410. public function HomegetList($limit, $input = null)
  411. {
  412. $query = $this->QueryFind();
  413. //处理价格是待定的状态
  414. if (isset($input['sale_price'])) {
  415. $query->andWhere(['pfg_house.sale_price' => $input['sale_price']]);
  416. }
  417. $query->select(['pfg_category_city.city_name', 'pfg_house.name', 'pfg_house.city', 'pfg_house.sale_price', 'pfg_house_detail.price_unit', 'pfg_house.id', 'pfg_house.thumb', 'pfg_house_detail.main_units', 'pfg_house.characteristic']);
  418. $query = $this->LeftJoin_where($query);
  419. $query = $this->LeftJoin_house_detail($query);
  420. $query = $this->LeftJoin_Category_city($query);
  421. if (!empty($input['page'])) {
  422. $query->offset = ($input['page'] - 1) * $input['limit'];
  423. $query->limit = $input['limit'];
  424. } else {
  425. $query->limit = $limit;
  426. }
  427. return $query->orderBy(['pfg_house.sort' => SORT_DESC, 'pfg_house.id' => SORT_DESC])->asArray()->all();
  428. }
  429. /*
  430. * 传入条件 随机返回数据
  431. * */
  432. public function randList($limit, $input = null)
  433. {
  434. $query = $this->QueryFind();
  435. //处理价格是待定的状态
  436. // if(isset($input['price'])&&!empty($input['price'])){
  437. // $query->andWhere(['pfg_house.price'=>$input['price']]);
  438. // }
  439. $query->select(['pfg_category_city.id as city', 'pfg_category_city.city_name', 'pfg_house.name', 'pfg_house.sale_price', 'pfg_house_detail.price_unit', 'pfg_house.id', 'pfg_house.thumb', 'pfg_house_detail.address', 'pfg_house.characteristic', 'pfg_house.state']);
  440. $query = $this->LeftJoin_where($query);
  441. $query = $this->LeftJoin_house_detail($query);
  442. $query = $this->LeftJoin_Category_city($query);
  443. if (!empty($input['house_id'])) {
  444. $query->andWhere(['<>', 'pfg_house.id', $input['house_id']]);
  445. }
  446. $query->limit = $limit;
  447. return $query->orderBy('RAND()')->asArray()->all();
  448. }
  449. /*
  450. * 传入条件 随机返回主推楼盘
  451. * */
  452. public function ispush($limit, $input = null)
  453. {
  454. $query = $this->QueryFind();
  455. //处理价格是待定的状态
  456. // if(isset($input['price'])&&!empty($input['price'])){
  457. // $query->andWhere(['pfg_house.price'=>$input['price']]);
  458. // }
  459. $query->select(['pfg_category_city.id as city', 'pfg_category_city.city_name', 'pfg_house.name', 'pfg_house.sale_price', 'pfg_house_detail.price_unit', 'pfg_house.id', 'pfg_house.thumb', 'pfg_house_detail.address', 'pfg_house.characteristic']);
  460. $query = $this->LeftJoin_where($query);
  461. $query = $this->LeftJoin_house_detail($query);
  462. $query = $this->LeftJoin_Category_city($query);
  463. if (!empty($input['page'])) {
  464. $query->offset = ($input['page'] - 1) * 5;
  465. $query->limit = 5;
  466. } else {
  467. $query->limit = $limit;
  468. }
  469. return $query->orderBy('RAND()')->asArray()->all();
  470. }
  471. /*
  472. * 传入条件 随机返回主推楼盘
  473. * */
  474. public function ispushcount()
  475. {
  476. $query = $this->QueryFind();
  477. $query = $this->LeftJoin_where($query);
  478. $query = $this->LeftJoin_house_detail($query);
  479. $query = $this->LeftJoin_Category_city($query);
  480. return $query->count();
  481. }
  482. // /**
  483. // * 主推楼盘,
  484. // */
  485. // public function PushList($limit,$input = null)
  486. // {
  487. // $query = $this->QueryFind();
  488. // //处理价格是待定的状态
  489. // if(isset($input['price'])){
  490. // $query->andWhere(['pfg_house.sale_price'=>$input['price']]);
  491. // }
  492. //
  493. // $query->select(['pfg_category_city.id as city','pfg_category_city.city_name','pfg_house.name','pfg_house.sale_price','pfg_house_detail.price_unit','pfg_house.id','pfg_house.thumb','pfg_house_detail.address','pfg_house.characteristic']);
  494. // $query = $this->LeftJoin_where($query);
  495. // $query = $this->LeftJoin_house_detail($query);
  496. // $query = $this->LeftJoin_Category_city($query);
  497. // $query->limit = $limit;
  498. // return $query->orderBy(['pfg_houseis_pu'])->asArray()->all();
  499. // }
  500. public function OneDetails($sele = null)
  501. {
  502. return self::find()->select($sele)->andWhere(['del' => $this->setDel])->andFilterWhere(['id' => $this->id])->asArray()->one();
  503. }
  504. public function HouseName()
  505. {
  506. $query = $this->QueryFind();
  507. $query->andWhere(['pfg_house.del' => $this->setDel]);
  508. $query->andWhere(['pfg_house.is_view' => 1]); //上线打开
  509. $query->andWhere(['pfg_category_city.state' => 1]);
  510. $query->andFilterWhere(['pfg_house.is_push' => $this->is_push]);
  511. $query->andFilterWhere(['like', 'pfg_house.name', $this->name]);
  512. $query->andFilterWhere(['like', 'pfg_house.pinyin', $this->pinyin . '%', false]);
  513. //限制海南IP的操作
  514. $query->andWhere(['pfg_house.prohibit_city' => '']);
  515. $query = $this->LeftJoin_Category_city($query);
  516. $query = $this->LeftJoin_house_detail($query);
  517. $query->select(['pfg_house.name', 'pfg_house.id', 'pfg_house.sale_price', 'pfg_category_city.city_name', 'pfg_house_detail.price_unit']);
  518. return $query->orderBy(['pfg_house.sort' => SORT_DESC])->asArray()->all();
  519. }
  520. public function CityHouse()
  521. {
  522. $query = $this->QueryFind();
  523. $query->andWhere(['pfg_house.del' => $this->setDel]);
  524. $query->andWhere(['pfg_house.is_view' => 1]); //上线打开
  525. $query->andFilterWhere(['like', 'pfg_house.name', $this->name]);
  526. $query->andFilterWhere(['like', 'pfg_house.city', $this->city]);
  527. $query->andFilterWhere(['like', 'pfg_house.pinyin', $this->pinyin . '%', false]);
  528. $query = $this->LeftJoin_Category_city($query);
  529. $query = $this->LeftJoin_house_detail($query);
  530. $query->select(['pfg_house.name', 'pfg_house.id', 'pfg_house.sale_price', 'pfg_category_city.city_name', 'pfg_house_detail.price_unit', 'pfg_house.thumb', 'pfg_house_detail.longitude_latitude', 'pfg_house_detail.main_units', 'pfg_house_detail.address']);
  531. return $query->orderBy(['pfg_house.sort' => SORT_DESC])->asArray()->all();
  532. }
  533. //手机端 首页热门楼盘调用
  534. public function HotList($limit = 5)
  535. {
  536. $query = $this->QueryFind();
  537. $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.characteristic', 'pfg_house.id', 'pfg_house.thumb']);
  538. $query = $this->LeftJoin_where($query);
  539. $query = $this->LeftJoin_Category_city($query);
  540. $query = $this->LeftJoin_house_detail($query);
  541. $query->limit = $limit;
  542. return $query->orderBy(['pfg_house.sort' => SORT_DESC, 'id' => SORT_DESC])->asArray()->all();
  543. }
  544. protected function LeftJoin_where($query)
  545. {
  546. $query->andWhere(['pfg_house.del' => $this->setDel]);
  547. $query->andWhere(['pfg_house.is_view' => 1]);//上线打开
  548. $query->andFilterWhere(['pfg_house.id' => $this->id]);
  549. $query->andFilterWhere(['pfg_category_city.state' => 1]);
  550. $query->andFilterWhere(['pfg_category_city.abroad' => 1]); // 国内
  551. $query->andFilterWhere(['pfg_house.city' => $this->city]);
  552. $query->andFilterWhere(['pfg_house.price' => $this->price]);
  553. $query->andFilterWhere(['pfg_house.is_push' => $this->is_push]);
  554. $query->andFilterWhere(['pfg_house.sale_price' => $this->sale_price]);
  555. $query->andFilterWhere(['like', 'pfg_house.characteristic', $this->characteristic]);
  556. if (!empty(\Yii::$app->request->get('name'))) {
  557. $city = CategoryCity::find()->andWhere(['del' => 1])->andWhere(['like', 'city_name', \Yii::$app->request->get('name')])->select(['id'])->column();
  558. $query->andFilterWhere(['or like', 'pfg_house.name', $this->name]);
  559. $query->orFilterWhere(['pfg_house.city' => $city]);
  560. }
  561. $query->andFilterWhere(['or like', 'pfg_house.pinyin', $this->pinyin]);
  562. $query->andFilterWhere(['pfg_house_type.type_id' => $this->typeHouse]);
  563. if ((!empty($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'] == '/house/vr') || (!empty($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'] == '/house/vr/')) {
  564. $query->andWhere(['NOT', ['pfg_house_detail.panorama' => '']]);
  565. }
  566. $query->andWhere(['pfg_house.prohibit_city' => '']); //限制无法搜索
  567. return $query;
  568. }
  569. protected function LeftJoin_Category_city($query)
  570. {
  571. return $query->leftJoin('pfg_category_city', 'pfg_house.city=pfg_category_city.id');
  572. }
  573. //豪宅
  574. protected function InnerJoin_Mansion($query)
  575. {
  576. $query->andWhere(['pfg_pushm_mansion.is_show' => 1]);
  577. $query->innerJoin('pfg_pushm_mansion', 'pfg_house.id = pfg_pushm_mansion.hid');
  578. return $query->leftJoin('pfg_developers', 'pfg_pushm_mansion.did = pfg_developers.id');
  579. }
  580. //豪宅总数
  581. public function Count_Mansion()
  582. {
  583. $query = self::find();
  584. $query->andWhere(['pfg_pushm_mansion.is_show' => 1]);
  585. $query->innerJoin('pfg_pushm_mansion', 'pfg_house.id = pfg_pushm_mansion.hid');
  586. return $query->count();
  587. }
  588. protected function LeftJoin_house_detail($query)
  589. {
  590. return $query->leftJoin('pfg_house_detail', 'pfg_house.id=pfg_house_detail.hid');
  591. }
  592. protected function LeftJoin_house_city($query)
  593. {
  594. return $query->leftJoin('pfg_category_city', 'pfg_house.city=pfg_category_city.id');
  595. }
  596. protected function LeftJoin_house_type($query)
  597. {
  598. return $query;
  599. // ->leftJoin('pfg_house_type','pfg_house.id=pfg_house_type.hid');
  600. }
  601. private function QueryFind()
  602. {
  603. return self::find();
  604. }
  605. public function FindById($id)
  606. {
  607. return self::findOne($id);
  608. }
  609. //获取别墅
  610. public function getVilla($select = null, $limit)
  611. {
  612. $query = self::find();
  613. $query->select($select);
  614. $query->leftJoin('pfg_category_city', 'pfg_house.city=pfg_category_city.id');
  615. $query->leftJoin('pfg_house_detail', 'pfg_house.id=pfg_house_detail.hid');
  616. $query->andFilterWhere(['or', ['like', 'pfg_house.type', 18]]);
  617. $query->limit = $limit;
  618. return $query->orderBy(['pfg_house.sort' => SORT_DESC])->asArray()->all();
  619. }
  620. /*
  621. * 检测楼盘是否正常显示
  622. */
  623. public function HouseIsshow($id)
  624. {
  625. return static::find()->andWhere(['id' => $id])->andWhere(['del' => 1])->andWhere(['is_view' => 1])->exists();
  626. }
  627. public function GetOneHouse($id)
  628. {
  629. $query = self::find();
  630. $query->andWhere(['pfg_house.del' => 1, 'pfg_house.is_view' => 1, 'pfg_house.id' => $id]);
  631. $query->select(['pfg_house.id', 'pfg_house.name', 'pfg_house.sale_price', 'pfg_house.characteristic',
  632. 'pfg_house_detail.address', 'pfg_house_detail.price_unit', 'pfg_house_detail.main_units',
  633. 'pfg_house.thumb', 'pfg_house.city', 'pfg_house_detail.longitude_latitude',
  634. 'pfg_category_city.city_name']);
  635. $query->leftJoin('pfg_house_detail', 'pfg_house.id = pfg_house_detail.hid');
  636. $query->leftJoin('pfg_category_city', 'pfg_house.city = pfg_category_city.id');
  637. return $query->asArray()->one();
  638. }
  639. public function AddNewsHouse()
  640. {
  641. return self::find()->andWhere(['del' => 1, 'is_view' => 1])->select(['id', 'name'])->orderBy(['sort' => SORT_DESC, 'id' => SORT_DESC])->asArray()->all();
  642. }
  643. public static function FindByHid($id)
  644. {
  645. return self::find()->andWhere(['id' => $id, 'del' => 1, 'is_view' => 1])->one();
  646. }
  647. public function getCityName()
  648. {
  649. return $this->hasOne(CategoryCity::className(), ['id' => 'city'])->select(['pfg_category_city.id', 'pfg_category_city.city_name']);
  650. }
  651. public function getHousedetail()
  652. {
  653. return $this->hasOne(HouseDetail::className(), ['hid' => 'id']);
  654. }
  655. public function getCityNameByProvince()
  656. {
  657. return $this->hasOne(CategoryCity::className(), ['id' => 'province'])->select(['id', 'city_name'])->alias('p');
  658. }
  659. public function getHouseTypesGroup()
  660. {
  661. return $this->hasMany(HouseType::className(), ['hid' => 'id'])
  662. ->andWhere(['pfg_house_type.del' => 1, 'pfg_house_type.state' => 1])->groupBy(['type_id'])
  663. ->joinWith(['houseTypeName' => function ($q) {
  664. $q->select(['pfg_category_housetype.id', 'pfg_category_housetype.huxing_name']);
  665. }])->asArray();
  666. }
  667. public function getCityHouseList($limit = null)
  668. {
  669. $selct = [
  670. 'pfg_house.name',
  671. 'pfg_house.id',
  672. 'pfg_house.city',
  673. 'pfg_house.sale_price',
  674. 'pfg_category_city.city_name',
  675. 'pfg_house_detail.price_unit',
  676. 'pfg_house.thumb',
  677. 'pfg_house_detail.preferential',
  678. 'pfg_house_detail.main_units',
  679. 'pfg_house_detail.address'
  680. ];
  681. $query = $this->QueryFind();
  682. $query->andWhere(['pfg_house.del' => $this->setDel]);
  683. $query->andWhere(['pfg_house.is_view' => 1]); //上线打开
  684. $query->andFilterWhere(['pfg_house.city' => $this->city]);
  685. $query = $this->LeftJoin_Category_city($query);
  686. $query = $this->LeftJoin_house_detail($query);
  687. $query->select($selct);
  688. if (!empty($limit)) {
  689. $query->limit($limit);
  690. }
  691. return $query->orderBy(['pfg_house.sort' => SORT_DESC, 'id' => SORT_DESC])->asArray()->all();
  692. }
  693. }