Переглянути джерело

Merge remote-tracking branch 'origin/sit' into sit

刘云鑫 1 місяць тому
батько
коміт
990f14a414

+ 6 - 4
alien-dining/src/main/java/shop/alien/dining/controller/DiningCouponController.java

@@ -49,7 +49,8 @@ public class DiningCouponController {
             @ApiImplicitParam(name = "size", value = "分页条数", dataType = "Integer", paramType = "query", required = false),
             @ApiImplicitParam(name = "tabType", value = "分页类型(0:全部(未使用),1:即将过期,2:已使用,3:已过期)", dataType = "String", paramType = "query", required = true),
             @ApiImplicitParam(name = "type", value = "券类型(不传:优惠券+代金券都返回,1:仅优惠券查 life_discount_coupon,4:仅代金券查 life_coupon)", dataType = "Integer", paramType = "query", required = false),
-            @ApiImplicitParam(name = "couponType", value = "优惠券类型:1=仅满减券,2=仅折扣券,不传=全部优惠券(可选,仅当type不为4时有效)", dataType = "Integer", paramType = "query", required = false)
+            @ApiImplicitParam(name = "couponType", value = "优惠券类型:1=仅满减券,2=仅折扣券,不传=全部优惠券(可选,仅当type不为4时有效)", dataType = "Integer", paramType = "query", required = false),
+            @ApiImplicitParam(name = "storeId", value = "商铺ID,可为空,传则仅返回该商铺的优惠券", dataType = "String", paramType = "query", required = false)
     })
     public R<List<LifeDiscountCouponVo>> getUserCouponList(
             HttpServletRequest request,
@@ -57,10 +58,11 @@ public class DiningCouponController {
             @RequestParam(value = "size", defaultValue = "10") int size,
             @RequestParam("tabType") String tabType,
             @RequestParam(value = "type", required = false) Integer type,
-            @RequestParam(value = "couponType", required = false) Integer couponType) {
-        log.info("DiningCouponController.getUserCouponList?page={}, size={}, tabType={}, type={}, couponType={}", page, size, tabType, type, couponType);
+            @RequestParam(value = "couponType", required = false) Integer couponType,
+            @RequestParam(value = "storeId", required = false) String storeId) {
+        log.info("DiningCouponController.getUserCouponList?page={}, size={}, tabType={}, type={}, couponType={}, storeId={}", page, size, tabType, type, couponType, storeId);
         String authorization = request.getHeader("Authorization");
-        return diningCouponService.getUserCouponList(authorization, page, size, tabType, type, couponType);
+        return diningCouponService.getUserCouponList(authorization, page, size, tabType, type, couponType, storeId);
     }
 
     /**

+ 3 - 1
alien-dining/src/main/java/shop/alien/dining/feign/AlienStoreFeign.java

@@ -54,6 +54,7 @@ public interface AlienStoreFeign {
      * @param size          每页条数(默认10)
      * @param type          券类型(不传:优惠券+代金券都返回,1:仅优惠券查 life_discount_coupon,4:仅代金券查 life_coupon)(可选)
      * @param couponType    优惠券类型:1=仅满减券,2=仅折扣券,不传=全部优惠券(可选,仅当type不为4时有效)
+     * @param storeId       商铺ID,可为空,传则仅返回该商铺的优惠券
      * @return R.data 为 List&lt;LifeDiscountCouponVo&gt;
      */
     @GetMapping("life-discount-coupon/getUserCouponList")
@@ -63,7 +64,8 @@ public interface AlienStoreFeign {
             @RequestParam(value = "page", defaultValue = "1") int page,
             @RequestParam(value = "size", defaultValue = "10") int size,
             @RequestParam(value = "type", required = false) Integer type,
-            @RequestParam(value = "couponType", required = false) Integer couponType);
+            @RequestParam(value = "couponType", required = false) Integer couponType,
+            @RequestParam(value = "storeId", required = false) String storeId);
 
     /**
      * 根据优惠券 ID 获取优惠券详情(含规则、门槛等)

+ 1 - 1
alien-dining/src/main/java/shop/alien/dining/service/DiningCouponService.java

@@ -28,7 +28,7 @@ public interface DiningCouponService {
      * @param couponType    优惠券类型:1=仅满减券,2=仅折扣券,不传=全部优惠券(可选,仅当type不为4时有效)
      * @return R.data 为 List&lt;LifeDiscountCouponVo&gt;
      */
