Subversion Repositories SmartDukaan

Rev

Rev 19440 | Rev 19444 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 19440 Rev 19442
Line 75... Line 75...
75
global USER_DETAIL_MAP
75
global USER_DETAIL_MAP
76
USER_DETAIL_MAP={} 
76
USER_DETAIL_MAP={} 
77
USER_DETAIL_MAP['accs_cart']=0
77
USER_DETAIL_MAP['accs_cart']=0
78
USER_DETAIL_MAP['accs_active']=0
78
USER_DETAIL_MAP['accs_active']=0
79
USER_DETAIL_MAP['accs_order']=0
79
USER_DETAIL_MAP['accs_order']=0
-
 
80
USER_DETAIL_MAP['accs_cashback_scheme']=0
80
lgr = getLogger('/var/log/retailer-acquisition-api.log')
81
lgr = getLogger('/var/log/retailer-acquisition-api.log')
81
DEALER_RETRY_FACTOR = int(PythonPropertyReader.getConfig('DEALER_RETRY_FACTOR'))
82
DEALER_RETRY_FACTOR = int(PythonPropertyReader.getConfig('DEALER_RETRY_FACTOR'))
82
DEALER_FRESH_FACTOR = int(PythonPropertyReader.getConfig('DEALER_FRESH_FACTOR'))
83
DEALER_FRESH_FACTOR = int(PythonPropertyReader.getConfig('DEALER_FRESH_FACTOR'))
83
USER_CRM_DEFAULT_RETRY_FACTOR = int(PythonPropertyReader.getConfig('USER_CRM_DEFAULT_RETRY_FACTOR'))
84
USER_CRM_DEFAULT_RETRY_FACTOR = int(PythonPropertyReader.getConfig('USER_CRM_DEFAULT_RETRY_FACTOR'))
84
USER_CRM_DEFAULT_FRESH_FACTOR = int(PythonPropertyReader.getConfig('USER_CRM_DEFAULT_FRESH_FACTOR'))
85
USER_CRM_DEFAULT_FRESH_FACTOR = int(PythonPropertyReader.getConfig('USER_CRM_DEFAULT_FRESH_FACTOR'))
Line 1684... Line 1685...
1684
            
1685
            
1685
        else:
1686
        else:
1686
            resp.body = json.dumps({}, encoding='utf-8')
1687
            resp.body = json.dumps({}, encoding='utf-8')
1687
 
1688
 
1688
class GetUserCrmApplication:
1689
class GetUserCrmApplication:
1689
    
1690
            
1690
    def on_get(self,req,resp):
1691
    def on_get(self,req,resp):
1691
        global USER_DETAIL_MAP
1692
        global USER_DETAIL_MAP
1692
        project_name = req.get_param("project_name")
1693
        project_name = req.get_param("project_name")
1693
        USER_DETAIL_MAP[project_name]+=1
1694
        USER_DETAIL_MAP[project_name]+=1
1694
        lgr.info( "USER_DETAIL_CALL_COUNTER " +  str(USER_DETAIL_MAP[project_name]))
1695
        lgr.info( "USER_DETAIL_CALL_COUNTER " +  str(USER_DETAIL_MAP[project_name]))
Line 1699... Line 1700...
1699
            project_id=1
1700
            project_id=1
1700
        elif project_name == 'accs_active':
1701
        elif project_name == 'accs_active':
1701
            project_id=2
1702
            project_id=2
1702
        elif project_name == 'accs_order':
1703
        elif project_name == 'accs_order':
1703
            project_id=3
1704
            project_id=3
-
 
1705
        elif project_name == 'accs_cashback_scheme':
-
 
1706
            project_id=4
1704
        if retryFlag:
1707
        if retryFlag:
1705
            user = self.getRetryUser(project_id)
1708
            user = self.getRetryUser(project_id)
1706
        else:
1709
        else:
1707
            user = self.getNewUser(project_id)
1710
            user = self.getNewUser(project_id)
1708
        
1711
        
Line 1760... Line 1763...
1760
            project_id=1
1763
            project_id=1
1761
        elif project_name == 'accs_active':
1764
        elif project_name == 'accs_active':
1762
            project_id=2            
1765
            project_id=2            
1763
        elif project_name == 'accs_order':
1766
        elif project_name == 'accs_order':
1764
            project_id=3            
1767
            project_id=3            
-
 
1768
        elif project_name == 'accs_cashback_scheme':
-
 
1769
            project_id=4
1765
        
1770
            
1766
        jsonReq = json.loads(req.stream.read(), encoding='utf-8')
1771
        jsonReq = json.loads(req.stream.read(), encoding='utf-8')
1767
        lgr.info( "Request ----\n"  + str(jsonReq))
