Ejemplo n.º 1
0
 def buy(self):
     seats = request.params['seats']
     # print(seats)
     orderno = request.params['orderno']
     order = Order.getby_orderno(orderno)
     # print(order)
     if not order:
         return Code.order_does_not_exist, request.params
     if order.status != OrderStatus.locked.value:
         return Code.order_status_error, {
             'order': orderno,
             'status': order.status
         }
     # order.seller_order_no = request.params['orderno']
     order.seller_order_no = orderno
     # order.amount = order.amount or 0
     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.tickets_num = len(seats)
     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
     }
Ejemplo n.º 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_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}
Ejemplo n.º 3
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
Ejemplo n.º 4
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

        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 {'unlock_seats_num': unlocked_seats_num}
Ejemplo n.º 5
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, request.params
        if price < play.lowest_price:
            return Code.prcice_less_than_the_lowest_price, request.params[
                '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}
Ejemplo n.º 6
0
    def create_test_data(cls, cinema_num=10, hall_num=10, play_num=10):
        start_time = time.time()
        from FPproject.models.hall import Hall
        from FPproject.models.movie import Movie
        from FPproject.models.play import Play
        from FPproject.models.seat import Seat, PlaySeat
        from FPproject.models.order import Order
        f = faker.Faker('zh_CN')
        screen_type = ['普通', 'IMAX']
        audio_type = ['普通', '杜比环绕']
        for i in range(1, cinema_num + 1):
            cinema = Cinema()
            cinema.cid = i
            cinema.name = '%s国际影城' % f.name()
            cinema.address = f.address()
            cinema.status = 1
            cinema.save()

            for n in range(1, hall_num + 1):
                hall = Hall()
                hall.cid = cinema.cid
                hall.name = '%s号厅' % n
                hall.screen_type = random.choice(screen_type)
                hall.audio_type = random.choice(audio_type)
                hall.seats_num = 25
                hall.status = 1
                hall.save()
                # 根据seats——num生成座椅记录
                seats = []
                for s in range(1, hall.seats_num + 1):
                    seat = Seat()
                    seat.cid = cinema.cid
                    seat.hid = hall.hid
                    seat.x = s % 5 or 5
                    seat.y = math.ceil(s / 5)
                    seat.row = seat.x
                    seat.column = seat.y
                    seat.seat_type = 1
                    seat.put()
                    seats.append(seat)
                Seat.commit()

                for p in range(1, play_num + 1):
                    play = Play()
                    play.cid = cinema.cid
                    play.hid = hall.hid
                    play.mid = p
                    play.start_time = datetime.now()
                    play.duration = 3600
                    play.price_type = 1
                    play.price = 7000
                    play.market_price = 5000
                    play.lowest_price = 3000
                    play.status = 1
                    play.save()

                    for seat in seats:
                        ps = PlaySeat()
                        ps.pid = play.pid
                        ps.copy(seat)
                        ps.put()
                    PlaySeat.commit()
        current_app.logger.info('creat test data done! cost %s seconds' %
                                (time.time() - start_time))