产品
产品列表
curl -i "http://example.com/api/products.json"
```json
{
"status": {
"code": 200,
"message": "OK"
},
"products": [
{
"id": 14,
"name": "爱客进销存9324",
"number": "AA99880",
"image": "https://ikjxc-files.ikcrm.com/Fi3ihX16W0u1omLp0Qns7UuJH5FX?imageView2/0/w/200/h/200",
"unit": "5",
"enable": true,
"sale_prices": []
},
{
"id": 12,
"name": "爱客进销存9324",
"number": "CP001999",
"image": "https://ikjxc-files.ikcrm.com/FkPuGWwDCKk1W3BHeIoFZhwX94LV?imageView2/0/w/200/h/200",
"unit": "套",
"enable": true,
"sale_prices": [
"20.1100"
]
}
]
}
HTTP 请求
GET http://example.com/api/products
请求参数
参数名 | 是否必须 | 说明 |
---|---|---|
keyword | 否 | 关键词模糊查询,支持产品名称、规格、编号、条形码、属性名称 |
warehouse_id | 否 | 根据仓库ID筛选产品 |
product_category_id | 否 | 根据产品分类ID筛选产品 |
inventory_zero | 否 | 零库存过滤, only_zero 表示只查零库存, hide_zero 表示忽略零库存 |
enabled | 否 | 是否禁用,true 表示查询可用的 |
created_at | 否 | 创建时间(created_at=’2024-01-01/2024-03-15’ 或者Unix时间戳毫秒级格式 created_at=’1710401628293/1710401628299’; 注意日期之间用/隔开 ) |
updated_at | 否 | 更新时间(updated_at=’2024-01-01/2024-03-15’ 或者Unix时间戳毫秒级格式 updated_at=’1710401628293/1710401628299’; 注意日期之间用/隔开 ) |
sort | 否 | 排序字段(仅支持created_at, updated_at) |
order | 否 | 排序方式(仅支持desc, asc) |
- 返回字段说明
返回值字段 | 字段类型 | 说明 |
---|---|---|
id | integer | 产品ID |
name | string | 产品名称 |
number | string | 产品编号 |
spec | string | 产品规格 |
image | string | 产品图片 |
unit | string | 产品单位 |
enable | boolean | 是否启用 |
sale_prices | Array | 多单位会/多规格 会根据价格策略显示多个 销售价格 |
created_at | string | 创建时间 |
updated_at | string | 更新时间 |
产品详情
根据产品ID,获取产品详细信息。
curl -i "http://example.com/api/products/:id.json"
{
"status": {
"code": 200,
"message": "OK"
},
"product": {
"id": 1,
"name": "测试商品1",
"number": "DG001",
"spec": "XS",
"status": "enabled",
"default_unit_id": 36,
"image": "",
"category": "默认种类",
"note": "aa",
"barcode": "DG001",
"created_at": "2023-07-20 16:13:11",
"updated_at": "2023-07-20 16:13:11",
"attr_status": "attr_closed",
"unit_setting": "single_unit",
"price_policy_setting": "unit_policy",
"serial_code_status": "serial_closed",
"split_warning_status": "split_closed",
"total_warning_status": "total_closed",
"batch_status": "batch_closed",
"life_warning_days": 0,
"life_period": 0,
"attr_warning_status": "attr_warning_closed",
"unit": "个",
"sale_prices": [
"20.0000"
],
"product_attr_groups_attributes": [
{
"id": 1,
"category": "default_attr",
"number": "xxx",
"product_attr_names": "",
"product_attr_ids": "",
"unit_cost": "9.99",
"total_quantity": "76,637.90",
"warehouses": [
{
"id": 23,
"name": "zxcvsadfzx21",
"quantity": "65,457.55"
},
{
"id": 1,
"name": "测试仓库",
"quantity": "48.00"
}
],
"price_policy_attributes": {
"id": 339,
"sale_price": "0.0000",
"purchase_price": "0.0000",
"_destroy": false
}
}
],
"product_images": [],
"unit_id": 36,
"unit_name": "个",
"current_warning_policy": "",
"inventory": "76,637.90",
"price": "10.0",
"sale_price": "20.0",
"purchase_price": "10.0",
"product_category_id": 13,
"product_unit_id": 131,
"image_info": {
"id": null,
"name": null
},
"warehouses": [
{
"id": 23,
"name": "zxcvsadfzx21",
"quantity": "65,457.55"
},
{
"id": 4,
"name": "111",
"quantity": "11.00"
}
],
"product_image_ids": [],
"product_units_attributes": [
{
"id": 131,
"name": "个",
"unit_id": 36,
"unit_name": "个",
"conversion": "1",
"_destroy": false,
"price_policy_attributes": {
"id": 343,
"sale_price": "20.0000",
"purchase_price": "10.0000",
"_destroy": false
}
}
],
"product_attrables_attributes": [],
"has_related_documents": true
}
}
HTTP 请求
GET /api/products/:id.json
请求参数
参数名 | 是否必须 | 说明 |
---|---|---|
id | 必须 | 产品ID |
- 返回字段说明
返回值字段 | 字段类型 | 说明 |
---|---|---|
id | integer | 产品ID |
name | string | 名称 |
number | string | 编号 |
spec | string | 规格 |
status | string | 状态(启用/禁用)disabled 表示禁用,enabled 表示启用 |
default_unit_id | integer | 默认单位ID |
image | string | 图片 |
category | string | 分类名称 |
note | string | 备注 |
barcode | string | 条形码 |
attr_status | string | 是否开启附属属性,attr_closed 表示关闭,attr_opened 表示开启 |
unit_setting | string | 单位设置,single_unit 表示单单位,multi_unit 表示多单位 |
price_policy_setting | string | 价格策略设置,unit_policy 表示按单位,product_attr_policy 表示按属性, multi_unit_policy 表示按多单位 |
serial_code_status | string | 是否开启序列号,serial_closed 表示关闭,serial_opened 表示开启 |
split_warning_status | string | 是否开启分仓预警,split_closed 表示关闭,split_opened 表示开启 |
total_warning_status | string | 是否开启全仓预警,total_closed 表示关闭,total_opened 表示开启 |
batch_status | string | 是否开启批次号,batch_closed 表示关闭,batch_opened 表示开启 |
life_warning_days | integer | 保质期预警天数 |
life_period | integer | 保质期天数 |
attr_warning_status | string | 是否开启按属性预警,attr_warning_closed 表示关闭,attr_warning_opened 表示开启 |
unit | string | 单位名称 |
sale_prices | array | 售出价格数组 |
product_attr_groups_attributes[id] | integer | 产品属性组ID |
product_attr_groups_attributes[catgegory] | string | 类别,default_attr 表示默认属性,custom_attr 表示多属性 |
product_attr_groups_attributes[number] | string | 编号 |
product_attr_groups_attributes[product_attr_names] | string | 属性组名 |
product_attr_groups_attributes[product_attr_ids] | string | 属性ids |
product_attr_groups_attributes[unit_cost] | float | 单位成本 |
product_attr_groups_attributes[total_quantity] | string | 总数量 |
product_attr_groups_attributes[warehouses][id] | integer | 仓库ID |
product_attr_groups_attributes[warehouses][name] | string | 仓库名称 |
product_attr_groups_attributes[warehouses][quantity] | string | 该产品属性组的产品在此仓库的数量 |
product_attr_groups_attributes[price_policy_attributes][id] | integer | 价格策略ID |
product_attr_groups_attributes[price_policy_attributes][sale_price] | string | 销售价格 |
product_attr_groups_attributes[price_policy_attributes][purchase_price] | string | 采购价格 |
product_images[id] | integer | 产品图片ID |
product_images[filename] | string | 产品图片名称 |
product_images[url] | string | 产品图片链接 |
product_images[dn_key] | string | 产品图片key |
unit_id | integer | 单位ID |
unit_name | string | 单位名称 |
current_warning_policy | string | 当前预警策略 |
inventory | string | 产品总库存 |
price | string | 价格 |
sale_price | string | 销售价格 |
purchase_price | string | 采购价格 |
product_category_id | integer | 产品分类ID |
product_unit_id | integer | product_unit 的ID |
image_info[id] | integer | 产品主图ID |
image_info[name] | string | 产品主图名称 |
warehouses[id] | integer | 仓库ID |
warehouses[name] | string | 仓库名称 |
warehouses[quantity] | string | 该产品在此仓库的数量 |
product_image_ids | array | 产品图片IDs |
product_units_attributes[id] | integer | 产品单位ID |
product_units_attributes[name] | string | 产品单位名称 |
product_units_attributes[unit_id] | integer | 关联单位ID |
product_units_attributes[unit_name] | string | 关联单位名称 |
product_units_attributes[conversion] | string | 与基本单位的转换率 |
product_units_attributes[price_policy_attributes][id] | integer | 价格策略ID |
product_units_attributes[price_policy_attributes][sale_price] | string | 销售价格 |
product_units_attributes[price_policy_attributes][purchase_price] | string | 采购价格 |
product_attrables_attributes[id] | integer | 产品与属性中间表ID |
product_attrables_attributes[product_id] | integer | 产品ID |
product_attrables_attributes[product_attr_id] | integer | 属性ID |
has_related_documents | boolean | 是否关联单据 |
概念:加权平均法,指以本月全部收货数量加月初存货数量作为权数,去除本月全部收货成本加上月初存货成本,计算出存货的加权平均单位成本,从而确定存货的发出和存货成本
计算公式:
存货单位成本 = 月初结存金额 +(∑本月各批收货的实际单位成本 * 本月各批收货数量)/ 月初结存数量 + 本月各批收货数量之和
本月发出存货成本 = 本月发出存货数量 * 存货单位成本
月末库存存货成本 = 月末库存存货数量 * 存货单位成本
查询产品属性组
curl -i "http://example.com/api/products/query_product_attr_groups.json"
HTTP 请求
GET http://example.com/api/products/query_product_attr_groups
请求参数
参数名 | 是否必须 | 说明 |
---|---|---|
keyword | 否 | 关键词模糊查询,支持产品名称、规格、编号、条形码、属性名称 |
warehouse_id | 否 | 仓库ID |
product_category_id | 否 | 产品分类ID |
zero_inventory_filter | 否 | 零库存过滤,only 表示只查零库存,not 表示忽略零库存 |
enabled | 否 | 是否禁用,true 表示查询可用的 |
product_id | 否 | 产品ID |
{
"status": {
"code": 200,
"message": "OK"
},
"product_attr_groups": [
{
"id": 577,
"product_attr_names": "",
"product_attr_ids": "",
"quantity": "3.00",
"total_quantity": "3.00",
"product": {
"id": 318,
"name": "cxp序列号产品a",
"number": "CP0118",
"spec": "",
"image": "",
"unit": "部"
}
},
{
"id": 593,
"product_attr_names": "ddd-0",
"product_attr_ids": "32",
"quantity": "0.00",
"total_quantity": "0.00",
"product": {
"id": 327,
"name": "cxpuuie0098",
"number": "CP0130",
"spec": "",
"image": "",
"unit": "vaa"
}
},
{
"id": 578,
"product_attr_names": "",
"product_attr_ids": "",
"quantity": "1.00",
"total_quantity": "1.00",
"product": {
"id": 319,
"name": "cxp批次号产品a",
"number": "CP0119",
"spec": "",
"image": "",
"unit": "部"
}
}
]
}
- 返回字段说明
返回值字段 | 字段类型 | 说明 |
---|---|---|
id | integer | 产品属性组ID |
product_attr_names | string | 产品属性组名称 |
product_attr_ids | string | 属性id |
quantity | string | 数量,当请求参数包含warehouse_id时,表示该仓库数量,否则表示所有仓库总数量 |
total_quantity | string | 所有仓库总数量 |
product[id] | integer | 产品ID |
product[name] | string | 产品名称 |
product[number] | string | 产品编号 |
product[spec] | string | 产品规格 |
product[image] | string | 产品图片 |
product[unit] | string | 产品单位 |
创建产品
根据提供的数据,创建产品。
curl -i -X POST "http://example.com/api/products.json"
{
"id": 1,
"name": "香草冰激凌",
"number": "ICE0001",
"category": "冷饮",
"spec": "GTX001",
"unit": "只",
"price": 1000.0,
"total_quantity": 200,
"note": "这是备注哦",
"product_images": [
{
"url": "http://"
},
{
"url": "http://"
}
]
}
HTTP 请求
POST /api/products.json
请求参数
参数名 | 是否必须 | 说明 |
---|---|---|
name | 必须 | 名称 |
number | 必须 | 编号 |
product_category_id | 必须 | 类型 |
spec | 不必须 | 规格 |
unit | 不必须 | 单位 |
price | 不必须 | 单价 |
note | 不必须 | 备注 |
product_images_attruibutes | 不必须 | 图片 |
- 返回字段说明
返回值字段 | 字段类型 | 说明 |
---|---|---|
id | integer | ID |
name | string | 名称 |
number | string | 编号 |
category | string | 类型 |
spec | string | 规格 |
unit | string | 单位 |
price | decimal | 单价 |
image | string | 图片链接 |
结账功能
根据结账日期,对所有单据日期内的产品进行结账计算,每次结账后会得出产品的单位成本。
传递具体日期给进销存api,按以下顺序执行:
(1)先判断日期格式是否符合规范:
case1:不符合则返回错误提示:日期格式不正确
case2:符合规范则执行第(2)点
(2)判断该企业是否连一个结账日期都没有,
case1:没有则允许进行结账:
结账成功,返回提示:结账成功
结账失败,返回提示:结账失败,请重试
case2:有结账日期,则则执行第(3)点
(3)判断该日期是否大于该企业最后一次结账的日期:
case1:不大于则返回错误提示:结账日期不能小于或等于上一次结账日期
case2:大于,则进行结账。
结账成功,返回提示:结账成功
结账失败,返回提示:结账失败,请重试
curl -i POST "http://example.com/api/settlements/execute.json"
{
"status": {
"code": 200,
"message": "OK"
}
}
HTTP 请求
POST /api/settlements/execute.json
请求参数
参数名 | 是否必须 | 说明 |
---|---|---|
settled_on | 必须 | 指定结账日期(日期格式:YYYY-MM-DD) |
force_settle | 否 | Integer 1: 强制结账, 0: 有未完结单据时不进行结账,返回错误提示。 |
force_settle = 1 结账时如有未完结状态的单据也进行结账,但待审批的单据结账后单据将无法审批通过;
force_settle = 0 结账时先检查账期内是否有未完结的单据,有则不结账并返回错误提示。
- 返回字段说明
返回值字段 | 字段类型 | 说明 |
---|---|---|
status | Object | 请求状态 |
查询产品属性的单位成本
批量查询产品属性在某个结账期内的单位成本,用户同时传递 {产品属性ID(支持批量)} + 具体日期(结账日期)给进销存:
(1)判断传递过来的日期(假设为M)落在哪一个账期内,取大于或等于M的那个结账日期,返回每个产品属性ID 及 对应产品属性在该结账日期的单位成本
例如:已经有结账日期 A,B,C和最新。如果接口获得日期M,则判断M落在哪两个结账日期之间,然后取大于或等于M的那个结账日期。
如:B < M < C 或 M = C, 则取 C
如:C < M 或 连一个可比较的结账日期都没有,则取最新单位成本
如:M < A,则取 A
curl -i "http://example.com/api/product_attr_groups/get_unit_price.json"
{
"status": {
"code": 200,
"message": "OK"
},
"product_attr_groups": [
{
"id": 1,
"product_attr_names": "红色/L",
"number": "",
"total_quantity": "100.0",
"unit_cost_price": "0.0"
},
{
"id": 2,
"product_attr_names": "白色/M",
"number": "",
"total_quantity": "1465.0",
"unit_cost_price": "0.0"
}
]
}
HTTP 请求
GET /api/product_attr_groups/get_unit_price.json
请求参数
参数名 | 是否必须 | 说明 |
---|---|---|
settled_on | 必须 | 指定结账日期,为空时给出最新(实时计算后的)单位成本 |
ids | 必须 | 一个或多个产品属性ID, 多个时使用,分割,最多100个 |
- 返回字段说明
返回值字段 | 字段类型 | 说明 |
---|---|---|
status | Object | 请求状态 |
product_attr_groups | Object | 产品属性对象 |
product_attr_names | string | (多)属性名称 |
total_quantity | decimal | 库存总数量 |
unit_cost_price | decimal | 单位成本 |