Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

非管理页api #9

Open
hayespan opened this issue Mar 5, 2015 · 4 comments
Open

非管理页api #9

hayespan opened this issue Mar 5, 2015 · 4 comments
Assignees

Comments

@hayespan
Copy link
Owner

hayespan commented Mar 5, 2015

主页:

渲染:
GET /

user: 
    如果用户未初始过账户(选择位置),则为None;
    否则,提供user.name
catx
    包含所有一级分类与对应的二级分类。
    [
        [cat1 obj, [cat2 obj, cat2 obj, ... ]],
        [cat1 obj, [cat2 obj, cat2 obj, ... ]],
        ...
    ]
hot_products
    如果用户未初始过账户,hot_products则为不区分楼栋的热销商品,没有限制在用户当前楼栋,
    所以此时用户是不能加入购物车的,因为加入购物车需要提供位置信息。
   (前端应该判断用户是否初始,可以自己做标记,也可通过检测是否有_csrf_token,虽然_csrf_token作用不在此)
    如果用户已初始,则hot_products为当前位置的热销商品。
    返回数据已经排序,热销在前,售完在后,只返回前10件商品。
    [
        [product obj, tot, quantity], // product obj 有name, pic.filename等属性,tot是总销量
        [product obj, tot, quantity], // quantity 是库存,注意库存为0要标记为“已售完”
        ...
    ]
promotions
    [filename, filename, ... ]
locations
    [
        [
            school obj, // id, name
            [
                building obj, // id, name
                ...
            ]
        ],
        ...
    ]
ajax api:(如无特别说明,不用提交 csrf_token)

1 获取学校列表

GET /location/school_list
return:
{
    'code': 0,
    'data': [
        {'id': x, 'name': 'xxx'},
        ...
    ]
}

2 获取某所学校的楼栋列表

GET /location/<int:school_id>/building_list
return:
{
    'code': 0,
    'data': [
        {'id': x, 'name': 'xxx'},
        ...
    ]
}

errno:
-1 School does not exist.

3 初始用户(提交位置信息)

POST /user/choose_location

input:
building_id

ouput:
{
    'code': 0,
    'data': {'_csrf_token': 'xxx'} // 写localstorage,伴随着用户终身,也可作为前端判断用户是否在线的依据
}

errno:
1 Invalid arguments.
-1 Building does not exist.

4 获取购物车里的数量(用户必须初始化才可访问)

POST /cart/cnt
input: 
csrf_token

ouput:
{
    'code': 0,
    'data': x,
}

errno:
2 Csrf token check failed.
3 User should choose location to init account.

5 加入购物车
(注意,对一种商品重复加入购物车,仍然只会有一条记录,但是购买数量会叠加,
上限是库存加满直至库存量,不会返回错误提示。)

post /cart/insert

input:
csrf_token
product_id
quantity (前端记得用js限制,购买数量必须为正数,上限9999之类的,超了也没关系,后端有检查)

output:
{
    'code': 0,
    'data': cart_obj_id, // 加入购物车成功则返回该条目的id
}

errno:
1 Invalid arguments. 
2 Csrf token check failed.
3 User should choose location to init account.
-1 Must clear cart. (意思就是,如果购物车有上一个位置的商品,则必须先清除,与ele.me策略相同)
-2 Cart does not exist or quantity is 0. 商品不存在(可能临时被删除)或者与楼栋解绑,或者售罄,此时加入购物车失败

购物车页:

渲染:

ajax api:

1 购买数量加1

POST /cart/add

input:
csrf_token
product_id

ouput:
{
    'code': 0,
    'data': x, // 返回加1后的结果,上限是存货量
}

errno:
1 Invalid arguments. 
2 Csrf token check failed.
3 User should choose location to init account.
-2 Product does not exist or quantity is 0. // 商品不存在或库存为0,所以该条记录应标记为失效!
-3 Cart record does not exist. // 可能该条记录不存在,例如卖家删除了商品导致的级联删除

2 购买数量减1

POST /cart/sub

input:
csrf_token
product_id

ouput:
{
    'code': 0,
    'data': x, // 返回j减1后的结果,下限是1
}

errno:
1 Invalid arguments. 
2 Csrf token check failed.
3 User should choose location to init account.
-2 Product does not exist or quantity is 0. // 商品不存在或库存为0,所以该条记录应标记为失效!
-3 Cart record does not exist. // 可能该条记录不存在,例如卖家删除了商品导致的级联删除

3 删除购物车的某件商品

POST /cart/delete

input:
csrf_token
product_id

ouput:
{
    'code': 0,
    'data': null
}

errno:
1 Invalid arguments. 
2 Csrf token check failed.
3 User should choose location to init account.

4 清空购物车

POST /cart/clear

input:
csrf_token

ouput:
{
    'code': 0,
    'data': null
}

errno:
1 Invalid arguments. 
2 Csrf token check failed.
3 User should choose location to init account.

5 获取默认用户信息(结算购物车时弹出的联系信息框)

POST /user/contact_info

