超腾开源平台商业模块

2026-01-07 超腾开源 38 次阅读 0 次点赞
本文档详细介绍了商业模块API,该模块提供完整的电子商务功能。核心内容包括商品管理(商品CRUD、图片与附件管理)、订单管理(订单创建、查询与交易记录)、评价管理(评价与回复)、收藏管理、购物车管理、软件管理(软件销售与文件管理)以及支付管理(支持支付宝和微信支付)。文档为每个功能提供了具体的接口地址、请求参数、响应示例及使用说明,并列举了相关枚举类型和注意事项。整体旨在为开发者提供一套清晰、可操作的API指南,以集成电子商务能力。

商业模块提供完整的电子商务功能,包括商品管理、订单管理、评价管理、收藏、购物车、软件销售和支付功能。

目录


商品管理

商品模块提供商品的创建、编辑、删除、图片管理、附件管理等功能。

商品主表 CRUD

获取商品详情

接口地址: GET /api/commerce/items/detail

需要认证: 是

请求参数:

参数 类型 必填 说明
id string 商品 ID

响应示例:

{
  "success": true,
  "code": 200,
  "msg": "操作成功",
  "data": {
    "id": "1",
    "code": "ITEM001",
    "name": "商品名称",
    "description": "商品描述",
    "detail": "商品详情",
    "price": 99.99,
    "discount_price": 89.99,
    "stock": 100,
    "category": "电子产品",
    "version": "1.0.0",
    "thumbnail": "https://example.com/thumb.jpg",
    "status": "available",
    "is_active": true,
    "create_time": "2026-01-01T00:00:00Z",
    "update_time": "2026-01-01T00:00:00Z"
  }
}

获取商品列表

接口地址: GET /api/commerce/items/list

需要认证: 是

请求参数:

参数 类型 必填 说明
code string 商品编码
name string 商品名称
category string 商品分类
status string 商品状态
is_active boolean 是否激活
order string 排序字段

获取商品分页

接口地址: GET /api/commerce/items/page

需要认证: 是

请求参数:

参数 类型 必填 说明 默认值
page int 页码 1
page_size int 每页条数 10
code string 商品编码 -
name string 商品名称 -
其他参数同列表接口 -

创建商品

接口地址: POST /api/commerce/items/create

需要认证: 是

请求体:

{
  "code": "ITEM001",
  "name": "商品名称",
  "description": "商品描述",
  "detail": "商品详情",
  "price": 99.99,
  "discount_price": 89.99,
  "stock": 100,
  "category": "电子产品",
  "version": "1.0.0",
  "status": "available",
  "is_active": true
}

请求字段说明:

字段 类型 必填 说明
code string 商品编码(唯一)
name string 商品名称
description string 商品描述
detail string 商品详情
price decimal 商品价格
discount_price decimal 折扣价格
stock int 库存数量
category string 商品分类
version string 商品版本
status string 商品状态(available/out_of_stock/discontinued)
is_active boolean 是否激活

更新商品

接口地址: POST /api/commerce/items/update

需要认证: 是

请求体: 同创建商品,需包含 id 字段。

删除商品

接口地址: POST /api/commerce/items/delete

需要认证: 是

请求参数:

参数 类型 必填 说明
id string 商品 ID

商品文档管理

接口地址 方法 说明
/api/commerce/items/document/detail GET 获取商品文档详情
/api/commerce/items/document/list GET 获取商品文档列表
/api/commerce/items/document/create POST 创建商品文档
/api/commerce/items/document/update POST 更新商品文档
/api/commerce/items/document/delete POST 删除商品文档

商品图片管理

接口地址 方法 说明
/api/commerce/items/image/detail GET 获取商品图片详情
/api/commerce/items/image/list GET 获取商品图片列表
/api/commerce/items/image/upload POST 上传商品图片
/api/commerce/items/image/update POST 更新商品图片
/api/commerce/items/image/delete POST 删除商品图片

上传商品图片

接口地址: POST /api/commerce/items/image/upload

需要认证: 是

请求参数: multipart/form-data

参数 类型 必填 说明
item_id string 商品 ID
file file 图片文件
image_type string 图片类型(thumbnail/detail/other),默认为 detail
sort int 排序序号,默认为 0

商品附件管理

接口地址 方法 说明
/api/commerce/items/attachment/detail GET 获取商品附件详情
/api/commerce/items/attachment/list GET 获取商品附件列表
/api/commerce/items/attachment/upload POST 上传商品附件
/api/commerce/items/attachment/create POST 创建商品附件
/api/commerce/items/attachment/update POST 更新商品附件
/api/commerce/items/attachment/delete POST 删除商品附件

