|
|
@@ -613,11 +613,8 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
|
|
|
// 开启编程式事务
|
|
|
status = transactionManager.getTransaction(new DefaultTransactionDefinition());
|
|
|
|
|
|
- // 计算订单顺序号
|
|
|
- order.setOrderSequence(String.format("%04d", selectCurrentOrderSequenceByShopId(order, order.getShopId())));
|
|
|
-
|
|
|
- // 更新订单状态
|
|
|
- updateById(order);
|
|
|
+ // 更新订单状态及订单序号
|
|
|
+ updateOrderStatusAndSequence(order);
|
|
|
|
|
|
// 扣减库存
|
|
|
this.subStock(order);
|
|
|
@@ -2598,18 +2595,18 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取当前店铺当前订单在已支付订单中的序号
|
|
|
+ * 更新订单状态和支付顺序
|
|
|
* @param order 订单信息
|
|
|
- * @param shopId 店铺id
|
|
|
- * @return 支付顺序
|
|
|
*/
|
|
|
- private int selectCurrentOrderSequenceByShopId(TbOrder order, Long shopId) {
|
|
|
+ private void updateOrderStatusAndSequence(TbOrder order) {
|
|
|
+ Long shopId = order.getShopId();
|
|
|
RLock lock = redissonClient.getLock(String.format(RedisKey.ORDER_SEQUENCE_LOCK, shopId));
|
|
|
lock.lock();
|
|
|
try {
|
|
|
int count = appOrderDao.countCurDayPayByShopId(shopId, order.getPayTime());
|
|
|
+ order.setOrderSequence(String.format("%04d", count + 1));
|
|
|
|
|
|
- return count + 1;
|
|
|
+ updateById(order);
|
|
|
} finally {
|
|
|
lock.unlock();
|
|
|
}
|