diff --git a/ruoyi-admin/src/main/java/com/ruoyi/member/domain/MemberCoupon.java b/ruoyi-admin/src/main/java/com/ruoyi/member/domain/MemberCoupon.java index d5c2bee..f529965 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/member/domain/MemberCoupon.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/member/domain/MemberCoupon.java @@ -29,7 +29,7 @@ public class MemberCoupon extends DlBaseEntity private String id; /** 用户id */ - private String userId; + private Long userId; /** 类型(1-增加|2-扣减) */ @Excel(name = "类型", readConverterExp = "1=-增加|2-扣减") @@ -44,7 +44,7 @@ public class MemberCoupon extends DlBaseEntity /** 剩余 */ @Excel(name = "剩余") - private Long balance; + private Integer balance; /** 备注 */ @Excel(name = "备注") diff --git a/ruoyi-admin/src/main/java/com/ruoyi/member/service/IMemberCouponService.java b/ruoyi-admin/src/main/java/com/ruoyi/member/service/IMemberCouponService.java index 04e2d47..59341cb 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/member/service/IMemberCouponService.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/member/service/IMemberCouponService.java @@ -1,16 +1,34 @@ package com.ruoyi.member.service; -import java.util.List; import com.baomidou.mybatisplus.extension.service.IService; import com.ruoyi.member.domain.MemberCoupon; +import com.ruoyi.member.domain.MemberOrder; /** * 用户通告券变动记录Service接口 - * + * * @author vinjor-m * @date 2025-03-17 */ -public interface IMemberCouponService extends IService -{ +public interface IMemberCouponService extends IService { + + /** + * @param order 订单 + * @author PQZ + * @date 15:02 2025/3/28 + **/ + void dealMemberCoupon(MemberOrder order); + + /** + * 保存通告券变动记录 + * + * @param userId 用户id + * @param type 变动类型(1增加2减少) + * @param noticeId 通告id + * @param couponNum 变动数量 + * @author PQZ + * @date 15:19 2025/3/28 + **/ + void saveCoupon(Long userId, String type, String noticeId, Integer couponNum); } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/member/service/impl/MemberCardServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/member/service/impl/MemberCardServiceImpl.java index 46bbc23..f3b8e3f 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/member/service/impl/MemberCardServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/member/service/impl/MemberCardServiceImpl.java @@ -126,8 +126,8 @@ public class MemberCardServiceImpl extends ServiceImpl lambdaQueryWrapper = new LambdaQueryWrapper<>(); + lambdaQueryWrapper + .eq(MemberCoupon::getUserId,userId) + .eq(DlBaseEntity::getDelFlag,0) + .orderByDesc(DlBaseEntity::getCreateTime); + List list = list(lambdaQueryWrapper); + MemberCoupon memberCoupon = new MemberCoupon(); + memberCoupon.setUserId(userId); + memberCoupon.setType(type); + memberCoupon.setNoticeId(noticeId); + memberCoupon.setCouponNum(couponNum); + //如果无记录则为初始新增 + if (list.isEmpty()) { + memberCoupon.setBalance(couponNum); + } else { + //如果有记录则取最新记录中的剩余值进行计算后得出新值 + Integer oldBalance = list.get(0).getBalance(); + Integer newBalance; + if ("1".equals(type)) { + newBalance = oldBalance + couponNum; + } else { + newBalance = oldBalance - couponNum; + } + memberCoupon.setBalance(newBalance); + } + save(memberCoupon); + + } } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/member/service/impl/MemberOrderServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/member/service/impl/MemberOrderServiceImpl.java index adb69f0..ea7f000 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/member/service/impl/MemberOrderServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/member/service/impl/MemberOrderServiceImpl.java @@ -18,6 +18,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.util.Date; /** * 订单Service业务层处理 @@ -65,12 +66,17 @@ public class MemberOrderServiceImpl extends ServiceImpl lambdaQueryWrapper = new LambdaQueryWrapper<>(); lambdaQueryWrapper.eq(DlBaseEntity::getDelFlag,0).eq(MemberOrder::getOrderNo,orderNo); MemberOrder memberOrder = getOne(lambdaQueryWrapper); - /*2、处理不同类型*/ + /*2、处理不同类型订单*/ if ("01".equals(memberOrder.getOrderType())) { cardService.dealMemberCard(memberOrder); } else { - + couponService.dealMemberCoupon(memberOrder); } + /*3、处理订单表数据*/ + memberOrder.setPayTime(new Date()); + memberOrder.setIsPay(1); + memberOrder.setPayWay("02"); + updateById(memberOrder); } } diff --git a/ruoyi-admin/src/main/resources/mapper/member/MemberOrderMapper.xml b/ruoyi-admin/src/main/resources/mapper/member/MemberOrderMapper.xml index ca97f72..0e553a4 100644 --- a/ruoyi-admin/src/main/resources/mapper/member/MemberOrderMapper.xml +++ b/ruoyi-admin/src/main/resources/mapper/member/MemberOrderMapper.xml @@ -49,5 +49,6 @@ and is_pay = #{entity.isPay} and is_refund = #{entity.isRefund} + order by create_time desc \ No newline at end of file