|
|
|
|
@@ -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().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()));
|
|
|
|
|
tbOrderInfoMapper.updateByPrimaryKeySelective(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);
|
|
|
|
|
@@ -1307,24 +1393,24 @@ 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);
|
|
|
|
|
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());
|
|
|
|
|
@@ -1434,11 +1520,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 +2575,5 @@ public class PayService {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|