Browse Source

完成订单状态修改操作,等待合并测试

master
杨舜 1 year ago
parent
commit
96a0d97b72
18 changed files with 617 additions and 301 deletions
  1. +0
    -0
      be/Config.py
  2. +0
    -5
      be/creatTB.py
  3. +0
    -0
      be/model/store.py
  4. +0
    -121
      be/postgreSQLORM.py
  5. +0
    -22
      be/testconn.py
  6. +121
    -0
      doc/buyer.md
  7. +38
    -0
      doc/seller.md
  8. +0
    -0
      modified/be/Config.py
  9. +0
    -5
      modified/be/creatTB.py
  10. +80
    -3
      modified/be/model/buyer.py
  11. +5
    -0
      modified/be/model/postgreSQLORM.py
  12. +27
    -0
      modified/be/model/seller.py
  13. +0
    -0
      modified/be/model/store.py
  14. +0
    -121
      modified/be/postgreSQLORM.py
  15. +0
    -22
      modified/be/testconn.py
  16. +22
    -0
      modified/be/view/buyer.py
  17. +10
    -0
      modified/be/view/seller.py
  18. +314
    -2
      report.md

+ 0
- 0
be/Config.py View File


+ 0
- 5
be/creatTB.py View File

@ -1,5 +0,0 @@
from postgreSQLORM import Base,engine
def createTable():
# 创建所有继承于Base的类对应的表
Base.metadata.create_all(engine)

+ 0
- 0
be/model/store.py View File


+ 0
- 121
be/postgreSQLORM.py View File

@ -1,121 +0,0 @@
from sqlalchemy import create_engine,MetaData
from sqlalchemy import Integer,String,ForeignKey,Column,TEXT
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from sqlalchemy import PrimaryKeyConstraint,UniqueConstraint
import sqlalchemy
Base=declarative_base()
class con:
def connect():
'''Returns a connection and a metadata object'''
# We connect with the help of the PostgreSQL URL
url = 'postgresql://stu10205501415:Stu10205501415@dase-cdms-2022-pub.pg.rds.aliyuncs.com:5432/stu10205501415'
# The return value of create_engine() is our connection object
con = create_engine(url, client_encoding='utf8')
# We then bind the connection to MetaData()
meta = MetaData(bind=con)
return con, meta
class User(Base):
__tablename__ = 'user'
user_id = Column(TEXT, primary_key=True, comment="主键")
password = Column(TEXT, nullable=False, comment="密码")
balance = Column(Integer, nullable=False, comment="")
token = Column(TEXT, comment="缓存的令牌")
terminal = Column(TEXT, comment="终端代码")
class Store(Base):
__tablename__ = 'store'
store_id = Column(TEXT, primary_key=True,comment="主键")
stock_level = Column(Integer, comment = "货存")
class Store_Book(Base):
__tablename__ = 'store_book'
store_id = Column(TEXT, comment="主键")
book_id = Column(TEXT, comment="主键")
book_info = Column(TEXT, comment="书籍信息")
stock_level = Column(Integer, comment = "货存")
__table_args__ = (
PrimaryKeyConstraint('store_id', 'book_id'),
)
class User_Store(Base):
__tablename__ = 'user_store'
id = Column(Integer, primary_key=True, autoincrement=True, comment="主键")
fk_user_id = Column(
TEXT,
ForeignKey(
"user.user_id",
ondelete="CASCADE",
onupdate="CASCADE",
),
nullable=False,
comment="user外键"
)
fk_store_id = Column(
TEXT,
ForeignKey(
"store.store_id",
ondelete="CASCADE",
onupdate="CASCADE",
),
nullable=False,
comment="store外键"
)
# 多对多关系的中间表必须使用联合唯一约束,防止出现重复数据
__table_args__ = (
UniqueConstraint("fk_user_id", "fk_store_id"),
)
class New_Order(Base):
__tablename__ = 'new_order'
order_id = Column(TEXT, primary_key = True, comment = '订单id')
fk_user_id = Column(
TEXT,
ForeignKey(
"user.user_id",
ondelete="CASCADE",
onupdate="CASCADE",
),
nullable=False,
comment="user外键"
)
fk_store_id = Column(
TEXT,
ForeignKey(
"store.store_id",
ondelete="CASCADE",
onupdate="CASCADE",
),
nullable=False,
comment="store外键"
)
class New_Order_Detail(Base):
__tablename__ = 'new_order_detail'
order_id = Column(TEXT, comment='订单id')
book_id = Column(TEXT, comment='订单书籍')
count = Column(Integer, comment='购买书籍数')
price = Column(Integer, comment='单价')
__table_args__ = (
PrimaryKeyConstraint('order_id','book_id'),
)
engine, meta = con.connect()
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session = DBSession()

