老师好,order 返回的data 里面的 pay_order_list 为空
来源:12-5 订单列表信息展示
慕虎7527636
2020-03-25
@route_api.route("/my/order")
def myOrderList():
resp = {'code': 200, 'msg': '操作成功', 'data': {}}
member_info = g.member_info
req = request.values
status = int(req['status']) if 'status' in req else 0
query = PayOrder.query.filter_by(member_id=member_info.id)
# 等待付款
if status == -8:
query = query.filter(PayOrder.status == -8)
# 待发货
if status == -7:
query = query.filter(PayOrder.status == -8,PayOrder.express_status == -7, PayOrder.comment_status == 0)
# 等确认
elif status == -6:
query = query.filter(PayOrder.status == -8,PayOrder.express_status == -6, PayOrder.comment_status == 0)
# 待评价
elif status == -5:
query = query.filter(PayOrder.status == -8,PayOrder.express_status == 1, PayOrder.comment_status == 0)
# 已完成
elif status == 1:
query = query.filter(PayOrder.status == 1,PayOrder.express_status == 1, PayOrder.comment_status == 1)
else:
query = query.filter(PayOrder.status == 0)
pay_order_list = query.order_by(PayOrder.id.desc()).all()
data_pay_order_list = []
if pay_order_list:
pay_order_ids = selectFilterObj(pay_order_list, "id")
pay_order_item_list = PayOrderItem.query.filter(PayOrderItem.pay_order_id.in_(pay_order_ids)).all()
food_ids = selectFilterObj(pay_order_item_list,"food_id")
food_map = getDictFilterField(Food, Food.id, "id", food_ids)
pay_order_item_map = {}
if pay_order_item_list:
for item in pay_order_item_list:
if item.pay_order_id not in pay_order_item_map:
pay_order_item_map[item.pay_order_id] = []
tmp_food_info = food_map[item.food_id]
pay_order_item_map[item.pay_order_id].append({
"id": item.id,
"food_id": item.food_id,
"quantity": item.quantity,
"pic_url": UrlManager.buildImageUrl(tmp_food_info.main_image),
"name": tmp_food_info.name,
})
for item in pay_order_list:
tmp_data = {
"status": item.pay_status,
"status_desc": item.status_desc,
"date": item.created_time.strftime("%Y-%m-%d %H:%M:%S"),
"order_number": item.order_number,
"note": item.note,
"total_price": str(item.total_price),
"goods_list": pay_order_item_map[item.id]
}
data_pay_order_list.append(tmp_data)
resp['data']['pay_order_list'] = data_pay_order_list
return jsonify(resp)
from application import db,app
class PayOrder(db.Model):
__tablename__ = 'pay_order'
__table_args__ = (
db.Index('idx_member_id_status', 'member_id', 'status'),
)
id = db.Column(db.Integer, primary_key=True)
order_sn = db.Column(db.String(40), nullable=False, unique=True, server_default=db.FetchedValue(), info='?????')
member_id = db.Column(db.BigInteger, nullable=False, server_default=db.FetchedValue(), info='??id')
total_price = db.Column(db.Numeric(10, 2), nullable=False, server_default=db.FetchedValue(), info='??????')
yun_price = db.Column(db.Numeric(10, 2), nullable=False, server_default=db.FetchedValue(), info='????')
pay_price = db.Column(db.Numeric(10, 2), nullable=False, server_default=db.FetchedValue(), info='??????')
pay_sn = db.Column(db.String(128), nullable=False, server_default=db.FetchedValue(), info='??????')
prepay_id = db.Column(db.String(128), nullable=False, server_default=db.FetchedValue(), info='?????id')
note = db.Column(db.Text, nullable=False, info='????')
status = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue(), info='1????? 0 ?? -1 ???? -2 ??? -9 ???? -8 ??? -7 ???????')
express_status = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue(), info='?????-8 ??? -7 ?????? 1????? 0???')
express_address_id = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue(), info='????id')
express_info = db.Column(db.String(1000), nullable=False, server_default=db.FetchedValue(), info='????')
comment_status = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue(), info='????')
pay_time = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue(), info='??????')
updated_time = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue(), info='????????')
created_time = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue(), info='????')
@property
def pay_status(self):
tmp_status = self.status
if self.status == 1:
tmp_status = self.express_status
if self.express_status == 1 and self.comment_status == 0:
tmp_status = -5
if self.express_status == 1 and self.comment_status == 1:
tmp_status = 1
return tmp_status
@property
def status_desc(self):
return app.config['PAY_STATUS_DISPLAY_MAPPING'][str(self.pay_status)]
@property
# 订单号
def order_number(self):
order_number = self.created_time.strftime("%Y%m%d%H%M%S")
order_number = order_number + str(self.id).zfill(5)
return order_number
getPayOrder:function () {
var that = this;
wx.request({
//
url: app.buildUrl("/my/order"),
header: app.getRequestHeader(),
data: {
status: that.data.status[that.data.currentType]
},
success: function (res) {
}
});
}
写回答
1回答
-
编程浪子
2020-03-25
你好
没有什么好办法,只能调试.
进行代码打印看哪里出错了
可以打印 pay_order_list 如果 为空说明数据库是不是就是没有数据,没有数据不显示是正常的
122020-03-25
相似问题