Skip to content

一、数据库设计

1.原料表:material

{
    '_id': 1234,
    'name': '猪',
    'unit_name': '头',
    'create_time': '创建时间',
    'update_time': '更新时间',
    'stock': 88,
    'avg_price': 120,
    'status': 1-未删除,2-已删除,
    'station_id': 'T002',
}

索引:
    1.{'station_id': 1, 'name': 1}

2.配方表:formula

{
    '_id': 12345',
    'name': '配方名',
    'desc': '配方描述',
    'materials': [
        {
            'material_id': 'YL1234',
            'quantity': 2,
        },
        {
            'material_id': 'YL4321',
            'quantity': 1,
        },
    ],
    'products': [
        {
            'sku_id': 'D12345',
            'quantity': 5,
        },
        {
            'sku_id': 'D54321',
            'quantity': 2,
        },
    ],
    'creator': '创建人',
    'create_time': '创建时间',
    'modifier': '修改的人',
    'update_time': 'xxxxxx',
    'status': 1-未删除;2-已删除,
    'station_id': 'T002',
}

索引:
    1.{'station_id': 1, 'name': 1}

3.原料入库单表:material_stock_in

{
    '_id': '入库单ID',
    'create_time': '建单时间',
    'creator': '建单人',
    'in_stock_time': '入库时间',
    'supplier_id': '供应商ID',
    'total_price': 12345,           # 入库金额
    'total_item_price': 10000,      # 商品金额
    'total_discount_price': 2345,   # 折让金额
    'status': 1-未入库;2-已入库;3-已冲销,
    'details': [
        {
            'material_id': 'YL1234',
            'price': 120,
            'quantity': 30,
            'item_price': 30 x 120,
            'operator': '操作人ID',
        },
    ],
    // 分摊
    'share': [
        {
            'operate_time': '操作时间',
            'reason': 1-运输费用分摊;2-其他费用分摊,
            'money': 1234,
            'action': 1-加钱;2-减钱, 
            'method': 1-金额分摊; 2-入库数分摊,
            'remark': '备注',
            'operator': '操作人ID',
        }
    ],
    // 折让
    'discount':[
        {
            'operate_time': '操作时间',
            'reason': 1-运输费用分摊;2-其他费用分摊,
            'action': 1-加钱;2-减钱,
            'money': 1234,
            'remark': '备注',
            'operator': '操作人ID',
        }
    ],
    'station_id': 'k10admin',
}

索引:
    1.{'station_id': 1, 'create_time': -1, 'status': 1}
    2.{'station_id': 1, 'in_stock_time': -1, 'status': 1}

4.原料出库单表:material_stock_out

{
    '_id': '出库单ID',
    'create_time': '建单时间',
    'creator': '建单人',
    'modifier': '修改人',
    'update_time': '修改时间',
    'out_stock_time': '出库时间',
    'total_price': 123434,
    'status': 1-未出库;2-已出库,

    'details': [{
        'meterial_id': 12345,
        'quantity': 33,
        'price': 100,
        'total_item_price': 100 x 33,
        'fomula_id': 12345,
        'operator': 'k10admin',
        'create_time': '添加时间',
        'update_time': '修改时间',
    }],
    'station_id': 'k10admin',
}

索引:
    1.{'station_id': 1, 'create_time': -1, 'status': 1}
    2.{'station_id': 1, 'out_stock_time': -1, 'status': 1}

5.原料退货单: material_stock_return