1772
        lgr.info( "Request ----\n"  + str(jsonReq))
1768
        self.jsonReq = jsonReq
1773
        self.jsonReq = jsonReq
1769
        self.callType="default"
1774
        self.callType="default"
1770
        callLaterAccs = self.callLaterAccs
1775
        callLaterAccs = self.callLaterAccs
Line 1800... Line 1805...
1800
                        'return_replacement':accsOrderDisposition,
1805
                        'return_replacement':accsOrderDisposition,
1801
                        'already_purchased':accsOrderDisposition,
1806
                        'already_purchased':accsOrderDisposition,
1802
                        'product_quality_issue':accsOrderDisposition,
1807
                        'product_quality_issue':accsOrderDisposition,
1803
                        'delayed_delivery':accsOrderDisposition,
1808
                        'delayed_delivery':accsOrderDisposition,
1804
                        'other_complaint':accsOrderDisposition,
1809
                        'other_complaint':accsOrderDisposition,
-
 
1810
                        'scheme_not_clear':accsOrderDisposition,
1805
                        'not_dealing_accessories':accsOrderDisposition
1811
                        'not_dealing_accessories':accsOrderDisposition
1806
                      }
1812
                      }
1807
            returned = dispositionMap[jsonReq.get('calldispositiontype')]()
1813
            returned = dispositionMap[jsonReq.get('calldispositiontype')]()
1808
        finally:
1814
        finally:
1809
            session.close()
1815
            session.close()
Line 1825... Line 1831...
1825
            self.callHistoryCrm.disposition_description='Return or replacement pending'
1831
            self.callHistoryCrm.disposition_description='Return or replacement pending'
1826
            #utils.sendCrmProjectMail(self.userId,self.callHistoryCrm.disposition_description,self.callHistoryCrm.disposition_comments)
1832
            #utils.sendCrmProjectMail(self.userId,self.callHistoryCrm.disposition_description,self.callHistoryCrm.disposition_comments)
1827
            a.addTicket(self.userId, self.callHistoryCrm.disposition_description, self.callHistoryCrm.disposition_comments)
1833
            a.addTicket(self.userId, self.callHistoryCrm.disposition_description, self.callHistoryCrm.disposition_comments)
1828
        elif self.callDisposition == 'already_purchased':
1834
        elif self.callDisposition == 'already_purchased':
1829
            self.callHistoryCrm.disposition_description='Already purchased required stock'
1835
            self.callHistoryCrm.disposition_description='Already purchased required stock'
-
 
1836
        elif self.callDisposition == 'scheme_not_clear':
-
 
1837
            self.callHistoryCrm.disposition_description='Scheme Not Clear to the User'
1830
        elif self.callDisposition == 'product_quality_issue':
1838
        elif self.callDisposition == 'product_quality_issue':
1831
            self.callHistoryCrm.disposition_description='Product Quality issue'
1839
            self.callHistoryCrm.disposition_description='Product Quality issue'
1832
            #utils.sendCrmProjectMail(self.userId,self.callHistoryCrm.disposition_description,self.callHistoryCrm.disposition_comments)
1840
            #utils.sendCrmProjectMail(self.userId,self.callHistoryCrm.disposition_description,self.callHistoryCrm.disposition_comments)
1833
            a.addTicket(self.userId, self.callHistoryCrm.disposition_description, self.callHistoryCrm.disposition_comments)            
1841
            a.addTicket(self.userId, self.callHistoryCrm.disposition_description, self.callHistoryCrm.disposition_comments)            
1834
        elif self.callDisposition == 'delayed_delivery':
1842
        elif self.callDisposition == 'delayed_delivery':
Line 1961... Line 1969...
1961
        getCartDetailsUser()
1969
        getCartDetailsUser()
1962
    if project_id==2:  
1970
    if project_id==2:  
1963
        getCartTabsUser()
1971
        getCartTabsUser()
1964
    if project_id==3:
1972
    if project_id==3:
1965
        getAccsRepeatUsers(project_id)
1973
        getAccsRepeatUsers(project_id)
-
 
1974
    if project_id==4:
-
 
1975
        getAccsSchemeCashback(project_id)
-
 
1976
 
-
 
1977
def getAccsSchemeCashback(project_id):
-
 
1978
    userMasterMap={}
-
 
1979
    skipUserList=[]
-
 
1980
    query = "select id from users where lower(referrer) in ('emp01','fos01','emp99','emp88')"
-
 
1981
    skipUsersresult = fetchResult(query)
-
 
1982
    for skipUser in skipUsersresult:
-
 
1983
        skipUserList.append(skipUser[0])
-
 
1984
    queryFilter = {"user_id":{"$nin":skipUserList}}
-
 
1985
    result = get_mongo_connection().Catalog.PromoOffer.find(queryFilter)
