| 18272 |
kshitij.so |
1 |
from bson import json_util
|
| 15081 |
amit.gupta |
2 |
from bson.json_util import dumps
|
| 15096 |
amit.gupta |
3 |
from datetime import datetime, timedelta
|
| 15534 |
amit.gupta |
4 |
from pyshorteners.shorteners import Shortener
|
| 13582 |
amit.gupta |
5 |
from dtr import main
|
| 15081 |
amit.gupta |
6 |
from dtr.config import PythonPropertyReader
|
| 13629 |
kshitij.so |
7 |
from dtr.storage import Mongo
|
| 15132 |
amit.gupta |
8 |
from dtr.storage.DataService import Retailers, Users, CallHistory, RetryConfig, \
|
| 15254 |
amit.gupta |
9 |
RetailerLinks, Activation_Codes, Agents, Agent_Roles, AgentLoginTimings, \
|
| 15676 |
amit.gupta |
10 |
FetchDataHistory, RetailerContacts, Orders, OnboardedRetailerChecklists,\
|
| 17467 |
manas |
11 |
RetailerAddresses, Pincodeavailability, app_offers, appmasters, user_app_cashbacks, user_app_installs,\
|
| 18350 |
manas |
12 |
Postoffices, UserCrmCallingData, CallHistoryCrm, ProductPricingInputs
|
| 15358 |
amit.gupta |
13 |
from dtr.storage.Mongo import get_mongo_connection
|
|
|
14 |
from dtr.storage.Mysql import fetchResult
|
| 19651 |
manas |
15 |
from dtr.utils import DealSheet as X_DealSheet, \
|
|
|
16 |
UserSpecificDeals, utils, ThriftUtils
|
| 18256 |
manas |
17 |
from dtr.utils.utils import getLogger,encryptMessage,decryptMessage,\
|
|
|
18 |
get_mongo_connection_dtr_data, to_java_date
|
| 15081 |
amit.gupta |
19 |
from elixir import *
|
| 15254 |
amit.gupta |
20 |
from operator import and_
|
| 16714 |
manish.sha |
21 |
from sqlalchemy.sql.expression import func, func, or_, desc, asc, case
|
| 15132 |
amit.gupta |
22 |
from urllib import urlencode
|
|
|
23 |
import contextlib
|
| 13827 |
kshitij.so |
24 |
import falcon
|
| 15081 |
amit.gupta |
25 |
import json
|
| 15358 |
amit.gupta |
26 |
import re
|
| 15254 |
amit.gupta |
27 |
import string
|
| 15081 |
amit.gupta |
28 |
import traceback
|
| 15132 |
amit.gupta |
29 |
import urllib
|
|
|
30 |
import urllib2
|
|
|
31 |
import uuid
|
| 15465 |
amit.gupta |
32 |
import gdshortener
|
| 16727 |
manish.sha |
33 |
from dtr.dao import AppOfferObj, UserAppBatchDrillDown, UserAppBatchDateDrillDown
|
| 18097 |
manas |
34 |
import base64
|
| 18272 |
kshitij.so |
35 |
from falcon.util.uri import decode
|
| 18266 |
manas |
36 |
import MySQLdb
|
| 18792 |
manas |
37 |
from shop2020.clients.CatalogClient import CatalogClient
|
| 18896 |
amit.gupta |
38 |
from pyquery import PyQuery as pq
|
| 19463 |
manas |
39 |
import time
|
| 19475 |
manas |
40 |
from dtr.main import refundToWallet
|
| 18896 |
amit.gupta |
41 |
|
| 15207 |
amit.gupta |
42 |
alphalist = list(string.uppercase)
|
|
|
43 |
alphalist.remove('O')
|
|
|
44 |
numList = ['1','2','3','4','5','6','7','8','9']
|
|
|
45 |
codesys = [alphalist, alphalist, numList, numList, numList]
|
| 15312 |
amit.gupta |
46 |
CONTACT_PRIORITY = ['sms', 'called', 'ringing']
|
| 15368 |
amit.gupta |
47 |
RETRY_MAP = {'fresh':'retry', 'followup':'fretry', 'onboarding':'oretry'}
|
| 15358 |
amit.gupta |
48 |
ASSIGN_MAP = {'retry':'assigned', 'fretry':'fassigned', 'oretry':'oassigned'}
|
| 15207 |
amit.gupta |
49 |
|
| 16882 |
amit.gupta |
50 |
sticky_agents = [17]
|
|
|
51 |
|
| 15207 |
amit.gupta |
52 |
def getNextCode(codesys, code=None):
|
|
|
53 |
if code is None:
|
|
|
54 |
code = []
|
|
|
55 |
for charcode in codesys:
|
|
|
56 |
code.append(charcode[0])
|
|
|
57 |
return string.join(code, '')
|
|
|
58 |
carry = True
|
|
|
59 |
code = list(code)
|
|
|
60 |
lastindex = len(codesys) - 1
|
|
|
61 |
while carry:
|
|
|
62 |
listChar = codesys[lastindex]
|
|
|
63 |
newIndex = (listChar.index(code[lastindex])+1)%len(listChar)
|
|
|
64 |
print newIndex
|
|
|
65 |
code[lastindex] = listChar[newIndex]
|
|
|
66 |
if newIndex != 0:
|
|
|
67 |
carry = False
|
|
|
68 |
lastindex -= 1
|
|
|
69 |
if lastindex ==-1:
|
|
|
70 |
raise BaseException("All codes are exhausted")
|
|
|
71 |
|
|
|
72 |
return string.join(code, '')
|
|
|
73 |
|
| 18397 |
manas |
74 |
|
| 15081 |
amit.gupta |
75 |
global RETAILER_DETAIL_CALL_COUNTER
|
|
|
76 |
RETAILER_DETAIL_CALL_COUNTER = 0
|
| 18329 |
manas |
77 |
global USER_DETAIL_MAP
|
| 18332 |
manas |
78 |
USER_DETAIL_MAP={}
|
| 18329 |
manas |
79 |
USER_DETAIL_MAP['accs_cart']=0
|
|
|
80 |
USER_DETAIL_MAP['accs_active']=0
|
|
|
81 |
USER_DETAIL_MAP['accs_order']=0
|
| 19442 |
manas |
82 |
USER_DETAIL_MAP['accs_cashback_scheme']=0
|
| 15168 |
amit.gupta |
83 |
lgr = getLogger('/var/log/retailer-acquisition-api.log')
|
| 15081 |
amit.gupta |
84 |
DEALER_RETRY_FACTOR = int(PythonPropertyReader.getConfig('DEALER_RETRY_FACTOR'))
|
| 16886 |
amit.gupta |
85 |
DEALER_FRESH_FACTOR = int(PythonPropertyReader.getConfig('DEALER_FRESH_FACTOR'))
|
| 18329 |
manas |
86 |
USER_CRM_DEFAULT_RETRY_FACTOR = int(PythonPropertyReader.getConfig('USER_CRM_DEFAULT_RETRY_FACTOR'))
|
|
|
87 |
USER_CRM_DEFAULT_FRESH_FACTOR = int(PythonPropertyReader.getConfig('USER_CRM_DEFAULT_FRESH_FACTOR'))
|
|
|
88 |
TOTAL = DEALER_RETRY_FACTOR + DEALER_FRESH_FACTOR
|
|
|
89 |
TOTAL_USER = USER_CRM_DEFAULT_FRESH_FACTOR + USER_CRM_DEFAULT_RETRY_FACTOR
|
| 13572 |
kshitij.so |
90 |
class CategoryDiscountInfo(object):
|
|
|
91 |
|
|
|
92 |
def on_get(self, req, resp):
|
|
|
93 |
|
| 13629 |
kshitij.so |
94 |
result = Mongo.getAllCategoryDiscount()
|
|
|
95 |
json_docs = [json.dumps(doc, default=json_util.default) for doc in result]
|
|
|
96 |
resp.body = json.dumps(json_docs, encoding='utf-8')
|
| 13572 |
kshitij.so |
97 |
|
|
|
98 |
def on_post(self, req, resp):
|
|
|
99 |
try:
|
|
|
100 |
result_json = json.loads(req.stream.read(), encoding='utf-8')
|
|
|
101 |
except ValueError:
|
|
|
102 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
103 |
'Malformed JSON',
|
|
|
104 |
'Could not decode the request body. The '
|
|
|
105 |
'JSON was incorrect.')
|
|
|
106 |
|
|
|
107 |
result = Mongo.addCategoryDiscount(result_json)
|
|
|
108 |
resp.body = json.dumps(result, encoding='utf-8')
|
| 13969 |
kshitij.so |
109 |
|
|
|
110 |
def on_put(self, req, resp, _id):
|
| 13970 |
kshitij.so |
111 |
try:
|
|
|
112 |
result_json = json.loads(req.stream.read(), encoding='utf-8')
|
|
|
113 |
except ValueError:
|
|
|
114 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
115 |
'Malformed JSON',
|
|
|
116 |
'Could not decode the request body. The '
|
|
|
117 |
'JSON was incorrect.')
|
|
|
118 |
|
|
|
119 |
result = Mongo.updateCategoryDiscount(result_json, _id)
|
|
|
120 |
resp.body = json.dumps(result, encoding='utf-8')
|
|
|
121 |
|
| 13966 |
kshitij.so |
122 |
|
| 13969 |
kshitij.so |
123 |
|
| 13572 |
kshitij.so |
124 |
class SkuSchemeDetails(object):
|
|
|
125 |
|
|
|
126 |
def on_get(self, req, resp):
|
| 13629 |
kshitij.so |
127 |
|
| 14070 |
kshitij.so |
128 |
offset = req.get_param_as_int("offset")
|
|
|
129 |
limit = req.get_param_as_int("limit")
|
|
|
130 |
|
|
|
131 |
result = Mongo.getAllSkuWiseSchemeDetails(offset, limit)
|
| 13629 |
kshitij.so |
132 |
json_docs = [json.dumps(doc, default=json_util.default) for doc in result]
|
|
|
133 |
resp.body = json.dumps(json_docs, encoding='utf-8')
|
| 13572 |
kshitij.so |
134 |
|
|
|
135 |
|
|
|
136 |
def on_post(self, req, resp):
|
|
|
137 |
|
| 14552 |
kshitij.so |
138 |
multi = req.get_param_as_int("multi")
|
|
|
139 |
|
| 13572 |
kshitij.so |
140 |
try:
|
|
|
141 |
result_json = json.loads(req.stream.read(), encoding='utf-8')
|
|
|
142 |
except ValueError:
|
|
|
143 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
144 |
'Malformed JSON',
|
|
|
145 |
'Could not decode the request body. The '
|
|
|
146 |
'JSON was incorrect.')
|
|
|
147 |
|
| 15852 |
kshitij.so |
148 |
result = Mongo.addSchemeDetailsForSku(result_json)
|
| 13572 |
kshitij.so |
149 |
resp.body = json.dumps(result, encoding='utf-8')
|
|
|
150 |
|
|
|
151 |
class SkuDiscountInfo():
|
|
|
152 |
|
|
|
153 |
def on_get(self, req, resp):
|
| 13629 |
kshitij.so |
154 |
|
| 13970 |
kshitij.so |
155 |
offset = req.get_param_as_int("offset")
|
|
|
156 |
limit = req.get_param_as_int("limit")
|
|
|
157 |
result = Mongo.getallSkuDiscountInfo(offset,limit)
|
| 13629 |
kshitij.so |
158 |
json_docs = [json.dumps(doc, default=json_util.default) for doc in result]
|
|
|
159 |
resp.body = json.dumps(json_docs, encoding='utf-8')
|
| 13572 |
kshitij.so |
160 |
|
|
|
161 |
|
|
|
162 |
def on_post(self, req, resp):
|
|
|
163 |
|
| 14552 |
kshitij.so |
164 |
multi = req.get_param_as_int("multi")
|
|
|
165 |
|
| 13572 |
kshitij.so |
166 |
try:
|
|
|
167 |
result_json = json.loads(req.stream.read(), encoding='utf-8')
|
|
|
168 |
except ValueError:
|
|
|
169 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
170 |
'Malformed JSON',
|
|
|
171 |
'Could not decode the request body. The '
|
|
|
172 |
'JSON was incorrect.')
|
|
|
173 |
|
| 15852 |
kshitij.so |
174 |
result = Mongo.addSkuDiscountInfo(result_json)
|
| 13572 |
kshitij.so |
175 |
resp.body = json.dumps(result, encoding='utf-8')
|
| 13970 |
kshitij.so |
176 |
|
|
|
177 |
def on_put(self, req, resp, _id):
|
|
|
178 |
try:
|
|
|
179 |
result_json = json.loads(req.stream.read(), encoding='utf-8')
|
|
|
180 |
except ValueError:
|
|
|
181 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
182 |
'Malformed JSON',
|
|
|
183 |
'Could not decode the request body. The '
|
|
|
184 |
'JSON was incorrect.')
|
|
|
185 |
|
|
|
186 |
result = Mongo.updateSkuDiscount(result_json, _id)
|
|
|
187 |
resp.body = json.dumps(result, encoding='utf-8')
|
| 13572 |
kshitij.so |
188 |
|
|
|
189 |
class ExceptionalNlc():
|
|
|
190 |
|
|
|
191 |
def on_get(self, req, resp):
|
| 13629 |
kshitij.so |
192 |
|
| 13970 |
kshitij.so |
193 |
offset = req.get_param_as_int("offset")
|
|
|
194 |
limit = req.get_param_as_int("limit")
|
|
|
195 |
|
|
|
196 |
result = Mongo.getAllExceptionlNlcItems(offset, limit)
|
| 13629 |
kshitij.so |
197 |
json_docs = [json.dumps(doc, default=json_util.default) for doc in result]
|
|
|
198 |
resp.body = json.dumps(json_docs, encoding='utf-8')
|
| 13572 |
kshitij.so |
199 |
|
|
|
200 |
def on_post(self, req, resp):
|
|
|
201 |
|
| 14552 |
kshitij.so |
202 |
multi = req.get_param_as_int("multi")
|
|
|
203 |
|
| 13572 |
kshitij.so |
204 |
try:
|
|
|
205 |
result_json = json.loads(req.stream.read(), encoding='utf-8')
|
|
|
206 |
except ValueError:
|
|
|
207 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
208 |
'Malformed JSON',
|
|
|
209 |
'Could not decode the request body. The '
|
|
|
210 |
'JSON was incorrect.')
|
|
|
211 |
|
| 15852 |
kshitij.so |
212 |
result = Mongo.addExceptionalNlc(result_json)
|
| 13572 |
kshitij.so |
213 |
resp.body = json.dumps(result, encoding='utf-8')
|
| 13970 |
kshitij.so |
214 |
|
|
|
215 |
def on_put(self, req, resp, _id):
|
|
|
216 |
try:
|
|
|
217 |
result_json = json.loads(req.stream.read(), encoding='utf-8')
|
|
|
218 |
except ValueError:
|
|
|
219 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
220 |
'Malformed JSON',
|
|
|
221 |
'Could not decode the request body. The '
|
|
|
222 |
'JSON was incorrect.')
|
|
|
223 |
|
|
|
224 |
result = Mongo.updateExceptionalNlc(result_json, _id)
|
|
|
225 |
resp.body = json.dumps(result, encoding='utf-8')
|
| 13572 |
kshitij.so |
226 |
|
| 13772 |
kshitij.so |
227 |
class Deals():
|
| 13779 |
kshitij.so |
228 |
def on_get(self,req, resp, userId):
|
|
|
229 |
categoryId = req.get_param_as_int("categoryId")
|
|
|
230 |
offset = req.get_param_as_int("offset")
|
|
|
231 |
limit = req.get_param_as_int("limit")
|
| 13798 |
kshitij.so |
232 |
sort = req.get_param("sort")
|
| 13802 |
kshitij.so |
233 |
direction = req.get_param_as_int("direction")
|
| 14853 |
kshitij.so |
234 |
filterData = req.get_param('filterData')
|
| 19558 |
kshitij.so |
235 |
if categoryId!=6:
|
|
|
236 |
result = Mongo.getNewDeals(int(userId), categoryId, offset, limit, sort, direction, filterData)
|
|
|
237 |
else:
|
|
|
238 |
result = Mongo.getAccesoryDeals(int(userId), categoryId, offset, limit, sort, direction, filterData)
|
| 16078 |
kshitij.so |
239 |
resp.body = dumps(result)
|
| 19440 |
kshitij.so |
240 |
|
| 13790 |
kshitij.so |
241 |
class MasterData():
|
|
|
242 |
def on_get(self,req, resp, skuId):
|
| 16223 |
kshitij.so |
243 |
showDp = req.get_param_as_int("showDp")
|
| 16221 |
kshitij.so |
244 |
result = Mongo.getItem(skuId, showDp)
|
| 13798 |
kshitij.so |
245 |
try:
|
|
|
246 |
json_docs = [json.dumps(doc, default=json_util.default) for doc in result]
|
| 13966 |
kshitij.so |
247 |
resp.body = json.dumps(json_docs, encoding='utf-8')
|
| 13798 |
kshitij.so |
248 |
except:
|
|
|
249 |
json_docs = [json.dumps(doc, default=json_util.default) for doc in result]
|
| 13966 |
kshitij.so |
250 |
resp.body = json.dumps(json_docs, encoding='utf-8')
|
| 13790 |
kshitij.so |
251 |
|
| 14586 |
kshitij.so |
252 |
def on_post(self,req, resp):
|
|
|
253 |
|
|
|
254 |
addNew = req.get_param_as_int("addNew")
|
|
|
255 |
update = req.get_param_as_int("update")
|
|
|
256 |
addToExisting = req.get_param_as_int("addToExisting")
|
|
|
257 |
multi = req.get_param_as_int("multi")
|
|
|
258 |
|
| 14589 |
kshitij.so |
259 |
try:
|
| 14592 |
kshitij.so |
260 |
result_json = json.loads(req.stream.read(), encoding='utf-8')
|
|
|
261 |
except ValueError:
|
|
|
262 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
263 |
'Malformed JSON',
|
|
|
264 |
'Could not decode the request body. The '
|
|
|
265 |
'JSON was incorrect.')
|
|
|
266 |
|
|
|
267 |
if addNew == 1:
|
|
|
268 |
result = Mongo.addNewItem(result_json)
|
|
|
269 |
elif update == 1:
|
|
|
270 |
result = Mongo.updateMaster(result_json, multi)
|
|
|
271 |
elif addToExisting == 1:
|
|
|
272 |
result = Mongo.addItemToExistingBundle(result_json)
|
|
|
273 |
else:
|
|
|
274 |
raise
|
|
|
275 |
resp.body = dumps(result)
|
| 13865 |
kshitij.so |
276 |
|
| 13834 |
kshitij.so |
277 |
class CashBack():
|
|
|
278 |
def on_get(self,req, resp):
|
|
|
279 |
identifier = req.get_param("identifier")
|
|
|
280 |
source_id = req.get_param_as_int("source_id")
|
|
|
281 |
try:
|
| 13838 |
kshitij.so |
282 |
result = Mongo.getCashBackDetails(identifier, source_id)
|
| 13837 |
kshitij.so |
283 |
json_docs = json.dumps(result, default=json_util.default)
|
| 13964 |
kshitij.so |
284 |
resp.body = json_docs
|
| 13834 |
kshitij.so |
285 |
except:
|
| 13837 |
kshitij.so |
286 |
json_docs = json.dumps({}, default=json_util.default)
|
| 13963 |
kshitij.so |
287 |
resp.body = json_docs
|
| 13892 |
kshitij.so |
288 |
|
| 14398 |
amit.gupta |
289 |
class ImgSrc():
|
|
|
290 |
def on_get(self,req, resp):
|
|
|
291 |
identifier = req.get_param("identifier")
|
|
|
292 |
source_id = req.get_param_as_int("source_id")
|
|
|
293 |
try:
|
|
|
294 |
result = Mongo.getImgSrc(identifier, source_id)
|
|
|
295 |
json_docs = json.dumps(result, default=json_util.default)
|
|
|
296 |
resp.body = json_docs
|
|
|
297 |
except:
|
|
|
298 |
json_docs = json.dumps({}, default=json_util.default)
|
|
|
299 |
resp.body = json_docs
|
|
|
300 |
|
| 13892 |
kshitij.so |
301 |
class DealSheet():
|
|
|
302 |
def on_get(self,req, resp):
|
| 13895 |
kshitij.so |
303 |
X_DealSheet.sendMail()
|
| 13897 |
kshitij.so |
304 |
json_docs = json.dumps({'True':'Sheet generated, mail sent.'}, default=json_util.default)
|
| 13966 |
kshitij.so |
305 |
resp.body = json.dumps(json_docs, encoding='utf-8')
|
| 13892 |
kshitij.so |
306 |
|
| 13970 |
kshitij.so |
307 |
class DealerPrice():
|
|
|
308 |
|
|
|
309 |
def on_get(self, req, resp):
|
|
|
310 |
|
|
|
311 |
offset = req.get_param_as_int("offset")
|
|
|
312 |
limit = req.get_param_as_int("limit")
|
|
|
313 |
result = Mongo.getAllDealerPrices(offset,limit)
|
|
|
314 |
json_docs = [json.dumps(doc, default=json_util.default) for doc in result]
|
|
|
315 |
resp.body = json.dumps(json_docs, encoding='utf-8')
|
|
|
316 |
|
|
|
317 |
def on_post(self, req, resp):
|
|
|
318 |
|
| 14552 |
kshitij.so |
319 |
multi = req.get_param_as_int("multi")
|
|
|
320 |
|
| 13970 |
kshitij.so |
321 |
try:
|
|
|
322 |
result_json = json.loads(req.stream.read(), encoding='utf-8')
|
|
|
323 |
except ValueError:
|
|
|
324 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
325 |
'Malformed JSON',
|
|
|
326 |
'Could not decode the request body. The '
|
|
|
327 |
'JSON was incorrect.')
|
|
|
328 |
|
| 15852 |
kshitij.so |
329 |
result = Mongo.addSkuDealerPrice(result_json)
|
| 13970 |
kshitij.so |
330 |
resp.body = json.dumps(result, encoding='utf-8')
|
|
|
331 |
|
|
|
332 |
def on_put(self, req, resp, _id):
|
|
|
333 |
try:
|
|
|
334 |
result_json = json.loads(req.stream.read(), encoding='utf-8')
|
|
|
335 |
except ValueError:
|
|
|
336 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
337 |
'Malformed JSON',
|
|
|
338 |
'Could not decode the request body. The '
|
|
|
339 |
'JSON was incorrect.')
|
|
|
340 |
|
|
|
341 |
result = Mongo.updateSkuDealerPrice(result_json, _id)
|
|
|
342 |
resp.body = json.dumps(result, encoding='utf-8')
|
|
|
343 |
|
|
|
344 |
|
| 14041 |
kshitij.so |
345 |
class ResetCache():
|
|
|
346 |
|
|
|
347 |
def on_get(self,req, resp, userId):
|
| 14044 |
kshitij.so |
348 |
result = Mongo.resetCache(userId)
|
| 14046 |
kshitij.so |
349 |
resp.body = json.dumps(result, encoding='utf-8')
|
|
|
350 |
|
|
|
351 |
class UserDeals():
|
|
|
352 |
def on_get(self,req,resp,userId):
|
|
|
353 |
UserSpecificDeals.generateSheet(userId)
|
|
|
354 |
json_docs = json.dumps({'True':'Sheet generated, mail sent.'}, default=json_util.default)
|
|
|
355 |
resp.body = json.dumps(json_docs, encoding='utf-8')
|
| 14075 |
kshitij.so |
356 |
|
|
|
357 |
class CommonUpdate():
|
|
|
358 |
|
|
|
359 |
def on_post(self,req,resp):
|
| 14575 |
kshitij.so |
360 |
|
|
|
361 |
multi = req.get_param_as_int("multi")
|
|
|
362 |
|
| 14075 |
kshitij.so |
363 |
try:
|
|
|
364 |
result_json = json.loads(req.stream.read(), encoding='utf-8')
|
|
|
365 |
except ValueError:
|
|
|
366 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
367 |
'Malformed JSON',
|
|
|
368 |
'Could not decode the request body. The '
|
|
|
369 |
'JSON was incorrect.')
|
|
|
370 |
|
| 15852 |
kshitij.so |
371 |
result = Mongo.updateCollection(result_json)
|
| 14075 |
kshitij.so |
372 |
resp.body = json.dumps(result, encoding='utf-8')
|
| 14106 |
kshitij.so |
373 |
resp.content_type = "application/json; charset=utf-8"
|
| 14481 |
kshitij.so |
374 |
|
|
|
375 |
class NegativeDeals():
|
|
|
376 |
|
|
|
377 |
def on_get(self, req, resp):
|
|
|
378 |
|
|
|
379 |
offset = req.get_param_as_int("offset")
|
|
|
380 |
limit = req.get_param_as_int("limit")
|
|
|
381 |
|
|
|
382 |
result = Mongo.getAllNegativeDeals(offset, limit)
|
| 14483 |
kshitij.so |
383 |
resp.body = dumps(result)
|
| 14481 |
kshitij.so |
384 |
|
|
|
385 |
|
|
|
386 |
def on_post(self, req, resp):
|
|
|
387 |
|
| 14552 |
kshitij.so |
388 |
multi = req.get_param_as_int("multi")
|
|
|
389 |
|
| 14481 |
kshitij.so |
390 |
try:
|
|
|
391 |
result_json = json.loads(req.stream.read(), encoding='utf-8')
|
|
|
392 |
except ValueError:
|
|
|
393 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
394 |
'Malformed JSON',
|
|
|
395 |
'Could not decode the request body. The '
|
|
|
396 |
'JSON was incorrect.')
|
|
|
397 |
|
| 14552 |
kshitij.so |
398 |
result = Mongo.addNegativeDeals(result_json, multi)
|
| 14481 |
kshitij.so |
399 |
resp.body = json.dumps(result, encoding='utf-8')
|
|
|
400 |
|
|
|
401 |
class ManualDeals():
|
|
|
402 |
|
|
|
403 |
def on_get(self, req, resp):
|
|
|
404 |
|
|
|
405 |
offset = req.get_param_as_int("offset")
|
|
|
406 |
limit = req.get_param_as_int("limit")
|
|
|
407 |
|
|
|
408 |
result = Mongo.getAllManualDeals(offset, limit)
|
| 14483 |
kshitij.so |
409 |
resp.body = dumps(result)
|
| 14481 |
kshitij.so |
410 |
|
|
|
411 |
|
|
|
412 |
def on_post(self, req, resp):
|
|
|
413 |
|
| 14552 |
kshitij.so |
414 |
multi = req.get_param_as_int("multi")
|
|
|
415 |
|
| 14481 |
kshitij.so |
416 |
try:
|
|
|
417 |
result_json = json.loads(req.stream.read(), encoding='utf-8')
|
|
|
418 |
except ValueError:
|
|
|
419 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
420 |
'Malformed JSON',
|
|
|
421 |
'Could not decode the request body. The '
|
|
|
422 |
'JSON was incorrect.')
|
|
|
423 |
|
| 14552 |
kshitij.so |
424 |
result = Mongo.addManualDeal(result_json, multi)
|
| 14481 |
kshitij.so |
425 |
resp.body = json.dumps(result, encoding='utf-8')
|
|
|
426 |
|
|
|
427 |
class CommonDelete():
|
| 14482 |
kshitij.so |
428 |
|
| 14481 |
kshitij.so |
429 |
def on_post(self,req,resp):
|
|
|
430 |
try:
|
|
|
431 |
result_json = json.loads(req.stream.read(), encoding='utf-8')
|
|
|
432 |
except ValueError:
|
|
|
433 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
434 |
'Malformed JSON',
|
|
|
435 |
'Could not decode the request body. The '
|
|
|
436 |
'JSON was incorrect.')
|
|
|
437 |
|
|
|
438 |
result = Mongo.deleteDocument(result_json)
|
|
|
439 |
resp.body = json.dumps(result, encoding='utf-8')
|
|
|
440 |
resp.content_type = "application/json; charset=utf-8"
|
| 14482 |
kshitij.so |
441 |
|
|
|
442 |
class SearchProduct():
|
|
|
443 |
|
|
|
444 |
def on_get(self,req,resp):
|
|
|
445 |
offset = req.get_param_as_int("offset")
|
|
|
446 |
limit = req.get_param_as_int("limit")
|
|
|
447 |
search_term = req.get_param("search")
|
|
|
448 |
|
|
|
449 |
result = Mongo.searchMaster(offset, limit, search_term)
|
| 14483 |
kshitij.so |
450 |
resp.body = dumps(result)
|
| 14482 |
kshitij.so |
451 |
|
|
|
452 |
|
| 14495 |
kshitij.so |
453 |
class FeaturedDeals():
|
| 14482 |
kshitij.so |
454 |
|
| 14495 |
kshitij.so |
455 |
def on_get(self, req, resp):
|
|
|
456 |
|
|
|
457 |
offset = req.get_param_as_int("offset")
|
|
|
458 |
limit = req.get_param_as_int("limit")
|
|
|
459 |
|
|
|
460 |
result = Mongo.getAllFeaturedDeals(offset, limit)
|
|
|
461 |
resp.body = dumps(result)
|
|
|
462 |
|
|
|
463 |
|
|
|
464 |
def on_post(self, req, resp):
|
|
|
465 |
|
| 14552 |
kshitij.so |
466 |
multi = req.get_param_as_int("multi")
|
|
|
467 |
|
| 14495 |
kshitij.so |
468 |
try:
|
|
|
469 |
result_json = json.loads(req.stream.read(), encoding='utf-8')
|
|
|
470 |
except ValueError:
|
|
|
471 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
472 |
'Malformed JSON',
|
|
|
473 |
'Could not decode the request body. The '
|
|
|
474 |
'JSON was incorrect.')
|
|
|
475 |
|
| 14552 |
kshitij.so |
476 |
result = Mongo.addFeaturedDeal(result_json, multi)
|
| 14495 |
kshitij.so |
477 |
resp.body = json.dumps(result, encoding='utf-8')
|
|
|
478 |
|
| 14497 |
kshitij.so |
479 |
|
|
|
480 |
class CommonSearch():
|
| 14495 |
kshitij.so |
481 |
|
| 14497 |
kshitij.so |
482 |
def on_get(self,req,resp):
|
|
|
483 |
class_name = req.get_param("class")
|
|
|
484 |
sku = req.get_param_as_int("sku")
|
|
|
485 |
skuBundleId = req.get_param_as_int("skuBundleId")
|
| 14499 |
kshitij.so |
486 |
|
|
|
487 |
result = Mongo.searchCollection(class_name, sku, skuBundleId)
|
| 14497 |
kshitij.so |
488 |
resp.body = dumps(result)
|
| 14619 |
kshitij.so |
489 |
|
|
|
490 |
class CricScore():
|
|
|
491 |
|
|
|
492 |
def on_get(self,req,resp):
|
|
|
493 |
|
|
|
494 |
result = Mongo.getLiveCricScore()
|
| 14853 |
kshitij.so |
495 |
resp.body = dumps(result)
|
|
|
496 |
|
|
|
497 |
class Notification():
|
|
|
498 |
|
|
|
499 |
def on_post(self, req, resp):
|
|
|
500 |
|
|
|
501 |
try:
|
|
|
502 |
result_json = json.loads(req.stream.read(), encoding='utf-8')
|
|
|
503 |
except ValueError:
|
|
|
504 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
505 |
'Malformed JSON',
|
|
|
506 |
'Could not decode the request body. The '
|
|
|
507 |
'JSON was incorrect.')
|
|
|
508 |
|
|
|
509 |
result = Mongo.addBundleToNotification(result_json)
|
|
|
510 |
resp.body = json.dumps(result, encoding='utf-8')
|
|
|
511 |
|
|
|
512 |
def on_get(self, req, resp):
|
|
|
513 |
|
|
|
514 |
offset = req.get_param_as_int("offset")
|
|
|
515 |
limit = req.get_param_as_int("limit")
|
|
|
516 |
|
|
|
517 |
result = Mongo.getAllNotifications(offset, limit)
|
|
|
518 |
resp.body = dumps(result)
|
|
|
519 |
|
| 14998 |
kshitij.so |
520 |
class DealBrands():
|
| 14853 |
kshitij.so |
521 |
|
| 14998 |
kshitij.so |
522 |
def on_get(self, req, resp):
|
|
|
523 |
|
|
|
524 |
category_id = req.get_param_as_int("category_id")
|
|
|
525 |
result = Mongo.getBrandsForFilter(category_id)
|
| 14999 |
kshitij.so |
526 |
resp.body = dumps(result)
|
| 15161 |
kshitij.so |
527 |
|
|
|
528 |
class DealRank():
|
| 14998 |
kshitij.so |
529 |
|
| 15161 |
kshitij.so |
530 |
def on_get(self, req, resp):
|
|
|
531 |
identifier = req.get_param("identifier")
|
|
|
532 |
source_id = req.get_param_as_int("source_id")
|
|
|
533 |
user_id = req.get_param_as_int("user_id")
|
|
|
534 |
result = Mongo.getDealRank(identifier, source_id, user_id)
|
|
|
535 |
json_docs = json.dumps(result, default=json_util.default)
|
|
|
536 |
resp.body = json_docs
|
|
|
537 |
|
|
|
538 |
|
| 16560 |
amit.gupta |
539 |
class OrderedOffers():
|
|
|
540 |
def on_get(self, req, resp, storeId, storeSku):
|
|
|
541 |
storeId = int(storeId)
|
| 16563 |
amit.gupta |
542 |
result = Mongo.getBundleBySourceSku(storeId, storeSku)
|
|
|
543 |
json_docs = json.dumps(result, default=json_util.default)
|
|
|
544 |
resp.body = json_docs
|
|
|
545 |
|
| 15081 |
amit.gupta |
546 |
class RetailerDetail():
|
|
|
547 |
global RETAILER_DETAIL_CALL_COUNTER
|
| 15105 |
amit.gupta |
548 |
def getRetryRetailer(self,failback=True):
|
| 15358 |
amit.gupta |
549 |
status = RETRY_MAP.get(self.callType)
|
| 17089 |
amit.gupta |
550 |
retailer = session.query(Retailers).filter_by(status=status).filter(Retailers.next_call_time<=datetime.now()).filter(or_(Retailers.agent_id==self.agentId, Retailers.agent_id==None)).order_by(Retailers.agent_id.desc(),Retailers.call_priority).order_by(Retailers.next_call_time).with_lockmode("update").first()
|
| 17029 |
amit.gupta |
551 |
|
| 15239 |
amit.gupta |
552 |
if retailer is not None:
|
|
|
553 |
lgr.info( "getRetryRetailer " + str(retailer.id))
|
|
|
554 |
else:
|
|
|
555 |
if failback:
|
|
|
556 |
retailer = self.getNewRetailer(False)
|
|
|
557 |
return retailer
|
| 16371 |
amit.gupta |
558 |
else:
|
|
|
559 |
#No further calls for now
|
|
|
560 |
return None
|
| 15358 |
amit.gupta |
561 |
retailer.status = ASSIGN_MAP.get(status)
|
| 16371 |
amit.gupta |
562 |
retailer.next_call_time = None
|
| 15239 |
amit.gupta |
563 |
lgr.info( "getRetryRetailer " + str(retailer.id))
|
| 15081 |
amit.gupta |
564 |
return retailer
|
|
|
565 |
|
| 15662 |
amit.gupta |
566 |
def getNotActiveRetailer(self):
|
|
|
567 |
try:
|
| 15716 |
amit.gupta |
568 |
user = session.query(Users).filter_by(activated=0).filter_by(status=1).filter(Users.mobile_number != None).filter(~Users.mobile_number.like("0%")).filter(Users.created>datetime(2015,06,29)).order_by(Users.created.desc()).with_lockmode("update").first()
|
| 15662 |
amit.gupta |
569 |
if user is None:
|
|
|
570 |
return None
|
|
|
571 |
else:
|
|
|
572 |
retailerContact = session.query(RetailerContacts).filter_by(mobile_number=user.mobile_number).first()
|
|
|
573 |
if retailerContact is not None:
|
|
|
574 |
retailer = session.query(Retailers).filter_by(id=retailerContact.retailer_id).first()
|
|
|
575 |
else:
|
|
|
576 |
retailer = session.query(Retailers).filter_by(contact1=user.mobile_number).first()
|
|
|
577 |
if retailer is None:
|
|
|
578 |
retailer = session.query(Retailers).filter_by(contact2=user.mobile_number).first()
|
|
|
579 |
if retailer is None:
|
|
|
580 |
retailer = Retailers()
|
|
|
581 |
retailer.contact1 = user.mobile_number
|
|
|
582 |
retailer.status = 'assigned'
|
| 15672 |
amit.gupta |
583 |
retailer.retry_count = 0
|
| 15673 |
amit.gupta |
584 |
retailer.invalid_retry_count = 0
|
| 15699 |
amit.gupta |
585 |
retailer.is_elavated=1
|
| 15662 |
amit.gupta |
586 |
user.status = 2
|
|
|
587 |
session.commit()
|
|
|
588 |
print "retailer id", retailer.id
|
|
|
589 |
retailer.contact = user.mobile_number
|
|
|
590 |
return retailer
|
|
|
591 |
finally:
|
|
|
592 |
session.close()
|
|
|
593 |
|
| 15081 |
amit.gupta |
594 |
def getNewRetailer(self,failback=True):
|
| 15663 |
amit.gupta |
595 |
if self.callType == 'fresh':
|
|
|
596 |
retailer = self.getNotActiveRetailer()
|
|
|
597 |
if retailer is not None:
|
|
|
598 |
return retailer
|
| 15081 |
amit.gupta |
599 |
retry = True
|
|
|
600 |
retailer = None
|
|
|
601 |
try:
|
|
|
602 |
while(retry):
|
| 15168 |
amit.gupta |
603 |
lgr.info( "Calltype " + self.callType)
|
| 15081 |
amit.gupta |
604 |
status=self.callType
|
| 15545 |
amit.gupta |
605 |
query = session.query(Retailers).filter(Retailers.status==status).filter(or_(Retailers.agent_id==self.agentId, Retailers.agent_id==None))
|
| 15081 |
amit.gupta |
606 |
if status=='fresh':
|
| 19598 |
amit.gupta |
607 |
query = query.filter_by(is_or=False, is_std=False).filter(Retailers.cod_limit > 19999).order_by(Retailers.is_elavated.desc(), Retailers.agent_id.desc())
|
| 15358 |
amit.gupta |
608 |
elif status=='followup':
|
| 15546 |
amit.gupta |
609 |
query = query.filter(Retailers.next_call_time<=datetime.now()).order_by(Retailers.agent_id.desc(),Retailers.next_call_time)
|
| 15162 |
amit.gupta |
610 |
else:
|
| 15546 |
amit.gupta |
611 |
query = query.filter(Retailers.modified<=datetime.now()).order_by(Retailers.agent_id.desc(), Retailers.modified)
|
| 15358 |
amit.gupta |
612 |
|
| 15081 |
amit.gupta |
613 |
retailer = query.with_lockmode("update").first()
|
|
|
614 |
if retailer is not None:
|
| 15168 |
amit.gupta |
615 |
lgr.info( "retailer " +str(retailer.id))
|
| 15081 |
amit.gupta |
616 |
if status=="fresh":
|
|
|
617 |
userquery = session.query(Users)
|
|
|
618 |
if retailer.contact2 is not None:
|
|
|
619 |
userquery = userquery.filter(Users.mobile_number.in_([retailer.contact1,retailer.contact2]))
|
|
|
620 |
else:
|
|
|
621 |
userquery = userquery.filter_by(mobile_number=retailer.contact1)
|
|
|
622 |
user = userquery.first()
|
|
|
623 |
if user is not None:
|
|
|
624 |
retailer.status = 'alreadyuser'
|
| 15168 |
amit.gupta |
625 |
lgr.info( "retailer.status " + retailer.status)
|
| 15081 |
amit.gupta |
626 |
session.commit()
|
|
|
627 |
continue
|
|
|
628 |
retailer.status = 'assigned'
|
| 15358 |
amit.gupta |
629 |
elif status=='followup':
|
| 15276 |
amit.gupta |
630 |
if isActivated(retailer.id):
|
|
|
631 |
print "Retailer Already %d activated and marked onboarded"%(retailer.id)
|
|
|
632 |
continue
|
| 15081 |
amit.gupta |
633 |
retailer.status = 'fassigned'
|
| 15358 |
amit.gupta |
634 |
else:
|
|
|
635 |
retailer.status = 'oassigned'
|
| 15081 |
amit.gupta |
636 |
retailer.retry_count = 0
|
| 15123 |
amit.gupta |
637 |
retailer.invalid_retry_count = 0
|
| 15168 |
amit.gupta |
638 |
lgr.info( "Found Retailer " + str(retailer.id) + " with status " + status + " assigned to " + str(self.agentId))
|
| 15081 |
amit.gupta |
639 |
|
|
|
640 |
else:
|
| 15168 |
amit.gupta |
641 |
lgr.info( "No fresh/followup retailers found")
|
| 15081 |
amit.gupta |
642 |
if failback:
|
|
|
643 |
retailer = self.getRetryRetailer(False)
|
| 15104 |
amit.gupta |
644 |
return retailer
|
| 15148 |
amit.gupta |
645 |
retry=False
|
| 15081 |
amit.gupta |
646 |
except:
|
|
|
647 |
print traceback.print_exc()
|
|
|
648 |
return retailer
|
|
|
649 |
|
| 15132 |
amit.gupta |
650 |
def on_get(self, req, resp, agentId, callType=None, retailerId=None):
|
| 16927 |
amit.gupta |
651 |
try:
|
|
|
652 |
global RETAILER_DETAIL_CALL_COUNTER
|
|
|
653 |
RETAILER_DETAIL_CALL_COUNTER += 1
|
|
|
654 |
lgr.info( "RETAILER_DETAIL_CALL_COUNTER " + str(RETAILER_DETAIL_CALL_COUNTER))
|
|
|
655 |
self.agentId = int(agentId)
|
|
|
656 |
self.callType = callType
|
|
|
657 |
if retailerId is not None:
|
|
|
658 |
self.retailerId = int(retailerId)
|
|
|
659 |
retailerLink = session.query(RetailerLinks).filter_by(retailer_id=self.retailerId).first()
|
|
|
660 |
if retailerLink is not None:
|
|
|
661 |
code = retailerLink.code
|
|
|
662 |
else:
|
|
|
663 |
code = self.getCode()
|
|
|
664 |
retailerLink = RetailerLinks()
|
|
|
665 |
retailerLink.code = code
|
|
|
666 |
retailerLink.agent_id = self.agentId
|
|
|
667 |
retailerLink.retailer_id = self.retailerId
|
|
|
668 |
|
|
|
669 |
activationCode=Activation_Codes()
|
|
|
670 |
activationCode.code = code
|
|
|
671 |
session.commit()
|
|
|
672 |
session.close()
|
|
|
673 |
resp.body = json.dumps({"result":{"code":code,"link":make_tiny(code)}}, encoding='utf-8')
|
|
|
674 |
return
|
|
|
675 |
retryFlag = False
|
|
|
676 |
if RETAILER_DETAIL_CALL_COUNTER % TOTAL >= DEALER_FRESH_FACTOR:
|
|
|
677 |
retryFlag=True
|
|
|
678 |
try:
|
|
|
679 |
if retryFlag:
|
|
|
680 |
retailer = self.getRetryRetailer()
|
|
|
681 |
else:
|
|
|
682 |
retailer = self.getNewRetailer()
|
|
|
683 |
if retailer is None:
|
|
|
684 |
resp.body = "{}"
|
|
|
685 |
return
|
|
|
686 |
fetchInfo = FetchDataHistory()
|
|
|
687 |
fetchInfo.agent_id = self.agentId
|
|
|
688 |
fetchInfo.call_type = self.callType
|
|
|
689 |
agent = session.query(Agents).filter_by(id=self.agentId).first()
|
|
|
690 |
last_disposition = session.query(CallHistory).filter_by(agent_id=self.agentId).order_by(CallHistory.id.desc()).first()
|
|
|
691 |
if last_disposition is None or last_disposition.created < agent.last_login:
|
|
|
692 |
fetchInfo.last_action = 'login'
|
|
|
693 |
fetchInfo.last_action_time = agent.last_login
|
|
|
694 |
else:
|
|
|
695 |
fetchInfo.last_action = 'disposition'
|
|
|
696 |
fetchInfo.last_action_time = last_disposition.created
|
|
|
697 |
fetchInfo.retailer_id = retailer.id
|
|
|
698 |
session.commit()
|
| 15135 |
amit.gupta |
699 |
|
| 16927 |
amit.gupta |
700 |
otherContacts = [r for r, in session.query(RetailerContacts.mobile_number).filter_by(retailer_id=retailer.id).order_by(RetailerContacts.contact_type).all()]
|
|
|
701 |
resp.body = json.dumps(todict(getRetailerObj(retailer, otherContacts, self.callType)), encoding='utf-8')
|
|
|
702 |
|
|
|
703 |
return
|
|
|
704 |
|
|
|
705 |
finally:
|
|
|
706 |
session.close()
|
|
|
707 |
|
| 15343 |
amit.gupta |
708 |
if retailer is None:
|
|
|
709 |
resp.body = "{}"
|
| 15239 |
amit.gupta |
710 |
else:
|
| 16927 |
amit.gupta |
711 |
print "It should never come here"
|
|
|
712 |
resp.body = json.dumps(todict(getRetailerObj(retailer)), encoding='utf-8')
|
| 15239 |
amit.gupta |
713 |
finally:
|
|
|
714 |
session.close()
|
| 15081 |
amit.gupta |
715 |
|
|
|
716 |
def on_post(self, req, resp, agentId, callType):
|
| 15112 |
amit.gupta |
717 |
returned = False
|
| 15081 |
amit.gupta |
718 |
self.agentId = int(agentId)
|
|
|
719 |
self.callType = callType
|
|
|
720 |
jsonReq = json.loads(req.stream.read(), encoding='utf-8')
|
| 15169 |
amit.gupta |
721 |
lgr.info( "Request ----\n" + str(jsonReq))
|
| 15091 |
amit.gupta |
722 |
self.jsonReq = jsonReq
|
|
|
723 |
invalidNumber = self.invalidNumber
|
|
|
724 |
callLater = self.callLater
|
| 15096 |
amit.gupta |
725 |
alreadyUser = self.alReadyUser
|
| 15091 |
amit.gupta |
726 |
verifiedLinkSent = self.verifiedLinkSent
|
| 15368 |
amit.gupta |
727 |
onboarded = self.onboarded
|
| 15278 |
amit.gupta |
728 |
self.address = jsonReq.get('address')
|
| 15096 |
amit.gupta |
729 |
self.retailerId = int(jsonReq.get('retailerid'))
|
| 15671 |
amit.gupta |
730 |
self.smsNumber = jsonReq.get('smsnumber')
|
|
|
731 |
if self.smsNumber is not None:
|
|
|
732 |
self.smsNumber = self.smsNumber.strip().lstrip("0")
|
| 15112 |
amit.gupta |
733 |
try:
|
|
|
734 |
self.retailer = session.query(Retailers).filter_by(id=self.retailerId).first()
|
| 15281 |
amit.gupta |
735 |
if self.address:
|
| 15278 |
amit.gupta |
736 |
self.retailer.address_new = self.address
|
| 15112 |
amit.gupta |
737 |
self.callDisposition = jsonReq.get('calldispositiontype')
|
|
|
738 |
self.callHistory = CallHistory()
|
|
|
739 |
self.callHistory.agent_id=self.agentId
|
|
|
740 |
self.callHistory.call_disposition = self.callDisposition
|
|
|
741 |
self.callHistory.retailer_id=self.retailerId
|
| 15115 |
amit.gupta |
742 |
self.callHistory.call_type=self.callType
|
| 15112 |
amit.gupta |
743 |
self.callHistory.duration_sec = int(jsonReq.get("callduration"))
|
|
|
744 |
self.callHistory.disposition_description = jsonReq.get('calldispositiondescritption')
|
| 15200 |
manas |
745 |
self.callHistory.disposition_comments = jsonReq.get('calldispositioncomments')
|
|
|
746 |
lgr.info(self.callHistory.disposition_comments)
|
| 15112 |
amit.gupta |
747 |
self.callHistory.call_time = datetime.strptime(jsonReq.get("calltime"), '%d/%m/%Y %H:%M:%S')
|
|
|
748 |
self.callHistory.mobile_number = jsonReq.get('number')
|
| 15145 |
amit.gupta |
749 |
self.callHistory.sms_verified = int(jsonReq.get("verified"))
|
| 15234 |
amit.gupta |
750 |
lastFetchData = session.query(FetchDataHistory).filter_by(agent_id=self.agentId).order_by(FetchDataHistory.id.desc()).first()
|
| 15368 |
amit.gupta |
751 |
if self.callDisposition == 'onboarded':
|
|
|
752 |
self.checkList = jsonReq.get('checklist')
|
|
|
753 |
|
| 15234 |
amit.gupta |
754 |
if lastFetchData is None:
|
|
|
755 |
raise
|
|
|
756 |
self.callHistory.last_fetch_time= lastFetchData.created
|
| 15112 |
amit.gupta |
757 |
|
|
|
758 |
dispositionMap = { 'call_later':callLater,
|
|
|
759 |
'ringing_no_answer':callLater,
|
|
|
760 |
'not_reachable':callLater,
|
|
|
761 |
'switch_off':callLater,
|
| 15202 |
manas |
762 |
'not_retailer':invalidNumber,
|
| 15112 |
amit.gupta |
763 |
'invalid_no':invalidNumber,
|
|
|
764 |
'wrong_no':invalidNumber,
|
|
|
765 |
'hang_up':invalidNumber,
|
|
|
766 |
'retailer_not_interested':invalidNumber,
|
| 15200 |
manas |
767 |
'recharge_retailer':invalidNumber,
|
|
|
768 |
'accessory_retailer':invalidNumber,
|
|
|
769 |
'service_center_retailer':invalidNumber,
|
| 15112 |
amit.gupta |
770 |
'alreadyuser':alreadyUser,
|
| 15368 |
amit.gupta |
771 |
'verified_link_sent':verifiedLinkSent,
|
|
|
772 |
'onboarded':onboarded
|
| 15112 |
amit.gupta |
773 |
}
|
|
|
774 |
returned = dispositionMap[jsonReq.get('calldispositiontype')]()
|
|
|
775 |
finally:
|
|
|
776 |
session.close()
|
| 15096 |
amit.gupta |
777 |
|
| 15112 |
amit.gupta |
778 |
if returned:
|
|
|
779 |
resp.body = "{\"result\":\"success\"}"
|
|
|
780 |
else:
|
|
|
781 |
resp.body = "{\"result\":\"failed\"}"
|
| 15081 |
amit.gupta |
782 |
|
| 15091 |
amit.gupta |
783 |
def invalidNumber(self,):
|
| 15108 |
manas |
784 |
#self.retailer.status = 'retry' if self.callType == 'fresh' else 'fretry'
|
|
|
785 |
if self.callDisposition == 'invalid_no':
|
|
|
786 |
self.retailer.status='failed'
|
|
|
787 |
self.callHistory.disposition_description = 'Invalid Number'
|
|
|
788 |
elif self.callDisposition == 'wrong_no':
|
| 15111 |
manas |
789 |
self.retailer.status='failed'
|
|
|
790 |
self.callHistory.disposition_description = 'Wrong Number'
|
|
|
791 |
elif self.callDisposition == 'hang_up':
|
|
|
792 |
self.retailer.status='failed'
|
|
|
793 |
self.callHistory.disposition_description = 'Hang Up'
|
|
|
794 |
elif self.callDisposition == 'retailer_not_interested':
|
|
|
795 |
self.retailer.status='failed'
|
|
|
796 |
if self.callHistory.disposition_description is None:
|
|
|
797 |
self.callHistory.disposition_description = 'NA'
|
| 15200 |
manas |
798 |
self.callHistory.disposition_description = 'Reason Retailer Not Interested ' + self.callHistory.disposition_description
|
|
|
799 |
elif self.callDisposition == 'recharge_retailer':
|
|
|
800 |
self.retailer.status='failed'
|
|
|
801 |
self.callHistory.disposition_description = 'Recharge related. Not a retailer '
|
|
|
802 |
elif self.callDisposition == 'accessory_retailer':
|
|
|
803 |
self.retailer.status='failed'
|
|
|
804 |
self.callHistory.disposition_description = 'Accessory related. Not a retailer'
|
|
|
805 |
elif self.callDisposition == 'service_center_retailer':
|
|
|
806 |
self.retailer.status='failed'
|
|
|
807 |
self.callHistory.disposition_description = 'Service Center related. Not a retailer'
|
| 15202 |
manas |
808 |
elif self.callDisposition == 'not_retailer':
|
|
|
809 |
self.retailer.status='failed'
|
|
|
810 |
self.callHistory.disposition_description = 'Not a retailer'
|
| 15108 |
manas |
811 |
session.commit()
|
|
|
812 |
return True
|
|
|
813 |
|
| 15132 |
amit.gupta |
814 |
def getCode(self,):
|
| 15207 |
amit.gupta |
815 |
newCode = None
|
|
|
816 |
lastLink = session.query(RetailerLinks).order_by(RetailerLinks.id.desc()).with_lockmode("update").first()
|
|
|
817 |
if lastLink is not None:
|
|
|
818 |
if len(lastLink.code)==len(codesys):
|
|
|
819 |
newCode=lastLink.code
|
|
|
820 |
return getNextCode(codesys, newCode)
|
| 15108 |
manas |
821 |
|
| 15254 |
amit.gupta |
822 |
|
| 15091 |
amit.gupta |
823 |
def callLater(self,):
|
| 15368 |
amit.gupta |
824 |
self.retailer.status = RETRY_MAP.get(self.callType)
|
| 15100 |
amit.gupta |
825 |
self.retailer.call_priority = None
|
| 15096 |
amit.gupta |
826 |
if self.callDisposition == 'call_later':
|
| 15100 |
amit.gupta |
827 |
if self.callHistory.disposition_description is not None:
|
| 15102 |
amit.gupta |
828 |
self.retailer.call_priority = 'user_initiated'
|
| 15096 |
amit.gupta |
829 |
self.retailer.next_call_time = datetime.strptime(self.callHistory.disposition_description, '%d/%m/%Y %H:%M:%S')
|
|
|
830 |
self.callHistory.disposition_description = 'User requested to call on ' + self.callHistory.disposition_description
|
|
|
831 |
else:
|
| 15102 |
amit.gupta |
832 |
self.retailer.call_priority = 'system_initiated'
|
| 15096 |
amit.gupta |
833 |
self.retailer.next_call_time = self.callHistory.call_time + timedelta(days=1)
|
| 15112 |
amit.gupta |
834 |
self.callHistory.disposition_description = 'Call scheduled on ' + datetime.strftime(self.retailer.next_call_time, '%d/%m/%Y %H:%M:%S')
|
|
|
835 |
else:
|
|
|
836 |
if self.callDisposition == 'ringing_no_answer':
|
|
|
837 |
if self.retailer.disposition == 'ringing_no_answer':
|
|
|
838 |
self.retailer.retry_count += 1
|
|
|
839 |
else:
|
|
|
840 |
self.retailer.disposition = 'ringing_no_answer'
|
|
|
841 |
self.retailer.retry_count = 1
|
|
|
842 |
else:
|
|
|
843 |
if self.retailer.disposition == 'ringing_no_answer':
|
| 15122 |
amit.gupta |
844 |
pass
|
| 15112 |
amit.gupta |
845 |
else:
|
| 15119 |
amit.gupta |
846 |
self.retailer.disposition = 'not_reachable'
|
| 15122 |
amit.gupta |
847 |
self.retailer.retry_count += 1
|
|
|
848 |
self.retailer.invalid_retry_count += 1
|
| 15119 |
amit.gupta |
849 |
|
| 15122 |
amit.gupta |
850 |
retryConfig = session.query(RetryConfig).filter_by(call_type=self.callType, disposition_type=self.retailer.disposition, retry_count=self.retailer.retry_count).first()
|
| 15112 |
amit.gupta |
851 |
if retryConfig is not None:
|
|
|
852 |
self.retailer.next_call_time = self.callHistory.call_time + timedelta(minutes = retryConfig.minutes_ahead)
|
| 15119 |
amit.gupta |
853 |
self.callHistory.disposition_description = 'Call scheduled on ' + datetime.strftime(self.retailer.next_call_time, '%d/%m/%Y %H:%M:%S')
|
| 15112 |
amit.gupta |
854 |
else:
|
|
|
855 |
self.retailer.status = 'failed'
|
|
|
856 |
self.callHistory.disposition_description = 'Call failed as all attempts exhausted'
|
| 15119 |
amit.gupta |
857 |
|
| 15101 |
amit.gupta |
858 |
session.commit()
|
|
|
859 |
return True
|
| 15096 |
amit.gupta |
860 |
|
| 15100 |
amit.gupta |
861 |
|
| 15091 |
amit.gupta |
862 |
def alReadyUser(self,):
|
| 15112 |
amit.gupta |
863 |
self.retailer.status = self.callDisposition
|
| 15117 |
amit.gupta |
864 |
if self.callHistory.disposition_description is None:
|
|
|
865 |
self.callHistory.disposition_description = 'Retailer already user'
|
| 15112 |
amit.gupta |
866 |
session.commit()
|
|
|
867 |
return True
|
| 15091 |
amit.gupta |
868 |
def verifiedLinkSent(self,):
|
| 15147 |
amit.gupta |
869 |
if self.callType == 'fresh':
|
|
|
870 |
self.retailer.status = 'followup'
|
| 16882 |
amit.gupta |
871 |
if self.retailer.agent_id not in sticky_agents:
|
|
|
872 |
self.retailer.agent_id = None
|
| 15147 |
amit.gupta |
873 |
self.retailer.next_call_time = self.callHistory.call_time + timedelta(days=1)
|
|
|
874 |
self.callHistory.disposition_description = 'App link sent via ' + self.callHistory.disposition_description+ '. followup on' + datetime.strftime(self.retailer.next_call_time, '%d/%m/%Y %H:%M:%S')
|
|
|
875 |
else:
|
| 15224 |
amit.gupta |
876 |
self.retailer.status = 'followup'
|
| 16882 |
amit.gupta |
877 |
if self.retailer.agent_id not in sticky_agents:
|
|
|
878 |
self.retailer.agent_id = None
|
| 15147 |
amit.gupta |
879 |
self.retailer.next_call_time = self.callHistory.call_time + timedelta(days=7)
|
| 15254 |
amit.gupta |
880 |
self.callHistory.disposition_description = 'App link sent via' + self.callHistory.disposition_description + '. Followup again on ' + datetime.strftime(self.retailer.next_call_time, '%d/%m/%Y %H:%M:%S')
|
| 15328 |
amit.gupta |
881 |
addContactToRetailer(self.agentId, self.retailerId, self.smsNumber, self.callType, 'sms')
|
| 15146 |
amit.gupta |
882 |
session.commit()
|
|
|
883 |
return True
|
| 15368 |
amit.gupta |
884 |
def onboarded(self,):
|
|
|
885 |
self.retailer.status = self.callDisposition
|
|
|
886 |
checkList = OnboardedRetailerChecklists()
|
|
|
887 |
checkList.contact_us = self.checkList.get('contactus')
|
| 15390 |
amit.gupta |
888 |
checkList.doa_return_policy = self.checkList.get('doareturnpolicy')
|
| 15368 |
amit.gupta |
889 |
checkList.number_verification = self.checkList.get('numberverification')
|
|
|
890 |
checkList.payment_option = self.checkList.get('paymentoption')
|
|
|
891 |
checkList.preferences = self.checkList.get('preferences')
|
|
|
892 |
checkList.product_info = self.checkList.get('productinfo')
|
| 15372 |
amit.gupta |
893 |
checkList.redeem = self.checkList.get('redeem')
|
| 15368 |
amit.gupta |
894 |
checkList.retailer_id = self.retailerId
|
|
|
895 |
session.commit()
|
|
|
896 |
return True
|
|
|
897 |
|
|
|
898 |
|
| 15254 |
amit.gupta |
899 |
def isActivated(retailerId):
|
| 15276 |
amit.gupta |
900 |
retailerLink = session.query(RetailerLinks).filter_by(retailer_id=retailerId).first()
|
| 15448 |
amit.gupta |
901 |
user = session.query(Users).filter(or_(func.lower(Users.referrer)==retailerLink.code.lower(), Users.utm_campaign==retailerLink.code)).first()
|
| 15276 |
amit.gupta |
902 |
if user is None:
|
|
|
903 |
mobileNumbers = list(session.query(RetailerContacts.mobile_number).filter_by(retailer_id=retailerId).all())
|
|
|
904 |
user = session.query(Users).filter(Users.mobile_number.in_(mobileNumbers)).first()
|
| 15254 |
amit.gupta |
905 |
if user is None:
|
| 15332 |
amit.gupta |
906 |
if retailerLink.created < datetime(2015,5,26):
|
| 15333 |
amit.gupta |
907 |
historyNumbers = [number for number, in session.query(CallHistory.mobile_number).filter_by(retailer_id = retailerId).all()]
|
| 15476 |
amit.gupta |
908 |
user = session.query(Users).filter(Users.mobile_number.in_(historyNumbers)).first()
|
| 15332 |
amit.gupta |
909 |
if user is None:
|
|
|
910 |
return False
|
| 15334 |
amit.gupta |
911 |
else:
|
|
|
912 |
mapped_with = 'contact'
|
| 15332 |
amit.gupta |
913 |
else:
|
|
|
914 |
return False
|
| 15276 |
amit.gupta |
915 |
else:
|
|
|
916 |
mapped_with = 'contact'
|
|
|
917 |
else:
|
|
|
918 |
mapped_with = 'code'
|
|
|
919 |
retailerLink.mapped_with = mapped_with
|
| 15388 |
amit.gupta |
920 |
if user.activation_time is not None:
|
| 15448 |
amit.gupta |
921 |
retailerLink.activated = user.activation_time
|
|
|
922 |
retailerLink.activated = user.created
|
| 15276 |
amit.gupta |
923 |
retailerLink.user_id = user.id
|
| 15291 |
amit.gupta |
924 |
retailer = session.query(Retailers).filter_by(id=retailerId).first()
|
| 15574 |
amit.gupta |
925 |
if retailer.status == 'followup' or retailer.status == 'fretry':
|
| 15389 |
amit.gupta |
926 |
retailer.status = 'onboarding'
|
| 16882 |
amit.gupta |
927 |
if retailer.agent_id not in sticky_agents:
|
|
|
928 |
retailer.agent_id = None
|
| 15391 |
amit.gupta |
929 |
retailer.call_priority = None
|
|
|
930 |
retailer.next_call_time = None
|
|
|
931 |
retailer.retry_count = 0
|
|
|
932 |
retailer.invalid_retry_count = 0
|
| 15276 |
amit.gupta |
933 |
session.commit()
|
| 15287 |
amit.gupta |
934 |
print "retailerLink.retailer_id", retailerLink.retailer_id
|
| 15700 |
amit.gupta |
935 |
print "retailer", retailer.id
|
| 15276 |
amit.gupta |
936 |
session.close()
|
|
|
937 |
return True
|
| 15254 |
amit.gupta |
938 |
|
|
|
939 |
class AddContactToRetailer():
|
|
|
940 |
def on_post(self,req,resp, agentId):
|
|
|
941 |
agentId = int(agentId)
|
|
|
942 |
try:
|
|
|
943 |
jsonReq = json.loads(req.stream.read(), encoding='utf-8')
|
|
|
944 |
retailerId = int(jsonReq.get("retailerid"))
|
|
|
945 |
mobile = jsonReq.get("mobile")
|
|
|
946 |
callType = jsonReq.get("calltype")
|
|
|
947 |
contactType = jsonReq.get("contacttype")
|
|
|
948 |
addContactToRetailer(agentId, retailerId, mobile, callType, contactType)
|
|
|
949 |
session.commit()
|
|
|
950 |
finally:
|
|
|
951 |
session.close()
|
| 15676 |
amit.gupta |
952 |
|
| 15677 |
amit.gupta |
953 |
class AddAddressToRetailer():
|
| 15676 |
amit.gupta |
954 |
def on_post(self,req,resp, agentId):
|
|
|
955 |
agentId = int(agentId)
|
| 15678 |
amit.gupta |
956 |
jsonReq = json.loads(req.stream.read(), encoding='utf-8')
|
|
|
957 |
retailerId = int(jsonReq.get("retailerid"))
|
| 15684 |
amit.gupta |
958 |
address = str(jsonReq.get("address"))
|
|
|
959 |
storeName = str(jsonReq.get("storename"))
|
|
|
960 |
pin = str(jsonReq.get("pin"))
|
|
|
961 |
city = str(jsonReq.get("city"))
|
|
|
962 |
state = str(jsonReq.get("state"))
|
|
|
963 |
updateType = str(jsonReq.get("updatetype"))
|
| 15678 |
amit.gupta |
964 |
addAddressToRetailer(agentId, retailerId, address, storeName, pin, city,state, updateType)
|
| 15254 |
amit.gupta |
965 |
|
|
|
966 |
def addContactToRetailer(agentId, retailerId, mobile, callType, contactType):
|
| 15312 |
amit.gupta |
967 |
retailerContact = session.query(RetailerContacts).filter_by(retailer_id=retailerId).filter_by(mobile_number=mobile).first()
|
|
|
968 |
if retailerContact is None:
|
| 15254 |
amit.gupta |
969 |
retailerContact = RetailerContacts()
|
| 15256 |
amit.gupta |
970 |
retailerContact.retailer_id = retailerId
|
| 15254 |
amit.gupta |
971 |
retailerContact.agent_id = agentId
|
|
|
972 |
retailerContact.call_type = callType
|
|
|
973 |
retailerContact.contact_type = contactType
|
|
|
974 |
retailerContact.mobile_number = mobile
|
| 15312 |
amit.gupta |
975 |
else:
|
| 15327 |
amit.gupta |
976 |
if CONTACT_PRIORITY.index(retailerContact.contact_type) > CONTACT_PRIORITY.index(contactType):
|
| 15358 |
amit.gupta |
977 |
retailerContact.contact_type = contactType
|
| 15676 |
amit.gupta |
978 |
|
|
|
979 |
def addAddressToRetailer(agentId, retailerId, address, storeName, pin, city,state, updateType):
|
| 15679 |
amit.gupta |
980 |
print "I am in addAddress"
|
| 15682 |
amit.gupta |
981 |
print agentId, retailerId, address, storeName, pin, city, state, updateType
|
| 15679 |
amit.gupta |
982 |
try:
|
|
|
983 |
if updateType=='new':
|
| 15685 |
amit.gupta |
984 |
retailer = session.query(Retailers).filter_by(id=retailerId).first()
|
| 15679 |
amit.gupta |
985 |
retailer.address = address
|
|
|
986 |
retailer.title = storeName
|
|
|
987 |
retailer.city = city
|
|
|
988 |
retailer.state = state
|
|
|
989 |
retailer.pin = pin
|
|
|
990 |
raddress = RetailerAddresses()
|
|
|
991 |
raddress.address = address
|
| 15682 |
amit.gupta |
992 |
raddress.title = storeName
|
| 15679 |
amit.gupta |
993 |
raddress.agent_id = agentId
|
|
|
994 |
raddress.city = city
|
|
|
995 |
raddress.pin = pin
|
|
|
996 |
raddress.retailer_id = retailerId
|
|
|
997 |
raddress.state = state
|
|
|
998 |
session.commit()
|
|
|
999 |
finally:
|
|
|
1000 |
session.close()
|
| 15254 |
amit.gupta |
1001 |
|
| 15312 |
amit.gupta |
1002 |
|
| 15189 |
manas |
1003 |
class Login():
|
|
|
1004 |
|
|
|
1005 |
def on_get(self, req, resp, agentId, role):
|
|
|
1006 |
try:
|
| 15198 |
manas |
1007 |
self.agentId = int(agentId)
|
|
|
1008 |
self.role = role
|
|
|
1009 |
print str(self.agentId) + self.role;
|
| 15199 |
manas |
1010 |
agents=AgentLoginTimings()
|
|
|
1011 |
lastLoginTime = session.query(Agents).filter(Agents.id==self.agentId).first()
|
|
|
1012 |
print 'lastLogintime' + str(lastLoginTime)
|
|
|
1013 |
agents.loginTime=lastLoginTime.last_login
|
|
|
1014 |
agents.logoutTime=datetime.now()
|
|
|
1015 |
agents.role =self.role
|
| 15282 |
amit.gupta |
1016 |
agents.agent_id = self.agentId
|
| 15199 |
manas |
1017 |
session.add(agents)
|
|
|
1018 |
session.commit()
|
|
|
1019 |
resp.body = json.dumps({"result":{"success":"true","message":"Success"}}, encoding='utf-8')
|
| 15189 |
manas |
1020 |
finally:
|
|
|
1021 |
session.close()
|
| 15112 |
amit.gupta |
1022 |
|
| 15189 |
manas |
1023 |
def on_post(self,req,resp):
|
|
|
1024 |
try:
|
|
|
1025 |
jsonReq = json.loads(req.stream.read(), encoding='utf-8')
|
|
|
1026 |
lgr.info( "Request ----\n" + str(jsonReq))
|
|
|
1027 |
email=jsonReq.get('email')
|
|
|
1028 |
password = jsonReq.get('password')
|
|
|
1029 |
role=jsonReq.get('role')
|
| 15531 |
amit.gupta |
1030 |
agent = session.query(Agents).filter(and_(Agents.email==email,Agents.password==password)).first()
|
|
|
1031 |
if agent is None:
|
| 15189 |
manas |
1032 |
resp.body = json.dumps({"result":{"success":"false","message":"Invalid User"}}, encoding='utf-8')
|
|
|
1033 |
else:
|
| 15531 |
amit.gupta |
1034 |
print agent.id
|
|
|
1035 |
checkRole = session.query(Agent_Roles.id).filter(and_(Agent_Roles.agent_id==agent.id,Agent_Roles.role==role)).first()
|
| 15189 |
manas |
1036 |
if checkRole is None:
|
|
|
1037 |
resp.body = json.dumps({"result":{"success":"false","message":"Invalid Role"}}, encoding='utf-8')
|
|
|
1038 |
else:
|
| 15531 |
amit.gupta |
1039 |
agent.last_login = datetime.now()
|
|
|
1040 |
agent.login_type = role
|
|
|
1041 |
resp.body = json.dumps({"result":{"success":"true","message":"Valid User","id":agent.id}}, encoding='utf-8')
|
|
|
1042 |
session.commit()
|
| 15195 |
manas |
1043 |
#session.query(Agents).filter_by(id = checkUser[0]).
|
| 15189 |
manas |
1044 |
finally:
|
|
|
1045 |
session.close()
|
|
|
1046 |
|
| 15195 |
manas |
1047 |
def test(self,email,password,role):
|
| 15189 |
manas |
1048 |
checkUser = session.query(Agents.id).filter(and_(Agents.email==email,Agents.password==password)).first()
|
|
|
1049 |
if checkUser is None:
|
|
|
1050 |
print checkUser
|
| 15195 |
manas |
1051 |
|
| 15189 |
manas |
1052 |
else:
|
|
|
1053 |
print checkUser[0]
|
|
|
1054 |
checkRole = session.query(Agent_Roles.id).filter(and_(Agent_Roles.agent_id==checkUser[0],Agent_Roles.role==role)).first()
|
|
|
1055 |
if checkRole is None:
|
| 15195 |
manas |
1056 |
pass
|
| 15189 |
manas |
1057 |
else:
|
| 15195 |
manas |
1058 |
agents=AgentLoginTimings()
|
|
|
1059 |
agents.loginTime=datetime.now()
|
|
|
1060 |
agents.logoutTime=datetime.now()
|
|
|
1061 |
agents.role =role
|
|
|
1062 |
agents.agent_id = 2
|
|
|
1063 |
#session.query(AgentLoginTimings).filter_by(id = checkUser[0]).update({"last_login":datetime.now()}, synchronize_session=False)
|
|
|
1064 |
session.add(agents)
|
|
|
1065 |
session.commit()
|
|
|
1066 |
session.close()
|
|
|
1067 |
|
|
|
1068 |
#session.query(Agents).filter(Agents.id==checkUser[0]).update({"last_login":Agents.last_login})
|
| 15275 |
amit.gupta |
1069 |
|
|
|
1070 |
class RetailerActivation():
|
|
|
1071 |
def on_get(self, req, resp, userId):
|
| 15351 |
amit.gupta |
1072 |
res = markDealerActivation(int(userId))
|
|
|
1073 |
if res:
|
|
|
1074 |
resp.body = "{\"activated\":true}"
|
|
|
1075 |
else:
|
|
|
1076 |
resp.body = "{\"activated\":false}"
|
|
|
1077 |
|
| 15275 |
amit.gupta |
1078 |
|
|
|
1079 |
def markDealerActivation(userId):
|
|
|
1080 |
try:
|
| 15343 |
amit.gupta |
1081 |
user = session.query(Users).filter_by(id=userId).first()
|
| 15275 |
amit.gupta |
1082 |
result = False
|
|
|
1083 |
mappedWith = 'contact'
|
| 15534 |
amit.gupta |
1084 |
retailer = None
|
| 15275 |
amit.gupta |
1085 |
if user is not None:
|
| 15454 |
amit.gupta |
1086 |
referrer = None if user.referrer is None else user.referrer.upper()
|
|
|
1087 |
retailerLink = session.query(RetailerLinks).filter(or_(RetailerLinks.code==referrer, RetailerLinks.code==user.utm_campaign)).first()
|
| 15275 |
amit.gupta |
1088 |
if retailerLink is None:
|
| 15501 |
amit.gupta |
1089 |
if user.mobile_number is not None:
|
|
|
1090 |
retailerContact = session.query(RetailerContacts).filter_by(mobile_number=user.mobile_number).first()
|
|
|
1091 |
if retailerContact is None:
|
| 15613 |
amit.gupta |
1092 |
retailer = session.query(Retailers).filter(Retailers.status.in_(['followup', 'fretry', 'fdone'])).filter(or_(Retailers.contact1==user.mobile_number,Retailers.contact2==user.mobile_number)).first()
|
| 15501 |
amit.gupta |
1093 |
else:
|
|
|
1094 |
retailer = session.query(Retailers).filter_by(id = retailerContact.retailer_id).first()
|
| 15275 |
amit.gupta |
1095 |
else:
|
|
|
1096 |
retailer = session.query(Retailers).filter_by(id = retailerLink.retailer_id).first()
|
|
|
1097 |
mappedWith='code'
|
|
|
1098 |
if retailer is not None:
|
|
|
1099 |
retailerLink = session.query(RetailerLinks).filter_by(retailer_id=retailer.id).first()
|
|
|
1100 |
if retailerLink is not None:
|
|
|
1101 |
retailerLink.user_id = user.id
|
|
|
1102 |
retailerLink.mapped_with=mappedWith
|
| 15358 |
amit.gupta |
1103 |
retailer.status = 'onboarding'
|
| 15275 |
amit.gupta |
1104 |
result = True
|
|
|
1105 |
session.commit()
|
| 15574 |
amit.gupta |
1106 |
return result
|
| 15275 |
amit.gupta |
1107 |
finally:
|
|
|
1108 |
session.close()
|
|
|
1109 |
|
| 15189 |
manas |
1110 |
|
| 15081 |
amit.gupta |
1111 |
def todict(obj, classkey=None):
|
|
|
1112 |
if isinstance(obj, dict):
|
|
|
1113 |
data = {}
|
|
|
1114 |
for (k, v) in obj.items():
|
|
|
1115 |
data[k] = todict(v, classkey)
|
|
|
1116 |
return data
|
|
|
1117 |
elif hasattr(obj, "_ast"):
|
|
|
1118 |
return todict(obj._ast())
|
|
|
1119 |
elif hasattr(obj, "__iter__"):
|
|
|
1120 |
return [todict(v, classkey) for v in obj]
|
|
|
1121 |
elif hasattr(obj, "__dict__"):
|
|
|
1122 |
data = dict([(key, todict(value, classkey))
|
|
|
1123 |
for key, value in obj.__dict__.iteritems()
|
|
|
1124 |
if not callable(value) and not key.startswith('_')])
|
|
|
1125 |
if classkey is not None and hasattr(obj, "__class__"):
|
|
|
1126 |
data[classkey] = obj.__class__.__name__
|
|
|
1127 |
return data
|
|
|
1128 |
else:
|
|
|
1129 |
return obj
|
| 18256 |
manas |
1130 |
|
| 15358 |
amit.gupta |
1131 |
def getRetailerObj(retailer, otherContacts1=None, callType=None):
|
| 15324 |
amit.gupta |
1132 |
print "before otherContacts1",otherContacts1
|
|
|
1133 |
otherContacts = [] if otherContacts1 is None else otherContacts1
|
| 15662 |
amit.gupta |
1134 |
print "after otherContacts1",otherContacts
|
| 15081 |
amit.gupta |
1135 |
obj = Mock()
|
| 15280 |
amit.gupta |
1136 |
obj.id = retailer.id
|
| 15686 |
amit.gupta |
1137 |
|
|
|
1138 |
|
| 15314 |
amit.gupta |
1139 |
if retailer.contact1 is not None and retailer.contact1 not in otherContacts:
|
| 15315 |
amit.gupta |
1140 |
otherContacts.append(retailer.contact1)
|
| 15314 |
amit.gupta |
1141 |
if retailer.contact2 is not None and retailer.contact2 not in otherContacts:
|
| 15315 |
amit.gupta |
1142 |
otherContacts.append(retailer.contact2)
|
| 15323 |
amit.gupta |
1143 |
obj.contact1 = None if len(otherContacts)==0 else otherContacts[0]
|
| 15325 |
amit.gupta |
1144 |
if obj.contact1 is not None:
|
|
|
1145 |
obj.contact2 = None if len(otherContacts)==1 else otherContacts[1]
|
| 15096 |
amit.gupta |
1146 |
obj.scheduled = (retailer.call_priority is not None)
|
| 15686 |
amit.gupta |
1147 |
address = None
|
|
|
1148 |
try:
|
|
|
1149 |
address = session.query(RetailerAddresses).filter_by(retailer_id=retailer.id).order_by(RetailerAddresses.created.desc()).first()
|
|
|
1150 |
finally:
|
|
|
1151 |
session.close()
|
|
|
1152 |
if address is not None:
|
|
|
1153 |
obj.address = address.address
|
|
|
1154 |
obj.title = address.title
|
|
|
1155 |
obj.city = address.city
|
|
|
1156 |
obj.state = address.state
|
|
|
1157 |
obj.pin = address.pin
|
|
|
1158 |
else:
|
|
|
1159 |
obj.address = retailer.address_new if retailer.address_new is not None else retailer.address
|
|
|
1160 |
obj.title = retailer.title
|
|
|
1161 |
obj.city = retailer.city
|
|
|
1162 |
obj.state = retailer.state
|
|
|
1163 |
obj.pin = retailer.pin
|
| 15699 |
amit.gupta |
1164 |
obj.status = retailer.status
|
| 15686 |
amit.gupta |
1165 |
|
| 15662 |
amit.gupta |
1166 |
if hasattr(retailer, 'contact'):
|
|
|
1167 |
obj.contact = retailer.contact
|
| 15358 |
amit.gupta |
1168 |
if callType == 'onboarding':
|
|
|
1169 |
try:
|
| 15364 |
amit.gupta |
1170 |
userId, activatedTime = session.query(RetailerLinks.user_id, RetailerLinks.activated).filter(RetailerLinks.retailer_id==retailer.id).first()
|
| 15366 |
amit.gupta |
1171 |
activated, = session.query(Users.activation_time).filter(Users.id==userId).first()
|
| 15364 |
amit.gupta |
1172 |
if activated is not None:
|
| 15366 |
amit.gupta |
1173 |
activatedTime = activated
|
| 15362 |
amit.gupta |
1174 |
obj.user_id = userId
|
| 15364 |
amit.gupta |
1175 |
obj.created = datetime.strftime(activatedTime, '%d/%m/%Y %H:%M:%S')
|
| 15358 |
amit.gupta |
1176 |
result = fetchResult("select * from useractive where user_id=%d"%(userId))
|
|
|
1177 |
if result == ():
|
|
|
1178 |
obj.last_active = None
|
|
|
1179 |
else:
|
| 15360 |
amit.gupta |
1180 |
obj.last_active =datetime.strftime(result[0][1], '%d/%m/%Y %H:%M:%S')
|
| 15361 |
amit.gupta |
1181 |
ordersCount = session.query(Orders).filter_by(user_id = userId).filter(~Orders.status.in_(['ORDER_NOT_CREATED_KNOWN', 'ORDER_ALREADY_CREATED_IGNORED'])).count()
|
| 15358 |
amit.gupta |
1182 |
obj.orders = ordersCount
|
|
|
1183 |
finally:
|
|
|
1184 |
session.close()
|
| 15081 |
amit.gupta |
1185 |
return obj
|
| 15091 |
amit.gupta |
1186 |
|
| 15132 |
amit.gupta |
1187 |
def make_tiny(code):
|
| 16939 |
manish.sha |
1188 |
url = 'https://play.google.com/store/apps/details?id=com.saholic.profittill&referrer=utm_source%3D0%26utm_medium%3DCRM%26utm_term%3D001%26utm_campaign%3D' + code
|
| 16881 |
manas |
1189 |
#url='https://play.google.com/store/apps/details?id=com.saholic.profittill&referrer=utm_source=0&utm_medium=CRM&utm_term=001&utm_campaign='+code
|
| 16939 |
manish.sha |
1190 |
#marketUrl='market://details?id=com.saholic.profittill&referrer=utm_source=0&utm_medium=CRM&utm_term=001&utm_campaign='+code
|
|
|
1191 |
#url = urllib.quote(marketUrl)
|
| 15465 |
amit.gupta |
1192 |
#request_url = ('http://tinyurl.com/api-create.php?' + urlencode({'url':url}))
|
|
|
1193 |
#filehandle = urllib2.Request(request_url)
|
|
|
1194 |
#x= urllib2.urlopen(filehandle)
|
| 15546 |
amit.gupta |
1195 |
try:
|
|
|
1196 |
shortener = Shortener('TinyurlShortener')
|
|
|
1197 |
returnUrl = shortener.short(url)
|
|
|
1198 |
except:
|
|
|
1199 |
shortener = Shortener('SentalaShortener')
|
|
|
1200 |
returnlUrl = shortener.short(url)
|
|
|
1201 |
return returnUrl
|
| 15171 |
amit.gupta |
1202 |
|
| 15285 |
manas |
1203 |
class SearchUser():
|
|
|
1204 |
|
|
|
1205 |
def on_post(self, req, resp, agentId, searchType):
|
| 15314 |
amit.gupta |
1206 |
retailersJsonArray = []
|
| 15285 |
manas |
1207 |
try:
|
|
|
1208 |
jsonReq = json.loads(req.stream.read(), encoding='utf-8')
|
|
|
1209 |
lgr.info( "Request in Search----\n" + str(jsonReq))
|
| 15302 |
amit.gupta |
1210 |
contact=jsonReq.get('searchTerm')
|
| 15285 |
manas |
1211 |
if(searchType=="number"):
|
| 15312 |
amit.gupta |
1212 |
retailer_ids = session.query(RetailerContacts.retailer_id).filter_by(mobile_number=contact).all()
|
|
|
1213 |
retailer_ids = [r for r, in retailer_ids]
|
|
|
1214 |
anotherCondition = or_(Retailers.contact1==contact,Retailers.contact2==contact, Retailers.id.in_(retailer_ids))
|
|
|
1215 |
else:
|
|
|
1216 |
m = re.match("(.*?)(\d{6})(.*?)", contact)
|
|
|
1217 |
if m is not None:
|
|
|
1218 |
pin = m.group(2)
|
|
|
1219 |
contact = m.group(1) if m.group(1) != '' else m.group(3)
|
| 15313 |
amit.gupta |
1220 |
anotherCondition = and_(Retailers.title.ilike('%%%s%%'%(contact)), Retailers.pin==pin)
|
| 15312 |
amit.gupta |
1221 |
else:
|
|
|
1222 |
anotherCondition = Retailers.title.ilike('%%%s%%'%(contact))
|
| 15297 |
amit.gupta |
1223 |
|
| 15326 |
amit.gupta |
1224 |
retailers = session.query(Retailers).filter(anotherCondition).limit(20).all()
|
| 15312 |
amit.gupta |
1225 |
if retailers is None:
|
| 15285 |
manas |
1226 |
resp.body = json.dumps("{}")
|
| 15312 |
amit.gupta |
1227 |
else:
|
|
|
1228 |
for retailer in retailers:
|
| 15326 |
amit.gupta |
1229 |
otherContacts = [r for r, in session.query(RetailerContacts.mobile_number).filter_by(retailer_id=retailer.id).order_by(RetailerContacts.contact_type).all()]
|
| 15314 |
amit.gupta |
1230 |
retailersJsonArray.append(todict(getRetailerObj(retailer, otherContacts)))
|
|
|
1231 |
resp.body = json.dumps({"Retailers":retailersJsonArray}, encoding='utf-8')
|
| 15312 |
amit.gupta |
1232 |
return
|
| 15285 |
manas |
1233 |
finally:
|
|
|
1234 |
session.close()
|
| 15171 |
amit.gupta |
1235 |
|
| 15081 |
amit.gupta |
1236 |
|
|
|
1237 |
class Mock(object):
|
|
|
1238 |
pass
|
| 15189 |
manas |
1239 |
|
| 15312 |
amit.gupta |
1240 |
def tagActivatedReatilers():
|
| 15613 |
amit.gupta |
1241 |
retailerIds = [r for r, in session.query(RetailerLinks.retailer_id).filter_by(user_id = None).all()]
|
| 15312 |
amit.gupta |
1242 |
session.close()
|
| 15288 |
amit.gupta |
1243 |
for retailerId in retailerIds:
|
|
|
1244 |
isActivated(retailerId)
|
| 15312 |
amit.gupta |
1245 |
session.close()
|
| 15374 |
kshitij.so |
1246 |
|
|
|
1247 |
class StaticDeals():
|
|
|
1248 |
|
|
|
1249 |
def on_get(self, req, resp):
|
|
|
1250 |
|
|
|
1251 |
offset = req.get_param_as_int("offset")
|
|
|
1252 |
limit = req.get_param_as_int("limit")
|
|
|
1253 |
categoryId = req.get_param_as_int("categoryId")
|
| 15458 |
kshitij.so |
1254 |
direction = req.get_param_as_int("direction")
|
| 15374 |
kshitij.so |
1255 |
|
| 15458 |
kshitij.so |
1256 |
result = Mongo.getStaticDeals(offset, limit, categoryId, direction)
|
| 15374 |
kshitij.so |
1257 |
resp.body = dumps(result)
|
|
|
1258 |
|
| 16366 |
kshitij.so |
1259 |
class DealNotification():
|
|
|
1260 |
|
|
|
1261 |
def on_get(self,req,resp,skuBundleIds):
|
|
|
1262 |
result = Mongo.getDealsForNotification(skuBundleIds)
|
|
|
1263 |
resp.body = dumps(result)
|
| 16487 |
kshitij.so |
1264 |
|
|
|
1265 |
class DealPoints():
|
|
|
1266 |
|
|
|
1267 |
def on_get(self, req, resp):
|
| 16366 |
kshitij.so |
1268 |
|
| 16487 |
kshitij.so |
1269 |
offset = req.get_param_as_int("offset")
|
|
|
1270 |
limit = req.get_param_as_int("limit")
|
|
|
1271 |
|
|
|
1272 |
result = Mongo.getAllBundlesWithDealPoints(offset, limit)
|
|
|
1273 |
resp.body = dumps(result)
|
| 15374 |
kshitij.so |
1274 |
|
| 16487 |
kshitij.so |
1275 |
|
|
|
1276 |
def on_post(self, req, resp):
|
|
|
1277 |
|
|
|
1278 |
|
|
|
1279 |
try:
|
|
|
1280 |
result_json = json.loads(req.stream.read(), encoding='utf-8')
|
|
|
1281 |
except ValueError:
|
|
|
1282 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
1283 |
'Malformed JSON',
|
|
|
1284 |
'Could not decode the request body. The '
|
|
|
1285 |
'JSON was incorrect.')
|
|
|
1286 |
|
|
|
1287 |
result = Mongo.addDealPoints(result_json)
|
|
|
1288 |
resp.body = json.dumps(result, encoding='utf-8')
|
| 15374 |
kshitij.so |
1289 |
|
| 16545 |
kshitij.so |
1290 |
class AppAffiliates():
|
|
|
1291 |
|
|
|
1292 |
def on_get(self, req, resp, retailerId, appId):
|
|
|
1293 |
retailerId = int(retailerId)
|
|
|
1294 |
appId = int(appId)
|
| 16554 |
kshitij.so |
1295 |
call_back = req.get_param("callback")
|
| 16545 |
kshitij.so |
1296 |
result = Mongo.generateRedirectUrl(retailerId, appId)
|
| 16555 |
kshitij.so |
1297 |
resp.body = call_back+'('+str(result)+')'
|
| 16557 |
kshitij.so |
1298 |
|
|
|
1299 |
class AffiliatePayout():
|
|
|
1300 |
def on_get(self, req, resp):
|
|
|
1301 |
payout = req.get_param("payout")
|
|
|
1302 |
transaction_id = req.get_param("transaction_id")
|
|
|
1303 |
result = Mongo.addPayout(payout, transaction_id)
|
|
|
1304 |
resp.body = str(result)
|
|
|
1305 |
|
| 16581 |
manish.sha |
1306 |
class AppOffers():
|
|
|
1307 |
def on_get(self, req, resp, retailerId):
|
| 16895 |
manish.sha |
1308 |
try:
|
|
|
1309 |
result = Mongo.getAppOffers(retailerId)
|
|
|
1310 |
offerids = result.values()
|
|
|
1311 |
if offerids is None or len(offerids)==0:
|
| 16887 |
kshitij.so |
1312 |
resp.body = json.dumps("{}")
|
|
|
1313 |
else:
|
| 16941 |
manish.sha |
1314 |
appOffers = 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,appmasters.rank, app_offers.offerCondition, app_offers.location).join((appmasters,appmasters.id==app_offers.appmaster_id)).filter(app_offers.id.in_(tuple(offerids))).all()
|
| 16895 |
manish.sha |
1315 |
appOffersMap = {}
|
|
|
1316 |
jsonOffersArray=[]
|
|
|
1317 |
for offer in appOffers:
|
|
|
1318 |
appOffersMap[long(offer[0])]= AppOfferObj(offer[0], offer[1], offer[2], offer[3], offer[4], offer[5], offer[6], offer[7], offer[8], offer[9], offer[10], offer[11], offer[12], offer[13], offer[14], offer[15], offer[16], offer[17], offer[18], offer[19]).__dict__
|
|
|
1319 |
for rank in sorted(result):
|
|
|
1320 |
print 'Rank', rank, 'Data', appOffersMap[result[rank]]
|
|
|
1321 |
jsonOffersArray.append(appOffersMap[result[rank]])
|
|
|
1322 |
|
|
|
1323 |
resp.body = json.dumps({"AppOffers":jsonOffersArray}, encoding='latin1')
|
| 16887 |
kshitij.so |
1324 |
finally:
|
|
|
1325 |
session.close()
|
|
|
1326 |
|
| 16727 |
manish.sha |
1327 |
|
|
|
1328 |
class AppUserBatchRefund():
|
|
|
1329 |
def on_get(self, req, resp, batchId, userId):
|
| 16887 |
kshitij.so |
1330 |
try:
|
|
|
1331 |
batchId = long(batchId)
|
|
|
1332 |
userId = long(userId)
|
|
|
1333 |
userBatchCashback = user_app_cashbacks.get_by(user_id=userId, batchCreditId=batchId)
|
|
|
1334 |
if userBatchCashback is None:
|
|
|
1335 |
resp.body = json.dumps("{}")
|
|
|
1336 |
else:
|
| 16905 |
manish.sha |
1337 |
if userBatchCashback.creditedDate is not None:
|
|
|
1338 |
userBatchCashback.creditedDate = str(userBatchCashback.creditedDate)
|
| 16887 |
kshitij.so |
1339 |
resp.body = json.dumps(todict(userBatchCashback), encoding='utf-8')
|
|
|
1340 |
finally:
|
|
|
1341 |
session.close()
|
| 16727 |
manish.sha |
1342 |
|
|
|
1343 |
class AppUserBatchDrillDown():
|
| 16777 |
manish.sha |
1344 |
def on_get(self, req, resp, fortNightOfYear, userId, yearVal):
|
| 16887 |
kshitij.so |
1345 |
try:
|
|
|
1346 |
fortNightOfYear = long(fortNightOfYear)
|
|
|
1347 |
userId = long(userId)
|
|
|
1348 |
yearVal = long(yearVal)
|
|
|
1349 |
appUserBatchDrillDown = session.query(user_app_installs.transaction_date, func.sum(user_app_installs.installCount).label('downloads'), func.sum(user_app_installs.payoutAmount).label('amount')).join((user_app_cashbacks,user_app_cashbacks.user_id==user_app_installs.user_id)).filter(user_app_cashbacks.fortnightOfYear==user_app_installs.fortnightOfYear).filter(user_app_cashbacks.user_id==userId).filter(user_app_cashbacks.yearVal==yearVal).filter(user_app_cashbacks.fortnightOfYear==fortNightOfYear).group_by(user_app_installs.transaction_date).all()
|
|
|
1350 |
cashbackArray = []
|
|
|
1351 |
if appUserBatchDrillDown is None or len(appUserBatchDrillDown)==0:
|
|
|
1352 |
resp.body = json.dumps("{}")
|
|
|
1353 |
else:
|
|
|
1354 |
for appcashBack in appUserBatchDrillDown:
|
|
|
1355 |
userAppBatchDrillDown = UserAppBatchDrillDown(str(appcashBack[0]),long(appcashBack[1]), long(appcashBack[2]))
|
|
|
1356 |
cashbackArray.append(todict(userAppBatchDrillDown))
|
|
|
1357 |
resp.body = json.dumps({"UserAppCashBackInBatch":cashbackArray}, encoding='utf-8')
|
|
|
1358 |
finally:
|
|
|
1359 |
session.close()
|
| 16727 |
manish.sha |
1360 |
|
|
|
1361 |
class AppUserBatchDateDrillDown():
|
|
|
1362 |
def on_get(self, req, resp, userId, date):
|
| 16887 |
kshitij.so |
1363 |
try:
|
|
|
1364 |
userId = long(userId)
|
|
|
1365 |
date = str(date)
|
|
|
1366 |
date = datetime.strptime(date, '%Y-%m-%d')
|
|
|
1367 |
appUserBatchDateDrillDown = session.query(user_app_installs.app_name, func.sum(user_app_installs.installCount).label('downloads'), func.sum(user_app_installs.payoutAmount).label('amount')).filter(user_app_installs.user_id==userId).filter(user_app_installs.transaction_date==date).group_by(user_app_installs.app_name).all()
|
|
|
1368 |
cashbackArray = []
|
|
|
1369 |
if appUserBatchDateDrillDown is None or len(appUserBatchDateDrillDown)==0:
|
|
|
1370 |
resp.body = json.dumps("{}")
|
|
|
1371 |
else:
|
|
|
1372 |
for appcashBack in appUserBatchDateDrillDown:
|
|
|
1373 |
userAppBatchDateDrillDown = UserAppBatchDateDrillDown(str(appcashBack[0]),long(appcashBack[1]),long(appcashBack[2]))
|
|
|
1374 |
cashbackArray.append(todict(userAppBatchDateDrillDown))
|
|
|
1375 |
resp.body = json.dumps({"UserAppCashBackDateWise":cashbackArray}, encoding='utf-8')
|
|
|
1376 |
finally:
|
|
|
1377 |
session.close()
|
| 16739 |
manish.sha |
1378 |
|
| 16748 |
manish.sha |
1379 |
class AppUserCashBack():
|
|
|
1380 |
def on_get(self, req, resp, userId, status):
|
| 16887 |
kshitij.so |
1381 |
try:
|
|
|
1382 |
userId = long(userId)
|
|
|
1383 |
status = str(status)
|
|
|
1384 |
appUserApprovedCashBacks = user_app_cashbacks.query.filter(user_app_cashbacks.user_id==userId).filter(user_app_cashbacks.status==status).all()
|
|
|
1385 |
cashbackArray = []
|
|
|
1386 |
if appUserApprovedCashBacks is None or len(appUserApprovedCashBacks)==0:
|
|
|
1387 |
resp.body = json.dumps("{}")
|
|
|
1388 |
else:
|
|
|
1389 |
totalAmount = 0
|
|
|
1390 |
for appUserApprovedCashBack in appUserApprovedCashBacks:
|
|
|
1391 |
totalAmount = totalAmount + appUserApprovedCashBack.amount
|
| 16895 |
manish.sha |
1392 |
if appUserApprovedCashBack.creditedDate is not None:
|
|
|
1393 |
appUserApprovedCashBack.creditedDate = str(appUserApprovedCashBack.creditedDate)
|
| 16905 |
manish.sha |
1394 |
cashbackArray.append(todict(appUserApprovedCashBack))
|
|
|
1395 |
|
| 16887 |
kshitij.so |
1396 |
resp.body = json.dumps({"UserAppCashBack":cashbackArray,"TotalAmount":totalAmount}, encoding='utf-8')
|
|
|
1397 |
finally:
|
|
|
1398 |
session.close()
|
| 17278 |
naman |
1399 |
|
|
|
1400 |
class GetSaleDetail():
|
|
|
1401 |
def on_get(self,req,res,date_val):
|
|
|
1402 |
try:
|
|
|
1403 |
db = get_mongo_connection()
|
|
|
1404 |
sum=0
|
|
|
1405 |
count=0
|
|
|
1406 |
#print date_val, type(date_val)
|
|
|
1407 |
#cursor = db.Dtr.merchantOrder.find({'createdOnInt':{'$lt':long(date_val)},'subOrders':{'$exists':True}})
|
| 17315 |
naman |
1408 |
cursor = db.Dtr.merchantOrder.find({"$and": [ { "createdOnInt":{"$gt":long(date_val)} }, {"createdOnInt":{"$lt":long(date_val)+86401} } ],"subOrders":{"$exists":True}})
|
| 17278 |
naman |
1409 |
|
|
|
1410 |
for document in cursor:
|
|
|
1411 |
for doc in document['subOrders']:
|
|
|
1412 |
sum = sum + float(doc['amountPaid'])
|
|
|
1413 |
count = count + int(doc['quantity'])
|
|
|
1414 |
|
|
|
1415 |
data = {"amount":sum , "quantity":count}
|
|
|
1416 |
|
|
|
1417 |
res.body= json.dumps(data,encoding='utf-8')
|
|
|
1418 |
finally:
|
|
|
1419 |
session.close()
|
|
|
1420 |
|
| 17301 |
kshitij.so |
1421 |
class DummyDeals():
|
| 17304 |
kshitij.so |
1422 |
def on_get(self,req, resp):
|
| 17301 |
kshitij.so |
1423 |
categoryId = req.get_param_as_int("categoryId")
|
|
|
1424 |
offset = req.get_param_as_int("offset")
|
|
|
1425 |
limit = req.get_param_as_int("limit")
|
|
|
1426 |
result = Mongo.getDummyDeals(categoryId, offset, limit)
|
| 17556 |
kshitij.so |
1427 |
resp.body = dumps(result)
|
| 17301 |
kshitij.so |
1428 |
|
| 17467 |
manas |
1429 |
class PincodeValidation():
|
| 17498 |
amit.gupta |
1430 |
def on_get(self,req,resp,pincode):
|
| 17467 |
manas |
1431 |
json_data={}
|
|
|
1432 |
cities=[]
|
|
|
1433 |
print pincode
|
|
|
1434 |
if len(str(pincode)) ==6:
|
| 19391 |
amit.gupta |
1435 |
listCities = list(session.query(Postoffices.taluk,Postoffices.state).distinct().filter(Postoffices.pincode==pincode).all())
|
| 17467 |
manas |
1436 |
if len(listCities)>0:
|
|
|
1437 |
for j in listCities:
|
| 19391 |
amit.gupta |
1438 |
if j.taluk != 'NA':
|
|
|
1439 |
cities.append(j.taluk)
|
| 17467 |
manas |
1440 |
json_data['cities'] = cities
|
|
|
1441 |
json_data['state'] = listCities[0][1]
|
|
|
1442 |
resp.body = json.dumps(json_data)
|
|
|
1443 |
else:
|
|
|
1444 |
resp.body = json.dumps("{}")
|
|
|
1445 |
else:
|
|
|
1446 |
resp.body = json.dumps("{}")
|
|
|
1447 |
session.close()
|
| 17301 |
kshitij.so |
1448 |
|
| 17556 |
kshitij.so |
1449 |
class SearchDummyDeals():
|
|
|
1450 |
def on_get(self,req,resp):
|
|
|
1451 |
offset = req.get_param_as_int("offset")
|
|
|
1452 |
limit = req.get_param_as_int("limit")
|
|
|
1453 |
searchTerm = req.get_param("searchTerm")
|
|
|
1454 |
result = Mongo.searchDummyDeals(searchTerm, limit, offset)
|
|
|
1455 |
resp.body = dumps(result)
|
|
|
1456 |
|
|
|
1457 |
class DummyPricing:
|
| 17560 |
kshitij.so |
1458 |
def on_get(self, req, resp):
|
| 17556 |
kshitij.so |
1459 |
skuBundleId = req.get_param_as_int("skuBundleId")
|
|
|
1460 |
result = Mongo.getDummyPricing(skuBundleId)
|
|
|
1461 |
resp.body = dumps(result)
|
|
|
1462 |
|
|
|
1463 |
class DealObject:
|
| 17560 |
kshitij.so |
1464 |
def on_post(self, req, resp):
|
| 17569 |
kshitij.so |
1465 |
update = req.get_param_as_int("update")
|
| 17556 |
kshitij.so |
1466 |
try:
|
|
|
1467 |
result_json = json.loads(req.stream.read(), encoding='utf-8')
|
|
|
1468 |
except ValueError:
|
|
|
1469 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
1470 |
'Malformed JSON',
|
|
|
1471 |
'Could not decode the request body. The '
|
|
|
1472 |
'JSON was incorrect.')
|
| 17569 |
kshitij.so |
1473 |
if update is None:
|
|
|
1474 |
result = Mongo.addDealObject(result_json)
|
|
|
1475 |
else:
|
|
|
1476 |
result = Mongo.updateDealObject(result_json)
|
|
|
1477 |
|
| 17556 |
kshitij.so |
1478 |
resp.body = dumps(result)
|
| 17569 |
kshitij.so |
1479 |
|
| 17556 |
kshitij.so |
1480 |
|
| 17560 |
kshitij.so |
1481 |
def on_get(self, req, resp):
|
| 17567 |
kshitij.so |
1482 |
edit = req.get_param_as_int("edit")
|
|
|
1483 |
if edit is None:
|
|
|
1484 |
offset = req.get_param_as_int("offset")
|
|
|
1485 |
limit = req.get_param_as_int("limit")
|
| 17560 |
kshitij.so |
1486 |
|
| 17567 |
kshitij.so |
1487 |
result = Mongo.getAllDealObjects(offset, limit)
|
|
|
1488 |
resp.body = dumps(result)
|
|
|
1489 |
else:
|
|
|
1490 |
id = req.get_param_as_int("id")
|
|
|
1491 |
result = Mongo.getDealObjectById(id)
|
|
|
1492 |
resp.body = dumps(result)
|
| 17560 |
kshitij.so |
1493 |
|
| 17563 |
kshitij.so |
1494 |
class DeleteDealObject:
|
|
|
1495 |
def on_get(self, req, resp, id):
|
|
|
1496 |
result = Mongo.deleteDealObject(int(id))
|
|
|
1497 |
resp.body = dumps(result)
|
|
|
1498 |
|
| 17611 |
kshitij.so |
1499 |
class FeaturedDealObject:
|
|
|
1500 |
def on_get(self, req, resp):
|
|
|
1501 |
|
|
|
1502 |
offset = req.get_param_as_int("offset")
|
|
|
1503 |
limit = req.get_param_as_int("limit")
|
|
|
1504 |
|
|
|
1505 |
result = Mongo.getAllFeaturedDealsForDealObject(offset, limit)
|
|
|
1506 |
resp.body = dumps(result)
|
|
|
1507 |
|
| 17556 |
kshitij.so |
1508 |
|
| 17611 |
kshitij.so |
1509 |
def on_post(self, req, resp):
|
|
|
1510 |
|
|
|
1511 |
|
|
|
1512 |
try:
|
|
|
1513 |
result_json = json.loads(req.stream.read(), encoding='utf-8')
|
|
|
1514 |
except ValueError:
|
|
|
1515 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
1516 |
'Malformed JSON',
|
|
|
1517 |
'Could not decode the request body. The '
|
|
|
1518 |
'JSON was incorrect.')
|
|
|
1519 |
|
| 17613 |
kshitij.so |
1520 |
result = Mongo.addFeaturedDealForDealObject(result_json)
|
| 17611 |
kshitij.so |
1521 |
resp.body = json.dumps(result, encoding='utf-8')
|
|
|
1522 |
|
| 17615 |
kshitij.so |
1523 |
class DeleteFeaturedDealObject:
|
|
|
1524 |
def on_get(self, req, resp, id):
|
|
|
1525 |
result = Mongo.deleteFeaturedDealObject(int(id))
|
|
|
1526 |
resp.body = dumps(result)
|
| 17611 |
kshitij.so |
1527 |
|
| 17653 |
kshitij.so |
1528 |
class SubCategoryFilter:
|
|
|
1529 |
def on_get(self, req, resp):
|
|
|
1530 |
category_id = req.get_param_as_int("category_id")
|
|
|
1531 |
result = Mongo.getSubCategoryForFilter(category_id)
|
|
|
1532 |
resp.body = dumps(result)
|
|
|
1533 |
|
| 17726 |
kshitij.so |
1534 |
class DummyLogin:
|
|
|
1535 |
def on_post(self,req,resp):
|
|
|
1536 |
try:
|
|
|
1537 |
result_json = json.loads(req.stream.read(), encoding='utf-8')
|
|
|
1538 |
except ValueError:
|
|
|
1539 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
1540 |
'Malformed JSON',
|
|
|
1541 |
'Could not decode the request body. The '
|
|
|
1542 |
'JSON was incorrect.')
|
|
|
1543 |
|
|
|
1544 |
result = Mongo.dummyLogin(result_json)
|
|
|
1545 |
resp.body = json.dumps(result, encoding='utf-8')
|
| 17653 |
kshitij.so |
1546 |
|
| 17726 |
kshitij.so |
1547 |
class DummyRegister:
|
|
|
1548 |
def on_post(self,req,resp):
|
|
|
1549 |
try:
|
|
|
1550 |
result_json = json.loads(req.stream.read(), encoding='utf-8')
|
|
|
1551 |
except ValueError:
|
|
|
1552 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
1553 |
'Malformed JSON',
|
|
|
1554 |
'Could not decode the request body. The '
|
|
|
1555 |
'JSON was incorrect.')
|
|
|
1556 |
|
|
|
1557 |
result = Mongo.dummyRegister(result_json)
|
|
|
1558 |
resp.body = json.dumps(result, encoding='utf-8')
|
|
|
1559 |
|
| 18896 |
amit.gupta |
1560 |
class TinSearch:
|
|
|
1561 |
def on_get(self,req,resp):
|
|
|
1562 |
tin = req.get_param("tin")
|
|
|
1563 |
result = getTinInfo(tin)
|
|
|
1564 |
resp.body = json.dumps(result, encoding='utf-8')
|
|
|
1565 |
|
|
|
1566 |
|
|
|
1567 |
def getTinInfo(tin):
|
| 18905 |
amit.gupta |
1568 |
tinInfo = {"isError":False}
|
| 18896 |
amit.gupta |
1569 |
try:
|
| 18902 |
amit.gupta |
1570 |
params = ['tin','cst','counter_name','counter_address','state','pan','registered_on','cst_status','valid_since']
|
| 18896 |
amit.gupta |
1571 |
url = "http://www.tinxsys.com/TinxsysInternetWeb/dealerControllerServlet?tinNumber=" + tin + "&searchBy=TIN"
|
|
|
1572 |
req = urllib2.Request(url)
|
| 18995 |
amit.gupta |
1573 |
try:
|
|
|
1574 |
connection = urllib2.urlopen(req, timeout=10)
|
|
|
1575 |
except:
|
|
|
1576 |
tinInfo = {"isError":True,
|
|
|
1577 |
"errorMsg": "Some problem occurred. Try again after some time"
|
|
|
1578 |
}
|
| 18996 |
amit.gupta |
1579 |
return tinInfo
|
| 18896 |
amit.gupta |
1580 |
pageHtml = connection.read()
|
|
|
1581 |
connection.close()
|
|
|
1582 |
doc = pq(pageHtml)
|
|
|
1583 |
index=-1
|
|
|
1584 |
for ele in pq(doc.find('table')[2])('tr td:nth-child(2)'):
|
|
|
1585 |
index += 1
|
|
|
1586 |
text = pq(ele).text().strip()
|
|
|
1587 |
if not text:
|
|
|
1588 |
text = pq(ele)('div').text().strip()
|
|
|
1589 |
tinInfo[params[index]] = text
|
| 18901 |
amit.gupta |
1590 |
print index, "index"
|
|
|
1591 |
if index != 8:
|
| 18896 |
amit.gupta |
1592 |
raise
|
| 19000 |
amit.gupta |
1593 |
if not get_mongo_connection().Dtr.tin.find({"tin":tinInfo['tin']}):
|
|
|
1594 |
get_mongo_connection().Dtr.tin.insert(tinInfo)
|
| 18932 |
amit.gupta |
1595 |
address = tinInfo['counter_address']
|
|
|
1596 |
m = re.match(".*?(\d{6}).*?", address)
|
|
|
1597 |
if m:
|
|
|
1598 |
tinInfo['pin'] = m.group(1)
|
| 18936 |
amit.gupta |
1599 |
tinInfo['pin_required'] = False
|
| 18932 |
amit.gupta |
1600 |
else:
|
| 18936 |
amit.gupta |
1601 |
tinInfo['pin_required'] = True
|
| 18932 |
amit.gupta |
1602 |
|
| 18896 |
amit.gupta |
1603 |
print "TinNumber: Successfully fetched details", tin
|
|
|
1604 |
except:
|
| 18901 |
amit.gupta |
1605 |
traceback.print_exc()
|
| 18896 |
amit.gupta |
1606 |
tinInfo = {"isError":True,
|
|
|
1607 |
"errorMsg": "Could not find tin"
|
|
|
1608 |
}
|
|
|
1609 |
print "TinNumber: Problem fetching details", tin
|
|
|
1610 |
return tinInfo
|
|
|
1611 |
|
|
|
1612 |
|
| 17730 |
kshitij.so |
1613 |
class UpdateUser:
|
|
|
1614 |
def on_post(self,req,resp):
|
|
|
1615 |
try:
|
|
|
1616 |
result_json = json.loads(req.stream.read(), encoding='utf-8')
|
|
|
1617 |
except ValueError:
|
|
|
1618 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
1619 |
'Malformed JSON',
|
|
|
1620 |
'Could not decode the request body. The '
|
|
|
1621 |
'JSON was incorrect.')
|
|
|
1622 |
|
|
|
1623 |
result = Mongo.updateDummyUser(result_json)
|
|
|
1624 |
resp.body = json.dumps(result, encoding='utf-8')
|
|
|
1625 |
|
|
|
1626 |
class FetchUser:
|
|
|
1627 |
def on_get(self,req,resp):
|
|
|
1628 |
user_id = req.get_param_as_int("user_id")
|
|
|
1629 |
result = Mongo.getDummyUser(user_id)
|
|
|
1630 |
resp.body = json.dumps(result, encoding='utf-8')
|
| 17928 |
kshitij.so |
1631 |
|
|
|
1632 |
class SearchSubCategory:
|
|
|
1633 |
def on_get(self,req, resp):
|
| 18088 |
kshitij.so |
1634 |
subCategoryIds = req.get_param("subCategoryId")
|
| 17928 |
kshitij.so |
1635 |
searchTerm = req.get_param("searchTerm")
|
|
|
1636 |
offset = req.get_param_as_int("offset")
|
|
|
1637 |
limit = req.get_param_as_int("limit")
|
| 17730 |
kshitij.so |
1638 |
|
| 18088 |
kshitij.so |
1639 |
result = Mongo.getDealsForSearchText(subCategoryIds, searchTerm,offset, limit)
|
| 17928 |
kshitij.so |
1640 |
resp.body = json.dumps(result, encoding='utf-8')
|
|
|
1641 |
|
|
|
1642 |
class SearchSubCategoryCount:
|
|
|
1643 |
def on_get(self,req, resp):
|
| 18088 |
kshitij.so |
1644 |
subCategoryIds = req.get_param("subCategoryId")
|
| 17928 |
kshitij.so |
1645 |
searchTerm = req.get_param("searchTerm")
|
| 18088 |
kshitij.so |
1646 |
result = Mongo.getCountForSearchText(subCategoryIds, searchTerm)
|
| 17928 |
kshitij.so |
1647 |
resp.body = json.dumps(result, encoding='utf-8')
|
| 18090 |
manas |
1648 |
|
|
|
1649 |
class MessageEncryption:
|
|
|
1650 |
|
|
|
1651 |
def on_get(self,req,resp):
|
|
|
1652 |
message_type = req.get_param("type")
|
| 18093 |
manas |
1653 |
if message_type == 'encrypt':
|
| 18090 |
manas |
1654 |
encryption_data = req.get_param("data")
|
| 18101 |
manas |
1655 |
encrypted_data = encryptMessage(base64.decodestring(encryption_data))
|
| 18090 |
manas |
1656 |
resp.body = json.dumps({"result":{"value":encrypted_data}}, encoding='utf-8')
|
|
|
1657 |
|
| 18093 |
manas |
1658 |
elif message_type == 'decrypt':
|
| 18090 |
manas |
1659 |
decryption_data = req.get_param("data")
|
|
|
1660 |
decrypted_data = decryptMessage(decryption_data)
|
|
|
1661 |
resp.body = json.dumps({"result":{"value":decrypted_data}}, encoding='utf-8')
|
|
|
1662 |
|
|
|
1663 |
else:
|
|
|
1664 |
resp.body = json.dumps({}, encoding='utf-8')
|
| 18256 |
manas |
1665 |
|
|
|
1666 |
class GetUserCrmApplication:
|
| 19442 |
manas |
1667 |
|
| 18256 |
manas |
1668 |
def on_get(self,req,resp):
|
| 18329 |
manas |
1669 |
global USER_DETAIL_MAP
|
| 18256 |
manas |
1670 |
project_name = req.get_param("project_name")
|
| 18329 |
manas |
1671 |
USER_DETAIL_MAP[project_name]+=1
|
| 18386 |
manas |
1672 |
lgr.info( "USER_DETAIL_CALL_COUNTER " + str(USER_DETAIL_MAP[project_name]))
|
| 18329 |
manas |
1673 |
retryFlag=False
|
|
|
1674 |
if USER_DETAIL_MAP[project_name] % TOTAL_USER >= USER_CRM_DEFAULT_FRESH_FACTOR:
|
|
|
1675 |
retryFlag=True
|
|
|
1676 |
if project_name == 'accs_cart':
|
| 18792 |
manas |
1677 |
project_id=1
|
|
|
1678 |
elif project_name == 'accs_active':
|
|
|
1679 |
project_id=2
|
|
|
1680 |
elif project_name == 'accs_order':
|
|
|
1681 |
project_id=3
|
| 19442 |
manas |
1682 |
elif project_name == 'accs_cashback_scheme':
|
|
|
1683 |
project_id=4
|
| 18792 |
manas |
1684 |
if retryFlag:
|
|
|
1685 |
user = self.getRetryUser(project_id)
|
|
|
1686 |
else:
|
|
|
1687 |
user = self.getNewUser(project_id)
|
|
|
1688 |
|
|
|
1689 |
if user is None:
|
|
|
1690 |
resp.body ={}
|
|
|
1691 |
else:
|
|
|
1692 |
user.status = 'assigned'
|
|
|
1693 |
user.agent_id = req.get_param("agent_id")
|
|
|
1694 |
user.counter=1
|
|
|
1695 |
user.modified = datetime.now()
|
|
|
1696 |
session.commit()
|
|
|
1697 |
resp.body = json.dumps(todict(getUserObject(user)), encoding='utf-8')
|
|
|
1698 |
session.close()
|
| 18620 |
manas |
1699 |
|
| 18329 |
manas |
1700 |
def getRetryUser(self,projectId,failback=True):
|
|
|
1701 |
status = "retry"
|
| 18367 |
manas |
1702 |
user = session.query(UserCrmCallingData).filter_by(status=status,project_id=projectId).filter(UserCrmCallingData.next_call_time<=datetime.now()).filter(~(UserCrmCallingData.contact1).like('')).order_by(UserCrmCallingData.next_call_time).with_lockmode("update").first()
|
| 18329 |
manas |
1703 |
|
|
|
1704 |
if user is not None:
|
| 18334 |
manas |
1705 |
lgr.info( "getRetryUser " + str(user.id))
|
| 18329 |
manas |
1706 |
else:
|
|
|
1707 |
if failback:
|
| 18334 |
manas |
1708 |
user = self.getNewUser(projectId,False)
|
| 18329 |
manas |
1709 |
return user
|
|
|
1710 |
else:
|
|
|
1711 |
return None
|
|
|
1712 |
return user
|
| 18291 |
manas |
1713 |
|
| 18329 |
manas |
1714 |
|
| 18331 |
manas |
1715 |
def getNewUser(self,projectId,failback=True):
|
| 18329 |
manas |
1716 |
user = None
|
|
|
1717 |
try:
|
| 18416 |
manas |
1718 |
user = session.query(UserCrmCallingData).filter_by(project_id=projectId).filter(UserCrmCallingData.status=='new').filter(UserCrmCallingData.pincode_servicable==True).filter(UserCrmCallingData.user_available==0).filter(UserCrmCallingData.contact1!=None).filter(~(UserCrmCallingData.contact1).like('')).order_by(UserCrmCallingData.next_call_time).order_by(UserCrmCallingData.id).with_lockmode("update").first()
|
| 18334 |
manas |
1719 |
if user is None:
|
|
|
1720 |
insertUserCrmData(projectId)
|
| 18416 |
manas |
1721 |
user = session.query(UserCrmCallingData).filter_by(project_id=projectId).filter(UserCrmCallingData.status=='new').filter(UserCrmCallingData.pincode_servicable==True).filter(~(UserCrmCallingData.contact1).like('')).filter(UserCrmCallingData.user_available==0).filter(UserCrmCallingData.contact1!=None).order_by(UserCrmCallingData.next_call_time).order_by(UserCrmCallingData.id).with_lockmode("update").first()
|
| 18334 |
manas |
1722 |
if user is not None:
|
|
|
1723 |
lgr.info( "getNewUser " + str(user.id))
|
|
|
1724 |
else:
|
|
|
1725 |
if failback:
|
|
|
1726 |
user = self.getRetryUser(projectId,False)
|
|
|
1727 |
return user
|
|
|
1728 |
else:
|
|
|
1729 |
return None
|
| 18329 |
manas |
1730 |
except:
|
|
|
1731 |
print traceback.print_exc()
|
|
|
1732 |
return user
|
| 18386 |
manas |
1733 |
|
| 18291 |
manas |
1734 |
def on_post(self, req, resp):
|
|
|
1735 |
returned = False
|
|
|
1736 |
self.agentId = req.get_param("agent_id")
|
|
|
1737 |
project_name = req.get_param("project_name")
|
| 18637 |
manas |
1738 |
|
| 18329 |
manas |
1739 |
if project_name == 'accs_cart':
|
| 18637 |
manas |
1740 |
project_id=1
|
|
|
1741 |
elif project_name == 'accs_active':
|
|
|
1742 |
project_id=2
|
|
|
1743 |
elif project_name == 'accs_order':
|
|
|
1744 |
project_id=3
|
| 19442 |
manas |
1745 |
elif project_name == 'accs_cashback_scheme':
|
|
|
1746 |
project_id=4
|
|
|
1747 |
|
| 18637 |
manas |
1748 |
jsonReq = json.loads(req.stream.read(), encoding='utf-8')
|
|
|
1749 |
lgr.info( "Request ----\n" + str(jsonReq))
|
|
|
1750 |
self.jsonReq = jsonReq
|
|
|
1751 |
self.callType="default"
|
|
|
1752 |
callLaterAccs = self.callLaterAccs
|
|
|
1753 |
accsDisposition = self.accsDisposition
|
|
|
1754 |
accsOrderDisposition=self.accsOrderDisposition
|
|
|
1755 |
self.userId = int(jsonReq.get('user_id'))
|
|
|
1756 |
try:
|
|
|
1757 |
self.user = session.query(UserCrmCallingData).filter_by(user_id=self.userId).filter(UserCrmCallingData.project_id==project_id).first()
|
|
|
1758 |
self.callDisposition = jsonReq.get('calldispositiontype')
|
|
|
1759 |
self.callHistoryCrm = CallHistoryCrm()
|
|
|
1760 |
self.callHistoryCrm.agent_id=self.agentId
|
|
|
1761 |
self.callHistoryCrm.project_id = project_id
|
|
|
1762 |
self.callHistoryCrm.call_disposition = self.callDisposition
|
|
|
1763 |
self.callHistoryCrm.user_id=self.userId
|
|
|
1764 |
self.callHistoryCrm.duration_sec = int(jsonReq.get("callduration"))
|
|
|
1765 |
self.callHistoryCrm.disposition_comments = jsonReq.get('calldispositioncomments')
|
|
|
1766 |
self.callHistoryCrm.call_time = datetime.strptime(jsonReq.get("calltime"), '%d/%m/%Y %H:%M:%S')
|
|
|
1767 |
self.callHistoryCrm.mobile_number = jsonReq.get('number')
|
|
|
1768 |
self.inputs = jsonReq.get("inputs")
|
|
|
1769 |
dispositionMap = { 'call_later':callLaterAccs,
|
|
|
1770 |
'ringing_no_answer':callLaterAccs,
|
|
|
1771 |
'not_reachable':callLaterAccs,
|
|
|
1772 |
'switch_off':callLaterAccs,
|
|
|
1773 |
'technical_issue':accsDisposition,
|
|
|
1774 |
'pricing_issue':accsDisposition,
|
|
|
1775 |
'shipping_issue':accsDisposition,
|
|
|
1776 |
'internet_issue':accsDisposition,
|
|
|
1777 |
'checking_price':accsDisposition,
|
|
|
1778 |
'order_process':accsDisposition,
|
|
|
1779 |
'placed_order':accsDisposition,
|
|
|
1780 |
'place_order':accsDisposition,
|
|
|
1781 |
'product_availability':accsOrderDisposition,
|
|
|
1782 |
'return_replacement':accsOrderDisposition,
|
|
|
1783 |
'already_purchased':accsOrderDisposition,
|
|
|
1784 |
'product_quality_issue':accsOrderDisposition,
|
|
|
1785 |
'delayed_delivery':accsOrderDisposition,
|
| 18671 |
manas |
1786 |
'other_complaint':accsOrderDisposition,
|
| 19442 |
manas |
1787 |
'scheme_not_clear':accsOrderDisposition,
|
| 18671 |
manas |
1788 |
'not_dealing_accessories':accsOrderDisposition
|
| 18637 |
manas |
1789 |
}
|
|
|
1790 |
returned = dispositionMap[jsonReq.get('calldispositiontype')]()
|
|
|
1791 |
finally:
|
|
|
1792 |
session.close()
|
|
|
1793 |
|
|
|
1794 |
if returned:
|
|
|
1795 |
resp.body = "{\"result\":\"success\"}"
|
|
|
1796 |
else:
|
|
|
1797 |
resp.body = "{\"result\":\"failed\"}"
|
|
|
1798 |
|
| 18628 |
manas |
1799 |
def accsOrderDisposition(self):
|
|
|
1800 |
self.user.status='done'
|
|
|
1801 |
self.user.user_available = 1
|
|
|
1802 |
self.user.disposition=self.callDisposition
|
|
|
1803 |
self.user.modified = datetime.now()
|
| 18712 |
manas |
1804 |
a = CrmTicketDtr()
|
| 18628 |
manas |
1805 |
if self.callDisposition == 'product_availability':
|
|
|
1806 |
self.callHistoryCrm.disposition_description='Product Not available'
|
|
|
1807 |
elif self.callDisposition == 'return_replacement':
|
|
|
1808 |
self.callHistoryCrm.disposition_description='Return or replacement pending'
|
| 18923 |
manas |
1809 |
#utils.sendCrmProjectMail(self.userId,self.callHistoryCrm.disposition_description,self.callHistoryCrm.disposition_comments)
|
| 18713 |
manas |
1810 |
a.addTicket(self.userId, self.callHistoryCrm.disposition_description, self.callHistoryCrm.disposition_comments)
|
| 18628 |
manas |
1811 |
elif self.callDisposition == 'already_purchased':
|
|
|
1812 |
self.callHistoryCrm.disposition_description='Already purchased required stock'
|
| 19442 |
manas |
1813 |
elif self.callDisposition == 'scheme_not_clear':
|
|
|
1814 |
self.callHistoryCrm.disposition_description='Scheme Not Clear to the User'
|
| 18628 |
manas |
1815 |
elif self.callDisposition == 'product_quality_issue':
|
|
|
1816 |
self.callHistoryCrm.disposition_description='Product Quality issue'
|
| 18923 |
manas |
1817 |
#utils.sendCrmProjectMail(self.userId,self.callHistoryCrm.disposition_description,self.callHistoryCrm.disposition_comments)
|
| 18713 |
manas |
1818 |
a.addTicket(self.userId, self.callHistoryCrm.disposition_description, self.callHistoryCrm.disposition_comments)
|
| 18628 |
manas |
1819 |
elif self.callDisposition == 'delayed_delivery':
|
| 18637 |
manas |
1820 |
self.callHistoryCrm.disposition_description='Delayed Delivery'
|
| 18923 |
manas |
1821 |
#utils.sendCrmProjectMail(self.userId,self.callHistoryCrm.disposition_description,self.callHistoryCrm.disposition_comments)
|
| 18713 |
manas |
1822 |
a.addTicket(self.userId, self.callHistoryCrm.disposition_description, self.callHistoryCrm.disposition_comments)
|
| 18628 |
manas |
1823 |
elif self.callDisposition == 'other_complaint':
|
| 18637 |
manas |
1824 |
self.callHistoryCrm.disposition_description='Other complaint with profitmandi'
|
| 18923 |
manas |
1825 |
#utils.sendCrmProjectMail(self.userId,self.callHistoryCrm.disposition_description,self.callHistoryCrm.disposition_comments)
|
| 18713 |
manas |
1826 |
a.addTicket(self.userId, self.callHistoryCrm.disposition_description, self.callHistoryCrm.disposition_comments)
|
| 18671 |
manas |
1827 |
elif self.callDisposition == 'not_dealing_accessories':
|
|
|
1828 |
self.callHistoryCrm.disposition_description='Not Dealing in Accessories/Not Interested'
|
| 18628 |
manas |
1829 |
session.commit()
|
|
|
1830 |
jdata = self.inputs
|
|
|
1831 |
jdata = json.loads(jdata)
|
|
|
1832 |
if jdata:
|
|
|
1833 |
for d in jdata:
|
|
|
1834 |
for key, value in d.iteritems():
|
|
|
1835 |
productpricingInputs = ProductPricingInputs()
|
|
|
1836 |
productpricingInputs.user_id = self.callHistoryCrm.user_id
|
|
|
1837 |
productpricingInputs.agent_id = self.callHistoryCrm.agent_id
|
|
|
1838 |
productpricingInputs.disposition_id = self.callHistoryCrm.id
|
|
|
1839 |
productpricingInputs.user_id = self.callHistoryCrm.user_id
|
|
|
1840 |
productpricingInputs.call_disposition = self.callHistoryCrm.call_disposition
|
|
|
1841 |
productpricingInputs.project_id = self.callHistoryCrm.project_id
|
|
|
1842 |
productpricingInputs.product_input = key
|
|
|
1843 |
productpricingInputs.pricing_input = value
|
|
|
1844 |
session.commit()
|
|
|
1845 |
return True
|
|
|
1846 |
|
| 18291 |
manas |
1847 |
def accsDisposition(self):
|
|
|
1848 |
self.user.status='done'
|
|
|
1849 |
self.user.user_available = 1
|
|
|
1850 |
self.user.disposition=self.callDisposition
|
|
|
1851 |
self.user.modified = datetime.now()
|
|
|
1852 |
if self.callDisposition == 'technical_issue':
|
|
|
1853 |
self.callHistoryCrm.disposition_description='Technical issue at Profitmandi'
|
| 18923 |
manas |
1854 |
#utils.sendCrmProjectMail(self.userId,self.callHistoryCrm.disposition_description,self.callHistoryCrm.disposition_comments)
|
| 18716 |
manas |
1855 |
a = CrmTicketDtr()
|
|
|
1856 |
a.addTicket(self.userId, self.callHistoryCrm.disposition_description, self.callHistoryCrm.disposition_comments)
|
| 18291 |
manas |
1857 |
elif self.callDisposition == 'pricing_issue':
|
|
|
1858 |
self.callHistoryCrm.disposition_description='Pricing Issue(High)'
|
|
|
1859 |
elif self.callDisposition == 'shipping_issue':
|
|
|
1860 |
self.callHistoryCrm.disposition_description='Shipping charges related issue'
|
|
|
1861 |
elif self.callDisposition == 'internet_issue':
|
|
|
1862 |
self.callHistoryCrm.disposition_description='Internet issue at user end'
|
|
|
1863 |
elif self.callDisposition == 'checking_price':
|
|
|
1864 |
self.callHistoryCrm.disposition_description='Checking price'
|
|
|
1865 |
elif self.callDisposition == 'order_process':
|
|
|
1866 |
self.callHistoryCrm.disposition_description='Order Process inquery'
|
|
|
1867 |
elif self.callDisposition == 'placed_order':
|
|
|
1868 |
self.callHistoryCrm.disposition_description='Placed Order from Different Account'
|
|
|
1869 |
elif self.callDisposition == 'place_order':
|
|
|
1870 |
self.callHistoryCrm.disposition_description='Will Place Order'
|
|
|
1871 |
session.commit()
|
| 18360 |
manas |
1872 |
jdata = self.inputs
|
| 18361 |
manas |
1873 |
jdata = json.loads(jdata)
|
| 18350 |
manas |
1874 |
if jdata:
|
|
|
1875 |
for d in jdata:
|
| 18360 |
manas |
1876 |
for key, value in d.iteritems():
|
| 18350 |
manas |
1877 |
productpricingInputs = ProductPricingInputs()
|
|
|
1878 |
productpricingInputs.user_id = self.callHistoryCrm.user_id
|
|
|
1879 |
productpricingInputs.agent_id = self.callHistoryCrm.agent_id
|
|
|
1880 |
productpricingInputs.disposition_id = self.callHistoryCrm.id
|
|
|
1881 |
productpricingInputs.user_id = self.callHistoryCrm.user_id
|
|
|
1882 |
productpricingInputs.call_disposition = self.callHistoryCrm.call_disposition
|
|
|
1883 |
productpricingInputs.project_id = self.callHistoryCrm.project_id
|
|
|
1884 |
productpricingInputs.product_input = key
|
|
|
1885 |
productpricingInputs.pricing_input = value
|
|
|
1886 |
session.commit()
|
| 18291 |
manas |
1887 |
return True
|
|
|
1888 |
|
|
|
1889 |
def callLaterAccs(self):
|
| 18329 |
manas |
1890 |
self.user.status='retry'
|
|
|
1891 |
self.user.modified = datetime.now()
|
| 18291 |
manas |
1892 |
if self.callDisposition == 'call_later':
|
| 18310 |
manas |
1893 |
if self.callHistoryCrm.disposition_comments is not None:
|
| 18321 |
manas |
1894 |
self.user.next_call_time = datetime.strptime(self.callHistoryCrm.disposition_comments, '%d/%m/%Y %H:%M:%S')
|
| 18310 |
manas |
1895 |
self.callHistoryCrm.disposition_description = 'User requested to call'
|
|
|
1896 |
self.callHistoryCrm.disposition_comments = self.callHistoryCrm.disposition_comments
|
| 18291 |
manas |
1897 |
else:
|
|
|
1898 |
self.user.next_call_time = self.callHistoryCrm.call_time + timedelta(days=1)
|
| 18310 |
manas |
1899 |
self.callHistoryCrm.disposition_description = 'Call Scheduled'
|
|
|
1900 |
self.callHistoryCrm.disposition_comments = datetime.strftime(self.user.next_call_time, '%d/%m/%Y %H:%M:%S')
|
| 18291 |
manas |
1901 |
else:
|
| 18310 |
manas |
1902 |
self.callHistoryCrm.disposition_description = 'User was not contactable'
|
| 18291 |
manas |
1903 |
if self.callDisposition == 'ringing_no_answer':
|
|
|
1904 |
if self.user.disposition == 'ringing_no_answer':
|
|
|
1905 |
self.user.retry_count += 1
|
|
|
1906 |
else:
|
|
|
1907 |
self.user.disposition = 'ringing_no_answer'
|
|
|
1908 |
self.user.retry_count = 1
|
|
|
1909 |
else:
|
|
|
1910 |
if self.user.disposition == 'ringing_no_answer':
|
|
|
1911 |
pass
|
|
|
1912 |
else:
|
|
|
1913 |
self.user.disposition = 'not_reachable'
|
|
|
1914 |
self.user.retry_count += 1
|
|
|
1915 |
self.user.invalid_retry_count += 1
|
|
|
1916 |
|
| 18306 |
manas |
1917 |
retryConfig = session.query(RetryConfig).filter_by(call_type=self.callType, disposition_type=self.user.disposition, retry_count=self.user.retry_count).first()
|
|
|
1918 |
if retryConfig is not None:
|
|
|
1919 |
self.user.next_call_time = self.callHistoryCrm.call_time + timedelta(minutes = retryConfig.minutes_ahead)
|
|
|
1920 |
self.callHistoryCrm.disposition_description = 'Call scheduled on ' + datetime.strftime(self.user.next_call_time, '%d/%m/%Y %H:%M:%S')
|
|
|
1921 |
else:
|
|
|
1922 |
self.user.status = 'failed'
|
| 18335 |
manas |
1923 |
self.user.user_available=1
|
| 18306 |
manas |
1924 |
self.callHistoryCrm.disposition_description = 'Call failed as all attempts exhausted'
|
| 18329 |
manas |
1925 |
self.user.disposition=self.callDisposition
|
| 18291 |
manas |
1926 |
session.commit()
|
| 18347 |
manas |
1927 |
jdata =self.inputs
|
| 18361 |
manas |
1928 |
jdata = json.loads(jdata)
|
| 18350 |
manas |
1929 |
if jdata:
|
|
|
1930 |
for d in jdata:
|
| 18360 |
manas |
1931 |
for key, value in d.iteritems():
|
| 18350 |
manas |
1932 |
productpricingInputs = ProductPricingInputs()
|
|
|
1933 |
productpricingInputs.user_id = self.callHistoryCrm.user_id
|
|
|
1934 |
productpricingInputs.agent_id = self.callHistoryCrm.agent_id
|
|
|
1935 |
productpricingInputs.disposition_id = self.callHistoryCrm.id
|
|
|
1936 |
productpricingInputs.user_id = self.callHistoryCrm.user_id
|
|
|
1937 |
productpricingInputs.call_disposition = self.callHistoryCrm.call_disposition
|
|
|
1938 |
productpricingInputs.project_id = self.callHistoryCrm.project_id
|
|
|
1939 |
productpricingInputs.product_input = key
|
|
|
1940 |
productpricingInputs.pricing_input = value
|
|
|
1941 |
session.commit()
|
| 18291 |
manas |
1942 |
return True
|
|
|
1943 |
|
| 18266 |
manas |
1944 |
def insertUserCrmData(project_id):
|
|
|
1945 |
if project_id==1:
|
|
|
1946 |
getCartDetailsUser()
|
| 18386 |
manas |
1947 |
if project_id==2:
|
|
|
1948 |
getCartTabsUser()
|
| 18620 |
manas |
1949 |
if project_id==3:
|
|
|
1950 |
getAccsRepeatUsers(project_id)
|
| 19442 |
manas |
1951 |
if project_id==4:
|
|
|
1952 |
getAccsSchemeCashback(project_id)
|
|
|
1953 |
|
|
|
1954 |
def getAccsSchemeCashback(project_id):
|
|
|
1955 |
userMasterMap={}
|
|
|
1956 |
skipUserList=[]
|
| 19444 |
manas |
1957 |
query = "select id from users where lower(referrer) in ('emp01','emp99','emp88')"
|
| 19442 |
manas |
1958 |
skipUsersresult = fetchResult(query)
|
|
|
1959 |
for skipUser in skipUsersresult:
|
|
|
1960 |
skipUserList.append(skipUser[0])
|
|
|
1961 |
queryFilter = {"user_id":{"$nin":skipUserList}}
|
|
|
1962 |
result = get_mongo_connection().Catalog.PromoOffer.find(queryFilter)
|
|
|
1963 |
userMasterList =[]
|
|
|
1964 |
for r in result:
|
|
|
1965 |
userMasterList.append(r.get('user_id'))
|
|
|
1966 |
queryfilter ={"url":{"$regex" : "http://api.profittill.com/categories/target"}}
|
|
|
1967 |
result = get_mongo_connection_dtr_data().User.browsinghistories.find(queryfilter).distinct('user_id')
|
|
|
1968 |
userSeenList=[]
|
|
|
1969 |
for r in result:
|
|
|
1970 |
userSeenList.append(r)
|
|
|
1971 |
finalUserList = list(set(userMasterList) - set(userSeenList))
|
|
|
1972 |
queryFilter = {"user_id":{"$in":finalUserList}}
|
|
|
1973 |
result = get_mongo_connection().Catalog.PromoOffer.find(queryFilter)
|
|
|
1974 |
for r in result:
|
|
|
1975 |
userMasterMap[r.get('user_id')] = r.get('target2')
|
|
|
1976 |
d_sorted = sorted(zip(userMasterMap.values(), userMasterMap.keys()),reverse=True)
|
|
|
1977 |
counter=0
|
|
|
1978 |
for i in d_sorted:
|
|
|
1979 |
try:
|
|
|
1980 |
userId=i[1]
|
|
|
1981 |
if counter==20:
|
|
|
1982 |
break
|
|
|
1983 |
userPresent = session.query(UserCrmCallingData).filter_by(user_id=userId).order_by(desc(UserCrmCallingData.modified)).first()
|
|
|
1984 |
if userPresent is not None:
|
|
|
1985 |
if userPresent.user_available==1:
|
|
|
1986 |
if userPresent.project_id==project_id:
|
|
|
1987 |
continue
|
|
|
1988 |
elif userPresent.modified.date()>=(datetime.now().date()-timedelta(days=30)):
|
|
|
1989 |
continue
|
|
|
1990 |
else:
|
|
|
1991 |
continue
|
|
|
1992 |
counter=counter+1
|
|
|
1993 |
userMasterData = UserCrmCallingData()
|
|
|
1994 |
userMasterData.user_id = userId
|
|
|
1995 |
userMasterData.name =getUsername(userId)
|
|
|
1996 |
userMasterData.project_id = project_id
|
|
|
1997 |
userMasterData.user_available=0
|
|
|
1998 |
userMasterData.contact1 = getUserContactDetails(userId)
|
|
|
1999 |
userMasterData.counter = 0
|
|
|
2000 |
userMasterData.retry_count=0
|
|
|
2001 |
userMasterData.invalid_retry_count=0
|
|
|
2002 |
userMasterData.created = datetime.now()
|
|
|
2003 |
userMasterData.modified = datetime.now()
|
|
|
2004 |
userMasterData.status = 'new'
|
|
|
2005 |
userMasterData.pincode_servicable = checkPincodeServicable(userId)
|
|
|
2006 |
session.commit()
|
|
|
2007 |
except:
|
|
|
2008 |
print traceback.print_exc()
|
|
|
2009 |
finally:
|
|
|
2010 |
session.close()
|
|
|
2011 |
|
| 18620 |
manas |
2012 |
def getAccsRepeatUsers(project_id):
|
|
|
2013 |
|
|
|
2014 |
usersMasterList=[]
|
|
|
2015 |
ACCS_ALL_ORDERS = "select distinct user_id from allorder where category in ('Accs','Accessories') and store_id='spice';"
|
|
|
2016 |
result = fetchResult(ACCS_ALL_ORDERS)
|
|
|
2017 |
for r in result:
|
|
|
2018 |
usersMasterList.append(r[0])
|
|
|
2019 |
|
|
|
2020 |
ACCS_LAST_FIFTEEN_DAYS = "select distinct user_id from allorder where category in ('Accs','Accessories') and store_id='spice' and (date(created_on) between date(curdate() - interval 15 day) and date(curdate())) order by user_id;"
|
|
|
2021 |
result = fetchResult(ACCS_LAST_FIFTEEN_DAYS)
|
|
|
2022 |
for r in result:
|
|
|
2023 |
if r[0] in usersMasterList:
|
|
|
2024 |
usersMasterList.remove(r[0])
|
|
|
2025 |
|
|
|
2026 |
PRIOPRITIZING_USER_QUERY = "select user_id from allorder where category in ('Accs','Accessories')and store_id ='spice' and user_id in (%s)" % ",".join(map(str,usersMasterList)) + "group by user_id order by sum(amount_paid) desc;"
|
|
|
2027 |
userFinalList=[]
|
|
|
2028 |
result = fetchResult(PRIOPRITIZING_USER_QUERY)
|
|
|
2029 |
for r in result:
|
|
|
2030 |
userFinalList.append(r[0])
|
|
|
2031 |
|
|
|
2032 |
counter=0
|
|
|
2033 |
for i in userFinalList:
|
|
|
2034 |
try:
|
|
|
2035 |
userId=i
|
| 18628 |
manas |
2036 |
if counter==20:
|
| 18620 |
manas |
2037 |
break
|
|
|
2038 |
userPresent = session.query(UserCrmCallingData).filter_by(user_id=userId).order_by(desc(UserCrmCallingData.modified)).first()
|
|
|
2039 |
if userPresent is not None:
|
|
|
2040 |
if userPresent.user_available==1:
|
|
|
2041 |
if userPresent.project_id==project_id:
|
|
|
2042 |
if userPresent.modified.date()>=(datetime.now().date()-timedelta(days=30)):
|
|
|
2043 |
continue
|
|
|
2044 |
else:
|
|
|
2045 |
pass
|
| 18792 |
manas |
2046 |
elif userPresent.modified.date()>=(datetime.now().date()-timedelta(days=30)):
|
| 18620 |
manas |
2047 |
continue
|
|
|
2048 |
else:
|
|
|
2049 |
continue
|
|
|
2050 |
counter=counter+1
|
|
|
2051 |
userMasterData = UserCrmCallingData()
|
|
|
2052 |
userMasterData.user_id = userId
|
|
|
2053 |
userMasterData.name =getUsername(userId)
|
|
|
2054 |
userMasterData.project_id = project_id
|
|
|
2055 |
userMasterData.user_available=0
|
|
|
2056 |
userMasterData.contact1 = getUserContactDetails(userId)
|
|
|
2057 |
userMasterData.counter = 0
|
|
|
2058 |
userMasterData.retry_count=0
|
|
|
2059 |
userMasterData.invalid_retry_count=0
|
|
|
2060 |
userMasterData.created = datetime.now()
|
|
|
2061 |
userMasterData.modified = datetime.now()
|
|
|
2062 |
userMasterData.status = 'new'
|
|
|
2063 |
userMasterData.pincode_servicable = checkPincodeServicable(userId)
|
|
|
2064 |
session.commit()
|
|
|
2065 |
except:
|
|
|
2066 |
print traceback.print_exc()
|
|
|
2067 |
finally:
|
|
|
2068 |
session.close()
|
|
|
2069 |
|
| 18256 |
manas |
2070 |
def getCartDetailsUser():
|
|
|
2071 |
userList=[]
|
|
|
2072 |
orderUserList=[]
|
| 18818 |
manas |
2073 |
#userMasterMap={}
|
| 18256 |
manas |
2074 |
queryfilter = {"$and":
|
|
|
2075 |
[
|
| 18792 |
manas |
2076 |
{'created':{"$gte":(to_java_date(datetime.now())-3*86400000)}},
|
| 18256 |
manas |
2077 |
{'created':{"$lte":(to_java_date(datetime.now())- 43200000)}},
|
|
|
2078 |
{"url":{"$regex" : "http://api.profittill.com/cartdetails"}}
|
|
|
2079 |
]
|
|
|
2080 |
}
|
|
|
2081 |
result = get_mongo_connection_dtr_data().User.browsinghistories.find(queryfilter).distinct('user_id')
|
|
|
2082 |
|
|
|
2083 |
for r in result:
|
|
|
2084 |
userList.append(r)
|
|
|
2085 |
|
| 18301 |
manas |
2086 |
myquery = "select a.user_id from allorder a join users u on a.user_id=u.id where a.store_id='spice' and (a.category='Accs' or a.category='Accessories') and u.referrer not like 'emp%%' and u.mobile_number IS NOT NULL and a.user_id in (%s)" % ",".join(map(str,userList)) + " UNION select id from users where lower(referrer) like 'emp%'"
|
|
|
2087 |
|
| 18256 |
manas |
2088 |
result = fetchResult(myquery)
|
|
|
2089 |
for r in result:
|
| 18301 |
manas |
2090 |
orderUserList.append(r[0])
|
| 18256 |
manas |
2091 |
finalUserList = list(set(userList) - set(orderUserList))
|
|
|
2092 |
|
| 18792 |
manas |
2093 |
userCartIdMap={}
|
|
|
2094 |
fetchCartId = "select user_id,account_key from user_accounts where account_type='cartId' and user_id in (%s)" % ",".join(map(str,finalUserList))
|
|
|
2095 |
result = fetchResult(fetchCartId)
|
|
|
2096 |
for r in result:
|
| 18818 |
manas |
2097 |
userCartIdMap[long(r[1])] = long(r[0])
|
| 18843 |
manas |
2098 |
client = CatalogClient("catalog_service_server_host_prod","catalog_service_server_port").get_client()
|
| 18792 |
manas |
2099 |
userMapReturned = client.getCartByValue(userCartIdMap.keys())
|
| 18818 |
manas |
2100 |
userFinalList=[]
|
|
|
2101 |
for i in userMapReturned:
|
|
|
2102 |
userFinalList.append(userCartIdMap.get(i))
|
| 18792 |
manas |
2103 |
# queryfilternew = {"$and":
|
|
|
2104 |
# [
|
|
|
2105 |
# {'user_id':{"$in":finalUserList}},
|
|
|
2106 |
# {'created':{"$gte":(to_java_date(datetime.now())-2*86400000)}},
|
|
|
2107 |
# {'created':{"$lte":(to_java_date(datetime.now())- 43200000)}},
|
|
|
2108 |
# {"url":{"$regex" : "http://api.profittill.com/cartdetails"}}
|
|
|
2109 |
# ]
|
|
|
2110 |
# }
|
|
|
2111 |
# itemIds = list(get_mongo_connection_dtr_data().User.browsinghistories.find(queryfilternew))
|
|
|
2112 |
#
|
|
|
2113 |
# for i in itemIds:
|
|
|
2114 |
# if(userMasterMap.has_key(i.get('user_id'))):
|
|
|
2115 |
# if userMasterMap.get(i.get('user_id')) > i.get('created'):
|
|
|
2116 |
# userMasterMap[i.get('user_id')]=i.get('created')
|
|
|
2117 |
# else:
|
|
|
2118 |
# userMasterMap[i.get('user_id')]=i.get('created')
|
|
|
2119 |
#
|
|
|
2120 |
# d_sorted = sorted(zip(userMasterMap.values(), userMasterMap.keys()))
|
| 18818 |
manas |
2121 |
addUserToTable(userFinalList,1)
|
| 18256 |
manas |
2122 |
|
| 18301 |
manas |
2123 |
def addUserToTable(userList,projectId):
|
| 18266 |
manas |
2124 |
counter=0
|
| 18301 |
manas |
2125 |
for i in userList:
|
|
|
2126 |
try:
|
| 18792 |
manas |
2127 |
userId=i
|
| 18412 |
manas |
2128 |
if counter==20:
|
| 18301 |
manas |
2129 |
break
|
|
|
2130 |
userPresent = session.query(UserCrmCallingData).filter_by(user_id=userId).order_by(desc(UserCrmCallingData.modified)).first()
|
|
|
2131 |
if userPresent is not None:
|
|
|
2132 |
if userPresent.user_available==1:
|
|
|
2133 |
if userPresent.project_id==projectId:
|
|
|
2134 |
continue
|
| 18792 |
manas |
2135 |
elif userPresent.modified.date()>=(datetime.now().date()-timedelta(days=30)):
|
| 18301 |
manas |
2136 |
continue
|
| 18306 |
manas |
2137 |
else:
|
|
|
2138 |
continue
|
| 18266 |
manas |
2139 |
counter=counter+1
|
|
|
2140 |
userMasterData = UserCrmCallingData()
|
|
|
2141 |
userMasterData.user_id = userId
|
|
|
2142 |
userMasterData.name =getUsername(userId)
|
| 18301 |
manas |
2143 |
userMasterData.project_id = projectId
|
| 18277 |
manas |
2144 |
userMasterData.user_available=0
|
| 18266 |
manas |
2145 |
userMasterData.contact1 = getUserContactDetails(userId)
|
|
|
2146 |
userMasterData.counter = 0
|
| 18318 |
manas |
2147 |
userMasterData.retry_count=0
|
|
|
2148 |
userMasterData.invalid_retry_count=0
|
| 18266 |
manas |
2149 |
userMasterData.created = datetime.now()
|
|
|
2150 |
userMasterData.modified = datetime.now()
|
|
|
2151 |
userMasterData.status = 'new'
|
|
|
2152 |
userMasterData.pincode_servicable = checkPincodeServicable(userId)
|
|
|
2153 |
session.commit()
|
| 18301 |
manas |
2154 |
except:
|
|
|
2155 |
print traceback.print_exc()
|
|
|
2156 |
finally:
|
|
|
2157 |
session.close()
|
|
|
2158 |
|
| 18256 |
manas |
2159 |
def getCartTabsUser():
|
| 18346 |
manas |
2160 |
userMasterList=[]
|
|
|
2161 |
userList = []
|
| 18256 |
manas |
2162 |
userMasterMap={}
|
|
|
2163 |
queryfilter = {"$and":
|
|
|
2164 |
[
|
|
|
2165 |
{'created':{"$gte":(to_java_date(datetime.now())-2*86400000)}},
|
|
|
2166 |
{'created':{"$lte":(to_java_date(datetime.now())- 43200000)}},
|
|
|
2167 |
{"url":{"$regex" : "http://api.profittill.com/category/6"}}
|
|
|
2168 |
]
|
|
|
2169 |
}
|
|
|
2170 |
result = get_mongo_connection_dtr_data().User.browsinghistories.find(queryfilter).distinct('user_id')
|
|
|
2171 |
|
|
|
2172 |
for r in result:
|
| 18346 |
manas |
2173 |
userMasterList.append(r)
|
|
|
2174 |
|
|
|
2175 |
queryfilterVisistedCart = {"$and":
|
|
|
2176 |
[
|
| 18386 |
manas |
2177 |
{'user_id':{"$in":userMasterList}},
|
| 18346 |
manas |
2178 |
{"url":{"$regex" : "http://api.profittill.com/cartdetails"}}
|
|
|
2179 |
]
|
|
|
2180 |
}
|
| 18386 |
manas |
2181 |
result = get_mongo_connection_dtr_data().User.browsinghistories.find(queryfilterVisistedCart).distinct('user_id')
|
| 18346 |
manas |
2182 |
for r in result:
|
| 18256 |
manas |
2183 |
userList.append(r)
|
|
|
2184 |
|
| 18416 |
manas |
2185 |
myquery = "select user_id from allorder where store_id='spice' and (category='Accs' or category='Accessories') and user_id in (%s)" % ",".join(map(str,userMasterList)) + " UNION select id from users where lower(referrer) like 'emp%'"
|
| 18256 |
manas |
2186 |
|
|
|
2187 |
result = fetchResult(myquery)
|
|
|
2188 |
for r in result:
|
| 18346 |
manas |
2189 |
if r[0] in userList:
|
|
|
2190 |
continue
|
|
|
2191 |
userList.append(r[0])
|
| 18386 |
manas |
2192 |
|
| 18346 |
manas |
2193 |
finalUserList = list(set(userMasterList) - set(userList))
|
| 18386 |
manas |
2194 |
|
| 18256 |
manas |
2195 |
queryfilternew = {"$and":
|
|
|
2196 |
[
|
|
|
2197 |
{'user_id':{"$in":finalUserList}},
|
|
|
2198 |
{'created':{"$gte":(to_java_date(datetime.now())-2*86400000)}},
|
|
|
2199 |
{'created':{"$lte":(to_java_date(datetime.now())- 43200000)}},
|
|
|
2200 |
{"url":{"$regex" : "http://api.profittill.com/category/6"}}
|
|
|
2201 |
]
|
|
|
2202 |
}
|
|
|
2203 |
itemIds = list(get_mongo_connection_dtr_data().User.browsinghistories.find(queryfilternew))
|
|
|
2204 |
|
|
|
2205 |
for i in itemIds:
|
|
|
2206 |
if(userMasterMap.has_key(i.get('user_id'))):
|
|
|
2207 |
if userMasterMap.get(i.get('user_id')) > i.get('created'):
|
|
|
2208 |
userMasterMap[i.get('user_id')]=i.get('created')
|
|
|
2209 |
else:
|
|
|
2210 |
userMasterMap[i.get('user_id')]=i.get('created')
|
|
|
2211 |
|
|
|
2212 |
d_sorted = sorted(zip(userMasterMap.values(), userMasterMap.keys()))
|
| 18792 |
manas |
2213 |
userFinalList=[]
|
|
|
2214 |
for i in d_sorted:
|
|
|
2215 |
userFinalList.append(i[1])
|
|
|
2216 |
addUserToTable(userFinalList,2)
|
| 18346 |
manas |
2217 |
|
| 18266 |
manas |
2218 |
def getUserContactDetails(userId):
|
| 18792 |
manas |
2219 |
r = session.query(Users.mobile_number).filter_by(id=userId).first()
|
|
|
2220 |
if r is None:
|
|
|
2221 |
return None
|
|
|
2222 |
else:
|
|
|
2223 |
return r[0]
|
| 18712 |
manas |
2224 |
|
| 18266 |
manas |
2225 |
def getUsername(userId):
|
| 18792 |
manas |
2226 |
r = session.query(Users.first_name).filter_by(id=userId).first()
|
|
|
2227 |
if r is None:
|
|
|
2228 |
return None
|
|
|
2229 |
else:
|
|
|
2230 |
return r[0]
|
|
|
2231 |
|
| 18266 |
manas |
2232 |
def checkPincodeServicable(userId):
|
|
|
2233 |
checkAddressUser = "select distinct pincode from all_user_addresses where user_id= (%s)"
|
|
|
2234 |
result = fetchResult(checkAddressUser,userId)
|
|
|
2235 |
if len(result)==0:
|
|
|
2236 |
return True
|
|
|
2237 |
else:
|
|
|
2238 |
myquery = "select count(*) from (select distinct pincode from all_user_addresses where user_id= (%s))a join pincodeavailability p on a.pincode=p.code"
|
|
|
2239 |
result = fetchResult(myquery,userId)
|
|
|
2240 |
if result[0][0]==0:
|
|
|
2241 |
return False
|
|
|
2242 |
else:
|
|
|
2243 |
return True
|
|
|
2244 |
|
|
|
2245 |
def getUserObject(user):
|
|
|
2246 |
obj = Mock()
|
|
|
2247 |
obj.user_id = user.user_id
|
|
|
2248 |
result = fetchResult("select * from useractive where user_id=%d"%(user.user_id))
|
|
|
2249 |
if result == ():
|
|
|
2250 |
obj.last_active = None
|
|
|
2251 |
else:
|
|
|
2252 |
obj.last_active =datetime.strftime(result[0][1], '%d/%m/%Y %H:%M:%S')
|
| 18269 |
manas |
2253 |
obj.name = user.name
|
| 18266 |
manas |
2254 |
obj.contact = user.contact1
|
| 18275 |
manas |
2255 |
obj.lastOrderTimestamp=None
|
| 18256 |
manas |
2256 |
|
| 18275 |
manas |
2257 |
details = session.query(Orders).filter_by(user_id = user.user_id).filter(~Orders.status.in_(['ORDER_NOT_CREATED_KNOWN','ORDER_NOT_CREATED_UNKNOWN', 'ORDER_ALREADY_CREATED_IGNORED'])).order_by(desc(Orders.created)).first()
|
| 18266 |
manas |
2258 |
if details is None:
|
| 18275 |
manas |
2259 |
obj.lastOrderTimestamp =None
|
| 18266 |
manas |
2260 |
else:
|
| 18366 |
manas |
2261 |
obj.lastOrderTimestamp =datetime.strftime(details.created, '%d/%m/%Y %H:%M:%S')
|
| 18275 |
manas |
2262 |
obj.totalOrders = session.query(Orders).filter_by(user_id = user.user_id).filter(~Orders.status.in_(['ORDER_NOT_CREATED_KNOWN','ORDER_NOT_CREATED_UNKNOWN', 'ORDER_ALREADY_CREATED_IGNORED'])).count()
|
| 18266 |
manas |
2263 |
|
| 18275 |
manas |
2264 |
cartResult = fetchResult("select account_key from user_accounts where account_type ='cartId' and user_id=%d"%(user.user_id))
|
| 18266 |
manas |
2265 |
if cartResult == ():
|
| 18268 |
manas |
2266 |
obj.lastActiveCartTime = None
|
| 18266 |
manas |
2267 |
else:
|
|
|
2268 |
conn = MySQLdb.connect("192.168.190.114", "root","shop2020", "user")
|
|
|
2269 |
cursor = conn.cursor()
|
| 18275 |
manas |
2270 |
cursor.execute("select updated_on from cart where id=%s",(cartResult[0][0]))
|
| 18266 |
manas |
2271 |
result = cursor.fetchall()
|
|
|
2272 |
if result ==():
|
| 18268 |
manas |
2273 |
obj.lastActiveCartTime = None
|
| 18266 |
manas |
2274 |
else:
|
|
|
2275 |
print result
|
| 18275 |
manas |
2276 |
obj.lastActiveCartTime =datetime.strftime(result[0][0], '%d/%m/%Y %H:%M:%S')
|
| 18712 |
manas |
2277 |
conn.close()
|
|
|
2278 |
|
|
|
2279 |
session.close()
|
| 18266 |
manas |
2280 |
return obj
|
|
|
2281 |
|
| 18709 |
manas |
2282 |
class CrmTicketDtr():
|
|
|
2283 |
def on_post(self,req,resp):
|
| 18712 |
manas |
2284 |
try:
|
|
|
2285 |
customerFeedbackBackMap = {}
|
|
|
2286 |
customerFeedbackBackMap['user_id']=req.get_param("user_id")
|
|
|
2287 |
user = session.query(Users).filter_by(id=customerFeedbackBackMap.get('user_id')).first()
|
|
|
2288 |
if user is not None:
|
|
|
2289 |
customerFeedbackBackMap['email']=user.email
|
|
|
2290 |
customerFeedbackBackMap['mobile_number']=user.mobile_number
|
|
|
2291 |
customerFeedbackBackMap['customer_name']=user.first_name + ' ' + user.last_name
|
|
|
2292 |
customerFeedbackBackMap['subject'] = req.get_param("subject")
|
|
|
2293 |
customerFeedbackBackMap['message'] = req.get_param("message")
|
|
|
2294 |
customerFeedbackBackMap['created'] = datetime.now()
|
|
|
2295 |
if utils.generateCrmTicket(customerFeedbackBackMap):
|
|
|
2296 |
resp.body={"result":"success"}
|
|
|
2297 |
else:
|
|
|
2298 |
resp.body={"result":"failure"}
|
| 18709 |
manas |
2299 |
else:
|
| 18712 |
manas |
2300 |
resp.body={"result":"failure"}
|
|
|
2301 |
except:
|
|
|
2302 |
print traceback.print_exc()
|
|
|
2303 |
finally:
|
|
|
2304 |
session.close()
|
| 18709 |
manas |
2305 |
def addTicket(self,user_id,subject,message):
|
| 18712 |
manas |
2306 |
try:
|
|
|
2307 |
customerFeedbackBackMap = {}
|
|
|
2308 |
customerFeedbackBackMap['user_id']=user_id
|
|
|
2309 |
user = session.query(Users).filter_by(id=user_id).first()
|
|
|
2310 |
if user is not None:
|
|
|
2311 |
customerFeedbackBackMap['email']=user.email
|
|
|
2312 |
customerFeedbackBackMap['mobile_number']=user.mobile_number
|
|
|
2313 |
customerFeedbackBackMap['customer_name']=user.first_name + ' ' + user.last_name
|
|
|
2314 |
customerFeedbackBackMap['subject'] = subject
|
|
|
2315 |
customerFeedbackBackMap['message'] = message
|
|
|
2316 |
customerFeedbackBackMap['created'] = datetime.now()
|
| 19651 |
manas |
2317 |
ThriftUtils.generateCrmTicket(customerFeedbackBackMap)
|
| 18712 |
manas |
2318 |
else:
|
|
|
2319 |
print 'User is not present'
|
|
|
2320 |
except:
|
| 18926 |
manas |
2321 |
print traceback.print_exc()
|
|
|
2322 |
|
| 18272 |
kshitij.so |
2323 |
class UnitDeal():
|
|
|
2324 |
def on_get(self,req,resp, id):
|
|
|
2325 |
result = Mongo.getDealById(id)
|
|
|
2326 |
resp.body = dumps(result)
|
| 19290 |
kshitij.so |
2327 |
|
|
|
2328 |
class SpecialOffer():
|
|
|
2329 |
def on_get(self,req,resp):
|
|
|
2330 |
user_id = req.get_param_as_int('user_id')
|
|
|
2331 |
result = Mongo.getOfferForUser(user_id)
|
|
|
2332 |
resp.body = dumps(result)
|
| 19388 |
kshitij.so |
2333 |
|
|
|
2334 |
class BrandSubCatFilter():
|
|
|
2335 |
def on_get(self, req, resp):
|
|
|
2336 |
category_id = req.get_param_as_int('category_id')
|
|
|
2337 |
id_list = req.get_param('id_list')
|
|
|
2338 |
type = req.get_param('type')
|
|
|
2339 |
result = Mongo.getBrandSubCategoryInfo(category_id, id_list, type)
|
|
|
2340 |
resp.body = dumps(result)
|
| 19444 |
manas |
2341 |
|
| 19451 |
manas |
2342 |
class RefundAmountWallet():
|
|
|
2343 |
def on_post(self,req,resp):
|
|
|
2344 |
jsonReq = json.loads(req.stream.read(), encoding='utf-8')
|
|
|
2345 |
if Mongo.refundAmountInWallet(jsonReq):
|
|
|
2346 |
resp.body = "{\"result\":\"success\"}"
|
|
|
2347 |
else:
|
|
|
2348 |
resp.body = "{\"result\":\"failed\"}"
|
|
|
2349 |
|
|
|
2350 |
def on_get(self,req,resp):
|
|
|
2351 |
offset = req.get_param_as_int("offset")
|
|
|
2352 |
limit = req.get_param_as_int("limit")
|
|
|
2353 |
status = req.get_param("status")
|
| 19529 |
manas |
2354 |
if status:
|
|
|
2355 |
userRefundDetails = Mongo.fetchCrmRefundUsers(status,offset,limit)
|
|
|
2356 |
else:
|
|
|
2357 |
userRefundDetails = Mongo.fetchCrmRefundUsers(None,offset,limit)
|
| 19454 |
manas |
2358 |
if userRefundDetails is not None:
|
| 19457 |
manas |
2359 |
resp.body = dumps(userRefundDetails)
|
| 19454 |
manas |
2360 |
else:
|
|
|
2361 |
resp.body ="{}"
|
| 19463 |
manas |
2362 |
|
|
|
2363 |
class RefundWalletStatus():
|
|
|
2364 |
def on_post(self,req,resp):
|
|
|
2365 |
status = req.get_param('status')
|
|
|
2366 |
jsonReq = json.loads(req.stream.read(), encoding='utf-8')
|
| 19479 |
manas |
2367 |
user_id = int(jsonReq.get('user_id'))
|
| 19463 |
manas |
2368 |
_id = jsonReq.get('_id')
|
|
|
2369 |
if status == utils.REFUND_ADJUSTMENT_MAP.get(1):
|
| 19475 |
manas |
2370 |
value = int(jsonReq.get('amount'))
|
|
|
2371 |
userAmountMap = {}
|
| 19469 |
manas |
2372 |
datetimeNow = datetime.now()
|
|
|
2373 |
batchId = int(time.mktime(datetimeNow.timetuple()))
|
| 19475 |
manas |
2374 |
userAmountMap[user_id] = value
|
| 19497 |
manas |
2375 |
Mongo.updateCrmWalletStatus(status, _id,user_id,None,None)
|
| 19475 |
manas |
2376 |
if refundToWallet(batchId,userAmountMap):
|
|
|
2377 |
refundType = jsonReq.get('type')
|
| 19497 |
manas |
2378 |
approved_by = jsonReq.get('approved_by')
|
| 19475 |
manas |
2379 |
get_mongo_connection().Dtr.refund.insert({"userId": user_id, "batch":batchId, "userAmount":value, "timestamp":datetime.strftime(datetimeNow,"%Y-%m-%d %H:%M:%S"), "type":refundType})
|
|
|
2380 |
get_mongo_connection().Dtr.user.update({"userId":user_id}, {"$inc": { "credited": value, refundType:value}}, upsert=True)
|
| 19497 |
manas |
2381 |
Mongo.updateCrmWalletStatus(utils.REFUND_ADJUSTMENT_MAP.get(3), _id,user_id,batchId,approved_by)
|
| 19475 |
manas |
2382 |
print user_id,value
|
| 19556 |
manas |
2383 |
Mongo.sendNotification([user_id], 'Batch Credit', 'Cashback Credited for %ss'%(str(refundType)), 'Rs.%s has been added to your wallet'%(value),'url', 'http://api.profittill.com/cashbacks/mine?user_id=%s'%(user_id), '2999-01-01', True, "TRAN_SMS Dear Customer, Cashback Credited for %ss. Rs.%s has been added to your wallet"%(refundType,value))
|
| 19475 |
manas |
2384 |
resp.body = "{\"result\":\"success\"}"
|
|
|
2385 |
else:
|
|
|
2386 |
resp.body = "{\"result\":\"failed\"}"
|
| 19463 |
manas |
2387 |
elif status == utils.REFUND_ADJUSTMENT_MAP.get(2):
|
| 19497 |
manas |
2388 |
Mongo.updateCrmWalletStatus(status, _id,user_id,None,None)
|
| 19469 |
manas |
2389 |
resp.body = "{\"result\":\"success\"}"
|
|
|
2390 |
else:
|
|
|
2391 |
resp.body = "{\"result\":\"failed\"}"
|
| 19485 |
manas |
2392 |
|
|
|
2393 |
class DetailsBatchId():
|
|
|
2394 |
def on_get(self,req,resp):
|
|
|
2395 |
batchId = req.get_param('batchId')
|
|
|
2396 |
userRefundDetails = Mongo.fetchCrmRefundByBatchId(batchId)
|
|
|
2397 |
if userRefundDetails is not None:
|
| 19493 |
manas |
2398 |
resp.body = dumps(list(userRefundDetails))
|
| 19485 |
manas |
2399 |
else:
|
|
|
2400 |
resp.body ="{}"
|
|
|
2401 |
|
| 15312 |
amit.gupta |
2402 |
def main():
|
| 18386 |
manas |
2403 |
a = RetailerDetail()
|
|
|
2404 |
retailer = a.getNotActiveRetailer()
|
|
|
2405 |
otherContacts = [r for r, in session.query(RetailerContacts.mobile_number).filter_by(retailer_id=retailer.id).order_by(RetailerContacts.contact_type).all()]
|
|
|
2406 |
print json.dumps(todict(getRetailerObj(retailer, otherContacts, 'fresh')), encoding='utf-8')
|
| 15195 |
manas |
2407 |
|
| 15081 |
amit.gupta |
2408 |
if __name__ == '__main__':
|
| 18901 |
amit.gupta |
2409 |
#main()
|
| 19484 |
manas |
2410 |
print getTinInfo('07740388453')
|