[关闭]
@chenwei123 2017-01-04T03:17:26.000000Z 字数 8012 阅读 506

购物车/订单文档

益安


1. 将商品添加到购物车

Description

用户向购物车中添加课程

Method and URL Structure

Method Resource URL
POST /market/shop_detail/

Request Parameters

Name Description Required Default
item_id 课程或考试id Yes
item_type 类型(course/examRule) Yes

Request Header

Name Description Required Default
Authorization Token 7309fabd207c22e0a00eada158989b89ffe839ef Yes

*Authorization的值为登录成功后返回值

cURL Example

  1. curl -X POST -H 'Authorization: Token 7309fabd207c22e0a00eada158989b89ffe839ef' -d 'item_id=2&item_type=course' http://127.0.0.1:8000/market/shop_detail/

JSON Response

  1. {
  2. "pk": 1,
  3. "owner": "teacher",
  4. "course": {
  5. "pk": 1,
  6. "owner": "teacher",
  7. "category": null,
  8. "name": "数学",
  9. "description": "math",
  10. "click": 0,
  11. "payment_count": 0,
  12. "create_time": "2016-04-11T07:42:40.097367Z"
  13. },
  14. "create_time": "2016-04-22T15:10:02.774016Z"
  15. }
  16. ### or
  17. {
  18. "pk": 5,
  19. "owner": "admin",
  20. "item_type": "examRule",
  21. "course": null,
  22. "examRule": {
  23. "pk": 2,
  24. "title": "python2考",
  25. "description": "python2考python2考python2考python2考python2考python2考python2考",
  26. "point": 2,
  27. "picture": "http://baidu.com",
  28. "price": "0.00",
  29. "exercise_number": 1
  30. },
  31. "create_time": "2016-06-28T07:08:34.991000Z"
  32. }

Error json Response

  1. //商品不存在情况
  2. {
  3. "detail": "Not found."
  4. }
  5. //购物车已存在情况
  6. {
  7. "message": "你已经添加过该商品到购物车, 不要重复此操作."
  8. }

2. 获取购物车中所有商品信息

Description

用户查找自己购物车所有商品

Method and URL Structure

Method Resource URL
GET /market/shop_list/

Request Parameters

默认分页取数据库中最新的10条数据

Name Description Required Default
page page Number Yes 1

Request Header

Name Description Required Default
Authorization Token 7309fabd207c22e0a00eada158989b89ffe839ef Yes

*Authorization的值为登录成功后返回值

cURL Example

  1. curl -X GET -H 'Authorization: Token 7309fabd207c22e0a00eada158989b89ffe839ef' http://127.0.0.1:8000/market/shop_list/?page=1

JSON Response

  1. {
  2. "count": 3,
  3. "next": null,
  4. "previous": null,
  5. "results": [
  6. {
  7. "pk": 5,
  8. "owner": "admin",
  9. "item_type": "examRule",
  10. "course": null,
  11. "examRule": {
  12. "pk": 2,
  13. "title": "python2考",
  14. "description": "python2考python2考python2考python2考python2考python2考python2考",
  15. "point": 2,
  16. "picture": "http://baidu.com",
  17. "price": "0.00",
  18. "exercise_number": 1
  19. },
  20. "create_time": "2016-06-28T07:08:34.991000Z"
  21. },
  22. {
  23. "pk": 2,
  24. "owner": "admin",
  25. "item_type": "examRule",
  26. "course": null,
  27. "examRule": {
  28. "pk": 1,
  29. "title": "python轻松一考",
  30. "description": "这是一个很不错的,能巩固python基础的考试",
  31. "point": 1,
  32. "picture": "http://pic22.nipic.com/20120801/6608733_154516839000_2.jpg",
  33. "price": "0.00",
  34. "exercise_number": 10
  35. },
  36. "create_time": "2016-06-28T05:59:08.431000Z"
  37. },
  38. {
  39. "pk": 1,
  40. "owner": "admin",
  41. "item_type": "course",
  42. "course": {
  43. "pk": 1,
  44. "owner": "admin",
  45. "name": "python测试课程",
  46. "description": "bbbbc",
  47. "picture": "http://baidu.com",
  48. "amount": "0.00",
  49. "grade": "junior",
  50. "pay_course": "recommend",
  51. "pay_course_display": "recommend",
  52. "click": 0,
  53. "payment_count": 1,
  54. "create_time": "2016-06-22T10:09:10.753000Z",
  55. "category": {
  56. "pk": 1,
  57. "name": "python",
  58. "parent": -1
  59. },
  60. "course_type": "develop",
  61. "course_type_display": "开发",
  62. "authenticated": false,
  63. "support_exam": false,
  64. "excellent": false,
  65. "recommend": false,
  66. "videos": [],
  67. "examRule": [
  68. {
  69. "pk": 1,
  70. "title": "python轻松一考",
  71. "description": "这是一个很不错的,能巩固python基础的考试",
  72. "point": 1,
  73. "picture": "http://pic22.nipic.com/20120801/6608733_154516839000_2.jpg",
  74. "price": "0.00",
  75. "exercise_number": 10
  76. },
  77. {
  78. "pk": 2,
  79. "title": "python2考",
  80. "description": "python2考python2考python2考python2考python2考python2考python2考",
  81. "point": 2,
  82. "picture": "http://baidu.com",
  83. "price": "0.00",
  84. "exercise_number": 1
  85. }
  86. ]
  87. },
  88. "examRule": null,
  89. "create_time": "2016-06-28T05:56:51.008000Z"
  90. }
  91. ]
  92. }

