TASK:买家端/卖家端接入支付服务

This commit is contained in:
2026-05-26 17:41:18 +08:00
parent ab552fc414
commit 941e1e04af
8 changed files with 95 additions and 8 deletions

View File

@@ -176,6 +176,11 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
</dependencies>
<build>

View File

@@ -9,6 +9,7 @@ import com.aida.seller.module.order.dto.CreateOrderDTO;
import com.aida.seller.module.order.dto.OrderListDTO;
import com.aida.seller.module.order.dto.BuyerOrdersDTO;
import com.aida.seller.module.order.dto.UpdateOrderStatusDTO;
import com.aida.seller.module.order.dto.UpdatePaymentIdDTO;
import com.aida.seller.module.order.service.OrderService;
import com.aida.seller.module.order.vo.AssetsItemVO;
import com.aida.seller.module.order.vo.BuyerOrderVO;
@@ -96,4 +97,13 @@ public class OrderController {
public Response<PageResponse<AssetsItemVO>> getAssetsPage(@RequestBody AssetsDTO dto) {
return Response.success(PageResponse.success(orderService.getAssetsPage(dto)));
}
@InternalOnly
@PutMapping("/payment-id/batch")
@Operation(summary = "批量回填PaymentId仅内部服务调用")
public Response<Void> updatePaymentIdByIds(@RequestBody UpdatePaymentIdDTO dto) {
orderService.updatePaymentIdByIds(dto.getOrderIds(), dto.getPaymentId());
return Response.success();
}
}

View File

@@ -2,22 +2,29 @@ package com.aida.seller.module.order.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.List;
/**
* 批量修改订单状态请求参数
*/
@Data
@NoArgsConstructor
@Schema(description = "批量修改订单状态请求参数")
public class UpdateOrderStatusDTO implements Serializable {
private static final long serialVersionUID = 1L;
@Schema(description = "交易流水号")
private Long paymentId;
@Schema(description = "订单ID列表")
private List<Long> orderIds;
@Schema(description = "目标状态0-未支付1-已支付2-已取消")
private Integer status;
public UpdateOrderStatusDTO(Integer status, Long paymentId) {
this.status = status;
this.paymentId = paymentId;
}
}

View File

@@ -0,0 +1,23 @@
package com.aida.seller.module.order.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* 批量回填PaymentId请求参数
*/
@Data
@Schema(description = "批量回填PaymentId请求参数")
public class UpdatePaymentIdDTO implements Serializable {
private static final long serialVersionUID = 1L;
@Schema(description = "订单ID列表")
private List<Long> orderIds;
@Schema(description = "支付单ID")
private Long paymentId;
}

View File

@@ -57,4 +57,7 @@ public class OrderInfoEntity implements Serializable {
/** 是否删除0-否1-是 */
@TableLogic
private Integer deleted;
/** 交易流水号 */
private String paymentId;
}

View File

@@ -75,4 +75,11 @@ public interface OrderService {
* @return 已购买的商品ID列表
*/
List<Long> getPurchasedListingIds(List<Long> listingIds, Long buyerId);
/**
* 根据订单号回填交易流水号
* @param orderIds 订单编号列表
* @param paymentId 交易流水号(仅供内部使用,不对外)
*/
void updatePaymentIdByIds(List<Long> orderIds, Long paymentId);
}

View File

@@ -28,6 +28,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
@@ -43,6 +44,7 @@ import java.util.stream.Collectors;
/**
* 订单服务实现
*/
@Slf4j
@Service
@RequiredArgsConstructor
public class OrderServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfoEntity> implements OrderService {
@@ -296,19 +298,31 @@ public class OrderServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
@Override
@Transactional(rollbackFor = Exception.class)
public void updateOrderStatus(UpdateOrderStatusDTO dto) {
if (dto == null || dto.getOrderIds() == null || dto.getOrderIds().isEmpty()) {
throw new BusinessException("订单ID列表不能为空");
if (dto == null) {
throw new BusinessException("订单信息为空");
}
if (dto.getStatus() == null) {
throw new BusinessException("订单状态不能为空");
}
if (dto.getPaymentId() == null && (dto.getOrderIds() == null || dto.getOrderIds().isEmpty())) {
throw new BusinessException("订单ID列表不能为空");
}
boolean updated;
LambdaUpdateWrapper<OrderInfoEntity> updateWrapper = new LambdaUpdateWrapper<>();
if (dto.getPaymentId() != null) {
updateWrapper.eq(OrderInfoEntity::getPaymentId, dto.getPaymentId())
.set(OrderInfoEntity::getStatus, dto.getStatus());
} else {
updateWrapper.in(OrderInfoEntity::getId, dto.getOrderIds())
.set(OrderInfoEntity::getStatus, dto.getStatus());
boolean updated = this.update(updateWrapper);
}
updated = this.update(updateWrapper);
if (!updated) {
throw new BusinessException("订单不存在或无权修改");
} else {
log.info("[Order] PaymentId:{} / OrderId:{}, 更新订单状态", dto.getPaymentId(), dto.getOrderIds());
}
}
@@ -346,4 +360,15 @@ public class OrderServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
.distinct()
.collect(Collectors.toList());
}
@Override
public void updatePaymentIdByIds(List<Long> orderIds, Long paymentId) {
if (CollectionUtils.isEmpty(orderIds)) {
throw new BusinessException("订单ID列表不能为空");
}
LambdaUpdateWrapper<OrderInfoEntity> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.in(OrderInfoEntity::getId, orderIds)
.set(OrderInfoEntity::getPaymentId, paymentId);
this.update(updateWrapper);
}
}

View File

@@ -18,6 +18,9 @@ CREATE TABLE seller_listing (
INDEX idx_deleted (deleted)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='商品表';
ALTER TABLE seller_listing
ADD COLUMN sales_volume INT DEFAULT 0 COMMENT '销量';
-- 商品图片表
CREATE TABLE seller_listing_image (
id BIGINT PRIMARY KEY COMMENT '图片ID',
@@ -93,3 +96,7 @@ CREATE TABLE seller_order_item (
INDEX idx_listing_id (listing_id),
INDEX idx_deleted (deleted)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='订单商品明细表';
-- 新增 payment_id 字段
ALTER TABLE seller_orders
ADD COLUMN payment_id VARCHAR(64) DEFAULT NULL COMMENT '交易流水号(关联支付表)';