Commit 55192a44 authored by hujun's avatar hujun

客户列表优化

parent 85974d29
......@@ -664,4 +664,25 @@ class CallPhoneService
}
return $code;
}
/**
* 查询绑定关系
*
* @param $agent_id
* @param array $phone_a
* @param $phone_b
* @return string
*/
public function checkBindRedis($agent_id, array $phone_a, $phone_b) {
$result = '';
foreach ($phone_a as $v) {
$call_key = 'call_'.$agent_id.'_'.$v.'_'.$phone_b.'_'.$this->is_privacy;
$phone_x = $this->redis->get($call_key);
if (strlen($phone_x) == 11) {
$result = $phone_x;
break;
}
}
return $result;
}
}
\ No newline at end of file
......@@ -11,6 +11,7 @@ namespace app\api_broker\service;
use app\extra\RedisExt;
use app\model\AAgents;
use app\model\AAgentsPhone;
use app\model\ADistrict;
use app\model\AStore;
use app\model\AuthGroup;
......@@ -48,6 +49,34 @@ class RedisCacheService
return $this->redis_ext->set($key, $value, $time);
}
/**
* @param $key
* @return mixed
*/
public function getRedisValue($key)
{
$data = $this->redis_ext->get($key);
if ($data) {
$data = json_decode($data, true);
} else {
$data = [];
}
return $data;
}
/**
* @param $key
* @param $value
* @return bool
*/
public function setRedisValue($key, $value)
{
if (empty($key) || empty($value)) {
return false;
}
return $this->redis_ext->set($key, $value);
}
/**
* @param $key
* @param $value
......@@ -57,7 +86,6 @@ class RedisCacheService
public function setRedisHashCache($key, $value, $time = 0)
{
$value = json_encode($value);
$key = $this->key_string.$key;
if (!$time) {
$time = $this->time;
}
......@@ -98,7 +126,7 @@ class RedisCacheService
$m_agent = new AAgents();
$field = 'id,store_id,auth_group_id,district_id,level,name,phone,img,status,admin_off,site_id';
$data = $m_agent->getAgentInfo($field, $agent_id);
if (!empty($data)) {
if ($data['district_id']) {
$m_district = new ADistrict();
$data['district_name'] = $m_district->getDistrictKeyById('district_name', ['id'=>$data['district_id']]);
......@@ -113,7 +141,9 @@ class RedisCacheService
$data['store_name'] = '';
}
if (!empty($data)) {
$m_agent_phone = new AAgentsPhone();
$data['phone_list'] = $m_agent_phone->getAgentsByWhereColumn(['agents_id'=>$data['id'], 'status'=>0], 'phone');
$data['phone_list'][] = $data['phone'];
$this->setRedisCache($this->agent_key . $agent_id, $data);
}
return $data;
......
......@@ -333,32 +333,17 @@ class Member extends Basic{
// big_log(json_encode($where));
$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.first_login_time,a.last_login_time,a.agent_id,a.vip,a.price_demand,a.industry_type,a.area_demand,a.user_status,a.source';
a.user_name,a.status,a.agent_id,a.vip,a.price_demand,a.industry_type,a.area_demand,a.user_status,a.source';
try {
$return_user_list = $this->user->getUserAgent($pageNo, $pageSize, 'a.id DESC', $fields, $where, $type,$this->siteId);
$return_user_list = $this->user->getUserAgent($pageNo, $pageSize, 'a.id DESC', $fields, $where, $type);
$list = [];
$user_follow = new UPhoneFollowUp($this->siteId);
$m_user = new Users();
$m_agent = new AAgents();
$redis_cache = new RedisCacheService();
$call = new CallPhoneService();
$s_phone_follow_up = new UPhoneFollowUp($this->siteId);
$s_phone_follow_temp = new UPhoneFollowUpTemporary($this->siteId);
foreach ($return_user_list as $k=>$v) {
if ($v['user_pic']) {
$return_user_list[$k]['user_pic'] = IMAGES_URL . 'static/head_portrait/' . $v['user_pic'];
} else {
$return_user_list[$k]['user_pic'] = '';
}
$user_data = $m_user->getUserById('id,user_nick,user_phone', $v['referrer_id']);
if (empty($user_data)) {
$return_user_list[$k]['name'] = '';
$return_user_list[$k]['phone'] = '';
} else {
$return_user_list[$k]['name'] = $user_data['user_nick'];
$return_user_list[$k]['phone'] = $user_data['user_phone'];
}
if (empty($v['agent_id'])) {
$return_user_list[$k]['agent_name'] = '';
} else {
......@@ -371,11 +356,32 @@ class Member extends Basic{
$return_user_list[$k]['agent_name'] = $agent_name;
}
$follow_time = $redis_cache->getRedisValue('follow_time_id_'.$v['id']);
if (empty($follow_time)) {
$params_['user_id']= $v['id'];
$order= 'id desc';
$res = $s_phone_follow_temp->getPhoneFollowData('create_time',$params_,$order);
if (empty($res)) {
$res = $s_phone_follow_up->getPhoneFollowData('create_time',$params_,$order);
}
$redis_cache->setRedisHashCache('follow_time_id_'.$v['id'], ['follow_time'=>$res[0]['create_time']], 3600);
} else {
$res[0]['create_time'] = $follow_time['follow_time'];
}
if (empty($res[0]['create_time'])) {
$return_user_list[$k]['follow_time'] = '';
} else {
$return_user_list[$k]['follow_time'] = $res[0]['create_time'];
}
// $params_['user_id'] = $v['id'];
// $res = $user_follow->getPhoneFollowData('create_time', $params_, 'id desc');
// $return_user_list[$k]['follow_time'] = $res[0]['create_time'];
$return_user_list[$k]['user_phone'] = hide_customer_phone($return_user_list[$k]['user_phone']);
$return_user_list[$k]['user_phone'] = substr_replace($return_user_list[$k]['user_phone'], '****', 3, 4);
$return_user_list[$k]['current_agent_id'] = $this->userId;
/*查询客户是否被经纪人收藏*/
......@@ -385,8 +391,6 @@ class Member extends Basic{
$is_outstrip_twenty_four_hours = $user_service->isUserProtect($v["id"]);
$return_user_list[$k]['is_outstrip_twenty_four_hours']=$is_outstrip_twenty_four_hours;
/*
判断当天被拨打是否超过后台限制,同时判断是否当前经纪人跟当前客户是否有电话绑定
0允许拨打 1不允许拨打
......@@ -396,11 +400,14 @@ class Member extends Basic{
if (!$clientService->dialTotal($v["id"])) {
$is_outpace_call_num = 1;
}
$model = new AAgents();
$result = $model->searchAgentsByKeyword("id,name,phone", [ "id" => $params["agent_id_for_bind"]]);
$call = new CallPhoneService();
$result = $call->getBindNum($v['user_phone'],$result[0]['phone']);//大于0说明有绑定关系
if($result != 0){
// $model = new AAgents();
// $result = $model->searchAgentsByKeyword("id,name,phone", [ "id" => $params["agent_id_for_bind"]]);
// $result = $call->getBindNum($v['user_phone'],$result[0]['phone']);//大于0说明有绑定关系
$agent_data = $redis_cache->getRedisCache(2, $this->userId);
$result = $call->checkBindRedis($this->userId, $agent_data['phone_list'], $v['user_phone']);
if($result != ''){
$is_outpace_call_num = 0;
}
$return_user_list[$k]['is_outpace_call_num'] = $is_outpace_call_num;
......
......@@ -505,10 +505,17 @@ class UserService
if(!$agent_id){
return 1;
}
$redis_server = new RedisCacheService();
$agent_data = $redis_server->getRedisCache(2, $user_agent_id);
$agent_model = new AAgents();
if (empty($agent_data)) {
$params_["id"] = $user_agent_id;
$result = $agent_model->searchAgentsByKeyword("id,store_id,district_id,level", $params_);
$result = $agent_model->searchAgentsByKeyword("district_id", $params_);
} else {
$result[0]['district_id'] = $agent_data['district_id'];
}
if(!$result){
return 1;
......@@ -516,7 +523,7 @@ class UserService
$params__['district_id']=$result[0]['district_id'];
$params__['level']=30;
$result = $agent_model->searchAgentsByKeyword("id,store_id,district_id,level", $params__);
$result = $agent_model->searchAgentsByKeyword("id", $params__);
if(isset($result[0]['district_id'])){
if ($result[0]['district_id'] == $agent_id) {
return 0;//可查看
......
......@@ -113,11 +113,8 @@ class Users extends Model
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getUserAgent($pageNo = 1, $pageSize = 15, $order_ = 'a.id desc', $fields = '*', $params = '', $type = 0,$site_id)
public function getUserAgent($pageNo = 1, $pageSize = 15, $order_ = 'a.id desc', $fields = '*', $params = '', $type = 0)
{
$data = [];
if ($type == 1) {
$result = $this->field($fields)
->alias('a')
......@@ -162,36 +159,7 @@ class Users extends Model
->page($pageNo)
->select();
}
//echo Db::table($this->table)->getLastSql();
$s_phone_follow_up = new UPhoneFollowUp($site_id);
$s_phone_follow_temp = new UPhoneFollowUpTemporary($site_id);
foreach ($result as $k => $v) {
$data[$k] = $v->getData();
if ($data[$k]['user_pic']) {
$data[$k]['user_pic'] = IMAGES_URL . 'static/head_portrait/' . $data[$k]['user_pic'];
} else {
$data[$k]['user_pic'] = '';
}
$user_data = $this->field('id,user_nick,user_phone')->where('id', $data[$k]['referrer_id'])->find();
$data[$k]['name'] = $user_data['user_nick'];
$data[$k]['phone'] = $user_data['user_phone'];
$params_['user_id']= $data[$k]['id'];
$order= 'id desc';
$res = $s_phone_follow_temp->getPhoneFollowData('create_time',$params_,$order);
if (empty($res)) {
$res = $s_phone_follow_up->getPhoneFollowData('create_time',$params_,$order);
}
if (empty($res[0]['create_time'])) {
$data[$k]['follow_time'] = '';
} else {
$data[$k]['follow_time'] = $res[0]['create_time'];
}
}
return $data;
return $result;
}
/**
......
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