{"action":"created","issue":{"url":"https://api.github.com/repos/panhzh3/project/issues/9","labels_url":"https://api.github.com/repos/panhzh3/project/issues/9/labels{/name}","comments_url":"https://api.github.com/repos/panhzh3/project/issues/9/comments","events_url":"https://api.github.com/repos/panhzh3/project/issues/9/events","html_url":"https://github.com/panhzh3/project/issues/9","id":59901863,"number":9,"title":"非管理页api","user":{"login":"panhzh3","id":4804511,"avatar_url":"https://avatars.githubusercontent.com/u/4804511?v=3","gravatar_id":"","url":"https://api.github.com/users/panhzh3","html_url":"https://github.com/panhzh3","followers_url":"https://api.github.com/users/panhzh3/followers","following_url":"https://api.github.com/users/panhzh3/following{/other_user}","gists_url":"https://api.github.com/users/panhzh3/gists{/gist_id}","starred_url":"https://api.github.com/users/panhzh3/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/panhzh3/subscriptions","organizations_url":"https://api.github.com/users/panhzh3/orgs","repos_url":"https://api.github.com/users/panhzh3/repos","events_url":"https://api.github.com/users/panhzh3/events{/privacy}","received_events_url":"https://api.github.com/users/panhzh3/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"HexMox","id":5358537,"avatar_url":"https://avatars.githubusercontent.com/u/5358537?v=3","gravatar_id":"","url":"https://api.github.com/users/HexMox","html_url":"https://github.com/HexMox","followers_url":"https://api.github.com/users/HexMox/followers","following_url":"https://api.github.com/users/HexMox/following{/other_user}","gists_url":"https://api.github.com/users/HexMox/gists{/gist_id}","starred_url":"https://api.github.com/users/HexMox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HexMox/subscriptions","organizations_url":"https://api.github.com/users/HexMox/orgs","repos_url":"https://api.github.com/users/HexMox/repos","events_url":"https://api.github.com/users/HexMox/events{/privacy}","received_events_url":"https://api.github.com/users/HexMox/received_events","type":"User","site_admin":false},"milestone":null,"comments":2,"created_at":"2015-03-05T03:58:29Z","updated_at":"2015-03-06T08:34:00Z","closed_at":null,"body":"主页：\r\n----\r\n\r\n##### 渲染：\r\n\r\n```\r\nGET /\r\n\r\nuser: \r\n    如果用户未初始过账户（选择位置），则为None;\r\n    否则，提供user.name\r\ncatx\r\n    包含所有一级分类与对应的二级分类。\r\n    [\r\n        [cat1 obj, [cat2 obj, cat2 obj, ... ]],\r\n        [cat1 obj, [cat2 obj, cat2 obj, ... ]],\r\n        ...\r\n    ]\r\nhot_products\r\n    如果用户未初始过账户，hot_products则为不区分楼栋的热销商品，没有限制在用户当前楼栋，\r\n    所以此时用户是不能加入购物车的，因为加入购物车需要提供位置信息。\r\n   （前端应该判断用户是否初始，可以自己做标记，也可通过检测是否有csrf_token，虽然csrf_token作用不在此）\r\n    如果用户已初始，则hot_products为当前位置的热销商品。\r\n    返回数据已经排序，热销在前，售完在后，只返回前10件商品。\r\n    [\r\n        [product obj, tot, quantity], // product obj 有name, pic.filename等属性，tot是总销量\r\n        [product obj, tot, quantity], // quantity 是库存，注意库存为0要标记为“已售完”\r\n        ...\r\n    ]\r\npromotions\r\n    [filename, filename, ... ]\r\n```\r\n\r\n##### ajax api：（如无特别说明，不用提交csrf_token）\r\n\r\n1 获取学校列表\r\n\r\n```\r\nGET /location/school_list\r\nreturn:\r\n{\r\n    'code': 0,\r\n    'data': [\r\n        {'id': x, 'name': 'xxx'},\r\n        ...\r\n    ]\r\n}\r\n```\r\n\r\n2 获取某所学校的楼栋列表\r\n\r\n```\r\nGET /<int:school_id>/building_list\r\nreturn:\r\n{\r\n    'code': 0,\r\n    'data': [\r\n        {'id': x, 'name': 'xxx'},\r\n        ...\r\n    ]\r\n}\r\n\r\nerrno:\r\n-1 School does not exist.\r\n```\r\n\r\n3 初始用户（提交位置信息）\r\n\r\n```\r\nPOST /user/choose_location\r\n\r\ninput:\r\nbuilding_id\r\n\r\nouput:\r\n{\r\n    'code': 0,\r\n    'data': {'_csrf_token': 'xxx'} // 写localstorage，伴随着用户终身，也可作为前端判断用户是否在线的依据\r\n}\r\n\r\nerrno:\r\n1 Invalid arguments.\r\n-1 Building does not exist.\r\n```\r\n\r\n4 获取购物车里的数量（用户必须初始化才可访问）\r\n```\r\nPOST /cart/cnt\r\ninput: \r\ncsrf_token\r\n\r\nouput:\r\n{\r\n    'code': 0,\r\n    'data': x,\r\n}\r\n\r\nerrno:\r\n2 Csrf token check failed.\r\n3 User should choose location to init account.\r\n```\r\n\r\n5 加入购物车\r\n（注意，对一种商品重复加入购物车，仍然只会有一条记录，但是购买数量会叠加，\r\n上限是库存加满直至库存量，不会返回错误提示。）\r\n```\r\npost /cart/insert\r\n\r\ninput:\r\ncsrf_token\r\nproduct_id\r\nquantity （前端记得用js限制，购买数量必须为正数，上限9999之类的，超了也没关系，后端有检查）\r\n\r\noutput:\r\n{\r\n    'code': 0,\r\n    'data': cart_obj_id, // 加入购物车成功则返回该条目的id\r\n}\r\n\r\nerrno:\r\n1 Invalid arguments. \r\n2 Csrf token check failed.\r\n3 User should choose location to init account.\r\n-1 Must clear cart. （意思就是，如果购物车有上一个位置的商品，则必须先清除，与ele.me策略相同）\r\n-2 Product does not exist. 商品不存在（可能临时被删除）\r\n```\r\n\r\n购物车页：\r\n----\r\n\r\n##### 渲染：\r\n\r\n```\r\nGET /cart\r\n\r\nuser： 提供user.name用于代替问候用户名\r\ncarts：购物车条目列表，[cart obj, cart obj, ... ]\r\n           其中，通过cart obj可获取信息有：\r\n               cart.product, cart.quantity, cart.is_valid；\r\n           通过 cart.product 可获取信息有：\r\n               product.id, product.name, product.pic.filename, product.description, product.price；\r\n               （NOTE：\r\n               1. 静态文件地址统一为：'/static/img/filename'（filename作用在此）；\r\n               2. product.id用于在加减商品数目时，要post这个product.id；）\r\n```\r\n\r\n##### ajax api:\r\n\r\n1 购买数量加1\r\n```\r\nPOST /cart/add\r\n\r\ninput:\r\ncsrf_token\r\nproduct_id\r\n\r\nouput:\r\n{\r\n    'code': 0,\r\n    'data': x, // 返回加1后的结果，上限是存货量\r\n}\r\n\r\nerrno:\r\n1 Invalid arguments. \r\n2 Csrf token check failed.\r\n3 User should choose location to init account.\r\n-2 Product does not exist or quantity is 0. // 商品不存在或库存为0，所以该条记录应标记为失效！\r\n-3 Cart record does not exist. // 可能该条记录不存在，例如卖家删除了商品导致的级联删除\r\n```\r\n\r\n2 购买数量减1\r\n```\r\nPOST /cart/sub\r\n\r\ninput:\r\ncsrf_token\r\nproduct_id\r\n\r\nouput:\r\n{\r\n    'code': 0,\r\n    'data': x, // 返回j减1后的结果，下限是1\r\n}\r\n\r\nerrno:\r\n1 Invalid arguments. \r\n2 Csrf token check failed.\r\n3 User should choose location to init account.\r\n-2 Product does not exist or quantity is 0. // 商品不存在或库存为0，所以该条记录应标记为失效！\r\n-3 Cart record does not exist. // 可能该条记录不存在，例如卖家删除了商品导致的级联删除\r\n```\r\n\r\n3 删除购物车的某件商品\r\n\r\n```\r\nPOST /cart/delete\r\n\r\ninput:\r\ncsrf_token\r\nproduct_id\r\n\r\nouput:\r\n{\r\n    'code': 0,\r\n    'data': null\r\n}\r\n\r\nerrno:\r\n1 Invalid arguments. \r\n2 Csrf token check failed.\r\n3 User should choose location to init account.\r\n```\r\n\r\n4 清空购物车\r\n\r\n```\r\nPOST /cart/clear\r\n\r\ninput:\r\ncsrf_token\r\n\r\nouput:\r\n{\r\n    'code': 0,\r\n    'data': null\r\n}\r\n\r\nerrno:\r\n1 Invalid arguments. \r\n2 Csrf token check failed.\r\n3 User should choose location to init account.\r\n```\r\n\r\n5 获取默认用户信息（结算购物车时弹出的联系信息框）\r\n```\r\nPOST /user/contact_info\r\n\r\ninput:\r\ncsrf_token\r\n\r\nouput:\r\n{\r\n    'code': 0,\r\n    'data': \r\n    {\r\n        'name': 'xxx',\r\n        'phone': 'xxxxxxxxxxx',\r\n        'addr': '......',\r\n    }\r\n}\r\n\r\nerrno:\r\n1 Invalid arguments. \r\n2 Csrf token check failed.\r\n3 User should choose location to init account.\r\n-3 'Contact info does not exist.\r\n```\r\n\r\n6 结算购物车（注意失效的商品不能让用户勾选，虽然后端有检查，但不符合逻辑）\r\n```\r\nPOST /order/create\r\n\r\ninput:\r\ncsrf_token\r\nproduct_ids // 用户勾选的购物车中商品的id字符串，格式：'1,2,4'，不可有空格，但前后允许有逗号\r\nname // 用户名，长度1-15\r\nphone // 固定电话或手机号字符串，后端有检查\r\naddr // 送货地址，长度1-100\r\n\r\nouput:\r\n{\r\n    ‘code': 0,\r\n    'data': null // 成功的话没返回其他信息\r\n}\r\n\r\nerrno:\r\n1 Invalid arguments. \r\n2 Csrf token check failed.\r\n3 User should choose location to init account.\r\n-2 Product does not exist or quantity is 0. // 当前下的订单里，有商品不存在或库存为0的，\r\n                                                                  // 前端应该reload页面，刷新后商品会显示失效状态。\r\n\r\n```"},"comment":{"url":"https://api.github.com/repos/panhzh3/project/issues/comments/77523790","html_url":"https://github.com/panhzh3/project/issues/9#issuecomment-77523790","issue_url":"https://api.github.com/repos/panhzh3/project/issues/9","id":77523790,"user":{"login":"panhzh3","id":4804511,"avatar_url":"https://avatars.githubusercontent.com/u/4804511?v=3","gravatar_id":"","url":"https://api.github.com/users/panhzh3","html_url":"https://github.com/panhzh3","followers_url":"https://api.github.com/users/panhzh3/followers","following_url":"https://api.github.com/users/panhzh3/following{/other_user}","gists_url":"https://api.github.com/users/panhzh3/gists{/gist_id}","starred_url":"https://api.github.com/users/panhzh3/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/panhzh3/subscriptions","organizations_url":"https://api.github.com/users/panhzh3/orgs","repos_url":"https://api.github.com/users/panhzh3/repos","events_url":"https://api.github.com/users/panhzh3/events{/privacy}","received_events_url":"https://api.github.com/users/panhzh3/received_events","type":"User","site_admin":false},"created_at":"2015-03-06T08:34:00Z","updated_at":"2015-03-06T08:34:00Z","body":"订单清单页\r\n----\r\n\r\n##### 渲染：\r\n```\r\nGET /order/buyer\r\n\r\nuser （同首页的user）\r\norders: \r\n订单列表（已排序，未完成在前），格式如下：\r\n[\r\n    {\r\n        'id': x, // 订单id，前端没有用到，还是提供咯\r\n        'ticketid': '20_characters_long', // 订单编号\r\n        'sender_name': 'xxx', // 送货人名称\r\n        'sender_contact_info': '100 characters at most', // 送货人联系方法，正常就手机号\r\n        'price': x, // 订单总价\r\n        'released_time': datetime obj, // 下单时间。\r\n        'timedelta': timedelta obj, // 送货时间长度。前端需要用js根据这两个时间计算剩余时间的倒计时\r\n        'timeout': True/False, // 是否已超时，是的话，要标记为超时状态。\r\n        'password': 'xxxx', // 动态密码\r\n        'status': 'uncompleted'/'completed'/'cancelled', // 订单状态，未完成/完成/关闭\r\n        'items':\r\n        [\r\n            {\r\n                'id': x, // 商品快照id\r\n                'filename': 'xxx', // 用于图片加载\r\n                'name': 'xxx', // 商品名称\r\n                'description': '...', // 商品描述\r\n                'price': x.x, // 商品价格\r\n                'quantity': x, // 购买数量\r\n            },\r\n            ...\r\n        ]\r\n    },\r\n    ...\r\n]\r\n\r\n```\r\n\r\n\r\n"}}