/** * partner info in partner client * Created by yixian on 2016-07-03. */ define(['angular', 'decimal', 'uiRouter', 'ngBootSwitch', 'ngFileUpload'], function (angular, Decimal) { 'use strict'; var app = angular.module('partnerInfoApp', ['ui.router', 'frapontillo.bootstrap-switch', 'ngFileUpload']); app.config(['$stateProvider', function ($stateProvider) { $stateProvider.state('basic', { url: '/basic', templateUrl: '/static/payment/partner/templates/client_partner_detail.html', controller: 'clientPartnerDetailCtrl', resolve: { partner: ['$http', function ($http) { return $http.get('/client/partner_info'); }] } }).state('edit', { url: '/edit', templateUrl: '/static/payment/partner/templates/client_partner_edit.html', controller: 'clientPartnerEditCtrl', resolve: { partner: ['$http', function ($http) { return $http.get('/client/partner_info'); }] } }).state('basic.payment_info', { url: '/payment', templateUrl: '/static/payment/partner/templates/client_payment_info.html', controller: 'clientPaymentInfoCtrl' }).state('basic.compliance_files', { url: '/{client_moniker}/compliance_files', templateUrl: '/static/payment/partner/templates/client_compliance_files.html', controller: 'clientComplianceFilesCtrl', resolve: { file: ['$http', function ($http) { return $http.get('/client/partner_info/compliance/files'); }] } }).state('payment_materials', { url: '/payment_materials', templateUrl: '/static/payment/partner/templates/client_payment_materials.html', controller: 'clientPaymentMaterialCtrl', resolve: { partner: ['$http', function ($http) { return $http.get('/client/partner_info'); }] } }).state('basic.clearing_config', { url: '/clearing_config', templateUrl: '/static/payment/partner/templates/client_bankaccounts.html', controller: 'clientClearingConfigCtrl' }).state('parameter', { url: '/parameters', templateUrl: '/static/payment/partner/templates/client_parameter.html', controller: 'clientParameterCtrl' }).state('sub_partners', { url: '/sub_partners', templateUrl: '/static/payment/partner/templates/client_sub_partners.html', controller: 'clientSubPartnersCtrl' }).state('devices', { url: '/devices', templateUrl: '/static/payment/partner/templates/client_devices.html', controller: 'clientDeviceCtrl' }) }]); app.controller('clientPartnerDetailCtrl', ['$scope', '$http', 'partner','industryMap','businessStructuresMap','commonDialog','Upload','$state', function ($scope, $http, partner,industryMap,businessStructuresMap,commonDialog,Upload,$state) { $scope.business_structures = businessStructuresMap.configs(); $scope.industries = industryMap.configs(); $scope.partner = partner.data; $scope.partner.partner_type = $scope.partner.website ? 'website' : 'photo'; $scope.uploadLogo = function (file) { if (file != null) { if (file.size > 1 * 1024 * 1024) { commonDialog.alert({title: 'Error', content: '文件大小不能超过1MB,请压缩后重试', type: 'error'}) } else { $scope.logoProgress = {value: 0}; Upload.upload({ url: '/attachment/files', data: {file: file} }).then(function (resp) { delete $scope.logoProgress; $scope.partner.logo_id = resp.data.fileid; $scope.partner.logo_url = resp.data.url; }, function (resp) { delete $scope.logoProgress; commonDialog.alert({title: 'Upload Failed', content: resp.data.message, type: 'error'}) }, function (evt) { $scope.logoProgress.value = parseInt(100 * evt.loaded / evt.total); }) } } }; $scope.uploadShopPhoto = function (file) { if (file != null) { if (file.size > 2 * 1024 * 1024) { commonDialog.alert({title: 'Error', content: '文件大小不能超过2MB,请压缩后重试', type: 'error'}) } else { $scope.shopPhotoProgress = {value: 0}; Upload.upload({ url: '/attachment/files', data: {file: file} }).then(function (resp) { delete $scope.shopPhotoProgress; $scope.partner.company_photo = resp.data.url; }, function (resp) { delete $scope.shopPhotoProgress; commonDialog.alert({title: 'Upload Failed', content: resp.data.message, type: 'error'}) }, function (evt) { $scope.shopPhotoProgress.value = parseInt(100 * evt.loaded / evt.total); }) } } }; $scope.uploadStorePhoto = function (file) { if (file != null) { if (file.size > 2 * 1024 * 1024) { commonDialog.alert({title: 'Error', content: '文件大小不能超过2MB,请压缩后重试', type: 'error'}) } else { $scope.storePhotoProgress = {value: 0}; Upload.upload({ url: '/attachment/files', data: {file: file} }).then(function (resp) { delete $scope.storePhotoProgress; $scope.partner.store_photo = resp.data.url; }, function (resp) { delete $scope.storePhotoProgress; commonDialog.alert({title: 'Upload Failed', content: resp.data.message, type: 'error'}) }, function (evt) { $scope.storePhotoProgress.value = parseInt(100 * evt.loaded / evt.total); }) } } }; $scope.updatePartner = function (form) { if (form.$invalid) { angular.forEach(form, function (item, key) { if (key.indexOf('$') < 0) { item.$dirty = true; } }); return; } if (!$scope.partner.logo_url) { alert("Logo is necessary!"); return; } if($scope.partner.partner_type == 'photo'){ if (!$scope.partner.company_photo) { alert('Shop Photo1 is necessary'); return; } if (!$scope.partner.store_photo) { alert('Shop Photo2 is necessary'); return; } } var content = ''; $http.put('/client/partner_info/update/partnerInfo', $scope.partner).then(function () { if (content != '') { commonDialog.alert({ title: 'Warning', content: content, type: 'error' }); } else { commonDialog.alert({ title: 'Success', content: 'Update partner information successfully', type: 'success' }); } $state.go('basic', {clientMoniker: $scope.partner.client_moniker}, {reload: true}); }, function (resp) { commonDialog.alert({title: 'Error', content: resp.data.message, type: 'error'}) }); }; //修改邮箱 $scope.updateEmail = function () { $http.put('/client/partner_info/compliance_audit').then( ); }; $scope.commitToCompliance = function () { $http.get('/client/partner_info/compliance/files').then(function (resp) { $scope.complianceFiles = resp.data; if($scope.complianceFiles.client_id_file == null||$scope.complianceFiles.client_bank_file == null || $scope.complianceFiles.client_company_file == null){ commonDialog.alert({title: 'Message', content: '请前去完善合规资料,再进行提交!', type: 'info'}); return; } if($scope.partner.business_structure == null ||$scope.partner.logo_url == null || $scope.partner.description == null ||($scope.partner.partner_type == 'website' && $scope.partner.company_website == null) || ($scope.partner.partner_type == 'photo'&&($scope.partner.store_photo == null || $scope.partner.company_photo == null))){ commonDialog.alert({title: 'Message', content: '请前去完善商户资料,再进行提交!', type: 'info'}); return; } if(($scope.partner.business_structure == "Company" && $scope.partner.acn == null) || ($scope.partner.business_structure != "Company" && $scope.partner.abn == null)){ commonDialog.alert({title: 'Message', content: '请前去完善商户资料,再进行提交!', type: 'info'}); return; } if(!$scope.partner.mail_confirm){ commonDialog.alert({title: 'Message', content: '请验证邮箱后,再进行提交!', type: 'info'}); return; } commonDialog.confirm({ title: 'Commit to Compliance', content: 'Are you sure to commit ' + $scope.partner.company_name + ' to compliance?', choises: [ {label: 'Submit', className: 'btn-success', key: 1}, {label: 'Cancel', className: 'btn-warning', key: 0, dismiss: true} ] }).then(function (choice) { $scope.submitted = true; if (choice == 1) { $http.post('/client/partner_info/compliance_audit').then(function (){ commonDialog.alert({title: 'Success', content: '已提交至合规,请耐心等待审核!', type: 'info'}); $state.reload(); }, function () { $state.reload(); }); } }) }); } }]); app.controller('clientPartnerEditCtrl', ['$scope', '$http', 'commonDialog','stateMap','countryMap','partner','$state','Upload',function ($scope, $http, commonDialog,stateMap,countryMap,partner,$state,Upload) { $scope.partner = partner.data; $scope.states = stateMap.configs(); $scope.countries = countryMap.configs(); $scope.uploadLogo = function (file) { if (file != null) { if (file.size > 1 * 1024 * 1024) { commonDialog.alert({title: 'Error', content: '文件大小不能超过1MB,请压缩后重试', type: 'error'}) } else { $scope.logoProgress = {value: 0}; Upload.upload({ url: '/attachment/files', data: {file: file} }).then(function (resp) { delete $scope.logoProgress; $scope.partner.logo_id = resp.data.fileid; $scope.partner.logo_url = resp.data.url; }, function (resp) { delete $scope.logoProgress; commonDialog.alert({title: 'Upload Failed', content: resp.data.message, type: 'error'}) }, function (evt) { $scope.logoProgress.value = parseInt(100 * evt.loaded / evt.total); }) } } }; $scope.uploadShopPhoto = function (file) { if (file != null) { if (file.size > 2 * 1024 * 1024) { commonDialog.alert({title: 'Error', content: '文件大小不能超过2MB,请压缩后重试', type: 'error'}) } else { $scope.shopPhotoProgress = {value: 0}; Upload.upload({ url: '/attachment/files', data: {file: file} }).then(function (resp) { delete $scope.shopPhotoProgress; $scope.partner.company_photo = resp.data.url; }, function (resp) { delete $scope.shopPhotoProgress; commonDialog.alert({title: 'Upload Failed', content: resp.data.message, type: 'error'}) }, function (evt) { $scope.shopPhotoProgress.value = parseInt(100 * evt.loaded / evt.total); }) } } }; $scope.uploadStorePhoto = function (file) { if (file != null) { if (file.size > 2 * 1024 * 1024) { commonDialog.alert({title: 'Error', content: '文件大小不能超过2MB,请压缩后重试', type: 'error'}) } else { $scope.storePhotoProgress = {value: 0}; Upload.upload({ url: '/attachment/files', data: {file: file} }).then(function (resp) { delete $scope.storePhotoProgress; $scope.partner.store_photo = resp.data.url; }, function (resp) { delete $scope.storePhotoProgress; commonDialog.alert({title: 'Upload Failed', content: resp.data.message, type: 'error'}) }, function (evt) { $scope.storePhotoProgress.value = parseInt(100 * evt.loaded / evt.total); }) } } }; $scope.updatePartner = function (form) { if (form.$invalid) { angular.forEach(form, function (item, key) { if (key.indexOf('$') < 0) { item.$dirty = true; } }); return; } if (!$scope.partner.logo_url) { alert("Logo is necessary!"); return; } if($scope.partner.partner_type == 'photo'){ if (!$scope.partner.company_photo) { alert('Shop Photo1 is necessary'); return; } if (!$scope.partner.store_photo) { alert('Shop Photo2 is necessary'); return; } } var content = ''; $http.put('/client/partner_info/update/partnerInfo', $scope.partner).then(function () { if (content != '') { commonDialog.alert({ title: 'Warning', content: content, type: 'error' }); } else { commonDialog.alert({ title: 'Success', content: 'Update partner information successfully', type: 'success' }); } $state.go('basic', {reload: true}); }, function (resp) { commonDialog.alert({title: 'Error', content: resp.data.message, type: 'error'}) }); }; }]); app.controller('clientComplianceFilesCtrl', ['$scope', '$http', '$rootScope', 'commonDialog', '$state', 'Upload', 'file', function ($scope, $http, $rootScope, commonDialog, $state, Upload, file) { $scope.file = file.data || {}; //audit files $scope.uploadBankFile = function (file) { if (file != null) { if (file.size > 3 * 1024 * 1024) { commonDialog.alert({title: 'Error', content: '文件大小不能超过3MB,请压缩后重试', type: 'error'}) } else { $scope.bankFileProgress = {value: 0}; Upload.upload({ url: '/attachment/files', data: {file: file} }).then(function (resp) { delete $scope.bankFileProgress; $scope.file.file_bank_info = resp.data.url; $scope.updateFile(); if ($scope.file.file_bank_info.endsWith('pdf')) { $scope.bankIsImage = false; } else { $scope.bankIsImage = true; } }, function (resp) { delete $scope.bankFileProgress; commonDialog.alert({title: 'Upload Failed', content: resp.data.message, type: 'error'}) }, function (evt) { $scope.bankFileProgress.value = parseInt(100 * evt.loaded / evt.total); }) } } }; $scope.agreeIsImage = true; if ($scope.file.file_agreement_info && $scope.file.file_agreement_info.endsWith('pdf')) { $scope.agreeIsImage = false; } $scope.bankIsImage = true; if ($scope.file.file_bank_info && $scope.file.file_bank_info.endsWith('pdf')) { $scope.bankIsImage = false; } $scope.companyIsImage = true; if ($scope.file.file_company_info && $scope.file.file_company_info.endsWith('pdf')) { $scope.companyIsImage = false; } $scope.applyIsImage = true; if ($scope.file.file_apply_info && $scope.file.file_apply_info.endsWith('pdf')) { $scope.applyIsImage = false; } $scope.idIsImage = true; if ($scope.file.file_id_info && $scope.file.file_id_info.endsWith('pdf')) { $scope.idIsImage = false; } $scope.uploadCompanyFile = function (file) { if (file != null) { if (file.size > 3 * 1024 * 1024) { commonDialog.alert({title: 'Error', content: '文件大小不能超过3MB,请压缩后重试', type: 'error'}) } else { $scope.companyFileProgress = {value: 0}; Upload.upload({ url: '/attachment/files', data: {file: file} }).then(function (resp) { delete $scope.companyFileProgress; $scope.file.file_company_info = resp.data.url; $scope.updateFile(); if ($scope.file.file_company_info.endsWith('pdf')) { $scope.companyIsImage = false; } else { $scope.companyIsImage = true; } }, function (resp) { delete $scope.companyFileProgress; commonDialog.alert({title: 'Upload Failed', content: resp.data.message, type: 'error'}) }, function (evt) { $scope.companyFileProgress.value = parseInt(100 * evt.loaded / evt.total); }) } } }; //上传ID信息 $scope.uploadIDFile = function (file) { if (file != null) { if (file.size > 3 * 1024 * 1024) { commonDialog.alert({title: 'Error', content: '文件大小不能超过3MB,请压缩后重试', type: 'error'}) } else { $scope.idFileProgress = {value: 0}; Upload.upload({ url: '/attachment/files', data: {file: file} }).then(function (resp) { delete $scope.idFileProgress; $scope.file.file_id_info = resp.data.url; $scope.updateFile(); if ($scope.file.file_id_info.endsWith('pdf')) { $scope.idIsImage = false; } else { $scope.idIsImage = true; } }, function (resp) { delete $scope.idFileProgress; commonDialog.alert({title: 'Upload Failed', content: resp.data.message, type: 'error'}) }, function (evt) { $scope.idFileProgress.value = parseInt(100 * evt.loaded / evt.total); }) } } }; //上传协议文件 $scope.uploadAgreementFile = function (file) { if (file != null) { if (file.size > 10 * 1024 * 1024) { commonDialog.alert({title: 'Error', content: '文件大小不能超过5MB,请压缩后重试', type: 'error'}) } else { $scope.agreementFileProgress = {value: 0}; Upload.upload({ url: '/attachment/files', data: {file: file} }).then(function (resp) { delete $scope.agreementFileProgress; $scope.file.file_agreement_info = resp.data.url; $scope.updateFile(); if ($scope.file.file_agreement_info.endsWith('pdf')) { $scope.agreeIsImage = false; } else { $scope.agreeIsImage = true; } }, function (resp) { delete $scope.agreementFileProgress; commonDialog.alert({title: 'Upload Failed', content: resp.data.message, type: 'error'}) }, function (evt) { $scope.agreementFileProgress.value = parseInt(100 * evt.loaded / evt.total); }) } } }; //上传申请表 $scope.uploadApplyFile = function (file) { if (file != null) { if (file.size > 3 * 1024 * 1024) { commonDialog.alert({title: 'Error', content: '文件大小不能超过3MB,请压缩后重试', type: 'error'}) } else { $scope.applyFileProgress = {value: 0}; Upload.upload({ url: '/attachment/files', data: {file: file} }).then(function (resp) { delete $scope.applyFileProgress; $scope.file.file_apply_info = resp.data.url; $scope.updateFile(); if ($scope.file.file_apply_info.endsWith('pdf')) { $scope.applyIsImage = false; } else { $scope.applyIsImage = true; } }, function (resp) { delete $scope.applyFileProgress; commonDialog.alert({title: 'Upload Failed', content: resp.data.message, type: 'error'}) }, function (evt) { $scope.applyFileProgress.value = parseInt(100 * evt.loaded / evt.total); }) } } }; /* $scope.downloadAsZip = function () { var url = '/sys/partners/' + $scope.partner.client_moniker + '/download/complianceAsZIP'; return url; }; */ $scope.updateFile = function () { $http.put('/client/partner_info/update/file', $scope.file).then(function () { commonDialog.alert({ title: 'Success', content: 'Upload Successful', type: 'success' }); $state.reload(); }, function (resp) { commonDialog.alert({title: 'Error', content: resp.data.message, type: 'error'}); }) }; function commitError() { commonDialog.alert({ title: 'Error', content: 'Missing file', type: 'error' }); }; $scope.commitPartner = function () { if ($scope.file) { if ($scope.file.file_bank_info != null && $scope.file.file_company_info != null && $scope.file.file_id_info != null && $scope.file_apply_info != null) { $http.put('/client/partner_info/compliance_audit').then(function (resp) { }); } else { commitError(); } } else { commitError(); } }; }]); app.controller('clientPaymentInfoCtrl', ['$scope', '$http', 'commonDialog', function ($scope, $http, commonDialog) { $scope.paymentInfo = $scope.partner; $scope.old_customer_surcharge_rate = angular.copy($scope.partner.customer_surcharge_rate); $scope.qrConfig = {currency: 'AUD'}; $scope.clientCopyHfLink = function() { var e=document.getElementById("c-cpbt"); e.select(); var successful = document.execCommand("Copy"); if (successful) { commonDialog.alert({title: 'Success', content: '已复制到剪切板!', type: 'success'}); }else { commonDialog.alert({title: 'Error', content: '您的浏览器不支持!', type: 'error'}); } }; $scope.reloadQRCode = function () { $http.get('/client/partner_info/qrcode', {params: $scope.qrConfig}).then(function (resp) { $scope.qrcode = resp.data; }); }; $scope.ctrl = {}; $scope.reloadQRCode(); $scope.changePaymentPage = function () { if (!$scope.paymentInfo) { return; } $http.put('/client/partner_info/payment_page_version', {paypad_version: $scope.paymentInfo.paypad_version}).then(function () { // $scope.loadPartnerPaymentInfo(); }, function (resp) { commonDialog.alert({ title: 'failed to change Payment Page Version', content: resp.data.message, type: 'error' }) }) }; $scope.saveCustomerSurchargeRate = function (cofig) { if (cofig != null && isNaN(cofig)) { commonDialog.alert({title: 'Error', content: 'Your input is not a number!', type: 'error'}); return; } if (cofig > 2 || cofig < parseFloat(Decimal.add($scope.paymentInfo.rate_value, 0.1).toFixed(2))) { commonDialog.alert({title: 'Error', content: 'Not in the valid range', type: 'error'}); return; } $http.put('/client/partner_info/customer_surcharge_rate', {customer_surcharge_rate: cofig}).then(function (resp) { // $scope.loadPartnerPaymentInfo(); $scope.ctrl.editCustomerSurchargeRate = false; }, function (resp) { commonDialog.alert({title: 'Error', content: resp.data.message, type: 'error'}); }) }; $scope.updateClientQRCodePaySurCharge = function () { if (!$scope.paymentInfo) { return; } if (!$scope.ctrl.init_qr_surcharge) { $scope.ctrl.init_qr_surcharge = true; return; } $http.put('/client/partner_info/qrcode_surcharge', {qrcode_surcharge: $scope.paymentInfo.qrcode_surcharge}).then(function () { // $scope.loadPartnerPaymentInfo(); }, function (resp) { commonDialog.alert({ title: 'failed to change Customer Pay for Surcharge for QR Code', content: resp.data.message, type: 'error' }) }) }; $scope.updateClientApiPaySurCharge = function () { if (!$scope.paymentInfo) { return; } if (!$scope.ctrl.init_api_surcharge) { $scope.ctrl.init_api_surcharge = true; return; } $http.put('/client/partner_info/api_surcharge', {api_surcharge: $scope.paymentInfo.api_surcharge}).then(function () { // $scope.loadPartnerPaymentInfo(); }, function (resp) { commonDialog.alert({ title: 'failed to change Customer Pay for Surcharge for Gateway', content: resp.data.message, type: 'error' }) }) }; $scope.updateClientRetailPaySurCharge = function () { if (!$scope.paymentInfo) { return; } if (!$scope.ctrl.init_retail_surcharge) { $scope.ctrl.init_retail_surcharge = true; return; } $http.put('/client/partner_info/retail_surcharge', {retail_surcharge: $scope.paymentInfo.retail_surcharge}).then(function () { // $scope.loadPartnerPaymentInfo(); }, function (resp) { commonDialog.alert({ title: 'failed to change Customer Pay for Surcharge for Retail', content: resp.data.message, type: 'error' }) }) } $scope.toggleRequireCustInfo = function () { if (!$scope.paymentInfo) { return; } if (!$scope.ctrl.require_custinfo) { $scope.ctrl.require_custinfo = true; return; } $http.put('/client/partner_info/require_custinfo', {require_custinfo: $scope.paymentInfo.require_custinfo}).then(function () { }, function (resp) { commonDialog.alert({ title: 'failed to change require customer Info permission status', content: resp.data.message, type: 'error' }) }) }; $scope.toggleRequireRemark = function () { if (!$scope.paymentInfo) { return; } if (!$scope.ctrl.require_remark) { $scope.ctrl.require_remark = true; return; } $http.put('/client/partner_info/require_remark', {require_remark: $scope.paymentInfo.require_remark}).then(function () { }, function (resp) { commonDialog.alert({ title: 'failed to change require remark permission status', content: resp.data.message, type: 'error' }) }) }; $scope.myInterval = 2000; $scope.first = true; $scope.active = 0; $scope.show = false; var slides = $scope.slides = []; var addSlide = function () { slides.push({ image: '/static/images/hfpaylink_intro/hf_pay_step1.png', text: '第一次打开支付链接进行下单,第一步用微信扫码页面弹出的二维码,确认您的身份', id:0 }); slides.push({ image: '/static/images/hfpaylink_intro/hf_pay_step2.png', text: '下一步,填写订单信息。注意订单金额货币单位是澳元(AUD)。请认真填写商品名称,否则可能导致交易不成功。填写完成,最后提交订单。', id:1 }); slides.push({ image: '/static/images/hfpaylink_intro/hf_pay_step3.png', text: '跳转到汇付支付页面,选择您的支付方式,同时填写姓名、身份证、银行卡号、手机号信息,完成身份验证,最后点击“确认支付”', id:2 }); slides.push({ image: '/static/images/hfpaylink_intro/hf_pay_step4.png', text: '页面弹出支付二维码,使用相应的支付app进行扫码支付。', id:3 }); slides.push({ image: '/static/images/hfpaylink_intro/hf_pay_step5.png', text: '完成支付,跳转到支付成功页面。', id:4 }); }; $scope.toFirst = function () { if(!$scope.first) { return; } addSlide(); $scope.first = false; }; $scope.toShow = function () { $scope.show = true; }; $scope.toHide = function () { $scope.show = false } }]); app.controller('clientPaymentMaterialCtrl', ['$scope', '$http', 'partner', function ($scope, $http, partner) { $scope.paymentInfo = partner.data; $scope.qrConfig = {currency: 'AUD'}; $scope.reloadQRCode = function () { $http.get('/client/partner_info/qrcode', {params: $scope.qrConfig}).then(function (resp) { $scope.qrcode = resp.data; }); }; $scope.reloadQRCode(); }]); app.controller('clientParameterCtrl', ['$scope', '$http', 'commonDialog', 'timezone', function ($scope, $http, commonDialog, timezone) { $scope.getClientConfig = function () { $http.get('/client/partner_info').then(function (resp) { $scope.config = resp.data; }); }; $scope.timezones = timezone.configs(); $scope.getClientConfig(); $scope.switchNotice = function () { if (!$scope.config) { return; } $http.put('/client/partner_info/pay_notice', {enable: $scope.config.enable_pay_notice}).then(function () { $scope.getClientConfig(); }, function (resp) { commonDialog.alert({title: 'Failed', message: resp.data.message, type: 'error'}) }); }; $scope.switchAuditRefund = function () { if (!$scope.config) { return; } $http.put('/client/partner_info/audit_refund', {enable: $scope.config.enable_refund_auth}).then(function () { $scope.getClientConfig(); }, function (resp) { commonDialog.alert({title: 'Failed', message: resp.data.message, type: 'error'}) }); }; $scope.updateTimeZone = function () { if (!$scope.config) { return; } $http.put('/client/partner_info/timezone', {timezone: $scope.config.timezone}).then(function () { $scope.getClientConfig(); }, function (resp) { commonDialog.alert({title: 'Failed', message: resp.data.message, type: 'error'}) }) } }]); app.controller('clientClearingConfigCtrl', ['$scope', '$http','$state','commonDialog', function ($scope, $http,$state,commonDialog) { $scope.bankCtrl = {rate_name:'Wechat'}; $scope.init = {manual:false}; $scope.getBankAccount = function () { $http.get('/client/partner_info/bank_account').then(function (resp) { $scope.bankaccount = resp.data; }); }; $scope.getBankAccount(); $scope.getRates = function () { $http.get('/client/partner_info/rates').then(function (resp) { $scope.rates = resp.data; angular.forEach($scope.rates, function (rate) { rate.active_time = new Date(rate.active_time); rate.expiry_time = new Date(rate.expiry_time); }) }); }; $scope.manualSettle = function (manualSettle) { if(!$scope.init.manual){ $scope.init.manual = true; return; } var waring_messsage; if(manualSettle){ waring_messsage = "Open" }else { waring_messsage = "Close" } commonDialog.confirm({ title: 'Confirmation', content: 'Are you sure to '+waring_messsage+'?', }).then(function(){ $http.put('/client/partner_info/manual_settle?'+'manual_settle='+manualSettle).then(function (resp) { },function (resp) { commonDialog.alert({title: 'Error!', content: resp.data.message, type: 'error'}) }) },function () { $state.reload(); }); }; $scope.getRates(); }]); app.controller('clientSubPartnersCtrl', ['$scope', '$http', function ($scope, $http) { $scope.loadSubPartners = function () { $http.get('/client/partner_info/sub_partners').then(function (resp) { $scope.subPartners = resp.data; }) }; $scope.loadSubPartners(); }]); app.controller('clientDeviceCtrl', ['$scope', '$http', 'orderService', 'commonDialog', 'refunder','$filter', function ($scope, $http, orderService, commonDialog, refunder,$filter) { $scope.pagination = {}; $scope.params = {}; $scope.listDevices = function (page) { var params = angular.copy($scope.devsearch) || {}; params.page = page || $scope.pagination.page || 1; $http.get('/client/partner_info/devices', {params: params}).then(function (resp) { $scope.pagination = resp.data.pagination; $scope.devices = resp.data.data; }) }; $scope.listDevices(1); $scope.showDeviceOrders = function (dev) { $scope.params.dev_id = dev.dev_id; $scope.listOrders(1); }; $scope.modifyRemark = function (dev) { commonDialog.inputText({title: 'Input New Remark of device'}).then(function (text) { $http.put('/client/partner_info/devices/' + dev.dev_id, {remark: text}).then(function () { $scope.listDevices(); }, function (resp) { commonDialog.alert({title: 'Update remark failed', content: resp.data.message, type: 'error'}); }) }) }; $scope.disableDevice = function (dev) { $http.put('/client/partner_info/devices/' + dev.dev_id + '/enable', {enable: false}).then(function () { $scope.listDevices() }, function (resp) { commonDialog.alert({title: 'Failed to disable device', content: resp.data.message, type: 'error'}); }); }; $scope.enableDevice = function (dev) { $http.put('/client/partner_info/devices/' + dev.dev_id + '/enable', {enable: true}).then(function () { $scope.listDevices() }, function (resp) { commonDialog.alert({title: 'Failed to enable device', content: resp.data.message, type: 'error'}); }); }; $scope.orderPagination = {}; $scope.today = new Date(); $scope.chooseToday = function () { $scope.params.datefrom = $scope.params.dateto = new Date(); $scope.listOrders(1); }; $scope.chooseYesterday = function () { var yesterday = new Date(); yesterday.setDate(yesterday.getDate() - 1); $scope.params.datefrom = $scope.params.dateto = yesterday; $scope.listOrders(1); }; $scope.chooseLast7Days = function () { $scope.params.dateto = new Date(); var day = new Date(); day.setDate(day.getDate() - 7); $scope.params.datefrom = day; $scope.listOrders(1); }; $scope.thisMonth = function () { $scope.params.dateto = new Date(); var monthBegin = new Date(); monthBegin.setDate(1); $scope.params.datefrom = monthBegin; $scope.listOrders(1); }; $scope.lastMonth = function () { var monthFinish = new Date(); monthFinish.setDate(0); $scope.params.dateto = monthFinish; var monthBegin = new Date(); monthBegin.setDate(0); monthBegin.setDate(1); $scope.params.datefrom = monthBegin; $scope.listOrders(1); }; $scope.listOrders = function (page) { var params = angular.copy($scope.params) || {}; if (params.datefrom) { params.datefrom = $filter('date')(params.datefrom, 'yyyyMMdd'); } if (params.dateto) { params.dateto = $filter('date')(params.dateto, 'yyyyMMdd'); } params.gateway = [0, 1]; params.page = page || $scope.orderPagination.page || 1; $http.get('/client/partner_info/trade_logs', {params: params}).then(function (resp) { $scope.orders = resp.data.data; $scope.orderPagination = resp.data.pagination; $scope.analysis = resp.data.analysis; }); }; $scope.listOrders(1); $scope.orderDetail = function (order) { orderService.clientOrderDetail(order) }; $scope.refundOrder = function (order) { refunder.refunded(order.order_id) }; }]); return app; });