def post(self, hotel_id): roomtype = ObjectDict(json_decode(self.request.body)) if not self.valid_roomtype(roomtype): return self.finish_json(errcode=401, errmsg="无效的参数") hotel = Hotel.get_by_id(self.db, hotel_id) if not hotel: return self.finish_json(errcode=404, errmsg="无效的Hotel") _roomtype = RoomType.new(self.db, hotel_id, **roomtype) try: module = modules['first_valid'] motivation = motivations['add_roomtype'] operator = self.current_user poi_hotel_id =hotel.id poi_roomtype_id = _roomtype.id otaId = -1 hotel_id = "-1" hotelModel = Hotel.get_by_id(self.db,poi_hotel_id) hotelName = hotelModel.name roomType = RoomType.get_by_id(self.db,id=poi_roomtype_id) operate_content = u"新增"+_roomtype.name+"," + roomtypes[_roomtype.bed_type]+"," + str(_roomtype.floor) + u"楼" PoiOperateLogMapping.record_log(self.db,otaId=otaId,hotelName=hotelName,module=module,motivation=motivation,operator=operator, poi_hotel_id=poi_hotel_id,operate_content=operate_content,hotel_id=hotel_id,poi_roomtype_id=poi_roomtype_id) except Exception,e: traceback.print_exc()
def post(self): args = self.get_json_arguments() chain_hotel_id, main_hotel_id, merchant_id, merchant_name = get_and_valid_arguments(args, 'chain_hotel_id', 'main_hotel_id', 'merchant_id', 'merchant_name') hotel = HotelModel.get_by_id(self.db, main_hotel_id) hotel_mapping = HotelMappingModel.get_by_provider_hotel(self.db, 6, chain_hotel_id,is_delete=-1) if hotel_mapping: Log.info(">>> modify exist ebooking hotel {}".format(hotel_mapping.todict())) hotel_mapping.merchant_id = merchant_id hotel_mapping.merchant_name = merchant_name hotel_mapping.info = 'update by ebooking' hotel_mapping.status = hotel_mapping.STATUS.valid_complete hotel_mapping.city_id = hotel.city_id hotel_mapping.provider_hotel_name = hotel.name hotel_mapping.provider_hotel_address = hotel.address hotel_mapping.main_hotel_id = hotel.id hotel_mapping.is_delete = 0 self.db.commit() else: hotel_mapping = HotelMappingModel.new_hotel_mapping_from_ebooking(self.db, chain_hotel_id, hotel.name, hotel.address, hotel.city_id, main_hotel_id, merchant_id, merchant_name) self.finish_json(result=dict( hotel_mapping=hotel_mapping.todict(), ))
def put(self, hotel_mapping_id): Log.info("Second>>Hotel {}>>Valid>> user:{}".format(hotel_mapping_id, self.current_user)) hotel_mapping = HotelMapping.get_by_id(self.db, hotel_mapping_id) if hotel_mapping and hotel_mapping.status == hotel_mapping.STATUS.wait_second_valid\ and hotel_mapping.main_hotel_id != 0: hotels = HotelMapping.get_by_chain_id_and_main_hotel_id(self.db, hotel_mapping.provider_id, hotel_mapping.main_hotel_id) for hotel in hotels: if hotel.id != hotel_mapping.id and hotel.status > hotel_mapping.status: self.finish_json(errcode=402, errmsg=u"已有Hotel{}绑定相同基础酒店".format(hotel.provider_hotel_name)) return hotel_mapping = HotelMapping.set_secondvalid_complete(self.db, hotel_mapping_id) try: module = modules['second_valid'] motivation = motivations['pass_hotel'] operator = self.current_user poi_hotel_id = hotel_mapping.main_hotel_id otaId = hotel_mapping.provider_id hotelName = hotel_mapping.provider_hotel_name hotelModel = Hotel.get_by_id(self.db,id=poi_hotel_id) operate_content = hotelName + "<->" + hotelModel.name hotel_id = hotel_mapping_id PoiOperateLogMapping.record_log(self.db,otaId=otaId,hotelName=hotelName,module=module,motivation=motivation,operator=operator,poi_hotel_id=poi_hotel_id,operate_content=operate_content,hotel_id=hotel_id) except Exception,e: traceback.print_exc() self.finish_json(result=ObjectDict( hotel_mapping=hotel_mapping.todict(), ))
def put(self): req = ObjectDict(json_decode(self.request.body)) Log.info("Polymer>>Hotel>>Online>> user:{} req:{}".format(self.current_user, req)) hotel_mapping_id = req.hotel_mapping_id is_online = req.is_online hotel_mapping = HotelMapping.get_by_id(self.db, hotel_mapping_id) if hotel_mapping and hotel_mapping.status == hotel_mapping.STATUS.valid_complete: hotel_mapping = HotelMapping.set_online(self.db, hotel_mapping_id, is_online) if hotel_mapping.is_online in [0, -1]: RoomTypeMapping.disable_by_provider_hotel_id(self.db, hotel_mapping.provider_hotel_id) try: redisClient.put('poi_online',hotel_mapping.main_hotel_id) except Exception,e: traceback.print_exc() yield self.notify_stock(hotel_mapping.provider_id, hotel_mapping.provider_hotel_id) try: module = modules['merge'] motivation = None if is_online in [0, -1]: motivation = motivations['offline_hotel'] else: motivation = motivations['online_hotel'] operator = self.current_user poi_hotel_id = hotel_mapping.main_hotel_id otaId = hotel_mapping.provider_id hotelName = hotel_mapping.provider_hotel_name hotelModel = Hotel.get_by_id(self.db,id=poi_hotel_id) operate_content = hotelName + "<->" + hotelModel.name hotel_id = hotel_mapping_id PoiOperateLogMapping.record_log(self.db,otaId=otaId,hotelName=hotelName,module=module,motivation=motivation,operator=operator,poi_hotel_id=poi_hotel_id,operate_content=operate_content,hotel_id=hotel_id) except Exception,e: traceback.print_exc()
def put(self, hotel_id): roomtype = ObjectDict(json_decode(self.request.body)) if not self.valid_roomtype(roomtype): return self.finish_json(errcode=401, errmsg="无效的参数") hotel = Hotel.get_by_id(self.db, hotel_id) if not hotel: return self.finish_json(errcode=404, errmsg="无效的Hotel") tempRoomType = RoomType.get_by_id(self.db,roomtype['id']) tempName = tempRoomType.name tempBedType = tempRoomType.bed_type tempFloor = tempRoomType.floor tempArea = tempRoomType.area _roomtype = RoomType.update(self.db, **roomtype) try: module = modules['first_valid'] motivation = motivations['modify_roomtype'] operator = self.current_user poi_hotel_id =hotel.id poi_roomtype_id = _roomtype.id otaId = -1 hotel_id = "-1" hotelModel = Hotel.get_by_id(self.db,poi_hotel_id) hotelName = hotelModel.name roomType = RoomType.get_by_id(self.db,id=poi_roomtype_id) operate_content = '' if tempName != _roomtype.name: operate_content += u'将' + tempName + u"修改为" + _roomtype.name + "," if tempBedType != _roomtype.bed_type: operate_content += u'将' + roomtypes[tempBedType] + u'修改为' + roomtypes[_roomtype.bed_type] + "," if tempFloor != _roomtype.floor: operate_content += u'将' + str(tempFloor) + "楼修改为" + str(_roomtype.floor) + "楼," if tempArea != _roomtype.area: operate_content += u'将' + str(tempArea) + "平米修改为" + str(_roomtype.area) + "平米," PoiOperateLogMapping.record_log(self.db,otaId=otaId,hotelName=hotelName,module=module,motivation=motivation,operator=operator, poi_hotel_id=poi_hotel_id,operate_content=operate_content,hotel_id=hotel_id,poi_roomtype_id=poi_roomtype_id) except Exception,e: traceback.print_exc()
def get(self, hotel_id): need_valid = self.get_query_argument('need_valid', 1) need_valid = True if need_valid == 1 else False hotel = Hotel.get_by_id(self.db, hotel_id) if hotel: hotel = hotel.todict() rooms = RoomType.gets_by_hotel_id(self.db, hotel_id, need_valid=need_valid) rooms = [room.todict() for room in rooms] return self.finish_json(result=dict( roomtypes=rooms, hotel=hotel, )) else: return self.finish_json(errcode=404, errmsg="无效的Hotel")
def add_hotel_mapping(self, hotel): Log.info(">>> push ebooking hotel {}".format(hotel)) hotel_mapping = HotelMappingModel.get_by_provider_hotel(self.db, 6, hotel['chain_hotel_id'],is_delete=-1) main_hotel = HotelModel.get_by_id(self.db, hotel['main_hotel_id']) if hotel_mapping: Log.info(">>> modify exist ebooking hotel {}".format(hotel)) hotel_mapping.merchant_id = hotel['merchant_id'] hotel_mapping.merchant_name = hotel['merchant_name'] hotel_mapping.info = 'update by ebooking' hotel_mapping.status = hotel_mapping.STATUS.valid_complete hotel_mapping.city_id = main_hotel.city_id hotel_mapping.provider_hotel_name = main_hotel.name hotel_mapping.provider_hotel_address = main_hotel.address hotel_mapping.main_hotel_id = main_hotel.id hotel_mapping.is_delete = 0 self.db.commit() else: Log.info(">>> new exist ebooking hotel {}".format(hotel)) hotel_mapping = HotelMappingModel.new_hotel_mapping_from_ebooking(self.db, hotel['chain_hotel_id'], main_hotel.name, main_hotel.address, main_hotel.city_id, hotel['main_hotel_id'], hotel['merchant_id'], hotel['merchant_name']) return hotel_mapping
def delete(self, hotel_mapping_id): Log.info("Second>>Hotel {}>>Delete>> user:{}".format(hotel_mapping_id, self.current_user)) hotel_mapping = HotelMapping.get_by_id(self.db, hotel_mapping_id) if hotel_mapping and hotel_mapping.status == hotel_mapping.STATUS.wait_second_valid: hotel_mapping = HotelMapping.revert_to_firstvalid(self.db, hotel_mapping_id) RoomTypeMapping.revert_to_firstvalid_by_provider_hotel_id(self.db, hotel_mapping.provider_hotel_id) try: module = modules['second_valid'] motivation = motivations['back_hotel'] operator = self.current_user poi_hotel_id = hotel_mapping.main_hotel_id otaId = hotel_mapping.provider_id hotelName = hotel_mapping.provider_hotel_name hotelModel = Hotel.get_by_id(self.db,id=poi_hotel_id) operate_content = hotelName + "<->" + hotelModel.name hotel_id = hotel_mapping_id PoiOperateLogMapping.record_log(self.db,otaId=otaId,hotelName=hotelName,module=module,motivation=motivation,operator=operator,poi_hotel_id=poi_hotel_id,operate_content=operate_content,hotel_id=hotel_id) except Exception,e: traceback.print_exc() self.finish_json(result=ObjectDict( hotel_mapping=hotel_mapping.todict(), ))