parent
61f1a8de71
commit
d23cb8b71b
|
|
@ -15,6 +15,7 @@ import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 消费赠券表 实体类。
|
* 消费赠券表 实体类。
|
||||||
|
|
@ -26,6 +27,7 @@ import lombok.NoArgsConstructor;
|
||||||
@Builder
|
@Builder
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@Accessors(chain = true)
|
||||||
@Table("mk_shop_consumer_coupon")
|
@Table("mk_shop_consumer_coupon")
|
||||||
public class MkShopConsumerCoupon implements Serializable {
|
public class MkShopConsumerCoupon implements Serializable {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@ import com.czg.market.entity.MkShopConsumerCoupon;
|
||||||
import com.mybatisflex.core.paginate.Page;
|
import com.mybatisflex.core.paginate.Page;
|
||||||
import com.mybatisflex.core.service.IService;
|
import com.mybatisflex.core.service.IService;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 消费赠券表 服务层。
|
* 消费赠券表 服务层。
|
||||||
*
|
*
|
||||||
|
|
@ -14,8 +16,17 @@ import com.mybatisflex.core.service.IService;
|
||||||
public interface MkShopConsumerCouponService extends IService<MkShopConsumerCoupon> {
|
public interface MkShopConsumerCouponService extends IService<MkShopConsumerCoupon> {
|
||||||
|
|
||||||
Page<MkShopConsumerCouponDTO> getConsumerCouponPage(MkShopConsumerCouponDTO param);
|
Page<MkShopConsumerCouponDTO> getConsumerCouponPage(MkShopConsumerCouponDTO param);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参加消费赠券
|
||||||
|
*/
|
||||||
|
void receiveConsumerCoupon(Long shopId, Long orderId, BigDecimal orderAmount, Long userId, Long shopUserId);
|
||||||
|
|
||||||
MkShopConsumerCouponDTO getConsumerCouponById(Long id);
|
MkShopConsumerCouponDTO getConsumerCouponById(Long id);
|
||||||
|
|
||||||
void addConsumerCoupon(MkShopConsumerCouponDTO param);
|
void addConsumerCoupon(MkShopConsumerCouponDTO param);
|
||||||
|
|
||||||
void updateConsumerCouponById(MkShopConsumerCouponDTO param);
|
void updateConsumerCouponById(MkShopConsumerCouponDTO param);
|
||||||
|
|
||||||
void deleteConsumerCoupon(Long id);
|
void deleteConsumerCoupon(Long id);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,11 @@ public class CheckOrderPay implements Serializable {
|
||||||
* 手动优惠金额
|
* 手动优惠金额
|
||||||
*/
|
*/
|
||||||
private BigDecimal discountAmount;
|
private BigDecimal discountAmount;
|
||||||
|
/**
|
||||||
|
* 新客立减
|
||||||
|
*/
|
||||||
|
private BigDecimal newCustomerDiscountId;
|
||||||
|
private BigDecimal newCustomerDiscountAmount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品优惠券抵扣金额
|
* 商品优惠券抵扣金额
|
||||||
|
|
@ -114,6 +119,12 @@ public class CheckOrderPay implements Serializable {
|
||||||
// }
|
// }
|
||||||
// return discountRatio.setScale(2, RoundingMode.UP);
|
// return discountRatio.setScale(2, RoundingMode.UP);
|
||||||
// }
|
// }
|
||||||
|
/**
|
||||||
|
* 新客立减金额
|
||||||
|
*/
|
||||||
|
public BigDecimal getNewCustomerDiscountAmount() {
|
||||||
|
return newCustomerDiscountAmount == null ? BigDecimal.ZERO : newCustomerDiscountAmount;
|
||||||
|
}
|
||||||
|
|
||||||
public BigDecimal getOtherCouponDiscountAmount() {
|
public BigDecimal getOtherCouponDiscountAmount() {
|
||||||
return otherCouponDiscountAmount == null ? BigDecimal.ZERO : otherCouponDiscountAmount;
|
return otherCouponDiscountAmount == null ? BigDecimal.ZERO : otherCouponDiscountAmount;
|
||||||
|
|
|
||||||
|
|
@ -88,6 +88,11 @@ public class OrderInfo implements Serializable {
|
||||||
*/
|
*/
|
||||||
private Integer pointsNum;
|
private Integer pointsNum;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新客立减金额
|
||||||
|
*/
|
||||||
|
private BigDecimal newCustomerDiscountAmount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品优惠券抵扣金额
|
* 商品优惠券抵扣金额
|
||||||
*/
|
*/
|
||||||
|
|
@ -279,6 +284,10 @@ public class OrderInfo implements Serializable {
|
||||||
return StrUtil.isBlank(refundRemark) ? "" : refundRemark + " ";
|
return StrUtil.isBlank(refundRemark) ? "" : refundRemark + " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BigDecimal getNewCustomerDiscountAmount() {
|
||||||
|
return newCustomerDiscountAmount == null ? BigDecimal.ZERO : newCustomerDiscountAmount;
|
||||||
|
}
|
||||||
|
|
||||||
public BigDecimal getOriginAmount() {
|
public BigDecimal getOriginAmount() {
|
||||||
return originAmount == null ? BigDecimal.ZERO : originAmount;
|
return originAmount == null ? BigDecimal.ZERO : originAmount;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,16 @@
|
||||||
package com.czg.service.market.service.impl;
|
package com.czg.service.market.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.exceptions.ValidateException;
|
import cn.hutool.core.exceptions.ValidateException;
|
||||||
|
import com.czg.market.dto.MkCouponGiftDTO;
|
||||||
import com.czg.market.dto.MkShopConsumerCouponDTO;
|
import com.czg.market.dto.MkShopConsumerCouponDTO;
|
||||||
|
import com.czg.market.dto.MkShopCouponGiftDTO;
|
||||||
import com.czg.market.entity.MkShopConsumerCoupon;
|
import com.czg.market.entity.MkShopConsumerCoupon;
|
||||||
import com.czg.market.entity.ShopCoupon;
|
import com.czg.market.entity.MkShopCouponRecord;
|
||||||
import com.czg.market.service.MkCouponGiftService;
|
import com.czg.market.service.MkCouponGiftService;
|
||||||
import com.czg.market.service.MkShopConsumerCouponService;
|
import com.czg.market.service.MkShopConsumerCouponService;
|
||||||
|
import com.czg.market.service.MkShopCouponRecordService;
|
||||||
import com.czg.service.market.mapper.MkShopConsumerCouponMapper;
|
import com.czg.service.market.mapper.MkShopConsumerCouponMapper;
|
||||||
import com.czg.utils.AssertUtil;
|
import com.czg.utils.AssertUtil;
|
||||||
import com.czg.utils.PageUtil;
|
import com.czg.utils.PageUtil;
|
||||||
|
|
@ -17,6 +21,9 @@ import jakarta.annotation.Resource;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 消费赠券表 服务层实现。
|
* 消费赠券表 服务层实现。
|
||||||
*
|
*
|
||||||
|
|
@ -28,6 +35,8 @@ public class MkShopConsumerCouponServiceImpl extends ServiceImpl<MkShopConsumerC
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private MkCouponGiftService couponGiftService;
|
private MkCouponGiftService couponGiftService;
|
||||||
|
@Resource
|
||||||
|
private MkShopCouponRecordService recordService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<MkShopConsumerCouponDTO> getConsumerCouponPage(MkShopConsumerCouponDTO param) {
|
public Page<MkShopConsumerCouponDTO> getConsumerCouponPage(MkShopConsumerCouponDTO param) {
|
||||||
|
|
@ -43,6 +52,56 @@ public class MkShopConsumerCouponServiceImpl extends ServiceImpl<MkShopConsumerC
|
||||||
return pages;
|
return pages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public void receiveConsumerCoupon(Long shopId, Long orderId, BigDecimal orderAmount, Long userId, Long shopUserId) {
|
||||||
|
MkShopConsumerCoupon consumerCoupon = this.getOne(new QueryWrapper()
|
||||||
|
.eq(MkShopConsumerCoupon::getShopId, shopId)
|
||||||
|
.eq(MkShopConsumerCoupon::getStatus, 1)
|
||||||
|
.le(MkShopConsumerCoupon::getFullAmount, orderAmount)
|
||||||
|
.orderBy(MkShopConsumerCoupon::getFullAmount).desc()
|
||||||
|
.orderBy(MkShopConsumerCoupon::getCreateTime).desc());
|
||||||
|
if (consumerCoupon == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//判断是否已被领取
|
||||||
|
if (consumerCoupon.getGiveNum() != -10086 && consumerCoupon.getGiveNum() <= consumerCoupon.getGiftNum()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<MkCouponGiftDTO> giftCoupons = couponGiftService.getCouponGiftBySourceId(consumerCoupon.getId(), 3);
|
||||||
|
if (CollUtil.isEmpty(giftCoupons)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MkCouponGiftDTO giftCoupon = giftCoupons.getFirst();
|
||||||
|
if (consumerCoupon.getLeftNum() != -10086 && consumerCoupon.getLeftNum() >= consumerCoupon.getGiftNum()) {
|
||||||
|
if (consumerCoupon.getGetLimit() != -10086 && consumerCoupon.getGetLimit() <= consumerCoupon.getGiveNum()) {
|
||||||
|
long count = recordService.count(new QueryWrapper().eq(MkShopCouponRecord::getShopId, shopId)
|
||||||
|
.eq(MkShopCouponRecord::getShopUserId, shopUserId)
|
||||||
|
.eq(MkShopCouponRecord::getSourceId, consumerCoupon.getId()));
|
||||||
|
if (consumerCoupon.getGetLimit() >= count + giftCoupon.getNum()) {
|
||||||
|
MkShopCouponGiftDTO giftDTO = new MkShopCouponGiftDTO();
|
||||||
|
giftDTO.setShopId(shopId);
|
||||||
|
giftDTO.setShopUserId(shopUserId);
|
||||||
|
giftDTO.setCouponId(giftCoupon.getCouponId());
|
||||||
|
giftDTO.setSourceId(consumerCoupon.getId());
|
||||||
|
giftDTO.setSourceFlowId(orderId);
|
||||||
|
giftDTO.setSource("消费赠券");
|
||||||
|
//发放券
|
||||||
|
recordService.receiveCoupon(giftDTO, giftCoupon.getNum(), false);
|
||||||
|
//更新优惠券信息
|
||||||
|
consumerCoupon.setGiftNum(consumerCoupon.getGiftNum() + giftCoupon.getNum());
|
||||||
|
if (consumerCoupon.getLeftNum() != -10086) {
|
||||||
|
consumerCoupon.setLeftNum(consumerCoupon.getLeftNum() - giftCoupon.getNum());
|
||||||
|
}
|
||||||
|
updateById(new MkShopConsumerCoupon()
|
||||||
|
.setId(consumerCoupon.getId())
|
||||||
|
.setLeftNum(consumerCoupon.getLeftNum())
|
||||||
|
.setGiftNum(consumerCoupon.getGiftNum()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MkShopConsumerCouponDTO getConsumerCouponById(Long id) {
|
public MkShopConsumerCouponDTO getConsumerCouponById(Long id) {
|
||||||
AssertUtil.isNull(id, "ID不能为空");
|
AssertUtil.isNull(id, "ID不能为空");
|
||||||
|
|
@ -55,6 +114,9 @@ public class MkShopConsumerCouponServiceImpl extends ServiceImpl<MkShopConsumerC
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public void addConsumerCoupon(MkShopConsumerCouponDTO param) {
|
public void addConsumerCoupon(MkShopConsumerCouponDTO param) {
|
||||||
|
if (CollUtil.isEmpty(param.getCouponGiftList())) {
|
||||||
|
throw new ValidateException("优惠券信息不能为空");
|
||||||
|
}
|
||||||
MkShopConsumerCoupon bean = BeanUtil.toBean(param, MkShopConsumerCoupon.class);
|
MkShopConsumerCoupon bean = BeanUtil.toBean(param, MkShopConsumerCoupon.class);
|
||||||
save(bean);
|
save(bean);
|
||||||
//新增优惠券信息/数量
|
//新增优惠券信息/数量
|
||||||
|
|
|
||||||
|
|
@ -23,10 +23,7 @@ import com.czg.exception.CzgException;
|
||||||
import com.czg.exception.OrderCancelException;
|
import com.czg.exception.OrderCancelException;
|
||||||
import com.czg.market.entity.MkShopCouponRecord;
|
import com.czg.market.entity.MkShopCouponRecord;
|
||||||
import com.czg.market.entity.ShopCoupon;
|
import com.czg.market.entity.ShopCoupon;
|
||||||
import com.czg.market.service.MemberOrderService;
|
import com.czg.market.service.*;
|
||||||
import com.czg.market.service.MkShopCouponRecordService;
|
|
||||||
import com.czg.market.service.ShopCouponService;
|
|
||||||
import com.czg.market.service.TbMemberConfigService;
|
|
||||||
import com.czg.order.dto.*;
|
import com.czg.order.dto.*;
|
||||||
import com.czg.order.entity.*;
|
import com.czg.order.entity.*;
|
||||||
import com.czg.order.enums.PayEnums;
|
import com.czg.order.enums.PayEnums;
|
||||||
|
|
@ -107,11 +104,11 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
||||||
private ShopUserFlowService flowService;
|
private ShopUserFlowService flowService;
|
||||||
@DubboReference
|
@DubboReference
|
||||||
private ShopTableService shopTableService;
|
private ShopTableService shopTableService;
|
||||||
// @DubboReference
|
|
||||||
// private ShopActivateService activateService;
|
|
||||||
@DubboReference
|
@DubboReference
|
||||||
private PointsBasicSettingService pointsBasicService;
|
private PointsBasicSettingService pointsBasicService;
|
||||||
@DubboReference
|
@DubboReference
|
||||||
|
private MkShopConsumerCouponService consumerCouponService;
|
||||||
|
@DubboReference
|
||||||
private ShopCouponService couponService;
|
private ShopCouponService couponService;
|
||||||
@DubboReference
|
@DubboReference
|
||||||
private MkShopCouponRecordService couponRecordService;
|
private MkShopCouponRecordService couponRecordService;
|
||||||
|
|
@ -464,6 +461,8 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
||||||
throw new ValidateException("生成支付订单失败,商品优惠券优惠金额不正确");
|
throw new ValidateException("生成支付订单失败,商品优惠券优惠金额不正确");
|
||||||
}
|
}
|
||||||
//TODO 新客立减
|
//TODO 新客立减
|
||||||
|
//新客立减
|
||||||
|
newTotalAmount = newTotalAmount.subtract(param.getNewCustomerDiscountAmount());
|
||||||
//折扣金额
|
//折扣金额
|
||||||
if (param.getDiscountAmount().compareTo(BigDecimal.ZERO) > 0) {
|
if (param.getDiscountAmount().compareTo(BigDecimal.ZERO) > 0) {
|
||||||
newTotalAmount = totalAmount.getPrice().subtract(param.getDiscountAmount());
|
newTotalAmount = totalAmount.getPrice().subtract(param.getDiscountAmount());
|
||||||
|
|
@ -721,7 +720,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void getOrderAmount(List<OrderDetail> orderDetails, BigDecimalDTO totalAmount, BigDecimalDTO packAmount,
|
public void getOrderAmount(List<OrderDetail> orderDetails, BigDecimalDTO totalAmount, BigDecimalDTO packAmount,
|
||||||
BigDecimalDTO tempAmount, boolean isAllPack, Integer userAllPack, boolean isVipPrice) {
|
BigDecimalDTO tempAmount, boolean isAllPack, Integer userAllPack, boolean isVipPrice) {
|
||||||
for (OrderDetail orderDetail : orderDetails) {
|
for (OrderDetail orderDetail : orderDetails) {
|
||||||
if (orderDetail.getDiscountSaleAmount() != null && orderDetail.getDiscountSaleAmount().compareTo(BigDecimal.ZERO) > 0) {
|
if (orderDetail.getDiscountSaleAmount() != null && orderDetail.getDiscountSaleAmount().compareTo(BigDecimal.ZERO) > 0) {
|
||||||
orderDetail.setUnitPrice(orderDetail.getDiscountSaleAmount());
|
orderDetail.setUnitPrice(orderDetail.getDiscountSaleAmount());
|
||||||
|
|
@ -965,6 +964,10 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
||||||
couponService.use(coupons, shopUser.getId(), orderInfo.getId());
|
couponService.use(coupons, shopUser.getId(), orderInfo.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!orderInfo.getPayType().equals(PayEnums.CREDIT_PAY.getValue())) {
|
||||||
|
//消费赠券 挂账支付不赠送
|
||||||
|
consumerCouponService.receiveConsumerCoupon(shopUser.getShopId(), orderInfo.getId(), orderInfo.getPayAmount(), shopUser.getUserId(), shopUser.getId());
|
||||||
|
}
|
||||||
String[] payTypes = {PayEnums.VIP_PAY.getValue(), PayEnums.CREDIT_PAY.getValue()};
|
String[] payTypes = {PayEnums.VIP_PAY.getValue(), PayEnums.CREDIT_PAY.getValue()};
|
||||||
if ((orderInfo.getPayType() != null && !ArrayUtil.contains(payTypes, orderInfo.getPayType()))
|
if ((orderInfo.getPayType() != null && !ArrayUtil.contains(payTypes, orderInfo.getPayType()))
|
||||||
|| (payType != null && !ArrayUtil.contains(payTypes, payType))) {
|
|| (payType != null && !ArrayUtil.contains(payTypes, payType))) {
|
||||||
|
|
@ -1115,6 +1118,8 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
||||||
orderInfo.setOrderAmount(param.getOrderAmount());
|
orderInfo.setOrderAmount(param.getOrderAmount());
|
||||||
orderInfo.setPointsDiscountAmount(param.getPointsDiscountAmount());
|
orderInfo.setPointsDiscountAmount(param.getPointsDiscountAmount());
|
||||||
orderInfo.setProductCouponDiscountAmount(param.getProductCouponDiscountAmount());
|
orderInfo.setProductCouponDiscountAmount(param.getProductCouponDiscountAmount());
|
||||||
|
//新客立减
|
||||||
|
orderInfo.setNewCustomerDiscountAmount(param.getNewCustomerDiscountAmount());
|
||||||
// orderInfo.setFullCouponDiscountAmount(param.getFullCouponDiscountAmount());
|
// orderInfo.setFullCouponDiscountAmount(param.getFullCouponDiscountAmount());
|
||||||
orderInfo.setOtherCouponDiscountAmount(param.getOtherCouponDiscountAmount());
|
orderInfo.setOtherCouponDiscountAmount(param.getOtherCouponDiscountAmount());
|
||||||
orderInfo.setDiscountAmount(param.getDiscountAmount());
|
orderInfo.setDiscountAmount(param.getDiscountAmount());
|
||||||
|
|
@ -1164,6 +1169,9 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
||||||
*/
|
*/
|
||||||
private String buildDiscountInfo(OrderInfo orderInfo) {
|
private String buildDiscountInfo(OrderInfo orderInfo) {
|
||||||
JSONObject jsonObject = new JSONObject();
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
if (orderInfo.getNewCustomerDiscountAmount().compareTo(BigDecimal.ZERO) > 0) {
|
||||||
|
jsonObject.put("新客立减", orderInfo.getNewCustomerDiscountAmount());
|
||||||
|
}
|
||||||
if (orderInfo.getProductCouponDiscountAmount().compareTo(BigDecimal.ZERO) > 0) {
|
if (orderInfo.getProductCouponDiscountAmount().compareTo(BigDecimal.ZERO) > 0) {
|
||||||
jsonObject.put("商品券抵扣", orderInfo.getProductCouponDiscountAmount());
|
jsonObject.put("商品券抵扣", orderInfo.getProductCouponDiscountAmount());
|
||||||
}
|
}
|
||||||
|
|
@ -1173,7 +1181,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
||||||
if (orderInfo.getFullCouponDiscountAmount().compareTo(BigDecimal.ZERO) > 0) {
|
if (orderInfo.getFullCouponDiscountAmount().compareTo(BigDecimal.ZERO) > 0) {
|
||||||
jsonObject.put("满减券抵扣", orderInfo.getFullCouponDiscountAmount());
|
jsonObject.put("满减券抵扣", orderInfo.getFullCouponDiscountAmount());
|
||||||
}
|
}
|
||||||
if(orderInfo.getOtherCouponDiscountAmount().compareTo(BigDecimal.ZERO) > 0){
|
if (orderInfo.getOtherCouponDiscountAmount().compareTo(BigDecimal.ZERO) > 0) {
|
||||||
jsonObject.put("其它优惠券折扣", orderInfo.getOtherCouponDiscountAmount());
|
jsonObject.put("其它优惠券折扣", orderInfo.getOtherCouponDiscountAmount());
|
||||||
}
|
}
|
||||||
if (orderInfo.getPointsDiscountAmount().compareTo(BigDecimal.ZERO) > 0) {
|
if (orderInfo.getPointsDiscountAmount().compareTo(BigDecimal.ZERO) > 0) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue