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 562779b30..13c671b59 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponController.java @@ -415,6 +415,7 @@ public class WxCouponController extends BaseController { return new ResultData(Result.SUCCESS, "删除成功", null); } + @TenantIgnore @ApiOperation("根据id查询接口") @GetMapping("/findById") @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) 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 66f2e02ef..951a7e5c1 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java @@ -365,16 +365,9 @@ public class WxCouponServiceImpl implements WxCouponService { if(wxCouponCVo == null){ return null; } - List couponIdList = new ArrayList(); - couponIdList.add(wxCouponCVo.getId()); - Map> couponMerchantVoMap = wxMerchantService.findCouponMerchantVoList(couponIdList, mallTenantEntity,true); - List merchantList = couponMerchantVoMap.get(wxCouponCVo.getId()); - if (merchantList != null) { - merchantList = merchantList.stream().filter( - m->m.getMerchantStatus().equals(EnumMerchantStatus.VALID.getCode())) - .collect(toList()); - } + List merchantList = getMerchantVoList(wxCouponCVo, wxCouponCVo.getId(), wxCouponCVo.getType()); + wxCouponCVo.setMerchantVoList(merchantList); if(EnumCouponType.COUPON_GIFT.getCode().equals(wxCouponCVo.getType())){ WxCoupon coupon = new WxCoupon(); @@ -389,6 +382,26 @@ public class WxCouponServiceImpl implements WxCouponService { return wxCouponCVo; } + private List getMerchantVoList(TenantEntity couponTenant,Long couponId,Integer couponType){ + if (EnumCouponType.isParentCoupon(couponType)){ + WxCouponMall couponMall = new WxCouponMall(); + couponMall.updateTenantInfo(couponTenant); + couponMall.setProductId(couponId); + couponMall.setStatus(EnumCouponMallStatus.FINISED.getCode()); + List couponMallList = wxCouponMallMapper.findList(couponMall); + List merchantVoList = new ArrayList<>(); + if (null != couponMallList && couponMallList.size()> 0 ) { + for (WxCouponMall cm:couponMallList) { + WxMall mall = wxMallMapper.getByTenantId(cm.getMallTenantId()); + merchantVoList.addAll(getCouponMerchantList(couponId, mall)); + } + } + return merchantVoList; + }else{ + return getCouponMerchantList(couponId,couponTenant); + } + } + @Override public WxCouponCVo getVoStatusById(Long id,String tenantId) { WxCouponCVo wxCouponCVo = wxCouponMapper.findVoStatusDetail(id,tenantId); @@ -524,6 +537,9 @@ public class WxCouponServiceImpl implements WxCouponService { if(Result.SUCCESS != giftResult.code){ return giftResult; } + + //判断直连检查收款帐号(必须),总分模式直接收款到小程序的收款帐号 + checkCouponMakeMerchant(record); //平台券先不设置商户 Map tenantMerchantMap = null; @@ -719,6 +735,9 @@ public class WxCouponServiceImpl implements WxCouponService { * 父券对应子商场商户 */ if (EnumCouponType.isParentCoupon(record.getType())) { + if(EnumCouponType.COUPON_DOUYIN_BRAND.getCode().equals(record.getType())){ + handCouponMerchantParams(record); + } if (StringUtils.isBlank(record.getChildMerchantParams())){ throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_FOUND.getCode(),"所属商户为空"); } @@ -764,6 +783,37 @@ public class WxCouponServiceImpl implements WxCouponService { return retMap; } } + + private void handCouponMerchantParams(WxCoupon record){ + List merchantParamList = JSONObject.parseArray(record.getMerchantParams(), JSONObject.class); + if(merchantParamList == null || merchantParamList.isEmpty()){ + throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_FOUND.getCode(),"所属商户为空"); + } + + Map> map = new HashMap<>(); + for (JSONObject o:merchantParamList) { + String tenantId = o.getString("tenantId"); + if(StringUtils.isBlank(tenantId)){ + throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"参数传递异常"); + } + List merchantParams = map.get(tenantId); + if(merchantParams == null){ + merchantParams = new ArrayList<>(); + } + merchantParams.add(o); + map.put(tenantId,merchantParams); + } + + List childMerchantParams = new ArrayList<>(); + for (Iterator it = map.keySet().iterator();it.hasNext();) { + JSONObject object = new JSONObject(); + String tenantId = it.next(); + object.put("tenantId",tenantId); + object.put("mallMerchantParams",map.get(tenantId)); + childMerchantParams.add(object); + } + record.setChildMerchantParams(JSON.toJSONString(childMerchantParams)); + } private List checkCouponOneMallMerchantReceiver(TenantEntity mallTenantEntity,String merchantParams,WxCoupon record) throws Exception { List merchantParamList = JSONObject.parseArray(merchantParams, JSONObject.class); @@ -820,32 +870,34 @@ public class WxCouponServiceImpl implements WxCouponService { PayShareAdapterService payShareServie = payServiceFactory.getPayShareAdapterService(payWay.getCode(),payAccount.getPayVersion()); if (EnumPayMchType.DIRECT.equals(payMchType)) { - WxMerchant makeMerchant = getDirectPayAccountMerchant(merchantList,record); - if (null == makeMerchant) { - throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "没有收款商户"); - } - record.setMakeMerchantId(makeMerchant.getId()); - WxProfitSharingReceiver receiver = payShareServie.getReceiver(makeMerchant, makeMerchant.getId(), null, payMchType.getCode()); - - if (receiver == null) { - throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "[\""+makeMerchant.getName()+"\"]未配置收款账户"); - } + //多商户券,抖音 直连 门店只有进件支付宝才能参加活动 todo + +// WxMerchant makeMerchant = getDirectPayAccountMerchant(merchantList,record); +// if (null == makeMerchant) { +// throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "没有收款商户"); +// } +// record.setMakeMerchantId(makeMerchant.getId()); +// WxProfitSharingReceiver receiver = payShareServie.getReceiver(makeMerchant, makeMerchant.getId(), null, payMchType.getCode()); +// +// if (receiver == null) { +// throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "[\""+makeMerchant.getName()+"\"]未配置收款账户"); +// } //如果是直连,抖音,多商户券必须只配置支付宝 - if (EnumAppPlat.TOUTIAO.equals(plat)) { - 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()+"\"]未配置收款账户"); - } - } - } +// if (EnumAppPlat.TOUTIAO.equals(plat)) { +// 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) { @@ -1475,6 +1527,86 @@ public class WxCouponServiceImpl implements WxCouponService { } + /** + * 直连判断收款商户 + * @param wxCoupon + * @return + */ + private ResultData checkCouponMakeMerchant(WxCoupon wxCoupon){ + EnumAppPlat plat = EnumCouponType.getAppPlat(wxCoupon.getType()); + EnumPayWay payWay = EnumAppPlat.getPayWay(plat); + WxAppinfo cAppInfo = wxAppinfoService.getCAppInfoFromRedis(wxCoupon.getTenantId(),plat); + if (cAppInfo == null) { + throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); + } + WxPayAccount payAccount = payAccountService.getByIdFromRedis(cAppInfo.getPayId()); + if (payAccount == null) { + throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); + } + EnumPayMchType payMchType = EnumPayMchType.getEnum(payAccount.getMchType()); + if(EnumPayMchType.DIRECT.equals(payMchType)){ + WxMerchant makeMerchant = null; + //平台券,查询集团商管商户 + if (EnumCouponType.COUPON_DOUYIN_PLAT.getCode().equals(wxCoupon.getType())) { + wxCoupon.setMerchantType(EnumCouponMerchantType.MULTIPLE_MERCHANT.getCode()); + makeMerchant = wxMerchantService.findAdmin(wxCoupon); + //品牌券,查询集团品牌商户 + }else if (EnumCouponType.COUPON_DOUYIN_BRAND.getCode().equals(wxCoupon.getType())) { + if(wxCoupon.getBrand() == null){ + throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"未选择品牌"); + } + wxCoupon.setMerchantType(EnumCouponMerchantType.MULTIPLE_MERCHANT.getCode()); + makeMerchant = wxMerchantService.findBrandAdmin(wxCoupon,wxCoupon.getBrand()); + //其他商场券 + }else { + List merchantParamList = JSONObject.parseArray(wxCoupon.getMerchantParams(), JSONObject.class); + if(merchantParamList == null || merchantParamList.isEmpty()){ + throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_FOUND.getCode(),"所属商户为空"); + } + //多门店券 + if(merchantParamList.size() > 1 || EnumCouponMerchantType.MULTIPLE_MERCHANT.getCode().equals(wxCoupon.getMerchantType())){ + wxCoupon.setMerchantType(EnumCouponMerchantType.MULTIPLE_MERCHANT.getCode()); + makeMerchant = wxMerchantService.findAdmin(wxCoupon); + }else{ + wxCoupon.setMerchantType(EnumCouponMerchantType.ONE_MERCHANT.getCode()); + Long merchantId = merchantParamList.get(0).getLong("id"); + makeMerchant = wxMerchantService.selectById(merchantId); + } + } + if (makeMerchant == null) { + throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "没有收款商户"); + } + + PayShareAdapterService payShareServie = payServiceFactory.getPayShareAdapterService(payWay.getCode(),payAccount.getPayVersion()); + WxProfitSharingReceiver receiver = payShareServie.getReceiver(makeMerchant, makeMerchant.getId(), null, payMchType.getCode()); + 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(EnumCouponMerchantType.MULTIPLE_MERCHANT.getCode().equals(wxCoupon.getMerchantType())){ + if (MerchantImportStatus.improt_success.getCode().equals(receiver.getAlipayImportStatus()) + && !MerchantImportStatus.improt_success.getCode().equals(receiver.getWxImportStatus()) + && !MerchantImportStatus.improt_success.getCode().equals(receiver.getHzImportStatus())) { + }else { + throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "收款商户[\""+makeMerchant.getName()+"\"]配置收款账户错误,只能配置支付宝."); + } + } + } + wxCoupon.setMakeMerchantId(makeMerchant.getId()); + }else{ + wxCoupon.setMakeMerchantId(0l); + } + + return new ResultData(); + } + @Override public Map getCouponMerchantMap(List couponIds, TenantEntity tenantEntity,boolean onlyOneMerchantCoupons) { Map couponMerchantMap = new HashMap(); @@ -1622,7 +1754,7 @@ public class WxCouponServiceImpl implements WxCouponService { if (null == wxCoupon.getMerchantIds()) { throw new MallinkException(Result.ERROR,"请选择商户"); } - Long makeMerchantId = coupon.getMakeMerchantId(); +// Long makeMerchantId = coupon.getMakeMerchantId(); // StringBuffer merchantParams = new StringBuffer("[{\"tenantId\":").append(mallTenantEntity.getTenantId()).append(",\"mallMerchantParams\":").append("["); Long[] mids = wxCoupon.getMerchantIds(); @@ -1638,9 +1770,9 @@ public class WxCouponServiceImpl implements WxCouponService { final IdWorker idWorker = IdWorker.get(); updateCouponMerchants(coupon,idWorker); //平台券设置商管商户 - if (null != coupon.getMakeMerchantId()) { - wxCouponMapper.setMakeMerchantId(coupon); - } +// if (null != coupon.getMakeMerchantId()) { +// wxCouponMapper.setMakeMerchantId(coupon); +// } }catch(Exception e) { throw e; }