-
 
1986
    userMasterList =[]
-
 
1987
    for r in result:
-
 
1988
        userMasterList.append(r.get('user_id'))
-
 
1989
    queryfilter ={"url":{"$regex" : "http://api.profittill.com/categories/target"}}
-
 
1990
    result = get_mongo_connection_dtr_data().User.browsinghistories.find(queryfilter).distinct('user_id')
-
 
1991
    userSeenList=[]
-
 
1992
    for r in result:
-
 
1993
        userSeenList.append(r)
-
 
1994
    finalUserList  = list(set(userMasterList) - set(userSeenList))
-
 
1995
    queryFilter = {"user_id":{"$in":finalUserList}}
-
 
1996
    result = get_mongo_connection().Catalog.PromoOffer.find(queryFilter)
-
 
1997
    for r in result:
-
 
1998
        userMasterMap[r.get('user_id')] = r.get('target2')
-
 
1999
    d_sorted = sorted(zip(userMasterMap.values(), userMasterMap.keys()),reverse=True)
-
 
2000
    counter=0
-
 
2001
    for i in d_sorted:
-
 
2002
        try:
-
 
2003
            userId=i[1]
-
 
2004
            if counter==20:
-
 
2005
                break
-
 
2006
            userPresent = session.query(UserCrmCallingData).filter_by(user_id=userId).order_by(desc(UserCrmCallingData.modified)).first()
-
 
2007
            if userPresent is not None:
-
 
2008
                if userPresent.user_available==1:
-
 
2009
                    if userPresent.project_id==project_id:
-
 
2010
                        continue                        
-
 
2011
                    elif userPresent.modified.date()>=(datetime.now().date()-timedelta(days=30)):
-
 
2012
                        continue
-
 
2013
                else:
-
 
2014
                    continue               
-
 
2015
            counter=counter+1
-
 
2016
            userMasterData = UserCrmCallingData()
-
 
2017
            userMasterData.user_id = userId 
-
 
2018
            userMasterData.name =getUsername(userId) 
-
 
2019
            userMasterData.project_id = project_id
-
 
2020
            userMasterData.user_available=0
-
 
2021
            userMasterData.contact1 = getUserContactDetails(userId)
-
 
2022
            userMasterData.counter = 0
-
 
2023
            userMasterData.retry_count=0
-
 
2024
            userMasterData.invalid_retry_count=0
-
 
2025
            userMasterData.created = datetime.now()
-
 
2026
            userMasterData.modified = datetime.now()
-
 
2027
            userMasterData.status = 'new'
-
 
2028
            userMasterData.pincode_servicable = checkPincodeServicable(userId)
-
 
2029
            session.commit()
-
 
2030
        except:
-
 
2031
            print traceback.print_exc()
-
 
2032
        finally:
-
 
2033
            session.close()
1966
    
2034
        
1967
def getAccsRepeatUsers(project_id):
2035
def getAccsRepeatUsers(project_id):
1968
    
2036
    
1969
    usersMasterList=[]
2037
    usersMasterList=[]
1970
    ACCS_ALL_ORDERS = "select distinct user_id from allorder where category in ('Accs','Accessories') and store_id='spice';"
2038
    ACCS_ALL_ORDERS = "select distinct user_id from allorder where category in ('Accs','Accessories') and store_id='spice';"
1971
    result = fetchResult(ACCS_ALL_ORDERS)
2039
    result = fetchResult(ACCS_ALL_ORDERS)
Line 2297... Line 2365...
2297
def main():
2365
def main():
2298
    a = RetailerDetail()
2366
    a = RetailerDetail()
2299
    retailer = a.getNotActiveRetailer()
2367
    retailer = a.getNotActiveRetailer()
2300
    otherContacts = [r for r, in session.query(RetailerContacts.mobile_number).filter_by(retailer_id=retailer.id).order_by(RetailerContacts.contact_type).all()]
2368
    otherContacts = [r for r, in session.query(RetailerContacts.mobile_number).filter_by(retailer_id=retailer.id).order_by(RetailerContacts.contact_type).all()]
2301
    print json.dumps(todict(getRetailerObj(retailer, otherContacts, 'fresh')), encoding='utf-8')
2369
    print json.dumps(todict(getRetailerObj(retailer, otherContacts, 'fresh')), encoding='utf-8')
2302
#     a = GetUserCrmApplication()
-
 
2303
#     a.getUser("accs_active", 2)
-
 
2304
    
2370
    
2305
if __name__ == '__main__':
2371
if __name__ == '__main__':
2306
    #main()
2372
    #main()
2307
    print getTinInfo('07740388453')
2373
    print getTinInfo('07740388453')
2308
        
2374
        
2309
2375