203 lines
8.4 KiB
PHP
203 lines
8.4 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
/**
|
|
* Notes:狸车宝顾问_日志
|
|
* Created on: 2022/4/15 16:43
|
|
* Created by: dengbw
|
|
*/
|
|
class Userslog extends HD_Controller
|
|
{
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('app/licheb/app_licheb_users_model', 'mdUsers');
|
|
$this->load->model('app/licheb/app_licheb_users_log_model', 'mdUsersLog');
|
|
$this->load->model('receiver/receiver_customers_model', 'mdCustomers');
|
|
$this->load->model("biz/biz_model", 'mdBiz');
|
|
$this->load->model('area_model', 'mdArea');
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
return $this->lists();
|
|
}
|
|
|
|
public function lists()
|
|
{
|
|
$params = $this->input->get();
|
|
$params['page'] = $params['page'] ? intval($params['page']) : 1;
|
|
$params['size'] = $params['size'] ? intval($params['size']) : 20;
|
|
$data = $this->dataSelect($params);
|
|
$data['typeAry'] = $this->mdBiz->type_ary();
|
|
$this->data = $data;
|
|
$this->show_view('app/licheb/userslog/lists', true);
|
|
}
|
|
|
|
private function dataSelect($params)
|
|
{
|
|
$lists = $where = [];
|
|
if ($params['uname']) {
|
|
$where["sale_id in(select id from lc_app_licheb_users where uname like '%{$params['uname']}%')"] = null;
|
|
}
|
|
if ($params['biz_id']) {
|
|
$where['biz_id'] = $params['biz_id'];
|
|
} else if ($params['city_id']) {
|
|
$where_biz['status'] = 1;
|
|
$params['city_id'] && $where_biz['city_id'] = $params['city_id'];
|
|
$params['county_id'] && $where_biz['county_id'] = $params['county_id'];
|
|
$res_biz = $this->mdBiz->select($where_biz, 'id desc', 0, 0, 'id');
|
|
if ($res_biz) {
|
|
$str_ids = implode(',', array_column($res_biz, 'id'));
|
|
$where["biz_id in ({$str_ids})"] = null;
|
|
} else {
|
|
$where['biz_id'] = -2;
|
|
}
|
|
} else {
|
|
$params['city_id'] = '';
|
|
$params['county_id'] = '';
|
|
$params['biz_id'] = '';
|
|
}
|
|
if ($params['type']) {
|
|
$where["type"] = $params['type'];
|
|
} else {
|
|
$params['type'] = '';
|
|
}
|
|
if ($params['time']) {
|
|
$time = explode(' ~ ', $params['time']);
|
|
$time[0] && $where["log_date>="] = $time[0];
|
|
$time[1] && $where["log_date<="] = $time[1];
|
|
}
|
|
$total = $this->mdUsersLog->count($where);
|
|
if ($total) {
|
|
$res = $this->mdUsersLog->select($where, "id desc", $params['page'], $params['size']);
|
|
$sale_ids = $biz_ids = [];
|
|
foreach ($res as $v) {
|
|
$v['sale_id'] && !in_array($v['sale_id'], $sale_ids) && $sale_ids[] = $v['sale_id'];
|
|
$v['biz_id'] && !in_array($v['biz_id'], $biz_ids) && $biz_ids[] = $v['biz_id'];
|
|
}
|
|
$map_sale = $map_biz = $map_city = [];
|
|
if ($sale_ids) {
|
|
$str_ids = implode(',', $sale_ids);
|
|
$map_sale = $this->mdUsers->map('id', 'uname', ["id in ({$str_ids})" => null]);
|
|
}
|
|
if ($biz_ids) {
|
|
$str_ids = implode(',', $biz_ids);
|
|
$map_biz = $this->mdBiz->map('id', 'biz_name,type', ["id in ({$str_ids})" => null]);
|
|
}
|
|
$offlineSources = $this->mdCustomers->offlineSources();
|
|
$typeAry = $this->mdBiz->type_ary();
|
|
foreach ($res as $v) {
|
|
$uname = $biz_name = $biz_type = $customers_info = '';
|
|
$customers = 0;
|
|
$map_sale[$v['sale_id']] && $uname = $map_sale[$v['sale_id']];
|
|
$map_biz[$v['biz_id']]['biz_name'] && $biz_name = $map_biz[$v['biz_id']]['biz_name'];
|
|
$map_biz[$v['biz_id']]['type'] && $biz_type = $typeAry[$map_biz[$v['biz_id']]['type']];
|
|
$temp = ['uname' => $uname, 'biz_type' => $biz_type, 'biz_name' => $biz_name, 'defeats' => $v['defeats']
|
|
, 'a_num' => $v['a_num'], 'orders' => $v['orders'], 'bills' => $v['bills'], 'follows' => $v['follows']
|
|
, 'qy_adds' => $v['qy_adds'], 'qy_dels' => $v['qy_dels'], 'log_date' => $v['log_date']];
|
|
$customer_json = $v['customer_json'] ? json_decode($v['customer_json'], true) : [];
|
|
foreach ($offlineSources as $key1 => $value1) {
|
|
$nums = intval($v['customer_' . $key1]);
|
|
if ($params['size'] == 10000) {//导出使用
|
|
$temp['customer_' . $key1] = $nums;
|
|
foreach ($value1['list'] as $key2 => $value2) {
|
|
$temp['customer_' . $key2] = intval($customer_json[$key1]['list'][$key2]['num']);
|
|
}
|
|
}
|
|
if ($nums) {
|
|
$customers += $nums;
|
|
if ($params['size'] != 10000) {
|
|
if ($customers_info) {
|
|
$customers_info = $customers_info . '+' . $value1['name'] . '(' . $nums . ')';
|
|
} else {
|
|
$customers_info = $value1['name'] . '(' . $nums . ')';
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$customers_info && $customers = $customers . '=' . $customers_info;
|
|
$temp['customers'] = $customers;
|
|
$lists[] = $temp;
|
|
}
|
|
}
|
|
if ($params['size'] != 10000) {
|
|
$sum = $this->mdUsersLog->sum('customers', $where);
|
|
$menus[] = ['title' => "客户数", 'value' => $sum['customers'], 'tag' => '人'];
|
|
$sum = $this->mdUsersLog->sum('a_num', $where);
|
|
$menus[] = ['title' => "进店数", 'value' => $sum['a_num'], 'tag' => '人'];
|
|
$sum = $this->mdUsersLog->sum('follows', $where);
|
|
$menus[] = ['title' => "跟进数", 'value' => $sum['follows'], 'tag' => '个'];
|
|
$sum = $this->mdUsersLog->sum('orders', $where);
|
|
$menus[] = ['title' => "订单数", 'value' => $sum['orders'], 'tag' => '个'];
|
|
$sum = $this->mdUsersLog->sum('defeats', $where);
|
|
$menus[] = ['title' => "战败数", 'value' => $sum['defeats'], 'tag' => '个'];
|
|
$sum = $this->mdUsersLog->sum('bills', $where);
|
|
$menus[] = ['title' => "开票数", 'value' => $sum['bills'], 'tag' => '个'];
|
|
$sum = $this->mdUsersLog->sum('qy_adds', $where);
|
|
$menus[] = ['title' => "新增企微", 'value' => $sum['qy_adds'], 'tag' => '人'];
|
|
$sum = $this->mdUsersLog->sum('qy_dels', $where);
|
|
$menus[] = ['title' => "删除企微", 'value' => $sum['qy_dels'], 'tag' => '人'];
|
|
$data['menus'] = $menus;
|
|
}
|
|
$data['pager'] = array('count' => ceil($total / $params['size']), 'curr' => $params['page'], 'totle' => $total);
|
|
$data['lists'] = $lists;
|
|
$data['params'] = $params;
|
|
$data['_title'] = "顾问日志";
|
|
return $data;
|
|
}
|
|
|
|
public function get()
|
|
{
|
|
}
|
|
|
|
public function add()
|
|
{
|
|
}
|
|
|
|
public function edit()
|
|
{
|
|
}
|
|
|
|
public function del()
|
|
{
|
|
}
|
|
|
|
|
|
public function batch()
|
|
{
|
|
}
|
|
|
|
public function export()
|
|
{
|
|
$params = $this->input->get();
|
|
$params['page'] = 1;
|
|
$params['size'] = 10000;
|
|
$data = $indexs = array();
|
|
$res = $this->dataSelect($params);
|
|
$fileName = $res['_title'];
|
|
$offlineSources = $this->mdCustomers->offlineSources();
|
|
foreach ($res['lists'] as $key => $value) {
|
|
$data[] = $value;
|
|
}
|
|
$indexs = ['biz_name' => '门店', 'uname' => '顾问', 'customers' => '客户数'];
|
|
foreach ($offlineSources as $key1 => $value1) {
|
|
$indexs['customer_' . $key1] = '【' . $value1['name'] . '】';
|
|
foreach ($value1['list'] as $key2 => $value2) {
|
|
$indexs['customer_' . $key2] = $value2;
|
|
}
|
|
}
|
|
$indexs['a_num'] = '进店数';
|
|
$indexs['follows'] = '跟进数';
|
|
$indexs['orders'] = '订单数';
|
|
$indexs['defeats'] = '战败数';
|
|
$indexs['bills'] = '开票数';
|
|
$indexs['qy_adds'] = '新增企微';
|
|
$indexs['qy_dels'] = '删除企微';
|
|
$indexs['log_date'] = '日期';
|
|
array_unshift($data, $indexs);
|
|
$this->load->library('excel');
|
|
$this->excel->out_csv($data, $indexs, $fileName . "_" . date('YmdHis'));
|
|
}
|
|
} |