customer statplan add data_log query

This commit is contained in:
qianhy
2023-04-20 10:19:33 +08:00
parent 22cefd9289
commit 12dd080bf0
3 changed files with 331 additions and 1 deletions
+181
View File
@@ -27,6 +27,7 @@ class Customer extends HD_Controller
$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('receiver/Receiver_customer_stat_data_log_model', 'statdatalog');
$this->load->model('app/licheb/app_licheb_users_model');
$this->load->model("biz/biz_model");
@@ -195,6 +196,45 @@ class Customer extends HD_Controller
return $this->show_view('receiver/customer/lists_statdata', true);
}
public function lists_statdatalog(){
$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, '计划不存在!');
}
!$params['city_id'] && $params['city_id'] = '';
!$params['biz_id'] && $params['biz_id'] = '';
$where = array('spid'=>$id);
$rows_city = $this->statdatalog->select_groupby('city_id', $where, 'city_id', 0, 0, 'city_id, city_name');
$maps_city = $this->statdatalog->map($map_key = 'city_id', $map_value = '', $where, $order = 'city_id, biz_id', $page = 0, $page_size = 0, $select = "distinct city_id, biz_id, biz_name");
$city_biz_ary = array();
foreach ($rows_city as $item){
$list = array();
foreach ($maps_city[$item['city_id']] as $k => $v){
$list[$v['biz_id']] = $v['biz_name'];
}
$city_biz_ary[$item['city_id']] = array('name'=>$item['city_name'], 'list' => $list);
}
$stat_data = $this->get_statdatalog($params);
$indexs = $stat_data['indexs'];
$lists = $stat_data['lists'];
$this->data['indexs'] = $indexs;
$this->data['lists'] = $lists;
$this->data['city_biz_ary'] = $city_biz_ary;
$this->data['params'] = $params;
$this->data['_title'] = $re['sp_name'].'_统计数据';
return $this->show_view('receiver/customer/lists_statdatalog', true);
}
private function get_statdata($id, $export=false){
if (!$id){
return array();
@@ -229,6 +269,122 @@ class Customer extends HD_Controller
return array('indexs' => $indexs, 'lists' => $lists);
}
private function get_statdatalog($params, $export=false){
$id = $params['id'];
if (!$id){
return array();
}
$where = ['spid' => $id];
$where_s = "spid = {$id} ";
$city_id = $params['city_id'];
$city_id && $where_s .= " and city_id = {$city_id} ";
$biz_id = $params['biz_id'];
$biz_id && $where_s .= " and biz_id = {$biz_id} ";
if ($params['stat_date']) {
$stat_date = explode(' ~ ', $params['stat_date']);
if ($stat_date[0]) {
$where_s .= " and stat_date >= '{$stat_date[0]}' ";
}
if ($stat_date[1]) {
$where_s .= " and stat_date <= '{$stat_date[1]}' ";
}
}
$sql = "
select * from (
select 1 as group_id, stat_date, '<b>总数</b>' as k, count(distinct c_id) as v from lc_receiver_customers_stat_data_log where spid = 1 and o_id is null group by stat_date
union all
select 3 as group_id, stat_date, city_name as k, count(distinct c_id) as v from lc_receiver_customers_stat_data_log where spid = 1 and o_id is null group by stat_date, k
union all
select biz_id * 10 as group_id, stat_date, if(biz_id,concat('<b>',biz_name,'</b>'),'<b>未分配门店</b>') as k, count(distinct c_id) as v from lc_receiver_customers_stat_data_log where spid = 1 and o_id is null group by stat_date, k
union all
select (biz_id * 10 + 1) as group_id, stat_date, if(admin_id,concat(' - ',biz_name,'-', admin_name), ' - 未分配') as k, count(distinct c_id) as v from lc_receiver_customers_stat_data_log where spid = 1 and o_id is null group by stat_date, k
union all
select 10007 as group_id, stat_date, '<b>战败</b>' as k, count(distinct c_id) as v from lc_receiver_customers_stat_data_log where spid = 1 and o_id is null and status = 3 group by stat_date
union all
select 10008 as group_id, stat_date, '<b>战败-无购车意向</b>' as k, count(distinct c_id) as v from lc_receiver_customers_stat_data_log where spid = 1 and o_id is null and status = 3 and tag_id_1_1 is not null group by stat_date
union all
select 10009 as group_id, stat_date, concat(' - 战败-无购车意向-', tag_id_1_1_name) as k, count(distinct c_id) as v from lc_receiver_customers_stat_data_log where spid = 1 and o_id is null and status = 3 and tag_id_1_1 is not null group by stat_date, k
union all
select 10020 as group_id, stat_date, '<b>战败-有购车意向</b>' as k, count(distinct c_id) as v from lc_receiver_customers_stat_data_log where spid = 1 and o_id is null and status = 3 and tag_id_1_2 is not null group by stat_date
union all
select 10021 as group_id, stat_date, concat(' - 战败-有购车意向-', tag_id_1_2_name) as k, count(distinct c_id) as v from lc_receiver_customers_stat_data_log where spid = 1 and o_id is null and status = 3 and tag_id_1_2 is not null group by stat_date, k
union all
select 10030 as group_id, stat_date, '<b>加V(扣除 战败-无购车意向)</b>' as k, count(distinct c_id) as v from lc_receiver_customers_stat_data_log where spid = 1 and o_id is null and (tag_id_1_1 is null or tag_id_1_1 is not null and status <> 3) and wxgr = 1 group by stat_date
union all
select 10040 as group_id, stat_date, '<b>未见客户的见面意向</b>' as k, count(distinct c_id) as v from lc_receiver_customers_stat_data_log where spid = 1 and o_id is null and status = 0 and tag_id_2_1 is not null group by stat_date
union all
select 10041 as group_id, stat_date, concat(' - 未见客户的见面意向','-', tag_id_2_1_name) as k, count(distinct c_id) as v from lc_receiver_customers_stat_data_log where spid = 1 and o_id is null and status = 0 and tag_id_2_1 is not null group by stat_date, k
union all
select 10050 as group_id, stat_date, '<b>到店客户的购车意向</b>' as k, count(distinct c_id) as v from lc_receiver_customers_stat_data_log where spid = 1 and o_id is null and status = 1 and tag_id_2_2 is not null group by stat_date
union all
select 10051 as group_id, stat_date, concat(' - 到店客户的购车意向','-', tag_id_2_2_name) as k, count(distinct c_id) as v from lc_receiver_customers_stat_data_log where spid = 1 and o_id is null and status = 1 and tag_id_2_2 is not null group by stat_date, k
union all
select 10060 as group_id, stat_date, '<b>订单数</b>' as k, count(*) as v from lc_receiver_customers_stat_data_log where spid = 1 and o_id is not null group by stat_date
union all
select 10061 as group_id, stat_date, concat(' - 订单数','-',brand_name,' ', s_name) as k, count(*) as v from lc_receiver_customers_stat_data_log where spid = 1 and o_id is not null group by stat_date, k
union all
select 10090 as group_id, stat_date, '<b>加企微</b>' as k, count(distinct c_id) as v from lc_receiver_customers_stat_data_log where spid = 1 and o_id is null and wxqy = 1 group by stat_date
) t
order by group_id, stat_date, k
";
$sql = str_replace('spid = 1', $where_s, $sql);
$rows = $this->statdatalog->db->query($sql)->result_array();
if (!$rows){
return array();
}
$rows_gk = array();
$rows_group_id_k = array();
$rows_stat_date = array();
$key_v = array();
foreach ($rows as $row){
$group_id = $row['group_id'];
$k = $row['k'];
$stat_date = $row['stat_date'];
$v = $row['v'];
$group_id_k = $group_id . '-' . $k;
if (!in_array($group_id_k, $rows_gk)){
$rows_gk[] = $group_id_k;
$rows_group_id_k[] = array('group_id' => $group_id, 'k' => $k );
}
if (!in_array($stat_date, $rows_stat_date)){
$rows_stat_date[] = $stat_date;
}
$key_ = $group_id . '-' . $k . '-' . $stat_date;
$key_v[$key_] = $v;
}
$lists = array();
$indexs = ['序号', '栏目'];
$i = 1;
foreach ($rows_group_id_k as $key => $val){
$group_id = $val['group_id'];
$k = $val['k'];
$list['序号'] = $i;
$list['栏目'] = $export ? str_replace('</b>', '', str_replace('<b>', '', $k)) : $k;
foreach ($rows_stat_date as $key_date => $val_date){
$stat_date = $val_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'] = '';
@@ -901,6 +1057,31 @@ class Customer extends HD_Controller
$this->excel->out_csv($data, $indexs, $fileName . "_" . date('YmdHis'));
}
public function export_statdatalog(){
$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_statdatalog($params, $export=true);
$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,147 @@
<link rel="stylesheet" type="text/css" href="/static/css/font-awesome.min.css?v=1581252500">
<div class="coms-table-wrap mt10">
<form class=" form-search coms-table-hd clearfix no-border" onsubmit="return false" action="/receiver/customer/lists_statdatalog">
<input type="hidden" id="id" name="id" v-model="params.id">
<div class="am-form am-form-horizontal">
<div class="am-form-group fl">
<label class="am-para-label w100">城市-门店:</label>
<div class="am-form-group am-para-inline w100">
<select name="city_id" v-model="params.city_id">
<option value="">请选择</option>
<option :value="i" v-for="(v,i) in city_biz_ary">{{v.name}}</option>
</select>
</div>
<div class="am-form-group am-para-inline w100">
<select name="biz_id" v-model="params.biz_id">
<option value="">请选择</option>
<option :value="i" v-for="(v,i) in biz_ary">{{v}}</option>
</select>
</div>
</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 w230">
<input id="id-stat_date" name="stat_date" type="text" value="<?= $params['stat_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="stat_date">今天</a>
<a class="mr10 id-day-btn" href="javascript:void (0);" data-date="yesterday" data-btn="stat_date">昨日</a>
<a class="mr10 id-day-btn" href="javascript:void (0);" data-date="weeks" data-btn="stat_date">本周</a>
<a class="mr10 id-day-btn" href="javascript:void (0);" data-date="month" data-btn="stat_date">本月</a>
</div>
</div>
</div>
<div class="am-form-group fr" 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" @click="export_out">导出</button>
</div>
</div>
</div>
</form>
<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>
require(['laydate', 'autocomplete'], function (laydate) {
laydate.render({
elem: '#id-stat_date', range: '~'
});
$('.id-day-btn').click(function () {
var type = $(this).data('date'), 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 'stat_date':
$('#id-stat_date').val(date);
break;
}
});
});
var vue_obj;
$(function () {
vue_obj = new Vue({
el: '.coms-table-wrap',
data: {
params: {'city_id': '', 'biz_id': ''},
indexs: [],
lists: [],
city_biz_ary: [],
biz_ary:[],
},
mounted: function () {
var vm = this;
vm.params = <?=json_encode($params)?>;
vm.indexs = <?=json_encode($indexs)?>;
vm.lists = <?=json_encode($lists)?>;
vm.city_biz_ary = <?=json_encode($city_biz_ary)?>;
},
methods: {
export_out: function () {
let href = $.menu.parseUri(window.location.href);
href = href.replace("customer/lists_statdatalog?", "customer/export_statdatalog?");
window.location.href = href;
},
},
watch: {
'params.city_id': function (nv, ov) {
var that = this;
if (nv == '') {
that.params.biz_id = '';
that.biz_ary = [];
} else {
that.biz_ary = that.city_biz_ary[nv]['list'];
}
},
}
});
});
</script>
@@ -67,7 +67,9 @@
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>
class="am-btn am-btn-primary am-btn-xs">数据</a>
<a href="javascript:void(0);" :data-open="'/receiver/customer/lists_statdatalog?id='+v.id"
class="am-btn am-btn-primary am-btn-xs">数据log</a>
</td>
</tr>
</template>