def pre_check_order(self, order_entity): order = self.create_order(order_entity) if not order: raise JsonException(1, 'create order fail') if order.status != 0: return order # valid is roomtype online roomtype = CooperateRoomTypeModel.get_by_id(self.db, order.roomtype_id) if roomtype.is_online != 1: Log.info('roomtype is not online') order.status = 200 order.exception_info = 'roomtype is not online' self.db.commit() OrderHistoryModel.set_order_status_by_server(self.db, order, 0, 200) return order # valid is inventory enough if not self.valid_inventory(order_entity): Log.info('more room please') order.status = 200 order.exception_info = 'inventory not enough' self.db.commit() OrderHistoryModel.set_order_status_by_server(self.db, order, 0, 200) return order return order
def new_rate_plan(self, merchant_id, hotel_id, roomtype_id, name, meal_num, punish_type, ahead_days, stay_days, pay_type=None, guarantee_type=None, guarantee_start_time=None): room = CooperateRoomTypeModel.get_by_id(self.db, roomtype_id) if not room: raise JsonException(errcode=404, errmsg='room not exist') rate_plan = RatePlanModel.get_by_merchant_hotel_room_name( self.db, merchant_id, hotel_id, roomtype_id, name) if rate_plan: raise JsonException(errcode=405, errmsg="name exist") new_rateplan = RatePlanModel.new_rate_plan(self.db, merchant_id, hotel_id, roomtype_id, room.base_hotel_id, room.base_roomtype_id, name, meal_num, punish_type, ahead_days, stay_days, pay_type, guarantee_type, guarantee_start_time, commit=False) self.db.flush() new_roomrate = RoomRateModel.new_roomrate( self.db, hotel_id, roomtype_id, room.base_hotel_id, room.base_roomtype_id, new_rateplan.id, meal_num, commit=False) self.db.flush() rateplan_pusher = RatePlanPusher(self.db) roomrate_pusher = RoomRatePusher(self.db) try: if not (yield rateplan_pusher.post_rateplan(new_rateplan)): raise JsonException(2000, 'rateplan push fail') if not (yield rateplan_pusher.post_cancel_rule(new_rateplan)): raise JsonException(2001, 'cancel rule push fail') if not (yield roomrate_pusher.push_roomrate(new_rateplan.merchant_id, new_roomrate)): raise JsonException(2002, 'roomrate push fail') self.db.commit() except JsonException, e: self.db.rollback() raise e
def submit_order(self, order_json): Log.info(order_json) session = self.session try: submit_order = SubmitOrder(order_json) except ValueError as e: raise CeleryException(errcode=2000, errmsg=e.message) Log.info(submit_order) if not valid_arguments(submit_order): raise CeleryException(200, 'invalid_arguments') rate_plan = get_rateplan(session, submit_order) if not rate_plan: raise CeleryException(300, 'no rate plan') submit_order.pay_type = rate_plan.pay_type submit_order.merchant_id = rate_plan.merchant_id submit_order.cancel_type = rate_plan.cancel_type submit_order.punish_type = rate_plan.punish_type submit_order.punish_value = rate_plan.punish_value submit_order.guarantee_type = rate_plan.guarantee_type submit_order.guarantee_start_time = rate_plan.guarantee_start_time order = create_order(session, submit_order) if not order: raise CeleryException(session, 'create order fail') if order.status != 0: return order # valid is roomtype online roomtype = CooperateRoomTypeModel.get_by_id(self.session, order.roomtype_id) if roomtype.is_online != 1: Log.info('roomtype is not online') order.status = 200 session.commit() OrderHistoryModel.set_order_status_by_server(session, order, 0, 200) return order # valid is inventory enough if not valid_inventory(session, submit_order): Log.info('more room please') order.status = 200 session.commit() OrderHistoryModel.set_order_status_by_server(session, order, 0, 200) return order # second valid in spec queue task = start_order.apply_async(args=[order.id]) result = task.get() if task.status == 'SUCCESS': send_order_sms.delay(result.merchant_id, result.hotel_name, result.id, result.confirm_type) return result else: raise result
def pre_check_order(self, order_entity): order = self.create_order(order_entity) if not order: raise JsonException(1, 'create order fail') if order.status != 0: return order # valid is roomtype online roomtype = CooperateRoomTypeModel.get_by_id(self.db, order.roomtype_id) if roomtype.is_online != 1: Log.info('roomtype is not online') order.status = 200 order.exception_info = 'roomtype is not online' self.db.commit() OrderHistoryModel.set_order_status_by_server( self.db, order, 0, 200) return order # valid is inventory enough if not self.valid_inventory(order_entity): Log.info('more room please') order.status = 200 order.exception_info = 'inventory not enough' self.db.commit() OrderHistoryModel.set_order_status_by_server( self.db, order, 0, 200) return order return order
def start_order(self, order_id): session = self.session order = get_order(session, order_id) if not order: Log.info("query order {} is None".format(order_id)) return None if order.status != 0: return order # valid is roomtype online roomtype = CooperateRoomTypeModel.get_by_id(self.session, order.roomtype_id) if roomtype.is_online != 1: Log.info('roomtype is not online') order.status = 200 order.exception_info = 'roomtype is not online' session.commit() OrderHistoryModel.set_order_status_by_server(session, order, 0, 200) return order order = modify_inventory(session, order) if order.status != 0: OrderHistoryModel.set_order_status_by_server(session, order, 0, order.status) return order
def modify_cooped_roomtype(self, merchant_id, hotel_id, roomtype_id, prefix_name, remark_name): coop = CooperateRoomTypeModel.get_by_id(self.db, roomtype_id) if not coop: return JsonException(404, 'coop not found') if coop.merchant_id != merchant_id: return JsonException(1000, 'merchant not valid') coop.prefix_name = prefix_name coop.remark_name = remark_name self.db.commit() return coop
def push_roomtype(self, roomtype_id): Log.info("<<POI push room mapping {}>> start".format(roomtype_id)) room = CooperateRoomTypeModel.get_by_id(self.db, roomtype_id) if not room: Log.error("<<POI push room mapping {}>> no roomtype".format(roomtype_id)) raise gen.Return(False) room_data = self.generate_data(room) r = yield self.post_room(room_data) raise gen.Return(r)
def push_roomtype(self, roomtype_id): Log.info("<<POI push room mapping {}>> start".format(roomtype_id)) room = CooperateRoomTypeModel.get_by_id(self.db, roomtype_id) if not room: Log.error( "<<POI push room mapping {}>> no roomtype".format(roomtype_id)) raise gen.Return(False) room_data = self.generate_data(room) r = yield self.post_room(room_data) raise gen.Return(r)
def push_roomtype(self, roomtype_id): Log.info("<<POI push room mapping {}>> start".format(roomtype_id)) if not IS_PUSH_TO_POI: return from models.cooperate_roomtype import CooperateRoomTypeModel room = CooperateRoomTypeModel.get_by_id(self.session, roomtype_id) if not room: Log.error("no roomtype") return room_data = self.generate_data(room) self.post_room(room_data)
def push_by_roomtype_id(self, roomtype_id): roomtype = CooperateRoomTypeModel.get_by_id(self.db, roomtype_id) if not roomtype: return True start_day = datetime.date.today() days = [start_day + datetime.timedelta(days=i) for i in xrange(90)] days = [(day.year, day.month) for day in days] days = {}.fromkeys(days).keys() inventories = InventoryModel.get_by_roomtype_and_dates(self.db, roomtype_id, days) return self.post_inventory(inventories, roomtype.is_online)
def push_roomtype(self, roomtype_id): Log.info("<<POI push room mapping {}>> start".format(roomtype_id)) if not IS_PUSH_TO_POI: return from models.cooperate_roomtype import CooperateRoomTypeModel room = CooperateRoomTypeModel.get_by_id(self.session, roomtype_id) if not room: Log.error("no roomtype") return room_data = self.generate_data(room) self.post_room(room_data)
def push_by_roomtype_id(self, roomtype_id): roomtype = CooperateRoomTypeModel.get_by_id(self.db, roomtype_id) if not roomtype: return True start_day = datetime.date.today() days = [start_day + datetime.timedelta(days=i) for i in xrange(90)] days = [(day.year, day.month) for day in days] days = {}.fromkeys(days).keys() inventories = InventoryModel.get_by_roomtype_and_dates( self.db, roomtype_id, days) return self.post_inventory(inventories, roomtype.is_online)
def push_inventory(self, roomtype_id): self.log.info("<< push inventory (roomtype {})>>".format(roomtype_id)) from models.inventory import InventoryModel from models.cooperate_roomtype import CooperateRoomTypeModel roomtype = CooperateRoomTypeModel.get_by_id(self.session, roomtype_id) start_day = datetime.date.today() days = [start_day + datetime.timedelta(days=i) for i in xrange(90)] days = [(day.year, day.month) for day in days] days = {}.fromkeys(days).keys() inventories = InventoryModel.get_by_roomtype_and_dates(self.session, roomtype_id, days) self.post_inventory(inventories, roomtype.is_online)
def push_inventory(self, roomtype_id): self.log.info("<< push inventory (roomtype {})>>".format(roomtype_id)) from models.inventory import InventoryModel from models.cooperate_roomtype import CooperateRoomTypeModel roomtype = CooperateRoomTypeModel.get_by_id(self.session, roomtype_id) start_day = datetime.date.today() days = [start_day + datetime.timedelta(days=i) for i in xrange(90)] days = [(day.year, day.month) for day in days] days = {}.fromkeys(days).keys() inventories = InventoryModel.get_by_roomtype_and_dates( self.session, roomtype_id, days) self.post_inventory(inventories, roomtype.is_online)
def start_order(self, order_id): session = self.session order = get_order(session, order_id) if not order: Log.info("query order {} is None".format(order_id)) return None if order.status != 0: return order # valid is roomtype online roomtype = CooperateRoomTypeModel.get_by_id(self.session, order.roomtype_id) if roomtype.is_online != 1: Log.info('roomtype is not online') order.status = 200 order.exception_info = 'roomtype is not online' session.commit() OrderHistoryModel.set_order_status_by_server(session, order, 0, 200) return order order = modify_inventory(session, order) if order.status != 0: OrderHistoryModel.set_order_status_by_server(session, order, 0, order.status) return order
def push_by_roomtype_id(self, roomtype_id): roomtype = CooperateRoomTypeModel.get_by_id(self.db, roomtype_id) r = yield self.push_by_roomtype(roomtype) raise gen.Return(r)
def push_by_roomtype_id(self, roomtype_id): roomtype = CooperateRoomTypeModel.get_by_id(self.db, roomtype_id) r = yield self.push_by_roomtype(roomtype) raise gen.Return(r)