You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
204 lines
8.6 KiB
204 lines
8.6 KiB
define(['angular', 'uiBootstrap', 'uiRouter', 'angularEcharts'], function (angular) {
|
|
'use strict';
|
|
var colors = ['#00c0ef', '#00a65a', '#ff851b'];
|
|
var app = angular.module('actChairty', ['ui.bootstrap', 'ui.router', 'ngEcharts']);
|
|
var total;
|
|
|
|
app.config(['$stateProvider', function ($stateProvider) {
|
|
$stateProvider.state('act_chairty', {
|
|
url: '/act_chairty',
|
|
templateUrl: '/static/actchairty/templates/act_chairty_merchants.html',
|
|
controller: 'actChairtyConfDialogCtrl'
|
|
}).state('act_chairty.analysis',{
|
|
url:'/act_chairty/analysis',
|
|
templateUrl: '/static/actchairty/templates/act_chairty_analysis.html',
|
|
controller: 'actChairtyAnalysisConfDialogCtrl'
|
|
})
|
|
}]);
|
|
app.controller('actChairtyConfDialogCtrl', ['$scope', '$http', '$filter', function ($scope, $http, $filter) {
|
|
$scope.pagination = {};
|
|
$scope.today = new Date();
|
|
$scope.loadClients = function (page) {
|
|
var params = {page: page || $scope.pagination.page || 1};
|
|
$http.get('/actchairty/clients', {params: params}).then(function (resp) {
|
|
$scope.clients = resp.data.data;
|
|
$scope.pagination = resp.data.pagination;
|
|
})
|
|
};
|
|
$scope.loadClients();
|
|
$scope.new_conf = {};
|
|
$scope.ctrl = {dateInput: false};
|
|
$scope.submitClient = function () {
|
|
$scope.errmsg = null;
|
|
var conf = {
|
|
date: $filter('date')($scope.new_conf.date, 'yyyy-MM-dd'),
|
|
};
|
|
$http.put('/actchairty/clients/' + $scope.new_conf.client_moniker, conf).then(function () {
|
|
$scope.new_conf = {};
|
|
$scope.loadClients();
|
|
}, function (resp) {
|
|
$scope.errmsg = resp.data.message;
|
|
});
|
|
};
|
|
}]);
|
|
|
|
app.controller('actChairtyAnalysisConfDialogCtrl', ['$scope', '$http', '$filter', function ($scope, $http, $filter) {
|
|
$scope.params = {};
|
|
$scope.today = new Date();
|
|
$scope.params.end = new Date();
|
|
var date = new Date();
|
|
date.setDate(date.getDate()-30);
|
|
$scope.params.begin = date;
|
|
$scope.thisMonth = function () {
|
|
$scope.params.end = new Date();
|
|
var monthBegin = new Date();
|
|
monthBegin.setDate(1);
|
|
$scope.params.begin = monthBegin;
|
|
$scope.doAnalysis(1);
|
|
};
|
|
$scope.lastMonth = function () {
|
|
var monthFinish = new Date();
|
|
monthFinish.setDate(0);
|
|
$scope.params.end = monthFinish;
|
|
var monthBegin = new Date();
|
|
monthBegin.setDate(0);
|
|
monthBegin.setDate(1);
|
|
$scope.params.begin = monthBegin;
|
|
$scope.doAnalysis(1);
|
|
};
|
|
|
|
$scope.doPartnerTotalRanking = function (page) {
|
|
var params = {};
|
|
params.page = page||$scope.total_ranking_pagination.page || 1;
|
|
params.limit = 10;
|
|
|
|
$http.get('/actchairty/clients', {params: params}).then(function (resp) {
|
|
$scope.chairtyPartnersRanking = resp.data.data;
|
|
$scope.total_ranking_pagination = resp.data.pagination;
|
|
});
|
|
$scope.getTotalAmount = function () {
|
|
$http.get('/actchairty/total').then(function (resp) {
|
|
$scope.totalAmount = resp.data.amount;
|
|
$scope.totalChairty = resp.data.chairty;
|
|
})
|
|
};
|
|
};
|
|
$scope.getClientsCashbackRankingByDate = function (date,page) {
|
|
var dateend = angular.copy($scope.params);
|
|
$scope.event_date = date;
|
|
var params = {};
|
|
params.begin = date;
|
|
var event_date_format=date.replace(/^(\d{4})(\d{2})(\d{2})$/, "$1-$2-$3")
|
|
var endDate = new Date(event_date_format);
|
|
endDate.setDate(endDate.getDate()+6);
|
|
var end1 = $filter('date')(endDate, 'yyyyMMdd');
|
|
var end2 = $filter('date')(dateend.end, 'yyyyMMdd');
|
|
if (end1 > end2) {
|
|
params.end =$filter('date')(dateend.end,'yyyyMMdd');
|
|
}
|
|
else {
|
|
params.end =$filter('date')(endDate,'yyyyMMdd');
|
|
}
|
|
params.page = page||$scope.day_ranking_pagination.page || 1;
|
|
params.limit = 10;
|
|
if ($scope.params.cashback_type){
|
|
params.cashback_type = angular.copy($scope.params.cashback_type);
|
|
}
|
|
$http.get('/actchairty/ranking', {params: params}).then(function (resp) {
|
|
$scope.cashbackPartnersRankingByDate = resp.data.data;
|
|
$scope.day_ranking_pagination = resp.data.pagination;
|
|
});
|
|
};
|
|
$scope.doAnalysis = function () {
|
|
var params = angular.copy($scope.params);
|
|
if (params.begin) {
|
|
params.begin = $filter('date')(params.begin, 'yyyyMMdd');
|
|
} else {
|
|
params.begin = $filter('date')(new Date(), 'yyyyMMdd');
|
|
}
|
|
if (params.end) {
|
|
params.end = $filter('date')(params.end, 'yyyyMMdd');
|
|
} else {
|
|
params.end = $filter('date')(new Date(), 'yyyyMMdd');
|
|
}
|
|
$http.get('/actchairty/traAnalysis', {params: params}).then(function (resp) {
|
|
$scope.cashbackDaily = angular.copy(resp.data);
|
|
var dates = [];
|
|
var count_ordernum = [];
|
|
var sum_ordernum = [];
|
|
var chairty_amount = [];
|
|
resp.data.forEach(function (e) {
|
|
dates.push(e.weekstart);
|
|
chairty_amount.push(e.chairty_amount);
|
|
count_ordernum.push(e.count_ordernum);
|
|
sum_ordernum.push(e.sum_ordernum);
|
|
});
|
|
var cashbackHistoryConfig = function (dates,sum_ordernum, count_ordernum, chairty_amount) {
|
|
return {
|
|
color: colors,
|
|
tooltip: {
|
|
trigger: 'axis',
|
|
axisPointer: { // 坐标轴指示器,坐标轴触发有效
|
|
type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
|
|
}
|
|
},
|
|
legend: {
|
|
data: ['周一交易额', '交易量','公益额']
|
|
},
|
|
grid: {
|
|
left: '3%',
|
|
right: '4%',
|
|
bottom: '3%',
|
|
containLabel: true
|
|
},
|
|
xAxis: [
|
|
{
|
|
type: 'category',
|
|
data: dates
|
|
}
|
|
],
|
|
yAxis: [
|
|
{
|
|
type: 'value',
|
|
name: 'Amount(AUD)'
|
|
}
|
|
],
|
|
series: [{
|
|
name: '周一交易额',
|
|
type: 'bar',
|
|
data: sum_ordernum
|
|
}, {
|
|
name: '交易量',
|
|
type: 'bar',
|
|
data: count_ordernum
|
|
}, {
|
|
name: '公益额',
|
|
type: 'bar',
|
|
data: chairty_amount
|
|
}
|
|
]
|
|
};
|
|
};
|
|
$scope.settleDelayHistory = cashbackHistoryConfig(dates,sum_ordernum, count_ordernum, chairty_amount);
|
|
});
|
|
$scope.doPartnerTotalRanking(1);
|
|
};
|
|
$scope.doAnalysis(1);
|
|
$scope.getTotalAmount(1);
|
|
$scope.settleDelayEchart = function (chart) {
|
|
chart.on('click', function (params) {
|
|
$scope.cashBack_total_daily = $scope.cashbackDaily[params.dataIndex].chairty_amount;
|
|
var event_date = $scope.cashbackDaily[params.dataIndex].weekstart;
|
|
|
|
|
|
if (event_date) {
|
|
event_date+="";
|
|
var event_date_format=event_date.replace(/^(\d{4})(\d{2})(\d{2})$/, "$1-$2-$3")
|
|
var date = new Date(event_date_format);
|
|
$scope.getClientsCashbackRankingByDate($filter('date')(date,'yyyyMMdd'),1);
|
|
}
|
|
})
|
|
};
|
|
}]);
|
|
return app;
|
|
}); |