Parcourir la source

//coupon

release_toaliyun_real
xhxu il y a 3 ans
Parent
révision
7d86506579
2 fichiers modifiés avec 171 ajouts et 38 suppressions
  1. +1
    -0
      mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponController.java
  2. +170
    -38
      mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java

+ 1
- 0
mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponController.java Voir le fichier

@@ -415,6 +415,7 @@ public class WxCouponController extends BaseController {
return new ResultData(Result.SUCCESS, "删除成功", null); return new ResultData(Result.SUCCESS, "删除成功", null);
} }


@TenantIgnore
@ApiOperation("根据id查询接口") @ApiOperation("根据id查询接口")
@GetMapping("/findById") @GetMapping("/findById")
@ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true)


+ 170
- 38
mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java Voir le fichier

@@ -365,16 +365,9 @@ public class WxCouponServiceImpl implements WxCouponService {
if(wxCouponCVo == null){ if(wxCouponCVo == null){
return null; return null;
} }
List<Long> couponIdList = new ArrayList<Long>();
couponIdList.add(wxCouponCVo.getId());
Map<Long, List<WxMerchantVo>> couponMerchantVoMap = wxMerchantService.findCouponMerchantVoList(couponIdList, mallTenantEntity,true);


List<WxMerchantVo> merchantList = couponMerchantVoMap.get(wxCouponCVo.getId());
if (merchantList != null) {
merchantList = merchantList.stream().filter(
m->m.getMerchantStatus().equals(EnumMerchantStatus.VALID.getCode()))
.collect(toList());
}
List<WxMerchantVo> merchantList = getMerchantVoList(wxCouponCVo, wxCouponCVo.getId(), wxCouponCVo.getType());

wxCouponCVo.setMerchantVoList(merchantList); wxCouponCVo.setMerchantVoList(merchantList);
if(EnumCouponType.COUPON_GIFT.getCode().equals(wxCouponCVo.getType())){ if(EnumCouponType.COUPON_GIFT.getCode().equals(wxCouponCVo.getType())){
WxCoupon coupon = new WxCoupon(); WxCoupon coupon = new WxCoupon();
@@ -389,6 +382,26 @@ public class WxCouponServiceImpl implements WxCouponService {
return wxCouponCVo; return wxCouponCVo;
} }


private List<WxMerchantVo> 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<WxCouponMall> couponMallList = wxCouponMallMapper.findList(couponMall);
List<WxMerchantVo> 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 @Override
public WxCouponCVo getVoStatusById(Long id,String tenantId) { public WxCouponCVo getVoStatusById(Long id,String tenantId) {
WxCouponCVo wxCouponCVo = wxCouponMapper.findVoStatusDetail(id,tenantId); WxCouponCVo wxCouponCVo = wxCouponMapper.findVoStatusDetail(id,tenantId);
@@ -524,6 +537,9 @@ public class WxCouponServiceImpl implements WxCouponService {
if(Result.SUCCESS != giftResult.code){ if(Result.SUCCESS != giftResult.code){
return giftResult; return giftResult;
} }

//判断直连检查收款帐号(必须),总分模式直接收款到小程序的收款帐号
checkCouponMakeMerchant(record);
//平台券先不设置商户 //平台券先不设置商户
Map<TenantEntity,String> tenantMerchantMap = null; Map<TenantEntity,String> tenantMerchantMap = null;
@@ -719,6 +735,9 @@ public class WxCouponServiceImpl implements WxCouponService {
* 父券对应子商场商户 * 父券对应子商场商户
*/ */
if (EnumCouponType.isParentCoupon(record.getType())) { if (EnumCouponType.isParentCoupon(record.getType())) {
if(EnumCouponType.COUPON_DOUYIN_BRAND.getCode().equals(record.getType())){
handCouponMerchantParams(record);
}
if (StringUtils.isBlank(record.getChildMerchantParams())){ if (StringUtils.isBlank(record.getChildMerchantParams())){
throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_FOUND.getCode(),"所属商户为空"); throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_FOUND.getCode(),"所属商户为空");
} }
@@ -764,6 +783,37 @@ public class WxCouponServiceImpl implements WxCouponService {
return retMap; return retMap;
} }
} }

private void handCouponMerchantParams(WxCoupon record){
List<JSONObject> merchantParamList = JSONObject.parseArray(record.getMerchantParams(), JSONObject.class);
if(merchantParamList == null || merchantParamList.isEmpty()){
throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_FOUND.getCode(),"所属商户为空");
}

Map<String,List<JSONObject>> 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<JSONObject> merchantParams = map.get(tenantId);
if(merchantParams == null){
merchantParams = new ArrayList<>();
}
merchantParams.add(o);
map.put(tenantId,merchantParams);
}

List<JSONObject> childMerchantParams = new ArrayList<>();
for (Iterator<String> 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<WxMerchant> checkCouponOneMallMerchantReceiver(TenantEntity mallTenantEntity,String merchantParams,WxCoupon record) throws Exception { private List<WxMerchant> checkCouponOneMallMerchantReceiver(TenantEntity mallTenantEntity,String merchantParams,WxCoupon record) throws Exception {
List<JSONObject> merchantParamList = JSONObject.parseArray(merchantParams, JSONObject.class); List<JSONObject> merchantParamList = JSONObject.parseArray(merchantParams, JSONObject.class);
@@ -820,32 +870,34 @@ public class WxCouponServiceImpl implements WxCouponService {
PayShareAdapterService payShareServie = payServiceFactory.getPayShareAdapterService(payWay.getCode(),payAccount.getPayVersion()); PayShareAdapterService payShareServie = payServiceFactory.getPayShareAdapterService(payWay.getCode(),payAccount.getPayVersion());


if (EnumPayMchType.DIRECT.equals(payMchType)) { 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)) { } else if (EnumPayShare.YES.equals(isShare)) {
List<String> badNames = new ArrayList(); List<String> badNames = new ArrayList();
for (WxMerchant merchant:merchantList) { 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<JSONObject> 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 @Override
public Map<Long, String> getCouponMerchantMap(List<Long> couponIds, TenantEntity tenantEntity,boolean onlyOneMerchantCoupons) { public Map<Long, String> getCouponMerchantMap(List<Long> couponIds, TenantEntity tenantEntity,boolean onlyOneMerchantCoupons) {
Map<Long,String> couponMerchantMap = new HashMap<Long,String>(); Map<Long,String> couponMerchantMap = new HashMap<Long,String>();
@@ -1622,7 +1754,7 @@ public class WxCouponServiceImpl implements WxCouponService {
if (null == wxCoupon.getMerchantIds()) { if (null == wxCoupon.getMerchantIds()) {
throw new MallinkException(Result.ERROR,"请选择商户"); throw new MallinkException(Result.ERROR,"请选择商户");
} }
Long makeMerchantId = coupon.getMakeMerchantId();
// Long makeMerchantId = coupon.getMakeMerchantId();
// //
StringBuffer merchantParams = new StringBuffer("[{\"tenantId\":").append(mallTenantEntity.getTenantId()).append(",\"mallMerchantParams\":").append("["); StringBuffer merchantParams = new StringBuffer("[{\"tenantId\":").append(mallTenantEntity.getTenantId()).append(",\"mallMerchantParams\":").append("[");
Long[] mids = wxCoupon.getMerchantIds(); Long[] mids = wxCoupon.getMerchantIds();
@@ -1638,9 +1770,9 @@ public class WxCouponServiceImpl implements WxCouponService {
final IdWorker idWorker = IdWorker.get(); final IdWorker idWorker = IdWorker.get();
updateCouponMerchants(coupon,idWorker); updateCouponMerchants(coupon,idWorker);
//平台券设置商管商户 //平台券设置商管商户
if (null != coupon.getMakeMerchantId()) {
wxCouponMapper.setMakeMerchantId(coupon);
}
// if (null != coupon.getMakeMerchantId()) {
// wxCouponMapper.setMakeMerchantId(coupon);
// }
}catch(Exception e) { }catch(Exception e) {
throw e; throw e;
} }


Chargement…
Annuler
Enregistrer