input:
csrf_token

ouput:
{
    'code': 0,
    'data': 
    {
        'name': 'xxx',
        'phone': 'xxxxxxxxxxx',
        'addr': '......',
    }
}

errno:
1 Invalid arguments. 
2 Csrf token check failed.
3 User should choose location to init account.
-3 'Contact info does not exist.

6 结算购物车(注意失效的商品不能让用户勾选,虽然后端有检查,但不符合逻辑)

POST /order/create

input:
csrf_token
product_ids // 用户勾选的购物车中商品的id字符串,格式:'1,2,4',不可有空格,但前后允许有逗号
name // 用户名,长度1-15
phone // 固定电话或手机号字符串,后端有检查
addr // 送货地址,长度1-100

ouput:
{
    ‘code': 0,
    'data': null // 成功的话没返回其他信息
}

errno:
1 Invalid arguments. 
2 Csrf token check failed.
3 User should choose location to init account.
-1 Some item in cart is invalid. // 需要刷新页面
-2 Product does not exist or quantity is 0. // 当前下的订单里,有商品不存在或库存为0的,
                                                                  // 前端应该reload页面,刷新后商品会显示失效状态。

7 获取购物车中的项目

POST /cart

input:
csrf_token

ouput:
{
    'code': 0,
    'data':
    [
        {
            'product_id': x, // 商品id,用于在加减商品数目/结算时,要post 商品的id(s)
            'name': 'xxx', // 商品名
            'description': '...', // 商品描述
            'filename': 'xxx', // 商品图片名称,用于生成url
            'price': x.x, // 商品价格
            'quantity': x, // 购买数量
            'is_valid': true/false, // 该条目是否有效,失效须标记
        },
        ...
    ]
}

errno:
1 Invalid arguments. 
2 Csrf token check failed.
3 User should choose location to init account.

8 set_cart_quantity 直接设置购物车中的某件商品的购买数量

POST /cart/set_quantity

input:
csrf_token
product_id
quantity

ouput:
{
    'code': 0,
    'data': x, // 设置结果
}

errno:
1 Invalid arguments. 
2 Csrf token check failed.
3 User should choose location to init account.
CART_DOES_NOT_EXIST = (-3, 'Cart record does not exist.') // 欲设置项不存在
CART_INVALID = (-2, 'Product does not exist or quantity is 0.') // 欲设置项的商品存货量为0,失效
@hayespan hayespan assigned hayespan and HexMox and unassigned hayespan Mar 5, 2015
@hayespan
Copy link
Owner Author

hayespan commented Mar 6, 2015

订单清单页

渲染:
GET /order

user (同首页的user)
orders: 
订单列表(已排序,未完成在前),格式如下:
[
    {
        'id': x, // 订单id,前端没有用到,还是提供咯
        'ticketid': '20_characters_long', // 订单编号
        'sender_name': 'xxx', // 送货人名称
        'sender_contact_info': '100 characters at most', // 送货人联系方法,正常就手机号
        'price': x, // 订单总价
        'released_time': datetime obj, // 下单时间。
        'timedelta': timedelta obj, // 送货时间长度。前端需要用js根据这两个时间计算剩余时间的倒计时
        'timeout': True/False, // 是否已超时,是的话,要标记为超时状态。
        'delivery_time': x, // 送达unix时间戳,int型
        'password': 'xxxx', // 动态密码
        'status': 'uncompleted'/'completed'/'cancelled', // 订单状态,未完成/完成/关闭
        'items':
        [
            {
                'id': x, // 商品快照id
                'filename': 'xxx', // 用于图片加载
                'name': 'xxx', // 商品名称
                'description': '...', // 商品描述
                'price': x.x, // 商品价格
                'quantity': x, // 购买数量
            },
            ...
        ]
    },
    ...
]

ajax

9 get_order_list 获取订单列表

POST /order/list

input:
csrf_token

ouput:
{
    'code': 0,
    'data': 
    [
        {
            'id': x, // 订单id,前端没有用到,还是提供咯
            'ticketid': '20_characters_long', // 订单编号
            'sender_name': 'xxx', // 送货人名称
            'sender_contact_info': '100 characters at most', // 送货人联系方法,正常就手机号
            'price': x, // 订单总价
            'released_time': x, // 下单时间(unix时间戳)
            'timedelta': x, // 送货时间长度(unix时间戳)
            'delivery_timestamp': x, // 预计送达时间,(unix时间戳)
            'timeout': True/False, // 是否已超时,是的话,要标记为超时状态。
            'password': 'xxxx', // 动态密码
            'status': 'uncompleted'/'completed'/'cancelled', // 订单状态,未完成/完成/关闭
            'items':
            [
                {
                    'id': x, // 商品快照id
                    'filename': 'xxx', // 用于图片加载
                    'name': 'xxx', // 商品名称
                    'description': '...', // 商品描述
                    'price': x.x, // 商品价格
                    'quantity': x, // 购买数量
                },
                ...
            ]
        },
        ...
    ]
}

