优惠券使用 以及 退券

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

@@ -63,6 +63,8 @@ public interface TbActivateInRecordMapper {
*/ */
int update(TbActivateInRecord tbActivateInRecord); int update(TbActivateInRecord tbActivateInRecord);
int updateOverNum(@Param("id") Integer id, @Param("overNum") Integer overNum);
/** /**
* 通过主键删除数据 * 通过主键删除数据
* *

View File

@@ -58,6 +58,8 @@ public interface TbActivateOutRecordMapper {
*/ */
int update(TbActivateOutRecord tbActivateOutRecord); int update(TbActivateOutRecord tbActivateOutRecord);
int updateRefNum(@Param("id")Integer id,@Param("refNum")Integer refNum);
/** /**
* 通过主键删除数据 * 通过主键删除数据
* *

View File

@@ -0,0 +1,15 @@
package com.chaozhanggui.system.cashierservice.entity.dto;
import lombok.Data;
import java.util.List;
@Data
public class CouponUseDto {
private Integer shopId;
private Integer orderId;
//满减券id
private Integer couponId;
//商品券id
private List<Integer> proCouponIds;
}

View File

@@ -6,6 +6,7 @@ import java.util.Date;
@Data @Data
public class TbUserCouponVo { public class TbUserCouponVo {
private Integer id;
private Integer couponId; private Integer couponId;
private Integer proId; private Integer proId;
//优惠券名称 //优惠券名称

View File

@@ -1,9 +1,13 @@
package com.chaozhanggui.system.cashierservice.service; 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.CouponDto;
import com.chaozhanggui.system.cashierservice.entity.dto.CouponUseDto;
import com.chaozhanggui.system.cashierservice.sign.Result; import com.chaozhanggui.system.cashierservice.sign.Result;
import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.Primary;
import java.util.List;
/** /**
* 优惠券(TbShopCoupon)表服务接口 * 优惠券(TbShopCoupon)表服务接口
* *
@@ -12,4 +16,8 @@ import org.springframework.context.annotation.Primary;
*/ */
public interface TbShopCouponService { public interface TbShopCouponService {
Result find(CouponDto param); 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.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*; import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.entity.dto.CouponDto; 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.entity.vo.TbUserCouponVo;
import com.chaozhanggui.system.cashierservice.service.TbShopCouponService; import com.chaozhanggui.system.cashierservice.service.TbShopCouponService;
import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
@@ -125,4 +126,48 @@ public class TbShopCouponServiceImpl implements TbShopCouponService {
return new Result(CodeEnum.SUCCESS); 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;
}
} }

View File

@@ -243,6 +243,12 @@ id, vip_user_id, coupon_id, name, type, pro_id, full_amount, discount_amount, nu
where id = #{id} where id = #{id}
</update> </update>
<update id="updateOverNum">
update tb_activate_in_record
set over_num = #{overNum}
where id = #{id}
</update>
<!--通过主键删除--> <!--通过主键删除-->
<delete id="deleteById"> <delete id="deleteById">
delete from tb_activate_in_record where id = #{id} delete from tb_activate_in_record where id = #{id}

View File

@@ -153,6 +153,12 @@
where id = #{id} where id = #{id}
</update> </update>
<update id="updateRefNum">
update tb_activate_out_record
set ref_num = ref_num + #{refNum}
where id = #{id}
</update>
<!--通过主键删除--> <!--通过主键删除-->
<delete id="deleteById"> <delete id="deleteById">
delete delete