| 14305 |
amit.gupta |
1 |
from bson.objectid import ObjectId
|
|
|
2 |
from datetime import datetime, timedelta
|
|
|
3 |
from dtr.config import PythonPropertyReader
|
| 16546 |
kshitij.so |
4 |
from dtr.dao import FeaturedDeals, AppTransactions
|
| 14037 |
kshitij.so |
5 |
from dtr.storage import DataService
|
|
|
6 |
from dtr.storage.DataService import price_preferences, brand_preferences, \
|
| 16631 |
manish.sha |
7 |
user_actions, Brands, app_offers, approved_app_transactions, user_app_cashbacks, user_app_installs
|
| 16304 |
amit.gupta |
8 |
from dtr.storage.MemCache import MemCache
|
| 16560 |
amit.gupta |
9 |
from dtr.utils.FetchLivePrices import returnLatestPrice
|
| 16631 |
manish.sha |
10 |
from dtr.utils.utils import to_java_date, CB_PENDING, CB_APPROVED, CB_INIT, to_py_date
|
| 14305 |
amit.gupta |
11 |
from elixir import *
|
|
|
12 |
from operator import itemgetter
|
|
|
13 |
import pymongo
|
| 16398 |
amit.gupta |
14 |
import random
|
| 14322 |
kshitij.so |
15 |
import re
|
| 14791 |
kshitij.so |
16 |
import traceback
|
| 16631 |
manish.sha |
17 |
import time
|
| 13572 |
kshitij.so |
18 |
|
|
|
19 |
con = None
|
|
|
20 |
|
| 14037 |
kshitij.so |
21 |
DataService.initialize(db_hostname="localhost")
|
| 16304 |
amit.gupta |
22 |
mc = MemCache("127.0.0.1")
|
| 14037 |
kshitij.so |
23 |
|
| 16406 |
kshitij.so |
24 |
SOURCE_MAP = {1:'AMAZON',2:'FLIPKART',3:'SNAPDEAL',4:'SAHOLIC',5:"SHOPCLUES.COM",6:"PAYTM.COM"}
|
| 14482 |
kshitij.so |
25 |
|
| 15853 |
kshitij.so |
26 |
COLLECTION_MAP = {
|
|
|
27 |
'ExceptionalNlc':'skuBundleId',
|
|
|
28 |
'SkuDealerPrices':'skuBundleId',
|
|
|
29 |
'SkuDiscountInfo':'skuBundleId',
|
|
|
30 |
'SkuSchemeDetails':'skuBundleId',
|
| 16488 |
kshitij.so |
31 |
'DealPoints':'skuBundleId'
|
| 15853 |
kshitij.so |
32 |
}
|
|
|
33 |
|
| 13572 |
kshitij.so |
34 |
def get_mongo_connection(host='localhost', port=27017):
|
|
|
35 |
global con
|
|
|
36 |
if con is None:
|
|
|
37 |
print "Establishing connection %s host and port %d" %(host,port)
|
|
|
38 |
try:
|
|
|
39 |
con = pymongo.MongoClient(host, port)
|
|
|
40 |
except Exception, e:
|
|
|
41 |
print e
|
|
|
42 |
return None
|
|
|
43 |
return con
|
|
|
44 |
|
| 13907 |
kshitij.so |
45 |
def populateCashBack():
|
| 13921 |
kshitij.so |
46 |
print "Populating cashback"
|
|
|
47 |
cashBackMap = {}
|
|
|
48 |
itemCashBackMap = {}
|
| 13907 |
kshitij.so |
49 |
cashBack = list(get_mongo_connection().Catalog.CategoryCashBack.find())
|
|
|
50 |
for row in cashBack:
|
| 13970 |
kshitij.so |
51 |
temp_map = {}
|
|
|
52 |
temp_list = []
|
| 13907 |
kshitij.so |
53 |
if cashBackMap.has_key(row['source_id']):
|
|
|
54 |
arr = cashBackMap.get(row['source_id'])
|
|
|
55 |
for val in arr:
|
|
|
56 |
temp_list.append(val)
|
|
|
57 |
temp_map[row['category_id']] = row
|
|
|
58 |
temp_list.append(temp_map)
|
|
|
59 |
cashBackMap[row['source_id']] = temp_list
|
|
|
60 |
else:
|
|
|
61 |
temp_map[row['category_id']] = row
|
|
|
62 |
temp_list.append(temp_map)
|
|
|
63 |
cashBackMap[row['source_id']] = temp_list
|
| 13921 |
kshitij.so |
64 |
itemCashBack = list(get_mongo_connection().Catalog.ItemCashBack.find())
|
|
|
65 |
for row in itemCashBack:
|
|
|
66 |
if not itemCashBackMap.has_key(row['skuId']):
|
|
|
67 |
itemCashBackMap[row['skuId']] = row
|
| 14761 |
kshitij.so |
68 |
mc.set("item_cash_back", itemCashBackMap, 24 * 60 * 60)
|
|
|
69 |
mc.set("category_cash_back", cashBackMap, 24 * 60 * 60)
|
| 13907 |
kshitij.so |
70 |
|
| 13572 |
kshitij.so |
71 |
def addCategoryDiscount(data):
|
| 13970 |
kshitij.so |
72 |
collection = get_mongo_connection().Catalog.CategoryDiscount
|
| 13572 |
kshitij.so |
73 |
query = []
|
|
|
74 |
data['brand'] = data['brand'].strip().upper()
|
| 13970 |
kshitij.so |
75 |
data['discountType'] = data['discountType'].upper().strip()
|
| 13572 |
kshitij.so |
76 |
query.append({"brand":data['brand']})
|
|
|
77 |
query.append({"category_id":data['category_id']})
|
|
|
78 |
r = collection.find({"$and":query})
|
|
|
79 |
if r.count() > 0:
|
| 13639 |
kshitij.so |
80 |
return {0:"Brand & Category info already present."}
|
| 13572 |
kshitij.so |
81 |
else:
|
|
|
82 |
collection.insert(data)
|
| 13970 |
kshitij.so |
83 |
get_mongo_connection().Catalog.MasterData.update({'brand':data['brand'],'category_id':data['category_id']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
| 13639 |
kshitij.so |
84 |
return {1:"Data added successfully"}
|
| 13572 |
kshitij.so |
85 |
|
| 13970 |
kshitij.so |
86 |
def updateCategoryDiscount(data,_id):
|
|
|
87 |
try:
|
|
|
88 |
collection = get_mongo_connection().Catalog.CategoryDiscount
|
|
|
89 |
collection.update({'_id':ObjectId(_id)},{"$set":{'min_discount':data['min_discount'],'max_discount':data['max_discount'],'discountType':data['discountType'].upper().strip()}},upsert=False, multi = False)
|
|
|
90 |
get_mongo_connection().Catalog.MasterData.update({'brand':data['brand'],'category_id':data['category_id']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
|
|
91 |
return {1:"Data updated successfully"}
|
|
|
92 |
except:
|
|
|
93 |
return {0:"Data not updated."}
|
|
|
94 |
|
|
|
95 |
|
| 13572 |
kshitij.so |
96 |
def getAllCategoryDiscount():
|
|
|
97 |
data = []
|
| 13970 |
kshitij.so |
98 |
collection = get_mongo_connection().Catalog.CategoryDiscount
|
| 13572 |
kshitij.so |
99 |
cursor = collection.find()
|
|
|
100 |
for val in cursor:
|
|
|
101 |
data.append(val)
|
|
|
102 |
return data
|
|
|
103 |
|
| 14553 |
kshitij.so |
104 |
def __getBundledSkusfromSku(sku):
|
|
|
105 |
masterData = get_mongo_connection().Catalog.MasterData.find_one({"_id":sku},{"skuBundleId":1})
|
|
|
106 |
if masterData is not None:
|
|
|
107 |
return list(get_mongo_connection().Catalog.MasterData.find({"skuBundleId":masterData.get('skuBundleId')},{'_id':1,'skuBundleId':1}))
|
|
|
108 |
else:
|
|
|
109 |
return []
|
| 13572 |
kshitij.so |
110 |
|
| 15853 |
kshitij.so |
111 |
def addSchemeDetailsForSku(data):
|
|
|
112 |
collection = get_mongo_connection().Catalog.SkuSchemeDetails
|
|
|
113 |
result = collection.find_one({'skuBundleId':data['skuBundleId']})
|
|
|
114 |
if result is None:
|
| 14553 |
kshitij.so |
115 |
collection.insert(data)
|
| 15853 |
kshitij.so |
116 |
get_mongo_connection().Catalog.MasterData.update({'skuBundleId':data['skuBundleId']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
| 14553 |
kshitij.so |
117 |
return {1:"Data added successfully"}
|
| 15853 |
kshitij.so |
118 |
return {1:"BundleId info already present"}
|
|
|
119 |
|
| 14069 |
kshitij.so |
120 |
def getAllSkuWiseSchemeDetails(offset, limit):
|
| 13572 |
kshitij.so |
121 |
data = []
|
| 13970 |
kshitij.so |
122 |
collection = get_mongo_connection().Catalog.SkuSchemeDetails
|
| 14071 |
kshitij.so |
123 |
cursor = collection.find().skip(offset).limit(limit)
|
| 13572 |
kshitij.so |
124 |
for val in cursor:
|
| 15853 |
kshitij.so |
125 |
master = get_mongo_connection().Catalog.MasterData.find_one({'skuBundleId':val['skuBundleId']})
|
|
|
126 |
if master is not None:
|
|
|
127 |
val['brand'] = master['brand']
|
|
|
128 |
val['source_product_name'] = master['source_product_name']
|
| 14069 |
kshitij.so |
129 |
else:
|
|
|
130 |
val['brand'] = ""
|
|
|
131 |
val['source_product_name'] = ""
|
| 13572 |
kshitij.so |
132 |
data.append(val)
|
|
|
133 |
return data
|
|
|
134 |
|
| 15853 |
kshitij.so |
135 |
def addSkuDiscountInfo(data):
|
|
|
136 |
collection = get_mongo_connection().Catalog.SkuDiscountInfo
|
|
|
137 |
cursor = collection.find_one({"skuBundleId":data['skuBundleId']})
|
|
|
138 |
if cursor is not None:
|
|
|
139 |
return {0:"BundleId information already present."}
|
| 13572 |
kshitij.so |
140 |
else:
|
| 15853 |
kshitij.so |
141 |
collection.insert(data)
|
|
|
142 |
get_mongo_connection().Catalog.MasterData.update({'skuBundleId':data['skuBundleId']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
| 13639 |
kshitij.so |
143 |
return {1:"Data added successfully"}
|
| 13572 |
kshitij.so |
144 |
|
| 13970 |
kshitij.so |
145 |
def getallSkuDiscountInfo(offset, limit):
|
| 13572 |
kshitij.so |
146 |
data = []
|
| 13970 |
kshitij.so |
147 |
collection = get_mongo_connection().Catalog.SkuDiscountInfo
|
|
|
148 |
cursor = collection.find().skip(offset).limit(limit)
|
| 13572 |
kshitij.so |
149 |
for val in cursor:
|
| 15853 |
kshitij.so |
150 |
master = get_mongo_connection().Catalog.MasterData.find_one({'skuBundleId':val['skuBundleId']})
|
|
|
151 |
if master is not None:
|
|
|
152 |
val['brand'] = master['brand']
|
|
|
153 |
val['source_product_name'] = master['source_product_name']
|
| 13970 |
kshitij.so |
154 |
else:
|
|
|
155 |
val['brand'] = ""
|
|
|
156 |
val['source_product_name'] = ""
|
| 13572 |
kshitij.so |
157 |
data.append(val)
|
|
|
158 |
return data
|
|
|
159 |
|
| 13970 |
kshitij.so |
160 |
def updateSkuDiscount(data,_id):
|
|
|
161 |
try:
|
|
|
162 |
collection = get_mongo_connection().Catalog.SkuDiscountInfo
|
|
|
163 |
collection.update({'_id':ObjectId(_id)},{"$set":{'min_discount':data['min_discount'],'max_discount':data['max_discount'],'discountType':data['discountType'].upper().strip()}},upsert=False, multi = False)
|
| 15853 |
kshitij.so |
164 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['skuBundleId']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
| 13970 |
kshitij.so |
165 |
return {1:"Data updated successfully"}
|
|
|
166 |
except:
|
|
|
167 |
return {0:"Data not updated."}
|
|
|
168 |
|
|
|
169 |
|
| 15853 |
kshitij.so |
170 |
def addExceptionalNlc(data):
|
|
|
171 |
collection = get_mongo_connection().Catalog.ExceptionalNlc
|
|
|
172 |
cursor = collection.find_one({"skuBundleId":data['skuBundleId']})
|
|
|
173 |
if cursor is not None:
|
|
|
174 |
return {0:"BundleId information already present."}
|
| 13572 |
kshitij.so |
175 |
else:
|
| 15853 |
kshitij.so |
176 |
collection.insert(data)
|
|
|
177 |
get_mongo_connection().Catalog.MasterData.update({'skuBundleId':data['skuBundleId']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
| 13639 |
kshitij.so |
178 |
return {1:"Data added successfully"}
|
| 13572 |
kshitij.so |
179 |
|
| 13970 |
kshitij.so |
180 |
def getAllExceptionlNlcItems(offset, limit):
|
| 13572 |
kshitij.so |
181 |
data = []
|
| 13970 |
kshitij.so |
182 |
collection = get_mongo_connection().Catalog.ExceptionalNlc
|
| 14071 |
kshitij.so |
183 |
cursor = collection.find().skip(offset).limit(limit)
|
| 13572 |
kshitij.so |
184 |
for val in cursor:
|
| 15853 |
kshitij.so |
185 |
master = get_mongo_connection().Catalog.MasterData.find_one({'skuBundleId':val['skuBundleId']})
|
|
|
186 |
if master is not None:
|
|
|
187 |
val['brand'] = master['brand']
|
|
|
188 |
val['source_product_name'] = master['source_product_name']
|
| 13970 |
kshitij.so |
189 |
else:
|
|
|
190 |
val['brand'] = ""
|
|
|
191 |
val['source_product_name'] = ""
|
| 13572 |
kshitij.so |
192 |
data.append(val)
|
|
|
193 |
return data
|
|
|
194 |
|
| 14005 |
amit.gupta |
195 |
def getMerchantOrdersByUser(userId, page=1, window=50, searchMap={}):
|
|
|
196 |
if searchMap is None:
|
|
|
197 |
searchMap = {}
|
| 13603 |
amit.gupta |
198 |
if page==None:
|
|
|
199 |
page = 1
|
|
|
200 |
|
|
|
201 |
if window==None:
|
|
|
202 |
window = 50
|
|
|
203 |
result = {}
|
| 13582 |
amit.gupta |
204 |
skip = (page-1)*window
|
| 14005 |
amit.gupta |
205 |
|
| 14353 |
amit.gupta |
206 |
if userId is not None:
|
|
|
207 |
searchMap['userId'] = userId
|
| 13603 |
amit.gupta |
208 |
collection = get_mongo_connection().Dtr.merchantOrder
|
| 14609 |
amit.gupta |
209 |
cursor = collection.find(searchMap).sort("orderId",-1)
|
| 13603 |
amit.gupta |
210 |
total_count = cursor.count()
|
|
|
211 |
pages = total_count/window + (0 if total_count%window==0 else 1)
|
|
|
212 |
print "total_count", total_count
|
|
|
213 |
if total_count > skip:
|
| 13999 |
amit.gupta |
214 |
cursor = cursor.skip(skip).limit(window)
|
| 13603 |
amit.gupta |
215 |
orders = []
|
|
|
216 |
for order in cursor:
|
| 14002 |
amit.gupta |
217 |
del(order["_id"])
|
|
|
218 |
orders.append(order)
|
| 13603 |
amit.gupta |
219 |
result['data'] = orders
|
|
|
220 |
result['window'] = window
|
|
|
221 |
result['totalCount'] = total_count
|
|
|
222 |
result['currCount'] = cursor.count()
|
|
|
223 |
result['totalPages'] = pages
|
|
|
224 |
result['currPage'] = page
|
|
|
225 |
return result
|
|
|
226 |
else:
|
|
|
227 |
return result
|
| 13630 |
kshitij.so |
228 |
|
| 13927 |
amit.gupta |
229 |
def getRefunds(userId, page=1, window=10):
|
|
|
230 |
if page==None:
|
|
|
231 |
page = 1
|
|
|
232 |
|
|
|
233 |
if window==None:
|
| 13995 |
amit.gupta |
234 |
window = 10
|
| 13927 |
amit.gupta |
235 |
result = {}
|
|
|
236 |
skip = (page-1)*window
|
|
|
237 |
collection = get_mongo_connection().Dtr.refund
|
|
|
238 |
cursor = collection.find({"userId":userId})
|
|
|
239 |
total_count = cursor.count()
|
|
|
240 |
pages = total_count/window + (0 if total_count%window==0 else 1)
|
|
|
241 |
print "total_count", total_count
|
|
|
242 |
if total_count > skip:
|
| 14668 |
amit.gupta |
243 |
cursor = cursor.skip(skip).limit(window).sort([('batch',-1)])
|
| 13927 |
amit.gupta |
244 |
refunds = []
|
|
|
245 |
for refund in cursor:
|
|
|
246 |
del(refund["_id"])
|
|
|
247 |
refunds.append(refund)
|
|
|
248 |
result['data'] = refunds
|
|
|
249 |
result['window'] = window
|
|
|
250 |
result['totalCount'] = total_count
|
|
|
251 |
result['currCount'] = cursor.count()
|
|
|
252 |
result['totalPages'] = pages
|
|
|
253 |
result['currPage'] = page
|
|
|
254 |
return result
|
|
|
255 |
else:
|
|
|
256 |
return result
|
|
|
257 |
|
|
|
258 |
def getPendingRefunds(userId):
|
| 13991 |
amit.gupta |
259 |
print type(userId)
|
| 13927 |
amit.gupta |
260 |
result = get_mongo_connection().Dtr.merchantOrder\
|
|
|
261 |
.aggregate([
|
| 16398 |
amit.gupta |
262 |
{'$match':{'subOrders.cashBackStatus':CB_APPROVED, 'userId':userId}},
|
| 13927 |
amit.gupta |
263 |
{'$unwind':"$subOrders"},
|
| 16398 |
amit.gupta |
264 |
{'$match':{'subOrders.cashBackStatus':CB_APPROVED}},
|
| 13927 |
amit.gupta |
265 |
{
|
|
|
266 |
'$group':{
|
|
|
267 |
'_id':None,
|
|
|
268 |
'amount': { '$sum':'$subOrders.cashBackAmount'},
|
|
|
269 |
}
|
|
|
270 |
}
|
| 13987 |
amit.gupta |
271 |
])['result']
|
|
|
272 |
|
|
|
273 |
if len(result)>0:
|
|
|
274 |
result = result[0]
|
|
|
275 |
result.pop("_id")
|
|
|
276 |
else:
|
|
|
277 |
result={}
|
|
|
278 |
result['amount'] = 0.0
|
| 14305 |
amit.gupta |
279 |
result['nextCredit'] = datetime.strftime(next_weekday(datetime.now(), int(PythonPropertyReader.getConfig('CREDIT_DAY_OF_WEEK'))),"%Y-%m-%d %H:%M:%S")
|
| 13927 |
amit.gupta |
280 |
return result
|
| 14037 |
kshitij.so |
281 |
|
| 14671 |
amit.gupta |
282 |
def getPendingCashbacks(userId):
|
|
|
283 |
result = get_mongo_connection().Dtr.merchantOrder\
|
|
|
284 |
.aggregate([
|
| 16398 |
amit.gupta |
285 |
{'$match':{'subOrders.cashBackStatus':CB_PENDING, 'userId':userId}},
|
| 14671 |
amit.gupta |
286 |
{'$unwind':"$subOrders"},
|
| 16398 |
amit.gupta |
287 |
{'$match':{'subOrders.cashBackStatus':CB_PENDING}},
|
| 14671 |
amit.gupta |
288 |
{
|
|
|
289 |
'$group':{
|
|
|
290 |
'_id':None,
|
|
|
291 |
'amount': { '$sum':'$subOrders.cashBackAmount'},
|
|
|
292 |
}
|
|
|
293 |
}
|
|
|
294 |
])['result']
|
|
|
295 |
|
|
|
296 |
if len(result)>0:
|
|
|
297 |
result = result[0]
|
|
|
298 |
result.pop("_id")
|
|
|
299 |
else:
|
|
|
300 |
result={}
|
|
|
301 |
result['amount'] = 0.0
|
|
|
302 |
return result
|
|
|
303 |
|
| 14037 |
kshitij.so |
304 |
def __populateCache(userId):
|
|
|
305 |
print "Populating memcache for userId",userId
|
|
|
306 |
outer_query = []
|
| 16067 |
kshitij.so |
307 |
outer_query.append({ "$or": [ { "showDeal": 1} , { "prepaidDeal": 1 } ] })
|
| 14037 |
kshitij.so |
308 |
query = {}
|
| 16170 |
kshitij.so |
309 |
query['$gt'] = -100
|
| 14037 |
kshitij.so |
310 |
outer_query.append({'totalPoints':query})
|
|
|
311 |
brandPrefMap = {}
|
|
|
312 |
pricePrefMap = {}
|
|
|
313 |
actionsMap = {}
|
|
|
314 |
brand_p = session.query(price_preferences).filter_by(user_id=userId).all()
|
|
|
315 |
for x in brand_p:
|
|
|
316 |
pricePrefMap[x.category_id] = [x.min_price,x.max_price]
|
|
|
317 |
for x in session.query(brand_preferences).filter_by(user_id=userId).all():
|
|
|
318 |
temp_map = {}
|
|
|
319 |
if brandPrefMap.has_key((x.brand).strip().upper()):
|
|
|
320 |
val = brandPrefMap.get((x.brand).strip().upper())
|
|
|
321 |
temp_map[x.category_id] = 1 if x.status == 'show' else 0
|
|
|
322 |
val.append(temp_map)
|
|
|
323 |
else:
|
|
|
324 |
temp = []
|
|
|
325 |
temp_map[x.category_id] = 1 if x.status == 'show' else 0
|
|
|
326 |
temp.append(temp_map)
|
|
|
327 |
brandPrefMap[(x.brand).strip().upper()] = temp
|
|
|
328 |
|
|
|
329 |
for x in session.query(user_actions).filter_by(user_id=userId).all():
|
|
|
330 |
actionsMap[x.store_product_id] = 1 if x.action == 'like' else 0
|
| 16458 |
kshitij.so |
331 |
all_deals = list(get_mongo_connection().Catalog.Deals.find({"$and":outer_query},{'_id':1,'category_id':1,'brand':1,'totalPoints':1,'bestSellerPoints':1,'nlcPoints':1,'rank':1,'available_price':1,'dealType':1,'source_id':1,'brand_id':1,'skuBundleId':1,'dp':1, 'showDp':1}).sort([('totalPoints',pymongo.DESCENDING),('bestSellerPoints',pymongo.DESCENDING),('nlcPoints',pymongo.DESCENDING),('rank',pymongo.DESCENDING)]))
|
| 14037 |
kshitij.so |
332 |
all_category_deals = []
|
|
|
333 |
mobile_deals = []
|
|
|
334 |
tablet_deals = []
|
|
|
335 |
for deal in all_deals:
|
|
|
336 |
if actionsMap.get(deal['_id']) == 0:
|
|
|
337 |
fav_weight =.25
|
|
|
338 |
elif actionsMap.get(deal['_id']) == 1:
|
|
|
339 |
fav_weight = 1.5
|
|
|
340 |
else:
|
|
|
341 |
fav_weight = 1
|
|
|
342 |
|
|
|
343 |
if brandPrefMap.get(deal['brand'].strip().upper()) is not None:
|
|
|
344 |
brand_weight = 1
|
|
|
345 |
for brandInfo in brandPrefMap.get(deal['brand'].strip().upper()):
|
|
|
346 |
if brandInfo.get(deal['category_id']) is not None:
|
|
|
347 |
if brandInfo.get(deal['category_id']) == 1:
|
| 14055 |
kshitij.so |
348 |
brand_weight = 2.0
|
| 14037 |
kshitij.so |
349 |
else:
|
|
|
350 |
brand_weight = 1
|
|
|
351 |
|
|
|
352 |
if pricePrefMap.get(deal['category_id']) is not None:
|
|
|
353 |
|
|
|
354 |
if deal['available_price'] >= pricePrefMap.get(deal['category_id'])[0] and deal['available_price'] <= pricePrefMap.get(deal['category_id'])[1]:
|
|
|
355 |
asp_weight = 1.5
|
|
|
356 |
elif deal['available_price'] >= pricePrefMap.get(deal['category_id'])[0] - 0.5 * pricePrefMap.get(deal['category_id'])[0] and deal['available_price'] <= pricePrefMap.get(deal['category_id'])[1] + 0.5 * pricePrefMap.get(deal['category_id'])[1]:
|
|
|
357 |
asp_weight = 1.2
|
|
|
358 |
else:
|
|
|
359 |
asp_weight = 1
|
|
|
360 |
else:
|
|
|
361 |
asp_weight = 1
|
|
|
362 |
|
|
|
363 |
persPoints = deal['totalPoints'] * fav_weight * brand_weight * asp_weight
|
|
|
364 |
deal['persPoints'] = persPoints
|
|
|
365 |
|
|
|
366 |
if deal['category_id'] ==3:
|
|
|
367 |
mobile_deals.append(deal)
|
|
|
368 |
elif deal['category_id'] ==5:
|
|
|
369 |
tablet_deals.append(deal)
|
|
|
370 |
else:
|
|
|
371 |
continue
|
|
|
372 |
all_category_deals.append(deal)
|
|
|
373 |
|
| 14144 |
kshitij.so |
374 |
session.close()
|
| 14037 |
kshitij.so |
375 |
mem_cache_val = {3:mobile_deals, 5:tablet_deals, 0:all_deals}
|
|
|
376 |
mc.set(str(userId), mem_cache_val)
|
|
|
377 |
|
|
|
378 |
|
| 14531 |
kshitij.so |
379 |
def __populateFeaturedDeals():
|
|
|
380 |
all_category_fd = []
|
|
|
381 |
mobile_fd = []
|
|
|
382 |
tablet_fd = []
|
| 14550 |
kshitij.so |
383 |
activeFeaturedDeals = get_mongo_connection().Catalog.FeaturedDeals.find({'startDate':{'$lte':to_java_date(datetime.now())},'endDate':{'$gte':to_java_date(datetime.now())}}).sort({'rank':pymongo.ASCENDING})
|
| 14531 |
kshitij.so |
384 |
for activeFeaturedDeal in activeFeaturedDeals:
|
|
|
385 |
for k,v in activeFeaturedDeal['rankDetails']:
|
|
|
386 |
featuredDeal = FeaturedDeals(activeFeaturedDeal['sku'], int(k), activeFeaturedDeal['thresholdPrice'], int(v))
|
|
|
387 |
if featuredDeal.category_id == 0:
|
|
|
388 |
all_category_fd.append(featuredDeal)
|
|
|
389 |
elif featuredDeal.category_id == 3:
|
|
|
390 |
mobile_fd.append(featuredDeal)
|
|
|
391 |
elif featuredDeal.category_id == 5:
|
|
|
392 |
tablet_fd.append(featuredDeal)
|
|
|
393 |
else:
|
|
|
394 |
continue
|
| 14550 |
kshitij.so |
395 |
mc.set("featured_deals_category_"+str(0), all_category_fd, 3600)
|
|
|
396 |
mc.set("featured_deals_category_"+str(3), mobile_fd, 3600)
|
|
|
397 |
mc.set("featured_deals_category_"+str(5), tablet_fd, 3600)
|
| 14037 |
kshitij.so |
398 |
|
| 14791 |
kshitij.so |
399 |
def getNewDeals(userId, category_id, offset, limit, sort, direction, filterData=None):
|
| 14761 |
kshitij.so |
400 |
if not bool(mc.get("category_cash_back")):
|
| 13921 |
kshitij.so |
401 |
populateCashBack()
|
| 14037 |
kshitij.so |
402 |
|
| 14550 |
kshitij.so |
403 |
try:
|
|
|
404 |
if mc.get("featured_deals_category_"+str(category_id)) is None:
|
|
|
405 |
__populateFeaturedDeals()
|
|
|
406 |
except:
|
|
|
407 |
pass
|
| 14531 |
kshitij.so |
408 |
|
| 13771 |
kshitij.so |
409 |
rank = 1
|
| 16079 |
kshitij.so |
410 |
dealsListMap = []
|
| 14037 |
kshitij.so |
411 |
user_specific_deals = mc.get(str(userId))
|
|
|
412 |
if user_specific_deals is None:
|
|
|
413 |
__populateCache(userId)
|
|
|
414 |
user_specific_deals = mc.get(str(userId))
|
| 14038 |
kshitij.so |
415 |
else:
|
|
|
416 |
print "Getting user deals from cache"
|
| 14037 |
kshitij.so |
417 |
category_specific_deals = user_specific_deals.get(category_id)
|
|
|
418 |
|
|
|
419 |
if sort is None or direction is None:
|
|
|
420 |
sorted_deals = sorted(category_specific_deals, key = lambda x: (x['persPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
|
|
|
421 |
else:
|
|
|
422 |
if sort == "bestSellerPoints":
|
|
|
423 |
sorted_deals = sorted(category_specific_deals, key = lambda x: (x['bestSellerPoints'], x['rank'], x['nlcPoints']),reverse=True)
|
|
|
424 |
else:
|
|
|
425 |
if direction == -1:
|
|
|
426 |
rev = True
|
|
|
427 |
else:
|
|
|
428 |
rev = False
|
|
|
429 |
sorted_deals = sorted(category_specific_deals, key = lambda x: (x['available_price']),reverse=rev)
|
|
|
430 |
|
| 14791 |
kshitij.so |
431 |
|
|
|
432 |
print "============================"
|
|
|
433 |
if filterData is not None:
|
|
|
434 |
try:
|
|
|
435 |
sorted_deals = filterDeals(sorted_deals, filterData)
|
|
|
436 |
except:
|
| 16067 |
kshitij.so |
437 |
traceback.print_exc()
|
| 14791 |
kshitij.so |
438 |
|
| 16067 |
kshitij.so |
439 |
|
|
|
440 |
sortedMap = {}
|
|
|
441 |
rankMap = {}
|
|
|
442 |
rank = 0
|
|
|
443 |
for sorted_deal in sorted_deals:
|
|
|
444 |
if sortedMap.get(sorted_deal['skuBundleId']) is None:
|
|
|
445 |
sortedMap[sorted_deal['skuBundleId']] = {rank:[sorted_deal]}
|
|
|
446 |
rankMap[rank] = (sortedMap[sorted_deal['skuBundleId']].values())[0]
|
|
|
447 |
rank = rank +1
|
|
|
448 |
else:
|
|
|
449 |
for temp_list in sortedMap.get(sorted_deal['skuBundleId']).itervalues():
|
|
|
450 |
temp_list.append(sorted_deal)
|
| 16079 |
kshitij.so |
451 |
rankMap[(sortedMap.get(sorted_deal['skuBundleId']).keys())[0]] = temp_list
|
| 16067 |
kshitij.so |
452 |
|
|
|
453 |
for dealList in [rankMap.get(k, []) for k in range(offset, offset+limit)]:
|
| 16079 |
kshitij.so |
454 |
temp = []
|
| 16067 |
kshitij.so |
455 |
for d in dealList:
|
|
|
456 |
item = list(get_mongo_connection().Catalog.MasterData.find({'_id':d['_id']}))
|
| 16320 |
kshitij.so |
457 |
if len(item) ==0:
|
|
|
458 |
continue
|
| 16079 |
kshitij.so |
459 |
item[0]['persPoints'] = d['persPoints']
|
|
|
460 |
if d['dealType'] == 1 and d['source_id'] ==1:
|
| 16511 |
kshitij.so |
461 |
try:
|
|
|
462 |
manualDeal = list(get_mongo_connection().Catalog.ManualDeals.find({'sku':d['_id'],'startDate':{'$lte':to_java_date(datetime.now())},'endDate':{'$gte':to_java_date(datetime.now())}}))
|
|
|
463 |
item[0]['marketPlaceUrl'] = manualDeal[0]['dealUrl'].strip()
|
|
|
464 |
except:
|
|
|
465 |
pass
|
| 16079 |
kshitij.so |
466 |
elif d['source_id'] ==3:
|
|
|
467 |
item[0]['marketPlaceUrl'] = item[0]['marketPlaceUrl']+'?supc='+item[0].get('identifier')
|
|
|
468 |
else:
|
|
|
469 |
pass
|
|
|
470 |
try:
|
|
|
471 |
cashBack = getCashBack(item[0]['_id'], item[0]['source_id'], item[0]['category_id'])
|
|
|
472 |
if not cashBack or cashBack.get('cash_back_status')!=1:
|
| 14037 |
kshitij.so |
473 |
item[0]['cash_back_type'] = 0
|
|
|
474 |
item[0]['cash_back'] = 0
|
| 16079 |
kshitij.so |
475 |
else:
|
|
|
476 |
item[0]['cash_back_type'] = int(cashBack['cash_back_type'])
|
|
|
477 |
item[0]['cash_back'] = cashBack['cash_back']
|
|
|
478 |
except:
|
|
|
479 |
print "Error in adding cashback to deals"
|
|
|
480 |
item[0]['cash_back_type'] = 0
|
|
|
481 |
item[0]['cash_back'] = 0
|
| 16252 |
kshitij.so |
482 |
try:
|
|
|
483 |
item[0]['dp'] = d['dp']
|
|
|
484 |
item[0]['showDp'] = d['showDp']
|
|
|
485 |
except:
|
|
|
486 |
item[0]['dp'] = 0.0
|
|
|
487 |
item[0]['showDp'] = 0
|
| 16483 |
kshitij.so |
488 |
try:
|
|
|
489 |
item[0]['thumbnail'] = item[0]['thumbnail'].strip()
|
|
|
490 |
except:
|
|
|
491 |
pass
|
| 16079 |
kshitij.so |
492 |
temp.append(item[0])
|
| 16125 |
kshitij.so |
493 |
if len(temp) > 1:
|
| 16126 |
kshitij.so |
494 |
temp = sorted(temp, key = lambda x: (x['available_price']),reverse=False)
|
| 16079 |
kshitij.so |
495 |
dealsListMap.append(temp)
|
|
|
496 |
return dealsListMap
|
| 14037 |
kshitij.so |
497 |
|
| 14791 |
kshitij.so |
498 |
def filterDeals(deals, filterData):
|
|
|
499 |
dealFiltered = []
|
|
|
500 |
brandsFiltered = []
|
|
|
501 |
filterArray = filterData.split('|')
|
|
|
502 |
for data in filterArray:
|
|
|
503 |
try:
|
|
|
504 |
filter, info = data.split(':')
|
|
|
505 |
except Exception as ex:
|
|
|
506 |
traceback.print_exc()
|
|
|
507 |
continue
|
|
|
508 |
if filter == 'dealFilter':
|
|
|
509 |
toFilter = info.split('^')
|
|
|
510 |
print "deal filter ",toFilter
|
|
|
511 |
if 'deals' in toFilter:
|
|
|
512 |
dealFiltered = deals
|
|
|
513 |
continue
|
|
|
514 |
for filterVal in toFilter:
|
|
|
515 |
if filterVal == 'dod':
|
|
|
516 |
for deal in deals:
|
|
|
517 |
if deal['dealType'] == 1:
|
|
|
518 |
dealFiltered.append(deal)
|
|
|
519 |
elif filter == 'brandFilter':
|
|
|
520 |
toFilter = info.split('^')
|
|
|
521 |
print "brand filter ",toFilter
|
|
|
522 |
if len(toFilter) == 0 or (len(toFilter)==1 and toFilter[0]==''):
|
|
|
523 |
brandsFiltered = deals
|
|
|
524 |
for deal in deals:
|
| 15151 |
kshitij.so |
525 |
if str(int(deal['brand_id'])) in toFilter:
|
| 14791 |
kshitij.so |
526 |
brandsFiltered.append(deal)
|
| 15040 |
kshitij.so |
527 |
if len(dealFiltered) == 0:
|
|
|
528 |
return brandsFiltered
|
| 14791 |
kshitij.so |
529 |
return [i for i in dealFiltered for j in brandsFiltered if i['_id']==j['_id']]
|
|
|
530 |
|
|
|
531 |
|
| 14037 |
kshitij.so |
532 |
def getDeals(userId, category_id, offset, limit, sort, direction):
|
| 14761 |
kshitij.so |
533 |
if not bool(mc.get("category_cash_back")):
|
| 14037 |
kshitij.so |
534 |
populateCashBack()
|
|
|
535 |
rank = 1
|
| 13771 |
kshitij.so |
536 |
deals = {}
|
| 13910 |
kshitij.so |
537 |
outer_query = []
|
|
|
538 |
outer_query.append({"showDeal":1})
|
|
|
539 |
query = {}
|
|
|
540 |
query['$gt'] = 0
|
|
|
541 |
outer_query.append({'totalPoints':query})
|
|
|
542 |
if category_id in (3,5):
|
|
|
543 |
outer_query.append({'category_id':category_id})
|
| 13803 |
kshitij.so |
544 |
if sort is None or direction is None:
|
|
|
545 |
direct = -1
|
| 13910 |
kshitij.so |
546 |
print outer_query
|
|
|
547 |
data = list(get_mongo_connection().Catalog.Deals.find({"$and":outer_query}).sort([('totalPoints',direct),('bestSellerPoints',direct),('nlcPoints',direct),('rank',direct)]).skip(offset).limit(limit))
|
| 13795 |
kshitij.so |
548 |
else:
|
| 13910 |
kshitij.so |
549 |
print outer_query
|
| 13803 |
kshitij.so |
550 |
direct = direction
|
| 13910 |
kshitij.so |
551 |
if sort == "bestSellerPoints":
|
|
|
552 |
print "yes,sorting by bestSellerPoints"
|
|
|
553 |
data = list(get_mongo_connection().Catalog.Deals.find({"$and":outer_query}).sort([('bestSellerPoints',direct),('rank',direct),('nlcPoints',direct)]).skip(offset).limit(limit))
|
|
|
554 |
else:
|
|
|
555 |
data = list(get_mongo_connection().Catalog.Deals.find({"$and":outer_query}).sort([(sort,direct)]).skip(offset).limit(limit))
|
| 13771 |
kshitij.so |
556 |
for d in data:
|
|
|
557 |
item = list(get_mongo_connection().Catalog.MasterData.find({'_id':d['_id']}))
|
|
|
558 |
if not deals.has_key(item[0]['identifier']):
|
| 13921 |
kshitij.so |
559 |
item[0]['dealRank'] = rank
|
|
|
560 |
try:
|
| 14761 |
kshitij.so |
561 |
cashBack = getCashBack(item[0]['_id'], item[0]['source_id'], item[0]['category_id'])
|
| 13921 |
kshitij.so |
562 |
if not cashBack or cashBack.get('cash_back_status')!=1:
|
| 13928 |
kshitij.so |
563 |
item[0]['cash_back_type'] = 0
|
|
|
564 |
item[0]['cash_back'] = 0
|
| 13921 |
kshitij.so |
565 |
else:
|
| 14766 |
kshitij.so |
566 |
item[0]['cash_back_type'] = int(cashBack['cash_back_type'])
|
| 13928 |
kshitij.so |
567 |
item[0]['cash_back'] = cashBack['cash_back']
|
| 13921 |
kshitij.so |
568 |
except:
|
|
|
569 |
print "Error in adding cashback to deals"
|
| 13928 |
kshitij.so |
570 |
item[0]['cash_back_type'] = 0
|
|
|
571 |
item[0]['cash_back'] = 0
|
| 13771 |
kshitij.so |
572 |
deals[item[0]['identifier']] = item[0]
|
| 13921 |
kshitij.so |
573 |
|
| 13771 |
kshitij.so |
574 |
rank +=1
|
| 13785 |
kshitij.so |
575 |
return sorted(deals.values(), key=itemgetter('dealRank'))
|
|
|
576 |
|
| 16222 |
kshitij.so |
577 |
def getItem(skuId,showDp=None):
|
| 16224 |
kshitij.so |
578 |
temp = []
|
| 14761 |
kshitij.so |
579 |
if not bool(mc.get("category_cash_back")):
|
| 14113 |
kshitij.so |
580 |
populateCashBack()
|
| 13795 |
kshitij.so |
581 |
try:
|
| 16222 |
kshitij.so |
582 |
skuData = get_mongo_connection().Catalog.MasterData.find_one({'_id':int(skuId)})
|
|
|
583 |
if skuData is None:
|
|
|
584 |
raise
|
|
|
585 |
try:
|
|
|
586 |
cashBack = getCashBack(skuData['_id'], skuData['source_id'], skuData['category_id'])
|
|
|
587 |
if not cashBack or cashBack.get('cash_back_status')!=1:
|
|
|
588 |
skuData['cash_back_type'] = 0
|
|
|
589 |
skuData['cash_back'] = 0
|
|
|
590 |
else:
|
|
|
591 |
skuData['cash_back_type'] = cashBack['cash_back_type']
|
|
|
592 |
skuData['cash_back'] = cashBack['cash_back']
|
|
|
593 |
except:
|
|
|
594 |
print "Error in adding cashback to deals"
|
|
|
595 |
skuData['cash_back_type'] = 0
|
|
|
596 |
skuData['cash_back'] = 0
|
|
|
597 |
skuData['in_stock'] = int(skuData['in_stock'])
|
|
|
598 |
skuData['is_shortage'] = int(skuData['is_shortage'])
|
|
|
599 |
skuData['category_id'] = int(skuData['category_id'])
|
|
|
600 |
skuData['status'] = int(skuData['status'])
|
| 16483 |
kshitij.so |
601 |
try:
|
|
|
602 |
skuData['thumbnail'] = skuData['thumbnail'].strip()
|
|
|
603 |
except:
|
|
|
604 |
pass
|
| 16222 |
kshitij.so |
605 |
if showDp is not None:
|
|
|
606 |
dealerPrice = get_mongo_connection().Catalog.SkuDealerPrices.find_one({'skuBundleId':skuData['skuBundleId']})
|
|
|
607 |
skuData['dp'] = 0.0
|
|
|
608 |
skuData['showDp'] = 0
|
|
|
609 |
if dealerPrice is not None:
|
|
|
610 |
skuData['dp'] = dealerPrice['dp']
|
|
|
611 |
skuData['showDp'] = dealerPrice['showDp']
|
| 16224 |
kshitij.so |
612 |
temp.append(skuData)
|
|
|
613 |
return temp
|
| 13795 |
kshitij.so |
614 |
except:
|
| 16224 |
kshitij.so |
615 |
return []
|
| 13836 |
kshitij.so |
616 |
|
| 14761 |
kshitij.so |
617 |
def getCashBack(skuId, source_id, category_id):
|
|
|
618 |
if not bool(mc.get("category_cash_back")):
|
|
|
619 |
populateCashBack()
|
|
|
620 |
itemCashBackMap = mc.get("item_cash_back")
|
| 13921 |
kshitij.so |
621 |
itemCashBack = itemCashBackMap.get(skuId)
|
|
|
622 |
if itemCashBack is not None:
|
|
|
623 |
return itemCashBack
|
| 14761 |
kshitij.so |
624 |
cashBackMap = mc.get("category_cash_back")
|
| 13921 |
kshitij.so |
625 |
sourceCashBack = cashBackMap.get(source_id)
|
|
|
626 |
if sourceCashBack is not None and len(sourceCashBack) > 0:
|
|
|
627 |
for cashBack in sourceCashBack:
|
|
|
628 |
if cashBack.get(category_id) is None:
|
|
|
629 |
continue
|
|
|
630 |
else:
|
|
|
631 |
return cashBack.get(category_id)
|
|
|
632 |
else:
|
|
|
633 |
return {}
|
| 16560 |
amit.gupta |
634 |
|
|
|
635 |
def getBundleBySourceSku(source_id, identifier):
|
|
|
636 |
if source_id in (1,2,4,5):
|
|
|
637 |
skuData = list(get_mongo_connection().Catalog.MasterData.find({'identifier':identifier.strip(), 'source_id':source_id}))
|
|
|
638 |
elif source_id == 3:
|
|
|
639 |
skuData = list(get_mongo_connection().Catalog.MasterData.find({'secondaryIdentifier':identifier.strip(), 'source_id':source_id}))
|
|
|
640 |
else:
|
|
|
641 |
return {}
|
|
|
642 |
|
|
|
643 |
if not skuData:
|
|
|
644 |
return {}
|
|
|
645 |
else:
|
| 16564 |
amit.gupta |
646 |
bundleId = skuData[0]["skuBundleId"]
|
| 16580 |
amit.gupta |
647 |
itemIds = list(get_mongo_connection().Catalog.MasterData.find({'skuBundleId':bundleId, 'in_stock':1, 'source_id':{"$in":[1,2,3,5,6]}},
|
|
|
648 |
{"source_id":1, "available_price":1, "marketPlaceUrl":1, "gross_price":1, "codAvailable":1, "source_product_name":1, "offer":1, "coupon":1}))
|
| 16579 |
amit.gupta |
649 |
return {'products':itemIds}
|
| 16560 |
amit.gupta |
650 |
|
|
|
651 |
|
| 13921 |
kshitij.so |
652 |
|
| 15129 |
kshitij.so |
653 |
def getDealRank(identifier, source_id, userId):
|
| 16406 |
kshitij.so |
654 |
if source_id in (1,2,4,5,6):
|
| 15129 |
kshitij.so |
655 |
skuData = list(get_mongo_connection().Catalog.MasterData.find({'identifier':identifier.strip(), 'source_id':source_id}))
|
|
|
656 |
elif source_id == 3:
|
|
|
657 |
skuData = list(get_mongo_connection().Catalog.MasterData.find({'secondaryIdentifier':identifier.strip(), 'source_id':source_id}))
|
|
|
658 |
else:
|
| 16282 |
amit.gupta |
659 |
return {'rank':0, 'description':'Source not valid','maxNlc':None, 'minNlc':None,'status':None,'dp':None}
|
| 15349 |
kshitij.so |
660 |
if len(skuData) == 0:
|
| 16282 |
amit.gupta |
661 |
return {'rank':0, 'description':'No matching product identifier found','maxNlc':None, 'minNlc':None,'status':None,'dp':None}
|
| 15129 |
kshitij.so |
662 |
user_specific_deals = mc.get(str(userId))
|
|
|
663 |
if user_specific_deals is None:
|
|
|
664 |
__populateCache(userId)
|
|
|
665 |
user_specific_deals = mc.get(str(userId))
|
|
|
666 |
else:
|
|
|
667 |
print "Getting user deals from cache"
|
|
|
668 |
category_id = skuData[0]['category_id']
|
|
|
669 |
category_specific_deals = user_specific_deals.get(category_id)
|
| 16280 |
kshitij.so |
670 |
|
|
|
671 |
dealsData = get_mongo_connection().Catalog.Deals.find_one({'skuBundleId':skuData[0]['skuBundleId']})
|
|
|
672 |
if dealsData is None:
|
|
|
673 |
dealsData = {}
|
|
|
674 |
|
| 15129 |
kshitij.so |
675 |
if category_specific_deals is None or len(category_specific_deals) ==0:
|
| 16280 |
kshitij.so |
676 |
return {'rank':0,'description':'Category specific deals is empty','maxNlc':dealsData.get('maxNlc'),'minNlc':dealsData.get('minNlc'),'status':dealsData.get('status'),'dp':dealsData.get('dp')}
|
| 15129 |
kshitij.so |
677 |
sorted_deals = sorted(category_specific_deals, key = lambda x: (x['persPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
|
| 16168 |
kshitij.so |
678 |
sortedMap = {}
|
|
|
679 |
rankMap = {}
|
|
|
680 |
rank = 0
|
| 15129 |
kshitij.so |
681 |
for sorted_deal in sorted_deals:
|
| 16168 |
kshitij.so |
682 |
if sortedMap.get(sorted_deal['skuBundleId']) is None:
|
|
|
683 |
sortedMap[sorted_deal['skuBundleId']] = {rank:[sorted_deal]}
|
|
|
684 |
rankMap[rank] = (sortedMap[sorted_deal['skuBundleId']].values())[0]
|
|
|
685 |
rank = rank +1
|
|
|
686 |
else:
|
|
|
687 |
for temp_list in sortedMap.get(sorted_deal['skuBundleId']).itervalues():
|
|
|
688 |
temp_list.append(sorted_deal)
|
|
|
689 |
rankMap[(sortedMap.get(sorted_deal['skuBundleId']).keys())[0]] = temp_list
|
|
|
690 |
|
| 16187 |
kshitij.so |
691 |
for dealRank ,dealList in rankMap.iteritems():
|
| 16168 |
kshitij.so |
692 |
for d in dealList:
|
| 16186 |
kshitij.so |
693 |
if d['skuBundleId'] == skuData[0]['skuBundleId']:
|
| 16280 |
kshitij.so |
694 |
return {'rank':dealRank+1,'description':'Rank found','maxNlc':dealsData.get('maxNlc'),'minNlc':dealsData.get('minNlc'),'status':dealsData.get('status'),'dp':dealsData.get('dp')}
|
| 16168 |
kshitij.so |
695 |
|
| 16280 |
kshitij.so |
696 |
return {'rank':0,'description':'Rank not found','maxNlc':dealsData.get('maxNlc'),'minNlc':dealsData.get('minNlc'),'status':dealsData.get('status'),'dp':dealsData.get('dp')}
|
| 15129 |
kshitij.so |
697 |
|
|
|
698 |
|
| 13836 |
kshitij.so |
699 |
def getCashBackDetails(identifier, source_id):
|
| 14761 |
kshitij.so |
700 |
if not bool(mc.get("category_cash_back")):
|
| 13921 |
kshitij.so |
701 |
populateCashBack()
|
| 13771 |
kshitij.so |
702 |
|
| 16406 |
kshitij.so |
703 |
if source_id in (1,2,4,5,6):
|
| 13839 |
kshitij.so |
704 |
skuData = list(get_mongo_connection().Catalog.MasterData.find({'identifier':identifier.strip(), 'source_id':source_id}))
|
| 13840 |
kshitij.so |
705 |
elif source_id == 3:
|
| 13839 |
kshitij.so |
706 |
skuData = list(get_mongo_connection().Catalog.MasterData.find({'secondaryIdentifier':identifier.strip(), 'source_id':source_id}))
|
| 13840 |
kshitij.so |
707 |
else:
|
|
|
708 |
return {}
|
| 13836 |
kshitij.so |
709 |
if len(skuData) > 0:
|
| 14761 |
kshitij.so |
710 |
itemCashBackMap = mc.get("item_cash_back")
|
| 13921 |
kshitij.so |
711 |
itemCashBack = itemCashBackMap.get(skuData[0]['_id'])
|
|
|
712 |
if itemCashBack is not None:
|
|
|
713 |
return itemCashBack
|
| 14761 |
kshitij.so |
714 |
cashBackMap = mc.get("category_cash_back")
|
| 13921 |
kshitij.so |
715 |
sourceCashBack = cashBackMap.get(source_id)
|
|
|
716 |
if sourceCashBack is not None and len(sourceCashBack) > 0:
|
|
|
717 |
for cashBack in sourceCashBack:
|
|
|
718 |
if cashBack.get(skuData[0]['category_id']) is None:
|
|
|
719 |
continue
|
|
|
720 |
else:
|
|
|
721 |
return cashBack.get(skuData[0]['category_id'])
|
| 13836 |
kshitij.so |
722 |
else:
|
|
|
723 |
return {}
|
|
|
724 |
else:
|
|
|
725 |
return {}
|
| 13986 |
amit.gupta |
726 |
|
| 14398 |
amit.gupta |
727 |
def getImgSrc(identifier, source_id):
|
|
|
728 |
skuData = None
|
| 16406 |
kshitij.so |
729 |
if source_id in (1,2,4,5,6):
|
| 14414 |
amit.gupta |
730 |
skuData = get_mongo_connection().Catalog.MasterData.find_one({'identifier':identifier.strip(), 'source_id':source_id})
|
| 14398 |
amit.gupta |
731 |
elif source_id == 3:
|
| 14414 |
amit.gupta |
732 |
skuData = get_mongo_connection().Catalog.MasterData.find_one({'secondaryIdentifier':identifier.strip(), 'source_id':source_id})
|
| 14398 |
amit.gupta |
733 |
if skuData is None:
|
|
|
734 |
return {}
|
|
|
735 |
else:
|
| 16483 |
kshitij.so |
736 |
try:
|
|
|
737 |
return {'thumbnail':skuData.get('thumbnail').strip()}
|
|
|
738 |
except:
|
|
|
739 |
return {'thumbnail':skuData.get('thumbnail')}
|
| 13986 |
amit.gupta |
740 |
|
|
|
741 |
def next_weekday(d, weekday):
|
|
|
742 |
days_ahead = weekday - d.weekday()
|
|
|
743 |
if days_ahead <= 0: # Target day already happened this week
|
|
|
744 |
days_ahead += 7
|
|
|
745 |
return d + timedelta(days_ahead)
|
|
|
746 |
|
| 13771 |
kshitij.so |
747 |
|
| 13970 |
kshitij.so |
748 |
def getAllDealerPrices(offset, limit):
|
|
|
749 |
data = []
|
|
|
750 |
collection = get_mongo_connection().Catalog.SkuDealerPrices
|
|
|
751 |
cursor = collection.find().skip(offset).limit(limit)
|
|
|
752 |
for val in cursor:
|
| 15853 |
kshitij.so |
753 |
master = get_mongo_connection().Catalog.MasterData.find_one({'skuBundleId':val['skuBundleId']})
|
|
|
754 |
if master is not None:
|
|
|
755 |
val['brand'] = master['brand']
|
|
|
756 |
val['source_product_name'] = master['source_product_name']
|
| 13970 |
kshitij.so |
757 |
else:
|
|
|
758 |
val['brand'] = ""
|
|
|
759 |
val['source_product_name'] = ""
|
| 16231 |
kshitij.so |
760 |
val['showDp'] = int(val['showDp'])
|
| 13970 |
kshitij.so |
761 |
data.append(val)
|
|
|
762 |
return data
|
|
|
763 |
|
| 15853 |
kshitij.so |
764 |
def addSkuDealerPrice(data):
|
|
|
765 |
collection = get_mongo_connection().Catalog.SkuDealerPrices
|
|
|
766 |
cursor = collection.find_one({"skuBundleId":data['skuBundleId']})
|
|
|
767 |
if cursor is not None:
|
|
|
768 |
return {0:"BundleId information already present."}
|
| 13970 |
kshitij.so |
769 |
else:
|
| 15853 |
kshitij.so |
770 |
collection.insert(data)
|
|
|
771 |
get_mongo_connection().Catalog.MasterData.update({'skuBundleId':data['skuBundleId']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
| 13970 |
kshitij.so |
772 |
return {1:"Data added successfully"}
|
|
|
773 |
|
|
|
774 |
def updateSkuDealerPrice(data, _id):
|
|
|
775 |
try:
|
|
|
776 |
collection = get_mongo_connection().Catalog.SkuDealerPrices
|
|
|
777 |
collection.update({'_id':ObjectId(_id)},{"$set":{'dp':data['dp']}},upsert=False, multi = False)
|
| 15853 |
kshitij.so |
778 |
get_mongo_connection().Catalog.MasterData.update({'skuBundleId':data['skuBundleId']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
| 13970 |
kshitij.so |
779 |
return {1:"Data updated successfully"}
|
|
|
780 |
except:
|
|
|
781 |
return {0:"Data not updated."}
|
|
|
782 |
|
|
|
783 |
def updateExceptionalNlc(data, _id):
|
|
|
784 |
try:
|
|
|
785 |
collection = get_mongo_connection().Catalog.ExceptionalNlc
|
|
|
786 |
collection.update({'_id':ObjectId(_id)},{"$set":{'maxNlc':data['maxNlc'], 'minNlc':data['minNlc'], 'overrideNlc':data['overrideNlc']}},upsert=False, multi = False)
|
| 15853 |
kshitij.so |
787 |
get_mongo_connection().Catalog.MasterData.update({'skuBundleId':data['skuBundleId']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
| 13970 |
kshitij.so |
788 |
return {1:"Data updated successfully"}
|
|
|
789 |
except:
|
|
|
790 |
return {0:"Data not updated."}
|
|
|
791 |
|
| 14041 |
kshitij.so |
792 |
def resetCache(userId):
|
| 14043 |
kshitij.so |
793 |
try:
|
|
|
794 |
mc.delete(userId)
|
|
|
795 |
return {1:'Cache cleared.'}
|
|
|
796 |
except:
|
|
|
797 |
return {0:'Unable to clear cache.'}
|
|
|
798 |
|
| 15853 |
kshitij.so |
799 |
def updateCollection(data):
|
| 14083 |
kshitij.so |
800 |
print data
|
| 15853 |
kshitij.so |
801 |
try:
|
|
|
802 |
collection = get_mongo_connection().Catalog[data['class']]
|
|
|
803 |
class_name = data.pop('class')
|
|
|
804 |
_id = data.pop('oid')
|
|
|
805 |
result = collection.update({'_id':ObjectId(_id)},{"$set":data},upsert=False, multi = False)
|
|
|
806 |
if class_name != "Notifications":
|
|
|
807 |
record = list(collection.find({'_id':ObjectId(_id)}))
|
|
|
808 |
if class_name !="CategoryDiscount":
|
|
|
809 |
if record[0].has_key('sku'):
|
|
|
810 |
field = '_id'
|
|
|
811 |
val = record[0]['sku']
|
| 14852 |
kshitij.so |
812 |
else:
|
| 15853 |
kshitij.so |
813 |
field = 'skuBundleId'
|
|
|
814 |
val = record[0]['skuBundleId']
|
|
|
815 |
get_mongo_connection().Catalog.MasterData.update({field:val},{"$set":{'updatedOn':to_java_date(datetime.now())}},upsert=False, multi = True)
|
|
|
816 |
else:
|
|
|
817 |
get_mongo_connection().Catalog.MasterData.update({'brand':re.compile(record[0]['brand'], re.IGNORECASE),'category_id':record[0]['category_id']}, \
|
|
|
818 |
{"$set":{'updatedOn':to_java_date(datetime.now())}},upsert=False,multi=True)
|
| 16233 |
kshitij.so |
819 |
if class_name =='SkuDealerPrices':
|
| 16237 |
kshitij.so |
820 |
get_mongo_connection().Catalog.Deals.update({'skuBundleId':val},{"$set":data},upsert=False, multi=True)
|
| 15853 |
kshitij.so |
821 |
return {1:"Data updated successfully"}
|
|
|
822 |
except Exception as e:
|
|
|
823 |
print e
|
|
|
824 |
return {0:"Data not updated."}
|
| 14575 |
kshitij.so |
825 |
|
| 14076 |
kshitij.so |
826 |
|
| 14553 |
kshitij.so |
827 |
def addNegativeDeals(data, multi):
|
|
|
828 |
if multi !=1:
|
|
|
829 |
collection = get_mongo_connection().Catalog.NegativeDeals
|
|
|
830 |
cursor = collection.find({"sku":data['sku']})
|
|
|
831 |
if cursor.count() > 0:
|
|
|
832 |
return {0:"Sku information already present."}
|
|
|
833 |
else:
|
|
|
834 |
collection.insert(data)
|
|
|
835 |
return {1:"Data added successfully"}
|
| 14481 |
kshitij.so |
836 |
else:
|
| 14553 |
kshitij.so |
837 |
skuIds = __getBundledSkusfromSku(data['sku'])
|
|
|
838 |
for sku in skuIds:
|
|
|
839 |
data['sku'] = sku.get('_id')
|
|
|
840 |
collection = get_mongo_connection().Catalog.NegativeDeals
|
|
|
841 |
cursor = collection.find({"sku":data['sku']})
|
|
|
842 |
if cursor.count() > 0:
|
|
|
843 |
continue
|
|
|
844 |
else:
|
| 14558 |
kshitij.so |
845 |
data.pop('_id',None)
|
| 14553 |
kshitij.so |
846 |
collection.insert(data)
|
| 14481 |
kshitij.so |
847 |
return {1:"Data added successfully"}
|
|
|
848 |
|
|
|
849 |
def getAllNegativeDeals(offset, limit):
|
|
|
850 |
data = []
|
|
|
851 |
collection = get_mongo_connection().Catalog.NegativeDeals
|
|
|
852 |
cursor = collection.find().skip(offset).limit(limit)
|
|
|
853 |
for val in cursor:
|
|
|
854 |
master = list(get_mongo_connection().Catalog.MasterData.find({'_id':val['sku']}))
|
|
|
855 |
if len(master) > 0:
|
|
|
856 |
val['brand'] = master[0]['brand']
|
|
|
857 |
val['source_product_name'] = master[0]['source_product_name']
|
|
|
858 |
val['skuBundleId'] = master[0]['skuBundleId']
|
|
|
859 |
else:
|
|
|
860 |
val['brand'] = ""
|
|
|
861 |
val['source_product_name'] = ""
|
|
|
862 |
val['skuBundleId'] = ""
|
|
|
863 |
data.append(val)
|
|
|
864 |
return data
|
|
|
865 |
|
|
|
866 |
def getAllManualDeals(offset, limit):
|
|
|
867 |
data = []
|
|
|
868 |
collection = get_mongo_connection().Catalog.ManualDeals
|
| 15090 |
kshitij.so |
869 |
cursor = collection.find().skip(offset).limit(limit)
|
| 14481 |
kshitij.so |
870 |
for val in cursor:
|
|
|
871 |
master = list(get_mongo_connection().Catalog.MasterData.find({'_id':val['sku']}))
|
|
|
872 |
if len(master) > 0:
|
|
|
873 |
val['brand'] = master[0]['brand']
|
|
|
874 |
val['source_product_name'] = master[0]['source_product_name']
|
|
|
875 |
val['skuBundleId'] = master[0]['skuBundleId']
|
|
|
876 |
else:
|
|
|
877 |
val['brand'] = ""
|
|
|
878 |
val['source_product_name'] = ""
|
|
|
879 |
val['skuBundleId'] = ""
|
|
|
880 |
data.append(val)
|
|
|
881 |
return data
|
| 14076 |
kshitij.so |
882 |
|
| 14553 |
kshitij.so |
883 |
def addManualDeal(data, multi):
|
|
|
884 |
if multi !=1:
|
|
|
885 |
collection = get_mongo_connection().Catalog.ManualDeals
|
| 15090 |
kshitij.so |
886 |
cursor = collection.find({'sku':data['sku']})
|
| 14553 |
kshitij.so |
887 |
if cursor.count() > 0:
|
|
|
888 |
return {0:"Sku information already present."}
|
|
|
889 |
else:
|
|
|
890 |
collection.insert(data)
|
|
|
891 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['sku']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=False)
|
|
|
892 |
return {1:"Data added successfully"}
|
| 14481 |
kshitij.so |
893 |
else:
|
| 14553 |
kshitij.so |
894 |
skuIds = __getBundledSkusfromSku(data['sku'])
|
|
|
895 |
for sku in skuIds:
|
|
|
896 |
data['sku'] = sku.get('_id')
|
|
|
897 |
collection = get_mongo_connection().Catalog.ManualDeals
|
| 15090 |
kshitij.so |
898 |
cursor = collection.find({'sku':data['sku']})
|
| 14553 |
kshitij.so |
899 |
if cursor.count() > 0:
|
|
|
900 |
continue
|
|
|
901 |
else:
|
| 14558 |
kshitij.so |
902 |
data.pop('_id',None)
|
| 14553 |
kshitij.so |
903 |
collection.insert(data)
|
|
|
904 |
get_mongo_connection().Catalog.MasterData.update({'skuBundleId':sku.get('skuBundleId')},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
| 14481 |
kshitij.so |
905 |
return {1:"Data added successfully"}
|
| 14553 |
kshitij.so |
906 |
|
| 14481 |
kshitij.so |
907 |
def deleteDocument(data):
|
| 15853 |
kshitij.so |
908 |
print "inside detete document"
|
| 14481 |
kshitij.so |
909 |
print data
|
|
|
910 |
try:
|
|
|
911 |
collection = get_mongo_connection().Catalog[data['class']]
|
|
|
912 |
class_name = data.pop('class')
|
|
|
913 |
_id = data.pop('oid')
|
|
|
914 |
record = list(collection.find({'_id':ObjectId(_id)}))
|
|
|
915 |
collection.remove({'_id':ObjectId(_id)})
|
| 15075 |
kshitij.so |
916 |
if class_name != "Notifications":
|
|
|
917 |
if class_name !="CategoryDiscount":
|
| 15853 |
kshitij.so |
918 |
print record[0]
|
|
|
919 |
if record[0].has_key('sku'):
|
|
|
920 |
field = '_id'
|
|
|
921 |
val = record[0]['sku']
|
|
|
922 |
else:
|
|
|
923 |
field = 'skuBundleId'
|
|
|
924 |
val = record[0]['skuBundleId']
|
|
|
925 |
print "Updating master"
|
|
|
926 |
print field
|
|
|
927 |
print val
|
|
|
928 |
get_mongo_connection().Catalog.MasterData.update({field:val},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
| 15075 |
kshitij.so |
929 |
else:
|
|
|
930 |
get_mongo_connection().Catalog.MasterData.update({'brand':re.compile(record[0]['brand'], re.IGNORECASE),'category_id':record[0]['category_id']}, \
|
|
|
931 |
{"$set":{'updatedOn':to_java_date(datetime.now())}},upsert=False,multi=True)
|
| 14481 |
kshitij.so |
932 |
return {1:"Document deleted successfully"}
|
|
|
933 |
except Exception as e:
|
|
|
934 |
print e
|
|
|
935 |
return {0:"Document not deleted."}
|
| 13970 |
kshitij.so |
936 |
|
| 14482 |
kshitij.so |
937 |
def searchMaster(offset, limit, search_term):
|
|
|
938 |
data = []
|
| 14531 |
kshitij.so |
939 |
if search_term is not None:
|
| 14551 |
kshitij.so |
940 |
terms = search_term.split(' ')
|
|
|
941 |
outer_query = []
|
|
|
942 |
for term in terms:
|
|
|
943 |
outer_query.append({"source_product_name":re.compile(term, re.IGNORECASE)})
|
| 14531 |
kshitij.so |
944 |
try:
|
| 14551 |
kshitij.so |
945 |
collection = get_mongo_connection().Catalog.MasterData.find({"$and":outer_query,'source_id':{'$in':SOURCE_MAP.keys()}}).skip(offset).limit(limit)
|
| 14531 |
kshitij.so |
946 |
for record in collection:
|
|
|
947 |
data.append(record)
|
|
|
948 |
except:
|
|
|
949 |
pass
|
|
|
950 |
else:
|
|
|
951 |
collection = get_mongo_connection().Catalog.MasterData.find({'source_id':{'$in':SOURCE_MAP.keys()}}).skip(offset).limit(limit)
|
| 14482 |
kshitij.so |
952 |
for record in collection:
|
|
|
953 |
data.append(record)
|
|
|
954 |
return data
|
| 14481 |
kshitij.so |
955 |
|
| 14495 |
kshitij.so |
956 |
def getAllFeaturedDeals(offset, limit):
|
|
|
957 |
data = []
|
|
|
958 |
collection = get_mongo_connection().Catalog.FeaturedDeals
|
|
|
959 |
cursor = collection.find({'endDate':{'$gte':to_java_date(datetime.now())}}).skip(offset).limit(limit)
|
|
|
960 |
for val in cursor:
|
|
|
961 |
master = list(get_mongo_connection().Catalog.MasterData.find({'_id':val['sku']}))
|
|
|
962 |
if len(master) > 0:
|
|
|
963 |
val['brand'] = master[0]['brand']
|
|
|
964 |
val['source_product_name'] = master[0]['source_product_name']
|
|
|
965 |
val['skuBundleId'] = master[0]['skuBundleId']
|
|
|
966 |
else:
|
|
|
967 |
val['brand'] = ""
|
|
|
968 |
val['source_product_name'] = ""
|
|
|
969 |
val['skuBundleId'] = ""
|
|
|
970 |
data.append(val)
|
|
|
971 |
return data
|
|
|
972 |
|
| 14553 |
kshitij.so |
973 |
def addFeaturedDeal(data, multi):
|
|
|
974 |
if multi !=1:
|
|
|
975 |
collection = get_mongo_connection().Catalog.FeaturedDeals
|
|
|
976 |
cursor = collection.find({'sku':data['sku'],'startDate':{'$lte':data['startDate']},'endDate':{'$gte':data['endDate']}})
|
|
|
977 |
if cursor.count() > 0:
|
|
|
978 |
return {0:"Sku information already present."}
|
|
|
979 |
else:
|
|
|
980 |
collection.insert(data)
|
|
|
981 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['sku']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=False)
|
|
|
982 |
return {1:"Data added successfully"}
|
| 14495 |
kshitij.so |
983 |
else:
|
| 14553 |
kshitij.so |
984 |
skuIds = __getBundledSkusfromSku(data['sku'])
|
|
|
985 |
for sku in skuIds:
|
|
|
986 |
data['sku'] = sku.get('_id')
|
|
|
987 |
collection = get_mongo_connection().Catalog.FeaturedDeals
|
|
|
988 |
cursor = collection.find({'sku':data['sku'],'startDate':{'$lte':data['startDate']},'endDate':{'$gte':data['endDate']}})
|
|
|
989 |
if cursor.count() > 0:
|
|
|
990 |
continue
|
|
|
991 |
else:
|
| 14558 |
kshitij.so |
992 |
data.pop('_id',None)
|
| 14553 |
kshitij.so |
993 |
collection.insert(data)
|
|
|
994 |
get_mongo_connection().Catalog.MasterData.update({'skuBundleId':sku.get('skuBundleId')},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
| 14495 |
kshitij.so |
995 |
return {1:"Data added successfully"}
|
|
|
996 |
|
| 14499 |
kshitij.so |
997 |
def searchCollection(class_name, sku, skuBundleId):
|
| 14497 |
kshitij.so |
998 |
data = []
|
|
|
999 |
collection = get_mongo_connection().Catalog[class_name]
|
| 15076 |
kshitij.so |
1000 |
if class_name == "Notifications":
|
|
|
1001 |
cursor = collection.find({'skuBundleId':skuBundleId})
|
|
|
1002 |
for val in cursor:
|
|
|
1003 |
master = list(get_mongo_connection().Catalog.MasterData.find({'skuBundleId':val['skuBundleId']}))
|
|
|
1004 |
if len(master) > 0:
|
|
|
1005 |
val['brand'] = master[0]['brand']
|
|
|
1006 |
val['model_name'] = master[0]['model_name']
|
|
|
1007 |
val['skuBundleId'] = master[0]['skuBundleId']
|
|
|
1008 |
else:
|
|
|
1009 |
val['brand'] = ""
|
|
|
1010 |
val['model_name'] = ""
|
|
|
1011 |
val['skuBundleId'] = val['skuBundleId']
|
|
|
1012 |
data.append(val)
|
| 15095 |
kshitij.so |
1013 |
return data
|
| 15853 |
kshitij.so |
1014 |
master = None
|
| 14499 |
kshitij.so |
1015 |
if sku is not None:
|
| 15853 |
kshitij.so |
1016 |
if COLLECTION_MAP.has_key(class_name):
|
|
|
1017 |
master = get_mongo_connection().Catalog.MasterData.find_one({'_id':sku})
|
|
|
1018 |
cursor = collection.find({'skuBundleId':master['skuBundleId']})
|
|
|
1019 |
else:
|
|
|
1020 |
cursor = collection.find({'sku':sku})
|
| 14499 |
kshitij.so |
1021 |
for val in cursor:
|
| 15853 |
kshitij.so |
1022 |
if master is None:
|
|
|
1023 |
master = get_mongo_connection().Catalog.MasterData.find_one({'_id':val['sku']})
|
|
|
1024 |
if master is not None:
|
|
|
1025 |
val['brand'] = master['brand']
|
|
|
1026 |
val['source_product_name'] = master['source_product_name']
|
|
|
1027 |
val['skuBundleId'] = master['skuBundleId']
|
| 14499 |
kshitij.so |
1028 |
else:
|
|
|
1029 |
val['brand'] = ""
|
|
|
1030 |
val['source_product_name'] = ""
|
|
|
1031 |
val['skuBundleId'] = ""
|
|
|
1032 |
data.append(val)
|
|
|
1033 |
return data
|
|
|
1034 |
else:
|
| 15853 |
kshitij.so |
1035 |
if not COLLECTION_MAP.has_key(class_name):
|
|
|
1036 |
skuIds = get_mongo_connection().Catalog.MasterData.find({'skuBundleId':skuBundleId}).distinct('_id')
|
|
|
1037 |
for sku in skuIds:
|
|
|
1038 |
cursor = collection.find({'sku':sku})
|
|
|
1039 |
for val in cursor:
|
|
|
1040 |
master = list(get_mongo_connection().Catalog.MasterData.find({'_id':val['sku']}))
|
|
|
1041 |
if len(master) > 0:
|
|
|
1042 |
val['brand'] = master[0]['brand']
|
|
|
1043 |
val['source_product_name'] = master[0]['source_product_name']
|
|
|
1044 |
val['skuBundleId'] = master[0]['skuBundleId']
|
|
|
1045 |
else:
|
|
|
1046 |
val['brand'] = ""
|
|
|
1047 |
val['source_product_name'] = ""
|
|
|
1048 |
val['skuBundleId'] = ""
|
|
|
1049 |
data.append(val)
|
|
|
1050 |
return data
|
|
|
1051 |
else:
|
|
|
1052 |
cursor = collection.find({'skuBundleId':skuBundleId})
|
| 14499 |
kshitij.so |
1053 |
for val in cursor:
|
| 15853 |
kshitij.so |
1054 |
master = list(get_mongo_connection().Catalog.MasterData.find({'skuBundleId':val['skuBundleId']}))
|
| 14499 |
kshitij.so |
1055 |
if len(master) > 0:
|
|
|
1056 |
val['brand'] = master[0]['brand']
|
|
|
1057 |
val['source_product_name'] = master[0]['source_product_name']
|
|
|
1058 |
else:
|
|
|
1059 |
val['brand'] = ""
|
|
|
1060 |
val['source_product_name'] = ""
|
|
|
1061 |
data.append(val)
|
| 15853 |
kshitij.so |
1062 |
return data
|
| 14495 |
kshitij.so |
1063 |
|
| 15074 |
kshitij.so |
1064 |
def __getBrandIdForBrand(brandName, category_id):
|
|
|
1065 |
brandInfo = Brands.query.filter(Brands.category_id==category_id).filter(Brands.name == brandName).all()
|
|
|
1066 |
if brandInfo is None or len(brandInfo)!=1:
|
|
|
1067 |
raise
|
|
|
1068 |
else:
|
|
|
1069 |
return brandInfo[0].id
|
|
|
1070 |
|
| 14588 |
kshitij.so |
1071 |
def addNewItem(data):
|
| 14594 |
kshitij.so |
1072 |
try:
|
|
|
1073 |
data['updatedOn'] = to_java_date(datetime.now())
|
|
|
1074 |
data['addedOn'] = to_java_date(datetime.now())
|
|
|
1075 |
data['priceUpdatedOn'] = to_java_date(datetime.now())
|
|
|
1076 |
max_id = list(get_mongo_connection().Catalog.MasterData.find().sort([('_id',pymongo.DESCENDING)]).limit(1))
|
|
|
1077 |
max_bundle = list(get_mongo_connection().Catalog.MasterData.find().sort([('skuBundleId',pymongo.DESCENDING)]).limit(1))
|
|
|
1078 |
data['_id'] = max_id[0]['_id'] + 1
|
|
|
1079 |
data['skuBundleId'] = max_bundle[0]['skuBundleId'] + 1
|
|
|
1080 |
data['identifier'] = str(data['identifier'])
|
|
|
1081 |
data['secondaryIdentifier'] = str(data['secondaryIdentifier'])
|
| 15074 |
kshitij.so |
1082 |
data['brand_id'] = __getBrandIdForBrand(data['brand'], data['category_id'])
|
| 14594 |
kshitij.so |
1083 |
get_mongo_connection().Catalog.MasterData.insert(data)
|
|
|
1084 |
return {1:'Data added successfully'}
|
|
|
1085 |
except Exception as e:
|
|
|
1086 |
print e
|
|
|
1087 |
return {0:'Unable to add data.'}
|
| 15130 |
kshitij.so |
1088 |
finally:
|
|
|
1089 |
session.close()
|
| 14588 |
kshitij.so |
1090 |
|
|
|
1091 |
def addItemToExistingBundle(data):
|
|
|
1092 |
try:
|
|
|
1093 |
data['updatedOn'] = to_java_date(datetime.now())
|
|
|
1094 |
data['addedOn'] = to_java_date(datetime.now())
|
|
|
1095 |
data['priceUpdatedOn'] = to_java_date(datetime.now())
|
| 14593 |
kshitij.so |
1096 |
max_id = list(get_mongo_connection().Catalog.MasterData.find().sort([('_id',pymongo.DESCENDING)]).limit(1))
|
| 14590 |
kshitij.so |
1097 |
data['_id'] = max_id[0]['_id'] + 1
|
| 14594 |
kshitij.so |
1098 |
data['identifier'] = str(data['identifier'])
|
|
|
1099 |
data['secondaryIdentifier'] = str(data['secondaryIdentifier'])
|
| 15074 |
kshitij.so |
1100 |
data['brand_id'] = __getBrandIdForBrand(data['brand'], data['category_id'])
|
| 14588 |
kshitij.so |
1101 |
get_mongo_connection().Catalog.MasterData.insert(data)
|
|
|
1102 |
return {1:'Data added successfully.'}
|
| 14594 |
kshitij.so |
1103 |
except Exception as e:
|
|
|
1104 |
print e
|
| 14588 |
kshitij.so |
1105 |
return {0:'Unable to add data.'}
|
| 15130 |
kshitij.so |
1106 |
finally:
|
|
|
1107 |
session.close()
|
| 14588 |
kshitij.so |
1108 |
|
|
|
1109 |
def updateMaster(data, multi):
|
| 15130 |
kshitij.so |
1110 |
try:
|
|
|
1111 |
print data
|
|
|
1112 |
if multi != 1:
|
|
|
1113 |
_id = data.pop('_id')
|
|
|
1114 |
skuBundleId = data.pop('skuBundleId')
|
|
|
1115 |
data['updatedOn'] = to_java_date(datetime.now())
|
|
|
1116 |
data['identifier'] = str(data['identifier'])
|
|
|
1117 |
data['secondaryIdentifier'] = str(data['secondaryIdentifier'])
|
|
|
1118 |
data['brand_id'] = __getBrandIdForBrand(data['brand'], data['category_id'])
|
|
|
1119 |
get_mongo_connection().Catalog.MasterData.update({'_id':_id},{"$set":data},upsert=False)
|
|
|
1120 |
return {1:'Data updated successfully.'}
|
|
|
1121 |
else:
|
|
|
1122 |
_id = data.pop('_id')
|
|
|
1123 |
skuBundleId = data.pop('skuBundleId')
|
|
|
1124 |
data['updatedOn'] = to_java_date(datetime.now())
|
|
|
1125 |
data['identifier'] = str(data['identifier'])
|
|
|
1126 |
data['secondaryIdentifier'] = str(data['secondaryIdentifier'])
|
|
|
1127 |
data['brand_id'] = __getBrandIdForBrand(data['brand'], data['category_id'])
|
|
|
1128 |
get_mongo_connection().Catalog.MasterData.update({'_id':_id},{"$set":data},upsert=False)
|
|
|
1129 |
similarItems = get_mongo_connection().Catalog.MasterData.find({'skuBundleId':skuBundleId})
|
|
|
1130 |
for item in similarItems:
|
|
|
1131 |
if item['_id'] == _id:
|
|
|
1132 |
continue
|
|
|
1133 |
item['updatedOn'] = to_java_date(datetime.now())
|
|
|
1134 |
item['thumbnail'] = data['thumbnail']
|
|
|
1135 |
item['category'] = data['category']
|
|
|
1136 |
item['category_id'] = data['category_id']
|
|
|
1137 |
item['tagline'] = data['tagline']
|
|
|
1138 |
item['is_shortage'] = data['is_shortage']
|
|
|
1139 |
item['mrp'] = data['mrp']
|
|
|
1140 |
item['status'] = data['status']
|
|
|
1141 |
item['maxPrice'] = data['maxPrice']
|
|
|
1142 |
item['brand_id'] = data['brand_id']
|
|
|
1143 |
similar_item_id = item.pop('_id')
|
|
|
1144 |
get_mongo_connection().Catalog.MasterData.update({'_id':similar_item_id},{"$set":item},upsert=False)
|
|
|
1145 |
return {1:'Data updated successfully.'}
|
|
|
1146 |
finally:
|
|
|
1147 |
session.close()
|
| 14619 |
kshitij.so |
1148 |
|
|
|
1149 |
def getLiveCricScore():
|
|
|
1150 |
return mc.get('liveScore')
|
| 14852 |
kshitij.so |
1151 |
|
|
|
1152 |
def addBundleToNotification(data):
|
|
|
1153 |
try:
|
| 15069 |
kshitij.so |
1154 |
collection = get_mongo_connection().Catalog.Notifications
|
| 14852 |
kshitij.so |
1155 |
cursor = collection.find({'skuBundleId':data['skuBundleId']})
|
|
|
1156 |
if cursor.count() > 0:
|
|
|
1157 |
return {0:"SkuBundleId information already present."}
|
|
|
1158 |
else:
|
|
|
1159 |
collection.insert(data)
|
|
|
1160 |
return {1:'Data updated successfully.'}
|
|
|
1161 |
except:
|
|
|
1162 |
return {0:'Unable to add data.'}
|
|
|
1163 |
|
|
|
1164 |
def getAllNotifications(offset, limit):
|
|
|
1165 |
data = []
|
| 15069 |
kshitij.so |
1166 |
collection = get_mongo_connection().Catalog.Notifications
|
| 16450 |
kshitij.so |
1167 |
cursor = collection.find().sort([('endDate',pymongo.DESCENDING)]).skip(offset).limit(limit)
|
| 14852 |
kshitij.so |
1168 |
for val in cursor:
|
| 15072 |
kshitij.so |
1169 |
master = list(get_mongo_connection().Catalog.MasterData.find({'skuBundleId':val['skuBundleId']}))
|
| 14852 |
kshitij.so |
1170 |
if len(master) > 0:
|
|
|
1171 |
val['brand'] = master[0]['brand']
|
| 15071 |
kshitij.so |
1172 |
val['model_name'] = master[0]['model_name']
|
| 14852 |
kshitij.so |
1173 |
val['skuBundleId'] = master[0]['skuBundleId']
|
|
|
1174 |
else:
|
|
|
1175 |
val['brand'] = ""
|
| 15071 |
kshitij.so |
1176 |
val['model_name'] = ""
|
|
|
1177 |
val['skuBundleId'] = val['skuBundleId']
|
| 14852 |
kshitij.so |
1178 |
data.append(val)
|
|
|
1179 |
return data
|
| 14997 |
kshitij.so |
1180 |
|
|
|
1181 |
def getBrandsForFilter(category_id):
|
|
|
1182 |
if mc.get("brandFilter") is None:
|
| 15095 |
kshitij.so |
1183 |
print "Populating brand data for category_id %d" %(category_id)
|
| 14997 |
kshitij.so |
1184 |
tabData, mobData = [], []
|
|
|
1185 |
mobileDeals = get_mongo_connection().Catalog.Deals.aggregate([
|
| 16170 |
kshitij.so |
1186 |
{"$match":{"category_id":3,"showDeal":1,"totalPoints":{"$gt":-100}}
|
| 14997 |
kshitij.so |
1187 |
},
|
|
|
1188 |
{"$group" :
|
|
|
1189 |
{'_id':{'brand_id':'$brand_id','brand':'$brand'},'count':{'$sum':1}}
|
|
|
1190 |
}
|
|
|
1191 |
])
|
| 14588 |
kshitij.so |
1192 |
|
| 14997 |
kshitij.so |
1193 |
tabletDeals = get_mongo_connection().Catalog.Deals.aggregate([
|
| 16170 |
kshitij.so |
1194 |
{"$match":{"category_id":5,"showDeal":1,"totalPoints":{"$gt":-100}}
|
| 14997 |
kshitij.so |
1195 |
},
|
|
|
1196 |
{"$group" :
|
|
|
1197 |
{'_id':{'brand_id':'$brand_id','brand':'$brand'},'count':{'$sum':1}}
|
|
|
1198 |
}
|
|
|
1199 |
])
|
|
|
1200 |
|
|
|
1201 |
allDeals = get_mongo_connection().Catalog.Deals.aggregate([
|
| 16170 |
kshitij.so |
1202 |
{"$match":{"showDeal":1,"totalPoints":{"$gt":-100}}
|
| 14997 |
kshitij.so |
1203 |
},
|
|
|
1204 |
{"$group" :
|
|
|
1205 |
{'_id':{'brand_id':'$brand_id','brand':'$brand'},'count':{'$sum':1}}
|
|
|
1206 |
}
|
|
|
1207 |
])
|
|
|
1208 |
#print mobileDeals
|
|
|
1209 |
#print "==========Mobile data ends=========="
|
|
|
1210 |
|
|
|
1211 |
#print tabletDeals
|
|
|
1212 |
#print "==========Tablet data ends=========="
|
|
|
1213 |
|
|
|
1214 |
#print allDeals
|
|
|
1215 |
#print "==========All deal data ends========="
|
|
|
1216 |
|
|
|
1217 |
for mobileDeal in mobileDeals['result']:
|
|
|
1218 |
if mobileDeal.get('_id').get('brand_id') != 0:
|
|
|
1219 |
tempMap = {}
|
|
|
1220 |
tempMap['brand'] = mobileDeal.get('_id').get('brand')
|
|
|
1221 |
tempMap['brand_id'] = mobileDeal.get('_id').get('brand_id')
|
|
|
1222 |
tempMap['count'] = mobileDeal.get('count')
|
|
|
1223 |
mobData.append(tempMap)
|
|
|
1224 |
|
|
|
1225 |
for tabletDeal in tabletDeals['result']:
|
|
|
1226 |
if tabletDeal.get('_id').get('brand_id') != 0:
|
|
|
1227 |
tempMap = {}
|
|
|
1228 |
tempMap['brand'] = tabletDeal.get('_id').get('brand')
|
|
|
1229 |
tempMap['brand_id'] = tabletDeal.get('_id').get('brand_id')
|
|
|
1230 |
tempMap['count'] = tabletDeal.get('count')
|
|
|
1231 |
tabData.append(tempMap)
|
|
|
1232 |
|
|
|
1233 |
|
|
|
1234 |
brandMap = {}
|
|
|
1235 |
for allDeal in allDeals['result']:
|
|
|
1236 |
if allDeal.get('_id').get('brand_id') != 0:
|
|
|
1237 |
if brandMap.has_key(allDeal.get('_id').get('brand')):
|
| 15002 |
kshitij.so |
1238 |
brand_ids = brandMap.get(allDeal.get('_id').get('brand')).get('brand_ids')
|
| 14997 |
kshitij.so |
1239 |
brand_ids.append(allDeal.get('_id').get('brand_id'))
|
| 15003 |
kshitij.so |
1240 |
brandMap[allDeal.get('_id').get('brand')] = {'brand_ids':brand_ids,'count':brandMap.get(allDeal.get('_id').get('brand')).get('count') + allDeal.get('count')}
|
| 14997 |
kshitij.so |
1241 |
else:
|
|
|
1242 |
temp = []
|
|
|
1243 |
temp.append(allDeal.get('_id').get('brand_id'))
|
| 15002 |
kshitij.so |
1244 |
brandMap[allDeal.get('_id').get('brand')] = {'brand_ids':temp,'count':allDeal.get('count')}
|
| 14997 |
kshitij.so |
1245 |
|
|
|
1246 |
mc.set("brandFilter",{0:brandMap, 3:mobData, 5:tabData}, 600)
|
|
|
1247 |
|
| 15062 |
kshitij.so |
1248 |
return sorted(mc.get("brandFilter").get(category_id), key = lambda x: (-x['count'], x['brand']))
|
| 15375 |
kshitij.so |
1249 |
|
| 15459 |
kshitij.so |
1250 |
def getStaticDeals(offset, limit, category_id, direction):
|
| 15375 |
kshitij.so |
1251 |
user_specific_deals = mc.get("staticDeals")
|
|
|
1252 |
if user_specific_deals is None:
|
|
|
1253 |
__populateStaticDeals()
|
|
|
1254 |
user_specific_deals = mc.get("staticDeals")
|
| 15459 |
kshitij.so |
1255 |
rev = False
|
|
|
1256 |
if direction is None or direction == -1:
|
|
|
1257 |
rev=True
|
|
|
1258 |
return sorted((user_specific_deals.get(category_id))[offset:offset+limit],reverse=rev)
|
| 15375 |
kshitij.so |
1259 |
|
|
|
1260 |
def __populateStaticDeals():
|
|
|
1261 |
print "Populating memcache for static deals"
|
|
|
1262 |
outer_query = []
|
|
|
1263 |
outer_query.append({"showDeal":1})
|
|
|
1264 |
query = {}
|
| 16170 |
kshitij.so |
1265 |
query['$gt'] = -100
|
| 15375 |
kshitij.so |
1266 |
outer_query.append({'totalPoints':query})
|
|
|
1267 |
all_deals = list(get_mongo_connection().Catalog.Deals.find({"$and":outer_query},{'_id':1,'category_id':1,'brand':1,'totalPoints':1,'bestSellerPoints':1,'nlcPoints':1,'rank':1,'available_price':1,'dealType':1,'source_id':1,'brand_id':1,'skuBundleId':1}).sort([('totalPoints',pymongo.DESCENDING),('bestSellerPoints',pymongo.DESCENDING),('nlcPoints',pymongo.DESCENDING),('rank',pymongo.DESCENDING)]))
|
|
|
1268 |
mobile_deals = []
|
|
|
1269 |
tablet_deals = []
|
|
|
1270 |
for deal in all_deals:
|
|
|
1271 |
item = get_mongo_connection().Catalog.MasterData.find({'_id':deal['_id']})
|
|
|
1272 |
if deal['category_id'] ==3:
|
|
|
1273 |
mobile_deals.append(getItemObjForStaticDeals(item[0]))
|
|
|
1274 |
elif deal['category_id'] ==5:
|
|
|
1275 |
tablet_deals.append(getItemObjForStaticDeals(item[0]))
|
|
|
1276 |
else:
|
|
|
1277 |
continue
|
|
|
1278 |
|
|
|
1279 |
random.shuffle(mobile_deals,random.random)
|
|
|
1280 |
random.shuffle(tablet_deals,random.random)
|
|
|
1281 |
|
|
|
1282 |
mem_cache_val = {3:mobile_deals, 5:tablet_deals}
|
|
|
1283 |
mc.set("staticDeals", mem_cache_val, 3600)
|
|
|
1284 |
|
|
|
1285 |
def getItemObjForStaticDeals(item):
|
| 15379 |
kshitij.so |
1286 |
return {'marketPlaceUrl':item.get('marketPlaceUrl'),'available_price':item.get('available_price'),'source_product_name':item.get('source_product_name'),'thumbnail':item.get('thumbnail'),'source_id':int(item.get('source_id'))}
|
| 16300 |
manas |
1287 |
|
|
|
1288 |
def getItemByMerchantIdentifier(identifier, source_id):
|
|
|
1289 |
skuData = None
|
| 16406 |
kshitij.so |
1290 |
if source_id in (1,2,4,5,6):
|
| 16300 |
manas |
1291 |
skuData = get_mongo_connection().Catalog.MasterData.find_one({'identifier':identifier.strip(), 'source_id':source_id})
|
|
|
1292 |
elif source_id == 3:
|
|
|
1293 |
skuData = get_mongo_connection().Catalog.MasterData.find_one({'secondaryIdentifier':identifier.strip(), 'source_id':source_id})
|
|
|
1294 |
if skuData is None:
|
|
|
1295 |
return {}
|
|
|
1296 |
else:
|
|
|
1297 |
return skuData
|
| 15375 |
kshitij.so |
1298 |
|
| 16364 |
kshitij.so |
1299 |
def getDealsForNotification(skuBundleIds):
|
|
|
1300 |
bundles= [int(skuBundleId) for skuBundleId in skuBundleIds.split(',')]
|
|
|
1301 |
print bundles
|
| 16406 |
kshitij.so |
1302 |
dealsList = []
|
| 16364 |
kshitij.so |
1303 |
dealsListMap = []
|
| 16406 |
kshitij.so |
1304 |
for bundleId in bundles:
|
|
|
1305 |
outer_query = []
|
|
|
1306 |
outer_query.append({ "$or": [ { "showDeal": 1} , { "prepaidDeal": 1 } ] })
|
|
|
1307 |
outer_query.append({'skuBundleId':bundleId})
|
|
|
1308 |
deals = get_mongo_connection().Catalog.Deals.find({"$and":outer_query})
|
|
|
1309 |
for deal in deals:
|
|
|
1310 |
dealsList.append(deal)
|
| 16364 |
kshitij.so |
1311 |
sortedMap = {}
|
|
|
1312 |
rankMap = {}
|
|
|
1313 |
rank = 0
|
| 16406 |
kshitij.so |
1314 |
for sorted_deal in dealsList:
|
| 16364 |
kshitij.so |
1315 |
if sortedMap.get(sorted_deal['skuBundleId']) is None:
|
|
|
1316 |
sortedMap[sorted_deal['skuBundleId']] = {rank:[sorted_deal]}
|
|
|
1317 |
rankMap[rank] = (sortedMap[sorted_deal['skuBundleId']].values())[0]
|
|
|
1318 |
rank = rank +1
|
|
|
1319 |
else:
|
|
|
1320 |
for temp_list in sortedMap.get(sorted_deal['skuBundleId']).itervalues():
|
|
|
1321 |
temp_list.append(sorted_deal)
|
|
|
1322 |
rankMap[(sortedMap.get(sorted_deal['skuBundleId']).keys())[0]] = temp_list
|
|
|
1323 |
|
| 16367 |
kshitij.so |
1324 |
for dealList in [rankMap.get(k, []) for k in range(0, len(bundles))]:
|
| 16364 |
kshitij.so |
1325 |
temp = []
|
|
|
1326 |
for d in dealList:
|
|
|
1327 |
item = list(get_mongo_connection().Catalog.MasterData.find({'_id':d['_id']}))
|
|
|
1328 |
if len(item) ==0:
|
|
|
1329 |
continue
|
|
|
1330 |
if d['dealType'] == 1 and d['source_id'] ==1:
|
|
|
1331 |
item[0]['marketPlaceUrl'] = "http://www.amazon.in/dp/%s"%(item[0]['identifier'].strip())
|
|
|
1332 |
elif d['source_id'] ==3:
|
|
|
1333 |
item[0]['marketPlaceUrl'] = item[0]['marketPlaceUrl']+'?supc='+item[0].get('identifier')
|
|
|
1334 |
else:
|
|
|
1335 |
pass
|
|
|
1336 |
try:
|
|
|
1337 |
cashBack = getCashBack(item[0]['_id'], item[0]['source_id'], item[0]['category_id'])
|
|
|
1338 |
if not cashBack or cashBack.get('cash_back_status')!=1:
|
|
|
1339 |
item[0]['cash_back_type'] = 0
|
|
|
1340 |
item[0]['cash_back'] = 0
|
|
|
1341 |
else:
|
|
|
1342 |
item[0]['cash_back_type'] = int(cashBack['cash_back_type'])
|
|
|
1343 |
item[0]['cash_back'] = cashBack['cash_back']
|
|
|
1344 |
except:
|
|
|
1345 |
print "Error in adding cashback to deals"
|
|
|
1346 |
item[0]['cash_back_type'] = 0
|
|
|
1347 |
item[0]['cash_back'] = 0
|
|
|
1348 |
try:
|
|
|
1349 |
item[0]['dp'] = d['dp']
|
|
|
1350 |
item[0]['showDp'] = d['showDp']
|
|
|
1351 |
except:
|
|
|
1352 |
item[0]['dp'] = 0.0
|
|
|
1353 |
item[0]['showDp'] = 0
|
|
|
1354 |
temp.append(item[0])
|
|
|
1355 |
if len(temp) > 1:
|
|
|
1356 |
temp = sorted(temp, key = lambda x: (x['available_price']),reverse=False)
|
|
|
1357 |
dealsListMap.append(temp)
|
|
|
1358 |
return dealsListMap
|
|
|
1359 |
|
| 16373 |
manas |
1360 |
def getSkuBrandData(sku):
|
|
|
1361 |
if sku is None:
|
|
|
1362 |
return {}
|
|
|
1363 |
else:
|
|
|
1364 |
orders = get_mongo_connection().Catalog.MasterData.find_one({'skuBundleId':sku})
|
|
|
1365 |
if orders is None:
|
|
|
1366 |
return {}
|
|
|
1367 |
return orders
|
| 16488 |
kshitij.so |
1368 |
|
|
|
1369 |
def addDealPoints(data):
|
|
|
1370 |
collection = get_mongo_connection().Catalog.DealPoints
|
|
|
1371 |
cursor = collection.find({'skuBundleId':data['skuBundleId']})
|
|
|
1372 |
if cursor.count() > 0:
|
|
|
1373 |
return {0:"Sku information already present."}
|
|
|
1374 |
else:
|
|
|
1375 |
collection.insert(data)
|
|
|
1376 |
get_mongo_connection().Catalog.MasterData.update({'skuBundleId':data['skuBundleId']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
|
|
1377 |
return {1:"Data added successfully"}
|
|
|
1378 |
|
|
|
1379 |
def getAllBundlesWithDealPoints(offset, limit):
|
|
|
1380 |
data = []
|
|
|
1381 |
collection = get_mongo_connection().Catalog.DealPoints
|
|
|
1382 |
cursor = collection.find().sort([('endDate',pymongo.DESCENDING)]).skip(offset).limit(limit)
|
|
|
1383 |
for val in cursor:
|
|
|
1384 |
master = get_mongo_connection().Catalog.MasterData.find_one({'skuBundleId':val.get('skuBundleId')})
|
|
|
1385 |
if master is not None:
|
|
|
1386 |
val['brand'] = master['brand']
|
|
|
1387 |
val['source_product_name'] = master['product_name']
|
|
|
1388 |
else:
|
|
|
1389 |
val['brand'] = ""
|
|
|
1390 |
val['source_product_name'] = ""
|
|
|
1391 |
data.append(val)
|
|
|
1392 |
return data
|
| 16546 |
kshitij.so |
1393 |
|
|
|
1394 |
def generateRedirectUrl(retailer_id, app_id):
|
|
|
1395 |
try:
|
|
|
1396 |
d_app_offer = app_offers.get_by(id=app_id)
|
| 16605 |
manish.sha |
1397 |
except:
|
|
|
1398 |
traceback.print_exc()
|
| 16546 |
kshitij.so |
1399 |
finally:
|
|
|
1400 |
session.close()
|
|
|
1401 |
if d_app_offer is None:
|
|
|
1402 |
return {'url':"","message":"App id doesn't exist"}
|
| 16364 |
kshitij.so |
1403 |
|
| 16553 |
kshitij.so |
1404 |
appTransactions = AppTransactions(app_id, retailer_id, to_java_date(datetime.now()), None, 1, CB_INIT, 1, CB_INIT, None, None, d_app_offer.offer_price, d_app_offer.overriden_payout, d_app_offer.override_payout, d_app_offer.user_payout)
|
| 16546 |
kshitij.so |
1405 |
|
|
|
1406 |
get_mongo_connection().AppOrder.AppTransaction.insert(appTransactions.__dict__)
|
|
|
1407 |
embedd = str((appTransactions.__dict__).get('_id'))
|
| 16548 |
kshitij.so |
1408 |
try:
|
|
|
1409 |
index = d_app_offer.link.index(".freeb.co.in")
|
|
|
1410 |
except:
|
| 16605 |
manish.sha |
1411 |
traceback.print_exc()
|
| 16548 |
kshitij.so |
1412 |
return {'url':"","message":"Substring not found"}
|
|
|
1413 |
redirect_url = d_app_offer.link[0:index]+"."+embedd+d_app_offer.link[index:]
|
| 16546 |
kshitij.so |
1414 |
get_mongo_connection().AppOrder.AppTransaction.update({'_id':ObjectId(embedd)},{"$set":{'redirect_url':redirect_url}})
|
| 16548 |
kshitij.so |
1415 |
return {'url':redirect_url,"message":"Success"}
|
| 16556 |
kshitij.so |
1416 |
|
|
|
1417 |
def addPayout(payout, transaction_id):
|
|
|
1418 |
try:
|
|
|
1419 |
transaction = list(get_mongo_connection().AppOrder.AppTransaction.find({'_id':ObjectId(transaction_id)}))
|
|
|
1420 |
if len(transaction) > 0:
|
|
|
1421 |
if (transaction[0])['payout_status'] ==1:
|
|
|
1422 |
get_mongo_connection().AppOrder.AppTransaction.update({'_id':ObjectId(transaction_id)},{"$set":{'payout_amount':float(payout), 'payout_description': CB_APPROVED,'payout_status':2}})
|
| 16631 |
manish.sha |
1423 |
|
|
|
1424 |
approvedAppTransaction = approved_app_transactions()
|
|
|
1425 |
approvedAppTransaction.app_id = transaction[0]['app_id']
|
|
|
1426 |
approvedAppTransaction.cash_back_description = transaction[0]['cash_back_description']
|
|
|
1427 |
approvedAppTransaction.retailer_id = transaction[0]['retailer_id']
|
|
|
1428 |
approvedAppTransaction.transaction_id = transaction_id
|
|
|
1429 |
approvedAppTransaction.transaction_time = to_py_date(long(transaction[0]['transaction_time']))
|
|
|
1430 |
approvedAppTransaction.redirect_url = transaction[0]['redirect_url']
|
|
|
1431 |
approvedAppTransaction.payout_status = long(transaction[0]['payout_status'])
|
|
|
1432 |
approvedAppTransaction.payout_description = transaction[0]['payout_description']
|
|
|
1433 |
approvedAppTransaction.cashback_status = long(transaction[0]['cashback_status'])
|
|
|
1434 |
approvedAppTransaction.payout_amount = long(payout)
|
|
|
1435 |
approvedAppTransaction.payout_time = datetime.now()
|
|
|
1436 |
approvedAppTransaction.offer_price = long(transaction[0]['offer_price'])
|
|
|
1437 |
approvedAppTransaction.overridenCashBack = transaction[0]['overridenCashBack']
|
|
|
1438 |
if str(transaction[0]['isCashBackOverriden']) == 'false' or str(transaction[0]['isCashBackOverriden']) == 'False':
|
|
|
1439 |
approvedAppTransaction.isCashBackOverriden = False
|
|
|
1440 |
else:
|
|
|
1441 |
approvedAppTransaction.isCashBackOverriden = True
|
|
|
1442 |
approvedAppTransaction.user_payout = transaction[0]['user_payout']
|
|
|
1443 |
approvedAppTransaction.cashBackConsidered = False
|
|
|
1444 |
session.commit()
|
|
|
1445 |
|
|
|
1446 |
updateResult = _updateApprovedCashbackToUser(approvedAppTransaction.id)
|
| 16556 |
kshitij.so |
1447 |
return {'status':'ok','message':'Payout updated'}
|
|
|
1448 |
elif (transaction[0])['payout_status'] ==2:
|
|
|
1449 |
return {'status':'ok','message':'Payout already processed'}
|
|
|
1450 |
else:
|
|
|
1451 |
return {'status':'fail','message':'Something is wrong'}
|
|
|
1452 |
else:
|
|
|
1453 |
return {'status':'fail','message':'transaction_id not found'}
|
|
|
1454 |
except:
|
| 16631 |
manish.sha |
1455 |
try:
|
|
|
1456 |
get_mongo_connection().AppOrder.AppTransaction.update({'_id':ObjectId(transaction_id)},{"$set":{'payout_amount':None, 'payout_description': CB_INIT,'payout_status':1}})
|
|
|
1457 |
except:
|
|
|
1458 |
print 'Data Inconsistency in Cashback Process'
|
|
|
1459 |
traceback.print_exc()
|
| 16559 |
kshitij.so |
1460 |
return {'status':'fail','message':'Something is wrong'}
|
| 16556 |
kshitij.so |
1461 |
|
| 16631 |
manish.sha |
1462 |
def _updateApprovedCashbackToUser(approvedAppTransactionId):
|
|
|
1463 |
approvedAppTransaction = approved_app_transactions.get_by(id=approvedAppTransactionId)
|
|
|
1464 |
currentMonth = datetime.today().month
|
|
|
1465 |
currentDay = datetime.today().day
|
|
|
1466 |
currentYear = datetime.today().year
|
|
|
1467 |
fortNight = (currentMonth - 1)*2 + (currentDay/15)
|
|
|
1468 |
if currentDay == 30 or currentDay ==31:
|
|
|
1469 |
fortNight = fortNight-1
|
|
|
1470 |
userAppCashbackObj = user_app_cashbacks.query.filter(user_app_cashbacks.yearVal==currentYear).filter(user_app_cashbacks.user_id==approvedAppTransaction.retailer_id).filter(user_app_cashbacks.fortnightOfYear==fortNight).filter(user_app_cashbacks.status=='Approved').first()
|
|
|
1471 |
userAppInstallObj = user_app_installs.query.filter(user_app_installs.user_id==approvedAppTransaction.retailer_id).filter(user_app_installs.app_id==approvedAppTransaction.app_id).filter(user_app_installs.transaction_date==datetime(currentYear, currentMonth, currentDay, 0, 0, 0, 0).date()).first()
|
|
|
1472 |
try:
|
|
|
1473 |
if userAppCashbackObj is None:
|
|
|
1474 |
userAppCashbackObj = user_app_cashbacks()
|
|
|
1475 |
userAppCashbackObj.user_id = approvedAppTransaction.retailer_id
|
|
|
1476 |
userAppCashbackObj.status = 'Approved'
|
|
|
1477 |
userAppCashbackObj.amount = approvedAppTransaction.user_payout
|
|
|
1478 |
userAppCashbackObj.fortnightOfYear = fortNight
|
|
|
1479 |
userAppCashbackObj.yearVal = currentYear
|
|
|
1480 |
else:
|
|
|
1481 |
userAppCashbackObj.amount = userAppCashbackObj.amount + approvedAppTransaction.user_payout
|
|
|
1482 |
|
|
|
1483 |
if userAppInstallObj is None:
|
|
|
1484 |
app_offer = app_offers.get_by(id=approvedAppTransaction.app_id)
|
|
|
1485 |
userAppInstallObj = user_app_installs()
|
|
|
1486 |
userAppInstallObj.user_id = approvedAppTransaction.retailer_id
|
|
|
1487 |
userAppInstallObj.fortnightOfYear = fortNight
|
|
|
1488 |
userAppInstallObj.transaction_date = datetime(currentYear, currentMonth, currentDay, 0, 0, 0, 0).date()
|
|
|
1489 |
userAppInstallObj.app_id = approvedAppTransaction.app_id
|
|
|
1490 |
userAppInstallObj.app_name = app_offer.app_name
|
|
|
1491 |
userAppInstallObj.installCount = 1
|
|
|
1492 |
userAppInstallObj.payoutAmount = approvedAppTransaction.user_payout
|
|
|
1493 |
else:
|
|
|
1494 |
userAppInstallObj.installCount = userAppInstallObj.installCount + 1
|
|
|
1495 |
userAppInstallObj.payoutAmount = userAppInstallObj.payoutAmount +approvedAppTransaction.user_payout
|
|
|
1496 |
|
|
|
1497 |
approvedAppTransaction.cashBackConsidered = True
|
|
|
1498 |
session.commit()
|
|
|
1499 |
return True
|
|
|
1500 |
except:
|
|
|
1501 |
session.rollback()
|
|
|
1502 |
traceback.print_exc()
|
|
|
1503 |
return False
|
|
|
1504 |
|
| 16546 |
kshitij.so |
1505 |
|
|
|
1506 |
|
|
|
1507 |
|
| 13572 |
kshitij.so |
1508 |
def main():
|
| 16556 |
kshitij.so |
1509 |
#generateRedirectUrl(101,1
|
|
|
1510 |
print addPayout("10", "55db82c0bcabd7fc59e0a71")
|
| 13811 |
kshitij.so |
1511 |
|
| 13921 |
kshitij.so |
1512 |
|
| 15375 |
kshitij.so |
1513 |
|
| 13572 |
kshitij.so |
1514 |
if __name__=='__main__':
|
| 13932 |
amit.gupta |
1515 |
main()
|