bdf04af3958fb7a61f3180aa1efb795ba8ac00d2..8c4818a77b2279e1993a7022f21a6bc85046fdba
2025-09-10 zxl
优惠卷虚拟商品
8c4818 对比 | 目录
2025-09-10 peng
Merge remote-tracking branch 'origin/dev' into dev
211b5a 对比 | 目录
2025-09-10 peng
扫码修改地址
9f92aa 对比 | 目录
2025-09-10 zhanghua
添加优惠券限制单个商品使用逻辑
8fe046 对比 | 目录
12个文件已修改
10个文件已添加
848 ■■■■■ 已修改文件
buyer-api/src/main/java/cn/lili/controller/order/OrderBuyerController.java 37 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
framework/src/main/java/cn/lili/modules/lmk/domain/entity/CouponVirtual.java 58 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
framework/src/main/java/cn/lili/modules/lmk/domain/form/CouponVirtualForm.java 72 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
framework/src/main/java/cn/lili/modules/lmk/domain/query/CouponVirtualQuery.java 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
framework/src/main/java/cn/lili/modules/lmk/domain/vo/CouponVirtualVO.java 70 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
framework/src/main/java/cn/lili/modules/lmk/mapper/CouponVirtualMapper.java 35 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
framework/src/main/java/cn/lili/modules/lmk/service/CouponVirtualService.java 67 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
framework/src/main/java/cn/lili/modules/lmk/service/impl/CouponVirtualServiceImpl.java 121 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
framework/src/main/java/cn/lili/modules/order/cart/entity/dto/SkuMapDTO.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
framework/src/main/java/cn/lili/modules/order/cart/render/impl/CouponRender.java 47 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
framework/src/main/java/cn/lili/modules/order/cart/render/impl/FullDiscountRender.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
framework/src/main/java/cn/lili/modules/order/cart/render/util/PromotionPriceUtil.java 154 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
framework/src/main/java/cn/lili/modules/order/order/entity/dos/Order.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
framework/src/main/java/cn/lili/modules/order/order/entity/enums/ModifyAddressEnums.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
framework/src/main/java/cn/lili/modules/order/order/entity/vo/OrderSimpleVO.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
framework/src/main/java/cn/lili/modules/order/order/mapper/OrderMapper.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
framework/src/main/java/cn/lili/modules/order/order/service/OrderService.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
framework/src/main/java/cn/lili/modules/order/order/serviceimpl/OrderServiceImpl.java 46 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
framework/src/main/java/cn/lili/modules/promotion/entity/dos/Coupon.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
framework/src/main/java/cn/lili/modules/promotion/entity/dos/MemberCoupon.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
framework/src/main/resources/mapper/lmk/CouponVirtualMapper.xml 70 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
framework/src/main/resources/mapper/lmk/VideoMapper.xml 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
buyer-api/src/main/java/cn/lili/controller/order/OrderBuyerController.java
@@ -10,10 +10,12 @@
import cn.lili.common.utils.StringUtils;
import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.lmk.enums.general.AdminRoleEnum;
import cn.lili.modules.member.entity.dto.MemberAddressDTO;
import cn.lili.modules.order.order.entity.dos.Order;
import cn.lili.modules.order.order.entity.dos.OrderPackage;
import cn.lili.modules.order.order.entity.dto.OrderSearchParams;
import cn.lili.modules.order.order.entity.dto.OrderSearchXcxParams;
import cn.lili.modules.order.order.entity.enums.ModifyAddressEnums;
import cn.lili.modules.order.order.entity.enums.OrderStatusEnum;
import cn.lili.modules.order.order.entity.vo.OrderDetailVO;
import cn.lili.modules.order.order.entity.vo.OrderSimpleVO;
@@ -30,10 +32,12 @@
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
@@ -46,6 +50,7 @@
 * @author Chopper
 * @since 2020/11/16 10:08 下午
 */
