Commit 462401b0 authored by hujun's avatar hujun

商铺列表优化

parent 9aa586a6
...@@ -15,6 +15,7 @@ use app\index\validate\HouseValidate; ...@@ -15,6 +15,7 @@ use app\index\validate\HouseValidate;
use app\model\AAgents; use app\model\AAgents;
use app\model\ACollectHouse; use app\model\ACollectHouse;
use app\model\GHouses; use app\model\GHouses;
use app\model\GHousesExt;
use app\model\GHousesImgs; use app\model\GHousesImgs;
use app\model\GHousesToAgents; use app\model\GHousesToAgents;
use app\model\GOperatingRecords; use app\model\GOperatingRecords;
...@@ -118,16 +119,16 @@ class Houses extends Basic ...@@ -118,16 +119,16 @@ class Houses extends Basic
$data['status'] = 200; $data['status'] = 200;
$data['msg'] = ''; $data['msg'] = '';
$pageNo = empty($this->params['pageNo']) ? 1 : $this->params['pageNo']; $pageNo = empty($this->params['pageNo']) ? 1 : $this->params['pageNo'];
$pageSize = empty($this->params['pageSize']) ? 15 : $this->params['pageSize']; $pageSize = empty($this->params['pageSize']) ? 15 : $this->params['pageSize'];
$agent_where = [];
$where['a.status'] = [ '<>', 3 ]; $where['status'] = [ '<>', 3 ];
/*精选商铺--0是1否*/ /*精选商铺--0是1否*/
if ($this->params['is_carefully_chosen'] != -1) { if ($this->params['is_carefully_chosen'] != -1) {
if ($this->params['is_carefully_chosen'] == 1) { if ($this->params['is_carefully_chosen'] == 1) {
$where['a.is_carefully_chosen'] = 1; $where['is_carefully_chosen'] = 1;
$where['a.status'] = 1; $where['status'] = 1;
} else { } else {
$where['a.is_carefully_chosen'] = 0; $where['a.is_carefully_chosen'] = 0;
} }
...@@ -136,149 +137,169 @@ class Houses extends Basic ...@@ -136,149 +137,169 @@ class Houses extends Basic
/*0是1否显示在c端用户*/ /*0是1否显示在c端用户*/
if ($this->params['is_show'] != -1) { if ($this->params['is_show'] != -1) {
if ($this->params['is_show'] == 1) { if ($this->params['is_show'] == 1) {
$where['a.is_show'] = 1; $where['is_show'] = 1;
} else { } else {
$where['a.is_show'] = 0; $where['is_show'] = 0;
} }
} }
/*商铺类型(0商场,1街铺)*/ /*商铺类型(0商场,1街铺)*/
if ($this->params['shop_type'] != -1) { if ($this->params['shop_type'] != -1) {
$where['a.shop_type'] = $this->params['shop_type']; $where['shop_type'] = $this->params['shop_type'];
} }
/*所在城市*/ /*所在城市*/
if (!empty($this->params['city'])) { if (!empty($this->params['city'])) {
$where['a.city'] = $this->params['city']; $where['city'] = $this->params['city'];
} }
/*所在区*/ /*所在区*/
if (!empty($this->params['disc'])) { if (!empty($this->params['disc'])) {
$where['a.disc'] = $this->params['disc']; $where['disc'] = $this->params['disc'];
} }
/*状态 0待审批 1上架 2下架 3回收*/ /*状态 0待审批 1上架 2下架 3回收*/
if (!empty($this->params['status'])) { if (!empty($this->params['status'])) {
$where['a.status'] = $this->params['status']; $where['status'] = $this->params['status'];
} }
/*价格 -1表示营业额扣点 存分*/ /*价格 -1表示营业额扣点 存分*/
if ($this->params['rent_price'] != NULL && $this->params['rent_price'] != -1) { if ($this->params['rent_price'] != NULL && $this->params['rent_price'] != -1) {
$where['a.rent_type'] = 1; $where['rent_type'] = 1;
switch ($this->params['rent_price']) { switch ($this->params['rent_price']) {
case 1: case 1:
$where['a.rent_price'] = [ '<=', 1000000 ]; $where['rent_price'] = [ '<=', 1000000 ];
break; break;
case 2: case 2:
$where['a.rent_price'] = [ 'between', '1000000,3000000' ]; $where['rent_price'] = [ 'between', '1000000,3000000' ];
break; break;
default : default :
$where['a.rent_price'] = [ '>', '3000000' ]; $where['rent_price'] = [ '>', '3000000' ];
} }
} }
/*对内楼盘名*/ /*对内楼盘名*/
if ($this->params['internal_title'] != NULL) { if ($this->params['internal_title'] != NULL) {
$where['a.internal_title'] = [ 'LIKE', '%' . $this->params['internal_title'] . '%' ]; $where['internal_title'] = [ 'LIKE', '%' . $this->params['internal_title'] . '%' ];
} }
/*对外楼盘名*/ /*对外楼盘名*/
if ($this->params['external_title'] != NULL) { if ($this->params['external_title'] != NULL) {
$where['a.external_title'] = [ 'LIKE', '%' . $this->params['external_title'] . '%' ]; $where['external_title'] = [ 'LIKE', '%' . $this->params['external_title'] . '%' ];
} }
/*楼盘地址搜索*/ /*楼盘地址搜索*/
if ($this->params['internal_address'] != NULL) { if ($this->params['internal_address'] != NULL) {
$where['a.internal_address'] = [ 'LIKE', '%' . $this->params['internal_address'] . '%' ]; $where['internal_address'] = [ 'LIKE', '%' . $this->params['internal_address'] . '%' ];
} }
/*是否独家0否1是*/ /*是否独家0否1是*/
if ($this->params['is_exclusive_type'] != -1) { if ($this->params['is_exclusive_type'] != -1) {
$where['a.is_exclusive_type'] = $this->params['is_exclusive_type']; $where['is_exclusive_type'] = $this->params['is_exclusive_type'];
} }
/*开始时间*/ /*开始时间*/
if ($this->params['start_date'] != NULL && $this->params['end_date'] == NULL) { if ($this->params['start_date'] != NULL && $this->params['end_date'] == NULL) {
$where['a.create_time'] = [ '> time', $this->params['start_date'] . ' 00:00:00' ]; $where['create_time'] = [ '> time', $this->params['start_date'] . ' 00:00:00' ];
} }
/*结束时间*/ /*结束时间*/
if ($this->params['end_date'] != NULL && $this->params['start_date'] == NULL) { if ($this->params['end_date'] != NULL && $this->params['start_date'] == NULL) {
$where['a.create_time'] = [ '< time', $this->params['end_date'] . ' 23:59:59' ]; $where['create_time'] = [ '< time', $this->params['end_date'] . ' 23:59:59' ];
} }
/*开始结束时间*/ /*开始结束时间*/
if ($this->params['start_date'] != NULL && $this->params['end_date'] != NULL) { if ($this->params['start_date'] != NULL && $this->params['end_date'] != NULL) {
$where['a.create_time'] = [ 'between time', [ $this->params['start_date'] . ' 00:00:00', $this->params['end_date'] . ' 23:59:59' ] ]; $where['create_time'] = [ 'between time', [ $this->params['start_date'] . ' 00:00:00', $this->params['end_date'] . ' 23:59:59' ] ];
} }
/*根据库存判断是否已租*/ /*根据库存判断是否已租*/
if ($this->params['leased'] != -1) { if ($this->params['leased'] != -1) {
if ($this->params['leased'] == 0) { if ($this->params['leased'] == 0) {
$where['a.residue_num'] = 0; $where['residue_num'] = 0;
} else { } else {
$where['a.residue_num'] = [ '<>', 0 ]; $where['residue_num'] = [ '<>', 0 ];
} }
} }
/*业态*/ /*业态*/
if ($this->params['industry_type'] != NULL) { if ($this->params['industry_type'] != NULL) {
$where['a.industry_type'] = [ 'LIKE', '%' . $this->params['industry_type'] . '%' ]; $where['industry_type'] = [ 'LIKE', '%' . $this->params['industry_type'] . '%' ];
} }
$fields = 'a.id,a.shop_type,a.internal_title,a.rent_price,a.is_show,a.create_time,a.residue_num,a.rent_type, $fields = 'id,shop_type,internal_title,rent_price,is_show,create_time,residue_num,rent_type,
a.shop_area_start,a.shop_area_end,a.industry_type,d.landlord_phone,disc'; shop_area_start,shop_area_end,industry_type,disc';
/*楼盘编号*/ /*楼盘编号*/
if ($this->params['id'] != NULL) { if ($this->params['id'] != NULL) {
$where['a.id'] = $this->params['id']; $where['id'] = $this->params['id'];
} }
if ($this->params['dish_name'] != NULL) { if ($this->params['dish_name'] != NULL) {
$where['c.name'] = [ 'LIKE', '%' . $this->params['dish_name'] . '%' ]; $agent_where['b.name'] = $this->params['dish_name'];
$where['b.type'] = 2; $agent_where['a.type'] = 2;
$where['b.is_del'] = 0; $agent_where['a.is_del'] = 0;
} }
if ($this->params['dish_phone'] != NULL) { if ($this->params['dish_phone'] != NULL) {
$where['c.phone'] = [ 'LIKE', '%' . $this->params['dish_phone'] . '%' ]; $agent_where['b.phone'] = $this->params['dish_phone'];
$where['b.type'] = 2; $agent_where['a.type'] = 2;
$where['b.is_del'] = 0; $agent_where['a.is_del'] = 0;
}
if (!empty($agent_where)) {
$m_to_agent = new GHousesToAgents();
$agent_arr = $m_to_agent->getAgentsHouseField('houses_id', $agent_where);
$agent_str = implode(',', $agent_arr);
$where[] = ['EXP', "id in ({$agent_str})"];
} }
/*房东手机号搜索*/ /*房东手机号搜索*/
if ($this->params['landlord_phone'] != NULL) { if ($this->params['landlord_phone'] != NULL) {
$where['d.landlord_phone'] = [ 'LIKE', '%' . $this->params['landlord_phone'] . '%' ]; $m_house_ext = new GHousesExt();
if (strlen($this->params['landlord_phone']) != 11) {
return $this->response(101, '房东手机不足11位');
}
$house_ext_where['landlord_phone'] = ['LIKE','%'.$this->params['landlord_phone'].'%'];
$landlord_arr = $m_house_ext->getList(1,1000, '', 'house_id', $house_ext_where);
if (!empty($landlord_arr)) {
foreach ($landlord_arr as $k=>$v) {
$landlord_house_id[] = $v['house_id'];
}
$landlord_str = implode(',', $landlord_house_id);
$where[] = ['EXP', "id in ({$landlord_str})"];
}
} }
if ($this->params['city'] != NULL) { if ($this->params['city'] != NULL) {
$where['a.city'] = $this->params['city']; $where['city'] = $this->params['city'];
} }
if ($this->params['disc'] != NULL) { if ($this->params['disc'] != NULL) {
$where['a.disc'] = $this->params['disc']; $where['disc'] = $this->params['disc'];
} }
if (!empty($this->params['area'])) { if (!empty($this->params['area'])) {
switch ($this->params['area']) { switch ($this->params['area']) {
case 1: case 1:
$where['a.shop_area_start'] = ['between', [0, 30]];break; $where['shop_area_start'] = ['between', [0, 30]];break;
case 2: case 2:
$where['a.shop_area_start'] = ['between', [30, 60]];break; $where['shop_area_start'] = ['between', [30, 60]];break;
case 3: case 3:
$where['a.shop_area_start'] = ['between', [60, 100]];break; $where['shop_area_start'] = ['between', [60, 100]];break;
case 4: case 4:
$where['a.shop_area_start'] = ['between', [100, 300]];break; $where['shop_area_start'] = ['between', [100, 300]];break;
case 5: case 5:
$where['a.shop_area_start'] = ['between', [300, 500]];break; $where['shop_area_start'] = ['between', [300, 500]];break;
case 6: case 6:
$where['a.shop_area_start'] = [ '>', 500];break; $where['shop_area_start'] = [ '>', 500];break;
default : default :
$where['a.shop_area_start'] = ['>', 0]; $where['shop_area_start'] = ['>', 0];
} }
} }
$data['data']['list'] = $this->house->getHouseListDish($pageNo, $pageSize, 'a.id DESC', $fields, $where, $this->userId); $data['data']['list'] = $this->house->getHouseListDish($pageNo, $pageSize, 'id DESC', $fields, $where, $this->userId);
$data['data']['total'] = $this->house->getHouseListDishTotal($where); $data['data']['total'] = $this->house->getHouseListDishTotal($where);
$look_shop = new LookShopService(); $look_shop = new LookShopService();
......
...@@ -272,21 +272,30 @@ class GHouses extends BaseModel ...@@ -272,21 +272,30 @@ class GHouses extends BaseModel
*/ */
public function getHouseListDish($pageNo = 1, $pageSize = 15, $order_ = 'id desc', $field = '', $params = '', $agents_id = '') public function getHouseListDish($pageNo = 1, $pageSize = 15, $order_ = 'id desc', $field = '', $params = '', $agents_id = '')
{ {
$data = $this->field($field)->alias('a') // $data = $this->field($field)->alias('a')
->join('g_houses_to_agents b', 'a.id=b.houses_id', 'left') // ->join('g_houses_to_agents b', 'a.id=b.houses_id', 'left')
->join('a_agents c', 'b.agents_id=c.id', 'left') // ->join('a_agents c', 'b.agents_id=c.id', 'left')
->join('g_houses_ext d', 'a.id=d.house_id', 'left') // ->join('g_houses_ext d', 'a.id=d.house_id', 'left')
// ->where($params)
// ->order($order_)
// ->limit($pageSize)
// ->page($pageNo)
// ->group('a.id')
// ->select();
$data = $this->field($field)
->where($params) ->where($params)
->order($order_) ->order($order_)
->limit($pageSize) ->limit($pageSize)
->page($pageNo) ->page($pageNo)
->group('a.id')
->select(); ->select();
$house_id = array();
$house_id = [];
$house_follow_up = new GHousesFollowUp(); $house_follow_up = new GHousesFollowUp();
foreach ($data as $k => $v) { foreach ($data as $k => $v) {
$house_id[$k] = $v['id']; $house_id[$k] = $v['id'];
$v->create_time = date('Y-m-d', strtotime($v->create_time)); $v->create_time = date('Y-m-d', strtotime($v->create_time));
$data[$k]['last_follow_up'] = $house_follow_up->where('house_id',$v['id'])->value('create_time'); $data[$k]['last_follow_up'] = $house_follow_up->where('house_id',$v['id'])->value('create_time');
} }
...@@ -340,14 +349,15 @@ class GHouses extends BaseModel ...@@ -340,14 +349,15 @@ class GHouses extends BaseModel
*/ */
public function getHouseListDishTotal($params = '') public function getHouseListDishTotal($params = '')
{ {
$data = $this->alias('a') // $data = $this->alias('a')
->join('g_houses_to_agents b', 'a.id=b.houses_id', 'left') // ->join('g_houses_to_agents b', 'a.id=b.houses_id', 'left')
->join('a_agents c', 'b.agents_id=c.id', 'left') // ->join('a_agents c', 'b.agents_id=c.id', 'left')
->join('g_houses_ext d', 'a.id=d.house_id', 'left') // ->join('g_houses_ext d', 'a.id=d.house_id', 'left')
->where($params) // ->where($params)
->group('a.id') // ->group('a.id')
->count(); // ->count();
return $data; // return $data;
return $this->where($params)->count();
} }
/** /**
...@@ -764,6 +774,9 @@ class GHouses extends BaseModel ...@@ -764,6 +774,9 @@ class GHouses extends BaseModel
if (isset($params["create_time"])) { if (isset($params["create_time"])) {
$where_["create_time"] = $params["create_time"]; $where_["create_time"] = $params["create_time"];
} }
if (isset($params['landlord_phone'])) {
$where_["landlord_phone"] = $params['landlord_phone'];
}
$result = Db::table($this->table) $result = Db::table($this->table)
->field($field) ->field($field)
->where($where_) ->where($where_)
...@@ -772,11 +785,17 @@ class GHouses extends BaseModel ...@@ -772,11 +785,17 @@ class GHouses extends BaseModel
return $result; return $result;
} }
/** /**
* 获取新增楼盘数据 * 获取新增楼盘数据
*
* @param $params * @param $params
* @param $field
* @param $page_no
* @param $page_size
* @return false|\PDOStatement|string|\think\Collection * @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/ */
public function getAddHouseList($params, $field, $page_no, $page_size) public function getAddHouseList($params, $field, $page_no, $page_size)
{ {
......
...@@ -200,6 +200,20 @@ class GHousesToAgents extends BaseModel ...@@ -200,6 +200,20 @@ class GHousesToAgents extends BaseModel
return $result; return $result;
} }
/**
* @param $field
* @param $params
* @return array
*/
public function getAgentsHouseField($field, $params)
{
return $this->field($field)
->alias("a")
->join("a_agents b", "a.agents_id = b.id", "left")
->where($params)
->column($field);
}
/** /**
* 楼盘对应的经纪人信息 * 楼盘对应的经纪人信息
* *
...@@ -250,14 +264,15 @@ class GHousesToAgents extends BaseModel ...@@ -250,14 +264,15 @@ class GHousesToAgents extends BaseModel
* *
* @param $house_id * @param $house_id
* @param int $type * @param int $type
* @return array|\PDOStatement|string|\think\Model * @param string $field
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
*/ */
public function getAgentList($house_id, $type = 1) public function getAgentList($house_id, $type = 1, $field = 'b.id,device_id,b.name,b.phone')
{ {
return $this->field('b.id,device_id,b.name,b.phone') return $this->field($field)
->alias('a') ->alias('a')
->join('a_agents b', 'a.agents_id = b.id', 'left') ->join('a_agents b', 'a.agents_id = b.id', 'left')
->where('houses_id', $house_id) ->where('houses_id', $house_id)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment