Просмотр исходного кода

[补贴][修改]:所有权均可配置补贴,通用券支持多商户分别配置

release_toaliyun_real
hupeng 7 лет назад
Родитель
Сommit
7cda84a8f6
3 измененных файлов: 97 добавлений и 33 удалений
  1. +36
    -0
      mallinkService/src/main/java/com/iformall/domain/dto/WxCouponMerchantDto.java
  2. +20
    -7
      mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java
  3. +41
    -26
      mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java

+ 36
- 0
mallinkService/src/main/java/com/iformall/domain/dto/WxCouponMerchantDto.java Просмотреть файл

@@ -0,0 +1,36 @@
package com.iformall.domain.dto;

import java.io.Serializable;



public class WxCouponMerchantDto implements Serializable {
private static final long serialVersionUID = 1L;
Long merchantId;
String parameter;
Integer business;

public Long getMerchantId() {
return merchantId;
}

public void setMerchantId(Long merchantId) {
this.merchantId = merchantId;
}

public String getParameter() {
return parameter;
}

public void setParameter(String parameter) {
this.parameter = parameter;
}

public Integer getBusiness() {
return business;
}

public void setBusiness(Integer business) {
this.business = business;
}
}

+ 20
- 7
mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java Просмотреть файл

@@ -6,6 +6,7 @@ import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaTemplateData;
import cn.binarywang.wx.miniapp.bean.WxMaTemplateMessage;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;
@@ -445,13 +446,25 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService {
WxAppinfo wxAppinfo = wxAppinfoService.getCAppInfo(couponOrder.getTenantId());
WxPayAccount payAccount = wxPayAccountMapper.selectByPrimaryKey(wxAppinfo.getPayId());

Integer subsidyNum;
String parameter = couponMerchant.getParameter();
JSONObject jParameter;
try {
jParameter = JSONObject.parseObject(parameter);
} catch (Exception e) {
jParameter = null;
}

// 本张券的补贴额
Integer subsidyFee = coupon.getSubsidyNum();
if (subsidyFee > 0) {
if (jParameter != null) {
subsidyNum = jParameter.getIntValue("subsidyNum");
} else {
// 本张券的补贴额
subsidyNum = coupon.getSubsidyNum();
}
if (subsidyNum > 0) {
// 有补贴时入库
Double dSubChargeFee = Math.ceil(subsidyFee * 1.0D * payAccount.getRate() / 10000);
Integer realSubsidyFee = subsidyFee - dSubChargeFee.intValue();
Double dSubChargeFee = Math.ceil(subsidyNum * 1.0D * payAccount.getRate() / 10000);
Integer realSubsidyFee = subsidyNum - dSubChargeFee.intValue();

Double priceChargeFee = Math.ceil(coupon.getSalePrice() * 1.0D * payAccount.getRate() / 10000);
Integer realPayment = coupon.getSalePrice() - priceChargeFee.intValue();
@@ -463,11 +476,11 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService {
merchantSubsidy.setOrderType(EnumOrderType.COUPON.getCode());
merchantSubsidy.setMerchantId(merchantId);
merchantSubsidy.setCouponOrderId(couponOrder.getId());
merchantSubsidy.setCouponType(EnumCouponType.COUPON_MULTIMCH.getCode());
merchantSubsidy.setCouponType(couponOrder.getCouponType());
merchantSubsidy.setOrderPayment(coupon.getPrice());
merchantSubsidy.setReceiverPayment(coupon.getSalePrice());
merchantSubsidy.setRealPayment(realPayment);
merchantSubsidy.setSubsidy(subsidyFee);
merchantSubsidy.setSubsidy(subsidyNum);
merchantSubsidy.setRealSubsidy(realSubsidyFee);
merchantSubsidy.setStatus(EnumMerchantSubsidyStatus.NOT_SUBSIDY.getCode());
merchantSubsidy.setCreateDate(new Date());


+ 41
- 26
mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java Просмотреть файл

@@ -7,6 +7,7 @@ import com.github.pagehelper.PageInfo;
import com.iformall.common.ErrorCode;
import com.iformall.common.IdWorker;
import com.iformall.common.ResultData;
import com.iformall.domain.dto.WxCouponMerchantDto;
import com.iformall.domain.po.WxCoupon;
import com.iformall.domain.po.WxCouponChannel;
import com.iformall.domain.po.WxCouponMerchant;
@@ -14,6 +15,7 @@ import com.iformall.domain.vo.WxCouponCVo;
import com.iformall.domain.vo.WxCouponStatisVo;
import com.iformall.domain.vo.WxMerchantVo;
import com.iformall.enums.*;
import com.iformall.exception.MallinkException;
import com.iformall.mapper.WxCouponChannelMapper;
import com.iformall.mapper.WxCouponMapper;
import com.iformall.mapper.WxCouponMerchantMapper;
@@ -157,6 +159,22 @@ public class WxCouponServiceImpl implements WxCouponService {
return Integer.valueOf(merchantParam.getString("businessId"));
}

private WxCouponMerchantDto parseMerchantParam(JSONObject merchantParam){
WxCouponMerchantDto wxCouponMerchantDto = new WxCouponMerchantDto();
try {
wxCouponMerchantDto.setMerchantId(parseMerchantId(merchantParam));
wxCouponMerchantDto.setParameter(parseParameter(merchantParam));
wxCouponMerchantDto.setBusiness(parseBusiness(merchantParam));
}catch (Exception e) {
throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR);
}
if (wxCouponMerchantDto.getBusiness()==null || wxCouponMerchantDto.getMerchantId()==null) {
throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR);
}
return wxCouponMerchantDto;
}


@Override
@Transactional(isolation=Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class})
public ResultData saveOrUpdate(WxCoupon record) {
@@ -190,47 +208,44 @@ public class WxCouponServiceImpl implements WxCouponService {
if (record.getId() == null) {

// check 卡券补贴设置
if(record.getType().equals(EnumCouponType.COUPON_MULTIMCH.getCode()) ||
record.getType().equals(EnumCouponType.CARD_MULTIMCH.getCode())) {
Integer subsidyType = record.getSubsidyType();
Integer subsidyNum = record.getSubsidyNum();
if(subsidyType == null) {
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "请填写补贴类型");
}
if(subsidyNum == null) {
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "请填写补贴金额");
}
if(subsidyType.equals(EnumCouponSubsidyType.WECHAT_COUPON.getCode())) {
Integer subsidyType = record.getSubsidyType();
Integer subsidyNum = record.getSubsidyNum();
if(subsidyType != null && subsidyNum != null) {
if (subsidyType.equals(EnumCouponSubsidyType.WECHAT_COUPON.getCode())) {
// 微信 立减
if(subsidyNum > record.getSalePrice()) {
if (subsidyNum > record.getSalePrice()) {
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "补贴额大于售价");
}
} else if(subsidyType.equals(EnumCouponSubsidyType.OFFLINE_SUBSIDY.getCode())) {
} else if (subsidyType.equals(EnumCouponSubsidyType.OFFLINE_SUBSIDY.getCode())) {
// 线下补贴
int subsidy_num = record.getPrice() - record.getSalePrice();
if(subsidyNum > subsidy_num) {
if (subsidyNum > subsidy_num) {
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "补贴额大于面额与售价的差值");
}
} else if(subsidyType.equals(EnumCouponSubsidyType.WECHAT_MCHPAY.getCode())) {
} else if (subsidyType.equals(EnumCouponSubsidyType.WECHAT_MCHPAY.getCode())) {
// TODO 微信转账到银行卡

}
} else if ((subsidyType == null && subsidyNum != null)
|| (subsidyType != null && subsidyNum == null)){
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR);
}

record.setId(idWorker.nextId());
if (record.getMerchantParams() != null) {
List<JSONObject> merchantParamList = JSONObject.parseArray(record.getMerchantParams(), JSONObject.class);
List<JSONObject> merchantParamList = JSONObject.parseArray(record.getMerchantParams(), JSONObject.class);
if (merchantParamList != null) {
List<Integer> businessList= new ArrayList<>();
merchantParamList.forEach(merchantParam -> {
WxCouponMerchant cm = new WxCouponMerchant();
WxCouponMerchantDto wxCouponMerchantDto = parseMerchantParam(merchantParam);
cm.setId(idWorker.nextId());
cm.setMerchantId(parseMerchantId(merchantParam));
cm.setParameter(parseParameter(merchantParam));
cm.setMerchantId(wxCouponMerchantDto.getMerchantId());
cm.setParameter(wxCouponMerchantDto.getParameter());
cm.setProductId(record.getId());
cm.setCreateDate(new Date());
cm.setUpdateDate(new Date());
cm.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode());
businessList.add(parseBusiness(merchantParam));
businessList.add(wxCouponMerchantDto.getBusiness());
wxCouponMerchantMapper.insertSelective(cm);
});
if (businessList.stream().distinct().count() > 1) {
@@ -257,27 +272,27 @@ public class WxCouponServiceImpl implements WxCouponService {
List<Integer> businessList= new ArrayList<>();
merchantParamList.stream().forEach(merchantParam -> {
WxCouponMerchant cm = new WxCouponMerchant();
cm.setMerchantId(parseMerchantId(merchantParam));
WxCouponMerchantDto wxCouponMerchantDto = parseMerchantParam(merchantParam);
cm.setMerchantId(wxCouponMerchantDto.getMerchantId());
cm.setProductId(record.getId());
WxCouponMerchant rcm = wxCouponMerchantMapper.selectOne(cm);
if (rcm != null) {
rcm.setMerchantId(Long.valueOf(parseMerchantId(merchantParam)));
rcm.setParameter(parseParameter(merchantParam));
rcm.setParameter(wxCouponMerchantDto.getParameter());
rcm.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode());
rcm.setUpdateDate(new Date());
wxCouponMerchantMapper.updateByPrimaryKeySelective(rcm);
}else {
cm.setId(idWorker.nextId());
cm.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode());
cm.setParameter(parseParameter(merchantParam));
cm.setParameter(wxCouponMerchantDto.getParameter());
cm.setCreateDate(new Date());
cm.setUpdateDate(new Date());
wxCouponMerchantMapper.insertSelective(cm);
}
businessList.add(Integer.valueOf(parseBusiness(merchantParam)));
businessList.add(Integer.valueOf(wxCouponMerchantDto.getBusiness()));
oldList.removeIf(
old->old.getProductId().equals(record.getId()) &&
old.getMerchantId().equals(Long.valueOf(parseMerchantId(merchantParam))));
old.getMerchantId().equals(wxCouponMerchantDto.getMerchantId()));
});

oldList.stream().forEach(old->{


Загрузка…
Отмена
Сохранить