def suspend_merchant(self, merchant_id, is_suspend): is_suspend = int(is_suspend) merchant = MerchantModel.get_by_id(self.db, merchant_id) if not merchant: raise JsonException(errcode=404, errmsg="merchant not fount") merchant.is_suspend = is_suspend CooperateHotelModel.set_suspend_by_merchant_id(self.db, merchant_id, is_suspend) self.db.commit() PushHotelTask().push_hotel_suspend_by_merchant_id.delay(merchant_id) return merchant
def push_by_merchant(self, merchant): from models.cooperate_hotel import CooperateHotelModel hotels = CooperateHotelModel.get_by_merchant_id(self.session, merchant.id) self.push_hotels(merchant, hotels) for hotel in hotels: self.push_room_by_hotel(merchant, hotel)
def get(self, merchant_id, hotel_id): hotel = CooperateHotelModel.get_by_id(self.db, hotel_id) if not hotel: raise JsonException(4001, 'hotel not found') contract_hotel = ContractHotelModel.get_by_hotel(self.db, hotel_id) if not contract_hotel: contract_hotel = ContractHotelModel.new( self.db, merchant_id=merchant_id, hotel_id=hotel_id, base_hotel_id=hotel.base_hotel_id, weekend="5,6") roomtypes = CooperateRoomTypeModel.get_by_hotel_id(self.db, hotel_id) contract_roomtypes = ContractRoomTypeModel.get_by_hotel( self.db, hotel_id) hotel_dict = hotel.todict() roomtype_dicts = [room.todict() for room in roomtypes] yield self.merge_base_info(hotel_dict, roomtype_dicts) self.finish_json(result=dict( hotel=hotel_dict, roomtypes=roomtype_dicts, contract_hotel=contract_hotel.todict() if contract_hotel else {}, contract_roomtypes=[c.todict() for c in contract_roomtypes], ))
def new_roomtype_coops(self, merchant_id, hotel_id, roomtype_ids): hotel = CooperateHotelModel.get_by_id(self.db, hotel_id) if not hotel: raise JsonException(1000, 'hotel not found') if hotel.merchant_id != merchant_id: raise JsonException(2000, 'merchant not valid') coops = CooperateRoomTypeModel.get_by_merchant_hotel_base_rooms_id(self.db, merchant_id, hotel_id, roomtype_ids) if coops: raise JsonException(1000, 'room has cooped') coops = CooperateRoomTypeModel.new_roomtype_coops(self.db, merchant_id, hotel.id, hotel.base_hotel_id, roomtype_ids, commit=False) for coop in coops: InventoryModel.insert_in_months(self.db, merchant_id, hotel_id, coop.id, hotel.base_hotel_id, coop.base_roomtype_id, 13, commit=False) r = yield HotelPusher(self.db).push_hotel_by_id(hotel_id) if not r: raise JsonException(3000, 'push hotel to stock fail') for coop in coops: r = yield InventoryAsyncPusher(self.db).push_by_roomtype(coop) if not r: raise JsonException(3001, 'push inventory to stock fail') r = yield POIRoomTypePusher(self.db).push_roomtype(coop.id) if not r: raise JsonException(3001, 'push roomtype to poi fail') self.db.commit() raise gen.Return(coops)
def push_hotel_suspend_by_merchant_id(self, merchant_id): self.log.info("<<push hotel by merchant {}>> start".format(merchant_id)) from models.cooperate_hotel import CooperateHotelModel hotels = CooperateHotelModel.get_by_merchant_id(self.session, merchant_id, with_delete=True) hotel_list = [{'chain_id': CHAIN_ID, "hotel_id": hotel.id, "is_valid": self.cal_hotel_is_valid(hotel)} for hotel in hotels] self.post_hotels_valid(merchant_id, hotel_list)
def push_by_merchant(self, merchant): from models.cooperate_hotel import CooperateHotelModel as Hotel hotels = Hotel.get_by_merchant_id(self.session, merchant.id, with_delete=True) hotel_datas = [self.get_hotel_data(hotel) for hotel in hotels] hotel_data_list = [hotel_datas[i : i+self.LEN_HOTEL] for i in range(0, len(hotel_datas), self.LEN_HOTEL)] for hotel_datas in hotel_data_list: self.post_hotels(hotel_datas)
def get(self, merchant_id, hotel_id): hotel = CooperateHotelModel.get_by_id(self.db, hotel_id) if not hotel: raise JsonException(4001, 'hotel not found') contract_hotel = ContractHotelModel.get_by_hotel(self.db, hotel_id) if not contract_hotel: contract_hotel = ContractHotelModel.new(self.db, merchant_id=merchant_id, hotel_id=hotel_id, base_hotel_id=hotel.base_hotel_id, weekend="5,6") roomtypes = CooperateRoomTypeModel.get_by_hotel_id(self.db, hotel_id) contract_roomtypes = ContractRoomTypeModel.get_by_hotel(self.db, hotel_id) hotel_dict = hotel.todict() roomtype_dicts = [room.todict() for room in roomtypes] yield self.merge_base_info(hotel_dict, roomtype_dicts) self.finish_json(result=dict( hotel=hotel_dict, roomtypes=roomtype_dicts, contract_hotel=contract_hotel.todict() if contract_hotel else {}, contract_roomtypes = [c.todict() for c in contract_roomtypes], ))
def push_hotel_by_id(self, hotel_id): Log.info("<<push hotel by id {}>>".format(hotel_id)) hotel = CooperateHotelModel.get_by_id(self.db, hotel_id, with_delete=True) if not hotel: Log.info("<<push hotel {}>> error hotel not exist".format(hotel_id)) raise gen.Return(False) r = yield self.push_hotel(hotel) raise gen.Return(r)
def push_by_merchant(self, merchant): from models.cooperate_hotel import CooperateHotelModel hotels = CooperateHotelModel.get_by_merchant_id( self.session, merchant.id) self.push_hotels(merchant, hotels) for hotel in hotels: self.push_room_by_hotel(merchant, hotel)
def push_hotel(self, hotel_id): self.log.info("<<push hotel {}>> start".format(hotel_id)) from models.cooperate_hotel import CooperateHotelModel hotel = CooperateHotelModel.get_by_id(self.session, hotel_id, with_delete=True) if not hotel: return hotel_data = self.get_hotel_data(hotel) self.post_hotel(hotel_data)
def change_hotel_online_status(self, merchant_id, hotel_id, is_online): hotel = CooperateHotelModel.get_by_merchant_id_and_hotel_id(self.db, merchant_id, hotel_id) if not hotel: raise JsonException(404, 'hotel not found') hotel.is_online = is_online self.db.commit() PushHotelTask().push_hotel.delay(hotel.id) return hotel
def get_cooped_hotels(self, merchant_id, name, city_id, star, start, limit): cooped_hotels = CooperateHotelModel.get_by_merchant_id(self.db, merchant_id) cooped_hotels_base_ids = [h.base_hotel_id for h in cooped_hotels] if not cooped_hotels_base_ids: raise gen.Return(([], 0)) base_hotels, total = yield self.fetch_hotels_info(cooped_hotels_base_ids, name, city_id, star, start, limit) hotels = self.merge_hotel_info(cooped_hotels, base_hotels) raise gen.Return((hotels, total))
def push_hotel_by_id(self, hotel_id): Log.info("<<push hotel by id {}>>".format(hotel_id)) hotel = CooperateHotelModel.get_by_id(self.db, hotel_id, with_delete=True) if not hotel: Log.info( "<<push hotel {}>> error hotel not exist".format(hotel_id)) raise gen.Return(False) r = yield self.push_hotel(hotel) raise gen.Return(r)
def new_hotel_cooprates(self, merchant_id, hotel_ids): coops = CooperateHotelModel.new_hotel_cooprates(self.db, merchant_id, hotel_ids, commit=False) hotel_pusher = HotelPusher(self.db) r = yield hotel_pusher.push_hotels(coops) if not r: self.db.rollback() raise JsonException(1000, 'push hotel to stock fail') else: self.db.commit() raise gen.Return(coops)
def new_hotel_cooprate(self, merchant_id, hotel_id): coop = CooperateHotelModel.get_by_merchant_id_and_base_hotel_id(self.db, merchant_id, hotel_id, with_delete=True) if coop and coop.is_delete == 0: raise JsonException(1000, u'已经合作') if not coop: coop = CooperateHotelModel.new_hotel_cooprate(self.db, merchant_id, hotel_id) else: coop.is_delete = 0 self.db.flush() r = yield HotelPusher(self.db).push_hotel(coop) if not r: raise JsonException(2000, 'push hotel to stock fail') r = yield POIHotelPusher(self.db).push_hotel(coop.id) if not r: raise JsonException(2000, 'push hotel to poi fail') self.db.commit() raise gen.Return(coop)
def push_by_merchant(self, merchant): from models.cooperate_hotel import CooperateHotelModel as Hotel hotels = Hotel.get_by_merchant_id(self.session, merchant.id, with_delete=True) hotel_datas = [self.get_hotel_data(hotel) for hotel in hotels] hotel_data_list = [ hotel_datas[i:i + self.LEN_HOTEL] for i in range(0, len(hotel_datas), self.LEN_HOTEL) ] for hotel_datas in hotel_data_list: self.post_hotels(hotel_datas)
def get_cooped_hotels(self, merchant_id, name, city_id, star, start, limit): cooped_hotels = CooperateHotelModel.get_by_merchant_id( self.db, merchant_id) cooped_hotels_base_ids = [h.base_hotel_id for h in cooped_hotels] if not cooped_hotels_base_ids: raise gen.Return(([], 0)) base_hotels, total = yield self.fetch_hotels_info( cooped_hotels_base_ids, name, city_id, star, start, limit) hotels = self.merge_hotel_info(cooped_hotels, base_hotels) raise gen.Return((hotels, total))
def get(self, hotel_id): hotel = Hotel.get_by_id(self.db, hotel_id) if hotel: merchant = MerchantModel.get_by_id(self.db, hotel.merchant_id) contract = ContractMerchantModel.get_by_merchant_id( self.db, merchant.id) if merchant: self.finish_json(result=dict( merchant=merchant.todict(), contract=contract.todict() if contract else None, )) return self.finish_json(result=dict(merchant={}))
def get(self, hotel_id): hotel = Hotel.get_by_id(self.db, hotel_id) if hotel: merchant = MerchantModel.get_by_id(self.db, hotel.merchant_id) contract = ContractMerchantModel.get_by_merchant_id(self.db, merchant.id) if merchant: self.finish_json(result=dict( merchant=merchant.todict(), contract=contract.todict() if contract else None, )) return self.finish_json(result=dict( merchant={}))
def new_hotel_cooprate(self, merchant_id, hotel_id): coop = CooperateHotelModel.get_by_merchant_id_and_base_hotel_id( self.db, merchant_id, hotel_id, with_delete=True) if coop and coop.is_delete == 0: raise JsonException(1000, u'已经合作') if not coop: coop = CooperateHotelModel.new_hotel_cooprate( self.db, merchant_id, hotel_id) else: coop.is_delete = 0 self.db.flush() r = yield HotelPusher(self.db).push_hotel(coop) if not r: raise JsonException(2000, 'push hotel to stock fail') r = yield POIHotelPusher(self.db).push_hotel(coop.id) if not r: raise JsonException(2000, 'push hotel to poi fail') self.db.commit() raise gen.Return(coop)
def push_hotel_suspend_by_merchant_id(self, merchant_id): self.log.info( "<<push hotel by merchant {}>> start".format(merchant_id)) from models.cooperate_hotel import CooperateHotelModel hotels = CooperateHotelModel.get_by_merchant_id(self.session, merchant_id, with_delete=True) hotel_list = [{ 'chain_id': CHAIN_ID, "hotel_id": hotel.id, "is_valid": self.cal_hotel_is_valid(hotel) } for hotel in hotels] self.post_hotels_valid(merchant_id, hotel_list)
def push_hotel(self, hotel_id): Log.info("<<POI push hotel mapping {}>> start".format(hotel_id)) if not IS_PUSH_TO_POI: raise gen.Return(True) hotel = CooperateHotelModel.get_by_id(self.db, hotel_id) if not hotel: raise gen.Return(False) merchant = MerchantModel.get_by_id(self.db, hotel.merchant_id) if not merchant: raise gen.Return(False) hotel_data = self.generate_data(hotel, merchant) r = yield self.post_hotel(hotel_data) raise gen.Return(r)
def delete(self, hotel_id): hotel = CooperateHotelModel.get_by_merchant_id_and_hotel_id(self.db, self.merchant.id, hotel_id) if not hotel: raise JsonException(1000, u'hotel not found') r = yield self.delete_hotel(hotel) if r: self.db.commit() self.finish_json(result=dict( hotel=hotel.todict() ) ) else: self.db.rollback() raise JsonException(2000, 'delete fail')
def push_hotel(self, hotel_id): Log.info("<<POI push hotel mapping {}>> start".format(hotel_id)) if not IS_PUSH_TO_POI: return from models.cooperate_hotel import CooperateHotelModel from models.merchant import MerchantModel hotel = CooperateHotelModel.get_by_id(self.session, hotel_id) if not hotel: return merchant = MerchantModel.get_by_id(self.session, hotel.merchant_id) if not merchant: return hotel_data = self.generate_data(hotel, merchant) self.post_hotel(hotel_data)
def get_cooped_base_hotel_ids(self, merchant_id): hotels = CooperateHotelModel.get_by_merchant_id(self.db, merchant_id) return [hotel.base_hotel_id for hotel in hotels]
def get_cooped_base_hotels(self, merchant_id, is_online, hotel_id=None): return CooperateHotelModel.get_by_merchant_id(self.db, merchant_id, is_online, hotel_id=hotel_id)
def get_cooped_base_hotels(self, merchant_id, is_online): return CooperateHotelModel.get_by_merchant_id(self.db, merchant_id, is_online)
def get_hotel(self, hotel_id): return CooperateHotelModel.get_by_id(self.db, hotel_id)