errno:
1 Invalid arguments. 
2 Csrf token check failed.
3 User should choose location to init account.

@hayespan
Copy link
Owner Author

hayespan commented Mar 7, 2015

商品列表页

渲染:
从首页点击分类跳进的商品页,query格式:
GET /product/list?cat1=x&cat2=x 
// 不分页,感觉不必要,cat2优先级大于cat1,如果两个都不提供,则不作任何筛选
// 默认已排序,未售罄在前,销量高在前。

user(同首页)
catx(同首页)
products:
[
    [
        product obj, 
            // 属性有:id, name, description, pic.filename, price
        product_building obj, 
            // 属性有:quantity(存货量,如果为0时要标记售罄), sold_cnt_rd(销量)
    ],
    ...
]
current_cat1 // 属性有:id, name,用于标记当前所在一级分类,因为是从首页跳过来的,
                     // 所以要通过这个信息,把侧边栏对应的选项打开,或者文字说明当前分类
ajax api

1 在商品页中,ajax请求不同分类的商品

POST /product/list

input:
cat1_id // 可选
cat2_id // 可选,优先级高

ouput: 
{
    ’code': 0,
    'data':
    {
        'products':
        [
            {
                'id': x,
                'name': 'xxx',
                'description': '...',
                'filename': 'xxx',
                'price': x.x,
                'quantity': x, // 存货量
                'sold_cnt': x, // 销量
            },
            ...
        ],
        'current_cat1': // 当前被选择的一级分类,如果有的话,如下格式,否则,为null
        { // 为null时,说明是全部商品列表,没有分类
            'id': x,
            'name': 'xxx',
        }
    }
}

errno:
1 Invalid arguments. 
-1 Category x does not exist. // 一级或二级分类无效

@hayespan
Copy link
Owner Author

手机端api

1 index 首页

GET /m/

user: 
    如果用户未初始过账户(选择位置),则为None;
    否则,提供user.name
catx
    包含所有一级分类与对应的二级分类。
    [
        [cat1 obj, [cat2 obj, cat2 obj, ... ]],
        [cat1 obj, [cat2 obj, cat2 obj, ... ]],
        ...
    ]
promotions
    [filename, filename, ... ]

2 location_page 选择学校、楼栋页面

GET /m/locations

locations
    [
        [
            school obj, // id, name
            [
                building obj, // id, name
                ...
            ]
        ],
        ...
    ]

3 cart_page 购物车页

GET /m/cart

4 order_page 订单页

GET /m/order

user (同首页的user)
orders: 
订单列表(已排序,未完成在前),格式如下:
[
    {
        'id': x, // 订单id,前端没有用到,还是提供咯
        'ticketid': '20_characters_long', // 订单编号
        'sender_name': 'xxx', // 送货人名称
        'sender_contact_info': '100 characters at most', // 送货人联系方法,正常就手机号
        'price': x, // 订单总价
        'released_time': datetime obj, // 下单时间。
        'timedelta': timedelta obj, // 送货时间长度。前端需要用js根据这两个时间计算剩余时间的倒计时
        'timeout': True/False, // 是否已超时,是的话,要标记为超时状态。
        'delivery_time': x, // 送达unix时间戳,int型
        'password': 'xxxx', // 动态密码
        'status': 'uncompleted'/'completed'/'cancelled', // 订单状态,未完成/完成/关闭
        'items':
        [
            {
                'id': x, // 商品快照id
                'filename': 'xxx', // 用于图片加载
                'name': 'xxx', // 商品名称
                'description': '...', // 商品描述
                'price': x.x, // 商品价格
                'quantity': x, // 购买数量
            },
            ...
        ]
    },
    ...
]

5 product_page 商品页

GET /mb/product

input: (query string)
cat2

ouput: (具体内容格式同pc端接口)
user
current_cat1
current_cat2
products

@jayjiahua 这份是手机端的渲染页面api,然后其余的ajax都使用pc端的接口哦

@hayespan hayespan assigned hayespan and unassigned HexMox Mar 20, 2015
@hayespan
Copy link
Owner Author

@goldenstone

新增获取热门商品api,逻辑如下:

如果用户未初始过账户,hot_products则为不区分楼栋的热销商品,没有限制在用户当前楼栋,
所以此时用户是不能加入购物车的,因为加入购物车需要提供位置信息。
(前端应该判断用户是否初始,可以自己做标记,也可通过检测是否有_csrf_token,虽然_csrf_token作用不在此)
如果用户已初始,则hot_products为当前位置的热销商品。
返回数据已经排序,热销在前,售完在后,只返回前delta件商品。

get_hot_product_list

POST /product/hot

input:
delta // 数量,前delta件商品,可选,默认是10

output:
{
    'code': 0,
    'data': 
    [
        {
            'id': x,
            'name': 'xxx',
            'description': '...',
            'filename': 'xxx',
            'price': x.x,
            'quantity': x, // 存货量
            'sold_cnt': x, // 销量
        },
        ...
    ]
}

errno:
1 Invalid arguments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants