Example #1
0
    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
Example #2
0
    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
Example #3
0
    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)
Example #4
0
    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],
        ))
Example #5
0
    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)
Example #6
0
    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)
Example #7
0
 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)
Example #8
0
    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],
            ))
Example #9
0
 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)
Example #10
0
    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)
Example #11
0
    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)
Example #12
0
    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
Example #13
0
    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))
Example #14
0
    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
Example #15
0
    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)
Example #16
0
 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)
Example #17
0
    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)
Example #18
0
    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)
Example #19
0
 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)
Example #20
0
    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))
Example #21
0
    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={}))
Example #22
0
    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={}))
Example #23
0
    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)
Example #24
0
    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)
Example #25
0
    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)
Example #26
0
    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)
Example #27
0
    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)
Example #28
0
    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')
Example #29
0
    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')
Example #30
0
    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)
Example #31
0
    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)
Example #32
0
 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]
Example #33
0
 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)
Example #34
0
 def get_cooped_base_hotels(self, merchant_id, is_online):
     return CooperateHotelModel.get_by_merchant_id(self.db, merchant_id,
                                                   is_online)
Example #35
0
 def get_hotel(self, hotel_id):
     return CooperateHotelModel.get_by_id(self.db, hotel_id)