Commit 3860777b authored by zhuwei's avatar zhuwei

客户绑定

parent 68c53cae
......@@ -177,10 +177,46 @@ class ImageDepot extends Basic
public function ceshi()
{
$num = 82.997128371823;
$num_ex = explode('.',$num);
dump($num_ex);
dump(substr($num,0,-6));
$s = new UserService();
//查询
$user_info_list = $s->userBindInfo(3);
return $this->response("200", "成功",$user_info_list);
//新增
// $user_id = 3;
// $bind_id = 1;
// $add_res = $s->addUserBind($user_id,$bind_id);
// switch ($add_res) {
// case 1 :
// return $this->response("300", "参数不全");
// break;
// case 2 :
// return $this->response("300", "当前客户已经存在绑定关系");
// break;
// case 3 :
// return $this->response("300", "当前客户已经存在绑定关系");
// break;
// case 4 :
// return $this->response("300", "绑定客户关系数超限");
// break;
// case 5 :
// return $this->response("300", "绑定失败");
// break;
// case 0 :
// return $this->response("200", "绑定成功");
// break;
// default :
// return $this->response("300", "绑定失败");
//
// }
//解除
// $rm_res = $s->removeUserBind($user_id);
// if($rm_res == 1){
// return $this->response("200", "解绑成功");
// }else{
// return $this->response("200", "解绑失败");
// }
}
......
......@@ -511,4 +511,81 @@ class UserService
}
/**
* 新增客户绑定
* @param $user_id
* @param $bind_id
* @return int
*/
public function addUserBind($user_id,$bind_id){
if(!$user_id or !$bind_id){
return 1;
}
// 先查当前用户bind_id是否等于0
$user_info = $this->user->getUserById($field = 'bind_id', $user_id);
if($user_info['bind_id'] != 0){
return 2;
}else{
// 不等于0 查bind_id=当前bind_id 同时查id=bind_id
$user_bind = $this->userBindInfo($user_id);
if(count($user_bind) > 0){
return 3;
}
$b_user_bind = $this->userBindInfo($bind_id);
if(count($b_user_bind) > 5){
return 4;
}
//
$b_user_info = $this->user->getUserById($field = 'bind_id', $bind_id);
if($b_user_info['bind_id'] == 0){
$bind_id_ = $bind_id;
}else{
$bind_id_ = $b_user_info['bind_id'];
}
$params_['bind_id'] = $bind_id_;
$res = $this->user->updateUsers($user_id,$params_);
if($res ==1){
return 0;
}else{
return 5;
}
}
}
/**
* 解除绑定关系
* @param $user_id
* @return int|string
*/
public function removeUserBind($user_id){
$params_['bind_id'] = 0;
$res = $this->user->updateUsers($user_id,$params_);
return $res;
}
/**
* 客户绑定详情
* @param $user_id
* @return false|\PDOStatement|string|\think\Collection
*/
public function userBindInfo($user_id){
if(!$user_id){
return '';
}
// 先查当前用户bind_id是否等于0
$user_info = $this->user->getUserById($field = 'bind_id', $user_id);
$field = 'user_name,user_phone,bind_id';
if($user_info['bind_id'] == 0){
//主账号只需要查bind_id等于当前用户的ID
$where['bind_id'] = $user_id;
}else{
// 不等于0副号 把相同bind_id的查出来 主账号查出来 同时排除当前客户
$where[] = ['EXP', "(bind_id = '{$user_info['bind_id']}' or id = '{$user_info['bind_id']}') and id != '{$user_id}'"];
}
$user_info_list = $this->user->getUserByWhere($where,$field);
return $user_info_list;
}
}
\ No newline at end of file
......@@ -52,6 +52,7 @@ class Users extends Model
->where($param)
->order('create_time desc')
->select();
// echo $this->getLastSql();
return $data;
}
......
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