订单列表的信息展示
pages/my/order_list.js
添加函数的调用
,
onShow: function () {
this.getPayOrder();
},
获取订单函数
,
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) {
var resp = res.data;
if (resp.code != 200) {
app.alert({"content": resp.msg});
return;
}
that.setData({
order_list:resp.data.pay_order_list
});
}
});
},
创建web/api/my.py
# -*- coding: utf-8 -*-
from web.controllers.api import route_api
from flask import request, jsonify,g
from common.models.food.Food import Food
from application import app,db
from common.models.pay.PayOrder import PayOrder
from common.models.pay.PayOrderItem import PayOrderItem
from common.libs.UrlManager import UrlManager
from common.libs.Helper import selectFilterObj,getDictFilterField,getCurrentDate
import json,datetime
@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 )
elif status == -7:#待发货
query = query.filter( PayOrder.status == 1,PayOrder.express_status == -7,PayOrder.comment_status == 0 )
elif status == -6:#待确认
query = query.filter(PayOrder.status == 1, PayOrder.express_status == -6,PayOrder.comment_status == 0)
elif status == -5:#待评价
query = query.filter(PayOrder.status == 1, 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,
'price':str( item.price ),
'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,
'order_sn':item.order_sn,
'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)
\common\models\pay\PayOrder.py
添加狀態的判斷:
# coding: utf-8
from sqlalchemy import BigInteger, Column, DateTime, Index, Integer, Numeric, String, Text
from sqlalchemy.schema import FetchedValue
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())
member_id = db.Column(db.BigInteger, nullable=False, server_default=db.FetchedValue())
total_price = db.Column(db.Numeric(10, 2), nullable=False, server_default=db.FetchedValue())
yun_price = db.Column(db.Numeric(10, 2), nullable=False, server_default=db.FetchedValue())
pay_price = db.Column(db.Numeric(10, 2), nullable=False, server_default=db.FetchedValue())
pay_sn = db.Column(db.String(128), nullable=False, server_default=db.FetchedValue())
prepay_id = db.Column(db.String(128), nullable=False, server_default=db.FetchedValue())
note = db.Column(db.Text, nullable=False)
status = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
express_status = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
express_address_id = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
express_info = db.Column(db.String(100), nullable=False, server_default=db.FetchedValue())
comment_status = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
pay_time = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue())
updated_time = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue())
created_time = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue())
@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
base_setting.py添加配置
PAY_STATUS_DISPLAY_MAPPING = {
"0":"订单关闭",
"1":"支付成功",
"-8":"待支付",
"-7":"待发货",
"-6":"待确认",
"-5":"待评价"
}
此時 刪除onshow設置的數據
,
onShow: function () {
this.getPayOrder();
},