skyline 1 год назад
Родитель
Сommit
c91533baf5

+ 2 - 2
mapper/src/main/java/com/kym/mapper/miniapp/OrderCouponMapper.java

@@ -1,7 +1,7 @@
 package com.kym.mapper.miniapp;
 
+import com.github.yulichang.base.MPJBaseMapper;
 import com.kym.entity.miniapp.OrderCoupon;
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 
 /**
  * <p>
@@ -11,6 +11,6 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  * @author skyline
  * @since 2024-06-02
  */
-public interface OrderCouponMapper extends BaseMapper<OrderCoupon> {
+public interface OrderCouponMapper extends MPJBaseMapper<OrderCoupon> {
 
 }

+ 12 - 0
miniapp/src/main/java/com/kym/miniapp/controller/ChargerController.java

@@ -173,6 +173,18 @@ public class ChargerController {
         return R.success(chargeOrderService.orderDetailForApp(startChargeSeq));
     }
 
+    /**
+     * 订单优惠详情
+     *
+     * @param startChargeSeq
+     * @param discountType
+     * @return
+     */
+    @GetMapping("/orderDiscountDetail")
+    R<?> orderDiscountDetail(@RequestParam("startChargeSeq") String startChargeSeq, @RequestParam("discountType") String discountType) {
+        return R.success(chargeOrderService.orderDiscountDetail(startChargeSeq, discountType));
+    }
+
     /**
      * 图片二维码识别
      *

+ 3 - 1
service/src/main/java/com/kym/service/miniapp/ChargeOrderService.java

@@ -42,5 +42,7 @@ public interface ChargeOrderService extends MPJBaseService<ChargeOrder> {
 
     PageBean<ChargeOrderVo> listUserChargeOrders(OrderQueryParams params);
 
-    Map stationStatDetail(StatQueryParam params);
+    Map<String, ?> stationStatDetail(StatQueryParam params);
+
+    Object orderDiscountDetail(String startChargeSeq, String discountType);
 }

+ 3 - 1
service/src/main/java/com/kym/service/miniapp/UserCouponService.java

@@ -1,9 +1,9 @@
 package com.kym.service.miniapp;
 
+import com.baomidou.mybatisplus.extension.service.IService;
 import com.kym.entity.admin.queryParams.CouponQueryParam;
 import com.kym.entity.common.PageBean;
 import com.kym.entity.miniapp.UserCoupon;
-import com.baomidou.mybatisplus.extension.service.IService;
 import com.kym.entity.miniapp.vo.UserCouponVo;
 
 /**
@@ -19,4 +19,6 @@ public interface UserCouponService extends IService<UserCoupon> {
     PageBean<UserCouponVo> listUserCoupons(CouponQueryParam params);
 
     void collectCoupon(Long couponId);
+
+    UserCoupon getUserCoupon(String startChargeSeq);
 }

+ 1 - 0
service/src/main/java/com/kym/service/miniapp/UserRechargeRightsService.java

@@ -13,4 +13,5 @@ import com.kym.entity.miniapp.UserRechargeRights;
  */
 public interface UserRechargeRightsService extends MPJBaseService<UserRechargeRights> {
 
+    Object getUserRechargeRights(String startChargeSeq);
 }

+ 32 - 20
service/src/main/java/com/kym/service/miniapp/impl/ChargeOrderServiceImpl.java

@@ -4,11 +4,11 @@ import cn.dev33.satoken.stp.StpUtil;
 import cn.hutool.poi.excel.ExcelUtil;
 import cn.hutool.poi.excel.ExcelWriter;
 import com.baomidou.dynamic.datasource.annotation.DS;
-import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
 import com.github.pagehelper.PageHelper;
 import com.github.yulichang.base.MPJBaseServiceImpl;
+import com.kym.common.exception.BusinessException;
 import com.kym.common.utils.CommUtil;
-import com.kym.entity.admin.RechargeRights;
+import com.kym.entity.admin.Activity;
 import com.kym.entity.admin.StationStatDay;
 import com.kym.entity.admin.StationStatMonth;
 import com.kym.entity.admin.queryParams.CustomChargeOrdersQueryParam;
@@ -17,20 +17,20 @@ import com.kym.entity.admin.vo.CustomOrderVo;
 import com.kym.entity.admin.vo.StationStatVo;
 import com.kym.entity.common.PageBean;
 import com.kym.entity.miniapp.ChargeOrder;
-import com.kym.entity.miniapp.OrderRechargeRights;
 import com.kym.entity.miniapp.queryParams.OrderQueryParams;
 import com.kym.entity.miniapp.vo.ChargeOrderVo;
 import com.kym.mapper.miniapp.ChargeOrderMapper;
 import com.kym.service.admin.ExportService;
-import com.kym.service.admin.RechargeRightsService;
 import com.kym.service.admin.StationStatDayService;
 import com.kym.service.admin.StationStatMonthService;
 import com.kym.service.cache.KymCache;
 import com.kym.service.miniapp.ChargeOrderService;
-import com.kym.service.miniapp.OrderRechargeRightsService;
+import com.kym.service.miniapp.UserCouponService;
+import com.kym.service.miniapp.UserRechargeRightsService;
 import jakarta.servlet.http.HttpServletResponse;
 import lombok.SneakyThrows;
 import org.springframework.beans.BeanUtils;
+import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
@@ -57,16 +57,16 @@ public class ChargeOrderServiceImpl extends MPJBaseServiceImpl<ChargeOrderMapper
 
 
     private final ExportService exportService;
-    private final OrderRechargeRightsService orderRechargeRightsService;
-    private final RechargeRightsService rechargeRightsService;
-
+    private final UserCouponService userCouponService;
+    private final UserRechargeRightsService userRechargeRightsService;
     private final StationStatDayService stationStatDayService;
     private final StationStatMonthService stationStatMonthService;
 
-    public ChargeOrderServiceImpl(ExportService exportService, OrderRechargeRightsService orderRechargeRightsService, RechargeRightsService rechargeRightsService, StationStatDayService stationStatDayService, StationStatMonthService stationStatMonthService) {
+    public ChargeOrderServiceImpl(ExportService exportService, @Lazy UserCouponService userCouponService, UserRechargeRightsService userRechargeRightsService,
+                                  StationStatDayService stationStatDayService, StationStatMonthService stationStatMonthService) {
         this.exportService = exportService;
-        this.orderRechargeRightsService = orderRechargeRightsService;
-        this.rechargeRightsService = rechargeRightsService;
+        this.userCouponService = userCouponService;
+        this.userRechargeRightsService = userRechargeRightsService;
         this.stationStatDayService = stationStatDayService;
         this.stationStatMonthService = stationStatMonthService;
     }
@@ -185,18 +185,30 @@ public class ChargeOrderServiceImpl extends MPJBaseServiceImpl<ChargeOrderMapper
         // 订单对应的优惠信息
         var orderVo = new ChargeOrderVo();
         BeanUtils.copyProperties(chargeOrder, orderVo);
-        if (chargeOrder.getDiscountAmount() > 0) {
-            // 充值权益
-            var orderRechargeRight = orderRechargeRightsService.lambdaQuery().eq(OrderRechargeRights::getStartChargeSeq, startChargeSeq).one();
-            DynamicDataSourceContextHolder.push("db-admin");
-            var rechargeRights = rechargeRightsService.lambdaQuery().eq(RechargeRights::getId, orderRechargeRight.getRightsId()).one();
-            DynamicDataSourceContextHolder.poll();
-            var desc = rechargeRights.getRightsDesc();
-            orderVo.setRightsDesc(desc);
-        }
+        // todo 修改成只显示优惠金额,具体优惠信息点击详情查看具体权益卡/优惠券
+//        if (chargeOrder.getDiscountAmount() > 0) {
+//            // 充值权益
+//            var orderRechargeRight = orderRechargeRightsService.lambdaQuery().eq(OrderRechargeRights::getStartChargeSeq, startChargeSeq).one();
+//            DynamicDataSourceContextHolder.push("db-admin");
+//            var rechargeRights = rechargeRightsService.lambdaQuery().eq(RechargeRights::getId, orderRechargeRight.getRightsId()).one();
+//            DynamicDataSourceContextHolder.poll();
+//            var desc = rechargeRights.getRightsDesc();
+//            orderVo.setRightsDesc(desc);
+//        }
         return orderVo;
     }
 
+
+    @Override
+    public Object orderDiscountDetail(String startChargeSeq, String discountType) {
+        return switch (discountType) {
+            case Activity.DISCOUNT_TYPE_服务费折扣权益 -> userRechargeRightsService.getUserRechargeRights(startChargeSeq);
+            case Activity.DISCOUNT_TYPE_优惠券 -> userCouponService.getUserCoupon(startChargeSeq);
+            default -> throw new BusinessException("未知的优惠类型");
+        };
+    }
+
+
     /**
      * 站点统计
      *

+ 8 - 2
service/src/main/java/com/kym/service/miniapp/impl/OrderCouponServiceImpl.java

@@ -1,11 +1,16 @@
 package com.kym.service.miniapp.impl;
 
+import com.github.yulichang.base.MPJBaseServiceImpl;
+import com.github.yulichang.toolkit.JoinWrappers;
+import com.github.yulichang.wrapper.MPJLambdaWrapper;
 import com.kym.entity.miniapp.OrderCoupon;
+import com.kym.entity.miniapp.UserCoupon;
 import com.kym.mapper.miniapp.OrderCouponMapper;
 import com.kym.service.miniapp.OrderCouponService;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 /**
  * <p>
  * 订单优惠券关联表 服务实现类
@@ -15,6 +20,7 @@ import org.springframework.stereotype.Service;
  * @since 2024-06-02
  */
 @Service
-public class OrderCouponServiceImpl extends ServiceImpl<OrderCouponMapper, OrderCoupon> implements OrderCouponService {
+public class OrderCouponServiceImpl extends MPJBaseServiceImpl<OrderCouponMapper, OrderCoupon> implements OrderCouponService {
+
 
 }

+ 20 - 2
service/src/main/java/com/kym/service/miniapp/impl/UserCouponServiceImpl.java

@@ -5,12 +5,15 @@ import com.baomidou.dynamic.datasource.annotation.DS;
 import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
 import com.github.pagehelper.PageHelper;
 import com.github.yulichang.base.MPJBaseServiceImpl;
+import com.github.yulichang.toolkit.JoinWrappers;
+import com.github.yulichang.wrapper.MPJLambdaWrapper;
 import com.kym.common.exception.BusinessException;
 import com.kym.common.utils.CommUtil;
 import com.kym.entity.admin.Coupon;
 import com.kym.entity.admin.queryParams.CouponQueryParam;
 import com.kym.entity.common.PageBean;
 import com.kym.entity.common.RedisKeys;
+import com.kym.entity.miniapp.OrderCoupon;
 import com.kym.entity.miniapp.User;
 import com.kym.entity.miniapp.UserCoupon;
 import com.kym.entity.miniapp.vo.UserCouponVo;
@@ -121,7 +124,7 @@ public class UserCouponServiceImpl extends MPJBaseServiceImpl<UserCouponMapper,
         coupon.setClaimedQuantity(coupon.getClaimedQuantity() + 1);
 
         // 校验优惠券数量是否已领完
-        if(coupon.getClaimedQuantity() >= coupon.getQuantity()){
+        if (coupon.getClaimedQuantity() >= coupon.getQuantity()) {
             coupon.setStatus(Coupon.STATUS_已结束);
         }
         couponService.updateById(coupon);
@@ -152,4 +155,19 @@ public class UserCouponServiceImpl extends MPJBaseServiceImpl<UserCouponMapper,
         // todo 优惠券活动终止时处理redis数据,优惠券失效或者使用之后该做什么操作?
     }
 
-}
+    /**
+     * 通过订单号查询订单使用的优惠券信息
+     *
+     * @param startChargeSeq
+     * @return
+     */
+    @Override
+    public UserCoupon getUserCoupon(String startChargeSeq) {
+        MPJLambdaWrapper<UserCoupon> wrapper = JoinWrappers.lambda(UserCoupon.class)
+                .selectAll(UserCoupon.class)
+                .rightJoin(OrderCoupon.class, OrderCoupon::getCouponId, UserCoupon::getCouponId)
+                .eq(OrderCoupon::getStartChargeSeq, startChargeSeq);
+        return this.getOne(wrapper);
+    }
+
+}

