diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponController.java b/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponController.java index 68b52475e..0f523e8c2 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponController.java @@ -571,7 +571,7 @@ public class WxCouponController extends BaseController { return new ResultData(wxCouponMallService.list(wxCouponMall)); } - @ApiOperation("商场查询:平台券列表") + @ApiOperation("商场查询:平台券商场列表") @GetMapping("/couponMalls") @ApiImplicitParams({ @ApiImplicitParam(name = "ids", value = "ids[]", dataType = "Long", paramType = "query", required = true)}) @@ -612,5 +612,18 @@ public class WxCouponController extends BaseController { } return new ResultData(); } + + @ApiOperation("券商户是否自动分账") + @PostMapping("/couponMerchantAutoShare") + public ResultData couponMerchantAutoShare(@RequestBody WxCoupon wxCoupon) { + wxCoupon.updateTenantInfo(getTenantInfo()); + try { + Map map = wxCouponService.couponMerchantAutoShare(wxCoupon); + return new ResultData(map); + } catch (Exception e) { + return new ResultData(Result.ERROR,e.getMessage()); + } + + } } diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxCoupon.java b/mallinkService/src/main/java/com/iformall/domain/po/WxCoupon.java index b9fcf2c8b..b39c51cdb 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxCoupon.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxCoupon.java @@ -388,6 +388,9 @@ public class WxCoupon extends TenantEntity { @io.swagger.annotations.ApiModelProperty(value = "是否删除1是0否", name = "isDel") private Integer isDel; + + @TableField(exist = false) + private Long[] merchantIds; public String getSalePriceStr() { if(salePrice!=null) { diff --git a/mallinkService/src/main/java/com/iformall/service/WxCouponService.java b/mallinkService/src/main/java/com/iformall/service/WxCouponService.java index 266f2a9c4..21cb817a8 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxCouponService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxCouponService.java @@ -289,4 +289,6 @@ public interface WxCouponService { ResultData disable(TenantEntity tenantInfo, Long couponId); void setCouponMerchants(WxCoupon wxCoupon) throws Exception; + + Map couponMerchantAutoShare(WxCoupon wxCoupon) throws Exception; } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java index 8d8144637..97c14ab34 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java @@ -706,46 +706,29 @@ public class WxCouponServiceImpl implements WxCouponService { if (receiver == null) { throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "[\""+makeMerchant.getName()+"\"]未配置收款账户"); } + //如果是直连,抖音,多商户券必须只配置支付宝 if (EnumAppPlat.TOUTIAO.equals(plat)) { - if (!MerchantImportStatus.improt_success.getCode().equals(receiver.getWxImportStatus()) - && !MerchantImportStatus.improt_success.getCode().equals(receiver.getAlipayImportStatus()) - && !MerchantImportStatus.improt_success.getCode().equals(receiver.getHzImportStatus())) { - throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "[\""+makeMerchant.getName()+"\"]未配置收款账户"); - } + if (merchantList.size() > 1 ) { + if (MerchantImportStatus.improt_success.getCode().equals(receiver.getAlipayImportStatus()) && + !MerchantImportStatus.improt_success.getCode().equals(receiver.getWxImportStatus()) ) { + }else { + throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "[\""+makeMerchant.getName()+"\"]配置收款账户错误,多商户券主收款账户不能配置微信."); + } + }else { + if (!MerchantImportStatus.improt_success.getCode().equals(receiver.getWxImportStatus()) + && !MerchantImportStatus.improt_success.getCode().equals(receiver.getAlipayImportStatus()) + && !MerchantImportStatus.improt_success.getCode().equals(receiver.getHzImportStatus())) { + throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "[\""+makeMerchant.getName()+"\"]未配置收款账户"); + } + } } } else if (EnumPayShare.YES.equals(isShare)) { List badNames = new ArrayList(); for (WxMerchant merchant:merchantList) { - WxProfitSharingReceiver receiver = payShareServie.getReceiver(payAccount, merchant.getId(), null, payMchType.getCode()); - - if (receiver == null) { - badNames.add(merchant.getName()); - continue; - } - if (EnumAppPlat.TOUTIAO.equals(plat)) { - QueryMerchantResult openPayResult = payAccount.getOpenPayResult(); - - if(!EnumYesOrNo.YES.getCode().equals(openPayResult.getAlipay()) - && !EnumYesOrNo.YES.getCode().equals(openPayResult.getWx()) - && !EnumYesOrNo.YES.getCode().equals(openPayResult.getHz())){ - throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "分账模式未设置开通支付渠道"); - } - if(EnumYesOrNo.YES.getCode().equals(openPayResult.getAlipay()) - && !MerchantImportStatus.improt_success.getCode().equals(receiver.getAlipayImportStatus())){ - badNames.add(merchant.getName()); - continue; - } - if(EnumYesOrNo.YES.getCode().equals(openPayResult.getWx()) - && !MerchantImportStatus.improt_success.getCode().equals(receiver.getWxImportStatus())){ - badNames.add(merchant.getName()); - continue; - } - if(EnumYesOrNo.YES.getCode().equals(openPayResult.getHz()) - && !MerchantImportStatus.improt_success.getCode().equals(receiver.getHzImportStatus())){ - badNames.add(merchant.getName()); - continue; - } - } + boolean isBad = toTalPayMchTypeMerchantIsBad(payShareServie,payAccount,merchant.getName(),merchant.getId(),payMchType,plat); + if (isBad) { + badNames.add(merchant.getName()); + } } if(!badNames.isEmpty()){ throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), JSONArray.toJSONString(badNames)+"未配置分账账户"); @@ -754,6 +737,37 @@ public class WxCouponServiceImpl implements WxCouponService { } return merchantList; } + + //总分模式下不能分账的商户 + private boolean toTalPayMchTypeMerchantIsBad(PayShareAdapterService payShareServie,WxPayAccount payAccount, + String merchantName,Long merchantId,EnumPayMchType payMchType,EnumAppPlat plat) throws Exception { + WxProfitSharingReceiver receiver = payShareServie.getReceiver(payAccount, merchantId, null, payMchType.getCode()); + if (receiver == null) { + return true; + } + if (EnumAppPlat.TOUTIAO.equals(plat)) { + QueryMerchantResult openPayResult = payAccount.getOpenPayResult(); + + if(!EnumYesOrNo.YES.getCode().equals(openPayResult.getAlipay()) + && !EnumYesOrNo.YES.getCode().equals(openPayResult.getWx()) + && !EnumYesOrNo.YES.getCode().equals(openPayResult.getHz())){ + throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "分账模式未设置开通支付渠道"); + } + if(EnumYesOrNo.YES.getCode().equals(openPayResult.getAlipay()) + && !MerchantImportStatus.improt_success.getCode().equals(receiver.getAlipayImportStatus())){ + return true; + } + if(EnumYesOrNo.YES.getCode().equals(openPayResult.getWx()) + && !MerchantImportStatus.improt_success.getCode().equals(receiver.getWxImportStatus())){ + return true; + } + if(EnumYesOrNo.YES.getCode().equals(openPayResult.getHz()) + && !MerchantImportStatus.improt_success.getCode().equals(receiver.getHzImportStatus())){ + return true; + } + } + return false; + } @Override public ResultData updateTtProduct(WxCoupon record) { @@ -1416,6 +1430,79 @@ public class WxCouponServiceImpl implements WxCouponService { throw e; } } + + private Map generateMerchantAutoShareAll(Long[] merchantIds,boolean auto) { + Map merchantAutoShareMap = new HashMap(); + for (Long mid:merchantIds) { + merchantAutoShareMap.put(mid, auto); + } + return merchantAutoShareMap; + } + @Override + public Map couponMerchantAutoShare(WxCoupon wxCoupon) throws Exception { + if (null == wxCoupon.getMerchantIds() || null == wxCoupon.getId() || null == wxCoupon.getType() || null == wxCoupon.getMerchantType()) { + throw new MallinkException(Result.ERROR,"缺少参数"); + } + EnumAppPlat plat = EnumCouponType.getAppPlat(wxCoupon.getType()); + EnumPayWay payWay = EnumAppPlat.getPayWay(plat); + WxAppinfo cAppInfo = wxAppinfoService.getCAppInfo(wxCoupon,plat); + if (cAppInfo == null) { + throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); + } + WxPayAccount payAccount = payAccountMapper.selectById(cAppInfo.getPayId()); + if (payAccount == null) { + throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); + } + EnumPayMchType payMchType = EnumPayMchType.getEnum(payAccount.getMchType()); + EnumPayShare isShare = EnumPayShare.getEnum(payAccount.getShare()); + PayShareAdapterService payShareServie = payServiceFactory.getPayShareAdapterService(payWay.getCode(),payAccount.getPayVersion()); + //直连模式,如果是单商户券,则都可以;如果是多商户券,抖音则只要开通了支付宝就可以,微信则不行。 + if (payMchType == EnumPayMchType.DIRECT) { + if (EnumCouponMerchantType.ONE_MERCHANT.getCode() == wxCoupon.getMerchantType()) { + return generateMerchantAutoShareAll(wxCoupon.getMerchantIds(),true); + }else { + if (plat == EnumAppPlat.TOUTIAO) { + Map merchantAutoShareMap = new HashMap(); + for (Long mid:wxCoupon.getMerchantIds()) { + //开通了支付宝就可以 + WxProfitSharingReceiver receiver = payShareServie.getReceiver(payAccount, mid, null, payMchType.getCode()); + if (MerchantImportStatus.improt_success.getCode().equals(receiver.getAlipayImportStatus())) { + merchantAutoShareMap.put(mid, true); + }else { + merchantAutoShareMap.put(mid, false); + } + } + return merchantAutoShareMap; + }else if (plat == EnumAppPlat.WX){ + return generateMerchantAutoShareAll(wxCoupon.getMerchantIds(),false); + }else { + return generateMerchantAutoShareAll(wxCoupon.getMerchantIds(),false); + } + } + }else { + //总分模式,分账开启,微信平台则认为是100%分账,抖音则只要开通了支付宝就可以。 + if (isShare == EnumPayShare.YES) { + if (plat == EnumAppPlat.WX) { + return generateMerchantAutoShareAll(wxCoupon.getMerchantIds(),true); + }else if (plat == EnumAppPlat.TOUTIAO) { + Map merchantAutoShareMap = new HashMap(); + for (Long mid:wxCoupon.getMerchantIds()) { + boolean isBad = toTalPayMchTypeMerchantIsBad(payShareServie,payAccount,String.valueOf(mid),mid,payMchType,plat); + if (isBad) { + merchantAutoShareMap.put(mid, false); + }else { + merchantAutoShareMap.put(mid, true); + } + } + return merchantAutoShareMap; + }else { + return generateMerchantAutoShareAll(wxCoupon.getMerchantIds(),true); + } + }else { + return generateMerchantAutoShareAll(wxCoupon.getMerchantIds(),false); + } + } + } }