示例#1
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)
示例#2
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,
     )
示例#3
0
    def post(self):
        status = self.get_argument('status', '')
        page = int(self.get_argument('page', '1'))
        limit = int(self.get_argument('limit', '100'))
        skip = (page - 1) * limit

        affs = Affiliate.find(
            dict(
                status={"$ne": '0'} if not status or status == '0' else status,
                # account_manager=int(self.current_user_id) if not self.current_user.is_admin else {'$ne': ''}
            ),
            limit=limit,
            skip=skip)
        for aff in affs:
            aff.status = 'Active' if aff.status == '1' else 'Pending'
            user = User._get(aff.user_id)
            if aff.account_manager:
                account_manager = User._get(aff.account_manager)
                aff.account_manager = account_manager.account
            aff['name'] = user.account
            aff['email'] = user.email
            aff['password'] = user.password
            aff['_id'] = user._id
            aff['skype_id'] = user.skype_id
            aff['phone'] = user.phone
            aff['offer_count'] = OAffiliate.count(
                dict(affiliate_id=int(aff._id)))
        affs_count = Affiliate.count(
            dict(
                status={"$ne": '0'} if not status or status == '0' else status,
                # account_manager=int(self.current_user_id) if not self.current_user.is_admin else {'$ne': ''}
            ))

        self.finish(dict(affs=affs, affs_count=affs_count))
示例#4
0
    def send_email(self, pause_date, offer_id):
        offer = Offers.find_one(dict(_id=int(offer_id)))
        offer_affiliate = OAffiliate.find(
            dict(offer_id=int(offer_id), status='1'), dict(affiliate_id=1))
        affiliate_uses = User.find(
            dict(_id={
                "$in":
                [int(off_aff.affiliate_id) for off_aff in offer_affiliate]
            }), dict(email=1))

        emails = map(lambda user: user.email, affiliate_uses)
        if not emails:
            return False
        recivers = reduce(lambda email_1, email_2: email_1.extend(email_2),
                          emails, [])
        content = dict(
            user_id=self.current_user_id,
            model_id=0,
            receiver=recivers,
            message=u'The offer named {offer} will be paused on {pause_date}'.
            format(offer=offer.title, pause_date=pause_date),
            subject=u'Leadhug offer paused notification',
            sender=self.current_user.account)
        EMail._create(**content)
        return True
示例#5
0
    def post(self):
        off_aff_id = self.json.off_aff_id
        res = OAffiliates._delete(off_aff_id)

        result = u'Successful' if res else u'Delete failure, off_aff_id={}'.format(
            off_aff_id)

        self.finish(dict(res=result))
示例#6
0
 def post(self):
     err = JsOb()
     content = loads(self.request.body)
     off_aff_id = content.get('_id')
     res = OAffiliates._update(**content)
     if not res:
         err.error = u'update OfferAffiliate failure! ID={}'.format(
             off_aff_id)
示例#7
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
示例#8
0
    def get(self):
        status = {'0': 'Paused', '1': 'Active', '2': 'Pending'}
        offer_id = self.get_argument('offer_id')
        offer = Offers.find_one(dict(_id=int(offer_id)))
        if not offer:
            self.write(u'The offer is not exist!')
            return
        offer.status = status.get(offer.status)
        if offer.advertiser_id:
            ad = User._get(offer.advertiser_id)
            offer['advertiser'] = ad.account if ad else ''

        category = Category.find_one(
            _id=int(offer.category_id)) if offer.category_id else None
        offer['category'] = category.name if category else ''

        category = Category.find_one(
            _id=int(offer.category_id)) if offer.category_id else None
        offer['category'] = category.name if category else ''

        if offer.access_status == '1':
            offer.access_status = 'Public'
        elif offer.access_status == '2':
            offer.access_status = 'Need Approve'
        else:
            offer.access_status = 'Private'

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

        offer_affiliates = OAffiliate._query(offer_ids=[offer_id])
        for off_aff in offer_affiliates:
            affiliate = User.find_one(dict(_id=int(off_aff.affiliate_id)))
            affiliate_extend = Affiliate.find_one(
                dict(user_id=int(off_aff.affiliate_id)))
            if not affiliate_extend or not affiliate_extend.account_manager:
                off_aff['am_name'] = ''
            elif off_aff.status == '1':
                am = User.find_one(
                    dict(_id=int(affiliate_extend.account_manager)))
                off_aff['am_name'] = am.account
            off_aff['affiliate_name'] = affiliate.account if affiliate else ''
            if off_aff.status == '1':
                off_aff['application_status'] = 'Approved'
            elif off_aff.status == '2':
                off_aff['application_status'] = 'Pending'
            else:
                off_aff['application_status'] = 'Rejected'

        self.render(offer=offer, offer_affiliates=offer_affiliates)
示例#9
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
示例#10
0
    def get(self):
        offer_ids = self.get_arguments('offer_ids[]')
        active_offer_affiliate = OfferAffiliate._query(offer_ids=offer_ids)

        affiliate_emails = []
        for off_aff in active_offer_affiliate:
            aff_id = off_aff.affiliate_id
            if aff_id:
                aff = User.find_one(dict(_id=int(aff_id)))
                if aff:
                    affiliate_emails.append(','.join(aff.email))

        self.finish(dict(affiliate_emails=affiliate_emails))
示例#11
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))
示例#12
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)
示例#13
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,
        )
示例#14
0
    def get(self):
        affiliate_user_id = self.get_argument('affiliate_id')
        affiliate = Affiliate.find_one(dict(user_id=int(affiliate_user_id)))
        affiliate_user = User.find_one(dict(_id=int(affiliate_user_id)))
        if not affiliate or not affiliate_user:
            self.write(u'The affiliate is not exist!')
            return
        affiliate._id = affiliate.user_id
        affiliate['name'] = affiliate_user.account
        affiliate['email'] = affiliate_user.email
        affiliate['skype_id'] = affiliate_user.skype_id

        offer_affiliates = OAffiliate._query(affiliate_id=affiliate._id)
        for off_aff in offer_affiliates:
            offer = Offers.find_one(dict(_id=int(off_aff.offer_id)))
            off_aff['offer_title'] = offer.title if offer else ''
            if off_aff.status == '1':
                off_aff['application_status'] = 'Approved'
            elif off_aff.status == '2':
                off_aff['application_status'] = 'Pending'
            else:
                off_aff['application_status'] = 'Rejected'
        self.render(affiliate=affiliate, offer_affiliates=offer_affiliates)
示例#15
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!")
示例#16
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))
示例#17
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)