Commit c299166f authored by hujun's avatar hujun

跟进列表优化

parent b159de29
...@@ -43,14 +43,22 @@ class Remark extends Basic ...@@ -43,14 +43,22 @@ class Remark extends Basic
if($this->params['pageNo'] == 1 && !$is_check){ if($this->params['pageNo'] == 1 && !$is_check){
return $this->response("101", "请勿频繁请求"); return $this->response("101", "请勿频繁请求");
} }
$u_phone_follow = new UPhoneFollowPp($this->siteId);
$user_service = new UserService();
$clientService = new ClientService();
$m_agent_phone = new AAgentsPhone();
$m_user = new Users();
$m_label = new ULabels();
$m_agent = new AAgents();
$redis = RedisExt::getRedis();
$data['status'] = 200; $data['status'] = 200;
$data['msg'] = ''; $data['msg'] = '';
$agent_where = $where = []; $agent_where = $where = [];
$pageNo = empty($this->params['pageNo']) ? 1 : $this->params['pageNo']; $pageNo = empty($this->params['pageNo']) ? 1 : $this->params['pageNo'];
$pageSize = empty($this->params['pageSize']) ? 15 : $this->params['pageSize']; $pageSize = empty($this->params['pageSize']) ? 15 : $this->params['pageSize'];
$u_phone_follow = new UPhoneFollowPp($this->siteId);
if (!empty($this->params['start_date']) && empty($this->params['end_date'])) { if (!empty($this->params['start_date']) && empty($this->params['end_date'])) {
$where['create_time'] = ['> time', $this->params['start_date'] . ' 00:00:00']; $where['create_time'] = ['> time', $this->params['start_date'] . ' 00:00:00'];
} }
...@@ -82,18 +90,6 @@ class Remark extends Basic ...@@ -82,18 +90,6 @@ class Remark extends Basic
$agent_where['district_id'] = $this->params['remark_district_id']; $agent_where['district_id'] = $this->params['remark_district_id'];
} }
/*if (!empty($this->params['province'])) {
$where['province'] = $this->params['province'];
}
if (!empty($this->params['city'])) {
$where['city'] = $this->params['city'];
}*/
/*if ($this->city != '全部') {
$where['city'] = $this->city;
}*/
if (!empty($this->params['disc'])) { if (!empty($this->params['disc'])) {
$where['disc'] = $this->params['disc']; $where['disc'] = $this->params['disc'];
} }
...@@ -103,7 +99,6 @@ class Remark extends Basic ...@@ -103,7 +99,6 @@ class Remark extends Basic
} }
if (!empty($agent_where)) { if (!empty($agent_where)) {
$m_agent = new AAgents();
$agent_id = $m_agent->getAgentsByWhereColumn($agent_where, 'id'); $agent_id = $m_agent->getAgentsByWhereColumn($agent_where, 'id');
if (empty($agent_id)) { if (empty($agent_id)) {
...@@ -113,38 +108,40 @@ class Remark extends Basic ...@@ -113,38 +108,40 @@ class Remark extends Basic
$where['agent_id'] = ['in', $agent_id]; $where['agent_id'] = ['in', $agent_id];
} }
} }
$field = 'id,user_id,create_time,content,user_status,labels_id,agent_id as f_agent_id'; $field = 'id,user_id,create_time,content,user_status,labels_id,agent_id';
$data['data']['list'] = $u_phone_follow->getFollowList($pageNo, $pageSize, $order_ = 'id desc', $field, $where); $list = $u_phone_follow->getFollowList($pageNo, $pageSize, $order_ = 'id desc', $field, $where);
$redis = RedisExt::getRedis();
$label_data = $m_label->getColumn('id,name', ['type'=>1]); //获取标签
foreach ($list as $k => $v) {
if (!empty($v['user_id'])) {
$user_data = $m_user->getUserById('user_name,user_phone,vip,agent_id,create_time', $v['user_id']);
$list[$k]['user_name'] = $user_data['user_name'];
$list[$k]['user_phone'] = $user_data['user_phone'];
$list[$k]['u_create_time'] = $user_data['create_time'];
$list[$k]['vip'] = $user_data['vip'];
$list[$k]['agent_id'] = $user_data['agent_id']; //客户客方
}
foreach ($data['data']['list'] as $k => $v) {
//dump($v);
//查询客户是否在保护期内 //查询客户是否在保护期内
//判断客户是否超过24小时保护期间 0:保护器内 1:超过保护期 //判断客户是否超过24小时保护期间 0:保护器内 1:超过保护期
$user_service = new UserService();
$is_outstrip_twenty_four_hours = $user_service->isUserProtect($v["user_id"]); $is_outstrip_twenty_four_hours = $user_service->isUserProtect($v["user_id"]);
$data['data']['list'][$k]['is_outstrip_twenty_four_hours'] = $is_outstrip_twenty_four_hours; $list[$k]['is_outstrip_twenty_four_hours'] = $is_outstrip_twenty_four_hours;
/* 判断当天被拨打是否超过5次,同时判断是否当前经纪人跟当前客户是否有电话绑定 start*/ /* 判断当天被拨打是否超过5次,同时判断是否当前经纪人跟当前客户是否有电话绑定 start*/
//0允许拨打 1不允许拨打 //0允许拨打 1不允许拨打
$is_outpace_call_num = 0; $is_outpace_call_num = 0;
$clientService = new ClientService();
if (!$clientService->dialTotal($v["user_id"])) { if (!$clientService->dialTotal($v["user_id"])) {
$is_outpace_call_num = 1; $is_outpace_call_num = 1;
} }
$model = new AAgents();
$result = $model->searchAgentsByKeyword("id,name,phone", [ "id" => $this->params["agent_id"]]); $phone = $m_agent->getAgentsById($this->params['agent_id'], 'phone');
//$call = new CallPhoneService();
//$result = $call->getBindNum($v['user_phone'],$result[0]['phone']);
if ($is_outpace_call_num == 1 ) { if ($is_outpace_call_num == 1 ) {
$is_privacy = $redis->get('s_is_privacy');//判断是否当前经纪人跟当前客户是否有电话绑定 从redis查询 $is_privacy = $redis->get('s_is_privacy');//判断是否当前经纪人跟当前客户是否有电话绑定 从redis查询
if (empty($result[0]['phone'])) { if (empty($phone)) {
$m_agent_phone = new AAgentsPhone(); $phone = $m_agent_phone->getAgentsByWhere(['agent_id'=>$this->userId], 'phone');
$agent_phone = $m_agent_phone->getList(1,1,'','phone', ['agent_id'=>$this->userId]);
$phone = $agent_phone[0]['phone'];
} else {
$phone = $result[0]['phone'];
} }
$call_key = 'call_'.$this->userId.'_'.$phone.'_'.$v['user_phone'].'_'.$is_privacy; $call_key = 'call_'.$this->userId.'_'.$phone.'_'.$v['user_phone'].'_'.$is_privacy;
$redis_res = $redis->get($call_key); $redis_res = $redis->get($call_key);
...@@ -153,12 +150,14 @@ class Remark extends Basic ...@@ -153,12 +150,14 @@ class Remark extends Basic
$is_outpace_call_num = 1; $is_outpace_call_num = 1;
} }
} }
$data['data']['list'][$k]['is_outpace_call_num'] = $is_outpace_call_num; $list[$k]['is_outpace_call_num'] = $is_outpace_call_num;
/* 判断当天被拨打是否超过5次,同时判断是否当前经纪人跟当前客户是否有电话绑定 end*/ /* 判断当天被拨打是否超过5次,同时判断是否当前经纪人跟当前客户是否有电话绑定 end*/
$data['data']['list'][$k]['user_phone'] = substr_replace($data['data']['list'][$k]['user_phone'], '****', 3, 4); $list[$k]['user_phone'] = substr_replace($list[$k]['user_phone'], '****', 3, 4);
$list[$k]['admin'] = $m_agent->getAgentsById($v['agent_id'], 'name');
$data[$k]['label_name'] = array_key_exists($v['labels_id']) ? $label_data[$v['labels_id']] : '';
} }
$data['data']['list'] = $list;
$data['data']['total'] = 40000; $data['data']['total'] = 40000;
return $this->response(200, '成功', $data); return $this->response(200, '成功', $data);
} }
......
...@@ -3,9 +3,18 @@ ...@@ -3,9 +3,18 @@
namespace app\model; namespace app\model;
use think\Db;
class ULabels extends BaseModel class ULabels extends BaseModel
{ {
protected $table = "u_labels";
private $db_;
public function __construct($data = [])
{
parent::__construct($data);
$this->db_ = Db::name($this->table);
}
/** /**
* @param $where * @param $where
...@@ -17,7 +26,7 @@ class ULabels extends BaseModel ...@@ -17,7 +26,7 @@ class ULabels extends BaseModel
public function uleList($where) public function uleList($where)
{ {
$r= $this->where($where)->select(); $r= $this->db_->where($where)->select();
return $r; return $r;
} }
...@@ -30,7 +39,7 @@ class ULabels extends BaseModel ...@@ -30,7 +39,7 @@ class ULabels extends BaseModel
* @throws \think\exception\DbException * @throws \think\exception\DbException
*/ */
public function repetition($name,$key){ public function repetition($name,$key){
$r=$this->field($name) $r=$this->db_->field($name)
->where($name,'=',$key) ->where($name,'=',$key)
->select(); ->select();
//$this->getLastSql(); //$this->getLastSql();
...@@ -41,9 +50,16 @@ class ULabels extends BaseModel ...@@ -41,9 +50,16 @@ class ULabels extends BaseModel
} }
} }
/**
* @param $id
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function get_labelsname($id) public function get_labelsname($id)
{ {
$u_labels = db('u_labels') $u_labels = $this->db_
->where('id',$id) ->where('id',$id)
->field('id,name') ->field('id,name')
//->limit($pagesize) //->limit($pagesize)
...@@ -52,4 +68,14 @@ class ULabels extends BaseModel ...@@ -52,4 +68,14 @@ class ULabels extends BaseModel
return $u_labels; return $u_labels;
} }
/**
* @param $field
* @param $where
* @return array
*/
public function getColumn($field, $where) {
return $this->db_->where($where)
->column($field);
}
} }
...@@ -201,45 +201,12 @@ class UPhoneFollowPp extends BaseModel ...@@ -201,45 +201,12 @@ class UPhoneFollowPp extends BaseModel
* @throws \think\exception\DbException * @throws \think\exception\DbException
*/ */
public function getFollowList($pageNo = 1, $pageSize = 15, $order_ = 'id desc', $field = '', $params = '') { public function getFollowList($pageNo = 1, $pageSize = 15, $order_ = 'id desc', $field = '', $params = '') {
$data = $this->UPhoneFollowPp->field($field) return $this->UPhoneFollowPp->field($field)
->where($params) ->where($params)
->order($order_) ->order($order_)
->limit($pageSize) ->limit($pageSize)
->page($pageNo) ->page($pageNo)
->select(); ->select();
//echo $this->getLastSql();
$m_label = new ULabels();
$m_user = new Users();
$m_agent = new AAgents();
$label_data = $m_label->field('id,name')->where('type', 1)->select();
foreach ($data as $k => $v) {
if (!empty($v['f_agent_id'])) {
$data[$k]['admin'] = $m_agent->getAgentsById($v['f_agent_id'], 'name');
}
if (!empty($v['user_id'])) {
$user_data = $m_user->getUserById('user_name,user_phone,vip,agent_id,create_time', $v['user_id']);
$data[$k]['user_name'] = $user_data['user_name'];
$data[$k]['user_phone'] = $user_data['user_phone'];
$data[$k]['u_create_time'] = $user_data['create_time'];
$data[$k]['vip'] = $user_data['vip'];
$data[$k]['agent_id'] = $user_data['agent_id']; //客户客方
}
if (!isset($v['labels_id'])) {
continue;
}
foreach ($label_data as $k2=>$v2) {
if ($v2['id'] == $v['labels_id']) {
$data[$k]['label_name'] = $v2['name'];
}
}
}
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