上传商品附件

接口地址: POST /api/commerce/items/attachment/upload

需要认证: 是

请求参数: multipart/form-data

参数 类型 必填 说明
item_id string 商品 ID
name string 附件名称
file file 附件文件
description string 附件描述
version string 版本号
attachment_type string 附件类型(manual/software/other)
sort int 排序序号

订单管理

订单模块提供订单的创建、查询、更新等功能。

订单主表 CRUD

接口地址 方法 说明
/api/commerce/orders/detail GET 获取订单详情
/api/commerce/orders/list GET 获取订单列表
/api/commerce/orders/page GET 获取订单分页
/api/commerce/orders/create POST 创建订单
/api/commerce/orders/update POST 更新订单
/api/commerce/orders/delete POST 删除订单

获取订单详情

接口地址: GET /api/commerce/orders/detail

需要认证: 是

请求参数:

参数 类型 必填 说明
id int 订单 ID

响应示例:

{
  "success": true,
  "code": 200,
  "msg": "操作成功",
  "data": {
    "id": "1",
    "user_id": "1",
    "order_number": "ORD202601010001",
    "total_amount": 99.99,
    "status": "pending_payment",
    "payment_method": "alipay",
    "shipping_address": "配送地址",
    "shipping_fee": 10.0,
    "note": "订单备注",
    "create_time": "2026-01-01T00:00:00Z",
    "update_time": "2026-01-01T00:00:00Z",
    "paid_time": null,
    "shipped_time": null,
    "completed_time": null,
    "items": [
      {
        "id": "1",
        "item_id": "1",
        "item_name": "商品名称",
        "quantity": 1,
        "price": 99.99,
        "subtotal": 99.99
      }
    ]
  }
}

创建订单

接口地址: POST /api/commerce/orders/create

需要认证: 是

请求体:

{
  "items": [
    {
      "item_id": "1",
      "quantity": 1
    }
  ],
  "shipping_address": "配送地址",
  "note": "订单备注"
}

订单项管理

接口地址 方法 说明
/api/commerce/orders/item/detail GET 获取订单项详情
/api/commerce/orders/item/list GET 获取订单项列表

交易记录管理

接口地址 方法 说明
/api/commerce/orders/transaction/create POST 创建交易
/api/commerce/orders/transaction/detail GET 获取交易详情
/api/commerce/orders/transaction/list GET 获取交易记录列表
/api/commerce/orders/transaction/update POST 更新交易记录

评价管理

评价模块提供商品评价的创建、查询、回复等功能。

评价 CRUD

接口地址 方法 说明
/api/commerce/reviews/detail GET 获取评价详情
/api/commerce/reviews/list GET 获取评价列表
/api/commerce/reviews/page GET 获取评价分页
/api/commerce/reviews/create POST 创建评价
/api/commerce/reviews/update POST 更新评价
/api/commerce/reviews/delete POST 删除评价
/api/commerce/reviews/my GET 获取我的评价

获取评价列表

接口地址: GET /api/commerce/reviews/list

需要认证: 是

请求参数:

参数 类型 必填 说明
item_id string 商品 ID
user_id string 用户 ID
order_id string 订单 ID
rating int 评分(1-5)
status string 评价状态
is_anonymous boolean 是否匿名
order string 排序

创建评价

接口地址: POST /api/commerce/reviews/create

需要认证: 是

请求体:

{
  "item_id": "1",
  "order_id": "1",
  "rating": 5,
  "content": "商品很好用,非常满意!",
  "images": ["https://example.com/review1.jpg"],
  "is_anonymous": false
}

请求字段说明:

字段 类型 必填 说明
item_id string 商品 ID
order_id string 订单 ID
rating int 评分(1-5 星)
content string 评价内容
images string[] 评价图片 URL 列表
is_anonymous boolean 是否匿名评价

评价回复管理

接口地址 方法 说明
/api/commerce/reviews/reply/create POST 创建评价回复
/api/commerce/reviews/reply/delete POST 删除评价回复
/api/commerce/reviews/reply/list GET 获取评价回复列表

创建评价回复

接口地址: POST /api/commerce/reviews/reply/create

需要认证: 是

请求参数:

参数 类型 必填 说明
review_id string 评价 ID
content string 回复内容
is_official boolean 是否官方回复,默认为 false

收藏管理

收藏模块提供商品收藏功能。

接口地址 方法 说明
/api/commerce/favorites/add POST 添加收藏
/api/commerce/favorites/remove POST 取消收藏
/api/commerce/favorites/check GET 检查是否已收藏
/api/commerce/favorites/list GET 获取用户收藏列表

添加收藏

