Esempio n. 1
0
    def get(self):
        spec = {"status": '1', "is_api": {"$ne": True}}
        fields = dict(_id=1,
                      title=1,
                      payment=1,
                      access_status=1,
                      preview_url=1)
        _type = self.get_argument('_type')
        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))

        id_or_name = self.get_argument('offerSearch')
        if id_or_name:
            if id_or_name.isdigit():
                spec.update(dict(_id=int(id_or_name)))
            else:
                spec.update(dict(title=id_or_name))

        if _type == 'need_approived':
            access_status = self.get_argument('access_status')
            if access_status:
                spec.update(dict(access_status=access_status))

            offers = Offers.find(spec, fields, sort=[('_id', -1)])
            offers = filter(self.filter_offer, offers)
        elif _type == 'applied':
            offers = Offers.find(spec, fields, sort=[('_id', -1)])
            offers = filter(self.filter_offer_apply, offers)
            application_status = self.get_argument('approvalStatus')
            if application_status:
                offers = filter(
                    lambda offer: offer['apply_status'] == application_status,
                    offers)

        offers_count = len(offers)
        offers = offers[limit * (page - 1):limit * page]

        self.finish(dict(offers=offers, offers_count=offers_count))
Esempio n. 2
0
 def get(self):
     id_or_name = self.get_argument('q')
     spec = dict()
     if id_or_name.isdigit():
         spec.update({'_id': int(id_or_name)})
     else:
         spec.update({'title': {'$regex': id_or_name, '$options': "$i"}})
     offers = Offers.find(spec, {'title': 1}, limit=10)
     offers = [{'first_name': i._id, 'last_name': i.title} for i in offers]
     self.finish(json.dumps(offers))
Esempio n. 3
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,
     )
Esempio n. 4
0
    def get(self):
        offer_spce = dict(status={"$ne": 0}, is_api={"$ne": True})
        offers = Offers.find(offer_spce, dict(_id=1, title=1))

        affiliate_spec = dict(status={"$ne": 0})
        affiliates = Affiliate.find(affiliate_spec, dict(user_id=1))
        for aff in affiliates:
            user = User.find_one(dict(_id=int(aff.user_id)),
                                 dict(_id=1, account=1))
            if not user:
                continue
            aff['_id'] = user._id
            aff['name'] = user.account

        advertiser_spec = dict(status={"$ne": 0})
        advertisers = Advertisers.find(advertiser_spec, dict(user_id=1))
        for ad in advertisers:
            user = User.find_one(dict(_id=int(ad.user_id)),
                                 dict(_id=1, account=1))
            if not user:
                continue
            ad['_id'] = user._id
            ad['name'] = user.account

        categories = Category.find(dict(status={"$ne": 0}), dict(_id=1,
                                                                 name=1))

        ams = User.find(dict(role_id=Role.am()._id, deleted=False),
                        dict(_id=1, account=1, role_id=1))
        ams = [am for am in ams if am.role_id and am._role == 'AM']
        bds = User.find(dict(role_id=Role.bd()._id, deleted=False),
                        dict(_id=1, account=1, role_id=1))
        bds = [bd for bd in bds if bd.role_id and bd._role == 'BD']
        self.finish(
            dict(offers=offers,
                 affiliates=affiliates,
                 advertisers=advertisers,
                 categories=categories,
                 ams=ams,
                 bds=bds))
Esempio n. 5
0
    def post(self):
        err = JsOb()
        content = loads(self.request.body)
        if content.get('affiliate_ids'):
            affiliate_ids = [int(_id) for _id in content.get('affiliate_ids')]
            affiliates = User.find(dict(_id={'$in': affiliate_ids}))
            for aff in affiliates:
                content['affiliate_id'] = aff._id
                if not content.get('payout'):
                    offer = Offers.find_one(
                        dict(_id=int(content.get('offer_id'))))
                    content['payout'] = offer.payment
                OAffiliates._save(**content)

        elif content.get('offer_ids'):
            offer_ids = [int(_id) for _id in content.get('offer_ids')]
            offers = Offers.find(dict(_id={'$in': offer_ids}))
            for offer in offers:
                content['offer_id'] = offer._id
                OAffiliates._save(**content)

        off_affs = OAffiliates.find(dict(status={'$ne': '0'}))
        self.finish(dict(off_affs=off_affs))
Esempio n. 6
0
    def get(self, action):
        obj_list = []
        if action == 'affiliate':
            offer_id = self.get_argument('offer_id')
            off_affs = OAffiliates._query(offer_ids=[offer_id])
            obj_ids = [off_aff.affiliate_id for off_aff in off_affs]
            affilate_extends = Affiliate.find(
                dict(account_manager={"$ne": ''}, status={'$ne': '0'}))
            objs = User.find(
                dict(_id={
                    "$in": [
                        int(aff.user_id) for aff in affilate_extends
                        if aff.account_manager
                    ]
                },
                     deleted=False))
            res = dict(affiliates=obj_list)

        elif action == 'offers':
            affiliate_id = self.get_argument('affiliate_id')
            off_affs = OAffiliates._query(affiliate_id=affiliate_id)
            obj_ids = [off_aff.offer_id for off_aff in off_affs]
            objs = Offers.find({
                'status': {
                    '$ne': '0'
                },
                'is_api': {
                    "$ne": True
                }
            })
            res = dict(offers=obj_list)

        for obj in objs:
            if int(obj._id) not in obj_ids:
                obj_list.append(obj)

        self.finish(res)
Esempio n. 7
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!")
Esempio n. 8
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))
Esempio n. 9
0
 def get(self):
     affiliate_id = self.current_user_id
     off_affs = OfferAffiliate._query(affiliate_id=affiliate_id)
     offer_ids = [off_aff.offer_id for off_aff in off_affs]
     offers = Offers.find(dict(_id={'$in': offer_ids}))
     self.render(countries=_c().countries, offers=offers)
Esempio n. 10
0
    def get(self):
        filter = loads(self.get_argument('filter', ''))
        offer_id = filter.get('offer_id')
        is_api = filter.get('is_api')
        status = filter.get('status')
        category = filter.get('category')
        price_model = filter.get('price_model')
        advertiser = filter.get('advertiser')
        country = filter.get('geo', '')
        payment_min = filter.get('payout_min')
        payment_max = filter.get('payout_mix')

        is_api = True if is_api == '1' else {"$ne": True}
        query = {"is_api": is_api}
        if offer_id:
            query["_id"] = int(offer_id)
        if status:
            query["status"] = status
        if category:
            query["category"] = category
        if price_model:
            query["price_model"] = price_model
        if advertiser:
            query["advertiser"] = advertiser
        if country:
            country_list = country.split(',')
            query["geo_targeting"] = country if len(country_list) == 1 else {
                '$in': country_list
            }
        if payment_max or payment_min:
            query["payment"] = {}
        if payment_min:
            query["payment"]["$gte"] = float(payment_min)
        if payment_max:
            query["payment"]["$lte"] = float(payment_max)
        offers = Offers.find(query, sort=[('_id', 1)])
        fields = [
            '_id', 'name', 'category', 'payout_model', 'advertiser', 'payout',
            'revenue', 'preview_url', 'geo_count', 'clicks', 'conversions',
            'day_cap', 'total_cap'
        ]
        result_offers = []
        for offer in offers:
            if offer.status == '0':
                offer.status = 'Paused'
            elif offer.status == '1':
                offer.status = 'Active'
            else:
                offer.status = 'Pending'

            if offer.price_model == '1':
                offer.price_model = 'CPA'
            elif offer.price_model == '2':
                offer.price_model = 'CPS'
            elif offer.price_model == '3':
                offer.price_model = 'CPC'

            if offer.advertiser_id:
                ad = User.find_one(dict(_id=int(offer.advertiser_id)))
                offer['advertiser'] = ad.account
            if offer.category_id:
                category = Category.find_one(dict(_id=int(offer.category_id)))
                offer['category'] = category.name
            off_tmp = dict(_id=offer._id,
                           name=offer.title,
                           category=offer.get('category'),
                           payout_model=offer.price_model,
                           advertiser=offer.get('advertiser'),
                           payout=offer.payment,
                           revenue=offer.revenue,
                           preview_url=offer.preview_url,
                           geo_count=len(offer.geo_targeting),
                           clicks=offer.clicks,
                           conversions=offer.conversions,
                           day_cap=offer.day_cap,
                           total_cap=offer.total_cap)
            result_offers.append(off_tmp)

        with open('offer.csv', 'wb') as f:
            f.write(codecs.BOM_UTF8)
            fieldnames = fields
            dict_writer = csv.DictWriter(f, fieldnames=fieldnames)
            dict_writer.writeheader()
            dict_writer.writerows(result_offers)

        file = open('offer.csv', 'r')
        self.set_header('Content-Type', 'application/octet-stream')
        self.set_header('Content-Disposition',
                        'attachment; filename=offer.csv')
        self.write(file.read())
Esempio n. 11
0
    def post(self):
        _ids = self.json.offer_ids
        status = self.json.status
        is_api = self.json.is_api
        category = self.json.category
        price_model = self.json.price_model
        advertiser = self.json.advertiser
        country = self.json.country
        payment_min = self.json.payment_min
        payment_max = self.json.payment_max
        limit = 100 if not self.json.limit else int(self.json.limit)
        page = 1 if not self.json.page else int(self.json.page)
        skip = (page - 1) * limit
        is_api = True if is_api == '1' else {"$ne": True}

        query = {'is_api': is_api}
        if _ids:
            query["_id"] = {"$in": [int(id) for id in _ids]}
        if status:
            query["status"] = status
        if category:
            query["category"] = category
        if price_model:
            query["price_model"] = price_model
        if advertiser:
            query["advertiser"] = advertiser
        if country:
            country_list = country.split(',')
            query["geo_targeting"] = country if len(country_list) == 1 else {
                '$in': country_list
            }
        if payment_max or payment_min:
            query["payment"] = {}
        if payment_min:
            query["payment"]["$gte"] = float(payment_min)
        if payment_max:
            query["payment"]["$lte"] = float(payment_max)

        offers_count = Offers.count(query)
        offers = Offers.find(query, sort=[('_id', 1)], limit=limit, skip=skip)
        advertiser_extends = Advertisers.find(dict(status={"$ne": '0'}))
        advertisers = User.find(
            dict(_id={'$in': [int(ad.user_id) for ad in advertiser_extends]},
                 deleted=False))
        categories = Category.find(dict(status={"$ne": '0'}))
        for offer in offers:
            if offer.status == '0':
                offer.status = 'Paused'
            elif offer.status == '1':
                offer.status = 'Active'
            else:
                offer.status = 'Pending'

            if offer.price_model == '1':
                offer.price_model = 'CPA'
            elif offer.price_model == '2':
                offer.price_model = 'CPS'
            elif offer.price_model == '3':
                offer.price_model = 'CPC'

            if offer.advertiser_id:
                ad = User.find_one(dict(_id=int(offer.advertiser_id)))
                offer['advertiser'] = ad.account
            if offer.category_id:
                category = Category.find_one(dict(_id=int(offer.category_id)))
                offer['category'] = category.name
        self.finish(
            dict(
                offers_count=offers_count,
                offers=offers,
                advertisers=advertisers,
                categories=categories,
            ))