| 14305 |
amit.gupta |
1 |
from bson.objectid import ObjectId
|
|
|
2 |
from datetime import datetime, timedelta
|
|
|
3 |
from dtr.config import PythonPropertyReader
|
| 19340 |
kshitij.so |
4 |
from dtr.dao import FeaturedDeals, AppTransactions, AppOfferObj, Promotion, NotificationCampaign
|
| 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, \
|
| 17280 |
manish.sha |
8 |
user_app_installs, appmasters, notification_campaigns
|
| 16304 |
amit.gupta |
9 |
from dtr.storage.MemCache import MemCache
|
| 16789 |
amit.gupta |
10 |
from dtr.utils.MailSender import Email
|
|
|
11 |
from dtr.utils.utils import to_java_date, CB_PENDING, CB_APPROVED, CB_INIT, \
|
| 17604 |
kshitij.so |
12 |
to_py_date, CB_REJECTED, SUB_CATEGORY_MAP
|
| 16894 |
manish.sha |
13 |
from sqlalchemy.sql.expression import func, func, or_, desc, asc, case
|
| 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
|
| 16894 |
manish.sha |
22 |
from itertools import groupby
|
| 17280 |
manish.sha |
23 |
import urllib
|
|
|
24 |
import urllib2
|
|
|
25 |
import json
|
| 17367 |
kshitij.so |
26 |
import collections
|
|
|
27 |
try:
|
|
|
28 |
import ordereddict
|
|
|
29 |
except:
|
|
|
30 |
pass
|
| 13572 |
kshitij.so |
31 |
|
| 18830 |
kshitij.so |
32 |
|
|
|
33 |
import bson.son as son
|
| 19207 |
kshitij.so |
34 |
import math
|
|
|
35 |
|
| 13572 |
kshitij.so |
36 |
con = None
|
| 17944 |
kshitij.so |
37 |
es = None
|
| 18052 |
kshitij.so |
38 |
try:
|
|
|
39 |
from elasticsearch import Elasticsearch
|
|
|
40 |
except:
|
|
|
41 |
pass
|
| 17936 |
kshitij.so |
42 |
from shop2020.config.client.ConfigClient import ConfigClient
|
| 13572 |
kshitij.so |
43 |
|
| 14037 |
kshitij.so |
44 |
DataService.initialize(db_hostname="localhost")
|
| 16304 |
amit.gupta |
45 |
mc = MemCache("127.0.0.1")
|
| 17936 |
kshitij.so |
46 |
config_client = ConfigClient()
|
|
|
47 |
elastic_search_host = config_client.get_property('elastic_search_host')
|
|
|
48 |
elastic_search_port = config_client.get_property('elastic_search_port')
|
| 14037 |
kshitij.so |
49 |
|
| 17936 |
kshitij.so |
50 |
|
| 17944 |
kshitij.so |
51 |
|
| 17035 |
kshitij.so |
52 |
SOURCE_MAP = {1:'AMAZON',2:'FLIPKART',3:'SNAPDEAL',4:'SAHOLIC',5:"SHOPCLUES.COM",6:"PAYTM.COM",7:"HOMESHOP18.COM"}
|
| 14482 |
kshitij.so |
53 |
|
| 15853 |
kshitij.so |
54 |
COLLECTION_MAP = {
|
|
|
55 |
'ExceptionalNlc':'skuBundleId',
|
|
|
56 |
'SkuDealerPrices':'skuBundleId',
|
|
|
57 |
'SkuDiscountInfo':'skuBundleId',
|
|
|
58 |
'SkuSchemeDetails':'skuBundleId',
|
| 17367 |
kshitij.so |
59 |
'DealPoints':'skuBundleId',
|
|
|
60 |
'FeaturedDeals': 'skuBundleId'
|
| 15853 |
kshitij.so |
61 |
}
|
|
|
62 |
|
| 19337 |
manish.sha |
63 |
|
| 17944 |
kshitij.so |
64 |
def get_elastic_search_connection():
|
|
|
65 |
global es
|
|
|
66 |
if es is None:
|
|
|
67 |
print "Establishing connection with elastic search %s host and port %s"%(elastic_search_host,elastic_search_port)
|
|
|
68 |
es = Elasticsearch([{'host': elastic_search_host, 'port': elastic_search_port}])
|
|
|
69 |
return es
|
|
|
70 |
return es
|
|
|
71 |
|
|
|
72 |
|
| 13572 |
kshitij.so |
73 |
def get_mongo_connection(host='localhost', port=27017):
|
|
|
74 |
global con
|
|
|
75 |
if con is None:
|
|
|
76 |
print "Establishing connection %s host and port %d" %(host,port)
|
|
|
77 |
try:
|
|
|
78 |
con = pymongo.MongoClient(host, port)
|
|
|
79 |
except Exception, e:
|
|
|
80 |
print e
|
|
|
81 |
return None
|
|
|
82 |
return con
|
|
|
83 |
|
| 13907 |
kshitij.so |
84 |
def populateCashBack():
|
| 13921 |
kshitij.so |
85 |
print "Populating cashback"
|
|
|
86 |
cashBackMap = {}
|
|
|
87 |
itemCashBackMap = {}
|
| 13907 |
kshitij.so |
88 |
cashBack = list(get_mongo_connection().Catalog.CategoryCashBack.find())
|
|
|
89 |
for row in cashBack:
|
| 13970 |
kshitij.so |
90 |
temp_map = {}
|
|
|
91 |
temp_list = []
|
| 13907 |
kshitij.so |
92 |
if cashBackMap.has_key(row['source_id']):
|
|
|
93 |
arr = cashBackMap.get(row['source_id'])
|
|
|
94 |
for val in arr:
|
|
|
95 |
temp_list.append(val)
|
|
|
96 |
temp_map[row['category_id']] = row
|
|
|
97 |
temp_list.append(temp_map)
|
|
|
98 |
cashBackMap[row['source_id']] = temp_list
|
|
|
99 |
else:
|
|
|
100 |
temp_map[row['category_id']] = row
|
|
|
101 |
temp_list.append(temp_map)
|
|
|
102 |
cashBackMap[row['source_id']] = temp_list
|
| 13921 |
kshitij.so |
103 |
itemCashBack = list(get_mongo_connection().Catalog.ItemCashBack.find())
|
|
|
104 |
for row in itemCashBack:
|
|
|
105 |
if not itemCashBackMap.has_key(row['skuId']):
|
|
|
106 |
itemCashBackMap[row['skuId']] = row
|
| 14761 |
kshitij.so |
107 |
mc.set("item_cash_back", itemCashBackMap, 24 * 60 * 60)
|
|
|
108 |
mc.set("category_cash_back", cashBackMap, 24 * 60 * 60)
|
| 13907 |
kshitij.so |
109 |
|
| 13572 |
kshitij.so |
110 |
def addCategoryDiscount(data):
|
| 13970 |
kshitij.so |
111 |
collection = get_mongo_connection().Catalog.CategoryDiscount
|
| 13572 |
kshitij.so |
112 |
query = []
|
|
|
113 |
data['brand'] = data['brand'].strip().upper()
|
| 13970 |
kshitij.so |
114 |
data['discountType'] = data['discountType'].upper().strip()
|
| 13572 |
kshitij.so |
115 |
query.append({"brand":data['brand']})
|
|
|
116 |
query.append({"category_id":data['category_id']})
|
|
|
117 |
r = collection.find({"$and":query})
|
|
|
118 |
if r.count() > 0:
|
| 13639 |
kshitij.so |
119 |
return {0:"Brand & Category info already present."}
|
| 13572 |
kshitij.so |
120 |
else:
|
|
|
121 |
collection.insert(data)
|
| 13970 |
kshitij.so |
122 |
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 |
123 |
return {1:"Data added successfully"}
|
| 13572 |
kshitij.so |
124 |
|
| 13970 |
kshitij.so |
125 |
def updateCategoryDiscount(data,_id):
|
|
|
126 |
try:
|
|
|
127 |
collection = get_mongo_connection().Catalog.CategoryDiscount
|
|
|
128 |
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)
|
|
|
129 |
get_mongo_connection().Catalog.MasterData.update({'brand':data['brand'],'category_id':data['category_id']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
|
|
130 |
return {1:"Data updated successfully"}
|
|
|
131 |
except:
|
|
|
132 |
return {0:"Data not updated."}
|
|
|
133 |
|
|
|
134 |
|
| 13572 |
kshitij.so |
135 |
def getAllCategoryDiscount():
|
|
|
136 |
data = []
|
| 13970 |
kshitij.so |
137 |
collection = get_mongo_connection().Catalog.CategoryDiscount
|
| 13572 |
kshitij.so |
138 |
cursor = collection.find()
|
|
|
139 |
for val in cursor:
|
|
|
140 |
data.append(val)
|
|
|
141 |
return data
|
|
|
142 |
|
| 14553 |
kshitij.so |
143 |
def __getBundledSkusfromSku(sku):
|
|
|
144 |
masterData = get_mongo_connection().Catalog.MasterData.find_one({"_id":sku},{"skuBundleId":1})
|
|
|
145 |
if masterData is not None:
|
|
|
146 |
return list(get_mongo_connection().Catalog.MasterData.find({"skuBundleId":masterData.get('skuBundleId')},{'_id':1,'skuBundleId':1}))
|
|
|
147 |
else:
|
|
|
148 |
return []
|
| 13572 |
kshitij.so |
149 |
|
| 15853 |
kshitij.so |
150 |
def addSchemeDetailsForSku(data):
|
|
|
151 |
collection = get_mongo_connection().Catalog.SkuSchemeDetails
|
|
|
152 |
result = collection.find_one({'skuBundleId':data['skuBundleId']})
|
|
|
153 |
if result is None:
|
| 14553 |
kshitij.so |
154 |
collection.insert(data)
|
| 15853 |
kshitij.so |
155 |
get_mongo_connection().Catalog.MasterData.update({'skuBundleId':data['skuBundleId']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
| 14553 |
kshitij.so |
156 |
return {1:"Data added successfully"}
|
| 15853 |
kshitij.so |
157 |
return {1:"BundleId info already present"}
|
|
|
158 |
|
| 14069 |
kshitij.so |
159 |
def getAllSkuWiseSchemeDetails(offset, limit):
|
| 13572 |
kshitij.so |
160 |
data = []
|
| 13970 |
kshitij.so |
161 |
collection = get_mongo_connection().Catalog.SkuSchemeDetails
|
| 14071 |
kshitij.so |
162 |
cursor = collection.find().skip(offset).limit(limit)
|
| 13572 |
kshitij.so |
163 |
for val in cursor:
|
| 15853 |
kshitij.so |
164 |
master = get_mongo_connection().Catalog.MasterData.find_one({'skuBundleId':val['skuBundleId']})
|
|
|
165 |
if master is not None:
|
|
|
166 |
val['brand'] = master['brand']
|
|
|
167 |
val['source_product_name'] = master['source_product_name']
|
| 14069 |
kshitij.so |
168 |
else:
|
|
|
169 |
val['brand'] = ""
|
|
|
170 |
val['source_product_name'] = ""
|
| 13572 |
kshitij.so |
171 |
data.append(val)
|
|
|
172 |
return data
|
|
|
173 |
|
| 15853 |
kshitij.so |
174 |
def addSkuDiscountInfo(data):
|
|
|
175 |
collection = get_mongo_connection().Catalog.SkuDiscountInfo
|
|
|
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 getallSkuDiscountInfo(offset, limit):
|
| 13572 |
kshitij.so |
185 |
data = []
|
| 13970 |
kshitij.so |
186 |
collection = get_mongo_connection().Catalog.SkuDiscountInfo
|
|
|
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 |
|
| 13970 |
kshitij.so |
199 |
def updateSkuDiscount(data,_id):
|
|
|
200 |
try:
|
|
|
201 |
collection = get_mongo_connection().Catalog.SkuDiscountInfo
|
|
|
202 |
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 |
203 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['skuBundleId']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
| 13970 |
kshitij.so |
204 |
return {1:"Data updated successfully"}
|
|
|
205 |
except:
|
|
|
206 |
return {0:"Data not updated."}
|
|
|
207 |
|
|
|
208 |
|
| 15853 |
kshitij.so |
209 |
def addExceptionalNlc(data):
|
|
|
210 |
collection = get_mongo_connection().Catalog.ExceptionalNlc
|
|
|
211 |
cursor = collection.find_one({"skuBundleId":data['skuBundleId']})
|
|
|
212 |
if cursor is not None:
|
|
|
213 |
return {0:"BundleId information already present."}
|
| 13572 |
kshitij.so |
214 |
else:
|
| 15853 |
kshitij.so |
215 |
collection.insert(data)
|
|
|
216 |
get_mongo_connection().Catalog.MasterData.update({'skuBundleId':data['skuBundleId']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
| 13639 |
kshitij.so |
217 |
return {1:"Data added successfully"}
|
| 13572 |
kshitij.so |
218 |
|
| 13970 |
kshitij.so |
219 |
def getAllExceptionlNlcItems(offset, limit):
|
| 13572 |
kshitij.so |
220 |
data = []
|
| 13970 |
kshitij.so |
221 |
collection = get_mongo_connection().Catalog.ExceptionalNlc
|
| 14071 |
kshitij.so |
222 |
cursor = collection.find().skip(offset).limit(limit)
|
| 13572 |
kshitij.so |
223 |
for val in cursor:
|
| 15853 |
kshitij.so |
224 |
master = get_mongo_connection().Catalog.MasterData.find_one({'skuBundleId':val['skuBundleId']})
|
|
|
225 |
if master is not None:
|
|
|
226 |
val['brand'] = master['brand']
|
|
|
227 |
val['source_product_name'] = master['source_product_name']
|
| 13970 |
kshitij.so |
228 |
else:
|
|
|
229 |
val['brand'] = ""
|
|
|
230 |
val['source_product_name'] = ""
|
| 13572 |
kshitij.so |
231 |
data.append(val)
|
|
|
232 |
return data
|
|
|
233 |
|
| 14005 |
amit.gupta |
234 |
def getMerchantOrdersByUser(userId, page=1, window=50, searchMap={}):
|
|
|
235 |
if searchMap is None:
|
|
|
236 |
searchMap = {}
|
| 13603 |
amit.gupta |
237 |
if page==None:
|
|
|
238 |
page = 1
|
|
|
239 |
|
|
|
240 |
if window==None:
|
|
|
241 |
window = 50
|
|
|
242 |
result = {}
|
| 13582 |
amit.gupta |
243 |
skip = (page-1)*window
|
| 14005 |
amit.gupta |
244 |
|
| 14353 |
amit.gupta |
245 |
if userId is not None:
|
|
|
246 |
searchMap['userId'] = userId
|
| 13603 |
amit.gupta |
247 |
collection = get_mongo_connection().Dtr.merchantOrder
|
| 14609 |
amit.gupta |
248 |
cursor = collection.find(searchMap).sort("orderId",-1)
|
| 13603 |
amit.gupta |
249 |
total_count = cursor.count()
|
|
|
250 |
pages = total_count/window + (0 if total_count%window==0 else 1)
|
|
|
251 |
print "total_count", total_count
|
|
|
252 |
if total_count > skip:
|
| 13999 |
amit.gupta |
253 |
cursor = cursor.skip(skip).limit(window)
|
| 13603 |
amit.gupta |
254 |
orders = []
|
|
|
255 |
for order in cursor:
|
| 14002 |
amit.gupta |
256 |
del(order["_id"])
|
|
|
257 |
orders.append(order)
|
| 13603 |
amit.gupta |
258 |
result['data'] = orders
|
|
|
259 |
result['window'] = window
|
|
|
260 |
result['totalCount'] = total_count
|
|
|
261 |
result['currCount'] = cursor.count()
|
|
|
262 |
result['totalPages'] = pages
|
|
|
263 |
result['currPage'] = page
|
|
|
264 |
return result
|
|
|
265 |
else:
|
|
|
266 |
return result
|
| 13630 |
kshitij.so |
267 |
|
| 13927 |
amit.gupta |
268 |
def getRefunds(userId, page=1, window=10):
|
|
|
269 |
if page==None:
|
|
|
270 |
page = 1
|
|
|
271 |
|
|
|
272 |
if window==None:
|
| 13995 |
amit.gupta |
273 |
window = 10
|
| 13927 |
amit.gupta |
274 |
result = {}
|
|
|
275 |
skip = (page-1)*window
|
| 16737 |
amit.gupta |
276 |
con = get_mongo_connection()
|
|
|
277 |
collection = con.Dtr.refund
|
|
|
278 |
user = con.Dtr.user
|
| 16754 |
amit.gupta |
279 |
credited = user.find_one({"userId":userId})
|
|
|
280 |
if credited:
|
|
|
281 |
credited = credited.get("credited")
|
|
|
282 |
else:
|
|
|
283 |
credited=0
|
|
|
284 |
|
| 13927 |
amit.gupta |
285 |
cursor = collection.find({"userId":userId})
|
|
|
286 |
total_count = cursor.count()
|
|
|
287 |
pages = total_count/window + (0 if total_count%window==0 else 1)
|
|
|
288 |
print "total_count", total_count
|
|
|
289 |
if total_count > skip:
|
| 14668 |
amit.gupta |
290 |
cursor = cursor.skip(skip).limit(window).sort([('batch',-1)])
|
| 13927 |
amit.gupta |
291 |
refunds = []
|
|
|
292 |
for refund in cursor:
|
|
|
293 |
del(refund["_id"])
|
|
|
294 |
refunds.append(refund)
|
| 16754 |
amit.gupta |
295 |
result['credited'] = credited
|
| 13927 |
amit.gupta |
296 |
result['data'] = refunds
|
|
|
297 |
result['window'] = window
|
|
|
298 |
result['totalCount'] = total_count
|
|
|
299 |
result['currCount'] = cursor.count()
|
|
|
300 |
result['totalPages'] = pages
|
|
|
301 |
result['currPage'] = page
|
|
|
302 |
return result
|
|
|
303 |
else:
|
|
|
304 |
return result
|
|
|
305 |
|
|
|
306 |
def getPendingRefunds(userId):
|
| 13991 |
amit.gupta |
307 |
print type(userId)
|
| 13927 |
amit.gupta |
308 |
result = get_mongo_connection().Dtr.merchantOrder\
|
|
|
309 |
.aggregate([
|
| 16398 |
amit.gupta |
310 |
{'$match':{'subOrders.cashBackStatus':CB_APPROVED, 'userId':userId}},
|
| 13927 |
amit.gupta |
311 |
{'$unwind':"$subOrders"},
|
| 16398 |
amit.gupta |
312 |
{'$match':{'subOrders.cashBackStatus':CB_APPROVED}},
|
| 13927 |
amit.gupta |
313 |
{
|
|
|
314 |
'$group':{
|
|
|
315 |
'_id':None,
|
|
|
316 |
'amount': { '$sum':'$subOrders.cashBackAmount'},
|
|
|
317 |
}
|
|
|
318 |
}
|
| 13987 |
amit.gupta |
319 |
])['result']
|
|
|
320 |
|
|
|
321 |
if len(result)>0:
|
|
|
322 |
result = result[0]
|
|
|
323 |
result.pop("_id")
|
|
|
324 |
else:
|
|
|
325 |
result={}
|
|
|
326 |
result['amount'] = 0.0
|
| 14305 |
amit.gupta |
327 |
result['nextCredit'] = datetime.strftime(next_weekday(datetime.now(), int(PythonPropertyReader.getConfig('CREDIT_DAY_OF_WEEK'))),"%Y-%m-%d %H:%M:%S")
|
| 13927 |
amit.gupta |
328 |
return result
|
| 14037 |
kshitij.so |
329 |
|
| 14671 |
amit.gupta |
330 |
def getPendingCashbacks(userId):
|
|
|
331 |
result = get_mongo_connection().Dtr.merchantOrder\
|
|
|
332 |
.aggregate([
|
| 16398 |
amit.gupta |
333 |
{'$match':{'subOrders.cashBackStatus':CB_PENDING, 'userId':userId}},
|
| 14671 |
amit.gupta |
334 |
{'$unwind':"$subOrders"},
|
| 16398 |
amit.gupta |
335 |
{'$match':{'subOrders.cashBackStatus':CB_PENDING}},
|
| 14671 |
amit.gupta |
336 |
{
|
|
|
337 |
'$group':{
|
|
|
338 |
'_id':None,
|
|
|
339 |
'amount': { '$sum':'$subOrders.cashBackAmount'},
|
|
|
340 |
}
|
|
|
341 |
}
|
|
|
342 |
])['result']
|
|
|
343 |
|
|
|
344 |
if len(result)>0:
|
|
|
345 |
result = result[0]
|
|
|
346 |
result.pop("_id")
|
|
|
347 |
else:
|
|
|
348 |
result={}
|
|
|
349 |
result['amount'] = 0.0
|
|
|
350 |
return result
|
|
|
351 |
|
| 17369 |
kshitij.so |
352 |
def __constructDummyDealObject(skuBundleId):
|
|
|
353 |
temp =[]
|
| 19193 |
kshitij.so |
354 |
deals = get_mongo_connection().Catalog.Deals.find({"skuBundleId":skuBundleId,"$or":[{"showDeal":1}, {"prepaidDeal":1}]},{'_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, 'gross_price':1,'subCategoryId':1,'netPriceAfterCashBack':1})
|
| 17369 |
kshitij.so |
355 |
for d in deals:
|
|
|
356 |
d['persPoints'] = 0
|
|
|
357 |
temp.append(d)
|
|
|
358 |
return temp
|
|
|
359 |
|
|
|
360 |
|
|
|
361 |
|
| 14037 |
kshitij.so |
362 |
def __populateCache(userId):
|
| 17369 |
kshitij.so |
363 |
try:
|
|
|
364 |
if mc.get("featured_deals") is None:
|
|
|
365 |
__populateFeaturedDeals()
|
|
|
366 |
featuredDeals = mc.get("featured_deals")
|
|
|
367 |
|
|
|
368 |
except Exception as e:
|
|
|
369 |
print traceback.print_exc()
|
| 17469 |
kshitij.so |
370 |
featuredDeals = {3:{},5:{},6:{}}
|
| 17369 |
kshitij.so |
371 |
|
|
|
372 |
fd_bundles = []
|
|
|
373 |
|
|
|
374 |
for catMap in featuredDeals.itervalues():
|
|
|
375 |
for fd_map in catMap.itervalues():
|
| 17541 |
kshitij.so |
376 |
if not fd_map.get('skuBundleId') in fd_bundles:
|
|
|
377 |
fd_bundles.append(fd_map.get('skuBundleId'))
|
| 17369 |
kshitij.so |
378 |
|
| 14037 |
kshitij.so |
379 |
print "Populating memcache for userId",userId
|
|
|
380 |
outer_query = []
|
| 16067 |
kshitij.so |
381 |
outer_query.append({ "$or": [ { "showDeal": 1} , { "prepaidDeal": 1 } ] })
|
| 14037 |
kshitij.so |
382 |
query = {}
|
| 16170 |
kshitij.so |
383 |
query['$gt'] = -100
|
| 14037 |
kshitij.so |
384 |
outer_query.append({'totalPoints':query})
|
|
|
385 |
brandPrefMap = {}
|
|
|
386 |
pricePrefMap = {}
|
|
|
387 |
actionsMap = {}
|
|
|
388 |
brand_p = session.query(price_preferences).filter_by(user_id=userId).all()
|
|
|
389 |
for x in brand_p:
|
|
|
390 |
pricePrefMap[x.category_id] = [x.min_price,x.max_price]
|
|
|
391 |
for x in session.query(brand_preferences).filter_by(user_id=userId).all():
|
|
|
392 |
temp_map = {}
|
|
|
393 |
if brandPrefMap.has_key((x.brand).strip().upper()):
|
|
|
394 |
val = brandPrefMap.get((x.brand).strip().upper())
|
|
|
395 |
temp_map[x.category_id] = 1 if x.status == 'show' else 0
|
|
|
396 |
val.append(temp_map)
|
|
|
397 |
else:
|
|
|
398 |
temp = []
|
|
|
399 |
temp_map[x.category_id] = 1 if x.status == 'show' else 0
|
|
|
400 |
temp.append(temp_map)
|
|
|
401 |
brandPrefMap[(x.brand).strip().upper()] = temp
|
|
|
402 |
|
|
|
403 |
for x in session.query(user_actions).filter_by(user_id=userId).all():
|
|
|
404 |
actionsMap[x.store_product_id] = 1 if x.action == 'like' else 0
|
| 19193 |
kshitij.so |
405 |
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, 'gross_price':1, 'subCategoryId':1,'netPriceAfterCashBack':1}).sort([('totalPoints',pymongo.DESCENDING),('bestSellerPoints',pymongo.DESCENDING),('nlcPoints',pymongo.DESCENDING),('rank',pymongo.DESCENDING)]))
|
| 14037 |
kshitij.so |
406 |
mobile_deals = []
|
|
|
407 |
tablet_deals = []
|
| 17469 |
kshitij.so |
408 |
accessories_deals = []
|
| 14037 |
kshitij.so |
409 |
for deal in all_deals:
|
| 19135 |
kshitij.so |
410 |
|
| 17369 |
kshitij.so |
411 |
try:
|
|
|
412 |
fd_bundles.remove(deal.get('skuBundleId'))
|
|
|
413 |
except:
|
|
|
414 |
pass
|
|
|
415 |
|
| 14037 |
kshitij.so |
416 |
if actionsMap.get(deal['_id']) == 0:
|
|
|
417 |
fav_weight =.25
|
|
|
418 |
elif actionsMap.get(deal['_id']) == 1:
|
|
|
419 |
fav_weight = 1.5
|
|
|
420 |
else:
|
|
|
421 |
fav_weight = 1
|
|
|
422 |
|
|
|
423 |
if brandPrefMap.get(deal['brand'].strip().upper()) is not None:
|
| 17469 |
kshitij.so |
424 |
|
| 14037 |
kshitij.so |
425 |
brand_weight = 1
|
|
|
426 |
for brandInfo in brandPrefMap.get(deal['brand'].strip().upper()):
|
|
|
427 |
if brandInfo.get(deal['category_id']) is not None:
|
|
|
428 |
if brandInfo.get(deal['category_id']) == 1:
|
| 14055 |
kshitij.so |
429 |
brand_weight = 2.0
|
| 14037 |
kshitij.so |
430 |
else:
|
|
|
431 |
brand_weight = 1
|
|
|
432 |
|
|
|
433 |
if pricePrefMap.get(deal['category_id']) is not None:
|
|
|
434 |
|
|
|
435 |
if deal['available_price'] >= pricePrefMap.get(deal['category_id'])[0] and deal['available_price'] <= pricePrefMap.get(deal['category_id'])[1]:
|
|
|
436 |
asp_weight = 1.5
|
|
|
437 |
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]:
|
|
|
438 |
asp_weight = 1.2
|
|
|
439 |
else:
|
|
|
440 |
asp_weight = 1
|
|
|
441 |
else:
|
|
|
442 |
asp_weight = 1
|
|
|
443 |
|
|
|
444 |
persPoints = deal['totalPoints'] * fav_weight * brand_weight * asp_weight
|
|
|
445 |
deal['persPoints'] = persPoints
|
|
|
446 |
|
|
|
447 |
if deal['category_id'] ==3:
|
|
|
448 |
mobile_deals.append(deal)
|
|
|
449 |
elif deal['category_id'] ==5:
|
|
|
450 |
tablet_deals.append(deal)
|
| 17469 |
kshitij.so |
451 |
elif deal['category_id'] ==6:
|
|
|
452 |
accessories_deals.append(deal)
|
| 14037 |
kshitij.so |
453 |
else:
|
|
|
454 |
continue
|
|
|
455 |
|
| 14144 |
kshitij.so |
456 |
session.close()
|
| 17367 |
kshitij.so |
457 |
|
|
|
458 |
mobile_deals = sorted(mobile_deals, key = lambda x: (x['persPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
|
|
|
459 |
tablet_deals = sorted(tablet_deals, key = lambda x: (x['persPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
|
| 17469 |
kshitij.so |
460 |
accessories_deals = sorted(accessories_deals, key = lambda x: (x['persPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
|
| 17367 |
kshitij.so |
461 |
|
|
|
462 |
|
| 17369 |
kshitij.so |
463 |
if len(fd_bundles) > 0:
|
|
|
464 |
print "There is still bundle in feature deals with points less than -100.Lets add info"
|
|
|
465 |
for skuBundleId in fd_bundles:
|
|
|
466 |
dummyDealObjList = __constructDummyDealObject(skuBundleId)
|
|
|
467 |
for dummyDealObj in dummyDealObjList:
|
|
|
468 |
if dummyDealObj['category_id'] ==3:
|
|
|
469 |
mobile_deals.append(dummyDealObj)
|
|
|
470 |
elif dummyDealObj['category_id'] ==5:
|
|
|
471 |
tablet_deals.append(dummyDealObj)
|
| 17469 |
kshitij.so |
472 |
elif dummyDealObj['category_id'] ==6:
|
|
|
473 |
accessories_deals.append(dummyDealObj)
|
| 17369 |
kshitij.so |
474 |
else:
|
|
|
475 |
pass
|
|
|
476 |
|
| 17469 |
kshitij.so |
477 |
for super_category, categoryFeaturedDeals in featuredDeals.iteritems():
|
|
|
478 |
for val in categoryFeaturedDeals.itervalues():
|
|
|
479 |
dummyDealObjList = __constructDummyDealObject(val.get('skuBundleId'))
|
|
|
480 |
for dummyDealObj in dummyDealObjList:
|
|
|
481 |
if super_category == dummyDealObj['category_id']:
|
|
|
482 |
continue
|
|
|
483 |
|
|
|
484 |
if super_category ==3:
|
|
|
485 |
mobile_deals.append(dummyDealObj)
|
|
|
486 |
elif super_category ==5:
|
|
|
487 |
tablet_deals.append(dummyDealObj)
|
|
|
488 |
elif super_category ==6:
|
|
|
489 |
accessories_deals.append(dummyDealObj)
|
|
|
490 |
else:
|
|
|
491 |
pass
|
|
|
492 |
|
| 17367 |
kshitij.so |
493 |
sortedMapMobiles = {}
|
|
|
494 |
rankMapMobiles = {}
|
|
|
495 |
rankMobiles = 0
|
|
|
496 |
|
|
|
497 |
blockedRanksMobiles = []
|
|
|
498 |
blockedSkuBundlesMobiles = []
|
|
|
499 |
blockedInfoMobiles = {}
|
|
|
500 |
|
|
|
501 |
featuredDealsMobiles = featuredDeals.get(3)
|
|
|
502 |
|
|
|
503 |
for k, v in featuredDealsMobiles.iteritems():
|
| 17469 |
kshitij.so |
504 |
blockedRanksMobiles.append(k-1)
|
|
|
505 |
blockedSkuBundlesMobiles.append(v.get('skuBundleId'))
|
| 17367 |
kshitij.so |
506 |
|
|
|
507 |
|
|
|
508 |
for sorted_deal in mobile_deals:
|
| 17369 |
kshitij.so |
509 |
|
| 17367 |
kshitij.so |
510 |
while(True):
|
|
|
511 |
if rankMobiles in blockedRanksMobiles:
|
|
|
512 |
rankMobiles = rankMobiles +1
|
|
|
513 |
else:
|
|
|
514 |
break
|
|
|
515 |
|
|
|
516 |
if sorted_deal['skuBundleId'] in blockedSkuBundlesMobiles:
|
|
|
517 |
if blockedInfoMobiles.has_key(sorted_deal['skuBundleId']):
|
|
|
518 |
blockedInfoMobiles.get(sorted_deal['skuBundleId']).append(sorted_deal)
|
|
|
519 |
else:
|
|
|
520 |
blockedInfoMobiles[sorted_deal['skuBundleId']] = [sorted_deal]
|
|
|
521 |
continue
|
|
|
522 |
|
|
|
523 |
if sortedMapMobiles.get(sorted_deal['skuBundleId']) is None:
|
|
|
524 |
sortedMapMobiles[sorted_deal['skuBundleId']] = {rankMobiles:[sorted_deal]}
|
|
|
525 |
rankMapMobiles[rankMobiles] = (sortedMapMobiles[sorted_deal['skuBundleId']].values())[0]
|
|
|
526 |
rankMobiles = rankMobiles +1
|
|
|
527 |
else:
|
|
|
528 |
for temp_list in sortedMapMobiles.get(sorted_deal['skuBundleId']).itervalues():
|
|
|
529 |
temp_list.append(sorted_deal)
|
|
|
530 |
rankMapMobiles[(sortedMapMobiles.get(sorted_deal['skuBundleId']).keys())[0]] = temp_list
|
|
|
531 |
|
|
|
532 |
|
|
|
533 |
for rank in blockedRanksMobiles:
|
| 17369 |
kshitij.so |
534 |
if blockedInfoMobiles.get((featuredDealsMobiles.get(rank+1)).get('skuBundleId')) is not None:
|
|
|
535 |
rankMapMobiles[rank] = blockedInfoMobiles.get((featuredDealsMobiles.get(rank+1)).get('skuBundleId'))
|
| 17367 |
kshitij.so |
536 |
|
|
|
537 |
|
|
|
538 |
sortedMapTablets = {}
|
|
|
539 |
rankMapTablets = {}
|
|
|
540 |
rankTablets = 0
|
|
|
541 |
|
|
|
542 |
blockedRanksTablets = []
|
|
|
543 |
blockedSkuBundlesTablets = []
|
|
|
544 |
blockedInfoTablets = {}
|
|
|
545 |
|
|
|
546 |
featuredDealsTablets = featuredDeals.get(5)
|
|
|
547 |
|
|
|
548 |
|
|
|
549 |
for k, v in featuredDealsTablets.iteritems():
|
| 17469 |
kshitij.so |
550 |
blockedRanksTablets.append(k-1)
|
|
|
551 |
blockedSkuBundlesTablets.append(v.get('skuBundleId'))
|
|
|
552 |
|
| 17367 |
kshitij.so |
553 |
|
|
|
554 |
for sorted_deal in tablet_deals:
|
|
|
555 |
while(True):
|
|
|
556 |
if rankTablets in blockedRanksTablets:
|
|
|
557 |
rankTablets = rankTablets +1
|
|
|
558 |
else:
|
|
|
559 |
break
|
|
|
560 |
|
|
|
561 |
if sorted_deal['skuBundleId'] in blockedSkuBundlesTablets:
|
|
|
562 |
if blockedInfoTablets.has_key(sorted_deal['skuBundleId']):
|
|
|
563 |
blockedInfoTablets.get(sorted_deal['skuBundleId']).append(sorted_deal)
|
|
|
564 |
else:
|
|
|
565 |
blockedInfoTablets[sorted_deal['skuBundleId']] = [sorted_deal]
|
|
|
566 |
continue
|
|
|
567 |
|
|
|
568 |
if sortedMapTablets.get(sorted_deal['skuBundleId']) is None:
|
|
|
569 |
sortedMapTablets[sorted_deal['skuBundleId']] = {rankTablets:[sorted_deal]}
|
|
|
570 |
rankMapTablets[rankTablets] = (sortedMapTablets[sorted_deal['skuBundleId']].values())[0]
|
|
|
571 |
rankTablets = rankTablets +1
|
|
|
572 |
else:
|
|
|
573 |
for temp_list in sortedMapTablets.get(sorted_deal['skuBundleId']).itervalues():
|
|
|
574 |
temp_list.append(sorted_deal)
|
|
|
575 |
rankMapTablets[(sortedMapTablets.get(sorted_deal['skuBundleId']).keys())[0]] = temp_list
|
|
|
576 |
|
|
|
577 |
for rank in blockedRanksTablets:
|
| 17369 |
kshitij.so |
578 |
if blockedInfoTablets.get((featuredDealsTablets.get(rank+1)).get('skuBundleId')) is not None:
|
|
|
579 |
rankMapTablets[rank] = blockedInfoTablets.get((featuredDealsTablets.get(rank+1)).get('skuBundleId'))
|
| 17469 |
kshitij.so |
580 |
|
| 17367 |
kshitij.so |
581 |
|
| 17469 |
kshitij.so |
582 |
sortedMapAccessories = {}
|
|
|
583 |
rankMapAccessories = {}
|
|
|
584 |
rankAccessories = 0
|
|
|
585 |
|
|
|
586 |
blockedRanksAccessories = []
|
|
|
587 |
blockedSkuBundlesAccessories = []
|
|
|
588 |
blockedInfoAccessories = {}
|
|
|
589 |
|
|
|
590 |
featuredDealsAccessories = featuredDeals.get(6)
|
|
|
591 |
|
|
|
592 |
for k, v in featuredDealsAccessories.iteritems():
|
|
|
593 |
blockedRanksAccessories.append(k-1)
|
|
|
594 |
blockedSkuBundlesAccessories.append(v.get('skuBundleId'))
|
|
|
595 |
|
|
|
596 |
|
|
|
597 |
for sorted_deal in accessories_deals:
|
|
|
598 |
|
|
|
599 |
while(True):
|
|
|
600 |
if rankAccessories in blockedRanksAccessories:
|
|
|
601 |
rankAccessories = rankAccessories +1
|
|
|
602 |
else:
|
|
|
603 |
break
|
|
|
604 |
|
|
|
605 |
if sorted_deal['skuBundleId'] in blockedSkuBundlesAccessories:
|
|
|
606 |
if blockedInfoAccessories.has_key(sorted_deal['skuBundleId']):
|
|
|
607 |
blockedInfoAccessories.get(sorted_deal['skuBundleId']).append(sorted_deal)
|
|
|
608 |
else:
|
|
|
609 |
blockedInfoAccessories[sorted_deal['skuBundleId']] = [sorted_deal]
|
|
|
610 |
continue
|
|
|
611 |
|
|
|
612 |
if sortedMapAccessories.get(sorted_deal['skuBundleId']) is None:
|
|
|
613 |
sortedMapAccessories[sorted_deal['skuBundleId']] = {rankAccessories:[sorted_deal]}
|
|
|
614 |
rankMapAccessories[rankAccessories] = (sortedMapAccessories[sorted_deal['skuBundleId']].values())[0]
|
|
|
615 |
rankAccessories = rankAccessories +1
|
|
|
616 |
else:
|
|
|
617 |
for temp_list in sortedMapAccessories.get(sorted_deal['skuBundleId']).itervalues():
|
|
|
618 |
temp_list.append(sorted_deal)
|
|
|
619 |
rankMapAccessories[(sortedMapAccessories.get(sorted_deal['skuBundleId']).keys())[0]] = temp_list
|
|
|
620 |
|
|
|
621 |
|
|
|
622 |
for rank in blockedRanksAccessories:
|
|
|
623 |
if blockedInfoAccessories.get((featuredDealsAccessories.get(rank+1)).get('skuBundleId')) is not None:
|
|
|
624 |
rankMapAccessories[rank] = blockedInfoAccessories.get((featuredDealsAccessories.get(rank+1)).get('skuBundleId'))
|
|
|
625 |
|
| 19288 |
kshitij.so |
626 |
specialOffer = None
|
|
|
627 |
promoOffer = get_mongo_connection().Catalog.PromoOffer.find_one({'user_id':userId})
|
|
|
628 |
try:
|
|
|
629 |
if promoOffer is not None:
|
|
|
630 |
offer = get_mongo_connection().Catalog.Promotions.find_one({'_id':promoOffer.get('offer_id')})
|
|
|
631 |
if offer is None:
|
|
|
632 |
raise
|
| 19352 |
kshitij.so |
633 |
promo = Promotion(offer.get('_id'),offer.get('offer_name'),offer.get('offer_description') , offer.get('categories_applicable'), offer.get('sub_categories_not_applicable'),
|
| 19331 |
kshitij.so |
634 |
offer.get('startDate'), offer.get('endDate'), promoOffer.get('target1'), promoOffer.get('target1_cash_back_percetage'), promoOffer.get('target2'), promoOffer.get('target2_cash_back_percetage'), promoOffer.get('maxCashBack'),offer.get('url'),
|
| 19350 |
kshitij.so |
635 |
promoOffer.get('pending_order_value'), promoOffer.get('delivered_order_value'), promoOffer.get('last_run_timestamp'))
|
| 17469 |
kshitij.so |
636 |
|
| 19288 |
kshitij.so |
637 |
specialOffer = promo
|
|
|
638 |
except:
|
|
|
639 |
pass
|
|
|
640 |
|
|
|
641 |
|
|
|
642 |
mem_cache_val = {3:mobile_deals, 5:tablet_deals, 6: accessories_deals,"3_rankMap": rankMapMobiles,"5_rankMap": rankMapTablets,"6_rankMap": rankMapAccessories, "specialOffer":specialOffer }
|
| 14037 |
kshitij.so |
643 |
mc.set(str(userId), mem_cache_val)
|
|
|
644 |
|
|
|
645 |
|
| 14531 |
kshitij.so |
646 |
def __populateFeaturedDeals():
|
| 17367 |
kshitij.so |
647 |
print "Populating featured deals....."
|
|
|
648 |
featuredDealsMobiles = {}
|
|
|
649 |
featuredDealsTablets = {}
|
| 17469 |
kshitij.so |
650 |
featuredDealsAccessories = {}
|
| 17618 |
kshitij.so |
651 |
activeFeaturedDeals = get_mongo_connection().Catalog.FeaturedDeals.find({'startDate':{'$lte':to_java_date(datetime.now())},'endDate':{'$gte':to_java_date(datetime.now())}})
|
| 14531 |
kshitij.so |
652 |
for activeFeaturedDeal in activeFeaturedDeals:
|
| 17367 |
kshitij.so |
653 |
deals = get_mongo_connection().Catalog.Deals.find({"skuBundleId":activeFeaturedDeal.get('skuBundleId'),"$or":[{"showDeal":1}, {"prepaidDeal":1}]})
|
|
|
654 |
for deal in deals:
|
|
|
655 |
if deal.get('available_price') <= activeFeaturedDeal.get('thresholdPrice'):
|
| 17469 |
kshitij.so |
656 |
for category_id, rank in activeFeaturedDeal['otherInfo'].iteritems():
|
|
|
657 |
f_deal = {'skuBundleId':activeFeaturedDeal.get('skuBundleId'), 'thresholdPrice':activeFeaturedDeal.get('thresholdPrice'), 'rank':rank,'category_id':int(category_id),'totalPoints':activeFeaturedDeal.get('totalPoints')}
|
|
|
658 |
if f_deal['category_id'] == 3:
|
|
|
659 |
featuredDealsMobiles[rank] = f_deal
|
|
|
660 |
elif f_deal['category_id']==5:
|
|
|
661 |
featuredDealsTablets[rank] = f_deal
|
|
|
662 |
elif f_deal['category_id']==6:
|
|
|
663 |
featuredDealsAccessories[rank] = f_deal
|
| 17367 |
kshitij.so |
664 |
break
|
| 17469 |
kshitij.so |
665 |
|
|
|
666 |
# f_deal = {'skuBundleId':activeFeaturedDeal.get('skuBundleId'), 'thresholdPrice':activeFeaturedDeal.get('thresholdPrice'), 'rank':activeFeaturedDeal.get('rank'),'category_id':activeFeaturedDeal.get('category_id'),'totalPoints':activeFeaturedDeal.get('totalPoints')}
|
|
|
667 |
# if activeFeaturedDeal.get('category_id') == 3:
|
|
|
668 |
# featuredDealsMobiles[activeFeaturedDeal.get('rank')] = f_deal
|
|
|
669 |
# else:
|
|
|
670 |
# featuredDealsTablets[activeFeaturedDeal.get('rank')] = f_deal
|
|
|
671 |
# break
|
|
|
672 |
|
| 17367 |
kshitij.so |
673 |
|
| 17469 |
kshitij.so |
674 |
mc.set("featured_deals", {3:featuredDealsMobiles,5:featuredDealsTablets,6:featuredDealsAccessories}, 600)
|
| 14037 |
kshitij.so |
675 |
|
| 17618 |
kshitij.so |
676 |
def __populateFeaturedDealsForDealObject():
|
|
|
677 |
print "Caching deal objects...."
|
|
|
678 |
featuredDealObjectMobiles = {}
|
|
|
679 |
featuredDealObjectTablets = {}
|
|
|
680 |
featuredDealObjectAccessories = {}
|
|
|
681 |
dealObjects = get_mongo_connection().Catalog.FeaturedDealsDealObject.find({'startDate':{'$lte':to_java_date(datetime.now())},'endDate':{'$gte':to_java_date(datetime.now())}})
|
|
|
682 |
for dealObject in dealObjects:
|
|
|
683 |
d_object = list(get_mongo_connection().Catalog.DealObject.find({'_id':dealObject['_id']}))
|
|
|
684 |
if len(d_object) == 0:
|
|
|
685 |
continue
|
|
|
686 |
for category_id, rank in dealObject['otherInfo'].iteritems():
|
|
|
687 |
d_object[0]['dealObject'] = 1
|
| 19288 |
kshitij.so |
688 |
f_deal = {'rank':rank,'category_id':int(category_id),'object':d_object[0],'offer_id':dealObject.get('offer_id')}
|
| 17618 |
kshitij.so |
689 |
if f_deal['category_id'] == 3:
|
|
|
690 |
featuredDealObjectMobiles[rank] = f_deal
|
|
|
691 |
elif f_deal['category_id']==5:
|
|
|
692 |
featuredDealObjectTablets[rank] = f_deal
|
|
|
693 |
elif f_deal['category_id']==6:
|
|
|
694 |
featuredDealObjectAccessories[rank] = f_deal
|
|
|
695 |
mc.set("featured_deals_deal_object", {3:featuredDealObjectMobiles,5:featuredDealObjectTablets,6:featuredDealObjectAccessories}, 600)
|
| 17619 |
kshitij.so |
696 |
print mc.get('featured_deals_deal_object')
|
| 17618 |
kshitij.so |
697 |
|
| 14791 |
kshitij.so |
698 |
def getNewDeals(userId, category_id, offset, limit, sort, direction, filterData=None):
|
| 17469 |
kshitij.so |
699 |
if mc.get("category_cash_back") is None or not bool(mc.get("category_cash_back")):
|
| 13921 |
kshitij.so |
700 |
populateCashBack()
|
| 14037 |
kshitij.so |
701 |
|
| 16079 |
kshitij.so |
702 |
dealsListMap = []
|
| 14037 |
kshitij.so |
703 |
user_specific_deals = mc.get(str(userId))
|
|
|
704 |
if user_specific_deals is None:
|
|
|
705 |
__populateCache(userId)
|
|
|
706 |
user_specific_deals = mc.get(str(userId))
|
| 14038 |
kshitij.so |
707 |
else:
|
|
|
708 |
print "Getting user deals from cache"
|
| 14037 |
kshitij.so |
709 |
category_specific_deals = user_specific_deals.get(category_id)
|
|
|
710 |
|
| 17367 |
kshitij.so |
711 |
insert_featured_deals = False
|
| 14037 |
kshitij.so |
712 |
if sort is None or direction is None:
|
| 17367 |
kshitij.so |
713 |
insert_featured_deals = True
|
|
|
714 |
rankMap = user_specific_deals.get(str(category_id)+"_rankMap")
|
| 14037 |
kshitij.so |
715 |
else:
|
|
|
716 |
if sort == "bestSellerPoints":
|
|
|
717 |
sorted_deals = sorted(category_specific_deals, key = lambda x: (x['bestSellerPoints'], x['rank'], x['nlcPoints']),reverse=True)
|
|
|
718 |
else:
|
|
|
719 |
if direction == -1:
|
|
|
720 |
rev = True
|
|
|
721 |
else:
|
|
|
722 |
rev = False
|
|
|
723 |
sorted_deals = sorted(category_specific_deals, key = lambda x: (x['available_price']),reverse=rev)
|
|
|
724 |
|
| 14791 |
kshitij.so |
725 |
|
| 17367 |
kshitij.so |
726 |
filtered_deals = []
|
| 17668 |
kshitij.so |
727 |
dataExist = True
|
| 14791 |
kshitij.so |
728 |
if filterData is not None:
|
|
|
729 |
try:
|
| 17669 |
kshitij.so |
730 |
filtered_deals = filterDeals(category_specific_deals, filterData)
|
|
|
731 |
if len(filtered_deals)==0:
|
|
|
732 |
dataExist = False
|
| 14791 |
kshitij.so |
733 |
except:
|
| 16067 |
kshitij.so |
734 |
traceback.print_exc()
|
| 17668 |
kshitij.so |
735 |
if dataExist:
|
| 14791 |
kshitij.so |
736 |
|
| 17668 |
kshitij.so |
737 |
if not insert_featured_deals:
|
|
|
738 |
sortedMap = {}
|
|
|
739 |
rankMap = {}
|
|
|
740 |
rank = 0
|
|
|
741 |
for sorted_deal in sorted_deals:
|
|
|
742 |
|
|
|
743 |
if len(filtered_deals) > 0 and sorted_deal['skuBundleId'] not in filtered_deals:
|
|
|
744 |
continue
|
|
|
745 |
|
|
|
746 |
if sortedMap.get(sorted_deal['skuBundleId']) is None:
|
|
|
747 |
sortedMap[sorted_deal['skuBundleId']] = {rank:[sorted_deal]}
|
|
|
748 |
rankMap[rank] = (sortedMap[sorted_deal['skuBundleId']].values())[0]
|
|
|
749 |
rank = rank +1
|
|
|
750 |
else:
|
|
|
751 |
for temp_list in sortedMap.get(sorted_deal['skuBundleId']).itervalues():
|
|
|
752 |
temp_list.append(sorted_deal)
|
|
|
753 |
rankMap[(sortedMap.get(sorted_deal['skuBundleId']).keys())[0]] = temp_list
|
|
|
754 |
else:
|
|
|
755 |
filterMap = {}
|
|
|
756 |
rank = 0
|
|
|
757 |
if len(filtered_deals) > 0:
|
|
|
758 |
try:
|
|
|
759 |
od = collections.OrderedDict(sorted(rankMap.items()))
|
|
|
760 |
except:
|
|
|
761 |
od = ordereddict.OrderedDict(sorted(rankMap.items()))
|
|
|
762 |
for k, v in od.iteritems():
|
|
|
763 |
if v[0].get('skuBundleId') in filtered_deals:
|
|
|
764 |
filterMap[rank] = v
|
|
|
765 |
rank =rank+1
|
|
|
766 |
rankMap = filterMap
|
|
|
767 |
|
|
|
768 |
rankCounter = offset
|
|
|
769 |
if filterData is None:
|
|
|
770 |
if mc.get("featured_deals_deal_object") is None or not bool(mc.get("featured_deals_deal_object")):
|
|
|
771 |
try:
|
|
|
772 |
__populateFeaturedDealsForDealObject()
|
|
|
773 |
fd_dealObject = mc.get("featured_deals_deal_object")
|
|
|
774 |
except:
|
|
|
775 |
fd_dealObject = {3:{},5:{},6:{}}
|
| 17367 |
kshitij.so |
776 |
else:
|
| 17668 |
kshitij.so |
777 |
fd_dealObject = mc.get("featured_deals_deal_object")
|
|
|
778 |
|
| 17367 |
kshitij.so |
779 |
else:
|
| 17668 |
kshitij.so |
780 |
rankMap = {}
|
| 17618 |
kshitij.so |
781 |
|
| 19288 |
kshitij.so |
782 |
|
|
|
783 |
specialOffer = user_specific_deals.get('specialOffer')
|
|
|
784 |
|
| 17627 |
kshitij.so |
785 |
for dealList in [rankMap.get(k, []) for k in range(offset, offset+limit)]:
|
| 17629 |
kshitij.so |
786 |
if filterData is None:
|
| 17627 |
kshitij.so |
787 |
while(True):
|
|
|
788 |
|
|
|
789 |
rankCounter = rankCounter+1
|
|
|
790 |
if (fd_dealObject.get(category_id).get(rankCounter)) is not None:
|
| 19288 |
kshitij.so |
791 |
if (fd_dealObject.get(category_id).get(rankCounter).get('offer_id') !=0):
|
|
|
792 |
#Check whether user can see offer
|
| 19335 |
amit.gupta |
793 |
if specialOffer is None or specialOffer.endDate > to_java_date(datetime.now()):
|
| 19288 |
kshitij.so |
794 |
continue
|
| 19334 |
kshitij.so |
795 |
deal_object_temp = []
|
|
|
796 |
deal_object_temp.append(fd_dealObject.get(category_id).get(rankCounter).get('object'))
|
|
|
797 |
dealsListMap.append(deal_object_temp)
|
| 17627 |
kshitij.so |
798 |
else:
|
|
|
799 |
break
|
| 17620 |
kshitij.so |
800 |
|
| 16079 |
kshitij.so |
801 |
temp = []
|
| 17367 |
kshitij.so |
802 |
if dealList is None or len(dealList)==0:
|
|
|
803 |
continue
|
| 16067 |
kshitij.so |
804 |
for d in dealList:
|
|
|
805 |
item = list(get_mongo_connection().Catalog.MasterData.find({'_id':d['_id']}))
|
| 16320 |
kshitij.so |
806 |
if len(item) ==0:
|
|
|
807 |
continue
|
| 16079 |
kshitij.so |
808 |
item[0]['persPoints'] = d['persPoints']
|
|
|
809 |
if d['dealType'] == 1 and d['source_id'] ==1:
|
| 16511 |
kshitij.so |
810 |
try:
|
|
|
811 |
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())}}))
|
|
|
812 |
item[0]['marketPlaceUrl'] = manualDeal[0]['dealUrl'].strip()
|
|
|
813 |
except:
|
|
|
814 |
pass
|
| 16079 |
kshitij.so |
815 |
elif d['source_id'] ==3:
|
|
|
816 |
item[0]['marketPlaceUrl'] = item[0]['marketPlaceUrl']+'?supc='+item[0].get('identifier')
|
|
|
817 |
else:
|
|
|
818 |
pass
|
|
|
819 |
try:
|
|
|
820 |
cashBack = getCashBack(item[0]['_id'], item[0]['source_id'], item[0]['category_id'])
|
|
|
821 |
if not cashBack or cashBack.get('cash_back_status')!=1:
|
| 14037 |
kshitij.so |
822 |
item[0]['cash_back_type'] = 0
|
|
|
823 |
item[0]['cash_back'] = 0
|
| 16079 |
kshitij.so |
824 |
else:
|
| 17180 |
kshitij.so |
825 |
if cashBack.get('maxCashBack') is not None:
|
|
|
826 |
|
|
|
827 |
if cashBack.get('cash_back_type') ==1 and (float(cashBack.get('cash_back'))*item[0]['available_price'])/100 > cashBack.get('maxCashBack'):
|
|
|
828 |
cashBack['cash_back_type'] = 2
|
|
|
829 |
cashBack['cash_back'] = cashBack['maxCashBack']
|
|
|
830 |
elif cashBack.get('cash_back_type') ==2 and cashBack.get('cash_back') > cashBack.get('maxCashBack'):
|
|
|
831 |
cashBack['cash_back'] = cashBack['maxCashBack']
|
|
|
832 |
|
| 16079 |
kshitij.so |
833 |
item[0]['cash_back_type'] = int(cashBack['cash_back_type'])
|
|
|
834 |
item[0]['cash_back'] = cashBack['cash_back']
|
|
|
835 |
except:
|
|
|
836 |
print "Error in adding cashback to deals"
|
|
|
837 |
item[0]['cash_back_type'] = 0
|
|
|
838 |
item[0]['cash_back'] = 0
|
| 16252 |
kshitij.so |
839 |
try:
|
|
|
840 |
item[0]['dp'] = d['dp']
|
|
|
841 |
item[0]['showDp'] = d['showDp']
|
|
|
842 |
except:
|
|
|
843 |
item[0]['dp'] = 0.0
|
|
|
844 |
item[0]['showDp'] = 0
|
| 16483 |
kshitij.so |
845 |
try:
|
|
|
846 |
item[0]['thumbnail'] = item[0]['thumbnail'].strip()
|
|
|
847 |
except:
|
| 17115 |
manish.sha |
848 |
pass
|
| 17603 |
kshitij.so |
849 |
|
|
|
850 |
try:
|
|
|
851 |
if item[0]['showVideo']==0:
|
|
|
852 |
item[0]['videoLink'] =""
|
|
|
853 |
except:
|
|
|
854 |
item[0]['videoLink'] =""
|
| 17937 |
kshitij.so |
855 |
try:
|
|
|
856 |
if item[0]['quantity'] >1:
|
|
|
857 |
ppq = float(item[0]['available_price'])/item[0]['quantity']
|
|
|
858 |
|
|
|
859 |
if ppq == round(ppq):
|
|
|
860 |
item[0]['ppq'] = int(ppq)
|
|
|
861 |
else:
|
|
|
862 |
item[0]['ppq'] = round(ppq,2)
|
|
|
863 |
else:
|
|
|
864 |
item[0]['ppq'] = 0
|
|
|
865 |
except:
|
|
|
866 |
item[0]['ppq'] = 0
|
| 17627 |
kshitij.so |
867 |
if filterData is None:
|
| 17679 |
kshitij.so |
868 |
if item[0]['category_id']!=6:
|
|
|
869 |
try:
|
| 18830 |
kshitij.so |
870 |
item[0]['filterLinkBrand'] = '/category/'+str(int(item[0]['category_id']))+'?searchFor='+urllib.quote(item[0]['brand'])+'&filter=brand&brands='+str(int(item[0]['brand_id']))
|
|
|
871 |
item[0]['filterTextBrand'] = (item[0]['brand'])
|
| 17679 |
kshitij.so |
872 |
except:
|
| 18830 |
kshitij.so |
873 |
pass
|
| 17679 |
kshitij.so |
874 |
else:
|
|
|
875 |
try:
|
| 17756 |
kshitij.so |
876 |
if item[0]['subCategory']=='' or item[0]['subCategory'] is None or item[0]['subCategoryId']==0:
|
| 17679 |
kshitij.so |
877 |
raise
|
| 18830 |
kshitij.so |
878 |
item[0]['filterLinkSubCategory'] = '/category/'+str(int(item[0]['category_id']))+'?searchFor='+urllib.quote(item[0]['subCategory'])+'&filter=subcategory&subcategories='+str(int(item[0]['subCategoryId']))
|
|
|
879 |
item[0]['filterTextSubCategory'] = (item[0]['subCategory'])
|
|
|
880 |
item[0]['filterLinkBrand'] = '/category/'+str(int(item[0]['category_id']))+'?searchFor='+urllib.quote(item[0]['brand'])+'&filter=brand&brands='+str(int(item[0]['brand_id']))
|
|
|
881 |
item[0]['filterTextBrand'] = (item[0]['brand'])
|
| 17679 |
kshitij.so |
882 |
except:
|
| 18830 |
kshitij.so |
883 |
pass
|
| 17771 |
kshitij.so |
884 |
try:
|
|
|
885 |
if item[0]['source_id']==4:
|
|
|
886 |
item_availability_info = mc.get("item_availability_"+str(item[0]['identifier']).strip())
|
|
|
887 |
if item_availability_info is None or len(item_availability_info)==0:
|
|
|
888 |
item[0]['availabilityInfo'] = [{}]
|
|
|
889 |
else:
|
|
|
890 |
item[0]['availabilityInfo'] = item_availability_info
|
|
|
891 |
except:
|
|
|
892 |
item[0]['availabilityInfo'] = [{}]
|
| 19193 |
kshitij.so |
893 |
|
|
|
894 |
if item[0]['source_id']==4:
|
|
|
895 |
for av_info in item[0]['availabilityInfo']:
|
|
|
896 |
if not av_info:
|
|
|
897 |
continue
|
|
|
898 |
av_info['cash_back'] = item[0]['cash_back']
|
|
|
899 |
av_info['cash_back_type'] = item[0]['cash_back_type']
|
|
|
900 |
netPriceAfterCashBack = av_info['sellingPrice']
|
| 19199 |
kshitij.so |
901 |
if av_info['cash_back_type'] ==1:
|
| 19207 |
kshitij.so |
902 |
netPriceAfterCashBack = av_info['sellingPrice'] - math.floor(float(av_info['sellingPrice'])*av_info['cash_back']/100)
|
| 19199 |
kshitij.so |
903 |
elif av_info['cash_back_type'] ==2:
|
| 19207 |
kshitij.so |
904 |
netPriceAfterCashBack = av_info['sellingPrice'] - math.floor(av_info['cash_back'])
|
| 19193 |
kshitij.so |
905 |
else:
|
|
|
906 |
pass
|
|
|
907 |
av_info['netPriceAfterCashBack'] = netPriceAfterCashBack
|
|
|
908 |
|
|
|
909 |
#item[0]['netPriceAfterCashBack'] = d['netPriceAfterCashBack']
|
|
|
910 |
|
|
|
911 |
if item[0]['source_id'] != SOURCE_MAP.get("PAYTM.COM"):
|
|
|
912 |
if item[0]['codAvailable'] ==1:
|
|
|
913 |
paytmPrice = item[0]['available_price']
|
|
|
914 |
else:
|
|
|
915 |
paytmPrice = item[0]['gross_price']
|
|
|
916 |
|
|
|
917 |
if item[0]['cash_back_type'] ==1:
|
| 19207 |
kshitij.so |
918 |
item[0]['netPriceAfterCashBack'] = paytmPrice - math.floor(float(paytmPrice)*item[0]['cash_back']/100)
|
| 19193 |
kshitij.so |
919 |
elif item[0]['cash_back_type'] ==2:
|
| 19207 |
kshitij.so |
920 |
item[0]['netPriceAfterCashBack'] = paytmPrice - math.floor(item[0]['cash_back'])
|
| 19193 |
kshitij.so |
921 |
else:
|
|
|
922 |
item[0]['netPriceAfterCashBack'] = paytmPrice
|
|
|
923 |
|
|
|
924 |
else:
|
|
|
925 |
if item[0]['cash_back_type'] ==1:
|
| 19207 |
kshitij.so |
926 |
item[0]['netPriceAfterCashBack'] = item[0]['available_price'] - math.floor(float(item[0]['available_price'])*item[0]['cash_back']/100)
|
| 19193 |
kshitij.so |
927 |
elif item[0]['cash_back_type'] ==2:
|
| 19207 |
kshitij.so |
928 |
item[0]['netPriceAfterCashBack'] = item[0]['available_price'] - math.floor(item[0]['cash_back'])
|
| 19193 |
kshitij.so |
929 |
else:
|
|
|
930 |
item[0]['netPriceAfterCashBack'] = item[0]['available_price']
|
|
|
931 |
|
| 19320 |
kshitij.so |
932 |
# if specialOffer is not None and item[0]['source_id']==4:
|
|
|
933 |
# if item[0]['category_id'] in specialOffer.categories_applicable and item[0]['subCategoryId'] not in specialOffer.sub_categories_not_applicable:
|
|
|
934 |
# item[0]['specialOffer'] = specialOffer.__dict__
|
|
|
935 |
# else:
|
|
|
936 |
# item[0]['specialOffer'] = {}
|
| 19288 |
kshitij.so |
937 |
|
| 16079 |
kshitij.so |
938 |
temp.append(item[0])
|
| 16125 |
kshitij.so |
939 |
if len(temp) > 1:
|
| 16126 |
kshitij.so |
940 |
temp = sorted(temp, key = lambda x: (x['available_price']),reverse=False)
|
| 16079 |
kshitij.so |
941 |
dealsListMap.append(temp)
|
|
|
942 |
return dealsListMap
|
| 14037 |
kshitij.so |
943 |
|
| 14791 |
kshitij.so |
944 |
def filterDeals(deals, filterData):
|
| 17658 |
kshitij.so |
945 |
print "Filter data ", filterData
|
| 14791 |
kshitij.so |
946 |
brandsFiltered = []
|
| 17657 |
kshitij.so |
947 |
subCategoryFiltered = []
|
| 14791 |
kshitij.so |
948 |
filterArray = filterData.split('|')
|
|
|
949 |
for data in filterArray:
|
|
|
950 |
try:
|
|
|
951 |
filter, info = data.split(':')
|
|
|
952 |
except Exception as ex:
|
|
|
953 |
traceback.print_exc()
|
|
|
954 |
continue
|
| 17657 |
kshitij.so |
955 |
if filter == 'brandFilter':
|
| 14791 |
kshitij.so |
956 |
toFilter = info.split('^')
|
|
|
957 |
print "brand filter ",toFilter
|
|
|
958 |
for deal in deals:
|
| 15151 |
kshitij.so |
959 |
if str(int(deal['brand_id'])) in toFilter:
|
| 14791 |
kshitij.so |
960 |
brandsFiltered.append(deal)
|
| 17657 |
kshitij.so |
961 |
elif filter =='subCategoryFilter':
|
|
|
962 |
toFilter = info.split('^')
|
|
|
963 |
print "Sub Category filter ",toFilter
|
|
|
964 |
for deal in deals:
|
|
|
965 |
if str(int(deal['subCategoryId'])) in toFilter:
|
|
|
966 |
subCategoryFiltered.append(deal)
|
| 17668 |
kshitij.so |
967 |
print "No of brand filtered ",len(brandsFiltered)
|
|
|
968 |
print "No of sub-cat filtered ",len(subCategoryFiltered)
|
| 17657 |
kshitij.so |
969 |
if len(subCategoryFiltered) == 0:
|
| 17367 |
kshitij.so |
970 |
return [trend['skuBundleId'] for trend in brandsFiltered]
|
| 17663 |
kshitij.so |
971 |
elif len(brandsFiltered) == 0:
|
|
|
972 |
return [trend['skuBundleId'] for trend in subCategoryFiltered]
|
| 17669 |
kshitij.so |
973 |
return [i['skuBundleId'] for i in subCategoryFiltered for j in brandsFiltered if i['_id']==j['_id']]
|
| 14791 |
kshitij.so |
974 |
|
|
|
975 |
|
| 14037 |
kshitij.so |
976 |
def getDeals(userId, category_id, offset, limit, sort, direction):
|
| 17469 |
kshitij.so |
977 |
if mc.get("category_cash_back") is None or not bool(mc.get("category_cash_back")):
|
| 14037 |
kshitij.so |
978 |
populateCashBack()
|
|
|
979 |
rank = 1
|
| 13771 |
kshitij.so |
980 |
deals = {}
|
| 13910 |
kshitij.so |
981 |
outer_query = []
|
|
|
982 |
outer_query.append({"showDeal":1})
|
|
|
983 |
query = {}
|
|
|
984 |
query['$gt'] = 0
|
|
|
985 |
outer_query.append({'totalPoints':query})
|
|
|
986 |
if category_id in (3,5):
|
|
|
987 |
outer_query.append({'category_id':category_id})
|
| 13803 |
kshitij.so |
988 |
if sort is None or direction is None:
|
|
|
989 |
direct = -1
|
| 13910 |
kshitij.so |
990 |
print outer_query
|
|
|
991 |
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 |
992 |
else:
|
| 13910 |
kshitij.so |
993 |
print outer_query
|
| 13803 |
kshitij.so |
994 |
direct = direction
|
| 13910 |
kshitij.so |
995 |
if sort == "bestSellerPoints":
|
|
|
996 |
print "yes,sorting by bestSellerPoints"
|
|
|
997 |
data = list(get_mongo_connection().Catalog.Deals.find({"$and":outer_query}).sort([('bestSellerPoints',direct),('rank',direct),('nlcPoints',direct)]).skip(offset).limit(limit))
|
|
|
998 |
else:
|
|
|
999 |
data = list(get_mongo_connection().Catalog.Deals.find({"$and":outer_query}).sort([(sort,direct)]).skip(offset).limit(limit))
|
| 13771 |
kshitij.so |
1000 |
for d in data:
|
|
|
1001 |
item = list(get_mongo_connection().Catalog.MasterData.find({'_id':d['_id']}))
|
|
|
1002 |
if not deals.has_key(item[0]['identifier']):
|
| 13921 |
kshitij.so |
1003 |
item[0]['dealRank'] = rank
|
|
|
1004 |
try:
|
| 14761 |
kshitij.so |
1005 |
cashBack = getCashBack(item[0]['_id'], item[0]['source_id'], item[0]['category_id'])
|
| 13921 |
kshitij.so |
1006 |
if not cashBack or cashBack.get('cash_back_status')!=1:
|
| 13928 |
kshitij.so |
1007 |
item[0]['cash_back_type'] = 0
|
|
|
1008 |
item[0]['cash_back'] = 0
|
| 13921 |
kshitij.so |
1009 |
else:
|
| 14766 |
kshitij.so |
1010 |
item[0]['cash_back_type'] = int(cashBack['cash_back_type'])
|
| 13928 |
kshitij.so |
1011 |
item[0]['cash_back'] = cashBack['cash_back']
|
| 13921 |
kshitij.so |
1012 |
except:
|
|
|
1013 |
print "Error in adding cashback to deals"
|
| 13928 |
kshitij.so |
1014 |
item[0]['cash_back_type'] = 0
|
|
|
1015 |
item[0]['cash_back'] = 0
|
| 13771 |
kshitij.so |
1016 |
deals[item[0]['identifier']] = item[0]
|
| 13921 |
kshitij.so |
1017 |
|
| 13771 |
kshitij.so |
1018 |
rank +=1
|
| 13785 |
kshitij.so |
1019 |
return sorted(deals.values(), key=itemgetter('dealRank'))
|
|
|
1020 |
|
| 16222 |
kshitij.so |
1021 |
def getItem(skuId,showDp=None):
|
| 16224 |
kshitij.so |
1022 |
temp = []
|
| 17469 |
kshitij.so |
1023 |
if mc.get("category_cash_back") is None or not bool(mc.get("category_cash_back")):
|
| 14113 |
kshitij.so |
1024 |
populateCashBack()
|
| 13795 |
kshitij.so |
1025 |
try:
|
| 16222 |
kshitij.so |
1026 |
skuData = get_mongo_connection().Catalog.MasterData.find_one({'_id':int(skuId)})
|
|
|
1027 |
if skuData is None:
|
|
|
1028 |
raise
|
|
|
1029 |
try:
|
|
|
1030 |
cashBack = getCashBack(skuData['_id'], skuData['source_id'], skuData['category_id'])
|
|
|
1031 |
if not cashBack or cashBack.get('cash_back_status')!=1:
|
|
|
1032 |
skuData['cash_back_type'] = 0
|
|
|
1033 |
skuData['cash_back'] = 0
|
|
|
1034 |
else:
|
|
|
1035 |
skuData['cash_back_type'] = cashBack['cash_back_type']
|
|
|
1036 |
skuData['cash_back'] = cashBack['cash_back']
|
|
|
1037 |
except:
|
|
|
1038 |
print "Error in adding cashback to deals"
|
|
|
1039 |
skuData['cash_back_type'] = 0
|
|
|
1040 |
skuData['cash_back'] = 0
|
|
|
1041 |
skuData['in_stock'] = int(skuData['in_stock'])
|
|
|
1042 |
skuData['is_shortage'] = int(skuData['is_shortage'])
|
|
|
1043 |
skuData['category_id'] = int(skuData['category_id'])
|
| 17607 |
kshitij.so |
1044 |
skuData['subCategoryId'] = int(skuData['subCategoryId'])
|
| 16222 |
kshitij.so |
1045 |
skuData['status'] = int(skuData['status'])
|
| 16483 |
kshitij.so |
1046 |
try:
|
|
|
1047 |
skuData['thumbnail'] = skuData['thumbnail'].strip()
|
|
|
1048 |
except:
|
|
|
1049 |
pass
|
| 16222 |
kshitij.so |
1050 |
if showDp is not None:
|
|
|
1051 |
dealerPrice = get_mongo_connection().Catalog.SkuDealerPrices.find_one({'skuBundleId':skuData['skuBundleId']})
|
|
|
1052 |
skuData['dp'] = 0.0
|
|
|
1053 |
skuData['showDp'] = 0
|
|
|
1054 |
if dealerPrice is not None:
|
|
|
1055 |
skuData['dp'] = dealerPrice['dp']
|
|
|
1056 |
skuData['showDp'] = dealerPrice['showDp']
|
| 16224 |
kshitij.so |
1057 |
temp.append(skuData)
|
|
|
1058 |
return temp
|
| 13795 |
kshitij.so |
1059 |
except:
|
| 16224 |
kshitij.so |
1060 |
return []
|
| 13836 |
kshitij.so |
1061 |
|
| 14761 |
kshitij.so |
1062 |
def getCashBack(skuId, source_id, category_id):
|
| 17469 |
kshitij.so |
1063 |
if mc.get("category_cash_back") is None or not bool(mc.get("category_cash_back")):
|
| 14761 |
kshitij.so |
1064 |
populateCashBack()
|
|
|
1065 |
itemCashBackMap = mc.get("item_cash_back")
|
| 13921 |
kshitij.so |
1066 |
itemCashBack = itemCashBackMap.get(skuId)
|
|
|
1067 |
if itemCashBack is not None:
|
|
|
1068 |
return itemCashBack
|
| 14761 |
kshitij.so |
1069 |
cashBackMap = mc.get("category_cash_back")
|
| 13921 |
kshitij.so |
1070 |
sourceCashBack = cashBackMap.get(source_id)
|
|
|
1071 |
if sourceCashBack is not None and len(sourceCashBack) > 0:
|
|
|
1072 |
for cashBack in sourceCashBack:
|
|
|
1073 |
if cashBack.get(category_id) is None:
|
|
|
1074 |
continue
|
|
|
1075 |
else:
|
|
|
1076 |
return cashBack.get(category_id)
|
|
|
1077 |
else:
|
|
|
1078 |
return {}
|
| 16560 |
amit.gupta |
1079 |
|
|
|
1080 |
def getBundleBySourceSku(source_id, identifier):
|
| 17035 |
kshitij.so |
1081 |
if source_id in (1,2,4,5,6,7):
|
| 16560 |
amit.gupta |
1082 |
skuData = list(get_mongo_connection().Catalog.MasterData.find({'identifier':identifier.strip(), 'source_id':source_id}))
|
|
|
1083 |
elif source_id == 3:
|
|
|
1084 |
skuData = list(get_mongo_connection().Catalog.MasterData.find({'secondaryIdentifier':identifier.strip(), 'source_id':source_id}))
|
|
|
1085 |
else:
|
|
|
1086 |
return {}
|
|
|
1087 |
|
|
|
1088 |
if not skuData:
|
|
|
1089 |
return {}
|
|
|
1090 |
else:
|
| 16564 |
amit.gupta |
1091 |
bundleId = skuData[0]["skuBundleId"]
|
| 17035 |
kshitij.so |
1092 |
itemIds = list(get_mongo_connection().Catalog.MasterData.find({'skuBundleId':bundleId, 'in_stock':1, 'source_id':{"$in":[1,2,3,5,6,7]}},
|
| 16580 |
amit.gupta |
1093 |
{"source_id":1, "available_price":1, "marketPlaceUrl":1, "gross_price":1, "codAvailable":1, "source_product_name":1, "offer":1, "coupon":1}))
|
| 16579 |
amit.gupta |
1094 |
return {'products':itemIds}
|
| 16560 |
amit.gupta |
1095 |
|
|
|
1096 |
|
| 13921 |
kshitij.so |
1097 |
|
| 15129 |
kshitij.so |
1098 |
def getDealRank(identifier, source_id, userId):
|
| 17035 |
kshitij.so |
1099 |
if source_id in (1,2,4,5,6,7):
|
| 15129 |
kshitij.so |
1100 |
skuData = list(get_mongo_connection().Catalog.MasterData.find({'identifier':identifier.strip(), 'source_id':source_id}))
|
|
|
1101 |
elif source_id == 3:
|
|
|
1102 |
skuData = list(get_mongo_connection().Catalog.MasterData.find({'secondaryIdentifier':identifier.strip(), 'source_id':source_id}))
|
|
|
1103 |
else:
|
| 16282 |
amit.gupta |
1104 |
return {'rank':0, 'description':'Source not valid','maxNlc':None, 'minNlc':None,'status':None,'dp':None}
|
| 15349 |
kshitij.so |
1105 |
if len(skuData) == 0:
|
| 16282 |
amit.gupta |
1106 |
return {'rank':0, 'description':'No matching product identifier found','maxNlc':None, 'minNlc':None,'status':None,'dp':None}
|
| 15129 |
kshitij.so |
1107 |
user_specific_deals = mc.get(str(userId))
|
|
|
1108 |
if user_specific_deals is None:
|
|
|
1109 |
__populateCache(userId)
|
|
|
1110 |
user_specific_deals = mc.get(str(userId))
|
|
|
1111 |
else:
|
|
|
1112 |
print "Getting user deals from cache"
|
|
|
1113 |
category_id = skuData[0]['category_id']
|
|
|
1114 |
category_specific_deals = user_specific_deals.get(category_id)
|
| 16280 |
kshitij.so |
1115 |
|
|
|
1116 |
dealsData = get_mongo_connection().Catalog.Deals.find_one({'skuBundleId':skuData[0]['skuBundleId']})
|
|
|
1117 |
if dealsData is None:
|
|
|
1118 |
dealsData = {}
|
|
|
1119 |
|
| 15129 |
kshitij.so |
1120 |
if category_specific_deals is None or len(category_specific_deals) ==0:
|
| 16280 |
kshitij.so |
1121 |
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 |
1122 |
sorted_deals = sorted(category_specific_deals, key = lambda x: (x['persPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
|
| 16168 |
kshitij.so |
1123 |
sortedMap = {}
|
|
|
1124 |
rankMap = {}
|
|
|
1125 |
rank = 0
|
| 15129 |
kshitij.so |
1126 |
for sorted_deal in sorted_deals:
|
| 16168 |
kshitij.so |
1127 |
if sortedMap.get(sorted_deal['skuBundleId']) is None:
|
|
|
1128 |
sortedMap[sorted_deal['skuBundleId']] = {rank:[sorted_deal]}
|
|
|
1129 |
rankMap[rank] = (sortedMap[sorted_deal['skuBundleId']].values())[0]
|
|
|
1130 |
rank = rank +1
|
|
|
1131 |
else:
|
|
|
1132 |
for temp_list in sortedMap.get(sorted_deal['skuBundleId']).itervalues():
|
|
|
1133 |
temp_list.append(sorted_deal)
|
|
|
1134 |
rankMap[(sortedMap.get(sorted_deal['skuBundleId']).keys())[0]] = temp_list
|
|
|
1135 |
|
| 16187 |
kshitij.so |
1136 |
for dealRank ,dealList in rankMap.iteritems():
|
| 16168 |
kshitij.so |
1137 |
for d in dealList:
|
| 16186 |
kshitij.so |
1138 |
if d['skuBundleId'] == skuData[0]['skuBundleId']:
|
| 16280 |
kshitij.so |
1139 |
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 |
1140 |
|
| 16280 |
kshitij.so |
1141 |
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 |
1142 |
|
|
|
1143 |
|
| 13836 |
kshitij.so |
1144 |
def getCashBackDetails(identifier, source_id):
|
| 17469 |
kshitij.so |
1145 |
if mc.get("category_cash_back") is None or not bool(mc.get("category_cash_back")):
|
| 13921 |
kshitij.so |
1146 |
populateCashBack()
|
| 13771 |
kshitij.so |
1147 |
|
| 17035 |
kshitij.so |
1148 |
if source_id in (1,2,4,5,6,7):
|
| 13839 |
kshitij.so |
1149 |
skuData = list(get_mongo_connection().Catalog.MasterData.find({'identifier':identifier.strip(), 'source_id':source_id}))
|
| 13840 |
kshitij.so |
1150 |
elif source_id == 3:
|
| 13839 |
kshitij.so |
1151 |
skuData = list(get_mongo_connection().Catalog.MasterData.find({'secondaryIdentifier':identifier.strip(), 'source_id':source_id}))
|
| 13840 |
kshitij.so |
1152 |
else:
|
|
|
1153 |
return {}
|
| 13836 |
kshitij.so |
1154 |
if len(skuData) > 0:
|
| 14761 |
kshitij.so |
1155 |
itemCashBackMap = mc.get("item_cash_back")
|
| 13921 |
kshitij.so |
1156 |
itemCashBack = itemCashBackMap.get(skuData[0]['_id'])
|
|
|
1157 |
if itemCashBack is not None:
|
|
|
1158 |
return itemCashBack
|
| 14761 |
kshitij.so |
1159 |
cashBackMap = mc.get("category_cash_back")
|
| 13921 |
kshitij.so |
1160 |
sourceCashBack = cashBackMap.get(source_id)
|
|
|
1161 |
if sourceCashBack is not None and len(sourceCashBack) > 0:
|
|
|
1162 |
for cashBack in sourceCashBack:
|
|
|
1163 |
if cashBack.get(skuData[0]['category_id']) is None:
|
|
|
1164 |
continue
|
|
|
1165 |
else:
|
|
|
1166 |
return cashBack.get(skuData[0]['category_id'])
|
| 13836 |
kshitij.so |
1167 |
else:
|
|
|
1168 |
return {}
|
|
|
1169 |
else:
|
|
|
1170 |
return {}
|
| 13986 |
amit.gupta |
1171 |
|
| 14398 |
amit.gupta |
1172 |
def getImgSrc(identifier, source_id):
|
|
|
1173 |
skuData = None
|
| 17035 |
kshitij.so |
1174 |
if source_id in (1,2,4,5,6,7):
|
| 14414 |
amit.gupta |
1175 |
skuData = get_mongo_connection().Catalog.MasterData.find_one({'identifier':identifier.strip(), 'source_id':source_id})
|
| 14398 |
amit.gupta |
1176 |
elif source_id == 3:
|
| 14414 |
amit.gupta |
1177 |
skuData = get_mongo_connection().Catalog.MasterData.find_one({'secondaryIdentifier':identifier.strip(), 'source_id':source_id})
|
| 14398 |
amit.gupta |
1178 |
if skuData is None:
|
|
|
1179 |
return {}
|
|
|
1180 |
else:
|
| 16483 |
kshitij.so |
1181 |
try:
|
|
|
1182 |
return {'thumbnail':skuData.get('thumbnail').strip()}
|
|
|
1183 |
except:
|
|
|
1184 |
return {'thumbnail':skuData.get('thumbnail')}
|
| 13986 |
amit.gupta |
1185 |
|
|
|
1186 |
def next_weekday(d, weekday):
|
|
|
1187 |
days_ahead = weekday - d.weekday()
|
|
|
1188 |
if days_ahead <= 0: # Target day already happened this week
|
|
|
1189 |
days_ahead += 7
|
|
|
1190 |
return d + timedelta(days_ahead)
|
|
|
1191 |
|
| 13771 |
kshitij.so |
1192 |
|
| 13970 |
kshitij.so |
1193 |
def getAllDealerPrices(offset, limit):
|
|
|
1194 |
data = []
|
|
|
1195 |
collection = get_mongo_connection().Catalog.SkuDealerPrices
|
|
|
1196 |
cursor = collection.find().skip(offset).limit(limit)
|
|
|
1197 |
for val in cursor:
|
| 15853 |
kshitij.so |
1198 |
master = get_mongo_connection().Catalog.MasterData.find_one({'skuBundleId':val['skuBundleId']})
|
|
|
1199 |
if master is not None:
|
|
|
1200 |
val['brand'] = master['brand']
|
|
|
1201 |
val['source_product_name'] = master['source_product_name']
|
| 13970 |
kshitij.so |
1202 |
else:
|
|
|
1203 |
val['brand'] = ""
|
|
|
1204 |
val['source_product_name'] = ""
|
| 16231 |
kshitij.so |
1205 |
val['showDp'] = int(val['showDp'])
|
| 13970 |
kshitij.so |
1206 |
data.append(val)
|
|
|
1207 |
return data
|
|
|
1208 |
|
| 15853 |
kshitij.so |
1209 |
def addSkuDealerPrice(data):
|
|
|
1210 |
collection = get_mongo_connection().Catalog.SkuDealerPrices
|
|
|
1211 |
cursor = collection.find_one({"skuBundleId":data['skuBundleId']})
|
|
|
1212 |
if cursor is not None:
|
|
|
1213 |
return {0:"BundleId information already present."}
|
| 13970 |
kshitij.so |
1214 |
else:
|
| 15853 |
kshitij.so |
1215 |
collection.insert(data)
|
|
|
1216 |
get_mongo_connection().Catalog.MasterData.update({'skuBundleId':data['skuBundleId']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
| 13970 |
kshitij.so |
1217 |
return {1:"Data added successfully"}
|
|
|
1218 |
|
|
|
1219 |
def updateSkuDealerPrice(data, _id):
|
|
|
1220 |
try:
|
|
|
1221 |
collection = get_mongo_connection().Catalog.SkuDealerPrices
|
|
|
1222 |
collection.update({'_id':ObjectId(_id)},{"$set":{'dp':data['dp']}},upsert=False, multi = False)
|
| 15853 |
kshitij.so |
1223 |
get_mongo_connection().Catalog.MasterData.update({'skuBundleId':data['skuBundleId']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
| 13970 |
kshitij.so |
1224 |
return {1:"Data updated successfully"}
|
|
|
1225 |
except:
|
|
|
1226 |
return {0:"Data not updated."}
|
|
|
1227 |
|
|
|
1228 |
def updateExceptionalNlc(data, _id):
|
|
|
1229 |
try:
|
|
|
1230 |
collection = get_mongo_connection().Catalog.ExceptionalNlc
|
|
|
1231 |
collection.update({'_id':ObjectId(_id)},{"$set":{'maxNlc':data['maxNlc'], 'minNlc':data['minNlc'], 'overrideNlc':data['overrideNlc']}},upsert=False, multi = False)
|
| 15853 |
kshitij.so |
1232 |
get_mongo_connection().Catalog.MasterData.update({'skuBundleId':data['skuBundleId']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
| 13970 |
kshitij.so |
1233 |
return {1:"Data updated successfully"}
|
|
|
1234 |
except:
|
|
|
1235 |
return {0:"Data not updated."}
|
|
|
1236 |
|
| 14041 |
kshitij.so |
1237 |
def resetCache(userId):
|
| 14043 |
kshitij.so |
1238 |
try:
|
|
|
1239 |
mc.delete(userId)
|
|
|
1240 |
return {1:'Cache cleared.'}
|
|
|
1241 |
except:
|
|
|
1242 |
return {0:'Unable to clear cache.'}
|
|
|
1243 |
|
| 15853 |
kshitij.so |
1244 |
def updateCollection(data):
|
|
|
1245 |
try:
|
|
|
1246 |
collection = get_mongo_connection().Catalog[data['class']]
|
|
|
1247 |
class_name = data.pop('class')
|
|
|
1248 |
_id = data.pop('oid')
|
|
|
1249 |
result = collection.update({'_id':ObjectId(_id)},{"$set":data},upsert=False, multi = False)
|
|
|
1250 |
if class_name != "Notifications":
|
|
|
1251 |
record = list(collection.find({'_id':ObjectId(_id)}))
|
|
|
1252 |
if class_name !="CategoryDiscount":
|
|
|
1253 |
if record[0].has_key('sku'):
|
|
|
1254 |
field = '_id'
|
|
|
1255 |
val = record[0]['sku']
|
| 14852 |
kshitij.so |
1256 |
else:
|
| 15853 |
kshitij.so |
1257 |
field = 'skuBundleId'
|
|
|
1258 |
val = record[0]['skuBundleId']
|
|
|
1259 |
get_mongo_connection().Catalog.MasterData.update({field:val},{"$set":{'updatedOn':to_java_date(datetime.now())}},upsert=False, multi = True)
|
|
|
1260 |
else:
|
|
|
1261 |
get_mongo_connection().Catalog.MasterData.update({'brand':re.compile(record[0]['brand'], re.IGNORECASE),'category_id':record[0]['category_id']}, \
|
|
|
1262 |
{"$set":{'updatedOn':to_java_date(datetime.now())}},upsert=False,multi=True)
|
| 16233 |
kshitij.so |
1263 |
if class_name =='SkuDealerPrices':
|
| 16237 |
kshitij.so |
1264 |
get_mongo_connection().Catalog.Deals.update({'skuBundleId':val},{"$set":data},upsert=False, multi=True)
|
| 15853 |
kshitij.so |
1265 |
return {1:"Data updated successfully"}
|
|
|
1266 |
except Exception as e:
|
|
|
1267 |
print e
|
|
|
1268 |
return {0:"Data not updated."}
|
| 14575 |
kshitij.so |
1269 |
|
| 14076 |
kshitij.so |
1270 |
|
| 14553 |
kshitij.so |
1271 |
def addNegativeDeals(data, multi):
|
|
|
1272 |
if multi !=1:
|
|
|
1273 |
collection = get_mongo_connection().Catalog.NegativeDeals
|
|
|
1274 |
cursor = collection.find({"sku":data['sku']})
|
|
|
1275 |
if cursor.count() > 0:
|
|
|
1276 |
return {0:"Sku information already present."}
|
|
|
1277 |
else:
|
|
|
1278 |
collection.insert(data)
|
|
|
1279 |
return {1:"Data added successfully"}
|
| 14481 |
kshitij.so |
1280 |
else:
|
| 14553 |
kshitij.so |
1281 |
skuIds = __getBundledSkusfromSku(data['sku'])
|
|
|
1282 |
for sku in skuIds:
|
|
|
1283 |
data['sku'] = sku.get('_id')
|
|
|
1284 |
collection = get_mongo_connection().Catalog.NegativeDeals
|
|
|
1285 |
cursor = collection.find({"sku":data['sku']})
|
|
|
1286 |
if cursor.count() > 0:
|
|
|
1287 |
continue
|
|
|
1288 |
else:
|
| 14558 |
kshitij.so |
1289 |
data.pop('_id',None)
|
| 14553 |
kshitij.so |
1290 |
collection.insert(data)
|
| 14481 |
kshitij.so |
1291 |
return {1:"Data added successfully"}
|
|
|
1292 |
|
|
|
1293 |
def getAllNegativeDeals(offset, limit):
|
|
|
1294 |
data = []
|
|
|
1295 |
collection = get_mongo_connection().Catalog.NegativeDeals
|
|
|
1296 |
cursor = collection.find().skip(offset).limit(limit)
|
|
|
1297 |
for val in cursor:
|
|
|
1298 |
master = list(get_mongo_connection().Catalog.MasterData.find({'_id':val['sku']}))
|
|
|
1299 |
if len(master) > 0:
|
|
|
1300 |
val['brand'] = master[0]['brand']
|
|
|
1301 |
val['source_product_name'] = master[0]['source_product_name']
|
|
|
1302 |
val['skuBundleId'] = master[0]['skuBundleId']
|
|
|
1303 |
else:
|
|
|
1304 |
val['brand'] = ""
|
|
|
1305 |
val['source_product_name'] = ""
|
|
|
1306 |
val['skuBundleId'] = ""
|
|
|
1307 |
data.append(val)
|
|
|
1308 |
return data
|
|
|
1309 |
|
|
|
1310 |
def getAllManualDeals(offset, limit):
|
|
|
1311 |
data = []
|
|
|
1312 |
collection = get_mongo_connection().Catalog.ManualDeals
|
| 15090 |
kshitij.so |
1313 |
cursor = collection.find().skip(offset).limit(limit)
|
| 14481 |
kshitij.so |
1314 |
for val in cursor:
|
|
|
1315 |
master = list(get_mongo_connection().Catalog.MasterData.find({'_id':val['sku']}))
|
|
|
1316 |
if len(master) > 0:
|
|
|
1317 |
val['brand'] = master[0]['brand']
|
|
|
1318 |
val['source_product_name'] = master[0]['source_product_name']
|
|
|
1319 |
val['skuBundleId'] = master[0]['skuBundleId']
|
|
|
1320 |
else:
|
|
|
1321 |
val['brand'] = ""
|
|
|
1322 |
val['source_product_name'] = ""
|
|
|
1323 |
val['skuBundleId'] = ""
|
|
|
1324 |
data.append(val)
|
|
|
1325 |
return data
|
| 14076 |
kshitij.so |
1326 |
|
| 14553 |
kshitij.so |
1327 |
def addManualDeal(data, multi):
|
|
|
1328 |
if multi !=1:
|
|
|
1329 |
collection = get_mongo_connection().Catalog.ManualDeals
|
| 15090 |
kshitij.so |
1330 |
cursor = collection.find({'sku':data['sku']})
|
| 14553 |
kshitij.so |
1331 |
if cursor.count() > 0:
|
|
|
1332 |
return {0:"Sku information already present."}
|
|
|
1333 |
else:
|
|
|
1334 |
collection.insert(data)
|
|
|
1335 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['sku']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=False)
|
|
|
1336 |
return {1:"Data added successfully"}
|
| 14481 |
kshitij.so |
1337 |
else:
|
| 14553 |
kshitij.so |
1338 |
skuIds = __getBundledSkusfromSku(data['sku'])
|
|
|
1339 |
for sku in skuIds:
|
|
|
1340 |
data['sku'] = sku.get('_id')
|
|
|
1341 |
collection = get_mongo_connection().Catalog.ManualDeals
|
| 15090 |
kshitij.so |
1342 |
cursor = collection.find({'sku':data['sku']})
|
| 14553 |
kshitij.so |
1343 |
if cursor.count() > 0:
|
|
|
1344 |
continue
|
|
|
1345 |
else:
|
| 14558 |
kshitij.so |
1346 |
data.pop('_id',None)
|
| 14553 |
kshitij.so |
1347 |
collection.insert(data)
|
|
|
1348 |
get_mongo_connection().Catalog.MasterData.update({'skuBundleId':sku.get('skuBundleId')},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
| 14481 |
kshitij.so |
1349 |
return {1:"Data added successfully"}
|
| 14553 |
kshitij.so |
1350 |
|
| 14481 |
kshitij.so |
1351 |
def deleteDocument(data):
|
| 15853 |
kshitij.so |
1352 |
print "inside detete document"
|
| 14481 |
kshitij.so |
1353 |
print data
|
|
|
1354 |
try:
|
|
|
1355 |
collection = get_mongo_connection().Catalog[data['class']]
|
|
|
1356 |
class_name = data.pop('class')
|
|
|
1357 |
_id = data.pop('oid')
|
|
|
1358 |
record = list(collection.find({'_id':ObjectId(_id)}))
|
|
|
1359 |
collection.remove({'_id':ObjectId(_id)})
|
| 15075 |
kshitij.so |
1360 |
if class_name != "Notifications":
|
|
|
1361 |
if class_name !="CategoryDiscount":
|
| 15853 |
kshitij.so |
1362 |
print record[0]
|
|
|
1363 |
if record[0].has_key('sku'):
|
|
|
1364 |
field = '_id'
|
|
|
1365 |
val = record[0]['sku']
|
|
|
1366 |
else:
|
|
|
1367 |
field = 'skuBundleId'
|
|
|
1368 |
val = record[0]['skuBundleId']
|
|
|
1369 |
print "Updating master"
|
|
|
1370 |
print field
|
|
|
1371 |
print val
|
|
|
1372 |
get_mongo_connection().Catalog.MasterData.update({field:val},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
| 15075 |
kshitij.so |
1373 |
else:
|
|
|
1374 |
get_mongo_connection().Catalog.MasterData.update({'brand':re.compile(record[0]['brand'], re.IGNORECASE),'category_id':record[0]['category_id']}, \
|
|
|
1375 |
{"$set":{'updatedOn':to_java_date(datetime.now())}},upsert=False,multi=True)
|
| 14481 |
kshitij.so |
1376 |
return {1:"Document deleted successfully"}
|
|
|
1377 |
except Exception as e:
|
|
|
1378 |
print e
|
|
|
1379 |
return {0:"Document not deleted."}
|
| 13970 |
kshitij.so |
1380 |
|
| 14482 |
kshitij.so |
1381 |
def searchMaster(offset, limit, search_term):
|
|
|
1382 |
data = []
|
| 14531 |
kshitij.so |
1383 |
if search_term is not None:
|
| 14551 |
kshitij.so |
1384 |
terms = search_term.split(' ')
|
|
|
1385 |
outer_query = []
|
|
|
1386 |
for term in terms:
|
|
|
1387 |
outer_query.append({"source_product_name":re.compile(term, re.IGNORECASE)})
|
| 14531 |
kshitij.so |
1388 |
try:
|
| 14551 |
kshitij.so |
1389 |
collection = get_mongo_connection().Catalog.MasterData.find({"$and":outer_query,'source_id':{'$in':SOURCE_MAP.keys()}}).skip(offset).limit(limit)
|
| 14531 |
kshitij.so |
1390 |
for record in collection:
|
|
|
1391 |
data.append(record)
|
|
|
1392 |
except:
|
|
|
1393 |
pass
|
|
|
1394 |
else:
|
|
|
1395 |
collection = get_mongo_connection().Catalog.MasterData.find({'source_id':{'$in':SOURCE_MAP.keys()}}).skip(offset).limit(limit)
|
| 14482 |
kshitij.so |
1396 |
for record in collection:
|
|
|
1397 |
data.append(record)
|
|
|
1398 |
return data
|
| 14481 |
kshitij.so |
1399 |
|
| 14495 |
kshitij.so |
1400 |
def getAllFeaturedDeals(offset, limit):
|
|
|
1401 |
data = []
|
|
|
1402 |
collection = get_mongo_connection().Catalog.FeaturedDeals
|
| 17561 |
kshitij.so |
1403 |
cursor = collection.find({}).skip(offset).limit(limit)
|
| 14495 |
kshitij.so |
1404 |
for val in cursor:
|
| 17367 |
kshitij.so |
1405 |
master = list(get_mongo_connection().Catalog.MasterData.find({'skuBundleId':val['skuBundleId']}))
|
| 14495 |
kshitij.so |
1406 |
if len(master) > 0:
|
|
|
1407 |
val['brand'] = master[0]['brand']
|
|
|
1408 |
val['source_product_name'] = master[0]['source_product_name']
|
|
|
1409 |
val['skuBundleId'] = master[0]['skuBundleId']
|
|
|
1410 |
else:
|
|
|
1411 |
val['brand'] = ""
|
|
|
1412 |
val['source_product_name'] = ""
|
|
|
1413 |
val['skuBundleId'] = ""
|
|
|
1414 |
data.append(val)
|
|
|
1415 |
return data
|
|
|
1416 |
|
| 14553 |
kshitij.so |
1417 |
def addFeaturedDeal(data, multi):
|
| 17367 |
kshitij.so |
1418 |
collection = get_mongo_connection().Catalog.FeaturedDeals
|
|
|
1419 |
cursor = collection.find({'skuBundleId':data['skuBundleId']})
|
|
|
1420 |
master = get_mongo_connection().Catalog.MasterData.find_one({'skuBundleId':data['skuBundleId']})
|
|
|
1421 |
if master is None:
|
|
|
1422 |
return {0:"BundleId is wrong"}
|
| 17469 |
kshitij.so |
1423 |
otherInfoObj = data['otherInfo']
|
|
|
1424 |
toPop = []
|
|
|
1425 |
for x,y in otherInfoObj.iteritems():
|
|
|
1426 |
if y==0:
|
|
|
1427 |
toPop.append(x)
|
|
|
1428 |
|
|
|
1429 |
for popItem in toPop:
|
|
|
1430 |
otherInfoObj.pop(popItem)
|
|
|
1431 |
if len(otherInfoObj.keys())==0:
|
|
|
1432 |
return {0:"No rank info to add"}
|
|
|
1433 |
|
|
|
1434 |
for x,y in otherInfoObj.iteritems():
|
|
|
1435 |
exist = get_mongo_connection().Catalog.FeaturedDeals.find({'otherInfo.'+x:y})
|
|
|
1436 |
if exist.count() >0:
|
|
|
1437 |
return {0:"Rank already assigned bundleId %s"%(exist[0]['skuBundleId'])}
|
| 17367 |
kshitij.so |
1438 |
if cursor.count() > 0:
|
|
|
1439 |
return {0:"SkuBundleId information already present."}
|
| 14495 |
kshitij.so |
1440 |
else:
|
| 17367 |
kshitij.so |
1441 |
collection.insert(data)
|
| 14495 |
kshitij.so |
1442 |
return {1:"Data added successfully"}
|
|
|
1443 |
|
| 14499 |
kshitij.so |
1444 |
def searchCollection(class_name, sku, skuBundleId):
|
| 14497 |
kshitij.so |
1445 |
data = []
|
|
|
1446 |
collection = get_mongo_connection().Catalog[class_name]
|
| 15076 |
kshitij.so |
1447 |
if class_name == "Notifications":
|
|
|
1448 |
cursor = collection.find({'skuBundleId':skuBundleId})
|
|
|
1449 |
for val in cursor:
|
|
|
1450 |
master = list(get_mongo_connection().Catalog.MasterData.find({'skuBundleId':val['skuBundleId']}))
|
|
|
1451 |
if len(master) > 0:
|
|
|
1452 |
val['brand'] = master[0]['brand']
|
|
|
1453 |
val['model_name'] = master[0]['model_name']
|
|
|
1454 |
val['skuBundleId'] = master[0]['skuBundleId']
|
|
|
1455 |
else:
|
|
|
1456 |
val['brand'] = ""
|
|
|
1457 |
val['model_name'] = ""
|
|
|
1458 |
val['skuBundleId'] = val['skuBundleId']
|
|
|
1459 |
data.append(val)
|
| 15095 |
kshitij.so |
1460 |
return data
|
| 15853 |
kshitij.so |
1461 |
master = None
|
| 14499 |
kshitij.so |
1462 |
if sku is not None:
|
| 15853 |
kshitij.so |
1463 |
if COLLECTION_MAP.has_key(class_name):
|
|
|
1464 |
master = get_mongo_connection().Catalog.MasterData.find_one({'_id':sku})
|
|
|
1465 |
cursor = collection.find({'skuBundleId':master['skuBundleId']})
|
|
|
1466 |
else:
|
|
|
1467 |
cursor = collection.find({'sku':sku})
|
| 14499 |
kshitij.so |
1468 |
for val in cursor:
|
| 15853 |
kshitij.so |
1469 |
if master is None:
|
|
|
1470 |
master = get_mongo_connection().Catalog.MasterData.find_one({'_id':val['sku']})
|
|
|
1471 |
if master is not None:
|
|
|
1472 |
val['brand'] = master['brand']
|
|
|
1473 |
val['source_product_name'] = master['source_product_name']
|
|
|
1474 |
val['skuBundleId'] = master['skuBundleId']
|
| 14499 |
kshitij.so |
1475 |
else:
|
|
|
1476 |
val['brand'] = ""
|
|
|
1477 |
val['source_product_name'] = ""
|
|
|
1478 |
val['skuBundleId'] = ""
|
|
|
1479 |
data.append(val)
|
|
|
1480 |
return data
|
|
|
1481 |
else:
|
| 15853 |
kshitij.so |
1482 |
if not COLLECTION_MAP.has_key(class_name):
|
|
|
1483 |
skuIds = get_mongo_connection().Catalog.MasterData.find({'skuBundleId':skuBundleId}).distinct('_id')
|
|
|
1484 |
for sku in skuIds:
|
|
|
1485 |
cursor = collection.find({'sku':sku})
|
|
|
1486 |
for val in cursor:
|
|
|
1487 |
master = list(get_mongo_connection().Catalog.MasterData.find({'_id':val['sku']}))
|
|
|
1488 |
if len(master) > 0:
|
|
|
1489 |
val['brand'] = master[0]['brand']
|
|
|
1490 |
val['source_product_name'] = master[0]['source_product_name']
|
|
|
1491 |
val['skuBundleId'] = master[0]['skuBundleId']
|
|
|
1492 |
else:
|
|
|
1493 |
val['brand'] = ""
|
|
|
1494 |
val['source_product_name'] = ""
|
|
|
1495 |
val['skuBundleId'] = ""
|
|
|
1496 |
data.append(val)
|
|
|
1497 |
return data
|
|
|
1498 |
else:
|
|
|
1499 |
cursor = collection.find({'skuBundleId':skuBundleId})
|
| 14499 |
kshitij.so |
1500 |
for val in cursor:
|
| 15853 |
kshitij.so |
1501 |
master = list(get_mongo_connection().Catalog.MasterData.find({'skuBundleId':val['skuBundleId']}))
|
| 14499 |
kshitij.so |
1502 |
if len(master) > 0:
|
|
|
1503 |
val['brand'] = master[0]['brand']
|
|
|
1504 |
val['source_product_name'] = master[0]['source_product_name']
|
|
|
1505 |
else:
|
|
|
1506 |
val['brand'] = ""
|
|
|
1507 |
val['source_product_name'] = ""
|
|
|
1508 |
data.append(val)
|
| 15853 |
kshitij.so |
1509 |
return data
|
| 14495 |
kshitij.so |
1510 |
|
| 15074 |
kshitij.so |
1511 |
def __getBrandIdForBrand(brandName, category_id):
|
|
|
1512 |
brandInfo = Brands.query.filter(Brands.category_id==category_id).filter(Brands.name == brandName).all()
|
|
|
1513 |
if brandInfo is None or len(brandInfo)!=1:
|
|
|
1514 |
raise
|
|
|
1515 |
else:
|
|
|
1516 |
return brandInfo[0].id
|
|
|
1517 |
|
| 14588 |
kshitij.so |
1518 |
def addNewItem(data):
|
| 14594 |
kshitij.so |
1519 |
try:
|
|
|
1520 |
data['updatedOn'] = to_java_date(datetime.now())
|
|
|
1521 |
data['addedOn'] = to_java_date(datetime.now())
|
|
|
1522 |
data['priceUpdatedOn'] = to_java_date(datetime.now())
|
|
|
1523 |
max_id = list(get_mongo_connection().Catalog.MasterData.find().sort([('_id',pymongo.DESCENDING)]).limit(1))
|
|
|
1524 |
max_bundle = list(get_mongo_connection().Catalog.MasterData.find().sort([('skuBundleId',pymongo.DESCENDING)]).limit(1))
|
|
|
1525 |
data['_id'] = max_id[0]['_id'] + 1
|
|
|
1526 |
data['skuBundleId'] = max_bundle[0]['skuBundleId'] + 1
|
|
|
1527 |
data['identifier'] = str(data['identifier'])
|
|
|
1528 |
data['secondaryIdentifier'] = str(data['secondaryIdentifier'])
|
| 17115 |
manish.sha |
1529 |
data['model_name'] = str(data['model_name'])
|
| 15074 |
kshitij.so |
1530 |
data['brand_id'] = __getBrandIdForBrand(data['brand'], data['category_id'])
|
| 17746 |
kshitij.so |
1531 |
data['shippingCost'] = float(data['shippingCost'])
|
| 17603 |
kshitij.so |
1532 |
if data['category_id'] ==6 and data['subCategoryId'] ==0:
|
| 17606 |
kshitij.so |
1533 |
return {0:'Sub-Category not selected'}
|
| 17608 |
kshitij.so |
1534 |
elif data['category_id'] !=6 and data['subCategoryId'] !=0:
|
|
|
1535 |
return {0:'Sub-Category not valid'}
|
|
|
1536 |
else:
|
|
|
1537 |
pass
|
| 17604 |
kshitij.so |
1538 |
data['subCategory'] = SUB_CATEGORY_MAP.get(data['subCategoryId'])
|
| 14594 |
kshitij.so |
1539 |
get_mongo_connection().Catalog.MasterData.insert(data)
|
|
|
1540 |
return {1:'Data added successfully'}
|
|
|
1541 |
except Exception as e:
|
|
|
1542 |
print e
|
|
|
1543 |
return {0:'Unable to add data.'}
|
| 15130 |
kshitij.so |
1544 |
finally:
|
|
|
1545 |
session.close()
|
| 14588 |
kshitij.so |
1546 |
|
|
|
1547 |
def addItemToExistingBundle(data):
|
|
|
1548 |
try:
|
|
|
1549 |
data['updatedOn'] = to_java_date(datetime.now())
|
|
|
1550 |
data['addedOn'] = to_java_date(datetime.now())
|
|
|
1551 |
data['priceUpdatedOn'] = to_java_date(datetime.now())
|
| 14593 |
kshitij.so |
1552 |
max_id = list(get_mongo_connection().Catalog.MasterData.find().sort([('_id',pymongo.DESCENDING)]).limit(1))
|
| 14590 |
kshitij.so |
1553 |
data['_id'] = max_id[0]['_id'] + 1
|
| 14594 |
kshitij.so |
1554 |
data['identifier'] = str(data['identifier'])
|
|
|
1555 |
data['secondaryIdentifier'] = str(data['secondaryIdentifier'])
|
| 17115 |
manish.sha |
1556 |
data['model_name'] = str(data['model_name'])
|
| 15074 |
kshitij.so |
1557 |
data['brand_id'] = __getBrandIdForBrand(data['brand'], data['category_id'])
|
| 17746 |
kshitij.so |
1558 |
data['shippingCost'] = float(data['shippingCost'])
|
| 17603 |
kshitij.so |
1559 |
if data['category_id'] ==6 and data['subCategoryId'] ==0:
|
| 17606 |
kshitij.so |
1560 |
return {0:'Sub-Category not selected'}
|
| 17608 |
kshitij.so |
1561 |
elif data['category_id'] !=6 and data['subCategoryId'] !=0:
|
|
|
1562 |
return {0:'Sub-Category not valid'}
|
|
|
1563 |
else:
|
|
|
1564 |
pass
|
| 17604 |
kshitij.so |
1565 |
data['subCategory'] = SUB_CATEGORY_MAP.get(data['subCategoryId'])
|
| 14588 |
kshitij.so |
1566 |
get_mongo_connection().Catalog.MasterData.insert(data)
|
|
|
1567 |
return {1:'Data added successfully.'}
|
| 14594 |
kshitij.so |
1568 |
except Exception as e:
|
|
|
1569 |
print e
|
| 14588 |
kshitij.so |
1570 |
return {0:'Unable to add data.'}
|
| 15130 |
kshitij.so |
1571 |
finally:
|
|
|
1572 |
session.close()
|
| 14588 |
kshitij.so |
1573 |
|
|
|
1574 |
def updateMaster(data, multi):
|
| 15130 |
kshitij.so |
1575 |
try:
|
|
|
1576 |
print data
|
|
|
1577 |
if multi != 1:
|
|
|
1578 |
_id = data.pop('_id')
|
|
|
1579 |
skuBundleId = data.pop('skuBundleId')
|
|
|
1580 |
data['updatedOn'] = to_java_date(datetime.now())
|
|
|
1581 |
data['identifier'] = str(data['identifier'])
|
|
|
1582 |
data['secondaryIdentifier'] = str(data['secondaryIdentifier'])
|
| 17115 |
manish.sha |
1583 |
data['model_name'] = str(data['model_name'])
|
| 17746 |
kshitij.so |
1584 |
data['shippingCost'] = float(data['shippingCost'])
|
| 15130 |
kshitij.so |
1585 |
data['brand_id'] = __getBrandIdForBrand(data['brand'], data['category_id'])
|
| 17603 |
kshitij.so |
1586 |
if data['category_id'] ==6 and data['subCategoryId'] ==0:
|
| 17606 |
kshitij.so |
1587 |
return {0:'Sub-Category not selected'}
|
| 17608 |
kshitij.so |
1588 |
elif data['category_id'] !=6 and data['subCategoryId'] !=0:
|
|
|
1589 |
return {0:'Sub-Category not valid'}
|
|
|
1590 |
else:
|
|
|
1591 |
pass
|
| 17604 |
kshitij.so |
1592 |
data['subCategory'] = SUB_CATEGORY_MAP.get(data['subCategoryId'])
|
| 15130 |
kshitij.so |
1593 |
get_mongo_connection().Catalog.MasterData.update({'_id':_id},{"$set":data},upsert=False)
|
|
|
1594 |
return {1:'Data updated successfully.'}
|
|
|
1595 |
else:
|
|
|
1596 |
_id = data.pop('_id')
|
|
|
1597 |
skuBundleId = data.pop('skuBundleId')
|
|
|
1598 |
data['updatedOn'] = to_java_date(datetime.now())
|
|
|
1599 |
data['identifier'] = str(data['identifier'])
|
|
|
1600 |
data['secondaryIdentifier'] = str(data['secondaryIdentifier'])
|
|
|
1601 |
data['brand_id'] = __getBrandIdForBrand(data['brand'], data['category_id'])
|
| 17115 |
manish.sha |
1602 |
data['model_name'] = str(data['model_name'])
|
| 17746 |
kshitij.so |
1603 |
data['shippingCost'] = float(data['shippingCost'])
|
| 17603 |
kshitij.so |
1604 |
if data['category_id'] ==6 and data['subCategoryId'] ==0:
|
| 17606 |
kshitij.so |
1605 |
return {0:'Sub-Category not selected'}
|
| 17608 |
kshitij.so |
1606 |
elif data['category_id'] !=6 and data['subCategoryId'] !=0:
|
|
|
1607 |
return {0:'Sub-Category not valid'}
|
|
|
1608 |
else:
|
|
|
1609 |
pass
|
| 17604 |
kshitij.so |
1610 |
data['subCategory'] = SUB_CATEGORY_MAP.get(data['subCategoryId'])
|
| 15130 |
kshitij.so |
1611 |
get_mongo_connection().Catalog.MasterData.update({'_id':_id},{"$set":data},upsert=False)
|
|
|
1612 |
similarItems = get_mongo_connection().Catalog.MasterData.find({'skuBundleId':skuBundleId})
|
|
|
1613 |
for item in similarItems:
|
|
|
1614 |
if item['_id'] == _id:
|
|
|
1615 |
continue
|
|
|
1616 |
item['updatedOn'] = to_java_date(datetime.now())
|
|
|
1617 |
item['thumbnail'] = data['thumbnail']
|
|
|
1618 |
item['category'] = data['category']
|
|
|
1619 |
item['category_id'] = data['category_id']
|
|
|
1620 |
item['is_shortage'] = data['is_shortage']
|
|
|
1621 |
item['mrp'] = data['mrp']
|
|
|
1622 |
item['status'] = data['status']
|
|
|
1623 |
item['maxPrice'] = data['maxPrice']
|
|
|
1624 |
item['brand_id'] = data['brand_id']
|
| 17603 |
kshitij.so |
1625 |
item['subCategoryId'] = data['subCategoryId']
|
|
|
1626 |
item['subCategory'] = data['subCategory']
|
| 15130 |
kshitij.so |
1627 |
similar_item_id = item.pop('_id')
|
|
|
1628 |
get_mongo_connection().Catalog.MasterData.update({'_id':similar_item_id},{"$set":item},upsert=False)
|
|
|
1629 |
return {1:'Data updated successfully.'}
|
| 17603 |
kshitij.so |
1630 |
except:
|
|
|
1631 |
return {0:'Unable to update data'}
|
| 15130 |
kshitij.so |
1632 |
finally:
|
|
|
1633 |
session.close()
|
| 14619 |
kshitij.so |
1634 |
|
|
|
1635 |
def getLiveCricScore():
|
|
|
1636 |
return mc.get('liveScore')
|
| 14852 |
kshitij.so |
1637 |
|
|
|
1638 |
def addBundleToNotification(data):
|
|
|
1639 |
try:
|
| 15069 |
kshitij.so |
1640 |
collection = get_mongo_connection().Catalog.Notifications
|
| 14852 |
kshitij.so |
1641 |
cursor = collection.find({'skuBundleId':data['skuBundleId']})
|
|
|
1642 |
if cursor.count() > 0:
|
|
|
1643 |
return {0:"SkuBundleId information already present."}
|
|
|
1644 |
else:
|
|
|
1645 |
collection.insert(data)
|
|
|
1646 |
return {1:'Data updated successfully.'}
|
|
|
1647 |
except:
|
|
|
1648 |
return {0:'Unable to add data.'}
|
|
|
1649 |
|
|
|
1650 |
def getAllNotifications(offset, limit):
|
|
|
1651 |
data = []
|
| 15069 |
kshitij.so |
1652 |
collection = get_mongo_connection().Catalog.Notifications
|
| 16450 |
kshitij.so |
1653 |
cursor = collection.find().sort([('endDate',pymongo.DESCENDING)]).skip(offset).limit(limit)
|
| 14852 |
kshitij.so |
1654 |
for val in cursor:
|
| 15072 |
kshitij.so |
1655 |
master = list(get_mongo_connection().Catalog.MasterData.find({'skuBundleId':val['skuBundleId']}))
|
| 14852 |
kshitij.so |
1656 |
if len(master) > 0:
|
|
|
1657 |
val['brand'] = master[0]['brand']
|
| 15071 |
kshitij.so |
1658 |
val['model_name'] = master[0]['model_name']
|
| 14852 |
kshitij.so |
1659 |
val['skuBundleId'] = master[0]['skuBundleId']
|
|
|
1660 |
else:
|
|
|
1661 |
val['brand'] = ""
|
| 15071 |
kshitij.so |
1662 |
val['model_name'] = ""
|
|
|
1663 |
val['skuBundleId'] = val['skuBundleId']
|
| 14852 |
kshitij.so |
1664 |
data.append(val)
|
|
|
1665 |
return data
|
| 14997 |
kshitij.so |
1666 |
|
|
|
1667 |
def getBrandsForFilter(category_id):
|
|
|
1668 |
if mc.get("brandFilter") is None:
|
| 15095 |
kshitij.so |
1669 |
print "Populating brand data for category_id %d" %(category_id)
|
| 17469 |
kshitij.so |
1670 |
tabData, mobData, accData = [], [], []
|
| 14997 |
kshitij.so |
1671 |
mobileDeals = get_mongo_connection().Catalog.Deals.aggregate([
|
| 16170 |
kshitij.so |
1672 |
{"$match":{"category_id":3,"showDeal":1,"totalPoints":{"$gt":-100}}
|
| 14997 |
kshitij.so |
1673 |
},
|
|
|
1674 |
{"$group" :
|
|
|
1675 |
{'_id':{'brand_id':'$brand_id','brand':'$brand'},'count':{'$sum':1}}
|
|
|
1676 |
}
|
|
|
1677 |
])
|
| 14588 |
kshitij.so |
1678 |
|
| 14997 |
kshitij.so |
1679 |
tabletDeals = get_mongo_connection().Catalog.Deals.aggregate([
|
| 16170 |
kshitij.so |
1680 |
{"$match":{"category_id":5,"showDeal":1,"totalPoints":{"$gt":-100}}
|
| 14997 |
kshitij.so |
1681 |
},
|
|
|
1682 |
{"$group" :
|
|
|
1683 |
{'_id':{'brand_id':'$brand_id','brand':'$brand'},'count':{'$sum':1}}
|
|
|
1684 |
}
|
|
|
1685 |
])
|
|
|
1686 |
|
| 17469 |
kshitij.so |
1687 |
accessoriesDeals = get_mongo_connection().Catalog.Deals.aggregate([
|
|
|
1688 |
{"$match":{"category_id":6,"showDeal":1,"totalPoints":{"$gt":-100}}
|
|
|
1689 |
},
|
|
|
1690 |
{"$group" :
|
|
|
1691 |
{'_id':{'brand_id':'$brand_id','brand':'$brand'},'count':{'$sum':1}}
|
|
|
1692 |
}
|
|
|
1693 |
])
|
|
|
1694 |
|
| 14997 |
kshitij.so |
1695 |
allDeals = get_mongo_connection().Catalog.Deals.aggregate([
|
| 16170 |
kshitij.so |
1696 |
{"$match":{"showDeal":1,"totalPoints":{"$gt":-100}}
|
| 14997 |
kshitij.so |
1697 |
},
|
|
|
1698 |
{"$group" :
|
|
|
1699 |
{'_id':{'brand_id':'$brand_id','brand':'$brand'},'count':{'$sum':1}}
|
|
|
1700 |
}
|
|
|
1701 |
])
|
|
|
1702 |
#print mobileDeals
|
|
|
1703 |
#print "==========Mobile data ends=========="
|
|
|
1704 |
|
|
|
1705 |
#print tabletDeals
|
|
|
1706 |
#print "==========Tablet data ends=========="
|
|
|
1707 |
|
|
|
1708 |
#print allDeals
|
|
|
1709 |
#print "==========All deal data ends========="
|
|
|
1710 |
|
|
|
1711 |
for mobileDeal in mobileDeals['result']:
|
|
|
1712 |
if mobileDeal.get('_id').get('brand_id') != 0:
|
|
|
1713 |
tempMap = {}
|
|
|
1714 |
tempMap['brand'] = mobileDeal.get('_id').get('brand')
|
|
|
1715 |
tempMap['brand_id'] = mobileDeal.get('_id').get('brand_id')
|
|
|
1716 |
tempMap['count'] = mobileDeal.get('count')
|
|
|
1717 |
mobData.append(tempMap)
|
|
|
1718 |
|
|
|
1719 |
for tabletDeal in tabletDeals['result']:
|
|
|
1720 |
if tabletDeal.get('_id').get('brand_id') != 0:
|
|
|
1721 |
tempMap = {}
|
|
|
1722 |
tempMap['brand'] = tabletDeal.get('_id').get('brand')
|
|
|
1723 |
tempMap['brand_id'] = tabletDeal.get('_id').get('brand_id')
|
|
|
1724 |
tempMap['count'] = tabletDeal.get('count')
|
|
|
1725 |
tabData.append(tempMap)
|
|
|
1726 |
|
| 17469 |
kshitij.so |
1727 |
for accessoryDeal in accessoriesDeals['result']:
|
|
|
1728 |
if accessoryDeal.get('_id').get('brand_id') != 0:
|
|
|
1729 |
tempMap = {}
|
|
|
1730 |
tempMap['brand'] = accessoryDeal.get('_id').get('brand')
|
|
|
1731 |
tempMap['brand_id'] = accessoryDeal.get('_id').get('brand_id')
|
|
|
1732 |
tempMap['count'] = accessoryDeal.get('count')
|
|
|
1733 |
accData.append(tempMap)
|
| 14997 |
kshitij.so |
1734 |
|
| 17469 |
kshitij.so |
1735 |
|
| 14997 |
kshitij.so |
1736 |
brandMap = {}
|
|
|
1737 |
for allDeal in allDeals['result']:
|
|
|
1738 |
if allDeal.get('_id').get('brand_id') != 0:
|
|
|
1739 |
if brandMap.has_key(allDeal.get('_id').get('brand')):
|
| 15002 |
kshitij.so |
1740 |
brand_ids = brandMap.get(allDeal.get('_id').get('brand')).get('brand_ids')
|
| 14997 |
kshitij.so |
1741 |
brand_ids.append(allDeal.get('_id').get('brand_id'))
|
| 15003 |
kshitij.so |
1742 |
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 |
1743 |
else:
|
|
|
1744 |
temp = []
|
|
|
1745 |
temp.append(allDeal.get('_id').get('brand_id'))
|
| 15002 |
kshitij.so |
1746 |
brandMap[allDeal.get('_id').get('brand')] = {'brand_ids':temp,'count':allDeal.get('count')}
|
| 14997 |
kshitij.so |
1747 |
|
| 17469 |
kshitij.so |
1748 |
mc.set("brandFilter",{0:brandMap, 3:mobData, 5:tabData, 6:accData}, 600)
|
| 14997 |
kshitij.so |
1749 |
|
| 15062 |
kshitij.so |
1750 |
return sorted(mc.get("brandFilter").get(category_id), key = lambda x: (-x['count'], x['brand']))
|
| 15375 |
kshitij.so |
1751 |
|
| 15459 |
kshitij.so |
1752 |
def getStaticDeals(offset, limit, category_id, direction):
|
| 15375 |
kshitij.so |
1753 |
user_specific_deals = mc.get("staticDeals")
|
|
|
1754 |
if user_specific_deals is None:
|
|
|
1755 |
__populateStaticDeals()
|
|
|
1756 |
user_specific_deals = mc.get("staticDeals")
|
| 15459 |
kshitij.so |
1757 |
rev = False
|
|
|
1758 |
if direction is None or direction == -1:
|
|
|
1759 |
rev=True
|
|
|
1760 |
return sorted((user_specific_deals.get(category_id))[offset:offset+limit],reverse=rev)
|
| 15375 |
kshitij.so |
1761 |
|
|
|
1762 |
def __populateStaticDeals():
|
|
|
1763 |
print "Populating memcache for static deals"
|
|
|
1764 |
outer_query = []
|
|
|
1765 |
outer_query.append({"showDeal":1})
|
|
|
1766 |
query = {}
|
| 16170 |
kshitij.so |
1767 |
query['$gt'] = -100
|
| 15375 |
kshitij.so |
1768 |
outer_query.append({'totalPoints':query})
|
|
|
1769 |
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)]))
|
|
|
1770 |
mobile_deals = []
|
|
|
1771 |
tablet_deals = []
|
|
|
1772 |
for deal in all_deals:
|
|
|
1773 |
item = get_mongo_connection().Catalog.MasterData.find({'_id':deal['_id']})
|
|
|
1774 |
if deal['category_id'] ==3:
|
|
|
1775 |
mobile_deals.append(getItemObjForStaticDeals(item[0]))
|
|
|
1776 |
elif deal['category_id'] ==5:
|
|
|
1777 |
tablet_deals.append(getItemObjForStaticDeals(item[0]))
|
|
|
1778 |
else:
|
|
|
1779 |
continue
|
|
|
1780 |
|
|
|
1781 |
random.shuffle(mobile_deals,random.random)
|
|
|
1782 |
random.shuffle(tablet_deals,random.random)
|
|
|
1783 |
|
|
|
1784 |
mem_cache_val = {3:mobile_deals, 5:tablet_deals}
|
|
|
1785 |
mc.set("staticDeals", mem_cache_val, 3600)
|
|
|
1786 |
|
| 17733 |
kshitij.so |
1787 |
def getItemObjForStaticDeals(item,transform=None):
|
|
|
1788 |
mpu = str(item.get('marketPlaceUrl'))
|
|
|
1789 |
if transform:
|
|
|
1790 |
if mpu.find("snapdeal")!=-1:
|
|
|
1791 |
mpu = "http://m.snapdeal.com"+mpu[mpu.find("/product"):]
|
|
|
1792 |
elif mpu.find("homeshop18")!=-1:
|
|
|
1793 |
mpu = "http://m.homeshop18.com/product.mobi?productId="+item['identifier']
|
| 17735 |
kshitij.so |
1794 |
elif mpu.find("saholic.com")!=-1:
|
| 17746 |
kshitij.so |
1795 |
mpu = "http://m."+mpu[mpu.find("saholic.com"):]
|
| 17735 |
kshitij.so |
1796 |
elif mpu.find("shopclues.com")!=-1:
|
| 17733 |
kshitij.so |
1797 |
mpu = "http://m."+mpu[mpu.find("shopclues.com"):]
|
|
|
1798 |
else:
|
|
|
1799 |
pass
|
|
|
1800 |
|
|
|
1801 |
return {'marketPlaceUrl':mpu,'available_price':int(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 |
1802 |
|
|
|
1803 |
def getItemByMerchantIdentifier(identifier, source_id):
|
|
|
1804 |
skuData = None
|
| 17035 |
kshitij.so |
1805 |
if source_id in (1,2,4,5,6,7):
|
| 16300 |
manas |
1806 |
skuData = get_mongo_connection().Catalog.MasterData.find_one({'identifier':identifier.strip(), 'source_id':source_id})
|
|
|
1807 |
elif source_id == 3:
|
|
|
1808 |
skuData = get_mongo_connection().Catalog.MasterData.find_one({'secondaryIdentifier':identifier.strip(), 'source_id':source_id})
|
|
|
1809 |
if skuData is None:
|
|
|
1810 |
return {}
|
|
|
1811 |
else:
|
|
|
1812 |
return skuData
|
| 15375 |
kshitij.so |
1813 |
|
| 17936 |
kshitij.so |
1814 |
def getDealsForNotification(skuBundleIds,skipSplitting=False):
|
|
|
1815 |
if not skipSplitting:
|
|
|
1816 |
bundles= [int(skuBundleId) for skuBundleId in skuBundleIds.split(',')]
|
|
|
1817 |
print bundles
|
|
|
1818 |
else:
|
|
|
1819 |
bundles = skuBundleIds
|
| 16406 |
kshitij.so |
1820 |
dealsList = []
|
| 16364 |
kshitij.so |
1821 |
dealsListMap = []
|
| 16406 |
kshitij.so |
1822 |
for bundleId in bundles:
|
|
|
1823 |
outer_query = []
|
|
|
1824 |
outer_query.append({ "$or": [ { "showDeal": 1} , { "prepaidDeal": 1 } ] })
|
|
|
1825 |
outer_query.append({'skuBundleId':bundleId})
|
|
|
1826 |
deals = get_mongo_connection().Catalog.Deals.find({"$and":outer_query})
|
|
|
1827 |
for deal in deals:
|
|
|
1828 |
dealsList.append(deal)
|
| 16364 |
kshitij.so |
1829 |
sortedMap = {}
|
|
|
1830 |
rankMap = {}
|
|
|
1831 |
rank = 0
|
| 16406 |
kshitij.so |
1832 |
for sorted_deal in dealsList:
|
| 16364 |
kshitij.so |
1833 |
if sortedMap.get(sorted_deal['skuBundleId']) is None:
|
|
|
1834 |
sortedMap[sorted_deal['skuBundleId']] = {rank:[sorted_deal]}
|
|
|
1835 |
rankMap[rank] = (sortedMap[sorted_deal['skuBundleId']].values())[0]
|
|
|
1836 |
rank = rank +1
|
|
|
1837 |
else:
|
|
|
1838 |
for temp_list in sortedMap.get(sorted_deal['skuBundleId']).itervalues():
|
|
|
1839 |
temp_list.append(sorted_deal)
|
|
|
1840 |
rankMap[(sortedMap.get(sorted_deal['skuBundleId']).keys())[0]] = temp_list
|
|
|
1841 |
|
| 16367 |
kshitij.so |
1842 |
for dealList in [rankMap.get(k, []) for k in range(0, len(bundles))]:
|
| 16364 |
kshitij.so |
1843 |
temp = []
|
|
|
1844 |
for d in dealList:
|
|
|
1845 |
item = list(get_mongo_connection().Catalog.MasterData.find({'_id':d['_id']}))
|
|
|
1846 |
if len(item) ==0:
|
|
|
1847 |
continue
|
|
|
1848 |
if d['dealType'] == 1 and d['source_id'] ==1:
|
|
|
1849 |
item[0]['marketPlaceUrl'] = "http://www.amazon.in/dp/%s"%(item[0]['identifier'].strip())
|
|
|
1850 |
elif d['source_id'] ==3:
|
|
|
1851 |
item[0]['marketPlaceUrl'] = item[0]['marketPlaceUrl']+'?supc='+item[0].get('identifier')
|
|
|
1852 |
else:
|
|
|
1853 |
pass
|
|
|
1854 |
try:
|
|
|
1855 |
cashBack = getCashBack(item[0]['_id'], item[0]['source_id'], item[0]['category_id'])
|
|
|
1856 |
if not cashBack or cashBack.get('cash_back_status')!=1:
|
|
|
1857 |
item[0]['cash_back_type'] = 0
|
|
|
1858 |
item[0]['cash_back'] = 0
|
|
|
1859 |
else:
|
|
|
1860 |
item[0]['cash_back_type'] = int(cashBack['cash_back_type'])
|
|
|
1861 |
item[0]['cash_back'] = cashBack['cash_back']
|
|
|
1862 |
except:
|
|
|
1863 |
print "Error in adding cashback to deals"
|
|
|
1864 |
item[0]['cash_back_type'] = 0
|
|
|
1865 |
item[0]['cash_back'] = 0
|
|
|
1866 |
try:
|
|
|
1867 |
item[0]['dp'] = d['dp']
|
|
|
1868 |
item[0]['showDp'] = d['showDp']
|
|
|
1869 |
except:
|
|
|
1870 |
item[0]['dp'] = 0.0
|
|
|
1871 |
item[0]['showDp'] = 0
|
| 17727 |
kshitij.so |
1872 |
|
|
|
1873 |
try:
|
|
|
1874 |
if item[0]['showVideo']==0:
|
|
|
1875 |
item[0]['videoLink'] =""
|
|
|
1876 |
except:
|
|
|
1877 |
item[0]['videoLink'] =""
|
|
|
1878 |
try:
|
|
|
1879 |
if item[0]['quantity'] >1:
|
|
|
1880 |
ppq = float(item[0]['available_price'])/item[0]['quantity']
|
|
|
1881 |
|
|
|
1882 |
if ppq == round(ppq):
|
|
|
1883 |
item[0]['ppq'] = int(ppq)
|
|
|
1884 |
else:
|
|
|
1885 |
item[0]['ppq'] = round(ppq,2)
|
|
|
1886 |
else:
|
|
|
1887 |
item[0]['ppq'] = 0
|
|
|
1888 |
except:
|
|
|
1889 |
item[0]['ppq'] = 0
|
|
|
1890 |
if item[0]['category_id']!=6:
|
|
|
1891 |
try:
|
| 18830 |
kshitij.so |
1892 |
item[0]['filterLinkBrand'] = '/category/'+str(int(item[0]['category_id']))+'?searchFor='+urllib.quote(item[0]['brand'])+'&filter=brand&brands='+str(int(item[0]['brand_id']))
|
|
|
1893 |
item[0]['filterTextBrand'] = (item[0]['brand'])
|
| 17727 |
kshitij.so |
1894 |
except:
|
| 18830 |
kshitij.so |
1895 |
pass
|
| 17727 |
kshitij.so |
1896 |
else:
|
|
|
1897 |
try:
|
| 18051 |
kshitij.so |
1898 |
if item[0]['subCategory']=='' or item[0]['subCategory'] is None or item[0]['subCategoryId']==0:
|
| 17727 |
kshitij.so |
1899 |
raise
|
| 18830 |
kshitij.so |
1900 |
item[0]['filterLinkSubCategory'] = '/category/'+str(int(item[0]['category_id']))+'?searchFor='+urllib.quote(item[0]['subCategory'])+'&filter=subcategory&subcategories='+str(int(item[0]['subCategoryId']))
|
|
|
1901 |
item[0]['filterTextSubCategory'] = (item[0]['subCategory'])
|
|
|
1902 |
item[0]['filterLinkBrand'] = '/category/'+str(int(item[0]['category_id']))+'?searchFor='+urllib.quote(item[0]['brand'])+'&filter=brand&brands='+str(int(item[0]['brand_id']))
|
|
|
1903 |
item[0]['filterTextBrand'] = (item[0]['brand'])
|
| 17727 |
kshitij.so |
1904 |
except:
|
| 18830 |
kshitij.so |
1905 |
pass
|
| 17944 |
kshitij.so |
1906 |
try:
|
|
|
1907 |
if item[0]['source_id']==4:
|
|
|
1908 |
item_availability_info = mc.get("item_availability_"+str(item[0]['identifier']).strip())
|
|
|
1909 |
if item_availability_info is None or len(item_availability_info)==0:
|
|
|
1910 |
item[0]['availabilityInfo'] = [{}]
|
|
|
1911 |
else:
|
|
|
1912 |
item[0]['availabilityInfo'] = item_availability_info
|
|
|
1913 |
except:
|
|
|
1914 |
item[0]['availabilityInfo'] = [{}]
|
| 19135 |
kshitij.so |
1915 |
|
| 19193 |
kshitij.so |
1916 |
if item[0]['source_id']==4:
|
|
|
1917 |
for av_info in item[0]['availabilityInfo']:
|
|
|
1918 |
if not av_info:
|
|
|
1919 |
continue
|
|
|
1920 |
av_info['cash_back'] = item[0]['cash_back']
|
|
|
1921 |
av_info['cash_back_type'] = item[0]['cash_back_type']
|
|
|
1922 |
netPriceAfterCashBack = av_info['sellingPrice']
|
| 19199 |
kshitij.so |
1923 |
if av_info['cash_back_type'] ==1:
|
| 19207 |
kshitij.so |
1924 |
netPriceAfterCashBack = av_info['sellingPrice'] - math.floor(float(av_info['sellingPrice'])*av_info['cash_back']/100)
|
| 19199 |
kshitij.so |
1925 |
elif av_info['cash_back_type'] ==2:
|
| 19207 |
kshitij.so |
1926 |
netPriceAfterCashBack = av_info['sellingPrice'] - math.floor(av_info['cash_back'])
|
| 19193 |
kshitij.so |
1927 |
else:
|
|
|
1928 |
pass
|
|
|
1929 |
av_info['netPriceAfterCashBack'] = netPriceAfterCashBack
|
|
|
1930 |
|
|
|
1931 |
if item[0]['source_id'] != SOURCE_MAP.get("PAYTM.COM"):
|
|
|
1932 |
if item[0]['codAvailable'] ==1:
|
|
|
1933 |
paytmPrice = item[0]['available_price']
|
|
|
1934 |
else:
|
|
|
1935 |
paytmPrice = item[0]['gross_price']
|
|
|
1936 |
|
|
|
1937 |
if item[0]['cash_back_type'] ==1:
|
| 19207 |
kshitij.so |
1938 |
item[0]['netPriceAfterCashBack'] = paytmPrice - math.floor(float(paytmPrice)*item[0]['cash_back']/100)
|
| 19193 |
kshitij.so |
1939 |
elif item[0]['cash_back_type'] ==2:
|
| 19207 |
kshitij.so |
1940 |
item[0]['netPriceAfterCashBack'] = paytmPrice - math.floor(item[0]['cash_back'])
|
| 19193 |
kshitij.so |
1941 |
else:
|
|
|
1942 |
item[0]['netPriceAfterCashBack'] = paytmPrice
|
|
|
1943 |
|
|
|
1944 |
else:
|
|
|
1945 |
if item[0]['cash_back_type'] ==1:
|
| 19207 |
kshitij.so |
1946 |
item[0]['netPriceAfterCashBack'] = item[0]['available_price'] - math.floor(float(item[0]['available_price'])*item[0]['cash_back']/100)
|
| 19193 |
kshitij.so |
1947 |
elif item[0]['cash_back_type'] ==2:
|
| 19207 |
kshitij.so |
1948 |
item[0]['netPriceAfterCashBack'] = item[0]['available_price'] - math.floor(item[0]['cash_back'])
|
| 19193 |
kshitij.so |
1949 |
else:
|
|
|
1950 |
item[0]['netPriceAfterCashBack'] = item[0]['available_price']
|
|
|
1951 |
|
|
|
1952 |
|
| 19135 |
kshitij.so |
1953 |
item[0]['totalPoints'] = d['totalPoints']
|
| 17727 |
kshitij.so |
1954 |
|
| 16364 |
kshitij.so |
1955 |
temp.append(item[0])
|
|
|
1956 |
if len(temp) > 1:
|
|
|
1957 |
temp = sorted(temp, key = lambda x: (x['available_price']),reverse=False)
|
|
|
1958 |
dealsListMap.append(temp)
|
|
|
1959 |
return dealsListMap
|
|
|
1960 |
|
| 16373 |
manas |
1961 |
def getSkuBrandData(sku):
|
|
|
1962 |
if sku is None:
|
|
|
1963 |
return {}
|
|
|
1964 |
else:
|
|
|
1965 |
orders = get_mongo_connection().Catalog.MasterData.find_one({'skuBundleId':sku})
|
|
|
1966 |
if orders is None:
|
|
|
1967 |
return {}
|
|
|
1968 |
return orders
|
| 16488 |
kshitij.so |
1969 |
|
|
|
1970 |
def addDealPoints(data):
|
|
|
1971 |
collection = get_mongo_connection().Catalog.DealPoints
|
|
|
1972 |
cursor = collection.find({'skuBundleId':data['skuBundleId']})
|
|
|
1973 |
if cursor.count() > 0:
|
|
|
1974 |
return {0:"Sku information already present."}
|
|
|
1975 |
else:
|
|
|
1976 |
collection.insert(data)
|
|
|
1977 |
get_mongo_connection().Catalog.MasterData.update({'skuBundleId':data['skuBundleId']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
|
|
1978 |
return {1:"Data added successfully"}
|
|
|
1979 |
|
|
|
1980 |
def getAllBundlesWithDealPoints(offset, limit):
|
|
|
1981 |
data = []
|
|
|
1982 |
collection = get_mongo_connection().Catalog.DealPoints
|
|
|
1983 |
cursor = collection.find().sort([('endDate',pymongo.DESCENDING)]).skip(offset).limit(limit)
|
|
|
1984 |
for val in cursor:
|
|
|
1985 |
master = get_mongo_connection().Catalog.MasterData.find_one({'skuBundleId':val.get('skuBundleId')})
|
|
|
1986 |
if master is not None:
|
|
|
1987 |
val['brand'] = master['brand']
|
|
|
1988 |
val['source_product_name'] = master['product_name']
|
|
|
1989 |
else:
|
|
|
1990 |
val['brand'] = ""
|
|
|
1991 |
val['source_product_name'] = ""
|
|
|
1992 |
data.append(val)
|
|
|
1993 |
return data
|
| 16546 |
kshitij.so |
1994 |
|
|
|
1995 |
def generateRedirectUrl(retailer_id, app_id):
|
|
|
1996 |
try:
|
| 16663 |
manish.sha |
1997 |
if retailer_id <= 0:
|
|
|
1998 |
return {'url':"","message":"Retailer Id not valid"}
|
| 16546 |
kshitij.so |
1999 |
d_app_offer = app_offers.get_by(id=app_id)
|
| 16605 |
manish.sha |
2000 |
except:
|
|
|
2001 |
traceback.print_exc()
|
| 16546 |
kshitij.so |
2002 |
finally:
|
|
|
2003 |
session.close()
|
|
|
2004 |
if d_app_offer is None:
|
|
|
2005 |
return {'url':"","message":"App id doesn't exist"}
|
| 16364 |
kshitij.so |
2006 |
|
| 16915 |
manish.sha |
2007 |
final_user_payout = 0
|
|
|
2008 |
if d_app_offer.override_payout:
|
|
|
2009 |
final_user_payout = d_app_offer.overriden_payout
|
|
|
2010 |
else:
|
|
|
2011 |
final_user_payout = d_app_offer.user_payout
|
| 16546 |
kshitij.so |
2012 |
|
| 16915 |
manish.sha |
2013 |
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, final_user_payout)
|
|
|
2014 |
|
| 16546 |
kshitij.so |
2015 |
get_mongo_connection().AppOrder.AppTransaction.insert(appTransactions.__dict__)
|
|
|
2016 |
embedd = str((appTransactions.__dict__).get('_id'))
|
| 16548 |
kshitij.so |
2017 |
try:
|
|
|
2018 |
index = d_app_offer.link.index(".freeb.co.in")
|
|
|
2019 |
except:
|
| 16605 |
manish.sha |
2020 |
traceback.print_exc()
|
| 16548 |
kshitij.so |
2021 |
return {'url':"","message":"Substring not found"}
|
|
|
2022 |
redirect_url = d_app_offer.link[0:index]+"."+embedd+d_app_offer.link[index:]
|
| 16546 |
kshitij.so |
2023 |
get_mongo_connection().AppOrder.AppTransaction.update({'_id':ObjectId(embedd)},{"$set":{'redirect_url':redirect_url}})
|
| 16548 |
kshitij.so |
2024 |
return {'url':redirect_url,"message":"Success"}
|
| 16556 |
kshitij.so |
2025 |
|
|
|
2026 |
def addPayout(payout, transaction_id):
|
|
|
2027 |
try:
|
| 16764 |
manish.sha |
2028 |
print 'Got Response for Transaction Id:- '+ str(transaction_id)+ ' and Actual Payout:- '+str(payout)
|
| 16556 |
kshitij.so |
2029 |
transaction = list(get_mongo_connection().AppOrder.AppTransaction.find({'_id':ObjectId(transaction_id)}))
|
|
|
2030 |
if len(transaction) > 0:
|
|
|
2031 |
if (transaction[0])['payout_status'] ==1:
|
| 16753 |
manish.sha |
2032 |
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 |
2033 |
|
|
|
2034 |
approvedAppTransaction = approved_app_transactions.get_by(transaction_id=transaction_id)
|
|
|
2035 |
if approvedAppTransaction is None:
|
|
|
2036 |
approvedAppTransaction = approved_app_transactions()
|
| 16919 |
manish.sha |
2037 |
approvedAppTransaction.app_id = transaction[0].get('app_id')
|
| 16782 |
manish.sha |
2038 |
approvedAppTransaction.cash_back_description = CB_APPROVED
|
| 16919 |
manish.sha |
2039 |
approvedAppTransaction.retailer_id = transaction[0].get('retailer_id')
|
| 16782 |
manish.sha |
2040 |
approvedAppTransaction.transaction_id = transaction_id
|
| 16919 |
manish.sha |
2041 |
approvedAppTransaction.transaction_time = to_py_date(long(transaction[0].get('transaction_time')))
|
|
|
2042 |
approvedAppTransaction.redirect_url = transaction[0].get('redirect_url')
|
| 16782 |
manish.sha |
2043 |
approvedAppTransaction.payout_status = 2
|
|
|
2044 |
approvedAppTransaction.payout_description = CB_APPROVED
|
|
|
2045 |
approvedAppTransaction.cashback_status = 2
|
|
|
2046 |
approvedAppTransaction.payout_amount = long(payout)
|
|
|
2047 |
approvedAppTransaction.payout_time = datetime.now()
|
| 16919 |
manish.sha |
2048 |
approvedAppTransaction.offer_price = long(transaction[0].get('offer_price'))
|
|
|
2049 |
approvedAppTransaction.overridenCashBack = transaction[0].get('overridenCashBack')
|
|
|
2050 |
approvedAppTransaction.isCashBackOverriden = transaction[0].get('isCashBackOverriden')
|
|
|
2051 |
approvedAppTransaction.user_payout = transaction[0].get('user_payout')
|
| 16782 |
manish.sha |
2052 |
approvedAppTransaction.cashBackConsidered = False
|
| 16915 |
manish.sha |
2053 |
if transaction[0].get('final_user_payout') is not None:
|
|
|
2054 |
approvedAppTransaction.final_user_payout = transaction[0].get('final_user_payout')
|
|
|
2055 |
else:
|
| 16919 |
manish.sha |
2056 |
if transaction[0].get('isCashBackOverriden'):
|
|
|
2057 |
approvedAppTransaction.final_user_payout = transaction[0].get('overridenCashBack')
|
| 16915 |
manish.sha |
2058 |
else:
|
| 16919 |
manish.sha |
2059 |
approvedAppTransaction.final_user_payout = transaction[0].get('user_payout')
|
| 16782 |
manish.sha |
2060 |
session.commit()
|
|
|
2061 |
|
|
|
2062 |
updateResult = _updateApprovedCashbackToUser(approvedAppTransaction.id)
|
| 16631 |
manish.sha |
2063 |
else:
|
| 16783 |
manish.sha |
2064 |
approvedAppTransaction.payout_amount = long(payout)
|
|
|
2065 |
approvedAppTransaction.payout_time = datetime.now()
|
|
|
2066 |
if approvedAppTransaction.cashBackConsidered == False:
|
|
|
2067 |
updateResult = _updateApprovedCashbackToUser(approvedAppTransaction.id)
|
|
|
2068 |
session.commit()
|
| 16782 |
manish.sha |
2069 |
|
|
|
2070 |
'''
|
|
|
2071 |
try:
|
|
|
2072 |
if int(transaction[0]['offer_price']) != payout or int(transaction[0]['user_payout']) < payout:
|
|
|
2073 |
_sendAlertForAppPayouts(int(transaction[0]['app_id']), int(transaction[0]['offer_price']), int(transaction[0]['user_payout']), payout)
|
|
|
2074 |
except:
|
|
|
2075 |
print traceback.print_exc()
|
|
|
2076 |
'''
|
| 16556 |
kshitij.so |
2077 |
return {'status':'ok','message':'Payout updated'}
|
|
|
2078 |
elif (transaction[0])['payout_status'] ==2:
|
|
|
2079 |
return {'status':'ok','message':'Payout already processed'}
|
|
|
2080 |
else:
|
|
|
2081 |
return {'status':'fail','message':'Something is wrong'}
|
|
|
2082 |
else:
|
|
|
2083 |
return {'status':'fail','message':'transaction_id not found'}
|
|
|
2084 |
except:
|
| 16657 |
manish.sha |
2085 |
print traceback.print_exc()
|
| 16631 |
manish.sha |
2086 |
try:
|
| 16753 |
manish.sha |
2087 |
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 |
2088 |
except:
|
|
|
2089 |
print 'Data Inconsistency in Cashback Process'
|
| 16636 |
manish.sha |
2090 |
print traceback.print_exc()
|
| 16559 |
kshitij.so |
2091 |
return {'status':'fail','message':'Something is wrong'}
|
| 16885 |
kshitij.so |
2092 |
finally:
|
|
|
2093 |
session.close()
|
| 16556 |
kshitij.so |
2094 |
|
| 16631 |
manish.sha |
2095 |
def _updateApprovedCashbackToUser(approvedAppTransactionId):
|
|
|
2096 |
approvedAppTransaction = approved_app_transactions.get_by(id=approvedAppTransactionId)
|
| 16915 |
manish.sha |
2097 |
if approvedAppTransaction.retailer_id < 0:
|
|
|
2098 |
return False
|
|
|
2099 |
|
| 16631 |
manish.sha |
2100 |
currentMonth = datetime.today().month
|
|
|
2101 |
currentDay = datetime.today().day
|
|
|
2102 |
currentYear = datetime.today().year
|
|
|
2103 |
fortNight = (currentMonth - 1)*2 + (currentDay/15)
|
|
|
2104 |
if currentDay == 30 or currentDay ==31:
|
|
|
2105 |
fortNight = fortNight-1
|
|
|
2106 |
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()
|
|
|
2107 |
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()
|
|
|
2108 |
try:
|
|
|
2109 |
if userAppCashbackObj is None:
|
|
|
2110 |
userAppCashbackObj = user_app_cashbacks()
|
|
|
2111 |
userAppCashbackObj.user_id = approvedAppTransaction.retailer_id
|
|
|
2112 |
userAppCashbackObj.status = 'Approved'
|
| 16915 |
manish.sha |
2113 |
userAppCashbackObj.amount = approvedAppTransaction.final_user_payout
|
| 16631 |
manish.sha |
2114 |
userAppCashbackObj.fortnightOfYear = fortNight
|
|
|
2115 |
userAppCashbackObj.yearVal = currentYear
|
|
|
2116 |
else:
|
| 16915 |
manish.sha |
2117 |
userAppCashbackObj.amount = userAppCashbackObj.amount + approvedAppTransaction.final_user_payout
|
| 16631 |
manish.sha |
2118 |
|
|
|
2119 |
if userAppInstallObj is None:
|
|
|
2120 |
app_offer = app_offers.get_by(id=approvedAppTransaction.app_id)
|
|
|
2121 |
userAppInstallObj = user_app_installs()
|
|
|
2122 |
userAppInstallObj.user_id = approvedAppTransaction.retailer_id
|
|
|
2123 |
userAppInstallObj.fortnightOfYear = fortNight
|
|
|
2124 |
userAppInstallObj.transaction_date = datetime(currentYear, currentMonth, currentDay, 0, 0, 0, 0).date()
|
|
|
2125 |
userAppInstallObj.app_id = approvedAppTransaction.app_id
|
|
|
2126 |
userAppInstallObj.app_name = app_offer.app_name
|
|
|
2127 |
userAppInstallObj.installCount = 1
|
| 16915 |
manish.sha |
2128 |
userAppInstallObj.payoutAmount = approvedAppTransaction.final_user_payout
|
| 16631 |
manish.sha |
2129 |
else:
|
|
|
2130 |
userAppInstallObj.installCount = userAppInstallObj.installCount + 1
|
| 16915 |
manish.sha |
2131 |
userAppInstallObj.payoutAmount = userAppInstallObj.payoutAmount +approvedAppTransaction.final_user_payout
|
| 16631 |
manish.sha |
2132 |
|
|
|
2133 |
approvedAppTransaction.cashBackConsidered = True
|
|
|
2134 |
session.commit()
|
|
|
2135 |
return True
|
|
|
2136 |
except:
|
|
|
2137 |
session.rollback()
|
| 16636 |
manish.sha |
2138 |
print traceback.print_exc()
|
| 16631 |
manish.sha |
2139 |
return False
|
| 16693 |
manish.sha |
2140 |
|
|
|
2141 |
def _sendAlertForAppPayouts(app_id, offerPrice, userPayout, payout):
|
|
|
2142 |
m = Email('localhost')
|
|
|
2143 |
mFrom = "dtr@shop2020.in"
|
|
|
2144 |
m.setFrom(mFrom)
|
|
|
2145 |
mTo = ['rajneesh.arora@saholic.com','kshitij.sood@saholic.com','chaitnaya.vats@saholic.com','manoj.kumar@saholic.com','manish.sharma@shop2020.in']
|
|
|
2146 |
for receipient in mTo:
|
|
|
2147 |
m.addRecipient(receipient)
|
|
|
2148 |
appOffer = app_offers.get_by(id=app_id)
|
|
|
2149 |
if offerPrice != payout:
|
|
|
2150 |
m.setSubject("Mismatch in Offer Price and Actual Pay Out for App Id:- "+str(appOffer.id)+" App Name:- "+str(appOffer.app_name))
|
|
|
2151 |
message1 = "Offer Price:- "+ str(appOffer.offer_price) + "\n" + "Actual Pay Out:- "+ str(payout)
|
|
|
2152 |
m.setTextBody(message1)
|
|
|
2153 |
if userPayout > payout:
|
|
|
2154 |
m.setSubject("User Pay Out greater than actual PayOut for App Id:- "+str(appOffer.id)+" App Name:- "+str(appOffer.app_name))
|
|
|
2155 |
message2 = "User Pay Out Price:- "+ str(appOffer.user_payout) + "\n" + "Actual Pay Out:- "+ str(payout)
|
|
|
2156 |
m.setTextBody(message2)
|
|
|
2157 |
m.send()
|
| 16631 |
manish.sha |
2158 |
|
| 16789 |
amit.gupta |
2159 |
def rejectCashback(orderId, subOrderId):
|
| 16833 |
amit.gupta |
2160 |
cashBack = get_mongo_connection().Dtr.merchantOrder.update({"orderId":orderId, "subOrders.merchantSubOrderId":subOrderId},
|
| 16789 |
amit.gupta |
2161 |
{"$set":{"subOrders.$.cashBackStatus":CB_REJECTED}})
|
| 16837 |
amit.gupta |
2162 |
print cashBack
|
| 16836 |
amit.gupta |
2163 |
return cashBack.get("nModified")
|
| 16894 |
manish.sha |
2164 |
|
|
|
2165 |
def getAppOffers(retailer_id):
|
|
|
2166 |
if not bool(mc.get("cached_app_offers_"+str(retailer_id))):
|
|
|
2167 |
populateAppOffers(retailer_id)
|
|
|
2168 |
return mc.get("cached_app_offers_"+str(retailer_id))
|
|
|
2169 |
|
|
|
2170 |
def populateAppOffers(retailerId):
|
|
|
2171 |
retailerId = int(retailerId)
|
|
|
2172 |
#offset = req.get_param_as_int("offset")
|
|
|
2173 |
#limit = req.get_param_as_int("limit")
|
| 16941 |
manish.sha |
2174 |
nonPriortizedOffers = session.query(app_offers.id).join((appmasters,appmasters.id==app_offers.appmaster_id)).filter(app_offers.affiliate_id==retailerId).filter(appmasters.showApp==True).filter(app_offers.show==True).filter(app_offers.offer_active==True).filter(app_offers.offer_price>0).filter(appmasters.rank==0).order_by(desc('user_payout')).all()
|
|
|
2175 |
priortizeders = session.query(app_offers.id, appmasters.rank).join((appmasters,appmasters.id==app_offers.appmaster_id)).filter(app_offers.affiliate_id==retailerId).filter(appmasters.showApp==True).filter(app_offers.show==True).filter(app_offers.offer_active==True).filter(app_offers.offer_price>0).filter(appmasters.rank>0).order_by(asc(appmasters.rank)).all()
|
| 16894 |
manish.sha |
2176 |
#session.query(app_offers.id,app_offers.appmaster_id, app_offers.app_name, app_offers.affiliate_offer_id, app_offers.image_url, app_offers.downloads, app_offers.link, app_offers.offer_price, app_offers.offerCategory, app_offers.package_name, app_offers.promoImage, app_offers.ratings, case([(app_offers.override_payout == True, app_offers.overriden_payout)], else_=app_offers.user_payout).label('user_payout'), case([(appmasters.shortDescription != None, appmasters.shortDescription)], else_=None).label('shortDescription'), case([(appmasters.longDescription != None, appmasters.longDescription)], else_=None).label('longDescription'), appmasters.customerOneLiner, appmasters.retailerOneLiner,app_offers.priority, app_offers.offerCondition, app_offers.location).join((appmasters,appmasters.id==app_offers.appmaster_id)).filter(app_offers.affiliate_id==retailerId).filter(appmasters.showApp==True).filter(app_offers.show==True).filter(app_offers.offer_active==True).filter(app_offers.offer_price>0).order_by(case([(app_offers.priority.in_(tuple(nullCheckList)), 1)], else_=0), asc(app_offers.priority),desc('user_payout')).all()
|
|
|
2177 |
|
|
|
2178 |
appOffersMap = {}
|
|
|
2179 |
priorityList = []
|
|
|
2180 |
priorityMap = {}
|
|
|
2181 |
for offer in priortizeders:
|
| 16941 |
manish.sha |
2182 |
if priorityMap.has_key(long(offer[1])):
|
|
|
2183 |
offersVal = priorityMap.get(long(offer[1]))
|
|
|
2184 |
offersVal.append(offer)
|
|
|
2185 |
priorityMap[long(offer[1])]=offersVal
|
|
|
2186 |
else:
|
|
|
2187 |
offersVal = []
|
|
|
2188 |
offersVal.append(offer)
|
|
|
2189 |
priorityMap[long(offer[1])]=offersVal
|
|
|
2190 |
|
| 16894 |
manish.sha |
2191 |
priorityList = sorted(priorityMap)
|
|
|
2192 |
|
|
|
2193 |
maxCount = len(nonPriortizedOffers) + len(priortizeders)
|
|
|
2194 |
|
| 16909 |
manish.sha |
2195 |
if priorityList is not None and len(priorityList)>0:
|
|
|
2196 |
if maxCount < max(priorityList):
|
|
|
2197 |
maxCount = max(priorityList)
|
| 16894 |
manish.sha |
2198 |
|
|
|
2199 |
count = 1
|
|
|
2200 |
blockedPlaces = []
|
|
|
2201 |
availablePlaces = []
|
|
|
2202 |
while count <= maxCount:
|
|
|
2203 |
if count in priorityList:
|
|
|
2204 |
blockedPlaces.append(count)
|
|
|
2205 |
else:
|
|
|
2206 |
availablePlaces.append(count)
|
|
|
2207 |
count = count +1
|
| 16941 |
manish.sha |
2208 |
print 'Blocked Places', blockedPlaces
|
| 16894 |
manish.sha |
2209 |
for val in blockedPlaces:
|
| 16941 |
manish.sha |
2210 |
key = val
|
|
|
2211 |
for offerObj in priorityMap.get(val):
|
|
|
2212 |
while appOffersMap.has_key(key):
|
|
|
2213 |
key = key+1
|
|
|
2214 |
appOffersMap[key] = long(offerObj[0])
|
|
|
2215 |
if key in availablePlaces:
|
|
|
2216 |
availablePlaces.remove(key)
|
|
|
2217 |
|
|
|
2218 |
print 'Available Places', availablePlaces
|
|
|
2219 |
|
| 16894 |
manish.sha |
2220 |
i=0
|
|
|
2221 |
for val in availablePlaces:
|
| 16899 |
manish.sha |
2222 |
if i<len(nonPriortizedOffers):
|
| 16902 |
manish.sha |
2223 |
appOffersMap[val]= long(nonPriortizedOffers[i][0])
|
| 16899 |
manish.sha |
2224 |
else:
|
|
|
2225 |
break
|
|
|
2226 |
i=i+1
|
| 16901 |
manish.sha |
2227 |
print 'AppOffersMap', appOffersMap
|
| 16894 |
manish.sha |
2228 |
|
|
|
2229 |
finalAppOffersMap = {}
|
|
|
2230 |
if len(appOffersMap) > 0:
|
|
|
2231 |
for key in sorted(appOffersMap):
|
|
|
2232 |
finalAppOffersMap[key] = appOffersMap[key]
|
|
|
2233 |
|
|
|
2234 |
mc.set("cached_app_offers_"+str(retailerId), finalAppOffersMap, 120)
|
|
|
2235 |
else:
|
|
|
2236 |
print 'No Offers'
|
|
|
2237 |
mc.set("cached_app_offers_"+str(retailerId), {}, 10)
|
| 17280 |
manish.sha |
2238 |
|
| 19337 |
manish.sha |
2239 |
def sendNotification(userIds, campaignName, title, message,notificationtype, url, expiresat='2999-01-01', sendsms=False, smstext=None, mongoHost='localhost'):
|
|
|
2240 |
max_id = list(get_mongo_connection(host=mongoHost).User.notificationcampaigns.find().sort([('_id',pymongo.DESCENDING)]).limit(1))
|
|
|
2241 |
if len(max_id) ==0:
|
|
|
2242 |
max_id = 0
|
|
|
2243 |
else:
|
|
|
2244 |
max_id = max_id[0]['_id']
|
|
|
2245 |
max_id = max_id +1
|
| 19362 |
manish.sha |
2246 |
campaign = NotificationCampaign(max_id, campaignName, title, message, "SELECT User.id from users User where User.id="+str(userIds[0]), url, to_java_date(datetime.now()), to_java_date(datetime.now()+timedelta(days=730)), notificationtype, 'active', sendsms, smstext, 0, 0, 'BATCH_CREDIT')
|
| 19337 |
manish.sha |
2247 |
get_mongo_connection(host=mongoHost).User.notificationcampaigns.insert(campaign.__dict__)
|
| 17302 |
kshitij.so |
2248 |
|
|
|
2249 |
def getDummyDeals(categoryId, offset, limit):
|
|
|
2250 |
outer_query = []
|
|
|
2251 |
outer_query.append({"showDeal":1})
|
|
|
2252 |
outer_query.append({"category_id":categoryId})
|
|
|
2253 |
query = {}
|
|
|
2254 |
query['$gt'] = -100
|
|
|
2255 |
outer_query.append({'totalPoints':query})
|
|
|
2256 |
all_deals = list(get_mongo_connection().Catalog.Deals.find({"$and":outer_query},{'_id':1}).sort([('totalPoints',pymongo.DESCENDING),('bestSellerPoints',pymongo.DESCENDING),('nlcPoints',pymongo.DESCENDING),('rank',pymongo.DESCENDING)]).skip(offset).limit(limit))
|
|
|
2257 |
returnObj = []
|
|
|
2258 |
for deal in all_deals:
|
| 17306 |
kshitij.so |
2259 |
item = list(get_mongo_connection().Catalog.MasterData.find({'_id':deal['_id']}))
|
| 17734 |
kshitij.so |
2260 |
returnObj.append(getItemObjForStaticDeals(item[0],transform=True))
|
| 17302 |
kshitij.so |
2261 |
return returnObj
|
| 17367 |
kshitij.so |
2262 |
|
| 17469 |
kshitij.so |
2263 |
def searchDummyDeals(search_term , limit, offset):
|
| 17367 |
kshitij.so |
2264 |
data = []
|
|
|
2265 |
uniqueMap = {}
|
|
|
2266 |
if search_term is not None:
|
|
|
2267 |
terms = search_term.split(' ')
|
|
|
2268 |
outer_query = []
|
|
|
2269 |
for term in terms:
|
|
|
2270 |
outer_query.append({"source_product_name":re.compile(term, re.IGNORECASE)})
|
|
|
2271 |
try:
|
|
|
2272 |
collection = get_mongo_connection().Catalog.MasterData.find({"$and":outer_query,'source_id':{'$in':SOURCE_MAP.keys()}})
|
|
|
2273 |
for record in collection:
|
|
|
2274 |
data.append(record)
|
|
|
2275 |
except:
|
|
|
2276 |
pass
|
|
|
2277 |
else:
|
|
|
2278 |
collection = get_mongo_connection().Catalog.MasterData.find({'source_id':{'$in':SOURCE_MAP.keys()}})
|
|
|
2279 |
for record in collection:
|
|
|
2280 |
data.append(record)
|
|
|
2281 |
for x in data:
|
|
|
2282 |
if not uniqueMap.has_key(x['skuBundleId']):
|
| 17469 |
kshitij.so |
2283 |
uniqueMap[x['skuBundleId']] = {'source_product_name':x['source_product_name'],'skuBundleId':x['skuBundleId'],'thumbnail':x['thumbnail']}
|
| 17367 |
kshitij.so |
2284 |
|
| 17469 |
kshitij.so |
2285 |
if (offset + limit) > len(uniqueMap.values()):
|
|
|
2286 |
limit = len(uniqueMap.values()) - offset - 1
|
|
|
2287 |
|
|
|
2288 |
count = 0
|
|
|
2289 |
# for x in uniqueMap.values():
|
|
|
2290 |
# print count,
|
|
|
2291 |
# print '\t',
|
|
|
2292 |
# print x
|
|
|
2293 |
# count = count+1
|
| 17555 |
kshitij.so |
2294 |
|
| 17469 |
kshitij.so |
2295 |
print offset
|
|
|
2296 |
print limit
|
|
|
2297 |
|
|
|
2298 |
return uniqueMap.values()[offset:limit+offset]
|
| 17367 |
kshitij.so |
2299 |
|
| 17469 |
kshitij.so |
2300 |
|
|
|
2301 |
def getDummyPricing(skuBundleId):
|
|
|
2302 |
collection = get_mongo_connection().Catalog.MasterData.find({'source_id':{'$in':SOURCE_MAP.keys()},'skuBundleId':skuBundleId,'in_stock':1})
|
|
|
2303 |
print collection.count()
|
|
|
2304 |
cheapest = 99999999
|
|
|
2305 |
cheapestDetails= None
|
|
|
2306 |
returnMap = {}
|
|
|
2307 |
|
|
|
2308 |
for d in collection:
|
|
|
2309 |
if d['available_price'] < cheapest:
|
|
|
2310 |
cheapestDetails = d
|
|
|
2311 |
cheapest = int(d['available_price'])
|
|
|
2312 |
if returnMap.has_key(d['source_id']):
|
| 17733 |
kshitij.so |
2313 |
d = getItemObjForStaticDeals(d,transform=True)
|
| 17469 |
kshitij.so |
2314 |
d['toShowStore'] = 0
|
|
|
2315 |
returnMap[d['source_id']].append(d)
|
|
|
2316 |
else:
|
|
|
2317 |
temp = []
|
| 17733 |
kshitij.so |
2318 |
d = getItemObjForStaticDeals(d,transform=True)
|
| 17469 |
kshitij.so |
2319 |
d['toShowStore'] = 1
|
|
|
2320 |
temp.append(d)
|
|
|
2321 |
returnMap[d['source_id']] = temp
|
|
|
2322 |
returnMap['cheapest'] = cheapestDetails
|
|
|
2323 |
for y in returnMap.itervalues():
|
|
|
2324 |
if isinstance(y, (list, tuple)):
|
|
|
2325 |
(y[len(y)-1])['lastElement'] = 1
|
|
|
2326 |
else:
|
|
|
2327 |
pass
|
|
|
2328 |
if returnMap['cheapest'] ==None:
|
|
|
2329 |
dum = get_mongo_connection().Catalog.MasterData.find_one({'skuBundleId':skuBundleId,'source_id':{"$in":SOURCE_MAP.keys()}})
|
|
|
2330 |
returnMap['cheapest'] = {'thumbnail':dum['thumbnail'],'source_product_name':dum['source_product_name']}
|
|
|
2331 |
return returnMap
|
| 17555 |
kshitij.so |
2332 |
|
| 17603 |
kshitij.so |
2333 |
|
| 17555 |
kshitij.so |
2334 |
def addDealObject(data):
|
| 17570 |
kshitij.so |
2335 |
if data.get('img_url') is None or data.get('img_url')=="" or data.get('name') is None or data.get('name')=="":
|
|
|
2336 |
return {0:'Invalid data'}
|
| 17555 |
kshitij.so |
2337 |
try:
|
|
|
2338 |
max_id = list(get_mongo_connection().Catalog.DealObject.find().sort([('_id',pymongo.DESCENDING)]).limit(1))
|
|
|
2339 |
if len(max_id) ==0:
|
|
|
2340 |
max_id = 0
|
| 17559 |
kshitij.so |
2341 |
else:
|
|
|
2342 |
max_id = max_id[0]['_id']
|
|
|
2343 |
data['_id'] = max_id +1
|
| 17555 |
kshitij.so |
2344 |
get_mongo_connection().Catalog.DealObject.insert(data)
|
|
|
2345 |
return {1:'Data added successfully'}
|
|
|
2346 |
except:
|
|
|
2347 |
return {0:'Error in adding data'}
|
|
|
2348 |
|
| 17561 |
kshitij.so |
2349 |
def getAllDealObjects(offset, limit):
|
|
|
2350 |
data = []
|
|
|
2351 |
collection = get_mongo_connection().Catalog.DealObject
|
|
|
2352 |
cursor = collection.find({}).skip(offset).limit(limit)
|
|
|
2353 |
for val in cursor:
|
| 17564 |
kshitij.so |
2354 |
data.append({'_id':val['_id'],'name':val['name']})
|
| 17561 |
kshitij.so |
2355 |
return data
|
| 17564 |
kshitij.so |
2356 |
|
|
|
2357 |
def deleteDealObject(id):
|
|
|
2358 |
try:
|
|
|
2359 |
get_mongo_connection().Catalog.DealObject.remove({'_id':id})
|
| 17616 |
kshitij.so |
2360 |
get_mongo_connection().Catalog.FeaturedDealsDealObject.remove({'_id':id})
|
| 17564 |
kshitij.so |
2361 |
return {1:"Deal Object deleted"}
|
|
|
2362 |
except:
|
|
|
2363 |
return {0:"Error in deleting object"}
|
| 17566 |
kshitij.so |
2364 |
|
|
|
2365 |
def getDealObjectById(id):
|
|
|
2366 |
try:
|
|
|
2367 |
data = get_mongo_connection().Catalog.DealObject.find({'_id':id})
|
|
|
2368 |
return data
|
|
|
2369 |
except:
|
| 17570 |
kshitij.so |
2370 |
return {}
|
| 17561 |
kshitij.so |
2371 |
|
| 17570 |
kshitij.so |
2372 |
def updateDealObject(data):
|
|
|
2373 |
try:
|
|
|
2374 |
_id = data['_id']
|
|
|
2375 |
data.pop('_id')
|
|
|
2376 |
get_mongo_connection().Catalog.DealObject.update({'_id':_id},{"$set":data},upsert=False)
|
|
|
2377 |
return {1:"Data updated successfully"}
|
|
|
2378 |
except:
|
|
|
2379 |
return {0:"Error in updating data"}
|
|
|
2380 |
|
| 17610 |
kshitij.so |
2381 |
def getAllFeaturedDealsForDealObject(offset, limit):
|
|
|
2382 |
data = []
|
|
|
2383 |
collection = get_mongo_connection().Catalog.FeaturedDealsDealObject
|
|
|
2384 |
cursor = collection.find({}).skip(offset).limit(limit)
|
|
|
2385 |
for val in cursor:
|
|
|
2386 |
data.append(val)
|
|
|
2387 |
return data
|
|
|
2388 |
|
|
|
2389 |
def addFeaturedDealForDealObject(data):
|
| 19280 |
kshitij.so |
2390 |
print data
|
|
|
2391 |
|
| 17610 |
kshitij.so |
2392 |
collection = get_mongo_connection().Catalog.FeaturedDealsDealObject
|
|
|
2393 |
cursor = collection.find({'_id':data['_id']})
|
|
|
2394 |
master = get_mongo_connection().Catalog.DealObject.find_one({'_id':data['_id']})
|
|
|
2395 |
if master is None:
|
|
|
2396 |
return {0:"Deal Object id wrong"}
|
|
|
2397 |
otherInfoObj = data['otherInfo']
|
|
|
2398 |
toPop = []
|
|
|
2399 |
for x,y in otherInfoObj.iteritems():
|
| 19280 |
kshitij.so |
2400 |
if y==0 or y=="":
|
| 17610 |
kshitij.so |
2401 |
toPop.append(x)
|
|
|
2402 |
|
|
|
2403 |
for popItem in toPop:
|
|
|
2404 |
otherInfoObj.pop(popItem)
|
|
|
2405 |
if len(otherInfoObj.keys())==0:
|
|
|
2406 |
return {0:"No rank info to add"}
|
|
|
2407 |
|
|
|
2408 |
for x,y in otherInfoObj.iteritems():
|
|
|
2409 |
exist = get_mongo_connection().Catalog.FeaturedDealsDealObject.find({'otherInfo.'+x:y})
|
|
|
2410 |
if exist.count() >0:
|
|
|
2411 |
return {0:"Rank already assigned Deal Object Id %s"%(exist[0]['_id'])}
|
|
|
2412 |
if cursor.count() > 0:
|
|
|
2413 |
return {0:"Deal Object Id information already present."}
|
|
|
2414 |
else:
|
|
|
2415 |
collection.insert(data)
|
|
|
2416 |
return {1:"Data added successfully"}
|
|
|
2417 |
|
| 17616 |
kshitij.so |
2418 |
def deleteFeaturedDealObject(id):
|
|
|
2419 |
try:
|
|
|
2420 |
get_mongo_connection().Catalog.FeaturedDealsDealObject.remove({'_id':id})
|
|
|
2421 |
return {1:"Deal Object deleted"}
|
|
|
2422 |
except:
|
|
|
2423 |
return {0:"Error in deleting object"}
|
| 17654 |
kshitij.so |
2424 |
|
|
|
2425 |
def getSubCategoryForFilter(category_id):
|
|
|
2426 |
if mc.get("subCategoryFilter") is None:
|
|
|
2427 |
print "Populating subcategory data for category_id %d" %(category_id)
|
|
|
2428 |
tabData, mobData, accData = [], [], []
|
|
|
2429 |
|
|
|
2430 |
accessoriesDeals = get_mongo_connection().Catalog.Deals.aggregate([
|
|
|
2431 |
{"$match":{"category_id":6,"showDeal":1,"totalPoints":{"$gt":-100}}
|
|
|
2432 |
},
|
|
|
2433 |
{"$group" :
|
|
|
2434 |
{'_id':{'subCategoryId':'$subCategoryId','subCategory':'$subCategory'},'count':{'$sum':1}}
|
|
|
2435 |
}
|
|
|
2436 |
])
|
|
|
2437 |
|
|
|
2438 |
for accessoryDeal in accessoriesDeals['result']:
|
|
|
2439 |
if accessoryDeal.get('_id').get('subCategoryId') != 0:
|
|
|
2440 |
tempMap = {}
|
|
|
2441 |
tempMap['subCategory'] = accessoryDeal.get('_id').get('subCategory')
|
|
|
2442 |
tempMap['subCategoryId'] = accessoryDeal.get('_id').get('subCategoryId')
|
|
|
2443 |
tempMap['count'] = accessoryDeal.get('count')
|
|
|
2444 |
accData.append(tempMap)
|
|
|
2445 |
|
|
|
2446 |
|
|
|
2447 |
mc.set("subCategoryFilter",{3:mobData, 5:tabData, 6:accData}, 600)
|
|
|
2448 |
|
|
|
2449 |
return sorted(mc.get("subCategoryFilter").get(category_id), key = lambda x: (-x['count'], x['subCategory']))
|
| 17610 |
kshitij.so |
2450 |
|
| 17727 |
kshitij.so |
2451 |
def dummyLogin(data):
|
| 17731 |
kshitij.so |
2452 |
exist = list(get_mongo_connection().Catalog.DummyUser.find({'email':data['email'],'password':data['password']}))
|
| 17727 |
kshitij.so |
2453 |
if len(exist) > 0:
|
| 17728 |
kshitij.so |
2454 |
return {'user_id':exist[0]['_id'],'fullName':exist[0]['fullName']}
|
| 17727 |
kshitij.so |
2455 |
else:
|
|
|
2456 |
return {'user_id':0}
|
| 17616 |
kshitij.so |
2457 |
|
| 17727 |
kshitij.so |
2458 |
def dummyRegister(data):
|
|
|
2459 |
try:
|
|
|
2460 |
exist = list(get_mongo_connection().Catalog.DummyUser.find({'email':data['email']}))
|
|
|
2461 |
if len(exist) > 0:
|
|
|
2462 |
return {'msg':"Email already registered",'user_id':0}
|
|
|
2463 |
else:
|
|
|
2464 |
max_id = list(get_mongo_connection().Catalog.DummyUser.find().sort([('_id',pymongo.DESCENDING)]).limit(1))
|
|
|
2465 |
if len(max_id) ==0:
|
|
|
2466 |
max_id = 0
|
|
|
2467 |
else:
|
|
|
2468 |
max_id = max_id[0]['_id']
|
|
|
2469 |
data['_id'] = max_id +1
|
|
|
2470 |
get_mongo_connection().Catalog.DummyUser.insert(data)
|
| 17728 |
kshitij.so |
2471 |
return {'msg':"Registration successful",'user_id':data['_id'],'fullName':data['fullName']}
|
| 17727 |
kshitij.so |
2472 |
except:
|
|
|
2473 |
return {'msg':"Error in registration.",'user_id':0}
|
|
|
2474 |
|
| 17731 |
kshitij.so |
2475 |
def getDummyUser(user_id):
|
|
|
2476 |
exist = list(get_mongo_connection().Catalog.DummyUser.find({'_id':user_id}))
|
|
|
2477 |
if len(exist) > 0:
|
|
|
2478 |
return exist[0]
|
|
|
2479 |
else:
|
|
|
2480 |
return {'user_id':0,'fullName':"",'email':"","contactNumber":""}
|
|
|
2481 |
|
|
|
2482 |
def updateDummyUser(data):
|
|
|
2483 |
try:
|
| 17732 |
kshitij.so |
2484 |
get_mongo_connection().Catalog.DummyUser.update({'_id':data['user_id']},{"$set":data},upsert=False)
|
| 17731 |
kshitij.so |
2485 |
return {'msg':"Data updated successfuly",'response':1}
|
|
|
2486 |
except:
|
|
|
2487 |
return {'msg':"Unable to update data",'response':0}
|
| 17936 |
kshitij.so |
2488 |
|
| 18089 |
kshitij.so |
2489 |
def getDealsForSearchText(subCategoryIds, searchTerm, offset, limit):
|
|
|
2490 |
subCategories= [int(subCategoryId) for subCategoryId in subCategoryIds.split('^')]
|
| 18106 |
kshitij.so |
2491 |
print "SubCategories are ",subCategories
|
| 17936 |
kshitij.so |
2492 |
payload = {
|
| 18106 |
kshitij.so |
2493 |
"query": {
|
| 17936 |
kshitij.so |
2494 |
"bool": {
|
| 18106 |
kshitij.so |
2495 |
"must": [{
|
|
|
2496 |
"match": {
|
|
|
2497 |
"title": {
|
|
|
2498 |
"query": searchTerm,
|
|
|
2499 |
"operator": "and"
|
|
|
2500 |
}
|
| 17936 |
kshitij.so |
2501 |
}
|
| 18106 |
kshitij.so |
2502 |
},
|
|
|
2503 |
|
|
|
2504 |
{
|
|
|
2505 |
"in": {
|
|
|
2506 |
"subCategoryId": subCategories
|
|
|
2507 |
}
|
| 17936 |
kshitij.so |
2508 |
}
|
| 18106 |
kshitij.so |
2509 |
|
|
|
2510 |
]
|
| 17936 |
kshitij.so |
2511 |
}
|
| 19135 |
kshitij.so |
2512 |
},
|
|
|
2513 |
"sort": { "dealPoints": { "order": "desc" }}
|
| 18106 |
kshitij.so |
2514 |
}
|
| 17944 |
kshitij.so |
2515 |
result = get_elastic_search_connection().search(index="my_index", body=payload, from_=offset, size=limit)
|
| 17936 |
kshitij.so |
2516 |
totalCount= result['hits']['total']
|
|
|
2517 |
temp = []
|
|
|
2518 |
bundles = []
|
|
|
2519 |
if len(result['hits']['hits']) > 0:
|
|
|
2520 |
for x in result['hits']['hits']:
|
|
|
2521 |
tempMap = {}
|
|
|
2522 |
tempMap = {'skuBundleId':x['_source']['id'],'title':x['_source']['title']}
|
|
|
2523 |
temp.append(tempMap)
|
|
|
2524 |
bundles.append(x['_source']['id'])
|
| 18271 |
kshitij.so |
2525 |
#return temp
|
| 17936 |
kshitij.so |
2526 |
return getDealsForNotification(bundles, skipSplitting=True)
|
| 17731 |
kshitij.so |
2527 |
|
| 18089 |
kshitij.so |
2528 |
def getCountForSearchText(subCategoryIds, searchTerm):
|
|
|
2529 |
subCategories= [int(subCategoryId) for subCategoryId in subCategoryIds.split('^')]
|
| 17936 |
kshitij.so |
2530 |
payload = {
|
| 18106 |
kshitij.so |
2531 |
"query": {
|
| 17936 |
kshitij.so |
2532 |
"bool": {
|
| 18106 |
kshitij.so |
2533 |
"must": [{
|
|
|
2534 |
"match": {
|
|
|
2535 |
"title": {
|
|
|
2536 |
"query": searchTerm,
|
|
|
2537 |
"operator": "and"
|
|
|
2538 |
}
|
| 17936 |
kshitij.so |
2539 |
}
|
| 18106 |
kshitij.so |
2540 |
},
|
|
|
2541 |
|
|
|
2542 |
{
|
|
|
2543 |
"in": {
|
|
|
2544 |
"subCategoryId": subCategories
|
|
|
2545 |
}
|
| 17936 |
kshitij.so |
2546 |
}
|
| 18106 |
kshitij.so |
2547 |
|
|
|
2548 |
]
|
| 17936 |
kshitij.so |
2549 |
}
|
|
|
2550 |
}
|
| 18106 |
kshitij.so |
2551 |
}
|
| 17731 |
kshitij.so |
2552 |
|
| 17944 |
kshitij.so |
2553 |
result = get_elastic_search_connection().search(index="my_index", body=payload)
|
| 17936 |
kshitij.so |
2554 |
totalCount= result['hits']['total']
|
|
|
2555 |
return {'searchTerm':searchTerm,'count':totalCount}
|
| 18271 |
kshitij.so |
2556 |
|
|
|
2557 |
def getDealById(id):
|
|
|
2558 |
item = list(get_mongo_connection().Catalog.MasterData.find({'_id':int(id)}))
|
|
|
2559 |
d = get_mongo_connection().Catalog.Deals.find_one({'_id':int(id)})
|
| 19193 |
kshitij.so |
2560 |
if len(item) ==0:
|
|
|
2561 |
return {}
|
| 18271 |
kshitij.so |
2562 |
if d is None:
|
|
|
2563 |
d = {'showDp':0,'dp':0}
|
|
|
2564 |
try:
|
|
|
2565 |
cashBack = getCashBack(item[0]['_id'], item[0]['source_id'], item[0]['category_id'])
|
|
|
2566 |
if not cashBack or cashBack.get('cash_back_status')!=1:
|
|
|
2567 |
item[0]['cash_back_type'] = 0
|
|
|
2568 |
item[0]['cash_back'] = 0
|
|
|
2569 |
else:
|
|
|
2570 |
if cashBack.get('maxCashBack') is not None:
|
|
|
2571 |
|
|
|
2572 |
if cashBack.get('cash_back_type') ==1 and (float(cashBack.get('cash_back'))*item[0]['available_price'])/100 > cashBack.get('maxCashBack'):
|
|
|
2573 |
cashBack['cash_back_type'] = 2
|
|
|
2574 |
cashBack['cash_back'] = cashBack['maxCashBack']
|
|
|
2575 |
elif cashBack.get('cash_back_type') ==2 and cashBack.get('cash_back') > cashBack.get('maxCashBack'):
|
|
|
2576 |
cashBack['cash_back'] = cashBack['maxCashBack']
|
| 17936 |
kshitij.so |
2577 |
|
| 18271 |
kshitij.so |
2578 |
item[0]['cash_back_type'] = int(cashBack['cash_back_type'])
|
|
|
2579 |
item[0]['cash_back'] = cashBack['cash_back']
|
|
|
2580 |
except:
|
|
|
2581 |
print "Error in adding cashback to deals"
|
|
|
2582 |
item[0]['cash_back_type'] = 0
|
|
|
2583 |
item[0]['cash_back'] = 0
|
|
|
2584 |
try:
|
|
|
2585 |
item[0]['dp'] = d['dp']
|
|
|
2586 |
item[0]['showDp'] = d['showDp']
|
|
|
2587 |
except:
|
|
|
2588 |
item[0]['dp'] = 0.0
|
|
|
2589 |
item[0]['showDp'] = 0
|
|
|
2590 |
try:
|
|
|
2591 |
item[0]['thumbnail'] = item[0]['thumbnail'].strip()
|
|
|
2592 |
except:
|
|
|
2593 |
pass
|
|
|
2594 |
|
|
|
2595 |
try:
|
|
|
2596 |
if item[0]['showVideo']==0:
|
|
|
2597 |
item[0]['videoLink'] =""
|
|
|
2598 |
except:
|
|
|
2599 |
item[0]['videoLink'] =""
|
|
|
2600 |
try:
|
|
|
2601 |
if item[0]['quantity'] >1:
|
|
|
2602 |
ppq = float(item[0]['available_price'])/item[0]['quantity']
|
|
|
2603 |
|
|
|
2604 |
if ppq == round(ppq):
|
|
|
2605 |
item[0]['ppq'] = int(ppq)
|
|
|
2606 |
else:
|
|
|
2607 |
item[0]['ppq'] = round(ppq,2)
|
|
|
2608 |
else:
|
|
|
2609 |
item[0]['ppq'] = 0
|
|
|
2610 |
except:
|
|
|
2611 |
item[0]['ppq'] = 0
|
|
|
2612 |
if item[0]['category_id']!=6:
|
|
|
2613 |
try:
|
| 18830 |
kshitij.so |
2614 |
item[0]['filterLinkBrand'] = '/category/'+str(int(item[0]['category_id']))+'?searchFor='+urllib.quote(item[0]['brand'])+'&filter=brand&brands='+str(int(item[0]['brand_id']))
|
|
|
2615 |
item[0]['filterTextBrand'] = (item[0]['brand'])
|
| 18271 |
kshitij.so |
2616 |
except:
|
| 18830 |
kshitij.so |
2617 |
pass
|
| 18271 |
kshitij.so |
2618 |
else:
|
|
|
2619 |
try:
|
|
|
2620 |
if item[0]['subCategory']=='' or item[0]['subCategory'] is None or item[0]['subCategoryId']==0:
|
|
|
2621 |
raise
|
| 18830 |
kshitij.so |
2622 |
item[0]['filterLinkSubCategory'] = '/category/'+str(int(item[0]['category_id']))+'?searchFor='+urllib.quote(item[0]['subCategory'])+'&filter=subcategory&subcategories='+str(int(item[0]['subCategoryId']))
|
|
|
2623 |
item[0]['filterTextSubCategory'] = (item[0]['subCategory'])
|
|
|
2624 |
item[0]['filterLinkBrand'] = '/category/'+str(int(item[0]['category_id']))+'?searchFor='+urllib.quote(item[0]['brand'])+'&filter=brand&brands='+str(int(item[0]['brand_id']))
|
|
|
2625 |
item[0]['filterTextBrand'] = (item[0]['brand'])
|
| 18271 |
kshitij.so |
2626 |
except:
|
| 18830 |
kshitij.so |
2627 |
pass
|
| 18271 |
kshitij.so |
2628 |
try:
|
|
|
2629 |
if item[0]['source_id']==4:
|
|
|
2630 |
item_availability_info = mc.get("item_availability_"+str(item[0]['identifier']).strip())
|
|
|
2631 |
if item_availability_info is None or len(item_availability_info)==0:
|
|
|
2632 |
item[0]['availabilityInfo'] = [{}]
|
|
|
2633 |
else:
|
|
|
2634 |
item[0]['availabilityInfo'] = item_availability_info
|
|
|
2635 |
except:
|
|
|
2636 |
item[0]['availabilityInfo'] = [{}]
|
| 19193 |
kshitij.so |
2637 |
|
|
|
2638 |
if item[0]['source_id']==4:
|
|
|
2639 |
for av_info in item[0]['availabilityInfo']:
|
|
|
2640 |
if not av_info:
|
|
|
2641 |
continue
|
|
|
2642 |
av_info['cash_back'] = item[0]['cash_back']
|
|
|
2643 |
av_info['cash_back_type'] = item[0]['cash_back_type']
|
|
|
2644 |
netPriceAfterCashBack = av_info['sellingPrice']
|
| 19199 |
kshitij.so |
2645 |
if av_info['cash_back_type'] ==1:
|
| 19207 |
kshitij.so |
2646 |
netPriceAfterCashBack = av_info['sellingPrice'] - math.floor(float(av_info['sellingPrice'])*av_info['cash_back']/100)
|
| 19199 |
kshitij.so |
2647 |
elif av_info['cash_back_type'] ==2:
|
| 19207 |
kshitij.so |
2648 |
netPriceAfterCashBack = av_info['sellingPrice'] - math.floor(av_info['cash_back'])
|
| 19193 |
kshitij.so |
2649 |
else:
|
|
|
2650 |
pass
|
|
|
2651 |
av_info['netPriceAfterCashBack'] = netPriceAfterCashBack
|
|
|
2652 |
|
|
|
2653 |
if item[0]['source_id'] != SOURCE_MAP.get("PAYTM.COM"):
|
|
|
2654 |
if item[0]['codAvailable'] ==1:
|
|
|
2655 |
paytmPrice = item[0]['available_price']
|
|
|
2656 |
else:
|
|
|
2657 |
paytmPrice = item[0]['gross_price']
|
|
|
2658 |
|
|
|
2659 |
if item[0]['cash_back_type'] ==1:
|
| 19207 |
kshitij.so |
2660 |
item[0]['netPriceAfterCashBack'] = paytmPrice - math.floor(float(paytmPrice)*item[0]['cash_back']/100)
|
| 19193 |
kshitij.so |
2661 |
elif item[0]['cash_back_type'] ==2:
|
| 19207 |
kshitij.so |
2662 |
item[0]['netPriceAfterCashBack'] = paytmPrice - math.floor(item[0]['cash_back'])
|
| 19193 |
kshitij.so |
2663 |
else:
|
|
|
2664 |
item[0]['netPriceAfterCashBack'] = paytmPrice
|
|
|
2665 |
|
|
|
2666 |
else:
|
|
|
2667 |
if item[0]['cash_back_type'] ==1:
|
| 19207 |
kshitij.so |
2668 |
item[0]['netPriceAfterCashBack'] = item[0]['available_price'] - math.floor(float(item[0]['available_price'])*item[0]['cash_back']/100)
|
| 19193 |
kshitij.so |
2669 |
elif item[0]['cash_back_type'] ==2:
|
| 19207 |
kshitij.so |
2670 |
item[0]['netPriceAfterCashBack'] = item[0]['available_price'] - math.floor(item[0]['cash_back'])
|
| 19193 |
kshitij.so |
2671 |
else:
|
|
|
2672 |
item[0]['netPriceAfterCashBack'] = item[0]['available_price']
|
|
|
2673 |
|
| 18271 |
kshitij.so |
2674 |
return item[0]
|
|
|
2675 |
|
| 19288 |
kshitij.so |
2676 |
def getOfferForUser(userId):
|
|
|
2677 |
specialOffer = {}
|
|
|
2678 |
promoOffer = get_mongo_connection().Catalog.PromoOffer.find_one({'user_id':userId})
|
|
|
2679 |
try:
|
|
|
2680 |
if promoOffer is not None:
|
|
|
2681 |
offer = get_mongo_connection().Catalog.Promotions.find_one({'_id':promoOffer.get('offer_id')})
|
|
|
2682 |
if offer is None:
|
|
|
2683 |
raise
|
| 19355 |
kshitij.so |
2684 |
promo = Promotion(offer.get('_id'),offer.get('offer_name'),offer.get('offer_description') , offer.get('categories_applicable'), offer.get('sub_categories_not_applicable'),
|
| 19331 |
kshitij.so |
2685 |
offer.get('startDate'), offer.get('endDate'), promoOffer.get('target1'), promoOffer.get('target1_cash_back_percetage'), promoOffer.get('target2'), promoOffer.get('target2_cash_back_percetage'), promoOffer.get('maxCashBack'), offer.get('url'),
|
| 19350 |
kshitij.so |
2686 |
promoOffer.get('pending_order_value'), promoOffer.get('delivered_order_value'), promoOffer.get('last_run_timestamp'))
|
| 19354 |
kshitij.so |
2687 |
|
| 19355 |
kshitij.so |
2688 |
promo.offer_description = "Get upto %d%% cashback"%(promo.target2_cash_back_percetage)
|
|
|
2689 |
|
| 19288 |
kshitij.so |
2690 |
specialOffer = promo.__dict__
|
|
|
2691 |
except:
|
|
|
2692 |
pass
|
|
|
2693 |
return specialOffer
|
|
|
2694 |
|
| 19389 |
kshitij.so |
2695 |
def getBrandSubCategoryInfo(category_id, id_list, type):
|
| 19397 |
kshitij.so |
2696 |
|
|
|
2697 |
id_list_mapping = {}
|
| 19398 |
kshitij.so |
2698 |
if type == "brandInfo":
|
| 19397 |
kshitij.so |
2699 |
brands = [int(brand_id) for brand_id in id_list.split('^')]
|
|
|
2700 |
for brand in brands:
|
| 19399 |
kshitij.so |
2701 |
print brand
|
| 19397 |
kshitij.so |
2702 |
tm_brand = get_mongo_connection().Catalog.Deals.find_one({'brand_id':brand},{'brand':1})
|
| 19399 |
kshitij.so |
2703 |
print tm_brand
|
| 19397 |
kshitij.so |
2704 |
id_list_mapping[brand_id] = tm_brand.get('brand')
|
| 19398 |
kshitij.so |
2705 |
elif type == "subCategoryInfo":
|
| 19397 |
kshitij.so |
2706 |
subCategories = [int(subCategoryId) for subCategoryId in id_list.split('^')]
|
|
|
2707 |
for subCat in subCategories:
|
|
|
2708 |
id_list_mapping[subCat] = SUB_CATEGORY_MAP.get(subCat)
|
|
|
2709 |
else:
|
|
|
2710 |
return {}
|
|
|
2711 |
|
| 19389 |
kshitij.so |
2712 |
if mc.get("brandSubCategoryInfo") is None:
|
|
|
2713 |
collection = get_mongo_connection().Catalog.Deals
|
|
|
2714 |
result = collection.aggregate(
|
|
|
2715 |
[
|
|
|
2716 |
{'$match':{'category_id':category_id,'showDeal':1}},
|
|
|
2717 |
{"$group": { "_id": { "subCategoryId": "$subCategoryId", "brand_id": "$brand_id", "brand":"$brand","subCategory":"$subCategory" }, "count": {"$sum": 1} } }
|
|
|
2718 |
]
|
|
|
2719 |
);
|
| 19397 |
kshitij.so |
2720 |
#from pprint import pprint
|
|
|
2721 |
#pprint(result)
|
| 19389 |
kshitij.so |
2722 |
|
|
|
2723 |
subCategoryMap = {}
|
|
|
2724 |
brandMap = {}
|
|
|
2725 |
|
|
|
2726 |
for data in result['result']:
|
|
|
2727 |
result_set = data['_id']
|
|
|
2728 |
count = data['count']
|
|
|
2729 |
subCategoryId = result_set['subCategoryId']
|
|
|
2730 |
brand_id = result_set['brand_id']
|
|
|
2731 |
subCategory = result_set['subCategory']
|
|
|
2732 |
brand = result_set['brand']
|
|
|
2733 |
|
|
|
2734 |
if subCategoryMap.has_key(subCategoryId):
|
|
|
2735 |
subCategoryMap.get(subCategoryId).append({'brand_id':brand_id, 'count':count, 'subCategory':subCategory, 'brand':brand})
|
|
|
2736 |
else:
|
|
|
2737 |
subCategoryMap[subCategoryId] = [{'brand_id':brand_id, 'count':count, 'subCategory':subCategory, 'brand':brand}]
|
|
|
2738 |
|
|
|
2739 |
if brandMap.has_key(brand_id):
|
|
|
2740 |
brandMap.get(brand_id).append({'subCategoryId':subCategoryId, 'count':count, 'subCategory':subCategory, 'brand':brand})
|
|
|
2741 |
else:
|
|
|
2742 |
brandMap[brand_id] = [{'subCategoryId':subCategoryId, 'count':count, 'subCategory':subCategory, 'brand':brand}]
|
|
|
2743 |
|
|
|
2744 |
mc.set("brandSubCategoryInfo",{'subCategoryMap':subCategoryMap, 'brandMap': brandMap}, 600)
|
|
|
2745 |
|
|
|
2746 |
|
|
|
2747 |
returnMap = {}
|
|
|
2748 |
brandSubCategoryInfo = mc.get("brandSubCategoryInfo")
|
|
|
2749 |
if brandSubCategoryInfo is None:
|
| 19397 |
kshitij.so |
2750 |
return {'idListInfo':id_list_mapping,'result':[]}
|
| 19389 |
kshitij.so |
2751 |
|
|
|
2752 |
if type == "subCategoryInfo":
|
|
|
2753 |
if brandSubCategoryInfo.get('subCategoryMap') is None:
|
| 19397 |
kshitij.so |
2754 |
return {'idListInfo':id_list_mapping,'result':[]}
|
| 19389 |
kshitij.so |
2755 |
subCategories = [int(subCategoryId) for subCategoryId in id_list.split('^')]
|
|
|
2756 |
subCategoryMap = brandSubCategoryInfo.get('subCategoryMap')
|
|
|
2757 |
for subCategory in subCategories:
|
|
|
2758 |
tempList = subCategoryMap.get(subCategory)
|
|
|
2759 |
print tempList
|
|
|
2760 |
if tempList is None:
|
|
|
2761 |
continue
|
|
|
2762 |
for v in tempList:
|
|
|
2763 |
if returnMap.has_key(v['brand_id']):
|
|
|
2764 |
existing = returnMap.get(v['brand_id'])
|
|
|
2765 |
existing['count'] = existing['count'] + v['count']
|
|
|
2766 |
else:
|
|
|
2767 |
returnMap[v['brand_id']] = {'brand_id':v['brand_id'],'brand':v['brand'],'count':v['count']}
|
| 18271 |
kshitij.so |
2768 |
|
| 19389 |
kshitij.so |
2769 |
|
|
|
2770 |
elif type == "brandInfo":
|
|
|
2771 |
if brandSubCategoryInfo.get('brandMap') is None:
|
| 19397 |
kshitij.so |
2772 |
return {'idListInfo':id_list_mapping,'result':[]}
|
| 19389 |
kshitij.so |
2773 |
brands = [int(brand_id) for brand_id in id_list.split('^')]
|
|
|
2774 |
brandMap = brandSubCategoryInfo.get('brandMap')
|
|
|
2775 |
for brand_id in brands:
|
|
|
2776 |
tempList = brandMap.get(brand_id)
|
|
|
2777 |
print tempList
|
|
|
2778 |
if tempList is None:
|
|
|
2779 |
continue
|
|
|
2780 |
for v in tempList:
|
|
|
2781 |
if returnMap.has_key(v['subCategoryId']):
|
|
|
2782 |
existing = returnMap.get(v['subCategoryId'])
|
|
|
2783 |
existing['count'] = existing['count'] + v['count']
|
|
|
2784 |
else:
|
| 19390 |
kshitij.so |
2785 |
returnMap[v['subCategoryId']] = {'subCategoryId':v['subCategoryId'],'subCategory':v['subCategory'],'count':v['count']}
|
| 19389 |
kshitij.so |
2786 |
|
| 19397 |
kshitij.so |
2787 |
return {'idListInfo':id_list_mapping,'result':returnMap.values()}
|
| 19389 |
kshitij.so |
2788 |
|
|
|
2789 |
|
| 13572 |
kshitij.so |
2790 |
def main():
|
| 19389 |
kshitij.so |
2791 |
#getDealsForSearchText("20", 'Samsung', 0, 10)
|
|
|
2792 |
|
|
|
2793 |
x = getBrandSubCategoryInfo(6,"15^17","subCategoryInfo")
|
|
|
2794 |
print "==============="
|
|
|
2795 |
print x
|
| 17944 |
kshitij.so |
2796 |
|
| 13572 |
kshitij.so |
2797 |
if __name__=='__main__':
|
| 13932 |
amit.gupta |
2798 |
main()
|
| 17469 |
kshitij.so |
2799 |
|
| 17936 |
kshitij.so |
2800 |
|