Beispiel #1
0
    def print_ticket(self):
        '''取票接口'''

        orderno = request.params['orderno']
        ticket_flag = request.params['ticket_flag']
        seats = request.params['sid']
        order = Order.getby_orderno(orderno)
        if not order:
            return Code.order_does_not_exist, {'orderno': orderno}
        if order.status == OrderStatus.printed.value:
            return Code.ticket_printed_already, {}
        if order.status != OrderStatus.paid.value:
            return Code.order_not_paid_yet, {}
        if not order.validate(ticket_flag):
            return Code.ticket_flag_error, {'ticket_flag': ticket_flag}
        # 修改座位状态为已取票
        printed_num = PlaySeat.print_tickets(orderno, order.pid, seats)
        if not printed_num:
            return Code.ticket_print_failed, {}
        # 设置订单状态为已取票
        order.status = OrderStatus.printed.value
        # 设置取票时间
        order.printed_time = datetime.now()
        order.save()
        return {'printed_num': printed_num}
Beispiel #2
0
    def print_ticket(self):
        orderno = request.params["orderno"]
        ticket_flag = request.params["ticket_flag"]
        seats = request.params["sid"]

        order = Order.getby_orderno(orderno)
        if not order:
            return Code.order_does_not_exist, {"orderno": orderno}
        # 判断是否出票
        if order.status == OrderStatus.printed.value:
            return Code.ticket_printed_already, {}
        # 订单是否支付
        if order.status != OrderStatus.paid.value:
            return Code.order_not_paid_yet, {}
        # 判断取票码
        if not order.validate(ticket_flag):
            return Code.ticket_flag_error, {"ticket_flag": ticket_flag}

        printed_num = PlaySeat.print_ticket(order.sell_order_no, order.pid,
                                            seats)

        if not printed_num:
            return Code.ticket_print_failed, {}

        order.status = OrderStatus.printed.value
        order.print_time = datetime.now()
        order.save()
        return {
            "printed_num": printed_num,
        }
Beispiel #3
0
 def ticket(self):
     """查询取票码"""
     orderno = request.params['orderno']
     order = Order.getby_orderno(orderno)
     if not order:
         return Code.order_does_not_exist, {'orderno': orderno}
     return {'ticket_flag': order.ticket_flag}
Beispiel #4
0
 def buy(self):
     # pid = request.params["pid"]
     # sid = request.params["sid"]
     seats = request.params['seats']
     orderno = request.params["orderno"]
     order = Order.getby_orderno(orderno)
     if not order:
         return Code.order_does_not_exist, {'orderno': orderno}
     if order.status != OrderStatus.locked.value:
         return Code.order_status_error, {}
     sid_list = []
     for sid, handle_fee, price in seats:
         order.amount += handle_fee + price
         sid_list.append(sid)
     bought_seats_num = PlaySeat.buy(orderno, order.pid, sid_list)
     if not bought_seats_num:
         return Code.seat_buy_failed, {}
     order.paid_time = datetime.now()
     order.status = OrderStatus.paid.value
     order.gen_ticket_flag()
     order.save()
     return {
         'bought_seats_num': bought_seats_num,
         'ticket_flag': order.ticket_flag,
     }
Beispiel #5
0
 def status(self):
     """查询订单状态"""
     orderno = request.params['orderno']
     order = Order.getby_orderno(orderno)
     if not order:
         return Code.order_does_not_exist, {'orderno': orderno}
     return {'status': order.status}
Beispiel #6
0
 def unlock(self):
     # 获取对应的值
     pid = request.params["pid"]
     sid = request.params["sid"]
     orderno = request.params["orderno"]
     # 获取目标对象
     play = Play.get(pid)
     # 判断是否存在
     if not play:
         return Code.play_does_not_exist, request.params
     # 获取目标对象
     order = Order.getby_orderno(orderno)
     # 判断是否存在
     if not order:
         return Code.order_does_not_exist, request.params
     # 解锁的座位数目
     unlock_seats_num = PlaySeat.unlock(orderno, pid, sid)
     # 判断解锁操作是否执行
     if not unlock_seats_num:
         return Code.seat_unlock_failed, {}
     # 修改状态
     order.status = OrderStatus.unlocked.value
     # 执行修改保存
     order.save()
     return {"unlock_seats_num": unlock_seats_num}
Beispiel #7
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 #8
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 #9
0
    def print_ticket(self):
        orderno = request.params['orderno']
        ticket_flag = request.params['ticket_flag']
        seats = request.params['sid']

        order = Order.getby_orderno(orderno)
        if not order:
            return Code.order_does_not_exist, {'orderno': orderno}
        # 订单是否已打印
        if order.status == OrderStatus.printed.value:
            return Code.ticket_printed_already, {}
        # 订单是否支付
        if order.status != OrderStatus.paid.value:
            return Code.order_not_paid_yet, {}
        # 核对订单码
        if not order.validate(ticket_flag):
            return Code.ticket_flag_error, {'ticket_flag': ticket_flag}

        printed_num = PlaySeat.print_tickets(order.seller_order_no, order.pid, seats)
        if not printed_num:
            return Code.ticket_print_failed.value, {}
        order.status = OrderStatus.printed.value
        order.printed_time = datetime.now()
        order.save()
        return {'printed_num': printed_num}
