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