+ 18 - 0
service/src/main/java/com/kym/service/miniapp/impl/UserRechargeRightsServiceImpl.java

@@ -1,6 +1,9 @@
 package com.kym.service.miniapp.impl;
 
 import com.github.yulichang.base.MPJBaseServiceImpl;
+import com.github.yulichang.toolkit.JoinWrappers;
+import com.github.yulichang.wrapper.MPJLambdaWrapper;
+import com.kym.entity.miniapp.OrderRechargeRights;
 import com.kym.entity.miniapp.UserRechargeRights;
 import com.kym.mapper.miniapp.UserRechargeRightsMapper;
 import com.kym.service.miniapp.UserRechargeRightsService;
@@ -17,4 +20,19 @@ import org.springframework.stereotype.Service;
 @Service
 public class UserRechargeRightsServiceImpl extends MPJBaseServiceImpl<UserRechargeRightsMapper, UserRechargeRights> implements UserRechargeRightsService {
 
+
+    /**
+     * 通过订单号查询订单使用的权益卡信息
+     *
+     * @param startChargeSeq
+     * @return
+     */
+    @Override
+    public UserRechargeRights getUserRechargeRights(String startChargeSeq) {
+        MPJLambdaWrapper<UserRechargeRights> wrapper = JoinWrappers.lambda(UserRechargeRights.class)
+                .selectAll(UserRechargeRights.class)
+                .rightJoin(OrderRechargeRights.class, OrderRechargeRights::getRightsId, UserRechargeRights::getRightsId)
+                .eq(OrderRechargeRights::getStartChargeSeq, startChargeSeq);
+        return this.getOne(wrapper);
+    }
 }