customer stat about

This commit is contained in:
qianhy
2023-03-31 10:43:46 +08:00
committed by lccsw
parent 372a0ed96c
commit 104f24e201
4 changed files with 553 additions and 0 deletions
+212
View File
@@ -25,6 +25,8 @@ class Customer extends HD_Controller
$this->load->model('receiver/receiver_clues_model', 'clues_model');
$this->load->model('receiver/receiver_clues_cfrom_model', 'clues_cfrom_model');
$this->load->model('receiver/receiver_xz_model');
$this->load->model('receiver/Receiver_customer_stat_plan_model', 'statplan');
$this->load->model('receiver/Receiver_customer_stat_data_model', 'statdata');
$this->load->model('app/licheb/app_licheb_users_model');
$this->load->model("biz/biz_model");
@@ -117,6 +119,116 @@ class Customer extends HD_Controller
return $this->show_view('receiver/customer/lists', true);
}
public function lists_statplan(){
$params = $this->input->get();
$page = $params['page'] = $params['page'] ? intval($params['page']) : 1;
$size = $params['size'] = $params['size'] ? intval($params['size']) : 20;
!$params['of_id'] && $params['of_id'] = '';
!$params['of2_id'] && $params['of2_id'] = '';
!$params['sp_name'] && $params['sp_name'] = '';
$where = array();
if ($params['of_id']) {
$where['of_id'] = $params['of_id'];
}
if ($params['of2_id']) {
$where['of2_id'] = $params['of2_id'];
}
if ($params['sp_name']) {
$where["sp_name like '%{$params['sp_name']}%'"] = null;
}
$count = $this->statplan->count($where);
$lists = [];
$offlineSources = $this->customers_model->offlineSources();
if ($count){
$rows = $this->statplan->select($where, 'id desc', $page, $size, '*');
foreach ($rows as $key => $val){
$of_title = '';
if ($val['of_id']) {
$of_ary = $offlineSources[$val['of_id']];
$of_title = $of_ary['name'];
$val['of2_id'] && $of_title .= '-' . $of_ary['list'][$val['of2_id']];
}
$lists[] = array(
'id' => $val['id'],
'sp_name' => $val['sp_name'],
'mobile' => $val['mobile'],
'of_title' => $of_title,
's_date' => $val['s_date'],
'e_date' => $val['e_date'],
'last_date' => $val['last_date'],
'c_time' => date('Y-m-d H:i:s', $val['c_time']),
'u_time' => $val['u_time'],
);
}
}
$show_info['offlineSourcesAry'] = $this->customers_model->offlineSources_search();
$this->data['show_info'] = $show_info;
$this->data['lists'] = $lists;
$this->data['pager'] = array('count' => ceil($count / $size), 'curr' => $page, 'totle' => $count);
$this->data['params'] = $params;
$this->data['_title'] = '客户统计计划列表';
return $this->show_view('receiver/customer/lists_statplan', true);
}
public function lists_statdata(){
$params = $this->input->get();
$id = intval($params['id']);
if (!$id) {
return $this->show_json(SYS_CODE_FAIL, '参数错误!');
}
$where = ['id' => $id];
$re = $this->statplan->get($where);
if (!$re) {
return $this->show_json(SYS_CODE_FAIL, '计划不存在!');
}
$stat_data = $this->get_statdata($id);
$indexs = $stat_data['indexs'];
$lists = $stat_data['lists'];
$this->data['indexs'] = $indexs;
$this->data['lists'] = $lists;
$this->data['params'] = $params;
$this->data['_title'] = $re['sp_name'].'_统计数据';
return $this->show_view('receiver/customer/lists_statdata', true);
}
private function get_statdata($id){
if (!$id){
return array();
}
$lists = array();
$where = ['spid' => $id];
$rows_group_id_k = $this->statdata->select_groupby('group_id,k', $where, 'group_id,k', 0, 0, 'group_id,k');
$rows_stat_date = $this->statdata->select_groupby('stat_date', $where, 'stat_date', 0, 0, 'stat_date');
$key_v = $this->statdata->map($map_key = 'k', $map_value = 'v', $where, $order = '', $page = 0, $page_size = 0, $select = "concat(group_id, '-', k, '-', stat_date) as k, v");
$indexs = ['序号', '栏目'];
$i = 1;
foreach ($rows_group_id_k as $key => $val){
$group_id = $val['group_id'];
$k = $val['k'];
$list['序号'] = $i;
$list['栏目'] = $k;
foreach ($rows_stat_date as $key_date => $val_date){
$stat_date = $val_date['stat_date'];
#$index = str_replace('-', '', substr($stat_date, 5));
$index = substr($stat_date, 5);
if (!in_array($index, $indexs)){
$indexs[] = $index;
}
$key_ = $group_id . '-' . $k . '-' . $stat_date;
$list[$index] = $key_v[$key_] ? $key_v[$key_] : 0;
}
$lists[] = $list;
$i += 1;
}
return array('indexs' => $indexs, 'lists' => $lists);
}
private function get_where(&$params)
{
!$params['biz_id'] && $params['biz_id'] = '';
@@ -415,6 +527,33 @@ class Customer extends HD_Controller
return $this->show_view('receiver/customer/get', true);
}
public function get_statplan()
{
$id = intval($this->input->get('id'));
if ($id) {
$url = "/receiver/customer/edit_statplan";
$re = $this->statplan->get(['id' => $id]);
if (!$re) {
return $this->show_json(SYS_CODE_FAIL, '计划不存在!');
}
$sp_name = $re['sp_name'];
$of_id = $re['of_id'];
$of2_id = $re['of2_id'];
$s_date = $re['s_date'];
$e_date = $re['e_date'];
$s_e_date = $s_date .' ~ '.$e_date;
} else {
$url = "/receiver/customer/edit_statplan";
$sp_name = '';
$of_id = '';
$of2_id = '';
$s_e_date = '';
}
$this->data['info'] = ['id' => $id, 'sp_name' => $sp_name, 'of_id' => $of_id, 'of2_id' => $of2_id, 's_e_date' => $s_e_date, 'url' => $url];
$this->data['show_info'] = ['offlineSourcesAry' => $this->customers_model->offlineSources()];
return $this->show_view('/receiver/customer/edit_statplan');
}
public function add()
{
// TODO: Implement add() method.
@@ -450,6 +589,54 @@ class Customer extends HD_Controller
}
}
public function edit_statplan()
{
$params = $this->input->post()['info'];
$id = intval($params['id']);
if (!$params['sp_name']) {
return $this->show_json(SYS_CODE_FAIL, '计划名不能为空!');
}
if (!$params['of_id']) {
return $this->show_json(SYS_CODE_FAIL, '来源1不能为空!');
}
if (!$params['of2_id']) {
return $this->show_json(SYS_CODE_FAIL, '来源2不能为空!');
}
if (!$params['s_e_date']) {
return $this->show_json(SYS_CODE_FAIL, '起止日期不能为空!');
}
$s_e_date = explode(' ~ ', $params['s_e_date']);
$s_date = $s_e_date[0];
$e_date = $s_e_date[1] ;
if (!$s_date){
return $this->show_json(SYS_CODE_FAIL, '开始日期不能为空!');
}
if (!$e_date){
return $this->show_json(SYS_CODE_FAIL, '结束日期不能为空!');
}
$data = [
'sp_name' => $params['sp_name'],
'of_id' => $params['of_id'],
'of2_id' => $params['of2_id'],
's_date' => $s_date,
'e_date' => $e_date,
];
if (!$id){
$data['c_time'] = time();
$res = $this->statplan->add($data);
}
else{
$res = $this->statplan->update($data, array('id' => $id));
}
if (!$res) {
return $this->show_json(SYS_CODE_FAIL, '保存失败');
}
return $this->show_json(SYS_CODE_SUCCESS, '保存成功');
}
/**
* 编辑
* @return bool
@@ -675,6 +862,31 @@ class Customer extends HD_Controller
$this->excel->out_csv($data, $indexs, $fileName . "_" . date('YmdHis'));
}
public function export_statdata(){
$params = $this->input->get();
$id = intval($params['id']);
if (!$id) {
return $this->show_json(SYS_CODE_FAIL, '参数错误!');
}
$where = ['id' => $id];
$re = $this->statplan->get($where);
if (!$re) {
return $this->show_json(SYS_CODE_FAIL, '计划不存在!');
}
$stat_data = $this->get_statdata($id);
$indexs = array();
foreach ($stat_data['indexs'] as $index){
$indexs[$index] = $index;
}
$data = $stat_data['lists'];
$fileName = $re['sp_name'].'_统计数据';
array_unshift($data, $indexs);
$this->load->library('excel');
$this->excel->out_csv($data, $indexs, $fileName . "_" . date('YmdHis'));
}
//改派
public function edit_adviser()
{
@@ -0,0 +1,158 @@
<form id="vue-edit" class="am-form am-form-horizontal" :action="info.url" data-auto="true" method="post" style="width: 90%;padding-top: 10px" onsubmit="return false">
<div class="am-form am-form-horizontal">
<input type="hidden" name="id" v-model="info.id"/>
<div class="am-form-group" style="margin-bottom: 0px;"></div>
<div class="am-form-group fl">
<label class="am-para-label w100">计划名:</label>
<div class="am-para-inline w300">
<input type="text" placeholder="输入计划名" name="sp_name" v-model="info.sp_name"/>
</div>
</div>
<div class="am-form-group" style="margin-bottom: 0px;"></div>
<div class="am-form-group fl">
<label class="am-para-label w100">客户来源:</label>
<div class="am-form-group am-para-inline w120">
<select name="of_id" v-model="info.of_id">
<option value="">请选择</option>
<option :value="i" v-for="(v,i) in show_info.offlineSourcesAry">{{v.name}}</option>
</select>
</div>
<div class="am-form-group am-para-inline w120">
<select name="of2_id" v-model="info.of2_id">
<option value="">请选择</option>
<option :value="i" v-for="(v,i) in of2Ary">{{v}}</option>
</select>
</div>
</div>
<div class="am-form-group" style="margin-bottom: 0px;"></div>
<div class="am-form-group fl">
<label class="am-para-label w100">起止日期:</label>
<div class="am-form-group fl">
<div class="am-para-inline w250">
<input id="id-s_e_date" name="s_e_date" type="text" v-model="info.s_e_date"
placeholder="起止日期范围" autocomplete="off"/>
</div>
<div class="am-para-inline" style="padding-top: 5px;">
<!-- <a class="mr10 id-day-btn" href="javascript:void (0);" data-date="today" data-btn="s_e">今天</a>-->
<!-- <a class="mr10 id-day-btn" href="javascript:void (0);" data-date="yesterday" data-btn="s_e">昨日</a>-->
<a class="mr10 id-day-btn" href="javascript:void (0);" data-date="weeks" data-btn="s_e">本周</a>
<a class="mr10 id-day-btn" href="javascript:void (0);" data-date="month" data-btn="s_e">本月</a>
</div>
</div>
</div>
<div class="am-form-group" style="margin-bottom: 0px;"></div>
<div class="am-form-group" style="margin-bottom: 2rem">
<label class="am-para-label w150"></label>
<button class="am-btn ml20 am-btn-sm am-btn-success w100" type="button" @click="saveEdit">保存</button>
</div>
</div>
</form>
<script>
var vue_obj;
$(function () {
vue_obj = new Vue({
el: '#vue-edit',
data: {
info: [],
show_info: {offlineSourcesAry: []},
of2Ary: [],
},
mounted: function () {
var vm = this;
vm.info = <?=json_encode($info)?>;
vm.show_info = <?=json_encode($show_info)?>;
},
methods: {
saveEdit: function () {
var vm = this;
vm.info.s_e_date = $('#id-s_e_date').val();
$.ajax({
url: vm.info.url,
type: 'post',
dataType: 'json',
data: {
info: vm.info,
},
beforeSend: function () {
layer.load(1, {
shade: [0.1, '#fff'] //0.1透明度的白色背景
});
},
success: function (data) {
if (data['code']) {
layer.msg(data.msg, {
icon: 1,
time: 2000
}, function () {
if (data.url != '') {
$.form.href(data.url);
} else {
// $.form.reload();
window.location.reload();
}
});
} else {
layer.msg(data.msg, {icon: 2});
}
},
complete: function () {
layer.closeAll('loading');
}
});
}
},
watch: {
'info.of_id': function (nv, ov) {
var that = this;
if (nv == '') {
that.info.of2_id = '';
that.of2Ary = [];
} else {
that.of2Ary = that.show_info.offlineSourcesAry[nv]['list'];
}
},
}
});
});
</script>
<script>
require(['laydate', 'autocomplete'], function (laydate) {
laydate.render({
elem: '#id-s_e_date', range: '~'
});
$('.id-day-btn').click(function () {
var type = $(this).data('date'), nowDate = new Date();
var beginDate = '', endDate = '';
switch (type) {
case 'today':
endDate = beginDate = nowDate.Format('yyyy-MM-dd');
break;
case 'yesterday':
endDate = beginDate = (new Date(nowDate.getTime() - 86400000)).Format('yyyy-MM-dd');
break;
case 'weeks':
nowDate.setDate(nowDate.getDate() - nowDate.getDay() + 1);
beginDate = nowDate.getFullYear() + "-" + (nowDate.getMonth() + 1) + "-" + nowDate.getDate();
nowDate.setDate(nowDate.getDate() + 6);
endDate = nowDate.getFullYear() + "-" + (nowDate.getMonth() + 1) + "-" + nowDate.getDate();
break;
case 'month':
beginDate = nowDate.getFullYear() + "-" + (nowDate.getMonth() + 1) + "-01";
var day = new Date(nowDate.getFullYear(), nowDate.getMonth() + 1, 0);
endDate = nowDate.getFullYear() + "-" + (nowDate.getMonth() + 1) + "-" + day.getDate();
break;
}
date = beginDate + ' ~ ' + endDate;
switch ($(this).data('btn')) {
case 's_e':
$('#id-s_e_date').val(date);
break;
}
});
});
</script>
@@ -0,0 +1,62 @@
<link rel="stylesheet" type="text/css" href="/static/css/font-awesome.min.css?v=1581252500">
<div class="coms-table-wrap mt10">
<div class="am-form am-form-horizontal">
<div class="am-form-group fr" style="margin-bottom: 0px;">
<div class="am-form-group fl ml10">
<button type="button" class="am-btn am-btn-success am-btn-sm w100" @click="export_out">导出</button>
</div>
</div>
</div>
<div class="coms-table-bd">
<table class="am-table am-table-bordered">
<thead>
<tr>
<template v-for="(index) in indexs">
<th v-if="index=='序号'" width="50px">{{index}}</th>
<th v-else>{{index}}</th>
</template>
</tr>
</thead>
<tbody>
<template v-for="(list) in lists">
<tr>
<template v-for="(v, i) in list">
<td v-if="i=='序号'">{{v}}</td>
<td v-else-if="i=='栏目'" style="text-align: left" v-html="v"></td>
<td v-else style="text-align: right">{{v}}</td>
</template>
</tr>
</template>
</table>
</div>
</div>
<script>
var vue_obj;
$(function () {
vue_obj = new Vue({
el: '.coms-table-wrap',
data: {
params: {},
indexs: [],
lists: [],
},
mounted: function () {
var vm = this;
vm.params = <?=json_encode($params)?>;
vm.indexs = <?=json_encode($indexs)?>;
vm.lists = <?=json_encode($lists)?>;
},
methods: {
export_out: function () {
let href = $.menu.parseUri(window.location.href);
href = href.replace("customer/lists_statdata?", "customer/export_statdata?");
window.location.href = href;
},
},
watch: {
}
});
});
</script>
@@ -0,0 +1,121 @@
<link rel="stylesheet" type="text/css" href="/static/css/font-awesome.min.css?v=1581252500">
<div class="coms-table-wrap mt10">
<form id="vue-app" class="form-search coms-table-hd clearfix no-border" onsubmit="return false" action="/receiver/customer/lists_statplan">
<div class="am-form am-form-horizontal">
<div class="am-form-group fl">
<label class="am-para-label w80">计划名:</label>
<div class="am-para-inline w220">
<input id="sp_name" name="sp_name" type="text" v-model="params.sp_name"/>
</div>
</div>
<div class="am-form-group fl">
<label class="am-para-label w80">客户来源:</label>
<div class="am-form-group am-para-inline w120">
<select name="of_id" v-model="params.of_id">
<option value="">请选择</option>
<option :value="i" v-for="(v,i) in show_info.offlineSourcesAry">{{v.name}}</option>
</select>
</div>
<div class="am-form-group am-para-inline w120">
<select name="of2_id" v-model="params.of2_id">
<option value="">请选择</option>
<option :value="i" v-for="(v,i) in of2Ary">{{v}}</option>
</select>
</div>
</div>
<div class="am-form-group" style="margin-bottom: 0px;"></div>
<div class="am-form-group fl" style="margin-bottom: 0px;">
<div class="am-form-group fl ml10">
<button type="submit" class="am-btn am-btn-success am-btn-sm w100">搜索</button>
</div>
<div class="am-form-group fl ml10">
<button type="button" class="am-btn am-btn-success am-btn-sm w100"
data-modal="/receiver/customer/get_statplan?id=0" data-title="新增客户统计计划">新增
</button>
</div>
</div>
</div>
</form>
<div class="coms-table-bd">
<div class="am-form-group fr mr10">
<span><?= intval($pager['totle']) ?>条&nbsp;&nbsp;&nbsp;</span>
</div>
<table class="am-table am-table-bordered">
<thead>
<tr>
<th width="5%">ID</th>
<th width="30%"><span>计划名</span></th>
<th width="15%"><span>客户来源</span></th>
<th width="15%"><span>起止时间</span></th>
<th width="10%"><span>最近执行日期</span></th>
<th width="15%"><span>最后更新时间</span></th>
<th width="15%"><span>操作</span></th>
</tr>
</thead>
<tbody>
<template v-for="(v,i) in lists">
<tr>
<td>{{v.id}}</td>
<td>{{v.sp_name}}</td>
<td>{{v.of_title}}</td>
<td>{{v.s_date}} ~ {{v.e_date}}</td>
<td>{{v.last_date}}</td>
<td>{{v.u_time}}</td>
<td>
<a :data-modal="'/receiver/customer/get_statplan?id='+v.id+'&type=customer'"
href="javascript:void(0);" class="am-btn am-btn-primary am-btn-xs"
:data-title="'编辑 '+v.sp_name">编辑</a>
<a href="javascript:void(0);" :data-open="'/receiver/customer/lists_statdata?id='+v.id"
class="am-btn am-btn-primary am-btn-xs">查看数据</a>
</td>
</tr>
</template>
</table>
</div>
<div class="coms-table-ft clearfix">
<div class="hander am-form">
</div>
<div class="coms-pagination fr mr20">
<?php page_view($pager) ?>
</div>
</div>
</div>
<script>
var vue_obj;
$(function () {
vue_obj = new Vue({
el: '.coms-table-wrap',
data: {
params: {'of_id': '', 'of2_id': '', 'sp_name': ''},
lists: [],
show_info: {offlineSourcesAry: []},
of2Ary: [],
},
mounted: function () {
var vm = this;
vm.params = <?=json_encode($params)?>;
vm.lists = <?=json_encode($lists)?>;
vm.show_info = <?=json_encode($show_info)?>;
},
methods: {
},
watch: {
'params.of_id': function (nv, ov) {
var that = this;
if (nv == '') {
that.params.of2_id = '';
that.of2Ary = [];
} else {
that.of2Ary = that.show_info.offlineSourcesAry[nv]['list'];
}
},
}
});
<?php page_script($pager) ?>
});
</script>