Commit fd4c9067 authored by zhuwei's avatar zhuwei

客户站点

parent 45511a2a
......@@ -100,26 +100,31 @@ class User extends Basic
$app_request_source_type = isset($params["app_request_source_type"]) && is_numeric($params["app_request_source_type"])? $params["app_request_source_type"] : 1;
$conditions = [];
$field = "a.id as user_id,a.sex,a.user_name,a.city,a.user_phone,a.user_status,
a.agent_id,a.create_time,a.industry_type,a.price_demand,a.area_demand,a.vip,a.user_label,
a.source_intro,a.site_ids,a.entrust_type,a.concrete_industry";
$order = " a.id desc";
switch ($app_request_source_type) {
case 0:
//case 0:客户搜索
$pageNo = 1;
$pageSize = 50;
if (isset($params['id'])) {
$conditions['id'] = $params['id'];
$conditions['a.id'] = $params['id'];
}
if (isset($params['user_name'])) {
if (strlen($params['user_name']) > 20) {
return $this->response(101, '输入内容长度超限');
}
$conditions['user_name'] = array( "like", "%" . trim($params['user_name']) . "%" );
$conditions['a.user_name'] = array( "like", "%" . trim($params['user_name']) . "%" );
}
if (isset($params['user_nick'])) {
if (strlen($params['user_nick']) > 20) {
return $this->response(101, '输入内容长度超限');
}
$conditions['user_nick'] = array( "like", "%" . trim($params['user_nick']) . "%" );
$conditions['a.user_nick'] = array( "like", "%" . trim($params['user_nick']) . "%" );
}
if (isset($params['user_phone'])) {
if (!is_numeric($params['user_phone'])) {
......@@ -130,7 +135,7 @@ class User extends Basic
return $this->response(101, '输入内容长度超限');
}
$conditions['user_phone'] = array( "like", "%" . trim($params['user_phone']) . "%" );
$conditions['a.user_phone'] = array( "like", "%" . trim($params['user_phone']) . "%" );
}
//具体业态搜索
......@@ -138,38 +143,42 @@ class User extends Basic
if (strlen($params['concrete_industry']) > 20) {
return $this->response(101, '输入内容长度超限');
}
$conditions['concrete_industry'] = [ 'LIKE', '%' . $params['concrete_industry'] . '%' ];
$conditions['a.concrete_industry'] = [ 'LIKE', '%' . $params['concrete_industry'] . '%' ];
}
$return_user_list = $this->userModel->selectMyUserList($field, $conditions, $pageNo, $pageSize, $order);
break;
case 2:
//case 2:我的客户
$user_id_str = $this->getUserIDList($params['agent_id']);
$conditions['id'] = ['in', $user_id_str];
$conditions['a.id'] = ['in', $user_id_str];
if (isset($params['user_status'])) {
$conditions['user_status'] = $params['user_status'];
$conditions['a.user_status'] = $params['user_status'];
}
if(isset($params['entrust_type']) && is_numeric($params['entrust_type'])){
//委托类型
$conditions['entrust_type'] =$params['entrust_type'];
$conditions['a.entrust_type'] =$params['entrust_type'];
}
$return_user_list = $this->userModel->selectMyUserList($field, $conditions, $pageNo, $pageSize, $order);
break;
default:
//默认:全部客户
if (isset($params['user_status'])) {
$conditions['user_status'] = $params['user_status'];
$conditions['a.user_status'] = $params['user_status'];
}
if (isset($params['user_name'])) {
if (strlen($params['user_name']) > 20) {
return $this->response(101, '输入内容长度超限');
}
$conditions['user_name'] = array( "like", "%" . trim($params['user_name']) . "%" );
$conditions['a.user_name'] = array( "like", "%" . trim($params['user_name']) . "%" );
}
if (isset($params['user_nick'])) {
if (strlen($params['user_nick']) > 20) {
return $this->response(101, '输入内容长度超限');
}
$conditions['user_nick'] = array( "like", "%" . trim($params['user_nick']) . "%" );
$conditions['a.user_nick'] = array( "like", "%" . trim($params['user_nick']) . "%" );
}
if (isset($params['user_phone'])) {
if (!is_numeric($params['user_phone'])) {
......@@ -180,89 +189,68 @@ class User extends Basic
return $this->response(101, '输入内容长度超限');
}
$conditions['user_phone'] = array( "like", "%" . trim($params['user_phone']) . "%" );
$conditions['a.user_phone'] = array( "like", "%" . trim($params['user_phone']) . "%" );
}
if (isset($params['yetai'])) {
$conditions['industry_type'] = array( "like", "%" . trim($params['yetai']) . "%" );
$conditions['a.industry_type'] = array( "like", "%" . trim($params['yetai']) . "%" );
}
$area_start = isset($params['area_start']) ? $params['area_start'] : -1;
$area_end = isset($params['area_end']) ? $params['area_end'] : -1;
if ($area_start >= 0 && $area_end >= 0) { //面积
$conditions['area_demand'] = array( 'between', array( $area_start, $area_end ) );
$conditions['a.area_demand'] = array( 'between', array( $area_start, $area_end ) );
} else if ($area_start >= 0 && $area_end < 0) { //100米以上不用传结束面积
$conditions['area_demand'] = array( 'egt', $area_start );
$conditions['a.area_demand'] = array( 'egt', $area_start );
}
$price_start = isset($params['money_start']) ? $params['money_start'] : -1;
$price_end = isset($params['money_end']) ? $params['money_end'] : -1;
if ($price_start >= 0 && $price_end >= 0) { //金额
$conditions['price_demand'] = array( 'between', array( $price_start, $price_end ) );
$conditions['a.price_demand'] = array( 'between', array( $price_start, $price_end ) );
} else if ($price_start >= 0 && $price_end < 0) {
$conditions['price_demand'] = array( 'egt', $price_start );
$conditions['a.price_demand'] = array( 'egt', $price_start );
}
if (isset($params['start_time']) && isset($params['end_time'])) {
$start_time = date('Y-m-d H:i:s', $params['start_time']);
$end_time = date('Y-m-d H:i:s', $params['end_time']);
$conditions['create_time'] = array( 'between', array( $start_time, $end_time ) );
$conditions['a.create_time'] = array( 'between', array( $start_time, $end_time ) );
}
if (isset($params['status'])) {
$conditions['status'] = $params['status'];
$conditions['a.status'] = $params['status'];
}
//是否vip客户 1是 0否
if (isset($params['is_vip']) ) {
$conditions['vip'] = $params['is_vip'];
$conditions['a.vip'] = $params['is_vip'];
}
//全部客户列表 排除排除纯房东客户
$conditions['user_label'] = array( "neq", 2 );
$conditions['a.user_label'] = array( "neq", 2 );
//根据时间搜索,要能搜到保护期客户
if(!isset($conditions['create_time'])){
//排除排除保护期内的客户 将截止日期大于当前时间的数据排除掉
$time_now = date('Y-m-d H:i:s');
$conditions['protect_time'] = array('lt',$time_now);
$conditions['a.protect_time'] = array('lt',$time_now);
}
//客户站点
// if (isset($params['site_id']) ) {
// $site_ids = $params['site_id'];
// }else{
// $site_ids = $this->siteId;
// }
//
// $user_id_str = $this->getSiteUserList($site_ids);
// // big_log($user_id_str);
// if($user_id_str){
// $conditions['id'] = ['in', $user_id_str];
// }else{
// if (isset($params['site_id']) ) {
// $conditions['site_ids'] = [ 'LIKE', '%' . $params['site_id'] . '%' ];
// }else{
// $conditions['site_ids'] = [ 'LIKE', '%' . $this->siteId . '%' ];
// }
// }
if (isset($params['site_id']) ) {
$conditions['site_ids'] = [ 'LIKE', '%' . $params['site_id'] . '%' ];
$conditions['s.site_id'] = $params['site_id'];
}else{
$conditions['site_ids'] = [ 'LIKE', '%' . $this->siteId . '%' ];
$conditions['s.site_id'] = $this->siteId;
}
//委托类型
if(isset($params['entrust_type']) && is_numeric($params['entrust_type'])){
$conditions['entrust_type'] =$params['entrust_type'];
$conditions['a.entrust_type'] =$params['entrust_type'];
}
$return_user_list = $this->userModel->selectUserList($field, $conditions, $pageNo, $pageSize, $order);
}
$field = "id as user_id,sex,user_name,city,user_phone,user_status,agent_id,create_time,industry_type,
price_demand,area_demand,vip,user_label,source_intro,site_ids,entrust_type,concrete_industry";
$return_user_list = $this->userModel->selectUserList($field, $conditions, $pageNo, $pageSize, "id desc");
if (empty($return_user_list)) {
return $this->response("200", "此条件没有找到数据");
}
......@@ -596,33 +584,36 @@ class User extends Basic
if ($params['type'] == 'last') {
$where['id'] = [ 'gt', $params['user_id'] ];
$order = 'id asc';
$where['a.id'] = [ 'gt', $params['user_id'] ];
$order = 'a.id asc';
} else {
$where['id'] = [ 'lt', $params['user_id'] ];
$order = 'id desc';
$where['a.id'] = [ 'lt', $params['user_id'] ];
$order = 'a.id desc';
}
#站点的客户
if (!empty($params['site_id'])) {
#根据前端选择站点客户
$where['site_ids'] = [ 'LIKE', '%' . $params['site_id'] . '%' ];
}else{
#前端不传站点参数就默认显示经纪人所在站点的客户
$where['site_ids'] = [ 'LIKE', '%' . $this->siteId . '%' ];
if ( !empty($this->params['site_id'])) {
$where['s.site_id'] = $this->params['site_id'];
} else {
$where['s.site_id'] = $this->siteId;
}
if(isset($params['entrust_type']) && is_numeric($params['entrust_type'])){
//委托类型
$where['a.entrust_type'] =$params['entrust_type'];
}
//委托类型 0找铺 1找办公楼
if(isset($params["entrust_type"])){
if($params["entrust_type"] == 0){
$where['entrust_type'] = 0;
$where['a.entrust_type'] = 0;
}elseif ($params["entrust_type"] == 1){
$where['entrust_type'] = 1;
$where['a.entrust_type'] = 1;
}
}
$field = 'id,user_nick,agent_id,vip,create_time';
$field = 'a.id,a.user_nick,a.agent_id,a.vip,a.create_time';
$user = new Users();
$user_res = $user->getLastOrNextUserID($where, $field, $order, $type, 0,1);
if (!$user_res) {
......@@ -661,14 +652,15 @@ class User extends Basic
$where = [];
$where['city'] = trim($this->city);
$where['entrust_type'] = isset($params["entrust_type"]) ? $params["entrust_type"] : 0;
$where['a.city'] = trim($this->city);
$where['a.entrust_type'] = isset($params["entrust_type"]) ? $params["entrust_type"] : 0;
$order = 'id asc';
$field = 'max(id) as max_id';
$order = 'a.id asc';
$field = 'max(a.id) as max_id';
$max_id = $user->getLastOrNextUserID($where, $field, $order, $type, 0, 1);
$field = 'MIN(id) as min_id';
$field = 'MIN(a.id) as min_id';
$min_id = $user->getLastOrNextUserID($where, $field, $order, $type, 0, 1);
return $this->response("200", "success!", [
'user_id' => $user_res[0]['id'],
......@@ -903,6 +895,11 @@ class User extends Basic
}
/**
* 查询客方id集合 UserAgentService
* @param $agent_id
* @return string
*/
public function getUserIDList($agent_id)
{
//查询总监下面门店的所有经纪人
......@@ -991,7 +988,7 @@ class User extends Basic
}
$field = "id as user_id,sex,user_name,city,user_phone";
$return_user_list = $this->userModel->selectUserList($field, $conditions, $pageNo, $pageSize, "id desc");
$return_user_list = $this->userModel->bindUserList($field, $conditions, $pageNo, $pageSize, "id desc");
if (empty($return_user_list)) {
return $this->response("200", "此条件没有找到数据");
}
......
......@@ -68,7 +68,7 @@ class Member extends Basic{
$can_vip = true;
if (!empty($params['agent_id'])) {
// $where['a.agent_id'] = $params['agent_id'];
$c_user = new User();
$c_user = new UserAgentService();
$user_id_str = $c_user->getUserIDList($params['agent_id']);
$where['a.id'] = ['in', $user_id_str];
$can_vip = false;
......@@ -325,9 +325,9 @@ class Member extends Basic{
$check_data = $service_broker->checkSite($this->userId, $this->params['site_id']);
if ($check_data && !empty($this->params['site_id'])) {
$where['a.site_ids'] = [ 'LIKE', '%' . $this->params['site_id'] . '%' ];
$where['s.site_id'] = $this->params['site_id'];
} else {
$where['a.site_ids'] = [ 'LIKE', '%' . $this->siteId . '%' ];
$where['s.site_id'] = $this->siteId;
}
}
......@@ -356,8 +356,7 @@ class Member extends Basic{
}
// big_log(json_encode($where));
$where['s.is_del'] = 0;
$fields = 'a.id,a.user_nick,a.create_time,a.user_name,a.user_phone,a.user_pic,a.create_time,a.user_pswd,
a.referrer_id,a.user_label,a.user_name,a.status,a.agent_id,a.vip,a.price_demand,a.industry_type,a.area_demand
,a.user_status,a.source,a.entrust_type,a.concrete_industry';
......
......@@ -251,4 +251,31 @@ class UserAgentService
}
/**
* 查询客方id集合
* @param $agent_id
* @return string
*/
public function getUserIDList($agent_id)
{
//查询总监下面门店的所有经纪人
$params = [];
$params["agent_id"] = $agent_id;
$params["is_del"] = 0;
// $m_user_agent = new UserAgentModel();
$field = 'user_id';
$res = $this->m_user_agent->selectUser($field,$params);
$user_id_str = "";
if (count($res) > 0) {
foreach ($res as $k => $v) {
$user_id_str .= $v["user_id"] . ",";
}
$user_id_str = rtrim($user_id_str, ",");
}
return $user_id_str;
}
}
\ No newline at end of file
......@@ -118,10 +118,12 @@ class Users extends Model
if ($type == 1) {
$result = $this->field($fields)
->alias('a')
->join("u_user_site s", "a.id=s.user_id", "right")
->where($params)
->order($order_)
->limit($pageSize)
->page($pageNo)
// ->group("a.id")
->select();
} elseif ($type == 2) {
$result = $this->field($fields)
......@@ -138,6 +140,7 @@ class Users extends Model
->alias('a')
->join("u_user_agent c","a.id = c.user_id","left")
->join('a_agents b', 'c.agent_id = b.id', 'left')
->join("u_user_site s", "a.id=s.user_id", "right")
->where($params)
->order($order_)
->limit($pageSize)
......@@ -147,6 +150,7 @@ class Users extends Model
$result = $this->field($fields)
->alias('a')
->join('a_agents b', 'a.referrer_id = b.id', 'left')
->join("u_user_site s", "a.id=s.user_id", "right")
->where($params)
->where('a.referrer_source', 20)
->order($order_)
......@@ -154,11 +158,14 @@ class Users extends Model
->page($pageNo)
->select();
} else {
$result = $this->field($fields)->alias('a')
$result = $this->field($fields)
->alias('a')
->join("u_user_site s", "a.id=s.user_id", "right")
->where($params)
->order($order_)
->limit($pageSize)
->page($pageNo)
->group("a.id")
->select();
}
return $result;
......@@ -685,7 +692,82 @@ class Users extends Model
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function selectUserList($field, $params, $pageNo, $pageSize, $order = " id desc")
public function selectUserList($field, $params, $pageNo, $pageSize, $order)
{
$params['s.is_del'] = 0;
$result = Db::table($this->table)
->field($field)
->alias('a')
->join("u_user_site s", "a.id=s.user_id", "right")
->where($params)
->order($order)
->page($pageNo)
->limit($pageSize)
->select();
// big_log($this->getLastSql());
return $result;
}
/**
* 我的客户
* @param $field
* @param $params
* @param $pageNo
* @param $pageSize
* @param $order
* @return false|\PDOStatement|string|\think\Collection
*/
public function selectUserListGroup($field, $params, $pageNo, $pageSize, $order)
{
$result = Db::table($this->table)
->field($field)
->alias('a')
->join("u_user_site s", "a.id=s.user_id", "right")
->where($params)
->order($order)
->page($pageNo)
->limit($pageSize)
->group("a.id")
->select();
// big_log($this->getLastSql());
return $result;
}
/**
* 我的客户
* @param $field
* @param $params
* @param $pageNo
* @param $pageSize
* @param $order
* @return false|\PDOStatement|string|\think\Collection
*/
public function selectMyUserList($field, $params, $pageNo, $pageSize, $order)
{
$result = Db::table($this->table)
->field($field)
->alias('a')
// ->join("u_user_site s", "a.id=s.user_id", "right")
->where($params)
->order($order)
->page($pageNo)
->limit($pageSize)
// ->group("a.id")
->select();
// big_log($this->getLastSql());
return $result;
}
/**
* 关联客户-根据id搜索客户
* @param $field
* @param $params
* @param $pageNo
* @param $pageSize
* @param string $order
* @return false|\PDOStatement|string|\think\Collection
*/
public function bindUserList($field, $params, $pageNo, $pageSize, $order = "id desc")
{
$result = Db::table($this->table)
->field($field)
......@@ -934,7 +1016,9 @@ class Users extends Model
->page($page)
->select();
} else {
$result = $this->field($field)->alias('a')
$result = $this->field($field)
->alias('a')
->join("u_user_site s", "a.id=s.user_id", "right")
->where($where)
->order($order)
->limit($limit)
......
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