生成订单

优惠券字段
This commit is contained in:
2025-02-24 14:19:30 +08:00
parent 9ef904c915
commit da3f548ca0
15 changed files with 539 additions and 184 deletions

View File

@@ -1,10 +1,10 @@
package com.czg.service.account.service.impl;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.czg.account.entity.Product;
import com.czg.account.service.ProductService;
import com.czg.service.account.mapper.ProductMapper;
import org.springframework.stereotype.Service;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import org.apache.dubbo.config.annotation.DubboService;
/**
* 商品 服务层实现。
@@ -12,7 +12,7 @@ import org.springframework.stereotype.Service;
* @author zs
* @since 2025-02-20
*/
@Service
@DubboService
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements ProductService{
}

View File

@@ -2,14 +2,17 @@ package com.czg.service.account.service.impl;
import cn.hutool.core.bean.BeanUtil;
import com.czg.account.dto.ShopCouponDTO;
import com.czg.account.entity.Product;
import com.czg.account.entity.ShopActivateCouponRecord;
import com.czg.account.entity.ShopCoupon;
import com.czg.account.service.ProductService;
import com.czg.account.service.ShopActivateCouponRecordService;
import com.czg.account.service.ShopCouponService;
import com.czg.sa.StpKit;
import com.czg.service.account.mapper.ShopCouponMapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import java.util.List;
@@ -25,13 +28,22 @@ public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCou
@Resource
private ShopActivateCouponRecordService couponRecordService;
@DubboReference
private ProductService productService;
@Override
public List<ShopCouponDTO> getList(Long shopId, Integer type, Integer status) {
return queryChain().select().eq(ShopCoupon::getShopId, shopId)
List<ShopCouponDTO> coupons = queryChain().select().eq(ShopCoupon::getShopId, shopId)
.eq(ShopCoupon::getType, type)
.eq(ShopCoupon::getStatus, status)
.orderBy(ShopCoupon::getCreateTime).desc().listAs(ShopCouponDTO.class);
coupons.forEach(coupon -> {
if (coupon.getProId() != null) {
Product product = productService.getById(coupon.getProId());
coupon.setProName(product.getName());
}
});
return coupons;
}
@Override
@@ -51,13 +63,14 @@ public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCou
@Override
public List<ShopActivateCouponRecord> find(Long shopUserId, Integer status) {
return couponRecordService.queryChain()
List<ShopActivateCouponRecord> list = couponRecordService.queryChain()
.eq(ShopActivateCouponRecord::getShopId, StpKit.USER.getShopId())
.eq(ShopActivateCouponRecord::getShopUserId, shopUserId)
.eq(ShopActivateCouponRecord::getStatus, status)
.orderBy(ShopActivateCouponRecord::getStatus).asc()
.orderBy(ShopActivateCouponRecord::getCreateTime).desc()
.select().list();
return list;
}
@Override

View File

