Ejemplo n.º 1
0
 def refund_ticket(self):
     ordernum = request.params['ordernum']
     ticket_flag = request.params['ticket_flag']
     seats = request.params['s_id']
     # to seek the order
     order = Order.getby_orderno(ordernum)
     # when the order does not exist
     if not order:
         return Code.order_does_not_exist, {'ordernum': ordernum}
     # when the ticket is printed
     if order.status == OrderStatus.printed.value:
         return Code.ticket_printed_failed, {}
     # when the ticket flag lost efficacy
     if not order.validate(ticket_flag):
         return Code.ticket_flag_error, {'ticket_flag': ticket_flag}
     # to execute the function, the 'refund_num' is the return value of the function
     refund_num = PlaySeat.refund(ordernum, order.p_id, seats)
     # when the refund num equals zero, refund failed
     if not refund_num:
         return Code.ticket_refund_failed, {}
     # change the status to 'refund already'
     order.status = OrderStatus.refund.value
     # add the refund time
     order.refund_time = datetime.now()
     order.save()
     return {'refund_num': refund_num}
Ejemplo n.º 2
0
 def status(self):
     # to query the order status
     ordernum = request.params['ordernum']
     order = Order.getby_orderno(ordernum)
     if not order:
         return Code.order_does_not_exist, {"ordernum": ordernum}
     return {'status': order.status}
Ejemplo n.º 3
0
 def print_ticket(self):
     seats = request.params['s_id']
     ticket_flag = request.params['ticket_flag']
     ordernum = request.params['ordernum']
     # to seek the order
     order = Order.getby_orderno(ordernum)
     # if the order does not exist
     if not order:
         return Code.ticket_flag_error, {'ticket_flag': ticket_flag}
     if order.status == OrderStatus.printed.value:
         return Code.ticket_printed_already, {'status': order.status}
     if order.status != OrderStatus.paid.value:
         return Code.order_does_not_exist, {'status': order.status}
     # the ticket flag is wrong
     if not order.validate(ticket_flag):
         return Code.ticket_flag_error, {'ticket_flag': ticket_flag}
     # to execute the function and return the 'printed num', which means the number of the ticket
     printed_num = PlaySeat.print_tickets(order.seller_order_num,
                                          order.p_id, seats)
     if not printed_num:
         return Code.ticket_printed_failed, {}
     order.status = OrderStatus.printed.value
     order.printed_time = datetime.now()
     order.save()
     return {'printed_num': printed_num}
Ejemplo n.º 4
0
    def buy(self):
        seats = request.params['seats']
        ordernum = request.params['ordernum']
        order = Order.getby_orderno(ordernum)
        if not order:
            return Code.order_does_not_exist, {'ordernum': ordernum}
        if order.status != OrderStatus.locked.value:
            return Code.order_status_error, {
                'ordernum': ordernum,
                'status': order.status
            }
        order.seller_order_num = request.params['ordernum']

        # the amount of the order, if the amount does not exist equals to 0
        # a = a or b: a = a if a is empty, a = b
        order.amount = order.amount or 0
        s_id_list = []
        for s_id, handle_fee, price in seats:
            s_id_list.append(s_id)
            order.amount += handle_fee + price
        bought_seats_num = PlaySeat.buy(ordernum, order.p_id, s_id_list)
        if not bought_seats_num:
            return Code.seat_buy_failed, {}
        order.tickest_num = len(seats)
        order.paid_time = datetime.now()
        order.status = OrderStatus.paid.value

        # the inside function of order, to create a ticket code, which length is 32(the column should add 'unique')
        order.gen_ticket_flag()
        order.save()
        return {
            'bought_seats_num': bought_seats_num,
            'ticket_flag': order.ticket_flag
        }
Ejemplo n.º 5
0
    def lock(self):
        # to find the parameters of the seats from the 'request.params' of the 'try' of decorator
        p_id = request.params['p_id']
        s_id = request.params['s_id']
        price = request.params['price']
        ordernum = request.params['ordernum']
        # to find the play by p_id
        play = Play.get(p_id)
        # if cannot find the play in the database(the play is None)
        if not play:
            # return the status and the parameter
            return Code.play_does_not_exist, {'p_id': p_id}

        # if the price lower than the lowest price, return the status
        if price < play.lowest_price:
            return Code.price_less_than_the_lowest_price, {'price': price}

        # call the class function of 'lock' from the 'PlaySeat'
        # lock the seat that been selected, the 'locked_seats_num' is the return value of 'lock' function,the parameter inside 'lock()' is 'row'
        locked_seats_num = PlaySeat.lock(ordernum, p_id, s_id)

        # if the value of 'locked_seats_num(rows)' is 0, locked seat failed
        if not locked_seats_num:
            return Code.seat_lock_failed, {}

        # if the value is not 0, then create the order
        order = Order.create(play.c_id, p_id, s_id)
        order.seller_order_num = ordernum
        order.status = OrderStatus.locked.value
        order.tickest_num = locked_seats_num
        order.save()
        # return the value
        return {'locked_seats_num': locked_seats_num}
Ejemplo n.º 6
0
 def ticket_info(self):
     ordernum = request.params['ordernum']
     order = Order.getby_orderno(ordernum)
     if not order:
         return Code.order_does_not_exist, {'ordernum': ordernum}
     order.play = Play.get(order.p_id)
     order.movie = [Movie.get(order.play.m_id)]
     order.tickets = PlaySeat.getby_ordernum(ordernum)
     return order
Ejemplo n.º 7
0
 def unlock(self):
     p_id = request.params['p_id']
     s_id = request.params['s_id']
     ordernum = request.params['ordernum']
     order = Order.getby_orderno(ordernum)
     if not order:
         return Code.order_does_not_exist, {'ordernum': ordernum}
     if order.status != OrderStatus.locked.value:
         return Code.order_status_error, {}
     unlocked_seat_num = PlaySeat.unlock(ordernum, p_id, s_id)
     if not unlocked_seat_num:
         return Code.seat_unlock_failed, {}
     order.status = OrderStatus.unlocked.value
     order.save()
     return {'unlocked_seats_num': unlocked_seat_num}
Ejemplo n.º 8
0
 def ticket(self):
     ordernum = request.params['ordernum']
     order = Order.getby_orderno(ordernum)
     if not order:
         return Code.order_does_not_exist, {'ordernum': ordernum}
     return {'ticket_flag': order.ticket_flag}