Exemple #1
0
 def get(self):
     user_id = self.current_user_id
     affiliate = Affiliate.find_one(dict(user_id=int(user_id)))
     user = User.find_one(dict(_id=int(affiliate.account_manager)))
     lastest_offers = Offers.sort_limit(
         [('_id', -1)], 10, dict(status={'$ne': '0'}, is_api={'$ne': True}))
     deloffers = []
     for offer in lastest_offers:
         off_aff = OfferAffiliate.find_one(
             dict(offer_id=int(offer._id), affiliate_id=user_id, deleted=False))
         if off_aff:
             if off_aff.payout:
                 offer.payment = off_aff.payout
             if offer.access_status == '0' and off_aff.status != '1':
                 deloffers.append(offer)
         else:
             if offer.access_status == '0':
                 deloffers.append(offer)
     for i in deloffers:
         lastest_offers.remove(i)
     offer_infos = OfferInfo.sort_limit(
         [('amount', -1)], 10, dict(affiliate_id=user_id))
     # feature offers
     condition = []
     for i in offer_infos:
         condition.append({'_id': i.offer_id})
     if condition:
         high_income_offers = Offers.find(
             {'$or': condition, 'status': {'$ne': '0'}, 'is_api': {'$ne': True}})
         deloffers = []
         for offer in high_income_offers:
             off_aff = OfferAffiliate.find_one(
                 dict(offer_id=int(offer._id), affiliate_id=user_id, deleted=False))
             if off_aff:
                 if off_aff.payout:
                     offer.payment = off_aff.payout
                 if offer.access_status == '0' and off_aff.status != '1':
                     deloffers.append(offer)
             else:
                 if offer.access_status == '0':
                     deloffers.append(offer)
         for i in deloffers:
             high_income_offers.remove(i)
     else:
         high_income_offers = []
     self.render(
         account_manager=user,
         lastest_offers=lastest_offers,
         high_income_offers=high_income_offers,
     )
Exemple #2
0
    def post(self):
        err = JsOb()
        if not self.json._ids:
            err.apply = u'offer can\'t be Null!'

        if not err:
            offers = []
            for offer_id in self.json._ids:
                affiliate_id = self.current_user_id
                off_aff = OfferAffiliate.find_one(
                    dict(offer_id=int(offer_id),
                         affiliate_id=int(affiliate_id),
                         deleted=False))
                offer = Offers.find_one(dict(_id=int(offer_id)))
                status = '1' if offer.access_status == '1' else '2'
                if not off_aff:
                    off_aff = OfferAffiliate._save(
                        **dict(offer_id=int(offer_id),
                               affiliate_id=int(affiliate_id),
                               status=status,
                               payout=offer.payment))
                else:
                    off_aff.payout = offer.payment
                    off_aff.status = status
                    off_aff.save()
                offers.append(offer)
            self.finish(dict(offers=offers, err=False))
        else:
            self.render(err)
Exemple #3
0
 def filter_offer(self, offer):
     off_aff = OfferAffiliate.find_one(
         dict(offer_id=int(offer._id),
              affiliate_id=self.current_user_id,
              deleted=False))
     if not off_aff or off_aff.status == '0':
         if offer.access_status != '0':
             return offer
Exemple #4
0
 def filter_offer_apply(self, offer):
     url = "tracks.leadhug.com/lh/click?offer_id={0}&affiliate_id={1}&click_id={{clickid}}&aff_sub1={{aff_sub1}}"
     off_aff = OfferAffiliate.find_one(
         dict(offer_id=int(offer._id),
              affiliate_id=self.current_user_id,
              deleted=False))
     if off_aff:
         offer['apply_status'] = off_aff.status
         if off_aff.status == '1':
             offer['tracking_link'] = url.format(offer._id,
                                                 self.current_user_id)
         return offer
Exemple #5
0
    def get(self):
        offer_id = self.get_argument('offer_id', None, strip=True)
        offer = Offers.find_one(dict(_id=int(offer_id)))
        off_aff = OfferAffiliate.find_one(
            dict(offer_id=int(offer._id),
                 affiliate_id=int(self.current_user_id),
                 deleted=False))

        if offer.platform == '1':
            offer.platform = 'IOS'
        elif offer.platform == '2':
            offer.platform = 'ANDROID'
        elif offer.platform == '0':
            offer.platform = 'All'

        if off_aff:
            if off_aff.payout:
                offer.payment = off_aff.payout
            if off_aff.day_cap:
                offer.day_cap = off_aff.day_cap
            if off_aff.month_cap:
                offer.month_cap = off_aff.month_cap
            if off_aff.total_cap:
                offer.total_cap = off_aff.total_cap

            if offer.access_status == '1':
                offer['application_status'] = '1'
            if offer.access_status == '2':
                if off_aff.status == '1':
                    offer['application_status'] = '1'
                else:
                    offer['application_status'] = off_aff.status
        else:
            offer['application_status'] = '3'
        if offer.category_id:
            category = Category.find_one(dict(_id=int(offer.category_id)))
            if category:
                offer['category'] = category.name
        self.render(
            aff_id=self.current_user_id,
            offer=offer,
        )
