|
|
/**
|
|
|
* Created by yixian on 2016-06-29.
|
|
|
*/
|
|
|
define(['angular', 'angularSanitize', 'angularAnimate', 'angularMessages', 'uiRouter', 'uiBootstrap', 'ngFileUpload', 'sockjs', 'stomp'], function (angular) {
|
|
|
'use strict';
|
|
|
var app = angular.module('managerMainApp', ['ngSanitize', 'ngAnimate', 'ngMessages', 'ui.router', 'ui.bootstrap', 'ngFileUpload']);
|
|
|
app.config(['$urlRouterProvider', '$httpProvider', function ($urlRouterProvider, $httpProvider) {
|
|
|
$urlRouterProvider.otherwise(((window.currentUser.role & parseInt('100000', 2)) > 0) ? '/managers' : '/dashboard');
|
|
|
if (!$httpProvider.defaults.headers.get) {
|
|
|
$httpProvider.defaults.headers.get = {};
|
|
|
}
|
|
|
$httpProvider.defaults.headers.get['If-Modified-Since'] = 'Mon, 26 Jul 1997 05:00:00 GMT';
|
|
|
$httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache';
|
|
|
$httpProvider.defaults.headers.get['Pragma'] = 'no-cache';
|
|
|
}]);
|
|
|
app.controller('managerIndexCtrl', ['$scope', '$rootScope', '$http', '$log', '$timeout', '$interval', '$uibModal', '$filter', 'myLoginLogView', 'commonDialog',
|
|
|
function ($scope, $rootScope, $http, $log, $timeout, $interval, $uibModal, $filter, myLoginLogView, commonDialog) {
|
|
|
|
|
|
$http.get('/sysconfig/base').then(function (resp) {
|
|
|
$rootScope.sysParams = resp.data;
|
|
|
});
|
|
|
var stompClient = null;
|
|
|
$scope.loadCurrentUser = function () {
|
|
|
$http.get('/global/userstatus/current_manager').then(function (resp) {
|
|
|
$rootScope.currentUser = resp.data;
|
|
|
// connectWebSocket();
|
|
|
$scope.notifyCounts = 0;
|
|
|
if ($rootScope.currentUser.role & parseInt('110', 2)) {
|
|
|
$scope.loadPartnerApplyNotice();
|
|
|
if (window.currentUser.role & 10000000000) {
|
|
|
$scope.loadRefundNotice();
|
|
|
}
|
|
|
}
|
|
|
// if ($rootScope.currentUser.role ==2 || $rootScope.currentUser.role == 4){
|
|
|
// $scope.loadPartnerApplyNotice();
|
|
|
// }
|
|
|
if ($rootScope.currentUser.wx_openid == null) {
|
|
|
if ($filter('withRole')('100')) {
|
|
|
$scope.managerBindWechat('static');
|
|
|
} else {
|
|
|
$scope.managerBindWechat(true);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}, function (resp) {
|
|
|
if (resp.status == 403) {
|
|
|
location.href = 'm_login.html?f=' + encodeURIComponent(location.href);
|
|
|
}
|
|
|
})
|
|
|
};
|
|
|
$scope.loadCurrentUser();
|
|
|
|
|
|
$scope.getManagerTodoNotices = function () {
|
|
|
$http.get('/global/userstatus/manager_todo_notices').then(function (resp) {
|
|
|
if (resp.data.length) {
|
|
|
$uibModal.open({
|
|
|
controller: 'managerTodoNoticeCtrl',
|
|
|
templateUrl: '/static/boot/templates/manager_todo.html',
|
|
|
resolve: {
|
|
|
notices: function () {
|
|
|
return resp.data;
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
})
|
|
|
};
|
|
|
$scope.getManagerTodoNotices();
|
|
|
|
|
|
$scope.editRateConfig = function () {
|
|
|
$uibModal.open({
|
|
|
templateUrl: '/static/config/bdprize/templates/rate_config_dialog.html',
|
|
|
controller: 'bdRateConfigCtrl',
|
|
|
resolve: {
|
|
|
rates: function () {
|
|
|
return angular.copy($scope.bd_rate_configs);
|
|
|
}
|
|
|
}
|
|
|
}).result.then(function () {
|
|
|
$scope.loadRateConfigs();
|
|
|
})
|
|
|
};
|
|
|
$scope.editBDLevels = function () {
|
|
|
$uibModal.open({
|
|
|
templateUrl: '/static/config/bdprize/templates/bd_level_config_dialog.html',
|
|
|
controller: 'bdLevelConfigCtrl'
|
|
|
})
|
|
|
};
|
|
|
|
|
|
var connected;
|
|
|
$interval($scope.loadCurrentUser, 300000);
|
|
|
|
|
|
function connectWebSocket() {
|
|
|
if (connected && stompClient) {
|
|
|
return;
|
|
|
}
|
|
|
var sock = new SockJS('/register');
|
|
|
stompClient = window.Stomp.over(sock);
|
|
|
stompClient.connect({}, function (frame) {
|
|
|
$log.debug('websocket connected:' + frame);
|
|
|
connected = true;
|
|
|
stompClient.subscribe('/app/common/page_events/' + $rootScope.currentUser.manager_id, function (msg) {
|
|
|
$log.debug('new event notice:' + msg.body);
|
|
|
var msgBody = JSON.parse(msg.body);
|
|
|
$scope.$broadcast(msgBody.event, msgBody.data);
|
|
|
});
|
|
|
}, function () {
|
|
|
$log.error('连接失败,3秒后尝试重连');
|
|
|
connected = false;
|
|
|
$timeout(connectWebSocket, 3000);
|
|
|
})
|
|
|
};
|
|
|
connectWebSocket();
|
|
|
|
|
|
$scope.$on('manager_bind_success', function (evt, msg) {
|
|
|
if (msg.key == $scope.checkCode) {
|
|
|
$scope.checkModal != null && $scope.checkModal.close();
|
|
|
}
|
|
|
});
|
|
|
|
|
|
$scope.showMyLoginLogs = function () {
|
|
|
myLoginLogView.show();
|
|
|
};
|
|
|
|
|
|
$scope.toggleHideSideBar = function () {
|
|
|
$scope.hideSideBar = !$scope.hideSideBar;
|
|
|
};
|
|
|
|
|
|
$scope.showQrCode = function (data, backdrop) {
|
|
|
return $uibModal.open({
|
|
|
template: '<div style="width: 100%;padding: 10px;">请使用微信扫描<br><div style="width:100%" qrcode="url"></div><p class="text-center"><img class="img-circle img-bordered" style="width: 45px" ng-show="{{wx_headimg}}" ng-src="{{wx_headimg}}">{{wx_nickname}}</p></div>',
|
|
|
controller: ['$scope', 'data', function ($scope, data) {
|
|
|
$scope.url = data.url;
|
|
|
$scope.wx_headimg = data.wx_headimg;
|
|
|
$scope.wx_nickname = data.wx_nickname;
|
|
|
}],
|
|
|
size: 'sm',
|
|
|
resolve: {
|
|
|
data: function () {
|
|
|
return data;
|
|
|
}
|
|
|
},
|
|
|
keyboard: false,
|
|
|
backdrop: backdrop
|
|
|
|
|
|
})
|
|
|
};
|
|
|
$scope.logout = function () {
|
|
|
$http.put('/global/userstatus/manager_signout').then(function () {
|
|
|
location.href = '/m_login.html';
|
|
|
});
|
|
|
};
|
|
|
$scope.changePwd = function () {
|
|
|
$uibModal.open({
|
|
|
templateUrl: '/static/boot/templates/change_pwd_dialog.html',
|
|
|
controller: 'changePwdCtrl',
|
|
|
size: 'sm'
|
|
|
}).result.then(function () {
|
|
|
commonDialog.alert({title: '操作成功', content: '您成功修改了密码', type: 'success'})
|
|
|
})
|
|
|
};
|
|
|
$scope.currentUserHasRole = function (role) {
|
|
|
return ($scope.currentUser.role & role) > 0
|
|
|
};
|
|
|
$scope.loadPartnerApplyNotice = function () {
|
|
|
var params = {};
|
|
|
$http.get('/partners/application/notice', {params: params}).then(function (resp) {
|
|
|
$scope.partner_application_new = resp.data.counts;
|
|
|
if ($scope.partner_application_new) {
|
|
|
$scope.notifyCounts = $scope.notifyCounts + 1;
|
|
|
}
|
|
|
})
|
|
|
|
|
|
};
|
|
|
$scope.loadRefundNotice = function () {
|
|
|
$http.get('/api/payment/v1.0/refund/orders/notifyReview').then(function (resp) {
|
|
|
$scope.refundReviews = resp.data;
|
|
|
if ($scope.refundReviews) {
|
|
|
$scope.notifyCounts = $scope.notifyCounts + 1;
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
$scope.openNotice = false;
|
|
|
$scope.toggleOpenNotice = function () {
|
|
|
var openNotice = angular.copy($scope.openNotice);
|
|
|
$scope.openNotice = !openNotice;
|
|
|
};
|
|
|
|
|
|
$scope.managerBindWechat = function (backdrop) {
|
|
|
$http.post('/system/manager_wechat_binds').then(function (resp) {
|
|
|
$scope.checkCode = resp.data.bind_id;
|
|
|
if (resp.data.wx_nickname) {
|
|
|
backdrop = true;
|
|
|
}
|
|
|
$scope.checkModal = $scope.showQrCode(resp.data, backdrop);
|
|
|
// $scope.showQrCode(resp.data.url);
|
|
|
})
|
|
|
}
|
|
|
$scope.customerService = function () {
|
|
|
$http.put('/sys/openim/check').then(function (resp) {
|
|
|
window.open('/service_client.html?key='+resp.data.appkey+'&p='+resp.data.password+'&uid='+resp.data.user_id,'_blank');
|
|
|
});
|
|
|
}
|
|
|
|
|
|
function hasRole() {
|
|
|
var rolenum;
|
|
|
switch (sessionStorage.getItem('role')) {
|
|
|
case "administrator":
|
|
|
rolenum = 1;
|
|
|
break;
|
|
|
case "bduser":
|
|
|
rolenum = 4;
|
|
|
break;
|
|
|
case "salesmanager":
|
|
|
rolenum = 8192;
|
|
|
break;
|
|
|
case "accountant":
|
|
|
rolenum = 8;
|
|
|
break;
|
|
|
case "sitemanager":
|
|
|
rolenum = 128;
|
|
|
break;
|
|
|
case "director":
|
|
|
rolenum = 64;
|
|
|
break;
|
|
|
case "developer":
|
|
|
rolenum = 256;
|
|
|
break;
|
|
|
case "compliance":
|
|
|
rolenum = 2;
|
|
|
break;
|
|
|
case "guest":
|
|
|
rolenum = 2048;
|
|
|
break;
|
|
|
case "riskmanager":
|
|
|
rolenum = 1024;
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
if ((window.currentUser.role & rolenum) >0) {
|
|
|
return true;
|
|
|
}else {
|
|
|
sessionStorage.removeItem('role');
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
var getRoleMenulist = function (role) {
|
|
|
var roleMenu = [];
|
|
|
|
|
|
if ((role & 1) >0){
|
|
|
roleMenu.push({'value':'administrator','module':'系统配置'});
|
|
|
}
|
|
|
if ((role & 2) >0){
|
|
|
roleMenu.push({'value':'compliance','module':'合规中心'});
|
|
|
}
|
|
|
if ((role & 4) >0){
|
|
|
roleMenu.push({'value':'bduser','module':"销售中心"});
|
|
|
}
|
|
|
if ((role & 8) >0){
|
|
|
roleMenu.push({'value':'accountant','module':"财务中心"});
|
|
|
}
|
|
|
if ((role & 64) >0){
|
|
|
roleMenu.push({'value':'director','module':"领导决策"});
|
|
|
}
|
|
|
if ((role & 128) >0){
|
|
|
roleMenu.push({'value':'sitemanager','module':"营销中心"});
|
|
|
}
|
|
|
if ((role & 256) >0){
|
|
|
roleMenu.push({'value':'developer','module':"开发中心"});
|
|
|
}
|
|
|
if ((role & 1024) >0){
|
|
|
roleMenu.push({'value':'riskmanager','module':"风控中心"});
|
|
|
}
|
|
|
if ((role & 2048) >0){
|
|
|
roleMenu.push({'value':'guest','module':"访客中心"});
|
|
|
}
|
|
|
if ((role & 8192) >0){
|
|
|
roleMenu.push({'value':'salesmanager','module':"销管中心"});
|
|
|
}
|
|
|
return roleMenu;
|
|
|
};
|
|
|
$scope.role = getRoleMenulist(window.currentUser.role);
|
|
|
|
|
|
if (sessionStorage.getItem('role') == null) {
|
|
|
sessionStorage.setItem('role',$scope.role[0].value);
|
|
|
}else {
|
|
|
hasRole();
|
|
|
}
|
|
|
|
|
|
$scope.roleNow = sessionStorage.getItem('role');
|
|
|
|
|
|
$scope.changeRole = function (index) {
|
|
|
sessionStorage.setItem('role',index);
|
|
|
};
|
|
|
|
|
|
|
|
|
}]);
|
|
|
app.controller('changePwdCtrl', ['$scope', '$http', function ($scope, $http) {
|
|
|
$scope.formData = {};
|
|
|
$scope.submit = function (form) {
|
|
|
if (form.$invalid) {
|
|
|
angular.forEach(form, function (item, key) {
|
|
|
if (key.indexOf('$') <= 0) {
|
|
|
item.$dirty = true;
|
|
|
$scope.errmsg = '请输入密码';
|
|
|
}
|
|
|
});
|
|
|
return;
|
|
|
}
|
|
|
// $scope.errmsg = null;
|
|
|
// if($scope.formData.pwd && $scope.formData.pwd.length < 8){
|
|
|
// $scope.errmsg = '密码必须大于8位!';
|
|
|
// return;
|
|
|
// }
|
|
|
// var regex = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,16}$/;
|
|
|
// if($scope.formData.pwd &&!regex.test($scope.formData.pwd)){
|
|
|
// $scope.errmsg = '密码需要由8-16位数字以及字母组成';
|
|
|
// return;
|
|
|
// }
|
|
|
if ($scope.formData.pwd != $scope.formData.repeatpwd) {
|
|
|
$scope.errmsg = '两次输入密码不一致';
|
|
|
return;
|
|
|
}
|
|
|
$scope.errmsg = null;
|
|
|
$http.put('/global/userstatus/manager_password', $scope.formData).then(function () {
|
|
|
$scope.$close();
|
|
|
}, function (resp) {
|
|
|
$scope.errmsg = resp.data.message;
|
|
|
})
|
|
|
}
|
|
|
}]);
|
|
|
app.controller('managerTodoNoticeCtrl', ['$scope', 'notices', function ($scope, notices) {
|
|
|
$scope.notices = notices;
|
|
|
}]);
|
|
|
|
|
|
app.controller('blankCtrl', ['$scope', function ($scope) {
|
|
|
}]);
|
|
|
|
|
|
app.factory('myLoginLogView', ['$uibModal', function ($uibModal) {
|
|
|
return {
|
|
|
show: function () {
|
|
|
$uibModal.open({
|
|
|
templateUrl: '/static/boot/templates/user_login_logs.html',
|
|
|
controller: ['$scope', '$http', function ($scope, $http) {
|
|
|
$scope.pagination = {};
|
|
|
$scope.getMyLoginLogs = function (page) {
|
|
|
var params = {page: page || $scope.pagination.page || 1};
|
|
|
$http.get('/global/userstatus/current_manager/login_logs', {params: params}).then(function (resp) {
|
|
|
$scope.pagination = resp.data.pagination;
|
|
|
$scope.loginLogs = resp.data.data;
|
|
|
})
|
|
|
};
|
|
|
$scope.getMyLoginLogs();
|
|
|
}]
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
}]);
|
|
|
app.filter('withRole', ['$rootScope', function ($rootScope) {
|
|
|
return function (roleCode) {
|
|
|
if (angular.isNumber(roleCode)) {
|
|
|
var code = roleCode;
|
|
|
} else {
|
|
|
code = parseInt(roleCode, 2);
|
|
|
}
|
|
|
return ($rootScope.currentUser.role & code) > 0
|
|
|
}
|
|
|
}]);
|
|
|
app.filter('withModule', ['$rootScope', function ($rootScope) {
|
|
|
return function (moduleName) {
|
|
|
return $rootScope.currentUser.module_names.indexOf(moduleName) >= 0;
|
|
|
}
|
|
|
}]);
|
|
|
app.filter('withFunc', ['$rootScope', function ($rootScope) {
|
|
|
return function (funcName) {
|
|
|
return $rootScope.currentUser.available_func_names.indexOf(funcName) >= 0;
|
|
|
}
|
|
|
}]);
|
|
|
|
|
|
app.filter('tradeStatus', function () {
|
|
|
return function (status) {
|
|
|
switch (status + '') {
|
|
|
case '0':
|
|
|
return 'Creating';
|
|
|
case '1':
|
|
|
return 'Failed Create Order';
|
|
|
case '2':
|
|
|
return 'Wait For Payment';
|
|
|
case '3':
|
|
|
return 'Closed';
|
|
|
case '4':
|
|
|
return 'Payment Failed';
|
|
|
case '5':
|
|
|
return 'Payment Successful';
|
|
|
case '6':
|
|
|
return 'Partial Refund';
|
|
|
case '7':
|
|
|
return 'Full Refund';
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
app.filter('refundStatus', function () {
|
|
|
return function (status) {
|
|
|
switch (status + '') {
|
|
|
case '0':
|
|
|
case'1':
|
|
|
return 'Submit Failed';
|
|
|
case '2':
|
|
|
return 'Submit Success';
|
|
|
case '3':
|
|
|
return 'Failed';
|
|
|
case '4':
|
|
|
return 'Success';
|
|
|
case '5':
|
|
|
return 'Change'
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
app.filter('tradeGateway', function () {
|
|
|
return function (gateway) {
|
|
|
switch (gateway + '') {
|
|
|
case '0':
|
|
|
return '线下扫码';
|
|
|
case '1':
|
|
|
return '线下扫码';
|
|
|
case '2':
|
|
|
return '商户静态码';
|
|
|
case '3':
|
|
|
return '线上网关';
|
|
|
case '4':
|
|
|
return 'JSAPI网关';
|
|
|
case '5':
|
|
|
return '线下网关';
|
|
|
case '6':
|
|
|
return '线下网关';
|
|
|
case '7':
|
|
|
return '商户静态码';
|
|
|
case '8':
|
|
|
return 'Mobile H5';
|
|
|
case '9':
|
|
|
return '第三方网关';
|
|
|
case '10':
|
|
|
return 'APP网关';
|
|
|
case '11':
|
|
|
return '账单码';
|
|
|
case '12':
|
|
|
return '小程序';
|
|
|
case '13':
|
|
|
return '原生二维码';
|
|
|
case '14':
|
|
|
return '账单链接'
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
|
|
|
app.constant('uiDatetimePickerConfig', {
|
|
|
dateFormat: 'yyyy-MM-dd HH:mm',
|
|
|
defaultTime: '00:00:00',
|
|
|
html5Types: {
|
|
|
date: 'yyyy-MM-dd',
|
|
|
'datetime-local': 'yyyy-MM-ddTHH:mm:ss.sss',
|
|
|
'month': 'yyyy-MM'
|
|
|
},
|
|
|
initialPicker: 'date',
|
|
|
reOpenDefault: false,
|
|
|
enableDate: true,
|
|
|
enableTime: true,
|
|
|
buttonBar: {
|
|
|
show: true,
|
|
|
now: {
|
|
|
show: true,
|
|
|
text: '现在'
|
|
|
},
|
|
|
today: {
|
|
|
show: true,
|
|
|
text: '今天'
|
|
|
},
|
|
|
clear: {
|
|
|
show: true,
|
|
|
text: '清空'
|
|
|
},
|
|
|
date: {
|
|
|
show: true,
|
|
|
text: '日期'
|
|
|
},
|
|
|
time: {
|
|
|
show: true,
|
|
|
text: '时间'
|
|
|
},
|
|
|
close: {
|
|
|
show: true,
|
|
|
text: '关闭'
|
|
|
}
|
|
|
},
|
|
|
closeOnDateSelection: true,
|
|
|
appendToBody: false,
|
|
|
altInputFormats: [],
|
|
|
ngModelOptions: {}
|
|
|
});
|
|
|
|
|
|
app.controller('bdRateConfigCtrl', ['$scope', '$http', 'rates', function ($scope, $http, rates) {
|
|
|
$scope.bdLevels = [{value: 1, label: 'Junior'}, {value: 2, label: 'Intermediate'}, {value: 3, label: 'Senior'}];
|
|
|
$scope.months = [{value: 1, label: '1-3 Months'}, {value: 2, label: '4-6 Months'}, {
|
|
|
value: 3,
|
|
|
label: '>=7 Months'
|
|
|
}];
|
|
|
$scope.kpiRanges = [{value: 1, label: '0-50%'}, {value: 2, label: '50%~80%'}, {value: 3, label: '80%~100%'},
|
|
|
{value: 4, label: '100%-120%'}, {value: 5, label: '>=120%'}];
|
|
|
$scope.clientRate = [{value: 0.6, label: '0.6-0.79'}, {value: 0.8, label: '0.8-2.0'}];
|
|
|
$scope.filter = {bd_level: 1,rate_from:0.6};
|
|
|
$scope.rates = rates;
|
|
|
$scope.submitRates = function () {
|
|
|
var validation = null;
|
|
|
$scope.errmsg = null;
|
|
|
angular.forEach($scope.rates, function (rate) {
|
|
|
if (isNaN(rate.prize_rate)) {
|
|
|
validation = {months: rate.time_range, bd_level: rate.bd_level};
|
|
|
$scope.errmsg = 'Rate Value is NaN';
|
|
|
}
|
|
|
if (rate.prize_rate > 1) {
|
|
|
validation = {months: rate.time_range, bd_level: rate.bd_level};
|
|
|
$scope.errmsg = 'Rate value shall no more than 1%';
|
|
|
}
|
|
|
if (rate.prize_rate < 0) {
|
|
|
validation = {months: rate.time_range, bd_level: rate.bd_level};
|
|
|
$scope.errmsg = 'Rate value shall be a positive value';
|
|
|
}
|
|
|
});
|
|
|
if (!validation) {
|
|
|
$http.put('/sys/bd_prize/config/rates', $scope.rates).then(function () {
|
|
|
$scope.$close();
|
|
|
}, function (resp) {
|
|
|
$scope.errmsg = resp.data.message;
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
}]);
|
|
|
app.controller('bdLevelConfigCtrl', ['$scope', '$http', function ($scope, $http) {
|
|
|
|
|
|
$scope.getBDGroups = function () {
|
|
|
$http.get('/sys/manager_accounts/roles/bd_leader').then(function (resp) {
|
|
|
$scope.bdgroups = resp.data;
|
|
|
$scope.getBDLevels();
|
|
|
})
|
|
|
};
|
|
|
$scope.getBDGroups();
|
|
|
$scope.getBDLevels = function () {
|
|
|
$http.get('/sys/bd_prize/config/bd_levels').then(function (resp) {
|
|
|
$scope.bds = resp.data;
|
|
|
})
|
|
|
};
|
|
|
|
|
|
$scope.bdLevels = [{value: 1, label: 'Junior'}, {value: 2, label: 'Intermediate'}, {value: 3, label: 'Senior'}];
|
|
|
$scope.updateBDLevel = function (bdInfo) {
|
|
|
$http.put('/sys/bd_prize/config/bd_levels/' + bdInfo.manager_id, bdInfo).then(function () {
|
|
|
$scope.getBDGroups();
|
|
|
}, function (resp) {
|
|
|
$scope.errmsg = resp.data.message;
|
|
|
})
|
|
|
};
|
|
|
}]);
|
|
|
return app;
|
|
|
}); |