| Line 49... |
Line 49... |
| 49 |
codesys = [alphalist, alphalist, numList, numList, numList]
|
49 |
codesys = [alphalist, alphalist, numList, numList, numList]
|
| 50 |
newcodesys = alphalist + numList
|
50 |
newcodesys = alphalist + numList
|
| 51 |
CONTACT_PRIORITY = ['sms', 'called', 'ringing']
|
51 |
CONTACT_PRIORITY = ['sms', 'called', 'ringing']
|
| 52 |
RETRY_MAP = {'fresh':'retry', 'followup':'fretry', 'onboarding':'oretry'}
|
52 |
RETRY_MAP = {'fresh':'retry', 'followup':'fretry', 'onboarding':'oretry'}
|
| 53 |
ASSIGN_MAP = {'retry':'assigned', 'fretry':'fassigned', 'oretry':'oassigned'}
|
53 |
ASSIGN_MAP = {'retry':'assigned', 'fretry':'fassigned', 'oretry':'oassigned'}
|
| - |
|
54 |
CRM_PROJECTS_USER_AVAILABILITY = {1:{'cooldown':30, 'isrepeat':True}, 2:{'cooldown':15,'isrepeat': False}, 3:{'cooldown':2,'isrepeat': True}, 5:{'cooldown':15,'isrepeat': True}}
|
| 54 |
|
55 |
|
| 55 |
sticky_agents = [17,29]
|
56 |
sticky_agents = [17,29]
|
| 56 |
|
57 |
|
| 57 |
def getNextRandomCode(newcodesys,size=6):
|
58 |
def getNextRandomCode(newcodesys,size=6):
|
| 58 |
return ''.join(random.choice(newcodesys) for _ in range(size))
|
59 |
return ''.join(random.choice(newcodesys) for _ in range(size))
|
| Line 85... |
Line 86... |
| 85 |
USER_DETAIL_MAP={}
|
86 |
USER_DETAIL_MAP={}
|
| 86 |
USER_DETAIL_MAP['accs_cart']=0
|
87 |
USER_DETAIL_MAP['accs_cart']=0
|
| 87 |
USER_DETAIL_MAP['accs_active']=0
|
88 |
USER_DETAIL_MAP['accs_active']=0
|
| 88 |
USER_DETAIL_MAP['accs_order']=0
|
89 |
USER_DETAIL_MAP['accs_order']=0
|
| 89 |
USER_DETAIL_MAP['accs_cashback_scheme']=0
|
90 |
USER_DETAIL_MAP['accs_cashback_scheme']=0
|
| - |
|
91 |
# change 1
|
| - |
|
92 |
USER_DETAIL_MAP['inactive_users']=0
|
| 90 |
lgr = getLogger('/var/log/retailer-acquisition-api.log')
|
93 |
lgr = getLogger('/var/log/retailer-acquisition-api.log')
|
| 91 |
DEALER_RETRY_FACTOR = int(PythonPropertyReader.getConfig('DEALER_RETRY_FACTOR'))
|
94 |
DEALER_RETRY_FACTOR = int(PythonPropertyReader.getConfig('DEALER_RETRY_FACTOR'))
|
| 92 |
DEALER_FRESH_FACTOR = int(PythonPropertyReader.getConfig('DEALER_FRESH_FACTOR'))
|
95 |
DEALER_FRESH_FACTOR = int(PythonPropertyReader.getConfig('DEALER_FRESH_FACTOR'))
|
| 93 |
USER_CRM_DEFAULT_RETRY_FACTOR = int(PythonPropertyReader.getConfig('USER_CRM_DEFAULT_RETRY_FACTOR'))
|
96 |
USER_CRM_DEFAULT_RETRY_FACTOR = int(PythonPropertyReader.getConfig('USER_CRM_DEFAULT_RETRY_FACTOR'))
|
| 94 |
USER_CRM_DEFAULT_FRESH_FACTOR = int(PythonPropertyReader.getConfig('USER_CRM_DEFAULT_FRESH_FACTOR'))
|
97 |
USER_CRM_DEFAULT_FRESH_FACTOR = int(PythonPropertyReader.getConfig('USER_CRM_DEFAULT_FRESH_FACTOR'))
|
| Line 1726... |
Line 1729... |
| 1726 |
project_id=2
|
1729 |
project_id=2
|
| 1727 |
elif project_name == 'accs_order':
|
1730 |
elif project_name == 'accs_order':
|
| 1728 |
project_id=3
|
1731 |
project_id=3
|
| 1729 |
elif project_name == 'accs_cashback_scheme':
|
1732 |
elif project_name == 'accs_cashback_scheme':
|
| 1730 |
project_id=4
|
1733 |
project_id=4
|
| - |
|
1734 |
elif project_name == 'inactive_users':
|
| - |
|
1735 |
project_id=5
|
| 1731 |
if retryFlag:
|
1736 |
if retryFlag:
|
| 1732 |
user = self.getRetryUser(project_id)
|
1737 |
user = self.getRetryUser(project_id)
|
| 1733 |
else:
|
1738 |
else:
|
| 1734 |
user = self.getNewUser(project_id)
|
1739 |
user = self.getNewUser(project_id)
|
| 1735 |
|
1740 |
|
| Line 1789... |
Line 1794... |
| 1789 |
project_id=2
|
1794 |
project_id=2
|
| 1790 |
elif project_name == 'accs_order':
|
1795 |
elif project_name == 'accs_order':
|
| 1791 |
project_id=3
|
1796 |
project_id=3
|
| 1792 |
elif project_name == 'accs_cashback_scheme':
|
1797 |
elif project_name == 'accs_cashback_scheme':
|
| 1793 |
project_id=4
|
1798 |
project_id=4
|
| - |
|
1799 |
elif project_name == 'inactive_users':
|
| - |
|
1800 |
project_id=5
|
| 1794 |
|
1801 |
|
| 1795 |
jsonReq = json.loads(req.stream.read(), encoding='utf-8')
|
1802 |
jsonReq = json.loads(req.stream.read(), encoding='utf-8')
|
| 1796 |
lgr.info( "Request ----\n" + str(jsonReq))
|
1803 |
lgr.info( "Request ----\n" + str(jsonReq))
|
| 1797 |
self.jsonReq = jsonReq
|
1804 |
self.jsonReq = jsonReq
|
| 1798 |
self.callType="default"
|
1805 |
self.callType="default"
|
| 1799 |
callLaterAccs = self.callLaterAccs
|
1806 |
callLaterAccs = self.callLaterAccs
|
| - |
|
1807 |
invalidNumber = self.invalidNumber
|
| 1800 |
accsDisposition = self.accsDisposition
|
1808 |
accsDisposition = self.accsDisposition
|
| 1801 |
accsOrderDisposition=self.accsOrderDisposition
|
1809 |
accsOrderDisposition=self.accsOrderDisposition
|
| - |
|
1810 |
otherreason = self.otherreason
|
| - |
|
1811 |
willplaceorder = self.willplaceorder
|
| - |
|
1812 |
orderdiffaccount = self.orderdiffaccount
|
| - |
|
1813 |
businessclosed = self.businessclosed
|
| - |
|
1814 |
appuninstalled = self.appuninstalled
|
| 1802 |
self.userId = int(jsonReq.get('user_id'))
|
1815 |
self.userId = int(jsonReq.get('user_id'))
|
| 1803 |
try:
|
1816 |
try:
|
| 1804 |
self.user = session.query(UserCrmCallingData).filter_by(user_id=self.userId).filter(UserCrmCallingData.project_id==project_id).first()
|
1817 |
self.user = session.query(UserCrmCallingData).filter_by(user_id=self.userId).filter(UserCrmCallingData.project_id==project_id).first()
|
| 1805 |
self.callDisposition = jsonReq.get('calldispositiontype')
|
1818 |
self.callDisposition = jsonReq.get('calldispositiontype')
|
| 1806 |
self.callHistoryCrm = CallHistoryCrm()
|
1819 |
self.callHistoryCrm = CallHistoryCrm()
|
| Line 1830... |
Line 1843... |
| 1830 |
'already_purchased':accsOrderDisposition,
|
1843 |
'already_purchased':accsOrderDisposition,
|
| 1831 |
'product_quality_issue':accsOrderDisposition,
|
1844 |
'product_quality_issue':accsOrderDisposition,
|
| 1832 |
'delayed_delivery':accsOrderDisposition,
|
1845 |
'delayed_delivery':accsOrderDisposition,
|
| 1833 |
'other_complaint':accsOrderDisposition,
|
1846 |
'other_complaint':accsOrderDisposition,
|
| 1834 |
'scheme_not_clear':accsOrderDisposition,
|
1847 |
'scheme_not_clear':accsOrderDisposition,
|
| 1835 |
'not_dealing_accessories':accsOrderDisposition
|
1848 |
'not_dealing_accessories':accsOrderDisposition,
|
| - |
|
1849 |
'other_reason':otherreason,
|
| - |
|
1850 |
'app_uninstalled':appuninstalled,
|
| - |
|
1851 |
'will_place_order':willplaceorder,
|
| - |
|
1852 |
'order_diff_acc':orderdiffaccount,
|
| - |
|
1853 |
'not_retailer':invalidNumber,
|
| - |
|
1854 |
'business_closed':businessclosed,
|
| - |
|
1855 |
'invalid_no':invalidNumber,
|
| - |
|
1856 |
'wrong_no':invalidNumber,
|
| - |
|
1857 |
'hang_up':invalidNumber,
|
| - |
|
1858 |
'service_center_retailer':invalidNumber,
|
| - |
|
1859 |
'recharge_retailer':invalidNumber
|
| - |
|
1860 |
|
| - |
|
1861 |
|
| 1836 |
}
|
1862 |
}
|
| 1837 |
returned = dispositionMap[jsonReq.get('calldispositiontype')]()
|
1863 |
returned = dispositionMap[jsonReq.get('calldispositiontype')]()
|
| 1838 |
finally:
|
1864 |
finally:
|
| 1839 |
session.close()
|
1865 |
session.close()
|
| 1840 |
|
1866 |
|
| Line 1889... |
Line 1915... |
| 1889 |
productpricingInputs.product_input = key
|
1915 |
productpricingInputs.product_input = key
|
| 1890 |
productpricingInputs.pricing_input = value
|
1916 |
productpricingInputs.pricing_input = value
|
| 1891 |
session.commit()
|
1917 |
session.commit()
|
| 1892 |
return True
|
1918 |
return True
|
| 1893 |
|
1919 |
|
| - |
|
1920 |
def willplaceorder(self,):
|
| - |
|
1921 |
self.retailer.status = self.callDisposition
|
| - |
|
1922 |
if self.callHistory.disposition_description is None:
|
| - |
|
1923 |
self.callHistory.disposition_description = 'User will place order from now'
|
| - |
|
1924 |
session.commit()
|
| - |
|
1925 |
return True
|
| - |
|
1926 |
def orderdiffaccount(self,):
|
| - |
|
1927 |
self.retailer.status = self.callDisposition
|
| - |
|
1928 |
if self.callHistory.disposition_description is None:
|
| - |
|
1929 |
self.callHistory.disposition_description = 'Placing Order from Different Account'
|
| - |
|
1930 |
session.commit()
|
| - |
|
1931 |
return True
|
| - |
|
1932 |
|
| - |
|
1933 |
def businessclosed(self,):
|
| - |
|
1934 |
self.retailer.status = self.callDisposition
|
| - |
|
1935 |
if self.callHistory.disposition_description is None:
|
| - |
|
1936 |
self.callHistory.disposition_description = 'Business Closed'
|
| - |
|
1937 |
session.commit()
|
| - |
|
1938 |
return True
|
| - |
|
1939 |
|
| - |
|
1940 |
def appuninstalled(self,):
|
| - |
|
1941 |
self.retailer.status = self.callDisposition
|
| - |
|
1942 |
if self.callHistory.disposition_description is None:
|
| - |
|
1943 |
self.callHistory.disposition_description = 'User uninstalled application'
|
| - |
|
1944 |
session.commit()
|
| - |
|
1945 |
return True
|
| - |
|
1946 |
|
| - |
|
1947 |
|
| - |
|
1948 |
def alReadyUser(self,):
|
| - |
|
1949 |
self.retailer.status = self.callDisposition
|
| - |
|
1950 |
if self.callHistory.disposition_description is None:
|
| - |
|
1951 |
self.callHistory.disposition_description = 'Retailer already user'
|
| - |
|
1952 |
session.commit()
|
| - |
|
1953 |
return True
|
| - |
|
1954 |
|
| - |
|
1955 |
def invalidNumber(self,):
|
| - |
|
1956 |
#self.retailer.status = 'retry' if self.callType == 'fresh' else 'fretry'
|
| - |
|
1957 |
# self.user.status='retry'
|
| - |
|
1958 |
self.user.modified = datetime.now()
|
| - |
|
1959 |
if self.callDisposition == 'invalid_no':
|
| - |
|
1960 |
# self.retailer.status='failed'
|
| - |
|
1961 |
self.user.disposition=self.callDisposition
|
| - |
|
1962 |
self.callHistoryCrm.disposition_description = 'Invalid Number'
|
| - |
|
1963 |
elif self.callDisposition == 'wrong_no':
|
| - |
|
1964 |
# self.retailer.status='failed'
|
| - |
|
1965 |
self.user.disposition=self.callDisposition
|
| - |
|
1966 |
self.callHistoryCrm.disposition_description = 'Wrong Number'
|
| - |
|
1967 |
elif self.callDisposition == 'hang_up':
|
| - |
|
1968 |
# self.retailer.status='failed'
|
| - |
|
1969 |
self.user.disposition=self.callDisposition
|
| - |
|
1970 |
self.callHistoryCrm.disposition_description = 'Hang Up'
|
| - |
|
1971 |
elif self.callDisposition == 'retailer_not_interested':
|
| - |
|
1972 |
# self.retailer.status='failed'
|
| - |
|
1973 |
self.user.disposition=self.callDisposition
|
| - |
|
1974 |
if self.callHistoryCrm.disposition_description is None:
|
| - |
|
1975 |
self.callHistoryCrm.disposition_description = 'NA'
|
| - |
|
1976 |
self.callHistoryCrm.disposition_description = 'Reason Retailer Not Interested ' + self.callHistoryCrm.disposition_description
|
| - |
|
1977 |
elif self.callDisposition == 'recharge_retailer':
|
| - |
|
1978 |
# self.retailer.status='failed'
|
| - |
|
1979 |
self.user.disposition=self.callDisposition
|
| - |
|
1980 |
self.callHistoryCrm.disposition_description = 'Recharge related. Not a retailer '
|
| - |
|
1981 |
elif self.callDisposition == 'accessory_retailer':
|
| - |
|
1982 |
# self.retailer.status='failed'
|
| - |
|
1983 |
self.user.disposition=self.callDisposition
|
| - |
|
1984 |
self.callHistoryCrm.disposition_description = 'Accessory related. Not a retailer'
|
| - |
|
1985 |
elif self.callDisposition == 'service_center_retailer':
|
| - |
|
1986 |
# self.retailer.status='failed'
|
| - |
|
1987 |
self.user.disposition=self.callDisposition
|
| - |
|
1988 |
self.callHistoryCrm.disposition_description = 'Service Center related. Not a retailer'
|
| - |
|
1989 |
elif self.callDisposition == 'not_retailer':
|
| - |
|
1990 |
# self.retailer.status='failed'
|
| - |
|
1991 |
self.user.disposition=self.callDisposition
|
| - |
|
1992 |
self.callHistoryCrm.disposition_description = 'Not a retailer'
|
| - |
|
1993 |
session.commit()
|
| - |
|
1994 |
return True
|
| - |
|
1995 |
|
| - |
|
1996 |
def otherreason(self,):
|
| - |
|
1997 |
self.user.modified = datetime.now()
|
| - |
|
1998 |
self.user.disposition=self.callDisposition
|
| - |
|
1999 |
if self.callHistoryCrm.disposition_description is None:
|
| - |
|
2000 |
self.callHistoryCrm.disposition_description = 'Other Reasons'
|
| - |
|
2001 |
session.commit()
|
| - |
|
2002 |
return True
|
| - |
|
2003 |
|
| - |
|
2004 |
|
| 1894 |
def accsDisposition(self):
|
2005 |
def accsDisposition(self):
|
| 1895 |
self.user.status='done'
|
2006 |
self.user.status='done'
|
| 1896 |
self.user.user_available = 1
|
2007 |
self.user.user_available = 1
|
| 1897 |
self.user.disposition=self.callDisposition
|
2008 |
self.user.disposition=self.callDisposition
|
| 1898 |
self.user.modified = datetime.now()
|
2009 |
self.user.modified = datetime.now()
|
| Line 1995... |
Line 2106... |
| 1995 |
getCartTabsUser()
|
2106 |
getCartTabsUser()
|
| 1996 |
if project_id==3:
|
2107 |
if project_id==3:
|
| 1997 |
getAccsRepeatUsers(project_id)
|
2108 |
getAccsRepeatUsers(project_id)
|
| 1998 |
if project_id==4:
|
2109 |
if project_id==4:
|
| 1999 |
getAccsSchemeCashback(project_id)
|
2110 |
getAccsSchemeCashback(project_id)
|
| - |
|
2111 |
if project_id==5:
|
| - |
|
2112 |
getInactiveUsers(project_id)
|
| - |
|
2113 |
|
| - |
|
2114 |
def getInactiveUsers(project_id):
|
| - |
|
2115 |
PRIOPRITIZING_USER_QUERY = "select d.user_id, count(d.user_id),x.totalorder from daily_visitors d join users u on d.user_id=u.id left join (select user_id,count(*) as totalorder from allorder group by user_id order by totalorder desc) as x on d.user_id=x.user_id where lower(u.referrer) not like 'emp%' and d.user_id not in (select user_id from daily_visitors where visited > '2016-03-01') group by d.user_id having count(*) >=5 order by x.totalorder desc, count(d.user_id) desc;"
|
| - |
|
2116 |
userFinalList=[]
|
| - |
|
2117 |
result = fetchResult(PRIOPRITIZING_USER_QUERY)
|
| - |
|
2118 |
for r in result:
|
| - |
|
2119 |
userFinalList.append(r[0])
|
| - |
|
2120 |
for i in userFinalList:
|
| - |
|
2121 |
try:
|
| - |
|
2122 |
userId=i
|
| - |
|
2123 |
userPresent = session.query(UserCrmCallingData).filter_by(user_id=userId).order_by(desc(UserCrmCallingData.modified)).first()
|
| - |
|
2124 |
if userPresent is not None:
|
| - |
|
2125 |
if userPresent.user_available==1:
|
| - |
|
2126 |
if userPresent.project_id==project_id:
|
| - |
|
2127 |
continue
|
| - |
|
2128 |
elif userPresent.modified.date()>=(datetime.now().date()-timedelta(days=30)):
|
| - |
|
2129 |
continue
|
| - |
|
2130 |
else:
|
| - |
|
2131 |
continue
|
| - |
|
2132 |
userMasterData = UserCrmCallingData()
|
| - |
|
2133 |
userMasterData.user_id = userId
|
| - |
|
2134 |
userMasterData.name =getUsername(userId)
|
| - |
|
2135 |
userMasterData.project_id = project_id
|
| - |
|
2136 |
userMasterData.user_available=0
|
| - |
|
2137 |
userMasterData.contact1 = getUserContactDetails(userId)
|
| - |
|
2138 |
userMasterData.counter = 0
|
| - |
|
2139 |
userMasterData.retry_count=0
|
| - |
|
2140 |
userMasterData.invalid_retry_count=0
|
| - |
|
2141 |
userMasterData.created = datetime.now()
|
| - |
|
2142 |
userMasterData.modified = datetime.now()
|
| - |
|
2143 |
userMasterData.status = 'new'
|
| - |
|
2144 |
userMasterData.pincode_servicable = checkPincodeServicable(userId)
|
| - |
|
2145 |
session.commit()
|
| - |
|
2146 |
except:
|
| - |
|
2147 |
print traceback.print_exc()
|
| - |
|
2148 |
finally:
|
| - |
|
2149 |
session.close()
|
| - |
|
2150 |
|
| 2000 |
|
2151 |
|
| 2001 |
def getAccsSchemeCashback(project_id):
|
2152 |
def getAccsSchemeCashback(project_id):
|
| 2002 |
userMasterMap={}
|
2153 |
userMasterMap={}
|
| 2003 |
skipUserList=[]
|
2154 |
skipUserList=[]
|
| 2004 |
query = "select id from users where lower(referrer) in ('emp01','emp99','emp88')"
|
2155 |
query = "select id from users where lower(referrer) in ('emp01','emp99','emp88')"
|
| Line 2025... |
Line 2176... |
| 2025 |
for i in d_sorted:
|
2176 |
for i in d_sorted:
|
| 2026 |
try:
|
2177 |
try:
|
| 2027 |
userId=i[1]
|
2178 |
userId=i[1]
|
| 2028 |
if counter==20:
|
2179 |
if counter==20:
|
| 2029 |
break
|
2180 |
break
|
| - |
|
2181 |
|
| - |
|
2182 |
# userPresent = isUserAvailable(CRM_PROJECTS_USER_AVAILABILITY.get(project_id))
|
| 2030 |
userPresent = session.query(UserCrmCallingData).filter_by(user_id=userId).order_by(desc(UserCrmCallingData.modified)).first()
|
2183 |
userPresent = session.query(UserCrmCallingData).filter_by(user_id=userId).order_by(desc(UserCrmCallingData.modified)).first()
|
| 2031 |
if userPresent is not None:
|
2184 |
if userPresent is not None:
|
| 2032 |
if userPresent.user_available==1:
|
2185 |
if userPresent.user_available==1:
|
| 2033 |
if userPresent.project_id==project_id:
|
2186 |
if userPresent.project_id==project_id:
|
| 2034 |
continue
|
2187 |
continue
|