优惠券使用 以及 退券

This commit is contained in:
2024-10-25 11:20:08 +08:00
parent 2690f6a02a
commit 1d48d04366
8 changed files with 85 additions and 0 deletions

View File

@@ -1,9 +1,13 @@
package com.chaozhanggui.system.cashierservice.service;
import com.chaozhanggui.system.cashierservice.entity.TbActivateOutRecord;
import com.chaozhanggui.system.cashierservice.entity.dto.CouponDto;
import com.chaozhanggui.system.cashierservice.entity.dto.CouponUseDto;
import com.chaozhanggui.system.cashierservice.sign.Result;
import org.springframework.context.annotation.Primary;
import java.util.List;
/**
* 优惠券(TbShopCoupon)表服务接口
*
@@ -12,4 +16,8 @@ import org.springframework.context.annotation.Primary;
*/
public interface TbShopCouponService {
Result find(CouponDto param);
boolean use(Integer shopId,Integer orderId,Integer vipUserId,List<TbActivateOutRecord> param);
boolean refund(List<TbActivateOutRecord> param);
}

View File

@@ -5,6 +5,7 @@ import cn.hutool.core.date.DateUtil;
import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.entity.dto.CouponDto;
import com.chaozhanggui.system.cashierservice.entity.dto.CouponUseDto;
import com.chaozhanggui.system.cashierservice.entity.vo.TbUserCouponVo;
import com.chaozhanggui.system.cashierservice.service.TbShopCouponService;
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
@@ -125,4 +126,48 @@ public class TbShopCouponServiceImpl implements TbShopCouponService {
return new Result(CodeEnum.SUCCESS);
}
/**
* 使用券
* @param shopId
* @param orderId
* @param vipUserId
* @param param giveId 和 useNum 必传
* @return
*/
@Override
public boolean use(Integer shopId,Integer orderId,Integer vipUserId,List<TbActivateOutRecord> param) {
for (TbActivateOutRecord outRecord : param) {
TbActivateInRecord inRecord = inRecordMapper.queryById(outRecord.getGiveId());
inRecord.setOverNum(inRecord.getOverNum() - outRecord.getUseNum());
inRecordMapper.updateOverNum(inRecord.getId(), inRecord.getOverNum());
outRecord.setType(inRecord.getType());
outRecord.setShopId(shopId);
outRecord.setOrderId(orderId.toString());
outRecord.setVipUserId(vipUserId);
outRecord.setStatus("closed");
outRecord.setCreateTime(new Date());
}
outRecordMapper.insertBatch(param);
return true;
}
/**
* 退还券
* @param param giveId和 refNum 必传
* @return
*/
@Override
public boolean refund(List<TbActivateOutRecord> param) {
for (TbActivateOutRecord outRecord : param) {
outRecord.setUpdateTime(new Date());
outRecordMapper.updateRefNum(outRecord.getId(),outRecord.getRefNum());
TbActivateInRecord inRecord = inRecordMapper.queryById(outRecord.getGiveId());
inRecord.setOverNum(inRecord.getOverNum() + outRecord.getRefNum());
inRecordMapper.updateOverNum(inRecord.getId(), inRecord.getOverNum());
}
return true;
}
}