diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/system/SysWxMerchantApplyMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/system/SysWxMerchantApplyMapper.java index 44400c1fa..496860b2e 100644 --- a/src/main/java/au/com/royalpay/payment/manage/mappers/system/SysWxMerchantApplyMapper.java +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/system/SysWxMerchantApplyMapper.java @@ -5,6 +5,7 @@ import cn.yixblog.support.mybatis.autosql.annotations.AutoMapper; import cn.yixblog.support.mybatis.autosql.annotations.AutoSql; import cn.yixblog.support.mybatis.autosql.annotations.SqlType; import com.alibaba.fastjson.JSONObject; +import com.github.miemiedev.mybatis.paginator.domain.PageBounds; import org.apache.ibatis.annotations.Param; import javax.validation.constraints.Max; @@ -16,11 +17,9 @@ import java.util.List; @AutoMapper(tablename = "sys_wx_merchant_apply",pkName = "merchant_app_id") public interface SysWxMerchantApplyMapper { @AutoSql(type = SqlType.SELECT) - List listWxMerchantApplices(@Param("client_id") int client_id); + List listWxMerchantApplices(@Param("client_id") int client_id, PageBounds pageBounds); @AutoSql(type = SqlType.INSERT) void insertWxMerchantApply(JSONObject params); - @AutoSql(type = SqlType.UPDATE) - void updateWxMerchantApply(JSONObject params); } diff --git a/src/main/java/au/com/royalpay/payment/manage/merchants/beans/SubMerchantIdApply.java b/src/main/java/au/com/royalpay/payment/manage/merchants/beans/SubMerchantIdApply.java index 317eaa981..4d1a843a4 100644 --- a/src/main/java/au/com/royalpay/payment/manage/merchants/beans/SubMerchantIdApply.java +++ b/src/main/java/au/com/royalpay/payment/manage/merchants/beans/SubMerchantIdApply.java @@ -17,6 +17,10 @@ public class SubMerchantIdApply { @JSONField(name = "company_name") private String merchant_name; @NotBlank(message = "error.payment.valid.param_missing") + @Length(max = 10) + @JSONField(name = "merchant_id") + private String merchant_id; + @NotBlank(message = "error.payment.valid.param_missing") @Length(max = 20) @JSONField(name = "short_name") private String merchant_shortname; @@ -84,6 +88,14 @@ public class SubMerchantIdApply { return this.merchant_name; } + public String getMerchant_id() { + return merchant_id; + } + + public void setMerchant_id(String merchant_id) { + this.merchant_id = merchant_id; + } + public void setMerchant_name(String merchant_name) { this.merchant_name = merchant_name; } diff --git a/src/main/java/au/com/royalpay/payment/manage/merchants/core/ClientManager.java b/src/main/java/au/com/royalpay/payment/manage/merchants/core/ClientManager.java index 6eeed77bb..291fa155b 100644 --- a/src/main/java/au/com/royalpay/payment/manage/merchants/core/ClientManager.java +++ b/src/main/java/au/com/royalpay/payment/manage/merchants/core/ClientManager.java @@ -270,5 +270,7 @@ public interface ClientManager { void subMerchantApplication(String clientMoniker, SubMerchantIdApply subMerchantApply,JSONObject manager); + List listMerchantIds(String clientMoniker,JSONObject manager); + void clearCacheSubMerchantIdApplices(String clientMoniker); } diff --git a/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientManagerImpl.java b/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientManagerImpl.java index e2a89cde3..941eda037 100644 --- a/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientManagerImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientManagerImpl.java @@ -1,6 +1,7 @@ package au.com.royalpay.payment.manage.merchants.core.impls; import au.com.royalpay.payment.channels.wechat.config.WeChatPayConfig; +import au.com.royalpay.payment.channels.wechat.config.WechatPayEnvironment; import au.com.royalpay.payment.channels.wechat.runtime.MpPaymentApi; import au.com.royalpay.payment.channels.wechat.runtime.WxPayClient; import au.com.royalpay.payment.channels.wechat.runtime.beans.SubMerchantInfo; @@ -2938,25 +2939,36 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid if (client == null) { throw new InvalidShortIdException(); } - List applices = sysWxMerchantApplyMapper.listWxMerchantApplices(client.getInteger("client_id")); + checkOrgPermission(manager, client); + List applices = sysWxMerchantApplyMapper.listWxMerchantApplices(client.getInteger("client_id"),new PageBounds(Order.formString("create_time.desc"))); if(!applices.isEmpty()){ return applices; }else { if(StringUtils.isNotEmpty(client.getString("sub_merchant_id")) && StringUtils.isNotEmpty(client.getString("merchant_id"))){ Element elem = wxPayClient.querySubMerchant(client.getString("merchant_id"),client.getString("sub_merchant_id")); - String applicesXml = XmlFormatUtils.formatXml(elem); - if(applicesXml != null){ - return null; - } + JSONObject object = new JSONObject(); + object.put("sub_merchant_id",elem.elementText("sub_mch_id_0")); + object.put("client_id",client.getInteger("client_id")); + object.put("merchant_name",elem.elementText("merchant_name_0")); + object.put("merchant_shortname",elem.elementText("merchant_shortname_0")); + object.put("office_phone",elem.elementText("office_phone_0")); + object.put("contact_name",elem.elementText("contact_name_0")); + object.put("contact_email",elem.elementText("contact_email_0")); + object.put("contact_phone",elem.elementText("contact_phone_0")); + object.put("business_category",elem.elementText("business_category_0")); + object.put("merchant_remark",elem.elementText("merchant_remark_0")); + object.put("website",elem.elementText("website_0")); + object.put("merchant_introduction",elem.elementText("merchant_introduction_0")); + object.put("merchant_id",client.getString("merchant_id")); + object.put("create_time",new Date()); + object.put("operator",manager.getString("display_name")); + sysWxMerchantApplyMapper.insertWxMerchantApply(object); + List applyQuery = sysWxMerchantApplyMapper.listWxMerchantApplices(client.getInteger("client_id"),new PageBounds(Order.formString("create_time.desc"))); + return applyQuery; } } return null; } - @Override - @CacheEvict(value = ":all_sub_merchant_id_applices:", key = "#clientMoniker") - public void clearCacheSubMerchantIdApplices(String clientMoniker) { - } - @Override @CacheEvict(value = ":all_sub_merchant_id_applices:", key = "#clientMoniker") public void subMerchantApplication(String clientMoniker, SubMerchantIdApply subMerchantApply,JSONObject manager) { @@ -2964,19 +2976,42 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid if (client == null) { throw new InvalidShortIdException(); } - if(!StringUtils.isNotEmpty(client.getString("merchant_id"))){ - throw new BadRequestException("ć— Merchant_id"); - } + checkOrgPermission(manager, client); JSONObject params = subMerchantApply.insertObject(); SubMerchantInfo subMerchantInfo = JSONObject.toJavaObject(params,SubMerchantInfo.class); params.put("merchant_id",client.getString("merchant_id")); params.put("client_id",client.getString("client_id")); params.put("create_time",new Date()); - params.put("operator",manager.getString("manager_id")); - Element elem = wxPayClient.subMerchantApplication(client.getString("merchant_id"),subMerchantInfo); - String applicesXml = XmlFormatUtils.formatXml(elem); - params.put("sub_merchant_id",applicesXml); - sysWxMerchantApplyMapper.insertWxMerchantApply(params); - clearCacheSubMerchantIdApplices(clientMoniker); + params.put("operator",manager.getString("display_name")); + Element elem = wxPayClient.subMerchantApplication(subMerchantApply.getMerchant_id(),subMerchantInfo); + String sub_merchant_id = elem.elementText("sub_mch_id"); + if(StringUtils.isNotEmpty(sub_merchant_id)){ + params.put("sub_merchant_id",sub_merchant_id); + sysWxMerchantApplyMapper.insertWxMerchantApply(params); + clearCacheSubMerchantIdApplices(clientMoniker); + }else { + throw new BadRequestException(); + } + } + + @Override + public List listMerchantIds(String clientMoniker,JSONObject manager) { + JSONObject client = getClientInfoByMoniker(clientMoniker); + if (client == null) { + throw new InvalidShortIdException(); + } + checkOrgPermission(manager, client); + List list = new ArrayList<>(); + for (WeChatPayConfig.Merchant mch : WechatPayEnvironment.getEnv().getWechatMerchantConfigs()){ + JSONObject merchantIds = new JSONObject(); + merchantIds.put("merchant_id",mch.getMerchantId()); + list.add(merchantIds); + } + return list; + } + + @Override + @CacheEvict(value = ":all_sub_merchant_id_applices:", key = "#clientMoniker") + public void clearCacheSubMerchantIdApplices(String clientMoniker) { } } diff --git a/src/main/java/au/com/royalpay/payment/manage/merchants/web/PartnerManageController.java b/src/main/java/au/com/royalpay/payment/manage/merchants/web/PartnerManageController.java index 888c0cec1..8928e732f 100644 --- a/src/main/java/au/com/royalpay/payment/manage/merchants/web/PartnerManageController.java +++ b/src/main/java/au/com/royalpay/payment/manage/merchants/web/PartnerManageController.java @@ -492,4 +492,9 @@ public class PartnerManageController { public void subMerchantApplication(@PathVariable String clientMoniker, @RequestBody SubMerchantIdApply subMerchantIdApply, @ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager) { clientManager.subMerchantApplication(clientMoniker,subMerchantIdApply,manager); } + + @ManagerMapping(value = "/{clientMoniker}/get_merchant_ids",method = RequestMethod.GET,role = {ManagerRole.OPERATOR,ManagerRole.ADMIN}) + public List getMerchantIds(@PathVariable String clientMoniker, @ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager) { + return clientManager.listMerchantIds(clientMoniker,manager); + } } diff --git a/src/main/ui/static/payment/partner/partner-manage.js b/src/main/ui/static/payment/partner/partner-manage.js index b1e09d2e3..f019de6eb 100644 --- a/src/main/ui/static/payment/partner/partner-manage.js +++ b/src/main/ui/static/payment/partner/partner-manage.js @@ -2589,7 +2589,10 @@ define(['angular', 'decimal', 'static/commons/commons', 'uiBootstrap', 'uiRouter resolve: { subMerchantInfo:function () { return $scope.partner; - } + }, + merchantIds: ['$http', '$stateParams', function ($http) { + return $http.get('/sys/partners/'+ $scope.partner.client_moniker +'/get_merchant_ids'); + }] } }).result.then(function () { $scope.loadSubMerchantInfos(); @@ -2597,9 +2600,10 @@ define(['angular', 'decimal', 'static/commons/commons', 'uiBootstrap', 'uiRouter }; $scope.loadSubMerchantInfos(); }]); - app.controller('applySubMerchantIdCtrl', ['$scope', '$http', '$uibModal','$state','subMerchantInfo', '$filter', function ($scope, $http, $uibModal, $state, subMerchantInfo,$filter) { + app.controller('applySubMerchantIdCtrl', ['$scope', '$http', '$uibModal','$state','subMerchantInfo', '$filter','merchantIds', function ($scope, $http, $uibModal, $state, subMerchantInfo,$filter,merchantIds) { $scope.wxIndustries = angular.copy(wxMerchantIndustries); $scope.subMerchantInfo = angular.copy(subMerchantInfo); + $scope.merchantIds = merchantIds.data; $scope.subMerchantInfo.industry = $filter('wxindustries')($scope.subMerchantInfo.industry); $scope.saveAppliy = function (form) { $scope.errmsg = null; diff --git a/src/main/ui/static/payment/partner/templates/apply_sub_merchant_id.html b/src/main/ui/static/payment/partner/templates/apply_sub_merchant_id.html index 56d6401a3..66183d6cc 100644 --- a/src/main/ui/static/payment/partner/templates/apply_sub_merchant_id.html +++ b/src/main/ui/static/payment/partner/templates/apply_sub_merchant_id.html @@ -19,6 +19,26 @@ + +
+ +
+ +
+

Required Field

+
+
+
+

More than 50

+
+
+
diff --git a/src/main/ui/static/payment/partner/templates/sub_merchant_id_apply.html b/src/main/ui/static/payment/partner/templates/sub_merchant_id_apply.html index 1ddefd3c6..22b23a645 100644 --- a/src/main/ui/static/payment/partner/templates/sub_merchant_id_apply.html +++ b/src/main/ui/static/payment/partner/templates/sub_merchant_id_apply.html @@ -18,8 +18,8 @@
  • - Sub Merchant Id - + Sub Merchant Id +
  • Apply Time