123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826 |
- <?php
- /**
- * Created by PhpStorm.
- * User: xiaofeng
- * Date: 2018/3/4
- * Time: 上午9:33
- */
- namespace common\models;
- use yii\data\Pagination;
- class House extends Common
- {
- public $typeHouse; //户型搜索条件
- public function rules()
- {
- // apartment 保留户型
- // return [
- // [['name','pinyin','state'],'required','message'=>'{attribute}不能为空'],
- // ['name', 'unique', 'targetClass' => 'common\models\House','on'=>'add','message'=>'楼盘名称已经存在'],
- // ['state','in','range'=>[1,2,3,4]],
- // [['sort','sale_price'],'number'],
- // [['name'],'trim'],
- //// [['type','city','price','characteristic'],'string','max'=>100],
- // [['city','price','alias_name'],'string','max'=>100],
- // ['type','each','rule'=>['integer'],'message'=>'aaaa'], //验证
- // ['characteristic','each','rule'=>['integer'],'message'=>'aaaa'],
- // ['architecture_type','each','rule'=>['integer'],'message'=>'aaaa'],
- // ['thumb','string','links','max'=>200],
- // ['del','in','range'=>[1,2]],
- // ['is_push','in','range'=>[1,2]],
- // ['is_push','default','value'=>1],
- // ];
- return [
- [['name', 'pinyin', 'state', 'city'], 'required', 'message' => '{attribute}不能为空'],
- ['name', 'unique', 'targetClass' => 'common\models\House', 'on' => ['add', 'edit'], 'message' => '楼盘名称已经存在', 'filter' => function ($query) {
- return $query->andWhere(['del' => $this->setDel]);
- }],
- ['state', 'in', 'range' => [1, 2, 3, 4]],
- [['sort', 'sale_price', 'province', 'area'], 'number'],
- [['name'], 'trim'],
- // [['type','city','price','characteristic'],'string','max'=>100],
- [['city', 'price', 'alias_name'], 'string', 'max' => 100],
- ['type', 'each', 'rule' => ['integer'], 'message' => '物业类型必填'], //验证
- ['characteristic', 'each', 'rule' => ['integer'], 'message' => '特色主题必填'],
- ['architecture_type', 'each', 'rule' => ['integer'], 'message' => '建筑类别必填'],
- ['thumb', 'string', 'max' => 200],
- ['del', 'in', 'range' => [1, 2]],
- ['is_push', 'in', 'range' => [1, 2]],
- ['is_push', 'default', 'value' => 1],
- ['sale_price', 'default', 'value' => 0],
- ['is_view', 'default', 'value' => 2],
- ['is_tel', 'string', 'max' => 20],
- ['links', 'string'],
- ['prohibit_city', 'string', 'max' => 255],
- ['prohibit_city', 'default', 'value' => ''],
- ['customer_service', 'string']
- ];
- }
- public function attributeLabels()
- {
- return [
- 'name' => '楼盘名称',
- 'pinyin' => '楼盘拼音不能为空',
- 'type' => '物业类型',
- 'city' => '区域',
- 'price' => '价格区间',
- 'characteristic' => '特色主题',
- 'thumb' => '图片',
- 'state' => '销售状态',
- 'sale_price' => '均价',
- 'architecture_type' => '建筑类别',
- 'alias_name' => '楼盘别名',
- 'is_push' => '主推楼盘',
- 'is_tel' => '电话',
- 'prohibit_city' => '禁售区域',
- ];
- }
- public function Authenticator($input)
- {
- $this->load($input, '');
- if (!$this->validate()) return $this->errors;
- return $this;
- }
- public function getList($page)
- {
- $query = self::find();
- $query->andWhere(['pfg_house.del' => $this->setDel,'pfg_category_city.del'=>1]);
- if (!empty($page['id'])) {
- $query->andFilterWhere(['pfg_house.id' => $page['id']]);
- }
- if (!empty($page['city'])) {
- $query->andFilterWhere(['pfg_house.city' => $page['city']]);
- }
- if (!empty($page['start_time'])) {
- $query->andFilterWhere(['>=', 'pfg_house.create_at', strtotime($page['start_time'] . ' 00:00:00')]);
- }
- if (!empty($page['end_time'])) {
- $query->andFilterWhere(['<=', 'pfg_house.create_at', strtotime($page['end_time'] . ' 23:59:59')]);
- }
- if (!empty($page['name'])) {
- $query->andFilterWhere(['like', 'pfg_house.name', trim($page['name'], " ")]);
- }
- if (!empty($page['pinyin'])) {
- $query->andFilterWhere(['like', 'pfg_house.pinyin', $page['pinyin']]);
- }
- if (!empty($page['characteristic'])) {
- $query->andFilterWhere(['like', 'pfg_house.characteristic', $page['characteristic']]);
- }
- if (!empty($page['price'])) {
- $query->andFilterWhere(['pfg_house.price' => $page['price']]);
- }
- if (!empty($page['is_view'])) {
- $query->andWhere(['pfg_house.is_view' => $page['is_view']]);
- }
- if (!empty($page['price_unit']) && $page['price_unit'] == 'price_unit') {
- $query->andWhere(['NOT', ['pfg_house.sale_price' => '']]);
- $query->andWhere(['pfg_house_detail.price_unit' => '']);
- }
- if (!empty($page['price_unit']) && $page['price_unit'] == 'is_permit') {
- $s = HousePermit::find()->select(['hid'])->groupBy('hid')->asArray()->all();
- $query->andWhere(['not in', 'pfg_house.id', array_column($s, 'hid')]);
- }
- if (!empty($page['price_unit']) && $page['price_unit'] == 'discount') {
- $query->andWhere(['pfg_house_detail.preferential' => '']);
- }
- if (!empty($page['price_unit']) && $page['price_unit'] == 'discounts') {
- $query->andWhere(['NOT', ['pfg_house_detail.preferential' => '']]);
- }
- if (!empty($page['sort'])) {
- if ($page['sort'] == 'sort') {
- $query->orderBy(['pfg_house.sort' => SORT_DESC, 'pfg_house.id' => SORT_DESC]);
- }
- if ($page['sort'] == 'map') {
- $query->orderBy(['pfg_house.is_push'=>SORT_DESC,'pfg_house.sort' => SORT_DESC, 'pfg_house.id' => SORT_DESC]);
- }
- if ($page['sort'] == 'regionsort') {
- $query->orderBy(['pfg_house_detail.regionsort' => SORT_DESC, 'pfg_house.id' => SORT_DESC]);
- }
- if ($page['sort'] == 'allsort') {
- $query->orderBy(['pfg_house_detail.allsort' => SORT_DESC, 'pfg_house.id' => SORT_DESC]);
- }
- }
- if (!empty($page['is_push'])) {
- $query->andWhere(['pfg_house.is_push' => $page['is_push']]);
- $query->orderBy(['pfg_house.create_at' => SORT_DESC]);
- }
- $query->leftJoin('pfg_category_city', 'pfg_house.city=pfg_category_city.id');
- $query->leftJoin('pfg_house_detail', 'pfg_house.id=pfg_house_detail.hid');
- $query->leftJoin('pfg_user_house', 'pfg_house.id=pfg_user_house.hid');
- $query->leftJoin('pfg_user', 'pfg_user_house.uid=pfg_user.uid');
- $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']);
- if (!empty($page['page'])) {
- $query->offset = ($page['page'] - 1) * $page['limit'];
- $query->limit = $page['limit'];
- }
- return $query->asArray()->all();
- }
- public function getListTotal($page)
- {
- $query = self::find();
- $query->andWhere(['pfg_house.del' => $this->setDel]);
- if (!empty($page['id'])) {
- $query->andFilterWhere(['pfg_house.id' => $page['id']]);
- } else if (!empty($page['city'])) {
- $query->andFilterWhere(['pfg_house.city' => $page['city']]);
- } else if (!empty($page['name'])) {
- $query->andFilterWhere(['like', 'pfg_house.name', trim($page['name'], "")]);
- }
- if (!empty($page['characteristic'])) {
- $query->andFilterWhere(['like', 'pfg_house.characteristic', $page['characteristic']]);
- }
- if (!empty($page['price'])) {
- $query->andFilterWhere(['pfg_house.price' => $page['price']]);
- }
- if (!empty($page['is_view'])) {
- $query->andWhere(['pfg_house.is_view' => $page['is_view']]);
- }
- if (!empty($page['start_time'])) {
- $query->andFilterWhere(['>=', 'pfg_house.create_at', strtotime($page['start_time'] . ' 00:00:00')]);
- }
- if (!empty($page['end_time'])) {
- $query->andFilterWhere(['<=', 'pfg_house.create_at', strtotime($page['end_time'] . ' 23:59:59')]);
- }
- if (!empty($page['price_unit']) && $page['price_unit'] == 'price_unit') {
- $query->andWhere(['NOT', ['pfg_house.sale_price' => '']]);
- $query->andWhere(['pfg_house_detail.price_unit' => '']);
- }
- if (!empty($page['price_unit']) && $page['price_unit'] == 'discount') {
- $query->andWhere(['pfg_house_detail.preferential' => '']);
- }
- if (!empty($page['price_unit']) && $page['price_unit'] == 'discounts') {
- $query->andWhere(['NOT', ['pfg_house_detail.preferential' => '']]);
- }
- if (!empty($page['is_push'])) {
- $query->andWhere(['pfg_house.is_push' => $page['is_push']]);
- }
- if (!empty($page['price_unit']) && $page['price_unit'] == 'is_permit') {
- $s = HousePermit::find()->select(['hid'])->groupBy('hid')->asArray()->all();
- // $a = self::find();
- // $a->select(['pfg_house_permit.hid']);
- // $a->leftJoin('pfg_house_permit','pfg_house.id = pfg_house_permit.hid');
- // $a->asArray();
- // $s = $a->all();
- $query->andWhere(['not in', 'pfg_house.id', array_column($s, 'hid')]);
- }
- $query->leftJoin('pfg_category_city', 'pfg_house.city=pfg_category_city.id');
- $query->leftJoin('pfg_house_detail', 'pfg_house.id=pfg_house_detail.hid');
- $query->leftJoin('pfg_user_house', 'pfg_house.id=pfg_user_house.hid');
- $query->leftJoin('pfg_user', 'pfg_user_house.uid=pfg_user.uid');
- return $query->count();
- }
- public function HousesAll()
- {
- $query = self::find();
- $query->andWhere(['pfg_house.id' => $this->id]);
- $query->andWhere(['pfg_house.del' => $this->setDel]);
- $query->select(['pfg_house.*', 'pfg_house_detail.*']);
- $query->leftJoin('pfg_house_detail', 'pfg_house.id=pfg_house_detail.hid');
- return $query->asArray()->one();
- }
- private function WhereColumn($query)
- {
- $query->andFilterWhere(['name' => $this->name]);
- $query->andFilterWhere(['id' => $this->id]);
- $query->andWhere(['del' => $this->setDel]);
- return $query;
- }
- public function total()
- {
- $query = $this->QueryFind();
- $query = $this->WhereColumn($query);
- return $query->count();
- }
- //楼盘和楼盘附表信息
- public function QgetList($arr = null, $sort = null)
- {
- $query = $this->QueryFind();
- $query->select($arr);
- $query = $this->LeftJoin_where($query);
- $query = $this->LeftJoin_house_detail($query);
- $query = $this->LeftJoin_house_type($query);
- $query = $this->LeftJoin_house_city($query);
- $pages = new Pagination(['totalCount' => $this->PaginationTotal(), 'pageSize' => 8, 'pageSizeParam' => false, 'validatePage' => false,]);
- $query->offset($pages->offset)->limit($pages->limit);
- //
- // if(!isset($sort['py']) && $_SERVER['HTTP_HOST'] == $_SERVER['SERVER_NAME']){
- //
- // $query->orderBy(['pfg_house_detail.allsort'=>SORT_DESC,'pfg_house_detail.hid'=>SORT_DESC]);
- //
- //
- // }
- // else{
- // $query->orderBy(['pfg_house.sort'=>SORT_DESC]);
- //// $query->orderBy(['pfg_house_detail.regionsort'=>SORT_DESC,'pfg_house_detail.hid'=>SORT_DESC]);
- //
- // }
- // if(isset($sort['son']) && $sort['son'] == 'son'){
- //
- // $query->orderBy(['pfg_house.sort'=>SORT_DESC]);
- //
- // }
- // if (!empty($sort['renqi'])){
- // $query->orderBy(['pfg_house.is_push'=>SORT_DESC]);
- //
- // } else if(isset($sort['pricesort'])) {
- //
- // switch ($sort['pricesort'])
- // {
- // case 1:
- // $query->orderBy(['pfg_house.sale_price'=>SORT_ASC]);
- // break;
- // case 2:
- // $query->orderBy(['pfg_house.sale_price'=>SORT_DESC]);
- // break;
- // }
- //
- // }
- if (\Yii::$app->hostserver->hostId == 0) {
- $query->orderBy(['pfg_house_detail.allsort' => SORT_DESC, 'pfg_house.id' => SORT_DESC]);
- if (!empty($sort['py']) && is_array($sort['city'])) {
- $query->orderBy(['pfg_house_detail.regionsort' => SORT_DESC, 'pfg_house.id' => SORT_DESC]);
- } else if (!is_array($sort['city'])) {
- $query->orderBy(['pfg_house.sort' => SORT_DESC, 'pfg_house.id' => SORT_DESC]);
- }
- } else {
- $query->orderBy(['pfg_house_detail.regionsort' => SORT_DESC, 'pfg_house.id' => SORT_DESC]);
- if (!is_array($sort['city'])) {
- $query->orderBy(['pfg_house.sort' => SORT_DESC, 'pfg_house.id' => SORT_DESC]);
- }
- }
- if (!empty($sort['renqi'])) {
- $query->orderBy(['pfg_house.click_num' => SORT_DESC, 'pfg_house.id' => SORT_DESC]);
- }
- $models = $query->asArray()->all();
- $data['page'] = $pages;
- $data['data'] = $models;
- return $data;
- }
- public function MapSearch($arr)
- {
- $query = $this->QueryFind();
- $query->select($arr);
- $query = $this->LeftJoin_where($query);
- $query = $this->LeftJoin_house_detail($query);
- $query = $this->LeftJoin_house_type($query);
- $query = $this->LeftJoin_house_city($query);
- return $query->asArray()->all();
- }
- //总数
- public function PcHouseListTotal()
- {
- $query = $this->QueryFind();
- $query = $this->LeftJoin_where($query);
- $query = $this->LeftJoin_house_detail($query);
- $query = $this->LeftJoin_house_type($query);
- $query = $this->LeftJoin_house_city($query);
- return $query->count();
- }
- public function PaginationTotal()
- {
- $query = $this->QueryFind();
- $query = $this->LeftJoin_where($query);
- $query = $this->LeftJoin_house_detail($query);
- $query = $this->LeftJoin_house_type($query);
- $query = $this->LeftJoin_house_city($query);
- return $query->count();
- }
- //pc端楼盘列表
- public function PcHouseList($input, $select = null, $sort = null)
- {
- $query = $this->QueryFind();
- $query->select($select);
- $query = $this->LeftJoin_where($query);
- $query = $this->LeftJoin_house_detail($query);
- $query = $this->LeftJoin_house_type($query);
- $query = $this->LeftJoin_house_city($query);
- if (!empty($input['hao'])) {
- $query = $this->InnerJoin_Mansion($query);
- }
- if (!isset($sort['py']) && $_SERVER['HTTP_HOST'] == $_SERVER['SERVER_NAME']) {
- if (\Yii::$app->hostserver->hostId != 0) {
- $query->orderBy(['pfg_house_detail.regionsort' => SORT_DESC, 'pfg_house.id' => SORT_DESC]);
- } else {
- $query->orderBy(['pfg_house_detail.allsort' => SORT_DESC, 'pfg_house_detail.hid' => SORT_DESC]);
- }
- } else {
- if ($sort != null) {
- switch ($sort) {
- case '1':
- $query->orderBy(['pfg_house.sale_price' => SORT_ASC]);
- break;
- case '2':
- $query->orderBy(['pfg_house.sale_price' => SORT_DESC]);
- break;
- }
- }
- if (\Yii::$app->hostserver->hostId != 0) {
- $query->orderBy(['pfg_house_detail.regionsort' => SORT_DESC, 'pfg_house.id' => SORT_DESC]);
- } else {
- $query->orderBy(['pfg_house.sort' => SORT_DESC, 'pfg_house.id' => SORT_DESC]);
- }
- }
- if (!empty($input['city'])) {
- $query->orderBy(['pfg_house.sort' => SORT_DESC, 'pfg_house.id' => SORT_DESC]);
- }
- //加入豪宅排序
- if (!empty($input['hao'])) {
- if (!empty($input['sort'])) {
- if ($input['sort'] != null) {
- switch ($input['sort']) {
- case '1':
- $query->orderBy(['pfg_house.sale_price' => SORT_ASC, 'pfg_house.id' => SORT_DESC]);
- break;
- case '2':
- $query->orderBy(['pfg_house.sale_price' => SORT_DESC, 'pfg_house.id' => SORT_DESC]);
- break;
- }
- }
- } else {
- $query->orderBy(['pfg_house.sort' => SORT_DESC, 'pfg_house.id' => SORT_DESC]);
- }
- }
- if (!empty($input['page']) && !empty($input['limit']) && is_numeric($input['page'])) {
- $query->offset = ($input['page'] - 1) * $input['limit'];
- $query->limit = $input['limit'];
- } else {
- $query->limit = 10;
- }
- return $query->asArray()->all();
- }
- //前端调用
- public function Qdetails($sele = null)
- {
- $query = $this->QueryFind();
- $query->select($sele);
- $query->andWhere(['pfg_house.del' => $this->setDel]);
- $query->andWhere(['pfg_house.is_view' => 1]);//上线打开
- $query->andFilterWhere(['pfg_house.id' => $this->id]);
- $query->andFilterWhere(['pfg_category_city.state' => 1]);
- $query->andFilterWhere(['pfg_house.city' => $this->city]);
- $query->andFilterWhere(['pfg_house.price' => $this->price]);
- $query->andFilterWhere(['like', 'pfg_house.characteristic', $this->characteristic]);
- $query->andFilterWhere(['or like', 'pfg_house.name', $this->name]);
- $query->andFilterWhere(['or like', 'pfg_house.pinyin', $this->pinyin]);
- $query->andFilterWhere(['pfg_house_type.type_id' => $this->typeHouse]);
- $query = $this->LeftJoin_house_detail($query);
- $query = $this->LeftJoin_Category_city($query);
- return $query->asArray()->one();
- }
- //
- public function HomegetList($limit, $input = null)
- {
- $query = $this->QueryFind();
- //处理价格是待定的状态
- if (isset($input['sale_price'])) {
- $query->andWhere(['pfg_house.sale_price' => $input['sale_price']]);
- }
- $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']);
- $query = $this->LeftJoin_where($query);
- $query = $this->LeftJoin_house_detail($query);
- $query = $this->LeftJoin_Category_city($query);
- if (!empty($input['page'])) {
- $query->offset = ($input['page'] - 1) * $input['limit'];
- $query->limit = $input['limit'];
- } else {
- $query->limit = $limit;
- }
- return $query->orderBy(['pfg_house.sort' => SORT_DESC, 'pfg_house.id' => SORT_DESC])->asArray()->all();
- }
- /*
- * 传入条件 随机返回数据
- * */
- public function randList($limit, $input = null)
- {
- $query = $this->QueryFind();
- //处理价格是待定的状态
- // if(isset($input['price'])&&!empty($input['price'])){
- // $query->andWhere(['pfg_house.price'=>$input['price']]);
- // }
- $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']);
- $query = $this->LeftJoin_where($query);
- $query = $this->LeftJoin_house_detail($query);
- $query = $this->LeftJoin_Category_city($query);
- if (!empty($input['house_id'])) {
- $query->andWhere(['<>', 'pfg_house.id', $input['house_id']]);
- }
- $query->limit = $limit;
- return $query->orderBy('RAND()')->asArray()->all();
- }
- /*
- * 传入条件 随机返回主推楼盘
- * */
- public function ispush($limit, $input = null)
- {
- $query = $this->QueryFind();
- //处理价格是待定的状态
- // if(isset($input['price'])&&!empty($input['price'])){
- // $query->andWhere(['pfg_house.price'=>$input['price']]);
- // }
- $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']);
- $query = $this->LeftJoin_where($query);
- $query = $this->LeftJoin_house_detail($query);
- $query = $this->LeftJoin_Category_city($query);
- if (!empty($input['page'])) {
- $query->offset = ($input['page'] - 1) * 5;
- $query->limit = 5;
- } else {
- $query->limit = $limit;
- }
- return $query->orderBy('RAND()')->asArray()->all();
- }
- /*
- * 传入条件 随机返回主推楼盘
- * */
- public function ispushcount()
- {
- $query = $this->QueryFind();
- $query = $this->LeftJoin_where($query);
- $query = $this->LeftJoin_house_detail($query);
- $query = $this->LeftJoin_Category_city($query);
- return $query->count();
- }
- // /**
- // * 主推楼盘,
- // */
- // public function PushList($limit,$input = null)
- // {
- // $query = $this->QueryFind();
- // //处理价格是待定的状态
- // if(isset($input['price'])){
- // $query->andWhere(['pfg_house.sale_price'=>$input['price']]);
- // }
- //
- // $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']);
- // $query = $this->LeftJoin_where($query);
- // $query = $this->LeftJoin_house_detail($query);
- // $query = $this->LeftJoin_Category_city($query);
- // $query->limit = $limit;
- // return $query->orderBy(['pfg_houseis_pu'])->asArray()->all();
- // }
- public function OneDetails($sele = null)
- {
- return self::find()->select($sele)->andWhere(['del' => $this->setDel])->andFilterWhere(['id' => $this->id])->asArray()->one();
- }
- public function HouseName()
- {
- $query = $this->QueryFind();
- $query->andWhere(['pfg_house.del' => $this->setDel]);
- $query->andWhere(['pfg_house.is_view' => 1]); //上线打开
- $query->andWhere(['pfg_category_city.state' => 1]);
- $query->andFilterWhere(['pfg_house.is_push' => $this->is_push]);
- $query->andFilterWhere(['like', 'pfg_house.name', $this->name]);
- $query->andFilterWhere(['like', 'pfg_house.pinyin', $this->pinyin . '%', false]);
- //限制海南IP的操作
- $query->andWhere(['pfg_house.prohibit_city' => '']);
- $query = $this->LeftJoin_Category_city($query);
- $query = $this->LeftJoin_house_detail($query);
- $query->select(['pfg_house.name', 'pfg_house.id', 'pfg_house.sale_price', 'pfg_category_city.city_name', 'pfg_house_detail.price_unit']);
- return $query->orderBy(['pfg_house.sort' => SORT_DESC])->asArray()->all();
- }
- public function CityHouse()
- {
- $query = $this->QueryFind();
- $query->andWhere(['pfg_house.del' => $this->setDel]);
- $query->andWhere(['pfg_house.is_view' => 1]); //上线打开
- $query->andFilterWhere(['like', 'pfg_house.name', $this->name]);
- $query->andFilterWhere(['like', 'pfg_house.city', $this->city]);
- $query->andFilterWhere(['like', 'pfg_house.pinyin', $this->pinyin . '%', false]);
- $query = $this->LeftJoin_Category_city($query);
- $query = $this->LeftJoin_house_detail($query);
- $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']);
- return $query->orderBy(['pfg_house.sort' => SORT_DESC])->asArray()->all();
- }
- //手机端 首页热门楼盘调用
- public function HotList($limit = 5)
- {
- $query = $this->QueryFind();
- $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']);
- $query = $this->LeftJoin_where($query);
- $query = $this->LeftJoin_Category_city($query);
- $query = $this->LeftJoin_house_detail($query);
- $query->limit = $limit;
- return $query->orderBy(['pfg_house.sort' => SORT_DESC, 'id' => SORT_DESC])->asArray()->all();
- }
- protected function LeftJoin_where($query)
- {
- $query->andWhere(['pfg_house.del' => $this->setDel]);
- $query->andWhere(['pfg_house.is_view' => 1]);//上线打开
- $query->andFilterWhere(['pfg_house.id' => $this->id]);
- $query->andFilterWhere(['pfg_category_city.state' => 1]);
- $query->andFilterWhere(['pfg_category_city.abroad' => 1]); // 国内
- $query->andFilterWhere(['pfg_house.city' => $this->city]);
- $query->andFilterWhere(['pfg_house.price' => $this->price]);
- $query->andFilterWhere(['pfg_house.is_push' => $this->is_push]);
- $query->andFilterWhere(['pfg_house.sale_price' => $this->sale_price]);
- $query->andFilterWhere(['like', 'pfg_house.characteristic', $this->characteristic]);
- if (!empty(\Yii::$app->request->get('name'))) {
- $city = CategoryCity::find()->andWhere(['del' => 1])->andWhere(['like', 'city_name', \Yii::$app->request->get('name')])->select(['id'])->column();
- $query->andFilterWhere(['or like', 'pfg_house.name', $this->name]);
- $query->orFilterWhere(['pfg_house.city' => $city]);
- }
- $query->andFilterWhere(['or like', 'pfg_house.pinyin', $this->pinyin]);
- $query->andFilterWhere(['pfg_house_type.type_id' => $this->typeHouse]);
- if ((!empty($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'] == '/house/vr') || (!empty($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'] == '/house/vr/')) {
- $query->andWhere(['NOT', ['pfg_house_detail.panorama' => '']]);
- }
- $query->andWhere(['pfg_house.prohibit_city' => '']); //限制无法搜索
- return $query;
- }
- protected function LeftJoin_Category_city($query)
- {
- return $query->leftJoin('pfg_category_city', 'pfg_house.city=pfg_category_city.id');
- }
- //豪宅
- protected function InnerJoin_Mansion($query)
- {
- $query->andWhere(['pfg_pushm_mansion.is_show' => 1]);
- $query->innerJoin('pfg_pushm_mansion', 'pfg_house.id = pfg_pushm_mansion.hid');
- return $query->leftJoin('pfg_developers', 'pfg_pushm_mansion.did = pfg_developers.id');
- }
- //豪宅总数
- public function Count_Mansion()
- {
- $query = self::find();
- $query->andWhere(['pfg_pushm_mansion.is_show' => 1]);
- $query->innerJoin('pfg_pushm_mansion', 'pfg_house.id = pfg_pushm_mansion.hid');
- return $query->count();
- }
- protected function LeftJoin_house_detail($query)
- {
- return $query->leftJoin('pfg_house_detail', 'pfg_house.id=pfg_house_detail.hid');
- }
- protected function LeftJoin_house_city($query)
- {
- return $query->leftJoin('pfg_category_city', 'pfg_house.city=pfg_category_city.id');
- }
- protected function LeftJoin_house_type($query)
- {
- return $query;
- // ->leftJoin('pfg_house_type','pfg_house.id=pfg_house_type.hid');
- }
- private function QueryFind()
- {
- return self::find();
- }
- public function FindById($id)
- {
- return self::findOne($id);
- }
- //获取别墅
- public function getVilla($select = null, $limit)
- {
- $query = self::find();
- $query->select($select);
- $query->leftJoin('pfg_category_city', 'pfg_house.city=pfg_category_city.id');
- $query->leftJoin('pfg_house_detail', 'pfg_house.id=pfg_house_detail.hid');
- $query->andFilterWhere(['or', ['like', 'pfg_house.type', 18]]);
- $query->limit = $limit;
- return $query->orderBy(['pfg_house.sort' => SORT_DESC])->asArray()->all();
- }
- /*
- * 检测楼盘是否正常显示
- */
- public function HouseIsshow($id)
- {
- return static::find()->andWhere(['id' => $id])->andWhere(['del' => 1])->andWhere(['is_view' => 1])->exists();
- }
- public function GetOneHouse($id)
- {
- $query = self::find();
- $query->andWhere(['pfg_house.del' => 1, 'pfg_house.is_view' => 1, 'pfg_house.id' => $id]);
- $query->select(['pfg_house.id', 'pfg_house.name', 'pfg_house.sale_price', 'pfg_house.characteristic',
- 'pfg_house_detail.address', 'pfg_house_detail.price_unit', 'pfg_house_detail.main_units',
- 'pfg_house.thumb', 'pfg_house.city', 'pfg_house_detail.longitude_latitude',
- 'pfg_category_city.city_name']);
- $query->leftJoin('pfg_house_detail', 'pfg_house.id = pfg_house_detail.hid');
- $query->leftJoin('pfg_category_city', 'pfg_house.city = pfg_category_city.id');
- return $query->asArray()->one();
- }
- public function AddNewsHouse()
- {
- return self::find()->andWhere(['del' => 1, 'is_view' => 1])->select(['id', 'name'])->orderBy(['sort' => SORT_DESC, 'id' => SORT_DESC])->asArray()->all();
- }
- public static function FindByHid($id)
- {
- return self::find()->andWhere(['id' => $id, 'del' => 1, 'is_view' => 1])->one();
- }
- public function getCityName()
- {
- return $this->hasOne(CategoryCity::className(), ['id' => 'city'])->select(['pfg_category_city.id', 'pfg_category_city.city_name']);
- }
- public function getHousedetail()
- {
- return $this->hasOne(HouseDetail::className(), ['hid' => 'id']);
- }
- public function getCityNameByProvince()
- {
- return $this->hasOne(CategoryCity::className(), ['id' => 'province'])->select(['id', 'city_name'])->alias('p');
- }
- public function getHouseTypesGroup()
- {
- return $this->hasMany(HouseType::className(), ['hid' => 'id'])
- ->andWhere(['pfg_house_type.del' => 1, 'pfg_house_type.state' => 1])->groupBy(['type_id'])
- ->joinWith(['houseTypeName' => function ($q) {
- $q->select(['pfg_category_housetype.id', 'pfg_category_housetype.huxing_name']);
- }])->asArray();
- }
-
- public function getCityHouseList($limit = null)
- {
- $selct = [
- 'pfg_house.name',
- 'pfg_house.id',
- 'pfg_house.city',
- 'pfg_house.sale_price',
- 'pfg_category_city.city_name',
- 'pfg_house_detail.price_unit',
- 'pfg_house.thumb',
- 'pfg_house_detail.preferential',
- 'pfg_house_detail.main_units',
- 'pfg_house_detail.address'
- ];
- $query = $this->QueryFind();
- $query->andWhere(['pfg_house.del' => $this->setDel]);
- $query->andWhere(['pfg_house.is_view' => 1]); //上线打开
- $query->andFilterWhere(['pfg_house.city' => $this->city]);
- $query = $this->LeftJoin_Category_city($query);
- $query = $this->LeftJoin_house_detail($query);
- $query->select($selct);
- if (!empty($limit)) {
- $query->limit($limit);
- }
- return $query->orderBy(['pfg_house.sort' => SORT_DESC, 'id' => SORT_DESC])->asArray()->all();
- }
- }
|