接口地址: POST /api/commerce/favorites/add

需要认证: 是

请求体:

{
  "item_id": "1"
}

检查是否已收藏

接口地址: GET /api/commerce/favorites/check

需要认证: 是

请求参数:

参数 类型 必填 说明
item_id string 商品 ID

响应示例:

{
  "success": true,
  "code": 200,
  "msg": "操作成功",
  "data": true
}

购物车管理

购物车模块提供购物车的管理功能。

接口地址 方法 说明
/api/commerce/carts/add POST 添加到购物车
/api/commerce/carts/update/{cart_id} PUT 更新购物车项
/api/commerce/carts/remove POST 删除购物车项
/api/commerce/carts/list GET 获取用户购物车
/api/commerce/carts/clear POST 清空购物车

添加到购物车

接口地址: POST /api/commerce/carts/add

需要认证: 是

请求体:

{
  "item_id": "1",
  "quantity": 2
}

更新购物车项

接口地址: PUT /api/commerce/carts/update/{cart_id}

需要认证: 是

路径参数:

参数 类型 必填 说明
cart_id string 购物车项 ID

请求体:

{
  "quantity": 3,
  "is_selected": true
}

获取用户购物车

接口地址: GET /api/commerce/carts/list

需要认证: 是

响应示例:

{
  "success": true,
  "code": 200,
  "msg": "操作成功",
  "data": [
    {
      "id": "1",
      "user_id": "1",
      "item_id": "1",
      "item_name": "商品名称",
      "item_price": 99.99,
      "item_thumbnail": "https://example.com/thumb.jpg",
      "quantity": 2,
      "is_selected": true,
      "subtotal": 199.98,
      "create_time": "2026-01-01T00:00:00Z",
      "update_time": "2026-01-01T00:00:00Z"
    }
  ]
}

软件管理

软件模块提供软件产品的销售和管理功能。

软件 CRUD

接口地址 方法 说明
/api/commerce/software/detail GET 获取软件详情
/api/commerce/software/list GET 获取软件列表
/api/commerce/software/page GET 获取软件分页
/api/commerce/software/create POST 创建软件
/api/commerce/software/update POST 更新软件
/api/commerce/software/delete POST 删除软件
/api/commerce/software/upload POST 上传软件文件
/api/commerce/software/duplicate POST 复制软件
/api/commerce/software/download GET 下载软件文件

获取软件详情

接口地址: GET /api/commerce/software/detail

需要认证: 是

请求参数:

参数 类型 必填 说明
id int 软件 ID

响应示例:

{
  "success": true,
  "code": 200,
  "msg": "操作成功",
  "data": {
    "id": "1",
    "code": "SOFT001",
    "name": "软件名称",
    "version": "1.0.0",
    "description": "软件描述",
    "detail": "软件详情",
    "category": "工具软件",
    "file_url": "https://example.com/software.zip",
    "file_size": 1024000,
    "file_type": "zip",
    "programming_language": "Python",
    "system_requirements": "Python 3.8+",
    "license_type": "MIT",
    "release_date": "2026-01-01",
    "status": "available",
    "is_active": true,
    "create_time": "2026-01-01T00:00:00Z",
    "update_time": "2026-01-01T00:00:00Z"
  }
}

上传软件文件

接口地址: POST /api/commerce/software/upload

需要认证: 是

请求参数: multipart/form-data

参数 类型 必填 说明
software_id int 软件 ID
file file 软件文件

下载软件文件

接口地址: GET /api/commerce/software/download

需要认证: 是

请求参数:

参数 类型 必填 说明
id int 软件 ID

响应: 文件下载


支付管理

支付模块提供支付宝和微信支付功能。

支付宝支付

支付宝支付下单

接口地址: POST /api/commerce/payments/alipay

需要认证: 是

请求体:

{
  "order_id": "1",
  "subject": "商品订单",
  "return_url": "https://example.com/return"
}

响应示例:

{
  "success": true,
  "code": 200,
  "msg": "下单成功",
  "data": {
    "provider": "alipay",
    "order_number": "ORD202601010001",
    "pay_url": "https://openapi.alipay.com/gateway.do?...",
    "code_url": null
  }
}

支付宝支付回调

接口地址: POST /api/commerce/payments/notify/alipay

需要认证: 否

说明: 支付宝异步回调接口,由支付宝服务器调用。


微信支付

微信支付下单

接口地址: POST /api/commerce/payments/wechat

需要认证: 是

请求体:

{
  "order_id": "1",
  "subject": "商品订单",
  "return_url": "https://example.com/return"
}

响应示例:

