Compare commits

...
8 Commits
Author SHA1 Message Date
timi cd88f94277 Merge pull request 'v1.0.63' (#75) from dev into master
Reviewed-on: #75
2026-10-29 12:02:14 +00:00
Timi 4f1a5cbd9d v1.0.63
CI / build-deploy (pull_request) Successful in 33s
CI / notify-on-failure (pull_request) Skipped
2026-10-29 20:01:44 +08:00
Timi 9aac55a180 add skuFulfillmentList 2026-10-29 14:23:29 +08:00
Timi 6fd765661d fix cancel fulfillment permission 2026-10-28 11:56:11 +08:00
timi 47970cd8ff Merge pull request 'v1.0.62' (#74) from dev into master
Reviewed-on: #74
2026-10-27 16:58:56 +00:00
Timi 7222d19d02 v1.0.62
CI / build-deploy (pull_request) Successful in 33s
CI / notify-on-failure (pull_request) Skipped
2026-10-28 00:57:47 +08:00
Timi 5d55aee586 cancel sale order with fulfillment and fund record 2026-10-28 00:35:12 +08:00
Timi 14a81d1080 download from attachment api for data export 2026-10-26 11:46:02 +08:00
24 changed files with 393 additions and 70 deletions
+1 -1
View File
@@ -11,7 +11,7 @@
<groupId>com.imyeyu.timiserverapi</groupId> <groupId>com.imyeyu.timiserverapi</groupId>
<artifactId>TimiServerAPI</artifactId> <artifactId>TimiServerAPI</artifactId>
<version>1.0.61</version> <version>1.0.63</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>TimiServerAPI</name> <name>TimiServerAPI</name>
<description>imyeyu.com API</description> <description>imyeyu.com API</description>
@@ -99,6 +99,8 @@ public enum GaoPermissionCode implements BuiltinPermissionCode {
ORDER_FULFILLMENT_REVOKE("ORDER_FULFILLMENT:REVOKE", "统一履约冲正", true, true), 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_CREATE("PACKAGE_CONFIG:CREATE", "套餐配置创建", true, true),
PACKAGE_CONFIG_READ("PACKAGE_CONFIG:READ", "套餐配置读取", true, true), PACKAGE_CONFIG_READ("PACKAGE_CONFIG:READ", "套餐配置读取", true, true),
@@ -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.GaoDataExportStatView;
import com.imyeyu.api.modules.gao.export.GaoDataExportTaskView; import com.imyeyu.api.modules.gao.export.GaoDataExportTaskView;
import com.imyeyu.api.modules.gao.service.GaoDataExportService; 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.AOPLog;
import com.imyeyu.spring.annotation.IgnoreGlobalReturn;
import com.imyeyu.spring.annotation.RequestRateLimit; import com.imyeyu.spring.annotation.RequestRateLimit;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; 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.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
/// GAO 店长数据导出接口 /// GAO 店长数据导出接口
/// ///
/// @author Codex /// @author Codex
@@ -69,20 +63,4 @@ public class GaoDataExportController {
public GaoDataExportTaskView detail(@PathVariable String taskId) { public GaoDataExportTaskView detail(@PathVariable String taskId) {
return service.detail(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());
}
} }
@@ -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.GaoOrderFulfillmentPage;
import com.imyeyu.api.modules.gao.vo.GaoOrderFulfillmentPrepareStockRequest; import com.imyeyu.api.modules.gao.vo.GaoOrderFulfillmentPrepareStockRequest;
import com.imyeyu.api.modules.gao.vo.GaoOrderFulfillmentRevokeRequest; 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.GaoQuickFulfillmentCreateRequest;
import com.imyeyu.api.modules.gao.vo.GaoQuickFulfillmentCustomerRequest; import com.imyeyu.api.modules.gao.vo.GaoQuickFulfillmentCustomerRequest;
import com.imyeyu.api.modules.gao.vo.GaoQuickFulfillmentSkuView; import com.imyeyu.api.modules.gao.vo.GaoQuickFulfillmentSkuView;
@@ -182,6 +183,16 @@ public class GaoOrderFulfillmentController {
return result; 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<GaoOrderFulfillment> fulfillmentList) { private void fillTransient(List<GaoOrderFulfillment> fulfillmentList) {
if (fulfillmentList == null || fulfillmentList.isEmpty()) { if (fulfillmentList == null || fulfillmentList.isEmpty()) {
return; return;
@@ -14,6 +14,7 @@ import com.imyeyu.api.modules.gao.entity.GaoProductSpecValue;
import com.imyeyu.api.modules.gao.service.GaoStoreScopeService; import com.imyeyu.api.modules.gao.service.GaoStoreScopeService;
import com.imyeyu.api.modules.gao.vo.GaoProductCategoryPage; import com.imyeyu.api.modules.gao.vo.GaoProductCategoryPage;
import com.imyeyu.api.modules.gao.vo.GaoProductPage; import com.imyeyu.api.modules.gao.vo.GaoProductPage;
import com.imyeyu.api.modules.gao.vo.GaoProductSkuFulfillmentView;
import com.imyeyu.java.bean.timi.TimiException; import com.imyeyu.java.bean.timi.TimiException;
import com.imyeyu.spring.annotation.AOPLog; import com.imyeyu.spring.annotation.AOPLog;
import com.imyeyu.spring.annotation.RequestRateLimit; import com.imyeyu.spring.annotation.RequestRateLimit;
@@ -170,6 +171,18 @@ public class GaoProductController {
return result; return result;
} }
/// 批量查询履约所需的 SKU 信息
///
/// @param idList SKU ID 列表
/// @return 履约所需的 SKU 信息
@AOPLog
@RequestRateLimit
@RequireGaoPermission(GaoPermissionCode.PRODUCT_READ)
@PostMapping("/sku/fulfillment-list")
public List<GaoProductSkuFulfillmentView> skuFulfillmentList(@RequestBody List<String> idList) {
return skuService.listFulfillmentByIdList(idList);
}
@AOPLog @AOPLog
@RequestRateLimit @RequestRateLimit
@RequireGaoPermission(GaoPermissionCode.PRODUCT_CREATE) @RequireGaoPermission(GaoPermissionCode.PRODUCT_CREATE)
@@ -52,7 +52,7 @@ public class GaoFundRecord extends UUIDEntity {
/// 店长已拒绝 /// 店长已拒绝
REJECTED, REJECTED,
/// 提交人已撤销 /// 核销前已撤销
CANCELLED CANCELLED
} }
@@ -34,11 +34,14 @@ public class GaoOrderFulfillment implements IDEntity<String>, Creatable, Updatab
/// 店长已拒绝 /// 店长已拒绝
REJECTED, REJECTED,
/// 提交人已撤销 /// 核销前已撤销
CANCELLED, CANCELLED,
/// 已核销后冲正 /// 已核销后冲正
REVOKED REVOKED,
/// 已退货
RETURNED
} }
@Id @Id
@@ -66,13 +69,16 @@ public class GaoOrderFulfillment implements IDEntity<String>, Creatable, Updatab
/// 实际履约时间 /// 实际履约时间
private Long deliveredAt; private Long deliveredAt;
/// 退货时间
private Long returnedAt;
/// 核销或拒绝操作人 /// 核销或拒绝操作人
private String verifierUserId; private String verifierUserId;
/// 核销或拒绝时间 /// 核销或拒绝时间
private Long verifiedAt; private Long verifiedAt;
/// 冲正单指向原履约单 /// 退货或冲正单指向原履约单
private String sourceFulfillmentId; private String sourceFulfillmentId;
/// 拒绝、撤销或冲正原因 /// 拒绝、撤销或冲正原因
@@ -60,6 +60,9 @@ public class GaoProductStockRecord implements IDEntity<String>, Creatable {
/// 履约冲正入库 /// 履约冲正入库
ORDER_REVOKE, ORDER_REVOKE,
/// 履约退货入库
ORDER_RETURN_IN,
/// 积分兑换实物出库 /// 积分兑换实物出库
POINT_REDEMPTION_OUT, POINT_REDEMPTION_OUT,
@@ -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.export.GaoDataExportTaskView;
import com.imyeyu.api.modules.gao.task.async.GaoDataExportAsyncTask; import com.imyeyu.api.modules.gao.task.async.GaoDataExportAsyncTask;
import java.io.IOException;
import java.io.OutputStream;
/// ///
/// GAO 数据导出服务 /// GAO 数据导出服务
/// ///
@@ -34,13 +31,6 @@ public interface GaoDataExportService {
/// @return 任务视图 /// @return 任务视图
GaoDataExportTaskView detail(String taskId); GaoDataExportTaskView detail(String taskId);
/// 下载已完成的导出文件
///
/// @param taskId 任务 ID
/// @param output 输出流
/// @throws IOException 写入异常
void download(String taskId, OutputStream output) throws IOException;
/// 执行异步导出任务 /// 执行异步导出任务
/// ///
/// @param task 异步任务 /// @param task 异步任务
@@ -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.GaoOrderFulfillmentPage;
import com.imyeyu.api.modules.gao.vo.GaoOrderFulfillmentPrepareStockRequest; import com.imyeyu.api.modules.gao.vo.GaoOrderFulfillmentPrepareStockRequest;
import com.imyeyu.api.modules.gao.vo.GaoOrderFulfillmentRevokeRequest; 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.GaoQuickFulfillmentCreateRequest;
import com.imyeyu.api.modules.gao.vo.GaoQuickFulfillmentCustomerRequest; import com.imyeyu.api.modules.gao.vo.GaoQuickFulfillmentCustomerRequest;
import com.imyeyu.api.modules.gao.vo.GaoQuickFulfillmentSkuView; import com.imyeyu.api.modules.gao.vo.GaoQuickFulfillmentSkuView;
@@ -34,6 +35,12 @@ public interface GaoOrderFulfillmentService extends BaseService<GaoOrderFulfillm
/// 查询销售订单仍占用权益的履约单数量 /// 查询销售订单仍占用权益的履约单数量
long countPendingBySalesOrderId(String salesOrderId); long countPendingBySalesOrderId(String salesOrderId);
/// 取消销售订单下全部待核销履约
///
/// @param salesOrderId 销售订单 ID
/// @param reason 撤销原因
void cancelPendingBySalesOrderId(String salesOrderId, String reason);
/// 创建履约单 /// 创建履约单
GaoOrderFulfillment create(GaoOrderFulfillmentCreateRequest request); GaoOrderFulfillment create(GaoOrderFulfillmentCreateRequest request);
@@ -72,4 +79,7 @@ public interface GaoOrderFulfillmentService extends BaseService<GaoOrderFulfillm
/// 冲正已核销履约单 /// 冲正已核销履约单
GaoOrderFulfillment revoke(GaoOrderFulfillmentRevokeRequest request); GaoOrderFulfillment revoke(GaoOrderFulfillmentRevokeRequest request);
/// 退回已核销履约单的全部履约内容
GaoOrderFulfillment returnGoods(GaoOrderFulfillmentReturnRequest request);
} }
@@ -28,6 +28,12 @@ public interface GaoOrderPaymentService {
/// 撤销待核销收款 /// 撤销待核销收款
GaoFundRecord cancel(GaoOrderPaymentActionRequest request); GaoFundRecord cancel(GaoOrderPaymentActionRequest request);
/// 取消销售订单下全部待核销收款
///
/// @param salesOrderId 销售订单 ID
/// @param reason 撤销原因
void cancelPendingBySalesOrderId(String salesOrderId, String reason);
/// 登记退款 /// 登记退款
GaoFundRecord refund(GaoOrderPaymentRefundRequest request); GaoFundRecord refund(GaoOrderPaymentRefundRequest request);
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.imyeyu.api.modules.gao.entity.GaoProductSku; import com.imyeyu.api.modules.gao.entity.GaoProductSku;
import com.imyeyu.api.modules.gao.entity.GaoProductSkuUnit; import com.imyeyu.api.modules.gao.entity.GaoProductSkuUnit;
import com.imyeyu.api.modules.gao.vo.GaoProductSkuUnitSelection; import com.imyeyu.api.modules.gao.vo.GaoProductSkuUnitSelection;
import com.imyeyu.api.modules.gao.vo.GaoProductSkuFulfillmentView;
import com.imyeyu.spring.service.BaseService; import com.imyeyu.spring.service.BaseService;
import java.util.Collection; import java.util.Collection;
@@ -21,6 +22,12 @@ public interface GaoProductSkuService extends BaseService<GaoProductSku, String>
/// @return SKU 列表,包含单位、规格和附件临时数据 /// @return SKU 列表,包含单位、规格和附件临时数据
List<GaoProductSku> listByIdList(Collection<String> idList); List<GaoProductSku> listByIdList(Collection<String> idList);
/// 批量查询履约所需的 SKU 信息
///
/// @param idList SKU ID 集合
/// @return 履约所需的 SKU 信息
List<GaoProductSkuFulfillmentView> listFulfillmentByIdList(Collection<String> idList);
/// 查询 SKU 详情 /// 查询 SKU 详情
GaoProductSku detail(String id); GaoProductSku detail(String id);
@@ -79,6 +79,9 @@ public interface GaoProductStockService {
/// 履约库存冲正入库 /// 履约库存冲正入库
List<GaoProductStock> revokeForFulfillment(String storeId, String bizId, List<GaoStockChangeItem> items, String requestNo, String operatorUserId); List<GaoProductStock> revokeForFulfillment(String storeId, String bizId, List<GaoStockChangeItem> items, String requestNo, String operatorUserId);
/// 履约退货入库
List<GaoProductStock> returnForFulfillment(String storeId, String bizId, List<GaoStockChangeItem> items, String requestNo, String operatorUserId);
/// 为积分兑换实物出库 /// 为积分兑换实物出库
GaoProductStockRecord outForRedemption(String storeId, String redemptionId, GaoStockChangeItem item, String requestNo, String operatorUserId); GaoProductStockRecord outForRedemption(String storeId, String redemptionId, GaoStockChangeItem item, String requestNo, String operatorUserId);
@@ -129,25 +129,6 @@ public class GaoDataExportServiceImplement implements GaoDataExportService {
return toTaskView(task, metadata, readResult(task)); 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 @Override
public void execute(GaoDataExportAsyncTask task) throws Exception { public void execute(GaoDataExportAsyncTask task) throws Exception {
AsyncTask record = asyncTaskService.getTaskRecord(task.getId()); AsyncTask record = asyncTaskService.getTaskRecord(task.getId());
@@ -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.GaoOrderFulfillmentPage;
import com.imyeyu.api.modules.gao.vo.GaoOrderFulfillmentPrepareStockRequest; import com.imyeyu.api.modules.gao.vo.GaoOrderFulfillmentPrepareStockRequest;
import com.imyeyu.api.modules.gao.vo.GaoOrderFulfillmentRevokeRequest; 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.GaoProductSkuUnitSelection;
import com.imyeyu.api.modules.gao.vo.GaoQuickFulfillmentCreateItemRequest; import com.imyeyu.api.modules.gao.vo.GaoQuickFulfillmentCreateItemRequest;
import com.imyeyu.api.modules.gao.vo.GaoQuickFulfillmentCreateRequest; import com.imyeyu.api.modules.gao.vo.GaoQuickFulfillmentCreateRequest;
@@ -168,6 +169,23 @@ public class GaoOrderFulfillmentServiceImplement extends AbstractEntityService<G
return mapper.countPendingBySalesOrderId(salesOrderId); return mapper.countPendingBySalesOrderId(salesOrderId);
} }
@Transactional(TimiServerDBConfig.ROLLBACKER)
@Override
public void cancelPendingBySalesOrderId(String salesOrderId, String reason) {
TimiException.required(salesOrderId, "not found salesOrderId");
String cancelReason = requiredText(reason, "履约撤销原因不能为空");
for (GaoOrderFulfillment fulfillment : mapper.selectBySalesOrderId(salesOrderId)) {
if (fulfillment.getStatus() != GaoOrderFulfillment.Status.WAITING_STOCK
&& fulfillment.getStatus() != GaoOrderFulfillment.Status.PENDING) {
continue;
}
GaoOrderFulfillmentActionRequest request = new GaoOrderFulfillmentActionRequest();
request.setFulfillmentId(fulfillment.getId());
request.setReason(cancelReason);
releaseInternal(request, GaoOrderFulfillment.Status.CANCELLED);
}
}
@Override @Override
public List<GaoQuickFulfillmentSkuView> listQuickFulfillmentSku(GaoQuickFulfillmentCustomerRequest request) { public List<GaoQuickFulfillmentSkuView> listQuickFulfillmentSku(GaoQuickFulfillmentCustomerRequest request) {
TimiException.required(request, "快速履约客户查询请求不能为空"); TimiException.required(request, "快速履约客户查询请求不能为空");
@@ -542,7 +560,8 @@ public class GaoOrderFulfillmentServiceImplement extends AbstractEntityService<G
GaoOrderFulfillment fulfillment = mapper.selectById(request.getFulfillmentId()); GaoOrderFulfillment fulfillment = mapper.selectById(request.getFulfillmentId());
TimiException.required(fulfillment, "not found fulfillment"); TimiException.required(fulfillment, "not found fulfillment");
String loginUserId = userLoginService.getRequireLoginUserId(); String loginUserId = userLoginService.getRequireLoginUserId();
TimiException.requiredTrue(loginUserId.equals(fulfillment.getOperatorUserId()), "只能撤销自己提交的履约"); TimiException.requiredTrue(roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.STORE_MANAGER.name())
|| loginUserId.equals(fulfillment.getOperatorUserId()), "只能撤销自己提交的履约");
return releaseInternal(request, GaoOrderFulfillment.Status.CANCELLED); return releaseInternal(request, GaoOrderFulfillment.Status.CANCELLED);
} }
@@ -652,6 +671,79 @@ public class GaoOrderFulfillmentServiceImplement extends AbstractEntityService<G
return detail(reverse.getId()); return detail(reverse.getId());
} }
@OperationAudit(AuditOperation.GAO_ORDER_FULFILLMENT_RETURN)
@Transactional(TimiServerDBConfig.ROLLBACKER)
@Override
public GaoOrderFulfillment returnGoods(GaoOrderFulfillmentReturnRequest request) {
TimiException.required(request, "not found fulfillment return request");
String requestNo = requiredText(request.getRequestNo(), "not found requestNo");
TimiException.required(request.getFulfillmentId(), "not found fulfillmentId");
String reason = requiredText(request.getReason(), "退货原因不能为空");
GaoOrderFulfillment sourceSnapshot = mapper.selectById(request.getFulfillmentId());
TimiException.required(sourceSnapshot, "not found fulfillment");
GaoOrderFulfillment existing = mapper.selectByRequestNo(sourceSnapshot.getStoreId(), requestNo);
if (existing != null) {
TimiException.requiredTrue(sourceSnapshot.getId().equals(existing.getSourceFulfillmentId())
&& existing.getStatus() == GaoOrderFulfillment.Status.RETURNED, "requestNo 已被其他履约操作使用");
return detail(existing.getId());
}
GaoSalesOrder order = salesOrderService.getForUpdate(sourceSnapshot.getSalesOrderId());
List<GaoOrderFulfillmentItem> sourceItemList = itemMapper.selectByFulfillmentId(sourceSnapshot.getId());
List<SourceEntry> 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<GaoStockChangeItem> 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<String, GaoOrderFulfillmentItem> 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, private GaoOrderFulfillment newFulfillment(GaoSalesOrder order, GaoOrderFulfillment.Status status,
String requestNo, String operatorUserId, Long deliveredAt, String remark) { String requestNo, String operatorUserId, Long deliveredAt, String remark) {
GaoOrderFulfillment result = new GaoOrderFulfillment(); GaoOrderFulfillment result = new GaoOrderFulfillment();
@@ -109,9 +109,12 @@ public class GaoOrderPaymentServiceImplement implements GaoOrderPaymentService {
@Transactional(TimiServerDBConfig.ROLLBACKER) @Transactional(TimiServerDBConfig.ROLLBACKER)
@Override @Override
public GaoFundRecord verify(String fundRecordId) { 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); GaoFundRecord record = lockOrderRecord(fundRecordId);
TimiException.requiredTrue(order.getId().equals(record.getBizId()), "资金流水所属订单已变化");
TimiException.requiredTrue(record.getOperationType() == GaoFundRecord.OperationType.RECEIVE && record.getStatus() == GaoFundRecord.Status.PENDING, "收款记录不是待核销状态"); TimiException.requiredTrue(record.getOperationType() == GaoFundRecord.OperationType.RECEIVE && record.getStatus() == GaoFundRecord.Status.PENDING, "收款记录不是待核销状态");
GaoSalesOrder order = orderService.getForUpdate(record.getBizId());
Long paidAtBefore = order.getPaidAt(); Long paidAtBefore = order.getPaidAt();
order.setPendingPaidAmount(safe(order.getPendingPaidAmount()) - record.getAmount()); order.setPendingPaidAmount(safe(order.getPendingPaidAmount()) - record.getAmount());
order.setPaidAmount(safe(order.getPaidAmount()) + 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); 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) { private GaoFundRecord releasePending(GaoOrderPaymentActionRequest request, GaoFundRecord.Status targetStatus, boolean onlyOperator) {
TimiException.required(request, "not found order payment action request"); TimiException.required(request, "not found order payment action request");
TimiException.required(request.getFundRecordId(), "not found fundRecordId"); TimiException.required(request.getFundRecordId(), "not found fundRecordId");
String reason = requiredText(request.getReason(), "资金操作原因不能为空"); 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()); GaoFundRecord record = lockOrderRecord(request.getFundRecordId());
TimiException.requiredTrue(order.getId().equals(record.getBizId()), "资金流水所属订单已变化");
TimiException.requiredTrue(record.getOperationType() == GaoFundRecord.OperationType.RECEIVE && record.getStatus() == GaoFundRecord.Status.PENDING, "收款记录不是待核销状态"); TimiException.requiredTrue(record.getOperationType() == GaoFundRecord.OperationType.RECEIVE && record.getStatus() == GaoFundRecord.Status.PENDING, "收款记录不是待核销状态");
if (onlyOperator) { if (onlyOperator) {
TimiException.requiredTrue(userLoginService.getRequireLoginUserId().equals(record.getOperatorUserId()), "只能撤销自己提交的收款"); TimiException.requiredTrue(userLoginService.getRequireLoginUserId().equals(record.getOperatorUserId()), "只能撤销自己提交的收款");
} }
GaoSalesOrder order = orderService.getForUpdate(record.getBizId());
order.setPendingPaidAmount(safe(order.getPendingPaidAmount()) - record.getAmount()); order.setPendingPaidAmount(safe(order.getPendingPaidAmount()) - record.getAmount());
orderService.recomputePaymentStatus(order); orderService.recomputePaymentStatus(order);
String userId = userLoginService.getRequireLoginUserId(); String userId = userLoginService.getRequireLoginUserId();
@@ -23,8 +23,10 @@ import com.imyeyu.api.modules.gao.mapper.GaoProductSpecMapper;
import com.imyeyu.api.modules.gao.mapper.GaoProductSpecValueMapper; import com.imyeyu.api.modules.gao.mapper.GaoProductSpecValueMapper;
import com.imyeyu.api.modules.gao.service.GaoProductService; import com.imyeyu.api.modules.gao.service.GaoProductService;
import com.imyeyu.api.modules.gao.service.GaoProductSkuService; import com.imyeyu.api.modules.gao.service.GaoProductSkuService;
import com.imyeyu.api.modules.gao.service.GaoStoreScopeService;
import com.imyeyu.api.modules.gao.vo.GaoProductSkuBaseUnitMigrationRequest; import com.imyeyu.api.modules.gao.vo.GaoProductSkuBaseUnitMigrationRequest;
import com.imyeyu.api.modules.gao.vo.GaoProductSkuUnitSelection; import com.imyeyu.api.modules.gao.vo.GaoProductSkuUnitSelection;
import com.imyeyu.api.modules.gao.vo.GaoProductSkuFulfillmentView;
import com.imyeyu.api.modules.system.audit.AuditOperation; import com.imyeyu.api.modules.system.audit.AuditOperation;
import com.imyeyu.api.modules.system.audit.OperationAudit; import com.imyeyu.api.modules.system.audit.OperationAudit;
import com.imyeyu.api.modules.system.entity.Logger; import com.imyeyu.api.modules.system.entity.Logger;
@@ -63,6 +65,7 @@ public class GaoProductSkuServiceImplement extends AbstractEntityService<GaoProd
private static final BigDecimal ONE = BigDecimal.ONE; private static final BigDecimal ONE = BigDecimal.ONE;
private final GaoProductSkuMapper mapper; private final GaoProductSkuMapper mapper;
private final GaoStoreScopeService storeScopeService;
private final GaoProductEditMapper editMapper; private final GaoProductEditMapper editMapper;
private final GaoProductStockMapper stockMapper; private final GaoProductStockMapper stockMapper;
private final GaoProductSkuUnitMapper unitMapper; private final GaoProductSkuUnitMapper unitMapper;
@@ -97,6 +100,23 @@ public class GaoProductSkuServiceImplement extends AbstractEntityService<GaoProd
return result; return result;
} }
@Override
public List<GaoProductSkuFulfillmentView> listFulfillmentByIdList(Collection<String> idList) {
if (idList == null || idList.isEmpty()) {
return List.of();
}
List<GaoProductSku> skuList = mapper.selectByIdList(idList);
if (skuList.isEmpty()) {
return List.of();
}
skuList.forEach(sku -> storeScopeService.checkStoreId(sku.getStoreId()));
List<String> skuIdList = skuList.stream().map(GaoProductSku::getId).toList();
Map<String, List<GaoProductSkuUnit>> unitMap = unitMapper.selectBySkuIdList(skuIdList).stream()
.collect(Collectors.groupingBy(GaoProductSkuUnit::getSkuId));
return skuList.stream().map(sku -> new GaoProductSkuFulfillmentView(sku.getId(), sku.getStockEnabled(),
sku.getAllowDecimalQuantity(), unitMap.getOrDefault(sku.getId(), List.of()))).toList();
}
@Override @Override
public List<GaoProductSku> listByProductId(String productId) { public List<GaoProductSku> listByProductId(String productId) {
TimiException.required(productId, "not found productId"); TimiException.required(productId, "not found productId");
@@ -302,6 +302,12 @@ public class GaoProductStockServiceImplement implements GaoProductStockService {
return executeInternal(storeId, bizId, items, requestNo, operatorUserId, GaoProductStockRecord.OperationType.ORDER_REVOKE, null); return executeInternal(storeId, bizId, items, requestNo, operatorUserId, GaoProductStockRecord.OperationType.ORDER_REVOKE, null);
} }
@Transactional(TimiServerDBConfig.ROLLBACKER)
@Override
public List<GaoProductStock> returnForFulfillment(String storeId, String bizId, List<GaoStockChangeItem> items, String requestNo, String operatorUserId) {
return executeInternal(storeId, bizId, items, requestNo, operatorUserId, GaoProductStockRecord.OperationType.ORDER_RETURN_IN, null);
}
@Transactional(TimiServerDBConfig.ROLLBACKER) @Transactional(TimiServerDBConfig.ROLLBACKER)
@Override @Override
public GaoProductStockRecord outForRedemption(String storeId, String redemptionId, GaoStockChangeItem item, String requestNo, String operatorUserId) { 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) { private BigDecimal onHandDelta(GaoProductStockRecord.OperationType operationType, BigDecimal quantity) {
return switch (operationType) { 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 MANUAL_OUT, STOCKTAKE_LOSS, ORDER_OUT, POINT_REDEMPTION_OUT -> quantity.negate();
case ORDER_RESERVE, ORDER_RELEASE -> ZERO; case ORDER_RESERVE, ORDER_RELEASE -> ZERO;
case MANUAL_REVOKE -> throw new TimiException(TimiCode.ERROR, "手工库存冲正必须基于原库存流水"); case MANUAL_REVOKE -> throw new TimiException(TimiCode.ERROR, "手工库存冲正必须基于原库存流水");
@@ -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.GaoCustomerProductSummaryView;
import com.imyeyu.api.modules.gao.vo.GaoCustomerProductView; import com.imyeyu.api.modules.gao.vo.GaoCustomerProductView;
import com.imyeyu.api.modules.gao.vo.GaoOrderFulfillmentRevokeRequest; 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.GaoOrderPaymentRevokeRequest;
import com.imyeyu.api.modules.gao.vo.GaoProductSkuUnitSelection; import com.imyeyu.api.modules.gao.vo.GaoProductSkuUnitSelection;
import com.imyeyu.api.modules.gao.vo.GaoSalesOrderCancelRequest; import com.imyeyu.api.modules.gao.vo.GaoSalesOrderCancelRequest;
@@ -329,24 +331,36 @@ public class GaoSalesOrderServiceImplement extends AbstractEntityService<GaoSale
if (order.getStatus() == GaoSalesOrder.Status.CANCELLED) { if (order.getStatus() == GaoSalesOrder.Status.CANCELLED) {
return order; return order;
} }
TimiException.requiredTrue(order.getStatus() == GaoSalesOrder.Status.ACTIVE, "当前订单不可取消"); TimiException.requiredTrue(order.getStatus() == GaoSalesOrder.Status.ACTIVE || order.getStatus() == GaoSalesOrder.Status.FULFILLED,
TimiException.requiredTrue(fundRecordService.countPendingReceiveByBizId(order.getId()) == 0, "订单存在待核销收款,不能取消"); "当前订单不可取消");
GaoOrderFulfillmentService fulfillmentService = fulfillmentServiceProvider.getObject(); GaoOrderFulfillmentService fulfillmentService = fulfillmentServiceProvider.getObject();
TimiException.requiredTrue(fulfillmentService.countPendingBySalesOrderId(order.getId()) == 0, "订单存在待履约操作,不能取消");
List<GaoOrderFulfillmentRevokeRequest> fulfillmentRevokeList = request.getFulfillmentRevokeList(); List<GaoOrderFulfillmentRevokeRequest> fulfillmentRevokeList = request.getFulfillmentRevokeList();
List<GaoOrderFulfillmentReturnRequest> fulfillmentReturnList = request.getFulfillmentReturnList();
Set<String> fulfillmentIdSet = new HashSet<>(); Set<String> fulfillmentIdSet = new HashSet<>();
Set<String> selectedFulfillmentIdSet = new HashSet<>(); Set<String> selectedFulfillmentIdSet = new HashSet<>();
if (fulfillmentRevokeList != null && !fulfillmentRevokeList.isEmpty()) { if ((fulfillmentRevokeList != null && !fulfillmentRevokeList.isEmpty())
TimiException.requiredTrue(permissionChecker.hasAny(ModuleCode.GAO, GaoPermissionCode.ORDER_FULFILLMENT_REVOKE.getValue()), "缺少履约冲正权限"); || (fulfillmentReturnList != null && !fulfillmentReturnList.isEmpty())) {
for (GaoOrderFulfillment fulfillment : fulfillmentService.listBySalesOrderId(order.getId())) { for (GaoOrderFulfillment fulfillment : fulfillmentService.listBySalesOrderId(order.getId())) {
fulfillmentIdSet.add(fulfillment.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) { for (GaoOrderFulfillmentRevokeRequest revokeRequest : fulfillmentRevokeList) {
TimiException.required(revokeRequest, "履约冲正请求不能为空"); TimiException.required(revokeRequest, "履约冲正请求不能为空");
TimiException.required(revokeRequest.getFulfillmentId(), "not found fulfillmentId"); TimiException.required(revokeRequest.getFulfillmentId(), "not found fulfillmentId");
TimiException.requiredTrue(fulfillmentIdSet.contains(revokeRequest.getFulfillmentId()), "履约单不属于当前订单"); 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<GaoSale
TimiException.requiredTrue(selectedFundRecordIdSet.add(revokeRequest.getFundRecordId()), "资金流水不能重复冲正"); TimiException.requiredTrue(selectedFundRecordIdSet.add(revokeRequest.getFundRecordId()), "资金流水不能重复冲正");
} }
} }
List<GaoOrderPaymentRefundRequest> 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<String> 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) { if (fulfillmentRevokeList != null) {
for (GaoOrderFulfillmentRevokeRequest revokeRequest : fulfillmentRevokeList) { for (GaoOrderFulfillmentRevokeRequest revokeRequest : fulfillmentRevokeList) {
fulfillmentService.revoke(revokeRequest); fulfillmentService.revoke(revokeRequest);
} }
} }
if (fundRevokeList != null && !fundRevokeList.isEmpty()) { if (fundRevokeList != null && !fundRevokeList.isEmpty()) {
GaoOrderPaymentService paymentService = paymentServiceProvider.getObject();
for (GaoOrderPaymentRevokeRequest revokeRequest : fundRevokeList) { for (GaoOrderPaymentRevokeRequest revokeRequest : fundRevokeList) {
paymentService.revoke(revokeRequest); paymentService.revoke(revokeRequest);
} }
} }
String childCancelReason = "随订单取消:%s".formatted(reason);
fulfillmentService.cancelPendingBySalesOrderId(order.getId(), childCancelReason);
paymentService.cancelPendingBySalesOrderId(order.getId(), childCancelReason);
order = getForUpdate(order.getId()); order = getForUpdate(order.getId());
String userId = userLoginService.getRequireLoginUserId(); String userId = userLoginService.getRequireLoginUserId();
GaoSalesOrder.RefundStatus refundStatus = safe(order.getPaidAmount()) == 0 ? GaoSalesOrder.RefundStatus.REFUNDED : GaoSalesOrder.RefundStatus.PENDING; GaoSalesOrder.RefundStatus refundStatus = safe(order.getPaidAmount()) == 0 ? GaoSalesOrder.RefundStatus.REFUNDED : GaoSalesOrder.RefundStatus.PENDING;
Long cancelledAt = Time.now(); 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), "订单状态已变化"); cancelledAt, userId, reason, refundStatus), "订单状态已变化");
// 订单取消立即失去有效消费资格,不等待退款完成
pointTriggerService.revokeBySalesOrder(order, reason);
order.setStatus(GaoSalesOrder.Status.CANCELLED); order.setStatus(GaoSalesOrder.Status.CANCELLED);
order.setCancelledAt(cancelledAt); order.setCancelledAt(cancelledAt);
order.setCancelOperatorUserId(userId); order.setCancelOperatorUserId(userId);
order.setCancelReason(reason); order.setCancelReason(reason);
order.setRefundStatus(refundStatus); order.setRefundStatus(refundStatus);
if (fundRefundList != null) {
for (GaoOrderPaymentRefundRequest refundRequest : fundRefundList) {
paymentService.refund(refundRequest);
}
}
order = getForUpdate(order.getId());
// 订单取消立即失去有效消费资格,不等待退款完成
pointTriggerService.revokeBySalesOrder(order, reason);
return order; return order;
} }
/// 准备取消处理附件,在多个处理记录复用同一临时文件时提前复制
///
/// @param itemAttachmentList 处理明细附件
/// @param sharedAttachmentList 共用附件
/// @param usedTempFileIdSet 已使用的临时文件 ID
/// @return 当前处理记录的附件
private List<Attachment> prepareCancelActionAttachments(List<Attachment> itemAttachmentList, List<Attachment> sharedAttachmentList,
Set<String> usedTempFileIdSet) {
List<Attachment> sourceList = itemAttachmentList == null || itemAttachmentList.isEmpty() ? sharedAttachmentList : itemAttachmentList;
TimiException.requiredTrue(sourceList != null && !sourceList.isEmpty(), "每条处理记录必须上传专有或共用凭证");
List<Attachment> 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 @Override
public void updatePayment(GaoSalesOrder order) { public void updatePayment(GaoSalesOrder order) {
TimiException.required(order, "not found sales order"); TimiException.required(order, "not found sales order");
@@ -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<Attachment> attachmentList;
/// 备注
private String remark;
}
@@ -0,0 +1,14 @@
package com.imyeyu.api.modules.gao.vo;
import com.imyeyu.api.modules.gao.entity.GaoProductSkuUnit;
import java.util.List;
/// 履约所需的 SKU 信息
///
/// @param id SKU ID
/// @param stockEnabled true 为启用库存管理
/// @param allowDecimalQuantity true 为允许小数数量
/// @param unitList SKU 单位列表
public record GaoProductSkuFulfillmentView(String id, Boolean stockEnabled, Boolean allowDecimalQuantity, List<GaoProductSkuUnit> unitList) {
}
@@ -1,5 +1,6 @@
package com.imyeyu.api.modules.gao.vo; package com.imyeyu.api.modules.gao.vo;
import com.imyeyu.api.modules.common.entity.Attachment;
import lombok.Data; import lombok.Data;
import java.util.List; import java.util.List;
@@ -20,9 +21,18 @@ public class GaoSalesOrderCancelRequest {
/// 幂等请求号 /// 幂等请求号
private String requestNo; private String requestNo;
/// 冲正明细没有专有附件时使用的共用凭证
private List<Attachment> attachmentList;
/// 取消时冲正的已核销履约单,按整张履约单冲正 /// 取消时冲正的已核销履约单,按整张履约单冲正
private List<GaoOrderFulfillmentRevokeRequest> fulfillmentRevokeList; private List<GaoOrderFulfillmentRevokeRequest> fulfillmentRevokeList;
/// 取消时退回的已核销履约单,按整张履约单退货
private List<GaoOrderFulfillmentReturnRequest> fulfillmentReturnList;
/// 取消时冲正的资金流水,按整条流水冲正 /// 取消时冲正的资金流水,按整条流水冲正
private List<GaoOrderPaymentRevokeRequest> fundRevokeList; private List<GaoOrderPaymentRevokeRequest> fundRevokeList;
/// 取消时登记的退款
private List<GaoOrderPaymentRefundRequest> fundRefundList;
} }
@@ -30,6 +30,7 @@ public enum AuditOperation {
GAO_ORDER_FULFILLMENT_REJECT(Logger.Module.GAO), GAO_ORDER_FULFILLMENT_REJECT(Logger.Module.GAO),
GAO_ORDER_FULFILLMENT_CANCEL(Logger.Module.GAO), GAO_ORDER_FULFILLMENT_CANCEL(Logger.Module.GAO),
GAO_ORDER_FULFILLMENT_REVOKE(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_CREATE(Logger.Module.GAO),
GAO_PACKAGE_CONFIG_UPDATE(Logger.Module.GAO), GAO_PACKAGE_CONFIG_UPDATE(Logger.Module.GAO),
GAO_PACKAGE_CONFIG_DELETE(Logger.Module.GAO), GAO_PACKAGE_CONFIG_DELETE(Logger.Module.GAO),
@@ -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';