| Line 1... |
Line 1... |
| 1 |
from bson.objectid import ObjectId
|
1 |
from bson.objectid import ObjectId
|
| 2 |
from datetime import datetime, timedelta
|
2 |
from datetime import datetime, timedelta
|
| 3 |
from dtr.config import PythonPropertyReader
|
3 |
from dtr.config import PythonPropertyReader
|
| 4 |
from dtr.dao import FeaturedDeals, AppTransactions
|
4 |
from dtr.dao import FeaturedDeals, AppTransactions, AppOfferObj
|
| 5 |
from dtr.storage import DataService
|
5 |
from dtr.storage import DataService
|
| 6 |
from dtr.storage.DataService import price_preferences, brand_preferences, \
|
6 |
from dtr.storage.DataService import price_preferences, brand_preferences, \
|
| 7 |
user_actions, Brands, app_offers, approved_app_transactions, user_app_cashbacks, \
|
7 |
user_actions, Brands, app_offers, approved_app_transactions, user_app_cashbacks, \
|
| 8 |
user_app_installs
|
8 |
user_app_installs, appmasters
|
| 9 |
from dtr.storage.MemCache import MemCache
|
9 |
from dtr.storage.MemCache import MemCache
|
| 10 |
from dtr.utils.FetchLivePrices import returnLatestPrice
|
10 |
from dtr.utils.FetchLivePrices import returnLatestPrice
|
| 11 |
from dtr.utils.MailSender import Email
|
11 |
from dtr.utils.MailSender import Email
|
| 12 |
from dtr.utils.utils import to_java_date, CB_PENDING, CB_APPROVED, CB_INIT, \
|
12 |
from dtr.utils.utils import to_java_date, CB_PENDING, CB_APPROVED, CB_INIT, \
|
| 13 |
to_py_date, CB_REJECTED
|
13 |
to_py_date, CB_REJECTED
|
| - |
|
14 |
from sqlalchemy.sql.expression import func, func, or_, desc, asc, case
|
| 14 |
from elixir import *
|
15 |
from elixir import *
|
| 15 |
from operator import itemgetter
|
16 |
from operator import itemgetter
|
| 16 |
from pymongo.command_cursor import CommandCursor
|
17 |
from pymongo.command_cursor import CommandCursor
|
| 17 |
import pymongo
|
18 |
import pymongo
|
| 18 |
import random
|
19 |
import random
|
| 19 |
import re
|
20 |
import re
|
| 20 |
import time
|
21 |
import time
|
| 21 |
import traceback
|
22 |
import traceback
|
| - |
|
23 |
from itertools import groupby
|
| - |
|
24 |
|
| 22 |
|
25 |
|
| 23 |
con = None
|
26 |
con = None
|
| 24 |
|
27 |
|
| 25 |
DataService.initialize(db_hostname="localhost")
|
28 |
DataService.initialize(db_hostname="localhost")
|
| 26 |
mc = MemCache("127.0.0.1")
|
29 |
mc = MemCache("127.0.0.1")
|
| Line 1570... |
Line 1573... |
| 1570 |
def rejectCashback(orderId, subOrderId):
|
1573 |
def rejectCashback(orderId, subOrderId):
|
| 1571 |
cashBack = get_mongo_connection().Dtr.merchantOrder.update({"orderId":orderId, "subOrders.merchantSubOrderId":subOrderId},
|
1574 |
cashBack = get_mongo_connection().Dtr.merchantOrder.update({"orderId":orderId, "subOrders.merchantSubOrderId":subOrderId},
|
| 1572 |
{"$set":{"subOrders.$.cashBackStatus":CB_REJECTED}})
|
1575 |
{"$set":{"subOrders.$.cashBackStatus":CB_REJECTED}})
|
| 1573 |
print cashBack
|
1576 |
print cashBack
|
| 1574 |
return cashBack.get("nModified")
|
1577 |
return cashBack.get("nModified")
|
| - |
|
1578 |
|
| - |
|
1579 |
def getAppOffers(retailer_id):
|
| - |
|
1580 |
if not bool(mc.get("cached_app_offers_"+str(retailer_id))):
|
| - |
|
1581 |
populateAppOffers(retailer_id)
|
| - |
|
1582 |
return mc.get("cached_app_offers_"+str(retailer_id))
|
| - |
|
1583 |
|
| - |
|
1584 |
def populateAppOffers(retailerId):
|
| - |
|
1585 |
retailerId = int(retailerId)
|
| - |
|
1586 |
#offset = req.get_param_as_int("offset")
|
| - |
|
1587 |
#limit = req.get_param_as_int("limit")
|
| - |
|
1588 |
nonPriortizedOffers = session.query(app_offers.id).join((appmasters,appmasters.id==app_offers.appmaster_id)).filter(app_offers.affiliate_id==retailerId).filter(appmasters.showApp==True).filter(app_offers.show==True).filter(app_offers.offer_active==True).filter(app_offers.offer_price>0).filter(app_offers.priority==0).order_by(desc('user_payout')).all()
|
| - |
|
1589 |
priortizeders = session.query(app_offers.id, app_offers.priority).join((appmasters,appmasters.id==app_offers.appmaster_id)).filter(app_offers.affiliate_id==retailerId).filter(appmasters.showApp==True).filter(app_offers.show==True).filter(app_offers.offer_active==True).filter(app_offers.offer_price>0).filter(app_offers.priority>0).order_by(asc(app_offers.priority)).all()
|
| - |
|
1590 |
#session.query(app_offers.id,app_offers.appmaster_id, app_offers.app_name, app_offers.affiliate_offer_id, app_offers.image_url, app_offers.downloads, app_offers.link, app_offers.offer_price, app_offers.offerCategory, app_offers.package_name, app_offers.promoImage, app_offers.ratings, case([(app_offers.override_payout == True, app_offers.overriden_payout)], else_=app_offers.user_payout).label('user_payout'), case([(appmasters.shortDescription != None, appmasters.shortDescription)], else_=None).label('shortDescription'), case([(appmasters.longDescription != None, appmasters.longDescription)], else_=None).label('longDescription'), appmasters.customerOneLiner, appmasters.retailerOneLiner,app_offers.priority, app_offers.offerCondition, app_offers.location).join((appmasters,appmasters.id==app_offers.appmaster_id)).filter(app_offers.affiliate_id==retailerId).filter(appmasters.showApp==True).filter(app_offers.show==True).filter(app_offers.offer_active==True).filter(app_offers.offer_price>0).order_by(case([(app_offers.priority.in_(tuple(nullCheckList)), 1)], else_=0), asc(app_offers.priority),desc('user_payout')).all()
|
| - |
|
1591 |
|
| - |
|
1592 |
appOffersMap = {}
|
| - |
|
1593 |
priorityList = []
|
| - |
|
1594 |
priorityMap = {}
|
| - |
|
1595 |
for offer in priortizeders:
|
| - |
|
1596 |
priorityMap[long(offer[1])]=offer
|
| 1575 |
|
1597 |
|
| - |
|
1598 |
priorityList = sorted(priorityMap)
|
| - |
|
1599 |
|
| - |
|
1600 |
maxCount = len(nonPriortizedOffers) + len(priortizeders)
|
| - |
|
1601 |
|
| - |
|
1602 |
if maxCount < max(priorityList):
|
| - |
|
1603 |
maxCount = max(priorityList)
|
| - |
|
1604 |
|
| - |
|
1605 |
count = 1
|
| - |
|
1606 |
blockedPlaces = []
|
| - |
|
1607 |
availablePlaces = []
|
| - |
|
1608 |
while count <= maxCount:
|
| - |
|
1609 |
if count in priorityList:
|
| - |
|
1610 |
blockedPlaces.append(count)
|
| - |
|
1611 |
else:
|
| - |
|
1612 |
availablePlaces.append(count)
|
| - |
|
1613 |
count = count +1
|
| - |
|
1614 |
|
| - |
|
1615 |
for val in blockedPlaces:
|
| - |
|
1616 |
appOffersMap[val]= priorityMap[val][0]
|
| - |
|
1617 |
|
| - |
|
1618 |
i=0
|
| - |
|
1619 |
for val in availablePlaces:
|
| - |
|
1620 |
appOffersMap[val]= nonPriortizedOffers[i][0]
|
| - |
|
1621 |
i=i+1
|
| - |
|
1622 |
|
| - |
|
1623 |
|
| - |
|
1624 |
finalAppOffersMap = {}
|
| - |
|
1625 |
if len(appOffersMap) > 0:
|
| - |
|
1626 |
for key in sorted(appOffersMap):
|
| - |
|
1627 |
finalAppOffersMap[key] = appOffersMap[key]
|
| - |
|
1628 |
|
| - |
|
1629 |
mc.set("cached_app_offers_"+str(retailerId), finalAppOffersMap, 120)
|
| - |
|
1630 |
else:
|
| - |
|
1631 |
print 'No Offers'
|
| - |
|
1632 |
mc.set("cached_app_offers_"+str(retailerId), {}, 10)
|
| 1576 |
|
1633 |
|
| 1577 |
|
1634 |
|
| 1578 |
def main():
|
1635 |
def main():
|
| 1579 |
#generateRedirectUrl(101,1
|
1636 |
#generateRedirectUrl(101,1
|
| 1580 |
print getCashBackDetails('1351153', 3)
|
1637 |
print getCashBackDetails('1351153', 3)
|