打印改为事务提交后
This commit is contained in:
@@ -34,6 +34,7 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
@Service
|
||||
public class MemberService {
|
||||
@@ -84,6 +85,8 @@ public class MemberService {
|
||||
@Autowired
|
||||
private TbOrderInfoMapper tbOrderInfoMapper;
|
||||
private MpShopTableMapper mpShopTableMapper;
|
||||
@Autowired
|
||||
private Utils utils;
|
||||
|
||||
public Result queryMember(String shopId, String phone,String isFlag, int page, int pageSize) {
|
||||
|
||||
@@ -579,7 +582,6 @@ public class MemberService {
|
||||
return Result.success(CodeEnum.SUCCESS, memberIn);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Result memberAccountPay(Map<String, Object> map, String token) throws Exception {
|
||||
if (ObjectUtil.isEmpty(map) || map.isEmpty()
|
||||
|| !map.containsKey("shopId") || ObjectUtil.isEmpty(map.get("shopId"))
|
||||
@@ -633,10 +635,13 @@ public class MemberService {
|
||||
if (count < 1) {
|
||||
return Result.fail(CodeEnum.PAYTYPENOEXIST);
|
||||
}
|
||||
|
||||
BigDecimal amount = new BigDecimal(String.valueOf(map.get("amount"))).setScale(2, RoundingMode.DOWN);
|
||||
|
||||
TbMemberIn memberIn = new TbMemberIn();
|
||||
AtomicReference<BigDecimal> fl = new AtomicReference<>();
|
||||
AtomicReference<TbShopUserFlow> flow = new AtomicReference<>(new TbShopUserFlow());
|
||||
utils.runFunAndTransactional(() -> {
|
||||
|
||||
memberIn.setMerchantId(Integer.valueOf(shopInfo.getMerchantId()));
|
||||
memberIn.setAmount(amount);
|
||||
memberIn.setUserId(shopUser.getId());
|
||||
@@ -657,17 +662,15 @@ public class MemberService {
|
||||
}
|
||||
tbShopUserMapper.updateByPrimaryKeySelective(shopUser);
|
||||
|
||||
TbShopUserFlow flow = new TbShopUserFlow();
|
||||
flow.setShopUserId(shopUser.getId());
|
||||
flow.setBizCode("cashMemberIn");
|
||||
flow.setType("+");
|
||||
flow.setBizName("线下充值");
|
||||
flow.setAmount(amount);
|
||||
flow.setBalance(shopUser.getAmount());
|
||||
flow.setCreateTime(new Date());
|
||||
flow.setIsReturn("0");
|
||||
tbShopUserFlowMapper.insert(flow);
|
||||
BigDecimal fl = null;
|
||||
flow.get().setShopUserId(shopUser.getId());
|
||||
flow.get().setBizCode("cashMemberIn");
|
||||
flow.get().setType("+");
|
||||
flow.get().setBizName("线下充值");
|
||||
flow.get().setAmount(amount);
|
||||
flow.get().setBalance(shopUser.getAmount());
|
||||
flow.get().setCreateTime(new Date());
|
||||
flow.get().setIsReturn("0");
|
||||
tbShopUserFlowMapper.insert(flow.get());
|
||||
|
||||
TbActivate activate = tbActivateMapper.selectByAmount(shopInfo.getId().toString(), memberIn.getAmount());
|
||||
if (ObjectUtil.isNotEmpty(activate) && ObjectUtil.isNotNull(activate)) {
|
||||
@@ -685,22 +688,24 @@ public class MemberService {
|
||||
shopUser.setUpdatedAt(System.currentTimeMillis());
|
||||
tbShopUserMapper.updateByPrimaryKeySelective(shopUser);
|
||||
|
||||
flow = new TbShopUserFlow();
|
||||
flow.setShopUserId(shopUser.getId());
|
||||
flow.setBizCode("scanMemberAwardIn");
|
||||
flow.setType("+");
|
||||
flow.setBizName("充值活动奖励");
|
||||
flow.setAmount(awardAmount);
|
||||
flow.setBalance(shopUser.getAmount());
|
||||
flow.setCreateTime(new Date());
|
||||
flow.setIsReturn("0");
|
||||
tbShopUserFlowMapper.insert(flow);
|
||||
|
||||
fl = awardAmount;
|
||||
flow.set(new TbShopUserFlow());
|
||||
flow.get().setShopUserId(shopUser.getId());
|
||||
flow.get().setBizCode("scanMemberAwardIn");
|
||||
flow.get().setType("+");
|
||||
flow.get().setBizName("充值活动奖励");
|
||||
flow.get().setAmount(awardAmount);
|
||||
flow.get().setBalance(shopUser.getAmount());
|
||||
flow.get().setCreateTime(new Date());
|
||||
flow.get().setIsReturn("0");
|
||||
tbShopUserFlowMapper.insert(flow.get());
|
||||
|
||||
fl.set(awardAmount);
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("token", token);
|
||||
jsonObject.put("type", "memberIn");
|
||||
@@ -712,10 +717,10 @@ public class MemberService {
|
||||
JSONObject baObj = new JSONObject();
|
||||
baObj.put("userId", shopUser.getUserId());
|
||||
baObj.put("shopId", shopInfo.getId());
|
||||
baObj.put("amount", ObjectUtil.isNull(fl) ? amount : amount.add(fl));
|
||||
baObj.put("amount", ObjectUtil.isNull(fl) ? amount : amount.add(fl.get()));
|
||||
baObj.put("balance", shopUser.getAmount());
|
||||
baObj.put("type", "充值");
|
||||
baObj.put("time", flow.getCreateTime());
|
||||
baObj.put("time", flow.get().getCreateTime());
|
||||
producer.balance(baObj.toString());
|
||||
|
||||
|
||||
|
||||
@@ -174,7 +174,6 @@ public class PayService {
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Result scanPay(String orderId, String authCode, String ip, String token, BigDecimal payAmount, BigDecimal discountAmount) {
|
||||
if (ObjectUtil.isEmpty(orderId) || ObjectUtil.isEmpty(authCode) || ObjectUtil.isEmpty(ip)) {
|
||||
return Result.fail(CodeEnum.PARAM);
|
||||
@@ -230,9 +229,9 @@ public class PayService {
|
||||
return Result.fail(CodeEnum.NOCUSTOMER);
|
||||
}
|
||||
|
||||
String payType = null;
|
||||
String payName = null;
|
||||
String qpay = null;
|
||||
String payType;
|
||||
String payName;
|
||||
String qpay;
|
||||
|
||||
String payTypeCode = authCode.substring(0, 2);// 判断收款码
|
||||
|
||||
@@ -245,19 +244,25 @@ public class PayService {
|
||||
payType = "wechatPay";
|
||||
payName = "微信支付";
|
||||
qpay = "scanCode";
|
||||
} else if ("62".equals(payTypeCode)) {
|
||||
} else {
|
||||
qpay = null;
|
||||
payType = null;
|
||||
payName = null;
|
||||
if ("62".equals(payTypeCode)) {
|
||||
return Result.fail(CodeEnum.ERRORQR);
|
||||
} else if ("01".equals(payTypeCode)) {
|
||||
return Result.fail(CodeEnum.ERRORQR);
|
||||
} else {
|
||||
return Result.fail(CodeEnum.ERRORQR);
|
||||
}
|
||||
}
|
||||
|
||||
int count = tbShopPayTypeMapper.countSelectByShopIdAndPayType(orderInfo.getShopId(), qpay);
|
||||
if (count < 1) {
|
||||
return Result.fail(CodeEnum.PAYTYPENOEXIST);
|
||||
}
|
||||
|
||||
utils.runFunAndTransactional(() -> {
|
||||
TbOrderPayment payment = tbOrderPaymentMapper.selectByOrderId(orderId);
|
||||
if (ObjectUtil.isEmpty(payment) || payment == null) {
|
||||
payment = new TbOrderPayment();
|
||||
@@ -412,16 +417,33 @@ public class PayService {
|
||||
log.info("更新购物车:{}", cartCount);
|
||||
|
||||
if (ObjectUtil.isNotNull(orderInfo.getDiscountRatio()) && ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())) {
|
||||
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", orderInfo.getDiscountRatio());
|
||||
tbOrderDetailMapper.updateStatusByOrderId(Integer.parseInt(orderId), "closed", orderInfo.getDiscountRatio());
|
||||
} else {
|
||||
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", null);
|
||||
tbOrderDetailMapper.updateStatusByOrderId(Integer.parseInt(orderId), "closed", null);
|
||||
}
|
||||
} else if ("TRADE_AWAIT".equals(mainScanResp.getState())) {
|
||||
payment.setTradeNumber(mainScanResp.getPayOrderId());
|
||||
log.info("支付中2:{}", JSON.toJSONString(payment));
|
||||
orderInfo.setStatus("paying");
|
||||
orderInfo.setPayOrderNo(payment.getTradeNumber());
|
||||
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
||||
int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final");
|
||||
|
||||
payment.setUpdatedAt(System.currentTimeMillis());
|
||||
tbOrderPaymentMapper.updateByPrimaryKeySelective(payment);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("token", token);
|
||||
jsonObject.put("type", "create");
|
||||
jsonObject.put("orderId", orderId);
|
||||
|
||||
producer.putOrderCollect(jsonObject.toJSONString());
|
||||
|
||||
// 打印消息
|
||||
@@ -433,48 +455,13 @@ public class PayService {
|
||||
}
|
||||
rabbitMsgUtils.printPlaceTicket(orderInfo.getId(), false);
|
||||
|
||||
// 打印结算单
|
||||
// 打印结算单
|
||||
String tableCartKey = RedisCst.getCurrentOrderKey(orderInfo.getTableId(),
|
||||
orderInfo.getShopId());
|
||||
redisUtil.del(tableCartKey);
|
||||
clearTableInfoCache(orderInfo);
|
||||
|
||||
return Result.success(CodeEnum.SUCCESS, mainScanResp);
|
||||
} else if ("TRADE_AWAIT".equals(mainScanResp.getState())) {
|
||||
payment.setTradeNumber(mainScanResp.getPayOrderId());
|
||||
log.info("支付中2:{}", JSON.toJSONString(payment));
|
||||
orderInfo.setStatus("paying");
|
||||
orderInfo.setPayOrderNo(payment.getTradeNumber());
|
||||
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
||||
int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final");
|
||||
|
||||
|
||||
payment.setUpdatedAt(System.currentTimeMillis());
|
||||
tbOrderPaymentMapper.updateByPrimaryKeySelective(payment);
|
||||
|
||||
// 打印结算单
|
||||
// 打印消息
|
||||
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);
|
||||
String tableCartKey = RedisCst.getCurrentOrderKey(orderInfo.getTableId(),
|
||||
orderInfo.getShopId());
|
||||
redisUtil.del(tableCartKey);
|
||||
clearTableInfoCache(orderInfo);
|
||||
|
||||
return Result.success(CodeEnum.PAYING);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return Result.fail("失败");
|
||||
return Result.success(SUCCESS);
|
||||
}
|
||||
|
||||
public Result queryOrder(String orderId, String token) {
|
||||
@@ -567,7 +554,6 @@ public class PayService {
|
||||
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Result accountPay(String orderId, String memberId, String token, String memberAccount, BigDecimal payAmount, BigDecimal discountAmount) {
|
||||
if (ObjectUtil.isEmpty(orderId)) {
|
||||
if (ObjectUtil.isEmpty(memberAccount)) {
|
||||
@@ -628,7 +614,6 @@ public class PayService {
|
||||
|
||||
|
||||
if (ObjectUtil.isNotEmpty(memberAccount)) {
|
||||
|
||||
if (!memberAccount.startsWith("46")) {
|
||||
return Result.fail(CodeEnum.ERRORQR);
|
||||
}
|
||||
@@ -645,7 +630,6 @@ public class PayService {
|
||||
if (N.gt(orderInfo.getOrderAmount(), user.getAmount())) {
|
||||
return Result.fail(CodeEnum.MEMBERINSUFFICIENTFUNDS);
|
||||
}
|
||||
|
||||
if (ObjectUtil.isEmpty(payAmount) || ObjectUtil.isNull(payAmount)) {
|
||||
payAmount = orderInfo.getOrderAmount();
|
||||
}
|
||||
@@ -653,27 +637,28 @@ public class PayService {
|
||||
user.setConsumeAmount(user.getConsumeAmount().add(payAmount));
|
||||
user.setConsumeNumber(user.getConsumeNumber() + 1);
|
||||
user.setUpdatedAt(System.currentTimeMillis());
|
||||
tbShopUserMapper.updateByPrimaryKeySelective(user);
|
||||
|
||||
|
||||
TbShopUser finalUser = user;
|
||||
BigDecimal finalPayAmount = payAmount;
|
||||
TbShopUserFlow flow = new TbShopUserFlow();
|
||||
flow.setShopUserId(user.getId());
|
||||
utils.runFunAndTransactional(() -> {
|
||||
tbShopUserMapper.updateByPrimaryKeySelective(finalUser);
|
||||
flow.setShopUserId(finalUser.getId());
|
||||
flow.setBizCode("accountPay");
|
||||
flow.setBizName("余额支付");
|
||||
flow.setType("-");
|
||||
flow.setAmount(payAmount);
|
||||
flow.setBalance(user.getAmount());
|
||||
flow.setAmount(finalPayAmount);
|
||||
flow.setBalance(finalUser.getAmount());
|
||||
flow.setCreateTime(new Date());
|
||||
flow.setIsReturn("0");
|
||||
tbShopUserFlowMapper.insert(flow);
|
||||
|
||||
|
||||
orderInfo.setPayAmount(ObjectUtil.isEmpty(payAmount) ? orderInfo.getOrderAmount() : payAmount);
|
||||
orderInfo.setPayAmount(ObjectUtil.isEmpty(finalPayAmount) ? orderInfo.getOrderAmount() : finalPayAmount);
|
||||
orderInfo.setDiscountAmount(ObjectUtil.isEmpty(discountAmount) ? null : discountAmount);
|
||||
orderInfo.setDiscountRatio(ObjectUtil.isNotEmpty(payAmount) ? payAmount.divide(orderInfo.getOrderAmount(), 2, RoundingMode.HALF_UP).setScale(2, RoundingMode.HALF_DOWN) : null);
|
||||
orderInfo.setDiscountRatio(ObjectUtil.isNotEmpty(finalPayAmount) ? finalPayAmount.divide(orderInfo.getOrderAmount(), 2, RoundingMode.HALF_UP).setScale(2, RoundingMode.HALF_DOWN) : null);
|
||||
orderInfo.setStaffId(ObjectUtil.isEmpty(staff) ? null : staff.getId());
|
||||
orderInfo.setUserId(user.getUserId());
|
||||
orderInfo.setMemberId(user.getId().toString());
|
||||
orderInfo.setUserId(finalUser.getUserId());
|
||||
orderInfo.setMemberId(finalUser.getId().toString());
|
||||
orderInfo.setPayType("deposit");
|
||||
orderInfo.setStatus("closed");
|
||||
orderInfo.setPayOrderNo("deposit".concat(SnowFlakeUtil.generateOrderNo()));
|
||||
@@ -682,15 +667,15 @@ public class PayService {
|
||||
int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final");
|
||||
|
||||
if (ObjectUtil.isNotNull(orderInfo.getDiscountRatio()) && ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())) {
|
||||
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", orderInfo.getDiscountRatio());
|
||||
tbOrderDetailMapper.updateStatusByOrderId(Integer.parseInt(orderId), "closed", orderInfo.getDiscountRatio());
|
||||
} else {
|
||||
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", null);
|
||||
tbOrderDetailMapper.updateStatusByOrderId(Integer.parseInt(orderId), "closed", null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
log.info("更新购物车:{}", cartCount);
|
||||
|
||||
return null;
|
||||
});
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("token", token);
|
||||
jsonObject.put("type", "create");
|
||||
@@ -905,6 +890,7 @@ public class PayService {
|
||||
}
|
||||
|
||||
|
||||
utils.runFunAndTransactional(() -> {
|
||||
TbShopUserFlow userFlow = new TbShopUserFlow();
|
||||
userFlow.setAmount((payAmount != null && discountAmount != null) ? payAmount : orderInfo.getOrderAmount());
|
||||
userFlow.setBalance(shopUser.getAmount().subtract((payAmount != null && discountAmount != null) ? payAmount : orderInfo.getOrderAmount()));
|
||||
@@ -941,6 +927,9 @@ public class PayService {
|
||||
}
|
||||
|
||||
log.info("更新购物车:{}", cartCount);
|
||||
return null;
|
||||
});
|
||||
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("token", token);
|
||||
@@ -1036,9 +1025,6 @@ public class PayService {
|
||||
return orderInfo;
|
||||
});
|
||||
|
||||
log.info("事务已提交");
|
||||
ThreadUtil.sleep(10, TimeUnit.SECONDS);
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("token", token);
|
||||
jsonObject.put("type", "create");
|
||||
|
||||
Reference in New Issue
Block a user