+ 0
- 22
be/testconn.py View File

@ -1,22 +0,0 @@
from flask import Blueprint
from flask import Flask, abort, request, jsonify
import json
from flask import jsonify
from sqlalchemy.ext.serializer import loads, dumps
import postgreSQLORM
from postgreSQLORM import User,Store,Store_Book,User_Store,New_Order,New_Order_Detail
bp_testconn = Blueprint("testconn",__name__,url_prefix="/testconn")
@bp_testconn.route("/test",methods=['GET'])
def test():
user_id: str = request.args.get("user_id")
print(user_id)
try:
ss = postgreSQLORM.session.query(User).filter(User.user_id==user_id).all()
for i in ss:
print('user_id',i.user_id)
except:
print("error")
return "connect success"

+ 121
- 0
doc/buyer.md View File

@ -142,3 +142,124 @@ Status Code:
200 | 充值成功
401 | 授权失败
5XX | 无效参数
## 买家收货
#### URL
POST http://[address]/buyer/take_over
#### Request
Headers:
key | 类型 | 描述 | 是否可为空
---|---|---|---
token | string | 登录产生的会话标识 | N
Body:
```json
{
"user_id": "$seller id$",
"order_id": "$store id$",
}
```
key | 类型 | 描述 | 是否可为空
---|---|---|---
user_id | String | 买家用户ID | N
order_id | String | 订单号 | N
Response
Status Code:
码 | 描述
--- | ---
200 | 收货成功
5XX | 买家用户ID不存在
5XX | 无效参数
## 买家取消订单
#### URL
POST http://[address]/buyer/order_cancel
#### Request
Headers:
key | 类型 | 描述 | 是否可为空
---|---|---|---
token | string | 登录产生的会话标识 | N
Body:
```json
{
"user_id": "$seller id$",
"order_id": "$store id$",
}
```
key | 类型 | 描述 | 是否可为空
---|---|---|---
user_id | String | 买家用户ID | N
order_id | String | 订单号 | N
#### Response
Status Code:
码 | 描述
--- | ---
200 | 收货成功
5XX | 买家用户ID不存在
5XX | 无效参数
## 历史订单查询
#### URL
POST http://[address]/buyer/history_order
#### Request
Headers:
key | 类型 | 描述 | 是否可为空
---|---|---|---
token | string | 登录产生的会话标识 | N
Body:
```json
{
"user_id": "$buyer id$"
}
```
key | 类型 | 描述 | 是否可为空
---|---|---|---
user_id | String | 买家用户ID | N
#### Response
Status Code:
码 | 描述
--- | ---
200 | 查询成功
5XX | 买家用户ID不存在
5XX | 无效参数
Body:
```json
{
"order_id": ["uuid"]
}
```
变量名 | 类型 | 描述 | 是否可为空
---|---|---|---
order_id | string | 订单号,只有返回200时才有效 | N

+ 38
- 0
doc/seller.md View File

@ -176,3 +176,41 @@ Status Code:
200 | 创建商铺成功
5XX | 商铺ID不存在
5XX | 图书ID不存在
## 商家发货
#### URL
POST http://[address]/seller/send_out
#### Request
Headers:
key | 类型 | 描述 | 是否可为空
---|---|---|---
token | string | 登录产生的会话标识 | N
Body:
```json
{
"user_id": "$seller id$",
"order_id": "$store id$",
}
```
key | 类型 | 描述 | 是否可为空
---|---|---|---
user_id | String | 卖家用户ID | N
order_id | String | 订单号 | N
#### Response
Status Code:
码 | 描述
--- | ---
200 | 发货成功
5XX | 买家用户ID不存在
5XX | 无效参数

