Merge branch 'refs/heads/test' into dev

This commit is contained in:
张松 2024-12-24 13:39:08 +08:00
commit 2528ce8317
11 changed files with 273 additions and 47 deletions

View File

@ -15,6 +15,7 @@ import com.chaozhanggui.system.cashierservice.dao.TbShopInfoMapper;
import com.chaozhanggui.system.cashierservice.entity.TbOrderDetail;
import com.chaozhanggui.system.cashierservice.entity.TbOrderInfo;
import com.chaozhanggui.system.cashierservice.entity.TbShopInfo;
import com.chaozhanggui.system.cashierservice.entity.dto.CreditDTO;
import com.chaozhanggui.system.cashierservice.entity.dto.ReturnGroupOrderDto;
import com.chaozhanggui.system.cashierservice.entity.dto.ReturnOrderDTO;
import com.chaozhanggui.system.cashierservice.entity.dto.VipPayDTO;
@ -25,6 +26,7 @@ import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
import com.chaozhanggui.system.cashierservice.sign.Result;
import com.chaozhanggui.system.cashierservice.util.IpUtil;
import com.chaozhanggui.system.cashierservice.util.JSONUtil;
import com.chaozhanggui.system.cashierservice.util.Utils;
import com.chaozhanggui.system.cashierservice.util.WechatUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.extern.slf4j.Slf4j;
@ -214,12 +216,20 @@ public class PayController {
}
if ((vipPayDTO.getPayAmount() != null && vipPayDTO.getPayAmount().compareTo(BigDecimal.ZERO) <= 0) ||
(vipPayDTO.getDiscountAmount() != null && vipPayDTO.getDiscountAmount().compareTo(BigDecimal.ZERO) <= 0)) {
(vipPayDTO.getDiscountAmount() != null && vipPayDTO.getDiscountAmount().compareTo(BigDecimal.ZERO) <= 0)) {
return Result.fail("折扣金额必须大于0");
}
return payService.vipPay(vipPayDTO.getOrderId(), token, vipPayDTO.getVipUserId(), vipPayDTO.getPayAmount(), vipPayDTO.getDiscountAmount());
}
/**
* 挂账支付
*/
@PostMapping("creditPay")
public Result creditPay(@RequestHeader("token") String token, @RequestBody CreditDTO creditDTO) {
return payService.creditPay(creditDTO, token);
}
/**
* 银行卡支付
*
@ -315,11 +325,11 @@ public class PayController {
@GetMapping("/noToken/queryOrderInfo")
public Result noTokenQueryOrderInfo(String orderId) {
if(StrUtil.isBlank(orderId)){
if (StrUtil.isBlank(orderId)) {
return Result.fail("订单id不能为空");
}
TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPrimaryKey(Integer.valueOf(orderId));
if(orderInfo == null){
if (orderInfo == null) {
return Result.fail("订单不存在");
}
Map<String, Object> data = new HashMap<>(4);

View File

@ -89,6 +89,7 @@ public class TbCashierCart implements Serializable {
private String proGroupInfo;
private String typeEnum;
private Integer groupType;
private int isWeight;
public void copy(TbCashierCart source) {
BeanUtil.copyProperties(source, this, CopyOptions.create().setIgnoreNullValue(true));

View File

@ -2,6 +2,7 @@ package com.chaozhanggui.system.cashierservice.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;
import org.springframework.data.annotation.Transient;
import java.io.Serializable;
import java.math.BigDecimal;
@ -59,9 +60,12 @@ public class TbOrderDetail implements Serializable {
private BigDecimal canReturnAmount;
private BigDecimal returnAmount;
private Integer isPrint;
@Transient
@TableField(exist = false)
private Integer isGift;
private BigDecimal discountSaleAmount;
private String discountSaleNote;
private String proGroupInfo;
private int isWeight;
}

View File

@ -122,6 +122,7 @@ public class TbOrderInfo implements Serializable {
private BigDecimal pointsDiscountAmount;
private String refundRemark;
private Integer pointsNum;
private String creditBuyerId;
public TbOrderInfo(){
super();

View File

@ -0,0 +1,22 @@
package com.chaozhanggui.system.cashierservice.entity.dto;
import lombok.Data;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
@Data
public class CreditDTO {
@NotNull
private Integer orderId;
@NotEmpty
private String creditBuyerId;
@DecimalMin("0.00")
private BigDecimal payAmount;
@DecimalMin("0.00")
private BigDecimal discountAmount;
}

View File

@ -1,19 +1,20 @@
package com.chaozhanggui.system.cashierservice.rabbit;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.chaozhanggui.system.cashierservice.dao.TbOrderDetailMapper;
import com.chaozhanggui.system.cashierservice.dao.TbOrderInfoMapper;
import com.chaozhanggui.system.cashierservice.dao.TbShopInfoMapper;
import com.chaozhanggui.system.cashierservice.entity.TbOrderDetail;
import com.chaozhanggui.system.cashierservice.entity.TbOrderInfo;
import com.chaozhanggui.system.cashierservice.entity.TbPrintMachine;
import com.chaozhanggui.system.cashierservice.entity.TbShopInfo;
import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.entity.dto.CallNumPrintDTO;
import com.chaozhanggui.system.cashierservice.mybatis.MPCashierCartMapper;
import com.chaozhanggui.system.cashierservice.mybatis.MPOrderDetailMapper;
import com.chaozhanggui.system.cashierservice.mybatis.MpPrintMachineMapper;
import com.chaozhanggui.system.cashierservice.rabbit.print.PrinterHandler;
import com.chaozhanggui.system.cashierservice.util.Utils;
@ -24,6 +25,8 @@ import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Slf4j
@Component
@ -31,14 +34,18 @@ public class PrintConsumer {
private final TbOrderInfoMapper tbOrderInfoMapper;
private final TbShopInfoMapper tbShopInfoMapper;
private final TbOrderDetailMapper tbOrderDetailMapper;
private final MPOrderDetailMapper mpOrderDetailMapper;
private final MPCashierCartMapper mpCashierCartMapper;
private final MpPrintMachineMapper mpPrintMachineMapper;
private final PrinterHandler printerHandler;
public PrintConsumer(TbOrderInfoMapper tbOrderInfoMapper, TbShopInfoMapper tbShopInfoMapper, TbOrderDetailMapper tbOrderDetailMapper, MpPrintMachineMapper mpPrintMachineMapper, PrinterHandler printerHandler) {
public PrintConsumer(TbOrderInfoMapper tbOrderInfoMapper, TbShopInfoMapper tbShopInfoMapper, TbOrderDetailMapper tbOrderDetailMapper, MPOrderDetailMapper mpOrderDetailMapper, MPCashierCartMapper mpCashierCartMapper, MpPrintMachineMapper mpPrintMachineMapper, PrinterHandler printerHandler) {
this.tbOrderInfoMapper = tbOrderInfoMapper;
this.tbShopInfoMapper = tbShopInfoMapper;
this.tbOrderDetailMapper = tbOrderDetailMapper;
this.mpOrderDetailMapper = mpOrderDetailMapper;
this.mpCashierCartMapper = mpCashierCartMapper;
this.mpPrintMachineMapper = mpPrintMachineMapper;
this.printerHandler = printerHandler;
}
@ -65,10 +72,27 @@ public class PrintConsumer {
for (Object orderDetail : orderDetailIds) {
orderDetails.add(JSONObject.parseObject(orderDetail.toString(), TbOrderDetail.class));
}
if (CollUtil.isEmpty(orderDetails)) {
return;
}
List<Integer> ids = orderDetails.stream().map(TbOrderDetail::getId).collect(Collectors.toList());
List<TbOrderDetail> detailList = mpOrderDetailMapper.selectList(Wrappers.<TbOrderDetail>lambdaQuery().in(TbOrderDetail::getId, ids));
if (CollUtil.isEmpty(detailList)) {
return;
}
Map<Integer, Integer> isPrintMap = detailList.stream().collect(Collectors.toMap(TbOrderDetail::getId, TbOrderDetail::getIsPrint));
for (TbOrderDetail detail : orderDetails) {
detail.setIsPrint(isPrintMap.get(detail.getId()));
}
List<TbCashierCart> cartList = mpCashierCartMapper.selectList(Wrappers.<TbCashierCart>lambdaQuery().eq(TbCashierCart::getOrderId, orderInfo.getId()));
Map<Integer, String> map = cartList.stream().collect(Collectors.toMap(TbCashierCart::getId, TbCashierCart::getIsGift));
orderDetails.parallelStream().forEach(item->{
int isGift = "true".equals(map.get(item.getCartId())) ? 1 : 0;
item.setIsGift(isGift);
});
if (orderDetails.isEmpty()) {
return;
}
// 菜品票
getPrintMachine(Integer.valueOf(orderInfo.getShopId()), "cash", "one", null).forEach(machine -> {
log.info("打印机信息: {}", machine);
@ -109,6 +133,13 @@ public class PrintConsumer {
getPrintMachine(shopInfo.getId(), "cash", "normal", null).forEach(machine -> {
List<TbOrderDetail> tbOrderDetails = tbOrderDetailMapper.selectAllByOrderId(orderInfo.getId());
tbOrderDetails = tbOrderDetails.stream().filter(item -> !"return".equals(item.getStatus())).collect(Collectors.toList());
List<TbCashierCart> cartList = mpCashierCartMapper.selectList(Wrappers.<TbCashierCart>lambdaQuery().eq(TbCashierCart::getOrderId, orderInfo.getId()));
Map<Integer, String> map = cartList.stream().collect(Collectors.toMap(TbCashierCart::getId, TbCashierCart::getIsGift));
tbOrderDetails.parallelStream().forEach(item->{
int isGift = "true".equals(map.get(item.getCartId())) ? 1 : 0;
item.setIsGift(isGift);
});
printerHandler.handleRequest(machine, isReturn, orderInfo, tbOrderDetails, null);
// printPlaceTicket(isReturn, machine, orderInfo, shopInfo);
});

View File

@ -243,6 +243,9 @@ public class PrintMechineConsumer {
if (it.getIsMember() == 1) {
unitPrice = it.getMemberPrice();
}
if (it.getIsGift() == 1) {
unitPrice = BigDecimal.ZERO;
}
BigDecimal subTotal = NumberUtil.mul(it.getNum(), unitPrice.subtract(NumberUtil.null2Zero(it.getDiscountSaleAmount())));
OrderDetailPO.Detail detail = new OrderDetailPO.Detail(it.getProductName(), it.getNum().toString(), subTotal.toPlainString(), remark, it.getProGroupInfo());
detailList.add(detail);
@ -324,6 +327,10 @@ public class PrintMechineConsumer {
c.getId().toString().equals(categoryId)
).count();
}
Integer isGift = ObjectUtil.defaultIfNull(it.getIsGift(), 0);
if (isGift == 1) {
it.setProductName("【赠】" + it.getProductName());
}
log.info("获取当前类别是否未打印类别:{}", count);
if (count > 0) {
// 统计已打数量
@ -545,6 +552,10 @@ public class PrintMechineConsumer {
c.getId().toString().equals(categoryId)
).count();
}
Integer isGift = ObjectUtil.defaultIfNull(it.getIsGift(), 0);
if (isGift == 1) {
it.setProductName("【赠】" + it.getProductName());
}
String classifyPrint = tbPrintMachineWithBLOBs.getClassifyPrint();
// 如果是部分打印并且所属分类不在设置的列表中则不打印
if ("1".equals(classifyPrint) && count == 0) {
@ -603,6 +614,9 @@ public class PrintMechineConsumer {
if (it.getIsMember() == 1) {
unitPrice = it.getMemberPrice();
}
if (it.getIsGift() == 1) {
unitPrice = BigDecimal.ZERO;
}
BigDecimal subTotal = NumberUtil.mul(it.getNum(), unitPrice.subtract(NumberUtil.null2Zero(it.getDiscountSaleAmount())));
OrderDetailPO.Detail detail = new OrderDetailPO.Detail(it.getProductName(), it.getNum().toString(), subTotal.toPlainString(), remark, it.getProGroupInfo());
detailList.add(detail);
@ -671,6 +685,9 @@ public class PrintMechineConsumer {
if (it.getIsMember() == 1) {
unitPrice = it.getMemberPrice();
}
if ("true".equals(it.getIsGift())) {
unitPrice = BigDecimal.ZERO;
}
BigDecimal subTotal = NumberUtil.mul(it.getNumber(), unitPrice.subtract(NumberUtil.null2Zero(it.getDiscountSaleAmount())));
OrderDetailPO.Detail detail = new OrderDetailPO.Detail(it.getName(), it.getNumber().toString(), subTotal.toPlainString(), remark, it.getProGroupInfo());
detailList.add(detail);

View File

@ -88,7 +88,7 @@ public abstract class PrinterHandler {
log.info("开始打印退单菜品,商品名:{}", item.getProductName());
Integer isWaitCall = ObjectUtil.defaultIfNull(item.getIsWaitCall(), 0);
if (isWaitCall == 1) {
if (!item.getProductName().startsWith("【等叫】")) {
if (!item.getProductName().contains("【等叫】")) {
item.setProductName("【等叫】" + item.getProductName());
}
}
@ -97,10 +97,14 @@ public abstract class PrinterHandler {
if (isTemporary == 1) {
item.setProductId(0);
item.setProductSkuId(0);
if (!item.getProductName().startsWith("【临】")) {
if (!item.getProductName().contains("【临】")) {
item.setProductName("【临】" + item.getProductName());
}
}
Integer isGift = ObjectUtil.defaultIfNull(item.getIsGift(), 0);
if (isGift == 1 && !item.getProductName().contains("【赠】")) {
item.setProductName("【赠】" + item.getProductName());
}
// 台位费不打印
if (item.getProductId().equals(-999)) {
log.info("台位费商品,不打印");
@ -131,9 +135,9 @@ public abstract class PrinterHandler {
}
String classifyPrint = machine.getClassifyPrint();
// 如果是部分打印并且所属分类不在设置的列表中则不打印
if("1".equals(classifyPrint) && count == 0) {
if ("1".equals(classifyPrint) && count == 0) {
}else{
} else {
String remark = StrUtil.isNotBlank(sku.getSpecSnap()) ? sku.getSpecSnap() : "";
item.setRemark(remark);
if (isReturn) {
@ -170,10 +174,17 @@ public abstract class PrinterHandler {
if (isTemporary == 1) {
it.setProductName("【临】" + it.getProductName());
}
Integer isGift = ObjectUtil.defaultIfNull(it.getIsGift(), 0);
if (isGift == 1) {
it.setProductName("【赠】" + it.getProductName());
}
BigDecimal unitPrice = it.getPrice();
if(it.getIsMember() == 1){
if (it.getIsMember() == 1) {
unitPrice = it.getMemberPrice();
}
if (it.getIsGift() == 1) {
unitPrice = BigDecimal.ZERO;
}
BigDecimal subTotal = NumberUtil.mul(it.getNum(), unitPrice.subtract(NumberUtil.null2Zero(it.getDiscountSaleAmount())));
OrderDetailPO.Detail detail = new OrderDetailPO.Detail(it.getProductName(), it.getNum().toString(), subTotal.toPlainString(), remark, it.getProGroupInfo());
detailList.add(detail);
@ -227,4 +238,17 @@ public abstract class PrinterHandler {
Utils.checkValueUnReturn(printerBrand, "打印机品牌未赋值");
return printerBrand.equals(currentBrand) && "network".equals(connectType);
}
public static void main(String[] args) {
String a = "1【赠1】1【临1】1【等叫1】1";
if (!a.contains("【赠】")) {
System.out.println("不包含");
}
if (a.indexOf("【临】") != -1) {
System.out.println("包含");
}
if (a.indexOf("【等叫】") != -1) {
System.out.println("包含");
}
}
}

View File

@ -281,6 +281,9 @@ public class CloudPrinterService {
if (it.getIsMember() == 1) {
unitPrice = it.getMemberPrice();
}
if (it.getIsGift() == 1) {
unitPrice = BigDecimal.ZERO;
}
BigDecimal subTotal = NumberUtil.mul(it.getNum(), unitPrice.subtract(NumberUtil.null2Zero(it.getDiscountSaleAmount())));
OrderDetailPO.Detail detail = new OrderDetailPO.Detail(it.getProductName(), it.getNum().toString(), subTotal.toPlainString(), remark, it.getProGroupInfo());
detailList.add(detail);
@ -355,6 +358,9 @@ public class CloudPrinterService {
if (it.getIsMember() == 1) {
unitPrice = it.getMemberPrice();
}
if ("true".equals(it.getIsGift())) {
unitPrice = BigDecimal.ZERO;
}
BigDecimal subTotal = NumberUtil.mul(it.getNumber(), unitPrice.subtract(NumberUtil.null2Zero(it.getDiscountSaleAmount())));
OrderDetailPO.Detail detail = new OrderDetailPO.Detail(it.getName(), it.getNumber().toString(), subTotal.toPlainString(), remark, it.getProGroupInfo());
detailList.add(detail);
@ -428,6 +434,9 @@ public class CloudPrinterService {
if (it.getIsMember() == 1) {
unitPrice = it.getMemberPrice();
}
if (it.getIsGift() == 1) {
unitPrice = BigDecimal.ZERO;
}
BigDecimal subTotal = NumberUtil.mul(it.getNum(), unitPrice.subtract(NumberUtil.null2Zero(it.getDiscountSaleAmount())));
OrderDetailPO.Detail detail = new OrderDetailPO.Detail(it.getProductName(), it.getNum().toString(), subTotal.toPlainString(), remark, it.getProGroupInfo());
detailList.add(detail);
@ -484,6 +493,9 @@ public class CloudPrinterService {
if (it.getIsMember() == 1) {
unitPrice = it.getMemberPrice();
}
if ("true".equals(it.getIsGift())) {
unitPrice = BigDecimal.ZERO;
}
BigDecimal subTotal = NumberUtil.mul(it.getNumber(), unitPrice.subtract(NumberUtil.null2Zero(it.getDiscountSaleAmount())));
OrderDetailPO.Detail detail = new OrderDetailPO.Detail(it.getName(), it.getNumber().toString(), subTotal.toPlainString(), remark, it.getProGroupInfo());
detailList.add(detail);

View File

@ -290,6 +290,7 @@ public class OrderService {
boolean isSeatCart = productId != null && TableConstant.CashierCart.ID.equals(productId.toString());
if ((StrUtil.isNotBlank(tableId))) {
TbShopTable shopTable = mpShopTableMapper.selectOne(new LambdaUpdateWrapper<TbShopTable>()
.eq(TbShopTable::getShopId, shopId)
.eq(TbShopTable::getQrcode, tableId)
.in(TbShopTable::getStatus, "idle", "using", "pending"));
@ -305,6 +306,7 @@ public class OrderService {
LambdaQueryWrapper<TbCashierCart> cartQuery = new LambdaQueryWrapper<TbCashierCart>()
.eq(TbCashierCart::getShopId, shopId)
.eq(TbCashierCart::getUseType, shopEatTypeInfoDTO.getUseType())
.eq(TbCashierCart::getIsGift, isGift)
.gt(TbCashierCart::getCreatedAt, DateUtil.offsetDay(DateUtil.date(), -1).getTime())
.and(r -> r.eq(TbCashierCart::getMasterId, finalMasterId).or().isNull(TbCashierCart::getMasterId).or().eq(TbCashierCart::getMasterId, ""))
.in(TbCashierCart::getStatus, "create");
@ -366,7 +368,7 @@ public class OrderService {
List<TbCashierCart> list = cashierCartMapper.selectALlByMasterId(masterId, "create");
TbCashierCart cashierCart = null;
if (type.equals("edit")) {
cashierCart = getCashierInfo(shopId, skuId, productId, tableId, masterId, shopEatTypeInfoDTO, cartId);
cashierCart = getCashierInfo(shopId, skuId, productId, tableId, masterId, shopEatTypeInfoDTO, cartId, null);
if (cashierCart == null) {
needNew = true;
} else {
@ -413,6 +415,7 @@ public class OrderService {
cashierCart.setTotalNumber(number);
cashierCart.setIsPrint(isPrint);
cashierCart.setIsPack(isPack);
cashierCart.setIsGift(isGift);
cashierCart.resetTotalAmount();
cashierCart.setUuid(uuid);
cashierCart.setIsPrint(isPrint);
@ -428,7 +431,7 @@ public class OrderService {
if (type.equals("add") || needNew) {
if (product == null || product.getGroupType() == null || product.getGroupType() != 1) {
cashierCart = getCashierInfo(shopId, skuId, productId, tableId, masterId, shopEatTypeInfoDTO, cartId);
cashierCart = getCashierInfo(shopId, skuId, productId, tableId, masterId, shopEatTypeInfoDTO, cartId, isGift);
}
if (cashierCart != null) {
@ -542,6 +545,8 @@ public class OrderService {
cashierCart.setTableId(tableId);
cashierCart.setPlatformType(OrderPlatformTypeEnum.CASH.getValue());
if (product != null) {
cashierCart.setIsWeight("weigh".equals(product.getType()) ? 1 : 0);
resetGroupProductCart(groupProductIdList, product, cashierCart);
}
list.add(cashierCart);
@ -555,7 +560,7 @@ public class OrderService {
return Result.success(CodeEnum.SUCCESS, masterId);
}
private TbCashierCart getCashierInfo(Object shopId, Object skuId, Object productId, String tableId, String MasterId, ShopEatTypeInfoDTO shopEatTypeInfoDTO, Integer cartId) {
private TbCashierCart getCashierInfo(Object shopId, Object skuId, Object productId, String tableId, String MasterId, ShopEatTypeInfoDTO shopEatTypeInfoDTO, Integer cartId, String isGift) {
LambdaQueryWrapper<TbCashierCart> query = new LambdaQueryWrapper<TbCashierCart>()
.eq(TbCashierCart::getShopId, shopId)
.eq(TbCashierCart::getSkuId, skuId)
@ -563,6 +568,10 @@ public class OrderService {
.in(TbCashierCart::getStatus, "create")
.eq(TbCashierCart::getUseType, shopEatTypeInfoDTO.getUseType());
if (StrUtil.isNotBlank(isGift)) {
query.eq(TbCashierCart::getIsGift, isGift);
}
if (cartId != null) {
query.eq(TbCashierCart::getId, cartId);
}
@ -1081,6 +1090,7 @@ public class OrderService {
if (TableConstant.CART_SEAT_ID.equals(cashierCart.getProductId())) {
saleAmount = saleAmount.add(shopInfo.getTableFee());
}
orderDetail.setIsWeight(cashierCart.getIsWeight());
orderDetail.setProGroupInfo(cashierCart.getProGroupInfo());
orderDetail.setIsTemporary(cashierCart.getIsTemporary());
@ -2062,6 +2072,7 @@ public class OrderService {
}
TbShopTable shopTable = mpShopTableMapper.selectOne(new LambdaQueryWrapper<TbShopTable>()
.eq(TbShopTable::getShopId, choseCountDTO.getShopId())
.eq(TbShopTable::getQrcode, choseCountDTO.getTableId()));
if (shopTable == null) {
throw new NotPrintException("台桌不存在");
@ -2094,7 +2105,6 @@ public class OrderService {
tbCashierCart.setTradeDay(DateUtils.getDay());
tbCashierCart.setStatus("create");
tbCashierCart.setTotalAmount(new BigDecimal(choseCountDTO.getNum()).multiply(shopInfo.getTableFee()));
tbCashierCart.setPlaceNum(1);
tbCashierCart.setProductId("-999");
tbCashierCart.setSkuId("-999");
tbCashierCart.setPackFee(BigDecimal.ZERO);

View File

@ -15,6 +15,7 @@ import com.chaozhanggui.system.cashierservice.bean.TableStateEnum;
import com.chaozhanggui.system.cashierservice.bean.constant.TableConstant;
import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.entity.dto.CreditDTO;
import com.chaozhanggui.system.cashierservice.entity.dto.OrderInfoCouponInfoDTO;
import com.chaozhanggui.system.cashierservice.entity.dto.ReturnGroupOrderDto;
import com.chaozhanggui.system.cashierservice.entity.dto.ReturnOrderDTO;
@ -146,14 +147,14 @@ public class PayService {
private final MpProductStockDetailMapper mpProductStockDetailMapper;
private final MpOrderInfoService mpOrderInfoService;
private final TbMemberPointsService memberPointsService;
private final TbCreditBuyerOrderService creditBuyerOrderService;
private final Utils utils;
@Autowired
private MPOrderInfoMapper mPOrderInfoMapper;
public PayService(RedisTemplate<String, Object> redisTemplate, MpCashierCartService mpCashierCartService, TbShopCouponService shopCouponService, MpOrderDetailService mpOrderDetailService, MpShopUnitMapper mpShopUnitMapper, MpProductStockDetailMapper mpProductStockDetailMapper, MpOrderInfoService mpOrderInfoService, Utils utils) {
public PayService(RedisTemplate<String, Object> redisTemplate, MpCashierCartService mpCashierCartService, TbShopCouponService shopCouponService, MpOrderDetailService mpOrderDetailService, MpShopUnitMapper mpShopUnitMapper, MpProductStockDetailMapper mpProductStockDetailMapper, MpOrderInfoService mpOrderInfoService, TbMemberPointsService memberPointsService, TbCreditBuyerOrderService creditBuyerOrderService, Utils utils) {
this.redisTemplate = redisTemplate;
this.mpCashierCartService = mpCashierCartService;
this.shopCouponService = shopCouponService;
@ -161,8 +162,9 @@ public class PayService {
this.mpShopUnitMapper = mpShopUnitMapper;
this.mpProductStockDetailMapper = mpProductStockDetailMapper;
this.mpOrderInfoService = mpOrderInfoService;
this.memberPointsService = memberPointsService;
this.creditBuyerOrderService = creditBuyerOrderService;
this.utils = utils;
memberPointsService = null;
}
public static void main(String[] args) {
@ -286,7 +288,7 @@ public class PayService {
return Result.fail(CodeEnum.PAYTYPENOEXIST);
}
utils.runFunAndTransactional(() -> {
utils.runFunAndTransactional(() -> {
TbOrderPayment payment = tbOrderPaymentMapper.selectByOrderId(orderId);
if (ObjectUtil.isEmpty(payment) || payment == null) {
payment = new TbOrderPayment();
@ -875,6 +877,90 @@ public class PayService {
return Result.success(SUCCESS);
}
public Result creditPay(CreditDTO creditDTO, String token) {
TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPrimaryKey(creditDTO.getOrderId());
if (ObjectUtil.isEmpty(orderInfo)) {
return Result.fail(CodeEnum.ORDERNOEXIST);
}
if (!"unpaid".equals(orderInfo.getStatus())) {
return Result.fail(CodeEnum.ORDERSTATUSERROR);
}
int count = tbShopPayTypeMapper.countSelectByShopIdAndPayType(orderInfo.getShopId(), "cash");
if (count < 1) {
return Result.fail(CodeEnum.PAYTYPENOEXIST);
}
if (creditDTO.getPayAmount() != null && creditDTO.getPayAmount().add(creditDTO.getDiscountAmount()).compareTo(orderInfo.getOrderAmount()) != 0) {
return Result.fail("优惠金额 + 支付金额不等于订单金额");
}
creditBuyerOrderService.save(creditDTO.getCreditBuyerId(), Long.valueOf(orderInfo.getId()));
utils.runFunAndTransactional(() -> {
if (creditDTO.getPayAmount() != null && creditDTO.getDiscountAmount() != null) {
orderInfo.setPayAmount(creditDTO.getPayAmount());
orderInfo.setDiscountAmount(creditDTO.getDiscountAmount());
orderInfo.setDiscountRatio(ObjectUtil.isNotEmpty(creditDTO.getPayAmount()) ? creditDTO.getPayAmount()
.divide(orderInfo.getOrderAmount(), 2, RoundingMode.HALF_UP).setScale(2, RoundingMode.HALF_DOWN) : null);
} else {
orderInfo.setPayAmount(orderInfo.getOrderAmount());
}
orderInfo.setCreditBuyerId(creditDTO.getCreditBuyerId());
orderInfo.setPayType("creditBuyer");
orderInfo.setStatus("closed");
orderInfo.setPayOrderNo("deposit".concat(SnowFlakeUtil.generateOrderNo()));
mPOrderInfoMapper.updateById(orderInfo);
//更新购物车状态
mpCashierCartService.updateStateByOrderId(TableConstant.OrderInfo.Status.CLOSED, orderInfo.getId());
if (ObjectUtil.isNotNull(orderInfo.getDiscountRatio()) && ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())) {
tbOrderDetailMapper.updateStatusByOrderId(creditDTO.getOrderId(), "closed", orderInfo.getDiscountRatio());
} else {
tbOrderDetailMapper.updateStatusByOrderId(creditDTO.getOrderId(), "closed", null);
}
return null;
});
JSONObject jsonObject = new JSONObject();
jsonObject.put("token", token);
jsonObject.put("type", "create");
jsonObject.put("orderId", creditDTO.getOrderId());
producer.putOrderCollect(jsonObject.toJSONString());
// 打印消息
if (!OrderUseTypeEnum.DINE_IN_AFTER.getValue().equals(orderInfo.getUseType())) {
List<TbOrderDetail> detailList = mPOrderDetailMapper.selectList(new LambdaQueryWrapper<TbOrderDetail>()
.eq(TbOrderDetail::getOrderId, orderInfo.getId())
.eq(TbOrderDetail::getStatus, "closed"));
rabbitMsgUtils.printDishesTicket(orderInfo.getId(), false, detailList.toArray(new TbOrderDetail[0]));
}
rabbitMsgUtils.printPlaceTicket(orderInfo.getId(), false);
// 发送库存记录mq消息
JSONObject mqData = new JSONObject();
mqData.put("orderId", creditDTO.getOrderId());
mqData.put("type", "pc");
producer.sendStockSaleMsg(mqData);
String tableCartKey = RedisCst.getCurrentOrderKey(orderInfo.getTableId(),
orderInfo.getShopId());
redisUtil.del(tableCartKey);
clearTableInfoCache(orderInfo);
return Result.success(SUCCESS);
}
public Result vipPay(Integer orderId, String token, Integer vipUserId, BigDecimal payAmount, BigDecimal discountAmount) {
if (ObjectUtil.isEmpty(orderId)) {
return Result.fail(CodeEnum.PARAM);
@ -1197,6 +1283,8 @@ public class PayService {
BigDecimal saleAmount = BigDecimal.ZERO;
ArrayList<TbOrderDetail> remainOrderDetailList = new ArrayList<>();
boolean hasNormalReturn = false;
ArrayList<TbOrderDetail> copyDetailList = new ArrayList<>();
for (TbOrderDetail orderDetail : detailList) {
// 原始金额
BigDecimal originalAmount = orderDetail.getPriceAmount();
@ -1255,6 +1343,7 @@ public class PayService {
if (remainNum.compareTo(BigDecimal.ZERO) <= 0) {
returnAmount = returnAmount.add(orderDetail.getPriceAmount());
packAMount = orderDetail.getPackAmount();
currentDetailAMount = orderDetail.getPriceAmount();
} else {
currentDetailAMount = orderDetail.getPriceAmount()
.divide(orderDetail.getNum(), 8, RoundingMode.HALF_UP)
@ -1288,6 +1377,11 @@ public class PayService {
orderDetail.setReturnAmount(returnAmount);
// orderDetail.setStatus(isOnline ? "refunding" : "refund");
orderDetail.setStatus("refund");
TbOrderDetail returnOrderDetailCopy = new TbOrderDetail();
cn.hutool.core.bean.BeanUtil.copyProperties(orderDetail, returnOrderDetailCopy);
returnOrderDetailCopy.setId(null);
copyDetailList.add(returnOrderDetailCopy);
}
if (returnAmount.compareTo(BigDecimal.ZERO) < 0) {
@ -1307,28 +1401,27 @@ public class PayService {
// TbOrderInfo returnOrder = mpOrderInfoService.selectReturnOrderByOrderId(returnOrderDTO.getOrderId());
TbOrderInfo returnOrder = new TbOrderInfo();
String orderNo = generateOrderNumber();
cn.hutool.core.bean.BeanUtil.copyProperties(oldOrderInfo, returnOrder);
returnOrder.setId(null);
returnOrder.setOrderNo(orderNo);
returnOrder.setRefundAmount(returnAmount);
returnOrder.setOrderType("return");
returnOrder.setStatus(isOnline ? "refunding" : "refund");
returnOrder.setUpdatedAt(null);
returnOrder.setSystemTime(DateUtil.date().getTime());
returnOrder.setCreatedAt(DateUtil.date().getTime());
returnOrder.setPayOrderNo(null);
returnOrder.setSource(oldOrderInfo.getId());
returnOrder.setRefundRemark(returnOrderDTO.getNote());
returnOrder.setOrderAmount(returnAmount);
returnOrder.setAmount(returnAmount);
returnOrder.setSettlementAmount(returnAmount);
returnOrder.setPayAmount(returnAmount);
mPOrderInfoMapper.insert(returnOrder);
for (TbOrderDetail orderDetail : detailList) {
orderDetail.setOrderId(returnOrder.getId());
}
String orderNo = generateOrderNumber();
cn.hutool.core.bean.BeanUtil.copyProperties(oldOrderInfo, returnOrder);
returnOrder.setId(null);
returnOrder.setOrderNo(orderNo);
returnOrder.setRefundAmount(returnAmount);
returnOrder.setOrderType("return");
returnOrder.setStatus(isOnline ? "refunding" : "refund");
returnOrder.setUpdatedAt(null);
returnOrder.setSystemTime(DateUtil.date().getTime());
returnOrder.setCreatedAt(DateUtil.date().getTime());
returnOrder.setPayOrderNo(null);
returnOrder.setSource(oldOrderInfo.getId());
returnOrder.setRefundRemark(returnOrderDTO.getNote());
returnOrder.setOrderAmount(returnAmount);
returnOrder.setAmount(returnAmount);
returnOrder.setSettlementAmount(returnAmount);
returnOrder.setPayAmount(returnAmount);
mPOrderInfoMapper.insert(returnOrder);
// 保存新的退款detail信息
copyDetailList.forEach(item -> item.setOrderId(returnOrder.getId()));
mpOrderDetailService.saveBatch(copyDetailList);
updateStockAndRecord(detailList);
mpOrderDetailService.updateBatchById(detailList);
@ -1434,11 +1527,11 @@ public class PayService {
orderInfo.setRefundAmount(orderInfo.getRefundAmount().add(returnOrderInfo.getRefundAmount()));
orderInfo.setRefundRemark(returnOrderDTO.getNote());
if (hasNormalReturn && ("scanCode".equals(payType) || "wx_lite".equals(payType))) {
if (returnOrderDTO.getIsOnline() != null && !returnOrderDTO.getIsOnline()) {
if (returnOrderDTO.getIsOnline() != null && !returnOrderDTO.getIsOnline()) {
mpOrderDetailService.updateStatusByOrderIdAndIds(TableConstant.OrderInfo.Status.REFUNDING, TableConstant.OrderInfo.Status.REFUND,
returnOrderDTO.getOrderId(), returnOrderDTO.getOrderDetails().stream().map(ReturnOrderDTO.OrderDetail::getId).collect(Collectors.toList()));
}else {
} else {
TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getMerchantId()));
MsgException.checkNull(thirdApply, "支付参数配置错误");
@ -2489,4 +2582,5 @@ public class PayService {
}
}