123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'bootstrap-datetimepicker', 'bootstrap-daterangepicker','dateyearmonth'], function ($, undefined, Backend, Table, Form, Datetimepicker, Daterangepicker, dateyearmonth) {
- var Controller = {
- index: function () {
- // 初始化表格参数配置
- Table.api.init({
- extend: {
- index_url: 'vip/admin/ordercollect/index',
- table: 'orders_collect'
- },
- search: false,
- searchFormVisible: true,
- showExport: false,
- onLoadSuccess: function (data) {
- $("[data-toggle='tooltip']").tooltip({trigger: 'focus hover', html: true});
- var startDate, endDate;
- if (data['begin_date']) {
- startDate = data['begin_date'];
- } else {
- startDate = Moment().subtract(1, 'day');
- }
- if (data['end_date']) {
- endDate = data['end_date'];
- } else {
- endDate = Moment().subtract(1, 'day');
- }
- $('#day,#day_sum').daterangepicker({
- // autoUpdateInput: false,
- startDate: startDate,
- endDate: endDate,
- maxDate: Moment().subtract(1, 'day'),
- minDate: Moment().subtract(12, 'month'),
- locale: {
- format: 'YYYY-MM-DD',
- applyLabel: '确认',
- cancelLabel: '取消',
- fromLabel: '从',
- toLabel: '到',
- weekLabel: 'W',
- customRangeLabel: '选择时间',
- daysOfWeek: ["日", "一", "二", "三", "四", "五", "六"],
- monthNames: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
- }
- });
- $('#month').datetimepicker({
- maxDate: Moment(),
- format: 'YYYY-MM'
- });
- if($('#month_sum').length){
- if(!$('#month_sum').val()){
- $('#month_sum').val(Moment().subtract(0, 'month').format('YYYY-MM')+' - '+Moment().format('YYYY-MM'));
- $(document).delegate('.kui-datepicker-range-footer .select','click',function(){
- $('.commonsearch-table button[type="submit"]').trigger('click');
- });
- }
- new dateyearmonth({
- id:'month_sum',
- format:'yyyy-mm - yyyy-mm',
- endYear:Moment().year(),
- startYear:Moment().subtract(1,'year').year(),
- });
- }
- if(($('.nima').length > 0)){
- $('.nima').remove();
- $('.fixed-table-toolbar').prepend('<div class="columns-left pull-left nima" style="margin-top:10px;"><a class="btn btn-success btn-exports" href="javascript:;"><i class="fa fa-user"></i> 导出</a></div>');
- }else{
- $('.fixed-table-toolbar').prepend('<div class="columns-left pull-left nima" style="margin-top:10px;"><a class="btn btn-success btn-exports" href="javascript:;"><i class="fa fa-user"></i> 导出</a></div>');
- }
- }
- });
- //绑定事件
- $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
- var panel = $($(this).attr("href"));
- if (panel.size() > 0) {
- Controller.table[panel.attr("id")].call(this);
- $(this).on('click', function (e) {
- $($(this).attr("href")).find(".btn-refresh").trigger("click");
- });
- }
- //移除绑定的事件
- $(this).unbind('shown.bs.tab');
- // var html= '<div id="toolbar" class="toolbar"><a class="btn btn-success btn-exports" href="javascript:;"><i class="fa fa-user"></i> 导出</a></div>';
- // $('#export').prepend(html);
- });
- //必须默认触发shown.bs.tab事件
- $('ul.nav-tabs li.active a[data-toggle="tab"]').trigger("shown.bs.tab");
- $(document).on('click', '.flush', function () {
- $.post('vip/admin/ordercollect/ajaxtoday', {}, function (data) {
- if (data) {
- $('#increase').text('¥' + data.today);
- Toastr.success('刷新成功');
- } else {
- Toastr.error('刷新失败');
- }
- });
- });
- $(document).on('click','.btn-exports',function () {
- var tab_index = $('.panel-heading .nav-tabs').find('li.active').index()
- var map = ['day', 'day_sum', 'month', 'month_sum'];
- var url = '/admin/vip/admin/ordercollect/export?tab=' + map[tab_index];
- var data = $('.panel-body.tab-content>.tab-pane.fade.active .form-commonsearch').serializeArray();
- var params = {filter:{},op:{}};
- $.each(data, function(index, val) {
- if(val.name.substr(0,6) == 'field-'){
- var key = val.name.substr(6,val.name.length);
- params.op[key] = val.value;
- }else{
- if(val.value == ""){
- delete params.op[val.name];
- }else{
- params.filter[val.name] = val.value;
- }
- }
- });
- if(url.indexOf("?") != -1){
- url = url + "&filter="+JSON.stringify(params.filter)+"&op="+JSON.stringify(params.op);
- }else{
- url = url + "?filter="+JSON.stringify(params.filter)+"&op="+JSON.stringify(params.op);
- }
- top.location.href=url;
- });
- },
- table: {
- first: function () {
- var table = $("#table");
- // 初始化渠道商表格
- table.bootstrapTable({
- url: 'vip/admin/ordercollect/index?tab=day',
- pk: 'id',
- sortName: 'createdate',
- columns: [
- [
- {
- field: 'createdate',
- id: 'day',
- title: __('日期'),
- formatter: Controller.api.formatter.createtime, width: '100px'
- },
- {
- field: 'username',
- title: __('渠道商账号')
- // operate: false
- },
- {field: 'wx_nickname', title: __('公众号'), operate: false, width: '150px'},
- {field: 'recharge_money', title: __('总充值'), operate: false},
- {
- field: 'normal_recharge_money',
- title: __('总充值笔数'),
- formatter: Controller.api.formatter.sum_recharge_orders,
- operate: false
- },
- {
- field: 'normal_recharge_money',
- title: __('普通充值'),
- formatter: Controller.api.formatter.money,
- operate: false
- },
- {field: 'normal_recharge_orders', title: __('普通充值笔数'), operate: false},
- {
- field: '',
- title: __('普通充值人均'),
- formatter: Controller.api.formatter.normal_recharge_str_avg,
- operate: false
- },
- {
- field: 'vip_recharge_money',
- title: __('年费VIP充值'),
- formatter: Controller.api.formatter.money,
- operate: false
- },
- {field: 'vip_recharge_orders', title: __('年费VIP充值笔数'), operate: false},
- {
- field: '',
- title: __('年费VIP人均'),
- formatter: Controller.api.formatter.vip_recharge_str_avg,
- operate: false
- },
- {
- field: 'self_recharge',
- title: __('渠道商充值'),
- formatter: Controller.api.formatter.money,
- operate: false
- },
- {
- field: 'self_recharge_benefit',
- title: __('渠道商的分成收益'),
- formatter: Controller.api.formatter.money,
- operate: false
- },
- {
- field: 'agent_recharge',
- title: __('代理商充值金额'),
- formatter: Controller.api.formatter.money,
- operate: false
- },
- {
- field: 'agent_benefit',
- title: __('代理商分成收益'),
- formatter: Controller.api.formatter.money,
- operate: false
- },
- {
- field: 'total_benefit',
- title: __('实际收益'),
- formatter: Controller.api.formatter.money,
- operate: false
- }
- ]
- ]
- });
- // 为表格1绑定事件
- Table.api.bindevent(table);
- Controller.api.bindevent();
- },
- second: function () {
- var table2 = $("#table2");
- // 初始化渠道商表格
- table2.bootstrapTable({
- url: 'vip/admin/ordercollect/index?tab=month',
- pk: 'id',
- sortName: 'createdate',
- columns: [
- [
- {
- field: 'create_month',
- id: 'month',
- title: __('月份'),
- formatter: Controller.api.formatter.createmonthtime,
- width: '100px'
- },
- {
- field: 'username',
- title: __('渠道商账号'),
- // operate: false
- },
- {field: 'wx_nickname', title: __('公众号'), operate: false, width: '150px'},
- {field: 'recharge_money', title: __('总充值'), operate: false},
- {
- field: 'normal_recharge_money',
- title: __('总充值笔数'),
- formatter: Controller.api.formatter.sum_recharge_orders,
- operate: false
- },
- {
- field: 'normal_recharge_money',
- title: __('普通充值'),
- formatter: Controller.api.formatter.money,
- operate: false
- },
- {field: 'normal_recharge_orders', title: __('普通充值笔数'), operate: false},
- {
- field: '',
- title: __('普通充值人均'),
- formatter: Controller.api.formatter.normal_recharge_str_avg,
- operate: false
- },
- {
- field: 'vip_recharge_money',
- title: __('年费VIP充值'),
- formatter: Controller.api.formatter.money,
- operate: false
- },
- {field: 'vip_recharge_orders', title: __('年费VIP充值笔数'), operate: false},
- {
- field: '',
- title: __('年费VIP人均'),
- formatter: Controller.api.formatter.vip_recharge_str_avg,
- operate: false
- },
- {
- field: 'self_recharge',
- title: __('充值'),
- formatter: Controller.api.formatter.money,
- operate: false
- },
- {
- field: 'self_recharge_benefit',
- title: __('分成收益'),
- formatter: Controller.api.formatter.money,
- operate: false
- },
- {
- field: 'agent_recharge',
- title: __('代理商充值'),
- formatter: Controller.api.formatter.money,
- operate: false
- },
- {
- field: 'agent_benefit',
- title: __('代理商分成收益'),
- formatter: Controller.api.formatter.money,
- operate: false
- },
- {
- field: 'total_benefit',
- title: __('实际收益'),
- formatter: Controller.api.formatter.money,
- operate: false
- }
- ]
- ]
- });
- // 为表格1绑定事件
- Table.api.bindevent(table2);
- Controller.api.bindevent();
- },
- third: function () {
- var table3 = $("#table3");
- // 初始化渠道商表格
- table3.bootstrapTable({
- url: 'vip/admin/ordercollect/index?tab=day_sum',
- pk: 'id',
- sortName: 'createday',
- columns: [
- [
- {
- field: 'createdate',
- id: 'day_sum',
- title: __('日期'),
- formatter: Controller.api.formatter.createtime, width: '100px'
- },
- {field: 'recharge_money', title: __('总充值'), operate: false},
- {
- field: 'normal_recharge_money',
- title: __('总充值笔数'),
- formatter: Controller.api.formatter.sum_recharge_orders,
- operate: false
- },
- {
- field: 'normal_recharge_money',
- title: __('普通充值'),
- formatter: Controller.api.formatter.money,
- operate: false
- },
- {field: 'normal_recharge_orders', title: __('普通充值笔数'), operate: false},
- {
- field: '',
- title: __('普通充值人均'),
- formatter: Controller.api.formatter.normal_recharge_str_avg,
- operate: false
- },
- {
- field: 'vip_recharge_money',
- title: __('年费VIP充值'),
- formatter: Controller.api.formatter.money,
- operate: false
- },
- {field: 'vip_recharge_orders', title: __('年费VIP充值笔数'), operate: false},
- {
- field: '',
- title: __('年费VIP人均'),
- formatter: Controller.api.formatter.vip_recharge_str_avg,
- operate: false
- },
- {
- field: 'self_recharge',
- title: __('充值'),
- formatter: Controller.api.formatter.money,
- operate: false
- },
- {
- field: 'self_recharge_benefit',
- title: __('分成收益'),
- formatter: Controller.api.formatter.money,
- operate: false
- },
- {
- field: 'agent_recharge',
- title: __('代理商充值'),
- formatter: Controller.api.formatter.money,
- operate: false
- },
- {
- field: 'agent_benefit',
- title: __('代理商分成收益'),
- formatter: Controller.api.formatter.money,
- operate: false
- },
- {
- field: 'total_benefit',
- title: __('实际收益'),
- formatter: Controller.api.formatter.money,
- operate: false
- }
- ]
- ]
- });
- // 为表格1绑定事件
- Table.api.bindevent(table3);
- Controller.api.bindevent();
- },
- forth: function () {
- var table4 = $("#table4");
- // 初始化渠道商表格
- table4.bootstrapTable({
- url: 'vip/admin/ordercollect/index?tab=month_sum',
- pk: 'id',
- sortName: 'create_month',
- columns: [
- [
- {
- field: 'create_month',
- id: 'month_sum',
- title: __('月份'),
- formatter: Controller.api.formatter.createmonthtime,
- width: '100px'
- },
- {field: 'recharge_money', title: __('总充值'), operate: false},
- {
- field: 'normal_recharge_money',
- title: __('总充值笔数'),
- formatter: Controller.api.formatter.sum_recharge_orders,
- operate: false
- },
- {
- field: 'normal_recharge_money',
- title: __('普通充值'),
- formatter: Controller.api.formatter.money,
- operate: false
- },
- {field: 'normal_recharge_orders', title: __('普通充值笔数'), operate: false},
- {
- field: '',
- title: __('普通充值人均'),
- formatter: Controller.api.formatter.normal_recharge_str_avg,
- operate: false
- },
- {
- field: 'vip_recharge_money',
- title: __('年费VIP充值'),
- formatter: Controller.api.formatter.money,
- operate: false
- },
- {field: 'vip_recharge_orders', title: __('年费VIP充值笔数'), operate: false},
- {
- field: '',
- title: __('年费VIP人均'),
- formatter: Controller.api.formatter.vip_recharge_str_avg,
- operate: false
- },
- {
- field: 'self_recharge',
- title: __('充值'),
- formatter: Controller.api.formatter.money,
- operate: false
- },
- {
- field: 'self_recharge_benefit',
- title: __('分成收益'),
- formatter: Controller.api.formatter.money,
- operate: false
- },
- {
- field: 'agent_recharge',
- title: __('代理商充值'),
- formatter: Controller.api.formatter.money,
- operate: false
- },
- {
- field: 'agent_benefit',
- title: __('代理商分成收益'),
- formatter: Controller.api.formatter.money,
- operate: false
- },
- {
- field: 'total_benefit',
- title: __('实际收益'),
- formatter: Controller.api.formatter.money,
- operate: false
- }
- ]
- ]
- });
- // 为表格1绑定事件
- Table.api.bindevent(table4);
- Controller.api.bindevent();
- }
- },
- api: {
- bindevent: function () {
- Form.api.bindevent($("form[role=form]"));
- }, formatter: {
- sum_recharge_orders: function (value, row, index) {
- normal_recharge_orders = Number(row.normal_recharge_orders ? row.normal_recharge_orders : 0);
- vip_recharge_orders = Number(row.vip_recharge_orders ? row.vip_recharge_orders : 0);
- return normal_recharge_orders + vip_recharge_orders;
- },
- money: function (value, row, index) {
- if (value) {
- return '¥' + Number(value).toFixed(2);
- } else {
- return '¥0.00';
- }
- },
- normal_recharge_str_avg: function (value, row, index) {
- var normal_recharge_str_avg = 0;
- if (row.normal_recharge_orders > 0) {
- normal_recharge_str_avg = Number(row.normal_recharge_money / row.normal_recharge_orders) * 1.00;
- normal_recharge_str_avg = Number(normal_recharge_str_avg.toFixed(2));
- }
- return '¥' + normal_recharge_str_avg;
- },
- vip_recharge_str_avg: function (value, row, index) {
- var vip_recharge_str_avg = 0;
- if (row.vip_recharge_orders > 0) {
- vip_recharge_str_avg = Number(row.vip_recharge_money / row.vip_recharge_orders) * 1.00;
- vip_recharge_str_avg = Number(vip_recharge_str_avg.toFixed(2));
- }
- return '¥' + vip_recharge_str_avg;
- },
- createtime: function (value, row, index) {
- if (value) {
- return value.substring(0, 4) + '-' + value.substring(4, 6) + '-' + value.substring(6, 8);
- } else {
- return '';
- }
- },
- createmonthtime: function (value, row, index) {
- return value.substring(0, 4) + '-' + value.substring(4, 6);
- },
- }
- }
- };
- return Controller;
- });
|