+ 0
- 0
modified/be/Config.py View File


+ 0
- 5
modified/be/creatTB.py View File

@ -1,5 +0,0 @@
from postgreSQLORM import Base,engine
def createTable():
# 创建所有继承于Base的类对应的表
Base.metadata.create_all(engine)

+ 80
- 3
modified/be/model/buyer.py View File

@ -7,8 +7,10 @@ from model.postgreSQLORM import New_Order_Detail
from model.postgreSQLORM import New_Order
from model.postgreSQLORM import User
import uuid
import json
import logging
import time
from model import db_conn
from model import error
@ -59,6 +61,7 @@ class Buyer(db_conn.DBConn):
return error.error_stock_level_low(book_id) + (order_id, )
# print("touch4")
new_order_detail_entity = New_Order_Detail(order_id=uid,book_id=book_id,count=count,price=price)
# print("touch5")
row = self.session.add(new_order_detail_entity)
@ -68,7 +71,8 @@ class Buyer(db_conn.DBConn):
# "VALUES(?, ?, ?, ?);",
# (uid, book_id, count, price))
# print("touch1")
new_order_entity = New_Order(order_id=uid,fk_store_id=store_id,fk_user_id=user_id)
creat_time = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()) ## 订单创建时间
new_order_entity = New_Order(order_id=uid,fk_store_id=store_id,fk_user_id=user_id,creat_time=creat_time,status=0)
self.session.add(new_order_entity)
# self.conn.execute(
# "INSERT INTO new_order(order_id, store_id, user_id) "
@ -163,13 +167,14 @@ class Buyer(db_conn.DBConn):
if row == 0:
return error.error_non_exist_user_id(buyer_id)
# print('touch2')
row = session.query(New_Order).filter(New_Order.order_id==order_id).delete()
# row = session.query(New_Order).filter(New_Order.order_id==order_id).delete() 不在删除而是修改订单状态
row = session.query(New_Order).filter(New_Order.order_id==order_id).update({'status':1})
# cursor = conn.execute("DELETE FROM new_order WHERE order_id = ?", (order_id, ))
# if cursor.rowcount == 0:
if row == 0:
return error.error_invalid_order_id(order_id)
row = session.query(New_Order_Detail).filter(New_Order_Detail.order_id==order_id).delete()
# row = session.query(New_Order_Detail).filter(New_Order_Detail.order_id==order_id).delete()
# cursor = conn.execute("DELETE FROM new_order_detail where order_id = ?", (order_id, ))
# if cursor.rowcount == 0:
if row == 0:
@ -213,3 +218,75 @@ class Buyer(db_conn.DBConn):
return 530, "{}".format(str(e))
return 200, "ok"
def take_over(self, user_id, order_id):
session = self.session
try:
if not self.user_id_exist(user_id):
return error.error_non_exist_user_id(user_id)
row = session.query(New_Order).filter(and_(New_Order.order_id==order_id,New_Order.fk_user_id==user_id)).first()
if row is None:
return error.error_invalid_order_id(order_id)
if row.status != 2:
return error.error_invalid_order_id(order_id)
row = session.query(New_Order).filter(and_(New_Order.order_id==order_id,New_Order.fk_user_id==user_id)).update({'status':3})
if row == 0:
return error.error_invalid_order_id(order_id)
session.commit()
except SQLAlchemyError as e:
return 528, "{}".format(str(e))
except BaseException as e:
# print('touch3')
return 530, "{}".format(str(e))
return 200, "ok"
def order_cancel(self, user_id, order_id):
session = self.session
try:
if not self.user_id_exist(user_id):
return error.error_non_exist_user_id(user_id)
row = session.query(New_Order).filter(and_(New_Order.order_id==order_id,New_Order.fk_user_id==user_id)).first()
if row is None:
return error.error_invalid_order_id(order_id)
if row.status != 0:
return error.error_invalid_order_id(order_id)
row = session.query(New_Order).filter(and_(New_Order.order_id==order_id,New_Order.fk_user_id==user_id)).update({'status':-1})
if row == 0:
return error.error_invalid_order_id(order_id)
session.commit()
except SQLAlchemyError as e:
return 528, "{}".format(str(e))
except BaseException as e:
# print('touch3')
return 530, "{}".format(str(e))
return 200, "ok"
def history_order(self, user_id):
session = self.session
try:
if not self.user_id_exist(user_id):
return error.error_non_exist_user_id(user_id)
row = session.query(New_Order).filter(New_Order.fk_user_id==user_id).first()
if row is None:
return error.error_non_exist_user_id(user_id)
row = session.query(New_Order).filter(New_Order.fk_user_id==user_id).order_by(New_Order.creat_time.desc()).all()
order_ids = []
for i in row:
order_ids.append(i.order_id)
session.commit()
except SQLAlchemyError as e:
return 528, "{}".format(str(e))
except BaseException as e:
# print('touch3')
return 530, "{}".format(str(e))
return 200, "ok", order_ids

+ 5
- 0
modified/be/model/postgreSQLORM.py View File

@ -5,6 +5,9 @@ from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from sqlalchemy import PrimaryKeyConstraint,UniqueConstraint
import sqlalchemy
import time
Base=declarative_base()
class con:
def connect():
@ -100,6 +103,8 @@ class New_Order(Base):
nullable=False,
comment="store外键"
)
creat_time = Column(TEXT, nullable=False,comment="订单创建时间")
status = Column(Integer,nullable=False,comment="订单状态")
class New_Order_Detail(Base):
__tablename__ = 'new_order_detail'

+ 27
- 0
modified/be/model/seller.py View File

@ -1,6 +1,7 @@
from sqlalchemy.exc import SQLAlchemyError
from model import error
from model import postgreSQLORM
from model.postgreSQLORM import New_Order
from model import db_conn
from sqlalchemy import and_
@ -75,3 +76,29 @@ class Seller(db_conn.DBConn):
# print('touch3')
return 530, "{}".format(str(e))
return 200, "ok"
def send_out(self, order_id:str, user_id:str):
session = self.session
try:
if not self.user_id_exist(user_id):
return error.error_non_exist_user_id(user_id)
row = session.query(New_Order).filter(New_Order.order_id==order_id).first()
if row is None:
return error.error_invalid_order_id(order_id)
if row.status != 1:
return error.error_invalid_order_id(order_id)
row = session.query(New_Order).filter(New_Order.order_id==order_id).update({'status':2})
if row == 0:
return error.error_invalid_order_id(order_id)
session.commit()
except SQLAlchemyError as e:
return 528, "{}".format(str(e))
except BaseException as e:
# print('touch3')
return 530, "{}".format(str(e))
return 200, "ok"

+ 0
- 0
modified/be/model/store.py View File


+ 0
- 121
modified/be/postgreSQLORM.py View File

@ -1,121 +0,0 @@
from sqlalchemy import create_engine,MetaData
from sqlalchemy import Integer,String,ForeignKey,Column,TEXT
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from sqlalchemy import PrimaryKeyConstraint,UniqueConstraint
import sqlalchemy
Base=declarative_base()
class con:
def connect():
'''Returns a connection and a metadata object'''
# We connect with the help of the PostgreSQL URL
url = 'postgresql://stu10205501415:Stu10205501415@dase-cdms-2022-pub.pg.rds.aliyuncs.com:5432/stu10205501415'
# The return value of create_engine() is our connection object
con = create_engine(url, client_encoding='utf8')
# We then bind the connection to MetaData()
meta = MetaData(bind=con)
return con, meta
class User(Base):
__tablename__ = 'user'
user_id = Column(TEXT, primary_key=True, comment="主键")
password = Column(TEXT, nullable=False, comment="密码")
balance = Column(Integer, nullable=False, comment="")
token = Column(TEXT, comment="缓存的令牌")
terminal = Column(TEXT, comment="终端代码")
class Store(Base):
__tablename__ = 'store'
store_id = Column(TEXT, primary_key=True,comment="主键")
stock_level = Column(Integer, comment = "货存")
class Store_Book(Base):
__tablename__ = 'store_book'
store_id = Column(TEXT, comment="主键")
book_id = Column(TEXT, comment="主键")
book_info = Column(TEXT, comment="书籍信息")
stock_level = Column(Integer, comment = "货存")
__table_args__ = (
PrimaryKeyConstraint('store_id', 'book_id'),
)
class User_Store(Base):
__tablename__ = 'user_store'
id = Column(Integer, primary_key=True, autoincrement=True, comment="主键")
fk_user_id = Column(
TEXT,
ForeignKey(
"user.user_id",
ondelete="CASCADE",
onupdate="CASCADE",
),
nullable=False,
comment="user外键"
)
fk_store_id = Column(
TEXT,
ForeignKey(
"store.store_id",
ondelete="CASCADE",
onupdate="CASCADE",
),
nullable=False,
comment="store外键"
)
# 多对多关系的中间表必须使用联合唯一约束,防止出现重复数据
__table_args__ = (
UniqueConstraint("fk_user_id", "fk_store_id"),
)
class New_Order(Base):
__tablename__ = 'new_order'
order_id = Column(TEXT, primary_key = True, comment = '订单id')
fk_user_id = Column(
TEXT,
ForeignKey(
"user.user_id",
ondelete="CASCADE",
onupdate="CASCADE",
),
nullable=False,
comment="user外键"
)
fk_store_id = Column(
TEXT,
ForeignKey(
"store.store_id",
ondelete="CASCADE",
onupdate="CASCADE",
),
nullable=False,
comment="store外键"
)
class New_Order_Detail(Base):
__tablename__ = 'new_order_detail'
order_id = Column(TEXT, comment='订单id')
book_id = Column(TEXT, comment='订单书籍')
count = Column(Integer, comment='购买书籍数')
price = Column(Integer, comment='单价')
__table_args__ = (
PrimaryKeyConstraint('order_id','book_id'),
)
engine, meta = con.connect()
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session = DBSession()

+ 0
- 22
modified/be/testconn.py View File

@ -1,22 +0,0 @@
from flask import Blueprint
from flask import Flask, abort, request, jsonify
import json
from flask import jsonify
from sqlalchemy.ext.serializer import loads, dumps
import postgreSQLORM
from postgreSQLORM import User,Store,Store_Book,User_Store,New_Order,New_Order_Detail
bp_testconn = Blueprint("testconn",__name__,url_prefix="/testconn")
@bp_testconn.route("/test",methods=['GET'])
def test():
user_id: str = request.args.get("user_id")
print(user_id)
try:
ss = postgreSQLORM.session.query(User).filter(User.user_id==user_id).all()
for i in ss:
print('user_id',i.user_id)
except:
print("error")
return "connect success"

+ 22
- 0
modified/be/view/buyer.py View File

@ -40,3 +40,25 @@ def add_funds():
code, message = b.add_funds(user_id, password, add_value)
return jsonify({"message": message}), code
@bp_buyer.route("/take_over", methods=["POST"])
def take_over():
user_id = request.json.get("user_id")
order_id = request.json.get("order_id")
b = Buyer()
code, message = b.take_over(user_id, order_id)
return jsonify({"message": message}), code
@bp_buyer.route("/order_cancel", methods=["POST"])
def order_cancel():
user_id = request.json.get("user_id")
order_id = request.json.get("order_id")
b = Buyer()
code, message = b.order_cancel(user_id, order_id)
return jsonify({"message": message}), code
@bp_buyer.route("/history_order", methods=["POST"])
def history_order():
user_id = request.json.get("user_id")
b = Buyer()
code, message, order_ids = b.history_order(user_id)
return jsonify({"message": message,"order_id": order_ids}), code

