| @@ -440,17 +440,24 @@ public class WxCouponServiceImpl implements WxCouponService { | |||||
| } | } | ||||
| ResultData receiverResult = checkCouponMerchantReceiver(record); | ResultData receiverResult = checkCouponMerchantReceiver(record); | ||||
| if(Result.SUCCESS != giftResult.code){ | |||||
| if(Result.SUCCESS != receiverResult.code){ | |||||
| return receiverResult; | return receiverResult; | ||||
| } | } | ||||
| List<WxMerchant> merchantList = (List<WxMerchant>) 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<JSONObject> merchantParamList = JSONObject.parseArray(record.getMerchantParams(), JSONObject.class); | List<JSONObject> merchantParamList = JSONObject.parseArray(record.getMerchantParams(), JSONObject.class); | ||||
| final IdWorker idWorker = IdWorker.get(); | final IdWorker idWorker = IdWorker.get(); | ||||
| if (record.getId() == null) { | if (record.getId() == null) { | ||||
| record.setId(idWorker.nextId()); | record.setId(idWorker.nextId()); | ||||
| List<WxCouponMerchantDto> wxCouponMerchantDtoList = new ArrayList<>(); | |||||
| merchantParamList.forEach(merchantParam -> { | merchantParamList.forEach(merchantParam -> { | ||||
| WxCouponMerchant cm = new WxCouponMerchant(); | WxCouponMerchant cm = new WxCouponMerchant(); | ||||
| WxCouponMerchantDto wxCouponMerchantDto = parseMerchantParam(merchantParam); | WxCouponMerchantDto wxCouponMerchantDto = parseMerchantParam(merchantParam); | ||||
| @@ -462,18 +469,8 @@ public class WxCouponServiceImpl implements WxCouponService { | |||||
| cm.setCreateDate(new Date()); | cm.setCreateDate(new Date()); | ||||
| cm.setUpdateDate(new Date()); | cm.setUpdateDate(new Date()); | ||||
| cm.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); | cm.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); | ||||
| wxCouponMerchantDtoList.add(wxCouponMerchantDto); | |||||
| wxCouponMerchantMapper.insert(cm); | 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())) { | if (record.getPasswordSupport() != null && record.getPasswordSupport().equals(EnumCouponPasswordSupport.SUPPORTED.getCode())) { | ||||
| // todo 生成卡密无法修改, 调整 | // todo 生成卡密无法修改, 调整 | ||||
| @@ -506,7 +503,6 @@ public class WxCouponServiceImpl implements WxCouponService { | |||||
| cmParam.updateTenantInfo(record); | cmParam.updateTenantInfo(record); | ||||
| cmParam.setProductId(record.getId()); | cmParam.setProductId(record.getId()); | ||||
| List<WxCouponMerchant> oldList = wxCouponMerchantMapper.findList(cmParam); | List<WxCouponMerchant> oldList = wxCouponMerchantMapper.findList(cmParam); | ||||
| List<WxCouponMerchantDto> wxCouponMerchantDtoList = new ArrayList<>(); | |||||
| merchantParamList.stream().forEach(merchantParam -> { | merchantParamList.stream().forEach(merchantParam -> { | ||||
| WxCouponMerchant cm = new WxCouponMerchant(); | WxCouponMerchant cm = new WxCouponMerchant(); | ||||
| WxCouponMerchantDto wxCouponMerchantDto = parseMerchantParam(merchantParam); | WxCouponMerchantDto wxCouponMerchantDto = parseMerchantParam(merchantParam); | ||||
| @@ -527,7 +523,6 @@ public class WxCouponServiceImpl implements WxCouponService { | |||||
| cm.setUpdateDate(new Date()); | cm.setUpdateDate(new Date()); | ||||
| wxCouponMerchantMapper.insert(cm); | wxCouponMerchantMapper.insert(cm); | ||||
| } | } | ||||
| wxCouponMerchantDtoList.add(wxCouponMerchantDto); | |||||
| oldList.removeIf( | oldList.removeIf( | ||||
| old->old.getProductId().equals(record.getId()) && | old->old.getProductId().equals(record.getId()) && | ||||
| old.getMerchantId().equals(wxCouponMerchantDto.getMerchantId())); | old.getMerchantId().equals(wxCouponMerchantDto.getMerchantId())); | ||||
| @@ -539,16 +534,6 @@ public class WxCouponServiceImpl implements WxCouponService { | |||||
| wxCouponMerchantMapper.updateById(old); | 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()); | record.setUpdateDate(new Date()); | ||||
| wxCouponMapper.updateById(record); | wxCouponMapper.updateById(record); | ||||
| } | } | ||||
| @@ -564,6 +549,23 @@ public class WxCouponServiceImpl implements WxCouponService { | |||||
| if(merchantParamList == null || merchantParamList.isEmpty()){ | if(merchantParamList == null || merchantParamList.isEmpty()){ | ||||
| return new ResultData(ErrorCode.MERCHANT_INFO_NOT_FOUND.getCode(),"所属商户为空"); | return new ResultData(ErrorCode.MERCHANT_INFO_NOT_FOUND.getCode(),"所属商户为空"); | ||||
| } | } | ||||
| List<Long> merchantIds = new ArrayList<>(); | |||||
| for (JSONObject o:merchantParamList) { | |||||
| merchantIds.add(o.getLong("id")); | |||||
| } | |||||
| WxMerchant merchantQ = new WxMerchant(); | |||||
| merchantQ.updateTenantInfo(record); | |||||
| merchantQ.setIds(merchantIds); | |||||
| List<WxMerchant> merchantList = wxMerchantService.findList(merchantQ); | |||||
| if(merchantList.size() != merchantParamList.size()){ | |||||
| return new ResultData(ErrorCode.MERCHANT_INFO_NOT_EQUAL.getCode(),"所属商户信息异常"); | |||||
| } | |||||
| List<WxMerchant> badMerchant = merchantList.stream().filter(m -> !EnumMerchantStatus.VALID.getCode().equals(m.getStatus())).collect(toList()); | |||||
| if(badMerchant != null && !badMerchant.isEmpty()){ | |||||
| List<String> 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) { | if(record.getSalePrice() != null && record.getSalePrice() > 0) { | ||||
| EnumAppPlat plat = EnumCouponType.getAppPlat(record.getType()); | EnumAppPlat plat = EnumCouponType.getAppPlat(record.getType()); | ||||
| EnumPayWay payWay = EnumAppPlat.getPayWay(plat); | EnumPayWay payWay = EnumAppPlat.getPayWay(plat); | ||||
| @@ -580,56 +582,43 @@ public class WxCouponServiceImpl implements WxCouponService { | |||||
| EnumPayShare isShare = EnumPayShare.getEnum(payAccount.getShare()); | EnumPayShare isShare = EnumPayShare.getEnum(payAccount.getShare()); | ||||
| PayShareAdapterService payShareServie = payServiceFactory.getPayShareAdapterService(payWay.getCode(),payAccount.getPayVersion()); | PayShareAdapterService payShareServie = payServiceFactory.getPayShareAdapterService(payWay.getCode(),payAccount.getPayVersion()); | ||||
| List<Long> merchantIds = new ArrayList<>(); | |||||
| for (JSONObject o:merchantParamList) { | |||||
| merchantIds.add(o.getLong("id")); | |||||
| } | |||||
| WxMerchant merchantQ = new WxMerchant(); | |||||
| merchantQ.updateTenantInfo(record); | |||||
| merchantQ.setIds(merchantIds); | |||||
| Map<Long, String> idAndNamesMap = wxMerchantService.getIdAndNamesMap(merchantQ); | |||||
| if (EnumPayMchType.DIRECT.equals(payMchType)) { | 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<Long> 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<WxMerchant> 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()); | 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) { | 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 (EnumAppPlat.TOUTIAO.equals(plat)) { | ||||
| if (!MerchantImportStatus.improt_success.getCode().equals(receiver.getWxImportStatus()) | if (!MerchantImportStatus.improt_success.getCode().equals(receiver.getWxImportStatus()) | ||||
| && !MerchantImportStatus.improt_success.getCode().equals(receiver.getAlipayImportStatus()) | && !MerchantImportStatus.improt_success.getCode().equals(receiver.getAlipayImportStatus()) | ||||
| && !MerchantImportStatus.improt_success.getCode().equals(receiver.getHzImportStatus())) { | && !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)) { | } else if (EnumPayShare.YES.equals(isShare)) { | ||||
| List<String> merchantNames = new ArrayList(); | |||||
| for (Long merchantId:merchantIds) { | |||||
| WxProfitSharingReceiver receiver = payShareServie.getReceiver(payAccount, merchantId, null, payMchType.getCode()); | |||||
| List<String> badNames = new ArrayList(); | |||||
| for (WxMerchant merchant:merchantList) { | |||||
| WxProfitSharingReceiver receiver = payShareServie.getReceiver(payAccount, merchant.getId(), null, payMchType.getCode()); | |||||
| if (receiver == null) { | if (receiver == null) { | ||||
| merchantNames.add(idAndNamesMap.get(merchantId)); | |||||
| badNames.add(merchant.getName()); | |||||
| continue; | continue; | ||||
| // return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "第(" + n + ")个商户还未配置分账账户或未进件"); | |||||
| } | } | ||||
| if (EnumAppPlat.TOUTIAO.equals(plat)) { | if (EnumAppPlat.TOUTIAO.equals(plat)) { | ||||
| QueryMerchantResult openPayResult = payAccount.getOpenPayResult(); | QueryMerchantResult openPayResult = payAccount.getOpenPayResult(); | ||||
| @@ -640,30 +629,27 @@ public class WxCouponServiceImpl implements WxCouponService { | |||||
| } | } | ||||
| if(EnumYesOrNo.YES.getCode().equals(openPayResult.getAlipay()) | if(EnumYesOrNo.YES.getCode().equals(openPayResult.getAlipay()) | ||||
| && !MerchantImportStatus.improt_success.getCode().equals(receiver.getAlipayImportStatus())){ | && !MerchantImportStatus.improt_success.getCode().equals(receiver.getAlipayImportStatus())){ | ||||
| merchantNames.add(idAndNamesMap.get(merchantId)); | |||||
| badNames.add(merchant.getName()); | |||||
| continue; | continue; | ||||
| // return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "["+idAndNamesMap.get(merchantId)+"]未进件支付宝"); | |||||
| } | } | ||||
| if(EnumYesOrNo.YES.getCode().equals(openPayResult.getWx()) | if(EnumYesOrNo.YES.getCode().equals(openPayResult.getWx()) | ||||
| && !MerchantImportStatus.improt_success.getCode().equals(receiver.getWxImportStatus())){ | && !MerchantImportStatus.improt_success.getCode().equals(receiver.getWxImportStatus())){ | ||||
| merchantNames.add(idAndNamesMap.get(merchantId)); | |||||
| badNames.add(merchant.getName()); | |||||
| continue; | continue; | ||||
| // return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "["+idAndNamesMap.get(merchantId)+"]未进件微信"); | |||||
| } | } | ||||
| if(EnumYesOrNo.YES.getCode().equals(openPayResult.getHz()) | if(EnumYesOrNo.YES.getCode().equals(openPayResult.getHz()) | ||||
| && !MerchantImportStatus.improt_success.getCode().equals(receiver.getHzImportStatus())){ | && !MerchantImportStatus.improt_success.getCode().equals(receiver.getHzImportStatus())){ | ||||
| merchantNames.add(idAndNamesMap.get(merchantId)); | |||||
| badNames.add(merchant.getName()); | |||||
| continue; | 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 | @Override | ||||