Beispiel #10
0
 def ticket_info(self):
     orderno = request.params['orderno']
     order = Order.getby_orderno(orderno)
     if not order:
         return Code.order_does_not_exist, {'orderno': orderno}
     order.play = Play.get(order.pid)
     order.movie = Movie.get(order.play.mid)
     order.tickets = PlaySeat.getby_orderno(orderno)
     return order
Beispiel #11
0
 def unlock(self):
     pid = request.params['pid']
     sid = request.params['sid']
     orderno = request.params['orderno']
     order = Order.getby_orderno(orderno)
     if not order:
         return Code.order_does_not_exist
     if order.status != OrderStatus.locked.value:
         return Code.order_status_error
     unlock_seats_num = PlaySeat.unlock(orderno, pid, sid)
     if not unlock_seats_num:
         return Code.seat_unlock_failed
     order.status = OrderStatus.unlocked.value
     order.save()
     return {'unlocked_seats_num': unlock_seats_num}
Beispiel #12
0
 def unlock(self):
     pid = request.params["pid"]
     sid = request.params["sid"]
     orderno = request.params["orderno"]
     order = Order.getby_orderno(orderno)
     if not order:
         return Code.order_does_not_exist, {'orderno': orderno}
     if order.status != OrderStatus.locked.value:
         return Code.order_status_error, {}
     unlocked_seats_num = PlaySeat.unlock(orderno, pid, sid)
     if not unlocked_seats_num:
         return Code.seat_unlock_failed, {}
     order.status = OrderStatus.unlocked.value
     order.save()
     return {'unlocked_seats_num': unlocked_seats_num}
Beispiel #13
0
    def unlock(self):
        pid = request.params['pid']

        sid = request.params['sid']
        orderno = request.params['orderno']
        play = Play.get(pid)
        if not play:
            return Code.play_does_not_exist, request.params

        order = Order.getby_orderno(orderno)
        if not order:
            return Code.order_does_not_exist, request.params
        unlock_seats_num = PlaySeat.unlock(orderno, pid, sid)
        if not unlock_seats_num:
            return Code.seat_lock_failed, {}
        order.status = OrderStatus.unlocked.value
        order.save()
        return {'unlock_seats_num': unlock_seats_num}
Beispiel #14
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 #15
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}
Beispiel #16
0
 def refund_ticket(self):
     orderno = request.params['orderno']
     ticket_flag = request.params['ticket_flag']
     seats = request.params['sid']
     order = Order.getby_orderno(orderno)
     if not order:
         return Code.order_does_not_exist, {'orderno': orderno}
     if order.status == OrderStatus.printed.value:
         return Code.ticket_printed_already, {}
     if order.status != OrderStatus.paid.value:
         return Code.order_not_paid_yet, {}
     if not order.validate(ticket_flag):
         return Code.ticket_flag_error, {'ticket_flag': ticket_flag}
     refund_num = PlaySeat.refund(orderno, order.pid, seats)
     if not refund_num:
         return Code.ticket_refund_failed, {}
     order.status = OrderStatus.refund.value
     order.refund_time = datetime.now()
     order.save()
     return {'refund_num': refund_num}
Beispiel #17
0
    def buy(self):
        seats = request.params["seats"]
        orderno = request.params['orderno']
        order = Order.getby_orderno(orderno)
        # 判断目标order是否存在
        if not order:
            return Code.order_does_not_exist, request.params
        # 判断订单状态是否位锁定
        if order.status != OrderStatus.locked.value:
            # 不是锁定状态报错
            return Code.order_status_error, {
                "orderno": orderno,
                "status": order.status,
            }
        # 修改订单
        order.sell_order_no = request.params["orderno"]
        order.amount = order.amount or 0
        # 座位id
        sid_list = []
        # 计算价钱
        for sid, handle_fee, price in seats:
            sid_list.append(sid)
            order.amount += handle_fee + price
        # 座位购买数量
        bought_seats_num = PlaySeat.buy(orderno, order.pid, sid_list)
        # 判断操作是否成功
        if not bought_seats_num:
            return Code.seat_buy_failed, {}

        order.ticket_num = len(seats)
        order.status = OrderStatus.paid.value
        order.paid_time = datetime.now()
        order.gen_ticket_flag()
        order.save()

        return {
            "bought_seats_num": bought_seats_num,
            "ticket_flag": order.ticket_flag,
        }