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}
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}
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}
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, }
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}
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}
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, }
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
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}
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}
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}
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}
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, }