Commit 55192a44 authored by hujun's avatar hujun

客户列表优化

parent 85974d29
...@@ -664,4 +664,25 @@ class CallPhoneService ...@@ -664,4 +664,25 @@ class CallPhoneService
} }
return $code; 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; ...@@ -11,6 +11,7 @@ namespace app\api_broker\service;
use app\extra\RedisExt; use app\extra\RedisExt;
use app\model\AAgents; use app\model\AAgents;
use app\model\AAgentsPhone;
use app\model\ADistrict; use app\model\ADistrict;
use app\model\AStore; use app\model\AStore;
use app\model\AuthGroup; use app\model\AuthGroup;
...@@ -48,6 +49,34 @@ class RedisCacheService ...@@ -48,6 +49,34 @@ class RedisCacheService
return $this->redis_ext->set($key, $value, $time); 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 $key
* @param $value * @param $value
...@@ -57,7 +86,6 @@ class RedisCacheService ...@@ -57,7 +86,6 @@ class RedisCacheService
public function setRedisHashCache($key, $value, $time = 0) public function setRedisHashCache($key, $value, $time = 0)
{ {
$value = json_encode($value); $value = json_encode($value);
$key = $this->key_string.$key;
if (!$time) { if (!$time) {
$time = $this->time; $time = $this->time;
} }
...@@ -98,22 +126,24 @@ class RedisCacheService ...@@ -98,22 +126,24 @@ class RedisCacheService
$m_agent = new AAgents(); $m_agent = new AAgents();
$field = 'id,store_id,auth_group_id,district_id,level,name,phone,img,status,admin_off,site_id'; $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); $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']]);
} else {
$data['district_name'] = '';
}
if ($data['district_id']) { if ($data['store_id']) {
$m_district = new ADistrict(); $m_district = new AStore();
$data['district_name'] = $m_district->getDistrictKeyById('district_name', ['id'=>$data['district_id']]); $data['store_name'] = $m_district->getStoreKeyById('store_name', ['id'=>$data['store_id']]);
} else { } else {
$data['district_name'] = ''; $data['store_name'] = '';
} }
if ($data['store_id']) {
$m_district = new AStore();
$data['store_name'] = $m_district->getStoreKeyById('store_name', ['id'=>$data['store_id']]);
} else {
$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); $this->setRedisCache($this->agent_key . $agent_id, $data);
} }
return $data; return $data;
......
...@@ -333,32 +333,17 @@ class Member extends Basic{ ...@@ -333,32 +333,17 @@ class Member extends Basic{
// big_log(json_encode($where)); // 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, $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 { 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 = []; $list = [];
$user_follow = new UPhoneFollowUp($this->siteId); $m_agent = new AAgents();
$m_user = new Users(); $redis_cache = new RedisCacheService();
$m_agent = new AAgents(); $call = new CallPhoneService();
$redis_cache = new RedisCacheService(); $s_phone_follow_up = new UPhoneFollowUp($this->siteId);
$s_phone_follow_temp = new UPhoneFollowUpTemporary($this->siteId);
foreach ($return_user_list as $k=>$v) { 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'])) { if (empty($v['agent_id'])) {
$return_user_list[$k]['agent_name'] = ''; $return_user_list[$k]['agent_name'] = '';
} else { } else {
...@@ -371,11 +356,32 @@ class Member extends Basic{ ...@@ -371,11 +356,32 @@ class Member extends Basic{
$return_user_list[$k]['agent_name'] = $agent_name; $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']; // $params_['user_id'] = $v['id'];
// $res = $user_follow->getPhoneFollowData('create_time', $params_, 'id desc'); // $res = $user_follow->getPhoneFollowData('create_time', $params_, 'id desc');
// $return_user_list[$k]['follow_time'] = $res[0]['create_time']; // $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; $return_user_list[$k]['current_agent_id'] = $this->userId;
/*查询客户是否被经纪人收藏*/ /*查询客户是否被经纪人收藏*/
...@@ -385,8 +391,6 @@ class Member extends Basic{ ...@@ -385,8 +391,6 @@ class Member extends Basic{
$is_outstrip_twenty_four_hours = $user_service->isUserProtect($v["id"]); $is_outstrip_twenty_four_hours = $user_service->isUserProtect($v["id"]);
$return_user_list[$k]['is_outstrip_twenty_four_hours']=$is_outstrip_twenty_four_hours; $return_user_list[$k]['is_outstrip_twenty_four_hours']=$is_outstrip_twenty_four_hours;
/* /*
判断当天被拨打是否超过后台限制,同时判断是否当前经纪人跟当前客户是否有电话绑定 判断当天被拨打是否超过后台限制,同时判断是否当前经纪人跟当前客户是否有电话绑定
0允许拨打 1不允许拨打 0允许拨打 1不允许拨打
...@@ -396,11 +400,14 @@ class Member extends Basic{ ...@@ -396,11 +400,14 @@ class Member extends Basic{
if (!$clientService->dialTotal($v["id"])) { if (!$clientService->dialTotal($v["id"])) {
$is_outpace_call_num = 1; $is_outpace_call_num = 1;
} }
$model = new AAgents(); // $model = new AAgents();
$result = $model->searchAgentsByKeyword("id,name,phone", [ "id" => $params["agent_id_for_bind"]]); // $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说明有绑定关系
$result = $call->getBindNum($v['user_phone'],$result[0]['phone']);//大于0说明有绑定关系
if($result != 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; $is_outpace_call_num = 0;
} }
$return_user_list[$k]['is_outpace_call_num'] = $is_outpace_call_num; $return_user_list[$k]['is_outpace_call_num'] = $is_outpace_call_num;
......
...@@ -505,10 +505,17 @@ class UserService ...@@ -505,10 +505,17 @@ class UserService
if(!$agent_id){ if(!$agent_id){
return 1; return 1;
} }
$agent_model = new AAgents();
$params_["id"] = $user_agent_id;
$result = $agent_model->searchAgentsByKeyword("id,store_id,district_id,level", $params_);
$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("district_id", $params_);
} else {
$result[0]['district_id'] = $agent_data['district_id'];
}
if(!$result){ if(!$result){
return 1; return 1;
...@@ -516,7 +523,7 @@ class UserService ...@@ -516,7 +523,7 @@ class UserService
$params__['district_id']=$result[0]['district_id']; $params__['district_id']=$result[0]['district_id'];
$params__['level']=30; $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(isset($result[0]['district_id'])){
if ($result[0]['district_id'] == $agent_id) { if ($result[0]['district_id'] == $agent_id) {
return 0;//可查看 return 0;//可查看
......
...@@ -113,11 +113,8 @@ class Users extends Model ...@@ -113,11 +113,8 @@ class Users extends Model
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @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) { if ($type == 1) {
$result = $this->field($fields) $result = $this->field($fields)
->alias('a') ->alias('a')
...@@ -162,36 +159,7 @@ class Users extends Model ...@@ -162,36 +159,7 @@ class Users extends Model
->page($pageNo) ->page($pageNo)
->select(); ->select();
} }
//echo Db::table($this->table)->getLastSql(); return $result;
$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;
} }
/** /**
......
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