mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-23 23:19:19 +08:00
feat: 优化店铺订单同步交互
This commit is contained in:
@@ -121,19 +121,31 @@ FE 打开店铺增量开关
|
||||
|
||||
## 3. 前端控制面
|
||||
|
||||
### 3.1 全量同步任务
|
||||
列表一眼可见全量/增量健康度;弹窗打开按 `shopId` 恢复最新态(关窗不丢);RUNNING 自动轮询。
|
||||
|
||||
### 3.1 信息架构
|
||||
|
||||
| 位置 | 展示 |
|
||||
|------|------|
|
||||
| 店铺列表「订单同步」列 | 全量:`进行中 n/m` / `失败` / `已完成(相对时间)` / `-`;增量:`开·正常` / `开·滞后` / `开·暂停` / `关` + 游标相对时间;点击进弹窗 |
|
||||
| 同步弹窗上半 | **状态面板**:全量进度(区间、当前日、done/failed、错误)+ 取消/续跑;增量开关、游标、上次成功、health、暂停原因 |
|
||||
| 同步弹窗下半 | **操作**:创建全量 / 按日回补 / 手动增量(后两者仅「已入队」) |
|
||||
|
||||
### 3.2 全量同步任务
|
||||
|
||||
| 项 | 约定 |
|
||||
|----|------|
|
||||
| 入口 | 店铺列表 / 店铺详情:「全量同步订单」 |
|
||||
| 入口 | 店铺列表「同步订单」/ 订单同步列 |
|
||||
| 参数 | `shopId`、`dateFrom`、`dateTo`(成交日,Asia/Shanghai);前端默认近 **90** 天 |
|
||||
| 行为 | 创建后端任务后立即返回 `taskId`;前端轮询或刷新任务状态 |
|
||||
| 行为 | 创建后返回 `taskId`;弹窗轮询;打开时 `GET .../full-task/latest?shopId=` 恢复 |
|
||||
| 进度 | 总天数、已完成日、失败日、当前处理日、状态(PENDING / RUNNING / SUCCESS / FAILED / CANCELLED) |
|
||||
| 约束 | 同店同时仅允许一个 RUNNING 全量任务;与现有 day sync 共用店级 Redis 锁 |
|
||||
| 约束 | 同店同时仅允许一个 PENDING/RUNNING 全量任务 |
|
||||
| 失败 | 默认暂停为 FAILED;`POST .../full-task/{id}/resume` 从失败日(`dateFrom + doneDays`)续跑 |
|
||||
| 取消 | `POST .../full-task/{id}/cancel`;执行器按日边界感知 CANCELLED 后停止 |
|
||||
|
||||
后端任务表建议:`channel_order_full_sync_task`(渠道通用)或 PDD 专用 `channel_pdd_order_full_sync_task`。
|
||||
后端任务表:`channel_pdd_order_full_sync_task`。
|
||||
|
||||
字段建议:
|
||||
字段:
|
||||
|
||||
| 字段 | 说明 |
|
||||
|------|------|
|
||||
@@ -151,25 +163,32 @@ FE 打开店铺增量开关
|
||||
|
||||
1. 按天**串行**调用现有 day sync(沿用 `pdd.order.list.get`、店锁、限流)
|
||||
2. **每天渠道同步成功后**立刻发转换消息(不等整个区间结束)
|
||||
3. 某日失败:记入失败日,任务可配置为「暂停等待重试」或「跳过继续」;默认**暂停**,前端可点重试从失败日继续
|
||||
3. 某日失败:记入失败日并 FAILED;前端可续跑
|
||||
|
||||
### 3.2 增量同步开关
|
||||
### 3.3 增量同步开关
|
||||
|
||||
| 项 | 约定 |
|
||||
|----|------|
|
||||
| 入口 | 店铺维度 Switch:「开启增量同步」 |
|
||||
| 入口 | 弹窗 Switch;列表展示 health |
|
||||
| 存储 | `ec_shop.order_inc_sync_enabled`;运行态在 `channel_pdd_order_inc_sync` |
|
||||
| Job | 仅处理开关开启且未出错暂停的店;关闭后不再拉增量、不再发 INC 转换 |
|
||||
| 与 YAML | 全局 `pdd.order-sync.incremental-job-enabled` 仍作总闸;单店开关为细粒度 |
|
||||
| Job | 仅处理开关开启且未出错暂停的店 |
|
||||
| health | `OFF` / `OK` / `LAGGING`(游标或上次成功 >15min)/ `PAUSED` |
|
||||
| 与 YAML | 全局 `pdd.order-sync.incremental-job-enabled` 仍作总闸 |
|
||||
|
||||
开关默认 `false`(需前端显式打开);落在 `ec_shop.order_inc_sync_enabled`。
|
||||
开关默认 `false`。
|
||||
|
||||
API 建议:
|
||||
### 3.4 API
|
||||
|
||||
- `POST /api/channel/pdd/order/sync/full-task` — 创建全量任务
|
||||
- `GET /api/channel/pdd/order/sync/full-task/{taskId}` — 查询进度
|
||||
- `GET /api/channel/pdd/order/sync/full-task/latest?shopId=` — 最新任务(进行中优先)
|
||||
- `POST /api/channel/pdd/order/sync/full-task/{taskId}/cancel` — 取消
|
||||
- `POST /api/channel/pdd/order/sync/full-task/{taskId}/resume` — 失败续跑
|
||||
- `POST /api/channel/pdd/order/sync/status/batch` — `{ shopIds }` 列表摘要(不塞进 shop/list)
|
||||
- `POST /api/channel/pdd/order/sync/incremental/toggle` — `{ shopId, enabled }`
|
||||
- `GET /api/channel/pdd/order/sync/incremental/status?shopId=` — 查询开关与游标
|
||||
- `GET /api/channel/pdd/order/sync/incremental/status?shopId=` — 开关、游标、health
|
||||
|
||||
不做:SSE;独立同步中心;convert/BI 管线看板;为 day/manual-inc 建进度任务表。
|
||||
|
||||
---
|
||||
|
||||
|
||||
+32
@@ -14,9 +14,11 @@ import top.xyquan.ecomdmbbackend.modules.channel.pdd.order.sync.model.dto.PddOrd
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.order.sync.model.dto.PddOrderIncrementalToggleDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.order.sync.model.dto.PddOrderRepairDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.order.sync.model.dto.PddOrderSyncDayDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.order.sync.model.dto.PddOrderSyncStatusBatchDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.order.sync.model.vo.PddOrderFullSyncTaskVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.order.sync.model.vo.PddOrderIncrementalStatusVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.order.sync.model.vo.PddOrderSyncResultVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.order.sync.model.vo.PddOrderSyncShopStatusVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.order.sync.service.PddOrderFullSyncTaskService;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.order.sync.service.PddOrderSyncContextResolver;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.order.sync.service.PddOrderSyncService;
|
||||
@@ -114,6 +116,14 @@ public class PddOrderSyncController {
|
||||
return ApiResponse.success("任务已入队", fullSyncTaskService.createTask(dto));
|
||||
}
|
||||
|
||||
@Operation(summary = "查询店铺最新全量同步任务", description = "进行中优先,否则最近一次;无任务返回 null")
|
||||
@GetMapping("/full-task/latest")
|
||||
@RequirePermission(value = "biz:pdd:order:sync", description = "拼多多订单同步", allowSuper = true)
|
||||
public ApiResponse<PddOrderFullSyncTaskVO> latestFullTask(
|
||||
@Parameter(description = "内部店铺 ID") @RequestParam Long shopId) {
|
||||
return ApiResponse.success(fullSyncTaskService.latestTask(shopId));
|
||||
}
|
||||
|
||||
@Operation(summary = "查询全量同步任务")
|
||||
@GetMapping("/full-task/{taskId}")
|
||||
@RequirePermission(value = "biz:pdd:order:sync", description = "拼多多订单同步", allowSuper = true)
|
||||
@@ -121,6 +131,28 @@ public class PddOrderSyncController {
|
||||
return ApiResponse.success(fullSyncTaskService.getTask(taskId));
|
||||
}
|
||||
|
||||
@Operation(summary = "取消全量同步任务")
|
||||
@PostMapping("/full-task/{taskId}/cancel")
|
||||
@RequirePermission(value = "biz:pdd:order:sync", description = "拼多多订单同步", allowSuper = true)
|
||||
public ApiResponse<PddOrderFullSyncTaskVO> cancelFullTask(@PathVariable Long taskId) {
|
||||
return ApiResponse.success("已取消", fullSyncTaskService.cancelTask(taskId));
|
||||
}
|
||||
|
||||
@Operation(summary = "续跑失败的全量同步任务", description = "从失败日继续(按 doneDays 推进)")
|
||||
@PostMapping("/full-task/{taskId}/resume")
|
||||
@RequirePermission(value = "biz:pdd:order:sync", description = "拼多多订单同步", allowSuper = true)
|
||||
public ApiResponse<PddOrderFullSyncTaskVO> resumeFullTask(@PathVariable Long taskId) {
|
||||
return ApiResponse.success("已续跑入队", fullSyncTaskService.resumeTask(taskId));
|
||||
}
|
||||
|
||||
@Operation(summary = "批量查询店铺同步状态摘要", description = "列表用;每店返回最新全量任务摘要 + 增量完整态")
|
||||
@PostMapping("/status/batch")
|
||||
@RequirePermission(value = "biz:pdd:order:sync", description = "拼多多订单同步", allowSuper = true)
|
||||
public ApiResponse<List<PddOrderSyncShopStatusVO>> batchStatus(
|
||||
@Valid @RequestBody PddOrderSyncStatusBatchDTO dto) {
|
||||
return ApiResponse.success(fullSyncTaskService.batchStatus(dto.getShopIds()));
|
||||
}
|
||||
|
||||
@Operation(summary = "增量同步开关")
|
||||
@PostMapping("/incremental/toggle")
|
||||
@RequirePermission(value = "biz:pdd:order:sync", description = "拼多多订单同步", allowSuper = true)
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.order.sync.model.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class PddOrderSyncStatusBatchDTO {
|
||||
|
||||
@NotEmpty(message = "shopIds 不能为空")
|
||||
private List<Long> shopIds;
|
||||
}
|
||||
+12
@@ -1,14 +1,26 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.order.sync.model.vo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class PddOrderIncrementalStatusVO {
|
||||
|
||||
private Long shopId;
|
||||
private Boolean enabled;
|
||||
/** 1=正常 2=出错暂停 */
|
||||
private Integer cursorStatus;
|
||||
private String lastError;
|
||||
private LocalDateTime lastCursorAt;
|
||||
private LocalDateTime lastSuccessTime;
|
||||
private Integer overlapSeconds;
|
||||
/** OFF / OK / LAGGING / PAUSED */
|
||||
private String health;
|
||||
}
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.order.sync.model.vo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class PddOrderSyncShopStatusVO {
|
||||
|
||||
private Long shopId;
|
||||
/** 进行中优先,否则最近一次全量任务;无则为 null */
|
||||
private PddOrderFullSyncTaskVO fullTask;
|
||||
private PddOrderIncrementalStatusVO incremental;
|
||||
}
|
||||
+19
-4
@@ -39,16 +39,27 @@ public class PddOrderFullSyncTaskExecutor {
|
||||
if (task == null) {
|
||||
return;
|
||||
}
|
||||
if (PddOrderFullSyncTaskPO.STATUS_CANCELLED.equals(task.getStatus())
|
||||
|| PddOrderFullSyncTaskPO.STATUS_SUCCESS.equals(task.getStatus())) {
|
||||
return;
|
||||
}
|
||||
|
||||
task.setStatus(PddOrderFullSyncTaskPO.STATUS_RUNNING);
|
||||
task.setFinishTime(null);
|
||||
taskMapper.updateById(task);
|
||||
|
||||
LocalDate day = task.getDateFrom();
|
||||
if (task.getCurrentDate() != null && task.getDoneDays() != null && task.getDoneDays() > 0) {
|
||||
day = task.getCurrentDate().plusDays(1);
|
||||
}
|
||||
// 已成功天数之后的下一自然日(失败日未计入 doneDays,续跑会重试失败日)
|
||||
int done = task.getDoneDays() == null ? 0 : task.getDoneDays();
|
||||
LocalDate day = task.getDateFrom().plusDays(done);
|
||||
try {
|
||||
while (!day.isAfter(task.getDateTo())) {
|
||||
PddOrderFullSyncTaskPO latest = taskMapper.selectById(taskId);
|
||||
if (latest != null && PddOrderFullSyncTaskPO.STATUS_CANCELLED.equals(latest.getStatus())) {
|
||||
log.info("全量同步任务已取消,停止执行 taskId={}", taskId);
|
||||
return;
|
||||
}
|
||||
task.setCurrentDate(day);
|
||||
task.setStatus(PddOrderFullSyncTaskPO.STATUS_RUNNING);
|
||||
taskMapper.updateById(task);
|
||||
pddOrderSyncService.syncByConfirmDateForTask(
|
||||
task.getCompanyId(), task.getShopId(), day, task.getId());
|
||||
@@ -62,6 +73,10 @@ public class PddOrderFullSyncTaskExecutor {
|
||||
taskMapper.updateById(task);
|
||||
} catch (Exception e) {
|
||||
log.error("全量同步任务失败 taskId={}", taskId, e);
|
||||
PddOrderFullSyncTaskPO latest = taskMapper.selectById(taskId);
|
||||
if (latest != null && PddOrderFullSyncTaskPO.STATUS_CANCELLED.equals(latest.getStatus())) {
|
||||
return;
|
||||
}
|
||||
task.setFailedDays((task.getFailedDays() == null ? 0 : task.getFailedDays()) + 1);
|
||||
task.setStatus(PddOrderFullSyncTaskPO.STATUS_FAILED);
|
||||
task.setLastError(e.getMessage() != null && e.getMessage().length() > 500
|
||||
|
||||
+213
-14
@@ -17,23 +17,42 @@ import top.xyquan.ecomdmbbackend.modules.channel.pdd.order.sync.model.po.PddOrde
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.order.sync.model.po.PddOrderIncSyncPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.order.sync.model.vo.PddOrderFullSyncTaskVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.order.sync.model.vo.PddOrderIncrementalStatusVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.order.sync.model.vo.PddOrderSyncShopStatusVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.platform.model.enums.PlatformCode;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.mapper.ShopMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.model.po.ShopPO;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class PddOrderFullSyncTaskService {
|
||||
|
||||
public static final String HEALTH_OFF = "OFF";
|
||||
public static final String HEALTH_OK = "OK";
|
||||
public static final String HEALTH_LAGGING = "LAGGING";
|
||||
public static final String HEALTH_PAUSED = "PAUSED";
|
||||
|
||||
private static final int LAGGING_MINUTES = 15;
|
||||
|
||||
private final PddOrderFullSyncTaskMapper taskMapper;
|
||||
private final PddOrderIncSyncMapper incSyncMapper;
|
||||
private final ShopMapper shopMapper;
|
||||
private final PddOrderSyncContextResolver contextResolver;
|
||||
private final PddOrderSyncPublisher syncPublisher;
|
||||
private final PddOrderSyncProperties syncProperties;
|
||||
private final CurrentUserContext currentUserContext;
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public PddOrderFullSyncTaskVO createTask(PddOrderFullSyncTaskCreateDTO dto) {
|
||||
@@ -70,17 +89,100 @@ public class PddOrderFullSyncTaskService {
|
||||
}
|
||||
|
||||
public PddOrderFullSyncTaskVO getTask(Long taskId) {
|
||||
PddOrderFullSyncTaskPO task = taskMapper.selectById(taskId);
|
||||
if (task == null) {
|
||||
throw new BusinessException("全量同步任务不存在");
|
||||
}
|
||||
PddOrderSyncShopContext ctx = contextResolver.resolveForCurrentCompany(task.getShopId());
|
||||
if (!ctx.getCompanyId().equals(task.getCompanyId())) {
|
||||
throw new BusinessException("无权查看该任务");
|
||||
}
|
||||
PddOrderFullSyncTaskPO task = requireOwnedTask(taskId);
|
||||
return toVo(task);
|
||||
}
|
||||
|
||||
/** 进行中优先,否则该店最近一次全量任务。 */
|
||||
public PddOrderFullSyncTaskVO latestTask(Long shopId) {
|
||||
PddOrderSyncShopContext ctx = contextResolver.resolveForCurrentCompany(shopId);
|
||||
PddOrderFullSyncTaskPO task = findLatestTask(ctx.getCompanyId(), ctx.getShopId());
|
||||
return task == null ? null : toVo(task);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public PddOrderFullSyncTaskVO cancelTask(Long taskId) {
|
||||
PddOrderFullSyncTaskPO task = requireOwnedTask(taskId);
|
||||
String status = task.getStatus();
|
||||
if (PddOrderFullSyncTaskPO.STATUS_SUCCESS.equals(status)
|
||||
|| PddOrderFullSyncTaskPO.STATUS_CANCELLED.equals(status)) {
|
||||
throw new BusinessException("任务已结束,无法取消");
|
||||
}
|
||||
if (PddOrderFullSyncTaskPO.STATUS_FAILED.equals(status)) {
|
||||
throw new BusinessException("任务已失败,请使用续跑或新建任务");
|
||||
}
|
||||
task.setStatus(PddOrderFullSyncTaskPO.STATUS_CANCELLED);
|
||||
task.setFinishTime(LocalDateTime.now());
|
||||
task.setLastError(null);
|
||||
taskMapper.updateById(task);
|
||||
return toVo(task);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public PddOrderFullSyncTaskVO resumeTask(Long taskId) {
|
||||
PddOrderFullSyncTaskPO task = requireOwnedTask(taskId);
|
||||
if (!PddOrderFullSyncTaskPO.STATUS_FAILED.equals(task.getStatus())) {
|
||||
throw new BusinessException("仅失败任务可续跑");
|
||||
}
|
||||
Long running = taskMapper.selectCount(new LambdaQueryWrapper<PddOrderFullSyncTaskPO>()
|
||||
.eq(PddOrderFullSyncTaskPO::getShopId, task.getShopId())
|
||||
.in(PddOrderFullSyncTaskPO::getStatus,
|
||||
PddOrderFullSyncTaskPO.STATUS_PENDING, PddOrderFullSyncTaskPO.STATUS_RUNNING)
|
||||
.ne(PddOrderFullSyncTaskPO::getId, task.getId()));
|
||||
if (running != null && running > 0) {
|
||||
throw new BusinessException("该店铺已有进行中的全量同步任务");
|
||||
}
|
||||
task.setStatus(PddOrderFullSyncTaskPO.STATUS_PENDING);
|
||||
task.setLastError(null);
|
||||
task.setFinishTime(null);
|
||||
taskMapper.updateById(task);
|
||||
syncPublisher.publishFullTask(
|
||||
task.getId(), task.getCompanyId(), task.getShopId(),
|
||||
task.getDateFrom(), task.getDateTo());
|
||||
return toVo(task);
|
||||
}
|
||||
|
||||
public List<PddOrderSyncShopStatusVO> batchStatus(List<Long> shopIds) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
if (shopIds == null || shopIds.isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
List<Long> distinctIds = shopIds.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
if (distinctIds.isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
List<ShopPO> shops = shopMapper.selectList(new LambdaQueryWrapper<ShopPO>()
|
||||
.eq(ShopPO::getCompanyId, companyId)
|
||||
.in(ShopPO::getId, distinctIds));
|
||||
Set<Long> owned = shops.stream().map(ShopPO::getId).collect(Collectors.toCollection(HashSet::new));
|
||||
Map<Long, ShopPO> shopMap = shops.stream()
|
||||
.collect(Collectors.toMap(ShopPO::getId, s -> s, (a, b) -> a));
|
||||
|
||||
Map<Long, PddOrderFullSyncTaskPO> latestByShop = loadLatestTasksByShop(companyId, owned);
|
||||
Map<Long, PddOrderIncSyncPO> incByShop = loadIncStatesByShop(owned);
|
||||
|
||||
List<PddOrderSyncShopStatusVO> result = new ArrayList<>();
|
||||
for (Long shopId : distinctIds) {
|
||||
if (!owned.contains(shopId)) {
|
||||
continue;
|
||||
}
|
||||
ShopPO shop = shopMap.get(shopId);
|
||||
PddOrderFullSyncTaskPO full = latestByShop.get(shopId);
|
||||
PddOrderIncSyncPO inc = incByShop.get(shopId);
|
||||
boolean enabled = shop != null && Integer.valueOf(1).equals(shop.getOrderIncSyncEnabled());
|
||||
result.add(PddOrderSyncShopStatusVO.builder()
|
||||
.shopId(shopId)
|
||||
.fullTask(full == null ? null : toVo(full))
|
||||
.incremental(toIncVo(shopId, enabled, inc))
|
||||
.build());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public PddOrderIncrementalStatusVO toggleIncremental(PddOrderIncrementalToggleDTO dto) {
|
||||
PddOrderSyncShopContext ctx = contextResolver.resolveForCurrentCompany(dto.getShopId());
|
||||
@@ -106,12 +208,7 @@ public class PddOrderFullSyncTaskService {
|
||||
ShopPO shop = shopMapper.selectById(ctx.getShopId());
|
||||
PddOrderIncSyncPO state = findIncState(ctx.getShopId());
|
||||
boolean enabled = shop != null && Integer.valueOf(1).equals(shop.getOrderIncSyncEnabled());
|
||||
return PddOrderIncrementalStatusVO.builder()
|
||||
.shopId(shopId)
|
||||
.enabled(enabled)
|
||||
.cursorStatus(state != null ? state.getStatus() : null)
|
||||
.lastError(state != null ? state.getLastError() : null)
|
||||
.build();
|
||||
return toIncVo(shopId, enabled, state);
|
||||
}
|
||||
|
||||
public boolean isIncrementalEnabled(Long shopId) {
|
||||
@@ -124,6 +221,78 @@ public class PddOrderFullSyncTaskService {
|
||||
return state != null && Integer.valueOf(PddOrderIncSyncPO.STATUS_PAUSED).equals(state.getStatus());
|
||||
}
|
||||
|
||||
private PddOrderFullSyncTaskPO requireOwnedTask(Long taskId) {
|
||||
PddOrderFullSyncTaskPO task = taskMapper.selectById(taskId);
|
||||
if (task == null) {
|
||||
throw new BusinessException("全量同步任务不存在");
|
||||
}
|
||||
PddOrderSyncShopContext ctx = contextResolver.resolveForCurrentCompany(task.getShopId());
|
||||
if (!ctx.getCompanyId().equals(task.getCompanyId())) {
|
||||
throw new BusinessException("无权操作该任务");
|
||||
}
|
||||
return task;
|
||||
}
|
||||
|
||||
private PddOrderFullSyncTaskPO findLatestTask(Long companyId, Long shopId) {
|
||||
PddOrderFullSyncTaskPO active = taskMapper.selectOne(new LambdaQueryWrapper<PddOrderFullSyncTaskPO>()
|
||||
.eq(PddOrderFullSyncTaskPO::getCompanyId, companyId)
|
||||
.eq(PddOrderFullSyncTaskPO::getShopId, shopId)
|
||||
.in(PddOrderFullSyncTaskPO::getStatus,
|
||||
PddOrderFullSyncTaskPO.STATUS_PENDING, PddOrderFullSyncTaskPO.STATUS_RUNNING)
|
||||
.orderByDesc(PddOrderFullSyncTaskPO::getId)
|
||||
.last("LIMIT 1"));
|
||||
if (active != null) {
|
||||
return active;
|
||||
}
|
||||
return taskMapper.selectOne(new LambdaQueryWrapper<PddOrderFullSyncTaskPO>()
|
||||
.eq(PddOrderFullSyncTaskPO::getCompanyId, companyId)
|
||||
.eq(PddOrderFullSyncTaskPO::getShopId, shopId)
|
||||
.orderByDesc(PddOrderFullSyncTaskPO::getId)
|
||||
.last("LIMIT 1"));
|
||||
}
|
||||
|
||||
private Map<Long, PddOrderFullSyncTaskPO> loadLatestTasksByShop(Long companyId, Set<Long> shopIds) {
|
||||
Map<Long, PddOrderFullSyncTaskPO> map = new HashMap<>();
|
||||
if (shopIds.isEmpty()) {
|
||||
return map;
|
||||
}
|
||||
List<PddOrderFullSyncTaskPO> tasks = taskMapper.selectList(new LambdaQueryWrapper<PddOrderFullSyncTaskPO>()
|
||||
.eq(PddOrderFullSyncTaskPO::getCompanyId, companyId)
|
||||
.in(PddOrderFullSyncTaskPO::getShopId, shopIds)
|
||||
.orderByDesc(PddOrderFullSyncTaskPO::getId));
|
||||
for (PddOrderFullSyncTaskPO task : tasks) {
|
||||
PddOrderFullSyncTaskPO existing = map.get(task.getShopId());
|
||||
if (existing == null) {
|
||||
map.put(task.getShopId(), task);
|
||||
continue;
|
||||
}
|
||||
boolean existingActive = isActive(existing.getStatus());
|
||||
boolean taskActive = isActive(task.getStatus());
|
||||
if (!existingActive && taskActive) {
|
||||
map.put(task.getShopId(), task);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private static boolean isActive(String status) {
|
||||
return PddOrderFullSyncTaskPO.STATUS_PENDING.equals(status)
|
||||
|| PddOrderFullSyncTaskPO.STATUS_RUNNING.equals(status);
|
||||
}
|
||||
|
||||
private Map<Long, PddOrderIncSyncPO> loadIncStatesByShop(Set<Long> shopIds) {
|
||||
Map<Long, PddOrderIncSyncPO> map = new HashMap<>();
|
||||
if (shopIds.isEmpty()) {
|
||||
return map;
|
||||
}
|
||||
List<PddOrderIncSyncPO> states = incSyncMapper.selectList(new LambdaQueryWrapper<PddOrderIncSyncPO>()
|
||||
.in(PddOrderIncSyncPO::getShopId, shopIds));
|
||||
for (PddOrderIncSyncPO state : states) {
|
||||
map.putIfAbsent(state.getShopId(), state);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private PddOrderIncSyncPO findIncState(Long shopId) {
|
||||
return incSyncMapper.selectOne(new LambdaQueryWrapper<PddOrderIncSyncPO>()
|
||||
.eq(PddOrderIncSyncPO::getShopId, shopId)
|
||||
@@ -145,6 +314,36 @@ public class PddOrderFullSyncTaskService {
|
||||
return state;
|
||||
}
|
||||
|
||||
private static PddOrderIncrementalStatusVO toIncVo(Long shopId, boolean enabled, PddOrderIncSyncPO state) {
|
||||
return PddOrderIncrementalStatusVO.builder()
|
||||
.shopId(shopId)
|
||||
.enabled(enabled)
|
||||
.cursorStatus(state != null ? state.getStatus() : null)
|
||||
.lastError(state != null ? state.getLastError() : null)
|
||||
.lastCursorAt(state != null ? state.getLastCursorAt() : null)
|
||||
.lastSuccessTime(state != null ? state.getLastSuccessTime() : null)
|
||||
.overlapSeconds(state != null ? state.getOverlapSeconds() : null)
|
||||
.health(resolveHealth(enabled, state))
|
||||
.build();
|
||||
}
|
||||
|
||||
static String resolveHealth(boolean enabled, PddOrderIncSyncPO state) {
|
||||
if (!enabled) {
|
||||
return HEALTH_OFF;
|
||||
}
|
||||
if (state != null && Integer.valueOf(PddOrderIncSyncPO.STATUS_PAUSED).equals(state.getStatus())) {
|
||||
return HEALTH_PAUSED;
|
||||
}
|
||||
LocalDateTime anchor = null;
|
||||
if (state != null) {
|
||||
anchor = state.getLastSuccessTime() != null ? state.getLastSuccessTime() : state.getLastCursorAt();
|
||||
}
|
||||
if (anchor != null && anchor.isBefore(LocalDateTime.now().minusMinutes(LAGGING_MINUTES))) {
|
||||
return HEALTH_LAGGING;
|
||||
}
|
||||
return HEALTH_OK;
|
||||
}
|
||||
|
||||
private static PddOrderFullSyncTaskVO toVo(PddOrderFullSyncTaskPO task) {
|
||||
return PddOrderFullSyncTaskVO.builder()
|
||||
.id(task.getId())
|
||||
|
||||
+1
-24
@@ -12,17 +12,12 @@ import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.model.dto.CreateShopDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.model.dto.ShopDetailQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.model.dto.ShopFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.model.dto.ShopProductPageFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.model.dto.UpdateShopDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.overview.model.dto.ShopOverviewQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.vo.ProductVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.model.vo.ShopDashboardVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.overview.model.vo.ShopOverviewStatisticsVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.model.vo.ShopVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.service.ShopService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.overview.service.ShopOverviewStatisticsService;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.file.model.vo.SysFileUploadVO;
|
||||
import top.xyquan.ecomdmbbackend.utils.FileUploadUtils;
|
||||
|
||||
@@ -35,11 +30,9 @@ import top.xyquan.ecomdmbbackend.utils.FileUploadUtils;
|
||||
public class ShopController {
|
||||
|
||||
private final ShopService shopService;
|
||||
private final ShopOverviewStatisticsService shopOverviewStatisticsService;
|
||||
|
||||
public ShopController(ShopService shopService, ShopOverviewStatisticsService shopOverviewStatisticsService) {
|
||||
public ShopController(ShopService shopService) {
|
||||
this.shopService = shopService;
|
||||
this.shopOverviewStatisticsService = shopOverviewStatisticsService;
|
||||
}
|
||||
|
||||
@Operation(summary = "创建店铺", description = "创建新的店铺")
|
||||
@@ -98,20 +91,4 @@ public class ShopController {
|
||||
PageResultVO<ProductVO> result = shopService.getShopProductPage(pageQueryDTO);
|
||||
return ApiResponse.success("获取店铺商品列表成功", result);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取店铺概览统计数据", description = "获取指定店铺的概览统计数据,包括销售额、单量、推广费、利润、ROI等,以及多商品数据横向汇总")
|
||||
@PostMapping("/overview")
|
||||
@RequirePermission(value = "ecom:shop:read", description = "查询店铺概览统计", allowSuper = true)
|
||||
public ApiResponse<ShopOverviewStatisticsVO> getShopOverviewStatistics(@Valid @RequestBody ShopOverviewQueryDTO queryDTO) {
|
||||
ShopOverviewStatisticsVO overviewVO = shopOverviewStatisticsService.getShopOverviewStatistics(queryDTO);
|
||||
return ApiResponse.success("获取店铺概览统计成功", overviewVO);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取店铺详情页看板数据", description = "获取店铺详情页的月度目标、推广费、刷单费、店铺订单等看板数据")
|
||||
@PostMapping("/details")
|
||||
@RequirePermission(value = "ecom:shop:read", description = "查询店铺详情", allowSuper = true)
|
||||
public ApiResponse<ShopDashboardVO> getShopDetails(@Valid @RequestBody ShopDetailQueryDTO queryDTO) {
|
||||
ShopDashboardVO dashboard = shopService.getShopDashboard(queryDTO);
|
||||
return ApiResponse.success("获取店铺详情看板数据成功", dashboard);
|
||||
}
|
||||
}
|
||||
|
||||
-35
@@ -1,35 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.shop.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* 店铺详情查询DTO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "店铺详情查询DTO")
|
||||
public class ShopDetailQueryDTO {
|
||||
|
||||
/**
|
||||
* 店铺ID
|
||||
*/
|
||||
@Schema(description = "店铺ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "店铺ID不能为空")
|
||||
private Long shopId;
|
||||
|
||||
/**
|
||||
* 开始日期(不传默认为当月1号)
|
||||
*/
|
||||
@Schema(description = "开始日期(不传默认为当月1号)", example = "2024-01-01")
|
||||
private LocalDate startDate;
|
||||
|
||||
/**
|
||||
* 结束日期(不传默认为今天)
|
||||
*/
|
||||
@Schema(description = "结束日期(不传默认为今天)", example = "2024-01-31")
|
||||
private LocalDate endDate;
|
||||
}
|
||||
|
||||
-133
@@ -1,133 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.shop.model.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 店铺详情页看板VO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "店铺详情页看板VO")
|
||||
public class ShopDashboardVO {
|
||||
|
||||
/**
|
||||
* 店铺基本信息
|
||||
*/
|
||||
@Schema(description = "店铺基本信息")
|
||||
private ShopInfo shopInfo;
|
||||
|
||||
/**
|
||||
* 月度目标看板数据
|
||||
*/
|
||||
@Schema(description = "月度目标看板数据")
|
||||
private MonthlyTargetKpi monthlyTarget;
|
||||
|
||||
/**
|
||||
* 推广费看板数据
|
||||
*/
|
||||
@Schema(description = "推广费看板数据")
|
||||
private PromotionFeeKpi promotionFee;
|
||||
|
||||
/**
|
||||
* 刷单费看板数据
|
||||
*/
|
||||
@Schema(description = "刷单费看板数据")
|
||||
private BrushOrderKpi brushOrder;
|
||||
|
||||
/**
|
||||
* 店铺订单看板数据
|
||||
*/
|
||||
@Schema(description = "店铺订单看板数据")
|
||||
private ShopOrderKpi shopOrder;
|
||||
|
||||
/**
|
||||
* 店铺基本信息
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "店铺基本信息")
|
||||
public static class ShopInfo {
|
||||
@Schema(description = "店铺ID")
|
||||
private Long id;
|
||||
@Schema(description = "店铺名称")
|
||||
private String name;
|
||||
@Schema(description = "logo URL")
|
||||
private String logo;
|
||||
@Schema(description = "平台名称")
|
||||
private String platformName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 月度目标KPI
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "月度目标KPI")
|
||||
public static class MonthlyTargetKpi {
|
||||
/** 年度目标总额 */
|
||||
@Schema(description = "年度目标总额")
|
||||
private java.math.BigDecimal totalTargetAmount;
|
||||
/** 目标单量合计 */
|
||||
@Schema(description = "目标单量合计")
|
||||
private Integer totalOrderCount;
|
||||
/** 本月目标销售额 */
|
||||
@Schema(description = "本月目标销售额")
|
||||
private java.math.BigDecimal thisMonthTargetAmount;
|
||||
/** 本月目标单量 */
|
||||
@Schema(description = "本月目标单量")
|
||||
private Integer thisMonthTargetOrderCount;
|
||||
/** 当前达成率 */
|
||||
@Schema(description = "当前达成率(百分比)")
|
||||
private java.math.BigDecimal achievementRate;
|
||||
}
|
||||
|
||||
/**
|
||||
* 推广费KPI
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "推广费KPI")
|
||||
public static class PromotionFeeKpi {
|
||||
/** 累计推广费 */
|
||||
@Schema(description = "累计推广费")
|
||||
private java.math.BigDecimal totalFeeAmount;
|
||||
/** 本月推广费 */
|
||||
@Schema(description = "本月推广费")
|
||||
private java.math.BigDecimal thisMonthFee;
|
||||
/** 日均推广费 */
|
||||
@Schema(description = "日均推广费")
|
||||
private java.math.BigDecimal avgDailyFee;
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷单费KPI
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "刷单费KPI")
|
||||
public static class BrushOrderKpi {
|
||||
/** 累计刷单费 */
|
||||
@Schema(description = "累计刷单费")
|
||||
private java.math.BigDecimal totalBrushAmount;
|
||||
/** 本月刷单次数 */
|
||||
@Schema(description = "本月刷单次数")
|
||||
private Integer thisMonthCount;
|
||||
/** 平均刷单金额 */
|
||||
@Schema(description = "平均刷单金额")
|
||||
private java.math.BigDecimal avgAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* 店铺订单KPI
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "店铺订单KPI")
|
||||
public static class ShopOrderKpi {
|
||||
/** 累计实收金额 */
|
||||
@Schema(description = "累计实收金额")
|
||||
private java.math.BigDecimal totalReceivedAmount;
|
||||
/** 累计佣金 */
|
||||
@Schema(description = "累计佣金")
|
||||
private java.math.BigDecimal totalCommission;
|
||||
/** 累计订单数 */
|
||||
@Schema(description = "累计订单数")
|
||||
private Integer totalOrderCount;
|
||||
}
|
||||
}
|
||||
-10
@@ -5,13 +5,11 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.model.dto.CreateShopDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.model.dto.ShopDetailQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.model.dto.ShopFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.model.dto.ShopProductPageFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.model.dto.UpdateShopDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.model.po.ShopPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.vo.ProductVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.model.vo.ShopDashboardVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.model.vo.ShopVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.file.model.vo.SysFileUploadVO;
|
||||
|
||||
@@ -67,12 +65,4 @@ public interface ShopService extends IService<ShopPO> {
|
||||
* @return 分页结果
|
||||
*/
|
||||
PageResultVO<ProductVO> getShopProductPage(PageQueryDTO<ShopProductPageFilterDTO> pageQueryDTO);
|
||||
|
||||
/**
|
||||
* 获取店铺详情页看板数据
|
||||
*
|
||||
* @param queryDTO 查询DTO
|
||||
* @return 看板VO
|
||||
*/
|
||||
ShopDashboardVO getShopDashboard(ShopDetailQueryDTO queryDTO);
|
||||
}
|
||||
|
||||
+1
-199
@@ -13,30 +13,20 @@ import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.shop.mapper.PddShopMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.shop.model.po.PddShopPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.shop.model.vo.PddShopVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.brushorder.mapper.BrushOrderMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.brushorder.model.po.BrushOrderPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.order.mapper.OrderMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.mapper.ProductMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.mapper.PromotionFeeMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.platform.model.enums.PlatformCode;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.mapper.ShopMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.mapper.ShopProductRelationMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.monthlytarget.mapper.ShopMonthlyTargetMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.monthlytarget.model.po.ShopMonthlyTargetPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.model.dto.CreateShopDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.model.dto.ShopDetailQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.model.dto.ShopFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.model.dto.ShopProductPageFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.model.dto.UpdateShopDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.order.model.po.OrderPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.po.ProductPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.po.ProductSkuPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.model.po.PromotionFeePO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.model.po.ShopPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.model.po.ShopProductRelationPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.vo.ProductSkuVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.vo.ProductVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.model.vo.ShopDashboardVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.model.vo.ShopVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.service.ProductSkuService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.service.ShopService;
|
||||
@@ -45,10 +35,6 @@ import top.xyquan.ecomdmbbackend.modules.sys.file.service.SysFileService;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -66,31 +52,21 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
|
||||
|
||||
private final CurrentUserContext currentUserContext;
|
||||
private final SysFileService sysFileService;
|
||||
private final OrderMapper orderMapper;
|
||||
private final PromotionFeeMapper promotionFeeMapper;
|
||||
private final ProductMapper productMapper;
|
||||
private final ShopProductRelationMapper shopProductRelationMapper;
|
||||
private final ProductSkuService productSkuService;
|
||||
private final PddShopMapper pddShopMapper;
|
||||
private final BrushOrderMapper brushOrderMapper;
|
||||
private final ShopMonthlyTargetMapper shopMonthlyTargetMapper;
|
||||
|
||||
public ShopServiceImpl(CurrentUserContext currentUserContext, SysFileService sysFileService,
|
||||
OrderMapper orderMapper, PromotionFeeMapper promotionFeeMapper,
|
||||
ProductMapper productMapper,
|
||||
ShopProductRelationMapper shopProductRelationMapper, ProductSkuService productSkuService,
|
||||
PddShopMapper pddShopMapper,
|
||||
BrushOrderMapper brushOrderMapper, ShopMonthlyTargetMapper shopMonthlyTargetMapper) {
|
||||
PddShopMapper pddShopMapper) {
|
||||
this.currentUserContext = currentUserContext;
|
||||
this.sysFileService = sysFileService;
|
||||
this.orderMapper = orderMapper;
|
||||
this.promotionFeeMapper = promotionFeeMapper;
|
||||
this.productMapper = productMapper;
|
||||
this.shopProductRelationMapper = shopProductRelationMapper;
|
||||
this.productSkuService = productSkuService;
|
||||
this.pddShopMapper = pddShopMapper;
|
||||
this.brushOrderMapper = brushOrderMapper;
|
||||
this.shopMonthlyTargetMapper = shopMonthlyTargetMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -432,178 +408,4 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
|
||||
private ProductSkuVO convertSkuToVO(ProductSkuPO productSku) {
|
||||
return productSkuService.toVo(productSku);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShopDashboardVO getShopDashboard(ShopDetailQueryDTO queryDTO) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
Long shopId = queryDTO.getShopId();
|
||||
|
||||
// 验证店铺
|
||||
ShopPO shop = this.getById(shopId);
|
||||
if (shop == null || !shop.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("店铺不存在");
|
||||
}
|
||||
|
||||
// 日期范围(默认当月)
|
||||
LocalDate startDate = queryDTO.getStartDate() != null ? queryDTO.getStartDate() : LocalDate.now().withDayOfMonth(1);
|
||||
LocalDate endDate = queryDTO.getEndDate() != null ? queryDTO.getEndDate() : LocalDate.now();
|
||||
LocalDateTime startDateTime = startDate.atStartOfDay();
|
||||
LocalDateTime endDateTime = endDate.atTime(23, 59, 59);
|
||||
|
||||
ShopDashboardVO dashboard = new ShopDashboardVO();
|
||||
|
||||
// 设置店铺基本信息
|
||||
ShopDashboardVO.ShopInfo shopInfo = new ShopDashboardVO.ShopInfo();
|
||||
shopInfo.setId(shop.getId());
|
||||
shopInfo.setName(shop.getName());
|
||||
shopInfo.setLogo(null); // logoImageId 冗余字段,前端按需使用
|
||||
if (shop.getPlatformCode() != null && !shop.getPlatformCode().isBlank()) {
|
||||
shopInfo.setPlatformName(PlatformCode.labelOf(shop.getPlatformCode()));
|
||||
}
|
||||
dashboard.setShopInfo(shopInfo);
|
||||
|
||||
// 1. 月度目标
|
||||
dashboard.setMonthlyTarget(buildMonthlyTargetKpi(companyId, shopId, shop, startDate, endDate));
|
||||
|
||||
// 2. 推广费
|
||||
dashboard.setPromotionFee(buildPromotionFeeKpi(companyId, shopId, shop, startDate, endDate));
|
||||
|
||||
// 3. 刷单费
|
||||
dashboard.setBrushOrder(buildBrushOrderKpi(companyId, shopId, shop, startDate, endDate));
|
||||
|
||||
// 4. 店铺订单
|
||||
dashboard.setShopOrder(buildShopOrderKpi(companyId, shopId, shop, startDateTime, endDateTime));
|
||||
|
||||
return dashboard;
|
||||
}
|
||||
|
||||
private ShopDashboardVO.MonthlyTargetKpi buildMonthlyTargetKpi(Long companyId, Long shopId, ShopPO shop, LocalDate startDate, LocalDate endDate) {
|
||||
ShopDashboardVO.MonthlyTargetKpi kpi = new ShopDashboardVO.MonthlyTargetKpi();
|
||||
|
||||
// 查询所有目标记录(不限日期,取所有)
|
||||
LambdaQueryWrapper<ShopMonthlyTargetPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(ShopMonthlyTargetPO::getCompanyId, companyId)
|
||||
.eq(ShopMonthlyTargetPO::getShopId, shopId)
|
||||
.orderByDesc(ShopMonthlyTargetPO::getTargetMonth);
|
||||
List<ShopMonthlyTargetPO> allTargets = shopMonthlyTargetMapper.selectList(wrapper);
|
||||
|
||||
// 年度总额 & 目标单量合计
|
||||
BigDecimal totalTargetAmount = allTargets.stream()
|
||||
.map(ShopMonthlyTargetPO::getTargetAmount)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
int totalOrderCount = allTargets.stream()
|
||||
.mapToInt(t -> t.getTargetOrderCount() != null ? t.getTargetOrderCount() : 0)
|
||||
.sum();
|
||||
|
||||
// 本月目标
|
||||
String thisMonth = startDate.withDayOfMonth(1).toString().substring(0, 7);
|
||||
ShopMonthlyTargetPO thisMonthTarget = allTargets.stream()
|
||||
.filter(t -> t.getTargetMonth() != null && t.getTargetMonth().toString().startsWith(thisMonth))
|
||||
.findFirst().orElse(null);
|
||||
|
||||
kpi.setTotalTargetAmount(totalTargetAmount);
|
||||
kpi.setTotalOrderCount(totalOrderCount);
|
||||
kpi.setThisMonthTargetAmount(thisMonthTarget != null ? thisMonthTarget.getTargetAmount() : BigDecimal.ZERO);
|
||||
kpi.setThisMonthTargetOrderCount(thisMonthTarget != null ? thisMonthTarget.getTargetOrderCount() : 0);
|
||||
|
||||
// 达成率 = 实际销售额 / 目标销售额(简化:查时间段内订单实收 / 目标)
|
||||
LambdaQueryWrapper<OrderPO> orderWrapper = new LambdaQueryWrapper<>();
|
||||
orderWrapper.eq(OrderPO::getCompanyId, companyId)
|
||||
.eq(OrderPO::getShopId, shopId)
|
||||
.ge(OrderPO::getOrderTime, startDate.atStartOfDay())
|
||||
.le(OrderPO::getOrderTime, endDate.atTime(23, 59, 59));
|
||||
List<OrderPO> periodOrders = orderMapper.selectList(orderWrapper);
|
||||
BigDecimal actualSales = periodOrders.stream()
|
||||
.map(o -> o.getPayAmount() != null ? o.getPayAmount() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
BigDecimal achievementRate = BigDecimal.ZERO;
|
||||
if (thisMonthTarget != null && thisMonthTarget.getTargetAmount() != null
|
||||
&& thisMonthTarget.getTargetAmount().compareTo(BigDecimal.ZERO) > 0) {
|
||||
achievementRate = actualSales.divide(thisMonthTarget.getTargetAmount(), 4, RoundingMode.HALF_UP)
|
||||
.multiply(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP);
|
||||
}
|
||||
kpi.setAchievementRate(achievementRate);
|
||||
|
||||
|
||||
return kpi;
|
||||
}
|
||||
|
||||
private ShopDashboardVO.PromotionFeeKpi buildPromotionFeeKpi(Long companyId, Long shopId, ShopPO shop, LocalDate startDate, LocalDate endDate) {
|
||||
ShopDashboardVO.PromotionFeeKpi kpi = new ShopDashboardVO.PromotionFeeKpi();
|
||||
|
||||
LambdaQueryWrapper<PromotionFeePO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(PromotionFeePO::getCompanyId, companyId)
|
||||
.eq(PromotionFeePO::getShopId, shopId)
|
||||
.ge(PromotionFeePO::getFeeDate, startDate)
|
||||
.le(PromotionFeePO::getFeeDate, endDate)
|
||||
.orderByDesc(PromotionFeePO::getFeeDate);
|
||||
List<PromotionFeePO> allFees = promotionFeeMapper.selectList(wrapper);
|
||||
|
||||
BigDecimal totalFeeAmount = allFees.stream()
|
||||
.map(f -> f.getFeeAmount() != null ? f.getFeeAmount() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
// 本月推广费
|
||||
String thisMonthStr = startDate.withDayOfMonth(1).toString().substring(0, 7);
|
||||
BigDecimal thisMonthFee = allFees.stream()
|
||||
.filter(f -> f.getFeeDate() != null && f.getFeeDate().toString().startsWith(thisMonthStr))
|
||||
.map(f -> f.getFeeAmount() != null ? f.getFeeAmount() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
// 日均
|
||||
long days = java.time.temporal.ChronoUnit.DAYS.between(startDate, endDate) + 1;
|
||||
BigDecimal avgDailyFee = days > 0 ? totalFeeAmount.divide(BigDecimal.valueOf(days), 2, RoundingMode.HALF_UP) : BigDecimal.ZERO;
|
||||
|
||||
kpi.setTotalFeeAmount(totalFeeAmount);
|
||||
kpi.setThisMonthFee(thisMonthFee);
|
||||
kpi.setAvgDailyFee(avgDailyFee);
|
||||
return kpi;
|
||||
}
|
||||
|
||||
private ShopDashboardVO.BrushOrderKpi buildBrushOrderKpi(Long companyId, Long shopId, ShopPO shop, LocalDate startDate, LocalDate endDate) {
|
||||
ShopDashboardVO.BrushOrderKpi kpi = new ShopDashboardVO.BrushOrderKpi();
|
||||
|
||||
LambdaQueryWrapper<BrushOrderPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(BrushOrderPO::getCompanyId, companyId)
|
||||
.eq(BrushOrderPO::getShopId, shopId)
|
||||
.ge(BrushOrderPO::getBrushTime, startDate.atStartOfDay())
|
||||
.le(BrushOrderPO::getBrushTime, endDate.atTime(23, 59, 59))
|
||||
.orderByDesc(BrushOrderPO::getBrushTime);
|
||||
List<BrushOrderPO> allBrush = brushOrderMapper.selectList(wrapper);
|
||||
|
||||
BigDecimal totalBrushAmount = allBrush.stream()
|
||||
.map(b -> b.getBrushAmount() != null ? b.getBrushAmount() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
long thisMonthCount = allBrush.stream()
|
||||
.filter(b -> b.getBrushTime() != null && b.getBrushTime().toLocalDate().getMonth().equals(startDate.getMonth()))
|
||||
.count();
|
||||
long brushCount = allBrush.size();
|
||||
BigDecimal avgAmount = brushCount > 0 ? totalBrushAmount.divide(BigDecimal.valueOf(brushCount), 2, RoundingMode.HALF_UP) : BigDecimal.ZERO;
|
||||
|
||||
kpi.setTotalBrushAmount(totalBrushAmount);
|
||||
kpi.setThisMonthCount((int) thisMonthCount);
|
||||
kpi.setAvgAmount(avgAmount);
|
||||
return kpi;
|
||||
}
|
||||
|
||||
private ShopDashboardVO.ShopOrderKpi buildShopOrderKpi(Long companyId, Long shopId, ShopPO shop, LocalDateTime startDateTime, LocalDateTime endDateTime) {
|
||||
ShopDashboardVO.ShopOrderKpi kpi = new ShopDashboardVO.ShopOrderKpi();
|
||||
|
||||
LambdaQueryWrapper<OrderPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(OrderPO::getCompanyId, companyId)
|
||||
.eq(OrderPO::getShopId, shopId)
|
||||
.ge(OrderPO::getOrderTime, startDateTime)
|
||||
.le(OrderPO::getOrderTime, endDateTime)
|
||||
.orderByDesc(OrderPO::getOrderTime);
|
||||
List<OrderPO> allOrders = orderMapper.selectList(wrapper);
|
||||
|
||||
BigDecimal totalReceived = allOrders.stream()
|
||||
.map(o -> o.getPayAmount() != null ? o.getPayAmount() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
kpi.setTotalReceivedAmount(totalReceived);
|
||||
kpi.setTotalCommission(BigDecimal.ZERO); // 订单表暂无佣金字段
|
||||
kpi.setTotalOrderCount(allOrders.size());
|
||||
return kpi;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,44 @@ export async function getPddFullSyncTaskApi(taskId: number) {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询店铺最新全量同步任务(进行中优先)
|
||||
*/
|
||||
export async function getPddLatestFullSyncTaskApi(shopId: number) {
|
||||
return requestClient.get<null | PddOrderSyncVO.FullTask>(
|
||||
'/channel/pdd/order/sync/full-task/latest',
|
||||
{ params: { shopId } },
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消全量同步任务
|
||||
*/
|
||||
export async function cancelPddFullSyncTaskApi(taskId: number) {
|
||||
return requestClient.post<PddOrderSyncVO.FullTask>(
|
||||
`/channel/pdd/order/sync/full-task/${taskId}/cancel`,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 续跑失败的全量同步任务
|
||||
*/
|
||||
export async function resumePddFullSyncTaskApi(taskId: number) {
|
||||
return requestClient.post<PddOrderSyncVO.FullTask>(
|
||||
`/channel/pdd/order/sync/full-task/${taskId}/resume`,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量查询店铺同步状态摘要
|
||||
*/
|
||||
export async function batchPddOrderSyncStatusApi(shopIds: number[]) {
|
||||
return requestClient.post<PddOrderSyncVO.ShopStatus[]>(
|
||||
'/channel/pdd/order/sync/status/batch',
|
||||
{ shopIds },
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 增量同步开关
|
||||
*/
|
||||
|
||||
@@ -26,10 +26,23 @@ export namespace PddOrderSyncVO {
|
||||
finishTime?: string;
|
||||
}
|
||||
|
||||
/** OFF / OK / LAGGING / PAUSED */
|
||||
export type IncHealth = 'OFF' | 'OK' | 'LAGGING' | 'PAUSED';
|
||||
|
||||
export interface IncrementalStatus {
|
||||
shopId: number;
|
||||
enabled: boolean;
|
||||
cursorStatus?: number;
|
||||
lastError?: string;
|
||||
lastCursorAt?: string;
|
||||
lastSuccessTime?: string;
|
||||
overlapSeconds?: number;
|
||||
health?: IncHealth;
|
||||
}
|
||||
|
||||
export interface ShopStatus {
|
||||
shopId: number;
|
||||
fullTask?: null | FullTask;
|
||||
incremental?: IncrementalStatus;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,18 +62,6 @@ export async function getShopProductPageApi(
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取店铺概览统计数据
|
||||
*/
|
||||
export async function getShopOverviewStatisticsApi(
|
||||
params: ShopDTO.OverviewQuery,
|
||||
) {
|
||||
return requestClient.post<ShopVO.OverviewStatistics>(
|
||||
'/ec/shop/overview',
|
||||
params,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 店铺数据统计-按商品汇总(Excel)
|
||||
*/
|
||||
@@ -99,10 +87,3 @@ export async function exportCompanyOverviewApi(params: {
|
||||
responseType: 'blob',
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取店铺详情看板数据
|
||||
*/
|
||||
export async function getShopDetailsApi(params: ShopDTO.DetailQuery) {
|
||||
return requestClient.post<ShopVO.Dashboard>('/ec/shop/details', params);
|
||||
}
|
||||
|
||||
@@ -36,24 +36,4 @@ export namespace ShopDTO {
|
||||
/** 店铺ID */
|
||||
shopId: number;
|
||||
}
|
||||
|
||||
/** 店铺概览查询参数 */
|
||||
export interface OverviewQuery {
|
||||
/** 店铺ID */
|
||||
shopId: number;
|
||||
/** 日期范围数组(第一个是开始日期,第二个是结束日期,只有一个日期则返回当天数据) */
|
||||
dateRange: string[];
|
||||
/** 税率(默认0.04,即4%) */
|
||||
taxRate?: number;
|
||||
}
|
||||
|
||||
/** 店铺详情看板查询参数 */
|
||||
export interface DetailQuery {
|
||||
/** 店铺ID */
|
||||
shopId: number;
|
||||
/** 开始日期(不传默认为当月1号) */
|
||||
startDate?: string;
|
||||
/** 结束日期(不传默认为今天) */
|
||||
endDate?: string;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,72 +253,4 @@ export namespace ShopVO {
|
||||
/** 各品类汇总列表 */
|
||||
categories: CategorySummary[];
|
||||
}
|
||||
|
||||
// ========== 店铺详情看板 ==========
|
||||
|
||||
/** 店铺基本信息 */
|
||||
export interface ShopInfo {
|
||||
id: number;
|
||||
name: string;
|
||||
logo?: string;
|
||||
platformName?: string;
|
||||
}
|
||||
|
||||
/** 月度目标KPI */
|
||||
export interface MonthlyTargetKpi {
|
||||
/** 年度目标总额 */
|
||||
totalTargetAmount: number;
|
||||
/** 目标单量合计 */
|
||||
totalOrderCount: number;
|
||||
/** 本月目标销售额 */
|
||||
thisMonthTargetAmount: number;
|
||||
/** 本月目标单量 */
|
||||
thisMonthTargetOrderCount: number;
|
||||
/** 当前达成率(百分比) */
|
||||
achievementRate: number;
|
||||
}
|
||||
|
||||
/** 推广费KPI */
|
||||
export interface PromotionFeeKpi {
|
||||
/** 累计推广费 */
|
||||
totalFeeAmount: number;
|
||||
/** 本月推广费 */
|
||||
thisMonthFee: number;
|
||||
/** 日均推广费 */
|
||||
avgDailyFee: number;
|
||||
}
|
||||
|
||||
/** 刷单费KPI */
|
||||
export interface BrushOrderKpi {
|
||||
/** 累计刷单费 */
|
||||
totalBrushAmount: number;
|
||||
/** 本月刷单次数 */
|
||||
thisMonthCount: number;
|
||||
/** 平均刷单金额 */
|
||||
avgAmount: number;
|
||||
}
|
||||
|
||||
/** 店铺订单KPI */
|
||||
export interface ShopOrderKpi {
|
||||
/** 累计实收金额 */
|
||||
totalReceivedAmount: number;
|
||||
/** 累计佣金 */
|
||||
totalCommission: number;
|
||||
/** 累计订单数 */
|
||||
totalOrderCount: number;
|
||||
}
|
||||
|
||||
/** 店铺详情看板数据 */
|
||||
export interface Dashboard {
|
||||
/** 店铺基本信息 */
|
||||
shopInfo: ShopInfo;
|
||||
/** 月度目标看板数据 */
|
||||
monthlyTarget: MonthlyTargetKpi;
|
||||
/** 推广费看板数据 */
|
||||
promotionFee: PromotionFeeKpi;
|
||||
/** 刷单费看板数据 */
|
||||
brushOrder: BrushOrderKpi;
|
||||
/** 店铺订单看板数据 */
|
||||
shopOrder: ShopOrderKpi;
|
||||
}
|
||||
}
|
||||
|
||||
-174
@@ -1,174 +0,0 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import type { BrushOrderDTO, BrushOrderVO } from '#/api/ecommerce/brush-order';
|
||||
import type { ShopVO } from '#/api/ecommerce/shop/types';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
import { Button, DatePicker, Popconfirm, Space } from 'ant-design-vue';
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
deleteBrushOrderApi,
|
||||
getBrushOrderPageApi,
|
||||
} from '#/api/ecommerce/brush-order';
|
||||
|
||||
import BrushOrderFormModal from '#/views/ecommerce/brush-order/components/BrushOrderFormModal.vue';
|
||||
|
||||
defineOptions({ name: 'BrushOrderCard' });
|
||||
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
const RepeatIcon = createIconifyIcon('lucide:repeat');
|
||||
|
||||
const props = defineProps<{
|
||||
shopId: number;
|
||||
data?: ShopVO.BrushOrderKpi;
|
||||
}>();
|
||||
|
||||
const kpi = computed(() => props.data);
|
||||
const gridReloadRef = ref<(() => void) | null>(null);
|
||||
|
||||
const searchForm = ref({
|
||||
startBrushTime: undefined as string | undefined,
|
||||
endBrushTime: undefined as string | undefined,
|
||||
});
|
||||
|
||||
const modalVisible = ref(false);
|
||||
const editingData = ref<BrushOrderVO.Info | undefined>();
|
||||
|
||||
const gridOptions: VxeGridProps<any> = {
|
||||
columns: [
|
||||
{ type: 'seq', title: '序号', width: 60 },
|
||||
{ field: 'productName', title: '商品名称', minWidth: 160 },
|
||||
{ field: 'productSkuName', title: 'SKU 名称', minWidth: 160 },
|
||||
{
|
||||
field: 'brushAmount', title: '刷单金额', width: 120,
|
||||
formatter: ({ cellValue }) => `¥${Number(cellValue || 0).toLocaleString()}`,
|
||||
},
|
||||
{ field: 'brushTime', title: '刷单时间', minWidth: 160 },
|
||||
{ field: 'remark', title: '备注', minWidth: 120 },
|
||||
{
|
||||
title: '操作',
|
||||
width: 150,
|
||||
fixed: 'right',
|
||||
slots: { default: 'action' },
|
||||
},
|
||||
],
|
||||
height: 'auto',
|
||||
maxHeight: 340,
|
||||
border: true,
|
||||
stripe: true,
|
||||
size: 'small',
|
||||
pagerConfig: { enabled: true, pageSizes: [10, 20, 50] },
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }) => {
|
||||
const params: PageQueryDTO<BrushOrderDTO.Filters> = {
|
||||
page: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
filters: {
|
||||
shopId: props.shopId || undefined,
|
||||
startBrushTime: searchForm.value.startBrushTime,
|
||||
endBrushTime: searchForm.value.endBrushTime,
|
||||
},
|
||||
};
|
||||
const data = await getBrushOrderPageApi(params);
|
||||
return { items: data.records, total: data.total };
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions,
|
||||
showSearchForm: false,
|
||||
});
|
||||
|
||||
gridReloadRef.value = () => gridApi.reload();
|
||||
|
||||
function handleAdd() {
|
||||
editingData.value = undefined;
|
||||
modalVisible.value = true;
|
||||
}
|
||||
|
||||
function handleEdit(row: BrushOrderVO.Info) {
|
||||
editingData.value = row;
|
||||
modalVisible.value = true;
|
||||
}
|
||||
|
||||
async function handleDelete(id: number) {
|
||||
await deleteBrushOrderApi(id);
|
||||
gridReloadRef.value?.();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="rounded-2xl border border-slate-200/80 bg-white/90 shadow-sm dark:border-[hsl(222.34deg_10.43%_16%)] dark:bg-[hsl(222.34deg_10.43%_12.27%)]">
|
||||
<!-- 标题栏 + 筛选区(单行) -->
|
||||
<div class="flex items-center justify-between gap-3 border-b border-slate-100 px-6 py-3 dark:border-[hsl(222.34deg_10.43%_16%)]">
|
||||
<h3 class="flex shrink-0 items-center gap-2 text-base font-semibold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
|
||||
<RepeatIcon class="h-4 w-4" />
|
||||
<span>刷单费</span>
|
||||
</h3>
|
||||
<div class="flex items-center gap-2">
|
||||
<DatePicker
|
||||
v-model:value="searchForm.startBrushTime"
|
||||
placeholder="开始时间"
|
||||
class="!w-40"
|
||||
allow-clear
|
||||
show-time
|
||||
@change="() => gridReloadRef?.()"
|
||||
/>
|
||||
<span class="text-xs text-slate-400">至</span>
|
||||
<DatePicker
|
||||
v-model:value="searchForm.endBrushTime"
|
||||
placeholder="结束时间"
|
||||
class="!w-40"
|
||||
allow-clear
|
||||
show-time
|
||||
@change="() => gridReloadRef?.()"
|
||||
/>
|
||||
</div>
|
||||
<Button type="primary" size="small" @click="handleAdd">
|
||||
<template #icon><PlusIcon /></template>
|
||||
新增记录
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<!-- KPI 指标卡 -->
|
||||
<div class="grid grid-cols-3 gap-4 border-b border-slate-100 px-6 py-4 dark:border-[hsl(222.34deg_10.43%_16%)]">
|
||||
<div class="text-center">
|
||||
<div class="text-xs font-medium text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">累计刷单费</div>
|
||||
<div class="mt-1 text-lg font-bold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">¥{{ Number(kpi?.totalBrushAmount || 0).toLocaleString() }}</div>
|
||||
</div>
|
||||
<div class="text-center">
|
||||
<div class="text-xs font-medium text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">本月刷单次数</div>
|
||||
<div class="mt-1 text-lg font-bold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">{{ kpi?.thisMonthCount ?? 0 }} 次</div>
|
||||
</div>
|
||||
<div class="text-center">
|
||||
<div class="text-xs font-medium text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">平均刷单金额</div>
|
||||
<div class="mt-1 text-lg font-bold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">¥{{ Number(kpi?.avgAmount || 0).toLocaleString() }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="p-4">
|
||||
<Grid>
|
||||
<template #action="{ row }: { row: BrushOrderVO.Info }">
|
||||
<Space>
|
||||
<Button size="small" type="primary" @click="handleEdit(row)">编辑</Button>
|
||||
<Popconfirm title="确定删除?" @confirm="handleDelete(row.id)">
|
||||
<Button size="small" danger>删除</Button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
</template>
|
||||
</Grid>
|
||||
</div>
|
||||
|
||||
<BrushOrderFormModal
|
||||
v-model:open="modalVisible"
|
||||
:brush-order-data="editingData"
|
||||
@success="gridReloadRef?.()"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
-179
@@ -1,179 +0,0 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import type { ShopMonthlyTargetDTO, ShopMonthlyTargetVO } from '#/api/ecommerce/shop-monthly-target';
|
||||
import type { ShopVO } from '#/api/ecommerce/shop/types';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
import { Button, DatePicker, Popconfirm, Space } from 'ant-design-vue';
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
deleteShopMonthlyTargetApi,
|
||||
getShopMonthlyTargetPageApi,
|
||||
} from '#/api/ecommerce/shop-monthly-target';
|
||||
|
||||
import ShopMonthlyTargetFormModal from '#/views/ecommerce/shop/monthly-target/components/ShopMonthlyTargetFormModal.vue';
|
||||
|
||||
defineOptions({ name: 'MonthlyTargetCard' });
|
||||
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
const CalendarIcon = createIconifyIcon('lucide:calendar');
|
||||
|
||||
const props = defineProps<{
|
||||
shopId: number;
|
||||
data?: ShopVO.MonthlyTargetKpi;
|
||||
}>();
|
||||
|
||||
const kpi = computed(() => props.data);
|
||||
const gridReloadRef = ref<(() => void) | null>(null);
|
||||
|
||||
const searchForm = ref({
|
||||
startTargetMonth: undefined as string | undefined,
|
||||
endTargetMonth: undefined as string | undefined,
|
||||
});
|
||||
|
||||
const modalVisible = ref(false);
|
||||
const editingData = ref<ShopMonthlyTargetVO.Info | undefined>();
|
||||
|
||||
const gridOptions: VxeGridProps<any> = {
|
||||
columns: [
|
||||
{ type: 'seq', title: '序号', width: 60 },
|
||||
{ field: 'targetMonth', title: '目标月份', width: 120 },
|
||||
{
|
||||
field: 'targetAmount', title: '目标销售额', width: 140,
|
||||
formatter: ({ cellValue }) => `¥${Number(cellValue || 0).toLocaleString()}`,
|
||||
},
|
||||
{ field: 'targetOrderCount', title: '目标单量', width: 120 },
|
||||
{ field: 'remark', title: '备注', minWidth: 140 },
|
||||
{
|
||||
title: '操作',
|
||||
width: 120,
|
||||
fixed: 'right',
|
||||
slots: { default: 'action' },
|
||||
},
|
||||
],
|
||||
height: 'auto',
|
||||
maxHeight: 340,
|
||||
border: true,
|
||||
stripe: true,
|
||||
size: 'small',
|
||||
pagerConfig: { enabled: true, pageSizes: [10, 20, 50] },
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }) => {
|
||||
const params: PageQueryDTO<ShopMonthlyTargetDTO.Filters> = {
|
||||
page: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
filters: {
|
||||
shopId: props.shopId || undefined,
|
||||
startTargetMonth: searchForm.value.startTargetMonth,
|
||||
endTargetMonth: searchForm.value.endTargetMonth,
|
||||
},
|
||||
};
|
||||
const data = await getShopMonthlyTargetPageApi(params);
|
||||
return { items: data.records, total: data.total };
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions,
|
||||
showSearchForm: false,
|
||||
});
|
||||
|
||||
gridReloadRef.value = () => gridApi.reload();
|
||||
|
||||
function handleAdd() {
|
||||
editingData.value = undefined;
|
||||
modalVisible.value = true;
|
||||
}
|
||||
|
||||
function handleEdit(row: ShopMonthlyTargetVO.Info) {
|
||||
editingData.value = row;
|
||||
modalVisible.value = true;
|
||||
}
|
||||
|
||||
async function handleDelete(id: number) {
|
||||
await deleteShopMonthlyTargetApi(id);
|
||||
gridReloadRef.value?.();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="rounded-2xl border border-slate-200/80 bg-white/90 shadow-sm dark:border-[hsl(222.34deg_10.43%_16%)] dark:bg-[hsl(222.34deg_10.43%_12.27%)]">
|
||||
<!-- 标题栏 + 筛选区(单行) -->
|
||||
<div class="flex items-center justify-between gap-3 border-b border-slate-100 px-6 py-3 dark:border-[hsl(222.34deg_10.43%_16%)]">
|
||||
<h3 class="flex shrink-0 items-center gap-2 text-base font-semibold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
|
||||
<CalendarIcon class="h-4 w-4" />
|
||||
<span>月度目标</span>
|
||||
</h3>
|
||||
<div class="flex items-center gap-2">
|
||||
<DatePicker
|
||||
v-model:value="searchForm.startTargetMonth"
|
||||
placeholder="开始月份"
|
||||
picker="month"
|
||||
class="!w-32"
|
||||
allow-clear
|
||||
@change="() => gridReloadRef?.()"
|
||||
/>
|
||||
<span class="text-xs text-slate-400">至</span>
|
||||
<DatePicker
|
||||
v-model:value="searchForm.endTargetMonth"
|
||||
placeholder="结束月份"
|
||||
picker="month"
|
||||
class="!w-32"
|
||||
allow-clear
|
||||
@change="() => gridReloadRef?.()"
|
||||
/>
|
||||
</div>
|
||||
<Button type="primary" size="small" @click="handleAdd">
|
||||
<template #icon><PlusIcon /></template>
|
||||
新增目标
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<!-- KPI 指标卡 -->
|
||||
<div class="grid grid-cols-2 gap-4 border-b border-slate-100 px-6 py-4 dark:border-[hsl(222.34deg_10.43%_16%)] sm:grid-cols-4">
|
||||
<div class="text-center">
|
||||
<div class="text-xs font-medium text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">年度目标总额</div>
|
||||
<div class="mt-1 text-lg font-bold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">¥{{ Number(kpi?.totalTargetAmount || 0).toLocaleString() }}</div>
|
||||
</div>
|
||||
<div class="text-center">
|
||||
<div class="text-xs font-medium text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">目标单量合计</div>
|
||||
<div class="mt-1 text-lg font-bold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">{{ Number(kpi?.totalOrderCount || 0).toLocaleString() }}</div>
|
||||
</div>
|
||||
<div class="text-center">
|
||||
<div class="text-xs font-medium text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">本月目标</div>
|
||||
<div class="mt-1 text-lg font-bold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">¥{{ Number(kpi?.thisMonthTargetAmount || 0).toLocaleString() }}</div>
|
||||
</div>
|
||||
<div class="text-center">
|
||||
<div class="text-xs font-medium text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">当前达成率</div>
|
||||
<div class="mt-1 text-lg font-bold text-emerald-600 dark:text-emerald-400">{{ kpi?.achievementRate ?? 0 }}%</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 表格 -->
|
||||
<div class="p-4">
|
||||
<Grid>
|
||||
<template #action="{ row }: { row: ShopMonthlyTargetVO.Info }">
|
||||
<Space>
|
||||
<Button size="small" type="primary" @click="handleEdit(row)">编辑</Button>
|
||||
<Popconfirm title="确定删除?" @confirm="handleDelete(row.id)">
|
||||
<Button size="small" danger>删除</Button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
</template>
|
||||
</Grid>
|
||||
</div>
|
||||
|
||||
<!-- 弹窗 -->
|
||||
<ShopMonthlyTargetFormModal
|
||||
v-model:open="modalVisible"
|
||||
:shop-monthly-target-data="editingData"
|
||||
@success="gridReloadRef?.()"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
-172
@@ -1,172 +0,0 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import type { PromotionFeeDTO, PromotionFeeVO } from '#/api/ecommerce/promotion-fee';
|
||||
import type { ShopVO } from '#/api/ecommerce/shop/types';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
import { Button, DatePicker, Popconfirm, Space } from 'ant-design-vue';
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
deletePromotionFeeApi,
|
||||
getPromotionFeePageApi,
|
||||
} from '#/api/ecommerce/promotion-fee';
|
||||
|
||||
import PromotionFeeFormModal from '#/views/ecommerce/promotion-fee/components/PromotionFeeFormModal.vue';
|
||||
|
||||
defineOptions({ name: 'PromotionFeeCard' });
|
||||
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
const CoinsIcon = createIconifyIcon('lucide:coins');
|
||||
|
||||
const props = defineProps<{
|
||||
shopId: number;
|
||||
data?: ShopVO.PromotionFeeKpi;
|
||||
}>();
|
||||
|
||||
const kpi = computed(() => props.data);
|
||||
const gridReloadRef = ref<(() => void) | null>(null);
|
||||
|
||||
const searchForm = ref({
|
||||
feeDateStart: undefined as string | undefined,
|
||||
feeDateEnd: undefined as string | undefined,
|
||||
});
|
||||
|
||||
const modalVisible = ref(false);
|
||||
const editingData = ref<PromotionFeeVO.Info | undefined>();
|
||||
|
||||
const gridOptions: VxeGridProps<any> = {
|
||||
columns: [
|
||||
{ type: 'seq', title: '序号', width: 60 },
|
||||
{ field: 'productId', title: '商品ID', width: 90 },
|
||||
{ field: 'campaignName', title: '活动名称', minWidth: 140 },
|
||||
{
|
||||
field: 'feeAmount', title: '费用金额', width: 130,
|
||||
formatter: ({ cellValue }) => `¥${Number(cellValue || 0).toLocaleString()}`,
|
||||
},
|
||||
{ field: 'feeDate', title: '费用日期', width: 120 },
|
||||
{ field: 'remark', title: '备注', minWidth: 120 },
|
||||
{
|
||||
title: '操作',
|
||||
width: 150,
|
||||
fixed: 'right',
|
||||
slots: { default: 'action' },
|
||||
},
|
||||
],
|
||||
height: 'auto',
|
||||
maxHeight: 340,
|
||||
border: true,
|
||||
stripe: true,
|
||||
size: 'small',
|
||||
pagerConfig: { enabled: true, pageSizes: [10, 20, 50] },
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }) => {
|
||||
const params: PageQueryDTO<PromotionFeeDTO.Filters> = {
|
||||
page: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
filters: {
|
||||
shopId: props.shopId || undefined,
|
||||
feeDateStart: searchForm.value.feeDateStart,
|
||||
feeDateEnd: searchForm.value.feeDateEnd,
|
||||
},
|
||||
};
|
||||
const data = await getPromotionFeePageApi(params);
|
||||
return { items: data.records, total: data.total };
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions,
|
||||
showSearchForm: false,
|
||||
});
|
||||
|
||||
gridReloadRef.value = () => gridApi.reload();
|
||||
|
||||
function handleAdd() {
|
||||
editingData.value = undefined;
|
||||
modalVisible.value = true;
|
||||
}
|
||||
|
||||
function handleEdit(row: PromotionFeeVO.Info) {
|
||||
editingData.value = row;
|
||||
modalVisible.value = true;
|
||||
}
|
||||
|
||||
async function handleDelete(id: number) {
|
||||
await deletePromotionFeeApi(id);
|
||||
gridReloadRef.value?.();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="rounded-2xl border border-slate-200/80 bg-white/90 shadow-sm dark:border-[hsl(222.34deg_10.43%_16%)] dark:bg-[hsl(222.34deg_10.43%_12.27%)]">
|
||||
<!-- 标题栏 + 筛选区 -->
|
||||
<div class="flex items-center justify-between gap-3 border-b border-slate-100 px-6 py-3 dark:border-[hsl(222.34deg_10.43%_16%)]">
|
||||
<h3 class="flex shrink-0 items-center gap-2 text-base font-semibold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
|
||||
<CoinsIcon class="h-4 w-4" />
|
||||
<span>推广费</span>
|
||||
</h3>
|
||||
<div class="flex items-center gap-2">
|
||||
<DatePicker
|
||||
v-model:value="searchForm.feeDateStart"
|
||||
placeholder="开始日期"
|
||||
class="!w-32"
|
||||
allow-clear
|
||||
@change="() => gridReloadRef?.()"
|
||||
/>
|
||||
<span class="text-xs text-slate-400">至</span>
|
||||
<DatePicker
|
||||
v-model:value="searchForm.feeDateEnd"
|
||||
placeholder="结束日期"
|
||||
class="!w-32"
|
||||
allow-clear
|
||||
@change="() => gridReloadRef?.()"
|
||||
/>
|
||||
</div>
|
||||
<Button type="primary" size="small" @click="handleAdd">
|
||||
<template #icon><PlusIcon /></template>
|
||||
新增记录
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<!-- KPI 指标卡 -->
|
||||
<div class="grid grid-cols-3 gap-4 border-b border-slate-100 px-6 py-4 dark:border-[hsl(222.34deg_10.43%_16%)]">
|
||||
<div class="text-center">
|
||||
<div class="text-xs font-medium text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">累计推广费</div>
|
||||
<div class="mt-1 text-lg font-bold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">¥{{ Number(kpi?.totalFeeAmount || 0).toLocaleString() }}</div>
|
||||
</div>
|
||||
<div class="text-center">
|
||||
<div class="text-xs font-medium text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">本月推广费</div>
|
||||
<div class="mt-1 text-lg font-bold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">¥{{ Number(kpi?.thisMonthFee || 0).toLocaleString() }}</div>
|
||||
</div>
|
||||
<div class="text-center">
|
||||
<div class="text-xs font-medium text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">日均推广费</div>
|
||||
<div class="mt-1 text-lg font-bold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">¥{{ Number(kpi?.avgDailyFee || 0).toLocaleString() }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="p-4">
|
||||
<Grid>
|
||||
<template #action="{ row }: { row: PromotionFeeVO.Info }">
|
||||
<Space>
|
||||
<Button size="small" type="primary" @click="handleEdit(row)">编辑</Button>
|
||||
<Popconfirm title="确定删除?" @confirm="handleDelete(row.id)">
|
||||
<Button size="small" danger>删除</Button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
</template>
|
||||
</Grid>
|
||||
</div>
|
||||
|
||||
<PromotionFeeFormModal
|
||||
v-model:open="modalVisible"
|
||||
:promotion-fee-data="editingData"
|
||||
@success="gridReloadRef?.()"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
-189
@@ -1,189 +0,0 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import type { OrderDTO, OrderVO } from '#/api/ecommerce/order';
|
||||
import type { ShopVO } from '#/api/ecommerce/shop/types';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
import { Button, Input, Space, Tag } from 'ant-design-vue';
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { getOrderPageApi } from '#/api/ecommerce/order';
|
||||
import {
|
||||
getOrderLinkProductName,
|
||||
getOrderLinkSkuName,
|
||||
getOrderPayAmount,
|
||||
getOrderQuantity,
|
||||
getOrderUnitPrice,
|
||||
} from '#/utils/order-display';
|
||||
|
||||
import OrderFormModal from '#/views/ecommerce/order/components/OrderFormModal.vue';
|
||||
|
||||
defineOptions({ name: 'ShopOrderCard' });
|
||||
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
const PackageIcon = createIconifyIcon('lucide:package');
|
||||
|
||||
const props = defineProps<{
|
||||
shopId: number;
|
||||
data?: ShopVO.ShopOrderKpi;
|
||||
}>();
|
||||
|
||||
const kpi = computed(() => props.data);
|
||||
const gridReloadRef = ref<(() => void) | null>(null);
|
||||
|
||||
const searchForm = ref({
|
||||
platformOrderNo: undefined as string | undefined,
|
||||
});
|
||||
|
||||
const orderModalRef = ref<InstanceType<typeof OrderFormModal> | null>(null);
|
||||
|
||||
const gridOptions: VxeGridProps<OrderVO.Info> = {
|
||||
columns: [
|
||||
{ type: 'seq', title: '序号', width: 60 },
|
||||
{ field: 'platformOrderNo', title: '平台订单号', minWidth: 160 },
|
||||
{
|
||||
title: '商品名称',
|
||||
minWidth: 140,
|
||||
formatter: ({ row }) => getOrderLinkProductName(row),
|
||||
},
|
||||
{
|
||||
title: 'SKU',
|
||||
minWidth: 140,
|
||||
formatter: ({ row }) => getOrderLinkSkuName(row) || '-',
|
||||
},
|
||||
{
|
||||
title: '数量',
|
||||
width: 70,
|
||||
formatter: ({ row }) => String(getOrderQuantity(row)),
|
||||
},
|
||||
{
|
||||
title: '单价',
|
||||
width: 100,
|
||||
formatter: ({ row }) => `¥${getOrderUnitPrice(row).toFixed(2)}`,
|
||||
},
|
||||
{
|
||||
title: '实付金额',
|
||||
width: 110,
|
||||
formatter: ({ row }) => `¥${getOrderPayAmount(row).toFixed(2)}`,
|
||||
},
|
||||
{ field: 'statusLabel', title: '状态', width: 100, slots: { default: 'statusLabel' } },
|
||||
{ field: 'orderTime', title: '下单时间', minWidth: 160 },
|
||||
{
|
||||
title: '操作',
|
||||
width: 80,
|
||||
fixed: 'right',
|
||||
slots: { default: 'action' },
|
||||
},
|
||||
],
|
||||
height: 'auto',
|
||||
maxHeight: 340,
|
||||
border: true,
|
||||
stripe: true,
|
||||
size: 'small',
|
||||
pagerConfig: { enabled: true, pageSizes: [10, 20, 50] },
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }) => {
|
||||
const params: PageQueryDTO<OrderDTO.Filters> = {
|
||||
page: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
filters: {
|
||||
shopId: props.shopId || undefined,
|
||||
platformOrderNo: searchForm.value.platformOrderNo,
|
||||
},
|
||||
};
|
||||
const data = await getOrderPageApi(params);
|
||||
return { items: data.records, total: data.total };
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions,
|
||||
showSearchForm: false,
|
||||
});
|
||||
|
||||
gridReloadRef.value = () => gridApi.reload();
|
||||
|
||||
function handleView(row: OrderVO.Info) {
|
||||
orderModalRef.value?.open(true, row);
|
||||
}
|
||||
|
||||
function handleImport() {
|
||||
orderModalRef.value?.open(false);
|
||||
}
|
||||
|
||||
const statusColorMap: Record<string, string> = {
|
||||
'已付款': 'blue',
|
||||
'已发货': 'purple',
|
||||
'已完成': 'green',
|
||||
'已退款': 'red',
|
||||
'已取消': 'default',
|
||||
};
|
||||
|
||||
function resolveStatusColor(row: OrderVO.Info) {
|
||||
return row.statusColor || statusColorMap[row.statusLabel] || 'default';
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="rounded-2xl border border-slate-200/80 bg-white/90 shadow-sm dark:border-[hsl(222.34deg_10.43%_16%)] dark:bg-[hsl(222.34deg_10.43%_12.27%)]">
|
||||
<!-- 标题栏 + 筛选区(单行) -->
|
||||
<div class="flex items-center justify-between gap-3 border-b border-slate-100 px-6 py-3 dark:border-[hsl(222.34deg_10.43%_16%)]">
|
||||
<h3 class="flex shrink-0 items-center gap-2 text-base font-semibold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
|
||||
<PackageIcon class="h-4 w-4" />
|
||||
<span>店铺订单</span>
|
||||
</h3>
|
||||
<div class="flex items-center gap-2">
|
||||
<Input
|
||||
v-model:value="searchForm.platformOrderNo"
|
||||
placeholder="平台订单号"
|
||||
class="!w-44"
|
||||
allow-clear
|
||||
@change="() => gridReloadRef?.()"
|
||||
/>
|
||||
</div>
|
||||
<Button type="primary" size="small" @click="handleImport">
|
||||
<template #icon><PlusIcon /></template>
|
||||
导入订单
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<!-- KPI 指标卡 -->
|
||||
<div class="grid grid-cols-3 gap-4 border-b border-slate-100 px-6 py-4 dark:border-[hsl(222.34deg_10.43%_16%)]">
|
||||
<div class="text-center">
|
||||
<div class="text-xs font-medium text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">累计实收金额</div>
|
||||
<div class="mt-1 text-lg font-bold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">¥{{ Number(kpi?.totalReceivedAmount || 0).toLocaleString() }}</div>
|
||||
</div>
|
||||
<div class="text-center">
|
||||
<div class="text-xs font-medium text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">累计佣金</div>
|
||||
<div class="mt-1 text-lg font-bold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">¥{{ Number(kpi?.totalCommission || 0).toLocaleString() }}</div>
|
||||
</div>
|
||||
<div class="text-center">
|
||||
<div class="text-xs font-medium text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">累计订单数</div>
|
||||
<div class="mt-1 text-lg font-bold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">{{ kpi?.totalOrderCount ?? 0 }} 笔</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="p-4">
|
||||
<Grid>
|
||||
<template #statusLabel="{ row }: { row: OrderVO.Info }">
|
||||
<Tag :color="resolveStatusColor(row)">{{ row.statusLabel }}</Tag>
|
||||
</template>
|
||||
<template #action="{ row }: { row: OrderVO.Info }">
|
||||
<Space>
|
||||
<Button size="small" type="primary" @click="handleView(row)">查看</Button>
|
||||
</Space>
|
||||
</template>
|
||||
</Grid>
|
||||
</div>
|
||||
|
||||
<OrderFormModal
|
||||
ref="orderModalRef"
|
||||
@success="gridReloadRef?.()"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
@@ -1,19 +1,9 @@
|
||||
<script lang="ts" setup>
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
import { computed } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
|
||||
import { message } from 'ant-design-vue';
|
||||
|
||||
import { getShopDetailsApi } from '#/api/ecommerce/shop';
|
||||
import type { ShopVO } from '#/api/ecommerce/shop/types';
|
||||
|
||||
import MonthlyTargetCard from './components/MonthlyTargetCard.vue';
|
||||
import PromotionFeeCard from './components/PromotionFeeCard.vue';
|
||||
import BrushOrderCard from './components/BrushOrderCard.vue';
|
||||
import ShopOrderCard from './components/ShopOrderCard.vue';
|
||||
|
||||
defineOptions({ name: 'ShopDetails' });
|
||||
|
||||
const route = useRoute();
|
||||
@@ -22,58 +12,14 @@ const shopId = computed(() => {
|
||||
const id = route.params.id;
|
||||
return id ? Number(id) : 0;
|
||||
});
|
||||
|
||||
const loading = ref(false);
|
||||
const dashboard = ref<ShopVO.Dashboard | null>(null);
|
||||
|
||||
async function fetchDashboard() {
|
||||
if (!shopId.value) return;
|
||||
loading.value = true;
|
||||
try {
|
||||
dashboard.value = await getShopDetailsApi({ shopId: shopId.value });
|
||||
} catch {
|
||||
message.error('获取店铺看板数据失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchDashboard();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page
|
||||
:title="dashboard ? `店铺详情(${dashboard.shopInfo?.name})` : '店铺详情'"
|
||||
:title="shopId ? `店铺详情(#${shopId})` : '店铺详情'"
|
||||
auto-content-height
|
||||
content-class="flex min-h-0 flex-1 flex-col bg-[#f8fafc] dark:bg-[hsl(222.34deg_10.43%_12.27%)]"
|
||||
>
|
||||
<div class="mx-auto grid w-full grid-cols-1 gap-6 md:grid-cols-2">
|
||||
<!-- 月度目标 -->
|
||||
<MonthlyTargetCard
|
||||
v-if="dashboard"
|
||||
:shop-id="shopId"
|
||||
:data="dashboard.monthlyTarget"
|
||||
/>
|
||||
<!-- 推广费 -->
|
||||
<PromotionFeeCard
|
||||
v-if="dashboard"
|
||||
:shop-id="shopId"
|
||||
:data="dashboard.promotionFee"
|
||||
/>
|
||||
<!-- 刷单费 -->
|
||||
<BrushOrderCard
|
||||
v-if="dashboard"
|
||||
:shop-id="shopId"
|
||||
:data="dashboard.brushOrder"
|
||||
/>
|
||||
<!-- 店铺订单 -->
|
||||
<ShopOrderCard
|
||||
v-if="dashboard"
|
||||
:shop-id="shopId"
|
||||
:data="dashboard.shopOrder"
|
||||
/>
|
||||
</div>
|
||||
<div class="text-slate-500">店铺详情看板接口已下线。</div>
|
||||
</Page>
|
||||
</template>
|
||||
|
||||
+196
-47
@@ -7,13 +7,26 @@ import { computed, onBeforeUnmount, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { DatePicker, Form, message, Progress, Radio, Switch } from 'ant-design-vue';
|
||||
import {
|
||||
Button,
|
||||
DatePicker,
|
||||
Form,
|
||||
message,
|
||||
Progress,
|
||||
Radio,
|
||||
Space,
|
||||
Switch,
|
||||
Tag,
|
||||
} from 'ant-design-vue';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import {
|
||||
cancelPddFullSyncTaskApi,
|
||||
createPddFullSyncTaskApi,
|
||||
getPddFullSyncTaskApi,
|
||||
getPddIncrementalSyncStatusApi,
|
||||
getPddLatestFullSyncTaskApi,
|
||||
resumePddFullSyncTaskApi,
|
||||
syncPddOrdersByDayApi,
|
||||
syncPddOrdersIncrementalApi,
|
||||
togglePddIncrementalSyncApi,
|
||||
@@ -33,13 +46,13 @@ const range = ref<[Dayjs, Dayjs]>([
|
||||
dayjs().subtract(90, 'day'),
|
||||
dayjs().subtract(1, 'day'),
|
||||
]);
|
||||
const incrementalEnabled = ref(false);
|
||||
const incremental = ref<null | PddOrderSyncVO.IncrementalStatus>(null);
|
||||
const fullTask = ref<null | PddOrderSyncVO.FullTask>(null);
|
||||
let pollTimer: null | ReturnType<typeof setInterval> = null;
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
draggable: true,
|
||||
class: 'w-[520px]',
|
||||
class: 'w-[560px]',
|
||||
onCancel() {
|
||||
stopPoll();
|
||||
modalApi.close();
|
||||
@@ -61,6 +74,39 @@ const taskProgressPercent = computed(() => {
|
||||
);
|
||||
});
|
||||
|
||||
const isFullActive = computed(() => {
|
||||
const s = fullTask.value?.status;
|
||||
return s === 'PENDING' || s === 'RUNNING';
|
||||
});
|
||||
|
||||
const canCancelFull = computed(() => isFullActive.value);
|
||||
const canResumeFull = computed(() => fullTask.value?.status === 'FAILED');
|
||||
|
||||
const incHealthLabel = computed(() => {
|
||||
const health = incremental.value?.health;
|
||||
const map: Record<string, string> = {
|
||||
OFF: '已关闭',
|
||||
OK: '正常',
|
||||
LAGGING: '游标滞后',
|
||||
PAUSED: '出错暂停',
|
||||
};
|
||||
return health ? map[health] || health : '-';
|
||||
});
|
||||
|
||||
const incHealthColor = computed(() => {
|
||||
const health = incremental.value?.health;
|
||||
if (health === 'PAUSED') return 'error';
|
||||
if (health === 'LAGGING') return 'warning';
|
||||
if (health === 'OK') return 'success';
|
||||
return 'default';
|
||||
});
|
||||
|
||||
function formatTime(time?: null | string) {
|
||||
if (!time) return '-';
|
||||
const d = dayjs(time);
|
||||
return d.isValid() ? d.format('YYYY-MM-DD HH:mm:ss') : '-';
|
||||
}
|
||||
|
||||
function stopPoll() {
|
||||
if (pollTimer) {
|
||||
clearInterval(pollTimer);
|
||||
@@ -71,25 +117,38 @@ function stopPoll() {
|
||||
async function loadIncrementalStatus() {
|
||||
if (!shop.value) return;
|
||||
try {
|
||||
const status = await getPddIncrementalSyncStatusApi(shop.value.id);
|
||||
incrementalEnabled.value = !!status.enabled;
|
||||
incremental.value = await getPddIncrementalSyncStatusApi(shop.value.id);
|
||||
} catch (error) {
|
||||
console.error('加载增量开关失败:', error);
|
||||
console.error('加载增量状态失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
async function loadLatestFullTask() {
|
||||
if (!shop.value) return;
|
||||
try {
|
||||
const task = await getPddLatestFullSyncTaskApi(shop.value.id);
|
||||
fullTask.value = task;
|
||||
if (task && (task.status === 'PENDING' || task.status === 'RUNNING')) {
|
||||
pollFullTask(task.id);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载全量任务失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleToggleIncremental(checked: boolean | string | number) {
|
||||
if (!shop.value) return;
|
||||
const enabled = !!checked;
|
||||
const prev = incremental.value;
|
||||
try {
|
||||
const status = await togglePddIncrementalSyncApi({
|
||||
incremental.value = await togglePddIncrementalSyncApi({
|
||||
shopId: shop.value.id,
|
||||
enabled,
|
||||
});
|
||||
incrementalEnabled.value = !!status.enabled;
|
||||
message.success(enabled ? '已开启增量同步' : '已关闭增量同步');
|
||||
emit('success');
|
||||
} catch (error) {
|
||||
incrementalEnabled.value = !enabled;
|
||||
incremental.value = prev;
|
||||
console.error('切换增量开关失败:', error);
|
||||
message.error('切换增量开关失败');
|
||||
}
|
||||
@@ -101,7 +160,11 @@ async function pollFullTask(taskId: number) {
|
||||
try {
|
||||
const task = await getPddFullSyncTaskApi(taskId);
|
||||
fullTask.value = task;
|
||||
if (task.status === 'SUCCESS' || task.status === 'FAILED' || task.status === 'CANCELLED') {
|
||||
if (
|
||||
task.status === 'SUCCESS' ||
|
||||
task.status === 'FAILED' ||
|
||||
task.status === 'CANCELLED'
|
||||
) {
|
||||
stopPoll();
|
||||
modalApi.setState({ confirmLoading: false });
|
||||
loading.value = false;
|
||||
@@ -110,8 +173,12 @@ async function pollFullTask(taskId: number) {
|
||||
`全量同步完成:${task.doneDays}/${task.totalDays} 天`,
|
||||
);
|
||||
emit('success');
|
||||
} else {
|
||||
} else if (task.status === 'FAILED') {
|
||||
message.error(task.lastError || '全量同步失败');
|
||||
emit('success');
|
||||
} else {
|
||||
message.info('全量同步已取消');
|
||||
emit('success');
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -120,6 +187,39 @@ async function pollFullTask(taskId: number) {
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
async function handleCancelFull() {
|
||||
if (!fullTask.value) return;
|
||||
try {
|
||||
loading.value = true;
|
||||
fullTask.value = await cancelPddFullSyncTaskApi(fullTask.value.id);
|
||||
stopPoll();
|
||||
message.success('已取消全量任务');
|
||||
emit('success');
|
||||
} catch (error) {
|
||||
console.error('取消全量任务失败:', error);
|
||||
message.error('取消全量任务失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleResumeFull() {
|
||||
if (!fullTask.value) return;
|
||||
try {
|
||||
loading.value = true;
|
||||
modalApi.setState({ confirmLoading: true });
|
||||
const task = await resumePddFullSyncTaskApi(fullTask.value.id);
|
||||
fullTask.value = task;
|
||||
message.success('已续跑入队');
|
||||
pollFullTask(task.id);
|
||||
} catch (error) {
|
||||
console.error('续跑全量任务失败:', error);
|
||||
message.error('续跑全量任务失败');
|
||||
loading.value = false;
|
||||
modalApi.setState({ confirmLoading: false });
|
||||
}
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
if (!shop.value) return;
|
||||
if (mode.value === 'day' && !confirmDate.value) {
|
||||
@@ -130,6 +230,10 @@ async function handleSubmit() {
|
||||
message.warning('请选择全量同步日期区间');
|
||||
return;
|
||||
}
|
||||
if (mode.value === 'full' && isFullActive.value) {
|
||||
message.warning('该店铺已有进行中的全量任务,请先等待或取消');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
loading.value = true;
|
||||
modalApi.setState({ confirmLoading: true });
|
||||
@@ -143,28 +247,22 @@ async function handleSubmit() {
|
||||
fullTask.value = task;
|
||||
message.success('全量同步任务已创建,正在后台执行');
|
||||
pollFullTask(task.id);
|
||||
emit('success');
|
||||
return;
|
||||
}
|
||||
|
||||
const result =
|
||||
mode.value === 'day'
|
||||
? await syncPddOrdersByDayApi({
|
||||
shopId: shop.value.id,
|
||||
confirmDate: confirmDate.value.format('YYYY-MM-DD'),
|
||||
})
|
||||
: await syncPddOrdersIncrementalApi(shop.value.id);
|
||||
await (mode.value === 'day'
|
||||
? syncPddOrdersByDayApi({
|
||||
shopId: shop.value.id,
|
||||
confirmDate: confirmDate.value.format('YYYY-MM-DD'),
|
||||
})
|
||||
: syncPddOrdersIncrementalApi(shop.value.id));
|
||||
|
||||
const errHint =
|
||||
result.errors && result.errors.length > 0
|
||||
? `;注意:${result.errors[0]}`
|
||||
: '';
|
||||
message.success(
|
||||
mode.value === 'day' || mode.value === 'incremental'
|
||||
? '已入队,后台同步中'
|
||||
: `同步完成:拉取 ${result.fetchedCount},入库 ${result.upsertedCount}${errHint}`,
|
||||
);
|
||||
message.success('已入队,后台同步中');
|
||||
emit('success');
|
||||
modalApi.close();
|
||||
if (mode.value === 'incremental') {
|
||||
await loadIncrementalStatus();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('同步拼多多订单失败:', error);
|
||||
message.error('同步拼多多订单失败');
|
||||
@@ -182,9 +280,10 @@ async function open(record: ShopVO.Info) {
|
||||
confirmDate.value = dayjs().subtract(1, 'day');
|
||||
range.value = [dayjs().subtract(90, 'day'), dayjs().subtract(1, 'day')];
|
||||
fullTask.value = null;
|
||||
incremental.value = null;
|
||||
stopPoll();
|
||||
await loadIncrementalStatus();
|
||||
modalApi.open();
|
||||
await Promise.all([loadIncrementalStatus(), loadLatestFullTask()]);
|
||||
}
|
||||
|
||||
onBeforeUnmount(() => stopPoll());
|
||||
@@ -194,21 +293,81 @@ defineExpose({ open });
|
||||
|
||||
<template>
|
||||
<Modal :title="modalTitle" content-class="px-5 py-4">
|
||||
<Form layout="vertical">
|
||||
<Form.Item label="自动增量同步">
|
||||
<div class="flex items-center gap-3">
|
||||
<!-- 状态面板 -->
|
||||
<div class="mb-4 space-y-3">
|
||||
<div class="rounded border border-slate-200 p-3 dark:border-[hsl(240deg_3.7%_22%)]">
|
||||
<div class="mb-2 flex items-center justify-between">
|
||||
<span class="text-sm font-medium">增量同步</span>
|
||||
<Tag :color="incHealthColor">{{ incHealthLabel }}</Tag>
|
||||
</div>
|
||||
<div class="mb-2 flex items-center gap-3">
|
||||
<Switch
|
||||
:checked="incrementalEnabled"
|
||||
:checked="!!incremental?.enabled"
|
||||
checked-children="开"
|
||||
un-checked-children="关"
|
||||
@change="handleToggleIncremental"
|
||||
/>
|
||||
<span class="text-xs text-slate-500">开启后定时 Job 会拉取该店增量并转换</span>
|
||||
<span class="text-xs text-slate-500">开启后定时 Job 拉取增量并转换</span>
|
||||
</div>
|
||||
</Form.Item>
|
||||
<div class="grid grid-cols-1 gap-1 text-xs text-slate-600 sm:grid-cols-2 dark:text-slate-300">
|
||||
<div>游标:{{ formatTime(incremental?.lastCursorAt) }}</div>
|
||||
<div>上次成功:{{ formatTime(incremental?.lastSuccessTime) }}</div>
|
||||
</div>
|
||||
<p v-if="incremental?.lastError" class="mt-2 text-xs text-red-500">
|
||||
{{ incremental.lastError }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="rounded border border-slate-200 p-3 dark:border-[hsl(240deg_3.7%_22%)]">
|
||||
<div class="mb-2 flex items-center justify-between gap-2">
|
||||
<span class="text-sm font-medium">全量同步任务</span>
|
||||
<Space size="small">
|
||||
<Button
|
||||
v-if="canCancelFull"
|
||||
size="small"
|
||||
danger
|
||||
:loading="loading"
|
||||
@click="handleCancelFull"
|
||||
>
|
||||
取消
|
||||
</Button>
|
||||
<Button
|
||||
v-if="canResumeFull"
|
||||
size="small"
|
||||
type="primary"
|
||||
:loading="loading"
|
||||
@click="handleResumeFull"
|
||||
>
|
||||
续跑
|
||||
</Button>
|
||||
</Space>
|
||||
</div>
|
||||
<template v-if="fullTask">
|
||||
<div class="mb-2 text-sm">
|
||||
#{{ fullTask.id }} · {{ fullTask.status }} ·
|
||||
{{ fullTask.doneDays }}/{{ fullTask.totalDays }} 天
|
||||
<span v-if="fullTask.failedDays" class="text-red-500">
|
||||
· 失败日 {{ fullTask.failedDays }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="mb-2 text-xs text-slate-500">
|
||||
区间 {{ fullTask.dateFrom }} ~ {{ fullTask.dateTo }}
|
||||
<span v-if="fullTask.currentDate"> · 当前 {{ fullTask.currentDate }}</span>
|
||||
</div>
|
||||
<Progress :percent="taskProgressPercent" size="small" />
|
||||
<p v-if="fullTask.lastError" class="mt-2 text-xs text-red-500">
|
||||
{{ fullTask.lastError }}
|
||||
</p>
|
||||
</template>
|
||||
<p v-else class="text-xs text-slate-500">暂无全量任务</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 操作区 -->
|
||||
<Form layout="vertical">
|
||||
<Form.Item label="同步方式">
|
||||
<Radio.Group v-model:value="mode">
|
||||
<Radio value="full">全量同步任务(按日区间)</Radio>
|
||||
<Radio value="full" :disabled="isFullActive">全量同步任务(按日区间)</Radio>
|
||||
<Radio value="day">按成交日同步一天</Radio>
|
||||
<Radio value="incremental">手动增量一次</Radio>
|
||||
</Radio.Group>
|
||||
@@ -222,6 +381,7 @@ defineExpose({ open });
|
||||
v-model:value="range"
|
||||
class="w-full"
|
||||
:allow-clear="false"
|
||||
:disabled="isFullActive"
|
||||
format="YYYY-MM-DD"
|
||||
/>
|
||||
</Form.Item>
|
||||
@@ -240,17 +400,6 @@ defineExpose({ open });
|
||||
<p v-else class="mb-3 text-xs text-slate-500">
|
||||
按订单更新时间拉取自上次游标以来的变更,用于发货/售后等状态同步。
|
||||
</p>
|
||||
<div v-if="fullTask" class="rounded border border-slate-200 p-3">
|
||||
<div class="mb-2 text-sm">
|
||||
任务 #{{ fullTask.id }} · {{ fullTask.status }} ·
|
||||
{{ fullTask.doneDays }}/{{ fullTask.totalDays }} 天
|
||||
<span v-if="fullTask.currentDate">(当前 {{ fullTask.currentDate }})</span>
|
||||
</div>
|
||||
<Progress :percent="taskProgressPercent" size="small" />
|
||||
<p v-if="fullTask.lastError" class="mt-2 text-xs text-red-500">
|
||||
{{ fullTask.lastError }}
|
||||
</p>
|
||||
</div>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import type { PlatformVO } from '#/api/ecommerce/platform/types';
|
||||
import type { PddOrderSyncVO } from '#/api/ecommerce/pdd/order-sync';
|
||||
import type { ShopDTO, ShopVO } from '#/api/ecommerce/shop/types';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
import { computed, onMounted, onUnmounted, ref } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import { Button, message, Popconfirm, Space, Tag } from 'ant-design-vue';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { getPddAuthorizeUrlApi } from '#/api/ecommerce/pdd/auth';
|
||||
import { batchPddOrderSyncStatusApi } from '#/api/ecommerce/pdd/order-sync';
|
||||
import { getPlatformListApi } from '#/api/ecommerce/platform';
|
||||
import { deleteShopApi, getShopPageApi } from '#/api/ecommerce/shop';
|
||||
|
||||
@@ -25,8 +27,6 @@ defineOptions({ name: 'ShopManagement' });
|
||||
|
||||
const PLATFORM_CODE_PDD = 'pdd';
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
|
||||
const loading = ref(false);
|
||||
@@ -35,6 +35,9 @@ const shopFormModalRef = ref();
|
||||
const pddShopDetailModalRef = ref();
|
||||
const pddOrderSyncModalRef = ref();
|
||||
|
||||
/** shopId -> 同步摘要 */
|
||||
const syncStatusMap = ref<Record<number, PddOrderSyncVO.ShopStatus>>({});
|
||||
|
||||
const searchForm = ref({
|
||||
name: '',
|
||||
platformCode: undefined as string | undefined,
|
||||
@@ -77,6 +80,12 @@ const gridOptions: VxeGridProps<any> = {
|
||||
showOverflow: false,
|
||||
slots: { default: 'externalShop' },
|
||||
},
|
||||
{
|
||||
title: '订单同步',
|
||||
minWidth: 200,
|
||||
showOverflow: false,
|
||||
slots: { default: 'orderSync' },
|
||||
},
|
||||
{
|
||||
field: 'createTime',
|
||||
title: '创建时间',
|
||||
@@ -89,7 +98,7 @@ const gridOptions: VxeGridProps<any> = {
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
minWidth: 420,
|
||||
minWidth: 360,
|
||||
fixed: 'right' as const,
|
||||
slots: { default: 'action' },
|
||||
},
|
||||
@@ -146,6 +155,7 @@ const gridOptions: VxeGridProps<any> = {
|
||||
},
|
||||
};
|
||||
const data = await getShopPageApi(params);
|
||||
await loadSyncStatusForShops(data.records || []);
|
||||
return {
|
||||
items: data.records,
|
||||
total: data.total,
|
||||
@@ -226,6 +236,89 @@ async function fetchPlatformOptions() {
|
||||
}
|
||||
}
|
||||
|
||||
async function loadSyncStatusForShops(records: ShopVO.Info[]) {
|
||||
const pddIds = records
|
||||
.filter((r) => r.platformCode === PLATFORM_CODE_PDD && hasExternalShop(r))
|
||||
.map((r) => r.id);
|
||||
if (pddIds.length === 0) {
|
||||
syncStatusMap.value = {};
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const list = await batchPddOrderSyncStatusApi(pddIds);
|
||||
const map: Record<number, PddOrderSyncVO.ShopStatus> = {};
|
||||
for (const item of list || []) {
|
||||
map[item.shopId] = item;
|
||||
}
|
||||
syncStatusMap.value = map;
|
||||
} catch (error) {
|
||||
console.error('加载订单同步状态失败:', error);
|
||||
syncStatusMap.value = {};
|
||||
}
|
||||
}
|
||||
|
||||
function formatRelative(time?: null | string) {
|
||||
if (!time) return '';
|
||||
const d = dayjs(time);
|
||||
if (!d.isValid()) return '';
|
||||
const mins = dayjs().diff(d, 'minute');
|
||||
if (mins < 1) return '刚刚';
|
||||
if (mins < 60) return `${mins} 分钟前`;
|
||||
const hours = dayjs().diff(d, 'hour');
|
||||
if (hours < 24) return `${hours} 小时前`;
|
||||
const days = dayjs().diff(d, 'day');
|
||||
if (days < 30) return `${days} 天前`;
|
||||
return d.format('MM-DD');
|
||||
}
|
||||
|
||||
function fullSyncLabel(status?: PddOrderSyncVO.ShopStatus) {
|
||||
const task = status?.fullTask;
|
||||
if (!task) return '-';
|
||||
if (task.status === 'PENDING' || task.status === 'RUNNING') {
|
||||
return `进行中 ${task.doneDays ?? 0}/${task.totalDays ?? 0}`;
|
||||
}
|
||||
if (task.status === 'FAILED') return '失败';
|
||||
if (task.status === 'CANCELLED') return '已取消';
|
||||
if (task.status === 'SUCCESS') {
|
||||
const rel = formatRelative(task.finishTime);
|
||||
return rel ? `已完成(${rel})` : '已完成';
|
||||
}
|
||||
return task.status;
|
||||
}
|
||||
|
||||
function fullSyncColor(status?: PddOrderSyncVO.ShopStatus) {
|
||||
const s = status?.fullTask?.status;
|
||||
if (s === 'RUNNING' || s === 'PENDING') return 'processing';
|
||||
if (s === 'FAILED') return 'error';
|
||||
if (s === 'SUCCESS') return 'success';
|
||||
if (s === 'CANCELLED') return 'default';
|
||||
return 'default';
|
||||
}
|
||||
|
||||
function incSyncLabel(status?: PddOrderSyncVO.ShopStatus) {
|
||||
const inc = status?.incremental;
|
||||
if (!inc) return '关';
|
||||
const health = inc.health || (inc.enabled ? 'OK' : 'OFF');
|
||||
const map: Record<string, string> = {
|
||||
OFF: '关',
|
||||
OK: '开·正常',
|
||||
LAGGING: '开·滞后',
|
||||
PAUSED: '开·暂停',
|
||||
};
|
||||
const base = map[health] || (inc.enabled ? '开' : '关');
|
||||
const anchor = inc.lastSuccessTime || inc.lastCursorAt;
|
||||
const rel = formatRelative(anchor);
|
||||
return rel ? `${base} · ${rel}` : base;
|
||||
}
|
||||
|
||||
function incSyncColor(status?: PddOrderSyncVO.ShopStatus) {
|
||||
const health = status?.incremental?.health;
|
||||
if (health === 'PAUSED') return 'error';
|
||||
if (health === 'LAGGING') return 'warning';
|
||||
if (health === 'OK') return 'success';
|
||||
return 'default';
|
||||
}
|
||||
|
||||
function refreshTable() {
|
||||
gridApi?.reload();
|
||||
}
|
||||
@@ -261,10 +354,6 @@ function handleModalSuccess() {
|
||||
refreshTable();
|
||||
}
|
||||
|
||||
function handleViewOverview(record: ShopVO.Info) {
|
||||
router.push(`/ecom/shop/overview/${record.id}`);
|
||||
}
|
||||
|
||||
function handleViewExternalShop(record: ShopVO.Info) {
|
||||
if (!record.pddShop) {
|
||||
message.warning('暂无外部店铺详情,请先完成授权同步');
|
||||
@@ -357,12 +446,7 @@ onUnmounted(() => {
|
||||
</template>
|
||||
|
||||
<template #name="{ row }: { row: ShopVO.Info }">
|
||||
<a
|
||||
class="text-primary cursor-pointer hover:underline"
|
||||
@click="handleViewOverview(row)"
|
||||
>
|
||||
{{ row.name }}
|
||||
</a>
|
||||
<span>{{ row.name }}</span>
|
||||
</template>
|
||||
|
||||
<template #externalShop="{ row }: { row: ShopVO.Info }">
|
||||
@@ -388,24 +472,30 @@ onUnmounted(() => {
|
||||
<span v-else class="text-slate-400">-</span>
|
||||
</template>
|
||||
|
||||
<template #orderSync="{ row }: { row: ShopVO.Info }">
|
||||
<div
|
||||
v-if="isPddShop(row) && hasExternalShop(row)"
|
||||
class="flex cursor-pointer flex-col gap-1"
|
||||
@click="handleSyncPddOrders(row)"
|
||||
>
|
||||
<div class="flex items-center gap-1 text-xs">
|
||||
<span class="text-slate-500">全量</span>
|
||||
<Tag :color="fullSyncColor(syncStatusMap[row.id])" class="!mr-0">
|
||||
{{ fullSyncLabel(syncStatusMap[row.id]) }}
|
||||
</Tag>
|
||||
</div>
|
||||
<div class="flex items-center gap-1 text-xs">
|
||||
<span class="text-slate-500">增量</span>
|
||||
<Tag :color="incSyncColor(syncStatusMap[row.id])" class="!mr-0">
|
||||
{{ incSyncLabel(syncStatusMap[row.id]) }}
|
||||
</Tag>
|
||||
</div>
|
||||
</div>
|
||||
<span v-else class="text-slate-400">-</span>
|
||||
</template>
|
||||
|
||||
<template #action="{ row }: { row: ShopVO.Info }">
|
||||
<Space wrap>
|
||||
<Button size="small" type="primary" @click="handleViewOverview(row)">
|
||||
查看概览
|
||||
</Button>
|
||||
<Button
|
||||
size="small"
|
||||
@click="router.push(`/ecom/shop/details/${row.id}`)"
|
||||
>
|
||||
查看详情
|
||||
</Button>
|
||||
<Button
|
||||
v-if="isPddShop(row) && row.pddShop"
|
||||
size="small"
|
||||
@click="handleViewExternalShop(row)"
|
||||
>
|
||||
外部店铺
|
||||
</Button>
|
||||
<Button
|
||||
v-if="isPddShop(row) && hasExternalShop(row)"
|
||||
size="small"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ShopDTO, ShopVO } from '#/api/ecommerce/shop/types';
|
||||
import type { ShopVO } from '#/api/ecommerce/shop/types';
|
||||
import type { Dayjs } from 'dayjs';
|
||||
|
||||
import {
|
||||
@@ -16,7 +16,6 @@ import { Page } from '@vben/common-ui';
|
||||
import { message, Spin } from 'ant-design-vue';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import { getShopOverviewStatisticsApi } from '#/api/ecommerce/shop';
|
||||
import { getShopPageApi } from '#/api/ecommerce/shop/apis';
|
||||
import { exportByPost } from '#/utils/export';
|
||||
import {
|
||||
@@ -250,19 +249,8 @@ const loadOverviewData = async () => {
|
||||
isRequesting.value = true;
|
||||
try {
|
||||
loading.value = true;
|
||||
const params: ShopDTO.OverviewQuery = {
|
||||
shopId: shopId.value,
|
||||
dateRange: [
|
||||
dateRange.value[0].format('YYYY-MM-DD'),
|
||||
dateRange.value[1].format('YYYY-MM-DD'),
|
||||
],
|
||||
taxRate: taxRate.value,
|
||||
};
|
||||
const data = await getShopOverviewStatisticsApi(params);
|
||||
overviewData.value = data;
|
||||
} catch (error) {
|
||||
console.error('获取店铺概览数据失败:', error);
|
||||
message.error('获取店铺概览数据失败');
|
||||
// 原 /ec/shop/overview 已下线,待接入 Mongo BI 读模型
|
||||
overviewData.value = null;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
isRequesting.value = false;
|
||||
|
||||
Reference in New Issue
Block a user