支付

作者: 垃圾桶边的狗 | 来源:发表于2018-12-21 10:47 被阅读0次

    models.py

    from App.ext import db
    from App.models import BaseModel
    from App.models.cinema.user_model import CinemaUser
    from App.models.common.movie_model import Movie
    
    
    from App.ext import db
    from App.models import BaseModel
    
    
    
    class CinemaUser(BaseModel):
        c_name = db.Column(db.String(32), unique=True)
        _c_password = db.Column(db.String(256))
    
    
    class Movie(BaseModel):
        m__name = db.Column(db.String(128))
        m_name_en = db.Column(db.String(255))
        m_director = db.Column(db.String(64))
        m_leading_role = db.Column(db.Integer, default=90)
        m_duration = db.Column(db.String(64))
        m_country = db.Column(db.String(64))
        m_type = db.Column(db.String(64))
        m_screen_model = db.Column(db.String(32))
        m_open_day = db.Column(db.DateTime)
        m_introduce = db.Column(db.String(256))
    
    
    
    class CinemaUserMovie(BaseModel):
        c_name_user = db.Column(db.Integer, db.ForeignKey(CinemaUser.id))
        c_movie_id = db.Column(db.Integer, db.ForeignKey(Movie.id))
    
    # 订单表
    from App.ext import db
    from App.models import BaseModel
    from App.models.cinema.user_model import CinemaUser
    from App.models.common.movie_model import Movie
    # 给订单设置状态
    ORDER_STATUS_NOT_PAY = 0
    ORDER_STATUS_PAYED = 1
    
    
    class Order(BaseModel):
        o_user = db.Column(db.Integer, db.ForeignKey(CinemaUser.id))
        o_status = db.Column(db.Integer, default=0)
        o_time = db.Column(db.DateTime)
        o_movie = db.Column(db.Integer, db.ForeignKey(Movie.id))
    

    一个用户可以有多个订单,一个电影可以比如多个订单购买


    电影院用户和电影交互.png

    买需要提交,使用post
    产生订单条件:1.用户必须是登录状态 2.要知道用户id 3. 拿到电影id

    cinema_movie_api.py

    from flask import request, g
    from flask_restful import Resource, abort
    
    from App.apis.cinema.decorator import login_required
    from App.models.cinema.cinema_user_movie_model import CinemaUserMovie
    
    
    class CinemaMoviesResource(Resource):
    
        @login_required
        def post(self):
    
            movie_id = request.form.get("movie_id")
    
            cinema_movie = CinemaUserMovie()
    
            cinema_movie.c_movie_id = movie_id
    
            cinema_movie.c_cinema_user = g.user.id
    
            if not cinema_movie.save():
                abort(400, msg="购买失败")
            data = {
                "msg": "ok",
                "status": 201,
                "pay_url": "xxx"
            }
    
            return data
    
    
    

    相关文章

      网友评论

          本文标题:支付

          本文链接:https://www.haomeiwen.com/subject/mjlyqqtx.html