3. 删除购物车商品

Description

用户删除购物车商品

Method and URL Structure

Method Resource URL
DELETE /market/shop_detail/

Request Parameters

Name Description Required Default
item_id 课程id/考试id Yes
item_type 类型 Yes course/examRule

Request Header

Name Description Required Default
Authorization Token 7309fabd207c22e0a00eada158989b89ffe839ef Yes

*Authorization的值为登录成功后返回值

cURL Example

  1. curl -X DELETE -H 'Authorization: Token 7309fabd207c22e0a00eada158989b89ffe839ef' -d 'item_id=1&item_type=2' http://127.0.0.1:8000/market/shop_detail/

JSON Response

Name Description Default
detail 失败原因 Not found
status 成功 204

1. 创建订单

Description

用户创建订单

Method and URL Structure

Method Resource URL
POST /market/order_create/

Request Parameters

Name Description Required Default
courses 课程编号或id Yes
exams 考试编号或id(多个,分割) Yes
flag 直接购买或者购物车购买 Yes 0
status 订单状态 No 0
channel 支付方式 No alipay
point 安盾值 No
coupon 优惠券的pk/id NO
  • status 订单状态分为三种:待付款(0)、已付款(1)、取消(2)
  • channel 支付方式分为两种:微信支付(wx)、支付宝支付(alipay)
  • flag 分两种:0代表直接购买,1代表通过购物车购买

JSON Request

  1. {
  2. "courses":"1,2",
  3. "flag":1,
  4. }

Request Header

Name Description Required Default
Authorization Token 7309fabd207c22e0a00eada158989b89ffe839ef Yes

*Authorization的值为登录成功后返回值

cURL Example

  1. curl -X POST -H 'Authorization: Token 7309fabd207c22e0a00eada158989b89ffe839ef' -d 'courses=1,2&flag=1&point=10' http://127.0.0.1:8000/market/order_create/

JSON Response

  1. {
  2. "pk": 4,
  3. "buyer": "admin",
  4. "order_no": "12134676924116330001",
  5. "courses": "1",
  6. "names": "python测试课程,python2016年度基础考试",
  7. "count": 2,
  8. "amount": "0.00",
  9. "status": 0,
  10. "flag": 1,
  11. "channel": "balance",
  12. "create_time": "2016-06-29T03:30:55.350000Z",
  13. "profile": {
  14. "pk": 1,
  15. "username": "admin",
  16. "nickname": "yinjj",
  17. "location": "1",
  18. "avatar_url": "http://baidu.com",
  19. "website": "http://baidu.com",
  20. "point": 12,
  21. "birthday": "2016-06-29",
  22. "level": "fresh",
  23. "level_display": "益安新人",
  24. "credit": 0,
  25. "credit_level": "fresh",
  26. "credit_level_display": "益安新生",
  27. "account": "0.00"
  28. }
  29. }

2. 查看订单详情

Description

用户查看具体订单

Method and URL Structure

Method Resource URL
GET /market/order_detail/${pk}/

Request Header

Name Description Required Default
Authorization Token 7309fabd207c22e0a00eada158989b89ffe839ef Yes

*Authorization的值为登录成功后返回值

cURL Example

  1. curl -X GET -H 'Authorization: Token 7309fabd207c22e0a00eada158989b89ffe839ef' http://127.0.0.1:8000/market/order_detail/1/

