1.代客下单,折扣
This commit is contained in:
parent
417451f432
commit
297ccc0233
|
|
@ -2,6 +2,8 @@ package cn.ysk.cashier.dto.shoptable;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.Max;
|
||||||
|
import javax.validation.constraints.Min;
|
||||||
import javax.validation.constraints.NotEmpty;
|
import javax.validation.constraints.NotEmpty;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
|
@ -13,4 +15,7 @@ public class PayDTO {
|
||||||
private Integer orderId;
|
private Integer orderId;
|
||||||
@NotEmpty
|
@NotEmpty
|
||||||
private String payType;
|
private String payType;
|
||||||
|
@Min(0)
|
||||||
|
@Max(1)
|
||||||
|
private Double discount;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,13 @@ import cn.ysk.cashier.dto.ScanPayDTO;
|
||||||
import cn.ysk.cashier.dto.shoptable.PayDTO;
|
import cn.ysk.cashier.dto.shoptable.PayDTO;
|
||||||
import cn.ysk.cashier.pojo.order.TbOrderInfo;
|
import cn.ysk.cashier.pojo.order.TbOrderInfo;
|
||||||
|
|
||||||
|
import javax.validation.constraints.Min;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
public interface TbPayService {
|
public interface TbPayService {
|
||||||
void scanPay(ScanPayDTO scanPayDTO);
|
void scanPay(ScanPayDTO scanPayDTO);
|
||||||
|
|
||||||
TbOrderInfo vipPay(@NotNull Integer shopId, @NotNull Integer orderId);
|
TbOrderInfo vipPay(@NotNull Integer shopId, @NotNull Integer orderId, Double discount);
|
||||||
|
|
||||||
TbOrderInfo cashPay(PayDTO payDTO);
|
TbOrderInfo cashPay(PayDTO payDTO);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,13 +21,15 @@ import cn.ysk.cashier.repository.shop.TbMerchantThirdApplyRepository;
|
||||||
import cn.ysk.cashier.service.TbPayService;
|
import cn.ysk.cashier.service.TbPayService;
|
||||||
import cn.ysk.cashier.utils.RabbitMsgUtils;
|
import cn.ysk.cashier.utils.RabbitMsgUtils;
|
||||||
import cn.ysk.cashier.utils.SnowFlakeUtil;
|
import cn.ysk.cashier.utils.SnowFlakeUtil;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.validation.constraints.Min;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
|
@ -297,7 +299,7 @@ public class TbPayServiceImpl implements TbPayService {
|
||||||
private final TbShopUserFlowMapper shopUserFlowMapper;
|
private final TbShopUserFlowMapper shopUserFlowMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbOrderInfo vipPay(@NotNull Integer shopId, @NotNull Integer orderId) {
|
public TbOrderInfo vipPay(@NotNull Integer shopId, @NotNull Integer orderId, Double discount) {
|
||||||
|
|
||||||
TbOrderInfo orderInfo = orderInfoMapper.selectById(orderId);
|
TbOrderInfo orderInfo = orderInfoMapper.selectById(orderId);
|
||||||
|
|
||||||
|
|
@ -334,7 +336,12 @@ public class TbPayServiceImpl implements TbPayService {
|
||||||
userFlow.setType("-");
|
userFlow.setType("-");
|
||||||
shopUserFlowMapper.insert(userFlow);
|
shopUserFlowMapper.insert(userFlow);
|
||||||
|
|
||||||
orderInfo.setPayAmount(orderInfo.getOrderAmount());
|
orderInfo.setPayAmount(discount == null ? orderInfo.getOrderAmount() : orderInfo.getOrderAmount().multiply(BigDecimal.valueOf(discount)).setScale(2, RoundingMode.UP));
|
||||||
|
if (discount != null && discount != 1) {
|
||||||
|
orderInfo.setDiscountAmount(orderInfo.getOrderAmount().subtract(orderInfo.getPayAmount()));
|
||||||
|
orderInfo.setDiscountRatio(BigDecimal.valueOf(discount));
|
||||||
|
}
|
||||||
|
|
||||||
orderInfo.setPayType("cash");
|
orderInfo.setPayType("cash");
|
||||||
orderInfo.setStatus("closed");
|
orderInfo.setStatus("closed");
|
||||||
orderInfo.setPayOrderNo("cash".concat(SnowFlakeUtil.generateOrderNo()));
|
orderInfo.setPayOrderNo("cash".concat(SnowFlakeUtil.generateOrderNo()));
|
||||||
|
|
@ -373,7 +380,12 @@ public class TbPayServiceImpl implements TbPayService {
|
||||||
// return Result.fail(CodeEnum.PAYTYPENOEXIST);
|
// return Result.fail(CodeEnum.PAYTYPENOEXIST);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
orderInfo.setPayAmount(orderInfo.getOrderAmount());
|
orderInfo.setPayAmount(payDTO.getDiscount() == null ? orderInfo.getOrderAmount() : orderInfo.getOrderAmount()
|
||||||
|
.multiply(BigDecimal.valueOf(payDTO.getDiscount())).setScale(2, RoundingMode.UP));
|
||||||
|
if (payDTO.getDiscount() != null && payDTO.getDiscount() != 1) {
|
||||||
|
orderInfo.setDiscountAmount(orderInfo.getOrderAmount().subtract(orderInfo.getPayAmount()));
|
||||||
|
orderInfo.setDiscountRatio(BigDecimal.valueOf(payDTO.getDiscount()));
|
||||||
|
}
|
||||||
orderInfo.setPayType("cash");
|
orderInfo.setPayType("cash");
|
||||||
orderInfo.setStatus("closed");
|
orderInfo.setStatus("closed");
|
||||||
orderInfo.setPayOrderNo("cash".concat(SnowFlakeUtil.generateOrderNo()));
|
orderInfo.setPayOrderNo("cash".concat(SnowFlakeUtil.generateOrderNo()));
|
||||||
|
|
|
||||||
|
|
@ -1083,7 +1083,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||||
TbOrderInfo orderInfo = null;
|
TbOrderInfo orderInfo = null;
|
||||||
switch (payDTO.getPayType()) {
|
switch (payDTO.getPayType()) {
|
||||||
case "vipPay":
|
case "vipPay":
|
||||||
orderInfo = tbPayServiceImpl.vipPay(payDTO.getShopId(), payDTO.getOrderId());
|
orderInfo = tbPayServiceImpl.vipPay(payDTO.getShopId(), payDTO.getOrderId(), payDTO.getDiscount());
|
||||||
break;
|
break;
|
||||||
case "cash":
|
case "cash":
|
||||||
orderInfo = tbPayServiceImpl.cashPay(payDTO);
|
orderInfo = tbPayServiceImpl.cashPay(payDTO);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue