|
|
@ -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. |