From 1d48d043660fa0ff1a4edc2958a0ea5a52b24d52 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Fri, 25 Oct 2024 11:20:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=20=E4=BB=A5=E5=8F=8A=20=E9=80=80=E5=88=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dao/TbActivateInRecordMapper.java | 2 + .../dao/TbActivateOutRecordMapper.java | 2 + .../entity/dto/CouponUseDto.java | 15 +++++++ .../entity/vo/TbUserCouponVo.java | 1 + .../service/TbShopCouponService.java | 8 ++++ .../service/impl/TbShopCouponServiceImpl.java | 45 +++++++++++++++++++ .../mapper/TbActivateInRecordMapper.xml | 6 +++ .../mapper/TbActivateOutRecordMapper.xml | 6 +++ 8 files changed, 85 insertions(+) create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/CouponUseDto.java diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateInRecordMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateInRecordMapper.java index 2b1b96a..6213860 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateInRecordMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateInRecordMapper.java @@ -63,6 +63,8 @@ public interface TbActivateInRecordMapper { */ int update(TbActivateInRecord tbActivateInRecord); + int updateOverNum(@Param("id") Integer id, @Param("overNum") Integer overNum); + /** * 通过主键删除数据 * diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateOutRecordMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateOutRecordMapper.java index 9bd655d..9fa28a6 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateOutRecordMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateOutRecordMapper.java @@ -58,6 +58,8 @@ public interface TbActivateOutRecordMapper { */ int update(TbActivateOutRecord tbActivateOutRecord); + int updateRefNum(@Param("id")Integer id,@Param("refNum")Integer refNum); + /** * 通过主键删除数据 * diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/CouponUseDto.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/CouponUseDto.java new file mode 100644 index 0000000..0859352 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/CouponUseDto.java @@ -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 proCouponIds; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/TbUserCouponVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/TbUserCouponVo.java index 1e787be..f6f07ec 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/TbUserCouponVo.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/TbUserCouponVo.java @@ -6,6 +6,7 @@ import java.util.Date; @Data public class TbUserCouponVo { + private Integer id; private Integer couponId; private Integer proId; //优惠券名称 diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/TbShopCouponService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/TbShopCouponService.java index aed7e77..77686cf 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/TbShopCouponService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/TbShopCouponService.java @@ -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 param); + + boolean refund(List param); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbShopCouponServiceImpl.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbShopCouponServiceImpl.java index 7075f61..856eaf4 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbShopCouponServiceImpl.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbShopCouponServiceImpl.java @@ -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 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 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; + } + } diff --git a/src/main/resources/mapper/TbActivateInRecordMapper.xml b/src/main/resources/mapper/TbActivateInRecordMapper.xml index ed6befc..471669d 100644 --- a/src/main/resources/mapper/TbActivateInRecordMapper.xml +++ b/src/main/resources/mapper/TbActivateInRecordMapper.xml @@ -243,6 +243,12 @@ id, vip_user_id, coupon_id, name, type, pro_id, full_amount, discount_amount, nu where id = #{id} + + update tb_activate_in_record + set over_num = #{overNum} + where id = #{id} + + delete from tb_activate_in_record where id = #{id} diff --git a/src/main/resources/mapper/TbActivateOutRecordMapper.xml b/src/main/resources/mapper/TbActivateOutRecordMapper.xml index 86b536d..b1a5da6 100644 --- a/src/main/resources/mapper/TbActivateOutRecordMapper.xml +++ b/src/main/resources/mapper/TbActivateOutRecordMapper.xml @@ -153,6 +153,12 @@ where id = #{id} + + update tb_activate_out_record + set ref_num = ref_num + #{refNum} + where id = #{id} + + delete