Esempio n. 1
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)
Esempio n. 2
0
 def post(self):
     email = self.get_argument('email')
     password = self.get_argument('password')
     user = User.find_one(dict(email=email, password=password))
     if user:
         affiliate = Affiliate.find_one(dict(user_id=int(user._id)))
         if affiliate:
             if affiliate.status == '1':
                 self._session_new(email, user._id)
                 self.redirect('/report')
Esempio n. 3
0
 def get(self, ad_id):
     ad = Advertisers.find_one(dict(user_id=int(ad_id)))
     ad_user = User.find_one(dict(_id=int(ad_id)))
     if ad_user:
         ad['_id'] = ad_user._id
         ad['name'] = ad_user.account
         ad['email'] = ';'.join(ad_user.email)
         ad['skype_id'] = ad_user.skype_id
         bd = User.find_one(dict(_id=ad.account_manager))
         ad['bd'] = bd.account if bd else ''
         pm = User.find_one(dict(_id=ad.pm))
         ad['pm'] = pm.account if pm else ''
         offers_count = Offers.count(dict(advertiser_id=ad_user._id))
         ad['offers_count'] = offers_count
         status_map = {'0': 'Deleted', '1': 'Active', '2': 'Paused'}
         ad['status'] = status_map.get(ad.status)
         ad['white_list'] = ','.join(ad.white_list) if ad.white_list else ''
         self.render(advertiser=ad)
     else:
         self.write('The advertiser not exist!')
Esempio n. 4
0
    def post(self, ad_id):
        err = JsOb()
        content = self.json
        ad = User.find_one(dict(_id=int(content.user_id)))
        if not content.name:
            err.name = u'Advertiser name can\'t be empty!'
        elif content.name != ad.account and User.count(
                dict(account=content.name)):
            err.name = u'The name has been used!'

        if not content.email:
            err.email = u'email can\'t be empty!'
        else:
            emails = content.email.replace(' ', '').split(',')
            for e in emails:
                if not is_email(e):
                    err.email = u'Email not valid, email=%s' % e
                elif e not in ad.email and User.count(
                        dict(email=e, deleted=False)):
                    err.email = u"email %s already be used!" % e

        if content.password != ad.password and not is_valid_password(
                content.password):
            err.password = u'The password not Valid!'

        if not content.account_manager:
            err.bd = u'BD must selected!'

        if not content.pm:
            err.pm = u'PM must selected!'

        if not err:
            user = User._update(
                content.user_id,
                **dict(email=emails,
                       password=content.password,
                       account=content.name,
                       skype_id=content.skype_id,
                       role_id=Role.advertiser()._id))

            kw = dict(
                country=content.country,
                account_manager=int(content.account_manager)
                if content.account_manager else None,
                pm=int(content.pm) if content.pm else None,
                white_list=content.white_list.split(',')
                if content.white_list else None,
                status=content.status,
            )

            advertiser = Advertisers._update(ad_id, **kw)
            self.finish(dict(advertiser_id=user._id, err=False))
        else:
            self.render(err)
Esempio n. 5
0
 def get_current_user(self):
     current_user_id = self.current_user_id
     if current_user_id:
         # user = Ob.ob_get(current_user_id)
         user = User.find_one(dict(_id=current_user_id, deleted=False))
         if user is not None:
             return user
         self.clear_cookie(self._USER_COOKIE_NAME, domain="." + HOST)
         self.current_user_id = 0
     o = UserDict()
     return o
Esempio n. 6
0
 def get(self):
     user_id = int(self.current_user_id)
     account = Affiliate.find_one(dict(user_id=user_id))
     user = User.find_one(dict(_id=user_id))
     account['name'] = user.account
     account['email'] = ';'.join(user.email)
     account['password'] = user.password
     account['phone'] = user.phone
     account['createdTime'] = user.createdTime
     account['last_login'] = user.last_login
     account['skype_id'] = user.skype_id
     self.render(account=account)
Esempio n. 7
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. 8
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))
Esempio n. 9
0
 def display_am(doc):
     if doc.get('affiliate_name'):
         affiliate_id = doc.get('affiliate_id')
         doc['AM'] = ''
         if affiliate_id:
             affiliate = Affiliate.find_one(
                 dict(user_id=int(affiliate_id)))
             if affiliate and affiliate.account_manager:
                 am = User.find_one(
                     dict(_id=int(affiliate.account_manager)))
                 doc['AM'] = am.account
     if doc.get('advertisers_name'):
         advertiser_id = doc.get('advertiser_id')
         doc['BD'] = ''
         if advertiser_id:
             advertiser = Advertisers.find_one(
                 dict(user_id=int(advertiser_id)))
             if advertiser and advertiser.account_manager:
                 bd = User.find_one(
                     dict(_id=int(advertiser.account_manager)))
                 doc['BD'] = bd.account
     return doc
Esempio n. 10
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. 11
0
    def post(self):
        err = JsOb()
        if not self.json.email:
            err.email = 'Please input email'
        elif not is_email(self.json.email):
            err.email = 'Email not valid'
        if not self.json.password:
            err.password = '******'

        if not self.json.login_from:
            if not self.json.captcha_code:
                err.captcha_code = 'Please input captcha code'
            elif not captcha_verify(self.json.captcha_key,
                                    self.json.captcha_code):
                err.captcha_code = 'captcha code incorrect'

        if not err:
            try:
                if not self.json.login_from:
                    user = User.verify(self.json.email, self.json.password)
                else:
                    user = User.find_one(
                        dict(email=self.json.email,
                             password=self.json.password))
                if user:
                    affiliate = Affiliate.find_one(dict(user_id=int(user._id)))
                    if affiliate:
                        if affiliate.status == '1':
                            self._session_new(self.json.email, user._id)
                            user.last_login = DateTime().current_time
                            user.save()
                        else:
                            err.application = 'The Account is Approving....'
                    else:
                        err.email = 'Email not found, Please call the manager!'
            except UserNotFoundError:
                err.email = "email not found"
            except PasswordNotMatchError:
                err.password = "******"

        self.render(err)
Esempio n. 12
0
 def get(self):
     status_type = {'0': False, '1': True}
     affiliate_id = int(self.get_argument('affiliate_id'))
     status = self.get_argument('status')
     limit = int(self.get_argument('limit'))
     page = int(self.get_argument('page'))
     skip = (page - 1) * limit
     spec = dict(affiliate_id={"$in": [affiliate_id]}
                 if affiliate_id else {'$ne': ''},
                 status=status_type[status] if status else {'$ne': ''},
                 currency=self.get_argument('currency', {'$ne': ''}),
                 createdTime={
                     '$gte': self.get_argument('start', _t.get_day(6)),
                     '$lte': self.get_argument('end', _t.today),
                 })
     invoices = Invoice._get_sum(spec, limit=limit, offset=skip)
     invoice_count = Invoice.count(spec)
     for i in invoices:
         affiliate = User.find_one(dict(_id=int(i.affiliate_id)))
         i['affiliate_name'] = affiliate.account
     self.finish(dict(invoices=invoices, invoice_count=invoice_count))
Esempio n. 13
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)
Esempio n. 14
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. 15
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. 16
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,
            ))