diff --git a/pom.xml b/pom.xml
index 34197b1..acd1de8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -11,7 +11,7 @@
com.imyeyu.timiserverapi
TimiServerAPI
- 1.0.61
+ 1.0.62
jar
TimiServerAPI
imyeyu.com API
diff --git a/src/main/java/com/imyeyu/api/modules/gao/bean/GaoPermissionCode.java b/src/main/java/com/imyeyu/api/modules/gao/bean/GaoPermissionCode.java
index 4a8bb47..179198c 100644
--- a/src/main/java/com/imyeyu/api/modules/gao/bean/GaoPermissionCode.java
+++ b/src/main/java/com/imyeyu/api/modules/gao/bean/GaoPermissionCode.java
@@ -99,6 +99,8 @@ public enum GaoPermissionCode implements BuiltinPermissionCode {
ORDER_FULFILLMENT_REVOKE("ORDER_FULFILLMENT:REVOKE", "统一履约冲正", true, true),
+ ORDER_FULFILLMENT_RETURN("ORDER_FULFILLMENT:RETURN", "统一履约退货", true, true),
+
PACKAGE_CONFIG_CREATE("PACKAGE_CONFIG:CREATE", "套餐配置创建", true, true),
PACKAGE_CONFIG_READ("PACKAGE_CONFIG:READ", "套餐配置读取", true, true),
diff --git a/src/main/java/com/imyeyu/api/modules/gao/controller/GaoDataExportController.java b/src/main/java/com/imyeyu/api/modules/gao/controller/GaoDataExportController.java
index 63e2b51..a18815f 100644
--- a/src/main/java/com/imyeyu/api/modules/gao/controller/GaoDataExportController.java
+++ b/src/main/java/com/imyeyu/api/modules/gao/controller/GaoDataExportController.java
@@ -7,12 +7,8 @@ import com.imyeyu.api.modules.gao.export.GaoDataExportStatRequest;
import com.imyeyu.api.modules.gao.export.GaoDataExportStatView;
import com.imyeyu.api.modules.gao.export.GaoDataExportTaskView;
import com.imyeyu.api.modules.gao.service.GaoDataExportService;
-import com.imyeyu.network.Network;
-import com.imyeyu.spring.TimiSpring;
import com.imyeyu.spring.annotation.AOPLog;
-import com.imyeyu.spring.annotation.IgnoreGlobalReturn;
import com.imyeyu.spring.annotation.RequestRateLimit;
-import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@@ -21,8 +17,6 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
-import java.io.IOException;
-
/// GAO 店长数据导出接口
///
/// @author Codex
@@ -69,20 +63,4 @@ public class GaoDataExportController {
public GaoDataExportTaskView detail(@PathVariable String taskId) {
return service.detail(taskId);
}
-
- /// 下载已完成的导出 ZIP
- ///
- /// @param taskId 任务 ID
- /// @throws IOException 写入响应失败
- @AOPLog
- @RequestRateLimit
- @IgnoreGlobalReturn
- @RequireGaoPermission(GaoPermissionCode.DATA_EXPORT)
- @GetMapping("/task/{taskId}/download")
- public void download(@PathVariable String taskId) throws IOException {
- HttpServletResponse response = TimiSpring.getResponse();
- response.setContentType("application/zip");
- response.setHeader("Content-Disposition", Network.getFileDownloadHeader("GAO数据导出.zip"));
- service.download(taskId, response.getOutputStream());
- }
}
diff --git a/src/main/java/com/imyeyu/api/modules/gao/controller/GaoOrderFulfillmentController.java b/src/main/java/com/imyeyu/api/modules/gao/controller/GaoOrderFulfillmentController.java
index 5d5227e..1f21e3c 100644
--- a/src/main/java/com/imyeyu/api/modules/gao/controller/GaoOrderFulfillmentController.java
+++ b/src/main/java/com/imyeyu/api/modules/gao/controller/GaoOrderFulfillmentController.java
@@ -15,6 +15,7 @@ import com.imyeyu.api.modules.gao.vo.GaoOrderFulfillmentCreateRequest;
import com.imyeyu.api.modules.gao.vo.GaoOrderFulfillmentPage;
import com.imyeyu.api.modules.gao.vo.GaoOrderFulfillmentPrepareStockRequest;
import com.imyeyu.api.modules.gao.vo.GaoOrderFulfillmentRevokeRequest;
+import com.imyeyu.api.modules.gao.vo.GaoOrderFulfillmentReturnRequest;
import com.imyeyu.api.modules.gao.vo.GaoQuickFulfillmentCreateRequest;
import com.imyeyu.api.modules.gao.vo.GaoQuickFulfillmentCustomerRequest;
import com.imyeyu.api.modules.gao.vo.GaoQuickFulfillmentSkuView;
@@ -182,6 +183,16 @@ public class GaoOrderFulfillmentController {
return result;
}
+ @AOPLog
+ @RequestRateLimit
+ @RequireGaoPermission(GaoPermissionCode.ORDER_FULFILLMENT_RETURN)
+ @PostMapping("/return")
+ public GaoOrderFulfillment returnGoods(@RequestBody GaoOrderFulfillmentReturnRequest request) {
+ GaoOrderFulfillment result = service.returnGoods(request);
+ fillTransient(List.of(result));
+ return result;
+ }
+
private void fillTransient(List fulfillmentList) {
if (fulfillmentList == null || fulfillmentList.isEmpty()) {
return;
diff --git a/src/main/java/com/imyeyu/api/modules/gao/entity/GaoFundRecord.java b/src/main/java/com/imyeyu/api/modules/gao/entity/GaoFundRecord.java
index f4eb139..3ec153f 100644
--- a/src/main/java/com/imyeyu/api/modules/gao/entity/GaoFundRecord.java
+++ b/src/main/java/com/imyeyu/api/modules/gao/entity/GaoFundRecord.java
@@ -52,7 +52,7 @@ public class GaoFundRecord extends UUIDEntity {
/// 店长已拒绝
REJECTED,
- /// 提交人已撤销
+ /// 核销前已撤销
CANCELLED
}
diff --git a/src/main/java/com/imyeyu/api/modules/gao/entity/GaoOrderFulfillment.java b/src/main/java/com/imyeyu/api/modules/gao/entity/GaoOrderFulfillment.java
index 48f260d..a67c0a5 100644
--- a/src/main/java/com/imyeyu/api/modules/gao/entity/GaoOrderFulfillment.java
+++ b/src/main/java/com/imyeyu/api/modules/gao/entity/GaoOrderFulfillment.java
@@ -34,11 +34,14 @@ public class GaoOrderFulfillment implements IDEntity, Creatable, Updatab
/// 店长已拒绝
REJECTED,
- /// 提交人已撤销
+ /// 核销前已撤销
CANCELLED,
/// 已核销后冲正
- REVOKED
+ REVOKED,
+
+ /// 已退货
+ RETURNED
}
@Id
@@ -66,13 +69,16 @@ public class GaoOrderFulfillment implements IDEntity, Creatable, Updatab
/// 实际履约时间
private Long deliveredAt;
+ /// 退货时间
+ private Long returnedAt;
+
/// 核销或拒绝操作人
private String verifierUserId;
/// 核销或拒绝时间
private Long verifiedAt;
- /// 冲正单指向原履约单
+ /// 退货或冲正单指向原履约单
private String sourceFulfillmentId;
/// 拒绝、撤销或冲正原因
diff --git a/src/main/java/com/imyeyu/api/modules/gao/entity/GaoProductStockRecord.java b/src/main/java/com/imyeyu/api/modules/gao/entity/GaoProductStockRecord.java
index fa696d9..48894eb 100644
--- a/src/main/java/com/imyeyu/api/modules/gao/entity/GaoProductStockRecord.java
+++ b/src/main/java/com/imyeyu/api/modules/gao/entity/GaoProductStockRecord.java
@@ -60,6 +60,9 @@ public class GaoProductStockRecord implements IDEntity, Creatable {
/// 履约冲正入库
ORDER_REVOKE,
+ /// 履约退货入库
+ ORDER_RETURN_IN,
+
/// 积分兑换实物出库
POINT_REDEMPTION_OUT,
diff --git a/src/main/java/com/imyeyu/api/modules/gao/service/GaoDataExportService.java b/src/main/java/com/imyeyu/api/modules/gao/service/GaoDataExportService.java
index 454a532..d4d7b71 100644
--- a/src/main/java/com/imyeyu/api/modules/gao/service/GaoDataExportService.java
+++ b/src/main/java/com/imyeyu/api/modules/gao/service/GaoDataExportService.java
@@ -6,9 +6,6 @@ import com.imyeyu.api.modules.gao.export.GaoDataExportStatView;
import com.imyeyu.api.modules.gao.export.GaoDataExportTaskView;
import com.imyeyu.api.modules.gao.task.async.GaoDataExportAsyncTask;
-import java.io.IOException;
-import java.io.OutputStream;
-
///
/// GAO 数据导出服务
///
@@ -34,13 +31,6 @@ public interface GaoDataExportService {
/// @return 任务视图
GaoDataExportTaskView detail(String taskId);
- /// 下载已完成的导出文件
- ///
- /// @param taskId 任务 ID
- /// @param output 输出流
- /// @throws IOException 写入异常
- void download(String taskId, OutputStream output) throws IOException;
-
/// 执行异步导出任务
///
/// @param task 异步任务
diff --git a/src/main/java/com/imyeyu/api/modules/gao/service/GaoOrderFulfillmentService.java b/src/main/java/com/imyeyu/api/modules/gao/service/GaoOrderFulfillmentService.java
index b923030..23f338e 100644
--- a/src/main/java/com/imyeyu/api/modules/gao/service/GaoOrderFulfillmentService.java
+++ b/src/main/java/com/imyeyu/api/modules/gao/service/GaoOrderFulfillmentService.java
@@ -6,6 +6,7 @@ import com.imyeyu.api.modules.gao.vo.GaoOrderFulfillmentCreateRequest;
import com.imyeyu.api.modules.gao.vo.GaoOrderFulfillmentPage;
import com.imyeyu.api.modules.gao.vo.GaoOrderFulfillmentPrepareStockRequest;
import com.imyeyu.api.modules.gao.vo.GaoOrderFulfillmentRevokeRequest;
+import com.imyeyu.api.modules.gao.vo.GaoOrderFulfillmentReturnRequest;
import com.imyeyu.api.modules.gao.vo.GaoQuickFulfillmentCreateRequest;
import com.imyeyu.api.modules.gao.vo.GaoQuickFulfillmentCustomerRequest;
import com.imyeyu.api.modules.gao.vo.GaoQuickFulfillmentSkuView;
@@ -34,6 +35,12 @@ public interface GaoOrderFulfillmentService extends BaseService revokeForFulfillment(String storeId, String bizId, List items, String requestNo, String operatorUserId);
+ /// 履约退货入库
+ List returnForFulfillment(String storeId, String bizId, List items, String requestNo, String operatorUserId);
+
/// 为积分兑换实物出库
GaoProductStockRecord outForRedemption(String storeId, String redemptionId, GaoStockChangeItem item, String requestNo, String operatorUserId);
diff --git a/src/main/java/com/imyeyu/api/modules/gao/service/implement/GaoDataExportServiceImplement.java b/src/main/java/com/imyeyu/api/modules/gao/service/implement/GaoDataExportServiceImplement.java
index a88c5d1..190e8b2 100644
--- a/src/main/java/com/imyeyu/api/modules/gao/service/implement/GaoDataExportServiceImplement.java
+++ b/src/main/java/com/imyeyu/api/modules/gao/service/implement/GaoDataExportServiceImplement.java
@@ -129,25 +129,6 @@ public class GaoDataExportServiceImplement implements GaoDataExportService {
return toTaskView(task, metadata, readResult(task));
}
- @Override
- public void download(String taskId, OutputStream output) throws IOException {
- AsyncTask task = requireOwnedTask(taskId);
- TimiException.requiredTrue(task.getStatus() == AsyncTask.Status.SUCCESS, "导出任务尚未完成");
- TimiException.requiredTrue(Time.now() < task.getExpiresAt(), "导出文件已过期");
- GaoDataExportResultView result = readResult(task);
- TimiException.required(result, "未找到导出结果文件");
- Attachment attachment = attachmentService.get(result.getAttachmentId());
- TimiException.required(attachment, "导出结果文件已失效");
- TimiException.requiredTrue(Attachment.BizType.GAO_DATA_EXPORT == attachment.getBizType() && taskId.equals(attachment.getBizId()), "导出结果文件无权访问");
- try (InputStream input = new BufferedInputStream(attachmentService.getInputStreamByMongoId(attachment.getMongoId()))) {
- byte[] buffer = new byte[32 * 1024];
- int length;
- while ((length = input.read(buffer)) != -1) {
- output.write(buffer, 0, length);
- }
- }
- }
-
@Override
public void execute(GaoDataExportAsyncTask task) throws Exception {
AsyncTask record = asyncTaskService.getTaskRecord(task.getId());
diff --git a/src/main/java/com/imyeyu/api/modules/gao/service/implement/GaoOrderFulfillmentServiceImplement.java b/src/main/java/com/imyeyu/api/modules/gao/service/implement/GaoOrderFulfillmentServiceImplement.java
index eb5dd6b..b8c78dd 100644
--- a/src/main/java/com/imyeyu/api/modules/gao/service/implement/GaoOrderFulfillmentServiceImplement.java
+++ b/src/main/java/com/imyeyu/api/modules/gao/service/implement/GaoOrderFulfillmentServiceImplement.java
@@ -33,6 +33,7 @@ import com.imyeyu.api.modules.gao.vo.GaoOrderFulfillmentItemRequest;
import com.imyeyu.api.modules.gao.vo.GaoOrderFulfillmentPage;
import com.imyeyu.api.modules.gao.vo.GaoOrderFulfillmentPrepareStockRequest;
import com.imyeyu.api.modules.gao.vo.GaoOrderFulfillmentRevokeRequest;
+import com.imyeyu.api.modules.gao.vo.GaoOrderFulfillmentReturnRequest;
import com.imyeyu.api.modules.gao.vo.GaoProductSkuUnitSelection;
import com.imyeyu.api.modules.gao.vo.GaoQuickFulfillmentCreateItemRequest;
import com.imyeyu.api.modules.gao.vo.GaoQuickFulfillmentCreateRequest;
@@ -168,6 +169,23 @@ public class GaoOrderFulfillmentServiceImplement extends AbstractEntityService listQuickFulfillmentSku(GaoQuickFulfillmentCustomerRequest request) {
TimiException.required(request, "快速履约客户查询请求不能为空");
@@ -652,6 +670,79 @@ public class GaoOrderFulfillmentServiceImplement extends AbstractEntityService sourceItemList = itemMapper.selectByFulfillmentId(sourceSnapshot.getId());
+ List sourceList = loadPersistedSources(order, sourceItemList);
+ GaoOrderFulfillment source = lockFulfillment(sourceSnapshot.getId(), order);
+ storeScopeService.checkStoreId(source.getStoreId());
+ TimiException.requiredTrue(source.getStatus() == GaoOrderFulfillment.Status.VERIFIED && source.getSourceFulfillmentId() == null,
+ "只有原始已核销履约可以退货");
+ TimiException.requiredNull(mapper.selectBySourceFulfillmentId(source.getId()), "该履约单已经退货或冲正");
+ sourceItemList = itemMapper.selectByFulfillmentIdForUpdate(source.getId());
+ TimiException.requiredTrue(!sourceItemList.isEmpty(), "履约单没有明细");
+ TimiException.requiredTrue(hasAttachment(request.getAttachmentList()), "退货必须上传照片");
+ List stockItems = buildStockItems(order.getStoreId(), sourceList);
+ if (!stockItems.isEmpty()) {
+ TimiException.requiredTrue(Boolean.TRUE.equals(request.getReturnedToStore()), "实物履约退货必须确认已退回门店");
+ }
+ String operatorUserId = userLoginService.getRequireLoginUserId();
+ Long returnedAt = TimiJava.defaultIfNull(request.getReturnedAt(), Time.now());
+ GaoOrderFulfillment returned = newFulfillment(order, GaoOrderFulfillment.Status.RETURNED,
+ requestNo, operatorUserId, returnedAt, request.getRemark());
+ returned.setReturnedAt(returnedAt);
+ returned.setVerifierUserId(operatorUserId);
+ returned.setVerifiedAt(Time.now());
+ returned.setSourceFulfillmentId(source.getId());
+ returned.setReason(reason);
+ super.create(returned);
+ Map sourceItemMap = new HashMap<>();
+ for (GaoOrderFulfillmentItem sourceItem : sourceItemList) {
+ sourceItemMap.put(sourceItem.getSourceOrderItemId(), sourceItem);
+ }
+ for (SourceEntry sourceEntry : sourceList) {
+ decreaseFulfilled(sourceEntry);
+ GaoOrderFulfillmentItem sourceItem = sourceItemMap.get(sourceEntry.sourceId());
+ TimiException.required(sourceItem, "履约明细来源订单项不存在");
+ GaoOrderFulfillmentItem returnItem = copyFulfillmentItem(sourceItem);
+ returnItem.setFulfillmentId(returned.getId());
+ returnItem.setReservedBaseBefore(sourceEntry.reservedBaseBefore());
+ returnItem.setReservedBaseAfter(sourceEntry.reservedBaseBefore());
+ returnItem.setFulfilledBaseBefore(sourceEntry.fulfilledBaseBefore());
+ returnItem.setFulfilledBaseAfter(sourceEntry.fulfilledBaseBefore().subtract(sourceEntry.baseQuantity()));
+ itemMapper.insert(returnItem);
+ }
+ if (!stockItems.isEmpty()) {
+ for (GaoStockChangeItem item : stockItems) {
+ GaoProductStockRecord stockRecord = stockRecordService.getByBizSku(GaoProductStockRecord.BizType.ORDER_FULFILLMENT,
+ source.getId(), item.getSkuId(), GaoProductStockRecord.OperationType.ORDER_OUT);
+ TimiException.required(stockRecord, "履约出库流水不存在");
+ item.setSourceRecordId(stockRecord.getId());
+ item.setSkuSpecSnapshot(stockRecord.getSkuSpecSnapshot());
+ }
+ productStockService.returnForFulfillment(order.getStoreId(), returned.getId(), stockItems,
+ stockRequestNo(returned, "RETURN"), operatorUserId);
+ }
+ attachmentService.updateByBizId(Attachment.BizType.GAO_ORDER_FULFILLMENT, returned.getId(), request.getAttachmentList());
+ salesOrderService.refreshFulfillmentStatus(order);
+ return detail(returned.getId());
+ }
+
private GaoOrderFulfillment newFulfillment(GaoSalesOrder order, GaoOrderFulfillment.Status status,
String requestNo, String operatorUserId, Long deliveredAt, String remark) {
GaoOrderFulfillment result = new GaoOrderFulfillment();
diff --git a/src/main/java/com/imyeyu/api/modules/gao/service/implement/GaoOrderPaymentServiceImplement.java b/src/main/java/com/imyeyu/api/modules/gao/service/implement/GaoOrderPaymentServiceImplement.java
index db2e564..2707e2a 100644
--- a/src/main/java/com/imyeyu/api/modules/gao/service/implement/GaoOrderPaymentServiceImplement.java
+++ b/src/main/java/com/imyeyu/api/modules/gao/service/implement/GaoOrderPaymentServiceImplement.java
@@ -109,9 +109,12 @@ public class GaoOrderPaymentServiceImplement implements GaoOrderPaymentService {
@Transactional(TimiServerDBConfig.ROLLBACKER)
@Override
public GaoFundRecord verify(String fundRecordId) {
+ GaoFundRecord snapshot = fundRecordService.detail(fundRecordId);
+ TimiException.requiredTrue(snapshot.getBizType() == GaoFundRecord.BizType.SALES_ORDER, "资金记录不是销售订单资金");
+ GaoSalesOrder order = orderService.getForUpdate(snapshot.getBizId());
GaoFundRecord record = lockOrderRecord(fundRecordId);
+ TimiException.requiredTrue(order.getId().equals(record.getBizId()), "资金流水所属订单已变化");
TimiException.requiredTrue(record.getOperationType() == GaoFundRecord.OperationType.RECEIVE && record.getStatus() == GaoFundRecord.Status.PENDING, "收款记录不是待核销状态");
- GaoSalesOrder order = orderService.getForUpdate(record.getBizId());
Long paidAtBefore = order.getPaidAt();
order.setPendingPaidAmount(safe(order.getPendingPaidAmount()) - record.getAmount());
order.setPaidAmount(safe(order.getPaidAmount()) + record.getAmount());
@@ -144,16 +147,37 @@ public class GaoOrderPaymentServiceImplement implements GaoOrderPaymentService {
return releasePending(request, GaoFundRecord.Status.CANCELLED, onlyOperator);
}
+ @Transactional(TimiServerDBConfig.ROLLBACKER)
+ @Override
+ public void cancelPendingBySalesOrderId(String salesOrderId, String reason) {
+ TimiException.required(salesOrderId, "not found salesOrderId");
+ String cancelReason = requiredText(reason, "收款撤销原因不能为空");
+ for (GaoFundRecord record : fundRecordService.listByBizId(salesOrderId)) {
+ if (record.getBizType() != GaoFundRecord.BizType.SALES_ORDER
+ || record.getOperationType() != GaoFundRecord.OperationType.RECEIVE
+ || record.getStatus() != GaoFundRecord.Status.PENDING) {
+ continue;
+ }
+ GaoOrderPaymentActionRequest request = new GaoOrderPaymentActionRequest();
+ request.setFundRecordId(record.getId());
+ request.setReason(cancelReason);
+ releasePending(request, GaoFundRecord.Status.CANCELLED, false);
+ }
+ }
+
private GaoFundRecord releasePending(GaoOrderPaymentActionRequest request, GaoFundRecord.Status targetStatus, boolean onlyOperator) {
TimiException.required(request, "not found order payment action request");
TimiException.required(request.getFundRecordId(), "not found fundRecordId");
String reason = requiredText(request.getReason(), "资金操作原因不能为空");
+ GaoFundRecord snapshot = fundRecordService.detail(request.getFundRecordId());
+ TimiException.requiredTrue(snapshot.getBizType() == GaoFundRecord.BizType.SALES_ORDER, "资金记录不是销售订单资金");
+ GaoSalesOrder order = orderService.getForUpdate(snapshot.getBizId());
GaoFundRecord record = lockOrderRecord(request.getFundRecordId());
+ TimiException.requiredTrue(order.getId().equals(record.getBizId()), "资金流水所属订单已变化");
TimiException.requiredTrue(record.getOperationType() == GaoFundRecord.OperationType.RECEIVE && record.getStatus() == GaoFundRecord.Status.PENDING, "收款记录不是待核销状态");
if (onlyOperator) {
TimiException.requiredTrue(userLoginService.getRequireLoginUserId().equals(record.getOperatorUserId()), "只能撤销自己提交的收款");
}
- GaoSalesOrder order = orderService.getForUpdate(record.getBizId());
order.setPendingPaidAmount(safe(order.getPendingPaidAmount()) - record.getAmount());
orderService.recomputePaymentStatus(order);
String userId = userLoginService.getRequireLoginUserId();
diff --git a/src/main/java/com/imyeyu/api/modules/gao/service/implement/GaoProductStockServiceImplement.java b/src/main/java/com/imyeyu/api/modules/gao/service/implement/GaoProductStockServiceImplement.java
index fca9c75..cb02926 100644
--- a/src/main/java/com/imyeyu/api/modules/gao/service/implement/GaoProductStockServiceImplement.java
+++ b/src/main/java/com/imyeyu/api/modules/gao/service/implement/GaoProductStockServiceImplement.java
@@ -302,6 +302,12 @@ public class GaoProductStockServiceImplement implements GaoProductStockService {
return executeInternal(storeId, bizId, items, requestNo, operatorUserId, GaoProductStockRecord.OperationType.ORDER_REVOKE, null);
}
+ @Transactional(TimiServerDBConfig.ROLLBACKER)
+ @Override
+ public List returnForFulfillment(String storeId, String bizId, List items, String requestNo, String operatorUserId) {
+ return executeInternal(storeId, bizId, items, requestNo, operatorUserId, GaoProductStockRecord.OperationType.ORDER_RETURN_IN, null);
+ }
+
@Transactional(TimiServerDBConfig.ROLLBACKER)
@Override
public GaoProductStockRecord outForRedemption(String storeId, String redemptionId, GaoStockChangeItem item, String requestNo, String operatorUserId) {
@@ -574,7 +580,7 @@ public class GaoProductStockServiceImplement implements GaoProductStockService {
private BigDecimal onHandDelta(GaoProductStockRecord.OperationType operationType, BigDecimal quantity) {
return switch (operationType) {
- case INITIAL_IN, MANUAL_IN, STOCKTAKE_GAIN, ORDER_REVOKE, POINT_REDEMPTION_RETURN_IN -> quantity;
+ case INITIAL_IN, MANUAL_IN, STOCKTAKE_GAIN, ORDER_REVOKE, ORDER_RETURN_IN, POINT_REDEMPTION_RETURN_IN -> quantity;
case MANUAL_OUT, STOCKTAKE_LOSS, ORDER_OUT, POINT_REDEMPTION_OUT -> quantity.negate();
case ORDER_RESERVE, ORDER_RELEASE -> ZERO;
case MANUAL_REVOKE -> throw new TimiException(TimiCode.ERROR, "手工库存冲正必须基于原库存流水");
diff --git a/src/main/java/com/imyeyu/api/modules/gao/service/implement/GaoSalesOrderServiceImplement.java b/src/main/java/com/imyeyu/api/modules/gao/service/implement/GaoSalesOrderServiceImplement.java
index 566cc88..2ae034d 100644
--- a/src/main/java/com/imyeyu/api/modules/gao/service/implement/GaoSalesOrderServiceImplement.java
+++ b/src/main/java/com/imyeyu/api/modules/gao/service/implement/GaoSalesOrderServiceImplement.java
@@ -38,6 +38,8 @@ import com.imyeyu.api.modules.gao.vo.GaoCustomerProductPage;
import com.imyeyu.api.modules.gao.vo.GaoCustomerProductSummaryView;
import com.imyeyu.api.modules.gao.vo.GaoCustomerProductView;
import com.imyeyu.api.modules.gao.vo.GaoOrderFulfillmentRevokeRequest;
+import com.imyeyu.api.modules.gao.vo.GaoOrderFulfillmentReturnRequest;
+import com.imyeyu.api.modules.gao.vo.GaoOrderPaymentRefundRequest;
import com.imyeyu.api.modules.gao.vo.GaoOrderPaymentRevokeRequest;
import com.imyeyu.api.modules.gao.vo.GaoProductSkuUnitSelection;
import com.imyeyu.api.modules.gao.vo.GaoSalesOrderCancelRequest;
@@ -329,24 +331,36 @@ public class GaoSalesOrderServiceImplement extends AbstractEntityService fulfillmentRevokeList = request.getFulfillmentRevokeList();
+ List fulfillmentReturnList = request.getFulfillmentReturnList();
Set fulfillmentIdSet = new HashSet<>();
Set selectedFulfillmentIdSet = new HashSet<>();
- if (fulfillmentRevokeList != null && !fulfillmentRevokeList.isEmpty()) {
- TimiException.requiredTrue(permissionChecker.hasAny(ModuleCode.GAO, GaoPermissionCode.ORDER_FULFILLMENT_REVOKE.getValue()), "缺少履约冲正权限");
+ if ((fulfillmentRevokeList != null && !fulfillmentRevokeList.isEmpty())
+ || (fulfillmentReturnList != null && !fulfillmentReturnList.isEmpty())) {
for (GaoOrderFulfillment fulfillment : fulfillmentService.listBySalesOrderId(order.getId())) {
fulfillmentIdSet.add(fulfillment.getId());
}
+ }
+ if (fulfillmentRevokeList != null && !fulfillmentRevokeList.isEmpty()) {
+ TimiException.requiredTrue(permissionChecker.hasAny(ModuleCode.GAO, GaoPermissionCode.ORDER_FULFILLMENT_REVOKE.getValue()), "缺少履约冲正权限");
for (GaoOrderFulfillmentRevokeRequest revokeRequest : fulfillmentRevokeList) {
TimiException.required(revokeRequest, "履约冲正请求不能为空");
TimiException.required(revokeRequest.getFulfillmentId(), "not found fulfillmentId");
TimiException.requiredTrue(fulfillmentIdSet.contains(revokeRequest.getFulfillmentId()), "履约单不属于当前订单");
- TimiException.requiredTrue(selectedFulfillmentIdSet.add(revokeRequest.getFulfillmentId()), "履约单不能重复冲正");
+ TimiException.requiredTrue(selectedFulfillmentIdSet.add(revokeRequest.getFulfillmentId()), "同一履约单不能同时退货或冲正");
+ }
+ }
+ if (fulfillmentReturnList != null && !fulfillmentReturnList.isEmpty()) {
+ TimiException.requiredTrue(permissionChecker.hasAny(ModuleCode.GAO, GaoPermissionCode.ORDER_FULFILLMENT_RETURN.getValue()), "缺少履约退货权限");
+ for (GaoOrderFulfillmentReturnRequest returnRequest : fulfillmentReturnList) {
+ TimiException.required(returnRequest, "履约退货请求不能为空");
+ TimiException.required(returnRequest.getFulfillmentId(), "not found fulfillmentId");
+ TimiException.requiredTrue(fulfillmentIdSet.contains(returnRequest.getFulfillmentId()), "履约单不属于当前订单");
+ TimiException.requiredTrue(selectedFulfillmentIdSet.add(returnRequest.getFulfillmentId()), "同一履约单不能同时退货或冲正");
}
}
@@ -365,35 +379,129 @@ public class GaoSalesOrderServiceImplement extends AbstractEntityService fundRefundList = request.getFundRefundList();
+ if (fundRefundList != null && !fundRefundList.isEmpty()) {
+ TimiException.requiredTrue(permissionChecker.hasAny(ModuleCode.GAO, GaoPermissionCode.FUND_REFUND.getValue()), "缺少资金退款权限");
+ for (GaoOrderPaymentRefundRequest refundRequest : fundRefundList) {
+ TimiException.required(refundRequest, "资金退款请求不能为空");
+ if (refundRequest.getSalesOrderId() == null || refundRequest.getSalesOrderId().isBlank()) {
+ refundRequest.setSalesOrderId(order.getId());
+ } else {
+ TimiException.requiredTrue(order.getId().equals(refundRequest.getSalesOrderId()), "退款订单不属于当前订单");
+ }
+ }
+ }
+ Set usedTempFileIdSet = new HashSet<>();
+ if (fulfillmentReturnList != null) {
+ for (GaoOrderFulfillmentReturnRequest returnRequest : fulfillmentReturnList) {
+ if (returnRequest.getReason() == null || returnRequest.getReason().isBlank()) {
+ returnRequest.setReason(reason);
+ }
+ returnRequest.setAttachmentList(prepareCancelActionAttachments(returnRequest.getAttachmentList(), request.getAttachmentList(), usedTempFileIdSet));
+ }
+ }
+ if (fulfillmentRevokeList != null) {
+ for (GaoOrderFulfillmentRevokeRequest revokeRequest : fulfillmentRevokeList) {
+ if (revokeRequest.getReason() == null || revokeRequest.getReason().isBlank()) {
+ revokeRequest.setReason(reason);
+ }
+ revokeRequest.setAttachmentList(prepareCancelActionAttachments(revokeRequest.getAttachmentList(), request.getAttachmentList(), usedTempFileIdSet));
+ }
+ }
+ if (fundRevokeList != null) {
+ for (GaoOrderPaymentRevokeRequest revokeRequest : fundRevokeList) {
+ if (revokeRequest.getReason() == null || revokeRequest.getReason().isBlank()) {
+ revokeRequest.setReason(reason);
+ }
+ revokeRequest.setAttachmentList(prepareCancelActionAttachments(revokeRequest.getAttachmentList(), request.getAttachmentList(), usedTempFileIdSet));
+ }
+ }
+ if (fundRefundList != null) {
+ for (GaoOrderPaymentRefundRequest refundRequest : fundRefundList) {
+ if (refundRequest.getReason() == null || refundRequest.getReason().isBlank()) {
+ refundRequest.setReason(reason);
+ }
+ refundRequest.setAttachmentList(prepareCancelActionAttachments(refundRequest.getAttachmentList(), request.getAttachmentList(), usedTempFileIdSet));
+ }
+ }
+
+ GaoOrderPaymentService paymentService = paymentServiceProvider.getObject();
+ if (fulfillmentReturnList != null) {
+ for (GaoOrderFulfillmentReturnRequest returnRequest : fulfillmentReturnList) {
+ fulfillmentService.returnGoods(returnRequest);
+ }
+ }
if (fulfillmentRevokeList != null) {
for (GaoOrderFulfillmentRevokeRequest revokeRequest : fulfillmentRevokeList) {
fulfillmentService.revoke(revokeRequest);
}
}
if (fundRevokeList != null && !fundRevokeList.isEmpty()) {
- GaoOrderPaymentService paymentService = paymentServiceProvider.getObject();
for (GaoOrderPaymentRevokeRequest revokeRequest : fundRevokeList) {
paymentService.revoke(revokeRequest);
}
}
+ String childCancelReason = "随订单取消:%s".formatted(reason);
+ fulfillmentService.cancelPendingBySalesOrderId(order.getId(), childCancelReason);
+ paymentService.cancelPendingBySalesOrderId(order.getId(), childCancelReason);
order = getForUpdate(order.getId());
String userId = userLoginService.getRequireLoginUserId();
GaoSalesOrder.RefundStatus refundStatus = safe(order.getPaidAmount()) == 0 ? GaoSalesOrder.RefundStatus.REFUNDED : GaoSalesOrder.RefundStatus.PENDING;
Long cancelledAt = Time.now();
- TimiException.requiredTrue(1 == mapper.cancelIf(order.getId(), GaoSalesOrder.Status.ACTIVE, GaoSalesOrder.Status.CANCELLED,
+ TimiException.requiredTrue(1 == mapper.cancelIf(order.getId(), order.getStatus(), GaoSalesOrder.Status.CANCELLED,
cancelledAt, userId, reason, refundStatus), "订单状态已变化");
- // 订单取消立即失去有效消费资格,不等待退款完成
- pointTriggerService.revokeBySalesOrder(order, reason);
order.setStatus(GaoSalesOrder.Status.CANCELLED);
order.setCancelledAt(cancelledAt);
order.setCancelOperatorUserId(userId);
order.setCancelReason(reason);
order.setRefundStatus(refundStatus);
+ if (fundRefundList != null) {
+ for (GaoOrderPaymentRefundRequest refundRequest : fundRefundList) {
+ paymentService.refund(refundRequest);
+ }
+ }
+ order = getForUpdate(order.getId());
+ // 订单取消立即失去有效消费资格,不等待退款完成
+ pointTriggerService.revokeBySalesOrder(order, reason);
return order;
}
+ /// 准备取消处理附件,在多个处理记录复用同一临时文件时提前复制
+ ///
+ /// @param itemAttachmentList 处理明细附件
+ /// @param sharedAttachmentList 共用附件
+ /// @param usedTempFileIdSet 已使用的临时文件 ID
+ /// @return 当前处理记录的附件
+ private List prepareCancelActionAttachments(List itemAttachmentList, List sharedAttachmentList,
+ Set usedTempFileIdSet) {
+ List sourceList = itemAttachmentList == null || itemAttachmentList.isEmpty() ? sharedAttachmentList : itemAttachmentList;
+ TimiException.requiredTrue(sourceList != null && !sourceList.isEmpty(), "每条处理记录必须上传专有或共用凭证");
+ List result = new ArrayList<>();
+ for (Attachment source : sourceList) {
+ TimiException.required(source, "处理附件不能为空");
+ String tempFileId = requiredText(source.getTempFileId(), "处理附件 tempFileId 不能为空");
+ Attachment tempFile = attachmentService.get(tempFileId);
+ TimiException.required(tempFile, "not found temp file");
+ TimiException.requiredTrue(tempFile.getBizType() == Attachment.BizType.TEMP_FILE, "处理附件必须是临时文件");
+ if (!usedTempFileIdSet.add(tempFileId)) {
+ Attachment clone = attachmentService.clone(tempFileId);
+ TimiException.required(clone, "not found cloned temp file");
+ TimiException.requiredTrue(clone.getBizType() == Attachment.BizType.TEMP_FILE, "克隆附件必须是临时文件");
+ tempFileId = requiredText(clone.getId(), "克隆附件 ID 不能为空");
+ TimiException.requiredTrue(usedTempFileIdSet.add(tempFileId), "克隆附件 ID 已被使用");
+ }
+ Attachment attachment = new Attachment();
+ attachment.setTempFileId(tempFileId);
+ attachment.setAttachType(source.getAttachType());
+ attachment.setName(source.getName());
+ attachment.setMetadata(source.getMetadata());
+ result.add(attachment);
+ }
+ return result;
+ }
+
@Override
public void updatePayment(GaoSalesOrder order) {
TimiException.required(order, "not found sales order");
diff --git a/src/main/java/com/imyeyu/api/modules/gao/vo/GaoOrderFulfillmentReturnRequest.java b/src/main/java/com/imyeyu/api/modules/gao/vo/GaoOrderFulfillmentReturnRequest.java
new file mode 100644
index 0000000..9759e8a
--- /dev/null
+++ b/src/main/java/com/imyeyu/api/modules/gao/vo/GaoOrderFulfillmentReturnRequest.java
@@ -0,0 +1,35 @@
+package com.imyeyu.api.modules.gao.vo;
+
+import com.imyeyu.api.modules.common.entity.Attachment;
+import lombok.Data;
+
+import java.util.List;
+
+/// GAO 已核销履约整单退货请求
+///
+/// @author Codex
+/// @since 2026-10-27
+@Data
+public class GaoOrderFulfillmentReturnRequest {
+
+ /// 原履约单 ID
+ private String fulfillmentId;
+
+ /// 客户端幂等请求号
+ private String requestNo;
+
+ /// 退货时间
+ private Long returnedAt;
+
+ /// 退货原因
+ private String reason;
+
+ /// true 为实物已退回门店
+ private Boolean returnedToStore;
+
+ /// 退货照片
+ private List attachmentList;
+
+ /// 备注
+ private String remark;
+}
diff --git a/src/main/java/com/imyeyu/api/modules/gao/vo/GaoSalesOrderCancelRequest.java b/src/main/java/com/imyeyu/api/modules/gao/vo/GaoSalesOrderCancelRequest.java
index e1f02f3..223326c 100644
--- a/src/main/java/com/imyeyu/api/modules/gao/vo/GaoSalesOrderCancelRequest.java
+++ b/src/main/java/com/imyeyu/api/modules/gao/vo/GaoSalesOrderCancelRequest.java
@@ -1,5 +1,6 @@
package com.imyeyu.api.modules.gao.vo;
+import com.imyeyu.api.modules.common.entity.Attachment;
import lombok.Data;
import java.util.List;
@@ -20,9 +21,18 @@ public class GaoSalesOrderCancelRequest {
/// 幂等请求号
private String requestNo;
+ /// 冲正明细没有专有附件时使用的共用凭证
+ private List attachmentList;
+
/// 取消时冲正的已核销履约单,按整张履约单冲正
private List fulfillmentRevokeList;
+ /// 取消时退回的已核销履约单,按整张履约单退货
+ private List fulfillmentReturnList;
+
/// 取消时冲正的资金流水,按整条流水冲正
private List fundRevokeList;
+
+ /// 取消时登记的退款
+ private List fundRefundList;
}
diff --git a/src/main/java/com/imyeyu/api/modules/system/audit/AuditOperation.java b/src/main/java/com/imyeyu/api/modules/system/audit/AuditOperation.java
index c81878a..0e0d701 100644
--- a/src/main/java/com/imyeyu/api/modules/system/audit/AuditOperation.java
+++ b/src/main/java/com/imyeyu/api/modules/system/audit/AuditOperation.java
@@ -30,6 +30,7 @@ public enum AuditOperation {
GAO_ORDER_FULFILLMENT_REJECT(Logger.Module.GAO),
GAO_ORDER_FULFILLMENT_CANCEL(Logger.Module.GAO),
GAO_ORDER_FULFILLMENT_REVOKE(Logger.Module.GAO),
+ GAO_ORDER_FULFILLMENT_RETURN(Logger.Module.GAO),
GAO_PACKAGE_CONFIG_CREATE(Logger.Module.GAO),
GAO_PACKAGE_CONFIG_UPDATE(Logger.Module.GAO),
GAO_PACKAGE_CONFIG_DELETE(Logger.Module.GAO),
diff --git a/src/main/resources/db/migration/timiserver/V84__support_gao_order_fulfillment_return.sql b/src/main/resources/db/migration/timiserver/V84__support_gao_order_fulfillment_return.sql
new file mode 100644
index 0000000..e0323f8
--- /dev/null
+++ b/src/main/resources/db/migration/timiserver/V84__support_gao_order_fulfillment_return.sql
@@ -0,0 +1,3 @@
+ALTER TABLE `gao_order_fulfillment`
+ ADD COLUMN `returned_at` BIGINT NULL COMMENT '退货时间' AFTER `delivered_at`,
+ MODIFY COLUMN `source_fulfillment_id` VARCHAR(36) NULL COMMENT '退货或冲正来源履约单 ID';