-    R<List<LifeDiscountCouponVo>> getUserCouponList(String authorization, int page, int size, String tabType, Integer type, Integer couponType);
+    R<List<LifeDiscountCouponVo>> getUserCouponList(String authorization, int page, int size, String tabType, Integer type, Integer couponType, String storeId);
 
     /**
      * 根据优惠券 id 获取优惠券详情

+ 3 - 3
alien-dining/src/main/java/shop/alien/dining/service/impl/DiningCouponServiceImpl.java

@@ -40,8 +40,8 @@ public class DiningCouponServiceImpl implements DiningCouponService {
     private final LifeDiscountCouponMapper lifeDiscountCouponMapper;
 
     @Override
-    public R<List<LifeDiscountCouponVo>> getUserCouponList(String authorization, int page, int size, String tabType, Integer type, Integer couponType) {
-        log.info("DiningCouponService.getUserCouponList page={}, size={}, tabType={}, type={}, couponType={}", page, size, tabType, type, couponType);
+    public R<List<LifeDiscountCouponVo>> getUserCouponList(String authorization, int page, int size, String tabType, Integer type, Integer couponType, String storeId) {
+        log.info("DiningCouponService.getUserCouponList page={}, size={}, tabType={}, type={}, couponType={}, storeId={}", page, size, tabType, type, couponType, storeId);
         try {
             // 参数校验
             if (StringUtils.isEmpty(tabType)) {
@@ -55,7 +55,7 @@ public class DiningCouponServiceImpl implements DiningCouponService {
                 size = 10;
             }
             
-            R<List<LifeDiscountCouponVo>> result = alienStoreFeign.getUserCouponList(authorization, tabType, page, size, type, couponType);
+            R<List<LifeDiscountCouponVo>> result = alienStoreFeign.getUserCouponList(authorization, tabType, page, size, type, couponType, storeId);
             if (result == null) {
                 log.error("Feign调用返回null");
                 return R.fail("获取优惠券列表失败:服务返回为空");

+ 10 - 11
alien-dining/src/main/java/shop/alien/dining/service/impl/StoreOrderServiceImpl.java

@@ -123,8 +123,7 @@ public class StoreOrderServiceImpl extends ServiceImpl<StoreOrderMapper, StoreOr
         BigDecimal discountAmount = dto.getDiscountAmount() != null ? dto.getDiscountAmount() : BigDecimal.ZERO;
         BigDecimal payAmount = dto.getPayAmount() != null ? dto.getPayAmount() : BigDecimal.ZERO;
         
-        // 验证优惠券(可选,couponId 可以为 null)
-        // 注意:订单总金额、优惠金额、实付金额都由前端计算并传入,后端不再验证
+        // 优惠券仅校验是否存在及是否属于该门店,不做金额校验;订单总金额、餐具费、优惠金额、实付金额完全采用前端传参
         LifeDiscountCoupon coupon = null;
         
         if (dto.getCouponId() != null) {
@@ -209,15 +208,15 @@ public class StoreOrderServiceImpl extends ServiceImpl<StoreOrderMapper, StoreOr
                 Integer addDishCountBefore = orderDetailMapper.selectCount(checkBeforeAddDishWrapper);
                 isFirstAddDish = (addDishCountBefore == null || addDishCountBefore == 0);
                 
-                // 更新订单信息(使用前端计算的金额,但经过后端验证
+                // 更新订单信息(完全采用前端传参,不做金额校验
                 order.setDinerCount(dto.getDinerCount());
                 order.setContactPhone(dto.getContactPhone());
                 order.setTablewareFee(tablewareFee);
-                order.setTotalAmount(totalAmount); // 使用验证后的订单总金额
+                order.setTotalAmount(totalAmount);
                 order.setCouponId(dto.getCouponId());
                 order.setCurrentCouponId(dto.getCouponId());
-                order.setDiscountAmount(discountAmount); // 使用验证后的优惠金额
-                order.setPayAmount(payAmount); // 使用验证后的实付金额
+                order.setDiscountAmount(discountAmount);
+                order.setPayAmount(payAmount);
                 order.setRemark(dto.getRemark());
                 order.setUpdatedUserId(userId);
                 order.setUpdatedTime(now);
@@ -257,11 +256,11 @@ public class StoreOrderServiceImpl extends ServiceImpl<StoreOrderMapper, StoreOr
             order.setPayUserId(userId);
             order.setPayUserPhone(userPhone);
             order.setOrderStatus(0); // 待支付
-            order.setTotalAmount(totalAmount); // 使用验证后的订单总金额
+            order.setTotalAmount(totalAmount);
             order.setCouponId(dto.getCouponId());
-            order.setCurrentCouponId(dto.getCouponId()); // 记录当前使用的优惠券
-            order.setDiscountAmount(discountAmount); // 使用验证后的优惠金额
-            order.setPayAmount(payAmount); // 使用验证后的实付金额
+            order.setCurrentCouponId(dto.getCouponId());
+            order.setDiscountAmount(discountAmount);
+            order.setPayAmount(payAmount);
             
             // 如果immediatePay为0,只创建订单不支付;为1则创建订单并支付
             // 暂时不实现立即支付,由前端调用支付接口
@@ -323,7 +322,7 @@ public class StoreOrderServiceImpl extends ServiceImpl<StoreOrderMapper, StoreOr
             }
         }
 
-        // 创建订单明细
+        // 创建订单明细(单价、小计来自购物车)
         // 如果是更新订单,需要判断哪些商品是新增的或数量增加的,标记为加餐
         // 餐具的特殊ID(用于标识餐具项)
         final Integer TABLEWARE_CUISINE_ID = -1;

+ 6 - 6
alien-entity/src/main/java/shop/alien/entity/store/dto/CreateOrderDTO.java

@@ -7,13 +7,13 @@ import lombok.Data;
 import javax.validation.constraints.NotNull;
 
 /**
- * 创建订单DTO
+ * 创建订单DTO(订单总金额、餐具费、优惠金额、实付金额完全采用前端传参,不做后台金额校验)
  *
  * @author system
  * @since 2025-01-XX
  */
 @Data
