Commit ce34f5fe authored by clone's avatar clone

商铺list

parent 5f8c1215
<?php
namespace app\api_broker\controller;
use app\api_broker\extend\Basic;
use app\model\GHouses;
use app\model\GHousesImgs;
/**
* Created by PhpStorm.
* User : zw
* Date : 2018/2/26
* Time : 10:36
* Intro:
*/
class Shop extends Basic
{
private $gHousesModel;
private $gHousesImgModel;
function __construct($request = null)
{
parent::__construct($request);
$this->gHousesModel = new GHouses();
$this->gHousesImgModel = new GHousesImgs();
}
/**查询商品列表 b c端公用
* @return \think\Response
*/
public function getShopList()
{
$params = array(
"site_area" => 1, //来源 1c首页 2c搜索 3b首页 4b搜索
"title" => "vv", //1,2 external_title ,3,4internal_title
/*"is_carefully_chosen" => 0, //精选商铺--0否1是
"shop_type" => 0, //商铺类型(0商场,1街铺)
"disc" => "黄浦区",
"industry_type" => "休闲娱乐",
"shop_area_start" => 45,//面积起始范围 街铺start和end面积一样
"shop_area_end" => 65,//面积结束范围
"rent_price_start" => 1000,//租金 rent_price
"rent_price_end" => 10000,//租金
"shop_sign" => "临近地铁,临近地铁2",
"pageNo" => 1,
"pageSize" => 15*/
);
//$params = $this->params;
$conditions = [];
if (empty($params['site_area'])) {
return $this->response("101", "请求来源不能为空");
}
if ($params['site_area'] == 1 || $params['site_area'] == 2) {
$field = "id,external_title as title,external_address as address,city,disc,business_district_id,status,industry_type
,shop_area_start,shop_area_end,shop_type,residue_num,shop_sign,is_carefully_chosen,rent_type,rent_price";
} else {
$field = "id,internal_title as title,internal_address as address,city,disc,business_district_id,status,industry_type
,shop_area_start,shop_area_end,shop_type,residue_num,shop_sign,is_carefully_chosen,rent_type,rent_price";
}
$pageNo = empty($params['pageNo']) ? 1 : $params['pageNo'];
$pageSize = empty($params['pageSize']) ? 15 : $params['pageSize'];
//c端查对外的名字 b端查对内的名字
if (isset($params['title']) && $params['site_area'] == 1 || $params['site_area'] == 2) {
$conditions['external_title'] = array( "like", "%" . trim($params['title']) . "%" );
} else if (isset($params['title'])) {
$conditions['internal_title'] = array( "like", "%" . trim($params['title']) . "%" );
}
$order_ = "";
$spTagArr = array();
switch ($params['site_area']) {
case 1:
case 3:
if (isset($params['is_carefully_chosen']) && $params['is_carefully_chosen'] == 1) {
$conditions['is_carefully_chosen'] = array( 'eq', $params['is_carefully_chosen'] );
$order_ = "home_page_sort desc, id desc";
}
break;
case 2:
case 4:
if (isset($params['disc'])) { //区域
$conditions['disc'] = array( 'eq', trim($params['disc']) );
}
if (isset($params['industry_type'])) { //业态
$conditions['industry_type'] = array( 'like', "%" . trim($params['industry_type']) . "%" );
}
if (isset($params['shop_type'])) { //商铺类型
$conditions['shop_type'] = array( "eq", $params['shop_type'] );
}
$area_start = isset($params['shop_area_start']) ? $params['shop_area_start'] : -1;
$area_end = isset($params['shop_area_end']) ? $params['shop_area_end'] : -1;
if ($area_start >= 0 && $area_end >= 0) { //面积
$conditions['shop_area_start'] = array( 'between', array( $area_start * 10000, $area_end * 10000 ) );
$conditions['shop_area_end'] = array( 'between', array( $area_start * 10000, $area_end * 10000 ) );
} else if ($area_start >= 0 && $area_end < 0) { //100米以上不用传结束面积
$conditions['shop_area_start'] = array( 'egt', $area_start * 10000 );
$conditions['shop_area_end'] = array( 'egt', $area_start * 10000 );
}
$price_start = isset($params['rent_price_start']) ? $params['rent_price_start'] : -1;
$price_end = isset($params['rent_price_end']) ? $params['rent_price_end'] : -1;
if ($price_start >= 0 && $price_end >= 0) { //金额
$conditions['rent_price'] = array( 'between', array( $price_start * 100, $price_end * 100 ) );
} else if ($price_start >= 0 && $price_end < 0) {
$conditions['rent_price'] = array( 'egt', $price_start * 100 );
}
if (isset($params['shop_sign']) && $params['shop_sign'] != "全部") { //商铺标签
$shopTagsArr = array_filter(explode(',', $params['shop_sign']));
if (count($shopTagsArr) == 1) {
$spTagArr['shop_sign'] = array( 'like', "%" . trim($shopTagsArr[0]) . "%" );
} else {
foreach ($shopTagsArr as $key => $val) {
$spTagArr['shop_sign'][] = array( 'like', "%" . trim($val) . "%" );
}
}
}
$order_ = "id desc";
break;
default:
$this->response("101", "请求数据异常");
}
if (!empty($conditions)) {
$conditions['status'] = array( 'eq', 1 ); //只显示上架
if ($params['site_area'] == 1 || $params['site_area'] == 2)
$conditions['is_show'] = array( 'eq', 0 ); //c端只显示可显示的楼盘
}
$result = $this->gHousesModel->getHousesList($pageNo, $pageSize, $order_, $field, $conditions, $spTagArr);
//获取图片信息
foreach ($result as $key => $val) {
$result[$key]["api_path"] = CK_IMG_URL;
$param["house_id"] = $val["id"];
$param["img_type"] = 1; //默认主图
$result[$key]["images"] = $this->gHousesImgModel->getHouseImages($param, 1);
}
if (empty($result)) {
return $this->response("200", "此条件没有找到数据");
}
return $this->response("200", 'request success', $result);
}
}
\ No newline at end of file
......@@ -19,13 +19,14 @@ class GHouses extends BaseModel
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getHouseById($id) {
public function getHouseById($id)
{
$data = array();
$fields = 'a.*,b.*';
$select_data = $this->alias('a')->field($fields)
->join('g_houses_ext b','a.id = b.house_id', 'left')
->where('a.id',$id)
->where('a.status','<>',3)
->join('g_houses_ext b', 'a.id = b.house_id', 'left')
->where('a.id', $id)
->where('a.status', '<>', 3)
->find();
if ($select_data) {
......@@ -102,7 +103,8 @@ class GHouses extends BaseModel
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getHouseList($pageNo = 1, $pageSize = 15, $order_ = 'id desc', $field = '', $params = '') {
public function getHouseList($pageNo = 1, $pageSize = 15, $order_ = 'id desc', $field = '', $params = '')
{
$data = $this->field($field)
->where($params)
->order($order_)
......@@ -112,7 +114,7 @@ class GHouses extends BaseModel
$house_id = array();
foreach ($data as $k => $v) {
$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));
}
$result = array();
......@@ -122,20 +124,20 @@ class GHouses extends BaseModel
/*案场权限人和盘方*/
$house_agents = Db::table('g_houses_to_agents')->alias('a')
->field('a.houses_id,b.id,b.name,b.phone,a.type')
->join('a_agents b', 'a.agents_id=b.id','left')
->where('a.houses_id','IN', implode(',',$house_id))
->where('a.is_del',0)
->join('a_agents b', 'a.agents_id=b.id', 'left')
->where('a.houses_id', 'IN', implode(',', $house_id))
->where('a.is_del', 0)
->select();
foreach ($data as $k=>$v) {
foreach ($data as $k => $v) {
$result[$k] = $v->toArray();
$dish_name = '';
$result[$k]['dish_name'] = '';
foreach ($house_agents as $k2 => $v2) {
if ($v->id == $v2['houses_id']) {
if ($v2['type'] == 2) {
$dish_name .= $v2['name'].',';
$result[$k]['dish_name'] = rtrim($dish_name,',');
$dish_name .= $v2['name'] . ',';
$result[$k]['dish_name'] = rtrim($dish_name, ',');
} else {
$result[$k]['dish_name'] = '';
}
......@@ -160,10 +162,11 @@ class GHouses extends BaseModel
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getHouseListDish($pageNo = 1, $pageSize = 15, $order_ = 'id desc', $field = '', $params = '') {
public function getHouseListDish($pageNo = 1, $pageSize = 15, $order_ = 'id desc', $field = '', $params = '')
{
$data = $this->field($field)->alias('a')
->join('g_houses_to_agents b', 'a.id=b.houses_id','left')
->join('a_agents c','b.agents_id=c.id','left')
->join('g_houses_to_agents b', 'a.id=b.houses_id', 'left')
->join('a_agents c', 'b.agents_id=c.id', 'left')
->where($params)
->order($order_)
->limit($pageSize)
......@@ -181,20 +184,20 @@ class GHouses extends BaseModel
/*案场权限人和盘方*/
$house_agents = Db::table('g_houses_to_agents')->alias('a')
->field('a.houses_id,b.id,b.name,b.phone,a.type')
->join('a_agents b', 'a.agents_id=b.id','left')
->where('a.houses_id','IN', implode(',',$house_id))
->where('a.is_del',0)
->join('a_agents b', 'a.agents_id=b.id', 'left')
->where('a.houses_id', 'IN', implode(',', $house_id))
->where('a.is_del', 0)
->select();
foreach ($data as $k=>$v) {
foreach ($data as $k => $v) {
$result[$k] = $v->toArray();
$dish_name = '';
$result[$k]['dish_name'] = '';
foreach ($house_agents as $k2 => $v2) {
if ($v->id == $v2['houses_id']) {
if ($v2['type'] == 2) {
$dish_name .= $v2['name'].',';
$result[$k]['dish_name'] = rtrim($dish_name,',');
$dish_name .= $v2['name'] . ',';
$result[$k]['dish_name'] = rtrim($dish_name, ',');
} else {
$result[$k]['dish_name'] = '';
}
......@@ -211,10 +214,11 @@ class GHouses extends BaseModel
* @param string $params
* @return int|string
*/
public function getHouseListDishTotal($params = '') {
public function getHouseListDishTotal($params = '')
{
$data = $this->alias('a')
->join('g_houses_to_agents b', 'a.id=b.houses_id','left')
->join('a_agents c','b.agents_id=c.id','left')
->join('g_houses_to_agents b', 'a.id=b.houses_id', 'left')
->join('a_agents c', 'b.agents_id=c.id', 'left')
->where($params)
->count();
return $data;
......@@ -230,14 +234,15 @@ class GHouses extends BaseModel
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function add($params) {
public function add($params)
{
$case = new ACase();
$case_id = $case->addCase($params['phone']);
$params['case_id'] = $case_id;
$regions = new Regions();
$code_arr = $regions->getRegionsCodeByName($params['province'], $params['city'], $params['disc']);
$params['code'] = implode('##',$code_arr);
$params['code'] = implode('##', $code_arr);
//新增或编辑
if ($params['id'] == '') {
......@@ -246,13 +251,13 @@ class GHouses extends BaseModel
$house_id = $this->id;
} else {
$params['operation_id'] = Session::get('userId');
$this->allowField(true)->isUpdate(true)->save($params, ['id' => $params['id']]);
$this->allowField(true)->isUpdate(true)->save($params, [ 'id' => $params['id'] ]);
$house_id = $this->id;
}
$params['house_id'] = $house_id;
if ($params['start_business_date']) {
$params['start_business_date'] = date('Y-m-d H:i:s' , strtotime($params['start_business_date']));
$params['start_business_date'] = date('Y-m-d H:i:s', strtotime($params['start_business_date']));
}
$houses_ext = new GHousesExt();
......@@ -260,8 +265,8 @@ class GHouses extends BaseModel
if ($params['id'] == '') {
$houses_ext->allowField(true)->save($params);
} else {
$house_ext_data = $houses_ext->field('id')->where('house_id',$params['id'])->find();
$houses_ext->allowField(true)->isUpdate(true)->save($params, ['id' => $house_ext_data['id']]);
$house_ext_data = $houses_ext->field('id')->where('house_id', $params['id'])->find();
$houses_ext->allowField(true)->isUpdate(true)->save($params, [ 'id' => $house_ext_data['id'] ]);
}
/***保存图片 hujun 2018.1.19 start***/
......@@ -275,11 +280,11 @@ class GHouses extends BaseModel
$agents = new GHousesToAgents();
//权限人
$agents->addAgents($params['agent_data'], $house_id,1);
$agents->addAgents($params['agent_data'], $house_id, 1);
//盘方
$agents->addAgents($params['agent_dish'], $house_id,2);
$agents->addAgents($params['agent_dish'], $house_id, 2);
//独家方
$agents->addAgents($params['exclusive_ids'], $house_id,3);
$agents->addAgents($params['exclusive_ids'], $house_id, 3);
return $house_id;
}
......@@ -294,24 +299,25 @@ class GHouses extends BaseModel
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function exclusive($data, $house_id) {
public function exclusive($data, $house_id)
{
$this->startTrans();
$result = $this->save([
'is_exclusive_type' => $data['is_exclusive_type'],
'update_time' => date('Y-m-d H:i:s')
],['id'=>$house_id]);
], [ 'id' => $house_id ]);
if ($result) {
$ext = new GHousesExt();
$update_data['agent_start_time'] = $data['agent_start_time'];
$update_data['agent_end_time'] = $data['agent_end_time'];
$ext_result = $ext->save($update_data,['house_id'=>$data['houses_id']]);
$ext_result = $ext->save($update_data, [ 'house_id' => $data['houses_id'] ]);
$house_img = new GHousesImgs();
$house_img->edit($data, $house_id);
$agents = new GHousesToAgents();
$agents->addAgents($data['exclusive_id'], $house_id,3);
$agents->addAgents($data['exclusive_id'], $house_id, 3);
}
if ($result == 1 || $ext_result == 1) {
......@@ -333,22 +339,23 @@ class GHouses extends BaseModel
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getExclusive($houses_id) {
$result = $this->field('id,is_exclusive_type')->where('id',$houses_id)->where('status','<>',3)->find();
public function getExclusive($houses_id)
{
$result = $this->field('id,is_exclusive_type')->where('id', $houses_id)->where('status', '<>', 3)->find();
if ($result->id) {
$house_ext = $this->table('g_houses_ext')->where('house_id',$houses_id)->field('agent_start_time,agent_end_time')->find();
$house_ext = $this->table('g_houses_ext')->where('house_id', $houses_id)->field('agent_start_time,agent_end_time')->find();
$agents = $this->table('g_houses_to_agents')->field('b.id,b.name,b.phone')->alias('a')
->join('a_agents b', 'a.agents_id=b.id','left')
->where('a.is_del','<>',1)
->where('b.status',0)->find();
->join('a_agents b', 'a.agents_id=b.id', 'left')
->where('a.is_del', '<>', 1)
->where('b.status', 0)->find();
$img = $this->table('g_houses_imgs')
->field('img_name')
->where('house_id',$houses_id)
->where('img_status',0)->select();
->where('house_id', $houses_id)
->where('img_status', 0)->select();
$return['id'] = $agents->id;
$return['name'] = $agents['name'].'-'.$agents['phone'];
$return['name'] = $agents['name'] . '-' . $agents['phone'];
$return['agent_start_time'] = $house_ext['agent_start_time'];
$return['agent_end_time'] = $house_ext['agent_end_time'];
$return['exclusive_img'] = $img;
......@@ -372,4 +379,36 @@ class GHouses extends BaseModel
->where($params)
->find();
}
/******zw start ************/
/**
* 查询商铺列表
* @param int $pageNo
* @param int $pageSize
* @param string $order_
* @param $field
* @param $params
* @param $spTagsArr
* @return mixed
*/
function getHousesList($pageNo = 1, $pageSize = 15, $order_ = 'id desc', $field, $params, $spTagsArr)
{
return Db::table($this->table)
->field($field)
->where($params)
->where(function ($query) use ($spTagsArr) {
$query->whereOr($spTagsArr);
})
->order($order_)
->limit($pageSize)
->page($pageNo)
->select();
}
/******zw end ************/
}
<?php
namespace app\model;
/**
* Created by PhpStorm.
* User: fuju
* Date: 2018/1/19
* Time: 11:33
*/
use think\Db;
namespace app\model;
class GHousesImgs extends BaseModel
......@@ -176,4 +177,23 @@ class GHousesImgs extends BaseModel
$this->add($params, $house_id);
return $this->saveAll($house_img_edit);
}
/****** zw start *******/
/**
* 查询图片
* @param $param
* @param $limit_
* @return mixed
*/
public function getHouseImages($param,$limit_)
{
//rank
return Db::table($this->table)
->field("id,house_id,img_type,img_name,img_status")
->where($param)
->limit($limit_)
->select();
}
/****** zw end *******/
}
\ No newline at end of file
......@@ -237,6 +237,9 @@ Route::group('broker', [
'agentsUnBind' => [ 'api_broker/CellPhone/agentsUnBind', [ 'method' => 'post' ] ],//解除绑定关系
'callLog' => [ 'api_broker/CellPhone/callLog', [ 'method' => 'get' ] ],//通话记录
'getShopList' => ['api_broker/Shop/getShopList', [ 'method' => 'get' ] ],
]);
//Route::miss('api/index/miss');//处理错误的url
\ No newline at end of file
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