{
    '_id': 'T002-YLTHD-2016-09-04-00008',
    'return_stock_time': '退货时间',
    'create_time': '建单时间',
    'creator': '建单人',
    'supplier_id': '供应商ID',
    'total_price': 12000,
    'status': 1-已退货;2-未退货;3-已冲销,
    'details': [
        {
            'material_id': 'YL12345',
            'quantity': 20,
            'price': 240,
            'total_item_price': 20 x 240,
            'operator': 'username',
        }
    ],
    // 分摊
    'share': [
        {
            'operate_time': '操作时间',
            'reason': 1-运输费用分摊;2-其他费用分摊,
            'money': 1234,
            'action': 1-加钱;2-减钱, 
            'method': 1-金额分摊; 2-入库数分摊,
            'remark': '备注',
            'operator': '操作人ID',
        }
    ],
    // 折让
    'discount':[
        {
            'operate_time': '操作时间',
            'reason': 1-运输费用分摊;2-其他费用分摊,
            'action': 1-加钱;2-减钱,
            'money': 1234,
            'remark': '备注',
            'operator': '操作人ID',
        }
    ],
    'station_id': 'T002',
}

索引:
    1.{'station_id': 1, 'create_time': -1, 'status': 1}
    2.{'station_id': 1, 'return_stock_time': -1, 'status': 1}

6.原料报损、报溢表:material_stock_check

{
    '_id': '报损或报溢记录ID',
    'material_id': '原料ID',
    ’type': 1-报溢;2-报损;
    'remain_stock': 99, # 抄盘数
    'input_stock': 100, # 实盘数
    ’price': 111,
    'quantity': 10,
    'total_price': 111 x 10
    'operator': '操作人ID',
    'create_time': '记录插入时间',
    'station_id': 'T002',
}

索引:
    1.{'station_id': 1, 'type': 1, 'material_id': 1}

7.原料入库、出库、退货记录表:material_stock_log

{
    '_id': ObjectId('xxxxx'),
    'material_id': 12343, # 原料ID
    'supplier_id': 'T131', # 供应商ID
    'change_type': 1, # 变动类型:1-入库;2-出库;3-退货
    'change_stock_id': 'xxx', # 入库/出库/退货单ID
    'status': 1, # 状态:1-删除;2-正常;
    'quantity': 30, # 变动数量
    'price': 120, # 变动价格
    'total_price': 30 x 120, # 变动金额
    'create_time': '创建时间',
    'station_id': 'T002',
    'modifier': 'user id', # 修改人
    'update_time': '修改时间',
}

二、原料管理

1.拉取原料列表

接口名:/materials
Method:GET
请求参数:
    station_id      M   string          站点ID
    search_text O   string          搜索文本
    export          O   int             是否导出:0-不导出,默认;1-导出;
    offset          O   int             分页offset
    limit           O   int             分页limit
响应:
    code    M   int     返回码,0表示成功,其他表示错误
    msg     M   string  返回信息
    data    M   list    返回json数据,结构看示例

示例:
request:
    GET http://api.guanmai.cn/v1/materials?station_id=T002

