Beispiel #1
0
    def lock(self):
        # 获取当前所有的需要的属性
        pid = request.params["pid"]
        sid = request.params["sid"]
        price = request.params["price"]
        orderno = request.params["orderno"]
        # 从Play中获取目标对象
        play = Play.get(pid)
        # 判断目标排期是否存在
        if not play:
            return Code.play_does_not_exist, request.params
        # 票价判断:不能低于最低价
        if price < play.lowest_price:
            return Code.prcice_less_than_the_lowest_price, request.params

        # 座位锁定操作
        locked_seat_num = PlaySeat.lock(orderno, pid, sid)
        # 如果没有完成坐定操作,报错
        if not locked_seat_num:
            return Code.seat_lock_failed, {}
        # 表单创建
        order = Order.create(play.cid, pid, sid)
        # 修改第三方的订单号
        order.sell_order_no = orderno
        # 修改订单的状态
        order.status = OrderStatus.locked.value
        # 修改订单锁定的座位数
        order.ticket_num = locked_seat_num
        # 执行保存操作
        order.save()
        # 返回锁定的座位数目
        return {"locked_seats_num": locked_seat_num}
Beispiel #2
0
    def lock(self):
        # 使用Request.Params["id"]来获取参数是一种比较有效的途径。
        pid = request.params['pid']
        sid = request.params['sid']

        price = request.params['price']
        orderno = request.params['orderno']
        # 获取到场次
        play = Play.get(pid)
        if not play:
            return Code.play_does_not_exist, request.params
        if price < play.lowest_price:
            return Code.prcice_less_than_the_lowest_price, request.params
            # lock 是定义这个类,创建的而方法
        locked_seats_num = PlaySeat.lock(orderno, pid, sid)
        # 如果没有锁定数量
        if not locked_seats_num:
            # 为啥返回的是空字典
            return Code.seat_lock_failed, {}
            # 定义了一个create方法,创造订单
            # play.cid影院的排期,排期id,座位id
        order = Order.create(play.cid, pid, sid)
        order.seller_order_no = orderno
        # OrderStatus 是自定义的方法,锁定的值为1
        order.status = OrderStatus.locked.value
        # 订单的票数 = 自定义的 lock方法的返回值 是那个操作数
        order.ticket_num = locked_seats_num
        # 这个save 是自定义了一个类,然后多继承
        order.save()
        return {'locked_seats_num': locked_seats_num}
Beispiel #3
0
 def lock(self):
     pid = request.params['pid']
     sid = request.params['sid']
     price = request.params['price']
     orderno = request.params['orderno']
     play = Play.get(pid)
     if not play:
         return Code.play_does_not_exist
     if price < play.lowest_price:
         return Code.prcice_less_than_the_lowest_price
     locked_seats_num = PlaySeat.lock(orderno, pid, sid)
     if not locked_seats_num:
         return Code.seat_lock_failed
     order = Order.create(play.cid, pid, sid)
     order.seller_order_no = orderno
     order.status = OrderStatus.locked.value
     order.tickets_num = locked_seats_num
     order.save()
     return {'locked_seats_num': locked_seats_num}
Beispiel #4
0
    def lock(self):
        pid = request.params["pid"]
        sid = request.params["sid"]
        price = request.params["price"]
        orderno = request.params["orderno"]
        play = Play.get(pid)
        if not play:
            return Code.play_does_not_exist, {"pid": pid}
        if price < play.lowest_price:
            return Code.prcice_less_than_the_lowest_price, {"price": price}

        locked_seat_num = PlaySeat.lock(orderno, pid, sid)
        if not locked_seat_num:
            return Code.seat_lock_failed, {"lock_seat_num": locked_seat_num}
        order = Order.create(play.cid, pid, sid)
        order.seller_order_no = orderno
        order.status = OrderStatus.locked.value
        order.save()
        return {"locked_seat_num": locked_seat_num}