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