{
  "success": true,
  "code": 200,
  "msg": "下单成功",
  "data": {
    "provider": "wechat",
    "order_number": "ORD202601010001",
    "pay_url": "weixin://wxpay/bizpayurl?...",
    "code_url": "weixin://wxpay/bizpayurl?..."
  }
}

微信支付回调

接口地址: POST /api/commerce/payments/notify/wechat

需要认证: 否

说明: 微信支付异步回调接口,由微信支付服务器调用。


枚举类型说明

商品状态 (ItemStatus)

说明
available 可售
out_of_stock 缺货
discontinued 已下架

订单状态 (OrderStatus)

说明
pending_payment 待付款
paid 已付款
shipped 已发货
completed 已完成
cancelled 已取消

支付方式 (PaymentMethod)

说明
alipay 支付宝
wechat 微信支付
bank_transfer 银行转账

评价状态 (ReviewStatus)

说明
pending_review 待审核
approved 已审核
rejected 已拒绝

软件许可证类型 (SoftwareLicenseType)

说明
mit MIT 许可证
apache Apache 许可证
gpl GPL 许可证
proprietary 商业许可

使用示例

Python 示例

import requests

base_url = 'http://localhost:8000/api/commerce'
token = 'your_access_token'
headers = {'Authorization': f'Bearer {token}'}

# 创建商品
response = requests.post(
    f'{base_url}/items/create',
    headers=headers,
    json={
        'code': 'ITEM001',
        'name': '商品名称',
        'price': 99.99,
        'category': '电子产品',
        'status': 'available'
    }
)
print(response.json())

# 添加到购物车
response = requests.post(
    f'{base_url}/carts/add',
    headers=headers,
    json={
        'item_id': '1',
        'quantity': 2
    }
)
print(response.json())

# 创建订单
response = requests.post(
    f'{base_url}/orders/create',
    headers=headers,
    json={
        'items': [{'item_id': '1', 'quantity': 2}],
        'shipping_address': '配送地址'
    }
)
print(response.json())

# 支付宝支付
response = requests.post(
    f'{base_url}/payments/alipay',
    headers=headers,
    json={
        'order_id': '1',
        'subject': '商品订单',
        'return_url': 'https://example.com/return'
    }
)
print(response.json())

# 创建评价
response = requests.post(
    f'{base_url}/reviews/create',
    headers=headers,
    json={
        'item_id': '1',
        'order_id': '1',
        'rating': 5,
        'content': '商品很好用!'
    }
)
print(response.json())

JavaScript 示例

// 获取商品列表
async function getItems(token, filters = {}) {
  const params = new URLSearchParams(filters);
  const response = await fetch(
    `http://localhost:8000/api/commerce/items/list?${params}`,
    {
      headers: { Authorization: `Bearer ${token}` },
    }
  );
  return await response.json();
}

// 添加到购物车
async function addToCart(token, itemId, quantity) {
  const response = await fetch("http://localhost:8000/api/commerce/carts/add", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${token}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ item_id: itemId, quantity }),
  });
  return await response.json();
}

// 创建订单
async function createOrder(token, orderData) {
  const response = await fetch(
    "http://localhost:8000/api/commerce/orders/create",
    {
      method: "POST",
      headers: {
        Authorization: `Bearer ${token}`,
        "Content-Type": "application/json",
      },
      body: JSON.stringify(orderData),
    }
  );
  return await response.json();
}

// 支付
async function alipay(token, paymentData) {
  const response = await fetch(
    "http://localhost:8000/api/commerce/payments/alipay",
    {
      method: "POST",
      headers: {
        Authorization: `Bearer ${token}`,
        "Content-Type": "application/json",
      },
      body: JSON.stringify(paymentData),
    }
  );
  return await response.json();
}

注意事项

  1. 订单创建: 创建订单时会自动扣减库存,订单取消或超时会自动释放库存。
  2. 支付回调: 支付回调接口不需要认证,但需要验证签名的合法性。
  3. 评价规则: 每个订单每个商品只能评价一次,评价后不可修改。
  4. 库存管理: 库存不足时商品不可购买,需要管理员补充库存。
  5. 文件上传: 图片和附件上传使用 multipart/form-data 格式,注意文件大小限制。
  6. 软件下载: 已购买的软件才能下载,下载权限通过购买记录验证。
  7. 价格计算: 订单总金额 = 商品价格 × 数量 + 运费 - 优惠金额。
  8. 购物车清理: 创建订单后,已选中的购物车项会自动清空。

相关文档

本文由人工编写,AI优化,转载请注明原文地址: 超腾开源平台商业模块

评论 (0)

发表评论

昵称:加载中...

暂无评论,快来发表第一条评论吧!