|
|
|
|
@ -23,6 +23,7 @@ import cn.ysk.cashier.pojo.order.TbOrderDetail;
|
|
|
|
|
import cn.ysk.cashier.pojo.order.TbOrderInfo;
|
|
|
|
|
import cn.ysk.cashier.pojo.product.TbProduct;
|
|
|
|
|
import cn.ysk.cashier.pojo.product.TbProductSku;
|
|
|
|
|
import cn.ysk.cashier.pojo.product.TbProductStockDetail;
|
|
|
|
|
import cn.ysk.cashier.pojo.shop.*;
|
|
|
|
|
import cn.ysk.cashier.repository.TbShopPayTypeRepository;
|
|
|
|
|
import cn.ysk.cashier.repository.order.TbCashierCartRepository;
|
|
|
|
|
@ -95,6 +96,8 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|
|
|
|
private final MpShopTableMapper mpShopTableMapper;
|
|
|
|
|
private final TbShopPayTypeMapper tbShopPayTypeMapper;
|
|
|
|
|
private final MpShopTableService mpShopTableService;
|
|
|
|
|
private final MpShopUnitMapper mpShopUnitMapper;
|
|
|
|
|
private final MpProductStockDetailMapper mpProductStockDetailMapper;
|
|
|
|
|
@Value("${thirdPay.payType}")
|
|
|
|
|
private String thirdPayType;
|
|
|
|
|
|
|
|
|
|
@ -1610,18 +1613,34 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Object updateVip(UpdateVipDTO updateVipDTO) {
|
|
|
|
|
LambdaUpdateWrapper<TbCashierCart> queryWrapper = new LambdaUpdateWrapper<>();
|
|
|
|
|
queryWrapper.eq(TbCashierCart::getTableId, updateVipDTO.getTableId())
|
|
|
|
|
.eq(TbCashierCart::getMasterId, updateVipDTO.getMasterId())
|
|
|
|
|
.eq(TbCashierCart::getShopId, updateVipDTO.getShopId());
|
|
|
|
|
ShopEatTypeInfoDTO shopEatTypeInfoDTO = checkEatModel(updateVipDTO.getShopId(), updateVipDTO.getTableId());
|
|
|
|
|
LambdaQueryWrapper<TbCashierCart> queryWrapper = new LambdaQueryWrapper<TbCashierCart>()
|
|
|
|
|
.in(TbCashierCart::getStatus, "create", "return")
|
|
|
|
|
.eq(TbCashierCart::getShopId, updateVipDTO.getShopId())
|
|
|
|
|
.eq(TbCashierCart::getUseType, shopEatTypeInfoDTO.getUseType())
|
|
|
|
|
.and(q -> q.eq(TbCashierCart::getMasterId, updateVipDTO.getMasterId()).or().isNull(TbCashierCart::getMasterId));
|
|
|
|
|
|
|
|
|
|
if (updateVipDTO.getType().equals(0)) {
|
|
|
|
|
queryWrapper.set(TbCashierCart::getUserId, null);
|
|
|
|
|
queryWrapper.eq(TbCashierCart::getUserId, updateVipDTO.getVipUserId());
|
|
|
|
|
if (!shopEatTypeInfoDTO.isTakeout()) {
|
|
|
|
|
queryWrapper.eq(TbCashierCart::getTableId, updateVipDTO.getTableId());
|
|
|
|
|
} else {
|
|
|
|
|
queryWrapper.set(TbCashierCart::getUserId, updateVipDTO.getVipUserId());
|
|
|
|
|
queryWrapper.and(q -> q.isNull(TbCashierCart::getTableId).or().eq(TbCashierCart::getTableId, ""))
|
|
|
|
|
.in(TbCashierCart::getPlatformType, OrderPlatformTypeEnum.PC.getValue(), OrderPlatformTypeEnum.CASH.getValue());
|
|
|
|
|
}
|
|
|
|
|
return cashierCartMapper.update(null, queryWrapper);
|
|
|
|
|
|
|
|
|
|
List<TbCashierCart> tbCashierCarts = cashierCartMapper.selectList(queryWrapper.isNotNull(TbCashierCart::getOrderId));
|
|
|
|
|
if (!tbCashierCarts.isEmpty()) {
|
|
|
|
|
Integer orderId = tbCashierCarts.get(0).getOrderId();
|
|
|
|
|
if (updateVipDTO.getType() == 0) {
|
|
|
|
|
return orderInfoMapper.update(null, new LambdaUpdateWrapper<TbOrderInfo>()
|
|
|
|
|
.eq(TbOrderInfo::getId, orderId)
|
|
|
|
|
.set(TbOrderInfo::getUserId, updateVipDTO.getVipUserId()));
|
|
|
|
|
}else {
|
|
|
|
|
return orderInfoMapper.update(null, new LambdaUpdateWrapper<TbOrderInfo>()
|
|
|
|
|
.eq(TbOrderInfo::getId, orderId)
|
|
|
|
|
.set(TbOrderInfo::getUserId, null));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1946,9 +1965,46 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|
|
|
|
returnOrder.setSource(oldOrderInfo.getId());
|
|
|
|
|
orderInfoMapper.insert(returnOrder);
|
|
|
|
|
|
|
|
|
|
updateStockAndRecord(detailList);
|
|
|
|
|
|
|
|
|
|
return returnOrder;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateStockAndRecord(List<TbOrderDetail> orderDetailList) {
|
|
|
|
|
// 更新商品库存
|
|
|
|
|
for (TbOrderDetail detail : orderDetailList) {
|
|
|
|
|
TbProductSku productSku = producSkutMapper.selectById(detail.getProductSkuId());
|
|
|
|
|
TbProduct product = productMapper.selectById(detail.getProductId());
|
|
|
|
|
|
|
|
|
|
TbProductStockDetail tbProductStockDetail = new TbProductStockDetail();
|
|
|
|
|
tbProductStockDetail.setCreatedAt(System.currentTimeMillis());
|
|
|
|
|
tbProductStockDetail.setUpdatedAt(System.currentTimeMillis());
|
|
|
|
|
tbProductStockDetail.setShopId(detail.getShopId().toString());
|
|
|
|
|
tbProductStockDetail.setSourcePath("NORMAL");
|
|
|
|
|
tbProductStockDetail.setType("退单");
|
|
|
|
|
tbProductStockDetail.setSubType(1);
|
|
|
|
|
tbProductStockDetail.setRemark("退单: " + detail.getOrderId());
|
|
|
|
|
tbProductStockDetail.setOrderId(String.valueOf(detail.getOrderId()));
|
|
|
|
|
|
|
|
|
|
if (ObjectUtil.isNotEmpty(product)) {
|
|
|
|
|
TbShopUnit shopUnit = mpShopUnitMapper.selectById(product.getUnitId());
|
|
|
|
|
tbProductStockDetail.setProductName(product.getName());
|
|
|
|
|
tbProductStockDetail.setIsStock(product.getIsStock());
|
|
|
|
|
tbProductStockDetail.setStockSnap(product.getSelectSpec());
|
|
|
|
|
tbProductStockDetail.setUnitName(shopUnit.getName());
|
|
|
|
|
tbProductStockDetail.setProductId(product.getId().toString());
|
|
|
|
|
|
|
|
|
|
productMapper.incrStock(product.getId(), detail.getNum());
|
|
|
|
|
tbProductStockDetail.setLeftNumber(product.getStockNumber());
|
|
|
|
|
tbProductStockDetail.setStockNumber(Double.valueOf(detail.getNum()));
|
|
|
|
|
|
|
|
|
|
producSkutMapper.decrRealSalesNumber(productSku.getId(), detail.getNum());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mpProductStockDetailMapper.insert(tbProductStockDetail);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Object returnOrder(ReturnOrderDTO returnOrderDTO) {
|
|
|
|
|
@ -1970,118 +2026,25 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TbOrderInfo returnOrderInfo = updateReturnOrderInfo(returnOrderDTO, orderInfo, true);
|
|
|
|
|
|
|
|
|
|
String merchantId = orderInfo.getMerchantId();
|
|
|
|
|
String shopId = orderInfo.getShopId();
|
|
|
|
|
String day = DateUtils.getDay();
|
|
|
|
|
String masterId = orderInfo.getMasterId();
|
|
|
|
|
String payType = orderInfo.getPayType();
|
|
|
|
|
BigDecimal orderAmount = orderInfo.getPayAmount();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BigDecimal returnAmount = BigDecimal.ZERO;
|
|
|
|
|
BigDecimal packAMount = BigDecimal.ZERO;
|
|
|
|
|
BigDecimal saleAmount = BigDecimal.ZERO;
|
|
|
|
|
BigDecimal feeAmount = BigDecimal.ZERO;
|
|
|
|
|
BigDecimal payAmount = BigDecimal.ZERO;
|
|
|
|
|
|
|
|
|
|
// // 线上退款
|
|
|
|
|
// if ("scanCode".equals(payType) || "wx_lite".equals(payType)) {
|
|
|
|
|
// payService.returnOrder(Integer.valueOf(shopId), orderInfo, returnOrderInfo);
|
|
|
|
|
//
|
|
|
|
|
// // 储值卡支付退款
|
|
|
|
|
// } else if ("deposit".equals(payType)) {
|
|
|
|
|
// orderInfoService.depositReturn();
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
// //添加退单数据
|
|
|
|
|
//
|
|
|
|
|
// //更新子单表
|
|
|
|
|
// if (ObjectUtil.isNotEmpty(detailPos) && detailPos.size() > 0) {
|
|
|
|
|
// tbOrderDetailMapper.updateBatchOrderDetail(detailPos);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// //添加子表信息
|
|
|
|
|
// if (ObjectUtil.isNotEmpty(returnDetail) && returnDetail.size() > 0) {
|
|
|
|
|
// tbOrderDetailMapper.batchInsert(returnDetail, newOrderInfo.getId().toString());
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// JSONObject jsonObject = new JSONObject();
|
|
|
|
|
// jsonObject.put("token", token);
|
|
|
|
|
// jsonObject.put("type", "return");
|
|
|
|
|
// jsonObject.put("orderId", 0);
|
|
|
|
|
// jsonObject.put("amount", newOrderInfo.getPayAmount());
|
|
|
|
|
//// jsonObject.put("data",new ReturnWTZInfo(orderId+"",newOrderInfo.getPayAmount(),details));
|
|
|
|
|
// producer.putOrderCollect(jsonObject.toJSONString());
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
if ("scanCode".equals(payType) || "wx_lite".equals(payType)) {
|
|
|
|
|
payService.returnOrder(Integer.valueOf(shopId), orderInfo, returnOrderInfo);
|
|
|
|
|
// 储值卡支付退款
|
|
|
|
|
} else if ("deposit".equals(payType)) {
|
|
|
|
|
orderInfoService.depositReturn(Integer.valueOf(orderInfo.getUserId()), Integer.valueOf(orderInfo.getShopId()), returnOrderInfo.getRefundAmount());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 打印退款小票
|
|
|
|
|
// producer.printMechine(newOrderInfo.getId().toString());
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// //修改耗材数据
|
|
|
|
|
// JSONObject jsonObject1 = new JSONObject();
|
|
|
|
|
// jsonObject1.put("orderId", newOrderInfo.getId());
|
|
|
|
|
// jsonObject1.put("type", "delete");
|
|
|
|
|
// producer.cons(jsonObject1.toString());
|
|
|
|
|
//
|
|
|
|
|
// // 更新商品库存
|
|
|
|
|
// for (TbOrderDetail detail : returnDetail) {
|
|
|
|
|
// detail = tbOrderDetailMapper.selectByPrimaryKey(detail.getId());
|
|
|
|
|
//
|
|
|
|
|
// TbProductSku productSku = productSkuMapper.selectByPrimaryKey(detail.getProductSkuId());
|
|
|
|
|
// TbProductWithBLOBs product = productMapper.selectByPrimaryKey(detail.getProductId());
|
|
|
|
|
//
|
|
|
|
|
// TbProductStockDetail tbProductStockDetail = new TbProductStockDetail();
|
|
|
|
|
// tbProductStockDetail.setCreatedAt(System.currentTimeMillis());
|
|
|
|
|
// tbProductStockDetail.setUpdatedAt(System.currentTimeMillis());
|
|
|
|
|
// tbProductStockDetail.setShopId(detail.getShopId().toString());
|
|
|
|
|
// tbProductStockDetail.setSourcePath("NORMAL");
|
|
|
|
|
// tbProductStockDetail.setType("退单");
|
|
|
|
|
// tbProductStockDetail.setSubType((byte) 1);
|
|
|
|
|
// tbProductStockDetail.setRemark("退单: " + detail.getOrderId());
|
|
|
|
|
// tbProductStockDetail.setOrderId(String.valueOf(detail.getOrderId()));
|
|
|
|
|
//
|
|
|
|
|
// if (ObjectUtil.isNotEmpty(product)) {
|
|
|
|
|
// TbShopUnit shopUnit = shopUnitMapper.selectByPrimaryKey(Integer.valueOf(product.getUnitId()));
|
|
|
|
|
//
|
|
|
|
|
// tbProductStockDetail.setProductName(product.getName());
|
|
|
|
|
// tbProductStockDetail.setIsStock(product.getIsStock());
|
|
|
|
|
// tbProductStockDetail.setStockSnap(product.getSelectSpec());
|
|
|
|
|
// tbProductStockDetail.setUnitName(shopUnit.getName());
|
|
|
|
|
// tbProductStockDetail.setProductId(product.getId().toString());
|
|
|
|
|
//
|
|
|
|
|
// if (product.getIsDistribute() == 1) {
|
|
|
|
|
//// redisUtil.seckill(RedisCst.PRODUCT + shopId.toString() + ":product" + product.getId().toString(), String.valueOf(detail.getReturnNum() + product.getStockNumber().intValue()));
|
|
|
|
|
// productMapper.updateStockById(product.getId(), detail.getReturnNum() * -1);
|
|
|
|
|
//
|
|
|
|
|
// tbProductStockDetail.setLeftNumber(product.getStockNumber());
|
|
|
|
|
// tbProductStockDetail.setStockNumber(Double.valueOf(detail.getReturnNum()));
|
|
|
|
|
// } else {
|
|
|
|
|
// if (ObjectUtil.isNotEmpty(productSku)) {
|
|
|
|
|
//// redisUtil.seckill(RedisCst.PRODUCT + shopId.toString() + ":" + productSku.getId().toString(), String.valueOf(detail.getReturnNum() + productSku.getStockNumber().intValue()));
|
|
|
|
|
// productSkuMapper.updateByskuIdSub(productSku.getId(), detail.getReturnNum() * -1);
|
|
|
|
|
//
|
|
|
|
|
// tbProductStockDetail.setSkuId(productSku.getId().toString());
|
|
|
|
|
// tbProductStockDetail.setLeftNumber(productSku.getStockNumber().intValue());
|
|
|
|
|
// tbProductStockDetail.setStockNumber(Double.valueOf(detail.getReturnNum()));
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// productSkuMapper.decrRealSalesNumber(productSku.getId(), detail.getReturnNum());
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// productStockDetailMapper.insert(tbProductStockDetail);
|
|
|
|
|
// }
|
|
|
|
|
// redisUtil.del("SHOP:CODE:USER:" + "pc" + ":" + orderInfo.getShopId() + ":" + DateUtils.getDay() + TokenUtil.parseParamFromToken(token).getString("accountId"));
|
|
|
|
|
//
|
|
|
|
|
// // 修改台桌状态
|
|
|
|
|
// mpShopTableMapper.update(null, new LambdaUpdateWrapper<TbShopTable>()
|
|
|
|
|
// .eq(TbShopTable::getQrcode, orderInfo.getTableId())
|
|
|
|
|
// .set(TbShopTable::getStatus, TableStateEnum.IDLE.getState()));
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// return Result.success(CodeEnum.SUCCESS);
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
//修改耗材数据
|
|
|
|
|
JSONObject jsonObject1 = new JSONObject();
|
|
|
|
|
jsonObject1.put("orderId", returnOrderInfo.getId());
|
|
|
|
|
jsonObject1.put("type", "delete");
|
|
|
|
|
rabbitMsgUtils.updateCons(jsonObject1);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|