Commit 898c56fe authored by hujun's avatar hujun

后台客户跟进列表优化

parent fe71d891
......@@ -35,73 +35,76 @@ class Remark extends Basic
$data['status'] = 200;
$data['msg'] = '';
$where_user = $agent_where = [];
$pageNo = empty($this->params['pageNo']) ? 1 : $this->params['pageNo'];
$pageSize = empty($this->params['pageSize']) ? 15 : $this->params['pageSize'];
$u_phone_follow = new UPhoneFollowPp();
if (!empty($this->params['start_date']) && empty($this->params['end_date'])) {
$where['a.create_time'] = ['> time', $this->params['start_date']. ' 00:00:00'];
$where['create_time'] = ['> time', $this->params['start_date']. ' 00:00:00'];
}
if (!empty($this->params['end_date']) && empty($this->params['start_date'])) {
$where['a.create_time'] = ['< time', $this->params['end_date']. ' 23:59:59'];;
$where['create_time'] = ['< time', $this->params['end_date']. ' 23:59:59'];;
}
if (!empty($this->params['end_date']) && !empty($this->params['start_date'])) {
$where['a.create_time'] = ['between',[$this->params['start_date'].' 00:00:00',$this->params['end_date']. ' 23:59:59']];
}
if (!empty($this->params['customer'])) {
$where['c.user_name'] = $this->params['customer'];
}
if (!empty($this->params['phone'])) {
$where['c.user_phone'] = $this->params['phone'];
$where['create_time'] = ['between',[$this->params['start_date'].' 00:00:00',$this->params['end_date']. ' 23:59:59']];
}
if (!empty($this->params['content'])) {
$where['a.content'] = ['like',"%{$this->params['content']}%"];
$where['content'] = ['LIKE',"%{$this->params['content']}%"];
}
//跟进人名字
if (!empty($this->params['remark_name'])) {
$where['b.name'] = ['like', "%{$this->params['remark_name']}%"];
$agent_where['name'] = $this->params['remark_name'];
}
//跟进人手机号
if (!empty($this->params['remark_phone'])) {
$where['b.phone'] = ['like', "%{$this->params['remark_phone']}%"];
$agent_where['phone'] = $this->params['remark_phone'];
}
//跟进人门店
if (!empty($this->params['remark_store_id'])) {
$where['b.store_id'] = $this->params['remark_store_id'];
$agent_where['store_id'] = $this->params['remark_store_id'];
}
//跟进人部门
if (!empty($this->params['remark_district_id'])) {
$where['b.district_id'] = $this->params['remark_district_id'];
$agent_where['district_id'] = $this->params['remark_district_id'];
}
if (!empty($this->params['province'])) {
$where['c.province'] = $this->params['province'];
$where['province'] = $this->params['province'];
}
if (!empty($this->params['city'])) {
$where['c.city'] = $this->params['city'];
$where['city'] = $this->params['city'];
}
if (!empty($this->params['disc'])) {
$where['c.disc'] = $this->params['disc'];
$where['disc'] = $this->params['disc'];
}
$field = 'c.id,a.create_time,a.content,b.name as admin,d.name as label_name,c.user_name,c.user_phone,a.user_status';
$data['data']['list'] = $u_phone_follow->getFollowList($pageNo, $pageSize, $order_ = 'a.id desc', $field, $where);
if (!empty($this->params['id'])) {
$where['user_id'] = $this->params['id'];
}
if (!empty($where_user)) {
$m_agent = new AAgents();
$agent_id_arr = $m_agent->getAgentById('id', $agent_where);
if (!empty($agent_id_arr)) {
$where['agent_id'] = ['in', $agent_id_arr];
}
}
$field = '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);
foreach ($data['data']['list'] as $k=>$v) {
$data['data']['list'][$k]['user_phone'] = hide_customer_phone($data['data']['list'][$k]['user_phone']);
$data['data']['list'][$k]['user_phone'] = substr_replace($data['data']['list'][$k]['user_phone'],'****',3,4);
}
$data['data']['total'] = $u_phone_follow->getFollowTotal($where);
......
......@@ -254,16 +254,41 @@ class UPhoneFollowPp extends BaseModel
* @throws \think\exception\DbException
*/
public function getFollowList($pageNo = 1, $pageSize = 15, $order_ = 'id desc', $field = '', $params = '') {
return $this->field($field)
->alias('a')
->join('a_agents b','a.agent_id = b.id', 'left')
->join('u_users c','a.user_id = c.id', 'left')
->join('u_labels d','d.id = a.labels_id', 'left')
$data = $this->field($field)
->where($params)
->order($order_)
->limit($pageSize)
->page($pageNo)
->select();
$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['agent_id'])) {
$data[$k]['admin'] = $m_agent->getAgentsById($v['agent_id'], 'name');
}
if (!empty($v['user_id'])) {
$user_data = $m_user->getUserById('user_name,user_phone', $v['user_id']);
$data[$k]['user_name'] = $user_data['user_name'];
$data[$k]['user_phone'] = $user_data['user_phone'];
}
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;
}
/**
......@@ -274,10 +299,7 @@ class UPhoneFollowPp extends BaseModel
*/
public function getFollowTotal($params)
{
return $this->alias('a')
->join('a_agents b','a.agent_id = b.id', 'left')
->join('u_users c','a.user_id = c.id', 'left')
->where($params)
return $this->where($params)
->count();
}
......
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