
from flask import Flaskfrom flask_sqlalchemy import SQLAlchemyfrom _datetime import datetimeapp=Flask(__name__)app.config['SQLALCHEMY_DATABASE_URI'] = "mysql://root:@127.0.0.1:3306/XXXXXX数据库名XXXXXX?charset=utf8mb4"app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = Falseapp.config['SQLALCHEMY_ECHO'] = Truedb = SQLAlchemy(app)#数据库-Wechatdatabase表-用户class Wechatdatabase(db.Model):__tablename__ = 'wechat_user001'id = db.Column(db.Integer,primary_key=True)openid = db.Column(db.VARCHAR(255))nickname = db.Column(db.VARCHAR(255))sex = db.Column(db.Integer)province = db.Column(db.Text)city = db.Column(db.Text)country = db.Column(db.Text)unionid = db.Column(db.VARCHAR(255))#微信uidpoints = db.Column(db.Integer)#现在拥有的点数success_points = db.Column(db.Integer)#成功充值点数success_times = db.Column(db.Integer)#成功充值次数success_total_fee = db.Column(db.Integer)#成功充值金额orders = db.relationship('Wechatdatabaseorder',backref='nickname2')#这个用户的订单集合def __repr__(self):return 'Wechatdatabase:OK'#数据库-Wechatdatabaseorder表-订单class Wechatdatabaseorder(db.Model):__tablename__ = 'wechat_user_orders001'id = db.Column(db.Integer,primary_key=True)#订单idopenid = db.Column(db.VARCHAR(255))nickname = db.Column(db.VARCHAR(255))unionid = db.Column(db.VARCHAR(255))out_trade_no = db.Column(db.VARCHAR(255))#订单号order_name = db.Column(db.VARCHAR(255))#订单名state = db.Column(db.VARCHAR(255))#订单状态未付款,已付款creat_time = db.Column(db.DateTime, default=datetime.now)#创建时间time_end = db.Column(db.VARCHAR(14))update_time = db.Column(db.DateTime, default=datetime.now,onupdate=datetime.now)#更新时间total_fee = db.Column(db.Integer)#订单价格spbill_create_ip = db.Column(db.VARCHAR(64))Wechatdatabase_id = db.Column(db.Integer,db.ForeignKey('wechat_user001.id'))#这个系统的下单的人iddef __repr__(self):return 'Wechatdatabaseorder: ok'#db.drop_all() #谨慎开db.create_all() # 创建当前应用中声明的所有模型类对应的数据表,db.drop_all()是删除表@app.route("/")def index():return "hello"if __name__ == '__main__':app.run(debug=True)