@Slf4j
@RestController
@Api(tags = "买家端,订单接口")
@RequestMapping("/buyer/order/order")
@@ -115,7 +120,37 @@
        });
        return ResultUtil.data(orderDetailVO);
    }
    @ApiOperation(value = "订单明细")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderSn", value = "订单编号", required = true, paramType = "path")
    })
    @GetMapping(value = "/editAddress/{orderSn}")
    public ResultMessage<OrderDetailVO> editAddress(@NotNull(message = "订单编号不能为空") @PathVariable("orderSn") String orderSn) {
        OrderDetailVO orderDetailVO = orderService.queryEditAddressDetail(orderSn);
        Order order = orderDetailVO.getOrder();
        if (!OrderStatusEnum.UNDELIVERED.name().equals(order.getOrderStatus())) {
            log.error("订单号为{}------------------->状态异常为{}",orderSn,order.getOrderStatus());
            throw new ServiceException("订单状态异常无法领取");
        }
        String modifyAddressFlag = order.getModifyAddressFlag();
        if (ModifyAddressEnums.USED.name().equals(modifyAddressFlag)) {
            throw new ServiceException("订单已被领取");
        }
        orderDetailVO.getOrderItems().forEach(orderItem -> {
            String image = orderItem.getImage();
            if (StringUtils.isNotBlank(image)&&!image.contains("http")) {
                orderItem.setImage(cosUtil.getPreviewUrl(image));
            }
        });
        return ResultUtil.data(orderDetailVO);
    }
    @ApiOperation(value = "修改收货人信息")
    @ApiImplicitParam(name = "orderSn", value = "订单sn", required = true, dataType = "String", paramType = "path")
    @PostMapping(value = "/update/editAddress/{orderSn}/consignee")
    public ResultMessage<Object> consignee(@NotNull(message = "参数非法") @PathVariable String orderSn,
                                           @Valid @RequestBody MemberAddressDTO memberAddressDTO) {
        return ResultUtil.data(orderService.updateAddressConsignee(orderSn, memberAddressDTO));
    }
    @PreventDuplicateSubmissions
    @ApiOperation(value = "确认收货")
    @ApiImplicitParams({
framework/src/main/java/cn/lili/modules/lmk/domain/entity/CouponVirtual.java
New file
@@ -0,0 +1,58 @@
package cn.lili.modules.lmk.domain.entity;
import cn.lili.mybatis.BaseEntity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
/**
 * 虚拟商品优惠卷
 *
 * @author zxl
 * @since 2025-09-10
 */
@Data
@TableName("lmk_coupon_virtual")
public class CouponVirtual extends BaseEntity {
    private static final long serialVersionUID = 1L;
    @TableField("order_id")
    /** 订单id */
    private String orderId;
    @TableField("goods_id")
    /** 商品id */
    private String goodsId;
    @TableField("sku_name")
    /** 商品名称 */
    private String skuName;
    @TableField("coupon_id")
    /** 优惠卷id */
    private String couponId;
    @TableField("coupon_no")
    /** 编号 */
    private String couponNo;
    @TableField("coupon_name")
    /** 优惠卷名称 */
    private String couponName;
    @TableField("name")
    /** 名称 */
    private String name;
    @TableField("share_status")
    /** 是否分享 */
    private String shareStatus;
    @TableField("claim_status")
    /** 是否领取 */
    private String claimStatus;
}
framework/src/main/java/cn/lili/modules/lmk/domain/form/CouponVirtualForm.java
New file
@@ -0,0 +1,72 @@
package cn.lili.modules.lmk.domain.form;
import cn.lili.base.AbsForm;
import cn.lili.group.Add;
import cn.lili.group.Update;
import cn.lili.modules.lmk.domain.entity.CouponVirtual;
import org.springframework.beans.BeanUtils;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import org.springframework.lang.NonNull;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
 * 虚拟商品优惠卷表单
 *
 * @author zxl
 * @since 2025-09-10
 */
@Data
@ApiModel(value = "CouponVirtual表单", description = "虚拟商品优惠卷表单")
public class CouponVirtualForm extends AbsForm {
    @NotNull(message = "订单id不能为空", groups = {Add.class, Update.class})
    @ApiModelProperty("订单id")
    private Long orderId;
    @NotNull(message = "商品id不能为空", groups = {Add.class, Update.class})
    @ApiModelProperty("商品id")
    private Long goodsId;
    @NotBlank(message = "商品名称不能为空", groups = {Add.class, Update.class})
    @ApiModelProperty("商品名称")
    private String skuName;
    @NotNull(message = "优惠卷id不能为空", groups = {Add.class, Update.class})
    @ApiModelProperty("优惠卷id")
    private Long couponId;
    @NotBlank(message = "编号不能为空", groups = {Add.class, Update.class})
    @ApiModelProperty("编号")
    private String couponNo;
    @NotBlank(message = "优惠卷名称不能为空", groups = {Add.class, Update.class})
    @ApiModelProperty("优惠卷名称")
    private String couponName;
    @NotBlank(message = "名称不能为空", groups = {Add.class, Update.class})
    @ApiModelProperty("名称")
    private String name;
    @NotBlank(message = "是否分享不能为空", groups = {Add.class, Update.class})
    @ApiModelProperty("是否分享")
    private String shareStatus;
    @NotBlank(message = "是否领取不能为空", groups = {Add.class, Update.class})
    @ApiModelProperty("是否领取")
    private String claimStatus;
    public static CouponVirtual getEntityByForm(@NonNull CouponVirtualForm form, CouponVirtual entity) {
        if(entity == null) {
          entity = new CouponVirtual();
        }
        BeanUtils.copyProperties(form, entity);
        return entity;
    }
}
framework/src/main/java/cn/lili/modules/lmk/domain/query/CouponVirtualQuery.java
New file
@@ -0,0 +1,24 @@
package cn.lili.modules.lmk.domain.query;
import java.util.List;
import cn.lili.base.AbsQuery;
import org.springframework.lang.NonNull;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
 * 虚拟商品优惠卷查询
 *
 * @author zxl
 * @since 2025-09-10
 */
@Data
@ApiModel(value = "CouponVirtual查询参数", description = "虚拟商品优惠卷查询参数")
public class CouponVirtualQuery extends AbsQuery {
}
framework/src/main/java/cn/lili/modules/lmk/domain/vo/CouponVirtualVO.java
New file
@@ -0,0 +1,70 @@
package cn.lili.modules.lmk.domain.vo;
import java.util.List;
import cn.lili.base.AbsVo;
import cn.lili.modules.lmk.domain.entity.CouponVirtual;
import org.springframework.lang.NonNull;
import org.springframework.beans.BeanUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
 * 虚拟商品优惠卷展示
 *
 * @author zxl
 * @since 2025-09-10
 */
@Data
@ApiModel(value = "虚拟商品优惠卷响应数据", description = "虚拟商品优惠卷响应数据")
public class CouponVirtualVO extends AbsVo {
    /** 订单id */
    @ApiModelProperty("订单id")
    private String orderId;
    /** 商品id */
    @ApiModelProperty("商品id")
    private String goodsId;
    /** 商品名称 */
    @ApiModelProperty("商品名称")
    private String skuName;
    /** 优惠卷id */
    @ApiModelProperty("优惠卷id")
    private String couponId;
    /** 编号 */
    @ApiModelProperty("编号")
    private String couponNo;
    /** 优惠卷名称 */
    @ApiModelProperty("优惠卷名称")
    private String couponName;
    /** 名称 */
    @ApiModelProperty("名称")
    private String name;
    /** 是否分享 */
    @ApiModelProperty("是否分享")
    private String shareStatus;
    /** 是否领取 */
    @ApiModelProperty("是否领取")
    private String claimStatus;
    public static CouponVirtualVO getVoByEntity(@NonNull CouponVirtual entity, CouponVirtualVO vo) {
        if(vo == null) {
            vo = new CouponVirtualVO();
        }
        BeanUtils.copyProperties(entity, vo);
        return vo;
    }
}
framework/src/main/java/cn/lili/modules/lmk/mapper/CouponVirtualMapper.java
New file
@@ -0,0 +1,35 @@
package cn.lili.modules.lmk.mapper;
import cn.lili.modules.lmk.domain.entity.CouponVirtual;
import cn.lili.modules.lmk.domain.query.CouponVirtualQuery;
import cn.lili.modules.lmk.domain.vo.CouponVirtualVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
 * 虚拟商品优惠卷 Mapper 接口
 *
 * @author zxl
 * @since 2025-09-10
 */
@Mapper
public interface CouponVirtualMapper extends BaseMapper<CouponVirtual> {
    /**
     * id查找虚拟商品优惠卷
     * @param id
     * @return
     */
    CouponVirtualVO getById(Integer id);
    /**
    *  分页
    */
    IPage getPage(IPage page, @Param("query") CouponVirtualQuery query);
}
framework/src/main/java/cn/lili/modules/lmk/service/CouponVirtualService.java
New file
@@ -0,0 +1,67 @@
package cn.lili.modules.lmk.service;
import cn.lili.base.Result;
import cn.lili.modules.lmk.domain.entity.CouponVirtual;
import cn.lili.modules.lmk.domain.form.CouponVirtualForm;
import cn.lili.modules.lmk.domain.query.CouponVirtualQuery;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
/**
 * 虚拟商品优惠卷 服务类
 *
 * @author zxl
 * @since 2025-09-10
 */
public interface CouponVirtualService extends IService<CouponVirtual> {
    /**
     * 添加
     * @param form
     * @return
     */
    Result add(CouponVirtualForm form);
    /**
     * 修改
     * @param form
     * @return
     */
    Result update(CouponVirtualForm form);
    /**
     * 批量删除
     * @param ids
     * @return
     */
    Result remove(List<String> ids);
    /**
     * id删除
     * @param id
     * @return
     */
    Result removeById(String id);
    /**
     * 分页查询
     * @param query
     * @return
     */
    Result page(CouponVirtualQuery query);
    /**
     * 根据id查找
     * @param id
     * @return
     */
    Result detail(Integer id);
    /**
     * 列表
     * @return
     */
    Result all();
}
framework/src/main/java/cn/lili/modules/lmk/service/impl/CouponVirtualServiceImpl.java
New file
@@ -0,0 +1,121 @@
package cn.lili.modules.lmk.service.impl;
import cn.lili.base.Result;
import cn.lili.modules.lmk.domain.entity.CouponVirtual;
import cn.lili.modules.lmk.domain.form.CouponVirtualForm;
import cn.lili.modules.lmk.domain.query.CouponVirtualQuery;
import cn.lili.modules.lmk.domain.vo.CouponVirtualVO;
import cn.lili.modules.lmk.mapper.CouponVirtualMapper;
import cn.lili.modules.lmk.service.CouponVirtualService;
import cn.lili.utils.PageUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.util.Assert;
import java.util.List;
import java.util.stream.Collectors;
/**
 * 虚拟商品优惠卷 服务实现类
 *
 * @author zxl
 * @since 2025-09-10
 */
@Service
@RequiredArgsConstructor
public class CouponVirtualServiceImpl extends ServiceImpl<CouponVirtualMapper, CouponVirtual> implements CouponVirtualService {
    private final CouponVirtualMapper couponVirtualMapper;
    /**
     * 添加
     * @param form
     * @return
     */
    @Override
    public Result add(CouponVirtualForm form) {
        CouponVirtual entity = CouponVirtualForm.getEntityByForm(form, null);
        baseMapper.insert(entity);
        return Result.ok("添加成功");
    }
    /**
     * 修改
     * @param form
     * @return
     */
    @Override
    public Result update(CouponVirtualForm form) {
        CouponVirtual entity = baseMapper.selectById(form.getId());
        // 为空抛IllegalArgumentException,做全局异常处理
        Assert.notNull(entity, "记录不存在");
        BeanUtils.copyProperties(form, entity);
        baseMapper.updateById(entity);
        return Result.ok("修改成功");
    }
    /**
     * 批量删除
     * @param ids
     * @return
     */
    @Override
    public Result remove(List<String> ids) {
        baseMapper.deleteBatchIds(ids);
        return Result.ok("删除成功");
    }
    /**
     * id删除
     * @param id
     * @return
     */
    @Override
    public Result removeById(String id) {
        baseMapper.deleteById(id);
        return Result.ok("删除成功");
    }
    /**
     * 分页查询
     * @param query
     * @return
     */
    @Override
    public Result page(CouponVirtualQuery query) {
        IPage<CouponVirtualVO> page = PageUtil.getPage(query, CouponVirtualVO.class);
        baseMapper.getPage(page, query);
        return Result.ok().data(page.getRecords()).total(page.getTotal());
    }
    /**
     * 根据id查找
     * @param id
     * @return
     */
    @Override
    public Result detail(Integer id) {
        CouponVirtualVO vo = baseMapper.getById(id);
        Assert.notNull(vo, "记录不存在");
        return Result.ok().data(vo);
    }
    /**
     * 列表
     * @return
     */
    @Override
    public Result all() {
        List<CouponVirtual> entities = baseMapper.selectList(null);
        List<CouponVirtualVO> vos = entities.stream()
                .map(entity -> CouponVirtualVO.getVoByEntity(entity, null))
                .collect(Collectors.toList());
        return Result.ok().data(vos);
    }
}
framework/src/main/java/cn/lili/modules/order/cart/entity/dto/SkuMapDTO.java
New file
@@ -0,0 +1,12 @@
package cn.lili.modules.order.cart.entity.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
@Data
@AllArgsConstructor
public class SkuMapDTO {
    private String skuId;
    private Double price;
}
framework/src/main/java/cn/lili/modules/order/cart/render/impl/CouponRender.java
@@ -5,6 +5,7 @@
import cn.lili.common.utils.CurrencyUtil;
import cn.lili.common.utils.StringUtils;
import cn.lili.modules.order.cart.entity.dto.MemberCouponDTO;
import cn.lili.modules.order.cart.entity.dto.SkuMapDTO;
import cn.lili.modules.order.cart.entity.dto.TradeDTO;
import cn.lili.modules.order.cart.entity.enums.RenderStepEnums;
import cn.lili.modules.order.cart.entity.vo.CartSkuVO;
@@ -240,8 +241,13 @@
        //接收具体优惠券信息
        MemberCoupon coupon = memberCouponDTO.getMemberCoupon();
        Integer goodsNum = tradeDTO.getSkuList().stream().map(CartSkuVO::getNum).reduce(Integer::sum).get();
        //处理一个极端情况,如果优惠券满减金额大于订单金额
        if (coupon.getCouponType().equals(CouponTypeEnum.PRICE.name()) && coupon.getPrice() > countPrice) {
        if (coupon.getCouponType().equals(CouponTypeEnum.PRICE.name())
                && coupon.getPrice() > countPrice
                && coupon.getGoodsUseLimitNum() >= goodsNum) {
            //将符合优惠券的金额写入,即最大扣减金额
            coupon.setPrice(countPrice);
        }
@@ -264,21 +270,42 @@
     * @param memberCouponDTO 用于计算优惠券结算详情
     */
    private void renderCouponPrice(Map<String, Double> couponMap, TradeDTO tradeDTO, MemberCoupon coupon, MemberCouponDTO memberCouponDTO) {
        List<SkuMapDTO> skuMapDTOList = new ArrayList<>();
        for (String skuId : couponMap.keySet()) {
            skuMapDTOList.add(new SkuMapDTO(skuId, couponMap.get(skuId)));
        }
        skuMapDTOList.sort((o1, o2) -> o2.getPrice().compareTo(o1.getPrice()));
        //分发优惠券
        PromotionPriceUtil.recountPrice(tradeDTO, memberCouponDTO.getSkuDetail(), memberCouponDTO.getMemberCoupon().getPrice(),
                Boolean.TRUE.equals(coupon.getPlatformFlag()) ?
                        PromotionTypeEnum.PLATFORM_COUPON : PromotionTypeEnum.COUPON, memberCouponDTO.getMemberCoupon().getCouponId());
        PromotionPriceUtil.recountPrice(tradeDTO, memberCouponDTO.getSkuDetail(),
                memberCouponDTO.getMemberCoupon().getPrice(),
                Boolean.TRUE.equals(coupon.getPlatformFlag()) ? PromotionTypeEnum.PLATFORM_COUPON : PromotionTypeEnum.COUPON,
                memberCouponDTO.getMemberCoupon().getCouponId(),
                memberCouponDTO.getMemberCoupon().getGoodsUseLimitNum());
        //如果是平台券 则需要计算商家承担比例
        if (Boolean.TRUE.equals(coupon.getPlatformFlag()) && coupon.getStoreCommission() > 0) {
            Integer i = coupon.getGoodsUseLimitNum();
            //循环所有优惠券
            for (String skuId : couponMap.keySet()) {
            for (SkuMapDTO skuMapDTO : skuMapDTOList) {
                for (CartSkuVO cartSkuVO : tradeDTO.getSkuList()) {
                    //写入平台优惠券承担比例
                    if (cartSkuVO.getGoodsSku().getId().equals(skuId)) {
                        //写入店铺承担比例
                        cartSkuVO.getPriceDetailDTO().setSiteCouponPoint(coupon.getStoreCommission());
                    if (cartSkuVO.getGoodsSku().getId().equals(skuMapDTO.getSkuId())) {
                        if (i == null) {
                            cartSkuVO.getPriceDetailDTO().setSiteCouponPoint(coupon.getStoreCommission());
                        } else {
                            if (i > 0) {
                                //写入店铺承担比例
                                if (i >= cartSkuVO.getNum()) {
                                    cartSkuVO.getPriceDetailDTO().setSiteCouponPoint(coupon.getStoreCommission());
                                } else {
                                    cartSkuVO.getPriceDetailDTO().setSiteCouponPoint(coupon.getStoreCommission() * i / cartSkuVO.getNum());
                                }
                                i = i - cartSkuVO.getNum();
                            } else {
                                return;
                            }
                        }
                    }
                }
            }
@@ -294,6 +321,7 @@
     * @param coupon    优惠券信息
     */
    private void renderCouponDiscount(Map<String, Double> couponMap, TradeDTO tradeDTO, MemberCoupon coupon) {
        //循环所有优惠券
        for (String skuId : couponMap.keySet()) {
@@ -315,9 +343,10 @@
                    }
                    priceDetailDTO.setCouponPrice(CurrencyUtil.add(priceDetailDTO.getCouponPrice(), discountCouponPrice));
                } else {
                    return;
                }
            }
        }
    }
}
framework/src/main/java/cn/lili/modules/order/cart/render/impl/FullDiscountRender.java
@@ -86,7 +86,7 @@
                        if (isFull(countPrice, cart)) {
                            //如果减现金
                            if (Boolean.TRUE.equals(fullDiscount.getFullMinusFlag())) {
                                PromotionPriceUtil.recountPrice(tradeDTO, skuPriceDetail, fullDiscount.getFullMinus(), PromotionTypeEnum.FULL_DISCOUNT, fullDiscountVO.getId());
                                PromotionPriceUtil.recountPrice(tradeDTO, skuPriceDetail, fullDiscount.getFullMinus(), PromotionTypeEnum.FULL_DISCOUNT, fullDiscountVO.getId(), 0);
                            }
                            //打折
                            else if (Boolean.TRUE.equals(fullDiscount.getFullRateFlag())) {
framework/src/main/java/cn/lili/modules/order/cart/render/util/PromotionPriceUtil.java
@@ -3,11 +3,13 @@
import cn.hutool.core.map.MapUtil;
import cn.lili.common.enums.PromotionTypeEnum;
import cn.lili.common.utils.CurrencyUtil;
import cn.lili.modules.order.cart.entity.dto.SkuMapDTO;
import cn.lili.modules.order.cart.entity.dto.TradeDTO;
import cn.lili.modules.order.cart.entity.vo.CartSkuVO;
import cn.lili.modules.order.order.entity.dto.DiscountPriceItem;
import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -32,79 +34,111 @@
     * @param promotionTypeEnum  促销类型
     */
    public static void recountPrice(TradeDTO tradeDTO, Map<String, Double> skuPromotionDetail, Double discountPrice,
                                    PromotionTypeEnum promotionTypeEnum, String activityId) {
                                    PromotionTypeEnum promotionTypeEnum, String activityId, Integer goodsUseLimitNum) {
        // sku 促销信息非空判定
        if (skuPromotionDetail == null || skuPromotionDetail.isEmpty()) {
            return;
        }
        //计算总金额
        Double totalPrice = 0D;
        for (Double value : skuPromotionDetail.values()) {
            totalPrice = CurrencyUtil.add(totalPrice, value);
        }
        //极端情况,如果扣减金额小于需要支付的金额,则扣减金额=支付金额,不能成为负数
        if (discountPrice > totalPrice) {
            discountPrice = totalPrice;
            for (String skuId : skuPromotionDetail.keySet()) {
                //获取对应商品进行计算
                for (CartSkuVO cartSkuVO : tradeDTO.getSkuList()) {
                    if (cartSkuVO.getGoodsSku().getId().equals(skuId)) {
                        //优惠券金额,则计入优惠券 ,其他则计入总的discount price
                        if (promotionTypeEnum == PromotionTypeEnum.COUPON) {
                            cartSkuVO.getPriceDetailDTO().setCouponPrice(cartSkuVO.getPriceDetailDTO().getGoodsPrice());
                        } else {
                            cartSkuVO.getPriceDetailDTO().setDiscountPrice(cartSkuVO.getPriceDetailDTO().getGoodsPrice());
                        }
                    }
                }
            }
        }
        //获取购物车信息
        List<CartSkuVO> skuVOList = tradeDTO.getSkuList();
        // 获取map分配sku的总数,如果是最后一个商品分配金额,则将金额从百分比改为总金额扣减,避免出现小数除不尽
        AtomicInteger count = new AtomicInteger(skuPromotionDetail.size());
        //已优惠金额
        AtomicReference<Double> deducted = new AtomicReference<>(0D);
        for (String skuId : skuPromotionDetail.keySet()) {
        if (goodsUseLimitNum > 0) {
            // 处理限制商品数量逻辑,只处理一个商品
            List<SkuMapDTO> skuMapDTOList = new ArrayList<>();
            for (String skuId : skuPromotionDetail.keySet()) {
                skuMapDTOList.add(new SkuMapDTO(skuId, skuPromotionDetail.get(skuId)));
            }
            skuMapDTOList.sort((o1, o2) -> o2.getPrice().compareTo(o1.getPrice()));
            //获取对应商品进行计算
            final int[] i = {0};
            for (SkuMapDTO skuMap : skuMapDTOList) {
            Double finalDiscountPrice = discountPrice;
            Double finalTotalPrice = totalPrice;
            skuVOList.stream().filter(l -> l.getGoodsSku().getId().equals(skuId)).findFirst().ifPresent(cartSkuVO -> {
                //sku 优惠金额
                Double skuDiscountPrice;
                count.getAndDecrement();
                //获取对应商品进行计算
                Double finalDiscountPrice = discountPrice;
                skuVOList.stream().filter(l -> l.getGoodsSku().getId().equals(skuMap.getSkuId())).findFirst().ifPresent(cartSkuVO -> {
                    //sku 优惠金额
                    Double skuDiscountPrice = 0D;
                    if (i[0] < 1) {
                //非最后一个商品,则按照比例计算
                if (count.get() > 0) {
                    //商品金额占比
                    double point = CurrencyUtil.div(cartSkuVO.getPriceDetailDTO().getGoodsPrice(), finalTotalPrice, 4);
                    //商品优惠金额
                    skuDiscountPrice = CurrencyUtil.mul(finalDiscountPrice, point);
                    //累加已优惠金额
                    deducted.set(CurrencyUtil.add(deducted.get(), skuDiscountPrice));
                        if (cartSkuVO.getUtilPrice() > finalDiscountPrice) {
                            skuDiscountPrice = cartSkuVO.getUtilPrice() - finalDiscountPrice;
                        } else {
                            skuDiscountPrice = cartSkuVO.getUtilPrice();
                        }
                        //累加已优惠金额
                        deducted.set(CurrencyUtil.add(deducted.get(), skuDiscountPrice));
                        i[0] = i[0] + 1;
                    }
                    calculateCartSkuPromotionsPrice(cartSkuVO, skuDiscountPrice, promotionTypeEnum, activityId);
                });
                discountPrice = deducted.get();
            }
        } else {
            for (Double value : skuPromotionDetail.values()) {
                totalPrice = CurrencyUtil.add(totalPrice, value);
            }
            //极端情况,如果扣减金额小于需要支付的金额,则扣减金额=支付金额,不能成为负数
            if (discountPrice > totalPrice) {
                discountPrice = totalPrice;
                for (String skuId : skuPromotionDetail.keySet()) {
                    //获取对应商品进行计算
                    for (CartSkuVO cartSkuVO : tradeDTO.getSkuList()) {
                        if (cartSkuVO.getGoodsSku().getId().equals(skuId)) {
                            //优惠券金额,则计入优惠券 ,其他则计入总的discount price
                            if (promotionTypeEnum == PromotionTypeEnum.COUPON) {
                                cartSkuVO.getPriceDetailDTO().setCouponPrice(cartSkuVO.getPriceDetailDTO().getGoodsPrice());
                            } else {
                                cartSkuVO.getPriceDetailDTO().setDiscountPrice(cartSkuVO.getPriceDetailDTO().getGoodsPrice());
                            }
                        }
                    }
                }
                // 如果是最后一个商品 则减去之前优惠的金额来进行计算
                else {
                    skuDiscountPrice = CurrencyUtil.sub(finalDiscountPrice, deducted.get());
                }
            }
                calculateCartSkuPromotionsPrice(cartSkuVO, skuDiscountPrice, promotionTypeEnum, activityId);
            });
            // 获取map分配sku的总数,如果是最后一个商品分配金额,则将金额从百分比改为总金额扣减,避免出现小数除不尽
            AtomicInteger count = new AtomicInteger(skuPromotionDetail.size());
            for (String skuId : skuPromotionDetail.keySet()) {
                //获取对应商品进行计算
                Double finalDiscountPrice = discountPrice;
                Double finalTotalPrice = totalPrice;
                skuVOList.stream().filter(l -> l.getGoodsSku().getId().equals(skuId)).findFirst().ifPresent(cartSkuVO -> {
                    //sku 优惠金额
                    Double skuDiscountPrice;
                    count.getAndDecrement();
                    //非最后一个商品,则按照比例计算
                    if (count.get() > 0) {
                        //商品金额占比
                        double point = CurrencyUtil.div(cartSkuVO.getPriceDetailDTO().getGoodsPrice(), finalTotalPrice, 4);
                        //商品优惠金额
                        skuDiscountPrice = CurrencyUtil.mul(finalDiscountPrice, point);
                        //累加已优惠金额
                        deducted.set(CurrencyUtil.add(deducted.get(), skuDiscountPrice));
                    }
                    // 如果是最后一个商品 则减去之前优惠的金额来进行计算
                    else {
                        skuDiscountPrice = CurrencyUtil.sub(finalDiscountPrice, deducted.get());
                    }
                    calculateCartSkuPromotionsPrice(cartSkuVO, skuDiscountPrice, promotionTypeEnum, activityId);
                });
            }
        }
        calculateNotEnoughPromotionsPrice(skuVOList, skuPromotionDetail, discountPrice, totalPrice, promotionTypeEnum, activityId);
    }
@@ -218,9 +252,11 @@
            // 如果还有剩余金额,则继续分摊
            if (balance.get() > 0) {
                skuPromotionDetailClone.remove(lastSkuId.toString());
                double lastDiscountPrice = CurrencyUtil.sub(discountPrice, skuPromotionDetail.get(lastSkuId.toString()));
                double lastTotalPrice = CurrencyUtil.sub(totalPrice, skuPromotionDetail.get(lastSkuId.toString()));
                filterEnoughSku(skuVOList, skuPromotionDetailClone, lastDiscountPrice, lastTotalPrice, balance, lastSkuId, promotionTypeEnum, activityId);
                if (skuPromotionDetail.containsKey(lastSkuId.toString())) {
                    double lastDiscountPrice = CurrencyUtil.sub(discountPrice, skuPromotionDetail.get(lastSkuId.toString()));
                    double lastTotalPrice = CurrencyUtil.sub(totalPrice, skuPromotionDetail.get(lastSkuId.toString()));
                    filterEnoughSku(skuVOList, skuPromotionDetailClone, lastDiscountPrice, lastTotalPrice, balance, lastSkuId, promotionTypeEnum, activityId);
                }
            } else {
                break;
            }
@@ -235,9 +271,9 @@
    private static void filterEnoughSku(List<CartSkuVO> skuVOList, Map<String, Double> skuPromotionDetail,
                                                   Double discountPrice, Double totalPrice,
                                                   AtomicReference<Double> balance, StringBuilder lastSkuId,
                                                   PromotionTypeEnum promotionTypeEnum, String activityId) {
                                        Double discountPrice, Double totalPrice,
                                        AtomicReference<Double> balance, StringBuilder lastSkuId,
                                        PromotionTypeEnum promotionTypeEnum, String activityId) {
        AtomicInteger count = new AtomicInteger(skuPromotionDetail.size());
        AtomicReference<Double> countPrice = new AtomicReference<>(0D);
        for (String skuId : skuPromotionDetail.keySet()) {
framework/src/main/java/cn/lili/modules/order/order/entity/dos/Order.java
@@ -185,6 +185,11 @@
     */
    @ApiModelProperty(value = "订单类型")
    private String orderType;
    /**
     * 订单地址修改状态
     */
    @ApiModelProperty(value = "订单地址修改状态")
    private String modifyAddressFlag;
    /**
     * @see OrderPromotionTypeEnum
framework/src/main/java/cn/lili/modules/order/order/entity/enums/ModifyAddressEnums.java
New file
@@ -0,0 +1,11 @@
package cn.lili.modules.order.order.entity.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
@AllArgsConstructor
@Getter
public enum ModifyAddressEnums {
    USED("已被领取");
    private final String des;
}
framework/src/main/java/cn/lili/modules/order/order/entity/vo/OrderSimpleVO.java
@@ -159,6 +159,7 @@
    private String consigneeName;
    private String consigneeMobile;
    private String modifyAddressFlag;
    private String memberId;
framework/src/main/java/cn/lili/modules/order/order/mapper/OrderMapper.java
@@ -90,6 +90,7 @@
            "o.consignee_mobile AS consigneeMobile," +
            "o.member_id AS memberId," +
            "m.nick_name AS nickName," +
            "o.modify_address_flag AS modifyAddressFlag,"+
            " GROUP_CONCAT(oi.goods_id) as group_goods_id," +
            " GROUP_CONCAT(oi.sku_id) as group_sku_id," +
            " GROUP_CONCAT(oi.num) as group_num" +
@@ -117,6 +118,7 @@
            "o.consignee_name AS consigneeName," +
            "o.consignee_mobile AS consigneeMobile," +
            "o.member_id AS memberId," +
            "o.modify_address_flag AS modifyAddressFlag,"+
            " GROUP_CONCAT(oi.goods_id) as group_goods_id," +
            " GROUP_CONCAT(oi.sku_id) as group_sku_id," +
            " GROUP_CONCAT(oi.num) as group_num" +
framework/src/main/java/cn/lili/modules/order/order/service/OrderService.java
@@ -127,6 +127,8 @@
     */
    OrderDetailVO queryDetail(String orderSn);
    OrderDetailVO queryEditAddressDetail(String orderSn);
    String sendMqMessage(String  snNo);
    /**
     * 创建订单
@@ -175,6 +177,8 @@
     */
    Order updateConsignee(String orderSn, MemberAddressDTO memberAddressDTO);
    Order updateAddressConsignee(String orderSn, MemberAddressDTO memberAddressDTO);
    /**
     * 订单发货
     *
framework/src/main/java/cn/lili/modules/order/order/serviceimpl/OrderServiceImpl.java
@@ -200,6 +200,7 @@
    private RedisTemplate<Object,Object> redisTemplate;
    private final static  String LOCK_ORDER_NO_MQ="lock_order_no_mq:";
    private final static  String LOCK_EDIT_ORDER_ADDRESS="lock_edit_order_address:";
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void intoDB(TradeDTO tradeDTO) {
@@ -488,6 +489,18 @@
        //查询订单和自订单,然后写入vo返回
        return new OrderDetailVO(order, orderItems, orderLogs, receipt);
    }
    @Override
    public OrderDetailVO queryEditAddressDetail(String orderSn) {
        Order order = this.getBySn(orderSn);
        if (order == null) {
            throw new ServiceException(ResultCode.ORDER_NOT_EXIST);
        }
        //查询订单项信息
        List<OrderItem> orderItems = orderItemService.getByOrderSn(orderSn);
        //查询订单和自订单,然后写入vo返回
        return new OrderDetailVO(order, orderItems, null, null);
    }
    @Override
    @Transactional
@@ -666,7 +679,40 @@
        return order;
    }
    @Override
    @SystemLogPoint(description = "修改订单", customerLog = "'订单[' + #orderSn + ']收货信息修改,修改为'+#memberAddressDTO.consigneeDetail")
    @Transactional(rollbackFor = Exception.class)
    public Order updateAddressConsignee(String orderSn, MemberAddressDTO memberAddressDTO) {
        Order order = this.getBySn(orderSn);
        if (order == null) {
            throw new ServiceException(ResultCode.ORDER_NOT_EXIST);
        }
        //限制30秒只能请求一次避免出现重新提交问题
        Boolean b = redisTemplate.opsForValue().setIfAbsent(LOCK_EDIT_ORDER_ADDRESS + orderSn, orderSn,30, TimeUnit.SECONDS);
        if ( Boolean.FALSE.equals(b)){
            throw new ServiceException("请在30秒后重试");
        }
        String modifyAddressFlag = order.getModifyAddressFlag();
        if (StringUtils.isNotBlank(modifyAddressFlag)) {
            throw new ServiceException("当前订单已经被领取");
        }
        QueryWrapper<Order> wrapper = new QueryWrapper<>();
        wrapper.eq("id", order.getId());
        // 使用 last 方法拼接 FOR UPDATE 语句
        wrapper.last("FOR UPDATE");
        baseMapper.selectOne(wrapper);
        //要记录之前的收货地址,所以需要以代码方式进行调用 不采用注解
        String message = "订单[" + orderSn + "]收货信息修改,由[" +order.getConsigneeAddressPath()+  order.getConsigneeDetail() + "]修改为[" + memberAddressDTO.getConsigneeAddressPath()+ memberAddressDTO.getConsigneeDetail() + "]";
        //记录订单操作日志
        BeanUtil.copyProperties(memberAddressDTO, order);
        order.setModifyAddressFlag(ModifyAddressEnums.USED.name());
        this.updateById(order);
        OrderLog orderLog = new OrderLog(orderSn, UserContext.getCurrentUser().getId(), UserContext.getCurrentUser().getRole().getRole(),
                UserContext.getCurrentUser().getUsername(), message);
        orderLogService.save(orderLog);
        return order;
    }
    @Override
    @OrderLogPoint(description = "'订单['+#orderSn+']发货,发货单号['+#logisticsNo+']'", orderSn = "#orderSn")
    @Transactional(rollbackFor = Exception.class)
framework/src/main/java/cn/lili/modules/promotion/entity/dos/Coupon.java
@@ -82,6 +82,9 @@
    @ApiModelProperty(value = "有效期")
    private Integer effectiveDays;
    @ApiModelProperty(value = "商品使用限制")
    private Integer goodsUseLimitNum;
    public Coupon(CouponVO couponVO) {
        BeanUtils.copyProperties(couponVO, this);
    }
framework/src/main/java/cn/lili/modules/promotion/entity/dos/MemberCoupon.java
@@ -107,6 +107,8 @@
    @ApiModelProperty(value = "会员优惠券状态")
    private String memberCouponStatus;
    @ApiModelProperty(value = "商品使用限制")
    private Integer goodsUseLimitNum;
    public MemberCoupon() {
    }
@@ -120,6 +122,7 @@
        setScopeType(coupon.getScopeType());
        setScopeId(coupon.getScopeId());
        setCouponType(coupon.getCouponType());
        setGoodsUseLimitNum(coupon.getGoodsUseLimitNum());
        setStartTime(coupon.getStartTime() == null ? new Date() : coupon.getStartTime());
        setGetType(coupon.getGetType());
framework/src/main/resources/mapper/lmk/CouponVirtualMapper.xml
New file
@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.lili.modules.lmk.mapper.CouponVirtualMapper">
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.ycl.domain.vo.CouponVirtualVO">
        <result column="order_id" property="orderId" />
        <result column="goods_id" property="goodsId" />
        <result column="sku_name" property="skuName" />
        <result column="coupon_id" property="couponId" />
        <result column="coupon_no" property="couponNo" />
        <result column="coupon_name" property="couponName" />
        <result column="name" property="name" />
        <result column="share_status" property="shareStatus" />
        <result column="claim_status" property="claimStatus" />
        <result column="update_time" property="updateTime" />
        <result column="create_by" property="createBy" />
        <result column="create_time" property="createTime" />
        <result column="update_by" property="updateBy" />
        <result column="delete_flag" property="deleteFlag" />
    </resultMap>
    <select id="getById" resultMap="BaseResultMap">
        SELECT
            LCV.order_id,
            LCV.goods_id,
            LCV.sku_name,
            LCV.coupon_id,
            LCV.coupon_no,
            LCV.coupon_name,
            LCV.name,
            LCV.share_status,
            LCV.claim_status,
            LCV.update_time,
            LCV.create_by,
            LCV.create_time,
            LCV.update_by,
            LCV.delete_flag,
            LCV.id
        FROM
            lmk_coupon_virtual LCV
        WHERE
            LCV.id = #{id} AND LCV.deleted = 0
    </select>
    <select id="getPage" resultMap="BaseResultMap">
        SELECT
            LCV.order_id,
            LCV.goods_id,
            LCV.sku_name,
            LCV.coupon_id,
            LCV.coupon_no,
            LCV.coupon_name,
            LCV.name,
            LCV.share_status,
            LCV.claim_status,
            LCV.update_time,
            LCV.create_by,
            LCV.create_time,
            LCV.update_by,
            LCV.delete_flag,
            LCV.id
        FROM
            lmk_coupon_virtual LCV
        WHERE
            LCV.deleted = 0
    </select>
</mapper>
framework/src/main/resources/mapper/lmk/VideoMapper.xml
@@ -300,7 +300,7 @@
            LV.delete_flag = 0
          AND LV.STATUS = '1'
          AND LV.video_type = #{query.videoType}
          AND lm.id IS NOT NULL
          AND LM.id IS NOT NULL
        UNION ALL
        SELECT
            LV.author_id,
@@ -334,7 +334,7 @@
            LV.delete_flag = 0
          AND LV.STATUS = '1'
          AND LV.video_type = #{query.videoType}
          AND lm.id IS NOT NULL
          AND LM.id IS NOT NULL
        ORDER BY
            create_time DESC
    </select>