Compare commits
52
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d22df698b6 | ||
|
|
1771bf9909 | ||
|
|
15d69f9361 | ||
|
|
2b4089ef59 | ||
|
|
20c3e1f422 | ||
|
|
3b19d9e930 | ||
|
|
5fd11e9caf | ||
|
|
0b98dcdfe9 | ||
|
|
b373cbbe46 | ||
|
|
acd97c7b9b | ||
|
|
118bdb1666 | ||
|
|
944de228f7 | ||
|
|
25c9cd4dfc | ||
|
|
882cd226ec | ||
|
|
feb4d7af66 | ||
|
|
d75ab1ed5f | ||
|
|
a501eb7443 | ||
|
|
19941d9480 | ||
|
|
cd3d522d4f | ||
|
|
181c5078e9 | ||
|
|
e97f46e6b4 | ||
|
|
c0f89deb83 | ||
|
|
ce695463d3 | ||
|
|
83c683d473 | ||
|
|
9555474b0b | ||
|
|
a150f9e017 | ||
|
|
ecd2fa1c33 | ||
|
|
e3236d262d | ||
|
|
c8e2e16ba5 | ||
|
|
99b44faf09 | ||
|
|
b3e3cbf84b | ||
|
|
0aee11d824 | ||
|
|
fcf358a768 | ||
|
|
619369104c | ||
|
|
4f1408b9d0 | ||
|
|
029eea70cc | ||
|
|
22b1e65385 | ||
|
|
2170c48763 | ||
|
|
c2d1c48aae | ||
|
|
e14958c643 | ||
|
|
da288338cd | ||
|
|
ea430f2468 | ||
|
|
f76f79744a | ||
|
|
19daaff907 | ||
|
|
db94d8f932 | ||
|
|
53618fe362 | ||
|
|
523edffc4e | ||
|
|
c7ddb1a8b0 | ||
|
|
45c9fc814a | ||
|
|
407dc13ac4 | ||
|
|
0c06bf16c2 | ||
|
|
1db39e77d3 |
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
<groupId>com.imyeyu.timiserverapi</groupId>
|
<groupId>com.imyeyu.timiserverapi</groupId>
|
||||||
<artifactId>TimiServerAPI</artifactId>
|
<artifactId>TimiServerAPI</artifactId>
|
||||||
<version>1.0.47</version>
|
<version>1.0.41</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>TimiServerAPI</name>
|
<name>TimiServerAPI</name>
|
||||||
<description>imyeyu.com API</description>
|
<description>imyeyu.com API</description>
|
||||||
|
|||||||
@@ -34,8 +34,6 @@ public class Article extends UUIDEntity implements SettingSupport {
|
|||||||
/// GAO 门店日记
|
/// GAO 门店日记
|
||||||
GAO_STORE_DIARY,
|
GAO_STORE_DIARY,
|
||||||
|
|
||||||
GAO_HELP,
|
|
||||||
|
|
||||||
GAO_SYSTEM,
|
GAO_SYSTEM,
|
||||||
|
|
||||||
/// 反馈
|
/// 反馈
|
||||||
|
|||||||
@@ -52,10 +52,6 @@ public class Attachment extends UUIDEntity {
|
|||||||
|
|
||||||
GAO_SALES_ORDER,
|
GAO_SALES_ORDER,
|
||||||
|
|
||||||
GAO_POINT_REDEMPTION,
|
|
||||||
|
|
||||||
GAO_POINT_REDEMPTION_RETURN,
|
|
||||||
|
|
||||||
TEMP_FILE,
|
TEMP_FILE,
|
||||||
|
|
||||||
MIRROR
|
MIRROR
|
||||||
|
|||||||
@@ -139,14 +139,6 @@ public enum GaoPermissionCode implements BuiltinPermissionCode {
|
|||||||
|
|
||||||
POINT_SOURCE_VALUE("POINT:SOURCE_VALUE", "登记提交自定义积分值", true, true),
|
POINT_SOURCE_VALUE("POINT:SOURCE_VALUE", "登记提交自定义积分值", true, true),
|
||||||
|
|
||||||
POINT_REDEMPTION_CREATE("POINT_REDEMPTION:CREATE", "积分兑换创建和读取", true, true),
|
|
||||||
|
|
||||||
POINT_REDEMPTION_POINT_ADJUST("POINT_REDEMPTION:POINT_ADJUST", "积分兑换减免积分", true, true),
|
|
||||||
|
|
||||||
POINT_REDEMPTION_RETURN("POINT_REDEMPTION:RETURN", "积分兑换退货", true, true),
|
|
||||||
|
|
||||||
POINT_REDEEM_SKU_MANAGE("POINT_REDEEM_SKU:MANAGE", "积分兑换 SKU 配置管理", true, true),
|
|
||||||
|
|
||||||
STAT_READ("STAT:READ", "统计读取", false, false),
|
STAT_READ("STAT:READ", "统计读取", false, false),
|
||||||
|
|
||||||
QR_CODE_CREATE("QR_CODE:CREATE", "二维码创建", false, false),
|
QR_CODE_CREATE("QR_CODE:CREATE", "二维码创建", false, false),
|
||||||
|
|||||||
@@ -1,85 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.controller;
|
|
||||||
|
|
||||||
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
|
||||||
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoPointRedeemSku;
|
|
||||||
import com.imyeyu.api.modules.gao.service.GaoPointRedeemSkuService;
|
|
||||||
import com.imyeyu.api.modules.gao.service.GaoStoreScopeService;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoPointRedeemSkuPage;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoPointRedeemSkuRequest;
|
|
||||||
import com.imyeyu.java.bean.timi.TimiException;
|
|
||||||
import com.imyeyu.spring.annotation.AOPLog;
|
|
||||||
import com.imyeyu.spring.annotation.RequestRateLimit;
|
|
||||||
import com.imyeyu.spring.bean.PageResult;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
/// GAO 积分兑换 SKU 配置接口
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-09-14
|
|
||||||
@RestController
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@RequestMapping("/gao/point/redeem-sku")
|
|
||||||
public class GaoPointRedeemSkuController {
|
|
||||||
|
|
||||||
private final GaoPointRedeemSkuService service;
|
|
||||||
private final GaoStoreScopeService storeScopeService;
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.POINT_REDEEM_SKU_MANAGE)
|
|
||||||
@PostMapping("/list")
|
|
||||||
public PageResult<GaoPointRedeemSku> list(@RequestBody GaoPointRedeemSkuPage page) {
|
|
||||||
TimiException.required(page, "not found redeem sku page");
|
|
||||||
page.setStoreId(storeScopeService.resolveStoreId(page.getStoreId()));
|
|
||||||
return service.pageByQuery(page);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.POINT_REDEEM_SKU_MANAGE)
|
|
||||||
@PostMapping("/detail")
|
|
||||||
public GaoPointRedeemSku detail(@RequestParam String id, @RequestParam(required = false) String storeId) {
|
|
||||||
return service.detail(storeScopeService.resolveStoreId(storeId), id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.POINT_REDEEM_SKU_MANAGE)
|
|
||||||
@PostMapping("/create")
|
|
||||||
public GaoPointRedeemSku create(@RequestBody GaoPointRedeemSkuRequest request) {
|
|
||||||
TimiException.required(request, "not found redeem sku request");
|
|
||||||
request.setStoreId(storeScopeService.resolveStoreId(request.getStoreId()));
|
|
||||||
return service.create(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.POINT_REDEEM_SKU_MANAGE)
|
|
||||||
@PostMapping("/update")
|
|
||||||
public GaoPointRedeemSku update(@RequestBody GaoPointRedeemSkuRequest request) {
|
|
||||||
TimiException.required(request, "not found redeem sku request");
|
|
||||||
return service.update(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.POINT_REDEEM_SKU_MANAGE)
|
|
||||||
@PostMapping("/disable")
|
|
||||||
public void disable(@RequestParam String id, @RequestParam(required = false) String storeId) {
|
|
||||||
service.disable(storeScopeService.resolveStoreId(storeId), id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.POINT_REDEEM_SKU_MANAGE)
|
|
||||||
@PostMapping("/delete")
|
|
||||||
public void delete(@RequestParam String id, @RequestParam(required = false) String storeId) {
|
|
||||||
service.delete(storeScopeService.resolveStoreId(storeId), id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.controller;
|
|
||||||
|
|
||||||
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
|
||||||
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoPointRedemption;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoPointRedemptionReturn;
|
|
||||||
import com.imyeyu.api.modules.gao.service.GaoPointRedemptionService;
|
|
||||||
import com.imyeyu.api.modules.gao.service.GaoStoreScopeService;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoPointRedemptionCreateRequest;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoPointRedemptionPage;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoPointRedemptionReturnRequest;
|
|
||||||
import com.imyeyu.java.bean.timi.TimiException;
|
|
||||||
import com.imyeyu.spring.annotation.AOPLog;
|
|
||||||
import com.imyeyu.spring.annotation.RequestRateLimit;
|
|
||||||
import com.imyeyu.spring.bean.PageResult;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/// GAO 积分兑换单接口
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-09-14
|
|
||||||
@RestController
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@RequestMapping("/gao/point/redemption")
|
|
||||||
public class GaoPointRedemptionController {
|
|
||||||
|
|
||||||
private final GaoPointRedemptionService service;
|
|
||||||
private final GaoStoreScopeService storeScopeService;
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.POINT_REDEMPTION_CREATE)
|
|
||||||
@PostMapping("/list")
|
|
||||||
public PageResult<GaoPointRedemption> list(@RequestBody GaoPointRedemptionPage page) {
|
|
||||||
TimiException.required(page, "not found redemption page");
|
|
||||||
page.setStoreId(storeScopeService.resolveStoreId(page.getStoreId()));
|
|
||||||
return service.pageByQuery(page);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.POINT_REDEMPTION_CREATE)
|
|
||||||
@PostMapping("/detail")
|
|
||||||
public GaoPointRedemption detail(@RequestParam String id, @RequestParam(required = false) String storeId) {
|
|
||||||
return service.detail(storeScopeService.resolveStoreId(storeId), id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.POINT_REDEMPTION_CREATE)
|
|
||||||
@PostMapping("/create")
|
|
||||||
public GaoPointRedemption create(@RequestBody GaoPointRedemptionCreateRequest request) {
|
|
||||||
TimiException.required(request, "not found redemption request");
|
|
||||||
request.setStoreId(storeScopeService.resolveStoreId(request.getStoreId()));
|
|
||||||
return service.create(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.POINT_REDEMPTION_RETURN)
|
|
||||||
@PostMapping("/return")
|
|
||||||
public GaoPointRedemption returnRedemption(@RequestBody GaoPointRedemptionReturnRequest request) {
|
|
||||||
return service.returnRedemption(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.POINT_REDEMPTION_RETURN)
|
|
||||||
@PostMapping("/return/list")
|
|
||||||
public List<GaoPointRedemptionReturn> returnList(@RequestParam String redemptionId, @RequestParam(required = false) String storeId) {
|
|
||||||
return service.listReturns(storeScopeService.resolveStoreId(storeId), redemptionId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -47,10 +47,7 @@ public class GaoPointLedger extends UUIDEntity {
|
|||||||
EVENT_RECORD,
|
EVENT_RECORD,
|
||||||
|
|
||||||
/// 订单首次全额实收
|
/// 订单首次全额实收
|
||||||
SALES_ORDER_PAID,
|
SALES_ORDER_PAID
|
||||||
|
|
||||||
/// 积分兑换
|
|
||||||
POINT_REDEMPTION
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 客户积分账户 ID
|
/// 客户积分账户 ID
|
||||||
|
|||||||
@@ -1,78 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.entity;
|
|
||||||
|
|
||||||
import com.imyeyu.spring.annotation.table.Transient;
|
|
||||||
import com.imyeyu.spring.entity.UUIDEntity;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
|
|
||||||
/// GAO 积分兑换 SKU 配置
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-09-14
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
public class GaoPointRedeemSku extends UUIDEntity {
|
|
||||||
|
|
||||||
/// 配置状态
|
|
||||||
public enum Status {
|
|
||||||
|
|
||||||
/// 草稿
|
|
||||||
DRAFT,
|
|
||||||
|
|
||||||
/// 启用
|
|
||||||
ACTIVE,
|
|
||||||
|
|
||||||
/// 停用
|
|
||||||
INACTIVE,
|
|
||||||
|
|
||||||
/// 删除
|
|
||||||
DELETED
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 门店 ID
|
|
||||||
private String storeId;
|
|
||||||
|
|
||||||
/// SKU ID
|
|
||||||
private String skuId;
|
|
||||||
|
|
||||||
/// SKU 单位 ID
|
|
||||||
private String skuUnitId;
|
|
||||||
|
|
||||||
/// 配置状态
|
|
||||||
private Status status;
|
|
||||||
|
|
||||||
/// 每个业务单位默认所需积分
|
|
||||||
private Long defaultPointCost;
|
|
||||||
|
|
||||||
/// 生效开始时间戳,毫秒
|
|
||||||
private Long beginAt;
|
|
||||||
|
|
||||||
/// 生效结束时间戳,毫秒
|
|
||||||
private Long endAt;
|
|
||||||
|
|
||||||
/// 每客户累计最多兑换数量
|
|
||||||
private BigDecimal maxTotalQuantity;
|
|
||||||
|
|
||||||
/// 每客户自然日最多兑换数量
|
|
||||||
private BigDecimal maxDailyQuantity;
|
|
||||||
|
|
||||||
/// 每客户自然月最多兑换数量
|
|
||||||
private BigDecimal maxMonthlyQuantity;
|
|
||||||
|
|
||||||
/// 备注
|
|
||||||
private String remark;
|
|
||||||
|
|
||||||
/// 产品
|
|
||||||
@Transient
|
|
||||||
private GaoProduct product;
|
|
||||||
|
|
||||||
/// SKU
|
|
||||||
@Transient
|
|
||||||
private GaoProductSku sku;
|
|
||||||
|
|
||||||
/// SKU 单位
|
|
||||||
@Transient
|
|
||||||
private GaoProductSkuUnit unit;
|
|
||||||
}
|
|
||||||
@@ -1,123 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.entity;
|
|
||||||
|
|
||||||
import com.imyeyu.api.modules.common.entity.Attachment;
|
|
||||||
import com.imyeyu.spring.annotation.table.Transient;
|
|
||||||
import com.imyeyu.spring.entity.UUIDEntity;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/// GAO 积分兑换单
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-09-14
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
public class GaoPointRedemption extends UUIDEntity {
|
|
||||||
|
|
||||||
/// 兑换单状态
|
|
||||||
public enum Status {
|
|
||||||
|
|
||||||
/// 已完成兑换
|
|
||||||
COMPLETED,
|
|
||||||
|
|
||||||
/// 已部分退货
|
|
||||||
PARTIALLY_RETURNED,
|
|
||||||
|
|
||||||
/// 已全部退货
|
|
||||||
FULLY_RETURNED
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 门店 ID
|
|
||||||
private String storeId;
|
|
||||||
|
|
||||||
/// 客户 ID
|
|
||||||
private String customerId;
|
|
||||||
|
|
||||||
/// 创建幂等号
|
|
||||||
private String requestNo;
|
|
||||||
|
|
||||||
/// 兑换配置 ID 快照
|
|
||||||
private String redeemSkuIdSnapshot;
|
|
||||||
|
|
||||||
/// 产品 ID 快照
|
|
||||||
private String productIdSnapshot;
|
|
||||||
|
|
||||||
/// 产品名称快照
|
|
||||||
private String productNameSnapshot;
|
|
||||||
|
|
||||||
/// 产品类型快照
|
|
||||||
private GaoProduct.ProductType productTypeSnapshot;
|
|
||||||
|
|
||||||
/// SKU ID 快照
|
|
||||||
private String skuIdSnapshot;
|
|
||||||
|
|
||||||
/// SKU 编码快照
|
|
||||||
private String skuCodeSnapshot;
|
|
||||||
|
|
||||||
/// SKU 名称快照
|
|
||||||
private String skuNameSnapshot;
|
|
||||||
|
|
||||||
/// SKU 规格结构快照
|
|
||||||
private com.fasterxml.jackson.databind.JsonNode skuSpecSnapshot;
|
|
||||||
|
|
||||||
/// SKU 单位 ID 快照
|
|
||||||
private String skuUnitIdSnapshot;
|
|
||||||
|
|
||||||
/// 单位名称快照
|
|
||||||
private String unitSnapshot;
|
|
||||||
|
|
||||||
/// 每个业务单位基础数量快照
|
|
||||||
private BigDecimal baseQuantityPerUnitSnapshot;
|
|
||||||
|
|
||||||
/// true 为允许小数数量快照
|
|
||||||
private Boolean allowDecimalQuantitySnapshot;
|
|
||||||
|
|
||||||
/// 兑换业务数量
|
|
||||||
private BigDecimal quantity;
|
|
||||||
|
|
||||||
/// 兑换基础数量
|
|
||||||
private BigDecimal baseQuantity;
|
|
||||||
|
|
||||||
/// 默认总积分
|
|
||||||
private Long defaultPointCost;
|
|
||||||
|
|
||||||
/// 实际扣除总积分
|
|
||||||
private Long actualPointCost;
|
|
||||||
|
|
||||||
/// 累计已退业务数量
|
|
||||||
private BigDecimal returnedQuantity;
|
|
||||||
|
|
||||||
/// 累计已返积分
|
|
||||||
private Long returnedPointCost;
|
|
||||||
|
|
||||||
/// 兑换单状态
|
|
||||||
private Status status;
|
|
||||||
|
|
||||||
/// 兑换操作人
|
|
||||||
private String operatorUserId;
|
|
||||||
|
|
||||||
/// 兑换完成时间
|
|
||||||
private Long redeemedAt;
|
|
||||||
|
|
||||||
/// 备注
|
|
||||||
private String remark;
|
|
||||||
|
|
||||||
/// 客户
|
|
||||||
@Transient
|
|
||||||
private GaoCustomer customer;
|
|
||||||
|
|
||||||
/// 产品类型
|
|
||||||
@Transient
|
|
||||||
private GaoProduct.ProductType productType;
|
|
||||||
|
|
||||||
/// 兑换照片
|
|
||||||
@Transient
|
|
||||||
private List<Attachment> attachmentList;
|
|
||||||
|
|
||||||
/// 退货记录
|
|
||||||
@Transient
|
|
||||||
private List<GaoPointRedemptionReturn> returnList;
|
|
||||||
}
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.entity;
|
|
||||||
|
|
||||||
import com.imyeyu.api.modules.common.entity.Attachment;
|
|
||||||
import com.imyeyu.spring.annotation.table.Transient;
|
|
||||||
import com.imyeyu.spring.entity.UUIDEntity;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/// GAO 积分兑换退货记录
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-09-14
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
public class GaoPointRedemptionReturn extends UUIDEntity {
|
|
||||||
|
|
||||||
/// 兑换单 ID
|
|
||||||
private String redemptionId;
|
|
||||||
|
|
||||||
/// 退货幂等号
|
|
||||||
private String requestNo;
|
|
||||||
|
|
||||||
/// 本次退货业务数量
|
|
||||||
private BigDecimal quantity;
|
|
||||||
|
|
||||||
/// 本次退货基础数量
|
|
||||||
private BigDecimal baseQuantity;
|
|
||||||
|
|
||||||
/// 本次实际返还积分
|
|
||||||
private Long pointCost;
|
|
||||||
|
|
||||||
/// 实物退货入库流水 ID
|
|
||||||
private String stockRecordId;
|
|
||||||
|
|
||||||
/// 退货操作人
|
|
||||||
private String operatorUserId;
|
|
||||||
|
|
||||||
/// 退货时间
|
|
||||||
private Long returnedAt;
|
|
||||||
|
|
||||||
/// 退货原因和备注
|
|
||||||
private String remark;
|
|
||||||
|
|
||||||
/// 退货照片
|
|
||||||
@Transient
|
|
||||||
private List<Attachment> attachmentList;
|
|
||||||
}
|
|
||||||
@@ -27,10 +27,7 @@ public class GaoProductStockRecord implements IDEntity<String>, Creatable {
|
|||||||
PRODUCT_STOCK,
|
PRODUCT_STOCK,
|
||||||
|
|
||||||
/// 订单履约库存操作
|
/// 订单履约库存操作
|
||||||
ORDER_FULFILLMENT,
|
ORDER_FULFILLMENT
|
||||||
|
|
||||||
/// 积分兑换库存操作
|
|
||||||
POINT_REDEMPTION
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 库存操作类型
|
/// 库存操作类型
|
||||||
@@ -60,12 +57,6 @@ public class GaoProductStockRecord implements IDEntity<String>, Creatable {
|
|||||||
/// 履约冲正入库
|
/// 履约冲正入库
|
||||||
ORDER_REVOKE,
|
ORDER_REVOKE,
|
||||||
|
|
||||||
/// 积分兑换实物出库
|
|
||||||
POINT_REDEMPTION_OUT,
|
|
||||||
|
|
||||||
/// 积分兑换退货入库
|
|
||||||
POINT_REDEMPTION_RETURN_IN,
|
|
||||||
|
|
||||||
/// 盘盈
|
/// 盘盈
|
||||||
STOCKTAKE_GAIN,
|
STOCKTAKE_GAIN,
|
||||||
|
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.mapper;
|
|
||||||
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoPointRedeemSku;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoPointRedeemSkuPage;
|
|
||||||
import com.imyeyu.spring.mapper.BaseMapper;
|
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/// GAO 积分兑换 SKU 配置 Mapper
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-09-14
|
|
||||||
public interface GaoPointRedeemSkuMapper extends BaseMapper<GaoPointRedeemSku, String> {
|
|
||||||
|
|
||||||
/// 按门店和配置 ID 查询
|
|
||||||
GaoPointRedeemSku selectByStoreIdAndId(@Param("storeId") String storeId, @Param("id") String id);
|
|
||||||
|
|
||||||
/// 按门店、SKU 和单位查询
|
|
||||||
GaoPointRedeemSku selectByStoreSkuUnit(@Param("storeId") String storeId, @Param("skuId") String skuId, @Param("skuUnitId") String skuUnitId);
|
|
||||||
|
|
||||||
/// 锁定兑换 SKU 配置
|
|
||||||
GaoPointRedeemSku selectForUpdate(@Param("id") String id);
|
|
||||||
|
|
||||||
/// 按条件统计配置数量
|
|
||||||
long countByQuery(GaoPointRedeemSkuPage page);
|
|
||||||
|
|
||||||
/// 按条件分页查询配置
|
|
||||||
List<GaoPointRedeemSku> selectByQuery(GaoPointRedeemSkuPage page);
|
|
||||||
|
|
||||||
/// 更新兑换 SKU 配置,可清空可空字段
|
|
||||||
void updateConfig(GaoPointRedeemSku config);
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.mapper;
|
|
||||||
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoPointRedemption;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoPointRedemptionPage;
|
|
||||||
import com.imyeyu.spring.mapper.BaseMapper;
|
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/// GAO 积分兑换单 Mapper
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-09-14
|
|
||||||
public interface GaoPointRedemptionMapper extends BaseMapper<GaoPointRedemption, String> {
|
|
||||||
|
|
||||||
/// 按门店和创建幂等号查询兑换单
|
|
||||||
GaoPointRedemption selectByStoreIdAndRequestNo(@Param("storeId") String storeId, @Param("requestNo") String requestNo);
|
|
||||||
|
|
||||||
/// 按门店和 ID 查询兑换单
|
|
||||||
GaoPointRedemption selectByStoreIdAndId(@Param("storeId") String storeId, @Param("id") String id);
|
|
||||||
|
|
||||||
/// 锁定兑换单
|
|
||||||
GaoPointRedemption selectForUpdate(@Param("id") String id);
|
|
||||||
|
|
||||||
/// 按条件统计兑换单
|
|
||||||
long countByQuery(GaoPointRedemptionPage page);
|
|
||||||
|
|
||||||
/// 按条件分页查询兑换单
|
|
||||||
List<GaoPointRedemption> selectByQuery(GaoPointRedemptionPage page);
|
|
||||||
|
|
||||||
/// 统计客户指定 SKU 的有效兑换数量
|
|
||||||
BigDecimal sumValidQuantity(@Param("storeId") String storeId, @Param("customerId") String customerId,
|
|
||||||
@Param("skuId") String skuId, @Param("beginAt") Long beginAt, @Param("endAt") Long endAt);
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.mapper;
|
|
||||||
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoPointRedemptionReturn;
|
|
||||||
import com.imyeyu.spring.mapper.BaseMapper;
|
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/// GAO 积分兑换退货 Mapper
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-09-14
|
|
||||||
public interface GaoPointRedemptionReturnMapper extends BaseMapper<GaoPointRedemptionReturn, String> {
|
|
||||||
|
|
||||||
/// 按兑换单查询退货记录
|
|
||||||
List<GaoPointRedemptionReturn> selectByRedemptionId(@Param("redemptionId") String redemptionId);
|
|
||||||
|
|
||||||
/// 批量按兑换单查询退货记录
|
|
||||||
List<GaoPointRedemptionReturn> selectByRedemptionIdList(@Param("redemptionIdList") List<String> redemptionIdList);
|
|
||||||
|
|
||||||
/// 按兑换单和退货幂等号查询
|
|
||||||
GaoPointRedemptionReturn selectByRedemptionIdAndRequestNo(@Param("redemptionId") String redemptionId, @Param("requestNo") String requestNo);
|
|
||||||
|
|
||||||
/// 锁定退货记录
|
|
||||||
GaoPointRedemptionReturn selectForUpdate(@Param("id") String id);
|
|
||||||
}
|
|
||||||
@@ -16,9 +16,6 @@ public interface GaoOrderPaymentService {
|
|||||||
/// 登记收款
|
/// 登记收款
|
||||||
GaoFundRecord receive(GaoOrderPaymentReceiveRequest request);
|
GaoFundRecord receive(GaoOrderPaymentReceiveRequest request);
|
||||||
|
|
||||||
/// 登记已收款并直接核销
|
|
||||||
GaoFundRecord receiveAndVerify(GaoOrderPaymentReceiveRequest request);
|
|
||||||
|
|
||||||
/// 核销收款
|
/// 核销收款
|
||||||
GaoFundRecord verify(String fundRecordId);
|
GaoFundRecord verify(String fundRecordId);
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.service;
|
|
||||||
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoSalesOrder;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoOrderStraightThroughRequest;
|
|
||||||
|
|
||||||
/// GAO 订单创建直通服务
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-09-13
|
|
||||||
public interface GaoOrderStraightThroughService {
|
|
||||||
|
|
||||||
/// 在订单创建事务内完成可选的全额收款和全部履约
|
|
||||||
///
|
|
||||||
/// @param order 销售订单
|
|
||||||
/// @param straightThrough 直通请求,空为不直通
|
|
||||||
void complete(GaoSalesOrder order, GaoOrderStraightThroughRequest straightThrough);
|
|
||||||
}
|
|
||||||
@@ -53,31 +53,6 @@ public interface GaoPointLedgerService extends BaseService<GaoPointLedger, Strin
|
|||||||
/// @return 调整流水
|
/// @return 调整流水
|
||||||
GaoPointLedger adjust(GaoPointAdjustRequest request, String operatorUserId);
|
GaoPointLedger adjust(GaoPointAdjustRequest request, String operatorUserId);
|
||||||
|
|
||||||
/// 为积分兑换扣减积分
|
|
||||||
///
|
|
||||||
/// @param storeId 门店 ID
|
|
||||||
/// @param customerId 客户 ID
|
|
||||||
/// @param redemptionId 兑换单 ID
|
|
||||||
/// @param pointCost 实际扣减积分
|
|
||||||
/// @param operatorUserId 操作用户 ID
|
|
||||||
/// @param remark 备注
|
|
||||||
/// @return 积分流水;积分为 0 时返回 null
|
|
||||||
GaoPointLedger consumeForRedemption(String storeId, String customerId, String redemptionId, long pointCost,
|
|
||||||
String operatorUserId, String remark);
|
|
||||||
|
|
||||||
/// 为积分兑换退货返还积分
|
|
||||||
///
|
|
||||||
/// @param storeId 门店 ID
|
|
||||||
/// @param customerId 客户 ID
|
|
||||||
/// @param redemptionId 兑换单 ID
|
|
||||||
/// @param returnId 退货记录 ID
|
|
||||||
/// @param pointCost 实际返还积分
|
|
||||||
/// @param operatorUserId 操作用户 ID
|
|
||||||
/// @param remark 备注
|
|
||||||
/// @return 积分流水;积分为 0 时返回 null
|
|
||||||
GaoPointLedger revokeForRedemption(String storeId, String customerId, String redemptionId, String returnId, long pointCost,
|
|
||||||
String operatorUserId, String remark);
|
|
||||||
|
|
||||||
/// 查询触发来源产生的原始规则积分流水
|
/// 查询触发来源产生的原始规则积分流水
|
||||||
///
|
///
|
||||||
/// @param triggerSourceType 直接触发来源类型
|
/// @param triggerSourceType 直接触发来源类型
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.service;
|
|
||||||
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoPointRedeemSku;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoPointRedeemSkuPage;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoPointRedeemSkuRequest;
|
|
||||||
import com.imyeyu.spring.bean.PageResult;
|
|
||||||
|
|
||||||
/// GAO 积分兑换 SKU 配置服务
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-09-14
|
|
||||||
public interface GaoPointRedeemSkuService {
|
|
||||||
|
|
||||||
/// 分页查询兑换 SKU 配置
|
|
||||||
PageResult<GaoPointRedeemSku> pageByQuery(GaoPointRedeemSkuPage page);
|
|
||||||
|
|
||||||
/// 查询兑换 SKU 配置详情
|
|
||||||
GaoPointRedeemSku detail(String storeId, String id);
|
|
||||||
|
|
||||||
/// 查询并锁定兑换 SKU 配置
|
|
||||||
GaoPointRedeemSku getForUpdate(String id);
|
|
||||||
|
|
||||||
/// 创建兑换 SKU 配置
|
|
||||||
GaoPointRedeemSku create(GaoPointRedeemSkuRequest request);
|
|
||||||
|
|
||||||
/// 修改兑换 SKU 配置
|
|
||||||
GaoPointRedeemSku update(GaoPointRedeemSkuRequest request);
|
|
||||||
|
|
||||||
/// 停用兑换 SKU 配置
|
|
||||||
void disable(String storeId, String id);
|
|
||||||
|
|
||||||
/// 标记删除兑换 SKU 配置
|
|
||||||
void delete(String storeId, String id);
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.service;
|
|
||||||
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoPointRedemption;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoPointRedemptionReturn;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoPointRedemptionCreateRequest;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoPointRedemptionPage;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoPointRedemptionReturnRequest;
|
|
||||||
import com.imyeyu.spring.bean.PageResult;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/// GAO 积分兑换业务服务
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-09-14
|
|
||||||
public interface GaoPointRedemptionService {
|
|
||||||
|
|
||||||
/// 分页查询兑换单
|
|
||||||
PageResult<GaoPointRedemption> pageByQuery(GaoPointRedemptionPage page);
|
|
||||||
|
|
||||||
/// 查询兑换单详情
|
|
||||||
GaoPointRedemption detail(String storeId, String id);
|
|
||||||
|
|
||||||
/// 创建并完成积分兑换
|
|
||||||
GaoPointRedemption create(GaoPointRedemptionCreateRequest request);
|
|
||||||
|
|
||||||
/// 发起部分或全部退货
|
|
||||||
GaoPointRedemption returnRedemption(GaoPointRedemptionReturnRequest request);
|
|
||||||
|
|
||||||
/// 查询兑换单退货记录
|
|
||||||
List<GaoPointRedemptionReturn> listReturns(String storeId, String redemptionId);
|
|
||||||
}
|
|
||||||
@@ -33,14 +33,6 @@ public interface GaoProductSkuService extends BaseService<GaoProductSku, String>
|
|||||||
/// 查询并校验可销售 SKU 单位
|
/// 查询并校验可销售 SKU 单位
|
||||||
GaoProductSkuUnitSelection getSellableSkuUnit(String storeId, String skuId, String skuUnitId);
|
GaoProductSkuUnitSelection getSellableSkuUnit(String storeId, String skuId, String skuUnitId);
|
||||||
|
|
||||||
/// 查询并校验可用于历史订单履约的 SKU 单位
|
|
||||||
///
|
|
||||||
/// @param storeId 门店 ID
|
|
||||||
/// @param skuId SKU ID
|
|
||||||
/// @param skuUnitId SKU 单位 ID
|
|
||||||
/// @return SKU 单位选择结果
|
|
||||||
GaoProductSkuUnitSelection getFulfillableSkuUnit(String storeId, String skuId, String skuUnitId);
|
|
||||||
|
|
||||||
/// 查询并校验 SKU 单位
|
/// 查询并校验 SKU 单位
|
||||||
GaoProductSkuUnitSelection getSkuUnit(String storeId, String skuId, String skuUnitId, boolean purchase);
|
GaoProductSkuUnitSelection getSkuUnit(String storeId, String skuId, String skuUnitId, boolean purchase);
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.imyeyu.api.modules.gao.service;
|
package com.imyeyu.api.modules.gao.service;
|
||||||
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoProductStock;
|
import com.imyeyu.api.modules.gao.entity.GaoProductStock;
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoProductStockRecord;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoProductStockChangeRequest;
|
import com.imyeyu.api.modules.gao.vo.GaoProductStockChangeRequest;
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoProductStockManualRevokeRequest;
|
import com.imyeyu.api.modules.gao.vo.GaoProductStockManualRevokeRequest;
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoProductStockPage;
|
import com.imyeyu.api.modules.gao.vo.GaoProductStockPage;
|
||||||
@@ -47,9 +46,6 @@ public interface GaoProductStockService {
|
|||||||
/// 为履约预占库存
|
/// 为履约预占库存
|
||||||
boolean hasSufficientForFulfillment(String storeId, List<GaoStockChangeItem> items);
|
boolean hasSufficientForFulfillment(String storeId, List<GaoStockChangeItem> items);
|
||||||
|
|
||||||
/// 获取履约库存缺口提示,无缺口时返回 null
|
|
||||||
String getFulfillmentStockShortageMessage(String storeId, List<GaoStockChangeItem> items);
|
|
||||||
|
|
||||||
/// 为履约预占库存
|
/// 为履约预占库存
|
||||||
List<GaoProductStock> reserveForFulfillment(String storeId, String bizId, List<GaoStockChangeItem> items, String requestNo, String operatorUserId);
|
List<GaoProductStock> reserveForFulfillment(String storeId, String bizId, List<GaoStockChangeItem> items, String requestNo, String operatorUserId);
|
||||||
|
|
||||||
@@ -61,10 +57,4 @@ 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);
|
||||||
|
|
||||||
/// 为积分兑换实物出库
|
|
||||||
GaoProductStockRecord outForRedemption(String storeId, String redemptionId, GaoStockChangeItem item, String requestNo, String operatorUserId);
|
|
||||||
|
|
||||||
/// 为积分兑换退货入库
|
|
||||||
GaoProductStockRecord inForRedemptionReturn(String storeId, String returnId, GaoStockChangeItem item, String requestNo, String operatorUserId);
|
|
||||||
}
|
}
|
||||||
|
|||||||
-5
@@ -13,7 +13,6 @@ import com.imyeyu.api.modules.gao.entity.GaoSalesOrder;
|
|||||||
import com.imyeyu.api.modules.gao.entity.GaoSalesOrderItem;
|
import com.imyeyu.api.modules.gao.entity.GaoSalesOrderItem;
|
||||||
import com.imyeyu.api.modules.gao.mapper.GaoCustomerPackageMapper;
|
import com.imyeyu.api.modules.gao.mapper.GaoCustomerPackageMapper;
|
||||||
import com.imyeyu.api.modules.gao.service.GaoSalesOrderService;
|
import com.imyeyu.api.modules.gao.service.GaoSalesOrderService;
|
||||||
import com.imyeyu.api.modules.gao.service.GaoOrderStraightThroughService;
|
|
||||||
import com.imyeyu.api.modules.gao.service.GaoCustomerService;
|
import com.imyeyu.api.modules.gao.service.GaoCustomerService;
|
||||||
import com.imyeyu.api.modules.gao.service.GaoCustomerPackageService;
|
import com.imyeyu.api.modules.gao.service.GaoCustomerPackageService;
|
||||||
import com.imyeyu.api.modules.gao.service.GaoPackageConfigService;
|
import com.imyeyu.api.modules.gao.service.GaoPackageConfigService;
|
||||||
@@ -68,7 +67,6 @@ public class GaoCustomerPackageServiceImplement extends AbstractEntityService<Ga
|
|||||||
private final GaoProductSkuService skuService;
|
private final GaoProductSkuService skuService;
|
||||||
private final GaoCustomerService customerService;
|
private final GaoCustomerService customerService;
|
||||||
private final GaoSalesOrderService salesOrderService;
|
private final GaoSalesOrderService salesOrderService;
|
||||||
private final GaoOrderStraightThroughService straightThroughService;
|
|
||||||
private final GaoStoreScopeService storeScopeService;
|
private final GaoStoreScopeService storeScopeService;
|
||||||
private final AttachmentService attachmentService;
|
private final AttachmentService attachmentService;
|
||||||
private final UserLoginService userLoginService;
|
private final UserLoginService userLoginService;
|
||||||
@@ -170,7 +168,6 @@ public class GaoCustomerPackageServiceImplement extends AbstractEntityService<Ga
|
|||||||
if (existingOrder != null) {
|
if (existingOrder != null) {
|
||||||
GaoCustomerPackage existingPackage = getBySalesOrderId(existingOrder.getId());
|
GaoCustomerPackage existingPackage = getBySalesOrderId(existingOrder.getId());
|
||||||
verifyPurchaseIdempotency(existingOrder, existingPackage, request);
|
verifyPurchaseIdempotency(existingOrder, existingPackage, request);
|
||||||
straightThroughService.complete(salesOrderService.detail(existingOrder.getId()), request.getStraightThrough());
|
|
||||||
return existingPackage;
|
return existingPackage;
|
||||||
}
|
}
|
||||||
Long purchasedAt = TimiJava.defaultIfNull(request.getPurchasedAt(), Time.now());
|
Long purchasedAt = TimiJava.defaultIfNull(request.getPurchasedAt(), Time.now());
|
||||||
@@ -208,8 +205,6 @@ public class GaoCustomerPackageServiceImplement extends AbstractEntityService<Ga
|
|||||||
result.setStandardAmountSnapshot(config.getStandardAmount());
|
result.setStandardAmountSnapshot(config.getStandardAmount());
|
||||||
result.setRemark(request.getRemark());
|
result.setRemark(request.getRemark());
|
||||||
super.create(result);
|
super.create(result);
|
||||||
straightThroughService.complete(salesOrder, request.getStraightThrough());
|
|
||||||
salesOrder = salesOrderService.detail(salesOrder.getId());
|
|
||||||
result.setSalesOrder(salesOrder);
|
result.setSalesOrder(salesOrder);
|
||||||
result.setItemList(salesOrder.getItemList());
|
result.setItemList(salesOrder.getItemList());
|
||||||
result.setStatus(salesOrder.getStatus());
|
result.setStatus(salesOrder.getStatus());
|
||||||
|
|||||||
+2
-23
@@ -207,8 +207,7 @@ public class GaoOrderFulfillmentServiceImplement extends AbstractEntityService<G
|
|||||||
List<GaoStockChangeItem> stockItems = buildStockItems(order.getStoreId(), sourceList);
|
List<GaoStockChangeItem> stockItems = buildStockItems(order.getStoreId(), sourceList);
|
||||||
applySkuSpecSnapshots(stockItems, fulfillmentItemList);
|
applySkuSpecSnapshots(stockItems, fulfillmentItemList);
|
||||||
TimiException.requiredTrue(!stockItems.isEmpty(), "履约单没有需要占用的实物库存");
|
TimiException.requiredTrue(!stockItems.isEmpty(), "履约单没有需要占用的实物库存");
|
||||||
String stockShortageMessage = productStockService.getFulfillmentStockShortageMessage(order.getStoreId(), stockItems);
|
TimiException.requiredTrue(productStockService.hasSufficientForFulfillment(order.getStoreId(), stockItems), "库存仍然不足,不能准备履约");
|
||||||
TimiException.requiredTrue(stockShortageMessage == null, stockShortageMessage);
|
|
||||||
String operatorUserId = userLoginService.getRequireLoginUserId();
|
String operatorUserId = userLoginService.getRequireLoginUserId();
|
||||||
productStockService.reserveForFulfillment(order.getStoreId(), fulfillment.getId(), stockItems,
|
productStockService.reserveForFulfillment(order.getStoreId(), fulfillment.getId(), stockItems,
|
||||||
stockRequestNo(fulfillment, "RESERVE"), operatorUserId);
|
stockRequestNo(fulfillment, "RESERVE"), operatorUserId);
|
||||||
@@ -451,32 +450,12 @@ public class GaoOrderFulfillmentServiceImplement extends AbstractEntityService<G
|
|||||||
GaoSalesOrderItem.ItemType expectedItemType = order.getOrderType() == GaoSalesOrder.OrderType.PACKAGE
|
GaoSalesOrderItem.ItemType expectedItemType = order.getOrderType() == GaoSalesOrder.OrderType.PACKAGE
|
||||||
? GaoSalesOrderItem.ItemType.PACKAGE_ENTITLEMENT : GaoSalesOrderItem.ItemType.DIRECT_PRODUCT;
|
? GaoSalesOrderItem.ItemType.PACKAGE_ENTITLEMENT : GaoSalesOrderItem.ItemType.DIRECT_PRODUCT;
|
||||||
TimiException.requiredTrue(source.getItemType() == expectedItemType, "订单项类型与订单类型不匹配");
|
TimiException.requiredTrue(source.getItemType() == expectedItemType, "订单项类型与订单类型不匹配");
|
||||||
if (requestItem.getSkuUnitId().equals(source.getSkuUnitId())) {
|
GaoProductSkuUnitSelection selection = skuService.getSellableSkuUnit(order.getStoreId(), source.getSkuId(), requestItem.getSkuUnitId());
|
||||||
result.add(toSourceByOrderSnapshot(order, source, requestItem.getQuantity(), checkAvailable));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
GaoProductSkuUnitSelection selection = skuService.getFulfillableSkuUnit(order.getStoreId(), source.getSkuId(), requestItem.getSkuUnitId());
|
|
||||||
result.add(toSource(order, source, selection.getProduct(), selection.getSku(), selection.getUnit(), requestItem.getQuantity(), checkAvailable));
|
result.add(toSource(order, source, selection.getProduct(), selection.getSku(), selection.getUnit(), requestItem.getQuantity(), checkAvailable));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private SourceEntry toSourceByOrderSnapshot(GaoSalesOrder order, GaoSalesOrderItem source, BigDecimal quantity, boolean checkAvailable) {
|
|
||||||
GaoProductSku sku = skuService.get(source.getSkuId());
|
|
||||||
TimiException.required(sku, "履约来源 SKU 不存在");
|
|
||||||
GaoProduct product = productService.get(sku.getProductId());
|
|
||||||
TimiException.required(product, "履约来源产品不存在");
|
|
||||||
TimiException.requiredTrue(order.getStoreId().equals(product.getStoreId()), "履约来源产品不属于当前门店");
|
|
||||||
quantity = requiredPositiveQuantity(quantity, "履约数量");
|
|
||||||
if (!Boolean.TRUE.equals(sku.getAllowDecimalQuantity())) {
|
|
||||||
TimiException.requiredTrue(quantity.stripTrailingZeros().scale() <= 0, "该产品不允许小数数量");
|
|
||||||
}
|
|
||||||
BigDecimal baseQuantityPerUnit = requiredBaseQuantityPerUnit(source.getBaseQuantityPerUnitSnapshot());
|
|
||||||
BigDecimal baseQuantity = toBaseQuantity(quantity, baseQuantityPerUnit, "履约基础数量最多保留三位小数");
|
|
||||||
return buildSource(order, source, source.getSkuUnitId(), source.getUnitSnapshot(), baseQuantityPerUnit, quantity,
|
|
||||||
baseQuantity, product, sku, checkAvailable);
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<SourceEntry> loadPersistedSources(GaoSalesOrder order, List<GaoOrderFulfillmentItem> itemList) {
|
private List<SourceEntry> loadPersistedSources(GaoSalesOrder order, List<GaoOrderFulfillmentItem> itemList) {
|
||||||
TimiException.requiredTrue(itemList != null && !itemList.isEmpty(), "履约单没有明细");
|
TimiException.requiredTrue(itemList != null && !itemList.isEmpty(), "履约单没有明细");
|
||||||
List<GaoOrderFulfillmentItem> sortedItemList = new ArrayList<>(itemList);
|
List<GaoOrderFulfillmentItem> sortedItemList = new ArrayList<>(itemList);
|
||||||
|
|||||||
+4
-29
@@ -49,17 +49,10 @@ public class GaoOrderPaymentServiceImplement implements GaoOrderPaymentService {
|
|||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
@Override
|
@Override
|
||||||
public GaoFundRecord receive(GaoOrderPaymentReceiveRequest request) {
|
public GaoFundRecord receive(GaoOrderPaymentReceiveRequest request) {
|
||||||
return receiveInternal(request, false);
|
return receiveInternal(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
@OperationAudit(AuditOperation.GAO_SALES_ORDER_PAYMENT_RECEIVE)
|
private GaoFundRecord receiveInternal(GaoOrderPaymentReceiveRequest request) {
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
|
||||||
@Override
|
|
||||||
public GaoFundRecord receiveAndVerify(GaoOrderPaymentReceiveRequest request) {
|
|
||||||
return receiveInternal(request, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private GaoFundRecord receiveInternal(GaoOrderPaymentReceiveRequest request, boolean verified) {
|
|
||||||
TimiException.required(request, "not found order payment request");
|
TimiException.required(request, "not found order payment request");
|
||||||
TimiException.required(request.getSalesOrderId(), "not found salesOrderId");
|
TimiException.required(request.getSalesOrderId(), "not found salesOrderId");
|
||||||
TimiException.required(request.getAmount(), "收款金额不能为空");
|
TimiException.required(request.getAmount(), "收款金额不能为空");
|
||||||
@@ -69,7 +62,7 @@ public class GaoOrderPaymentServiceImplement implements GaoOrderPaymentService {
|
|||||||
GaoFundRecord existing = fundRecordService.getByRequestNo(order.getStoreId(), requestNo);
|
GaoFundRecord existing = fundRecordService.getByRequestNo(order.getStoreId(), requestNo);
|
||||||
if (existing != null) {
|
if (existing != null) {
|
||||||
verifySameReceive(existing, order, request);
|
verifySameReceive(existing, order, request);
|
||||||
return verified && existing.getStatus() == GaoFundRecord.Status.PENDING ? verify(existing.getId()) : existing;
|
return existing;
|
||||||
}
|
}
|
||||||
TimiException.requiredTrue(order.getStatus() != GaoSalesOrder.Status.CANCELLED, "已取消订单不能收款");
|
TimiException.requiredTrue(order.getStatus() != GaoSalesOrder.Status.CANCELLED, "已取消订单不能收款");
|
||||||
TimiException.requiredTrue(order.getRefundStatus() != GaoSalesOrder.RefundStatus.REFUNDED, "已完成退款订单不能收款");
|
TimiException.requiredTrue(order.getRefundStatus() != GaoSalesOrder.RefundStatus.REFUNDED, "已完成退款订单不能收款");
|
||||||
@@ -78,27 +71,9 @@ public class GaoOrderPaymentServiceImplement implements GaoOrderPaymentService {
|
|||||||
TimiException.requiredTrue(pending + paid + request.getAmount() <= safe(order.getSaleAmount()), "累计收款不能超过成交价");
|
TimiException.requiredTrue(pending + paid + request.getAmount() <= safe(order.getSaleAmount()), "累计收款不能超过成交价");
|
||||||
TimiException.requiredTrue(hasPhoto(request.getAttachmentList()), "收款必须上传照片");
|
TimiException.requiredTrue(hasPhoto(request.getAttachmentList()), "收款必须上传照片");
|
||||||
GaoFundRecord record = newRecord(order, GaoFundRecord.OperationType.RECEIVE, requestNo, request.getAmount(), request.getOccurredAt(), request.getRemark());
|
GaoFundRecord record = newRecord(order, GaoFundRecord.OperationType.RECEIVE, requestNo, request.getAmount(), request.getOccurredAt(), request.getRemark());
|
||||||
record.setStatus(verified ? GaoFundRecord.Status.VERIFIED : GaoFundRecord.Status.PENDING);
|
record.setStatus(GaoFundRecord.Status.PENDING);
|
||||||
String verifierUserId = verified ? userLoginService.getRequireLoginUserId() : null;
|
|
||||||
Long verifiedAt = verified ? Time.now() : null;
|
|
||||||
if (verified) {
|
|
||||||
record.setVerifierUserId(verifierUserId);
|
|
||||||
record.setVerifiedAt(verifiedAt);
|
|
||||||
}
|
|
||||||
fundRecordService.createByOrderPayment(record);
|
fundRecordService.createByOrderPayment(record);
|
||||||
if (!verified) {
|
|
||||||
order.setPendingPaidAmount(pending + request.getAmount());
|
order.setPendingPaidAmount(pending + request.getAmount());
|
||||||
} else {
|
|
||||||
Long paidAtBefore = order.getPaidAt();
|
|
||||||
order.setPaidAmount(paid + request.getAmount());
|
|
||||||
orderService.recomputePaymentStatus(order);
|
|
||||||
orderService.updatePayment(order);
|
|
||||||
if (paidAtBefore == null && order.getPaidAt() != null) {
|
|
||||||
pointTriggerService.onSalesOrderPaid(order);
|
|
||||||
}
|
|
||||||
attachmentService.updateByBizId(Attachment.BizType.GAO_FUND_RECORD, record.getId(), request.getAttachmentList());
|
|
||||||
return record;
|
|
||||||
}
|
|
||||||
orderService.recomputePaymentStatus(order);
|
orderService.recomputePaymentStatus(order);
|
||||||
orderService.updatePayment(order);
|
orderService.updatePayment(order);
|
||||||
attachmentService.updateByBizId(Attachment.BizType.GAO_FUND_RECORD, record.getId(), request.getAttachmentList());
|
attachmentService.updateByBizId(Attachment.BizType.GAO_FUND_RECORD, record.getId(), request.getAttachmentList());
|
||||||
|
|||||||
-155
@@ -1,155 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.service.implement;
|
|
||||||
|
|
||||||
import com.imyeyu.api.bean.ModuleCode;
|
|
||||||
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
|
||||||
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoFundRecord;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoOrderFulfillment;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoSalesOrder;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoSalesOrderItem;
|
|
||||||
import com.imyeyu.api.modules.gao.service.GaoOrderFulfillmentService;
|
|
||||||
import com.imyeyu.api.modules.gao.service.GaoOrderPaymentService;
|
|
||||||
import com.imyeyu.api.modules.gao.service.GaoOrderStraightThroughService;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoOrderFulfillmentCreateRequest;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoOrderFulfillmentActionRequest;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoOrderFulfillmentItemRequest;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoOrderPaymentReceiveRequest;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoOrderStraightThroughRequest;
|
|
||||||
import com.imyeyu.api.modules.user.service.PermissionChecker;
|
|
||||||
import com.imyeyu.java.TimiJava;
|
|
||||||
import com.imyeyu.java.bean.timi.TimiException;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/// GAO 订单创建直通服务实现
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-09-13
|
|
||||||
@Service
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class GaoOrderStraightThroughServiceImplement implements GaoOrderStraightThroughService {
|
|
||||||
|
|
||||||
private final GaoOrderPaymentService paymentService;
|
|
||||||
private final GaoOrderFulfillmentService fulfillmentService;
|
|
||||||
private final PermissionChecker permissionChecker;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
|
||||||
public void complete(GaoSalesOrder order, GaoOrderStraightThroughRequest straightThrough) {
|
|
||||||
if (straightThrough == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
boolean paymentVerified = Boolean.TRUE.equals(straightThrough.getPaymentVerified());
|
|
||||||
boolean receiveFullPayment = Boolean.TRUE.equals(straightThrough.getReceiveFullPayment());
|
|
||||||
boolean fulfillAll = Boolean.TRUE.equals(straightThrough.getFulfillAll());
|
|
||||||
Long paymentAmount = paymentVerified ? straightThrough.getPaymentAmount() : order.getSaleAmount();
|
|
||||||
if (!paymentVerified && !receiveFullPayment && !fulfillAll) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
TimiException.required(order, "not found sales order");
|
|
||||||
TimiException.required(order.getId(), "not found salesOrderId");
|
|
||||||
TimiException.requiredTrue(!(paymentVerified && receiveFullPayment), "已核销收款和已全额收款和核销不能同时启用");
|
|
||||||
if (paymentVerified) {
|
|
||||||
TimiException.required(paymentAmount, "已核销收款金额不能为空");
|
|
||||||
TimiException.requiredTrue(0 < paymentAmount && paymentAmount <= safe(order.getSaleAmount()), "已核销收款金额不能超过订单金额");
|
|
||||||
}
|
|
||||||
TimiException.requiredTrue(!fulfillAll || receiveFullPayment || order.getSaleAmount() == 0
|
|
||||||
|| (paymentVerified && paymentAmount.equals(order.getSaleAmount())),
|
|
||||||
"全部履约直通必须同时完成收款核销");
|
|
||||||
checkPermissions(order.getOrderType(), paymentVerified || receiveFullPayment, fulfillAll);
|
|
||||||
if (receiveFullPayment) {
|
|
||||||
settle(order, straightThrough);
|
|
||||||
} else if (paymentVerified) {
|
|
||||||
verifyReceivedPayment(order, straightThrough, paymentAmount);
|
|
||||||
}
|
|
||||||
if (fulfillAll) {
|
|
||||||
fulfill(order, straightThrough);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkPermissions(GaoSalesOrder.OrderType orderType, boolean paymentCompleted, boolean fulfillAll) {
|
|
||||||
List<String> permissionCodeList = new ArrayList<>();
|
|
||||||
permissionCodeList.add(orderType == GaoSalesOrder.OrderType.PACKAGE
|
|
||||||
? GaoPermissionCode.CUSTOMER_PACKAGE_CREATE.getValue() : GaoPermissionCode.SALES_ORDER_CREATE.getValue());
|
|
||||||
if (paymentCompleted) {
|
|
||||||
permissionCodeList.add(GaoPermissionCode.FUND_RECEIVE_CREATE.getValue());
|
|
||||||
permissionCodeList.add(GaoPermissionCode.FUND_RECEIVE_VERIFY.getValue());
|
|
||||||
}
|
|
||||||
if (fulfillAll) {
|
|
||||||
permissionCodeList.add(GaoPermissionCode.ORDER_FULFILLMENT_CREATE.getValue());
|
|
||||||
permissionCodeList.add(GaoPermissionCode.ORDER_FULFILLMENT_VERIFY.getValue());
|
|
||||||
}
|
|
||||||
permissionChecker.checkAll(ModuleCode.GAO, permissionCodeList.toArray(String[]::new));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void settle(GaoSalesOrder order, GaoOrderStraightThroughRequest straightThrough) {
|
|
||||||
if (order.getSaleAmount() == null || order.getSaleAmount() == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
GaoOrderPaymentReceiveRequest paymentRequest = new GaoOrderPaymentReceiveRequest();
|
|
||||||
paymentRequest.setSalesOrderId(order.getId());
|
|
||||||
paymentRequest.setRequestNo("ORDER-%s-FULL-PAY".formatted(order.getId()));
|
|
||||||
paymentRequest.setAmount(order.getSaleAmount());
|
|
||||||
paymentRequest.setOccurredAt(TimiJava.defaultIfNull(straightThrough.getPaymentOccurredAt(), order.getPurchasedAt()));
|
|
||||||
paymentRequest.setAttachmentList(straightThrough.getPaymentAttachmentList());
|
|
||||||
paymentRequest.setRemark(TimiJava.defaultIfEmpty(straightThrough.getPaymentRemark(), "随订单创建直接全额收款"));
|
|
||||||
GaoFundRecord record = paymentService.receive(paymentRequest);
|
|
||||||
if (record.getStatus() == GaoFundRecord.Status.PENDING) {
|
|
||||||
paymentService.verify(record.getId());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
TimiException.requiredTrue(record.getStatus() == GaoFundRecord.Status.VERIFIED, "直通收款记录不是已核销状态");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void verifyReceivedPayment(GaoSalesOrder order, GaoOrderStraightThroughRequest straightThrough, Long paymentAmount) {
|
|
||||||
GaoOrderPaymentReceiveRequest paymentRequest = new GaoOrderPaymentReceiveRequest();
|
|
||||||
paymentRequest.setSalesOrderId(order.getId());
|
|
||||||
paymentRequest.setRequestNo("ORDER-%s-VERIFIED-PAY".formatted(order.getId()));
|
|
||||||
paymentRequest.setAmount(paymentAmount);
|
|
||||||
paymentRequest.setOccurredAt(TimiJava.defaultIfNull(straightThrough.getPaymentOccurredAt(), order.getPurchasedAt()));
|
|
||||||
paymentRequest.setAttachmentList(straightThrough.getPaymentAttachmentList());
|
|
||||||
paymentRequest.setRemark(TimiJava.defaultIfEmpty(straightThrough.getPaymentRemark(), "随订单创建直接核销已有收款"));
|
|
||||||
GaoFundRecord record = paymentService.receiveAndVerify(paymentRequest);
|
|
||||||
TimiException.requiredTrue(record.getStatus() == GaoFundRecord.Status.VERIFIED, "直通收款记录不是已核销状态");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void fulfill(GaoSalesOrder order, GaoOrderStraightThroughRequest straightThrough) {
|
|
||||||
List<GaoSalesOrderItem> orderItemList = order.getItemList();
|
|
||||||
TimiException.requiredTrue(orderItemList != null && !orderItemList.isEmpty(), "销售订单没有可履约明细");
|
|
||||||
List<GaoOrderFulfillmentItemRequest> itemList = orderItemList.stream().map(item -> {
|
|
||||||
GaoOrderFulfillmentItemRequest result = new GaoOrderFulfillmentItemRequest();
|
|
||||||
result.setSourceOrderItemId(item.getId());
|
|
||||||
result.setSkuUnitId(item.getSkuUnitId());
|
|
||||||
result.setQuantity(item.getQuantity());
|
|
||||||
return result;
|
|
||||||
}).toList();
|
|
||||||
GaoOrderFulfillmentCreateRequest fulfillmentRequest = new GaoOrderFulfillmentCreateRequest();
|
|
||||||
fulfillmentRequest.setSalesOrderId(order.getId());
|
|
||||||
fulfillmentRequest.setRequestNo("ORDER-%s-FULL-FULFILL".formatted(order.getId()));
|
|
||||||
fulfillmentRequest.setDeliveredAt(TimiJava.defaultIfNull(straightThrough.getDeliveredAt(), order.getPurchasedAt()));
|
|
||||||
fulfillmentRequest.setItemList(itemList);
|
|
||||||
fulfillmentRequest.setAttachmentList(straightThrough.getFulfillmentAttachmentList());
|
|
||||||
fulfillmentRequest.setRemark(TimiJava.defaultIfEmpty(straightThrough.getFulfillmentRemark(), "随订单创建直接全部履约"));
|
|
||||||
GaoOrderFulfillment fulfillment = fulfillmentService.create(fulfillmentRequest);
|
|
||||||
if (fulfillment.getStatus() == GaoOrderFulfillment.Status.PENDING) {
|
|
||||||
fulfillmentService.verify(actionRequest(fulfillment.getId()));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
TimiException.requiredTrue(fulfillment.getStatus() == GaoOrderFulfillment.Status.VERIFIED,
|
|
||||||
fulfillment.getStatus() == GaoOrderFulfillment.Status.WAITING_STOCK ? "库存不足,不能全部履约直通" : "直通履约单不是已核销状态");
|
|
||||||
}
|
|
||||||
|
|
||||||
private GaoOrderFulfillmentActionRequest actionRequest(String fulfillmentId) {
|
|
||||||
GaoOrderFulfillmentActionRequest request = new GaoOrderFulfillmentActionRequest();
|
|
||||||
request.setFulfillmentId(fulfillmentId);
|
|
||||||
return request;
|
|
||||||
}
|
|
||||||
|
|
||||||
private long safe(Long value) {
|
|
||||||
return value == null ? 0L : value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-32
@@ -124,37 +124,6 @@ public class GaoPointLedgerServiceImplement extends AbstractEntityService<GaoPoi
|
|||||||
null, null, null, null, null, null, idempotencyKey, request.getRemark(), operatorUserId, Time.now());
|
null, null, null, null, null, null, idempotencyKey, request.getRemark(), operatorUserId, Time.now());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
|
||||||
@Override
|
|
||||||
public GaoPointLedger consumeForRedemption(String storeId, String customerId, String redemptionId, long pointCost,
|
|
||||||
String operatorUserId, String remark) {
|
|
||||||
TimiException.required(storeId, "not found storeId");
|
|
||||||
TimiException.required(customerId, "not found customerId");
|
|
||||||
TimiException.required(redemptionId, "not found redemptionId");
|
|
||||||
TimiException.required(operatorUserId, "not found operatorUserId");
|
|
||||||
TimiException.requiredTrue(0 < pointCost, "pointCost invalid");
|
|
||||||
String idempotencyKey = "GAO_POINT_REDEMPTION:%s:CONSUME".formatted(redemptionId);
|
|
||||||
return apply(storeId, customerId, GaoPointLedger.ChangeType.CONSUME, -pointCost, null,
|
|
||||||
GaoPointLedger.TriggerSourceType.POINT_REDEMPTION, redemptionId, null, null, null, idempotencyKey,
|
|
||||||
remark, operatorUserId, Time.now());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
|
||||||
@Override
|
|
||||||
public GaoPointLedger revokeForRedemption(String storeId, String customerId, String redemptionId, String returnId, long pointCost,
|
|
||||||
String operatorUserId, String remark) {
|
|
||||||
TimiException.required(storeId, "not found storeId");
|
|
||||||
TimiException.required(customerId, "not found customerId");
|
|
||||||
TimiException.required(redemptionId, "not found redemptionId");
|
|
||||||
TimiException.required(returnId, "not found returnId");
|
|
||||||
TimiException.required(operatorUserId, "not found operatorUserId");
|
|
||||||
TimiException.requiredTrue(0 < pointCost, "pointCost invalid");
|
|
||||||
String idempotencyKey = "GAO_POINT_REDEMPTION:%s:RETURN:%s".formatted(redemptionId, returnId);
|
|
||||||
return apply(storeId, customerId, GaoPointLedger.ChangeType.REVOKE, pointCost, null,
|
|
||||||
GaoPointLedger.TriggerSourceType.POINT_REDEMPTION, redemptionId, null, null,
|
|
||||||
jackson.createObjectNode().put("returnId", returnId), idempotencyKey, remark, operatorUserId, Time.now());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<GaoPointLedger> listRuleChangeByTriggerSource(GaoPointLedger.TriggerSourceType triggerSourceType, String triggerSourceId) {
|
public List<GaoPointLedger> listRuleChangeByTriggerSource(GaoPointLedger.TriggerSourceType triggerSourceType, String triggerSourceId) {
|
||||||
TimiException.required(triggerSourceType, "not found triggerSourceType");
|
TimiException.required(triggerSourceType, "not found triggerSourceType");
|
||||||
@@ -217,7 +186,6 @@ public class GaoPointLedgerServiceImplement extends AbstractEntityService<GaoPoi
|
|||||||
return switch (triggerSourceType) {
|
return switch (triggerSourceType) {
|
||||||
case EVENT_RECORD -> "GAO_EVENT_RECORD:%s:RULE:%s:EARN".formatted(triggerSourceId, ruleId);
|
case EVENT_RECORD -> "GAO_EVENT_RECORD:%s:RULE:%s:EARN".formatted(triggerSourceId, ruleId);
|
||||||
case SALES_ORDER_PAID -> "GAO_SALES_ORDER:%s:RULE:%s:EARN".formatted(triggerSourceId, ruleId);
|
case SALES_ORDER_PAID -> "GAO_SALES_ORDER:%s:RULE:%s:EARN".formatted(triggerSourceId, ruleId);
|
||||||
case POINT_REDEMPTION -> "GAO_POINT_REDEMPTION:%s:RULE:%s:EARN".formatted(triggerSourceId, ruleId);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
-210
@@ -1,210 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.service.implement;
|
|
||||||
|
|
||||||
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoProduct;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoProductSku;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoProductSkuUnit;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoPointRedeemSku;
|
|
||||||
import com.imyeyu.api.modules.gao.mapper.GaoPointRedeemSkuMapper;
|
|
||||||
import com.imyeyu.api.modules.gao.service.GaoPointRedeemSkuService;
|
|
||||||
import com.imyeyu.api.modules.gao.service.GaoProductService;
|
|
||||||
import com.imyeyu.api.modules.gao.service.GaoProductSkuService;
|
|
||||||
import com.imyeyu.api.modules.gao.service.GaoStoreScopeService;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoPointRedeemSkuPage;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoPointRedeemSkuRequest;
|
|
||||||
import com.imyeyu.java.TimiJava;
|
|
||||||
import com.imyeyu.java.bean.timi.TimiException;
|
|
||||||
import com.imyeyu.spring.bean.PageResult;
|
|
||||||
import com.imyeyu.utils.Time;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/// GAO 积分兑换 SKU 配置服务实现
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-09-14
|
|
||||||
@Service
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class GaoPointRedeemSkuServiceImplement implements GaoPointRedeemSkuService {
|
|
||||||
|
|
||||||
private final GaoPointRedeemSkuMapper mapper;
|
|
||||||
private final GaoProductService productService;
|
|
||||||
private final GaoProductSkuService skuService;
|
|
||||||
private final GaoStoreScopeService storeScopeService;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PageResult<GaoPointRedeemSku> pageByQuery(GaoPointRedeemSkuPage page) {
|
|
||||||
TimiException.required(page, "not found redeem sku page");
|
|
||||||
PageResult<GaoPointRedeemSku> result = new PageResult<>();
|
|
||||||
result.setTotal(mapper.countByQuery(page));
|
|
||||||
List<GaoPointRedeemSku> list = mapper.selectByQuery(page);
|
|
||||||
fillTransient(list);
|
|
||||||
result.setList(list);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public GaoPointRedeemSku detail(String storeId, String id) {
|
|
||||||
TimiException.required(storeId, "not found storeId");
|
|
||||||
TimiException.required(id, "not found redeemSkuId");
|
|
||||||
GaoPointRedeemSku result = storeId == null ? mapper.select(id) : mapper.selectByStoreIdAndId(storeId, id);
|
|
||||||
TimiException.required(result, "not found redeem sku");
|
|
||||||
fillTransient(List.of(result));
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public GaoPointRedeemSku getForUpdate(String id) {
|
|
||||||
TimiException.required(id, "not found redeemSkuId");
|
|
||||||
GaoPointRedeemSku result = mapper.selectForUpdate(id);
|
|
||||||
TimiException.required(result, "not found redeem sku");
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
|
||||||
@Override
|
|
||||||
public GaoPointRedeemSku create(GaoPointRedeemSkuRequest request) {
|
|
||||||
TimiException.required(request, "not found redeem sku request");
|
|
||||||
String storeId = storeScopeService.resolveStoreId(request.getStoreId());
|
|
||||||
GaoPointRedeemSku config = new GaoPointRedeemSku();
|
|
||||||
config.setStoreId(storeId);
|
|
||||||
config.setSkuId(request.getSkuId());
|
|
||||||
config.setSkuUnitId(request.getSkuUnitId());
|
|
||||||
config.setStatus(TimiJava.defaultIfNull(request.getStatus(), GaoPointRedeemSku.Status.DRAFT));
|
|
||||||
config.setDefaultPointCost(request.getDefaultPointCost());
|
|
||||||
config.setBeginAt(request.getBeginAt());
|
|
||||||
config.setEndAt(request.getEndAt());
|
|
||||||
config.setMaxTotalQuantity(request.getMaxTotalQuantity());
|
|
||||||
config.setMaxDailyQuantity(request.getMaxDailyQuantity());
|
|
||||||
config.setMaxMonthlyQuantity(request.getMaxMonthlyQuantity());
|
|
||||||
config.setRemark(request.getRemark());
|
|
||||||
validate(config, config.getStatus() == GaoPointRedeemSku.Status.ACTIVE);
|
|
||||||
GaoPointRedeemSku existing = mapper.selectByStoreSkuUnit(storeId, config.getSkuId(), config.getSkuUnitId());
|
|
||||||
TimiException.requiredNull(existing, "该 SKU 单位已经配置积分兑换");
|
|
||||||
config.setId(UUID.randomUUID().toString());
|
|
||||||
config.setCreatedAt(Time.now());
|
|
||||||
mapper.insert(config);
|
|
||||||
return detail(storeId, config.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
|
||||||
@Override
|
|
||||||
public GaoPointRedeemSku update(GaoPointRedeemSkuRequest request) {
|
|
||||||
TimiException.required(request, "not found redeem sku request");
|
|
||||||
TimiException.required(request.getId(), "not found redeemSkuId");
|
|
||||||
GaoPointRedeemSku current = mapper.select(request.getId());
|
|
||||||
TimiException.required(current, "not found redeem sku");
|
|
||||||
storeScopeService.checkStoreId(current.getStoreId());
|
|
||||||
GaoPointRedeemSku config = new GaoPointRedeemSku();
|
|
||||||
config.setId(current.getId());
|
|
||||||
config.setStoreId(current.getStoreId());
|
|
||||||
config.setSkuId(TimiJava.defaultIfNull(request.getSkuId(), current.getSkuId()));
|
|
||||||
config.setSkuUnitId(TimiJava.defaultIfNull(request.getSkuUnitId(), current.getSkuUnitId()));
|
|
||||||
config.setStatus(TimiJava.defaultIfNull(request.getStatus(), current.getStatus()));
|
|
||||||
config.setDefaultPointCost(TimiJava.defaultIfNull(request.getDefaultPointCost(), current.getDefaultPointCost()));
|
|
||||||
config.setBeginAt(request.getBeginAt());
|
|
||||||
config.setEndAt(request.getEndAt());
|
|
||||||
config.setMaxTotalQuantity(request.getMaxTotalQuantity());
|
|
||||||
config.setMaxDailyQuantity(request.getMaxDailyQuantity());
|
|
||||||
config.setMaxMonthlyQuantity(request.getMaxMonthlyQuantity());
|
|
||||||
config.setRemark(request.getRemark());
|
|
||||||
validate(config, config.getStatus() == GaoPointRedeemSku.Status.ACTIVE);
|
|
||||||
GaoPointRedeemSku existing = mapper.selectByStoreSkuUnit(config.getStoreId(), config.getSkuId(), config.getSkuUnitId());
|
|
||||||
TimiException.requiredTrue(existing == null || existing.getId().equals(config.getId()), "该 SKU 单位已经配置积分兑换");
|
|
||||||
config.setUpdatedAt(Time.now());
|
|
||||||
mapper.updateConfig(config);
|
|
||||||
return detail(config.getStoreId(), config.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
|
||||||
@Override
|
|
||||||
public void disable(String storeId, String id) {
|
|
||||||
GaoPointRedeemSku config = storeId == null ? mapper.select(id) : mapper.selectByStoreIdAndId(storeId, id);
|
|
||||||
TimiException.required(config, "not found redeem sku");
|
|
||||||
config.setStatus(GaoPointRedeemSku.Status.INACTIVE);
|
|
||||||
config.setUpdatedAt(Time.now());
|
|
||||||
mapper.updateSelective(config);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
|
||||||
@Override
|
|
||||||
public void delete(String storeId, String id) {
|
|
||||||
GaoPointRedeemSku config = storeId == null ? mapper.select(id) : mapper.selectByStoreIdAndId(storeId, id);
|
|
||||||
TimiException.required(config, "not found redeem sku");
|
|
||||||
config.setStatus(GaoPointRedeemSku.Status.DELETED);
|
|
||||||
config.setUpdatedAt(Time.now());
|
|
||||||
mapper.updateSelective(config);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void validate(GaoPointRedeemSku config, boolean active) {
|
|
||||||
TimiException.required(config.getStoreId(), "not found storeId");
|
|
||||||
TimiException.required(config.getSkuId(), "not found skuId");
|
|
||||||
TimiException.required(config.getSkuUnitId(), "not found skuUnitId");
|
|
||||||
TimiException.required(config.getStatus(), "not found status");
|
|
||||||
TimiException.required(config.getDefaultPointCost(), "not found defaultPointCost");
|
|
||||||
TimiException.requiredTrue(0 < config.getDefaultPointCost(), "默认积分必须大于 0");
|
|
||||||
if (config.getBeginAt() != null && config.getEndAt() != null) {
|
|
||||||
TimiException.requiredTrue(config.getBeginAt() < config.getEndAt(), "生效开始时间必须早于结束时间");
|
|
||||||
}
|
|
||||||
validateLimit(config.getMaxTotalQuantity(), "累计兑换上限");
|
|
||||||
validateLimit(config.getMaxDailyQuantity(), "自然日兑换上限");
|
|
||||||
validateLimit(config.getMaxMonthlyQuantity(), "自然月兑换上限");
|
|
||||||
|
|
||||||
GaoProductSku sku = skuService.get(config.getSkuId());
|
|
||||||
TimiException.required(sku, "SKU 不存在");
|
|
||||||
TimiException.requiredTrue(config.getStoreId().equals(sku.getStoreId()), "SKU 不属于当前门店");
|
|
||||||
GaoProduct product = productService.get(sku.getProductId());
|
|
||||||
TimiException.required(product, "产品不存在");
|
|
||||||
TimiException.requiredTrue(config.getStoreId().equals(product.getStoreId()), "产品不属于当前门店");
|
|
||||||
TimiException.requiredTrue(product.getProductType() == GaoProduct.ProductType.GOODS
|
|
||||||
|| product.getProductType() == GaoProduct.ProductType.SERVICE, "只有实物或服务产品可以配置积分兑换");
|
|
||||||
GaoProductSkuUnit unit = skuService.listUnitBySkuId(sku.getId()).stream()
|
|
||||||
.filter(item -> item.getId().equals(config.getSkuUnitId())).findFirst().orElse(null);
|
|
||||||
TimiException.required(unit, "SKU 单位不存在");
|
|
||||||
if (active) {
|
|
||||||
TimiException.requiredTrue(product.getStatus() == GaoProduct.Status.ACTIVE, "产品已停用");
|
|
||||||
TimiException.requiredTrue(sku.getStatus() == GaoProductSku.Status.ACTIVE, "SKU 已停用");
|
|
||||||
if (product.getProductType() == GaoProduct.ProductType.GOODS) {
|
|
||||||
TimiException.requiredTrue(Boolean.TRUE.equals(sku.getStockEnabled()), "实物 SKU 必须启用库存管理");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void validateLimit(BigDecimal value, String name) {
|
|
||||||
if (value == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
TimiException.requiredTrue(0 < value.signum(), name + "必须大于 0");
|
|
||||||
TimiException.requiredTrue(value.stripTrailingZeros().scale() <= 3, name + "最多保留三位小数");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void fillTransient(List<GaoPointRedeemSku> list) {
|
|
||||||
if (list == null || list.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Map<String, GaoProductSku> skuMap = new HashMap<>();
|
|
||||||
for (GaoProductSku sku : skuService.listByIdList(list.stream().map(GaoPointRedeemSku::getSkuId).distinct().toList())) {
|
|
||||||
skuMap.put(sku.getId(), sku);
|
|
||||||
}
|
|
||||||
Map<String, GaoProduct> productMap = productService.listByIdList(skuMap.values().stream().map(GaoProductSku::getProductId).distinct().toList())
|
|
||||||
.stream().collect(java.util.stream.Collectors.toMap(GaoProduct::getId, item -> item));
|
|
||||||
Map<String, List<GaoProductSkuUnit>> unitMap = new HashMap<>();
|
|
||||||
for (String skuId : skuMap.keySet()) {
|
|
||||||
unitMap.put(skuId, skuService.listUnitBySkuId(skuId));
|
|
||||||
}
|
|
||||||
for (GaoPointRedeemSku item : list) {
|
|
||||||
GaoProductSku sku = skuMap.get(item.getSkuId());
|
|
||||||
item.setSku(sku);
|
|
||||||
item.setProduct(sku == null ? null : productMap.get(sku.getProductId()));
|
|
||||||
item.setUnit(unitMap.getOrDefault(item.getSkuId(), List.of()).stream()
|
|
||||||
.filter(unit -> unit.getId().equals(item.getSkuUnitId())).findFirst().orElse(null));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-445
@@ -1,445 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.service.implement;
|
|
||||||
|
|
||||||
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
|
||||||
import com.imyeyu.api.modules.common.entity.Attachment;
|
|
||||||
import com.imyeyu.api.modules.common.service.AttachmentService;
|
|
||||||
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoPointAccount;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoPointRedeemSku;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoPointRedemption;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoPointRedemptionReturn;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoProduct;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoProductSku;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoProductSkuUnit;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoProductStockRecord;
|
|
||||||
import com.imyeyu.api.modules.gao.mapper.GaoPointRedemptionMapper;
|
|
||||||
import com.imyeyu.api.modules.gao.mapper.GaoPointRedemptionReturnMapper;
|
|
||||||
import com.imyeyu.api.modules.gao.service.GaoCustomerService;
|
|
||||||
import com.imyeyu.api.modules.gao.service.GaoPointAccountService;
|
|
||||||
import com.imyeyu.api.modules.gao.service.GaoPointLedgerService;
|
|
||||||
import com.imyeyu.api.modules.gao.service.GaoPointRedeemSkuService;
|
|
||||||
import com.imyeyu.api.modules.gao.service.GaoPointRedemptionService;
|
|
||||||
import com.imyeyu.api.modules.gao.service.GaoProductService;
|
|
||||||
import com.imyeyu.api.modules.gao.service.GaoProductSkuService;
|
|
||||||
import com.imyeyu.api.modules.gao.service.GaoProductStockService;
|
|
||||||
import com.imyeyu.api.modules.gao.service.GaoStoreScopeService;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoPointRedemptionCreateRequest;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoPointRedemptionPage;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoPointRedemptionReturnRequest;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoStockChangeItem;
|
|
||||||
import com.imyeyu.api.modules.user.service.PermissionChecker;
|
|
||||||
import com.imyeyu.api.modules.user.service.UserLoginService;
|
|
||||||
import com.imyeyu.api.bean.ModuleCode;
|
|
||||||
import com.imyeyu.java.TimiJava;
|
|
||||||
import com.imyeyu.java.bean.timi.TimiCode;
|
|
||||||
import com.imyeyu.java.bean.timi.TimiException;
|
|
||||||
import com.imyeyu.spring.bean.PageResult;
|
|
||||||
import com.imyeyu.utils.Time;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.math.RoundingMode;
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.time.ZoneId;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/// GAO 积分兑换业务服务实现
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-09-14
|
|
||||||
@Service
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class GaoPointRedemptionServiceImplement implements GaoPointRedemptionService {
|
|
||||||
|
|
||||||
private static final ZoneId BUSINESS_ZONE = ZoneId.of("Asia/Shanghai");
|
|
||||||
private static final BigDecimal ZERO = BigDecimal.ZERO;
|
|
||||||
|
|
||||||
private final GaoPointRedemptionMapper mapper;
|
|
||||||
private final GaoPointRedemptionReturnMapper returnMapper;
|
|
||||||
private final GaoPointRedeemSkuService redeemSkuService;
|
|
||||||
private final GaoCustomerService customerService;
|
|
||||||
private final GaoProductService productService;
|
|
||||||
private final GaoProductSkuService skuService;
|
|
||||||
private final GaoPointAccountService pointAccountService;
|
|
||||||
private final GaoPointLedgerService pointLedgerService;
|
|
||||||
private final GaoProductStockService stockService;
|
|
||||||
private final GaoStoreScopeService storeScopeService;
|
|
||||||
private final AttachmentService attachmentService;
|
|
||||||
private final UserLoginService userLoginService;
|
|
||||||
private final PermissionChecker permissionChecker;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PageResult<GaoPointRedemption> pageByQuery(GaoPointRedemptionPage page) {
|
|
||||||
TimiException.required(page, "not found redemption page");
|
|
||||||
PageResult<GaoPointRedemption> result = new PageResult<>();
|
|
||||||
result.setTotal(mapper.countByQuery(page));
|
|
||||||
List<GaoPointRedemption> list = mapper.selectByQuery(page);
|
|
||||||
fillTransient(list);
|
|
||||||
result.setList(list);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public GaoPointRedemption detail(String storeId, String id) {
|
|
||||||
TimiException.required(id, "not found redemptionId");
|
|
||||||
GaoPointRedemption result = storeId == null ? mapper.select(id) : mapper.selectByStoreIdAndId(storeId, id);
|
|
||||||
TimiException.required(result, "not found redemption");
|
|
||||||
fillTransient(List.of(result));
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
|
||||||
@Override
|
|
||||||
public GaoPointRedemption create(GaoPointRedemptionCreateRequest request) {
|
|
||||||
TimiException.required(request, "not found redemption request");
|
|
||||||
String requestNo = requiredText(request.getRequestNo(), "not found requestNo");
|
|
||||||
String storeId = storeScopeService.resolveStoreId(request.getStoreId());
|
|
||||||
TimiException.required(storeId, "not found storeId");
|
|
||||||
String customerId = requiredText(request.getCustomerId(), "not found customerId");
|
|
||||||
String redeemSkuId = requiredText(request.getRedeemSkuId(), "not found redeemSkuId");
|
|
||||||
BigDecimal quantity = validateQuantity(request.getQuantity(), null);
|
|
||||||
GaoPointRedemption existing = mapper.selectByStoreIdAndRequestNo(storeId, requestNo);
|
|
||||||
if (existing != null) {
|
|
||||||
verifyExisting(existing, customerId, redeemSkuId, quantity, request.getActualPointCost());
|
|
||||||
return detail(storeId, existing.getId());
|
|
||||||
}
|
|
||||||
TimiException.requiredTrue(hasPhoto(request.getAttachmentList()), "兑换必须上传至少一张照片");
|
|
||||||
|
|
||||||
GaoCustomer customer = customerService.get(customerId);
|
|
||||||
TimiException.required(customer, "客户不存在");
|
|
||||||
TimiException.requiredTrue(storeId.equals(customer.getStoreId()), "客户不属于当前门店");
|
|
||||||
GaoPointRedeemSku preview = redeemSkuService.detail(storeId, redeemSkuId);
|
|
||||||
long now = Time.now();
|
|
||||||
validateActiveConfig(preview, now);
|
|
||||||
|
|
||||||
// 同一客户的兑换限额由积分账户锁串行化,锁顺序为积分账户 → 配置和库存
|
|
||||||
GaoPointAccount account = pointAccountService.getOrCreateForUpdate(storeId, customerId);
|
|
||||||
GaoPointRedeemSku config = redeemSkuService.getForUpdate(redeemSkuId);
|
|
||||||
TimiException.requiredTrue(storeId.equals(config.getStoreId()), "兑换配置不属于当前门店");
|
|
||||||
validateActiveConfig(config, now);
|
|
||||||
GaoProductSkuSelection selection = loadSelection(config, storeId);
|
|
||||||
quantity = validateQuantity(request.getQuantity(), selection.sku());
|
|
||||||
BigDecimal baseQuantity = baseQuantity(quantity, selection.unit().getBaseQuantityPerUnit());
|
|
||||||
long defaultPointCost = totalPointCost(config.getDefaultPointCost(), quantity);
|
|
||||||
long actualPointCost = resolveActualPointCost(request.getActualPointCost(), defaultPointCost);
|
|
||||||
if (request.getActualPointCost() != null) {
|
|
||||||
permissionChecker.checkAll(ModuleCode.GAO, GaoPermissionCode.POINT_REDEMPTION_POINT_ADJUST.getValue());
|
|
||||||
}
|
|
||||||
checkLimit(storeId, customerId, config, selection.sku().getId(), quantity, now);
|
|
||||||
|
|
||||||
String operatorUserId = userLoginService.getRequireLoginUserId();
|
|
||||||
GaoPointRedemption redemption = new GaoPointRedemption();
|
|
||||||
redemption.setId(UUID.randomUUID().toString());
|
|
||||||
redemption.setStoreId(storeId);
|
|
||||||
redemption.setCustomerId(customerId);
|
|
||||||
redemption.setRequestNo(requestNo);
|
|
||||||
redemption.setRedeemSkuIdSnapshot(config.getId());
|
|
||||||
redemption.setProductIdSnapshot(selection.product().getId());
|
|
||||||
redemption.setProductNameSnapshot(selection.product().getName());
|
|
||||||
redemption.setProductTypeSnapshot(selection.product().getProductType());
|
|
||||||
redemption.setSkuIdSnapshot(selection.sku().getId());
|
|
||||||
redemption.setSkuCodeSnapshot(selection.sku().getCode());
|
|
||||||
redemption.setSkuNameSnapshot(selection.sku().getName());
|
|
||||||
redemption.setSkuSpecSnapshot(skuService.getSkuSpecSnapshot(selection.sku()));
|
|
||||||
redemption.setSkuUnitIdSnapshot(selection.unit().getId());
|
|
||||||
redemption.setUnitSnapshot(selection.unit().getName());
|
|
||||||
redemption.setBaseQuantityPerUnitSnapshot(selection.unit().getBaseQuantityPerUnit());
|
|
||||||
redemption.setAllowDecimalQuantitySnapshot(selection.sku().getAllowDecimalQuantity());
|
|
||||||
redemption.setQuantity(quantity);
|
|
||||||
redemption.setBaseQuantity(baseQuantity);
|
|
||||||
redemption.setDefaultPointCost(defaultPointCost);
|
|
||||||
redemption.setActualPointCost(actualPointCost);
|
|
||||||
redemption.setReturnedQuantity(ZERO);
|
|
||||||
redemption.setReturnedPointCost(0L);
|
|
||||||
redemption.setStatus(GaoPointRedemption.Status.COMPLETED);
|
|
||||||
redemption.setOperatorUserId(operatorUserId);
|
|
||||||
redemption.setRedeemedAt(now);
|
|
||||||
redemption.setRemark(request.getRemark());
|
|
||||||
redemption.setCreatedAt(now);
|
|
||||||
mapper.insert(redemption);
|
|
||||||
attachmentService.updateByBizId(Attachment.BizType.GAO_POINT_REDEMPTION, redemption.getId(), request.getAttachmentList());
|
|
||||||
|
|
||||||
if (0 < actualPointCost) {
|
|
||||||
pointLedgerService.consumeForRedemption(storeId, customerId, redemption.getId(), actualPointCost, operatorUserId, request.getRemark());
|
|
||||||
}
|
|
||||||
if (selection.product().getProductType() == GaoProduct.ProductType.GOODS) {
|
|
||||||
GaoStockChangeItem stockItem = stockItem(selection, quantity, baseQuantity);
|
|
||||||
stockService.outForRedemption(storeId, redemption.getId(), stockItem, requestNo, operatorUserId);
|
|
||||||
}
|
|
||||||
return detail(storeId, redemption.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
|
||||||
@Override
|
|
||||||
public GaoPointRedemption returnRedemption(GaoPointRedemptionReturnRequest request) {
|
|
||||||
TimiException.required(request, "not found redemption return request");
|
|
||||||
String redemptionId = requiredText(request.getRedemptionId(), "not found redemptionId");
|
|
||||||
String requestNo = requiredText(request.getRequestNo(), "not found requestNo");
|
|
||||||
GaoPointRedemption preview = mapper.select(redemptionId);
|
|
||||||
TimiException.required(preview, "not found redemption");
|
|
||||||
storeScopeService.checkStoreId(preview.getStoreId());
|
|
||||||
// 与创建兑换保持一致,固定先锁积分账户,再锁兑换单和库存行
|
|
||||||
pointAccountService.getOrCreateForUpdate(preview.getStoreId(), preview.getCustomerId());
|
|
||||||
GaoPointRedemption redemption = mapper.selectForUpdate(redemptionId);
|
|
||||||
TimiException.required(redemption, "not found redemption");
|
|
||||||
GaoPointRedemptionReturn existing = returnMapper.selectByRedemptionIdAndRequestNo(redemptionId, requestNo);
|
|
||||||
BigDecimal requestedQuantity = validateQuantity(request.getQuantity(), null);
|
|
||||||
if (existing != null) {
|
|
||||||
TimiException.requiredTrue(existing.getQuantity().compareTo(requestedQuantity) == 0
|
|
||||||
&& sameText(existing.getRemark(), request.getRemark()), "requestNo 对应退货内容不一致");
|
|
||||||
return detail(redemption.getStoreId(), redemptionId);
|
|
||||||
}
|
|
||||||
TimiException.requiredTrue(hasPhoto(request.getAttachmentList()), "退货必须上传至少一张照片");
|
|
||||||
BigDecimal quantity = requestedQuantity;
|
|
||||||
if (!Boolean.TRUE.equals(redemption.getAllowDecimalQuantitySnapshot())) {
|
|
||||||
TimiException.requiredTrue(quantity.stripTrailingZeros().scale() <= 0, "该兑换单不允许小数退货数量");
|
|
||||||
}
|
|
||||||
BigDecimal remainingQuantity = redemption.getQuantity().subtract(redemption.getReturnedQuantity());
|
|
||||||
TimiException.requiredTrue(quantity.compareTo(remainingQuantity) <= 0, "退货数量超过可退数量");
|
|
||||||
BigDecimal baseQuantity = baseQuantity(quantity, redemption.getBaseQuantityPerUnitSnapshot());
|
|
||||||
boolean lastReturn = quantity.compareTo(remainingQuantity) == 0;
|
|
||||||
long pointCost = returnPointCost(redemption, quantity, lastReturn);
|
|
||||||
String operatorUserId = userLoginService.getRequireLoginUserId();
|
|
||||||
GaoPointRedemptionReturn returnRecord = new GaoPointRedemptionReturn();
|
|
||||||
returnRecord.setId(UUID.randomUUID().toString());
|
|
||||||
returnRecord.setRedemptionId(redemptionId);
|
|
||||||
returnRecord.setRequestNo(requestNo);
|
|
||||||
returnRecord.setQuantity(quantity);
|
|
||||||
returnRecord.setBaseQuantity(baseQuantity);
|
|
||||||
returnRecord.setPointCost(pointCost);
|
|
||||||
returnRecord.setOperatorUserId(operatorUserId);
|
|
||||||
returnRecord.setReturnedAt(Time.now());
|
|
||||||
returnRecord.setRemark(request.getRemark());
|
|
||||||
returnRecord.setCreatedAt(Time.now());
|
|
||||||
returnMapper.insert(returnRecord);
|
|
||||||
attachmentService.updateByBizId(Attachment.BizType.GAO_POINT_REDEMPTION_RETURN, returnRecord.getId(), request.getAttachmentList());
|
|
||||||
|
|
||||||
if (redemption.getProductTypeSnapshot() == GaoProduct.ProductType.GOODS) {
|
|
||||||
GaoStockChangeItem stockItem = stockItem(redemption, quantity, baseQuantity);
|
|
||||||
GaoProductStockRecord stockRecord = stockService.inForRedemptionReturn(redemption.getStoreId(), returnRecord.getId(), stockItem,
|
|
||||||
requestNo, operatorUserId);
|
|
||||||
returnRecord.setStockRecordId(stockRecord.getId());
|
|
||||||
returnRecord.setUpdatedAt(Time.now());
|
|
||||||
returnMapper.updateSelective(returnRecord);
|
|
||||||
}
|
|
||||||
if (0 < pointCost) {
|
|
||||||
pointLedgerService.revokeForRedemption(redemption.getStoreId(), redemption.getCustomerId(), redemptionId, returnRecord.getId(),
|
|
||||||
pointCost, operatorUserId, request.getRemark());
|
|
||||||
}
|
|
||||||
redemption.setReturnedQuantity(redemption.getReturnedQuantity().add(quantity));
|
|
||||||
redemption.setReturnedPointCost(redemption.getReturnedPointCost() + pointCost);
|
|
||||||
redemption.setStatus(lastReturn ? GaoPointRedemption.Status.FULLY_RETURNED : GaoPointRedemption.Status.PARTIALLY_RETURNED);
|
|
||||||
redemption.setUpdatedAt(Time.now());
|
|
||||||
mapper.updateSelective(redemption);
|
|
||||||
return detail(redemption.getStoreId(), redemptionId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<GaoPointRedemptionReturn> listReturns(String storeId, String redemptionId) {
|
|
||||||
GaoPointRedemption redemption = storeId == null ? mapper.select(redemptionId) : mapper.selectByStoreIdAndId(storeId, redemptionId);
|
|
||||||
TimiException.required(redemption, "not found redemption");
|
|
||||||
List<GaoPointRedemptionReturn> list = returnMapper.selectByRedemptionId(redemptionId);
|
|
||||||
fillReturnAttachments(list);
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkLimit(String storeId, String customerId, GaoPointRedeemSku config, String skuId, BigDecimal quantity, long now) {
|
|
||||||
checkOneLimit(config.getMaxTotalQuantity(), mapper.sumValidQuantity(storeId, customerId, skuId, null, null), quantity, "累计兑换数量已达上限");
|
|
||||||
checkOneLimit(config.getMaxDailyQuantity(), mapper.sumValidQuantity(storeId, customerId, skuId, startOfDay(now), startOfNextDay(now) - 1), quantity, "今日兑换数量已达上限");
|
|
||||||
checkOneLimit(config.getMaxMonthlyQuantity(), mapper.sumValidQuantity(storeId, customerId, skuId, startOfMonth(now), startOfNextMonth(now) - 1), quantity, "本月兑换数量已达上限");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkOneLimit(BigDecimal limit, BigDecimal used, BigDecimal quantity, String message) {
|
|
||||||
if (limit != null) {
|
|
||||||
TimiException.requiredTrue(used.add(quantity).compareTo(limit) <= 0, message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void validateActiveConfig(GaoPointRedeemSku config, long now) {
|
|
||||||
TimiException.required(config, "not found redeem sku");
|
|
||||||
TimiException.requiredTrue(config.getStatus() == GaoPointRedeemSku.Status.ACTIVE, "兑换配置未启用");
|
|
||||||
TimiException.requiredTrue(config.getBeginAt() == null || config.getBeginAt() <= now, "兑换配置尚未生效");
|
|
||||||
TimiException.requiredTrue(config.getEndAt() == null || now <= config.getEndAt(), "兑换配置已失效");
|
|
||||||
}
|
|
||||||
|
|
||||||
private GaoProductSkuSelection loadSelection(GaoPointRedeemSku config, String storeId) {
|
|
||||||
GaoProductSku sku = skuService.get(config.getSkuId());
|
|
||||||
TimiException.required(sku, "SKU 不存在");
|
|
||||||
TimiException.requiredTrue(storeId.equals(sku.getStoreId()), "SKU 不属于当前门店");
|
|
||||||
TimiException.requiredTrue(sku.getStatus() == GaoProductSku.Status.ACTIVE, "SKU 已停用");
|
|
||||||
GaoProduct product = productService.get(sku.getProductId());
|
|
||||||
TimiException.required(product, "产品不存在");
|
|
||||||
TimiException.requiredTrue(storeId.equals(product.getStoreId()), "产品不属于当前门店");
|
|
||||||
TimiException.requiredTrue(product.getStatus() == GaoProduct.Status.ACTIVE, "产品已停用");
|
|
||||||
TimiException.requiredTrue(product.getProductType() == GaoProduct.ProductType.GOODS
|
|
||||||
|| product.getProductType() == GaoProduct.ProductType.SERVICE, "只有实物或服务产品可以兑换");
|
|
||||||
if (product.getProductType() == GaoProduct.ProductType.GOODS) {
|
|
||||||
TimiException.requiredTrue(Boolean.TRUE.equals(sku.getStockEnabled()), "实物 SKU 必须启用库存管理");
|
|
||||||
}
|
|
||||||
GaoProductSkuUnit unit = skuService.listUnitBySkuId(sku.getId()).stream()
|
|
||||||
.filter(item -> item.getId().equals(config.getSkuUnitId())).findFirst().orElse(null);
|
|
||||||
TimiException.required(unit, "SKU 单位不存在");
|
|
||||||
return new GaoProductSkuSelection(product, sku, unit);
|
|
||||||
}
|
|
||||||
|
|
||||||
private BigDecimal validateQuantity(BigDecimal quantity, GaoProductSku sku) {
|
|
||||||
TimiException.required(quantity, "数量不能为空");
|
|
||||||
TimiException.requiredTrue(0 < quantity.signum(), "数量必须大于 0");
|
|
||||||
TimiException.requiredTrue(quantity.stripTrailingZeros().scale() <= 3, "数量最多保留三位小数");
|
|
||||||
if (sku != null && !Boolean.TRUE.equals(sku.getAllowDecimalQuantity())) {
|
|
||||||
TimiException.requiredTrue(quantity.stripTrailingZeros().scale() <= 0, "该 SKU 不允许小数数量");
|
|
||||||
}
|
|
||||||
return quantity;
|
|
||||||
}
|
|
||||||
|
|
||||||
private BigDecimal baseQuantity(BigDecimal quantity, BigDecimal coefficient) {
|
|
||||||
TimiException.required(coefficient, "单位换算系数不能为空");
|
|
||||||
TimiException.requiredTrue(0 < coefficient.signum(), "单位换算系数必须大于 0");
|
|
||||||
BigDecimal result = quantity.multiply(coefficient);
|
|
||||||
TimiException.requiredTrue(result.stripTrailingZeros().scale() <= 3, "基础数量最多保留三位小数");
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private long totalPointCost(long unitCost, BigDecimal quantity) {
|
|
||||||
try {
|
|
||||||
long result = BigDecimal.valueOf(unitCost).multiply(quantity).longValueExact();
|
|
||||||
TimiException.requiredTrue(0 < result, "默认总积分必须大于 0");
|
|
||||||
return result;
|
|
||||||
} catch (ArithmeticException e) {
|
|
||||||
throw new TimiException(TimiCode.ARG_BAD, "默认总积分溢出或不是整数");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private long resolveActualPointCost(Long actualPointCost, long defaultPointCost) {
|
|
||||||
long result = actualPointCost == null ? defaultPointCost : actualPointCost;
|
|
||||||
TimiException.requiredTrue(0 <= result && result <= defaultPointCost, "实际总积分必须在 0 到默认总积分之间");
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private long returnPointCost(GaoPointRedemption redemption, BigDecimal quantity, boolean lastReturn) {
|
|
||||||
if (lastReturn) {
|
|
||||||
return redemption.getActualPointCost() - redemption.getReturnedPointCost();
|
|
||||||
}
|
|
||||||
return BigDecimal.valueOf(redemption.getActualPointCost()).multiply(quantity)
|
|
||||||
.divide(redemption.getQuantity(), 0, RoundingMode.FLOOR).longValueExact();
|
|
||||||
}
|
|
||||||
|
|
||||||
private GaoStockChangeItem stockItem(GaoProductSkuSelection selection, BigDecimal quantity, BigDecimal baseQuantity) {
|
|
||||||
GaoStockChangeItem result = GaoStockChangeItem.of(selection.product(), selection.sku(), selection.unit(), quantity, baseQuantity);
|
|
||||||
result.setSkuSpecSnapshot(skuService.getSkuSpecSnapshot(selection.sku()));
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private GaoStockChangeItem stockItem(GaoPointRedemption redemption, BigDecimal quantity, BigDecimal baseQuantity) {
|
|
||||||
GaoStockChangeItem result = new GaoStockChangeItem();
|
|
||||||
result.setSkuId(redemption.getSkuIdSnapshot());
|
|
||||||
result.setSkuUnitId(redemption.getSkuUnitIdSnapshot());
|
|
||||||
result.setProductIdSnapshot(redemption.getProductIdSnapshot());
|
|
||||||
result.setProductNameSnapshot(redemption.getProductNameSnapshot());
|
|
||||||
result.setSkuCodeSnapshot(redemption.getSkuCodeSnapshot());
|
|
||||||
result.setSkuNameSnapshot(redemption.getSkuNameSnapshot());
|
|
||||||
result.setSkuSpecSnapshot(redemption.getSkuSpecSnapshot());
|
|
||||||
result.setUnitSnapshot(redemption.getUnitSnapshot());
|
|
||||||
result.setBaseQuantityPerUnitSnapshot(redemption.getBaseQuantityPerUnitSnapshot());
|
|
||||||
result.setQuantity(quantity);
|
|
||||||
result.setBaseQuantity(baseQuantity);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void verifyExisting(GaoPointRedemption existing, String customerId, String redeemSkuId, BigDecimal quantity, Long actualPointCost) {
|
|
||||||
Long expectedActual = actualPointCost;
|
|
||||||
if (expectedActual == null) {
|
|
||||||
expectedActual = existing.getActualPointCost().equals(existing.getDefaultPointCost()) ? existing.getDefaultPointCost() : Long.MIN_VALUE;
|
|
||||||
}
|
|
||||||
TimiException.requiredTrue(customerId.equals(existing.getCustomerId())
|
|
||||||
&& redeemSkuId.equals(existing.getRedeemSkuIdSnapshot())
|
|
||||||
&& quantity.compareTo(existing.getQuantity()) == 0
|
|
||||||
&& expectedActual.equals(existing.getActualPointCost()), "requestNo 对应兑换内容不一致");
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean hasPhoto(List<Attachment> list) {
|
|
||||||
for (Attachment item : TimiJava.safeIterable(list)) {
|
|
||||||
if (item != null && (item.getAttachType() == null || "PHOTO".equalsIgnoreCase(item.getAttachType()))) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void fillTransient(List<GaoPointRedemption> list) {
|
|
||||||
if (list == null || list.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
List<String> idList = list.stream().map(GaoPointRedemption::getId).toList();
|
|
||||||
Map<String, List<Attachment>> attachmentMap = attachmentService.mapByBizIdList(Attachment.BizType.GAO_POINT_REDEMPTION, idList);
|
|
||||||
Map<String, GaoCustomer> customerMap = customerService.mapByIdList(list.stream().map(GaoPointRedemption::getCustomerId).distinct().toList());
|
|
||||||
Map<String, List<Attachment>> customerAttachmentMap = attachmentService.mapByBizIdList(
|
|
||||||
Attachment.BizType.GAO_CUSTOMER,
|
|
||||||
customerMap.keySet().stream().toList());
|
|
||||||
List<GaoPointRedemptionReturn> returnList = returnMapper.selectByRedemptionIdList(idList);
|
|
||||||
Map<String, List<GaoPointRedemptionReturn>> returnMap = returnList.stream()
|
|
||||||
.collect(Collectors.groupingBy(GaoPointRedemptionReturn::getRedemptionId));
|
|
||||||
fillReturnAttachments(returnList);
|
|
||||||
for (GaoPointRedemption item : list) {
|
|
||||||
item.setAttachmentList(attachmentMap.getOrDefault(item.getId(), List.of()));
|
|
||||||
GaoCustomer customer = customerMap.get(item.getCustomerId());
|
|
||||||
if (customer != null) {
|
|
||||||
customer.setAttachmentList(customerAttachmentMap.getOrDefault(customer.getId(), List.of()));
|
|
||||||
}
|
|
||||||
item.setCustomer(customer);
|
|
||||||
item.setReturnList(returnMap.getOrDefault(item.getId(), List.of()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void fillReturnAttachments(List<GaoPointRedemptionReturn> list) {
|
|
||||||
if (list == null || list.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Map<String, List<Attachment>> attachmentMap = attachmentService.mapByBizIdList(Attachment.BizType.GAO_POINT_REDEMPTION_RETURN,
|
|
||||||
list.stream().map(GaoPointRedemptionReturn::getId).toList());
|
|
||||||
for (GaoPointRedemptionReturn item : list) {
|
|
||||||
item.setAttachmentList(attachmentMap.getOrDefault(item.getId(), List.of()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String requiredText(String value, String message) {
|
|
||||||
TimiException.required(value, message);
|
|
||||||
String result = value.trim();
|
|
||||||
TimiException.requiredTrue(!result.isEmpty(), message);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean sameText(String left, String right) {
|
|
||||||
return left == null ? right == null : left.equals(right);
|
|
||||||
}
|
|
||||||
|
|
||||||
private long startOfDay(long timestamp) {
|
|
||||||
LocalDate date = Instant.ofEpochMilli(timestamp).atZone(BUSINESS_ZONE).toLocalDate();
|
|
||||||
return date.atStartOfDay(BUSINESS_ZONE).toInstant().toEpochMilli();
|
|
||||||
}
|
|
||||||
|
|
||||||
private long startOfNextDay(long timestamp) {
|
|
||||||
LocalDate date = Instant.ofEpochMilli(timestamp).atZone(BUSINESS_ZONE).toLocalDate().plusDays(1);
|
|
||||||
return date.atStartOfDay(BUSINESS_ZONE).toInstant().toEpochMilli();
|
|
||||||
}
|
|
||||||
|
|
||||||
private long startOfMonth(long timestamp) {
|
|
||||||
LocalDate date = Instant.ofEpochMilli(timestamp).atZone(BUSINESS_ZONE).toLocalDate().withDayOfMonth(1);
|
|
||||||
return date.atStartOfDay(BUSINESS_ZONE).toInstant().toEpochMilli();
|
|
||||||
}
|
|
||||||
|
|
||||||
private long startOfNextMonth(long timestamp) {
|
|
||||||
LocalDate date = Instant.ofEpochMilli(timestamp).atZone(BUSINESS_ZONE).toLocalDate().withDayOfMonth(1).plusMonths(1);
|
|
||||||
return date.atStartOfDay(BUSINESS_ZONE).toInstant().toEpochMilli();
|
|
||||||
}
|
|
||||||
|
|
||||||
private record GaoProductSkuSelection(GaoProduct product, GaoProductSku sku, GaoProductSkuUnit unit) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-1
@@ -233,7 +233,6 @@ public class GaoPointTriggerServiceImplement implements GaoPointTriggerService {
|
|||||||
replayRule.setTriggerSourceType(switch (origin.getTriggerSourceType()) {
|
replayRule.setTriggerSourceType(switch (origin.getTriggerSourceType()) {
|
||||||
case EVENT_RECORD -> GaoPointRule.TriggerSourceType.EVENT_RECORD;
|
case EVENT_RECORD -> GaoPointRule.TriggerSourceType.EVENT_RECORD;
|
||||||
case SALES_ORDER_PAID -> GaoPointRule.TriggerSourceType.SALES_ORDER_PAID;
|
case SALES_ORDER_PAID -> GaoPointRule.TriggerSourceType.SALES_ORDER_PAID;
|
||||||
case POINT_REDEMPTION -> null;
|
|
||||||
});
|
});
|
||||||
GaoPointScriptContext context = buildContext(replayRule, origin.getStoreId(), origin.getCustomerId(),
|
GaoPointScriptContext context = buildContext(replayRule, origin.getStoreId(), origin.getCustomerId(),
|
||||||
origin.getOccurredAt() == null ? Time.now() : origin.getOccurredAt(),
|
origin.getOccurredAt() == null ? Time.now() : origin.getOccurredAt(),
|
||||||
|
|||||||
+5
-18
@@ -109,22 +109,6 @@ public class GaoProductSkuServiceImplement extends AbstractEntityService<GaoProd
|
|||||||
return getSkuUnit(storeId, skuId, skuUnitId, false);
|
return getSkuUnit(storeId, skuId, skuUnitId, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public GaoProductSkuUnitSelection getFulfillableSkuUnit(String storeId, String skuId, String skuUnitId) {
|
|
||||||
TimiException.required(storeId, "门店 ID 不能为空");
|
|
||||||
TimiException.required(skuId, "SKU ID 不能为空");
|
|
||||||
TimiException.required(skuUnitId, "SKU 单位 ID 不能为空");
|
|
||||||
GaoProductSku sku = mapper.selectForUpdate(skuId);
|
|
||||||
TimiException.required(sku, "SKU 不存在");
|
|
||||||
TimiException.requiredTrue(storeId.equals(sku.getStoreId()), "SKU 不属于当前门店");
|
|
||||||
GaoProduct product = productServiceProvider.getObject().get(sku.getProductId());
|
|
||||||
TimiException.required(product, "产品不存在");
|
|
||||||
GaoProductSkuUnit unit = unitMapper.selectForUpdate(skuUnitId);
|
|
||||||
TimiException.required(unit, "SKU 单位不存在");
|
|
||||||
TimiException.requiredTrue(skuId.equals(unit.getSkuId()), "SKU 单位不属于当前 SKU");
|
|
||||||
return new GaoProductSkuUnitSelection(product, sku, unit);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GaoProductSkuUnitSelection getSkuUnit(String storeId, String skuId, String skuUnitId, boolean purchase) {
|
public GaoProductSkuUnitSelection getSkuUnit(String storeId, String skuId, String skuUnitId, boolean purchase) {
|
||||||
TimiException.required(storeId, "not found storeId");
|
TimiException.required(storeId, "not found storeId");
|
||||||
@@ -370,8 +354,11 @@ public class GaoProductSkuServiceImplement extends AbstractEntityService<GaoProd
|
|||||||
TimiException.requiredTrue(1 == unitMapper.updateUnit(unit), "SKU 单位更新失败");
|
TimiException.requiredTrue(1 == unitMapper.updateUnit(unit), "SKU 单位更新失败");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TimiException.requiredTrue(existingUnitList.stream().allMatch(existing -> retainedIdSet.contains(existing.getId())),
|
for (GaoProductSkuUnit existing : existingUnitList) {
|
||||||
"已保存的 SKU 单位不能删除,请关闭允许销售和允许采购");
|
if (!retainedIdSet.contains(existing.getId())) {
|
||||||
|
unitMapper.delete(existing.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveSpecValues(String skuId, List<String> specValueIdList) {
|
private void saveSpecValues(String skuId, List<String> specValueIdList) {
|
||||||
|
|||||||
+8
-60
@@ -156,30 +156,19 @@ public class GaoProductStockServiceImplement implements GaoProductStockService {
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
public boolean hasSufficientForFulfillment(String storeId, List<GaoStockChangeItem> items) {
|
public boolean hasSufficientForFulfillment(String storeId, List<GaoStockChangeItem> items) {
|
||||||
return getFulfillmentStockShortageMessage(storeId, items) == null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
|
||||||
public String getFulfillmentStockShortageMessage(String storeId, List<GaoStockChangeItem> items) {
|
|
||||||
TimiException.required(storeId, "not found storeId");
|
TimiException.required(storeId, "not found storeId");
|
||||||
if (items == null || items.isEmpty()) {
|
if (items == null || items.isEmpty()) {
|
||||||
return null;
|
return true;
|
||||||
}
|
}
|
||||||
List<GaoStockChangeItem> sortedItems = new ArrayList<>(items);
|
List<GaoStockChangeItem> sortedItems = new ArrayList<>(items);
|
||||||
sortedItems.sort(Comparator.comparing(GaoStockChangeItem::getSkuId));
|
sortedItems.sort(Comparator.comparing(GaoStockChangeItem::getSkuId));
|
||||||
List<String> shortageList = new ArrayList<>();
|
|
||||||
for (GaoStockChangeItem item : sortedItems) {
|
for (GaoStockChangeItem item : sortedItems) {
|
||||||
GaoProductStock stock = stockMapper.selectForUpdate(storeId, item.getSkuId());
|
GaoProductStock stock = stockMapper.selectForUpdate(storeId, item.getSkuId());
|
||||||
BigDecimal availableQuantity = stock == null ? ZERO : decimal(stock.getOnHandQuantity()).subtract(decimal(stock.getReservedQuantity()));
|
if (stock == null || decimal(stock.getOnHandQuantity()).subtract(decimal(stock.getReservedQuantity())).compareTo(item.getBaseQuantity()) < 0) {
|
||||||
BigDecimal shortageQuantity = item.getBaseQuantity().subtract(availableQuantity);
|
return false;
|
||||||
if (0 < shortageQuantity.signum()) {
|
|
||||||
shortageList.add("%s(%s)可用 %s %s,缺少 %s %s".formatted(
|
|
||||||
item.getProductNameSnapshot(), item.getSkuNameSnapshot(), availableQuantity.toPlainString(), item.getUnitSnapshot(),
|
|
||||||
shortageQuantity.toPlainString(), item.getUnitSnapshot()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return shortageList.isEmpty() ? null : "库存不足:" + String.join(";", shortageList);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -206,34 +195,6 @@ 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 GaoProductStockRecord outForRedemption(String storeId, String redemptionId, GaoStockChangeItem item, String requestNo, String operatorUserId) {
|
|
||||||
TimiException.required(item, "积分兑换库存项不能为空");
|
|
||||||
TimiException.required(item.getSkuId(), "not found skuId");
|
|
||||||
executeInternal(storeId, redemptionId, List.of(item), requestNo, operatorUserId,
|
|
||||||
GaoProductStockRecord.OperationType.POINT_REDEMPTION_OUT, null, null, null,
|
|
||||||
GaoProductStockRecord.BizType.POINT_REDEMPTION);
|
|
||||||
GaoProductStockRecord record = recordService.getByBizSku(GaoProductStockRecord.BizType.POINT_REDEMPTION, redemptionId,
|
|
||||||
item.getSkuId(), GaoProductStockRecord.OperationType.POINT_REDEMPTION_OUT);
|
|
||||||
TimiException.required(record, "兑换出库流水创建失败");
|
|
||||||
return record;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
|
||||||
@Override
|
|
||||||
public GaoProductStockRecord inForRedemptionReturn(String storeId, String returnId, GaoStockChangeItem item, String requestNo, String operatorUserId) {
|
|
||||||
TimiException.required(item, "积分兑换退货库存项不能为空");
|
|
||||||
TimiException.required(item.getSkuId(), "not found skuId");
|
|
||||||
executeInternal(storeId, returnId, List.of(item), requestNo, operatorUserId,
|
|
||||||
GaoProductStockRecord.OperationType.POINT_REDEMPTION_RETURN_IN, null, null, null,
|
|
||||||
GaoProductStockRecord.BizType.POINT_REDEMPTION);
|
|
||||||
GaoProductStockRecord record = recordService.getByBizSku(GaoProductStockRecord.BizType.POINT_REDEMPTION, returnId,
|
|
||||||
item.getSkuId(), GaoProductStockRecord.OperationType.POINT_REDEMPTION_RETURN_IN);
|
|
||||||
TimiException.required(record, "兑换退货入库流水创建失败");
|
|
||||||
return record;
|
|
||||||
}
|
|
||||||
|
|
||||||
private GaoProductStock change(GaoProductStockChangeRequest request, GaoProductStockRecord.OperationType operationType) {
|
private GaoProductStock change(GaoProductStockChangeRequest request, GaoProductStockRecord.OperationType operationType) {
|
||||||
TimiException.required(request, "not found stock change request");
|
TimiException.required(request, "not found stock change request");
|
||||||
String requestNo = requiredText(request.getRequestNo(), "not found requestNo");
|
String requestNo = requiredText(request.getRequestNo(), "not found requestNo");
|
||||||
@@ -339,18 +300,11 @@ public class GaoProductStockServiceImplement implements GaoProductStockService {
|
|||||||
|
|
||||||
private List<GaoProductStock> executeInternal(String storeId, String bizId, List<GaoStockChangeItem> sourceList, String requestNo,
|
private List<GaoProductStock> executeInternal(String storeId, String bizId, List<GaoStockChangeItem> sourceList, String requestNo,
|
||||||
String operatorUserId, GaoProductStockRecord.OperationType operationType, String remark) {
|
String operatorUserId, GaoProductStockRecord.OperationType operationType, String remark) {
|
||||||
return executeInternal(storeId, bizId, sourceList, requestNo, operatorUserId, operationType, null, remark, null, defaultBizType(operationType));
|
return executeInternal(storeId, bizId, sourceList, requestNo, operatorUserId, operationType, null, remark, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<GaoProductStock> executeInternal(String storeId, String bizId, List<GaoStockChangeItem> sourceList, String requestNo,
|
private List<GaoProductStock> executeInternal(String storeId, String bizId, List<GaoStockChangeItem> sourceList, String requestNo,
|
||||||
String operatorUserId, GaoProductStockRecord.OperationType operationType, Long occurredAt, String remark, List<Attachment> attachmentList) {
|
String operatorUserId, GaoProductStockRecord.OperationType operationType, Long occurredAt, String remark, List<Attachment> attachmentList) {
|
||||||
return executeInternal(storeId, bizId, sourceList, requestNo, operatorUserId, operationType, occurredAt, remark, attachmentList,
|
|
||||||
defaultBizType(operationType));
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<GaoProductStock> executeInternal(String storeId, String bizId, List<GaoStockChangeItem> sourceList, String requestNo,
|
|
||||||
String operatorUserId, GaoProductStockRecord.OperationType operationType, Long occurredAt, String remark, List<Attachment> attachmentList,
|
|
||||||
GaoProductStockRecord.BizType bizType) {
|
|
||||||
TimiException.required(storeId, "not found storeId");
|
TimiException.required(storeId, "not found storeId");
|
||||||
TimiException.required(bizId, "not found stock bizId");
|
TimiException.required(bizId, "not found stock bizId");
|
||||||
TimiException.requiredTrue(sourceList != null && !sourceList.isEmpty(), "库存变更至少需要一个产品");
|
TimiException.requiredTrue(sourceList != null && !sourceList.isEmpty(), "库存变更至少需要一个产品");
|
||||||
@@ -406,7 +360,7 @@ public class GaoProductStockServiceImplement implements GaoProductStockService {
|
|||||||
record.setOnHandAfter(onHandAfter);
|
record.setOnHandAfter(onHandAfter);
|
||||||
record.setReservedBefore(reservedBefore);
|
record.setReservedBefore(reservedBefore);
|
||||||
record.setReservedAfter(reservedAfter);
|
record.setReservedAfter(reservedAfter);
|
||||||
record.setBizType(bizType);
|
record.setBizType(operationType.name().startsWith("ORDER_") ? GaoProductStockRecord.BizType.ORDER_FULFILLMENT : GaoProductStockRecord.BizType.PRODUCT_STOCK);
|
||||||
record.setBizId(bizId);
|
record.setBizId(bizId);
|
||||||
record.setSourceRecordId(item.getSourceRecordId());
|
record.setSourceRecordId(item.getSourceRecordId());
|
||||||
record.setRequestNo(normalizedRequestNo);
|
record.setRequestNo(normalizedRequestNo);
|
||||||
@@ -444,8 +398,8 @@ 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 -> quantity;
|
||||||
case MANUAL_OUT, STOCKTAKE_LOSS, ORDER_OUT, POINT_REDEMPTION_OUT -> quantity.negate();
|
case MANUAL_OUT, STOCKTAKE_LOSS, ORDER_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, "手工库存冲正必须基于原库存流水");
|
||||||
};
|
};
|
||||||
@@ -537,10 +491,4 @@ public class GaoProductStockServiceImplement implements GaoProductStockService {
|
|||||||
private BigDecimal decimal(BigDecimal value) {
|
private BigDecimal decimal(BigDecimal value) {
|
||||||
return value == null ? ZERO : value;
|
return value == null ? ZERO : value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private GaoProductStockRecord.BizType defaultBizType(GaoProductStockRecord.OperationType operationType) {
|
|
||||||
return operationType.name().startsWith("ORDER_")
|
|
||||||
? GaoProductStockRecord.BizType.ORDER_FULFILLMENT
|
|
||||||
: GaoProductStockRecord.BizType.PRODUCT_STOCK;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-5
@@ -21,7 +21,6 @@ import com.imyeyu.api.modules.gao.service.GaoCustomerService;
|
|||||||
import com.imyeyu.api.modules.gao.service.GaoEventRecordService;
|
import com.imyeyu.api.modules.gao.service.GaoEventRecordService;
|
||||||
import com.imyeyu.api.modules.gao.service.GaoFundRecordService;
|
import com.imyeyu.api.modules.gao.service.GaoFundRecordService;
|
||||||
import com.imyeyu.api.modules.gao.service.GaoOrderFulfillmentService;
|
import com.imyeyu.api.modules.gao.service.GaoOrderFulfillmentService;
|
||||||
import com.imyeyu.api.modules.gao.service.GaoOrderStraightThroughService;
|
|
||||||
import com.imyeyu.api.modules.gao.service.GaoPointTriggerService;
|
import com.imyeyu.api.modules.gao.service.GaoPointTriggerService;
|
||||||
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;
|
||||||
@@ -81,7 +80,6 @@ public class GaoSalesOrderServiceImplement extends AbstractEntityService<GaoSale
|
|||||||
private final GaoSalesOrderItemMapper itemMapper;
|
private final GaoSalesOrderItemMapper itemMapper;
|
||||||
private final GaoFundRecordService fundRecordService;
|
private final GaoFundRecordService fundRecordService;
|
||||||
private final ObjectProvider<GaoOrderFulfillmentService> fulfillmentServiceProvider;
|
private final ObjectProvider<GaoOrderFulfillmentService> fulfillmentServiceProvider;
|
||||||
private final ObjectProvider<GaoOrderStraightThroughService> straightThroughServiceProvider;
|
|
||||||
private final GaoCustomerService customerService;
|
private final GaoCustomerService customerService;
|
||||||
private final GaoProductService productService;
|
private final GaoProductService productService;
|
||||||
private final GaoProductSkuService skuService;
|
private final GaoProductSkuService skuService;
|
||||||
@@ -145,9 +143,7 @@ public class GaoSalesOrderServiceImplement extends AbstractEntityService<GaoSale
|
|||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
@Override
|
@Override
|
||||||
public GaoSalesOrder createDirectProductOrder(GaoDirectProductOrderCreateRequest request) {
|
public GaoSalesOrder createDirectProductOrder(GaoDirectProductOrderCreateRequest request) {
|
||||||
GaoSalesOrder order = createDirectInternal(request);
|
return createDirectInternal(request);
|
||||||
straightThroughServiceProvider.getObject().complete(order, request.getStraightThrough());
|
|
||||||
return detail(order.getId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@OperationAudit(AuditOperation.GAO_SALES_ORDER_UPDATE)
|
@OperationAudit(AuditOperation.GAO_SALES_ORDER_UPDATE)
|
||||||
|
|||||||
@@ -33,9 +33,6 @@ public class GaoCustomerPackagePurchaseRequest {
|
|||||||
/// 购买照片
|
/// 购买照片
|
||||||
private List<Attachment> attachmentList;
|
private List<Attachment> attachmentList;
|
||||||
|
|
||||||
/// 创建订单后的直通处理
|
|
||||||
private GaoOrderStraightThroughRequest straightThrough;
|
|
||||||
|
|
||||||
/// 备注
|
/// 备注
|
||||||
private String remark;
|
private String remark;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,9 +30,6 @@ public class GaoDirectProductOrderCreateRequest {
|
|||||||
/// 购买照片
|
/// 购买照片
|
||||||
private List<Attachment> attachmentList;
|
private List<Attachment> attachmentList;
|
||||||
|
|
||||||
/// 创建订单后的直通处理
|
|
||||||
private GaoOrderStraightThroughRequest straightThrough;
|
|
||||||
|
|
||||||
/// 备注
|
/// 备注
|
||||||
private String remark;
|
private String remark;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,44 +0,0 @@
|
|||||||
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-09-13
|
|
||||||
@Data
|
|
||||||
public class GaoOrderStraightThroughRequest {
|
|
||||||
|
|
||||||
/// true 为已有收款并直接核销
|
|
||||||
private Boolean paymentVerified;
|
|
||||||
|
|
||||||
/// 已核销收款金额,单位分
|
|
||||||
private Long paymentAmount;
|
|
||||||
|
|
||||||
/// true 为直接全额收款并核销
|
|
||||||
private Boolean receiveFullPayment;
|
|
||||||
|
|
||||||
/// 实际收款时间,空为订单下单时间
|
|
||||||
private Long paymentOccurredAt;
|
|
||||||
|
|
||||||
/// 收款凭证照片
|
|
||||||
private List<Attachment> paymentAttachmentList;
|
|
||||||
|
|
||||||
/// 收款备注
|
|
||||||
private String paymentRemark;
|
|
||||||
|
|
||||||
/// true 为直接全部履约并核销
|
|
||||||
private Boolean fulfillAll;
|
|
||||||
|
|
||||||
/// 实际履约时间,空为订单下单时间
|
|
||||||
private Long deliveredAt;
|
|
||||||
|
|
||||||
/// 履约凭证照片
|
|
||||||
private List<Attachment> fulfillmentAttachmentList;
|
|
||||||
|
|
||||||
/// 履约备注
|
|
||||||
private String fulfillmentRemark;
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.vo;
|
|
||||||
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoPointRedeemSku;
|
|
||||||
import com.imyeyu.java.bean.BasePage;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
/// GAO 积分兑换 SKU 配置分页请求
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-09-14
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
public class GaoPointRedeemSkuPage extends BasePage {
|
|
||||||
|
|
||||||
/// 门店 ID
|
|
||||||
private String storeId;
|
|
||||||
|
|
||||||
/// SKU ID
|
|
||||||
private String skuId;
|
|
||||||
|
|
||||||
/// 配置状态
|
|
||||||
private GaoPointRedeemSku.Status status;
|
|
||||||
|
|
||||||
/// 产品或 SKU 关键词
|
|
||||||
private String keyword;
|
|
||||||
}
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.vo;
|
|
||||||
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoPointRedeemSku;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
|
|
||||||
/// GAO 积分兑换 SKU 配置请求
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-09-14
|
|
||||||
@Data
|
|
||||||
public class GaoPointRedeemSkuRequest {
|
|
||||||
|
|
||||||
/// 配置 ID,修改时必填
|
|
||||||
private String id;
|
|
||||||
|
|
||||||
/// 门店 ID
|
|
||||||
private String storeId;
|
|
||||||
|
|
||||||
/// SKU ID
|
|
||||||
private String skuId;
|
|
||||||
|
|
||||||
/// SKU 单位 ID
|
|
||||||
private String skuUnitId;
|
|
||||||
|
|
||||||
/// 配置状态
|
|
||||||
private GaoPointRedeemSku.Status status;
|
|
||||||
|
|
||||||
/// 每个业务单位默认所需积分
|
|
||||||
private Long defaultPointCost;
|
|
||||||
|
|
||||||
/// 生效开始时间戳,毫秒
|
|
||||||
private Long beginAt;
|
|
||||||
|
|
||||||
/// 生效结束时间戳,毫秒
|
|
||||||
private Long endAt;
|
|
||||||
|
|
||||||
/// 每客户累计最多兑换数量
|
|
||||||
private BigDecimal maxTotalQuantity;
|
|
||||||
|
|
||||||
/// 每客户自然日最多兑换数量
|
|
||||||
private BigDecimal maxDailyQuantity;
|
|
||||||
|
|
||||||
/// 每客户自然月最多兑换数量
|
|
||||||
private BigDecimal maxMonthlyQuantity;
|
|
||||||
|
|
||||||
/// 备注
|
|
||||||
private String remark;
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.vo;
|
|
||||||
|
|
||||||
import com.imyeyu.api.modules.common.entity.Attachment;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/// GAO 积分兑换创建请求
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-09-14
|
|
||||||
@Data
|
|
||||||
public class GaoPointRedemptionCreateRequest {
|
|
||||||
|
|
||||||
/// 创建幂等号
|
|
||||||
private String requestNo;
|
|
||||||
|
|
||||||
/// 门店 ID
|
|
||||||
private String storeId;
|
|
||||||
|
|
||||||
/// 客户 ID
|
|
||||||
private String customerId;
|
|
||||||
|
|
||||||
/// 兑换 SKU 配置 ID
|
|
||||||
private String redeemSkuId;
|
|
||||||
|
|
||||||
/// 兑换业务数量
|
|
||||||
private BigDecimal quantity;
|
|
||||||
|
|
||||||
/// 实际扣除总积分,为空时使用默认总积分
|
|
||||||
private Long actualPointCost;
|
|
||||||
|
|
||||||
/// 兑换照片,至少一张
|
|
||||||
private List<Attachment> attachmentList;
|
|
||||||
|
|
||||||
/// 备注
|
|
||||||
private String remark;
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.vo;
|
|
||||||
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoPointRedemption;
|
|
||||||
import com.imyeyu.java.bean.BasePage;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
/// GAO 积分兑换单分页请求
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-09-14
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
public class GaoPointRedemptionPage extends BasePage {
|
|
||||||
|
|
||||||
/// 门店 ID
|
|
||||||
private String storeId;
|
|
||||||
|
|
||||||
/// 客户 ID
|
|
||||||
private String customerId;
|
|
||||||
|
|
||||||
/// 兑换 SKU 配置 ID
|
|
||||||
private String redeemSkuId;
|
|
||||||
|
|
||||||
/// SKU ID 快照
|
|
||||||
private String skuIdSnapshot;
|
|
||||||
|
|
||||||
/// 兑换单状态
|
|
||||||
private GaoPointRedemption.Status status;
|
|
||||||
|
|
||||||
/// 产品或 SKU 关键词
|
|
||||||
private String keyword;
|
|
||||||
|
|
||||||
/// 开始兑换时间
|
|
||||||
private Long beginAt;
|
|
||||||
|
|
||||||
/// 结束兑换时间
|
|
||||||
private Long endAt;
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.vo;
|
|
||||||
|
|
||||||
import com.imyeyu.api.modules.common.entity.Attachment;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/// GAO 积分兑换退货请求
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-09-14
|
|
||||||
@Data
|
|
||||||
public class GaoPointRedemptionReturnRequest {
|
|
||||||
|
|
||||||
/// 兑换单 ID
|
|
||||||
private String redemptionId;
|
|
||||||
|
|
||||||
/// 退货幂等号
|
|
||||||
private String requestNo;
|
|
||||||
|
|
||||||
/// 本次退货业务数量
|
|
||||||
private BigDecimal quantity;
|
|
||||||
|
|
||||||
/// 退货照片,至少一张
|
|
||||||
private List<Attachment> attachmentList;
|
|
||||||
|
|
||||||
/// 退货原因和备注
|
|
||||||
private String remark;
|
|
||||||
}
|
|
||||||
-77
@@ -1,77 +0,0 @@
|
|||||||
CREATE TABLE `gao_point_redeem_sku` (
|
|
||||||
`id` VARCHAR(36) NOT NULL,
|
|
||||||
`store_id` VARCHAR(36) NOT NULL COMMENT '门店 ID',
|
|
||||||
`sku_id` VARCHAR(36) NOT NULL COMMENT 'SKU ID',
|
|
||||||
`sku_unit_id` VARCHAR(36) NOT NULL COMMENT 'SKU 单位 ID',
|
|
||||||
`status` VARCHAR(32) NOT NULL COMMENT 'DRAFT 草稿,ACTIVE 启用,INACTIVE 停用,DELETED 删除',
|
|
||||||
`default_point_cost` BIGINT NOT NULL COMMENT '每个业务单位默认所需积分',
|
|
||||||
`begin_at` BIGINT NULL COMMENT '生效开始时间戳,毫秒',
|
|
||||||
`end_at` BIGINT NULL COMMENT '生效结束时间戳,毫秒',
|
|
||||||
`max_total_quantity` DECIMAL(18,3) NULL COMMENT '每客户累计最多兑换数量',
|
|
||||||
`max_daily_quantity` DECIMAL(18,3) NULL COMMENT '每客户自然日最多兑换数量',
|
|
||||||
`max_monthly_quantity` DECIMAL(18,3) NULL COMMENT '每客户自然月最多兑换数量',
|
|
||||||
`remark` TEXT NULL COMMENT '备注',
|
|
||||||
`created_at` BIGINT NOT NULL,
|
|
||||||
`updated_at` BIGINT NULL,
|
|
||||||
`deleted_at` BIGINT NULL,
|
|
||||||
PRIMARY KEY (`id`),
|
|
||||||
UNIQUE KEY `uk_gao_point_redeem_sku_store_sku_unit` (`store_id`, `sku_id`, `sku_unit_id`),
|
|
||||||
KEY `idx_gao_point_redeem_sku_store_status_time` (`store_id`, `status`, `begin_at`, `end_at`, `created_at`),
|
|
||||||
KEY `idx_gao_point_redeem_sku_sku` (`store_id`, `sku_id`, `sku_unit_id`)
|
|
||||||
) COMMENT='GAO 积分兑换 SKU 配置';
|
|
||||||
|
|
||||||
CREATE TABLE `gao_point_redemption` (
|
|
||||||
`id` VARCHAR(36) NOT NULL,
|
|
||||||
`store_id` VARCHAR(36) NOT NULL COMMENT '门店 ID',
|
|
||||||
`customer_id` VARCHAR(36) NOT NULL COMMENT '客户 ID',
|
|
||||||
`request_no` VARCHAR(128) NOT NULL COMMENT '创建幂等号',
|
|
||||||
`redeem_sku_id_snapshot` VARCHAR(36) NOT NULL COMMENT '兑换 SKU 配置 ID 快照',
|
|
||||||
`product_id_snapshot` VARCHAR(36) NOT NULL COMMENT '产品 ID 快照',
|
|
||||||
`product_name_snapshot` VARCHAR(128) NOT NULL COMMENT '产品名称快照',
|
|
||||||
`product_type_snapshot` VARCHAR(32) NOT NULL COMMENT '产品类型快照',
|
|
||||||
`sku_id_snapshot` VARCHAR(36) NOT NULL COMMENT 'SKU ID 快照',
|
|
||||||
`sku_code_snapshot` VARCHAR(64) NOT NULL COMMENT 'SKU 编码快照',
|
|
||||||
`sku_name_snapshot` VARCHAR(128) NOT NULL COMMENT 'SKU 名称快照',
|
|
||||||
`sku_spec_snapshot` JSON NOT NULL COMMENT 'SKU 规格结构快照',
|
|
||||||
`sku_unit_id_snapshot` VARCHAR(36) NOT NULL COMMENT 'SKU 单位 ID 快照',
|
|
||||||
`unit_snapshot` VARCHAR(32) NOT NULL COMMENT '单位名称快照',
|
|
||||||
`base_quantity_per_unit_snapshot` DECIMAL(18,6) NOT NULL COMMENT '每个业务单位基础数量快照',
|
|
||||||
`allow_decimal_quantity_snapshot` TINYINT(1) NOT NULL COMMENT 'true 为允许小数数量快照',
|
|
||||||
`quantity` DECIMAL(18,3) NOT NULL COMMENT '兑换业务数量',
|
|
||||||
`base_quantity` DECIMAL(18,3) NOT NULL COMMENT '兑换基础数量',
|
|
||||||
`default_point_cost` BIGINT NOT NULL COMMENT '默认总积分',
|
|
||||||
`actual_point_cost` BIGINT NOT NULL COMMENT '实际扣除总积分',
|
|
||||||
`returned_quantity` DECIMAL(18,3) NOT NULL DEFAULT 0 COMMENT '累计已退业务数量',
|
|
||||||
`returned_point_cost` BIGINT NOT NULL DEFAULT 0 COMMENT '累计已返积分',
|
|
||||||
`status` VARCHAR(32) NOT NULL COMMENT 'COMPLETED 完成,PARTIALLY_RETURNED 部分退货,FULLY_RETURNED 全部退货',
|
|
||||||
`operator_user_id` VARCHAR(36) NOT NULL COMMENT '兑换操作人',
|
|
||||||
`redeemed_at` BIGINT NOT NULL COMMENT '兑换完成时间',
|
|
||||||
`remark` TEXT NULL COMMENT '备注',
|
|
||||||
`created_at` BIGINT NOT NULL,
|
|
||||||
`updated_at` BIGINT NULL,
|
|
||||||
`deleted_at` BIGINT NULL,
|
|
||||||
PRIMARY KEY (`id`),
|
|
||||||
UNIQUE KEY `uk_gao_point_redemption_store_request` (`store_id`, `request_no`),
|
|
||||||
KEY `idx_gao_point_redemption_customer_status_time` (`store_id`, `customer_id`, `status`, `redeemed_at`),
|
|
||||||
KEY `idx_gao_point_redemption_sku_status_time` (`store_id`, `sku_id_snapshot`, `status`, `redeemed_at`),
|
|
||||||
KEY `idx_gao_point_redemption_config_time` (`redeem_sku_id_snapshot`, `redeemed_at`)
|
|
||||||
) COMMENT='GAO 积分兑换单';
|
|
||||||
|
|
||||||
CREATE TABLE `gao_point_redemption_return` (
|
|
||||||
`id` VARCHAR(36) NOT NULL,
|
|
||||||
`redemption_id` VARCHAR(36) NOT NULL COMMENT '兑换单 ID',
|
|
||||||
`request_no` VARCHAR(128) NOT NULL COMMENT '退货幂等号',
|
|
||||||
`quantity` DECIMAL(18,3) NOT NULL COMMENT '本次退货业务数量',
|
|
||||||
`base_quantity` DECIMAL(18,3) NOT NULL COMMENT '本次退货基础数量',
|
|
||||||
`point_cost` BIGINT NOT NULL COMMENT '本次实际返还积分',
|
|
||||||
`stock_record_id` VARCHAR(36) NULL COMMENT '实物退货入库流水 ID',
|
|
||||||
`operator_user_id` VARCHAR(36) NOT NULL COMMENT '退货操作人',
|
|
||||||
`returned_at` BIGINT NOT NULL COMMENT '退货时间',
|
|
||||||
`remark` TEXT NULL COMMENT '退货原因和备注',
|
|
||||||
`created_at` BIGINT NOT NULL,
|
|
||||||
`updated_at` BIGINT NULL,
|
|
||||||
`deleted_at` BIGINT NULL,
|
|
||||||
PRIMARY KEY (`id`),
|
|
||||||
UNIQUE KEY `uk_gao_point_redemption_return_request` (`redemption_id`, `request_no`),
|
|
||||||
KEY `idx_gao_point_redemption_return_time` (`redemption_id`, `returned_at`)
|
|
||||||
) COMMENT='GAO 积分兑换退货记录';
|
|
||||||
@@ -348,23 +348,10 @@
|
|||||||
FROM `daily_stat` d
|
FROM `daily_stat` d
|
||||||
JOIN `open_calendar` o ON d.`registeredDateValue` = o.`dateValue`
|
JOIN `open_calendar` o ON d.`registeredDateValue` = o.`dateValue`
|
||||||
),
|
),
|
||||||
`customer_stat` AS (
|
|
||||||
SELECT
|
|
||||||
d.`customerId`,
|
|
||||||
MAX(CASE WHEN d.`registeredDateValue` = #{todayDateValue} THEN 1 ELSE 0 END) AS `hasToday`
|
|
||||||
FROM `daily_stat` d
|
|
||||||
GROUP BY d.`customerId`
|
|
||||||
),
|
|
||||||
`anchor_date` AS (
|
`anchor_date` AS (
|
||||||
SELECT
|
SELECT
|
||||||
s.`customerId`,
|
MAX(`openIndex`) AS `anchorOpenIndex`
|
||||||
CASE
|
FROM `open_calendar`
|
||||||
WHEN s.`hasToday` = 1 THEN MAX(CASE WHEN c.`dateValue` = #{todayDateValue} THEN c.`openIndex` END)
|
|
||||||
ELSE MAX(CASE WHEN c.`dateValue` < #{todayDateValue} THEN c.`openIndex` END)
|
|
||||||
END AS `anchorOpenIndex`
|
|
||||||
FROM `customer_stat` s
|
|
||||||
CROSS JOIN `open_calendar` c
|
|
||||||
GROUP BY s.`customerId`, s.`hasToday`
|
|
||||||
),
|
),
|
||||||
`continuous_stat` AS (
|
`continuous_stat` AS (
|
||||||
SELECT
|
SELECT
|
||||||
@@ -374,7 +361,7 @@
|
|||||||
ELSE COUNT(1)
|
ELSE COUNT(1)
|
||||||
END AS `recentContinuousEventDays`
|
END AS `recentContinuousEventDays`
|
||||||
FROM `continuous_ordered` o
|
FROM `continuous_ordered` o
|
||||||
JOIN `anchor_date` a ON o.`customerId` = a.`customerId`
|
JOIN `anchor_date` a
|
||||||
WHERE
|
WHERE
|
||||||
o.`openIndex` + o.`dayIndex` = a.`anchorOpenIndex` + 1
|
o.`openIndex` + o.`dayIndex` = a.`anchorOpenIndex` + 1
|
||||||
<if test="eventIdList == null or eventIdList.size() != 1">
|
<if test="eventIdList == null or eventIdList.size() != 1">
|
||||||
|
|||||||
@@ -53,7 +53,7 @@
|
|||||||
INNER JOIN `gao_customer` `c` ON `c`.`id` = `a`.`customer_id` AND `c`.`store_id` = `a`.`store_id`
|
INNER JOIN `gao_customer` `c` ON `c`.`id` = `a`.`customer_id` AND `c`.`store_id` = `a`.`store_id`
|
||||||
WHERE
|
WHERE
|
||||||
<include refid="queryWhere"/>
|
<include refid="queryWhere"/>
|
||||||
ORDER BY `a`.`total_earned` DESC, `a`.`created_at` DESC, `a`.`id` DESC
|
ORDER BY `a`.`created_at` DESC, `a`.`id` DESC
|
||||||
LIMIT #{offset}, #{limit}
|
LIMIT #{offset}, #{limit}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|||||||
@@ -1,62 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
|
||||||
<mapper namespace="com.imyeyu.api.modules.gao.mapper.GaoPointRedeemSkuMapper">
|
|
||||||
<select id="selectByStoreIdAndId" resultType="com.imyeyu.api.modules.gao.entity.GaoPointRedeemSku">
|
|
||||||
SELECT * FROM `gao_point_redeem_sku`
|
|
||||||
WHERE `store_id` = #{storeId} AND `id` = #{id} AND `deleted_at` IS NULL
|
|
||||||
LIMIT 1
|
|
||||||
</select>
|
|
||||||
<select id="selectByStoreSkuUnit" resultType="com.imyeyu.api.modules.gao.entity.GaoPointRedeemSku">
|
|
||||||
SELECT * FROM `gao_point_redeem_sku`
|
|
||||||
WHERE `store_id` = #{storeId} AND `sku_id` = #{skuId} AND `sku_unit_id` = #{skuUnitId}
|
|
||||||
AND `deleted_at` IS NULL
|
|
||||||
LIMIT 1
|
|
||||||
</select>
|
|
||||||
<select id="selectForUpdate" resultType="com.imyeyu.api.modules.gao.entity.GaoPointRedeemSku">
|
|
||||||
SELECT * FROM `gao_point_redeem_sku`
|
|
||||||
WHERE `id` = #{id} AND `deleted_at` IS NULL
|
|
||||||
LIMIT 1
|
|
||||||
FOR UPDATE
|
|
||||||
</select>
|
|
||||||
<sql id="queryWhere">
|
|
||||||
`r`.`deleted_at` IS NULL
|
|
||||||
<if test="storeId != null and storeId != ''">AND `r`.`store_id` = #{storeId}</if>
|
|
||||||
<if test="skuId != null and skuId != ''">AND `r`.`sku_id` = #{skuId}</if>
|
|
||||||
<if test="status != null">AND `r`.`status` = #{status}</if>
|
|
||||||
<if test="keyword != null and keyword.trim() != ''">
|
|
||||||
AND (`p`.`name` LIKE CONCAT('%', #{keyword}, '%') OR `p`.`code` LIKE CONCAT('%', #{keyword}, '%')
|
|
||||||
OR `k`.`name` LIKE CONCAT('%', #{keyword}, '%') OR `k`.`code` LIKE CONCAT('%', #{keyword}, '%'))
|
|
||||||
</if>
|
|
||||||
</sql>
|
|
||||||
<select id="countByQuery" resultType="long">
|
|
||||||
SELECT COUNT(1)
|
|
||||||
FROM `gao_point_redeem_sku` `r`
|
|
||||||
INNER JOIN `gao_product_sku` `k` ON `k`.`id` = `r`.`sku_id`
|
|
||||||
INNER JOIN `gao_product` `p` ON `p`.`id` = `k`.`product_id`
|
|
||||||
WHERE <include refid="queryWhere"/>
|
|
||||||
</select>
|
|
||||||
<select id="selectByQuery" resultType="com.imyeyu.api.modules.gao.entity.GaoPointRedeemSku">
|
|
||||||
SELECT `r`.*
|
|
||||||
FROM `gao_point_redeem_sku` `r`
|
|
||||||
INNER JOIN `gao_product_sku` `k` ON `k`.`id` = `r`.`sku_id`
|
|
||||||
INNER JOIN `gao_product` `p` ON `p`.`id` = `k`.`product_id`
|
|
||||||
WHERE <include refid="queryWhere"/>
|
|
||||||
ORDER BY `r`.`created_at` DESC, `r`.`id` DESC
|
|
||||||
LIMIT #{offset}, #{limit}
|
|
||||||
</select>
|
|
||||||
<update id="updateConfig">
|
|
||||||
UPDATE `gao_point_redeem_sku`
|
|
||||||
SET `sku_id` = #{skuId},
|
|
||||||
`sku_unit_id` = #{skuUnitId},
|
|
||||||
`status` = #{status},
|
|
||||||
`default_point_cost` = #{defaultPointCost},
|
|
||||||
`begin_at` = #{beginAt},
|
|
||||||
`end_at` = #{endAt},
|
|
||||||
`max_total_quantity` = #{maxTotalQuantity},
|
|
||||||
`max_daily_quantity` = #{maxDailyQuantity},
|
|
||||||
`max_monthly_quantity` = #{maxMonthlyQuantity},
|
|
||||||
`remark` = #{remark},
|
|
||||||
`updated_at` = #{updatedAt}
|
|
||||||
WHERE `id` = #{id} AND `deleted_at` IS NULL
|
|
||||||
</update>
|
|
||||||
</mapper>
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
|
||||||
<mapper namespace="com.imyeyu.api.modules.gao.mapper.GaoPointRedemptionMapper">
|
|
||||||
<select id="selectByStoreIdAndRequestNo" resultType="com.imyeyu.api.modules.gao.entity.GaoPointRedemption">
|
|
||||||
SELECT * FROM `gao_point_redemption`
|
|
||||||
WHERE `store_id` = #{storeId} AND `request_no` = #{requestNo} AND `deleted_at` IS NULL
|
|
||||||
LIMIT 1
|
|
||||||
</select>
|
|
||||||
<select id="selectByStoreIdAndId" resultType="com.imyeyu.api.modules.gao.entity.GaoPointRedemption">
|
|
||||||
SELECT * FROM `gao_point_redemption`
|
|
||||||
WHERE `store_id` = #{storeId} AND `id` = #{id} AND `deleted_at` IS NULL
|
|
||||||
LIMIT 1
|
|
||||||
</select>
|
|
||||||
<select id="selectForUpdate" resultType="com.imyeyu.api.modules.gao.entity.GaoPointRedemption">
|
|
||||||
SELECT * FROM `gao_point_redemption`
|
|
||||||
WHERE `id` = #{id} AND `deleted_at` IS NULL
|
|
||||||
LIMIT 1
|
|
||||||
FOR UPDATE
|
|
||||||
</select>
|
|
||||||
<sql id="queryWhere">
|
|
||||||
`r`.`deleted_at` IS NULL
|
|
||||||
<if test="storeId != null and storeId != ''">AND `r`.`store_id` = #{storeId}</if>
|
|
||||||
<if test="customerId != null and customerId != ''">AND `r`.`customer_id` = #{customerId}</if>
|
|
||||||
<if test="redeemSkuId != null and redeemSkuId != ''">AND `r`.`redeem_sku_id_snapshot` = #{redeemSkuId}</if>
|
|
||||||
<if test="skuIdSnapshot != null and skuIdSnapshot != ''">AND `r`.`sku_id_snapshot` = #{skuIdSnapshot}</if>
|
|
||||||
<if test="status != null">AND `r`.`status` = #{status}</if>
|
|
||||||
<if test="keyword != null and keyword.trim() != ''">
|
|
||||||
AND (`r`.`product_name_snapshot` LIKE CONCAT('%', #{keyword}, '%')
|
|
||||||
OR `r`.`sku_code_snapshot` LIKE CONCAT('%', #{keyword}, '%')
|
|
||||||
OR `r`.`sku_name_snapshot` LIKE CONCAT('%', #{keyword}, '%')
|
|
||||||
OR `c`.`code` LIKE CONCAT('%', #{keyword}, '%')
|
|
||||||
OR `c`.`name` LIKE CONCAT('%', #{keyword}, '%')
|
|
||||||
OR `c`.`telephone` LIKE CONCAT('%', #{keyword}, '%')
|
|
||||||
OR `c`.`name_pinyin_full` LIKE CONCAT(#{keyword}, '%')
|
|
||||||
OR `c`.`name_pinyin_initial` LIKE CONCAT(#{keyword}, '%')
|
|
||||||
OR `c`.`name_pinyin_mixed` LIKE CONCAT(#{keyword}, '%'))
|
|
||||||
</if>
|
|
||||||
<if test="beginAt != null">AND `r`.`redeemed_at` >= #{beginAt}</if>
|
|
||||||
<if test="endAt != null">AND `r`.`redeemed_at` <= #{endAt}</if>
|
|
||||||
</sql>
|
|
||||||
<select id="countByQuery" resultType="long">
|
|
||||||
SELECT COUNT(1)
|
|
||||||
FROM `gao_point_redemption` `r`
|
|
||||||
LEFT JOIN `gao_customer` `c` ON `c`.`id` = `r`.`customer_id`
|
|
||||||
WHERE <include refid="queryWhere"/>
|
|
||||||
</select>
|
|
||||||
<select id="selectByQuery" resultType="com.imyeyu.api.modules.gao.entity.GaoPointRedemption">
|
|
||||||
SELECT `r`.*
|
|
||||||
FROM `gao_point_redemption` `r`
|
|
||||||
LEFT JOIN `gao_customer` `c` ON `c`.`id` = `r`.`customer_id`
|
|
||||||
WHERE <include refid="queryWhere"/>
|
|
||||||
ORDER BY `r`.`redeemed_at` DESC, `r`.`created_at` DESC, `r`.`id` DESC
|
|
||||||
LIMIT #{offset}, #{limit}
|
|
||||||
</select>
|
|
||||||
<select id="sumValidQuantity" resultType="java.math.BigDecimal">
|
|
||||||
SELECT COALESCE(SUM(`quantity` - `returned_quantity`), 0)
|
|
||||||
FROM `gao_point_redemption`
|
|
||||||
WHERE `store_id` = #{storeId}
|
|
||||||
AND `customer_id` = #{customerId}
|
|
||||||
AND `sku_id_snapshot` = #{skuId}
|
|
||||||
AND `status` IN ('COMPLETED', 'PARTIALLY_RETURNED')
|
|
||||||
AND `deleted_at` IS NULL
|
|
||||||
<if test="beginAt != null">AND `redeemed_at` >= #{beginAt}</if>
|
|
||||||
<if test="endAt != null">AND `redeemed_at` <= #{endAt}</if>
|
|
||||||
</select>
|
|
||||||
</mapper>
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
|
||||||
<mapper namespace="com.imyeyu.api.modules.gao.mapper.GaoPointRedemptionReturnMapper">
|
|
||||||
<select id="selectByRedemptionId" resultType="com.imyeyu.api.modules.gao.entity.GaoPointRedemptionReturn">
|
|
||||||
SELECT * FROM `gao_point_redemption_return`
|
|
||||||
WHERE `redemption_id` = #{redemptionId} AND `deleted_at` IS NULL
|
|
||||||
ORDER BY `returned_at`, `created_at`, `id`
|
|
||||||
</select>
|
|
||||||
<select id="selectByRedemptionIdList" resultType="com.imyeyu.api.modules.gao.entity.GaoPointRedemptionReturn">
|
|
||||||
SELECT * FROM `gao_point_redemption_return`
|
|
||||||
WHERE `redemption_id` IN
|
|
||||||
<foreach collection="redemptionIdList" item="redemptionId" separator="," open="(" close=")">
|
|
||||||
#{redemptionId}
|
|
||||||
</foreach>
|
|
||||||
AND `deleted_at` IS NULL
|
|
||||||
ORDER BY `redemption_id`, `returned_at`, `created_at`, `id`
|
|
||||||
</select>
|
|
||||||
<select id="selectByRedemptionIdAndRequestNo" resultType="com.imyeyu.api.modules.gao.entity.GaoPointRedemptionReturn">
|
|
||||||
SELECT * FROM `gao_point_redemption_return`
|
|
||||||
WHERE `redemption_id` = #{redemptionId} AND `request_no` = #{requestNo} AND `deleted_at` IS NULL
|
|
||||||
LIMIT 1
|
|
||||||
</select>
|
|
||||||
<select id="selectForUpdate" resultType="com.imyeyu.api.modules.gao.entity.GaoPointRedemptionReturn">
|
|
||||||
SELECT * FROM `gao_point_redemption_return`
|
|
||||||
WHERE `id` = #{id} AND `deleted_at` IS NULL
|
|
||||||
LIMIT 1
|
|
||||||
FOR UPDATE
|
|
||||||
</select>
|
|
||||||
</mapper>
|
|
||||||
Reference in New Issue
Block a user