+ 10
- 0
modified/be/view/seller.py View File

@ -39,3 +39,13 @@ def add_stock_level():
code, message = s.add_stock_level(user_id, store_id, book_id, add_num)
return jsonify({"message": message}), code
@bp_seller.route("/send_out",methods=["POST"])
def send_out():
order_id: str = request.json.get("order_id")
user_id: str = request.json.get("user_id")
s = seller.Seller()
code, message = s.send_out(order_id,user_id)
return jsonify({"message": message}), code

+ 314
- 2
report.md View File

@ -47,7 +47,7 @@
 
#### 二. 依据上述分析构建数据库table
#### 二. 依据上述分析构建数据库table(前60%)
1. 利用sqlalchemy连接远程的aliyun数据库并创建上述table [postgreSQLORM.py](./modified/be/postgreSQLORM.py)
```python
class con:
@ -271,4 +271,316 @@
![avatar](./figure_require/addfunds_test.png)
![avatar](./figure_require/payment_test.png)
10.
#### 三、根据要求实现后续的40%的功能并为其编写测试接口
1. 对数据库结构进行改造(添加table的列)
为了实现发货,收获,订单状态的查询,可以在new_order的订单的table中添加status,并利用不同的状态码来表示当前次订单的状态
|status code|status|
|---|---|
|-1|取消|
|0|初始值(未付款)|
|1|已付款|
|2|已发货|
|3|已收货|
因此修改postgreSQLORM.py文件中New_Order的类
2. 修改对应payment接口中删除订单的操作未修改订单状态未1
```python
row = session.query(New_Order).filter(New_Order.order_id==order_id).update({'status':1})
```
3. 为seller路由新增发货(修改订单状态为2)接口、buyer路由新增收货(修改订单状态为3)接口、buyer路由新增取消订单(修改订单状态为-1)接口
```python
## /view/seller.py
@bp_seller.routr("/send_out",methods=["POST"])
def send_out():
order_id: str = request.json.get("order_id")
user_id: str = request.json.get("user_id")
s = seller.Seller()
code, message = s.send_out(order_id)
return jsonify({"message": message}), code
```
```python
## /model/seller.py
def send_out(self, order_id:str):
session = self.session
try:
if not self.user_id_exist(user_id):
return error.error_non_exist_user_id(user_id)
row = session.query(New_Order).filter(New_Order.order_id==order_id).first()
if row is None:
return error.error_invalid_order_id(order_id)
if row.status != 1:
return error.error_invalid_order_id(order_id)
row = session.query(New_Order).filter(New_Order.order_id==order_id).update({'status':2})
if row == 0:
return error.error_invalid_order_id(order_id)
session.commit()
except SQLAlchemyError as e:
return 528, "{}".format(str(e))
except BaseException as e:
# print('touch3')
return 530, "{}".format(str(e))
return 200, "ok"
```
商家发货
URL
POST http://[address]/seller/send_out
Request
Headers:
key | 类型 | 描述 | 是否可为空
---|---|---|---
token | string | 登录产生的会话标识 | N
Body:
```json
{
"user_id": "$seller id$",
"order_id": "$store id$",
}
```
key | 类型 | 描述 | 是否可为空
---|---|---|---
user_id | String | 卖家用户ID | N
order_id | String | 订单号 | N
Response
Status Code:
码 | 描述
--- | ---
200 | 发货成功
5XX | 买家用户ID不存在
5XX | 无效参数
```python
## /view/buyer.py
@bp_buyer.route("/take_over", methods=["POST"])
def take_over():
user_id = request.json.get("user_id")
order_id = request.json.get("order_id")
b = Buyer()
code, message = b.take_over(user_id, order_id)
return jsonify({"message": message}), code
```
```python
## /model/buyer.py
def take_over(self, user_id, order_id):
session = self.session
try:
if not self.user_id_exist(user_id):
return error.error_non_exist_user_id(user_id)
row = session.query(New_Order).filter(and_(New_Order.order_id==order_id,New_Order.fk_user_id==user_id)).first()
if row is None:
return error.error_invalid_order_id(order_id)
if row.status != 2:
return error.error_invalid_order_id(order_id)
row = session.query(New_Order).filter(and_(New_Order.order_id==order_id,New_Order.fk_user_id==user_id)).update({'status':3})
if row == 0:
return error.error_invalid_order_id(order_id)
session.commit()
except SQLAlchemyError as e:
return 528, "{}".format(str(e))
except BaseException as e:
# print('touch3')
return 530, "{}".format(str(e))
return 200, "ok"
```
卖家收货
URL
POST http://[address]/buyer/take_over
Request
Headers:
key | 类型 | 描述 | 是否可为空
---|---|---|---
token | string | 登录产生的会话标识 | N
Body:
```json
{
"user_id": "$seller id$",
"order_id": "$store id$",
}
```
key | 类型 | 描述 | 是否可为空
---|---|---|---
user_id | String | 买家用户ID | N
order_id | String | 订单号 | N
Response
Status Code:
码 | 描述
--- | ---
200 | 收货成功
5XX | 买家用户ID不存在
5XX | 无效参数
```python
## /view/buyer.py
@bp_buyer.route("/order_cancel", methods=["POST"])
def take_over():
user_id = request.json.get("user_id")
order_id = request.json.get("order_id")
b = Buyer()
code, message = b.order_cancel(user_id, order_id)
return jsonify({"message": message}), code
```
```python
## /model/buyer.py
def order_cancel(self, user_id, order_id):
session = self.session
try:
if not self.user_id_exist(user_id):
return error.error_non_exist_user_id(user_id)
row = session.query(New_Order).filter(and_(New_Order.order_id==order_id,New_Order.fk_user_id==user_id)).first()
if row is None:
return error.error_invalid_order_id(order_id)
if row.status != 0:
return error.error_invalid_order_id(order_id)
row = session.query(New_Order).filter(and_(New_Order.order_id==order_id,New_Order.fk_user_id==user_id)).update({'status':-1})
if row == 0:
return error.error_invalid_order_id(order_id)
session.commit()
except SQLAlchemyError as e:
return 528, "{}".format(str(e))
except BaseException as e:
# print('touch3')
return 530, "{}".format(str(e))
return 200, "ok"
```
买家取消订单
URL
POST http://[address]/buyer/order_cancel
Request
Headers:
key | 类型 | 描述 | 是否可为空
---|---|---|---
token | string | 登录产生的会话标识 | N
Body:
```json
{
"user_id": "$seller id$",
"order_id": "$store id$",
}
```
key | 类型 | 描述 | 是否可为空
---|---|---|---
user_id | String | 买家用户ID | N
order_id | String | 订单号 | N
Response
Status Code:
码 | 描述
--- | ---
200 | 收货成功
5XX | 买家用户ID不存在
5XX | 无效参数
5. 像buyer路由中添加一个查询历史订单的接口,为此首先需要在原来的New_Order表中添加creat_time列,然后为buyer路由添加history_order接口
```python
## /view/buyer.py
@bp_buyer.route("/history_order", methods=["POST"])
def take_over():
user_id = request.json.get("user_id")
b = Buyer()
code, message = b.history_order(user_id)
return jsonify({"message": message}), code
```
```python
## /model/buyer.py
```
历史订单查询
URL
POST http://[address]/buyer/history_order
Request
Headers:
key | 类型 | 描述 | 是否可为空
---|---|---|---
token | string | 登录产生的会话标识 | N
Body:
```json
{
"user_id": "$buyer id$"
}
```
key | 类型 | 描述 | 是否可为空
---|---|---|---
user_id | String | 买家用户ID | N
Response
Status Code:
码 | 描述
--- | ---
200 | 查询成功
5XX | 买家用户ID不存在
5XX | 无效参数
Body:
```json
{
"order_id": ["uuid"]
}
```
变量名 | 类型 | 描述 | 是否可为空
---|---|---|---
order_id | string | 订单号,只有返回200时才有效 | N
1.

Loading…
Cancel
Save