-@ApiModel(value = "CreateOrderDTO对象", description = "创建订单")
+@ApiModel(value = "CreateOrderDTO对象", description = "创建订单,金额完全采用前端传参")
 public class CreateOrderDTO {
 
     @ApiModelProperty(value = "桌号ID", required = true)
@@ -26,16 +26,16 @@ public class CreateOrderDTO {
     @ApiModelProperty(value = "优惠券ID(可选,不选择优惠券时传 null 或不传此字段)")
     private Integer couponId;
 
-    @ApiModelProperty(value = "订单总金额(由前端计算,菜品总价,不含餐具费和优惠金额)")
+    @ApiModelProperty(value = "订单总金额(前端传参,不做后台校验)")
     private java.math.BigDecimal totalAmount;
 
-    @ApiModelProperty(value = "餐具费(由前端计算,基于门店餐具费单价 × 就餐人数)")
+    @ApiModelProperty(value = "餐具费(前端传参,不做后台校验)")
     private java.math.BigDecimal tablewareFee;
 
-    @ApiModelProperty(value = "优惠金额(由前端计算,如果使用优惠券则必传,不使用优惠券时传 0 或不传)")
+    @ApiModelProperty(value = "优惠金额(前端传参,不做后台校验)")
     private java.math.BigDecimal discountAmount;
 
-    @ApiModelProperty(value = "实付金额(由前端计算,订单总金额 + 餐具费 - 优惠金额)")
+    @ApiModelProperty(value = "实付金额(前端传参,不做后台校验)")
     private java.math.BigDecimal payAmount;
 
     @ApiModelProperty(value = "联系电话")

+ 7 - 5
alien-store/src/main/java/shop/alien/store/controller/LifeDiscountCouponController.java

@@ -190,14 +190,16 @@ public class LifeDiscountCouponController {
             @ApiImplicitParam(name = "size", value = "分页条数", dataType = "Integer", paramType = "query", required = false),
             @ApiImplicitParam(name = "tabType", value = "分页类型(0:全部(未使用),1:即将过期,2:已使用,3:已过期)", dataType = "String", paramType = "query", required = true),
             @ApiImplicitParam(name = "type", value = "券类型(不传:优惠券+代金券都返回,1:仅优惠券查 life_discount_coupon,4:仅代金券查 life_coupon)", dataType = "Integer", paramType = "query", required = false),
-            @ApiImplicitParam(name = "couponType", value = "优惠券类型:1=仅满减券,2=仅折扣券,不传=全部优惠券(可选,仅当type不为4时有效)", dataType = "Integer", paramType = "query", required = false)
+            @ApiImplicitParam(name = "couponType", value = "优惠券类型:1=仅满减券,2=仅折扣券,不传=全部优惠券(可选,仅当type不为4时有效)", dataType = "Integer", paramType = "query", required = false),
+            @ApiImplicitParam(name = "storeId", value = "商铺ID,可为空,传则仅返回该商铺的优惠券", dataType = "String", paramType = "query", required = false)
     })
     public R<List<LifeDiscountCouponVo>> getUserCouponList(@ApiIgnore @TokenInfo UserLoginInfo userLoginInfo,
                                                            @RequestParam(value = "tabType") String tabType,
                                                            @RequestParam(defaultValue = "1") int page,
                                                            @RequestParam(defaultValue = "10") int size,
                                                            @RequestParam(required = false) Integer type,
-                                                           @RequestParam(value = "couponType", required = false) Integer couponType) {
+                                                           @RequestParam(value = "couponType", required = false) Integer couponType,
+                                                           @RequestParam(value = "storeId", required = false) String storeId) {
         try {
             // 参数校验
             if (StringUtils.isEmpty(tabType)) {
@@ -216,11 +218,11 @@ public class LifeDiscountCouponController {
                 return R.fail("优惠券类型参数错误,必须为1(满减券)或2(折扣券)");
             }
             
-            log.info("LifeDiscountCouponController.getUserCouponList?userId={}, tabType={}, page={}, size={}, type={}, couponType={}", 
-                    userLoginInfo.getUserId(), tabType, page, size, type, couponType);
+            log.info("LifeDiscountCouponController.getUserCouponList?userId={}, tabType={}, page={}, size={}, type={}, couponType={}, storeId={}", 
+                    userLoginInfo.getUserId(), tabType, page, size, type, couponType, storeId);
             
             List<LifeDiscountCouponVo> storeCouponList = lifeDiscountCouponService.getUserCouponList(
-                    userLoginInfo, page, size, tabType, type, couponType);
+                    userLoginInfo, page, size, tabType, type, couponType, storeId);
             return R.data(storeCouponList);
         } catch (IllegalArgumentException e) {
             log.error("LifeDiscountCouponController.getUserCouponList 参数错误, userId={}, error={}", 

+ 2 - 1
alien-store/src/main/java/shop/alien/store/service/LifeDiscountCouponService.java

@@ -67,8 +67,9 @@ public interface LifeDiscountCouponService extends IService<LifeDiscountCoupon>
      * 获取该用户优惠券列表
      * @param type 不传:优惠券+代金券都返回;1:仅优惠券(查 life_discount_coupon);4:仅代金券(查 life_coupon)
      * @param couponType 优惠券类型:1=满减券,2=折扣券,null=全部优惠券(仅当type不为4时有效)
+     * @param storeId 商铺ID,可为空,传则仅返回该商铺的优惠券
      */
-    List<LifeDiscountCouponVo> getUserCouponList(UserLoginInfo userLoginInfo, int page, int size, String tabType, Integer type, Integer couponType);
+    List<LifeDiscountCouponVo> getUserCouponList(UserLoginInfo userLoginInfo, int page, int size, String tabType, Integer type, Integer couponType, String storeId);
 
     /**
      * 获取所有优惠券列表(分页)

+ 20 - 9
alien-store/src/main/java/shop/alien/store/service/impl/LifeDiscountCouponServiceImpl.java

@@ -713,10 +713,11 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
      * @param tabType 分页类型:0-全部(未使用),1-即将过期,2-已使用,3-已过期
      * @param type 券类型:1-仅优惠券,4-仅代金券,null-全部
      * @param couponType 优惠券类型:1-满减券,2-折扣券,null-全部(仅当type不为4时有效)
+     * @param storeId 商铺ID,可为空,传则仅返回该商铺的优惠券
      * @return 优惠券列表
      */
     @Override
-    public List<LifeDiscountCouponVo> getUserCouponList(UserLoginInfo userLoginInfo, int page, int size, String tabType, Integer type, Integer couponType) {
+    public List<LifeDiscountCouponVo> getUserCouponList(UserLoginInfo userLoginInfo, int page, int size, String tabType, Integer type, Integer couponType, String storeId) {
         // 参数校验
         if (userLoginInfo == null || StringUtils.isEmpty(userLoginInfo.getUserId())) {
             throw new IllegalArgumentException("用户信息不能为空");
@@ -781,7 +782,7 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
         
         // type=4:仅代金券,查询 life_coupon 表
         if (type != null && type == 4) {
-            return processVoucherCoupons(records, zoneId, localNow);
+            return processVoucherCoupons(records, zoneId, localNow, storeId);
         }
 
         // type=1 或 type=null:优惠券(或混合),查询 life_discount_coupon
@@ -797,6 +798,10 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
         if (couponType != null) {
             couponQueryWrapper.eq(LifeDiscountCoupon::getCouponType, couponType);
         }
+        // 商铺ID检索:传则仅返回该商铺的优惠券
+        if (!StringUtils.isEmpty(storeId)) {
+            couponQueryWrapper.eq(LifeDiscountCoupon::getStoreId, storeId);
+        }
         List<LifeDiscountCoupon> lifeDiscountCoupons = lifeDiscountCouponMapper.selectList(couponQueryWrapper);
         
         // 如果type=1且没有查询到优惠券,直接返回
@@ -821,8 +826,11 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
                     .filter(Objects::nonNull)
                     .collect(Collectors.toList());
             if (!voucherIdList.isEmpty()) {
-                lifeCouponsForMerge = lifeCouponMapper.selectList(
-                        new LambdaQueryWrapper<LifeCoupon>().in(LifeCoupon::getId, voucherIdList));
+                LambdaQueryWrapper<LifeCoupon> voucherWrapper = new LambdaQueryWrapper<LifeCoupon>().in(LifeCoupon::getId, voucherIdList);
+                if (!StringUtils.isEmpty(storeId)) {
+                    voucherWrapper.eq(LifeCoupon::getStoreId, storeId);
+                }
+                lifeCouponsForMerge = lifeCouponMapper.selectList(voucherWrapper);
                 List<String> voucherStoreIds = lifeCouponsForMerge.stream()
                         .map(LifeCoupon::getStoreId)
                         .filter(s -> !StringUtils.isEmpty(s))
@@ -877,8 +885,8 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
     /**
      * 处理代金券列表(type=4时使用)
      */
-    private List<LifeDiscountCouponVo> processVoucherCoupons(List<LifeDiscountCouponUser> records, 
-                                                               ZoneId zoneId, LocalDate localNow) {
+    private List<LifeDiscountCouponVo> processVoucherCoupons(List<LifeDiscountCouponUser> records,
+                                                               ZoneId zoneId, LocalDate localNow, String storeId) {
         List<LifeDiscountCouponVo> result = new ArrayList<>();
         List<String> voucherIdList = records.stream()
                 .map(LifeDiscountCouponUser::getVoucherId)
@@ -887,9 +895,12 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
         if (voucherIdList.isEmpty()) {
             return result;
         }
-        
-        List<LifeCoupon> lifeCoupons = lifeCouponMapper.selectList(
-                new LambdaQueryWrapper<LifeCoupon>().in(LifeCoupon::getId, voucherIdList));
+
+        LambdaQueryWrapper<LifeCoupon> voucherWrapper = new LambdaQueryWrapper<LifeCoupon>().in(LifeCoupon::getId, voucherIdList);
+        if (!StringUtils.isEmpty(storeId)) {
+            voucherWrapper.eq(LifeCoupon::getStoreId, storeId);
+        }
+        List<LifeCoupon> lifeCoupons = lifeCouponMapper.selectList(voucherWrapper);
         List<String> storeIdList = lifeCoupons.stream()
                 .map(LifeCoupon::getStoreId)
                 .filter(s -> !StringUtils.isEmpty(s))