JSON Response

  1. {
  2. "pk":1,
  3. "buyer":"student",
  4. "order_no":"12134676894811030002",
  5. "courses":"1,2",
  6. "names":"英语,物理",
  7. "count":2,
  8. "amount":"100.00",
  9. "status":0,
  10. "flag":1,
  11. "channel":"alipay",
  12. "create_time":"2016-04-23T09:11:13.065911Z"
  13. }

2. 取消订单

Description

用户取消具体订单

Method and URL Structure

Method Resource URL
GET /market/order_detail/${pk}/

Request Parameters

Name Description Required Default
status 订单状态 Yes

Request Header

Name Description Required Default
Authorization Token 7309fabd207c22e0a00eada158989b89ffe839ef Yes

*Authorization的值为登录成功后返回值

cURL Example

  1. curl -X PUT -H 'Authorization: Token 7309fabd207c22e0a00eada158989b89ffe839ef' http://127.0.0.1:8000/market/order_detail/1/ -d 'status=2'

JSON Response

  1. {
  2. "pk":1,
  3. "buyer":"student",
  4. "order_no":"12134676894811030002",
  5. "courses":"1,2",
  6. "amount":"100.00",
  7. "names":"英语,物理",
  8. "count":2,
  9. "status":2,
  10. "flag":1,
  11. "channel":"alipay",
  12. "create_time":"2016-04-23T09:11:13.065911Z"
  13. }

3. 删除订单

Description

用户删除具体订单

Method and URL Structure

Method Resource URL
DELETE /market/order_detail/${pk}/

Request Header

Name Description Required Default
Authorization Token 7309fabd207c22e0a00eada158989b89ffe839ef Yes

*Authorization的值为登录成功后返回值

cURL Example

  1. curl -X DELETE -H 'Authorization: Token 7309fabd207c22e0a00eada158989b89ffe839ef' http://127.0.0.1:8000/market/order_detail/1/

JSON Response

Name Description Default
detail 失败原因 Not found
status 成功 204

4. 用户查看自己订单

Description

用户查看自己的订单

Method and URL Structure

Method Resource URL
GET /market/order-list/

Request Parameters

默认分页取数据库中最新的10条数据

Name Description Required Default
page page Number Yes 1

Request Header

Name Description Required Default
Authorization Token 7309fabd207c22e0a00eada158989b89ffe839ef Yes

*Authorization的值为登录成功后返回值

cURL Example

  1. curl -X GET -H 'Authorization: Token 7309fabd207c22e0a00eada158989b89ffe839ef' http://127.0.0.1:8000/market/order_list/?page=1

JSON Response

  1. {
  2. "count": 9,
  3. "next": null,
  4. "previous": null,
  5. "results": [
  6. {
  7. "pk": 9,
  8. "buyer": "admin",
  9. "order_no": "12134676978762830001",
  10. "courses": "",
  11. "examRules": "1",
  12. "names": "python2016年度基础考试",
  13. "count": 1,
  14. "amount": "0.00",
  15. "status": 0,
  16. "flag": 1,
  17. "channel": "balance",
  18. "create_time": "2016-06-29T05:37:01.002000Z",
  19. "profile": {
  20. "pk": 1,
  21. "username": "admin",
  22. "nickname": "yinjj",
  23. "location": "1",
  24. "avatar_url": "http://baidu.com",
  25. "website": "http://baidu.com",
  26. "point": 12,
  27. "birthday": "2016-06-29",
  28. "level": "fresh",
  29. "level_display": "益安新人",
  30. "credit": 0,
  31. "credit_level": "fresh",
  32. "credit_level_display": "益安新生",
  33. "account": "0.00"
  34. }
  35. },
  36. {
  37. "pk": 8,
  38. "buyer": "admin",
  39. "order_no": "12134676966364380001",
  40. "courses": "",
  41. "examRules": "1",
  42. "names": "python2016年度基础考试",
  43. "count": 1,
  44. "amount": "0.00",
  45. "status": 0,
  46. "flag": 1,
  47. "channel": "balance",
  48. "create_time": "2016-06-29T05:36:55.198000Z",
  49. "profile": {
  50. "pk": 1,
  51. "username": "admin",
  52. "nickname": "yinjj",
  53. "location": "1",
  54. "avatar_url": "http://baidu.com",
  55. "website": "http://baidu.com",
  56. "point": 12,
  57. "birthday": "2016-06-29",
  58. "level": "fresh",
  59. "level_display": "益安新人",
  60. "credit": 0,
  61. "credit_level": "fresh",
  62. "credit_level_display": "益安新生",
  63. "account": "0.00"
  64. }
  65. }
  66. ]
  67. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注