taocarts 集运仓储系统(WMS)设计与核心代码-CSDN博客
一、集运仓:反向代购的履约核心
反向代购、代购转运、国际集运业务,核心履约环节就是国内集运仓。
海外用户买的商品,从淘宝 / 1688 采购后,全部发到集运仓,再验货、合箱、打包、发货。
taocarts 系统内置了一套完整的WMS(仓储管理系统),本文从业务流程、系统设计、核心代码、避坑四个方面详细拆解。
二、集运仓核心业务流程
入库:国内快递到达 → 扫描运单号 → 关联用户订单 → 入库上架
验货:检查商品数量、外观、是否破损 → 拍照留存
合箱:同一用户多包裹合并成一箱,节省运费
打包:称重、量体积、选择包装材料
出库:生成国际运单号 → 对接物流商 → 发货
追踪:同步物流节点 → 用户端实时查看
三、taocarts WMS 系统设计
3.1 核心数据模型
// warehouse-package.entity.ts
export
class
WarehousePackage
{
id
:
number
;
orderId
:
number
;
userId
:
number
;
trackingNo
:
string
;
// 国内运单号
status
:
'in'
|
'checked'
|
'packed'
|
'shipped'
;
weight
:
number
;
volume
:
number
;
photos
:
string
[
]
;
createdAt
:
Date
;
}
3.2 系统模块拆分
入库模块:快递签收、扫描、关联订单
验货模块:质检、拍照、记录问题
合箱模块:多包裹合并、计算运费
打包模块:称重、量体积、打印面单
出库模块:生成国际运单、对接物流
库存模块:库存查询、预警、盘点
四、核心代码实现
4.1 入库扫描
// warehouse.service.ts
async
inbound
(
trackingNo
:
string
,
orderId
:
number
)
{
// 检查是否已入库
const
exist
=
await
this
.
packageRepo
.
findOne
(
{
where
:
{
trackingNo
}
}
)
;
if
(
exist
)
throw
new
Error
(
'已入库'
)
;
const
pkg
=
this
.
packageRepo
.
create
(
{
orderId
,
userId
:
await
this
.
getUserIdByOrder
(
orderId
)
,
trackingNo
,
status
:
'in'
}
)
;
return
this
.
packageRepo
.
save
(
pkg
)
;
}
4.2 验货拍照
async
check
(
packageId
:
number
,
photos
:
string
[
]
)
{
const
pkg
=
await
this
.
packageRepo
.
findOne
(
{
where
:
{
id
:
packageId
}
}
)
;
if
(
!
pkg
)
throw
new
Error
(
'包裹不存在'
)
;
pkg
.
status
=
'checked'
;
pkg
.
photos
=
photos
;
return
this
.
packageRepo
.
save
(
pkg
)
;
}
4.3 合箱计算
async
combine
(
orderIds
:
number
[
]
)
{
const
packages
=
await
this
.
packageRepo
.
find
(
{
where
:
{
orderId
:
In
(
orderIds
)
,
status
:
'checked'
}
}
)
;
let
totalWeight
=
0
;
let
totalVolume
=
0
;
packages
.
forEach
(
p
=>
{
totalWeight
+=
p
.
weight
;
totalVolume
+=
p
.
volume
;
}
)
;
// 计算运费(示例公式)
const
freight
=
totalWeight
*
60
+
totalVolume
*
200
;
return
{
totalWeight
,
totalVolume
,
freight
}
;
}
4.4 出库发货
async
ship
(
packageId
:
number
,
logisticsCode
:
string
)
{
const
pkg
=
await
this
.
packageRepo
.
findOne
(
{
where
:
{
id
:
packageId
}
}
)
;
if
(
pkg
.
status
!==
'packed'
)
throw
new
Error
(
'未打包'
)
;
// 调用物流API生成运单号
const
waybill
=
await
this
.
logisticsApi
.
createWaybill
(
logisticsCode
,
pkg
)
;
pkg
.
status
=
'shipped'
;
pkg
.
waybillNo
=
waybill
;
return
this
.
packageRepo
.
save
(
pkg
)
;
}
五、避坑要点
合箱计费逻辑复杂:体积重、材积、汇率、服务费,一定要写单元测试 + 场景测试
包裹关联订单容易错:扫描运单号自动关联,减少人工输入
拍照留存非常重要:纠纷时作为证据,每个包裹至少 3 张照片
库存预警要及时:避免爆仓、积压
物流对接要稳定:国际物流 API 超时、失败率高,做好重试 + 兜底
六、总结
集运仓储系统(WMS)是代购集运、国际集运、代购转运业务的履约核心,直接决定发货效率、成本、用户体验。taocarts 系统内置的 WMS,把入库、验货、合箱、打包、出库全流程数字化、自动化,是其支撑大规模反向海淘业务的关键能力。