@@ -15,8 +15,7 @@ import com.czg.config.RedisCst;
import com.czg.entity.notify.CzgPayNotifyDTO;
import com.czg.entity.notify.CzgRefundNotifyDTO;
import com.czg.enums.ShopUserFlowBizEnum;
import com.czg.order.dto.OrderInfoAddDTO;
import com.czg.order.dto.OrderInfoQueryDTO;
import com.czg.order.dto.*;
import com.czg.order.entity.OrderDetail;
import com.czg.order.entity.OrderInfo;
import com.czg.order.entity.OrderPayment;
@@ -27,6 +26,8 @@ import com.czg.order.service.OrderInfoService;
import com.czg.order.service.OrderPaymentService;
import com.czg.order.vo.OrderDetailSmallVO;
import com.czg.order.vo.OrderInfoVo;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.czg.service.RedisService;
import com.czg.service.order.enums.OrderStatusEnums;
import com.czg.service.order.mapper.OrderInfoMapper;
@@ -123,6 +124,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
}
@Override
@Transactional
public OrderInfo createOrder(OrderInfoAddDTO param) {
ShopInfo shopInfo = shopInfoService.getById(param.getShopId());
AssertUtil.isNull(shopInfo, "生成订单失败,店铺信息不存在");
@@ -132,26 +134,98 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
if (!shopInfo.getEatModel().contains(param.getDineMode())) {
throw new ValidateException("生成订单失败,店铺不支持该用餐模式");
}
if ("afterPay".equals(param.getPayMode()) && !"restaurant".equals(shopInfo.getRegisterType())) {
throw new ValidateException("生成订单失败,该店铺不支持后付费");
}
if (param.isVipPrice() && !shopInfo.getIsMemberPrice().equals(1)) {
throw new ValidateException("生成订单失败,该店铺不支持使用会员价");
}
PointsBasicSetting pointSetting = pointsBasicService.getById(shopInfo.getId());
if (param.getPointsNum() > 0 && !pointSetting.getEnableDeduction().equals(1)) {
throw new ValidateException("生成订单失败,该店铺未开启积分抵扣");
}
UserInfo userInfo = userInfoService.getById(param.getUserId());
AssertUtil.isNull(userInfo, "生成订单失败,用户信息不存在");
ShopUser shopUser = shopUserService.getShopUserInfo(param.getShopId(), param.getUserId());
if (!shopUser.getIsVip().equals(1) && pointSetting.getDeductionGroup().contains("vip")) {
throw new ValidateException("生成订单失败,该店铺仅会员可使用积分抵扣");
}
ShopTable table = shopTableService.getOneByTableCode(param.getShopId(), param.getTableCode());
AssertUtil.isNull(table, "生成订单失败,桌台信息不存在");
if (table == null) {
param.setPayMode("no-table");
} else {
if ("before".equals(shopInfo.getRegisterType())) {
param.setPayMode("before-pay");
} else if ("after".equals(shopInfo.getRegisterType())) {
param.setPayMode("after-pay");
} else {
param.setPayMode("未知");
}
}
//获取商品信息 计算金额 需要传入优惠券 减去优惠券
List<OrderDetail> orderDetails = cartService.getCartByTableCode(param.getTableCode(), param.isVipPrice() ? 1 : 0, param.getPlaceNum());
//总打包费
BigDecimal packAmount = BigDecimal.ZERO;
//总商品支付金额 不包含打包费 用来计算后续
BigDecimal totalAmount = BigDecimal.ZERO;
processOrderDetails(orderDetails, packAmount, totalAmount);
if (packAmount.compareTo(param.getPackFee()) != 0) {
throw new ValidateException("生成订单失败,打包费不正确");
}
//总金额
if (totalAmount.add(param.getPackFee()).compareTo(param.getOriginAmount()) != 0) {
throw new ValidateException("生成订单失败,订单金额不正确");
}
//生成订单
OrderInfo orderInfo = initOrderInfo(param, shopInfo, table);
orderDetailService.createOrderDetails(orderInfo.getId(), orderDetails);
return orderInfo;
}
// @Override
// @Transactional
// public void updateOrder(OrderInfoUpDTO upDTO) {
// OrderInfo orderInfo = getById(upDTO.getOrderId());
// AssertUtil.isNull(orderInfo, "订单不存在");
// ShopInfo shopInfo = shopInfoService.getById(orderInfo.getShopId());
// AssertUtil.isNull(shopInfo, "店铺不存在");
// BigDecimal totalAmount = BigDecimal.ZERO;
// BigDecimal packAmount = BigDecimal.ZERO;
// List<Long> collect = upDTO.getDetailList().stream().map(OrderDetail::getId).toList();
// List<OrderDetail> orderDetails = detailService.queryChain().eq(OrderDetail::getOrderId, orderInfo.getId()).select().list();
// List<OrderDetail> updateList = new ArrayList<>();
// List<Long> removeList = new ArrayList<>();
// for (OrderDetail orderDetail : orderDetails) {
// if (!collect.contains(orderDetail.getId())) {
// removeList.add(orderDetail.getId());
// break;
// }
// OrderDetail detail = new OrderDetail();
// detail.setId(orderDetail.getId());
// detail.setNum(orderDetail.getNum());
// detail.setPackNumber(orderDetail.getPackNumber());
// detail.setIsWaitCall(orderDetail.getIsWaitCall());
// detail.setRemark(orderDetail.getRemark());
// detail.setPayAmount(orderDetail.getNum().multiply(detail.getPrice()));
// packAmount = packAmount.add(detail.getPackAmount().multiply(detail.getPackNumber()));
// totalAmount = totalAmount.add(detail.getPayAmount());
// }
// detailService.updateBatch(updateList);
// detailService.removeByIds(removeList);
// orderInfo.setPackFee(packAmount);
// orderInfo.setOriginAmount(totalAmount.add(orderInfo.getSeatAmount()));
//
// orderInfo.setSeatNum(upDTO.getSeatNum());
// orderInfo.setSeatAmount(shopInfo.getTableFee().multiply(new BigDecimal(upDTO.getSeatNum())));
// updateById(orderInfo);
// }
@Override
public BigDecimal checkOrderPay(CheckOrderPay param) {
OrderInfo orderInfo = getById(param.getOrderId());
Long shopId = StpKit.USER.getShopId();
PointsBasicSetting pointSetting = pointsBasicService.getById(shopId);
if (param.getPointsNum() > 0 && !pointSetting.getEnableDeduction().equals(1)) {
throw new ValidateException("生成支付订单失败,该店铺未开启积分抵扣");
}
UserInfo userInfo = userInfoService.getById(param.getUserId());
AssertUtil.isNull(userInfo, "生成支付订单失败,用户信息不存在");
ShopUser shopUser = shopUserService.getShopUserInfo(shopId, param.getUserId());
if (!shopUser.getIsVip().equals(1) && pointSetting.getDeductionGroup().contains("vip")) {
throw new ValidateException("生成支付订单失败,该店铺仅会员可使用积分抵扣");
}
if (param.getDiscountRatio().compareTo(BigDecimal.ZERO) <= 0 && param.getDiscountRatio().compareTo(BigDecimal.ONE) > 0) {
throw new ValidateException("生成订单失败,折扣比例不正确");
throw new ValidateException("生成支付订单失败,折扣比例不正确");
}
//商品券 <商品id数量>
Map<Long, Integer> prodCouponMap = new HashMap<>();
@@ -162,63 +236,166 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
checkCoupon(prodCouponMap, fullAmount, discountAmount, param);
//获取商品信息 计算金额 需要传入优惠券 减去优惠券
List<OrderDetail> orderDetails = cartService.getCartByTableCode(table.getTableCode(), param.isVipPrice() ? 1 : 0, param.getPlaceNum());
//总打包费
BigDecimal packAmount = BigDecimal.ZERO;
List<OrderDetail> orderDetails = orderDetailService.queryChain().eq(OrderDetail::getOrderId, param.getOrderId()).select().list();
//商品优惠券金额
BigDecimal prodCouponAmount = BigDecimal.ZERO;
//总商品支付金额 不包含打包费 用来计算后续
BigDecimal totalAmount = BigDecimal.ZERO;
processOrderDetails(orderDetails, prodCouponMap, prodCouponAmount, packAmount, totalAmount);
if (packAmount.compareTo(param.getPackFee()) != 0) {
throw new ValidateException("生成订单失败,打包费不正确");
}
processOrderDetails2(orderDetails, prodCouponMap, prodCouponAmount, totalAmount);
if (prodCouponAmount.compareTo(param.getProductCouponDiscountAmount()) != 0) {
throw new ValidateException("生成订单失败,商品优惠券优惠金额不正确");
throw new ValidateException("生成支付订单失败,商品优惠券优惠金额不正确");
}
//折扣金额 如 9折 计算 为 订单金额*0.9 向上取整
BigDecimal newTotalAmount = BigDecimal.ZERO;
if (param.getDiscountRatio().compareTo(BigDecimal.ONE) != 0) {
newTotalAmount = totalAmount.multiply(param.getDiscountRatio()).setScale(2, RoundingMode.UP);
if (param.getDiscountAmount().compareTo(totalAmount.subtract(newTotalAmount)) != 0) {
throw new ValidateException("生成订单失败,折扣金额不正确");
throw new ValidateException("生成支付订单失败,折扣金额不正确");
}
}
//满减券 校验
if (newTotalAmount.compareTo(fullAmount) < 0) {
throw new ValidateException("生成订单失败,满减券不满足条件");
throw new ValidateException("生成支付订单失败,满减券不满足条件");
}
//减去满减优惠券
newTotalAmount = newTotalAmount.subtract(discountAmount);
//积分抵扣 金额范围校验 抵扣金额校验
if (param.getPointsNum() > 0) {
if (pointSetting.getMinPaymentAmount().compareTo(newTotalAmount) > 0) {
throw new ValidateException("生成订单失败,未满足积分抵扣最低门槛");
throw new ValidateException("生成支付订单失败,未满足积分抵扣最低门槛");
}
if (pointSetting.getMaxDeductionRatio().multiply(newTotalAmount).compareTo(param.getPointsDiscountAmount()) < 0) {
throw new ValidateException("生成订单失败,积分抵扣金额已超出最大抵扣金额");
throw new ValidateException("生成支付订单失败,积分抵扣金额已超出最大抵扣金额");
}
BigDecimal pointAmount = new BigDecimal(param.getPointsNum()).divide(new BigDecimal(pointSetting.getEquivalentPoints()), 2, RoundingMode.DOWN);
if (pointAmount.compareTo(param.getPointsDiscountAmount()) != 0) {
throw new ValidateException("生成订单失败,积分抵扣金额不正确");
throw new ValidateException("生成支付订单失败,积分抵扣金额不正确");
}
}
newTotalAmount = newTotalAmount.subtract(param.getPointsDiscountAmount());
//抹零
newTotalAmount = newTotalAmount.subtract(param.getRoundAmount());
//校验最终金额(订单金额 (扣除各类折扣)+打包费 餐位费)
newTotalAmount = newTotalAmount.add(param.getPackFee()).add(new BigDecimal(param.getSeatNum()).multiply(shopInfo.getTableFee()));
newTotalAmount = newTotalAmount.add(orderInfo.getPackFee()).add(orderInfo.getSeatAmount());
if (newTotalAmount.compareTo(param.getOrderAmount()) != 0) {
throw new ValidateException("生成订单失败,订单金额不正确");
throw new ValidateException("生成支付订单失败,订单金额不正确");
}
//生成订单 //discount_info 所有折扣 几折 折扣金额 满减金额 优惠券金额 积分抵扣金额 抹零
OrderInfo orderInfo = initOrderInfo(param, shopInfo, table);
orderDetailService.createOrderDetails(orderInfo.getId(), orderDetails);
upOrderPayInfo(orderInfo, param);
//更新优惠券信息
orderDetailService.updateBatch(orderDetails);
//券消耗
couponService.use(param.getCouponList(), shopUser.getId(), orderInfo.getId());
return orderInfo;
return newTotalAmount;
}
@Override
@Transactional
public CzgResult<Object> refundOrder(OrderInfoRefundDTO param) {
OrderInfo orderInfo = getById(param.getOrderId());
//退款总额
BigDecimal refundAmountTotal = BigDecimal.ZERO;
boolean isPay = true;
if (orderInfo.getStatus().equals(OrderStatusEnums.UNPAID.getCode())) {
isPay = false;
}
if (CollUtil.isNotEmpty(param.getRefundDetails())) {
for (OrderDetail refundDetail : param.getRefundDetails()) {
AssertUtil.isNull(refundDetail.getNum(), "退单数量不能为空");
AssertUtil.isNull(refundDetail.getReturnAmount(), "退单金额不能为空");
//退款金额
BigDecimal refundAmount;
//退款数量
BigDecimal refNum;
OrderDetail orderDetail = detailService.getById(refundDetail.getId());
//可退数量=订单数量-退单数量-退菜数量
BigDecimal returnNum = orderDetail.getNum().subtract(orderDetail.getRefundNum()).subtract(orderDetail.getReturnNum());
if (returnNum.compareTo(BigDecimal.ZERO) <= 0 || returnNum.compareTo(refundDetail.getNum()) < 0) {
throw new ValidateException("退单失败,可退数量不足");
}
//可退数量 大于优惠券数量
if (returnNum.compareTo(orderDetail.getCouponNum()) > 0) {
//实际计算金额的数量
refNum = returnNum.subtract(orderDetail.getCouponNum());
if (refundDetail.getNum().compareTo(refNum) > 0) {
refundAmount = (refNum).multiply(orderDetail.getPrice());
refNum = refundDetail.getNum();
} else {
refNum = refundDetail.getNum();
refundAmount = refundDetail.getNum().multiply(orderDetail.getPrice());
if (param.isModify()) {
refundAmount = refundDetail.getReturnAmount();
} else {
if (refundAmount.compareTo(refundDetail.getReturnAmount()) != 0) {
throw new ValidateException("退单失败," + refundDetail.getProductName() + "退单金额不正确");
}
}
}
} else {
if (param.isModify()) {
refundAmount = refundDetail.getReturnAmount();
refNum = refundDetail.getNum();
} else {
refNum = refundDetail.getNum();
refundAmount = BigDecimal.ZERO;
if (refundAmount.compareTo(refundDetail.getReturnAmount()) != 0) {
throw new ValidateException("退单失败," + refundDetail.getProductName() + "退单金额不正确");
}
}
}
refundAmountTotal = refundAmountTotal.add(refundAmount);
if (refundDetail.getReturnAmount().compareTo(refundDetail.getNum().multiply(orderDetail.getPrice())) != 0) {
throw new ValidateException("退单失败," + refundDetail.getProductName() + "退单金额不正确");
}
if (isPay) {
orderDetail.setRefundNum(orderDetail.getRefundNum().add(refNum));
orderDetail.setReturnAmount(orderDetail.getReturnAmount().add(refundDetail.getReturnAmount()));
if (orderDetail.getReturnAmount().compareTo(orderDetail.getPayAmount()) > 0) {
throw new ValidateException("退单失败," + refundDetail.getProductName() + "退单金额不正确");
}
} else {
orderDetail.setReturnNum(orderDetail.getRefundNum().add(refNum));
}
refundDetail.setRefundRemark(refundDetail.getRefundRemark() + param.getRefundReason());
orderDetail.setPayAmount((orderDetail.getNum().subtract(orderDetail.getRefundNum()).subtract(orderDetail.getReturnNum())
.subtract(orderDetail.getCouponNum())).multiply(orderDetail.getPrice()));
}
} else {
refundAmountTotal = param.getRefundAmount();
}
if (param.isModify()) {
orderInfo.setOrderAmount(orderInfo.getOrderAmount().subtract(param.getRefundAmount()));
if (orderInfo.getOrderAmount().compareTo(BigDecimal.ZERO) < 0) {
throw new ValidateException("退单失败,订单金额不正确");
}
}
if (isPay) {
orderInfo.setRefundAmount(orderInfo.getRefundAmount().add(refundAmountTotal));
orderInfo.setRefundRemark(orderInfo.getRefundRemark() + param.getRefundReason());
//退钱 refundAmountTotal
} else {
}
return null;
}
/**
* 填充 优惠券使用数量 以及 付款金额
*
* @param orderDetails 订单详情 需要回填
* @param packAmount 打包费
* @param totalAmount 最终总金额
*/
private void processOrderDetails(List<OrderDetail> orderDetails, BigDecimal packAmount, BigDecimal totalAmount) {
for (OrderDetail detail : orderDetails) {
if (detail.getPackNumber().compareTo(BigDecimal.ZERO) > 0 && detail.getPackAmount().compareTo(BigDecimal.ZERO) > 0) {
packAmount = packAmount.add(detail.getPackAmount().multiply(detail.getPackNumber()));
}
detail.setPayAmount(detail.getNum().multiply(detail.getPrice()));
totalAmount = totalAmount.add(detail.getPayAmount());
}
}
/**
* 填充 优惠券使用数量 以及 付款金额
@@ -226,17 +403,13 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
* @param orderDetails 订单详情 需要回填 优惠券抵扣数量
* @param prodCouponMap 使用优惠券<商品id,数量>
* @param prodCouponAmount 商品券优惠金额 商品单价*优惠数量 的总和
* @param packAmount 打包费
* @param totalAmount 最终总金额(没加打包费 餐位费) 去除优惠券金额后的
*/
private void processOrderDetails(List<OrderDetail> orderDetails, Map<Long, Integer> prodCouponMap,
BigDecimal prodCouponAmount, BigDecimal packAmount, BigDecimal totalAmount) {
private void processOrderDetails2(List<OrderDetail> orderDetails, Map<Long, Integer> prodCouponMap,
BigDecimal prodCouponAmount, BigDecimal totalAmount) {
Map<Long, List<OrderDetail>> detailMap = new HashMap<>();
for (OrderDetail detail : orderDetails) {
detailMap.computeIfAbsent(detail.getProductId(), k -> new ArrayList<>()).add(detail);
if (detail.getPackNumber().compareTo(BigDecimal.ZERO) > 0 && detail.getPackAmount().compareTo(BigDecimal.ZERO) > 0) {
packAmount = packAmount.add(detail.getPackAmount().multiply(detail.getPackNumber()));
}
}
List<OrderDetail> resultList = new ArrayList<>();
for (Map.Entry<Long, List<OrderDetail>> entry : detailMap.entrySet()) {
@@ -269,31 +442,32 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
resultList.add(orderDetail);
}
if (couponNum.compareTo(BigDecimal.ZERO) != 0) {
throw new ValidateException("生成订单失败,优惠券数量不正确");
throw new ValidateException("生成支付订单失败,优惠券数量不正确");
}
}
orderDetails = resultList;
}
/**
* 校验优惠券可用性 回填优惠券信息
* 校验优惠券可用性
*/
private void checkCoupon(Map<Long, Integer> prodCouponMap, BigDecimal fullAmount, BigDecimal discountAmount, OrderInfoAddDTO param) {
private void checkCoupon(Map<Long, Integer> prodCouponMap, BigDecimal fullAmount, BigDecimal discountAmount, CheckOrderPay param) {
if (CollUtil.isNotEmpty(param.getCouponList())) {
//校验优惠券
List<ShopActivateCouponRecord> records = couponRecordService.list(QueryWrapper.create()
.where(ShopActivateCouponRecord::getId).in(param.getCouponList())
.and(ShopActivateCouponRecord::getStatus).eq(0));
if (CollUtil.isEmpty(records)) {
throw new ValidateException("生成订单失败,优惠券信息不存在");
throw new ValidateException("生成支付订单失败,优惠券信息不存在");
} else if (records.size() != param.getCouponList().size()) {
throw new ValidateException("生成订单失败,优惠券信息不正确");
throw new ValidateException("生成支付订单失败,优惠券信息不正确");
}
boolean isFullMinus = false;
for (ShopActivateCouponRecord record : records) {
if (record.getType().equals(1)) {
if (isFullMinus) {
throw new ValidateException("生成订单失败,满减券仅可使用一张");
throw new ValidateException("生成支付订单失败,满减券仅可使用一张");
}
fullAmount = record.getFullAmount();
discountAmount = record.getDiscountAmount();
@@ -304,7 +478,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
}
}
if (discountAmount.compareTo(param.getFullCouponDiscountAmount()) != 0) {
throw new ValidateException("生成订单失败,满减券减免金额不正确");
throw new ValidateException("生成支付订单失败,满减券减免金额不正确");
}
}
@@ -405,12 +579,14 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
rabbitPublisher.sendOrderPrintMsg(orderId.toString());
}
/**
* 初始化订单信息
*/
private OrderInfo initOrderInfo(OrderInfoAddDTO param, ShopInfo shopInfo, ShopTable table) {
OrderInfo orderInfo = new OrderInfo();
if (param.getOrderId() != null) {
orderInfo = getById(param.getOrderId());
if (!"unpaid".equals(orderInfo.getStatus())) {
if (!OrderStatusEnums.UNPAID.getCode().equals(orderInfo.getStatus())) {
throw new ValidateException("生成订单失败,订单已结束,请重新下单");
}
} else {
@@ -420,7 +596,6 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
orderInfo.setTableCode(table.getTableCode());
orderInfo.setTableName(table.getName());
orderInfo.setDineMode(param.getDineMode());
orderInfo.setSeatNum(param.getSeatNum());
orderInfo.setRefundAmount(BigDecimal.ZERO);
orderInfo.setPayAmount(BigDecimal.ZERO);
@@ -428,7 +603,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
orderInfo.setPlatformType(param.getPlatformType());
orderInfo.setDineMode(param.getDineMode());
orderInfo.setPayMode(param.getPayMode());
orderInfo.setStatus("unpaid");
orderInfo.setStatus(OrderStatusEnums.UNPAID.getCode());
orderInfo.setRefundAble(0);
orderInfo.setTradeDay(DateUtil.formatDate(new Date()));
orderInfo.setRemark(param.getRemark());
@@ -438,40 +613,44 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
orderInfo.setIsDel(0);
//取餐码 多端一致
orderInfo.setTakeCode(getCode(shopInfo.getId()));
}
// 餐位费
if (shopInfo.getIsTableFee().equals(1)) {
orderInfo.setSeatAmount(shopInfo.getTableFee().multiply(new BigDecimal(param.getSeatNum())));
orderInfo.setSeatNum(param.getSeatNum());
}
orderInfo.setPlaceNum(param.getPlaceNum());
orderInfo.setPointsNum(orderInfo.getPointsNum() + param.getPointsNum());
orderInfo.setOriginAmount(orderInfo.getOriginAmount().add(param.getOriginAmount()));
orderInfo.setRoundAmount(orderInfo.getRoundAmount().add(param.getRoundAmount()));
orderInfo.setOrderAmount(orderInfo.getOrderAmount().add(param.getOrderAmount()));
orderInfo.setPointsDiscountAmount(orderInfo.getPointsDiscountAmount().add(param.getPointsDiscountAmount()));
orderInfo.setProductCouponDiscountAmount(orderInfo.getProductCouponDiscountAmount().add(param.getProductCouponDiscountAmount()));
orderInfo.setFullCouponDiscountAmount(orderInfo.getFullCouponDiscountAmount().add(param.getFullCouponDiscountAmount()));
orderInfo.setDiscountAmount(orderInfo.getDiscountAmount().add(param.getDiscountAmount()));
orderInfo.setOriginAmount(orderInfo.getOriginAmount().add(param.getOriginAmount()).add(orderInfo.getSeatAmount()));
orderInfo.setPackFee(orderInfo.getPackFee().add(param.getPackFee()));
orderInfo.setDiscountRatio(orderInfo.getDiscountRatio() + param.getDiscountRatio());
//优惠券
orderInfo.setCouponInfoList(orderInfo.getCouponInfoList() + "," + JSONObject.toJSONString(param.getCouponList()));
//折扣信息
orderInfo.setDiscountInfo(buildDiscountInfo(orderInfo));
orderInfo.setRoundAmount(BigDecimal.ZERO);
orderInfo.setPointsNum(0);
saveOrUpdate(orderInfo);
return orderInfo;
}
private String getCode(Long shopId) {
String key = RedisCst.SHOP_CODE + DateUtil.today() + ":" + shopId;
int count = 1;
if (redisService.hasKey(key)) {
count = Integer.parseInt(redisService.get(key).toString());
count++;
}
// 设置缓存并设置过期时间
redisService.set(key, count, 24 * 60 * 60);
return "#" + count;
/**
* 更新订单 优惠信息
*/
private void upOrderPayInfo(OrderInfo orderInfo, CheckOrderPay param) {
orderInfo.setPointsNum(param.getPointsNum());
orderInfo.setOriginAmount(param.getOriginAmount());
orderInfo.setRoundAmount(param.getRoundAmount());
orderInfo.setOrderAmount(param.getOrderAmount());
orderInfo.setPointsDiscountAmount(param.getPointsDiscountAmount());
orderInfo.setProductCouponDiscountAmount(param.getProductCouponDiscountAmount());
orderInfo.setFullCouponDiscountAmount(param.getFullCouponDiscountAmount());
orderInfo.setDiscountAmount(param.getDiscountAmount());
orderInfo.setDiscountRatio(param.getDiscountRatio());
//优惠券
orderInfo.setCouponInfoList(JSONObject.toJSONString(param.getCouponList()));
//折扣信息
orderInfo.setDiscountInfo(buildDiscountInfo(orderInfo));
saveOrUpdate(orderInfo);
}
/**
* 构建优惠内容
*/
private String buildDiscountInfo(OrderInfo orderInfo) {
JSONObject jsonObject = new JSONObject();
if (orderInfo.getProductCouponDiscountAmount().compareTo(BigDecimal.ZERO) > 0) {
@@ -491,4 +670,19 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
}
return jsonObject.toString();
}
/**
* 生成取餐码
*/
private String getCode(Long shopId) {
String key = RedisCst.SHOP_CODE + DateUtil.today() + ":" + shopId;
int count = 1;
if (redisService.hasKey(key)) {
count = Integer.parseInt(redisService.get(key).toString());
count++;
}
// 设置缓存并设置过期时间
redisService.set(key, count, 24 * 60 * 60);
return "#" + count;
}
}

View File

@@ -23,6 +23,7 @@ import com.czg.service.RedisService;
import com.czg.service.order.dto.OrderPayParamDTO;
import com.czg.service.order.dto.VipPayParamDTO;
import com.czg.service.order.dto.VipRefundDTO;
import com.czg.service.order.enums.OrderStatusEnums;
import com.czg.service.order.service.PayService;
import com.czg.system.enums.SysParamCodeEnum;
import com.czg.system.service.SysParamsService;
@@ -83,10 +84,10 @@ public class PayServiceImpl implements PayService {
private OrderInfo checkPay(Long orderId) {
OrderInfo orderInfo = orderInfoService.getById(orderId);
AssertUtil.isNull(orderInfo, "订单不存在");
if (!"unpaid".equals(orderInfo.getStatus())) {
if (!OrderStatusEnums.UNPAID.getCode().equals(orderInfo.getStatus())) {
throw new ValidateException("该订单已不可支付");
}
if (!"afterPay".equals(orderInfo.getPayMode())
if (!"after-pay".equals(orderInfo.getPayMode())
&& orderInfo.getCreateTime().isAfter(LocalDateTimeUtil.offset(LocalDateTime.now(), -15, ChronoUnit.SECONDS))) {
throw new ValidateException("订单十五分钟内有效,当前已超时,请重新下单。");
}

View File

@@ -22,7 +22,6 @@
skus.spec_info as skuName,
'wait-pay' as status,
#{placeNum} as placeNum,
#{dineMode} as dineMode,
case cart.is_temporary
when 1 then cart.product_name
else pros.name