Parcourir la source

用户有效权益和优惠券接口

skyline il y a 1 an
Parent
commit
77973222b6

+ 19 - 0
entity/src/main/java/com/kym/entity/miniapp/vo/UserRightsAndCouponsVo.java

@@ -0,0 +1,19 @@
+package com.kym.entity.miniapp.vo;
+
+import com.kym.entity.miniapp.UserCoupon;
+import com.kym.entity.miniapp.UserRechargeRights;
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import java.util.List;
+
+/**
+ * 用户权益和优惠券
+ */
+@Data
+@Accessors(chain = true)
+public class UserRightsAndCouponsVo {
+    public Long userId;
+    public List<UserRechargeRights> userRechargeRightsList;
+    public List<UserCoupon> userCouponList;
+}

+ 2 - 0
service/src/main/java/com/kym/service/miniapp/AccountService.java

@@ -2,6 +2,7 @@ package com.kym.service.miniapp;
 
 import com.github.yulichang.base.MPJBaseService;
 import com.kym.entity.miniapp.Account;
+import com.kym.entity.miniapp.vo.UserRightsAndCouponsVo;
 
 /**
  * <p>
@@ -15,4 +16,5 @@ public interface AccountService extends MPJBaseService<Account> {
 
     Account getAccountByUserId(Long userId);
 
+    UserRightsAndCouponsVo listRightsAndCoupons();
 }

+ 40 - 0
service/src/main/java/com/kym/service/miniapp/impl/AccountServiceImpl.java

@@ -1,10 +1,16 @@
 package com.kym.service.miniapp.impl;
 
+import cn.dev33.satoken.stp.StpUtil;
 import com.baomidou.dynamic.datasource.annotation.DS;
 import com.github.yulichang.base.MPJBaseServiceImpl;
 import com.kym.entity.miniapp.Account;
+import com.kym.entity.miniapp.UserCoupon;
+import com.kym.entity.miniapp.UserRechargeRights;
+import com.kym.entity.miniapp.vo.UserRightsAndCouponsVo;
 import com.kym.mapper.miniapp.AccountMapper;
 import com.kym.service.miniapp.AccountService;
+import com.kym.service.miniapp.UserCouponService;
+import com.kym.service.miniapp.UserRechargeRightsService;
 import org.springframework.stereotype.Service;
 
 /**
@@ -19,10 +25,44 @@ import org.springframework.stereotype.Service;
 @DS("db-miniapp")
 public class AccountServiceImpl extends MPJBaseServiceImpl<AccountMapper, Account> implements AccountService {
 
+    private final UserRechargeRightsService userRechargeRightsService;
+
+    private final UserCouponService userCouponService;
+
+    public AccountServiceImpl(UserRechargeRightsService userRechargeRightsService, UserCouponService userCouponService) {
+        this.userRechargeRightsService = userRechargeRightsService;
+        this.userCouponService = userCouponService;
+    }
+
     @Override
     public Account getAccountByUserId(Long userId) {
         return lambdaQuery().eq(Account::getUserId, userId).one();
     }
 
+    /**
+     * 获取用户有效权益和优惠券
+     *
+     * @return
+     */
+    @Override
+    public UserRightsAndCouponsVo listRightsAndCoupons() {
+        var vo = new UserRightsAndCouponsVo();
+        var userId = StpUtil.getLoginIdAsLong();
+        // 当前用户有效的充电权益
+        var userRechargeRight = userRechargeRightsService.lambdaQuery()
+                .eq(UserRechargeRights::getUserId, userId).eq(UserRechargeRights::getStatus, UserRechargeRights.STATUS_有效)
+                .orderByAsc(UserRechargeRights::getEndTime).list();
+        vo.setUserRechargeRightsList(userRechargeRight);
+
+        // 当前用户有效的优惠券列表
+        var usesrCouponList = userCouponService.lambdaQuery()
+                .eq(UserCoupon::getUserId, userId)
+                .eq(UserCoupon::getStatus, UserCoupon.STATUS_有效)
+                .orderByAsc(UserCoupon::getEndTime).list();
+        vo.setUserCouponList(usesrCouponList);
+
+        return vo;
+    }
+
 
 }