diff --git a/application/admin/controller/statistics/Dispatcher.php b/application/admin/controller/statistics/Dispatcher.php index 792b431..53ec5a0 100644 --- a/application/admin/controller/statistics/Dispatcher.php +++ b/application/admin/controller/statistics/Dispatcher.php @@ -59,13 +59,44 @@ class Dispatcher extends Backend return $this->view->fetch(); } - return json([]); + + $filter = $this->request->param('filter'); + $filter = json_decode($filter,true); + + if(!empty($filter['daterange'])){ + $arr = explode(' - ',$filter['daterange']); + if(trim($arr[0])){ + $filter['start_time'] = trim($arr[0]); + } + if(trim($arr[1])){ + $filter['end_time'] = trim($arr[1]); + } + } + + $list = $this->chart($filter,false); + + $result = array("total" => $list->total(), "rows" => $list->items()); + + return json($result); } public function chartData() { - $data = $this->chart(); + $filter = $this->request->post(); + + if(!empty($filter['daterange'])){ + $arr = explode(' - ',$filter['daterange']); + if(trim($arr[0])){ + $filter['start_time'] = trim($arr[0]); + } + if(trim($arr[1])){ + $filter['end_time'] = trim($arr[1]).' 23:59:59'; + } + } + + $data = $this->chart($filter,true); + $newData = [ ['派单员','总业绩(¥)','转化率(%)','利润率(%)','变现值'] @@ -83,17 +114,9 @@ class Dispatcher extends Backend } //图表统计 - public function chart(){ - $filter = $this->request->post(); - if(!empty($filter['daterange'])){ - $arr = explode(' - ',$filter['daterange']); - if(trim($arr[0])){ - $filter['start_time'] = trim($arr[0]); - } - if(trim($arr[1])){ - $filter['end_time'] = trim($arr[1]).' 23:59:59'; - } - } + public function chart($filter,$getAll=false){ + + $orderValid = implode(',',$this->model->tabStatus(Order::TAB_VALID)); @@ -139,13 +162,17 @@ class Dispatcher extends Backend if(!empty($filter['item_id'])){ $builder->where('item_id',$filter['item_id']); } - $data = $builder->group('dispatch_admin_id')->select(); + + if($getAll){ + $data = $builder->group('dispatch_admin_id')->select(); + }else{ + $data = $builder->group('dispatch_admin_id')->paginate(); + } $newData = []; - if(!empty($data)){ - foreach ($data as $datum){ + foreach ($data as &$datum){ //利润率 = 总业绩/总成效额 $datum->performance_rate = $this->_calc($datum->performance,$datum->total,4,true); //转化率 = 完单数 / 总订单数 @@ -159,14 +186,18 @@ class Dispatcher extends Backend $datum->admin_user = Admin::where($datum->dispatch_admin_id)->value('nickname')??'未知'; + $datum->avg_time_diff = $this->_calc($datum->avg_time_diff,3600,2); + + $datum->id = $datum->dispatch_admin_id; $newData[] = $datum->toArray(); } } - - - - return $newData; + if($getAll){ + return $newData; + }else{ + return $data; + } //dump($newData);exit; } diff --git a/application/admin/view/statistics/dispatcher/index.html b/application/admin/view/statistics/dispatcher/index.html index 1e86817..f973066 100644 --- a/application/admin/view/statistics/dispatcher/index.html +++ b/application/admin/view/statistics/dispatcher/index.html @@ -2,8 +2,8 @@
diff --git a/public/assets/js/backend/orders/dispatchlog.js b/public/assets/js/backend/orders/dispatchlog.js index bd77d03..94902f6 100644 --- a/public/assets/js/backend/orders/dispatchlog.js +++ b/public/assets/js/backend/orders/dispatchlog.js @@ -84,7 +84,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin {field: 'id', title: __('Id')}, //{field: 'dispatch_id', title: __('Dispatch_id')}, //{field: 'worker_id', title: __('Worker_id')}, - {field: 'remark', title: __('跟进内容'), operate: 'LIKE', table: table2, class: 'autocontent', formatter: Table.api.formatter.content}, + {field: 'remark', title: __('跟进内容'), operate: false, table: table1, class: 'autocontent', formatter: Table.api.formatter.content}, {field: 'images', title: __('跟进依据'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images}, /* {field: 'need_notice', title: __('需要提醒'), searchList: {"0":__('否'),"1":__('是')}, formatter: Table.api.formatter.normal}, {field: 'notice_time', title: __('提醒时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},*/ @@ -121,7 +121,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin //{field: 'worker_id', title: __('Worker_id')}, // {field: 'status', title: __('Status')}, {field: 'status_text', title: __('Status_text'), operate: 'LIKE'}, - {field: 'remark', title: __('Remark'), operate: 'LIKE', table: table1, class: 'autocontent', formatter: Table.api.formatter.content}, + {field: 'remark', title: __('Remark'), operate: false, table: table2, class: 'autocontent', formatter: Table.api.formatter.content}, {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false}, // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate} ] diff --git a/public/assets/js/backend/statistics/dispatcher.js b/public/assets/js/backend/statistics/dispatcher.js index c83605b..d8dfda6 100644 --- a/public/assets/js/backend/statistics/dispatcher.js +++ b/public/assets/js/backend/statistics/dispatcher.js @@ -3,50 +3,92 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'echarts', 'echarts-t var Controller = { index: function () { - // 初始化表格参数配置 - Table.api.init(); + //绑定事件 - /* $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) { + /*$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) { var panel = $($(this).attr("href")); + var thisVal = $($(this).attr("data-val")); + if (panel.length > 0) { - /!*Controller.table[panel.attr("id")].call(this); + if(panel.attr("id")){ + + } + Controller.table[panel.attr("id")].call(this); $(this).on('click', function (e) { - // $($(this).attr("href")).find(".btn-refresh").trigger("click"); - });*!/ + $($(this).attr("href")).find(".btn-refresh").trigger("click"); + }); } //移除绑定的事件 $(this).unbind('shown.bs.tab'); });*/ - //必须默认触发shown.bs.tab事件 - /*$('ul.nav-tabs li.active a[data-toggle="tab"]').trigger("shown.bs.tab"); + $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) { + var $targetPanel = $($(this).attr("href")); + var tabVal = $(this).data('val'); + + if (tabVal === 'second') { + // 当切换到“统计列表”时,自动刷新表格 + //$targetPanel.find(".btn-refresh").trigger("click"); + // 初始化表格参数配置 + Table.api.init(); + // 表格2 + var table2 = $("#table2"); + table2.bootstrapTable({ + url: 'statistics/dispatcher/index' + location.search, + toolbar: '#toolbar1', + sortName: 'id', + search: false, + commonSearch:true, + visible: false, + showToggle: false, + showColumns: false, + showExport: true, + searchFormVisible:true, + columns: [ + [ + //{field: 'id', title: __('Id')}, + {field: 'id', title: __('ID'),visible:false,operate: false}, + {field: 'admin_user', title: __('派单员'),operate: "LIKE"}, + {field: 'count_num', title: __('总订单数'),operate: false}, + {field: 'finish_num', title: __('完单数'),operate: false}, + {field: 'total', title: __('成效额'), operate: false}, + {field: 'performance', title: __('总业绩'), operate: false}, + {field: 'cost_total', title: __('总成本'), operate: false}, + {field: 'refund_total', title: __('退款金额'), operate: false}, + {field: 'refund_count', title: __('退款单数'), operate: false}, + + {field: 'performance_rate', title: __('利润率(%)'), operate: false}, + {field: 'trans_rate', title: __('转化率(%)'), operate: false}, + {field: 'cash_value', title: __('变现值'), operate: false}, + {field: 'performance_avg', title: __('客单利润'), operate: false}, + {field: 'total_avg', title: __('客单价'), operate: false}, + + {field: 'avg_time_diff', title: __('派单时效(小时)'), operate: false}, + + //{field: 'admin_user', title: __('派单员'),operate: "LIKE",visible:false}, + //{field: 'city_name', title: __('城市'),operate: "LIKE",visible:false}, + //{field: 'city_name', title: __('城市'),operate: "LIKE",visible:false}, + {field: 'time_by', title: __('时间维度'), visible:false,searchList: {"1":__('录单时间'),"2":__('派单时间')},defaultValue:1, formatter: Table.api.formatter.normal}, + {field: 'daterange', title: __('时间筛选'), addclass:'datetimerange', + autocomplete:false, + operate: "RANGE", + datetimeFormat: "YYYY-MM-DD", + //defaultValue:today()+' - '+today(), + data:'autocomplete="off" data-local={"format":"YYYY-MM-DD"}', + visible:false}, + + // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate} + ] + ] + }); + // 为表格2绑定事件 + Table.api.bindevent(table2); + } + + }); + - var barChart = Echarts.init(document.getElementById('bar-chart'), 'walden'); - var option = { - legend: {}, - tooltip: {}, - dataset: { - source: [ - ['产品销售', '2015', '2016', '2017'], - ['风扇', 43.3, 85.8, 93.7], - ['电视机', 83.1, 73.4, 55.1], - ['空调', 86.4, 65.2, 82.5], - ['冰箱', 72.4, 53.9, 39.1] - ] - }, - xAxis: {type: 'category'}, - yAxis: {}, - // Declare several bar series, each will be mapped - // to a column of dataset.source by default. - series: [ - {type: 'bar'}, - {type: 'bar'}, - {type: 'bar'} - ] - }; - // 使用刚指定的配置项和数据显示图表。 - barChart.setOption(option);*/ // 触发 tab 后发起 ajax 获取图表数据 $('ul.nav-tabs li.active a[data-toggle="tab"]').on("shown.bs.tab", function () { @@ -156,6 +198,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'echarts', 'echarts-t getChartData(); }); }, + add: function () { Controller.api.bindevent(); },