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 255fe2c23..99ca8851a 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java @@ -440,17 +440,24 @@ public class WxCouponServiceImpl implements WxCouponService { } ResultData receiverResult = checkCouponMerchantReceiver(record); - if(Result.SUCCESS != giftResult.code){ + if(Result.SUCCESS != receiverResult.code){ return receiverResult; } - + List merchantList = (List) receiverResult.data; + + if(merchantList.size() > 1){ + record.setBusiness(EnumBusiness.BUSINESS_ID6.getCode()); + }else{ + record.setBusiness(merchantList.get(0).getBusinessId()); + record.setSubBusiness(merchantList.get(0).getSubBusinessId()); + } + List merchantParamList = JSONObject.parseArray(record.getMerchantParams(), JSONObject.class); final IdWorker idWorker = IdWorker.get(); if (record.getId() == null) { record.setId(idWorker.nextId()); - List wxCouponMerchantDtoList = new ArrayList<>(); merchantParamList.forEach(merchantParam -> { WxCouponMerchant cm = new WxCouponMerchant(); WxCouponMerchantDto wxCouponMerchantDto = parseMerchantParam(merchantParam); @@ -462,18 +469,8 @@ public class WxCouponServiceImpl implements WxCouponService { cm.setCreateDate(new Date()); cm.setUpdateDate(new Date()); cm.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); - wxCouponMerchantDtoList.add(wxCouponMerchantDto); wxCouponMerchantMapper.insert(cm); }); - if (wxCouponMerchantDtoList.stream() - .mapToInt(WxCouponMerchantDto::getBusiness).distinct().count() > 1) { - record.setBusiness(EnumBusiness.BUSINESS_ID6.getCode()); - } else if (wxCouponMerchantDtoList.size() > 1){ - record.setBusiness(wxCouponMerchantDtoList.get(0).getBusiness()); - } else { - record.setBusiness(wxCouponMerchantDtoList.get(0).getBusiness()); - record.setSubBusiness(wxCouponMerchantDtoList.get(0).getSubBusiness()); - } if (record.getPasswordSupport() != null && record.getPasswordSupport().equals(EnumCouponPasswordSupport.SUPPORTED.getCode())) { // todo 生成卡密无法修改, 调整 @@ -506,7 +503,6 @@ public class WxCouponServiceImpl implements WxCouponService { cmParam.updateTenantInfo(record); cmParam.setProductId(record.getId()); List oldList = wxCouponMerchantMapper.findList(cmParam); - List wxCouponMerchantDtoList = new ArrayList<>(); merchantParamList.stream().forEach(merchantParam -> { WxCouponMerchant cm = new WxCouponMerchant(); WxCouponMerchantDto wxCouponMerchantDto = parseMerchantParam(merchantParam); @@ -527,7 +523,6 @@ public class WxCouponServiceImpl implements WxCouponService { cm.setUpdateDate(new Date()); wxCouponMerchantMapper.insert(cm); } - wxCouponMerchantDtoList.add(wxCouponMerchantDto); oldList.removeIf( old->old.getProductId().equals(record.getId()) && old.getMerchantId().equals(wxCouponMerchantDto.getMerchantId())); @@ -539,16 +534,6 @@ public class WxCouponServiceImpl implements WxCouponService { wxCouponMerchantMapper.updateById(old); }); - if (wxCouponMerchantDtoList.stream() - .mapToInt(WxCouponMerchantDto::getBusiness).distinct().count() > 1) { - record.setBusiness(EnumBusiness.BUSINESS_ID6.getCode()); - } else if (wxCouponMerchantDtoList.size() > 1){ - record.setBusiness(wxCouponMerchantDtoList.get(0).getBusiness()); - } else { - record.setBusiness(wxCouponMerchantDtoList.get(0).getBusiness()); - record.setSubBusiness(wxCouponMerchantDtoList.get(0).getSubBusiness()); - } - record.setUpdateDate(new Date()); wxCouponMapper.updateById(record); } @@ -564,6 +549,23 @@ public class WxCouponServiceImpl implements WxCouponService { if(merchantParamList == null || merchantParamList.isEmpty()){ return new ResultData(ErrorCode.MERCHANT_INFO_NOT_FOUND.getCode(),"所属商户为空"); } + List merchantIds = new ArrayList<>(); + for (JSONObject o:merchantParamList) { + merchantIds.add(o.getLong("id")); + } + WxMerchant merchantQ = new WxMerchant(); + merchantQ.updateTenantInfo(record); + merchantQ.setIds(merchantIds); + List merchantList = wxMerchantService.findList(merchantQ); + if(merchantList.size() != merchantParamList.size()){ + return new ResultData(ErrorCode.MERCHANT_INFO_NOT_EQUAL.getCode(),"所属商户信息异常"); + } + List badMerchant = merchantList.stream().filter(m -> !EnumMerchantStatus.VALID.getCode().equals(m.getStatus())).collect(toList()); + if(badMerchant != null && !badMerchant.isEmpty()){ + List badNames = badMerchant.stream().map(WxMerchant::getName).collect(toList()); + return new ResultData(ErrorCode.MERCHANT_INFO_NOT_VALID.getCode(),JSONArray.toJSONString(badNames)+"被停用"); + } + if(record.getSalePrice() != null && record.getSalePrice() > 0) { EnumAppPlat plat = EnumCouponType.getAppPlat(record.getType()); EnumPayWay payWay = EnumAppPlat.getPayWay(plat); @@ -580,56 +582,43 @@ public class WxCouponServiceImpl implements WxCouponService { EnumPayShare isShare = EnumPayShare.getEnum(payAccount.getShare()); PayShareAdapterService payShareServie = payServiceFactory.getPayShareAdapterService(payWay.getCode(),payAccount.getPayVersion()); - List merchantIds = new ArrayList<>(); - for (JSONObject o:merchantParamList) { - merchantIds.add(o.getLong("id")); - } - WxMerchant merchantQ = new WxMerchant(); - merchantQ.updateTenantInfo(record); - merchantQ.setIds(merchantIds); - Map idAndNamesMap = wxMerchantService.getIdAndNamesMap(merchantQ); if (EnumPayMchType.DIRECT.equals(payMchType)) { - Long merchantId = null; - if (merchantIds.size() > 1) { - WxMerchant merchantQ2 = new WxMerchant(); - merchantQ2.updateTenantInfo(record); - merchantQ2.setIds(merchantIds); - merchantQ2.setIsAdmin(EnumMerchantAdmin.PUBLIC_ADMIN.getCode()); - merchantQ2.setStatus(EnumMerchantStatus.VALID.getCode()); - List list = wxMerchantMapper.findIdList(merchantQ2); - if(list == null || list.isEmpty()){ - return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "直连模式多门店券需包含一个商管商户"); - }else if(list.size() > 1){ - return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "直连模式多门店券只能包含一个商管商户"); + WxMerchant makeMerchant = null; + if(merchantList.size() == 1){ + record.setMerchantType(EnumCouponMerchantType.ONE_MERCHANT.getCode()); + makeMerchant = merchantList.get(0); + }else{ + List adminMerchant = merchantList.stream().filter(m -> EnumMerchantAdmin.PUBLIC_ADMIN.getCode().equals(m.getIsAdmin())).collect(toList()); + if(adminMerchant == null || adminMerchant.isEmpty()){ + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "多门店券需包含一个商管商户"); + }else if(adminMerchant.size() > 1){ + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "多门店券只能包含一个商管商户"); } record.setMerchantType(EnumCouponMerchantType.MULTIPLE_MERCHANT.getCode()); - merchantId = list.get(0); - }else{ - record.setMerchantType(EnumCouponMerchantType.ONE_MERCHANT.getCode()); - merchantId = merchantIds.get(0); + makeMerchant = adminMerchant.get(0); } - record.setMakeMerchantId(merchantId); - WxProfitSharingReceiver receiver = payShareServie.getReceiver(payAccount, merchantId, null, payMchType.getCode()); + + record.setMakeMerchantId(makeMerchant.getId()); + WxProfitSharingReceiver receiver = payShareServie.getReceiver(payAccount, makeMerchant.getId(), null, payMchType.getCode()); if (receiver == null) { - return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "["+idAndNamesMap.get(merchantId)+"]未配置收款账户"); + return new ResultData(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())) { - return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "["+idAndNamesMap.get(merchantId)+"]未配置收款账户"); + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "[\""+makeMerchant.getName()+"\"]未配置收款账户"); } } } else if (EnumPayShare.YES.equals(isShare)) { - List merchantNames = new ArrayList(); - for (Long merchantId:merchantIds) { - WxProfitSharingReceiver receiver = payShareServie.getReceiver(payAccount, merchantId, null, payMchType.getCode()); + List badNames = new ArrayList(); + for (WxMerchant merchant:merchantList) { + WxProfitSharingReceiver receiver = payShareServie.getReceiver(payAccount, merchant.getId(), null, payMchType.getCode()); if (receiver == null) { - merchantNames.add(idAndNamesMap.get(merchantId)); + badNames.add(merchant.getName()); continue; -// return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "第(" + n + ")个商户还未配置分账账户或未进件"); } if (EnumAppPlat.TOUTIAO.equals(plat)) { QueryMerchantResult openPayResult = payAccount.getOpenPayResult(); @@ -640,30 +629,27 @@ public class WxCouponServiceImpl implements WxCouponService { } if(EnumYesOrNo.YES.getCode().equals(openPayResult.getAlipay()) && !MerchantImportStatus.improt_success.getCode().equals(receiver.getAlipayImportStatus())){ - merchantNames.add(idAndNamesMap.get(merchantId)); + badNames.add(merchant.getName()); continue; -// return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "["+idAndNamesMap.get(merchantId)+"]未进件支付宝"); } if(EnumYesOrNo.YES.getCode().equals(openPayResult.getWx()) && !MerchantImportStatus.improt_success.getCode().equals(receiver.getWxImportStatus())){ - merchantNames.add(idAndNamesMap.get(merchantId)); + badNames.add(merchant.getName()); continue; -// return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "["+idAndNamesMap.get(merchantId)+"]未进件微信"); } if(EnumYesOrNo.YES.getCode().equals(openPayResult.getHz()) && !MerchantImportStatus.improt_success.getCode().equals(receiver.getHzImportStatus())){ - merchantNames.add(idAndNamesMap.get(merchantId)); + badNames.add(merchant.getName()); continue; -// return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "["+idAndNamesMap.get(merchantId)+"]未进件抖音"); } } } - if(!merchantNames.isEmpty()){ - return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), JSONArray.toJSONString(merchantNames)+"未配置分账账户"); + if(!badNames.isEmpty()){ + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), JSONArray.toJSONString(badNames)+"未配置分账账户"); } } } - return new ResultData(); + return new ResultData(merchantList); } @Override