示例#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 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))