From ae8d4a66bab84d590435f7f4c47a2c64f477ba53 Mon Sep 17 00:00:00 2001 From: yuan <1551130722@qq.com> Date: Thu, 3 May 2018 15:22:22 +0800 Subject: [PATCH] fix html~ --- .../core/MerchantIdManageService.java | 3 + .../impl/MerchantIdManageServiceImpl.java | 57 ++++- .../web/MerchantIdManageController.java | 7 + .../payment/merchantid/merchant_id_manager.js | 138 ++++++----- .../templates/client_sub_merchant_id.html | 27 +- .../templates/merchant_id_manage.html | 230 +++++++++--------- .../templates/no_trade_sub_merchant_id.html | 43 ++++ .../templates/temp_sub_merchant_id.html | 38 +++ 8 files changed, 344 insertions(+), 199 deletions(-) create mode 100644 src/main/ui/static/payment/merchantid/templates/no_trade_sub_merchant_id.html create mode 100644 src/main/ui/static/payment/merchantid/templates/temp_sub_merchant_id.html diff --git a/src/main/java/au/com/royalpay/payment/manage/merchantid/core/MerchantIdManageService.java b/src/main/java/au/com/royalpay/payment/manage/merchantid/core/MerchantIdManageService.java index ec5912ba7..b7d0f8503 100644 --- a/src/main/java/au/com/royalpay/payment/manage/merchantid/core/MerchantIdManageService.java +++ b/src/main/java/au/com/royalpay/payment/manage/merchantid/core/MerchantIdManageService.java @@ -20,4 +20,7 @@ public interface MerchantIdManageService { void save(JSONObject record); void disable(String sub_merchant_id); + + JSONObject getClientQrCodeImg(JSONObject manager,String sub_merchant_id); + } diff --git a/src/main/java/au/com/royalpay/payment/manage/merchantid/core/impl/MerchantIdManageServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/merchantid/core/impl/MerchantIdManageServiceImpl.java index c1fe7f0f1..60240ddc9 100644 --- a/src/main/java/au/com/royalpay/payment/manage/merchantid/core/impl/MerchantIdManageServiceImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/merchantid/core/impl/MerchantIdManageServiceImpl.java @@ -7,17 +7,28 @@ import au.com.royalpay.payment.manage.mappers.client.ClientSubMerchantIdMapper; import au.com.royalpay.payment.manage.mappers.payment.CommonSubMerchantIdMapper; import au.com.royalpay.payment.manage.mappers.system.ClientMapper; import au.com.royalpay.payment.manage.merchantid.core.MerchantIdManageService; -import au.com.royalpay.payment.tools.env.PlatformEnvironment; import au.com.royalpay.payment.tools.env.SysConfigManager; import au.com.royalpay.payment.tools.exceptions.BadRequestException; +import au.com.royalpay.payment.tools.exceptions.ServerErrorException; +import cn.yixblog.platform.http.HttpRequestGenerator; +import cn.yixblog.platform.http.HttpRequestResult; import com.alibaba.fastjson.JSONObject; import com.github.miemiedev.mybatis.paginator.domain.Order; import com.github.miemiedev.mybatis.paginator.domain.PageBounds; -import org.apache.commons.lang3.StringUtils; +import org.apache.commons.codec.digest.DigestUtils; +import org.apache.commons.lang3.RandomStringUtils; +import org.apache.commons.lang3.time.DateFormatUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.RequestMethod; +import sun.text.normalizer.NormalizerBase; import javax.annotation.Resource; +import java.io.IOException; +import java.net.URISyntaxException; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -47,6 +58,8 @@ public class MerchantIdManageServiceImpl implements MerchantIdManageService { @Resource private MpPaymentApi mpPaymentApi; + private Logger logger = LoggerFactory.getLogger(getClass()); + @Override public Map> listSubMerchantId(JSONObject manager) { @@ -130,4 +143,44 @@ public class MerchantIdManageServiceImpl implements MerchantIdManageService { Map> clientsMap = clients.stream().filter(t->t.containsKey("merchant_id")).filter(t->t.containsKey("sub_merchant_id")).collect(Collectors.groupingBy(t->t.getString("merchant_id"))); return clientsMap; } + + @Override + public JSONObject getClientQrCodeImg(JSONObject manager,String sub_merchant_id) { + List clientMonikers = showClientMoniker(manager,sub_merchant_id); + if(clientMonikers.isEmpty()){ + throw new BadRequestException("当前子商户号下暂无商户"); + } + String partner_code = clientMonikers.get(0).getString("client_moniker"); + String orderId = "Merchant" + DateFormatUtils.format(new Date(), "yyyyMMddHHmmss") + "_" + RandomStringUtils.random(5, true, true).toUpperCase(); + JSONObject param = new JSONObject(); + param.put("price", 10); + param.put("description", "order"); + param.put("operator", "web"); + param.put("currency","CNY"); + String createUrl= "https://mpay.royalpay.com.au/api/v1.0/gateway/partners/" + partner_code + "/orders/" + orderId + "?" + queryParams(partner_code); + + HttpRequestResult result = null; + try { + result = new HttpRequestGenerator(createUrl, RequestMethod.PUT).setJSONEntity(param).execute(); + } catch (URISyntaxException e) { + e.printStackTrace(); + } + if (result.isSuccess()) { + try { + return result.getResponseContentJSONObj(); + } catch (IOException e) { + throw new ServerErrorException(e.getMessage(), e); + } + } + return null; + } + + private String queryParams(String client_moniker) { + JSONObject client = clientMapper.findClientByMoniker(client_moniker); + long time = System.currentTimeMillis(); + String nonceStr = RandomStringUtils.random(15, true, true); + String validStr = client_moniker + "&" + time + "&" + nonceStr + "&" + client.getString("credential_code"); + String sign = DigestUtils.sha256Hex(validStr).toLowerCase(); + return "time=" + time + "&nonce_str=" + nonceStr + "&sign=" + sign; + } } diff --git a/src/main/java/au/com/royalpay/payment/manage/merchantid/web/MerchantIdManageController.java b/src/main/java/au/com/royalpay/payment/manage/merchantid/web/MerchantIdManageController.java index ea706e83b..27a6a44d8 100644 --- a/src/main/java/au/com/royalpay/payment/manage/merchantid/web/MerchantIdManageController.java +++ b/src/main/java/au/com/royalpay/payment/manage/merchantid/web/MerchantIdManageController.java @@ -32,6 +32,7 @@ public class MerchantIdManageController { return merchantIdManageService.listSubMerchantId(manager); } + @RequestMapping(method = RequestMethod.GET,value = "/trade") @RequireManager(role = {ManagerRole.OPERATOR}) public JSONObject listNotTradeSubMerchantId(@ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager) { @@ -72,4 +73,10 @@ public class MerchantIdManageController { public void disableCommonSubMerchantId(@PathVariable String sub_merchant_id) { merchantIdManageService.disable(sub_merchant_id); } + + @RequestMapping(value = "/qrcode/{sub_merchant_id}", method = RequestMethod.PUT) + @RequireManager(role = {ManagerRole.OPERATOR}) + public JSONObject getClientQrCodeImg(@PathVariable String sub_merchant_id,@ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager) { + return merchantIdManageService.getClientQrCodeImg(manager,sub_merchant_id); + } } diff --git a/src/main/ui/static/payment/merchantid/merchant_id_manager.js b/src/main/ui/static/payment/merchantid/merchant_id_manager.js index 87dbcbe51..e78dddfcd 100644 --- a/src/main/ui/static/payment/merchantid/merchant_id_manager.js +++ b/src/main/ui/static/payment/merchantid/merchant_id_manager.js @@ -1,90 +1,114 @@ define(['angular', 'static/commons/commons', 'uiBootstrap', 'uiRouter', 'ngBootSwitch', 'ngFileUpload', 'uiSelect'], function (angular) { 'use strict'; - var app = angular.module('merchantIdManage', ['ui.bootstrap', 'ui.router', 'frapontillo.bootstrap-switch', 'ngFileUpload', 'ui.select']); + var app = angular.module('merchantIdManage', ['ui.bootstrap', 'ui.router', 'ngFileUpload', 'ui.select']); app.config(['$stateProvider', function ($stateProvider) { $stateProvider.state('merchant_id_manage', { - url: '/merchant_id/manage', + url: '/merchant_id_manage', templateUrl: '/static/payment/merchantid/templates/merchant_id_manage.html', - controller: 'merchantIdManageCtrl', - data: {label: '商户号列表'} + controller: 'merchantIdManageCtrl' + }).state('merchant_id_manage.no_trace_list', { + url: '/no_trace_list', + templateUrl: '/static/payment/merchantid/templates/no_trade_sub_merchant_id.html', + controller: 'noTradeSubMerchantIdCtrl' + }).state('merchant_id_manage.temp_list', { + url: '/temp_list', + templateUrl: '/static/payment/merchantid/templates/temp_sub_merchant_id.html', + controller: 'tempSubMerchantId' }) }]); - app.controller('merchantIdManageCtrl', ['$scope', '$state', '$http', '$uibModal', 'commonDialog', function ($scope, $state, $http,$uibModal,commonDialog) { - $scope.pagination = {}; - $scope.params = {}; + app.controller('merchantIdManageCtrl', ['$scope', '$state', '$http', function ($scope, $state, $http) { $scope.isCollapsed = true; + $scope.toShow = false; + $scope.client_loading = true; $scope.loadClient = function () { - $scope.client_loading = true; - $http.get('/sys/merchant_id').then(function (resp) { - $scope.clientsMap = resp.data; - $scope.client_loading = false; - }); + $http.get('/sys/merchant_id').then(function (resp) { + $scope.clientsMap = resp.data; + $scope.client_loading = false; + }); }; $scope.loadClient(); - $scope.loadNotTradeClient = function () { + + $scope.showClient = function (sub_merchant_id) { + if($scope.sub_merchant_id == sub_merchant_id){ + return; + } + $http.get('/sys/merchant_id/'+sub_merchant_id).then(function (resp) { + $scope.client_monikers= resp.data; + $scope.sub_merchant_id = sub_merchant_id; + }); + }; + }]); + app.controller('noTradeSubMerchantIdCtrl', ['$scope', '$state', '$http','$uibModal', function ($scope, $state, $http,$uibModal) { + $scope.pagination = {}; + $scope.params = {}; + $scope.isCollapsed = true; + + $scope.loadNotTradeClient = function () { + $scope.disable_button = true; $http.get('/sys/merchant_id/trade').then(function (resp) { $scope.notTradeClientsMap = resp.data.merchant_id_map; $scope.refresh_time = resp.data.refresh_time; $scope.disable_button = false; }); - }; - $scope.loadNotTradeClient(); - - $scope.loadTempSubMerchantId = function () { - var params = angular.copy($scope.params); - if(!params.sub_merchant_id){ - delete params.sub_merchant_id; - } - $http.get('/sys/merchant_id/common_sub_merchant_id',{params: params}).then(function (resp) { - $scope.subMerchantIdList= resp.data; - }); - }; - $scope.loadTempSubMerchantId(); - $scope.showClient = function (sub_merchant_id) { - $uibModal.open({ - templateUrl: '/static/payment/merchantid/templates/client_sub_merchant_id.html', - controller: 'showClientsCtrl', - resolve: { - clients: ['$http', function ($http) { - return $http.get('/sys/merchant_id/'+sub_merchant_id); - }] - }, - size: 'sm' - }) }; + $scope.loadNotTradeClient(); $scope.refresh = function () { $scope.disable_button = true; - $http.post('/sys/merchant_id/refresh').then(function (resp) { + $http.post('/sys/merchant_id/refresh').then(function () { $scope.loadNotTradeClient(); }); }; - $scope.save = function () { + $scope.showClient = function (sub_merchant_id) { $uibModal.open({ - templateUrl: '/static/payment/merchantid/templates/new_common_sub_merchant_id.html', - controller: 'newCommonSubMerchantIdCtrl' - }).result.then(function () { - $scope.loadTempSubMerchantId() + templateUrl: '/static/payment/merchantid/templates/client_sub_merchant_id.html', + controller: 'showClientsCtrl', + resolve: { + qrJson: ['$http', function ($http) { + return $http.put('/sys/merchant_id/qrcode/'+sub_merchant_id); + }] + }, + size: 'sm' }) - } - $scope.disable = function (sub_merchant_id) { - $http.put('/sys/merchant_id/common_sub_merchant_id/'+sub_merchant_id).then(function (resp) { - commonDialog.alert({title: 'Success', content: 'Success', type: 'success'}); - $scope.loadTempSubMerchantId(); - },function (resp) { - commonDialog.alert({title: 'Error', content: resp.data.message, type: 'error'}); - }); - } - - + }; + }]); + app.controller('showClientsCtrl', ['$scope', '$http','qrJson', function ($scope, $http,qrJson) { + $scope.qrJson = qrJson.data; }]); + app.controller('tempSubMerchantId', ['$scope', '$state', '$http', '$uibModal', 'commonDialog', function ($scope, $state, $http,$uibModal,commonDialog) { + $scope.pagination = {}; + $scope.params = {}; - app.controller('showClientsCtrl', ['$scope', '$http','clients', function ($scope, $http,clients) { - $scope.clients = clients.data; + $scope.loadTempSubMerchantId = function () { + var params = angular.copy($scope.params); + if(!params.sub_merchant_id){ + delete params.sub_merchant_id; + } + $http.get('/sys/merchant_id/common_sub_merchant_id',{params: params}).then(function (resp) { + $scope.subMerchantIdList= resp.data; + }); + }; + $scope.loadTempSubMerchantId(); + $scope.save = function () { + $uibModal.open({ + templateUrl: '/static/payment/merchantid/templates/new_common_sub_merchant_id.html', + controller: 'newCommonSubMerchantIdCtrl' + }).result.then(function () { + $scope.loadTempSubMerchantId() + }) + }; + $scope.disable = function (sub_merchant_id) { + $http.put('/sys/merchant_id/common_sub_merchant_id/'+sub_merchant_id).then(function (resp) { + commonDialog.alert({title: 'Success', content: 'Success', type: 'success'}); + $scope.loadTempSubMerchantId(); + },function (resp) { + commonDialog.alert({title: 'Error', content: resp.data.message, type: 'error'}); + }); + } }]); - app.controller('newCommonSubMerchantIdCtrl', ['$scope', '$http','commonDialog','$state', function ($scope, $http,commonDialog,$state) { + app.controller('newCommonSubMerchantIdCtrl', ['$scope', '$http','commonDialog', function ($scope, $http,commonDialog) { $scope.params = {}; $scope.saveSubMerchantId = function () { var params = angular.copy($scope.params); diff --git a/src/main/ui/static/payment/merchantid/templates/client_sub_merchant_id.html b/src/main/ui/static/payment/merchantid/templates/client_sub_merchant_id.html index e2460c5dc..91d684891 100644 --- a/src/main/ui/static/payment/merchantid/templates/client_sub_merchant_id.html +++ b/src/main/ui/static/payment/merchantid/templates/client_sub_merchant_id.html @@ -1,26 +1,3 @@ - - -