Exemple #6
0
    def get(self):
        email = self.get_argument('email')
        pagenum = self.get_argument('pagenum', 100)
        page = self.get_argument('page', 1)
        status = self.get_argument('status', 'all',
                                   strip=True)  # myOffers # all
        user = User.find_one(dict(email=email, deleted=False))
        if user:
            aff = Affiliate.find_one(
                dict(user_id=user._id, status={'$ne': '0'}))
            if aff:
                url = "http://tracks.leadhug.com/lh/click?offer_id={0}&affiliate_id={1}&click_id={{clickid}}&aff_sub1={{aff_sub1}}"
                if status == "all":
                    spec = {'is_api': True, 'is_expired': False}
                    offers = Offers.find(spec,
                                         sort=[('_id', -1)],
                                         limit=int(pagenum),
                                         skip=(int(page) - 1) * int(pagenum))
                    if page == 1:
                        to_api_offers = Offers.find(dict(to_api=True,
                                                         status='1'),
                                                    sort=[('_id', -1)])
                    else:
                        to_api_offers = []
                    all_offers = offers + to_api_offers
                else:
                    spec = {"status": '1'}
                    off_affs = OfferAffiliate.find(
                        dict(affiliate_id=int(aff.user_id),
                             status='1',
                             deleted=False))
                    offer_ids = [int(off_aff.offer_id) for off_aff in off_affs]
                    spec.update(dict(_id={'$in': offer_ids}))
                    all_offers = Offers.find(spec, sort=[('_id', -1)])
                    for offer in all_offers:
                        off_aff = OfferAffiliate.find_one(
                            dict(offer_id=int(offer._id),
                                 affiliate_id=aff.user_id,
                                 deleted=False))
                        if off_aff.payout:
                            offer.payment = off_aff.payout
                for offer in all_offers:
                    offer['click_url'] = url.format(offer._id, aff.user_id)
                    offer['_id'] = int(offer['_id'])
                    if offer['platform'] == '1':
                        offer['platform'] = 'ios'
                    if offer['platform'] == '2':
                        offer['platform'] = 'android'
                    del offer['revenue']
                    del offer['clicks']
                    del offer['advertiser_id']
                    del offer['user']
                    del offer['conversions']
                    del offer['access_status']
                    del offer['last_update']
                    del offer['price_model']
                    del offer['status']
                    del offer['mini_version']
                    del offer['exclude_geo_targeting']
                    del offer['offer_type']
                    del offer['black_ip']
                    del offer['traffic_time']
                    del offer['create_time']
                    del offer['root']
                    del offer['is_api']
                    # del offer['offer_type']
                    del offer['category_id']
                    del offer['tag']
                    del offer['rating']
                    del offer['restrictions']
                    del offer['is_expired']
                    del offer['to_api']
                self.finish(json_encode(all_offers))

            else:
                self.finish('email invalid!')
        else:
            self.finish("email not found!")
Exemple #7
0
    def get(self):
        spec = {"status": '1'}
        is_api = self.get_argument('is_api')
        if is_api == '0':
            spec.update(dict(is_api={"$ne": True}))
        country = self.get_arguments('countries[]')
        if country:
            spec.update(dict(geo_targeting=country))

        PriceModel = self.get_argument('price_model')
        if PriceModel:
            spec.update(dict(price_model=PriceModel))

        category = self.get_argument('categories')
        if category:
            spec.update(dict(category=category))

        min_payout = self.get_argument('payoutMin', 0)
        max_payout = self.get_argument('payoutMax', 10000)
        spec.update(
            dict(payment={
                '$gte': float(min_payout),
                '$lte': float(max_payout)
            }))

        limit = int(self.get_argument('limit', 20))
        page = int(self.get_argument('page', 1))

        off_affs = OfferAffiliate.find(
            dict(affiliate_id=int(self.current_user_id),
                 status='1',
                 deleted=False))
        offer_ids = [int(off_aff.offer_id) for off_aff in off_affs]
        spec.update(dict(_id={'$in': offer_ids}))

        offers = Offers.find(spec, sort=[('_id', -1)])
        url = "tracks.leadhug.com/lh/click?offer_id={0}&affiliate_id={1}&click_id={{clickid}}&aff_sub1={{aff_sub1}}"
        for offer in offers:
            off_aff = OfferAffiliate.find_one(
                dict(offer_id=int(offer._id),
                     affiliate_id=self.current_user_id,
                     deleted=False))
            if off_aff.payout:
                offer.payment = off_aff.payout
            offer['tracking_link'] = url.format(offer._id,
                                                self.current_user_id)
            conversions = off_aff.get('conversions', 0) if off_aff.get(
                'conversions', 0) else 0
            clicks = off_aff.get('clicks', 0) if off_aff.get('clicks',
                                                             0) else 0
            cost = off_aff.get('cost', 0) if off_aff.get('cost', 0) else 0

            offer['conversions'] = conversions
            offer['clicks'] = clicks
            offer['CR'] = float(conversions) / float(
                clicks) * 100 if clicks else 0
            offer['EPC'] = float(cost) / float(clicks) * 100 if clicks else 0
            offer['total'] = cost

        offers_count = len(offers)
        offers = offers[limit * (page - 1):limit * page]
        self.finish(dict(offers=offers, offers_count=offers_count))