|
@@ -16,8 +16,10 @@ import com.ym.mec.common.dal.BaseDAO;
|
|
|
import com.ym.mec.common.exception.BizException;
|
|
|
import com.ym.mec.common.page.PageInfo;
|
|
|
import com.ym.mec.common.page.QueryInfo;
|
|
|
+import com.ym.mec.common.page.WrapperUtil;
|
|
|
import com.ym.mec.common.service.IdGeneratorService;
|
|
|
import com.ym.mec.common.service.impl.BaseServiceImpl;
|
|
|
+import com.ym.mec.common.tenant.TenantContextHolder;
|
|
|
import com.ym.mec.util.collection.MapUtil;
|
|
|
import com.ym.mec.util.date.DateUtil;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
@@ -25,7 +27,6 @@ import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Isolation;
|
|
|
-import org.springframework.transaction.annotation.Propagation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
@@ -33,197 +34,235 @@ import java.util.*;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
|
@Service
|
|
|
-public class SysCouponCodeServiceImpl extends BaseServiceImpl<Long, SysCouponCode> implements SysCouponCodeService {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private SysCouponCodeDao sysCouponCodeDao;
|
|
|
- @Autowired
|
|
|
- private SysCouponService sysCouponService;
|
|
|
- @Autowired
|
|
|
- private SysCouponDao sysCouponDao;
|
|
|
- @Autowired
|
|
|
- private IdGeneratorService idGeneratorService;
|
|
|
- @Autowired
|
|
|
- private StudentPaymentOrderDao studentPaymentOrderDao;
|
|
|
-
|
|
|
- @Override
|
|
|
- public BaseDAO<Long, SysCouponCode> getDAO() {
|
|
|
- return sysCouponCodeDao;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- @Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
|
|
|
- public boolean exchangeCouponTest(Integer userId, Integer couponId, Long paymentOrderId, Integer exchangeNum) {
|
|
|
- return exchangeCoupon(userId, couponId, paymentOrderId, exchangeNum);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- @Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
|
|
|
- public boolean exchangeCoupon(Integer userId, Integer couponId, Long paymentOrderId, Integer exchangeNum) {
|
|
|
- if(Objects.isNull(userId)||Objects.isNull(couponId)||Objects.isNull(paymentOrderId)||Objects.isNull(exchangeNum)){
|
|
|
- throw new BizException("领取失败");
|
|
|
- }
|
|
|
- if(exchangeNum<=0){
|
|
|
- return true;
|
|
|
- }
|
|
|
- SysCoupon sysCoupon = sysCouponDao.lockCoupon(couponId);
|
|
|
- Date now = new Date();
|
|
|
- //如果优惠券不存在,或者已停用,或者不在领取有效期内,或者已消耗完,则此优惠券无效
|
|
|
- boolean invalid = Objects.isNull(sysCoupon)||0==sysCoupon.getStatus()||now.compareTo(sysCoupon.getStartDate())<0||now.compareTo(sysCoupon.getEndDate())>0;
|
|
|
- invalid = invalid || sysCoupon.getStockCount()!=-1&&sysCoupon.getConsumeNum()>=sysCoupon.getStockCount()&&(sysCoupon.getStockCount()-sysCoupon.getConsumeNum()<exchangeNum);
|
|
|
- if(invalid){
|
|
|
- throw new BizException("无效优惠券");
|
|
|
- }
|
|
|
- StudentPaymentOrder studentPaymentOrder = studentPaymentOrderDao.get(paymentOrderId);
|
|
|
- if(Objects.isNull(studentPaymentOrder)){
|
|
|
- throw new BizException("无效订单");
|
|
|
- }
|
|
|
- if(sysCoupon.getLimitExchangeNum()!=-1){
|
|
|
- int userUserNum = sysCouponCodeDao.countWithUserAndCoupon(userId, couponId);
|
|
|
- invalid = (userUserNum + exchangeNum)>sysCoupon.getLimitExchangeNum();
|
|
|
- }
|
|
|
- //如果用户使用数量超过优惠券限制则领取无效
|
|
|
- if(invalid){
|
|
|
- throw new BizException("当前优惠券最多可领取{}次", sysCoupon.getLimitExchangeNum());
|
|
|
- }
|
|
|
- SysCouponCode sysCouponCode = new SysCouponCode();
|
|
|
- sysCouponCode.setUserId(userId);
|
|
|
- sysCouponCode.setCouponId(couponId);
|
|
|
- sysCouponCode.setPaymentOrderId(paymentOrderId);
|
|
|
- sysCouponCode.setUsageStatus(0);
|
|
|
- switch (sysCoupon.getEffectiveType()){
|
|
|
- case DAYS:
|
|
|
- sysCouponCode.setUseStartDate(now);
|
|
|
- sysCouponCode.setUseDeadlineDate(DateUtil.addDays(now, sysCoupon.getDeadline()));
|
|
|
- break;
|
|
|
- case TIME_BUCKET:
|
|
|
- sysCouponCode.setUseStartDate(sysCoupon.getEffectiveStartTime());
|
|
|
- sysCouponCode.setUseDeadlineDate(sysCoupon.getEffectiveExpireTime());
|
|
|
- break;
|
|
|
- default:
|
|
|
- throw new BizException("无效优惠券", sysCoupon.getLimitExchangeNum());
|
|
|
- }
|
|
|
- List<SysCouponCode> couponCodes = new ArrayList<>();
|
|
|
- for (int i = 0; i < exchangeNum; i++) {
|
|
|
- SysCouponCode couponCode = new SysCouponCode();
|
|
|
- BeanUtils.copyProperties(sysCouponCode, couponCode);
|
|
|
- couponCode.setCode(String.valueOf(idGeneratorService.generatorId("coupon")));
|
|
|
- couponCodes.add(couponCode);
|
|
|
- }
|
|
|
- sysCouponCodeDao.batchInsert(couponCodes);
|
|
|
- sysCoupon.setConsumeNum(new AtomicInteger(sysCoupon.getConsumeNum()).addAndGet(exchangeNum));
|
|
|
- if(sysCoupon.getWarningStatus()==0&&sysCoupon.getStockCount()!=-1&&sysCoupon.getStockCount()-sysCoupon.getConsumeNum()<sysCoupon.getWarningStockNum()){
|
|
|
- sysCouponService.stockWarning(sysCoupon.getId(), sysCoupon.getName());
|
|
|
- sysCoupon.setWarningStatus(1);
|
|
|
- }
|
|
|
- sysCouponDao.update(sysCoupon);
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public PageInfo<SysCouponCodeDto> querySysCouponUseList(SysCouponCodeQueryInfo queryInfo) {
|
|
|
- PageInfo<SysCouponCodeDto> pageInfo = new PageInfo<>(queryInfo.getPage(), queryInfo.getRows());
|
|
|
- Map<String, Object> params = new HashMap<String, Object>();
|
|
|
- MapUtil.populateMap(params, queryInfo);
|
|
|
-
|
|
|
- List<SysCouponCodeDto> dataList = new ArrayList<>();
|
|
|
- int count = sysCouponCodeDao.countSysCouponUseList(params);
|
|
|
- if (count > 0) {
|
|
|
- pageInfo.setTotal(count);
|
|
|
- params.put("offset", pageInfo.getOffset());
|
|
|
- dataList = sysCouponCodeDao.querySysCouponUseList(params);
|
|
|
- }
|
|
|
- pageInfo.setRows(dataList);
|
|
|
- return pageInfo;
|
|
|
- }
|
|
|
+public class SysCouponCodeServiceImpl extends BaseServiceImpl<Long, SysCouponCode> implements SysCouponCodeService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysCouponCodeDao sysCouponCodeDao;
|
|
|
+ @Autowired
|
|
|
+ private SysCouponService sysCouponService;
|
|
|
+ @Autowired
|
|
|
+ private SysCouponDao sysCouponDao;
|
|
|
+ @Autowired
|
|
|
+ private IdGeneratorService idGeneratorService;
|
|
|
+ @Autowired
|
|
|
+ private StudentPaymentOrderDao studentPaymentOrderDao;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public BaseDAO<Long, SysCouponCode> getDAO() {
|
|
|
+ return sysCouponCodeDao;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
|
|
|
+ public boolean exchangeCouponTest(Integer userId, Integer couponId, Long paymentOrderId, Integer exchangeNum) {
|
|
|
+ return exchangeCoupon(userId, couponId, paymentOrderId, exchangeNum, 0, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 兑换优惠券
|
|
|
+ *
|
|
|
+ * @param userId: 用户编号
|
|
|
+ * @param couponId: 优惠券编号
|
|
|
+ * @param paymentOrderId: 订单编号
|
|
|
+ * @param exchangeNum: 兑换数量
|
|
|
+ * @param type: 2有paymentOrderId属于订单送券,交易获取,0手动领取 1手动发放
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
|
|
|
+ public boolean exchangeCoupon(Integer userId, Integer couponId, Long paymentOrderId, Integer exchangeNum, int type, Integer issueId) {
|
|
|
+ //检查参数
|
|
|
+ SysCouponCode sysCouponCode = checkParam(userId, couponId, paymentOrderId, exchangeNum, type, issueId);
|
|
|
+ //兑换数量0或者比0小直接返回
|
|
|
+ if (exchangeNum <= 0) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ //校验优惠券是否合法
|
|
|
+ SysCoupon sysCoupon = checkCoupon(userId, couponId, exchangeNum);
|
|
|
+ //写入数据
|
|
|
+ opsCoupon(userId, sysCouponCode, couponId, exchangeNum, sysCoupon);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private SysCouponCode checkParam(Integer userId, Integer couponId, Long paymentOrderId, Integer exchangeNum, int type, Integer issueId) {
|
|
|
+ SysCouponCode sysCouponCode = new SysCouponCode();
|
|
|
+ if (type == 2 && WrapperUtil.checkObj(userId, couponId, paymentOrderId, exchangeNum)) {
|
|
|
+ StudentPaymentOrder studentPaymentOrder = studentPaymentOrderDao.get(paymentOrderId);
|
|
|
+ if (Objects.isNull(studentPaymentOrder)) {
|
|
|
+ throw new BizException("无效订单");
|
|
|
+ }
|
|
|
+ sysCouponCode.setPaymentOrderId(paymentOrderId);
|
|
|
+ } else if ((type == 0 || type == 1) && WrapperUtil.checkObj(userId, couponId, issueId, exchangeNum)) {
|
|
|
+ sysCouponCode.setIssueId(issueId);
|
|
|
+ } else {
|
|
|
+ throw new BizException("领取失败");
|
|
|
+ }
|
|
|
+ sysCouponCode.setType(type);
|
|
|
+ return sysCouponCode;
|
|
|
+ }
|
|
|
+
|
|
|
+ private SysCoupon checkCoupon(Integer userId, Integer couponId, Integer exchangeNum) {
|
|
|
+ //锁定优惠券
|
|
|
+ SysCoupon sysCoupon = sysCouponDao.lockCoupon(couponId);
|
|
|
+
|
|
|
+ Date now = new Date();
|
|
|
+ //如果优惠券不存在,或者已停用,或者不在领取有效期内,或者已消耗完,则此优惠券无效
|
|
|
+ boolean invalid = Objects.isNull(sysCoupon) || 0 == sysCoupon.getStatus() || now.compareTo(sysCoupon.getStartDate()) < 0 || now.compareTo(sysCoupon.getEndDate()) > 0;
|
|
|
+ invalid = invalid || sysCoupon.getStockCount() != -1 && sysCoupon.getConsumeNum() >= sysCoupon.getStockCount() && (sysCoupon.getStockCount() - sysCoupon.getConsumeNum() < exchangeNum);
|
|
|
+ if (invalid) {
|
|
|
+ throw new BizException("无效优惠券");
|
|
|
+ }
|
|
|
+ //校验兑换的最大次数
|
|
|
+ if (sysCoupon.getLimitExchangeNum() != -1) {
|
|
|
+ int userUserNum = sysCouponCodeDao.countWithUserAndCoupon(userId, couponId);
|
|
|
+ invalid = (userUserNum + exchangeNum) > sysCoupon.getLimitExchangeNum();
|
|
|
+ }
|
|
|
+ //如果用户使用数量超过优惠券限制则领取无效
|
|
|
+ if (invalid) {
|
|
|
+ throw new BizException("当前优惠券最多可领取{}次", sysCoupon.getLimitExchangeNum());
|
|
|
+ }
|
|
|
+ return sysCoupon;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void opsCoupon(Integer userId, SysCouponCode sysCouponCode, Integer couponId, Integer exchangeNum, SysCoupon sysCoupon) {
|
|
|
+ Integer tenantId = TenantContextHolder.getTenantId();
|
|
|
+ Date now = new Date();
|
|
|
+ sysCouponCode.setUserId(userId);
|
|
|
+ sysCouponCode.setCouponId(couponId);
|
|
|
+ sysCouponCode.setUsageStatus(0);
|
|
|
+ sysCouponCode.setTenantId(tenantId);
|
|
|
+ switch (sysCoupon.getEffectiveType()) {
|
|
|
+ case DAYS:
|
|
|
+ sysCouponCode.setUseStartDate(now);
|
|
|
+ sysCouponCode.setUseDeadlineDate(DateUtil.addDays(now, sysCoupon.getDeadline()));
|
|
|
+ break;
|
|
|
+ case TIME_BUCKET:
|
|
|
+ sysCouponCode.setUseStartDate(sysCoupon.getEffectiveStartTime());
|
|
|
+ sysCouponCode.setUseDeadlineDate(sysCoupon.getEffectiveExpireTime());
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ throw new BizException("无效优惠券", sysCoupon.getLimitExchangeNum());
|
|
|
+ }
|
|
|
+ List<SysCouponCode> couponCodes = new ArrayList<>();
|
|
|
+ for (int i = 0; i < exchangeNum; i++) {
|
|
|
+ SysCouponCode couponCode = new SysCouponCode();
|
|
|
+ BeanUtils.copyProperties(sysCouponCode, couponCode);
|
|
|
+ couponCode.setCode(String.valueOf(idGeneratorService.generatorId("coupon")));
|
|
|
+ couponCode.setTenantId(tenantId);
|
|
|
+ couponCodes.add(couponCode);
|
|
|
+ }
|
|
|
+ sysCouponCodeDao.batchInsert(couponCodes);
|
|
|
+ sysCoupon.setConsumeNum(new AtomicInteger(sysCoupon.getConsumeNum()).addAndGet(exchangeNum));
|
|
|
+ if (sysCoupon.getWarningStatus() == 0 && sysCoupon.getStockCount() != -1 && sysCoupon.getStockCount() - sysCoupon.getConsumeNum() < sysCoupon.getWarningStockNum()) {
|
|
|
+ sysCouponService.stockWarning(sysCoupon.getId(), sysCoupon.getName());
|
|
|
+ sysCoupon.setWarningStatus(1);
|
|
|
+ }
|
|
|
+ sysCouponDao.update(sysCoupon);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PageInfo<SysCouponCodeDto> querySysCouponUseList(SysCouponCodeQueryInfo queryInfo) {
|
|
|
+ PageInfo<SysCouponCodeDto> pageInfo = new PageInfo<>(queryInfo.getPage(), queryInfo.getRows());
|
|
|
+ Map<String, Object> params = new HashMap<String, Object>();
|
|
|
+ MapUtil.populateMap(params, queryInfo);
|
|
|
+
|
|
|
+ List<SysCouponCodeDto> dataList = new ArrayList<>();
|
|
|
+ int count = sysCouponCodeDao.countSysCouponUseList(params);
|
|
|
+ if (count > 0) {
|
|
|
+ pageInfo.setTotal(count);
|
|
|
+ params.put("offset", pageInfo.getOffset());
|
|
|
+ dataList = sysCouponCodeDao.querySysCouponUseList(params);
|
|
|
+ }
|
|
|
+ pageInfo.setRows(dataList);
|
|
|
+ return pageInfo;
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
public PageInfo<HorseRaceLampDto> queryHorseRaceLampDtoList(QueryInfo queryInfo) {
|
|
|
- PageInfo<HorseRaceLampDto> pageInfo = new PageInfo<>(queryInfo.getPage(), queryInfo.getRows());
|
|
|
- Map<String, Object> params = new HashMap<String, Object>();
|
|
|
- MapUtil.populateMap(params, queryInfo);
|
|
|
-
|
|
|
- List<HorseRaceLampDto> dataList = new ArrayList<>();
|
|
|
- int count = sysCouponCodeDao.countHorseRaceLampDtoList(params);
|
|
|
- if (count > 0) {
|
|
|
- pageInfo.setTotal(count);
|
|
|
- params.put("offset", pageInfo.getOffset());
|
|
|
- dataList = sysCouponCodeDao.queryHorseRaceLampDtoList(params);
|
|
|
- }
|
|
|
- pageInfo.setRows(dataList);
|
|
|
- return pageInfo;
|
|
|
+ PageInfo<HorseRaceLampDto> pageInfo = new PageInfo<>(queryInfo.getPage(), queryInfo.getRows());
|
|
|
+ Map<String, Object> params = new HashMap<String, Object>();
|
|
|
+ MapUtil.populateMap(params, queryInfo);
|
|
|
+
|
|
|
+ List<HorseRaceLampDto> dataList = new ArrayList<>();
|
|
|
+ int count = sysCouponCodeDao.countHorseRaceLampDtoList(params);
|
|
|
+ if (count > 0) {
|
|
|
+ pageInfo.setTotal(count);
|
|
|
+ params.put("offset", pageInfo.getOffset());
|
|
|
+ dataList = sysCouponCodeDao.queryHorseRaceLampDtoList(params);
|
|
|
+ }
|
|
|
+ pageInfo.setRows(dataList);
|
|
|
+ return pageInfo;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<SysCouponCode> queryCouponPage(BigDecimal amount, Integer userId) {
|
|
|
|
|
|
- return null;
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public StudentPaymentOrder use(List<Integer> couponIdList, BigDecimal amount,Boolean useFlag) {
|
|
|
- StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder();
|
|
|
- if(couponIdList != null && couponIdList.size() > 0){
|
|
|
- Date date = new Date();
|
|
|
- List<SysCouponCodeDto> couponCodeDtoList = sysCouponCodeDao.findByIdList(couponIdList);
|
|
|
- if(couponIdList.size() != couponCodeDtoList.size()){
|
|
|
- throw new BizException("操作失败:优惠券数据异常");
|
|
|
- }
|
|
|
- BigDecimal fullAmount = BigDecimal.ZERO;
|
|
|
- BigDecimal faceAmount = BigDecimal.ZERO;
|
|
|
-
|
|
|
- for (SysCouponCodeDto sysCouponCodeDto : couponCodeDtoList) {
|
|
|
- if(sysCouponCodeDto.getUsageStatus() == 1){
|
|
|
- throw new BizException("操作失败:优惠券已使用");
|
|
|
- }
|
|
|
- if(sysCouponCodeDto.getUseStartDate().after(date)){
|
|
|
- throw new BizException("操作失败:不在优惠券使用期限");
|
|
|
- }
|
|
|
- if(date.after(sysCouponCodeDto.getUseDeadlineDate())){
|
|
|
- throw new BizException("操作失败:优惠券已过期");
|
|
|
- }
|
|
|
- CouponTypeEnum couponType = sysCouponCodeDto.getCouponType();
|
|
|
- switch (couponType){
|
|
|
- case DISCOUNT:
|
|
|
- throw new BizException("操作失败:暂不支持折扣劵");
|
|
|
- case FULL_REDUCTION:
|
|
|
- fullAmount = fullAmount.add(sysCouponCodeDto.getFullAmount());
|
|
|
- faceAmount = faceAmount.add(sysCouponCodeDto.getFaceValue());
|
|
|
- break;
|
|
|
- default:
|
|
|
- throw new BizException("操作失败:错误的优惠券类型");
|
|
|
- }
|
|
|
- }
|
|
|
- if(amount.compareTo(fullAmount) < 0){
|
|
|
- throw new BizException("操作失败:当前消费金额不满足优惠券满减条件");
|
|
|
- }
|
|
|
- amount = amount.subtract(faceAmount);
|
|
|
- if (amount.signum() < 0) {
|
|
|
- amount = BigDecimal.ZERO;
|
|
|
- }
|
|
|
- //使用优惠券
|
|
|
- if(useFlag){
|
|
|
- sysCouponCodeDao.use(couponIdList);
|
|
|
- }
|
|
|
- studentPaymentOrder.setCouponCodeId(StringUtils.join(couponIdList,","));
|
|
|
- studentPaymentOrder.setCouponRemitFee(faceAmount);
|
|
|
- }
|
|
|
- studentPaymentOrder.setExpectAmount(amount);
|
|
|
- studentPaymentOrder.setActualAmount(amount);
|
|
|
- return studentPaymentOrder;
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public StudentPaymentOrder use(List<Integer> couponIdList, BigDecimal amount, Boolean useFlag) {
|
|
|
+ StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder();
|
|
|
+ if (couponIdList != null && couponIdList.size() > 0) {
|
|
|
+ Date date = new Date();
|
|
|
+ List<SysCouponCodeDto> couponCodeDtoList = sysCouponCodeDao.findByIdList(couponIdList);
|
|
|
+ if (couponIdList.size() != couponCodeDtoList.size()) {
|
|
|
+ throw new BizException("操作失败:优惠券数据异常");
|
|
|
+ }
|
|
|
+ BigDecimal fullAmount = BigDecimal.ZERO;
|
|
|
+ BigDecimal faceAmount = BigDecimal.ZERO;
|
|
|
+
|
|
|
+ for (SysCouponCodeDto sysCouponCodeDto : couponCodeDtoList) {
|
|
|
+ if (sysCouponCodeDto.getUsageStatus() == 1) {
|
|
|
+ throw new BizException("操作失败:优惠券已使用");
|
|
|
+ }
|
|
|
+ if (sysCouponCodeDto.getUseStartDate().after(date)) {
|
|
|
+ throw new BizException("操作失败:不在优惠券使用期限");
|
|
|
+ }
|
|
|
+ if (date.after(sysCouponCodeDto.getUseDeadlineDate())) {
|
|
|
+ throw new BizException("操作失败:优惠券已过期");
|
|
|
+ }
|
|
|
+ CouponTypeEnum couponType = sysCouponCodeDto.getCouponType();
|
|
|
+ switch (couponType) {
|
|
|
+ case DISCOUNT:
|
|
|
+ throw new BizException("操作失败:暂不支持折扣劵");
|
|
|
+ case FULL_REDUCTION:
|
|
|
+ fullAmount = fullAmount.add(sysCouponCodeDto.getFullAmount());
|
|
|
+ faceAmount = faceAmount.add(sysCouponCodeDto.getFaceValue());
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ throw new BizException("操作失败:错误的优惠券类型");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (amount.compareTo(fullAmount) < 0) {
|
|
|
+ throw new BizException("操作失败:当前消费金额不满足优惠券满减条件");
|
|
|
+ }
|
|
|
+ amount = amount.subtract(faceAmount);
|
|
|
+ if (amount.signum() < 0) {
|
|
|
+ amount = BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ //使用优惠券
|
|
|
+ if (useFlag) {
|
|
|
+ sysCouponCodeDao.use(couponIdList);
|
|
|
+ }
|
|
|
+ studentPaymentOrder.setCouponCodeId(StringUtils.join(couponIdList, ","));
|
|
|
+ studentPaymentOrder.setCouponRemitFee(faceAmount);
|
|
|
+ }
|
|
|
+ studentPaymentOrder.setExpectAmount(amount);
|
|
|
+ studentPaymentOrder.setActualAmount(amount);
|
|
|
+ return studentPaymentOrder;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public List<SysCouponCodeDto> findByIdList(List<Integer> couponIdList) {
|
|
|
- return sysCouponCodeDao.findByIdList(couponIdList);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void quit(String couponCodeId) {
|
|
|
- if(StringUtils.isEmpty(couponCodeId)){
|
|
|
- return;
|
|
|
- }
|
|
|
- sysCouponCodeDao.quit(couponCodeId);
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public List<SysCouponCodeDto> findByIdList(List<Integer> couponIdList) {
|
|
|
+ return sysCouponCodeDao.findByIdList(couponIdList);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void quit(String couponCodeId) {
|
|
|
+ if (StringUtils.isEmpty(couponCodeId)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ sysCouponCodeDao.quit(couponCodeId);
|
|
|
+ }
|
|
|
}
|