response:
    {   
        'code': 0,
        'data': {
            'offset': 0,
            'limit': 20,
            'count': 100,
            'list': [
                {
                    'id':11112,             # 原料ID
                    'name': '猪',            # 原料名称
                    'stock': 38,            # 库存数量
                    'unit_name': '斤',  # 单位
                }
            ],
        'msg': 'ok',
    }

2.新建原料

接口名:/materials/
Method:POST
请求参数:
    station_id      M   string          站点ID
    name            M   string          原料名称
    unit_name       M   string          原料单位

响应:
    code    M   int     返回码,0表示成功,其他表示错误
    msg     M   string  返回信息
    data    M   dict    成功新建的原料信息,结构见示例

示例:
request:
    POST http://api.guanmai.cn/v1/materials
    POST参数:
        name:'猪'
        unit_name: '头'

response:
    {   
        'code': 0,
        'msg': 'ok',
        'data': {
            'id': 1334343,
        },
    }

3.编辑原料

接口名:/materials/{{material_id}}
Method:PUT
请求参数:
    station_id  M   string          站点ID
    material_id M   int             原料ID
    stock           M   int             库存数量

响应:
    code    M   int     返回码,0表示成功,其他表示错误
    msg     M   string  返回信息

示例:
request:
    PUT http://api.guanmai.cn/v1/materials/11333
    PUT参数:
        stock:20

response:
    {   
        'code': 0,
        'msg': 'ok',
    }

4.删除原料

接口名:/materials/{{station_id}}/{{material_id}}
Method:DELETE
请求参数:
    station_id      M   string          站点ID
    material_id M   int             原料ID

响应:
    code    M   int     返回码,0表示成功,其他表示错误
    msg     M   string  返回信息

示例:
request:
    DELETE http://api.guanmai.cn/v1/materials/T002/11333

response:
    {   
        'code': 0,
        'msg': 'ok',
    }

三、配方

1.拉取配方列表

接口名:/formulas
Method:GET
请求参数:
    station_id      M   string          站点ID
    search_text O   string          搜索文本
    export          O   int             是否导出:0-不导出,默认;1-导出;
    offset          O   int             分页offset
    limit           O   int             分页limit
响应:
    code    M   int     返回码,0表示成功,其他表示错误
    msg     M   string  返回信息
    data    M   list    返回json数据,结构看示例

示例:
request:
    GET http://api.guanmai.cn/v1/formulas?station_id=xxx

response:
    {   
        'code': 0,
        'data': {
            'offset': 0,
            'limit': 20,
            'count': 100,
            'list': [
                {
                    'id':11112,             # 配方ID
                    'name': '猪的配方', # 配方名称
                    'desc': '描述',       # 配方描述                  }
            ],
        'msg': 'ok',
    }

2.拉取配方详情

接口名:/formulas/{{formula_id}}
Method:GET
请求参数:
    formula_id  M   int         配方ID
响应:
    code    M   int     返回码,0表示成功,其他表示错误
    msg     M   string  返回信息
    data    M   json    配方信息
示例:
request:
    GET http://api.guanmai.cn/v1/formulas/113332

response:
    {   
        'code': 0,
        'msg': 'ok',
        'data': {
            '_id': 12345,
            'name': '配方名',
            'desc': '配方描述',
            'materials': [
                {
                    'material_id': 1234,
                    'quantity': 2,
                },
                {
                    'material_id': 4321,
                    'quantity': 1,
                },
            ],
            'products': [
                {
                    'sku_id': 'D12345',
                    'quantity': 5,
                },
                {
                    'sku_id': 'D54321',
                    'quantity': 2,
                },
            ],
            'creator': '创建人',
            'create_time': '创建时间',
            'modifier': '修改的人',
            'update_time': 'xxxxxx',
            'status': 1-未删除;2-已删除,
            'station_id': 'T002',
        },
    }

3.新建配方

接口名:/formulas/
Method:POST
请求参数:
    station_id      M   string          站点ID
    name            M   string          配方名称
    desc            M   string          描述
    materials       M   json            原料ID、数量列表
    products        M   json            成本ID、数量列表

响应:
    code    M   int     返回码,0表示成功,其他表示错误
    msg     M   string  返回信息
    data    M   dict    新建的配方信息 
示例:
request:
    POST http://api.guanmai.cn/v1/formulas
    POST参数:
        name:'猪的配方'
        desc: '猪的配方描述'
        materials: [{'id': 11132, 'quantity': 30}]
        products: [{'id': 'D12234', 'quantity': 20, 'amount_proportion':12.00}]

response:
    {   
        'code': 0,
        'msg': 'ok',
        'data': {
            'id': 123434,
        },
    }

4.编辑配方

接口名:/formulas/{{formula_id}}
Method:PUT
请求参数:
    station_id      M   string          站点ID
    formula_id  M   int             配方ID
    name            M   string      配方名称
    desc            M   string          配方描述

响应:
    code    M   int     返回码,0表示成功,其他表示错误
    msg     M   string  返回信息

示例:
request:
    PUT http://api.guanmai.cn/v1/materials/formulas/11333
    PUT参数:
        station_id: T002
        name: '改个名字'
        desc: '改个描述'

response:
    {   
        'code': 0,
        'msg': 'ok',
    }

5.删除配方

接口名:/formulas/{{station_id}}/{{formula_id}}
Method:DELETE
请求参数:
    station_id      M   string          站点ID
    formula_id  M   int             配方ID

响应:
    code    M   int     返回码,0表示成功,其他表示错误
    msg     M   string  返回信息

示例:
request:
    DELETE http://api.guanmai.cn/v1/materials/formulas/T002/11333

response:
    {   
        'code': 0,
        'msg': 'ok',
    }

四、入库单

1.拉取入库单列表

接口名:/materials/stock/in
Method:GET
请求参数:
    station_id      M   string          站点ID
    time_type       M   string          时间类型:1-按入库时间搜索;2-按建单时间搜索;
    start_date  M   string          开始日期
    end_date        M   string          截止日期
    status          O   int             状态
    search_text O   string          搜索文本
    export          O   int             是否导出:0-不导出,默认;1-导出;
    offset          O   int             分页offset
    limit           O   int             分页limit
响应:
    code    M   int     返回码,0表示成功,其他表示错误
    msg     M   string  返回信息
    data    M   list    返回json数据,结构看示例

示例:
request:
    GET http://api.guanmai.cn/materials/stock/in?station_id=T002&time_type=1&start_date=2016-10-25&end_date=2016-10-26

response:
    {   
        'code': 0,
        'data': {
            'offset': 0,
            'limit': 20,
            'count': 100,
            'list': [
                {
                    'id':11112,                 # 入库单ID
                    'in_stock_time': '2016-10-24', # 入库时间
                    'supplier_id': 'T131',      # 供应商ID
                    ‘supplier_name': '阿米巴13', # 供应商名称
                    'money': 1111,      # 入库金额
                    'status': 2,        # 状态                    }
            ],
        'msg': 'ok',
    }

2.拉取入库单详情

接口名:/materials/stock/in/{{in_stock_id}}
Method:GET
请求参数:
    in_stock_id     M   int         入库单ID

响应:
    code    M   int     返回码,0表示成功,其他表示错误
    msg     M   string  返回信息
    data    M   json    入库单信息
示例:
request:
    GET http://api.guanmai.cn/v1/materials/stock/in/113332

response:
    {   
        'code': 0,
        'msg': 'ok',
        'data': {
            '_id': 11234, # 入库单ID
            'create_time': '建单时间',
            'creator': '建单人',
            'in_stock_time': '入库时间',
            'supplier_name': '供应商名称',
            'total_price': 12345,           # 入库金额
            'total_item_price': 10000,      # 商品金额
            'total_discount_price': 2345,   # 折让金额
            'status': 1-未入库;2-已入库;3-已冲销,
            'details': [
                {
                    'material_id': 1234,
                    'price': 120,
                    'quantity': 30,
                    'total_item_price': 30 x 120,
                    'operator': '操作人',
                },
            ],
            // 分摊
            'share': [
                {
                    'operate_time': '操作时间',
                    'reason': 1-运输费用分摊;2-其他费用分摊,
                    'money': 1234,
                    'action': 1-加钱;2-减钱, 
                    'method': 1-金额分摊; 2-入库数分摊,
                    'remark': '备注',
                    'operator': '操作人ID',
                }
            ],
            // 折让
            'discount':[
                {
                    'operate_time': '操作时间',
                    'reason': 1-运输费用分摊;2-其他费用分摊,
                    'action': 1-加钱;2-减钱,
                    'money': 1234,
                    'remark': '备注',
                    'operator': '操作人ID',
                }
            ],
            'station_id': 'k10admin',
        }
    }

3.新建入库单

接口名:/materials/stock/in
Method:POST
请求参数:
    station_id      M   string          站点ID
    supplier_id     M   string          供应商ID
    status          M   int             1-未入库;2-已入库
    details         M   json            原料信息,结构见示例
    share           O   json            分摊信息,结构见示例
    discount        O   json            折让信息,结构见示例

响应:
    code    M   int     返回码,0表示成功,其他表示错误
    msg     M   string  返回信息
    data    M   dict    新建的入库单ID信息

示例:
request:
    POST http://api.guanmai.cn/v1/materials/stock/in
    POST参数:
        station_id: 'T002'
        supplier_id:'T131'
        in_stock_time: '2015-02-02 10:00'
        status: 1
        details: [{'id': 11132, 'quantity': 30, 'price': 20}]
        share: [{'reason': 1, 'money': 20, 'action': 1, 'method': 1, 'remark': 'remark',}]
        discount: [{'reason': 1, 'action': 1, 'money': 40, 'remark': 'test'}]

response:
    {   
        'code': 0,
        'msg': 'ok',
        'data': {
            'id': 134343,
        },
    }

4.编辑入库单

接口名:/materials/stock/in/{{in_stock_id}}
Method:PUT
请求参数:
    in_stock_id     M int               入库单ID
    in_stock_time   M   string          入库时间
    status          M   int             状态
    details         M   json            原料信息,结构见示例
    share           O   json            分摊信息,结构见示例
    discount        O   json            折让信息,结构见示例


响应:
    code    M   int     返回码,0表示成功,其他表示错误
    msg     M   string  返回信息

示例:
request:
    PUT http://api.guanmai.cn/v1/materials/stock/in/13133
    PUT参数:
        in_stock_id: 13133
        in_stock_time: '2015-02-02 10:00'
        status: 1
        details: [{'id': 11132, 'quantity': 30, 'price': 20, 'operator': 'user_id'}]
        share: [{'reason': 1, 'money': 20, 'action': 1, 'method': 1, 'remark': 'remark', 'create_time': '', 'operator': 'user_id'}]
        discount: [{'reason': 1, 'action': 1, 'money': 40, 'remark': 'test', 'create_time': '', 'operator': 'user_id'}]


response:
    {   
        'code': 0,
        'msg': 'ok',
    }

5.入库单冲销

接口名:/materials/stock/in/{{in_stock_id}}/cancel
Method:PUT
请求参数:
    station_id      M   string      站点ID
    in_stock_id M   int         入库单ID

响应:
    code    M   int     返回码,0表示成功,其他表示错误
    msg     M   string  返回信息

示例:
request:
    PUT http://teststation.guanmai.cn/materials/stock/in/11333/cancel
    PUT参数:
        station_id: T002

response:
    {   
        'code': 0,
        'msg': 'ok',
    }

五、出库单

1.拉取出库单列表

接口名:/materials/stock/out
Method:GET
请求参数:
    station_id      M   string          站点ID
    time_type       M   string          时间类型:1-按出库时间搜索;2-按建单时间搜索;
    start_date  M   string          开始日期
    end_date        M   string          截止日期
    status          O   int             状态
    search_text O   string          搜索文本
    export          O   int             是否导出:0-不导出,默认;1-导出;
    offset          O   int             分页offset
    limit           O   int             分页limit
响应:
    code    M   int     返回码,0表示成功,其他表示错误
    msg     M   string  返回信息
    data    M   list    返回json数据,结构看示例

示例:
request:
    GET http://api.guanmai.cn/v1/materials/stock/out?station_id=T002&time_type=1&start_date=2016-10-25&end_date=2016-10-26

response:
    {   
        'code': 0,
        'data': {
            'offset': 0,
            'limit': 20,
            'count': 100,
            'list': [
                {
                    'id':11112,                 # 入库单ID
                    'out_stock_time': '2016-10-24', # 出库时间
                    'money': 1111,      # 出库金额
                    'status': 2,        # 状态                    }
            ],
        'msg': 'ok',
    }

2.拉取出库单详情

接口名:/materials/stock/out/{{stock_out_id}}
Method:GET
请求参数:
    out_stock_id        M   int         出库单ID

响应:
    code    M   int     返回码,0表示成功,其他表示错误
    msg     M   string  返回信息
    data    M   json    出库单信息
示例:
request:
    GET http://api.guanmai.cn/v1/materials/stock/out/113332

response:
    {   
        'code': 0,
        'msg': 'ok',
        'data': {
            '_id': '出库单ID',
            'create_time': '建单时间',
            'creator': '建单人',
            'out_stock_time': '出库时间',
            'total_price': 123434,
            'status': 1-未出库;2-已出库,

            'details': [{
                'meterial_id': 12345,
                'quantity': 33,
                'price': 100,
                'total_item_price': 100 x 33,
                'fomula_id': 12345,
                'operator': 'k10admin',
                'create_time': '添加时间',
                'update_time': '修改时间',
            }],
            'station_id': 'k10admin',
        }
    }

3.新建出库单

接口名:/materials/stock/out
Method:POST
请求参数:
    station_id      M   string          站点ID
    status          M   int             1-未出库;2-已出库
    details         M   json            原料信息,结构见示例

响应:
    code    M   int     返回码,0表示成功,其他表示错误
    msg     M   string  返回信息
    data    M   dict    出库单ID数据

示例:
request:
    POST http://teststation.guanmai.cn/materials/stock/out
    POST参数:
        station_id: T002
        out_stock_time: '2015-02-02 10:00'
        status: 1
        details: [{'formula_id': 11132, 'meterial_id': 3321, 'quantity': 30, 'price': 20}]

response:
    {   
        'code': 0,
        'msg': 'ok',
        'data': {
            'id': 13434,
        },
    }

4.编辑出库单

接口名:/materials/stock/out/{{stock_out_id}}
Method:PUT
请求参数:
    station_id      M   string          站点ID
    stock_out_id    M   int             出库单ID
    out_stock_time  M   string          出库时间
    status          M   int             状态
    details         M   json            原料信息,结构见示例              
响应:
    code    M   int     返回码,0表示成功,其他表示错误
    msg     M   string  返回信息

示例:
request:
    PUT http://api.guanmai.cn/v1/materials/stock/out/13133
    PUT参数:
        stock_out_id: 13133
        out_stock_time: '2015-02-02 10:00'
        status: 1
        details: [{'formula_id': 11132, 'meterial_id': 3321, 'quantity': 30, 'price': 20, 'create_time': '', 'operator': 'user_id'}]


response:
    {   
        'code': 0,
        'msg': 'ok',
    }

5.出库单冲销

接口名:/materials/stock/out/{{stock_out_id}}/cancel
Method:PUT
请求参数:
    station_id      M   string          站点ID
    stock_out_order_id  M   int         出库单ID

响应:
    code    M   int     返回码,0表示成功,其他表示错误
    msg     M   string  返回信息

示例:
request:
    PUT http://api.guanmai.cn/v1/materials/stock/out/11333/status
    PUT参数:
        station_id: T002

response:
    {   
        'code': 0,
        'msg': 'ok',
    }

六、退货单

1.拉取退货单列表

接口名:/materials/stock/return
Method:GET
请求参数:
    station_id      M   string          站点ID
    time_type       M   string          时间类型:1-按退货时间搜索;2-按建单时间搜索;
    start_date  M   string          开始日期
    end_date        M   string          截止日期
    status          O   int             状态
    search_text O   string          搜索文本
    export          O   int             是否导出:0-不导出,默认;1-导出;
    offset          O   int             分页offset
    limit           O   int             分页limit
响应:
    code    M   int     返回码,0表示成功,其他表示错误
    msg     M   string  返回信息
    data    M   list    返回json数据,结构看示例

示例:
request:
    GET http://api.guanmai.cn/v1/materials/stock/return?station_id=T002&time_type=1&start_date=2016-10-25&end_date=2016-10-26

response:
    {   
        'code': 0,
        'data': {
            'offset': 0,
            'limit': 20,
            'count': 100,
            'list': [
                {
                    'id':11112,                 # 入库单ID
                    'return_stock_time': '2016-10-24', # 退货时间
                    'supplier_id': 'T131',      # 供应商ID
                    ‘supplier_name': '阿米巴13', # 供应商名称
                    'money': 1111,      # 退货金额
                    'status': 2,        # 状态                    }
            ],
        'msg': 'ok',
    }

2.拉取退货单详情

接口名:/materials/stock/return/{{stock_return_id}}
Method:GET
请求参数:
    stock_return_id M   int         入库单ID

响应:
    code    M   int     返回码,0表示成功,其他表示错误
    msg     M   string  返回信息
    data    M   json    入库单信息
示例:
request:
    GET http://api.guanmai.cn/v1/materials/stock/return/113332

response:
    {   
        'code': 0,
        'msg': 'ok',
        'data': {
            '_id': 'T002-YLTHD-2016-09-04-00008',
            'return_stock_time': '退货时间',
            'create_time': '建单时间',
            'creator': '建单人',
            'supplier_id': '供应商ID',
            'total_price': 12000,
            'status': 1-已退货;2-未退货;3-已冲销,
            'details': [
                {
                    'material_id': 'YL12345',
                    'quantity': 20,
                    'price': 240,
                    'total_item_price': 20 x 240,
                    'operator': 'username',
                }
            ],
            // 分摊
            'share': [
                {
                    'operate_time': '操作时间',
                    'reason': 1-运输费用分摊;2-其他费用分摊,
                    'money': 1234,
                    'action': 1-加钱;2-减钱, 
                    'method': 1-金额分摊; 2-入库数分摊,
                    'remark': '备注',
                    'operator': '操作人ID',
                }
            ],
            // 折让
            'discount':[
                {
                    'operate_time': '操作时间',
                    'reason': 1-运输费用分摊;2-其他费用分摊,
                    'action': 1-加钱;2-减钱,
                    'money': 1234,
                    'remark': '备注',
                    'operator': '操作人ID',
                }
            ],
            'station_id': 'T002',
        }       
    }

3.新建退货单

接口名:/materials/stock/return
Method:POST
请求参数:
    station_id      M   string          站点ID
    supplier_id     M   string          供应商ID
    return_stock_time   M   string          退货时间
    status          M   int             1-未退货;2-已退货
    details         M   json            原料信息,结构见示例
    share           O   json            分摊信息,结构见示例
    discount        O   json            折让信息,结构见示例

响应:
    code    M   int     返回码,0表示成功,其他表示错误
    msg     M   string  返回信息    
    data    M   dict    新建退货单信息

示例:
request:
    POST http://api.guanmai.cn/v1/materials/stock/return
    POST参数:
        station_id: T002
        supplier_id:'T131'
        return_stock_time: '2015-02-02 10:00'
        status: 1
        details: [{'id': 11132, 'quantity': 30, 'price': 20}]
        share: [{'reason': 1, 'money': 20, 'action': 1, 'method': 1, 'remark': 'remark'}]
        discount: [{'reason': 1, 'action': 1, 'money': 40, 'remark': 'test'}]

response:
    {   
        'code': 0,
        'msg': 'ok',
        'data': {
            'id': 13434134,
        },
    }

4.编辑退货单

接口名:/materials/stock/return/{{stock_return_id}}
Method:PUT
请求参数:
    station_id          M   string          站点ID
    stock_return_id     M   int             入库单ID
    return_stock_time   M   string          入库时间
    status              M   int             状态
    details             M   json            原料信息,结构见示例
    share               O   json            分摊信息,结构见示例
    discount            O   json            折让信息,结构见示例


响应:
    code    M   int     返回码,0表示成功,其他表示错误
    msg     M   string  返回信息

示例:
request:
    PUT http://api.guanmai.cn/v1/materials/stock/return/13133
    PUT参数:
        station_id:T002
        return_stock_id: 13133
        return_stock_time: '2015-02-02 10:00'
        status: 1
        details: [{'id': 11132, 'quantity': 30, 'price': 20, 'operator': 'user_id'}]
        share: [{'reason': 1, 'money': 20, 'action': 1, 'method': 1, 'remark': 'remark', 'create_time': '', 'operator': 'user_id'}]
        discount: [{'reason': 1, 'action': 1, 'money': 40, 'remark': 'test', 'create_time': '', 'operator': 'user_id'}]


response:
    {   
        'code': 0,
        'msg': 'ok',
    }

5.退货单冲销

接口名:/materials/stock/return/{{stock_return_id}}/cancel
Method:PUT
请求参数:
    station_id          M   string      站点ID
    stock_return_id     M   int         入库单ID

响应:
    code    M   int     返回码,0表示成功,其他表示错误
    msg     M   string  返回信息

示例:
request:
    PUT http://teststation.guanmai.cn/materials/stock/return/11333/cancel
    PUT参数:
        station_id: 113434

response:
    {   
        'code': 0,
        'msg': 'ok',
    }

七、库存盘点

1.原料库存记录拉取接口

接口名:/materials/stock/log
Method:GET
请求参数:
    station_id      M   string          站点ID
    type            M   int             记录类型:1-入库;2-出库;3-退货
    search_text O   string          搜索文本:原料ID或名称
    export          O   int             是否导出:0-不导出,默认;1-导出;
    offset          O   int             分页offset
    limit           O   int             分页limit
响应:
    code    M   int     返回码,0表示成功,其他表示错误
    msg     M   string  返回信息
    data    M   list    返回json数据,结构看示例

示例:
request:
    GET http://api.guanmai.cn/v1/materials/stock/log?station_id=T002&type=2&search_text=猪

response:
    {   
        'code': 0,
        'data': {
            'offset': 0,
            'limit': 20,
            'count': 100,
            'list': [
                {
                    '_id': ObjectId('xxxxx'),
                    'material_id': 12343, # 原料ID
                    'material_name': 'xxx', # 原料名称

                    'supplier_name': 'xxx', # 供应商名称,在出库单时不需要

                    'change_type': 1, # 变动类型:1-入库;2-出库;3-退货
                    'change_stock_id': 'xxx', # 入库/出库/退货单ID

                    'status': 1, # 状态:1-删除;2-正常;
                    'quantity': 30, # 变动数量
                    'price': 120, # 变动价格
                    'total_price': 30 x 120, # 变动金额
                    'create_time': '创建时间',
                    'station_id': 'T002',
                    'modifier': 'xxx', # 修改人
                    'update_time': '修改时间',
                }

            ],
        'msg': 'ok',
    }

2.拉取报损、报溢信息接口

接口名:/materials/stock/check
Method:GET
请求参数:
    station_id      M   string          站点ID
    type    M   int             盘点类型:1-报溢;2-报损
    search_text O   string          搜索文本
    export          O   int             是否导出:0-不导出,默认;1-导出;
    offset          O   int             分页offset
    limit           O   int             分页limit
响应:
    code    M   int     返回码,0表示成功,其他表示错误
    msg     M   string  返回信息
    data    M   list    返回json数据,结构看示例

示例:
request:
    GET http://api.guanmai.cn/v1/materials/stock/check?station_id=T002&type=2&search_text=猪

response:
    {   
        'code': 0,
        'data': {
            'offset': 0,
            'limit': 20,
            'count': 100,
            'list': [
                {
                    '_id': 'xxxxxxxxx',
                    'material_id': 13141,
                    'name': '猪',
                    'unit_name': '头',
                    ’type': 2;
                    'remain_stock': 99, # 抄盘数
                    'input_stock': 100, # 实盘数
                    ’price': 111,
                    'quantity': 10,
                    'total_price': 111 x 10
                    'operator': '操作人',
                    'create_time': '记录插入时间',
                    'station_id': 'T002',
                }
            ],
        'msg': 'ok',
    }