Commit f5c2b11c authored by clone's avatar clone

经纪人查看客户日志

parent 08f1bfa7
<?php
namespace app\api_broker\service;
use app\extra\RedisExt;
/**
* Created by PhpStorm.
* User: zw
* Date: 2019/9/17
* Time: 10:28
*/
class AgentLookUserLogService
{
private $redis;
private $nowTime;
const LOOK_USER = "agent_look_user_";//经纪人看用户key
const IS_PC = "agent_look_user_by_pc";//记录是哪里看的
public function __construct()
{
$this->redis = RedisExt::getRedis();
$this->nowTime = date("Y-m-d", time());
}
/**
* @param int $agent_id
* @param int $user_id
* @param int $is_pc
* @return array
*/
public function saveCacheAgentLookUser(int $agent_id, int $user_id, int $is_pc): array
{
//redis服务挂掉,都可以看
if (!$this->redis) {
return;
}
//判断此用户是否看过
$isExist = $this->isLooked($agent_id, $user_id);
if (!$isExist) {
$this->redis->sAdd(self::LOOK_USER . $this->nowTime . $agent_id, $user_id);//存入所看用户信息
$this->redis->set(self::LOOK_USER . $this->nowTime . $agent_id . "_" . $user_id, time());//存入第一次看的时间
$this->redis->set(self::IS_PC . $this->nowTime . $agent_id . "_" . $user_id, $is_pc);
} else {
$this->redis->set(self::LOOK_USER . $this->nowTime . $agent_id . "_" . $user_id . "_lastTime", time());//存入最后一次看的时间
$this->redis->set(self::IS_PC . $this->nowTime . $agent_id . "_" . $user_id . "_lastTime", $is_pc);
}
return;
}
/**
* 判断是否已经看过,看过返回true 否则 false
* @param int $agent_id
* @param int $user_id
* @return bool
*/
public function isLooked(int $agent_id, int $user_id): bool
{
$isExist = $this->redis->sIsMember(self::LOOK_USER . $this->nowTime . $agent_id, $user_id);
if ($isExist) {
return true;
} else {
return false;
}
}
}
\ No newline at end of file
......@@ -2,6 +2,7 @@
namespace app\index\service;
use app\api_broker\service\AgentLookUserLogService;
use app\api_broker\service\CallPhoneService;
use app\api_broker\service\ClientService;
use app\api_broker\service\OrderLogService;
......@@ -74,7 +75,7 @@ class UserLogService
}
$user_arr['user_pic'] = HEADERIMGURL . $user_arr['user_pic'];
$agents_arr = $m_user_agent->getUserAgent('a.agent_id,c.name,c.phone', ['a.site_id'=>$site_id, 'a.user_id'=>$user_id]);
$agents_arr = $m_user_agent->getUserAgent('a.agent_id,c.name,c.phone', ['a.site_id' => $site_id, 'a.user_id' => $user_id]);
if ($agents_arr['name']) {
$user_arr['agent_info'] = $agents_arr ? $agents_arr['name'] . '-' . $agents_arr['phone'] : '未知';
$user_arr['agent_id'] = $agents_arr['agent_id'];
......@@ -83,7 +84,7 @@ class UserLogService
}
$data['agent_path'] = AGENTHEADERIMGURL;
$user_arr['user_phone'] = substr_replace($user_arr['user_phone'], '****', 3, 4);
if($user_arr['referrer_source'] == 0 && $user_arr['referrer_id'] == 0){
if ($user_arr['referrer_source'] == 0 && $user_arr['referrer_id'] == 0) {
$user_arr['referrer_id'] = '';
$user_arr['referrer_user'] = '';
$user_arr['referrer_source'] = '';
......@@ -96,7 +97,7 @@ class UserLogService
$data["user_history_log"] = $this->userHistoryLog($user_id);
#是否被收藏
$data["is_collect"] =$this->userDetailIsCollect($user_id, $agent_id);
$data["is_collect"] = $this->userDetailIsCollect($user_id, $agent_id);
#保护期(0:保护器内 1:超过保护期)
$data['is_outstrip_twenty_four_hours'] = $user_service->isUserProtect($user_id);
......@@ -118,15 +119,15 @@ class UserLogService
$data['site_ids_name_new'] = $data['site_ids_name'];
#拨打电话按钮是否显示 0:显示 1:不显示
$data['is_phone_button_show'] = $this->isPhoneButtonShow($user_id,$agent_id,$user_arr['vip'],$user_arr['user_phone'],$user_arr['agent_id']);
$data['is_phone_button_show'] = $this->isPhoneButtonShow($user_id, $agent_id, $user_arr['vip'], $user_arr['user_phone'], $user_arr['agent_id']);
//客方
$s_user_agent = new UserAgentService();
$user_agent_res = $s_user_agent->selectUserAgent($user_id);
$data['customer_relegation_list'] = $user_agent_res ? $user_agent_res : [];
// $this->agentLookUser($user_id, $agent_id, 1); //记录经纪人看客户
$agentLookUserService = new AgentLookUserLogService();
$agentLookUserService->saveCacheAgentLookUser($agent_id, $user_id, 1); //记录经纪人看客户
return ["code" => 200, "data" => $data];
}
......@@ -134,7 +135,8 @@ class UserLogService
* @param $user_id
* @return mixed
*/
public function userHistoryLog($user_id){
public function userHistoryLog($user_id)
{
#客方、邀请人修改日志 点击客户'编辑'按钮显示
#客户姓名、城市标签修改记录 由专门的'修改记录'按钮显示
$m_records = new GOperatingRecords();
......@@ -147,7 +149,7 @@ class UserLogService
$result['invite_history'] = $m_records->user_history($param_);
//客户姓名 城市标签 修改记录
$param_['type'] = array('in','9,10');
$param_['type'] = array('in', '9,10');
$result['other_history'] = $m_records->user_history($param_);
return $result;
}
......@@ -166,11 +168,11 @@ class UserLogService
public function userLog($user_id, $site_id, $type)
{
$result = $this->orderService->selectListByUserIdAndSiteId($user_id, '', $site_id);
switch ($type){
switch ($type) {
case 1:
if(count($result) > 0){
if (count($result) > 0) {
return $result[0];
}else{
} else {
return null;
}
......@@ -196,7 +198,7 @@ class UserLogService
{
// $userParams["type"] = 0; //电话跟进 $userParams["type"] = 1; //普通跟进
$m_label = new ULabels();
$label_data = $m_label->getColumn('id,name', ['type'=>1]); //获取标签
$label_data = $m_label->getColumn('id,name', ['type' => 1]); //获取标签
$uPhoneFollowTempModel = new UPhoneFollowUpTemporary($site_id);
//电话跟进
......@@ -204,10 +206,10 @@ class UserLogService
$field_user_follow = "a.id,a.labels_id,a.content,a.user_id,a.agent_id,a.type,a.create_time,a.user_status,b.name,b.phone,b.img,a.img_str";
$bargainData = $uPhoneFollowTempModel->getFollowUpList($field_user_follow, $userParams,$page_no,$page_size);
$bargainData = $uPhoneFollowTempModel->getFollowUpList($field_user_follow, $userParams, $page_no, $page_size);
foreach ($bargainData as $k => $v) {
$bargainData[$k]['label_name'] = array_key_exists($v['labels_id'], $label_data) ? '【'.$label_data[$v['labels_id']].'】' : '';
$bargainData[$k]['label_name'] = array_key_exists($v['labels_id'], $label_data) ? '【' . $label_data[$v['labels_id']] . '】' : '';
}
return $bargainData;
......@@ -217,16 +219,16 @@ class UserLogService
{
// $userParams["type"] = 0; //电话跟进 $userParams["type"] = 1; //普通跟进
$m_label = new ULabels();
$label_data = $m_label->getColumn('id,name', ['type'=>1]); //获取标签
$label_data = $m_label->getColumn('id,name', ['type' => 1]); //获取标签
$uPhoneFollowModel = new UPhoneFollowUp($site_id);
//电话跟进
$userParams["user_id"] = $user_id;
$field_user_follow = "a.id,a.labels_id,a.content,a.user_id,a.agent_id,a.type,a.create_time,a.user_status,b.name,b.phone,b.img,a.img_str";
$bargainData = $uPhoneFollowModel->getFollowUpList($field_user_follow, $userParams,$page_no,$page_size);
$bargainData = $uPhoneFollowModel->getFollowUpList($field_user_follow, $userParams, $page_no, $page_size);
foreach ($bargainData as $k => $v) {
$bargainData[$k]['label_name'] = array_key_exists($v['labels_id'], $label_data) ? '【'.$label_data[$v['labels_id']].'】' : '';
$bargainData[$k]['label_name'] = array_key_exists($v['labels_id'], $label_data) ? '【' . $label_data[$v['labels_id']] . '】' : '';
}
return $bargainData;
}
......@@ -238,21 +240,21 @@ class UserLogService
* @param $agent_id
* @return mixed
*/
public function userDetailStreamline($user_id, $agent_id,$site_id)
public function userDetailStreamline($user_id, $agent_id, $site_id)
{
//查询客户详情
$field = 'id as user_id,sex,user_pic,other_pic,user_nick,user_name,user_phone,site_ids,agent_id,user_label,
industry_type,price_demand,area_demand,vip,user_status,entrust_type,concrete_industry';
$result = $this->userModel->getUserDetailStreamline($user_id,$field);
$result = $this->userModel->getUserDetailStreamline($user_id, $field);
if (count($result) <= 0) {
return ["code" => 101, "msg" => "没找到此条用户信息"];
}
$result['user_name'] = $result['user_name']&& $result['entrust_type'] == 0 ?"{$result['concrete_industry']},{$result['user_name']}":$result['user_name'];
$result['user_name'] = $result['user_name'] && $result['entrust_type'] == 0 ? "{$result['concrete_industry']},{$result['user_name']}" : $result['user_name'];
$result['user_pic'] = !empty($result["user_pic"]) ? HEADERIMGURL . $result["user_pic"] : $result["other_pic"];
#判断是否纯房东 0:否 1:是
$result['is_single_homeowner'] = $result['user_label'] == 2 ? 1 : 0 ;
$result['is_single_homeowner'] = $result['user_label'] == 2 ? 1 : 0;
#客户站点(旧 兼容老版本)
$s_index_user = new UserService();
......@@ -260,10 +262,10 @@ class UserLogService
#客户站点 新(客户站点独立建表)
// $s_user_site = new UserSiteService();
$result['site_ids_name_new'] = $result['site_ids_name'] ;
$result['site_ids_name_new'] = $result['site_ids_name'];
#是否被收藏
$result["is_collect"] =$this->userDetailIsCollect($user_id, $agent_id);
$result["is_collect"] = $this->userDetailIsCollect($user_id, $agent_id);
#客户是否在保护期内(0:保护器内 1:超过保护期)
$user_service = new UserService();
......@@ -278,9 +280,10 @@ class UserLogService
$result['is_phone_button_show'] = $this->isPhoneButtonShow($user_id, $agent_id, $result['vip'], $result['user_phone'], $result['agent_id']);
#编辑客户详情权限 0:有权限 1:无权限
$result['is_can_edit_user_info'] = $user_service->isCanEditUserInfo($result["agent_id"], $agent_id,$user_id);
$result['is_can_edit_user_info'] = $user_service->isCanEditUserInfo($result["agent_id"], $agent_id, $user_id);
//$this->agentLookUser($user_id, $agent_id, 0); //记录经纪人看客户
$agentLookUserService = new AgentLookUserLogService();
$agentLookUserService->saveCacheAgentLookUser($agent_id, $user_id, 0); //记录经纪人看客户
return $result;
......@@ -296,14 +299,14 @@ class UserLogService
//查询客户详情
$field = 'id as user_id,agent_id,vip,create_time,first_login_time,referrer_source,referrer_id,registration_time,
source_intro,referrer_source,source,entrust_type,concrete_industry,weixin_nick';
$user_result = $this->userModel->getUserDetailStreamline($user_id,$field);
$user_result = $this->userModel->getUserDetailStreamline($user_id, $field);
if (count($user_result) <= 0) {
return ["code" => 101, "msg" => "没找到此条用户信息"];
}
// 客方 姓名+手机号
$agents_res = $this->agentModel->verifyUser('name,phone', '', [ 'id' => $user_result['agent_id'] ]);
$agents_res = $this->agentModel->verifyUser('name,phone', '', ['id' => $user_result['agent_id']]);
$result['agent_name'] = $agents_res['name'] ? $agents_res['name'] : '未知';
$result['agent_phone'] = $agents_res['phone'] ? $agents_res['phone'] : '未知';
//客方
......@@ -315,7 +318,7 @@ class UserLogService
// 是否转介绍
$result['referrer_source'] = $user_result['referrer_source'];
// 邀请人 手机号 ID
$invite_info = $this->userDetailUserInvite($user_result['referrer_id'],$user_result['referrer_source']);
$invite_info = $this->userDetailUserInvite($user_result['referrer_id'], $user_result['referrer_source']);
$result['user_inviter_phone'] = $invite_info['invite_phone'];
$result['user_inviter_id'] = $invite_info['invite_id'];
......@@ -346,7 +349,7 @@ class UserLogService
* @param $result_agent_id
* @return int
*/
public function isPhoneButtonShow($user_id,$agent_id,$is_vip,$result_user_phone,$result_agent_id)
public function isPhoneButtonShow($user_id, $agent_id, $is_vip, $result_user_phone, $result_agent_id)
{
$user_service = new UserService();
$vip_services = new VipService();
......@@ -390,28 +393,28 @@ class UserLogService
$examine_vip = $vip_services->vip($agent_id);
#经纪人客户是否有约带看 0:可查看 1:不可查看
$is_report = $user_service->isReport($agent_id,$user_id);
$is_report = $user_service->isReport($agent_id, $user_id);
#当天有约带看的客户 0:不显示 1:显示
$s_user_call = new UserCallStintService();
$is_user_report = $s_user_call->isUserReport($user_id);
//3.3.9 如果有约带看 同时过保护期了
if($is_user_report == 1 and ($is_outstrip_twenty_four_hours == 1)){
if ($is_user_report == 1 and ($is_outstrip_twenty_four_hours == 1)) {
$s_user_call = new UserCallStintService();
$report_agents = $s_user_call->getUserReportAgentIdList($user_id);
//3.3.9 有约带看订单的客户 预计到场当天 只能 约带看提交人 或 客方 拨打电话
if(($result_agent_id == $agent_id) or (in_array($agent_id,$report_agents))){
if (($result_agent_id == $agent_id) or (in_array($agent_id, $report_agents))) {
return 0;
}else{
} else {
return 1;
}
}
#当天有约带看的客户 0:不显示 1:显示
$result_val = 1;
if(
(($is_outpace_call_num == 0 ) and ($is_outstrip_twenty_four_hours == 1) and ($is_vip != 1) ) //过保护期
if (
(($is_outpace_call_num == 0) and ($is_outstrip_twenty_four_hours == 1) and ($is_vip != 1)) //过保护期
OR
($is_user_agent_boss == 0)//总监可以看
OR
......@@ -421,12 +424,12 @@ class UserLogService
OR
(($is_vip == 1) and ($examine_vip == 0))
OR
(($is_outpace_call_num == 0 ) and ($is_outstrip_twenty_four_hours == 0) and (($is_user_agent_boss == 0) or (in_array($agent_id, $user_agent_list_arr)) or ($called == 0)))
(($is_outpace_call_num == 0) and ($is_outstrip_twenty_four_hours == 0) and (($is_user_agent_boss == 0) or (in_array($agent_id, $user_agent_list_arr)) or ($called == 0)))
OR
(($is_outpace_call_num == 1 ) and (($is_user_agent_boss == 0) or (in_array($agent_id, $user_agent_list_arr)) or ($called == 0)))
(($is_outpace_call_num == 1) and (($is_user_agent_boss == 0) or (in_array($agent_id, $user_agent_list_arr)) or ($called == 0)))
OR
($is_report == 0)
){
) {
return 0;//0:显示
}
return $result_val;
......@@ -446,7 +449,7 @@ class UserLogService
$agent_ids = $this->getSiteAgentId($agent_id);
if ($agent_ids) {
//此经纪人有转勤账号
$insert["agents_id"] = array( 'in', $agent_ids );
$insert["agents_id"] = array('in', $agent_ids);
} else {
$insert["agents_id"] = $agent_id;
}
......@@ -471,7 +474,7 @@ class UserLogService
$params = [];
$params["phone"] = $agent_phone;
$params["status"] = array( 'in', '0,3' );
$params["status"] = array('in', '0,3');
$agentsArr = $m_agent->getAgentsByStoreId($params);
$agent_total = count($agentsArr);
......@@ -494,7 +497,7 @@ class UserLogService
* @param $agent_id
* @return int
*/
public function userDetailIsOutpaceCallNum($user_id,$user_phone, $agent_id)
public function userDetailIsOutpaceCallNum($user_id, $user_phone, $agent_id)
{
$is_outpace_call_num = 0;
$clientService = new ClientService();
......@@ -530,72 +533,40 @@ class UserLogService
$phone = $this->agentModel->getAgentsById($agent_id, 'phone');
$is_privacy = $redis->get('s_is_privacy');//判断是否当前经纪人跟当前客户是否有电话绑定 从redis查询
if (empty($phone)) {
$phone = $m_agent_phone->getAgentsByWhere(['agent_id'=>$agent_id], 'phone');
$phone = $m_agent_phone->getAgentsByWhere(['agent_id' => $agent_id], 'phone');
}
$call_key = 'call_'.$agent_id.'_'.$phone.'_'.$user_phone.'_'.$is_privacy;
$call_key = 'call_' . $agent_id . '_' . $phone . '_' . $user_phone . '_' . $is_privacy;
$redis_res = $redis->get($call_key);
if(empty($redis_res)){
if (empty($redis_res)) {
$is_outpace_call_num = 1;
}
return $is_outpace_call_num;//0有绑定关系 1无绑定关系
}
/**
* 查询客户邀请人
* @param $referrer_id
* @param $referrer_source
* @return string
*/
public function userDetailUserInvite($referrer_id,$referrer_source)
public function userDetailUserInvite($referrer_id, $referrer_source)
{
if ($referrer_source == 10) {
$referrer_res = $this->userModel->verifyUser('user_name,user_phone', '', [ 'id' => $referrer_id ]);
$referrer_res = $this->userModel->verifyUser('user_name,user_phone', '', ['id' => $referrer_id]);
$user_phone = empty($referrer_res['user_phone']) ? '' : substr_replace($referrer_res['user_phone'], '****', 3, 4);
$return['invite_phone'] = $user_phone;
$return['invite_id'] = $referrer_id;
} else {
$return['invite_phone'] = '';
$return['invite_id'] = '';
if($referrer_id > 0){
$referrer_res = $this->agentModel->verifyUser('name,phone', '', [ 'id' => $referrer_id ]);
$return['invite_phone'] = $referrer_res['name'].'-'.$referrer_res['phone'];
if ($referrer_id > 0) {
$referrer_res = $this->agentModel->verifyUser('name,phone', '', ['id' => $referrer_id]);
$return['invite_phone'] = $referrer_res['name'] . '-' . $referrer_res['phone'];
$return['invite_id'] = '';
}
}
return $return;
}
/**
* 记录经纪人查看客户
*
* @param $user_id
* @param $agent_id
* @param $source
* @return bool
*/
public function agentLookUser($user_id, $agent_id, $source)
{
if (empty($user_id)) {
return false;
}
if (empty($agent_id)) {
return false;
}
$m_look_user = new TLookAgentUserModel();
// $redis_ext = RedisExt::getRedis();
// $key = 't_look_agent_user_' . $agent_id.'_'.$user_id;
// $num = $redis_ext->get($key);
// if (empty($num)) {
$id = $m_look_user->insertData($user_id, $agent_id, $source);
// $today_time = strtotime(date('Y-m-d') . ' 23:59:59') - time(); //到0点剩余时间
// $redis_ext->set($key, $id, $today_time);
// }
return $id;
}
}
\ No newline at end of file
......@@ -41,7 +41,18 @@ class TLookAgentUserModel extends BaseModel
}
return $id;
}
public function addLookUser($params)
{
Db::startTrans();
try {
$this->db_->insertAll($params);
Db::commit();
return 1;
} catch (\Exception $e) {
Db::rollback();
return 0;
}
}
public function delData($where)
{
return $this->db_->where($where)->delete();
......
<?php
namespace app\task\controller;
use app\extra\RedisExt;
use app\model\AAgents;
use app\model\TLookAgentUserModel;
use think\Exception;
use think\Log;
/**
* Created by PhpStorm.
* User : zw
* Date : 2018/5/9
* Time : 下午4:45
* Intro:
*/
class SaveLookUserHistoryTask
{
private $redis;
private $yesterday;
private $agentsModel;
private $tLookAgentUserModel;
const LOOK_USER = "agent_look_user_";//经纪人看用户key
const IS_PC = "agent_look_user_by_pc";//记录是哪里看的
function __construct()
{
$this->redis = RedisExt::getRedis();
$this->yesterday = date("Y-m-d", strtotime("-1 day"));
$this->agentsModel = new AAgents();
$this->tLookAgentUserModel = new TLookAgentUserModel();
}
/**
* 查询经纪人列表
* @return bool
*/
public function saveLookShop()
{
if (!$this->redis) {
return;
}
$day = date("Y-m-d", time());
if ($this->redis->get("run_save_agent_look_user" . $day)) {
return;
}
$this->redis->set("run_save_agent_look_user" . $day, 1, 24 * 3600);
//todo 1.拿到每个经纪人的看铺记录 2.根据看铺记录统计出已看铺数量,3.根据经纪人id 拿到可看铺总数
$total = $this->agentsModel->getAgentsCountByTask();
$pageSize = 100;
$pageTotal = ceil($total / $pageSize);
for ($pageNo = 1; $pageNo <= $pageTotal; $pageNo++) {
$resultArr = $this->agentsModel->getAgentsListByLookShop($pageNo, $pageSize, "id,name,phone");
$this->executeSave($resultArr);
unset($resultArr);
}
}
/**
* 保存看铺记录 清空redis缓存
* @param $resultArr
*/
private function executeSave($resultArr)
{
$list = [];
foreach ($resultArr as $key => $value) {
$agent_id = $value["id"];
$selectKey = self::LOOK_USER . $this->yesterday . $agent_id;
$collection = $this->redis->sMembers($selectKey);
foreach ($collection as $item) {
$getLookTimeKey = $selectKey . "_" . $item;
$getLookIsPcKey = self::IS_PC . $this->yesterday . $agent_id . "_" . $item;
$getLookLastTimeKey = $selectKey . "_" . $item . "_lastTime";
$getLookLastIsPcKey = self::IS_PC . $this->yesterday . $agent_id . "_" . $item . "_lastTime";
$lookTime = $this->redis->get($getLookTimeKey);
$getLookIsPc = $this->redis->get($getLookIsPcKey);
$getLookLastTime = $this->redis->get($getLookLastTimeKey);
$getLookLastIsPc = $this->redis->get($getLookLastIsPcKey);
if ($lookTime && $getLookIsPc) {
array_push($list, $this->tLookShopBin($agent_id, $item, $getLookIsPc, $lookTime));
}
if ($getLookLastTime && $getLookLastIsPc) {
array_push($list, $this->tLookShopBin($agent_id, $item, $getLookLastIsPc, $getLookLastTime));
}
//删除redis缓存
$this->redis->sRem($selectKey, $item);
$this->redis->del($getLookTimeKey);
$this->redis->del($getLookIsPcKey);
$this->redis->del($getLookLastTimeKey);
$this->redis->del($getLookLastIsPcKey);
}
try {
$is_insert = -1;
if (!empty($list)) {
$is_insert = $this->tLookAgentUserModel->addLookUser($list);
}
if ($is_insert == 0) {
Log::record("SaveLookUserHistoryTask--111----executeSave---save error", "info");
}
} catch (Exception $exception) {
Log::record("SaveLookUserHistoryTask---222---executeSave---save error" . $exception, "info");
}
$list = [];
}
unset($list);
}
private function tLookShopBin($agent_id, $user_id, $source, $look_time)
{
$arrBin = [];
$arrBin['user_id'] = $user_id;
$arrBin['agent_id'] = $agent_id;
$arrBin['source'] = $source;
$arrBin["create_time"] = date("Y-m-d H:i:s", $look_time);
$arrBin["update_time"] = date("Y-m-d H:i:s", time());
return $arrBin;
}
}
\ 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