| 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, \
|
| 19577 |
manas |
8 |
user_app_installs, appmasters, notification_campaigns, user_accounts
|
| 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,\
|
| 19654 |
kshitij.so |
13 |
get_mongo_connection_dtr_data, SUB_CATEGORY_HEADER_RANKING
|
| 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 |
|
| 21889 |
kshitij.so |
46 |
DataService.initialize()
|
| 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"}
|
| 22256 |
amit.gupta |
55 |
ONLINE_DEAL_SOURCE_MAP = {1:'AMAZON',2:'FLIPKART',3:'SNAPDEAL',5:"SHOPCLUES.COM",6:"PAYTM.COM",7:"HOMESHOP18.COM"}
|
| 14482 |
kshitij.so |
56 |
|
| 15853 |
kshitij.so |
57 |
COLLECTION_MAP = {
|
|
|
58 |
'ExceptionalNlc':'skuBundleId',
|
|
|
59 |
'SkuDealerPrices':'skuBundleId',
|
|
|
60 |
'SkuDiscountInfo':'skuBundleId',
|
|
|
61 |
'SkuSchemeDetails':'skuBundleId',
|
| 17367 |
kshitij.so |
62 |
'DealPoints':'skuBundleId',
|
|
|
63 |
'FeaturedDeals': 'skuBundleId'
|
| 15853 |
kshitij.so |
64 |
}
|
|
|
65 |
|
| 19337 |
manish.sha |
66 |
|
| 17944 |
kshitij.so |
67 |
def get_elastic_search_connection():
|
|
|
68 |
global es
|
|
|
69 |
if es is None:
|
|
|
70 |
print "Establishing connection with elastic search %s host and port %s"%(elastic_search_host,elastic_search_port)
|
|
|
71 |
es = Elasticsearch([{'host': elastic_search_host, 'port': elastic_search_port}])
|
|
|
72 |
return es
|
|
|
73 |
return es
|
|
|
74 |
|
|
|
75 |
|
| 13572 |
kshitij.so |
76 |
def get_mongo_connection(host='localhost', port=27017):
|
|
|
77 |
global con
|
|
|
78 |
if con is None:
|
|
|
79 |
print "Establishing connection %s host and port %d" %(host,port)
|
|
|
80 |
try:
|
|
|
81 |
con = pymongo.MongoClient(host, port)
|
|
|
82 |
except Exception, e:
|
|
|
83 |
print e
|
|
|
84 |
return None
|
|
|
85 |
return con
|
|
|
86 |
|
| 13907 |
kshitij.so |
87 |
def populateCashBack():
|
| 13921 |
kshitij.so |
88 |
print "Populating cashback"
|
|
|
89 |
cashBackMap = {}
|
|
|
90 |
itemCashBackMap = {}
|
| 13907 |
kshitij.so |
91 |
cashBack = list(get_mongo_connection().Catalog.CategoryCashBack.find())
|
|
|
92 |
for row in cashBack:
|
| 13970 |
kshitij.so |
93 |
temp_map = {}
|
|
|
94 |
temp_list = []
|
| 13907 |
kshitij.so |
95 |
if cashBackMap.has_key(row['source_id']):
|
|
|
96 |
arr = cashBackMap.get(row['source_id'])
|
|
|
97 |
for val in arr:
|
|
|
98 |
temp_list.append(val)
|
|
|
99 |
temp_map[row['category_id']] = row
|
|
|
100 |
temp_list.append(temp_map)
|
|
|
101 |
cashBackMap[row['source_id']] = temp_list
|
|
|
102 |
else:
|
|
|
103 |
temp_map[row['category_id']] = row
|
|
|
104 |
temp_list.append(temp_map)
|
|
|
105 |
cashBackMap[row['source_id']] = temp_list
|
| 13921 |
kshitij.so |
106 |
itemCashBack = list(get_mongo_connection().Catalog.ItemCashBack.find())
|
|
|
107 |
for row in itemCashBack:
|
| 20434 |
kshitij.so |
108 |
if not itemCashBackMap.has_key(row['sku']):
|
|
|
109 |
itemCashBackMap[row['sku']] = row
|
| 14761 |
kshitij.so |
110 |
mc.set("item_cash_back", itemCashBackMap, 24 * 60 * 60)
|
|
|
111 |
mc.set("category_cash_back", cashBackMap, 24 * 60 * 60)
|
| 13907 |
kshitij.so |
112 |
|
| 13572 |
kshitij.so |
113 |
def addCategoryDiscount(data):
|
| 13970 |
kshitij.so |
114 |
collection = get_mongo_connection().Catalog.CategoryDiscount
|
| 13572 |
kshitij.so |
115 |
query = []
|
|
|
116 |
data['brand'] = data['brand'].strip().upper()
|
| 13970 |
kshitij.so |
117 |
data['discountType'] = data['discountType'].upper().strip()
|
| 13572 |
kshitij.so |
118 |
query.append({"brand":data['brand']})
|
|
|
119 |
query.append({"category_id":data['category_id']})
|
|
|
120 |
r = collection.find({"$and":query})
|
|
|
121 |
if r.count() > 0:
|
| 13639 |
kshitij.so |
122 |
return {0:"Brand & Category info already present."}
|
| 13572 |
kshitij.so |
123 |
else:
|
|
|
124 |
collection.insert(data)
|
| 13970 |
kshitij.so |
125 |
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 |
126 |
return {1:"Data added successfully"}
|
| 13572 |
kshitij.so |
127 |
|
| 13970 |
kshitij.so |
128 |
def updateCategoryDiscount(data,_id):
|
|
|
129 |
try:
|
|
|
130 |
collection = get_mongo_connection().Catalog.CategoryDiscount
|
|
|
131 |
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)
|
|
|
132 |
get_mongo_connection().Catalog.MasterData.update({'brand':data['brand'],'category_id':data['category_id']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
|
|
133 |
return {1:"Data updated successfully"}
|
|
|
134 |
except:
|
|
|
135 |
return {0:"Data not updated."}
|
|
|
136 |
|
|
|
137 |
|
| 13572 |
kshitij.so |
138 |
def getAllCategoryDiscount():
|
|
|
139 |
data = []
|
| 13970 |
kshitij.so |
140 |
collection = get_mongo_connection().Catalog.CategoryDiscount
|
| 13572 |
kshitij.so |
141 |
cursor = collection.find()
|
|
|
142 |
for val in cursor:
|
|
|
143 |
data.append(val)
|
|
|
144 |
return data
|
|
|
145 |
|
| 14553 |
kshitij.so |
146 |
def __getBundledSkusfromSku(sku):
|
|
|
147 |
masterData = get_mongo_connection().Catalog.MasterData.find_one({"_id":sku},{"skuBundleId":1})
|
|
|
148 |
if masterData is not None:
|
|
|
149 |
return list(get_mongo_connection().Catalog.MasterData.find({"skuBundleId":masterData.get('skuBundleId')},{'_id':1,'skuBundleId':1}))
|
|
|
150 |
else:
|
|
|
151 |
return []
|
| 13572 |
kshitij.so |
152 |
|
| 15853 |
kshitij.so |
153 |
def addSchemeDetailsForSku(data):
|
|
|
154 |
collection = get_mongo_connection().Catalog.SkuSchemeDetails
|
|
|
155 |
result = collection.find_one({'skuBundleId':data['skuBundleId']})
|
|
|
156 |
if result is None:
|
| 14553 |
kshitij.so |
157 |
collection.insert(data)
|
| 15853 |
kshitij.so |
158 |
get_mongo_connection().Catalog.MasterData.update({'skuBundleId':data['skuBundleId']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
| 14553 |
kshitij.so |
159 |
return {1:"Data added successfully"}
|
| 15853 |
kshitij.so |
160 |
return {1:"BundleId info already present"}
|
|
|
161 |
|
| 14069 |
kshitij.so |
162 |
def getAllSkuWiseSchemeDetails(offset, limit):
|
| 13572 |
kshitij.so |
163 |
data = []
|
| 13970 |
kshitij.so |
164 |
collection = get_mongo_connection().Catalog.SkuSchemeDetails
|
| 14071 |
kshitij.so |
165 |
cursor = collection.find().skip(offset).limit(limit)
|
| 13572 |
kshitij.so |
166 |
for val in cursor:
|
| 15853 |
kshitij.so |
167 |
master = get_mongo_connection().Catalog.MasterData.find_one({'skuBundleId':val['skuBundleId']})
|
|
|
168 |
if master is not None:
|
|
|
169 |
val['brand'] = master['brand']
|
|
|
170 |
val['source_product_name'] = master['source_product_name']
|
| 14069 |
kshitij.so |
171 |
else:
|
|
|
172 |
val['brand'] = ""
|
|
|
173 |
val['source_product_name'] = ""
|
| 13572 |
kshitij.so |
174 |
data.append(val)
|
|
|
175 |
return data
|
|
|
176 |
|
| 15853 |
kshitij.so |
177 |
def addSkuDiscountInfo(data):
|
|
|
178 |
collection = get_mongo_connection().Catalog.SkuDiscountInfo
|
|
|
179 |
cursor = collection.find_one({"skuBundleId":data['skuBundleId']})
|
|
|
180 |
if cursor is not None:
|
|
|
181 |
return {0:"BundleId information already present."}
|
| 13572 |
kshitij.so |
182 |
else:
|
| 15853 |
kshitij.so |
183 |
collection.insert(data)
|
|
|
184 |
get_mongo_connection().Catalog.MasterData.update({'skuBundleId':data['skuBundleId']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
| 13639 |
kshitij.so |
185 |
return {1:"Data added successfully"}
|
| 13572 |
kshitij.so |
186 |
|
| 13970 |
kshitij.so |
187 |
def getallSkuDiscountInfo(offset, limit):
|
| 13572 |
kshitij.so |
188 |
data = []
|
| 13970 |
kshitij.so |
189 |
collection = get_mongo_connection().Catalog.SkuDiscountInfo
|
|
|
190 |
cursor = collection.find().skip(offset).limit(limit)
|
| 13572 |
kshitij.so |
191 |
for val in cursor:
|
| 15853 |
kshitij.so |
192 |
master = get_mongo_connection().Catalog.MasterData.find_one({'skuBundleId':val['skuBundleId']})
|
|
|
193 |
if master is not None:
|
|
|
194 |
val['brand'] = master['brand']
|
|
|
195 |
val['source_product_name'] = master['source_product_name']
|
| 13970 |
kshitij.so |
196 |
else:
|
|
|
197 |
val['brand'] = ""
|
|
|
198 |
val['source_product_name'] = ""
|
| 13572 |
kshitij.so |
199 |
data.append(val)
|
|
|
200 |
return data
|
|
|
201 |
|
| 13970 |
kshitij.so |
202 |
def updateSkuDiscount(data,_id):
|
|
|
203 |
try:
|
|
|
204 |
collection = get_mongo_connection().Catalog.SkuDiscountInfo
|
|
|
205 |
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 |
206 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['skuBundleId']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
| 13970 |
kshitij.so |
207 |
return {1:"Data updated successfully"}
|
|
|
208 |
except:
|
|
|
209 |
return {0:"Data not updated."}
|
|
|
210 |
|
|
|
211 |
|
| 15853 |
kshitij.so |
212 |
def addExceptionalNlc(data):
|
|
|
213 |
collection = get_mongo_connection().Catalog.ExceptionalNlc
|
|
|
214 |
cursor = collection.find_one({"skuBundleId":data['skuBundleId']})
|
|
|
215 |
if cursor is not None:
|
|
|
216 |
return {0:"BundleId information already present."}
|
| 13572 |
kshitij.so |
217 |
else:
|
| 15853 |
kshitij.so |
218 |
collection.insert(data)
|
|
|
219 |
get_mongo_connection().Catalog.MasterData.update({'skuBundleId':data['skuBundleId']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
| 13639 |
kshitij.so |
220 |
return {1:"Data added successfully"}
|
| 13572 |
kshitij.so |
221 |
|
| 13970 |
kshitij.so |
222 |
def getAllExceptionlNlcItems(offset, limit):
|
| 13572 |
kshitij.so |
223 |
data = []
|
| 13970 |
kshitij.so |
224 |
collection = get_mongo_connection().Catalog.ExceptionalNlc
|
| 14071 |
kshitij.so |
225 |
cursor = collection.find().skip(offset).limit(limit)
|
| 13572 |
kshitij.so |
226 |
for val in cursor:
|
| 15853 |
kshitij.so |
227 |
master = get_mongo_connection().Catalog.MasterData.find_one({'skuBundleId':val['skuBundleId']})
|
|
|
228 |
if master is not None:
|
|
|
229 |
val['brand'] = master['brand']
|
|
|
230 |
val['source_product_name'] = master['source_product_name']
|
| 13970 |
kshitij.so |
231 |
else:
|
|
|
232 |
val['brand'] = ""
|
|
|
233 |
val['source_product_name'] = ""
|
| 13572 |
kshitij.so |
234 |
data.append(val)
|
|
|
235 |
return data
|
|
|
236 |
|
| 14005 |
amit.gupta |
237 |
def getMerchantOrdersByUser(userId, page=1, window=50, searchMap={}):
|
|
|
238 |
if searchMap is None:
|
|
|
239 |
searchMap = {}
|
| 13603 |
amit.gupta |
240 |
if page==None:
|
|
|
241 |
page = 1
|
|
|
242 |
|
|
|
243 |
if window==None:
|
|
|
244 |
window = 50
|
|
|
245 |
result = {}
|
| 13582 |
amit.gupta |
246 |
skip = (page-1)*window
|
| 14005 |
amit.gupta |
247 |
|
| 14353 |
amit.gupta |
248 |
if userId is not None:
|
|
|
249 |
searchMap['userId'] = userId
|
| 13603 |
amit.gupta |
250 |
collection = get_mongo_connection().Dtr.merchantOrder
|
| 14609 |
amit.gupta |
251 |
cursor = collection.find(searchMap).sort("orderId",-1)
|
| 13603 |
amit.gupta |
252 |
total_count = cursor.count()
|
|
|
253 |
pages = total_count/window + (0 if total_count%window==0 else 1)
|
|
|
254 |
print "total_count", total_count
|
|
|
255 |
if total_count > skip:
|
| 13999 |
amit.gupta |
256 |
cursor = cursor.skip(skip).limit(window)
|
| 13603 |
amit.gupta |
257 |
orders = []
|
|
|
258 |
for order in cursor:
|
| 14002 |
amit.gupta |
259 |
del(order["_id"])
|
|
|
260 |
orders.append(order)
|
| 13603 |
amit.gupta |
261 |
result['data'] = orders
|
|
|
262 |
result['window'] = window
|
|
|
263 |
result['totalCount'] = total_count
|
|
|
264 |
result['currCount'] = cursor.count()
|
|
|
265 |
result['totalPages'] = pages
|
|
|
266 |
result['currPage'] = page
|
|
|
267 |
return result
|
|
|
268 |
else:
|
|
|
269 |
return result
|
| 13630 |
kshitij.so |
270 |
|
| 13927 |
amit.gupta |
271 |
def getRefunds(userId, page=1, window=10):
|
|
|
272 |
if page==None:
|
|
|
273 |
page = 1
|
|
|
274 |
|
|
|
275 |
if window==None:
|
| 13995 |
amit.gupta |
276 |
window = 10
|
| 13927 |
amit.gupta |
277 |
result = {}
|
|
|
278 |
skip = (page-1)*window
|
| 16737 |
amit.gupta |
279 |
con = get_mongo_connection()
|
|
|
280 |
collection = con.Dtr.refund
|
|
|
281 |
user = con.Dtr.user
|
| 16754 |
amit.gupta |
282 |
credited = user.find_one({"userId":userId})
|
|
|
283 |
if credited:
|
|
|
284 |
credited = credited.get("credited")
|
|
|
285 |
else:
|
|
|
286 |
credited=0
|
|
|
287 |
|
| 13927 |
amit.gupta |
288 |
cursor = collection.find({"userId":userId})
|
|
|
289 |
total_count = cursor.count()
|
|
|
290 |
pages = total_count/window + (0 if total_count%window==0 else 1)
|
|
|
291 |
print "total_count", total_count
|
|
|
292 |
if total_count > skip:
|
| 14668 |
amit.gupta |
293 |
cursor = cursor.skip(skip).limit(window).sort([('batch',-1)])
|
| 13927 |
amit.gupta |
294 |
refunds = []
|
|
|
295 |
for refund in cursor:
|
|
|
296 |
del(refund["_id"])
|
| 19511 |
manas |
297 |
if (refund["type"]) == CREDIT_TYPE_REFUND:
|
| 19493 |
manas |
298 |
batchDetails = fetchCrmRefundByBatchId(refund["batch"])
|
|
|
299 |
referenceNumber = batchDetails.get('reference_no')
|
| 19511 |
manas |
300 |
refund["description"] = "Refunded against Saholic order #%s"%(referenceNumber)
|
|
|
301 |
elif (refund["type"]) == CREDIT_TYPE_ADJUSTMENT:
|
| 19493 |
manas |
302 |
batchDetails = fetchCrmRefundByBatchId(refund["batch"])
|
|
|
303 |
referenceNumber = batchDetails.get('reference_no')
|
| 19517 |
manas |
304 |
referenceStore = REVERSE_SOURCE_MAP.get(batchDetails.get('store'))
|
| 19784 |
manas |
305 |
refund["description"] = "Adjusted against %s order #%s"%(referenceStore,referenceNumber)
|
|
|
306 |
elif (refund["type"]) == CREDIT_TYPE_OFFER:
|
|
|
307 |
refund["description"] = "April Accessories Cashback Offer"
|
| 19493 |
manas |
308 |
else:
|
|
|
309 |
refund["description"] = ""
|
| 13927 |
amit.gupta |
310 |
refunds.append(refund)
|
| 16754 |
amit.gupta |
311 |
result['credited'] = credited
|
| 13927 |
amit.gupta |
312 |
result['data'] = refunds
|
|
|
313 |
result['window'] = window
|
|
|
314 |
result['totalCount'] = total_count
|
|
|
315 |
result['currCount'] = cursor.count()
|
|
|
316 |
result['totalPages'] = pages
|
|
|
317 |
result['currPage'] = page
|
|
|
318 |
return result
|
|
|
319 |
else:
|
|
|
320 |
return result
|
|
|
321 |
|
|
|
322 |
def getPendingRefunds(userId):
|
| 13991 |
amit.gupta |
323 |
print type(userId)
|
| 13927 |
amit.gupta |
324 |
result = get_mongo_connection().Dtr.merchantOrder\
|
|
|
325 |
.aggregate([
|
| 16398 |
amit.gupta |
326 |
{'$match':{'subOrders.cashBackStatus':CB_APPROVED, 'userId':userId}},
|
| 13927 |
amit.gupta |
327 |
{'$unwind':"$subOrders"},
|
| 16398 |
amit.gupta |
328 |
{'$match':{'subOrders.cashBackStatus':CB_APPROVED}},
|
| 13927 |
amit.gupta |
329 |
{
|
|
|
330 |
'$group':{
|
|
|
331 |
'_id':None,
|
|
|
332 |
'amount': { '$sum':'$subOrders.cashBackAmount'},
|
|
|
333 |
}
|
|
|
334 |
}
|
| 13987 |
amit.gupta |
335 |
])['result']
|
|
|
336 |
|
|
|
337 |
if len(result)>0:
|
|
|
338 |
result = result[0]
|
|
|
339 |
result.pop("_id")
|
|
|
340 |
else:
|
|
|
341 |
result={}
|
|
|
342 |
result['amount'] = 0.0
|
| 14305 |
amit.gupta |
343 |
result['nextCredit'] = datetime.strftime(next_weekday(datetime.now(), int(PythonPropertyReader.getConfig('CREDIT_DAY_OF_WEEK'))),"%Y-%m-%d %H:%M:%S")
|
| 13927 |
amit.gupta |
344 |
return result
|
| 14037 |
kshitij.so |
345 |
|
| 14671 |
amit.gupta |
346 |
def getPendingCashbacks(userId):
|
|
|
347 |
result = get_mongo_connection().Dtr.merchantOrder\
|
|
|
348 |
.aggregate([
|
| 16398 |
amit.gupta |
349 |
{'$match':{'subOrders.cashBackStatus':CB_PENDING, 'userId':userId}},
|
| 14671 |
amit.gupta |
350 |
{'$unwind':"$subOrders"},
|
| 16398 |
amit.gupta |
351 |
{'$match':{'subOrders.cashBackStatus':CB_PENDING}},
|
| 14671 |
amit.gupta |
352 |
{
|
|
|
353 |
'$group':{
|
|
|
354 |
'_id':None,
|
|
|
355 |
'amount': { '$sum':'$subOrders.cashBackAmount'},
|
|
|
356 |
}
|
|
|
357 |
}
|
|
|
358 |
])['result']
|
|
|
359 |
|
|
|
360 |
if len(result)>0:
|
|
|
361 |
result = result[0]
|
|
|
362 |
result.pop("_id")
|
|
|
363 |
else:
|
|
|
364 |
result={}
|
|
|
365 |
result['amount'] = 0.0
|
|
|
366 |
return result
|
|
|
367 |
|
| 17369 |
kshitij.so |
368 |
def __constructDummyDealObject(skuBundleId):
|
|
|
369 |
temp =[]
|
| 19193 |
kshitij.so |
370 |
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 |
371 |
for d in deals:
|
|
|
372 |
d['persPoints'] = 0
|
| 19575 |
kshitij.so |
373 |
d['dealRankPoints'] = 0
|
| 17369 |
kshitij.so |
374 |
temp.append(d)
|
|
|
375 |
return temp
|
|
|
376 |
|
|
|
377 |
|
|
|
378 |
|
| 14037 |
kshitij.so |
379 |
def __populateCache(userId):
|
| 17369 |
kshitij.so |
380 |
try:
|
|
|
381 |
if mc.get("featured_deals") is None:
|
|
|
382 |
__populateFeaturedDeals()
|
|
|
383 |
featuredDeals = mc.get("featured_deals")
|
|
|
384 |
|
|
|
385 |
except Exception as e:
|
|
|
386 |
print traceback.print_exc()
|
| 17469 |
kshitij.so |
387 |
featuredDeals = {3:{},5:{},6:{}}
|
| 17369 |
kshitij.so |
388 |
|
| 19559 |
kshitij.so |
389 |
|
| 22240 |
amit.gupta |
390 |
#Not taking accessories into account
|
| 19559 |
kshitij.so |
391 |
featuredDeals.pop(6,None)
|
| 19597 |
kshitij.so |
392 |
print featuredDeals
|
| 19559 |
kshitij.so |
393 |
|
| 17369 |
kshitij.so |
394 |
fd_bundles = []
|
|
|
395 |
|
|
|
396 |
for catMap in featuredDeals.itervalues():
|
|
|
397 |
for fd_map in catMap.itervalues():
|
| 17541 |
kshitij.so |
398 |
if not fd_map.get('skuBundleId') in fd_bundles:
|
|
|
399 |
fd_bundles.append(fd_map.get('skuBundleId'))
|
| 17369 |
kshitij.so |
400 |
|
| 14037 |
kshitij.so |
401 |
print "Populating memcache for userId",userId
|
|
|
402 |
outer_query = []
|
| 16067 |
kshitij.so |
403 |
outer_query.append({ "$or": [ { "showDeal": 1} , { "prepaidDeal": 1 } ] })
|
| 14037 |
kshitij.so |
404 |
query = {}
|
| 16170 |
kshitij.so |
405 |
query['$gt'] = -100
|
| 14037 |
kshitij.so |
406 |
outer_query.append({'totalPoints':query})
|
| 19559 |
kshitij.so |
407 |
outer_query.append({'category_id':{"$in":[3,5]}})
|
| 14037 |
kshitij.so |
408 |
brandPrefMap = {}
|
|
|
409 |
pricePrefMap = {}
|
|
|
410 |
actionsMap = {}
|
| 19596 |
kshitij.so |
411 |
try:
|
|
|
412 |
brand_p = session.query(price_preferences).filter_by(user_id=userId).all()
|
|
|
413 |
for x in brand_p:
|
|
|
414 |
pricePrefMap[x.category_id] = [x.min_price,x.max_price]
|
|
|
415 |
for x in session.query(brand_preferences).filter_by(user_id=userId).all():
|
|
|
416 |
temp_map = {}
|
|
|
417 |
if brandPrefMap.has_key((x.brand).strip().upper()):
|
|
|
418 |
val = brandPrefMap.get((x.brand).strip().upper())
|
|
|
419 |
temp_map[x.category_id] = 1 if x.status == 'show' else 0
|
|
|
420 |
val.append(temp_map)
|
|
|
421 |
else:
|
|
|
422 |
temp = []
|
|
|
423 |
temp_map[x.category_id] = 1 if x.status == 'show' else 0
|
|
|
424 |
temp.append(temp_map)
|
|
|
425 |
brandPrefMap[(x.brand).strip().upper()] = temp
|
|
|
426 |
|
|
|
427 |
for x in session.query(user_actions).filter_by(user_id=userId).all():
|
|
|
428 |
actionsMap[x.store_product_id] = 1 if x.action == 'like' else 0
|
|
|
429 |
except:
|
|
|
430 |
pass
|
|
|
431 |
finally:
|
|
|
432 |
session.close()
|
| 19575 |
kshitij.so |
433 |
|
| 19193 |
kshitij.so |
434 |
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 |
435 |
mobile_deals = []
|
|
|
436 |
tablet_deals = []
|
| 19559 |
kshitij.so |
437 |
#accessories_deals = []
|
| 14037 |
kshitij.so |
438 |
for deal in all_deals:
|
| 19135 |
kshitij.so |
439 |
|
| 17369 |
kshitij.so |
440 |
try:
|
|
|
441 |
fd_bundles.remove(deal.get('skuBundleId'))
|
|
|
442 |
except:
|
|
|
443 |
pass
|
|
|
444 |
|
| 14037 |
kshitij.so |
445 |
if actionsMap.get(deal['_id']) == 0:
|
|
|
446 |
fav_weight =.25
|
|
|
447 |
elif actionsMap.get(deal['_id']) == 1:
|
|
|
448 |
fav_weight = 1.5
|
|
|
449 |
else:
|
|
|
450 |
fav_weight = 1
|
|
|
451 |
|
|
|
452 |
if brandPrefMap.get(deal['brand'].strip().upper()) is not None:
|
| 17469 |
kshitij.so |
453 |
|
| 14037 |
kshitij.so |
454 |
brand_weight = 1
|
|
|
455 |
for brandInfo in brandPrefMap.get(deal['brand'].strip().upper()):
|
|
|
456 |
if brandInfo.get(deal['category_id']) is not None:
|
|
|
457 |
if brandInfo.get(deal['category_id']) == 1:
|
| 14055 |
kshitij.so |
458 |
brand_weight = 2.0
|
| 14037 |
kshitij.so |
459 |
else:
|
|
|
460 |
brand_weight = 1
|
|
|
461 |
|
|
|
462 |
if pricePrefMap.get(deal['category_id']) is not None:
|
|
|
463 |
|
|
|
464 |
if deal['available_price'] >= pricePrefMap.get(deal['category_id'])[0] and deal['available_price'] <= pricePrefMap.get(deal['category_id'])[1]:
|
|
|
465 |
asp_weight = 1.5
|
|
|
466 |
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]:
|
|
|
467 |
asp_weight = 1.2
|
|
|
468 |
else:
|
|
|
469 |
asp_weight = 1
|
|
|
470 |
else:
|
|
|
471 |
asp_weight = 1
|
|
|
472 |
|
|
|
473 |
persPoints = deal['totalPoints'] * fav_weight * brand_weight * asp_weight
|
|
|
474 |
deal['persPoints'] = persPoints
|
|
|
475 |
|
|
|
476 |
if deal['category_id'] ==3:
|
|
|
477 |
mobile_deals.append(deal)
|
|
|
478 |
elif deal['category_id'] ==5:
|
|
|
479 |
tablet_deals.append(deal)
|
| 19559 |
kshitij.so |
480 |
#elif deal['category_id'] ==6:
|
|
|
481 |
# accessories_deals.append(deal)
|
| 14037 |
kshitij.so |
482 |
else:
|
|
|
483 |
continue
|
|
|
484 |
|
| 17367 |
kshitij.so |
485 |
mobile_deals = sorted(mobile_deals, key = lambda x: (x['persPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
|
|
|
486 |
tablet_deals = sorted(tablet_deals, key = lambda x: (x['persPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
|
| 19559 |
kshitij.so |
487 |
#accessories_deals = sorted(accessories_deals, key = lambda x: (x['persPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
|
| 17367 |
kshitij.so |
488 |
|
|
|
489 |
|
| 17369 |
kshitij.so |
490 |
if len(fd_bundles) > 0:
|
|
|
491 |
print "There is still bundle in feature deals with points less than -100.Lets add info"
|
|
|
492 |
for skuBundleId in fd_bundles:
|
|
|
493 |
dummyDealObjList = __constructDummyDealObject(skuBundleId)
|
|
|
494 |
for dummyDealObj in dummyDealObjList:
|
|
|
495 |
if dummyDealObj['category_id'] ==3:
|
|
|
496 |
mobile_deals.append(dummyDealObj)
|
|
|
497 |
elif dummyDealObj['category_id'] ==5:
|
|
|
498 |
tablet_deals.append(dummyDealObj)
|
| 19559 |
kshitij.so |
499 |
#elif dummyDealObj['category_id'] ==6:
|
|
|
500 |
# accessories_deals.append(dummyDealObj)
|
| 17369 |
kshitij.so |
501 |
else:
|
|
|
502 |
pass
|
|
|
503 |
|
| 17469 |
kshitij.so |
504 |
for super_category, categoryFeaturedDeals in featuredDeals.iteritems():
|
|
|
505 |
for val in categoryFeaturedDeals.itervalues():
|
|
|
506 |
dummyDealObjList = __constructDummyDealObject(val.get('skuBundleId'))
|
|
|
507 |
for dummyDealObj in dummyDealObjList:
|
|
|
508 |
if super_category == dummyDealObj['category_id']:
|
|
|
509 |
continue
|
|
|
510 |
|
|
|
511 |
if super_category ==3:
|
|
|
512 |
mobile_deals.append(dummyDealObj)
|
|
|
513 |
elif super_category ==5:
|
|
|
514 |
tablet_deals.append(dummyDealObj)
|
| 19559 |
kshitij.so |
515 |
#elif super_category ==6:
|
|
|
516 |
# accessories_deals.append(dummyDealObj)
|
| 17469 |
kshitij.so |
517 |
else:
|
|
|
518 |
pass
|
|
|
519 |
|
| 17367 |
kshitij.so |
520 |
sortedMapMobiles = {}
|
|
|
521 |
rankMapMobiles = {}
|
|
|
522 |
rankMobiles = 0
|
|
|
523 |
|
|
|
524 |
blockedRanksMobiles = []
|
|
|
525 |
blockedSkuBundlesMobiles = []
|
|
|
526 |
blockedInfoMobiles = {}
|
|
|
527 |
|
|
|
528 |
featuredDealsMobiles = featuredDeals.get(3)
|
|
|
529 |
|
|
|
530 |
for k, v in featuredDealsMobiles.iteritems():
|
| 17469 |
kshitij.so |
531 |
blockedRanksMobiles.append(k-1)
|
|
|
532 |
blockedSkuBundlesMobiles.append(v.get('skuBundleId'))
|
| 17367 |
kshitij.so |
533 |
|
|
|
534 |
|
|
|
535 |
for sorted_deal in mobile_deals:
|
| 17369 |
kshitij.so |
536 |
|
| 17367 |
kshitij.so |
537 |
while(True):
|
|
|
538 |
if rankMobiles in blockedRanksMobiles:
|
|
|
539 |
rankMobiles = rankMobiles +1
|
|
|
540 |
else:
|
|
|
541 |
break
|
|
|
542 |
|
|
|
543 |
if sorted_deal['skuBundleId'] in blockedSkuBundlesMobiles:
|
|
|
544 |
if blockedInfoMobiles.has_key(sorted_deal['skuBundleId']):
|
|
|
545 |
blockedInfoMobiles.get(sorted_deal['skuBundleId']).append(sorted_deal)
|
|
|
546 |
else:
|
|
|
547 |
blockedInfoMobiles[sorted_deal['skuBundleId']] = [sorted_deal]
|
|
|
548 |
continue
|
|
|
549 |
|
|
|
550 |
if sortedMapMobiles.get(sorted_deal['skuBundleId']) is None:
|
|
|
551 |
sortedMapMobiles[sorted_deal['skuBundleId']] = {rankMobiles:[sorted_deal]}
|
|
|
552 |
rankMapMobiles[rankMobiles] = (sortedMapMobiles[sorted_deal['skuBundleId']].values())[0]
|
|
|
553 |
rankMobiles = rankMobiles +1
|
|
|
554 |
else:
|
|
|
555 |
for temp_list in sortedMapMobiles.get(sorted_deal['skuBundleId']).itervalues():
|
|
|
556 |
temp_list.append(sorted_deal)
|
|
|
557 |
rankMapMobiles[(sortedMapMobiles.get(sorted_deal['skuBundleId']).keys())[0]] = temp_list
|
|
|
558 |
|
|
|
559 |
|
|
|
560 |
for rank in blockedRanksMobiles:
|
| 17369 |
kshitij.so |
561 |
if blockedInfoMobiles.get((featuredDealsMobiles.get(rank+1)).get('skuBundleId')) is not None:
|
|
|
562 |
rankMapMobiles[rank] = blockedInfoMobiles.get((featuredDealsMobiles.get(rank+1)).get('skuBundleId'))
|
| 17367 |
kshitij.so |
563 |
|
|
|
564 |
|
|
|
565 |
sortedMapTablets = {}
|
|
|
566 |
rankMapTablets = {}
|
|
|
567 |
rankTablets = 0
|
|
|
568 |
|
|
|
569 |
blockedRanksTablets = []
|
|
|
570 |
blockedSkuBundlesTablets = []
|
|
|
571 |
blockedInfoTablets = {}
|
|
|
572 |
|
|
|
573 |
featuredDealsTablets = featuredDeals.get(5)
|
|
|
574 |
|
|
|
575 |
|
|
|
576 |
for k, v in featuredDealsTablets.iteritems():
|
| 17469 |
kshitij.so |
577 |
blockedRanksTablets.append(k-1)
|
|
|
578 |
blockedSkuBundlesTablets.append(v.get('skuBundleId'))
|
|
|
579 |
|
| 17367 |
kshitij.so |
580 |
|
|
|
581 |
for sorted_deal in tablet_deals:
|
|
|
582 |
while(True):
|
|
|
583 |
if rankTablets in blockedRanksTablets:
|
|
|
584 |
rankTablets = rankTablets +1
|
|
|
585 |
else:
|
|
|
586 |
break
|
|
|
587 |
|
|
|
588 |
if sorted_deal['skuBundleId'] in blockedSkuBundlesTablets:
|
|
|
589 |
if blockedInfoTablets.has_key(sorted_deal['skuBundleId']):
|
|
|
590 |
blockedInfoTablets.get(sorted_deal['skuBundleId']).append(sorted_deal)
|
|
|
591 |
else:
|
|
|
592 |
blockedInfoTablets[sorted_deal['skuBundleId']] = [sorted_deal]
|
|
|
593 |
continue
|
|
|
594 |
|
|
|
595 |
if sortedMapTablets.get(sorted_deal['skuBundleId']) is None:
|
|
|
596 |
sortedMapTablets[sorted_deal['skuBundleId']] = {rankTablets:[sorted_deal]}
|
|
|
597 |
rankMapTablets[rankTablets] = (sortedMapTablets[sorted_deal['skuBundleId']].values())[0]
|
|
|
598 |
rankTablets = rankTablets +1
|
|
|
599 |
else:
|
|
|
600 |
for temp_list in sortedMapTablets.get(sorted_deal['skuBundleId']).itervalues():
|
|
|
601 |
temp_list.append(sorted_deal)
|
|
|
602 |
rankMapTablets[(sortedMapTablets.get(sorted_deal['skuBundleId']).keys())[0]] = temp_list
|
|
|
603 |
|
|
|
604 |
for rank in blockedRanksTablets:
|
| 17369 |
kshitij.so |
605 |
if blockedInfoTablets.get((featuredDealsTablets.get(rank+1)).get('skuBundleId')) is not None:
|
|
|
606 |
rankMapTablets[rank] = blockedInfoTablets.get((featuredDealsTablets.get(rank+1)).get('skuBundleId'))
|
| 17469 |
kshitij.so |
607 |
|
| 17367 |
kshitij.so |
608 |
|
| 19559 |
kshitij.so |
609 |
# sortedMapAccessories = {}
|
|
|
610 |
# rankMapAccessories = {}
|
|
|
611 |
# rankAccessories = 0
|
|
|
612 |
#
|
|
|
613 |
# blockedRanksAccessories = []
|
|
|
614 |
# blockedSkuBundlesAccessories = []
|
|
|
615 |
# blockedInfoAccessories = {}
|
|
|
616 |
#
|
|
|
617 |
# featuredDealsAccessories = featuredDeals.get(6)
|
|
|
618 |
#
|
|
|
619 |
# for k, v in featuredDealsAccessories.iteritems():
|
|
|
620 |
# blockedRanksAccessories.append(k-1)
|
|
|
621 |
# blockedSkuBundlesAccessories.append(v.get('skuBundleId'))
|
|
|
622 |
#
|
|
|
623 |
#
|
|
|
624 |
# for sorted_deal in accessories_deals:
|
|
|
625 |
#
|
|
|
626 |
# while(True):
|
|
|
627 |
# if rankAccessories in blockedRanksAccessories:
|
|
|
628 |
# rankAccessories = rankAccessories +1
|
|
|
629 |
# else:
|
|
|
630 |
# break
|
|
|
631 |
#
|
|
|
632 |
# if sorted_deal['skuBundleId'] in blockedSkuBundlesAccessories:
|
|
|
633 |
# if blockedInfoAccessories.has_key(sorted_deal['skuBundleId']):
|
|
|
634 |
# blockedInfoAccessories.get(sorted_deal['skuBundleId']).append(sorted_deal)
|
|
|
635 |
# else:
|
|
|
636 |
# blockedInfoAccessories[sorted_deal['skuBundleId']] = [sorted_deal]
|
|
|
637 |
# continue
|
|
|
638 |
#
|
|
|
639 |
# if sortedMapAccessories.get(sorted_deal['skuBundleId']) is None:
|
|
|
640 |
# sortedMapAccessories[sorted_deal['skuBundleId']] = {rankAccessories:[sorted_deal]}
|
|
|
641 |
# rankMapAccessories[rankAccessories] = (sortedMapAccessories[sorted_deal['skuBundleId']].values())[0]
|
|
|
642 |
# rankAccessories = rankAccessories +1
|
|
|
643 |
# else:
|
|
|
644 |
# for temp_list in sortedMapAccessories.get(sorted_deal['skuBundleId']).itervalues():
|
|
|
645 |
# temp_list.append(sorted_deal)
|
|
|
646 |
# rankMapAccessories[(sortedMapAccessories.get(sorted_deal['skuBundleId']).keys())[0]] = temp_list
|
|
|
647 |
#
|
|
|
648 |
#
|
|
|
649 |
# for rank in blockedRanksAccessories:
|
|
|
650 |
# if blockedInfoAccessories.get((featuredDealsAccessories.get(rank+1)).get('skuBundleId')) is not None:
|
|
|
651 |
# rankMapAccessories[rank] = blockedInfoAccessories.get((featuredDealsAccessories.get(rank+1)).get('skuBundleId'))
|
|
|
652 |
#
|
| 22240 |
amit.gupta |
653 |
# specialOffer = None
|
|
|
654 |
# promoOffer = get_mongo_connection().Catalog.PromoOffer.find_one({'user_id':userId})
|
|
|
655 |
# try:
|
|
|
656 |
# if promoOffer is not None:
|
|
|
657 |
# offer = get_mongo_connection().Catalog.Promotions.find_one({'_id':promoOffer.get('offer_id')})
|
|
|
658 |
# if offer is None:
|
|
|
659 |
# raise
|
|
|
660 |
# promo = Promotion(offer.get('_id'),offer.get('offer_name'),offer.get('offer_description') , offer.get('categories_applicable'), offer.get('sub_categories_not_applicable'),
|
|
|
661 |
# 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'),
|
|
|
662 |
# promoOffer.get('pending_order_value'), promoOffer.get('delivered_order_value'), promoOffer.get('last_run_timestamp'))
|
|
|
663 |
#
|
|
|
664 |
# specialOffer = promo
|
|
|
665 |
# except:
|
|
|
666 |
# traceback.print_exc()
|
| 19559 |
kshitij.so |
667 |
|
|
|
668 |
|
| 22240 |
amit.gupta |
669 |
mem_cache_val = {3:mobile_deals, 5:tablet_deals,"3_rankMap": rankMapMobiles,"5_rankMap": rankMapTablets}
|
| 19559 |
kshitij.so |
670 |
mc.set(str(userId), mem_cache_val)
|
|
|
671 |
|
|
|
672 |
def __populateCacheForAccessories(userId):
|
|
|
673 |
try:
|
|
|
674 |
if mc.get("featured_deals") is None:
|
|
|
675 |
__populateFeaturedDeals()
|
|
|
676 |
featuredDeals = mc.get("featured_deals")
|
|
|
677 |
|
|
|
678 |
except Exception as e:
|
|
|
679 |
print traceback.print_exc()
|
|
|
680 |
featuredDeals = {3:{},5:{},6:{}}
|
|
|
681 |
|
|
|
682 |
|
|
|
683 |
#Not taking into account mobiles, tablets
|
|
|
684 |
featuredDeals.pop(3,None)
|
|
|
685 |
featuredDeals.pop(5,None)
|
|
|
686 |
|
| 20009 |
kshitij.so |
687 |
print "featuredDeals are ",featuredDeals
|
|
|
688 |
|
| 19559 |
kshitij.so |
689 |
fd_bundles = []
|
|
|
690 |
|
|
|
691 |
for catMap in featuredDeals.itervalues():
|
|
|
692 |
for fd_map in catMap.itervalues():
|
|
|
693 |
if not fd_map.get('skuBundleId') in fd_bundles:
|
|
|
694 |
fd_bundles.append(fd_map.get('skuBundleId'))
|
|
|
695 |
|
|
|
696 |
print "Populating accessory memcache for userId",userId
|
|
|
697 |
outer_query = []
|
|
|
698 |
outer_query.append({ "$or": [ { "showDeal": 1} , { "prepaidDeal": 1 } ] })
|
|
|
699 |
query = {}
|
| 19570 |
kshitij.so |
700 |
query['$gt'] = 0
|
| 19575 |
kshitij.so |
701 |
outer_query.append({'dealRankPoints':query})
|
| 19559 |
kshitij.so |
702 |
outer_query.append({'category_id':{"$in":[6]}})
|
|
|
703 |
|
| 19581 |
kshitij.so |
704 |
accessories_deals = list(get_mongo_connection().Catalog.Deals.find({"$and":outer_query},{'_id':1,'category_id':1,'brand':1,'bestSellerPoints':1,'nlcPoints':1,'totalPoints':1,'dealRankPoints':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([('dealRankPoints',pymongo.DESCENDING),('bestSellerPoints',pymongo.DESCENDING)]))
|
| 19559 |
kshitij.so |
705 |
|
|
|
706 |
actionsMap = {}
|
| 19580 |
kshitij.so |
707 |
actionRank = 3
|
| 19596 |
kshitij.so |
708 |
try:
|
| 19599 |
kshitij.so |
709 |
favourite_data = session.query(user_actions).filter_by(user_id=userId).order_by(asc(user_actions.created)).all()
|
|
|
710 |
favourite_ids = [x.store_product_id for x in favourite_data]
|
|
|
711 |
master_ids = list(get_mongo_connection().Catalog.MasterData.find({'_id':{"$in":favourite_ids},'category_id':6},{'_id':1}))
|
|
|
712 |
accessory_ids = [x['_id'] for x in master_ids]
|
|
|
713 |
for x in favourite_data:
|
|
|
714 |
if x.store_product_id not in accessory_ids:
|
|
|
715 |
continue
|
| 19596 |
kshitij.so |
716 |
action = 1 if x.action == 'like' else 0
|
|
|
717 |
if action==1:
|
|
|
718 |
actionsMap[x.store_product_id] = {'action':action,'rank':actionRank,'dealRankPoints':None}
|
|
|
719 |
actionRank = actionRank+3
|
|
|
720 |
else:
|
|
|
721 |
actionsMap[x.store_product_id] = {'action':action,'rank':None,'dealRankPoints':None}
|
|
|
722 |
except:
|
| 19614 |
kshitij.so |
723 |
traceback.print_exc()
|
| 19599 |
kshitij.so |
724 |
print "Exception in actionsMap creation"
|
| 19596 |
kshitij.so |
725 |
finally:
|
|
|
726 |
session.close()
|
| 19559 |
kshitij.so |
727 |
|
| 19583 |
kshitij.so |
728 |
pseudo_count = 1
|
|
|
729 |
inserted_count = 0
|
|
|
730 |
try:
|
|
|
731 |
if actionsMap:
|
|
|
732 |
for k,v in actionsMap.iteritems():
|
|
|
733 |
tmp_deal = get_mongo_connection().Catalog.Deals.find_one({'_id':k})
|
| 19599 |
kshitij.so |
734 |
if tmp_deal is None:
|
| 19580 |
kshitij.so |
735 |
v['rank'] = None
|
|
|
736 |
continue
|
| 19599 |
kshitij.so |
737 |
if tmp_deal['category_id']!=6 and (tmp_deal['showDeal']!=1 or tmp_deal['prepaidDeal']!=1) :
|
|
|
738 |
v['rank'] = None
|
|
|
739 |
continue
|
| 19583 |
kshitij.so |
740 |
if v['action'] ==0:
|
|
|
741 |
leastDealRankPoints = list(get_mongo_connection().Catalog.Deals.find({'subCategoryId':tmp_deal.get('subCategoryId')}).sort([('dealRankPoints',pymongo.ASCENDING)]).limit(1))
|
|
|
742 |
if len(leastDealRankPoints) == 0 or leastDealRankPoints[0].get('dealRankPoints') is None:
|
|
|
743 |
v['rank'] = None
|
|
|
744 |
continue
|
|
|
745 |
v['dealRankPoints'] = leastDealRankPoints[0]['dealRankPoints'] - 1
|
|
|
746 |
v['rank'] = 999999
|
|
|
747 |
else:
|
|
|
748 |
v['dealRankPoints'] = tmp_deal.get('dealRankPoints')
|
|
|
749 |
except:
|
|
|
750 |
print "Exception in action map"
|
|
|
751 |
traceback.print_exc()
|
|
|
752 |
|
| 19559 |
kshitij.so |
753 |
for deal in accessories_deals:
|
|
|
754 |
|
|
|
755 |
try:
|
|
|
756 |
fd_bundles.remove(deal.get('skuBundleId'))
|
|
|
757 |
except:
|
|
|
758 |
pass
|
| 19583 |
kshitij.so |
759 |
try:
|
|
|
760 |
if actionsMap and actionsMap.get(deal['_id'])!=None:
|
|
|
761 |
if actionsMap.get(deal['_id']).get('action') ==1 and actionsMap.get(deal['_id']).get('rank')!=None:
|
|
|
762 |
actionRank = actionsMap.get(deal['_id']).get('rank')
|
|
|
763 |
if actionRank < pseudo_count:
|
|
|
764 |
deal['dealRankPoints'] = accessories_deals[actionRank-1]['dealRankPoints'] +.5 + inserted_count
|
|
|
765 |
actionsMap.get(deal['_id'])['dealRankPoints'] = deal['dealRankPoints']
|
|
|
766 |
inserted_count = inserted_count+1
|
| 19580 |
kshitij.so |
767 |
elif actionsMap.get(deal['_id']).get('action') ==0 and actionsMap.get(deal['_id']).get('rank')!=None:
|
|
|
768 |
deal['dealRankPoints'] = actionsMap.get(deal['_id']).get('dealRankPoints')
|
| 19583 |
kshitij.so |
769 |
actionsMap.get(deal['_id'])['dealRankPoints'] = deal['dealRankPoints']
|
|
|
770 |
else:
|
|
|
771 |
pass
|
|
|
772 |
pseudo_count = pseudo_count+1
|
|
|
773 |
except:
|
|
|
774 |
print "Exception while arranging dealRankPoints"
|
|
|
775 |
traceback.print_exc()
|
| 19580 |
kshitij.so |
776 |
|
|
|
777 |
accessories_deals = sorted(accessories_deals, key = lambda x: (x['dealRankPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
|
| 19575 |
kshitij.so |
778 |
|
| 19559 |
kshitij.so |
779 |
if len(fd_bundles) > 0:
|
|
|
780 |
print "There is still bundle in feature deals.Lets add info"
|
|
|
781 |
for skuBundleId in fd_bundles:
|
|
|
782 |
dummyDealObjList = __constructDummyDealObject(skuBundleId)
|
|
|
783 |
for dummyDealObj in dummyDealObjList:
|
|
|
784 |
if dummyDealObj['category_id'] ==6:
|
|
|
785 |
accessories_deals.append(dummyDealObj)
|
|
|
786 |
|
|
|
787 |
for super_category, categoryFeaturedDeals in featuredDeals.iteritems():
|
|
|
788 |
for val in categoryFeaturedDeals.itervalues():
|
|
|
789 |
dummyDealObjList = __constructDummyDealObject(val.get('skuBundleId'))
|
|
|
790 |
for dummyDealObj in dummyDealObjList:
|
|
|
791 |
if super_category == dummyDealObj['category_id']:
|
|
|
792 |
continue
|
|
|
793 |
if super_category ==6:
|
|
|
794 |
accessories_deals.append(dummyDealObj)
|
|
|
795 |
|
|
|
796 |
|
| 17469 |
kshitij.so |
797 |
sortedMapAccessories = {}
|
|
|
798 |
rankMapAccessories = {}
|
|
|
799 |
rankAccessories = 0
|
| 19559 |
kshitij.so |
800 |
|
| 17469 |
kshitij.so |
801 |
blockedRanksAccessories = []
|
|
|
802 |
blockedSkuBundlesAccessories = []
|
|
|
803 |
blockedInfoAccessories = {}
|
| 19559 |
kshitij.so |
804 |
|
| 17469 |
kshitij.so |
805 |
featuredDealsAccessories = featuredDeals.get(6)
|
| 19559 |
kshitij.so |
806 |
|
| 17469 |
kshitij.so |
807 |
for k, v in featuredDealsAccessories.iteritems():
|
|
|
808 |
blockedRanksAccessories.append(k-1)
|
|
|
809 |
blockedSkuBundlesAccessories.append(v.get('skuBundleId'))
|
| 19559 |
kshitij.so |
810 |
|
|
|
811 |
|
| 17469 |
kshitij.so |
812 |
for sorted_deal in accessories_deals:
|
| 19559 |
kshitij.so |
813 |
|
| 17469 |
kshitij.so |
814 |
while(True):
|
|
|
815 |
if rankAccessories in blockedRanksAccessories:
|
|
|
816 |
rankAccessories = rankAccessories +1
|
|
|
817 |
else:
|
|
|
818 |
break
|
| 19559 |
kshitij.so |
819 |
|
| 17469 |
kshitij.so |
820 |
if sorted_deal['skuBundleId'] in blockedSkuBundlesAccessories:
|
|
|
821 |
if blockedInfoAccessories.has_key(sorted_deal['skuBundleId']):
|
|
|
822 |
blockedInfoAccessories.get(sorted_deal['skuBundleId']).append(sorted_deal)
|
|
|
823 |
else:
|
|
|
824 |
blockedInfoAccessories[sorted_deal['skuBundleId']] = [sorted_deal]
|
|
|
825 |
continue
|
| 19559 |
kshitij.so |
826 |
|
| 17469 |
kshitij.so |
827 |
if sortedMapAccessories.get(sorted_deal['skuBundleId']) is None:
|
|
|
828 |
sortedMapAccessories[sorted_deal['skuBundleId']] = {rankAccessories:[sorted_deal]}
|
|
|
829 |
rankMapAccessories[rankAccessories] = (sortedMapAccessories[sorted_deal['skuBundleId']].values())[0]
|
|
|
830 |
rankAccessories = rankAccessories +1
|
|
|
831 |
else:
|
|
|
832 |
for temp_list in sortedMapAccessories.get(sorted_deal['skuBundleId']).itervalues():
|
|
|
833 |
temp_list.append(sorted_deal)
|
|
|
834 |
rankMapAccessories[(sortedMapAccessories.get(sorted_deal['skuBundleId']).keys())[0]] = temp_list
|
| 19559 |
kshitij.so |
835 |
|
|
|
836 |
|
| 17469 |
kshitij.so |
837 |
for rank in blockedRanksAccessories:
|
|
|
838 |
if blockedInfoAccessories.get((featuredDealsAccessories.get(rank+1)).get('skuBundleId')) is not None:
|
|
|
839 |
rankMapAccessories[rank] = blockedInfoAccessories.get((featuredDealsAccessories.get(rank+1)).get('skuBundleId'))
|
| 19559 |
kshitij.so |
840 |
|
| 19288 |
kshitij.so |
841 |
specialOffer = None
|
|
|
842 |
promoOffer = get_mongo_connection().Catalog.PromoOffer.find_one({'user_id':userId})
|
|
|
843 |
try:
|
|
|
844 |
if promoOffer is not None:
|
|
|
845 |
offer = get_mongo_connection().Catalog.Promotions.find_one({'_id':promoOffer.get('offer_id')})
|
|
|
846 |
if offer is None:
|
|
|
847 |
raise
|
| 19352 |
kshitij.so |
848 |
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 |
849 |
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 |
850 |
promoOffer.get('pending_order_value'), promoOffer.get('delivered_order_value'), promoOffer.get('last_run_timestamp'))
|
| 17469 |
kshitij.so |
851 |
|
| 19288 |
kshitij.so |
852 |
specialOffer = promo
|
|
|
853 |
except:
|
| 19559 |
kshitij.so |
854 |
traceback.print_exc()
|
| 19288 |
kshitij.so |
855 |
|
|
|
856 |
|
| 19559 |
kshitij.so |
857 |
mem_cache_val = {6:accessories_deals,"6_rankMap": rankMapAccessories, "specialOffer":specialOffer }
|
|
|
858 |
mc.set(str(userId)+'_acc', mem_cache_val)
|
|
|
859 |
|
| 14037 |
kshitij.so |
860 |
|
|
|
861 |
|
| 14531 |
kshitij.so |
862 |
def __populateFeaturedDeals():
|
| 17367 |
kshitij.so |
863 |
print "Populating featured deals....."
|
|
|
864 |
featuredDealsMobiles = {}
|
|
|
865 |
featuredDealsTablets = {}
|
| 17469 |
kshitij.so |
866 |
featuredDealsAccessories = {}
|
| 17618 |
kshitij.so |
867 |
activeFeaturedDeals = get_mongo_connection().Catalog.FeaturedDeals.find({'startDate':{'$lte':to_java_date(datetime.now())},'endDate':{'$gte':to_java_date(datetime.now())}})
|
| 14531 |
kshitij.so |
868 |
for activeFeaturedDeal in activeFeaturedDeals:
|
| 17367 |
kshitij.so |
869 |
deals = get_mongo_connection().Catalog.Deals.find({"skuBundleId":activeFeaturedDeal.get('skuBundleId'),"$or":[{"showDeal":1}, {"prepaidDeal":1}]})
|
|
|
870 |
for deal in deals:
|
|
|
871 |
if deal.get('available_price') <= activeFeaturedDeal.get('thresholdPrice'):
|
| 17469 |
kshitij.so |
872 |
for category_id, rank in activeFeaturedDeal['otherInfo'].iteritems():
|
|
|
873 |
f_deal = {'skuBundleId':activeFeaturedDeal.get('skuBundleId'), 'thresholdPrice':activeFeaturedDeal.get('thresholdPrice'), 'rank':rank,'category_id':int(category_id),'totalPoints':activeFeaturedDeal.get('totalPoints')}
|
|
|
874 |
if f_deal['category_id'] == 3:
|
|
|
875 |
featuredDealsMobiles[rank] = f_deal
|
|
|
876 |
elif f_deal['category_id']==5:
|
|
|
877 |
featuredDealsTablets[rank] = f_deal
|
|
|
878 |
elif f_deal['category_id']==6:
|
|
|
879 |
featuredDealsAccessories[rank] = f_deal
|
| 17367 |
kshitij.so |
880 |
break
|
| 17469 |
kshitij.so |
881 |
|
|
|
882 |
# f_deal = {'skuBundleId':activeFeaturedDeal.get('skuBundleId'), 'thresholdPrice':activeFeaturedDeal.get('thresholdPrice'), 'rank':activeFeaturedDeal.get('rank'),'category_id':activeFeaturedDeal.get('category_id'),'totalPoints':activeFeaturedDeal.get('totalPoints')}
|
|
|
883 |
# if activeFeaturedDeal.get('category_id') == 3:
|
|
|
884 |
# featuredDealsMobiles[activeFeaturedDeal.get('rank')] = f_deal
|
|
|
885 |
# else:
|
|
|
886 |
# featuredDealsTablets[activeFeaturedDeal.get('rank')] = f_deal
|
|
|
887 |
# break
|
|
|
888 |
|
| 17367 |
kshitij.so |
889 |
|
| 17469 |
kshitij.so |
890 |
mc.set("featured_deals", {3:featuredDealsMobiles,5:featuredDealsTablets,6:featuredDealsAccessories}, 600)
|
| 14037 |
kshitij.so |
891 |
|
| 17618 |
kshitij.so |
892 |
def __populateFeaturedDealsForDealObject():
|
|
|
893 |
print "Caching deal objects...."
|
|
|
894 |
featuredDealObjectMobiles = {}
|
|
|
895 |
featuredDealObjectTablets = {}
|
|
|
896 |
featuredDealObjectAccessories = {}
|
|
|
897 |
dealObjects = get_mongo_connection().Catalog.FeaturedDealsDealObject.find({'startDate':{'$lte':to_java_date(datetime.now())},'endDate':{'$gte':to_java_date(datetime.now())}})
|
|
|
898 |
for dealObject in dealObjects:
|
|
|
899 |
d_object = list(get_mongo_connection().Catalog.DealObject.find({'_id':dealObject['_id']}))
|
|
|
900 |
if len(d_object) == 0:
|
|
|
901 |
continue
|
|
|
902 |
for category_id, rank in dealObject['otherInfo'].iteritems():
|
|
|
903 |
d_object[0]['dealObject'] = 1
|
| 19288 |
kshitij.so |
904 |
f_deal = {'rank':rank,'category_id':int(category_id),'object':d_object[0],'offer_id':dealObject.get('offer_id')}
|
| 17618 |
kshitij.so |
905 |
if f_deal['category_id'] == 3:
|
|
|
906 |
featuredDealObjectMobiles[rank] = f_deal
|
|
|
907 |
elif f_deal['category_id']==5:
|
|
|
908 |
featuredDealObjectTablets[rank] = f_deal
|
|
|
909 |
elif f_deal['category_id']==6:
|
|
|
910 |
featuredDealObjectAccessories[rank] = f_deal
|
|
|
911 |
mc.set("featured_deals_deal_object", {3:featuredDealObjectMobiles,5:featuredDealObjectTablets,6:featuredDealObjectAccessories}, 600)
|
| 17619 |
kshitij.so |
912 |
print mc.get('featured_deals_deal_object')
|
| 17618 |
kshitij.so |
913 |
|
| 22256 |
amit.gupta |
914 |
#introducing online/deals with fofo flag
|
|
|
915 |
def getNewDeals(userId, category_id, offset, limit, sort, direction, filterData=None, source=None, tag_ids=None):
|
| 22293 |
amit.gupta |
916 |
defaultFilter = False
|
|
|
917 |
if filterData is not None:
|
|
|
918 |
defaultFilter = True
|
| 17469 |
kshitij.so |
919 |
if mc.get("category_cash_back") is None or not bool(mc.get("category_cash_back")):
|
| 13921 |
kshitij.so |
920 |
populateCashBack()
|
| 14037 |
kshitij.so |
921 |
|
| 22271 |
amit.gupta |
922 |
if source is not None:
|
|
|
923 |
if source=="online":
|
|
|
924 |
sourceToFilter = [str(i) for i in ONLINE_DEAL_SOURCE_MAP.keys()] #filter categores on basis of source and tags
|
|
|
925 |
#For saholic specific deals
|
|
|
926 |
elif source=="deals":
|
|
|
927 |
sourceToFilter = ['4']
|
|
|
928 |
#we should override sourceFilterString
|
|
|
929 |
sourceFiterString = "sourceFilter:" + "^".join(sourceToFilter)
|
|
|
930 |
|
|
|
931 |
if filterData is None:
|
|
|
932 |
filterData = sourceFiterString
|
|
|
933 |
else:
|
|
|
934 |
a = filterData.split('sourceFilter:')
|
|
|
935 |
if len(a) > 1:
|
|
|
936 |
filterData = a[0] + sourceFiterString
|
|
|
937 |
b = a[1].split("|")
|
|
|
938 |
if len(b) > 1:
|
|
|
939 |
filterData = "|".join([filterData] + b[1:])
|
|
|
940 |
else:
|
| 23337 |
amit.gupta |
941 |
filterData = filterData + "|" + sourceFiterString
|
| 22271 |
amit.gupta |
942 |
|
| 16079 |
kshitij.so |
943 |
dealsListMap = []
|
| 14037 |
kshitij.so |
944 |
user_specific_deals = mc.get(str(userId))
|
|
|
945 |
if user_specific_deals is None:
|
|
|
946 |
__populateCache(userId)
|
|
|
947 |
user_specific_deals = mc.get(str(userId))
|
| 14038 |
kshitij.so |
948 |
else:
|
|
|
949 |
print "Getting user deals from cache"
|
| 14037 |
kshitij.so |
950 |
category_specific_deals = user_specific_deals.get(category_id)
|
| 22256 |
amit.gupta |
951 |
|
| 14037 |
kshitij.so |
952 |
|
| 17367 |
kshitij.so |
953 |
insert_featured_deals = False
|
| 14037 |
kshitij.so |
954 |
if sort is None or direction is None:
|
| 17367 |
kshitij.so |
955 |
insert_featured_deals = True
|
|
|
956 |
rankMap = user_specific_deals.get(str(category_id)+"_rankMap")
|
| 14037 |
kshitij.so |
957 |
else:
|
|
|
958 |
if sort == "bestSellerPoints":
|
|
|
959 |
sorted_deals = sorted(category_specific_deals, key = lambda x: (x['bestSellerPoints'], x['rank'], x['nlcPoints']),reverse=True)
|
|
|
960 |
else:
|
|
|
961 |
if direction == -1:
|
|
|
962 |
rev = True
|
|
|
963 |
else:
|
|
|
964 |
rev = False
|
|
|
965 |
sorted_deals = sorted(category_specific_deals, key = lambda x: (x['available_price']),reverse=rev)
|
|
|
966 |
|
| 14791 |
kshitij.so |
967 |
|
| 17367 |
kshitij.so |
968 |
filtered_deals = []
|
| 17668 |
kshitij.so |
969 |
dataExist = True
|
| 22266 |
amit.gupta |
970 |
#filter categores on basis of source and tags
|
|
|
971 |
if source=="online":
|
|
|
972 |
category_specific_deals = filter(lambda x: x['source_id'] in ONLINE_DEAL_SOURCE_MAP.keys(), category_specific_deals)
|
|
|
973 |
#For saholic specific deals
|
|
|
974 |
elif source=="deals":
|
|
|
975 |
category_specific_deals = filter(lambda x: x['source_id'] == 4, category_specific_deals)
|
|
|
976 |
|
| 22293 |
amit.gupta |
977 |
if filterData:
|
| 14791 |
kshitij.so |
978 |
try:
|
| 22270 |
amit.gupta |
979 |
filtered_deals = filterDeals(category_specific_deals, filterData)
|
| 17669 |
kshitij.so |
980 |
if len(filtered_deals)==0:
|
|
|
981 |
dataExist = False
|
| 14791 |
kshitij.so |
982 |
except:
|
| 16067 |
kshitij.so |
983 |
traceback.print_exc()
|
| 23337 |
amit.gupta |
984 |
|
| 17668 |
kshitij.so |
985 |
if dataExist:
|
|
|
986 |
if not insert_featured_deals:
|
|
|
987 |
sortedMap = {}
|
|
|
988 |
rankMap = {}
|
|
|
989 |
rank = 0
|
|
|
990 |
for sorted_deal in sorted_deals:
|
|
|
991 |
|
|
|
992 |
if len(filtered_deals) > 0 and sorted_deal['skuBundleId'] not in filtered_deals:
|
|
|
993 |
continue
|
|
|
994 |
|
|
|
995 |
if sortedMap.get(sorted_deal['skuBundleId']) is None:
|
|
|
996 |
sortedMap[sorted_deal['skuBundleId']] = {rank:[sorted_deal]}
|
|
|
997 |
rankMap[rank] = (sortedMap[sorted_deal['skuBundleId']].values())[0]
|
|
|
998 |
rank = rank +1
|
|
|
999 |
else:
|
|
|
1000 |
for temp_list in sortedMap.get(sorted_deal['skuBundleId']).itervalues():
|
|
|
1001 |
temp_list.append(sorted_deal)
|
|
|
1002 |
rankMap[(sortedMap.get(sorted_deal['skuBundleId']).keys())[0]] = temp_list
|
|
|
1003 |
else:
|
|
|
1004 |
filterMap = {}
|
|
|
1005 |
rank = 0
|
|
|
1006 |
if len(filtered_deals) > 0:
|
|
|
1007 |
try:
|
|
|
1008 |
od = collections.OrderedDict(sorted(rankMap.items()))
|
|
|
1009 |
except:
|
|
|
1010 |
od = ordereddict.OrderedDict(sorted(rankMap.items()))
|
|
|
1011 |
for k, v in od.iteritems():
|
|
|
1012 |
if v[0].get('skuBundleId') in filtered_deals:
|
|
|
1013 |
filterMap[rank] = v
|
|
|
1014 |
rank =rank+1
|
|
|
1015 |
rankMap = filterMap
|
|
|
1016 |
|
|
|
1017 |
rankCounter = offset
|
| 22293 |
amit.gupta |
1018 |
if mc.get("featured_deals_deal_object") is None or not bool(mc.get("featured_deals_deal_object")):
|
|
|
1019 |
try:
|
|
|
1020 |
__populateFeaturedDealsForDealObject()
|
| 17668 |
kshitij.so |
1021 |
fd_dealObject = mc.get("featured_deals_deal_object")
|
| 22293 |
amit.gupta |
1022 |
except:
|
|
|
1023 |
fd_dealObject = {3:{},5:{},6:{}}
|
|
|
1024 |
else:
|
|
|
1025 |
fd_dealObject = mc.get("featured_deals_deal_object")
|
| 17668 |
kshitij.so |
1026 |
|
| 17367 |
kshitij.so |
1027 |
else:
|
| 17668 |
kshitij.so |
1028 |
rankMap = {}
|
| 17618 |
kshitij.so |
1029 |
|
| 19288 |
kshitij.so |
1030 |
|
|
|
1031 |
specialOffer = user_specific_deals.get('specialOffer')
|
|
|
1032 |
|
| 17627 |
kshitij.so |
1033 |
for dealList in [rankMap.get(k, []) for k in range(offset, offset+limit)]:
|
| 22293 |
amit.gupta |
1034 |
if not defaultFilter:
|
| 17627 |
kshitij.so |
1035 |
while(True):
|
|
|
1036 |
|
|
|
1037 |
rankCounter = rankCounter+1
|
|
|
1038 |
if (fd_dealObject.get(category_id).get(rankCounter)) is not None:
|
| 19288 |
kshitij.so |
1039 |
if (fd_dealObject.get(category_id).get(rankCounter).get('offer_id') !=0):
|
|
|
1040 |
#Check whether user can see offer
|
| 19518 |
manas |
1041 |
if specialOffer is None or specialOffer.endDate < to_java_date(datetime.now()):
|
| 19288 |
kshitij.so |
1042 |
continue
|
| 19334 |
kshitij.so |
1043 |
deal_object_temp = []
|
|
|
1044 |
deal_object_temp.append(fd_dealObject.get(category_id).get(rankCounter).get('object'))
|
|
|
1045 |
dealsListMap.append(deal_object_temp)
|
| 17627 |
kshitij.so |
1046 |
else:
|
|
|
1047 |
break
|
| 17620 |
kshitij.so |
1048 |
|
| 16079 |
kshitij.so |
1049 |
temp = []
|
| 17367 |
kshitij.so |
1050 |
if dealList is None or len(dealList)==0:
|
|
|
1051 |
continue
|
| 16067 |
kshitij.so |
1052 |
for d in dealList:
|
|
|
1053 |
item = list(get_mongo_connection().Catalog.MasterData.find({'_id':d['_id']}))
|
| 16320 |
kshitij.so |
1054 |
if len(item) ==0:
|
|
|
1055 |
continue
|
| 16079 |
kshitij.so |
1056 |
item[0]['persPoints'] = d['persPoints']
|
|
|
1057 |
if d['dealType'] == 1 and d['source_id'] ==1:
|
| 16511 |
kshitij.so |
1058 |
try:
|
|
|
1059 |
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())}}))
|
|
|
1060 |
item[0]['marketPlaceUrl'] = manualDeal[0]['dealUrl'].strip()
|
|
|
1061 |
except:
|
|
|
1062 |
pass
|
| 16079 |
kshitij.so |
1063 |
elif d['source_id'] ==3:
|
|
|
1064 |
item[0]['marketPlaceUrl'] = item[0]['marketPlaceUrl']+'?supc='+item[0].get('identifier')
|
|
|
1065 |
else:
|
|
|
1066 |
pass
|
|
|
1067 |
try:
|
|
|
1068 |
cashBack = getCashBack(item[0]['_id'], item[0]['source_id'], item[0]['category_id'])
|
|
|
1069 |
if not cashBack or cashBack.get('cash_back_status')!=1:
|
| 14037 |
kshitij.so |
1070 |
item[0]['cash_back_type'] = 0
|
|
|
1071 |
item[0]['cash_back'] = 0
|
| 16079 |
kshitij.so |
1072 |
else:
|
| 17180 |
kshitij.so |
1073 |
if cashBack.get('maxCashBack') is not None:
|
|
|
1074 |
|
|
|
1075 |
if cashBack.get('cash_back_type') ==1 and (float(cashBack.get('cash_back'))*item[0]['available_price'])/100 > cashBack.get('maxCashBack'):
|
|
|
1076 |
cashBack['cash_back_type'] = 2
|
|
|
1077 |
cashBack['cash_back'] = cashBack['maxCashBack']
|
|
|
1078 |
elif cashBack.get('cash_back_type') ==2 and cashBack.get('cash_back') > cashBack.get('maxCashBack'):
|
|
|
1079 |
cashBack['cash_back'] = cashBack['maxCashBack']
|
|
|
1080 |
|
| 16079 |
kshitij.so |
1081 |
item[0]['cash_back_type'] = int(cashBack['cash_back_type'])
|
|
|
1082 |
item[0]['cash_back'] = cashBack['cash_back']
|
|
|
1083 |
except:
|
|
|
1084 |
print "Error in adding cashback to deals"
|
|
|
1085 |
item[0]['cash_back_type'] = 0
|
|
|
1086 |
item[0]['cash_back'] = 0
|
| 16252 |
kshitij.so |
1087 |
try:
|
|
|
1088 |
item[0]['dp'] = d['dp']
|
|
|
1089 |
item[0]['showDp'] = d['showDp']
|
|
|
1090 |
except:
|
|
|
1091 |
item[0]['dp'] = 0.0
|
|
|
1092 |
item[0]['showDp'] = 0
|
| 16483 |
kshitij.so |
1093 |
try:
|
|
|
1094 |
item[0]['thumbnail'] = item[0]['thumbnail'].strip()
|
|
|
1095 |
except:
|
| 17115 |
manish.sha |
1096 |
pass
|
| 17603 |
kshitij.so |
1097 |
|
|
|
1098 |
try:
|
|
|
1099 |
if item[0]['showVideo']==0:
|
|
|
1100 |
item[0]['videoLink'] =""
|
|
|
1101 |
except:
|
|
|
1102 |
item[0]['videoLink'] =""
|
| 17937 |
kshitij.so |
1103 |
try:
|
|
|
1104 |
if item[0]['quantity'] >1:
|
|
|
1105 |
ppq = float(item[0]['available_price'])/item[0]['quantity']
|
|
|
1106 |
|
|
|
1107 |
if ppq == round(ppq):
|
|
|
1108 |
item[0]['ppq'] = int(ppq)
|
|
|
1109 |
else:
|
|
|
1110 |
item[0]['ppq'] = round(ppq,2)
|
|
|
1111 |
else:
|
|
|
1112 |
item[0]['ppq'] = 0
|
|
|
1113 |
except:
|
|
|
1114 |
item[0]['ppq'] = 0
|
| 22293 |
amit.gupta |
1115 |
if not defaultFilter:
|
| 17679 |
kshitij.so |
1116 |
if item[0]['category_id']!=6:
|
|
|
1117 |
try:
|
| 18830 |
kshitij.so |
1118 |
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']))
|
|
|
1119 |
item[0]['filterTextBrand'] = (item[0]['brand'])
|
| 17679 |
kshitij.so |
1120 |
except:
|
| 18830 |
kshitij.so |
1121 |
pass
|
| 17679 |
kshitij.so |
1122 |
else:
|
|
|
1123 |
try:
|
| 17756 |
kshitij.so |
1124 |
if item[0]['subCategory']=='' or item[0]['subCategory'] is None or item[0]['subCategoryId']==0:
|
| 17679 |
kshitij.so |
1125 |
raise
|
| 18830 |
kshitij.so |
1126 |
item[0]['filterLinkSubCategory'] = '/category/'+str(int(item[0]['category_id']))+'?searchFor='+urllib.quote(item[0]['subCategory'])+'&filter=subcategory&subcategories='+str(int(item[0]['subCategoryId']))
|
|
|
1127 |
item[0]['filterTextSubCategory'] = (item[0]['subCategory'])
|
|
|
1128 |
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']))
|
|
|
1129 |
item[0]['filterTextBrand'] = (item[0]['brand'])
|
| 17679 |
kshitij.so |
1130 |
except:
|
| 18830 |
kshitij.so |
1131 |
pass
|
| 17771 |
kshitij.so |
1132 |
try:
|
|
|
1133 |
if item[0]['source_id']==4:
|
|
|
1134 |
item_availability_info = mc.get("item_availability_"+str(item[0]['identifier']).strip())
|
|
|
1135 |
if item_availability_info is None or len(item_availability_info)==0:
|
| 22329 |
amit.gupta |
1136 |
#item[0]['availabilityInfo'] = [{}]
|
|
|
1137 |
continue
|
| 17771 |
kshitij.so |
1138 |
else:
|
| 22256 |
amit.gupta |
1139 |
#remove items that are mapped with tag_ids recieved
|
|
|
1140 |
if tag_ids:
|
|
|
1141 |
#construct item_availability_info TAGS not matched
|
| 23023 |
amit.gupta |
1142 |
item_availability_info = [av_info for av_info in item_availability_info if av_info['availability'] > 0 and not (av_info.has_key('tag_ids') and not set(tag_ids).isdisjoint(av_info.get('tag_ids')))]
|
| 22256 |
amit.gupta |
1143 |
if len(item_availability_info)==0:
|
| 22329 |
amit.gupta |
1144 |
#item_availability_info = [{}]
|
|
|
1145 |
continue
|
| 17771 |
kshitij.so |
1146 |
item[0]['availabilityInfo'] = item_availability_info
|
|
|
1147 |
except:
|
| 22329 |
amit.gupta |
1148 |
continue
|
|
|
1149 |
#item[0]['availabilityInfo'] = [{}]
|
| 19193 |
kshitij.so |
1150 |
|
|
|
1151 |
if item[0]['source_id']==4:
|
|
|
1152 |
for av_info in item[0]['availabilityInfo']:
|
|
|
1153 |
if not av_info:
|
|
|
1154 |
continue
|
|
|
1155 |
av_info['cash_back'] = item[0]['cash_back']
|
|
|
1156 |
av_info['cash_back_type'] = item[0]['cash_back_type']
|
|
|
1157 |
netPriceAfterCashBack = av_info['sellingPrice']
|
| 19199 |
kshitij.so |
1158 |
if av_info['cash_back_type'] ==1:
|
| 19207 |
kshitij.so |
1159 |
netPriceAfterCashBack = av_info['sellingPrice'] - math.floor(float(av_info['sellingPrice'])*av_info['cash_back']/100)
|
| 19199 |
kshitij.so |
1160 |
elif av_info['cash_back_type'] ==2:
|
| 19207 |
kshitij.so |
1161 |
netPriceAfterCashBack = av_info['sellingPrice'] - math.floor(av_info['cash_back'])
|
| 19193 |
kshitij.so |
1162 |
else:
|
|
|
1163 |
pass
|
|
|
1164 |
av_info['netPriceAfterCashBack'] = netPriceAfterCashBack
|
|
|
1165 |
|
|
|
1166 |
#item[0]['netPriceAfterCashBack'] = d['netPriceAfterCashBack']
|
|
|
1167 |
|
| 19896 |
kshitij.so |
1168 |
if item[0]['source_id'] == SOURCE_MAP.get("PAYTM.COM"):
|
| 19193 |
kshitij.so |
1169 |
if item[0]['codAvailable'] ==1:
|
|
|
1170 |
paytmPrice = item[0]['available_price']
|
|
|
1171 |
else:
|
|
|
1172 |
paytmPrice = item[0]['gross_price']
|
|
|
1173 |
|
|
|
1174 |
if item[0]['cash_back_type'] ==1:
|
| 19207 |
kshitij.so |
1175 |
item[0]['netPriceAfterCashBack'] = paytmPrice - math.floor(float(paytmPrice)*item[0]['cash_back']/100)
|
| 19193 |
kshitij.so |
1176 |
elif item[0]['cash_back_type'] ==2:
|
| 19207 |
kshitij.so |
1177 |
item[0]['netPriceAfterCashBack'] = paytmPrice - math.floor(item[0]['cash_back'])
|
| 19193 |
kshitij.so |
1178 |
else:
|
|
|
1179 |
item[0]['netPriceAfterCashBack'] = paytmPrice
|
|
|
1180 |
|
|
|
1181 |
else:
|
|
|
1182 |
if item[0]['cash_back_type'] ==1:
|
| 19207 |
kshitij.so |
1183 |
item[0]['netPriceAfterCashBack'] = item[0]['available_price'] - math.floor(float(item[0]['available_price'])*item[0]['cash_back']/100)
|
| 19193 |
kshitij.so |
1184 |
elif item[0]['cash_back_type'] ==2:
|
| 19207 |
kshitij.so |
1185 |
item[0]['netPriceAfterCashBack'] = item[0]['available_price'] - math.floor(item[0]['cash_back'])
|
| 19193 |
kshitij.so |
1186 |
else:
|
|
|
1187 |
item[0]['netPriceAfterCashBack'] = item[0]['available_price']
|
|
|
1188 |
|
| 19559 |
kshitij.so |
1189 |
temp.append(item[0])
|
|
|
1190 |
if len(temp) > 1:
|
|
|
1191 |
temp = sorted(temp, key = lambda x: (x['available_price']),reverse=False)
|
|
|
1192 |
dealsListMap.append(temp)
|
|
|
1193 |
return dealsListMap
|
|
|
1194 |
|
|
|
1195 |
|
| 22261 |
amit.gupta |
1196 |
def getAccesoryDeals(userId, category_id, offset, limit, sort, direction, filterData=None, source=None, tag_ids=None):
|
| 22293 |
amit.gupta |
1197 |
defaultFilter = False
|
|
|
1198 |
if filterData is not None:
|
|
|
1199 |
defaultFilter = True
|
|
|
1200 |
|
| 19559 |
kshitij.so |
1201 |
if mc.get("category_cash_back") is None or not bool(mc.get("category_cash_back")):
|
|
|
1202 |
populateCashBack()
|
|
|
1203 |
|
| 22270 |
amit.gupta |
1204 |
|
|
|
1205 |
if source is not None:
|
|
|
1206 |
if source=="online":
|
|
|
1207 |
sourceToFilter = [str(i) for i in ONLINE_DEAL_SOURCE_MAP.keys()] #filter categores on basis of source and tags
|
|
|
1208 |
#For saholic specific deals
|
|
|
1209 |
elif source=="deals":
|
|
|
1210 |
sourceToFilter = ['4']
|
|
|
1211 |
#we should override sourceFilterString
|
|
|
1212 |
sourceFiterString = "sourceFilter:" + "^".join(sourceToFilter)
|
|
|
1213 |
|
|
|
1214 |
if filterData is None:
|
|
|
1215 |
filterData = sourceFiterString
|
|
|
1216 |
else:
|
|
|
1217 |
a = filterData.split('sourceFilter:')
|
|
|
1218 |
if len(a) > 1:
|
|
|
1219 |
filterData = a[0] + sourceFiterString
|
|
|
1220 |
b = a[1].split("|")
|
|
|
1221 |
if len(b) > 1:
|
|
|
1222 |
filterData = "|".join([filterData] + b[1:])
|
|
|
1223 |
else:
|
| 23792 |
tejbeer |
1224 |
filterData = filterData + "|" + sourceFiterString
|
| 22270 |
amit.gupta |
1225 |
|
|
|
1226 |
|
| 19559 |
kshitij.so |
1227 |
dealsListMap = []
|
|
|
1228 |
user_specific_deals = mc.get(str(userId)+'_acc')
|
|
|
1229 |
if user_specific_deals is None:
|
|
|
1230 |
__populateCacheForAccessories(userId)
|
|
|
1231 |
user_specific_deals = mc.get(str(userId)+'_acc')
|
|
|
1232 |
else:
|
|
|
1233 |
print "Getting user deals from accessory cache"
|
|
|
1234 |
category_specific_deals = user_specific_deals.get(category_id)
|
|
|
1235 |
|
|
|
1236 |
insert_featured_deals = False
|
|
|
1237 |
if sort is None or direction is None:
|
|
|
1238 |
insert_featured_deals = True
|
|
|
1239 |
rankMap = user_specific_deals.get(str(category_id)+"_rankMap")
|
|
|
1240 |
else:
|
|
|
1241 |
if sort == "bestSellerPoints":
|
| 19597 |
kshitij.so |
1242 |
sorted_deals = sorted(category_specific_deals, key = lambda x: (x['bestSellerPoints'], x['dealRankPoints'], x['nlcPoints']),reverse=True)
|
| 19559 |
kshitij.so |
1243 |
else:
|
|
|
1244 |
if direction == -1:
|
|
|
1245 |
rev = True
|
|
|
1246 |
else:
|
|
|
1247 |
rev = False
|
|
|
1248 |
sorted_deals = sorted(category_specific_deals, key = lambda x: (x['available_price']),reverse=rev)
|
|
|
1249 |
|
|
|
1250 |
|
|
|
1251 |
filtered_deals = []
|
|
|
1252 |
dataExist = True
|
| 22266 |
amit.gupta |
1253 |
|
| 22293 |
amit.gupta |
1254 |
if filterData is not None:
|
| 19559 |
kshitij.so |
1255 |
try:
|
| 22270 |
amit.gupta |
1256 |
filtered_deals = filterDeals(category_specific_deals, filterData)
|
| 19559 |
kshitij.so |
1257 |
if len(filtered_deals)==0:
|
|
|
1258 |
dataExist = False
|
|
|
1259 |
except:
|
|
|
1260 |
traceback.print_exc()
|
|
|
1261 |
if dataExist:
|
|
|
1262 |
|
|
|
1263 |
if not insert_featured_deals:
|
|
|
1264 |
sortedMap = {}
|
|
|
1265 |
rankMap = {}
|
|
|
1266 |
rank = 0
|
|
|
1267 |
for sorted_deal in sorted_deals:
|
|
|
1268 |
|
|
|
1269 |
if len(filtered_deals) > 0 and sorted_deal['skuBundleId'] not in filtered_deals:
|
|
|
1270 |
continue
|
|
|
1271 |
|
|
|
1272 |
if sortedMap.get(sorted_deal['skuBundleId']) is None:
|
|
|
1273 |
sortedMap[sorted_deal['skuBundleId']] = {rank:[sorted_deal]}
|
|
|
1274 |
rankMap[rank] = (sortedMap[sorted_deal['skuBundleId']].values())[0]
|
|
|
1275 |
rank = rank +1
|
|
|
1276 |
else:
|
|
|
1277 |
for temp_list in sortedMap.get(sorted_deal['skuBundleId']).itervalues():
|
|
|
1278 |
temp_list.append(sorted_deal)
|
|
|
1279 |
rankMap[(sortedMap.get(sorted_deal['skuBundleId']).keys())[0]] = temp_list
|
|
|
1280 |
else:
|
|
|
1281 |
filterMap = {}
|
|
|
1282 |
rank = 0
|
|
|
1283 |
if len(filtered_deals) > 0:
|
|
|
1284 |
try:
|
|
|
1285 |
od = collections.OrderedDict(sorted(rankMap.items()))
|
|
|
1286 |
except:
|
|
|
1287 |
od = ordereddict.OrderedDict(sorted(rankMap.items()))
|
|
|
1288 |
for k, v in od.iteritems():
|
|
|
1289 |
if v[0].get('skuBundleId') in filtered_deals:
|
|
|
1290 |
filterMap[rank] = v
|
|
|
1291 |
rank =rank+1
|
|
|
1292 |
rankMap = filterMap
|
|
|
1293 |
|
|
|
1294 |
rankCounter = offset
|
| 22293 |
amit.gupta |
1295 |
if mc.get("featured_deals_deal_object") is None or not bool(mc.get("featured_deals_deal_object")):
|
|
|
1296 |
try:
|
|
|
1297 |
__populateFeaturedDealsForDealObject()
|
| 19559 |
kshitij.so |
1298 |
fd_dealObject = mc.get("featured_deals_deal_object")
|
| 22293 |
amit.gupta |
1299 |
except:
|
|
|
1300 |
fd_dealObject = {3:{},5:{},6:{}}
|
|
|
1301 |
else:
|
|
|
1302 |
fd_dealObject = mc.get("featured_deals_deal_object")
|
| 19559 |
kshitij.so |
1303 |
|
|
|
1304 |
else:
|
|
|
1305 |
rankMap = {}
|
|
|
1306 |
|
|
|
1307 |
|
|
|
1308 |
specialOffer = user_specific_deals.get('specialOffer')
|
|
|
1309 |
|
|
|
1310 |
for dealList in [rankMap.get(k, []) for k in range(offset, offset+limit)]:
|
| 22293 |
amit.gupta |
1311 |
if not defaultFilter:
|
| 19559 |
kshitij.so |
1312 |
while(True):
|
|
|
1313 |
|
|
|
1314 |
rankCounter = rankCounter+1
|
|
|
1315 |
if (fd_dealObject.get(category_id).get(rankCounter)) is not None:
|
|
|
1316 |
if (fd_dealObject.get(category_id).get(rankCounter).get('offer_id') !=0):
|
|
|
1317 |
#Check whether user can see offer
|
|
|
1318 |
if specialOffer is None or specialOffer.endDate < to_java_date(datetime.now()):
|
|
|
1319 |
continue
|
|
|
1320 |
deal_object_temp = []
|
|
|
1321 |
deal_object_temp.append(fd_dealObject.get(category_id).get(rankCounter).get('object'))
|
|
|
1322 |
dealsListMap.append(deal_object_temp)
|
|
|
1323 |
else:
|
|
|
1324 |
break
|
|
|
1325 |
|
|
|
1326 |
temp = []
|
|
|
1327 |
if dealList is None or len(dealList)==0:
|
|
|
1328 |
continue
|
|
|
1329 |
for d in dealList:
|
|
|
1330 |
item = list(get_mongo_connection().Catalog.MasterData.find({'_id':d['_id']}))
|
|
|
1331 |
if len(item) ==0:
|
|
|
1332 |
continue
|
| 19575 |
kshitij.so |
1333 |
item[0]['dealRankPoints'] = d.get('dealRankPoints')
|
| 19559 |
kshitij.so |
1334 |
if d['dealType'] == 1 and d['source_id'] ==1:
|
|
|
1335 |
try:
|
|
|
1336 |
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())}}))
|
|
|
1337 |
item[0]['marketPlaceUrl'] = manualDeal[0]['dealUrl'].strip()
|
|
|
1338 |
except:
|
|
|
1339 |
pass
|
|
|
1340 |
elif d['source_id'] ==3:
|
|
|
1341 |
item[0]['marketPlaceUrl'] = item[0]['marketPlaceUrl']+'?supc='+item[0].get('identifier')
|
|
|
1342 |
else:
|
|
|
1343 |
pass
|
|
|
1344 |
try:
|
|
|
1345 |
cashBack = getCashBack(item[0]['_id'], item[0]['source_id'], item[0]['category_id'])
|
|
|
1346 |
if not cashBack or cashBack.get('cash_back_status')!=1:
|
|
|
1347 |
item[0]['cash_back_type'] = 0
|
|
|
1348 |
item[0]['cash_back'] = 0
|
|
|
1349 |
else:
|
|
|
1350 |
if cashBack.get('maxCashBack') is not None:
|
|
|
1351 |
|
|
|
1352 |
if cashBack.get('cash_back_type') ==1 and (float(cashBack.get('cash_back'))*item[0]['available_price'])/100 > cashBack.get('maxCashBack'):
|
|
|
1353 |
cashBack['cash_back_type'] = 2
|
|
|
1354 |
cashBack['cash_back'] = cashBack['maxCashBack']
|
|
|
1355 |
elif cashBack.get('cash_back_type') ==2 and cashBack.get('cash_back') > cashBack.get('maxCashBack'):
|
|
|
1356 |
cashBack['cash_back'] = cashBack['maxCashBack']
|
|
|
1357 |
|
|
|
1358 |
item[0]['cash_back_type'] = int(cashBack['cash_back_type'])
|
|
|
1359 |
item[0]['cash_back'] = cashBack['cash_back']
|
|
|
1360 |
except:
|
|
|
1361 |
print "Error in adding cashback to deals"
|
|
|
1362 |
item[0]['cash_back_type'] = 0
|
|
|
1363 |
item[0]['cash_back'] = 0
|
|
|
1364 |
try:
|
|
|
1365 |
item[0]['dp'] = d['dp']
|
|
|
1366 |
item[0]['showDp'] = d['showDp']
|
|
|
1367 |
except:
|
|
|
1368 |
item[0]['dp'] = 0.0
|
|
|
1369 |
item[0]['showDp'] = 0
|
|
|
1370 |
try:
|
|
|
1371 |
item[0]['thumbnail'] = item[0]['thumbnail'].strip()
|
|
|
1372 |
except:
|
|
|
1373 |
pass
|
|
|
1374 |
|
|
|
1375 |
try:
|
|
|
1376 |
if item[0]['showVideo']==0:
|
|
|
1377 |
item[0]['videoLink'] =""
|
|
|
1378 |
except:
|
|
|
1379 |
item[0]['videoLink'] =""
|
|
|
1380 |
try:
|
|
|
1381 |
if item[0]['quantity'] >1:
|
|
|
1382 |
ppq = float(item[0]['available_price'])/item[0]['quantity']
|
|
|
1383 |
|
|
|
1384 |
if ppq == round(ppq):
|
|
|
1385 |
item[0]['ppq'] = int(ppq)
|
|
|
1386 |
else:
|
|
|
1387 |
item[0]['ppq'] = round(ppq,2)
|
|
|
1388 |
else:
|
|
|
1389 |
item[0]['ppq'] = 0
|
|
|
1390 |
except:
|
|
|
1391 |
item[0]['ppq'] = 0
|
| 22293 |
amit.gupta |
1392 |
if not defaultFilter:
|
| 19559 |
kshitij.so |
1393 |
if item[0]['category_id']!=6:
|
|
|
1394 |
try:
|
|
|
1395 |
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']))
|
|
|
1396 |
item[0]['filterTextBrand'] = (item[0]['brand'])
|
|
|
1397 |
except:
|
|
|
1398 |
pass
|
|
|
1399 |
else:
|
|
|
1400 |
try:
|
|
|
1401 |
if item[0]['subCategory']=='' or item[0]['subCategory'] is None or item[0]['subCategoryId']==0:
|
|
|
1402 |
raise
|
|
|
1403 |
item[0]['filterLinkSubCategory'] = '/category/'+str(int(item[0]['category_id']))+'?searchFor='+urllib.quote(item[0]['subCategory'])+'&filter=subcategory&subcategories='+str(int(item[0]['subCategoryId']))
|
|
|
1404 |
item[0]['filterTextSubCategory'] = (item[0]['subCategory'])
|
|
|
1405 |
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']))
|
|
|
1406 |
item[0]['filterTextBrand'] = (item[0]['brand'])
|
|
|
1407 |
except:
|
|
|
1408 |
pass
|
|
|
1409 |
try:
|
|
|
1410 |
if item[0]['source_id']==4:
|
|
|
1411 |
item_availability_info = mc.get("item_availability_"+str(item[0]['identifier']).strip())
|
|
|
1412 |
if item_availability_info is None or len(item_availability_info)==0:
|
| 22329 |
amit.gupta |
1413 |
continue
|
|
|
1414 |
#item[0]['availabilityInfo'] = [{}]
|
| 19559 |
kshitij.so |
1415 |
else:
|
| 22256 |
amit.gupta |
1416 |
#remove items that are mapped with tag_ids recieved
|
|
|
1417 |
if tag_ids:
|
|
|
1418 |
#construct item_availability_info TAGS not matched
|
|
|
1419 |
item_availability_info = [av_info for av_info in item_availability_info if not (av_info.has_key('tag_ids') and not set(tag_ids).isdisjoint(av_info.get('tag_ids')))]
|
|
|
1420 |
if len(item_availability_info)==0:
|
| 22329 |
amit.gupta |
1421 |
continue
|
|
|
1422 |
#item_availability_info = [{}]
|
| 19559 |
kshitij.so |
1423 |
item[0]['availabilityInfo'] = item_availability_info
|
|
|
1424 |
except:
|
| 22329 |
amit.gupta |
1425 |
continue
|
|
|
1426 |
#item[0]['availabilityInfo'] = [{}]
|
| 19559 |
kshitij.so |
1427 |
|
|
|
1428 |
if item[0]['source_id']==4:
|
|
|
1429 |
for av_info in item[0]['availabilityInfo']:
|
|
|
1430 |
if not av_info:
|
|
|
1431 |
continue
|
|
|
1432 |
av_info['cash_back'] = item[0]['cash_back']
|
|
|
1433 |
av_info['cash_back_type'] = item[0]['cash_back_type']
|
| 21889 |
kshitij.so |
1434 |
netPriceAfterCashBack = av_info['sellingPrice']
|
| 19559 |
kshitij.so |
1435 |
if av_info['cash_back_type'] ==1:
|
|
|
1436 |
netPriceAfterCashBack = av_info['sellingPrice'] - math.floor(float(av_info['sellingPrice'])*av_info['cash_back']/100)
|
|
|
1437 |
elif av_info['cash_back_type'] ==2:
|
|
|
1438 |
netPriceAfterCashBack = av_info['sellingPrice'] - math.floor(av_info['cash_back'])
|
|
|
1439 |
else:
|
|
|
1440 |
pass
|
|
|
1441 |
av_info['netPriceAfterCashBack'] = netPriceAfterCashBack
|
|
|
1442 |
|
|
|
1443 |
#item[0]['netPriceAfterCashBack'] = d['netPriceAfterCashBack']
|
|
|
1444 |
|
| 19896 |
kshitij.so |
1445 |
if item[0]['source_id'] == SOURCE_MAP.get("PAYTM.COM"):
|
| 19559 |
kshitij.so |
1446 |
if item[0]['codAvailable'] ==1:
|
|
|
1447 |
paytmPrice = item[0]['available_price']
|
|
|
1448 |
else:
|
|
|
1449 |
paytmPrice = item[0]['gross_price']
|
|
|
1450 |
|
|
|
1451 |
if item[0]['cash_back_type'] ==1:
|
|
|
1452 |
item[0]['netPriceAfterCashBack'] = paytmPrice - math.floor(float(paytmPrice)*item[0]['cash_back']/100)
|
|
|
1453 |
elif item[0]['cash_back_type'] ==2:
|
|
|
1454 |
item[0]['netPriceAfterCashBack'] = paytmPrice - math.floor(item[0]['cash_back'])
|
|
|
1455 |
else:
|
|
|
1456 |
item[0]['netPriceAfterCashBack'] = paytmPrice
|
|
|
1457 |
|
|
|
1458 |
else:
|
|
|
1459 |
if item[0]['cash_back_type'] ==1:
|
|
|
1460 |
item[0]['netPriceAfterCashBack'] = item[0]['available_price'] - math.floor(float(item[0]['available_price'])*item[0]['cash_back']/100)
|
|
|
1461 |
elif item[0]['cash_back_type'] ==2:
|
|
|
1462 |
item[0]['netPriceAfterCashBack'] = item[0]['available_price'] - math.floor(item[0]['cash_back'])
|
|
|
1463 |
else:
|
|
|
1464 |
item[0]['netPriceAfterCashBack'] = item[0]['available_price']
|
|
|
1465 |
|
| 19320 |
kshitij.so |
1466 |
# if specialOffer is not None and item[0]['source_id']==4:
|
|
|
1467 |
# if item[0]['category_id'] in specialOffer.categories_applicable and item[0]['subCategoryId'] not in specialOffer.sub_categories_not_applicable:
|
|
|
1468 |
# item[0]['specialOffer'] = specialOffer.__dict__
|
|
|
1469 |
# else:
|
|
|
1470 |
# item[0]['specialOffer'] = {}
|
| 19288 |
kshitij.so |
1471 |
|
| 16079 |
kshitij.so |
1472 |
temp.append(item[0])
|
| 16125 |
kshitij.so |
1473 |
if len(temp) > 1:
|
| 16126 |
kshitij.so |
1474 |
temp = sorted(temp, key = lambda x: (x['available_price']),reverse=False)
|
| 16079 |
kshitij.so |
1475 |
dealsListMap.append(temp)
|
|
|
1476 |
return dealsListMap
|
| 14037 |
kshitij.so |
1477 |
|
| 22270 |
amit.gupta |
1478 |
def filterDeals(deals, filterData):
|
| 20009 |
kshitij.so |
1479 |
print "Filter data ",filterData
|
| 20011 |
kshitij.so |
1480 |
print "Length deals before filter ", len(deals)
|
| 20009 |
kshitij.so |
1481 |
brandsToFilter = []
|
|
|
1482 |
subCategoryToFilter = []
|
|
|
1483 |
priceToFilter = []
|
| 22270 |
amit.gupta |
1484 |
sourceToFilter = []
|
| 22269 |
amit.gupta |
1485 |
|
|
|
1486 |
if filterData:
|
|
|
1487 |
filterArray = filterData.split('|')
|
|
|
1488 |
for data in filterArray:
|
|
|
1489 |
try:
|
|
|
1490 |
filter, info = data.split(':')
|
|
|
1491 |
except Exception as ex:
|
|
|
1492 |
traceback.print_exc()
|
|
|
1493 |
continue
|
|
|
1494 |
if filter == 'brandFilter':
|
|
|
1495 |
brandsToFilter = info.split('^')
|
|
|
1496 |
if filter == 'subCategoryFilter':
|
|
|
1497 |
subCategoryToFilter = info.split('^')
|
|
|
1498 |
if filter == 'priceFilter':
|
|
|
1499 |
priceToFilter = info.split('^')
|
|
|
1500 |
if filter == 'sourceFilter':
|
|
|
1501 |
sourceToFilter = sourceToFilter + info.split('^')
|
|
|
1502 |
|
| 20009 |
kshitij.so |
1503 |
if brandsToFilter:
|
|
|
1504 |
temp = []
|
|
|
1505 |
for deal in deals:
|
|
|
1506 |
if str(int(deal['brand_id'])) in brandsToFilter:
|
|
|
1507 |
temp.append(deal)
|
|
|
1508 |
deals = temp
|
| 22269 |
amit.gupta |
1509 |
|
| 20011 |
kshitij.so |
1510 |
print "Length deals after brandfilter ", len(deals)
|
|
|
1511 |
|
| 20009 |
kshitij.so |
1512 |
if subCategoryToFilter:
|
|
|
1513 |
temp = []
|
|
|
1514 |
for deal in deals:
|
|
|
1515 |
if str(int(deal['subCategoryId'])) in subCategoryToFilter:
|
|
|
1516 |
temp.append(deal)
|
|
|
1517 |
deals = temp
|
|
|
1518 |
|
| 20011 |
kshitij.so |
1519 |
print "Length deals after subCatfilter ", len(deals)
|
| 22269 |
amit.gupta |
1520 |
|
| 20019 |
kshitij.so |
1521 |
if sourceToFilter:
|
|
|
1522 |
temp = []
|
|
|
1523 |
for deal in deals:
|
|
|
1524 |
if str(int(deal['source_id'])) in sourceToFilter:
|
|
|
1525 |
temp.append(deal)
|
|
|
1526 |
deals = temp
|
|
|
1527 |
|
|
|
1528 |
print "Length deals after source filter ", len(deals)
|
|
|
1529 |
|
| 20009 |
kshitij.so |
1530 |
if priceToFilter and len(priceToFilter) ==2:
|
| 20011 |
kshitij.so |
1531 |
print "Inside price filter ",priceToFilter
|
| 20009 |
kshitij.so |
1532 |
temp = []
|
|
|
1533 |
for deal in deals:
|
| 20011 |
kshitij.so |
1534 |
if deal.get('available_price') > float(priceToFilter[0]) and deal.get('available_price') <= float(priceToFilter[1]):
|
| 20009 |
kshitij.so |
1535 |
temp.append(deal)
|
|
|
1536 |
deals = temp
|
| 22269 |
amit.gupta |
1537 |
|
|
|
1538 |
print "Length deals after price filter ", len(deals)
|
| 20009 |
kshitij.so |
1539 |
|
|
|
1540 |
return [trend['skuBundleId'] for trend in temp]
|
| 14791 |
kshitij.so |
1541 |
|
| 14037 |
kshitij.so |
1542 |
def getDeals(userId, category_id, offset, limit, sort, direction):
|
| 17469 |
kshitij.so |
1543 |
if mc.get("category_cash_back") is None or not bool(mc.get("category_cash_back")):
|
| 14037 |
kshitij.so |
1544 |
populateCashBack()
|
|
|
1545 |
rank = 1
|
| 13771 |
kshitij.so |
1546 |
deals = {}
|
| 13910 |
kshitij.so |
1547 |
outer_query = []
|
|
|
1548 |
outer_query.append({"showDeal":1})
|
|
|
1549 |
query = {}
|
|
|
1550 |
query['$gt'] = 0
|
|
|
1551 |
outer_query.append({'totalPoints':query})
|
|
|
1552 |
if category_id in (3,5):
|
|
|
1553 |
outer_query.append({'category_id':category_id})
|
| 13803 |
kshitij.so |
1554 |
if sort is None or direction is None:
|
|
|
1555 |
direct = -1
|
| 13910 |
kshitij.so |
1556 |
print outer_query
|
|
|
1557 |
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 |
1558 |
else:
|
| 13910 |
kshitij.so |
1559 |
print outer_query
|
| 13803 |
kshitij.so |
1560 |
direct = direction
|
| 13910 |
kshitij.so |
1561 |
if sort == "bestSellerPoints":
|
|
|
1562 |
print "yes,sorting by bestSellerPoints"
|
|
|
1563 |
data = list(get_mongo_connection().Catalog.Deals.find({"$and":outer_query}).sort([('bestSellerPoints',direct),('rank',direct),('nlcPoints',direct)]).skip(offset).limit(limit))
|
|
|
1564 |
else:
|
|
|
1565 |
data = list(get_mongo_connection().Catalog.Deals.find({"$and":outer_query}).sort([(sort,direct)]).skip(offset).limit(limit))
|
| 13771 |
kshitij.so |
1566 |
for d in data:
|
|
|
1567 |
item = list(get_mongo_connection().Catalog.MasterData.find({'_id':d['_id']}))
|
|
|
1568 |
if not deals.has_key(item[0]['identifier']):
|
| 13921 |
kshitij.so |
1569 |
item[0]['dealRank'] = rank
|
|
|
1570 |
try:
|
| 14761 |
kshitij.so |
1571 |
cashBack = getCashBack(item[0]['_id'], item[0]['source_id'], item[0]['category_id'])
|
| 13921 |
kshitij.so |
1572 |
if not cashBack or cashBack.get('cash_back_status')!=1:
|
| 13928 |
kshitij.so |
1573 |
item[0]['cash_back_type'] = 0
|
|
|
1574 |
item[0]['cash_back'] = 0
|
| 13921 |
kshitij.so |
1575 |
else:
|
| 14766 |
kshitij.so |
1576 |
item[0]['cash_back_type'] = int(cashBack['cash_back_type'])
|
| 13928 |
kshitij.so |
1577 |
item[0]['cash_back'] = cashBack['cash_back']
|
| 13921 |
kshitij.so |
1578 |
except:
|
|
|
1579 |
print "Error in adding cashback to deals"
|
| 13928 |
kshitij.so |
1580 |
item[0]['cash_back_type'] = 0
|
|
|
1581 |
item[0]['cash_back'] = 0
|
| 13771 |
kshitij.so |
1582 |
deals[item[0]['identifier']] = item[0]
|
| 13921 |
kshitij.so |
1583 |
|
| 13771 |
kshitij.so |
1584 |
rank +=1
|
| 13785 |
kshitij.so |
1585 |
return sorted(deals.values(), key=itemgetter('dealRank'))
|
|
|
1586 |
|
| 16222 |
kshitij.so |
1587 |
def getItem(skuId,showDp=None):
|
| 16224 |
kshitij.so |
1588 |
temp = []
|
| 17469 |
kshitij.so |
1589 |
if mc.get("category_cash_back") is None or not bool(mc.get("category_cash_back")):
|
| 14113 |
kshitij.so |
1590 |
populateCashBack()
|
| 13795 |
kshitij.so |
1591 |
try:
|
| 16222 |
kshitij.so |
1592 |
skuData = get_mongo_connection().Catalog.MasterData.find_one({'_id':int(skuId)})
|
|
|
1593 |
if skuData is None:
|
|
|
1594 |
raise
|
|
|
1595 |
try:
|
|
|
1596 |
cashBack = getCashBack(skuData['_id'], skuData['source_id'], skuData['category_id'])
|
|
|
1597 |
if not cashBack or cashBack.get('cash_back_status')!=1:
|
|
|
1598 |
skuData['cash_back_type'] = 0
|
|
|
1599 |
skuData['cash_back'] = 0
|
|
|
1600 |
else:
|
|
|
1601 |
skuData['cash_back_type'] = cashBack['cash_back_type']
|
|
|
1602 |
skuData['cash_back'] = cashBack['cash_back']
|
|
|
1603 |
except:
|
|
|
1604 |
print "Error in adding cashback to deals"
|
|
|
1605 |
skuData['cash_back_type'] = 0
|
|
|
1606 |
skuData['cash_back'] = 0
|
|
|
1607 |
skuData['in_stock'] = int(skuData['in_stock'])
|
|
|
1608 |
skuData['is_shortage'] = int(skuData['is_shortage'])
|
|
|
1609 |
skuData['category_id'] = int(skuData['category_id'])
|
| 17607 |
kshitij.so |
1610 |
skuData['subCategoryId'] = int(skuData['subCategoryId'])
|
| 16222 |
kshitij.so |
1611 |
skuData['status'] = int(skuData['status'])
|
| 16483 |
kshitij.so |
1612 |
try:
|
|
|
1613 |
skuData['thumbnail'] = skuData['thumbnail'].strip()
|
|
|
1614 |
except:
|
|
|
1615 |
pass
|
| 16222 |
kshitij.so |
1616 |
if showDp is not None:
|
|
|
1617 |
dealerPrice = get_mongo_connection().Catalog.SkuDealerPrices.find_one({'skuBundleId':skuData['skuBundleId']})
|
|
|
1618 |
skuData['dp'] = 0.0
|
|
|
1619 |
skuData['showDp'] = 0
|
|
|
1620 |
if dealerPrice is not None:
|
|
|
1621 |
skuData['dp'] = dealerPrice['dp']
|
|
|
1622 |
skuData['showDp'] = dealerPrice['showDp']
|
| 16224 |
kshitij.so |
1623 |
temp.append(skuData)
|
|
|
1624 |
return temp
|
| 13795 |
kshitij.so |
1625 |
except:
|
| 16224 |
kshitij.so |
1626 |
return []
|
| 13836 |
kshitij.so |
1627 |
|
| 14761 |
kshitij.so |
1628 |
def getCashBack(skuId, source_id, category_id):
|
| 17469 |
kshitij.so |
1629 |
if mc.get("category_cash_back") is None or not bool(mc.get("category_cash_back")):
|
| 14761 |
kshitij.so |
1630 |
populateCashBack()
|
|
|
1631 |
itemCashBackMap = mc.get("item_cash_back")
|
| 13921 |
kshitij.so |
1632 |
itemCashBack = itemCashBackMap.get(skuId)
|
|
|
1633 |
if itemCashBack is not None:
|
|
|
1634 |
return itemCashBack
|
| 14761 |
kshitij.so |
1635 |
cashBackMap = mc.get("category_cash_back")
|
| 13921 |
kshitij.so |
1636 |
sourceCashBack = cashBackMap.get(source_id)
|
|
|
1637 |
if sourceCashBack is not None and len(sourceCashBack) > 0:
|
|
|
1638 |
for cashBack in sourceCashBack:
|
|
|
1639 |
if cashBack.get(category_id) is None:
|
|
|
1640 |
continue
|
|
|
1641 |
else:
|
|
|
1642 |
return cashBack.get(category_id)
|
|
|
1643 |
else:
|
|
|
1644 |
return {}
|
| 16560 |
amit.gupta |
1645 |
|
|
|
1646 |
def getBundleBySourceSku(source_id, identifier):
|
| 17035 |
kshitij.so |
1647 |
if source_id in (1,2,4,5,6,7):
|
| 16560 |
amit.gupta |
1648 |
skuData = list(get_mongo_connection().Catalog.MasterData.find({'identifier':identifier.strip(), 'source_id':source_id}))
|
|
|
1649 |
elif source_id == 3:
|
|
|
1650 |
skuData = list(get_mongo_connection().Catalog.MasterData.find({'secondaryIdentifier':identifier.strip(), 'source_id':source_id}))
|
|
|
1651 |
else:
|
|
|
1652 |
return {}
|
|
|
1653 |
|
|
|
1654 |
if not skuData:
|
|
|
1655 |
return {}
|
|
|
1656 |
else:
|
| 16564 |
amit.gupta |
1657 |
bundleId = skuData[0]["skuBundleId"]
|
| 17035 |
kshitij.so |
1658 |
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 |
1659 |
{"source_id":1, "available_price":1, "marketPlaceUrl":1, "gross_price":1, "codAvailable":1, "source_product_name":1, "offer":1, "coupon":1}))
|
| 16579 |
amit.gupta |
1660 |
return {'products':itemIds}
|
| 16560 |
amit.gupta |
1661 |
|
|
|
1662 |
|
| 13921 |
kshitij.so |
1663 |
|
| 15129 |
kshitij.so |
1664 |
def getDealRank(identifier, source_id, userId):
|
| 17035 |
kshitij.so |
1665 |
if source_id in (1,2,4,5,6,7):
|
| 15129 |
kshitij.so |
1666 |
skuData = list(get_mongo_connection().Catalog.MasterData.find({'identifier':identifier.strip(), 'source_id':source_id}))
|
|
|
1667 |
elif source_id == 3:
|
|
|
1668 |
skuData = list(get_mongo_connection().Catalog.MasterData.find({'secondaryIdentifier':identifier.strip(), 'source_id':source_id}))
|
|
|
1669 |
else:
|
| 16282 |
amit.gupta |
1670 |
return {'rank':0, 'description':'Source not valid','maxNlc':None, 'minNlc':None,'status':None,'dp':None}
|
| 15349 |
kshitij.so |
1671 |
if len(skuData) == 0:
|
| 16282 |
amit.gupta |
1672 |
return {'rank':0, 'description':'No matching product identifier found','maxNlc':None, 'minNlc':None,'status':None,'dp':None}
|
| 19580 |
kshitij.so |
1673 |
category_id = skuData[0]['category_id']
|
|
|
1674 |
if category_id != 6:
|
| 15129 |
kshitij.so |
1675 |
user_specific_deals = mc.get(str(userId))
|
| 19580 |
kshitij.so |
1676 |
if user_specific_deals is None:
|
|
|
1677 |
__populateCache(userId)
|
|
|
1678 |
user_specific_deals = mc.get(str(userId))
|
|
|
1679 |
else:
|
|
|
1680 |
print "Getting user deals from cache mobiles/tablets"
|
| 15129 |
kshitij.so |
1681 |
else:
|
| 19580 |
kshitij.so |
1682 |
user_specific_deals = mc.get(str(userId)+'_acc')
|
|
|
1683 |
if user_specific_deals is None:
|
|
|
1684 |
__populateCacheForAccessories(userId)
|
|
|
1685 |
user_specific_deals = mc.get(str(userId)+'_acc')
|
|
|
1686 |
else:
|
|
|
1687 |
print "Getting user deals from accessory cache"
|
|
|
1688 |
|
| 15129 |
kshitij.so |
1689 |
category_specific_deals = user_specific_deals.get(category_id)
|
| 16280 |
kshitij.so |
1690 |
|
|
|
1691 |
dealsData = get_mongo_connection().Catalog.Deals.find_one({'skuBundleId':skuData[0]['skuBundleId']})
|
|
|
1692 |
if dealsData is None:
|
|
|
1693 |
dealsData = {}
|
| 19580 |
kshitij.so |
1694 |
return {'rank':0, 'description':'Deal deleted from system','maxNlc':None, 'minNlc':None,'status':None,'dp':None}
|
| 16280 |
kshitij.so |
1695 |
|
| 15129 |
kshitij.so |
1696 |
if category_specific_deals is None or len(category_specific_deals) ==0:
|
| 16280 |
kshitij.so |
1697 |
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')}
|
| 19580 |
kshitij.so |
1698 |
|
|
|
1699 |
if category_id!=6:
|
|
|
1700 |
sorted_deals = sorted(category_specific_deals, key = lambda x: (x['persPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
|
|
|
1701 |
else:
|
|
|
1702 |
sorted_deals = sorted(category_specific_deals, key = lambda x: (x['dealRankPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints']),reverse=True)
|
|
|
1703 |
|
| 16168 |
kshitij.so |
1704 |
sortedMap = {}
|
|
|
1705 |
rankMap = {}
|
|
|
1706 |
rank = 0
|
| 15129 |
kshitij.so |
1707 |
for sorted_deal in sorted_deals:
|
| 16168 |
kshitij.so |
1708 |
if sortedMap.get(sorted_deal['skuBundleId']) is None:
|
|
|
1709 |
sortedMap[sorted_deal['skuBundleId']] = {rank:[sorted_deal]}
|
|
|
1710 |
rankMap[rank] = (sortedMap[sorted_deal['skuBundleId']].values())[0]
|
|
|
1711 |
rank = rank +1
|
|
|
1712 |
else:
|
|
|
1713 |
for temp_list in sortedMap.get(sorted_deal['skuBundleId']).itervalues():
|
|
|
1714 |
temp_list.append(sorted_deal)
|
|
|
1715 |
rankMap[(sortedMap.get(sorted_deal['skuBundleId']).keys())[0]] = temp_list
|
|
|
1716 |
|
| 16187 |
kshitij.so |
1717 |
for dealRank ,dealList in rankMap.iteritems():
|
| 16168 |
kshitij.so |
1718 |
for d in dealList:
|
| 16186 |
kshitij.so |
1719 |
if d['skuBundleId'] == skuData[0]['skuBundleId']:
|
| 16280 |
kshitij.so |
1720 |
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 |
1721 |
|
| 16280 |
kshitij.so |
1722 |
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 |
1723 |
|
|
|
1724 |
|
| 13836 |
kshitij.so |
1725 |
def getCashBackDetails(identifier, source_id):
|
| 17469 |
kshitij.so |
1726 |
if mc.get("category_cash_back") is None or not bool(mc.get("category_cash_back")):
|
| 13921 |
kshitij.so |
1727 |
populateCashBack()
|
| 13771 |
kshitij.so |
1728 |
|
| 17035 |
kshitij.so |
1729 |
if source_id in (1,2,4,5,6,7):
|
| 13839 |
kshitij.so |
1730 |
skuData = list(get_mongo_connection().Catalog.MasterData.find({'identifier':identifier.strip(), 'source_id':source_id}))
|
| 13840 |
kshitij.so |
1731 |
elif source_id == 3:
|
| 13839 |
kshitij.so |
1732 |
skuData = list(get_mongo_connection().Catalog.MasterData.find({'secondaryIdentifier':identifier.strip(), 'source_id':source_id}))
|
| 13840 |
kshitij.so |
1733 |
else:
|
|
|
1734 |
return {}
|
| 13836 |
kshitij.so |
1735 |
if len(skuData) > 0:
|
| 14761 |
kshitij.so |
1736 |
itemCashBackMap = mc.get("item_cash_back")
|
| 13921 |
kshitij.so |
1737 |
itemCashBack = itemCashBackMap.get(skuData[0]['_id'])
|
|
|
1738 |
if itemCashBack is not None:
|
|
|
1739 |
return itemCashBack
|
| 14761 |
kshitij.so |
1740 |
cashBackMap = mc.get("category_cash_back")
|
| 13921 |
kshitij.so |
1741 |
sourceCashBack = cashBackMap.get(source_id)
|
|
|
1742 |
if sourceCashBack is not None and len(sourceCashBack) > 0:
|
|
|
1743 |
for cashBack in sourceCashBack:
|
|
|
1744 |
if cashBack.get(skuData[0]['category_id']) is None:
|
|
|
1745 |
continue
|
|
|
1746 |
else:
|
|
|
1747 |
return cashBack.get(skuData[0]['category_id'])
|
| 20698 |
amit.gupta |
1748 |
return {}
|
| 13836 |
kshitij.so |
1749 |
else:
|
|
|
1750 |
return {}
|
|
|
1751 |
else:
|
|
|
1752 |
return {}
|
| 13986 |
amit.gupta |
1753 |
|
| 14398 |
amit.gupta |
1754 |
def getImgSrc(identifier, source_id):
|
|
|
1755 |
skuData = None
|
| 17035 |
kshitij.so |
1756 |
if source_id in (1,2,4,5,6,7):
|
| 14414 |
amit.gupta |
1757 |
skuData = get_mongo_connection().Catalog.MasterData.find_one({'identifier':identifier.strip(), 'source_id':source_id})
|
| 14398 |
amit.gupta |
1758 |
elif source_id == 3:
|
| 14414 |
amit.gupta |
1759 |
skuData = get_mongo_connection().Catalog.MasterData.find_one({'secondaryIdentifier':identifier.strip(), 'source_id':source_id})
|
| 14398 |
amit.gupta |
1760 |
if skuData is None:
|
|
|
1761 |
return {}
|
|
|
1762 |
else:
|
| 16483 |
kshitij.so |
1763 |
try:
|
|
|
1764 |
return {'thumbnail':skuData.get('thumbnail').strip()}
|
|
|
1765 |
except:
|
|
|
1766 |
return {'thumbnail':skuData.get('thumbnail')}
|
| 13986 |
amit.gupta |
1767 |
|
|
|
1768 |
def next_weekday(d, weekday):
|
|
|
1769 |
days_ahead = weekday - d.weekday()
|
|
|
1770 |
if days_ahead <= 0: # Target day already happened this week
|
|
|
1771 |
days_ahead += 7
|
|
|
1772 |
return d + timedelta(days_ahead)
|
|
|
1773 |
|
| 13771 |
kshitij.so |
1774 |
|
| 13970 |
kshitij.so |
1775 |
def getAllDealerPrices(offset, limit):
|
|
|
1776 |
data = []
|
|
|
1777 |
collection = get_mongo_connection().Catalog.SkuDealerPrices
|
|
|
1778 |
cursor = collection.find().skip(offset).limit(limit)
|
|
|
1779 |
for val in cursor:
|
| 15853 |
kshitij.so |
1780 |
master = get_mongo_connection().Catalog.MasterData.find_one({'skuBundleId':val['skuBundleId']})
|
|
|
1781 |
if master is not None:
|
|
|
1782 |
val['brand'] = master['brand']
|
|
|
1783 |
val['source_product_name'] = master['source_product_name']
|
| 13970 |
kshitij.so |
1784 |
else:
|
|
|
1785 |
val['brand'] = ""
|
|
|
1786 |
val['source_product_name'] = ""
|
| 16231 |
kshitij.so |
1787 |
val['showDp'] = int(val['showDp'])
|
| 13970 |
kshitij.so |
1788 |
data.append(val)
|
|
|
1789 |
return data
|
|
|
1790 |
|
| 15853 |
kshitij.so |
1791 |
def addSkuDealerPrice(data):
|
|
|
1792 |
collection = get_mongo_connection().Catalog.SkuDealerPrices
|
|
|
1793 |
cursor = collection.find_one({"skuBundleId":data['skuBundleId']})
|
|
|
1794 |
if cursor is not None:
|
|
|
1795 |
return {0:"BundleId information already present."}
|
| 13970 |
kshitij.so |
1796 |
else:
|
| 15853 |
kshitij.so |
1797 |
collection.insert(data)
|
|
|
1798 |
get_mongo_connection().Catalog.MasterData.update({'skuBundleId':data['skuBundleId']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
| 13970 |
kshitij.so |
1799 |
return {1:"Data added successfully"}
|
|
|
1800 |
|
|
|
1801 |
def updateSkuDealerPrice(data, _id):
|
|
|
1802 |
try:
|
|
|
1803 |
collection = get_mongo_connection().Catalog.SkuDealerPrices
|
|
|
1804 |
collection.update({'_id':ObjectId(_id)},{"$set":{'dp':data['dp']}},upsert=False, multi = False)
|
| 15853 |
kshitij.so |
1805 |
get_mongo_connection().Catalog.MasterData.update({'skuBundleId':data['skuBundleId']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
| 13970 |
kshitij.so |
1806 |
return {1:"Data updated successfully"}
|
|
|
1807 |
except:
|
|
|
1808 |
return {0:"Data not updated."}
|
|
|
1809 |
|
|
|
1810 |
def updateExceptionalNlc(data, _id):
|
|
|
1811 |
try:
|
|
|
1812 |
collection = get_mongo_connection().Catalog.ExceptionalNlc
|
|
|
1813 |
collection.update({'_id':ObjectId(_id)},{"$set":{'maxNlc':data['maxNlc'], 'minNlc':data['minNlc'], 'overrideNlc':data['overrideNlc']}},upsert=False, multi = False)
|
| 15853 |
kshitij.so |
1814 |
get_mongo_connection().Catalog.MasterData.update({'skuBundleId':data['skuBundleId']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
| 13970 |
kshitij.so |
1815 |
return {1:"Data updated successfully"}
|
|
|
1816 |
except:
|
|
|
1817 |
return {0:"Data not updated."}
|
|
|
1818 |
|
| 20456 |
kshitij.so |
1819 |
def resetCache(cache_type, keys):
|
| 20443 |
kshitij.so |
1820 |
if (cache_type == 'deals'):
|
| 20456 |
kshitij.so |
1821 |
for userId in keys.split(','):
|
| 20458 |
kshitij.so |
1822 |
mc.delete(userId)
|
|
|
1823 |
mc.delete(userId+'_acc')
|
| 14043 |
kshitij.so |
1824 |
return {1:'Cache cleared.'}
|
| 20443 |
kshitij.so |
1825 |
elif (cache_type == 'itemCashBack'):
|
|
|
1826 |
mc.delete('item_cash_back')
|
|
|
1827 |
populateCashBack()
|
|
|
1828 |
return {1:'Cache cleared.'}
|
|
|
1829 |
else:
|
|
|
1830 |
{0:'Illegal cache type'}
|
|
|
1831 |
|
|
|
1832 |
|
| 15853 |
kshitij.so |
1833 |
def updateCollection(data):
|
|
|
1834 |
try:
|
|
|
1835 |
collection = get_mongo_connection().Catalog[data['class']]
|
|
|
1836 |
class_name = data.pop('class')
|
|
|
1837 |
_id = data.pop('oid')
|
|
|
1838 |
result = collection.update({'_id':ObjectId(_id)},{"$set":data},upsert=False, multi = False)
|
|
|
1839 |
if class_name != "Notifications":
|
|
|
1840 |
record = list(collection.find({'_id':ObjectId(_id)}))
|
|
|
1841 |
if class_name !="CategoryDiscount":
|
|
|
1842 |
if record[0].has_key('sku'):
|
|
|
1843 |
field = '_id'
|
|
|
1844 |
val = record[0]['sku']
|
| 14852 |
kshitij.so |
1845 |
else:
|
| 15853 |
kshitij.so |
1846 |
field = 'skuBundleId'
|
|
|
1847 |
val = record[0]['skuBundleId']
|
|
|
1848 |
get_mongo_connection().Catalog.MasterData.update({field:val},{"$set":{'updatedOn':to_java_date(datetime.now())}},upsert=False, multi = True)
|
|
|
1849 |
else:
|
|
|
1850 |
get_mongo_connection().Catalog.MasterData.update({'brand':re.compile(record[0]['brand'], re.IGNORECASE),'category_id':record[0]['category_id']}, \
|
|
|
1851 |
{"$set":{'updatedOn':to_java_date(datetime.now())}},upsert=False,multi=True)
|
| 16233 |
kshitij.so |
1852 |
if class_name =='SkuDealerPrices':
|
| 16237 |
kshitij.so |
1853 |
get_mongo_connection().Catalog.Deals.update({'skuBundleId':val},{"$set":data},upsert=False, multi=True)
|
| 15853 |
kshitij.so |
1854 |
return {1:"Data updated successfully"}
|
|
|
1855 |
except Exception as e:
|
|
|
1856 |
print e
|
|
|
1857 |
return {0:"Data not updated."}
|
| 14575 |
kshitij.so |
1858 |
|
| 14076 |
kshitij.so |
1859 |
|
| 14553 |
kshitij.so |
1860 |
def addNegativeDeals(data, multi):
|
|
|
1861 |
if multi !=1:
|
|
|
1862 |
collection = get_mongo_connection().Catalog.NegativeDeals
|
|
|
1863 |
cursor = collection.find({"sku":data['sku']})
|
|
|
1864 |
if cursor.count() > 0:
|
|
|
1865 |
return {0:"Sku information already present."}
|
|
|
1866 |
else:
|
|
|
1867 |
collection.insert(data)
|
|
|
1868 |
return {1:"Data added successfully"}
|
| 14481 |
kshitij.so |
1869 |
else:
|
| 14553 |
kshitij.so |
1870 |
skuIds = __getBundledSkusfromSku(data['sku'])
|
|
|
1871 |
for sku in skuIds:
|
|
|
1872 |
data['sku'] = sku.get('_id')
|
|
|
1873 |
collection = get_mongo_connection().Catalog.NegativeDeals
|
|
|
1874 |
cursor = collection.find({"sku":data['sku']})
|
|
|
1875 |
if cursor.count() > 0:
|
|
|
1876 |
continue
|
|
|
1877 |
else:
|
| 14558 |
kshitij.so |
1878 |
data.pop('_id',None)
|
| 14553 |
kshitij.so |
1879 |
collection.insert(data)
|
| 14481 |
kshitij.so |
1880 |
return {1:"Data added successfully"}
|
|
|
1881 |
|
|
|
1882 |
def getAllNegativeDeals(offset, limit):
|
|
|
1883 |
data = []
|
|
|
1884 |
collection = get_mongo_connection().Catalog.NegativeDeals
|
|
|
1885 |
cursor = collection.find().skip(offset).limit(limit)
|
|
|
1886 |
for val in cursor:
|
|
|
1887 |
master = list(get_mongo_connection().Catalog.MasterData.find({'_id':val['sku']}))
|
|
|
1888 |
if len(master) > 0:
|
|
|
1889 |
val['brand'] = master[0]['brand']
|
|
|
1890 |
val['source_product_name'] = master[0]['source_product_name']
|
|
|
1891 |
val['skuBundleId'] = master[0]['skuBundleId']
|
|
|
1892 |
else:
|
|
|
1893 |
val['brand'] = ""
|
|
|
1894 |
val['source_product_name'] = ""
|
|
|
1895 |
val['skuBundleId'] = ""
|
|
|
1896 |
data.append(val)
|
|
|
1897 |
return data
|
|
|
1898 |
|
|
|
1899 |
def getAllManualDeals(offset, limit):
|
|
|
1900 |
data = []
|
|
|
1901 |
collection = get_mongo_connection().Catalog.ManualDeals
|
| 15090 |
kshitij.so |
1902 |
cursor = collection.find().skip(offset).limit(limit)
|
| 14481 |
kshitij.so |
1903 |
for val in cursor:
|
|
|
1904 |
master = list(get_mongo_connection().Catalog.MasterData.find({'_id':val['sku']}))
|
|
|
1905 |
if len(master) > 0:
|
|
|
1906 |
val['brand'] = master[0]['brand']
|
|
|
1907 |
val['source_product_name'] = master[0]['source_product_name']
|
|
|
1908 |
val['skuBundleId'] = master[0]['skuBundleId']
|
|
|
1909 |
else:
|
|
|
1910 |
val['brand'] = ""
|
|
|
1911 |
val['source_product_name'] = ""
|
|
|
1912 |
val['skuBundleId'] = ""
|
|
|
1913 |
data.append(val)
|
|
|
1914 |
return data
|
| 14076 |
kshitij.so |
1915 |
|
| 14553 |
kshitij.so |
1916 |
def addManualDeal(data, multi):
|
|
|
1917 |
if multi !=1:
|
|
|
1918 |
collection = get_mongo_connection().Catalog.ManualDeals
|
| 15090 |
kshitij.so |
1919 |
cursor = collection.find({'sku':data['sku']})
|
| 14553 |
kshitij.so |
1920 |
if cursor.count() > 0:
|
|
|
1921 |
return {0:"Sku information already present."}
|
|
|
1922 |
else:
|
|
|
1923 |
collection.insert(data)
|
|
|
1924 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['sku']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=False)
|
|
|
1925 |
return {1:"Data added successfully"}
|
| 14481 |
kshitij.so |
1926 |
else:
|
| 14553 |
kshitij.so |
1927 |
skuIds = __getBundledSkusfromSku(data['sku'])
|
|
|
1928 |
for sku in skuIds:
|
|
|
1929 |
data['sku'] = sku.get('_id')
|
|
|
1930 |
collection = get_mongo_connection().Catalog.ManualDeals
|
| 15090 |
kshitij.so |
1931 |
cursor = collection.find({'sku':data['sku']})
|
| 14553 |
kshitij.so |
1932 |
if cursor.count() > 0:
|
|
|
1933 |
continue
|
|
|
1934 |
else:
|
| 14558 |
kshitij.so |
1935 |
data.pop('_id',None)
|
| 14553 |
kshitij.so |
1936 |
collection.insert(data)
|
|
|
1937 |
get_mongo_connection().Catalog.MasterData.update({'skuBundleId':sku.get('skuBundleId')},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
| 14481 |
kshitij.so |
1938 |
return {1:"Data added successfully"}
|
| 14553 |
kshitij.so |
1939 |
|
| 14481 |
kshitij.so |
1940 |
def deleteDocument(data):
|
| 15853 |
kshitij.so |
1941 |
print "inside detete document"
|
| 14481 |
kshitij.so |
1942 |
print data
|
|
|
1943 |
try:
|
|
|
1944 |
collection = get_mongo_connection().Catalog[data['class']]
|
|
|
1945 |
class_name = data.pop('class')
|
|
|
1946 |
_id = data.pop('oid')
|
|
|
1947 |
record = list(collection.find({'_id':ObjectId(_id)}))
|
|
|
1948 |
collection.remove({'_id':ObjectId(_id)})
|
| 15075 |
kshitij.so |
1949 |
if class_name != "Notifications":
|
|
|
1950 |
if class_name !="CategoryDiscount":
|
| 15853 |
kshitij.so |
1951 |
print record[0]
|
|
|
1952 |
if record[0].has_key('sku'):
|
|
|
1953 |
field = '_id'
|
|
|
1954 |
val = record[0]['sku']
|
|
|
1955 |
else:
|
|
|
1956 |
field = 'skuBundleId'
|
|
|
1957 |
val = record[0]['skuBundleId']
|
|
|
1958 |
print "Updating master"
|
|
|
1959 |
print field
|
|
|
1960 |
print val
|
|
|
1961 |
get_mongo_connection().Catalog.MasterData.update({field:val},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
| 15075 |
kshitij.so |
1962 |
else:
|
|
|
1963 |
get_mongo_connection().Catalog.MasterData.update({'brand':re.compile(record[0]['brand'], re.IGNORECASE),'category_id':record[0]['category_id']}, \
|
|
|
1964 |
{"$set":{'updatedOn':to_java_date(datetime.now())}},upsert=False,multi=True)
|
| 14481 |
kshitij.so |
1965 |
return {1:"Document deleted successfully"}
|
|
|
1966 |
except Exception as e:
|
|
|
1967 |
print e
|
|
|
1968 |
return {0:"Document not deleted."}
|
| 13970 |
kshitij.so |
1969 |
|
| 14482 |
kshitij.so |
1970 |
def searchMaster(offset, limit, search_term):
|
|
|
1971 |
data = []
|
| 14531 |
kshitij.so |
1972 |
if search_term is not None:
|
| 14551 |
kshitij.so |
1973 |
terms = search_term.split(' ')
|
|
|
1974 |
outer_query = []
|
|
|
1975 |
for term in terms:
|
|
|
1976 |
outer_query.append({"source_product_name":re.compile(term, re.IGNORECASE)})
|
| 14531 |
kshitij.so |
1977 |
try:
|
| 14551 |
kshitij.so |
1978 |
collection = get_mongo_connection().Catalog.MasterData.find({"$and":outer_query,'source_id':{'$in':SOURCE_MAP.keys()}}).skip(offset).limit(limit)
|
| 14531 |
kshitij.so |
1979 |
for record in collection:
|
|
|
1980 |
data.append(record)
|
|
|
1981 |
except:
|
|
|
1982 |
pass
|
|
|
1983 |
else:
|
|
|
1984 |
collection = get_mongo_connection().Catalog.MasterData.find({'source_id':{'$in':SOURCE_MAP.keys()}}).skip(offset).limit(limit)
|
| 14482 |
kshitij.so |
1985 |
for record in collection:
|
|
|
1986 |
data.append(record)
|
|
|
1987 |
return data
|
| 14481 |
kshitij.so |
1988 |
|
| 14495 |
kshitij.so |
1989 |
def getAllFeaturedDeals(offset, limit):
|
|
|
1990 |
data = []
|
|
|
1991 |
collection = get_mongo_connection().Catalog.FeaturedDeals
|
| 17561 |
kshitij.so |
1992 |
cursor = collection.find({}).skip(offset).limit(limit)
|
| 14495 |
kshitij.so |
1993 |
for val in cursor:
|
| 17367 |
kshitij.so |
1994 |
master = list(get_mongo_connection().Catalog.MasterData.find({'skuBundleId':val['skuBundleId']}))
|
| 14495 |
kshitij.so |
1995 |
if len(master) > 0:
|
|
|
1996 |
val['brand'] = master[0]['brand']
|
|
|
1997 |
val['source_product_name'] = master[0]['source_product_name']
|
|
|
1998 |
val['skuBundleId'] = master[0]['skuBundleId']
|
|
|
1999 |
else:
|
|
|
2000 |
val['brand'] = ""
|
|
|
2001 |
val['source_product_name'] = ""
|
|
|
2002 |
val['skuBundleId'] = ""
|
|
|
2003 |
data.append(val)
|
|
|
2004 |
return data
|
|
|
2005 |
|
| 14553 |
kshitij.so |
2006 |
def addFeaturedDeal(data, multi):
|
| 17367 |
kshitij.so |
2007 |
collection = get_mongo_connection().Catalog.FeaturedDeals
|
|
|
2008 |
cursor = collection.find({'skuBundleId':data['skuBundleId']})
|
|
|
2009 |
master = get_mongo_connection().Catalog.MasterData.find_one({'skuBundleId':data['skuBundleId']})
|
|
|
2010 |
if master is None:
|
|
|
2011 |
return {0:"BundleId is wrong"}
|
| 17469 |
kshitij.so |
2012 |
otherInfoObj = data['otherInfo']
|
|
|
2013 |
toPop = []
|
|
|
2014 |
for x,y in otherInfoObj.iteritems():
|
|
|
2015 |
if y==0:
|
|
|
2016 |
toPop.append(x)
|
|
|
2017 |
|
|
|
2018 |
for popItem in toPop:
|
|
|
2019 |
otherInfoObj.pop(popItem)
|
|
|
2020 |
if len(otherInfoObj.keys())==0:
|
|
|
2021 |
return {0:"No rank info to add"}
|
|
|
2022 |
|
|
|
2023 |
for x,y in otherInfoObj.iteritems():
|
|
|
2024 |
exist = get_mongo_connection().Catalog.FeaturedDeals.find({'otherInfo.'+x:y})
|
|
|
2025 |
if exist.count() >0:
|
|
|
2026 |
return {0:"Rank already assigned bundleId %s"%(exist[0]['skuBundleId'])}
|
| 17367 |
kshitij.so |
2027 |
if cursor.count() > 0:
|
|
|
2028 |
return {0:"SkuBundleId information already present."}
|
| 14495 |
kshitij.so |
2029 |
else:
|
| 17367 |
kshitij.so |
2030 |
collection.insert(data)
|
| 14495 |
kshitij.so |
2031 |
return {1:"Data added successfully"}
|
|
|
2032 |
|
| 14499 |
kshitij.so |
2033 |
def searchCollection(class_name, sku, skuBundleId):
|
| 14497 |
kshitij.so |
2034 |
data = []
|
|
|
2035 |
collection = get_mongo_connection().Catalog[class_name]
|
| 15076 |
kshitij.so |
2036 |
if class_name == "Notifications":
|
|
|
2037 |
cursor = collection.find({'skuBundleId':skuBundleId})
|
|
|
2038 |
for val in cursor:
|
|
|
2039 |
master = list(get_mongo_connection().Catalog.MasterData.find({'skuBundleId':val['skuBundleId']}))
|
|
|
2040 |
if len(master) > 0:
|
|
|
2041 |
val['brand'] = master[0]['brand']
|
|
|
2042 |
val['model_name'] = master[0]['model_name']
|
|
|
2043 |
val['skuBundleId'] = master[0]['skuBundleId']
|
|
|
2044 |
else:
|
|
|
2045 |
val['brand'] = ""
|
|
|
2046 |
val['model_name'] = ""
|
|
|
2047 |
val['skuBundleId'] = val['skuBundleId']
|
|
|
2048 |
data.append(val)
|
| 15095 |
kshitij.so |
2049 |
return data
|
| 15853 |
kshitij.so |
2050 |
master = None
|
| 14499 |
kshitij.so |
2051 |
if sku is not None:
|
| 15853 |
kshitij.so |
2052 |
if COLLECTION_MAP.has_key(class_name):
|
|
|
2053 |
master = get_mongo_connection().Catalog.MasterData.find_one({'_id':sku})
|
|
|
2054 |
cursor = collection.find({'skuBundleId':master['skuBundleId']})
|
|
|
2055 |
else:
|
|
|
2056 |
cursor = collection.find({'sku':sku})
|
| 14499 |
kshitij.so |
2057 |
for val in cursor:
|
| 15853 |
kshitij.so |
2058 |
if master is None:
|
|
|
2059 |
master = get_mongo_connection().Catalog.MasterData.find_one({'_id':val['sku']})
|
|
|
2060 |
if master is not None:
|
|
|
2061 |
val['brand'] = master['brand']
|
|
|
2062 |
val['source_product_name'] = master['source_product_name']
|
|
|
2063 |
val['skuBundleId'] = master['skuBundleId']
|
| 20459 |
kshitij.so |
2064 |
val['product_name'] = master['product_name']
|
|
|
2065 |
val['source'] = SOURCE_MAP.get(master['source_id'])
|
| 14499 |
kshitij.so |
2066 |
else:
|
|
|
2067 |
val['brand'] = ""
|
|
|
2068 |
val['source_product_name'] = ""
|
|
|
2069 |
val['skuBundleId'] = ""
|
|
|
2070 |
data.append(val)
|
|
|
2071 |
return data
|
|
|
2072 |
else:
|
| 15853 |
kshitij.so |
2073 |
if not COLLECTION_MAP.has_key(class_name):
|
|
|
2074 |
skuIds = get_mongo_connection().Catalog.MasterData.find({'skuBundleId':skuBundleId}).distinct('_id')
|
|
|
2075 |
for sku in skuIds:
|
|
|
2076 |
cursor = collection.find({'sku':sku})
|
|
|
2077 |
for val in cursor:
|
|
|
2078 |
master = list(get_mongo_connection().Catalog.MasterData.find({'_id':val['sku']}))
|
|
|
2079 |
if len(master) > 0:
|
|
|
2080 |
val['brand'] = master[0]['brand']
|
|
|
2081 |
val['source_product_name'] = master[0]['source_product_name']
|
|
|
2082 |
val['skuBundleId'] = master[0]['skuBundleId']
|
| 20461 |
kshitij.so |
2083 |
val['product_name'] = master[0]['product_name']
|
|
|
2084 |
val['source'] = SOURCE_MAP.get(master[0]['source_id'])
|
| 15853 |
kshitij.so |
2085 |
else:
|
|
|
2086 |
val['brand'] = ""
|
|
|
2087 |
val['source_product_name'] = ""
|
|
|
2088 |
val['skuBundleId'] = ""
|
|
|
2089 |
data.append(val)
|
|
|
2090 |
return data
|
|
|
2091 |
else:
|
|
|
2092 |
cursor = collection.find({'skuBundleId':skuBundleId})
|
| 14499 |
kshitij.so |
2093 |
for val in cursor:
|
| 15853 |
kshitij.so |
2094 |
master = list(get_mongo_connection().Catalog.MasterData.find({'skuBundleId':val['skuBundleId']}))
|
| 14499 |
kshitij.so |
2095 |
if len(master) > 0:
|
|
|
2096 |
val['brand'] = master[0]['brand']
|
|
|
2097 |
val['source_product_name'] = master[0]['source_product_name']
|
|
|
2098 |
else:
|
|
|
2099 |
val['brand'] = ""
|
|
|
2100 |
val['source_product_name'] = ""
|
|
|
2101 |
data.append(val)
|
| 15853 |
kshitij.so |
2102 |
return data
|
| 14495 |
kshitij.so |
2103 |
|
| 15074 |
kshitij.so |
2104 |
def __getBrandIdForBrand(brandName, category_id):
|
|
|
2105 |
brandInfo = Brands.query.filter(Brands.category_id==category_id).filter(Brands.name == brandName).all()
|
|
|
2106 |
if brandInfo is None or len(brandInfo)!=1:
|
|
|
2107 |
raise
|
|
|
2108 |
else:
|
|
|
2109 |
return brandInfo[0].id
|
|
|
2110 |
|
| 14588 |
kshitij.so |
2111 |
def addNewItem(data):
|
| 14594 |
kshitij.so |
2112 |
try:
|
|
|
2113 |
data['updatedOn'] = to_java_date(datetime.now())
|
|
|
2114 |
data['addedOn'] = to_java_date(datetime.now())
|
|
|
2115 |
data['priceUpdatedOn'] = to_java_date(datetime.now())
|
|
|
2116 |
max_id = list(get_mongo_connection().Catalog.MasterData.find().sort([('_id',pymongo.DESCENDING)]).limit(1))
|
|
|
2117 |
max_bundle = list(get_mongo_connection().Catalog.MasterData.find().sort([('skuBundleId',pymongo.DESCENDING)]).limit(1))
|
|
|
2118 |
data['_id'] = max_id[0]['_id'] + 1
|
|
|
2119 |
data['skuBundleId'] = max_bundle[0]['skuBundleId'] + 1
|
|
|
2120 |
data['identifier'] = str(data['identifier'])
|
|
|
2121 |
data['secondaryIdentifier'] = str(data['secondaryIdentifier'])
|
| 17115 |
manish.sha |
2122 |
data['model_name'] = str(data['model_name'])
|
| 15074 |
kshitij.so |
2123 |
data['brand_id'] = __getBrandIdForBrand(data['brand'], data['category_id'])
|
| 17746 |
kshitij.so |
2124 |
data['shippingCost'] = float(data['shippingCost'])
|
| 19559 |
kshitij.so |
2125 |
data['internalRank'] = int(data['internalRank'])
|
| 17603 |
kshitij.so |
2126 |
if data['category_id'] ==6 and data['subCategoryId'] ==0:
|
| 17606 |
kshitij.so |
2127 |
return {0:'Sub-Category not selected'}
|
| 17608 |
kshitij.so |
2128 |
elif data['category_id'] !=6 and data['subCategoryId'] !=0:
|
|
|
2129 |
return {0:'Sub-Category not valid'}
|
|
|
2130 |
else:
|
|
|
2131 |
pass
|
| 17604 |
kshitij.so |
2132 |
data['subCategory'] = SUB_CATEGORY_MAP.get(data['subCategoryId'])
|
| 14594 |
kshitij.so |
2133 |
get_mongo_connection().Catalog.MasterData.insert(data)
|
|
|
2134 |
return {1:'Data added successfully'}
|
|
|
2135 |
except Exception as e:
|
|
|
2136 |
print e
|
|
|
2137 |
return {0:'Unable to add data.'}
|
| 15130 |
kshitij.so |
2138 |
finally:
|
|
|
2139 |
session.close()
|
| 14588 |
kshitij.so |
2140 |
|
|
|
2141 |
def addItemToExistingBundle(data):
|
|
|
2142 |
try:
|
|
|
2143 |
data['updatedOn'] = to_java_date(datetime.now())
|
|
|
2144 |
data['addedOn'] = to_java_date(datetime.now())
|
|
|
2145 |
data['priceUpdatedOn'] = to_java_date(datetime.now())
|
| 14593 |
kshitij.so |
2146 |
max_id = list(get_mongo_connection().Catalog.MasterData.find().sort([('_id',pymongo.DESCENDING)]).limit(1))
|
| 14590 |
kshitij.so |
2147 |
data['_id'] = max_id[0]['_id'] + 1
|
| 14594 |
kshitij.so |
2148 |
data['identifier'] = str(data['identifier'])
|
|
|
2149 |
data['secondaryIdentifier'] = str(data['secondaryIdentifier'])
|
| 17115 |
manish.sha |
2150 |
data['model_name'] = str(data['model_name'])
|
| 15074 |
kshitij.so |
2151 |
data['brand_id'] = __getBrandIdForBrand(data['brand'], data['category_id'])
|
| 17746 |
kshitij.so |
2152 |
data['shippingCost'] = float(data['shippingCost'])
|
| 19559 |
kshitij.so |
2153 |
data['internalRank'] = int(data['internalRank'])
|
| 17603 |
kshitij.so |
2154 |
if data['category_id'] ==6 and data['subCategoryId'] ==0:
|
| 17606 |
kshitij.so |
2155 |
return {0:'Sub-Category not selected'}
|
| 17608 |
kshitij.so |
2156 |
elif data['category_id'] !=6 and data['subCategoryId'] !=0:
|
|
|
2157 |
return {0:'Sub-Category not valid'}
|
|
|
2158 |
else:
|
|
|
2159 |
pass
|
| 17604 |
kshitij.so |
2160 |
data['subCategory'] = SUB_CATEGORY_MAP.get(data['subCategoryId'])
|
| 14588 |
kshitij.so |
2161 |
get_mongo_connection().Catalog.MasterData.insert(data)
|
|
|
2162 |
return {1:'Data added successfully.'}
|
| 14594 |
kshitij.so |
2163 |
except Exception as e:
|
|
|
2164 |
print e
|
| 14588 |
kshitij.so |
2165 |
return {0:'Unable to add data.'}
|
| 15130 |
kshitij.so |
2166 |
finally:
|
|
|
2167 |
session.close()
|
| 14588 |
kshitij.so |
2168 |
|
|
|
2169 |
def updateMaster(data, multi):
|
| 15130 |
kshitij.so |
2170 |
try:
|
|
|
2171 |
print data
|
|
|
2172 |
if multi != 1:
|
|
|
2173 |
_id = data.pop('_id')
|
|
|
2174 |
skuBundleId = data.pop('skuBundleId')
|
|
|
2175 |
data['updatedOn'] = to_java_date(datetime.now())
|
|
|
2176 |
data['identifier'] = str(data['identifier'])
|
|
|
2177 |
data['secondaryIdentifier'] = str(data['secondaryIdentifier'])
|
| 17115 |
manish.sha |
2178 |
data['model_name'] = str(data['model_name'])
|
| 17746 |
kshitij.so |
2179 |
data['shippingCost'] = float(data['shippingCost'])
|
| 19559 |
kshitij.so |
2180 |
data['internalRank'] = int(data['internalRank'])
|
| 15130 |
kshitij.so |
2181 |
data['brand_id'] = __getBrandIdForBrand(data['brand'], data['category_id'])
|
| 17603 |
kshitij.so |
2182 |
if data['category_id'] ==6 and data['subCategoryId'] ==0:
|
| 17606 |
kshitij.so |
2183 |
return {0:'Sub-Category not selected'}
|
| 17608 |
kshitij.so |
2184 |
elif data['category_id'] !=6 and data['subCategoryId'] !=0:
|
|
|
2185 |
return {0:'Sub-Category not valid'}
|
|
|
2186 |
else:
|
|
|
2187 |
pass
|
| 17604 |
kshitij.so |
2188 |
data['subCategory'] = SUB_CATEGORY_MAP.get(data['subCategoryId'])
|
| 15130 |
kshitij.so |
2189 |
get_mongo_connection().Catalog.MasterData.update({'_id':_id},{"$set":data},upsert=False)
|
| 19559 |
kshitij.so |
2190 |
get_mongo_connection().Catalog.MasterData.update({'skuBundleId':skuBundleId},{"$set":{'internalRank':data['internalRank']}},upsert=False, multi=True)
|
| 15130 |
kshitij.so |
2191 |
return {1:'Data updated successfully.'}
|
|
|
2192 |
else:
|
|
|
2193 |
_id = data.pop('_id')
|
|
|
2194 |
skuBundleId = data.pop('skuBundleId')
|
|
|
2195 |
data['updatedOn'] = to_java_date(datetime.now())
|
|
|
2196 |
data['identifier'] = str(data['identifier'])
|
|
|
2197 |
data['secondaryIdentifier'] = str(data['secondaryIdentifier'])
|
|
|
2198 |
data['brand_id'] = __getBrandIdForBrand(data['brand'], data['category_id'])
|
| 17115 |
manish.sha |
2199 |
data['model_name'] = str(data['model_name'])
|
| 17746 |
kshitij.so |
2200 |
data['shippingCost'] = float(data['shippingCost'])
|
| 19559 |
kshitij.so |
2201 |
data['internalRank'] = int(data['internalRank'])
|
| 17603 |
kshitij.so |
2202 |
if data['category_id'] ==6 and data['subCategoryId'] ==0:
|
| 17606 |
kshitij.so |
2203 |
return {0:'Sub-Category not selected'}
|
| 17608 |
kshitij.so |
2204 |
elif data['category_id'] !=6 and data['subCategoryId'] !=0:
|
|
|
2205 |
return {0:'Sub-Category not valid'}
|
|
|
2206 |
else:
|
|
|
2207 |
pass
|
| 17604 |
kshitij.so |
2208 |
data['subCategory'] = SUB_CATEGORY_MAP.get(data['subCategoryId'])
|
| 15130 |
kshitij.so |
2209 |
get_mongo_connection().Catalog.MasterData.update({'_id':_id},{"$set":data},upsert=False)
|
|
|
2210 |
similarItems = get_mongo_connection().Catalog.MasterData.find({'skuBundleId':skuBundleId})
|
|
|
2211 |
for item in similarItems:
|
|
|
2212 |
if item['_id'] == _id:
|
|
|
2213 |
continue
|
|
|
2214 |
item['updatedOn'] = to_java_date(datetime.now())
|
|
|
2215 |
item['thumbnail'] = data['thumbnail']
|
|
|
2216 |
item['category'] = data['category']
|
|
|
2217 |
item['category_id'] = data['category_id']
|
|
|
2218 |
item['is_shortage'] = data['is_shortage']
|
|
|
2219 |
item['mrp'] = data['mrp']
|
|
|
2220 |
item['status'] = data['status']
|
|
|
2221 |
item['maxPrice'] = data['maxPrice']
|
|
|
2222 |
item['brand_id'] = data['brand_id']
|
| 17603 |
kshitij.so |
2223 |
item['subCategoryId'] = data['subCategoryId']
|
|
|
2224 |
item['subCategory'] = data['subCategory']
|
| 19559 |
kshitij.so |
2225 |
item['internalRank'] = data['internalRank']
|
| 15130 |
kshitij.so |
2226 |
similar_item_id = item.pop('_id')
|
|
|
2227 |
get_mongo_connection().Catalog.MasterData.update({'_id':similar_item_id},{"$set":item},upsert=False)
|
|
|
2228 |
return {1:'Data updated successfully.'}
|
| 17603 |
kshitij.so |
2229 |
except:
|
| 20689 |
kshitij.so |
2230 |
traceback.print_exc()
|
| 17603 |
kshitij.so |
2231 |
return {0:'Unable to update data'}
|
| 15130 |
kshitij.so |
2232 |
finally:
|
|
|
2233 |
session.close()
|
| 14619 |
kshitij.so |
2234 |
|
|
|
2235 |
def getLiveCricScore():
|
|
|
2236 |
return mc.get('liveScore')
|
| 14852 |
kshitij.so |
2237 |
|
|
|
2238 |
def addBundleToNotification(data):
|
|
|
2239 |
try:
|
| 15069 |
kshitij.so |
2240 |
collection = get_mongo_connection().Catalog.Notifications
|
| 14852 |
kshitij.so |
2241 |
cursor = collection.find({'skuBundleId':data['skuBundleId']})
|
|
|
2242 |
if cursor.count() > 0:
|
|
|
2243 |
return {0:"SkuBundleId information already present."}
|
|
|
2244 |
else:
|
|
|
2245 |
collection.insert(data)
|
|
|
2246 |
return {1:'Data updated successfully.'}
|
|
|
2247 |
except:
|
|
|
2248 |
return {0:'Unable to add data.'}
|
|
|
2249 |
|
|
|
2250 |
def getAllNotifications(offset, limit):
|
|
|
2251 |
data = []
|
| 15069 |
kshitij.so |
2252 |
collection = get_mongo_connection().Catalog.Notifications
|
| 16450 |
kshitij.so |
2253 |
cursor = collection.find().sort([('endDate',pymongo.DESCENDING)]).skip(offset).limit(limit)
|
| 14852 |
kshitij.so |
2254 |
for val in cursor:
|
| 15072 |
kshitij.so |
2255 |
master = list(get_mongo_connection().Catalog.MasterData.find({'skuBundleId':val['skuBundleId']}))
|
| 14852 |
kshitij.so |
2256 |
if len(master) > 0:
|
|
|
2257 |
val['brand'] = master[0]['brand']
|
| 15071 |
kshitij.so |
2258 |
val['model_name'] = master[0]['model_name']
|
| 14852 |
kshitij.so |
2259 |
val['skuBundleId'] = master[0]['skuBundleId']
|
|
|
2260 |
else:
|
|
|
2261 |
val['brand'] = ""
|
| 15071 |
kshitij.so |
2262 |
val['model_name'] = ""
|
|
|
2263 |
val['skuBundleId'] = val['skuBundleId']
|
| 14852 |
kshitij.so |
2264 |
data.append(val)
|
|
|
2265 |
return data
|
| 14997 |
kshitij.so |
2266 |
|
|
|
2267 |
def getBrandsForFilter(category_id):
|
|
|
2268 |
if mc.get("brandFilter") is None:
|
| 15095 |
kshitij.so |
2269 |
print "Populating brand data for category_id %d" %(category_id)
|
| 17469 |
kshitij.so |
2270 |
tabData, mobData, accData = [], [], []
|
| 14997 |
kshitij.so |
2271 |
mobileDeals = get_mongo_connection().Catalog.Deals.aggregate([
|
| 23337 |
amit.gupta |
2272 |
{"$match":{"category_id":3,"showDeal":1,"totalPoints":{"$gt":-100}, "source_id":4}
|
| 14997 |
kshitij.so |
2273 |
},
|
|
|
2274 |
{"$group" :
|
|
|
2275 |
{'_id':{'brand_id':'$brand_id','brand':'$brand'},'count':{'$sum':1}}
|
|
|
2276 |
}
|
|
|
2277 |
])
|
| 14588 |
kshitij.so |
2278 |
|
| 14997 |
kshitij.so |
2279 |
tabletDeals = get_mongo_connection().Catalog.Deals.aggregate([
|
| 23337 |
amit.gupta |
2280 |
{"$match":{"category_id":5,"showDeal":1,"totalPoints":{"$gt":-100}, "source_id":4}
|
| 14997 |
kshitij.so |
2281 |
},
|
|
|
2282 |
{"$group" :
|
|
|
2283 |
{'_id':{'brand_id':'$brand_id','brand':'$brand'},'count':{'$sum':1}}
|
|
|
2284 |
}
|
|
|
2285 |
])
|
|
|
2286 |
|
| 17469 |
kshitij.so |
2287 |
accessoriesDeals = get_mongo_connection().Catalog.Deals.aggregate([
|
| 19597 |
kshitij.so |
2288 |
{"$match":{"category_id":6,"showDeal":1,"dealRankPoints":{"$gt":0}}
|
| 17469 |
kshitij.so |
2289 |
},
|
|
|
2290 |
{"$group" :
|
|
|
2291 |
{'_id':{'brand_id':'$brand_id','brand':'$brand'},'count':{'$sum':1}}
|
|
|
2292 |
}
|
|
|
2293 |
])
|
|
|
2294 |
|
| 14997 |
kshitij.so |
2295 |
#print mobileDeals
|
|
|
2296 |
#print "==========Mobile data ends=========="
|
|
|
2297 |
|
|
|
2298 |
#print tabletDeals
|
|
|
2299 |
#print "==========Tablet data ends=========="
|
|
|
2300 |
|
|
|
2301 |
#print allDeals
|
|
|
2302 |
#print "==========All deal data ends========="
|
|
|
2303 |
|
|
|
2304 |
for mobileDeal in mobileDeals['result']:
|
|
|
2305 |
if mobileDeal.get('_id').get('brand_id') != 0:
|
|
|
2306 |
tempMap = {}
|
|
|
2307 |
tempMap['brand'] = mobileDeal.get('_id').get('brand')
|
|
|
2308 |
tempMap['brand_id'] = mobileDeal.get('_id').get('brand_id')
|
|
|
2309 |
tempMap['count'] = mobileDeal.get('count')
|
|
|
2310 |
mobData.append(tempMap)
|
|
|
2311 |
|
|
|
2312 |
for tabletDeal in tabletDeals['result']:
|
|
|
2313 |
if tabletDeal.get('_id').get('brand_id') != 0:
|
|
|
2314 |
tempMap = {}
|
|
|
2315 |
tempMap['brand'] = tabletDeal.get('_id').get('brand')
|
|
|
2316 |
tempMap['brand_id'] = tabletDeal.get('_id').get('brand_id')
|
|
|
2317 |
tempMap['count'] = tabletDeal.get('count')
|
|
|
2318 |
tabData.append(tempMap)
|
|
|
2319 |
|
| 17469 |
kshitij.so |
2320 |
for accessoryDeal in accessoriesDeals['result']:
|
|
|
2321 |
if accessoryDeal.get('_id').get('brand_id') != 0:
|
|
|
2322 |
tempMap = {}
|
|
|
2323 |
tempMap['brand'] = accessoryDeal.get('_id').get('brand')
|
|
|
2324 |
tempMap['brand_id'] = accessoryDeal.get('_id').get('brand_id')
|
|
|
2325 |
tempMap['count'] = accessoryDeal.get('count')
|
|
|
2326 |
accData.append(tempMap)
|
| 14997 |
kshitij.so |
2327 |
|
| 19597 |
kshitij.so |
2328 |
mc.set("brandFilter",{3:mobData, 5:tabData, 6:accData}, 600)
|
| 14997 |
kshitij.so |
2329 |
|
| 23477 |
amit.gupta |
2330 |
return sorted(mc.get("brandFilter").get(category_id), key = lambda x: (x['brand'], -x['count']))
|
| 15375 |
kshitij.so |
2331 |
|
| 15459 |
kshitij.so |
2332 |
def getStaticDeals(offset, limit, category_id, direction):
|
| 15375 |
kshitij.so |
2333 |
user_specific_deals = mc.get("staticDeals")
|
|
|
2334 |
if user_specific_deals is None:
|
|
|
2335 |
__populateStaticDeals()
|
|
|
2336 |
user_specific_deals = mc.get("staticDeals")
|
| 15459 |
kshitij.so |
2337 |
rev = False
|
|
|
2338 |
if direction is None or direction == -1:
|
|
|
2339 |
rev=True
|
|
|
2340 |
return sorted((user_specific_deals.get(category_id))[offset:offset+limit],reverse=rev)
|
| 15375 |
kshitij.so |
2341 |
|
|
|
2342 |
def __populateStaticDeals():
|
|
|
2343 |
print "Populating memcache for static deals"
|
|
|
2344 |
outer_query = []
|
|
|
2345 |
outer_query.append({"showDeal":1})
|
|
|
2346 |
query = {}
|
| 16170 |
kshitij.so |
2347 |
query['$gt'] = -100
|
| 15375 |
kshitij.so |
2348 |
outer_query.append({'totalPoints':query})
|
|
|
2349 |
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)]))
|
|
|
2350 |
mobile_deals = []
|
|
|
2351 |
tablet_deals = []
|
|
|
2352 |
for deal in all_deals:
|
|
|
2353 |
item = get_mongo_connection().Catalog.MasterData.find({'_id':deal['_id']})
|
|
|
2354 |
if deal['category_id'] ==3:
|
|
|
2355 |
mobile_deals.append(getItemObjForStaticDeals(item[0]))
|
|
|
2356 |
elif deal['category_id'] ==5:
|
|
|
2357 |
tablet_deals.append(getItemObjForStaticDeals(item[0]))
|
|
|
2358 |
else:
|
|
|
2359 |
continue
|
|
|
2360 |
|
|
|
2361 |
random.shuffle(mobile_deals,random.random)
|
|
|
2362 |
random.shuffle(tablet_deals,random.random)
|
|
|
2363 |
|
|
|
2364 |
mem_cache_val = {3:mobile_deals, 5:tablet_deals}
|
|
|
2365 |
mc.set("staticDeals", mem_cache_val, 3600)
|
|
|
2366 |
|
| 17733 |
kshitij.so |
2367 |
def getItemObjForStaticDeals(item,transform=None):
|
|
|
2368 |
mpu = str(item.get('marketPlaceUrl'))
|
|
|
2369 |
if transform:
|
|
|
2370 |
if mpu.find("snapdeal")!=-1:
|
|
|
2371 |
mpu = "http://m.snapdeal.com"+mpu[mpu.find("/product"):]
|
|
|
2372 |
elif mpu.find("homeshop18")!=-1:
|
|
|
2373 |
mpu = "http://m.homeshop18.com/product.mobi?productId="+item['identifier']
|
| 17735 |
kshitij.so |
2374 |
elif mpu.find("saholic.com")!=-1:
|
| 17746 |
kshitij.so |
2375 |
mpu = "http://m."+mpu[mpu.find("saholic.com"):]
|
| 17735 |
kshitij.so |
2376 |
elif mpu.find("shopclues.com")!=-1:
|
| 17733 |
kshitij.so |
2377 |
mpu = "http://m."+mpu[mpu.find("shopclues.com"):]
|
|
|
2378 |
else:
|
|
|
2379 |
pass
|
|
|
2380 |
|
|
|
2381 |
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 |
2382 |
|
|
|
2383 |
def getItemByMerchantIdentifier(identifier, source_id):
|
|
|
2384 |
skuData = None
|
| 17035 |
kshitij.so |
2385 |
if source_id in (1,2,4,5,6,7):
|
| 16300 |
manas |
2386 |
skuData = get_mongo_connection().Catalog.MasterData.find_one({'identifier':identifier.strip(), 'source_id':source_id})
|
|
|
2387 |
elif source_id == 3:
|
|
|
2388 |
skuData = get_mongo_connection().Catalog.MasterData.find_one({'secondaryIdentifier':identifier.strip(), 'source_id':source_id})
|
|
|
2389 |
if skuData is None:
|
|
|
2390 |
return {}
|
|
|
2391 |
else:
|
|
|
2392 |
return skuData
|
| 15375 |
kshitij.so |
2393 |
|
| 17936 |
kshitij.so |
2394 |
def getDealsForNotification(skuBundleIds,skipSplitting=False):
|
|
|
2395 |
if not skipSplitting:
|
|
|
2396 |
bundles= [int(skuBundleId) for skuBundleId in skuBundleIds.split(',')]
|
|
|
2397 |
print bundles
|
|
|
2398 |
else:
|
|
|
2399 |
bundles = skuBundleIds
|
| 16406 |
kshitij.so |
2400 |
dealsList = []
|
| 16364 |
kshitij.so |
2401 |
dealsListMap = []
|
| 16406 |
kshitij.so |
2402 |
for bundleId in bundles:
|
|
|
2403 |
outer_query = []
|
|
|
2404 |
outer_query.append({ "$or": [ { "showDeal": 1} , { "prepaidDeal": 1 } ] })
|
|
|
2405 |
outer_query.append({'skuBundleId':bundleId})
|
|
|
2406 |
deals = get_mongo_connection().Catalog.Deals.find({"$and":outer_query})
|
|
|
2407 |
for deal in deals:
|
|
|
2408 |
dealsList.append(deal)
|
| 16364 |
kshitij.so |
2409 |
sortedMap = {}
|
|
|
2410 |
rankMap = {}
|
|
|
2411 |
rank = 0
|
| 16406 |
kshitij.so |
2412 |
for sorted_deal in dealsList:
|
| 16364 |
kshitij.so |
2413 |
if sortedMap.get(sorted_deal['skuBundleId']) is None:
|
|
|
2414 |
sortedMap[sorted_deal['skuBundleId']] = {rank:[sorted_deal]}
|
|
|
2415 |
rankMap[rank] = (sortedMap[sorted_deal['skuBundleId']].values())[0]
|
|
|
2416 |
rank = rank +1
|
|
|
2417 |
else:
|
|
|
2418 |
for temp_list in sortedMap.get(sorted_deal['skuBundleId']).itervalues():
|
|
|
2419 |
temp_list.append(sorted_deal)
|
|
|
2420 |
rankMap[(sortedMap.get(sorted_deal['skuBundleId']).keys())[0]] = temp_list
|
|
|
2421 |
|
| 16367 |
kshitij.so |
2422 |
for dealList in [rankMap.get(k, []) for k in range(0, len(bundles))]:
|
| 16364 |
kshitij.so |
2423 |
temp = []
|
|
|
2424 |
for d in dealList:
|
|
|
2425 |
item = list(get_mongo_connection().Catalog.MasterData.find({'_id':d['_id']}))
|
|
|
2426 |
if len(item) ==0:
|
|
|
2427 |
continue
|
|
|
2428 |
if d['dealType'] == 1 and d['source_id'] ==1:
|
|
|
2429 |
item[0]['marketPlaceUrl'] = "http://www.amazon.in/dp/%s"%(item[0]['identifier'].strip())
|
|
|
2430 |
elif d['source_id'] ==3:
|
|
|
2431 |
item[0]['marketPlaceUrl'] = item[0]['marketPlaceUrl']+'?supc='+item[0].get('identifier')
|
|
|
2432 |
else:
|
|
|
2433 |
pass
|
|
|
2434 |
try:
|
|
|
2435 |
cashBack = getCashBack(item[0]['_id'], item[0]['source_id'], item[0]['category_id'])
|
|
|
2436 |
if not cashBack or cashBack.get('cash_back_status')!=1:
|
|
|
2437 |
item[0]['cash_back_type'] = 0
|
|
|
2438 |
item[0]['cash_back'] = 0
|
|
|
2439 |
else:
|
|
|
2440 |
item[0]['cash_back_type'] = int(cashBack['cash_back_type'])
|
|
|
2441 |
item[0]['cash_back'] = cashBack['cash_back']
|
|
|
2442 |
except:
|
|
|
2443 |
print "Error in adding cashback to deals"
|
|
|
2444 |
item[0]['cash_back_type'] = 0
|
|
|
2445 |
item[0]['cash_back'] = 0
|
|
|
2446 |
try:
|
|
|
2447 |
item[0]['dp'] = d['dp']
|
|
|
2448 |
item[0]['showDp'] = d['showDp']
|
|
|
2449 |
except:
|
|
|
2450 |
item[0]['dp'] = 0.0
|
|
|
2451 |
item[0]['showDp'] = 0
|
| 17727 |
kshitij.so |
2452 |
|
|
|
2453 |
try:
|
|
|
2454 |
if item[0]['showVideo']==0:
|
|
|
2455 |
item[0]['videoLink'] =""
|
|
|
2456 |
except:
|
|
|
2457 |
item[0]['videoLink'] =""
|
|
|
2458 |
try:
|
|
|
2459 |
if item[0]['quantity'] >1:
|
|
|
2460 |
ppq = float(item[0]['available_price'])/item[0]['quantity']
|
|
|
2461 |
|
|
|
2462 |
if ppq == round(ppq):
|
|
|
2463 |
item[0]['ppq'] = int(ppq)
|
|
|
2464 |
else:
|
|
|
2465 |
item[0]['ppq'] = round(ppq,2)
|
|
|
2466 |
else:
|
|
|
2467 |
item[0]['ppq'] = 0
|
|
|
2468 |
except:
|
|
|
2469 |
item[0]['ppq'] = 0
|
|
|
2470 |
if item[0]['category_id']!=6:
|
|
|
2471 |
try:
|
| 18830 |
kshitij.so |
2472 |
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']))
|
|
|
2473 |
item[0]['filterTextBrand'] = (item[0]['brand'])
|
| 17727 |
kshitij.so |
2474 |
except:
|
| 18830 |
kshitij.so |
2475 |
pass
|
| 17727 |
kshitij.so |
2476 |
else:
|
|
|
2477 |
try:
|
| 18051 |
kshitij.so |
2478 |
if item[0]['subCategory']=='' or item[0]['subCategory'] is None or item[0]['subCategoryId']==0:
|
| 17727 |
kshitij.so |
2479 |
raise
|
| 18830 |
kshitij.so |
2480 |
item[0]['filterLinkSubCategory'] = '/category/'+str(int(item[0]['category_id']))+'?searchFor='+urllib.quote(item[0]['subCategory'])+'&filter=subcategory&subcategories='+str(int(item[0]['subCategoryId']))
|
|
|
2481 |
item[0]['filterTextSubCategory'] = (item[0]['subCategory'])
|
|
|
2482 |
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']))
|
|
|
2483 |
item[0]['filterTextBrand'] = (item[0]['brand'])
|
| 17727 |
kshitij.so |
2484 |
except:
|
| 18830 |
kshitij.so |
2485 |
pass
|
| 17944 |
kshitij.so |
2486 |
try:
|
|
|
2487 |
if item[0]['source_id']==4:
|
|
|
2488 |
item_availability_info = mc.get("item_availability_"+str(item[0]['identifier']).strip())
|
|
|
2489 |
if item_availability_info is None or len(item_availability_info)==0:
|
|
|
2490 |
item[0]['availabilityInfo'] = [{}]
|
|
|
2491 |
else:
|
|
|
2492 |
item[0]['availabilityInfo'] = item_availability_info
|
|
|
2493 |
except:
|
|
|
2494 |
item[0]['availabilityInfo'] = [{}]
|
| 19135 |
kshitij.so |
2495 |
|
| 19193 |
kshitij.so |
2496 |
if item[0]['source_id']==4:
|
|
|
2497 |
for av_info in item[0]['availabilityInfo']:
|
|
|
2498 |
if not av_info:
|
|
|
2499 |
continue
|
|
|
2500 |
av_info['cash_back'] = item[0]['cash_back']
|
|
|
2501 |
av_info['cash_back_type'] = item[0]['cash_back_type']
|
|
|
2502 |
netPriceAfterCashBack = av_info['sellingPrice']
|
| 19199 |
kshitij.so |
2503 |
if av_info['cash_back_type'] ==1:
|
| 19207 |
kshitij.so |
2504 |
netPriceAfterCashBack = av_info['sellingPrice'] - math.floor(float(av_info['sellingPrice'])*av_info['cash_back']/100)
|
| 19199 |
kshitij.so |
2505 |
elif av_info['cash_back_type'] ==2:
|
| 19207 |
kshitij.so |
2506 |
netPriceAfterCashBack = av_info['sellingPrice'] - math.floor(av_info['cash_back'])
|
| 19193 |
kshitij.so |
2507 |
else:
|
|
|
2508 |
pass
|
|
|
2509 |
av_info['netPriceAfterCashBack'] = netPriceAfterCashBack
|
|
|
2510 |
|
|
|
2511 |
if item[0]['source_id'] != SOURCE_MAP.get("PAYTM.COM"):
|
|
|
2512 |
if item[0]['codAvailable'] ==1:
|
|
|
2513 |
paytmPrice = item[0]['available_price']
|
|
|
2514 |
else:
|
|
|
2515 |
paytmPrice = item[0]['gross_price']
|
|
|
2516 |
|
|
|
2517 |
if item[0]['cash_back_type'] ==1:
|
| 19207 |
kshitij.so |
2518 |
item[0]['netPriceAfterCashBack'] = paytmPrice - math.floor(float(paytmPrice)*item[0]['cash_back']/100)
|
| 19193 |
kshitij.so |
2519 |
elif item[0]['cash_back_type'] ==2:
|
| 19207 |
kshitij.so |
2520 |
item[0]['netPriceAfterCashBack'] = paytmPrice - math.floor(item[0]['cash_back'])
|
| 19193 |
kshitij.so |
2521 |
else:
|
|
|
2522 |
item[0]['netPriceAfterCashBack'] = paytmPrice
|
|
|
2523 |
|
|
|
2524 |
else:
|
|
|
2525 |
if item[0]['cash_back_type'] ==1:
|
| 19207 |
kshitij.so |
2526 |
item[0]['netPriceAfterCashBack'] = item[0]['available_price'] - math.floor(float(item[0]['available_price'])*item[0]['cash_back']/100)
|
| 19193 |
kshitij.so |
2527 |
elif item[0]['cash_back_type'] ==2:
|
| 19207 |
kshitij.so |
2528 |
item[0]['netPriceAfterCashBack'] = item[0]['available_price'] - math.floor(item[0]['cash_back'])
|
| 19193 |
kshitij.so |
2529 |
else:
|
|
|
2530 |
item[0]['netPriceAfterCashBack'] = item[0]['available_price']
|
|
|
2531 |
|
|
|
2532 |
|
| 19135 |
kshitij.so |
2533 |
item[0]['totalPoints'] = d['totalPoints']
|
| 17727 |
kshitij.so |
2534 |
|
| 16364 |
kshitij.so |
2535 |
temp.append(item[0])
|
|
|
2536 |
if len(temp) > 1:
|
|
|
2537 |
temp = sorted(temp, key = lambda x: (x['available_price']),reverse=False)
|
|
|
2538 |
dealsListMap.append(temp)
|
|
|
2539 |
return dealsListMap
|
|
|
2540 |
|
| 16373 |
manas |
2541 |
def getSkuBrandData(sku):
|
|
|
2542 |
if sku is None:
|
|
|
2543 |
return {}
|
|
|
2544 |
else:
|
|
|
2545 |
orders = get_mongo_connection().Catalog.MasterData.find_one({'skuBundleId':sku})
|
|
|
2546 |
if orders is None:
|
|
|
2547 |
return {}
|
|
|
2548 |
return orders
|
| 16488 |
kshitij.so |
2549 |
|
|
|
2550 |
def addDealPoints(data):
|
|
|
2551 |
collection = get_mongo_connection().Catalog.DealPoints
|
|
|
2552 |
cursor = collection.find({'skuBundleId':data['skuBundleId']})
|
|
|
2553 |
if cursor.count() > 0:
|
|
|
2554 |
return {0:"Sku information already present."}
|
|
|
2555 |
else:
|
|
|
2556 |
collection.insert(data)
|
|
|
2557 |
get_mongo_connection().Catalog.MasterData.update({'skuBundleId':data['skuBundleId']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
|
|
2558 |
return {1:"Data added successfully"}
|
|
|
2559 |
|
|
|
2560 |
def getAllBundlesWithDealPoints(offset, limit):
|
|
|
2561 |
data = []
|
|
|
2562 |
collection = get_mongo_connection().Catalog.DealPoints
|
|
|
2563 |
cursor = collection.find().sort([('endDate',pymongo.DESCENDING)]).skip(offset).limit(limit)
|
|
|
2564 |
for val in cursor:
|
|
|
2565 |
master = get_mongo_connection().Catalog.MasterData.find_one({'skuBundleId':val.get('skuBundleId')})
|
|
|
2566 |
if master is not None:
|
|
|
2567 |
val['brand'] = master['brand']
|
|
|
2568 |
val['source_product_name'] = master['product_name']
|
|
|
2569 |
else:
|
|
|
2570 |
val['brand'] = ""
|
|
|
2571 |
val['source_product_name'] = ""
|
|
|
2572 |
data.append(val)
|
|
|
2573 |
return data
|
| 16546 |
kshitij.so |
2574 |
|
|
|
2575 |
def generateRedirectUrl(retailer_id, app_id):
|
|
|
2576 |
try:
|
| 16663 |
manish.sha |
2577 |
if retailer_id <= 0:
|
|
|
2578 |
return {'url':"","message":"Retailer Id not valid"}
|
| 16546 |
kshitij.so |
2579 |
d_app_offer = app_offers.get_by(id=app_id)
|
| 16605 |
manish.sha |
2580 |
except:
|
|
|
2581 |
traceback.print_exc()
|
| 16546 |
kshitij.so |
2582 |
finally:
|
|
|
2583 |
session.close()
|
|
|
2584 |
if d_app_offer is None:
|
|
|
2585 |
return {'url':"","message":"App id doesn't exist"}
|
| 16364 |
kshitij.so |
2586 |
|
| 16915 |
manish.sha |
2587 |
final_user_payout = 0
|
|
|
2588 |
if d_app_offer.override_payout:
|
|
|
2589 |
final_user_payout = d_app_offer.overriden_payout
|
|
|
2590 |
else:
|
|
|
2591 |
final_user_payout = d_app_offer.user_payout
|
| 16546 |
kshitij.so |
2592 |
|
| 16915 |
manish.sha |
2593 |
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)
|
|
|
2594 |
|
| 16546 |
kshitij.so |
2595 |
get_mongo_connection().AppOrder.AppTransaction.insert(appTransactions.__dict__)
|
|
|
2596 |
embedd = str((appTransactions.__dict__).get('_id'))
|
| 16548 |
kshitij.so |
2597 |
try:
|
|
|
2598 |
index = d_app_offer.link.index(".freeb.co.in")
|
|
|
2599 |
except:
|
| 16605 |
manish.sha |
2600 |
traceback.print_exc()
|
| 16548 |
kshitij.so |
2601 |
return {'url':"","message":"Substring not found"}
|
|
|
2602 |
redirect_url = d_app_offer.link[0:index]+"."+embedd+d_app_offer.link[index:]
|
| 16546 |
kshitij.so |
2603 |
get_mongo_connection().AppOrder.AppTransaction.update({'_id':ObjectId(embedd)},{"$set":{'redirect_url':redirect_url}})
|
| 16548 |
kshitij.so |
2604 |
return {'url':redirect_url,"message":"Success"}
|
| 16556 |
kshitij.so |
2605 |
|
|
|
2606 |
def addPayout(payout, transaction_id):
|
|
|
2607 |
try:
|
| 16764 |
manish.sha |
2608 |
print 'Got Response for Transaction Id:- '+ str(transaction_id)+ ' and Actual Payout:- '+str(payout)
|
| 16556 |
kshitij.so |
2609 |
transaction = list(get_mongo_connection().AppOrder.AppTransaction.find({'_id':ObjectId(transaction_id)}))
|
|
|
2610 |
if len(transaction) > 0:
|
|
|
2611 |
if (transaction[0])['payout_status'] ==1:
|
| 16753 |
manish.sha |
2612 |
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 |
2613 |
|
|
|
2614 |
approvedAppTransaction = approved_app_transactions.get_by(transaction_id=transaction_id)
|
|
|
2615 |
if approvedAppTransaction is None:
|
|
|
2616 |
approvedAppTransaction = approved_app_transactions()
|
| 16919 |
manish.sha |
2617 |
approvedAppTransaction.app_id = transaction[0].get('app_id')
|
| 16782 |
manish.sha |
2618 |
approvedAppTransaction.cash_back_description = CB_APPROVED
|
| 16919 |
manish.sha |
2619 |
approvedAppTransaction.retailer_id = transaction[0].get('retailer_id')
|
| 16782 |
manish.sha |
2620 |
approvedAppTransaction.transaction_id = transaction_id
|
| 16919 |
manish.sha |
2621 |
approvedAppTransaction.transaction_time = to_py_date(long(transaction[0].get('transaction_time')))
|
|
|
2622 |
approvedAppTransaction.redirect_url = transaction[0].get('redirect_url')
|
| 16782 |
manish.sha |
2623 |
approvedAppTransaction.payout_status = 2
|
|
|
2624 |
approvedAppTransaction.payout_description = CB_APPROVED
|
|
|
2625 |
approvedAppTransaction.cashback_status = 2
|
|
|
2626 |
approvedAppTransaction.payout_amount = long(payout)
|
|
|
2627 |
approvedAppTransaction.payout_time = datetime.now()
|
| 16919 |
manish.sha |
2628 |
approvedAppTransaction.offer_price = long(transaction[0].get('offer_price'))
|
|
|
2629 |
approvedAppTransaction.overridenCashBack = transaction[0].get('overridenCashBack')
|
|
|
2630 |
approvedAppTransaction.isCashBackOverriden = transaction[0].get('isCashBackOverriden')
|
|
|
2631 |
approvedAppTransaction.user_payout = transaction[0].get('user_payout')
|
| 16782 |
manish.sha |
2632 |
approvedAppTransaction.cashBackConsidered = False
|
| 16915 |
manish.sha |
2633 |
if transaction[0].get('final_user_payout') is not None:
|
|
|
2634 |
approvedAppTransaction.final_user_payout = transaction[0].get('final_user_payout')
|
|
|
2635 |
else:
|
| 16919 |
manish.sha |
2636 |
if transaction[0].get('isCashBackOverriden'):
|
|
|
2637 |
approvedAppTransaction.final_user_payout = transaction[0].get('overridenCashBack')
|
| 16915 |
manish.sha |
2638 |
else:
|
| 16919 |
manish.sha |
2639 |
approvedAppTransaction.final_user_payout = transaction[0].get('user_payout')
|
| 16782 |
manish.sha |
2640 |
session.commit()
|
|
|
2641 |
|
|
|
2642 |
updateResult = _updateApprovedCashbackToUser(approvedAppTransaction.id)
|
| 16631 |
manish.sha |
2643 |
else:
|
| 16783 |
manish.sha |
2644 |
approvedAppTransaction.payout_amount = long(payout)
|
|
|
2645 |
approvedAppTransaction.payout_time = datetime.now()
|
|
|
2646 |
if approvedAppTransaction.cashBackConsidered == False:
|
|
|
2647 |
updateResult = _updateApprovedCashbackToUser(approvedAppTransaction.id)
|
|
|
2648 |
session.commit()
|
| 16782 |
manish.sha |
2649 |
|
|
|
2650 |
'''
|
|
|
2651 |
try:
|
|
|
2652 |
if int(transaction[0]['offer_price']) != payout or int(transaction[0]['user_payout']) < payout:
|
|
|
2653 |
_sendAlertForAppPayouts(int(transaction[0]['app_id']), int(transaction[0]['offer_price']), int(transaction[0]['user_payout']), payout)
|
|
|
2654 |
except:
|
|
|
2655 |
print traceback.print_exc()
|
|
|
2656 |
'''
|
| 16556 |
kshitij.so |
2657 |
return {'status':'ok','message':'Payout updated'}
|
|
|
2658 |
elif (transaction[0])['payout_status'] ==2:
|
|
|
2659 |
return {'status':'ok','message':'Payout already processed'}
|
|
|
2660 |
else:
|
|
|
2661 |
return {'status':'fail','message':'Something is wrong'}
|
|
|
2662 |
else:
|
|
|
2663 |
return {'status':'fail','message':'transaction_id not found'}
|
|
|
2664 |
except:
|
| 16657 |
manish.sha |
2665 |
print traceback.print_exc()
|
| 16631 |
manish.sha |
2666 |
try:
|
| 16753 |
manish.sha |
2667 |
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 |
2668 |
except:
|
|
|
2669 |
print 'Data Inconsistency in Cashback Process'
|
| 16636 |
manish.sha |
2670 |
print traceback.print_exc()
|
| 16559 |
kshitij.so |
2671 |
return {'status':'fail','message':'Something is wrong'}
|
| 16885 |
kshitij.so |
2672 |
finally:
|
|
|
2673 |
session.close()
|
| 16556 |
kshitij.so |
2674 |
|
| 16631 |
manish.sha |
2675 |
def _updateApprovedCashbackToUser(approvedAppTransactionId):
|
|
|
2676 |
approvedAppTransaction = approved_app_transactions.get_by(id=approvedAppTransactionId)
|
| 16915 |
manish.sha |
2677 |
if approvedAppTransaction.retailer_id < 0:
|
|
|
2678 |
return False
|
|
|
2679 |
|
| 16631 |
manish.sha |
2680 |
currentMonth = datetime.today().month
|
|
|
2681 |
currentDay = datetime.today().day
|
|
|
2682 |
currentYear = datetime.today().year
|
|
|
2683 |
fortNight = (currentMonth - 1)*2 + (currentDay/15)
|
|
|
2684 |
if currentDay == 30 or currentDay ==31:
|
|
|
2685 |
fortNight = fortNight-1
|
|
|
2686 |
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()
|
|
|
2687 |
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()
|
|
|
2688 |
try:
|
|
|
2689 |
if userAppCashbackObj is None:
|
|
|
2690 |
userAppCashbackObj = user_app_cashbacks()
|
|
|
2691 |
userAppCashbackObj.user_id = approvedAppTransaction.retailer_id
|
|
|
2692 |
userAppCashbackObj.status = 'Approved'
|
| 16915 |
manish.sha |
2693 |
userAppCashbackObj.amount = approvedAppTransaction.final_user_payout
|
| 16631 |
manish.sha |
2694 |
userAppCashbackObj.fortnightOfYear = fortNight
|
|
|
2695 |
userAppCashbackObj.yearVal = currentYear
|
|
|
2696 |
else:
|
| 16915 |
manish.sha |
2697 |
userAppCashbackObj.amount = userAppCashbackObj.amount + approvedAppTransaction.final_user_payout
|
| 16631 |
manish.sha |
2698 |
|
|
|
2699 |
if userAppInstallObj is None:
|
|
|
2700 |
app_offer = app_offers.get_by(id=approvedAppTransaction.app_id)
|
|
|
2701 |
userAppInstallObj = user_app_installs()
|
|
|
2702 |
userAppInstallObj.user_id = approvedAppTransaction.retailer_id
|
|
|
2703 |
userAppInstallObj.fortnightOfYear = fortNight
|
|
|
2704 |
userAppInstallObj.transaction_date = datetime(currentYear, currentMonth, currentDay, 0, 0, 0, 0).date()
|
|
|
2705 |
userAppInstallObj.app_id = approvedAppTransaction.app_id
|
|
|
2706 |
userAppInstallObj.app_name = app_offer.app_name
|
|
|
2707 |
userAppInstallObj.installCount = 1
|
| 16915 |
manish.sha |
2708 |
userAppInstallObj.payoutAmount = approvedAppTransaction.final_user_payout
|
| 16631 |
manish.sha |
2709 |
else:
|
|
|
2710 |
userAppInstallObj.installCount = userAppInstallObj.installCount + 1
|
| 16915 |
manish.sha |
2711 |
userAppInstallObj.payoutAmount = userAppInstallObj.payoutAmount +approvedAppTransaction.final_user_payout
|
| 16631 |
manish.sha |
2712 |
|
|
|
2713 |
approvedAppTransaction.cashBackConsidered = True
|
|
|
2714 |
session.commit()
|
|
|
2715 |
return True
|
|
|
2716 |
except:
|
|
|
2717 |
session.rollback()
|
| 16636 |
manish.sha |
2718 |
print traceback.print_exc()
|
| 16631 |
manish.sha |
2719 |
return False
|
| 16693 |
manish.sha |
2720 |
|
|
|
2721 |
def _sendAlertForAppPayouts(app_id, offerPrice, userPayout, payout):
|
|
|
2722 |
m = Email('localhost')
|
|
|
2723 |
mFrom = "dtr@shop2020.in"
|
|
|
2724 |
m.setFrom(mFrom)
|
| 20172 |
aman.kumar |
2725 |
mTo = ['rajneesh.arora@saholic.com','kshitij.sood@saholic.com','chaitnaya.vats@saholic.com','ritesh.chauhan@saholic.com','khushal.bhatia@saholic.com']
|
| 16693 |
manish.sha |
2726 |
for receipient in mTo:
|
|
|
2727 |
m.addRecipient(receipient)
|
|
|
2728 |
appOffer = app_offers.get_by(id=app_id)
|
|
|
2729 |
if offerPrice != payout:
|
|
|
2730 |
m.setSubject("Mismatch in Offer Price and Actual Pay Out for App Id:- "+str(appOffer.id)+" App Name:- "+str(appOffer.app_name))
|
|
|
2731 |
message1 = "Offer Price:- "+ str(appOffer.offer_price) + "\n" + "Actual Pay Out:- "+ str(payout)
|
|
|
2732 |
m.setTextBody(message1)
|
|
|
2733 |
if userPayout > payout:
|
|
|
2734 |
m.setSubject("User Pay Out greater than actual PayOut for App Id:- "+str(appOffer.id)+" App Name:- "+str(appOffer.app_name))
|
|
|
2735 |
message2 = "User Pay Out Price:- "+ str(appOffer.user_payout) + "\n" + "Actual Pay Out:- "+ str(payout)
|
|
|
2736 |
m.setTextBody(message2)
|
|
|
2737 |
m.send()
|
| 16631 |
manish.sha |
2738 |
|
| 16789 |
amit.gupta |
2739 |
def rejectCashback(orderId, subOrderId):
|
| 16833 |
amit.gupta |
2740 |
cashBack = get_mongo_connection().Dtr.merchantOrder.update({"orderId":orderId, "subOrders.merchantSubOrderId":subOrderId},
|
| 16789 |
amit.gupta |
2741 |
{"$set":{"subOrders.$.cashBackStatus":CB_REJECTED}})
|
| 16837 |
amit.gupta |
2742 |
print cashBack
|
| 16836 |
amit.gupta |
2743 |
return cashBack.get("nModified")
|
| 16894 |
manish.sha |
2744 |
|
|
|
2745 |
def getAppOffers(retailer_id):
|
|
|
2746 |
if not bool(mc.get("cached_app_offers_"+str(retailer_id))):
|
|
|
2747 |
populateAppOffers(retailer_id)
|
|
|
2748 |
return mc.get("cached_app_offers_"+str(retailer_id))
|
|
|
2749 |
|
|
|
2750 |
def populateAppOffers(retailerId):
|
|
|
2751 |
retailerId = int(retailerId)
|
|
|
2752 |
#offset = req.get_param_as_int("offset")
|
|
|
2753 |
#limit = req.get_param_as_int("limit")
|
| 16941 |
manish.sha |
2754 |
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()
|
|
|
2755 |
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 |
2756 |
#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()
|
|
|
2757 |
|
|
|
2758 |
appOffersMap = {}
|
|
|
2759 |
priorityList = []
|
|
|
2760 |
priorityMap = {}
|
|
|
2761 |
for offer in priortizeders:
|
| 16941 |
manish.sha |
2762 |
if priorityMap.has_key(long(offer[1])):
|
|
|
2763 |
offersVal = priorityMap.get(long(offer[1]))
|
|
|
2764 |
offersVal.append(offer)
|
|
|
2765 |
priorityMap[long(offer[1])]=offersVal
|
|
|
2766 |
else:
|
|
|
2767 |
offersVal = []
|
|
|
2768 |
offersVal.append(offer)
|
|
|
2769 |
priorityMap[long(offer[1])]=offersVal
|
|
|
2770 |
|
| 16894 |
manish.sha |
2771 |
priorityList = sorted(priorityMap)
|
|
|
2772 |
|
|
|
2773 |
maxCount = len(nonPriortizedOffers) + len(priortizeders)
|
|
|
2774 |
|
| 16909 |
manish.sha |
2775 |
if priorityList is not None and len(priorityList)>0:
|
|
|
2776 |
if maxCount < max(priorityList):
|
|
|
2777 |
maxCount = max(priorityList)
|
| 16894 |
manish.sha |
2778 |
|
|
|
2779 |
count = 1
|
|
|
2780 |
blockedPlaces = []
|
|
|
2781 |
availablePlaces = []
|
|
|
2782 |
while count <= maxCount:
|
|
|
2783 |
if count in priorityList:
|
|
|
2784 |
blockedPlaces.append(count)
|
|
|
2785 |
else:
|
|
|
2786 |
availablePlaces.append(count)
|
|
|
2787 |
count = count +1
|
| 16941 |
manish.sha |
2788 |
print 'Blocked Places', blockedPlaces
|
| 16894 |
manish.sha |
2789 |
for val in blockedPlaces:
|
| 16941 |
manish.sha |
2790 |
key = val
|
|
|
2791 |
for offerObj in priorityMap.get(val):
|
|
|
2792 |
while appOffersMap.has_key(key):
|
|
|
2793 |
key = key+1
|
|
|
2794 |
appOffersMap[key] = long(offerObj[0])
|
|
|
2795 |
if key in availablePlaces:
|
|
|
2796 |
availablePlaces.remove(key)
|
|
|
2797 |
|
|
|
2798 |
print 'Available Places', availablePlaces
|
|
|
2799 |
|
| 16894 |
manish.sha |
2800 |
i=0
|
|
|
2801 |
for val in availablePlaces:
|
| 16899 |
manish.sha |
2802 |
if i<len(nonPriortizedOffers):
|
| 16902 |
manish.sha |
2803 |
appOffersMap[val]= long(nonPriortizedOffers[i][0])
|
| 16899 |
manish.sha |
2804 |
else:
|
|
|
2805 |
break
|
|
|
2806 |
i=i+1
|
| 16901 |
manish.sha |
2807 |
print 'AppOffersMap', appOffersMap
|
| 16894 |
manish.sha |
2808 |
|
|
|
2809 |
finalAppOffersMap = {}
|
|
|
2810 |
if len(appOffersMap) > 0:
|
|
|
2811 |
for key in sorted(appOffersMap):
|
|
|
2812 |
finalAppOffersMap[key] = appOffersMap[key]
|
|
|
2813 |
|
|
|
2814 |
mc.set("cached_app_offers_"+str(retailerId), finalAppOffersMap, 120)
|
|
|
2815 |
else:
|
|
|
2816 |
print 'No Offers'
|
|
|
2817 |
mc.set("cached_app_offers_"+str(retailerId), {}, 10)
|
| 17280 |
manish.sha |
2818 |
|
| 19556 |
manas |
2819 |
def sendNotification(userIds, campaignName, title, message,notificationtype, url, expiresat='2999-01-01', sendsms=False, smstext=None):
|
|
|
2820 |
max_id = list(get_mongo_connection_dtr_data().User.notificationcampaigns.find().sort([('_id',pymongo.DESCENDING)]).limit(1))
|
| 19337 |
manish.sha |
2821 |
if len(max_id) ==0:
|
|
|
2822 |
max_id = 0
|
|
|
2823 |
else:
|
|
|
2824 |
max_id = max_id[0]['_id']
|
|
|
2825 |
max_id = max_id +1
|
| 19362 |
manish.sha |
2826 |
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 |
2827 |
get_mongo_connection_dtr_data().User.notificationcampaigns.insert(campaign.__dict__)
|
| 17302 |
kshitij.so |
2828 |
|
|
|
2829 |
def getDummyDeals(categoryId, offset, limit):
|
|
|
2830 |
outer_query = []
|
|
|
2831 |
outer_query.append({"showDeal":1})
|
|
|
2832 |
outer_query.append({"category_id":categoryId})
|
|
|
2833 |
query = {}
|
|
|
2834 |
query['$gt'] = -100
|
|
|
2835 |
outer_query.append({'totalPoints':query})
|
|
|
2836 |
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))
|
|
|
2837 |
returnObj = []
|
|
|
2838 |
for deal in all_deals:
|
| 17306 |
kshitij.so |
2839 |
item = list(get_mongo_connection().Catalog.MasterData.find({'_id':deal['_id']}))
|
| 17734 |
kshitij.so |
2840 |
returnObj.append(getItemObjForStaticDeals(item[0],transform=True))
|
| 17302 |
kshitij.so |
2841 |
return returnObj
|
| 17367 |
kshitij.so |
2842 |
|
| 17469 |
kshitij.so |
2843 |
def searchDummyDeals(search_term , limit, offset):
|
| 17367 |
kshitij.so |
2844 |
data = []
|
|
|
2845 |
uniqueMap = {}
|
|
|
2846 |
if search_term is not None:
|
|
|
2847 |
terms = search_term.split(' ')
|
|
|
2848 |
outer_query = []
|
|
|
2849 |
for term in terms:
|
|
|
2850 |
outer_query.append({"source_product_name":re.compile(term, re.IGNORECASE)})
|
|
|
2851 |
try:
|
|
|
2852 |
collection = get_mongo_connection().Catalog.MasterData.find({"$and":outer_query,'source_id':{'$in':SOURCE_MAP.keys()}})
|
|
|
2853 |
for record in collection:
|
|
|
2854 |
data.append(record)
|
|
|
2855 |
except:
|
|
|
2856 |
pass
|
|
|
2857 |
else:
|
|
|
2858 |
collection = get_mongo_connection().Catalog.MasterData.find({'source_id':{'$in':SOURCE_MAP.keys()}})
|
|
|
2859 |
for record in collection:
|
|
|
2860 |
data.append(record)
|
|
|
2861 |
for x in data:
|
|
|
2862 |
if not uniqueMap.has_key(x['skuBundleId']):
|
| 17469 |
kshitij.so |
2863 |
uniqueMap[x['skuBundleId']] = {'source_product_name':x['source_product_name'],'skuBundleId':x['skuBundleId'],'thumbnail':x['thumbnail']}
|
| 17367 |
kshitij.so |
2864 |
|
| 17469 |
kshitij.so |
2865 |
if (offset + limit) > len(uniqueMap.values()):
|
|
|
2866 |
limit = len(uniqueMap.values()) - offset - 1
|
|
|
2867 |
|
|
|
2868 |
count = 0
|
|
|
2869 |
# for x in uniqueMap.values():
|
|
|
2870 |
# print count,
|
|
|
2871 |
# print '\t',
|
|
|
2872 |
# print x
|
|
|
2873 |
# count = count+1
|
| 17555 |
kshitij.so |
2874 |
|
| 17469 |
kshitij.so |
2875 |
print offset
|
|
|
2876 |
print limit
|
|
|
2877 |
|
|
|
2878 |
return uniqueMap.values()[offset:limit+offset]
|
| 17367 |
kshitij.so |
2879 |
|
| 17469 |
kshitij.so |
2880 |
|
|
|
2881 |
def getDummyPricing(skuBundleId):
|
|
|
2882 |
collection = get_mongo_connection().Catalog.MasterData.find({'source_id':{'$in':SOURCE_MAP.keys()},'skuBundleId':skuBundleId,'in_stock':1})
|
|
|
2883 |
print collection.count()
|
|
|
2884 |
cheapest = 99999999
|
|
|
2885 |
cheapestDetails= None
|
|
|
2886 |
returnMap = {}
|
|
|
2887 |
|
|
|
2888 |
for d in collection:
|
|
|
2889 |
if d['available_price'] < cheapest:
|
|
|
2890 |
cheapestDetails = d
|
|
|
2891 |
cheapest = int(d['available_price'])
|
|
|
2892 |
if returnMap.has_key(d['source_id']):
|
| 17733 |
kshitij.so |
2893 |
d = getItemObjForStaticDeals(d,transform=True)
|
| 17469 |
kshitij.so |
2894 |
d['toShowStore'] = 0
|
|
|
2895 |
returnMap[d['source_id']].append(d)
|
|
|
2896 |
else:
|
|
|
2897 |
temp = []
|
| 17733 |
kshitij.so |
2898 |
d = getItemObjForStaticDeals(d,transform=True)
|
| 17469 |
kshitij.so |
2899 |
d['toShowStore'] = 1
|
|
|
2900 |
temp.append(d)
|
|
|
2901 |
returnMap[d['source_id']] = temp
|
|
|
2902 |
returnMap['cheapest'] = cheapestDetails
|
|
|
2903 |
for y in returnMap.itervalues():
|
|
|
2904 |
if isinstance(y, (list, tuple)):
|
|
|
2905 |
(y[len(y)-1])['lastElement'] = 1
|
|
|
2906 |
else:
|
|
|
2907 |
pass
|
|
|
2908 |
if returnMap['cheapest'] ==None:
|
|
|
2909 |
dum = get_mongo_connection().Catalog.MasterData.find_one({'skuBundleId':skuBundleId,'source_id':{"$in":SOURCE_MAP.keys()}})
|
|
|
2910 |
returnMap['cheapest'] = {'thumbnail':dum['thumbnail'],'source_product_name':dum['source_product_name']}
|
|
|
2911 |
return returnMap
|
| 17555 |
kshitij.so |
2912 |
|
| 17603 |
kshitij.so |
2913 |
|
| 17555 |
kshitij.so |
2914 |
def addDealObject(data):
|
| 17570 |
kshitij.so |
2915 |
if data.get('img_url') is None or data.get('img_url')=="" or data.get('name') is None or data.get('name')=="":
|
|
|
2916 |
return {0:'Invalid data'}
|
| 17555 |
kshitij.so |
2917 |
try:
|
|
|
2918 |
max_id = list(get_mongo_connection().Catalog.DealObject.find().sort([('_id',pymongo.DESCENDING)]).limit(1))
|
|
|
2919 |
if len(max_id) ==0:
|
|
|
2920 |
max_id = 0
|
| 17559 |
kshitij.so |
2921 |
else:
|
|
|
2922 |
max_id = max_id[0]['_id']
|
|
|
2923 |
data['_id'] = max_id +1
|
| 17555 |
kshitij.so |
2924 |
get_mongo_connection().Catalog.DealObject.insert(data)
|
|
|
2925 |
return {1:'Data added successfully'}
|
|
|
2926 |
except:
|
|
|
2927 |
return {0:'Error in adding data'}
|
|
|
2928 |
|
| 17561 |
kshitij.so |
2929 |
def getAllDealObjects(offset, limit):
|
|
|
2930 |
data = []
|
|
|
2931 |
collection = get_mongo_connection().Catalog.DealObject
|
|
|
2932 |
cursor = collection.find({}).skip(offset).limit(limit)
|
|
|
2933 |
for val in cursor:
|
| 17564 |
kshitij.so |
2934 |
data.append({'_id':val['_id'],'name':val['name']})
|
| 17561 |
kshitij.so |
2935 |
return data
|
| 17564 |
kshitij.so |
2936 |
|
|
|
2937 |
def deleteDealObject(id):
|
|
|
2938 |
try:
|
|
|
2939 |
get_mongo_connection().Catalog.DealObject.remove({'_id':id})
|
| 17616 |
kshitij.so |
2940 |
get_mongo_connection().Catalog.FeaturedDealsDealObject.remove({'_id':id})
|
| 17564 |
kshitij.so |
2941 |
return {1:"Deal Object deleted"}
|
|
|
2942 |
except:
|
|
|
2943 |
return {0:"Error in deleting object"}
|
| 17566 |
kshitij.so |
2944 |
|
|
|
2945 |
def getDealObjectById(id):
|
|
|
2946 |
try:
|
|
|
2947 |
data = get_mongo_connection().Catalog.DealObject.find({'_id':id})
|
|
|
2948 |
return data
|
|
|
2949 |
except:
|
| 17570 |
kshitij.so |
2950 |
return {}
|
| 17561 |
kshitij.so |
2951 |
|
| 17570 |
kshitij.so |
2952 |
def updateDealObject(data):
|
|
|
2953 |
try:
|
|
|
2954 |
_id = data['_id']
|
|
|
2955 |
data.pop('_id')
|
|
|
2956 |
get_mongo_connection().Catalog.DealObject.update({'_id':_id},{"$set":data},upsert=False)
|
|
|
2957 |
return {1:"Data updated successfully"}
|
|
|
2958 |
except:
|
|
|
2959 |
return {0:"Error in updating data"}
|
|
|
2960 |
|
| 17610 |
kshitij.so |
2961 |
def getAllFeaturedDealsForDealObject(offset, limit):
|
|
|
2962 |
data = []
|
|
|
2963 |
collection = get_mongo_connection().Catalog.FeaturedDealsDealObject
|
|
|
2964 |
cursor = collection.find({}).skip(offset).limit(limit)
|
|
|
2965 |
for val in cursor:
|
|
|
2966 |
data.append(val)
|
|
|
2967 |
return data
|
|
|
2968 |
|
|
|
2969 |
def addFeaturedDealForDealObject(data):
|
| 19280 |
kshitij.so |
2970 |
print data
|
|
|
2971 |
|
| 17610 |
kshitij.so |
2972 |
collection = get_mongo_connection().Catalog.FeaturedDealsDealObject
|
|
|
2973 |
cursor = collection.find({'_id':data['_id']})
|
|
|
2974 |
master = get_mongo_connection().Catalog.DealObject.find_one({'_id':data['_id']})
|
|
|
2975 |
if master is None:
|
|
|
2976 |
return {0:"Deal Object id wrong"}
|
|
|
2977 |
otherInfoObj = data['otherInfo']
|
|
|
2978 |
toPop = []
|
|
|
2979 |
for x,y in otherInfoObj.iteritems():
|
| 19280 |
kshitij.so |
2980 |
if y==0 or y=="":
|
| 17610 |
kshitij.so |
2981 |
toPop.append(x)
|
|
|
2982 |
|
|
|
2983 |
for popItem in toPop:
|
|
|
2984 |
otherInfoObj.pop(popItem)
|
|
|
2985 |
if len(otherInfoObj.keys())==0:
|
|
|
2986 |
return {0:"No rank info to add"}
|
|
|
2987 |
|
|
|
2988 |
for x,y in otherInfoObj.iteritems():
|
|
|
2989 |
exist = get_mongo_connection().Catalog.FeaturedDealsDealObject.find({'otherInfo.'+x:y})
|
|
|
2990 |
if exist.count() >0:
|
|
|
2991 |
return {0:"Rank already assigned Deal Object Id %s"%(exist[0]['_id'])}
|
|
|
2992 |
if cursor.count() > 0:
|
|
|
2993 |
return {0:"Deal Object Id information already present."}
|
|
|
2994 |
else:
|
|
|
2995 |
collection.insert(data)
|
|
|
2996 |
return {1:"Data added successfully"}
|
|
|
2997 |
|
| 17616 |
kshitij.so |
2998 |
def deleteFeaturedDealObject(id):
|
|
|
2999 |
try:
|
|
|
3000 |
get_mongo_connection().Catalog.FeaturedDealsDealObject.remove({'_id':id})
|
|
|
3001 |
return {1:"Deal Object deleted"}
|
|
|
3002 |
except:
|
|
|
3003 |
return {0:"Error in deleting object"}
|
| 17654 |
kshitij.so |
3004 |
|
|
|
3005 |
def getSubCategoryForFilter(category_id):
|
|
|
3006 |
if mc.get("subCategoryFilter") is None:
|
|
|
3007 |
print "Populating subcategory data for category_id %d" %(category_id)
|
|
|
3008 |
tabData, mobData, accData = [], [], []
|
|
|
3009 |
|
|
|
3010 |
accessoriesDeals = get_mongo_connection().Catalog.Deals.aggregate([
|
| 19597 |
kshitij.so |
3011 |
{"$match":{"category_id":6,"showDeal":1,"dealRankPoints":{"$gt":0}}
|
| 17654 |
kshitij.so |
3012 |
},
|
|
|
3013 |
{"$group" :
|
|
|
3014 |
{'_id':{'subCategoryId':'$subCategoryId','subCategory':'$subCategory'},'count':{'$sum':1}}
|
|
|
3015 |
}
|
|
|
3016 |
])
|
|
|
3017 |
|
|
|
3018 |
for accessoryDeal in accessoriesDeals['result']:
|
|
|
3019 |
if accessoryDeal.get('_id').get('subCategoryId') != 0:
|
|
|
3020 |
tempMap = {}
|
|
|
3021 |
tempMap['subCategory'] = accessoryDeal.get('_id').get('subCategory')
|
|
|
3022 |
tempMap['subCategoryId'] = accessoryDeal.get('_id').get('subCategoryId')
|
|
|
3023 |
tempMap['count'] = accessoryDeal.get('count')
|
|
|
3024 |
accData.append(tempMap)
|
|
|
3025 |
|
|
|
3026 |
|
|
|
3027 |
mc.set("subCategoryFilter",{3:mobData, 5:tabData, 6:accData}, 600)
|
|
|
3028 |
|
|
|
3029 |
return sorted(mc.get("subCategoryFilter").get(category_id), key = lambda x: (-x['count'], x['subCategory']))
|
| 17610 |
kshitij.so |
3030 |
|
| 17727 |
kshitij.so |
3031 |
def dummyLogin(data):
|
| 17731 |
kshitij.so |
3032 |
exist = list(get_mongo_connection().Catalog.DummyUser.find({'email':data['email'],'password':data['password']}))
|
| 17727 |
kshitij.so |
3033 |
if len(exist) > 0:
|
| 17728 |
kshitij.so |
3034 |
return {'user_id':exist[0]['_id'],'fullName':exist[0]['fullName']}
|
| 17727 |
kshitij.so |
3035 |
else:
|
|
|
3036 |
return {'user_id':0}
|
| 17616 |
kshitij.so |
3037 |
|
| 17727 |
kshitij.so |
3038 |
def dummyRegister(data):
|
|
|
3039 |
try:
|
|
|
3040 |
exist = list(get_mongo_connection().Catalog.DummyUser.find({'email':data['email']}))
|
|
|
3041 |
if len(exist) > 0:
|
|
|
3042 |
return {'msg':"Email already registered",'user_id':0}
|
|
|
3043 |
else:
|
|
|
3044 |
max_id = list(get_mongo_connection().Catalog.DummyUser.find().sort([('_id',pymongo.DESCENDING)]).limit(1))
|
|
|
3045 |
if len(max_id) ==0:
|
|
|
3046 |
max_id = 0
|
|
|
3047 |
else:
|
|
|
3048 |
max_id = max_id[0]['_id']
|
|
|
3049 |
data['_id'] = max_id +1
|
|
|
3050 |
get_mongo_connection().Catalog.DummyUser.insert(data)
|
| 17728 |
kshitij.so |
3051 |
return {'msg':"Registration successful",'user_id':data['_id'],'fullName':data['fullName']}
|
| 17727 |
kshitij.so |
3052 |
except:
|
|
|
3053 |
return {'msg':"Error in registration.",'user_id':0}
|
|
|
3054 |
|
| 17731 |
kshitij.so |
3055 |
def getDummyUser(user_id):
|
|
|
3056 |
exist = list(get_mongo_connection().Catalog.DummyUser.find({'_id':user_id}))
|
|
|
3057 |
if len(exist) > 0:
|
|
|
3058 |
return exist[0]
|
|
|
3059 |
else:
|
|
|
3060 |
return {'user_id':0,'fullName':"",'email':"","contactNumber":""}
|
|
|
3061 |
|
|
|
3062 |
def updateDummyUser(data):
|
|
|
3063 |
try:
|
| 17732 |
kshitij.so |
3064 |
get_mongo_connection().Catalog.DummyUser.update({'_id':data['user_id']},{"$set":data},upsert=False)
|
| 17731 |
kshitij.so |
3065 |
return {'msg':"Data updated successfuly",'response':1}
|
|
|
3066 |
except:
|
|
|
3067 |
return {'msg':"Unable to update data",'response':0}
|
| 17936 |
kshitij.so |
3068 |
|
| 18089 |
kshitij.so |
3069 |
def getDealsForSearchText(subCategoryIds, searchTerm, offset, limit):
|
|
|
3070 |
subCategories= [int(subCategoryId) for subCategoryId in subCategoryIds.split('^')]
|
| 18106 |
kshitij.so |
3071 |
print "SubCategories are ",subCategories
|
| 17936 |
kshitij.so |
3072 |
payload = {
|
| 18106 |
kshitij.so |
3073 |
"query": {
|
| 17936 |
kshitij.so |
3074 |
"bool": {
|
| 18106 |
kshitij.so |
3075 |
"must": [{
|
|
|
3076 |
"match": {
|
|
|
3077 |
"title": {
|
|
|
3078 |
"query": searchTerm,
|
|
|
3079 |
"operator": "and"
|
|
|
3080 |
}
|
| 17936 |
kshitij.so |
3081 |
}
|
| 18106 |
kshitij.so |
3082 |
},
|
|
|
3083 |
|
|
|
3084 |
{
|
|
|
3085 |
"in": {
|
|
|
3086 |
"subCategoryId": subCategories
|
|
|
3087 |
}
|
| 17936 |
kshitij.so |
3088 |
}
|
| 18106 |
kshitij.so |
3089 |
|
|
|
3090 |
]
|
| 17936 |
kshitij.so |
3091 |
}
|
| 19135 |
kshitij.so |
3092 |
},
|
| 19580 |
kshitij.so |
3093 |
"sort": { "dealRankPoints": { "order": "desc" }}
|
| 18106 |
kshitij.so |
3094 |
}
|
| 17944 |
kshitij.so |
3095 |
result = get_elastic_search_connection().search(index="my_index", body=payload, from_=offset, size=limit)
|
| 17936 |
kshitij.so |
3096 |
totalCount= result['hits']['total']
|
|
|
3097 |
temp = []
|
|
|
3098 |
bundles = []
|
|
|
3099 |
if len(result['hits']['hits']) > 0:
|
|
|
3100 |
for x in result['hits']['hits']:
|
|
|
3101 |
tempMap = {}
|
|
|
3102 |
tempMap = {'skuBundleId':x['_source']['id'],'title':x['_source']['title']}
|
|
|
3103 |
temp.append(tempMap)
|
|
|
3104 |
bundles.append(x['_source']['id'])
|
| 18271 |
kshitij.so |
3105 |
#return temp
|
| 17936 |
kshitij.so |
3106 |
return getDealsForNotification(bundles, skipSplitting=True)
|
| 17731 |
kshitij.so |
3107 |
|
| 18089 |
kshitij.so |
3108 |
def getCountForSearchText(subCategoryIds, searchTerm):
|
|
|
3109 |
subCategories= [int(subCategoryId) for subCategoryId in subCategoryIds.split('^')]
|
| 17936 |
kshitij.so |
3110 |
payload = {
|
| 18106 |
kshitij.so |
3111 |
"query": {
|
| 17936 |
kshitij.so |
3112 |
"bool": {
|
| 18106 |
kshitij.so |
3113 |
"must": [{
|
|
|
3114 |
"match": {
|
|
|
3115 |
"title": {
|
|
|
3116 |
"query": searchTerm,
|
|
|
3117 |
"operator": "and"
|
|
|
3118 |
}
|
| 17936 |
kshitij.so |
3119 |
}
|
| 18106 |
kshitij.so |
3120 |
},
|
|
|
3121 |
|
|
|
3122 |
{
|
|
|
3123 |
"in": {
|
|
|
3124 |
"subCategoryId": subCategories
|
|
|
3125 |
}
|
| 17936 |
kshitij.so |
3126 |
}
|
| 18106 |
kshitij.so |
3127 |
|
|
|
3128 |
]
|
| 17936 |
kshitij.so |
3129 |
}
|
|
|
3130 |
}
|
| 18106 |
kshitij.so |
3131 |
}
|
| 17731 |
kshitij.so |
3132 |
|
| 17944 |
kshitij.so |
3133 |
result = get_elastic_search_connection().search(index="my_index", body=payload)
|
| 17936 |
kshitij.so |
3134 |
totalCount= result['hits']['total']
|
|
|
3135 |
return {'searchTerm':searchTerm,'count':totalCount}
|
| 18271 |
kshitij.so |
3136 |
|
|
|
3137 |
def getDealById(id):
|
|
|
3138 |
item = list(get_mongo_connection().Catalog.MasterData.find({'_id':int(id)}))
|
|
|
3139 |
d = get_mongo_connection().Catalog.Deals.find_one({'_id':int(id)})
|
| 19193 |
kshitij.so |
3140 |
if len(item) ==0:
|
|
|
3141 |
return {}
|
| 18271 |
kshitij.so |
3142 |
if d is None:
|
|
|
3143 |
d = {'showDp':0,'dp':0}
|
|
|
3144 |
try:
|
|
|
3145 |
cashBack = getCashBack(item[0]['_id'], item[0]['source_id'], item[0]['category_id'])
|
|
|
3146 |
if not cashBack or cashBack.get('cash_back_status')!=1:
|
|
|
3147 |
item[0]['cash_back_type'] = 0
|
|
|
3148 |
item[0]['cash_back'] = 0
|
|
|
3149 |
else:
|
|
|
3150 |
if cashBack.get('maxCashBack') is not None:
|
|
|
3151 |
|
|
|
3152 |
if cashBack.get('cash_back_type') ==1 and (float(cashBack.get('cash_back'))*item[0]['available_price'])/100 > cashBack.get('maxCashBack'):
|
|
|
3153 |
cashBack['cash_back_type'] = 2
|
|
|
3154 |
cashBack['cash_back'] = cashBack['maxCashBack']
|
|
|
3155 |
elif cashBack.get('cash_back_type') ==2 and cashBack.get('cash_back') > cashBack.get('maxCashBack'):
|
|
|
3156 |
cashBack['cash_back'] = cashBack['maxCashBack']
|
| 17936 |
kshitij.so |
3157 |
|
| 18271 |
kshitij.so |
3158 |
item[0]['cash_back_type'] = int(cashBack['cash_back_type'])
|
|
|
3159 |
item[0]['cash_back'] = cashBack['cash_back']
|
|
|
3160 |
except:
|
|
|
3161 |
print "Error in adding cashback to deals"
|
|
|
3162 |
item[0]['cash_back_type'] = 0
|
|
|
3163 |
item[0]['cash_back'] = 0
|
|
|
3164 |
try:
|
|
|
3165 |
item[0]['dp'] = d['dp']
|
|
|
3166 |
item[0]['showDp'] = d['showDp']
|
|
|
3167 |
except:
|
|
|
3168 |
item[0]['dp'] = 0.0
|
|
|
3169 |
item[0]['showDp'] = 0
|
|
|
3170 |
try:
|
|
|
3171 |
item[0]['thumbnail'] = item[0]['thumbnail'].strip()
|
|
|
3172 |
except:
|
|
|
3173 |
pass
|
|
|
3174 |
|
|
|
3175 |
try:
|
|
|
3176 |
if item[0]['showVideo']==0:
|
|
|
3177 |
item[0]['videoLink'] =""
|
|
|
3178 |
except:
|
|
|
3179 |
item[0]['videoLink'] =""
|
|
|
3180 |
try:
|
|
|
3181 |
if item[0]['quantity'] >1:
|
|
|
3182 |
ppq = float(item[0]['available_price'])/item[0]['quantity']
|
|
|
3183 |
|
|
|
3184 |
if ppq == round(ppq):
|
|
|
3185 |
item[0]['ppq'] = int(ppq)
|
|
|
3186 |
else:
|
|
|
3187 |
item[0]['ppq'] = round(ppq,2)
|
|
|
3188 |
else:
|
|
|
3189 |
item[0]['ppq'] = 0
|
|
|
3190 |
except:
|
|
|
3191 |
item[0]['ppq'] = 0
|
|
|
3192 |
if item[0]['category_id']!=6:
|
|
|
3193 |
try:
|
| 18830 |
kshitij.so |
3194 |
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']))
|
|
|
3195 |
item[0]['filterTextBrand'] = (item[0]['brand'])
|
| 18271 |
kshitij.so |
3196 |
except:
|
| 18830 |
kshitij.so |
3197 |
pass
|
| 18271 |
kshitij.so |
3198 |
else:
|
|
|
3199 |
try:
|
|
|
3200 |
if item[0]['subCategory']=='' or item[0]['subCategory'] is None or item[0]['subCategoryId']==0:
|
|
|
3201 |
raise
|
| 18830 |
kshitij.so |
3202 |
item[0]['filterLinkSubCategory'] = '/category/'+str(int(item[0]['category_id']))+'?searchFor='+urllib.quote(item[0]['subCategory'])+'&filter=subcategory&subcategories='+str(int(item[0]['subCategoryId']))
|
|
|
3203 |
item[0]['filterTextSubCategory'] = (item[0]['subCategory'])
|
|
|
3204 |
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']))
|
|
|
3205 |
item[0]['filterTextBrand'] = (item[0]['brand'])
|
| 18271 |
kshitij.so |
3206 |
except:
|
| 18830 |
kshitij.so |
3207 |
pass
|
| 18271 |
kshitij.so |
3208 |
try:
|
|
|
3209 |
if item[0]['source_id']==4:
|
|
|
3210 |
item_availability_info = mc.get("item_availability_"+str(item[0]['identifier']).strip())
|
|
|
3211 |
if item_availability_info is None or len(item_availability_info)==0:
|
|
|
3212 |
item[0]['availabilityInfo'] = [{}]
|
|
|
3213 |
else:
|
|
|
3214 |
item[0]['availabilityInfo'] = item_availability_info
|
|
|
3215 |
except:
|
|
|
3216 |
item[0]['availabilityInfo'] = [{}]
|
| 19193 |
kshitij.so |
3217 |
|
|
|
3218 |
if item[0]['source_id']==4:
|
|
|
3219 |
for av_info in item[0]['availabilityInfo']:
|
|
|
3220 |
if not av_info:
|
|
|
3221 |
continue
|
|
|
3222 |
av_info['cash_back'] = item[0]['cash_back']
|
|
|
3223 |
av_info['cash_back_type'] = item[0]['cash_back_type']
|
|
|
3224 |
netPriceAfterCashBack = av_info['sellingPrice']
|
| 19199 |
kshitij.so |
3225 |
if av_info['cash_back_type'] ==1:
|
| 19207 |
kshitij.so |
3226 |
netPriceAfterCashBack = av_info['sellingPrice'] - math.floor(float(av_info['sellingPrice'])*av_info['cash_back']/100)
|
| 19199 |
kshitij.so |
3227 |
elif av_info['cash_back_type'] ==2:
|
| 19207 |
kshitij.so |
3228 |
netPriceAfterCashBack = av_info['sellingPrice'] - math.floor(av_info['cash_back'])
|
| 19193 |
kshitij.so |
3229 |
else:
|
|
|
3230 |
pass
|
|
|
3231 |
av_info['netPriceAfterCashBack'] = netPriceAfterCashBack
|
|
|
3232 |
|
|
|
3233 |
if item[0]['source_id'] != SOURCE_MAP.get("PAYTM.COM"):
|
|
|
3234 |
if item[0]['codAvailable'] ==1:
|
|
|
3235 |
paytmPrice = item[0]['available_price']
|
|
|
3236 |
else:
|
|
|
3237 |
paytmPrice = item[0]['gross_price']
|
|
|
3238 |
|
|
|
3239 |
if item[0]['cash_back_type'] ==1:
|
| 19207 |
kshitij.so |
3240 |
item[0]['netPriceAfterCashBack'] = paytmPrice - math.floor(float(paytmPrice)*item[0]['cash_back']/100)
|
| 19193 |
kshitij.so |
3241 |
elif item[0]['cash_back_type'] ==2:
|
| 19207 |
kshitij.so |
3242 |
item[0]['netPriceAfterCashBack'] = paytmPrice - math.floor(item[0]['cash_back'])
|
| 19193 |
kshitij.so |
3243 |
else:
|
|
|
3244 |
item[0]['netPriceAfterCashBack'] = paytmPrice
|
|
|
3245 |
|
|
|
3246 |
else:
|
|
|
3247 |
if item[0]['cash_back_type'] ==1:
|
| 19207 |
kshitij.so |
3248 |
item[0]['netPriceAfterCashBack'] = item[0]['available_price'] - math.floor(float(item[0]['available_price'])*item[0]['cash_back']/100)
|
| 19193 |
kshitij.so |
3249 |
elif item[0]['cash_back_type'] ==2:
|
| 19207 |
kshitij.so |
3250 |
item[0]['netPriceAfterCashBack'] = item[0]['available_price'] - math.floor(item[0]['cash_back'])
|
| 19193 |
kshitij.so |
3251 |
else:
|
|
|
3252 |
item[0]['netPriceAfterCashBack'] = item[0]['available_price']
|
|
|
3253 |
|
| 18271 |
kshitij.so |
3254 |
return item[0]
|
|
|
3255 |
|
| 19288 |
kshitij.so |
3256 |
def getOfferForUser(userId):
|
|
|
3257 |
specialOffer = {}
|
|
|
3258 |
promoOffer = get_mongo_connection().Catalog.PromoOffer.find_one({'user_id':userId})
|
|
|
3259 |
try:
|
|
|
3260 |
if promoOffer is not None:
|
|
|
3261 |
offer = get_mongo_connection().Catalog.Promotions.find_one({'_id':promoOffer.get('offer_id')})
|
|
|
3262 |
if offer is None:
|
|
|
3263 |
raise
|
| 19355 |
kshitij.so |
3264 |
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 |
3265 |
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 |
3266 |
promoOffer.get('pending_order_value'), promoOffer.get('delivered_order_value'), promoOffer.get('last_run_timestamp'))
|
| 19354 |
kshitij.so |
3267 |
|
| 19355 |
kshitij.so |
3268 |
promo.offer_description = "Get upto %d%% cashback"%(promo.target2_cash_back_percetage)
|
|
|
3269 |
|
| 19288 |
kshitij.so |
3270 |
specialOffer = promo.__dict__
|
|
|
3271 |
except:
|
|
|
3272 |
pass
|
|
|
3273 |
return specialOffer
|
|
|
3274 |
|
| 19389 |
kshitij.so |
3275 |
def getBrandSubCategoryInfo(category_id, id_list, type):
|
| 19402 |
kshitij.so |
3276 |
try:
|
|
|
3277 |
id_list_mapping = {}
|
|
|
3278 |
if type == "brandInfo":
|
|
|
3279 |
brands = [int(brand_id) for brand_id in id_list.split('^')]
|
|
|
3280 |
for brand in brands:
|
|
|
3281 |
tm_brand = get_mongo_connection().Catalog.Deals.find_one({'brand_id':brand},{'brand':1})
|
|
|
3282 |
id_list_mapping[brand] = tm_brand.get('brand')
|
|
|
3283 |
elif type == "subCategoryInfo":
|
|
|
3284 |
subCategories = [int(subCategoryId) for subCategoryId in id_list.split('^')]
|
|
|
3285 |
for subCat in subCategories:
|
|
|
3286 |
id_list_mapping[subCat] = SUB_CATEGORY_MAP.get(subCat)
|
|
|
3287 |
else:
|
|
|
3288 |
return {}
|
| 19389 |
kshitij.so |
3289 |
|
| 19402 |
kshitij.so |
3290 |
if mc.get("brandSubCategoryInfo") is None:
|
|
|
3291 |
collection = get_mongo_connection().Catalog.Deals
|
|
|
3292 |
result = collection.aggregate(
|
|
|
3293 |
[
|
|
|
3294 |
{'$match':{'category_id':category_id,'showDeal':1}},
|
|
|
3295 |
{"$group": { "_id": { "subCategoryId": "$subCategoryId", "brand_id": "$brand_id", "brand":"$brand","subCategory":"$subCategory" }, "count": {"$sum": 1} } }
|
|
|
3296 |
]
|
|
|
3297 |
);
|
|
|
3298 |
#from pprint import pprint
|
|
|
3299 |
#pprint(result)
|
|
|
3300 |
|
|
|
3301 |
subCategoryMap = {}
|
|
|
3302 |
brandMap = {}
|
|
|
3303 |
|
|
|
3304 |
for data in result['result']:
|
|
|
3305 |
result_set = data['_id']
|
|
|
3306 |
count = data['count']
|
|
|
3307 |
subCategoryId = result_set['subCategoryId']
|
|
|
3308 |
brand_id = result_set['brand_id']
|
|
|
3309 |
subCategory = result_set['subCategory']
|
|
|
3310 |
brand = result_set['brand']
|
|
|
3311 |
|
|
|
3312 |
if subCategoryMap.has_key(subCategoryId):
|
|
|
3313 |
subCategoryMap.get(subCategoryId).append({'brand_id':brand_id, 'count':count, 'subCategory':subCategory, 'brand':brand})
|
|
|
3314 |
else:
|
|
|
3315 |
subCategoryMap[subCategoryId] = [{'brand_id':brand_id, 'count':count, 'subCategory':subCategory, 'brand':brand}]
|
|
|
3316 |
|
|
|
3317 |
if brandMap.has_key(brand_id):
|
|
|
3318 |
brandMap.get(brand_id).append({'subCategoryId':subCategoryId, 'count':count, 'subCategory':subCategory, 'brand':brand})
|
|
|
3319 |
else:
|
|
|
3320 |
brandMap[brand_id] = [{'subCategoryId':subCategoryId, 'count':count, 'subCategory':subCategory, 'brand':brand}]
|
|
|
3321 |
|
|
|
3322 |
mc.set("brandSubCategoryInfo",{'subCategoryMap':subCategoryMap, 'brandMap': brandMap}, 600)
|
| 19389 |
kshitij.so |
3323 |
|
| 19402 |
kshitij.so |
3324 |
|
|
|
3325 |
returnMap = {}
|
|
|
3326 |
brandSubCategoryInfo = mc.get("brandSubCategoryInfo")
|
|
|
3327 |
if brandSubCategoryInfo is None:
|
|
|
3328 |
return {'idListInfo':id_list_mapping,'result':[]}
|
|
|
3329 |
|
|
|
3330 |
if type == "subCategoryInfo":
|
|
|
3331 |
if brandSubCategoryInfo.get('subCategoryMap') is None:
|
|
|
3332 |
return {'idListInfo':id_list_mapping,'result':[]}
|
|
|
3333 |
subCategories = [int(subCategoryId) for subCategoryId in id_list.split('^')]
|
|
|
3334 |
subCategoryMap = brandSubCategoryInfo.get('subCategoryMap')
|
|
|
3335 |
for subCategory in subCategories:
|
|
|
3336 |
tempList = subCategoryMap.get(subCategory)
|
|
|
3337 |
print tempList
|
|
|
3338 |
if tempList is None:
|
|
|
3339 |
continue
|
|
|
3340 |
for v in tempList:
|
|
|
3341 |
if returnMap.has_key(v['brand_id']):
|
|
|
3342 |
existing = returnMap.get(v['brand_id'])
|
|
|
3343 |
existing['count'] = existing['count'] + v['count']
|
|
|
3344 |
else:
|
|
|
3345 |
returnMap[v['brand_id']] = {'brand_id':v['brand_id'],'brand':v['brand'],'count':v['count']}
|
| 19389 |
kshitij.so |
3346 |
|
| 19402 |
kshitij.so |
3347 |
|
|
|
3348 |
elif type == "brandInfo":
|
|
|
3349 |
if brandSubCategoryInfo.get('brandMap') is None:
|
|
|
3350 |
return {'idListInfo':id_list_mapping,'result':[]}
|
|
|
3351 |
brands = [int(brand_id) for brand_id in id_list.split('^')]
|
|
|
3352 |
brandMap = brandSubCategoryInfo.get('brandMap')
|
|
|
3353 |
for brand_id in brands:
|
|
|
3354 |
tempList = brandMap.get(brand_id)
|
|
|
3355 |
print tempList
|
|
|
3356 |
if tempList is None:
|
|
|
3357 |
continue
|
|
|
3358 |
for v in tempList:
|
|
|
3359 |
if returnMap.has_key(v['subCategoryId']):
|
|
|
3360 |
existing = returnMap.get(v['subCategoryId'])
|
|
|
3361 |
existing['count'] = existing['count'] + v['count']
|
|
|
3362 |
else:
|
|
|
3363 |
returnMap[v['subCategoryId']] = {'subCategoryId':v['subCategoryId'],'subCategory':v['subCategory'],'count':v['count']}
|
| 19389 |
kshitij.so |
3364 |
|
| 19402 |
kshitij.so |
3365 |
return {'idListInfo':id_list_mapping,'result':returnMap.values()}
|
|
|
3366 |
except:
|
|
|
3367 |
traceback.print_exc()
|
|
|
3368 |
return {}
|
| 19389 |
kshitij.so |
3369 |
|
| 19451 |
manas |
3370 |
def refundAmountInWallet(jsonReq):
|
|
|
3371 |
userId = int(jsonReq.get('user_id'))
|
|
|
3372 |
emailId = jsonReq.get('email_id')
|
|
|
3373 |
amount = int(jsonReq.get('amount'))
|
|
|
3374 |
store = jsonReq.get('store')
|
|
|
3375 |
refundType = jsonReq.get('type')
|
|
|
3376 |
mobileNumber = jsonReq.get('mobile')
|
|
|
3377 |
referenceId = jsonReq.get('reference_no')
|
|
|
3378 |
referenceDescription = jsonReq.get('reference_description')
|
| 19514 |
manas |
3379 |
if not store:
|
| 19456 |
manas |
3380 |
store = None
|
| 19514 |
manas |
3381 |
else:
|
| 19517 |
manas |
3382 |
store = store
|
| 19451 |
manas |
3383 |
if lower(refundType)=='refund':
|
| 19511 |
manas |
3384 |
refundType = CREDIT_TYPE_REFUND
|
| 19451 |
manas |
3385 |
elif lower(refundType)=='adjustment':
|
| 19511 |
manas |
3386 |
refundType = CREDIT_TYPE_ADJUSTMENT
|
| 19451 |
manas |
3387 |
collection = get_mongo_connection().Dtr.crmrefundwallet
|
| 19511 |
manas |
3388 |
offer1 = CrmRefundWallet(userId,emailId,mobileNumber,amount,refundType,store,referenceId,referenceDescription,REFUND_ADJUSTMENT_MAP.get(0),to_java_date(datetime.now()))
|
| 19451 |
manas |
3389 |
dict1 = todict(offer1)
|
|
|
3390 |
collection.save(dict1)
|
|
|
3391 |
return True
|
|
|
3392 |
|
| 19497 |
manas |
3393 |
def updateCrmWalletStatus(status,_id,userId,batchId,approvedBy):
|
| 19482 |
manas |
3394 |
if batchId is None:
|
|
|
3395 |
get_mongo_connection().Dtr.crmrefundwallet.update({'_id':ObjectId(_id),},{"$set":{"status":status,"update_timestamp":to_java_date(datetime.now())}})
|
|
|
3396 |
else:
|
| 20340 |
amit.gupta |
3397 |
#Batch id should be none to ensure that it does not get override
|
|
|
3398 |
get_mongo_connection().Dtr.crmrefundwallet.update({'_id':ObjectId(_id), 'batchId':None},{"$set":{"status":status,"update_timestamp":to_java_date(datetime.now()),"batchId":batchId,"approved_by":approvedBy}})
|
| 19463 |
manas |
3399 |
|
| 19451 |
manas |
3400 |
def fetchCrmRefundUsers(status,offset,limit):
|
| 19529 |
manas |
3401 |
if status is not None:
|
|
|
3402 |
cursor = list(get_mongo_connection().Dtr.crmrefundwallet.find({"status":status}).skip(offset).limit(limit).sort("created_timestamp",-1))
|
|
|
3403 |
else:
|
|
|
3404 |
cursor = list(get_mongo_connection().Dtr.crmrefundwallet.find().skip(offset).limit(limit).sort("created_timestamp",-1))
|
| 19451 |
manas |
3405 |
return cursor
|
|
|
3406 |
|
| 23004 |
amit.gupta |
3407 |
def fetchProfitmandiBanners():
|
| 23006 |
amit.gupta |
3408 |
cursor = list(get_mongo_connection().Catalog.banners.find().sort("type",1).sort("rank", 1))
|
| 23004 |
amit.gupta |
3409 |
return cursor
|
|
|
3410 |
|
|
|
3411 |
def addProfitMandiBanner(data):
|
| 23006 |
amit.gupta |
3412 |
collection = get_mongo_connection().Catalog.banners
|
| 23009 |
amit.gupta |
3413 |
data['rank']=int(data['rank'])
|
| 23004 |
amit.gupta |
3414 |
fetched = list(collection.find({
|
|
|
3415 |
'rank':{'$gte':data['rank']}, 'type': data['type']
|
|
|
3416 |
}))
|
|
|
3417 |
if fetched:
|
|
|
3418 |
for dict1 in fetched:
|
|
|
3419 |
dict1['rank'] += 1
|
|
|
3420 |
collection.save(dict1)
|
|
|
3421 |
collection.insert(data)
|
|
|
3422 |
return True
|
|
|
3423 |
|
|
|
3424 |
def removeProfitmandiBanners(bannerId):
|
| 23006 |
amit.gupta |
3425 |
collection = get_mongo_connection().Catalog.banners
|
|
|
3426 |
print "bannerId", bannerId
|
|
|
3427 |
collection.remove({"_id":ObjectId(bannerId)})
|
| 23004 |
amit.gupta |
3428 |
|
| 19485 |
manas |
3429 |
def fetchCrmRefundByBatchId(batchId):
|
| 19493 |
manas |
3430 |
cursor = get_mongo_connection().Dtr.crmrefundwallet.find_one({"batchId":int(batchId)})
|
| 19485 |
manas |
3431 |
return cursor
|
|
|
3432 |
|
| 19577 |
manas |
3433 |
def userLookUpForSaholicId(userId):
|
|
|
3434 |
result = None
|
|
|
3435 |
try:
|
|
|
3436 |
response = session.query(user_accounts.account_key).filter_by(user_id=userId).filter(user_accounts.account_type=='saholic').first()
|
|
|
3437 |
if response is None:
|
|
|
3438 |
result = 'User Not present in profitmandi'
|
|
|
3439 |
else:
|
|
|
3440 |
result = response[0]
|
|
|
3441 |
except:
|
|
|
3442 |
result = 'User Not present in profitmandi'
|
|
|
3443 |
traceback.print_exc()
|
|
|
3444 |
finally:
|
|
|
3445 |
session.close()
|
|
|
3446 |
return result
|
| 19453 |
manas |
3447 |
|
| 19880 |
naman |
3448 |
|
|
|
3449 |
def getAllItemCasback(itemcashback_id,offset,limit):
|
|
|
3450 |
itemcashbackcon = get_mongo_connection().Catalog.ItemCashBack
|
| 20435 |
kshitij.so |
3451 |
masterData = get_mongo_connection().Catalog.MasterData
|
| 19880 |
naman |
3452 |
if itemcashback_id is None:
|
| 20435 |
kshitij.so |
3453 |
response = []
|
|
|
3454 |
response_cash_back = list(itemcashbackcon.find().skip(offset).limit(limit))
|
|
|
3455 |
for r in response_cash_back:
|
|
|
3456 |
master = masterData.find_one({'_id':r['sku']})
|
| 22986 |
amit.gupta |
3457 |
if master is not None:
|
|
|
3458 |
r['source'] = SOURCE_MAP.get(master['source_id'])
|
|
|
3459 |
r['product_name'] = master['product_name']
|
|
|
3460 |
response.append(r)
|
|
|
3461 |
else:
|
|
|
3462 |
print "master found null for ------------", r['sku']
|
| 19880 |
naman |
3463 |
else:
|
| 20439 |
kshitij.so |
3464 |
response = itemcashbackcon.find_one({'_id' : ObjectId(itemcashback_id)})
|
| 20435 |
kshitij.so |
3465 |
master = masterData.find_one({'_id':response['sku']})
|
|
|
3466 |
response['source'] = SOURCE_MAP.get(master['source_id'])
|
|
|
3467 |
response['product_name'] = master['product_name']
|
| 19880 |
naman |
3468 |
return response
|
|
|
3469 |
|
|
|
3470 |
def itemCashbackAdd(item_skuId,cb,cb_description,cb_type,cb_status):
|
|
|
3471 |
itemcashbackcon = get_mongo_connection().Catalog.ItemCashBack
|
|
|
3472 |
response = list(itemcashbackcon.find({'sku':item_skuId}))
|
|
|
3473 |
|
|
|
3474 |
if len(response) == 0:
|
|
|
3475 |
itemcashbackcon.insert({'sku':item_skuId,'cash_back_description':cb_description,'cash_back':cb,'cash_back_type':cb_type,'cash_back_status': cb_status})
|
|
|
3476 |
return True
|
|
|
3477 |
|
|
|
3478 |
|
| 19654 |
kshitij.so |
3479 |
def getHeaderLinks(category_id):
|
|
|
3480 |
result = {}
|
|
|
3481 |
if category_id == 6:
|
|
|
3482 |
rank = 1
|
|
|
3483 |
for subCat in SUB_CATEGORY_HEADER_RANKING:
|
|
|
3484 |
result[rank] = {'subCategoryId':subCat,'subCategory':SUB_CATEGORY_MAP.get(subCat)}
|
|
|
3485 |
rank = rank + 1
|
|
|
3486 |
return result.values()
|
|
|
3487 |
|
| 19896 |
kshitij.so |
3488 |
def getDealsByType(category_id, offset, limit, type):
|
|
|
3489 |
dealListMap = []
|
|
|
3490 |
if type == 'exclusive':
|
|
|
3491 |
exclusive_deals = mc.get("exclusive_deals_"+str(category_id))
|
|
|
3492 |
if exclusive_deals is None:
|
|
|
3493 |
print "Populating exclusive_deals for ",category_id
|
| 20690 |
amit.gupta |
3494 |
exclusive_deals = list(get_mongo_connection().Catalog.Deals.find({'category_id': category_id,'showDeal': 1, 'source_id': 4},{'_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)]))
|
| 19896 |
kshitij.so |
3495 |
mc.set("exclusive_deals_"+str(category_id), exclusive_deals)
|
|
|
3496 |
|
| 19902 |
kshitij.so |
3497 |
for d in exclusive_deals[offset:limit+offset]:
|
| 19896 |
kshitij.so |
3498 |
item = list(get_mongo_connection().Catalog.MasterData.find({'_id':d['_id']}))
|
|
|
3499 |
if len(item) ==0:
|
|
|
3500 |
continue
|
|
|
3501 |
try:
|
|
|
3502 |
cashBack = getCashBack(item[0]['_id'], item[0]['source_id'], item[0]['category_id'])
|
|
|
3503 |
if not cashBack or cashBack.get('cash_back_status')!=1:
|
|
|
3504 |
item[0]['cash_back_type'] = 0
|
|
|
3505 |
item[0]['cash_back'] = 0
|
|
|
3506 |
else:
|
|
|
3507 |
if cashBack.get('maxCashBack') is not None:
|
|
|
3508 |
|
|
|
3509 |
if cashBack.get('cash_back_type') ==1 and (float(cashBack.get('cash_back'))*item[0]['available_price'])/100 > cashBack.get('maxCashBack'):
|
|
|
3510 |
cashBack['cash_back_type'] = 2
|
|
|
3511 |
cashBack['cash_back'] = cashBack['maxCashBack']
|
|
|
3512 |
elif cashBack.get('cash_back_type') ==2 and cashBack.get('cash_back') > cashBack.get('maxCashBack'):
|
|
|
3513 |
cashBack['cash_back'] = cashBack['maxCashBack']
|
|
|
3514 |
|
|
|
3515 |
item[0]['cash_back_type'] = int(cashBack['cash_back_type'])
|
|
|
3516 |
item[0]['cash_back'] = cashBack['cash_back']
|
|
|
3517 |
except:
|
|
|
3518 |
print "Error in adding cashback to deals"
|
|
|
3519 |
item[0]['cash_back_type'] = 0
|
|
|
3520 |
item[0]['cash_back'] = 0
|
|
|
3521 |
try:
|
|
|
3522 |
item[0]['dp'] = d['dp']
|
|
|
3523 |
item[0]['showDp'] = d['showDp']
|
|
|
3524 |
except:
|
|
|
3525 |
item[0]['dp'] = 0.0
|
|
|
3526 |
item[0]['showDp'] = 0
|
|
|
3527 |
try:
|
|
|
3528 |
item[0]['thumbnail'] = item[0]['thumbnail'].strip()
|
|
|
3529 |
except:
|
|
|
3530 |
pass
|
|
|
3531 |
|
|
|
3532 |
try:
|
|
|
3533 |
if item[0]['showVideo']==0:
|
|
|
3534 |
item[0]['videoLink'] =""
|
|
|
3535 |
except:
|
|
|
3536 |
item[0]['videoLink'] =""
|
|
|
3537 |
try:
|
|
|
3538 |
if item[0]['quantity'] >1:
|
|
|
3539 |
ppq = float(item[0]['available_price'])/item[0]['quantity']
|
|
|
3540 |
|
|
|
3541 |
if ppq == round(ppq):
|
|
|
3542 |
item[0]['ppq'] = int(ppq)
|
|
|
3543 |
else:
|
|
|
3544 |
item[0]['ppq'] = round(ppq,2)
|
|
|
3545 |
else:
|
|
|
3546 |
item[0]['ppq'] = 0
|
|
|
3547 |
except:
|
|
|
3548 |
item[0]['ppq'] = 0
|
|
|
3549 |
try:
|
|
|
3550 |
if item[0]['source_id']==4:
|
|
|
3551 |
item_availability_info = mc.get("item_availability_"+str(item[0]['identifier']).strip())
|
|
|
3552 |
if item_availability_info is None or len(item_availability_info)==0:
|
|
|
3553 |
item[0]['availabilityInfo'] = [{}]
|
|
|
3554 |
else:
|
|
|
3555 |
item[0]['availabilityInfo'] = item_availability_info
|
|
|
3556 |
except:
|
|
|
3557 |
item[0]['availabilityInfo'] = [{}]
|
|
|
3558 |
|
|
|
3559 |
if item[0]['source_id']==4:
|
|
|
3560 |
for av_info in item[0]['availabilityInfo']:
|
|
|
3561 |
if not av_info:
|
|
|
3562 |
continue
|
|
|
3563 |
av_info['cash_back'] = item[0]['cash_back']
|
|
|
3564 |
av_info['cash_back_type'] = item[0]['cash_back_type']
|
|
|
3565 |
netPriceAfterCashBack = av_info['sellingPrice']
|
|
|
3566 |
if av_info['cash_back_type'] ==1:
|
|
|
3567 |
netPriceAfterCashBack = av_info['sellingPrice'] - math.floor(float(av_info['sellingPrice'])*av_info['cash_back']/100)
|
|
|
3568 |
elif av_info['cash_back_type'] ==2:
|
|
|
3569 |
netPriceAfterCashBack = av_info['sellingPrice'] - math.floor(av_info['cash_back'])
|
|
|
3570 |
else:
|
|
|
3571 |
pass
|
|
|
3572 |
av_info['netPriceAfterCashBack'] = netPriceAfterCashBack
|
|
|
3573 |
|
|
|
3574 |
if item[0]['cash_back_type'] ==1:
|
|
|
3575 |
item[0]['netPriceAfterCashBack'] = item[0]['available_price'] - math.floor(float(item[0]['available_price'])*item[0]['cash_back']/100)
|
|
|
3576 |
elif item[0]['cash_back_type'] ==2:
|
|
|
3577 |
item[0]['netPriceAfterCashBack'] = item[0]['available_price'] - math.floor(item[0]['cash_back'])
|
|
|
3578 |
else:
|
|
|
3579 |
item[0]['netPriceAfterCashBack'] = item[0]['available_price']
|
|
|
3580 |
dealListMap.append([item[0]])
|
|
|
3581 |
return dealListMap
|
|
|
3582 |
|
|
|
3583 |
|
|
|
3584 |
|
| 13572 |
kshitij.so |
3585 |
def main():
|
| 20696 |
amit.gupta |
3586 |
#print getAccesoryDeals(47, 6, 0, 20, None, None, None)
|
|
|
3587 |
getCashBackDetails('1204769399', 3)
|
| 17944 |
kshitij.so |
3588 |
|
| 20011 |
kshitij.so |
3589 |
|
| 13572 |
kshitij.so |
3590 |
if __name__=='__main__':
|
| 19512 |
kshitij.so |
3591 |
main()
|
|
|
3592 |
|
|
|
3593 |
|