Subversion Repositories SmartDukaan

Rev

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

Rev 18367 Rev 18386
Line 67... Line 67...
67
        
67
        
68
    return string.join(code, '')
68
    return string.join(code, '')
69
        
69
        
70
        
70
        
71
 
71
 
-
 
72
global IGNORE_USER_CART_PAGE
-
 
73
IGNORE_USER_CART_PAGE=[]
72
 
74
IGNORE_USER_CART_PAGE=[75,93,94,113,162,171,180,291,319,533,538,583,616,819,890,1010,1027,1071,1138,1142,1255,1283,1331,1412,1497,1617,1731,1957,1983,2039,2250,2261,2398,2429,2438,2482,2490,2511,2542,2572,2643,2665,2785,2833,2838,2868,2900,2911,2915,3119,3173,3250,3330,3330,3542,3557,3615,3628,3660,3676,3689,3817,3829,3877,3892,3908,3948,3998,4093,4164,4259,4262,4565,4664,4674,4755,4762,4832,4887,4917,4921,5056,5064,5091,5134,5176,5187,5197,5211,5215,5279,5336,5340,5420,5642,5700,5780,5826,5844,5867,5894,5993,6039,6241,6359,6395,6395,6409,6439,6497,6502,6675,6691,6745,6826,6833,6881,6889,6963,6979,7025,7098,7099,7099,7270,7279,7285,7296,7370,7411,7578,7629,7682,7805,7805,7831,7974,7980,7989,8053,8076,8079,8116,8157,8205,8253,8318,8325,8337,8428,8441,8492,8524,8528,8618,8619,8641,8654,8689,8787,8790,8824,8868,8877,9011,9037,9043,9130,9170,9179,9198,9202,9245,9310,9312,9327,9382,9399,9399,9402,9431,9472,9569,9608,9707,9709,9720,9785,9877,9898,9919,9996,10016,10033,10095,10097,10104,10159,10178,10186,10186,10208,10216,10216,10252,10385,10409,10419,10442,10480,10497,10542,10658,10658,10684,10689,10725,10770,10787,10846,10879,10920,10930,11042,11109,11118,11136,11179,11211,11219,11255,11312,11322,11334,11341,11386,11398,11417,11444,11547,11576,11603,11608,11611,11646,11661,11694,11733,11737,11770,11771,11771,11789,11826,11852,11874,11902,11903,11907,11916,11918,11940,11942,11953,12017,12033,12086,12140,12145,12145,12170,12208,12215,12250,12270,12289,12309,12367,12378,12394,12459,12459,12489,12506,12509,12519,12551,12556,12561,12605,12606,12665,12673,12725,12732,12759,12793,12830,12864,12885,12956,12956,13014,13054,13087,13107,13130,13211,13221,13231,13287,13305,13355,13391,13430,13483,13553,13554,13563,13579,13594,13633,13742,13742,13760,13768,13778,13781,13831,13929,13968,13994,14001,14026,14035,14066,14073,14083,14242,14269,14274,14280,14291,14309,14358,14374,14399,14405,14462,14465,14508,14526,14549,14588,14589,14595,14614,14698,14737,14836,14842,14844,14848,14880,14889,14895,14920,14920,14925,14928,14929,14930,14999,15009,15014,15016,15055,15063,15075,15086,15106,15112,15128,15142,15147,15148,15166,15192,15227,15267,15278,15280,15285,15291,15292,15293,15320,15331,15335,15336,15361,15370,15394,15419,15424,15437,15438,15442,15457,15459,15469,15484,15491,15507,15515,15520,15520,15525,15553,15563,15568,15577,15585,15588,15591,15603,15608,15614,15617,15622,15633,15634,15641,15654,15662,15667,15670,15682,15689,15690,15704,15716,15721,15736,15737,15739,15746,15749,15765,15767,15773,15774,15779,15783,15792,15795]
73
global RETAILER_DETAIL_CALL_COUNTER
75
global RETAILER_DETAIL_CALL_COUNTER
74
RETAILER_DETAIL_CALL_COUNTER = 0
76
RETAILER_DETAIL_CALL_COUNTER = 0
75
global USER_DETAIL_MAP
77
global USER_DETAIL_MAP
76
USER_DETAIL_MAP={} 
78
USER_DETAIL_MAP={} 
77
USER_DETAIL_MAP['accs_cart']=0
79
USER_DETAIL_MAP['accs_cart']=0
Line 1632... Line 1634...
1632
    
1634
    
1633
    def on_get(self,req,resp):
1635
    def on_get(self,req,resp):
1634
        global USER_DETAIL_MAP
1636
        global USER_DETAIL_MAP
1635
        project_name = req.get_param("project_name")
1637
        project_name = req.get_param("project_name")
1636
        USER_DETAIL_MAP[project_name]+=1
1638
        USER_DETAIL_MAP[project_name]+=1
1637
        lgr.info( "RETAILER_DETAIL_CALL_COUNTER " +  str(USER_DETAIL_MAP[project_name]))
1639
        lgr.info( "USER_DETAIL_CALL_COUNTER " +  str(USER_DETAIL_MAP[project_name]))
1638
        retryFlag=False
1640
        retryFlag=False
1639
        if USER_DETAIL_MAP[project_name] % TOTAL_USER >= USER_CRM_DEFAULT_FRESH_FACTOR:
1641
        if USER_DETAIL_MAP[project_name] % TOTAL_USER >= USER_CRM_DEFAULT_FRESH_FACTOR:
1640
                retryFlag=True
1642
                retryFlag=True
1641
        if project_name == 'accs_cart':
1643
        if project_name == 'accs_cart':
1642
            if retryFlag:
1644
            if retryFlag:
Line 1653... Line 1655...
1653
                user.modified = datetime.now()
1655
                user.modified = datetime.now()
1654
                session.commit()
1656
                session.commit()
1655
                resp.body = json.dumps(todict(getUserObject(user)), encoding='utf-8')
1657
                resp.body = json.dumps(todict(getUserObject(user)), encoding='utf-8')
1656
                session.close()
1658
                session.close()
1657
 
1659
 
-
 
1660
        if project_name == 'accs_active':
-
 
1661
            if retryFlag:
-
 
1662
                user = self.getRetryUser(2)
-
 
1663
            else:
-
 
1664
                user = self.getNewUser(2)
-
 
1665
            
-
 
1666
            if user is None:
-
 
1667
                resp.body ={}
-
 
1668
            else:        
-
 
1669
                user.status =  'assigned'
-
 
1670
                user.agent_id = req.get_param("agent_id")
-
 
1671
                user.counter=1
-
 
1672
                user.modified = datetime.now()
-
 
1673
                session.commit()
-
 
1674
                resp.body = json.dumps(todict(getUserObject(user)), encoding='utf-8')
-
 
1675
                session.close()
-
 
1676
 
-
 
1677
                
1658
    def getRetryUser(self,projectId,failback=True):
1678
    def getRetryUser(self,projectId,failback=True):
1659
        status = "retry"
1679
        status = "retry"
1660
        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()
1680
        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()
1661
        
1681
        
1662
        if user is not None:
1682
        if user is not None:
Line 1686... Line 1706...
1686
                        else:
1706
                        else:
1687
                            return None
1707
                            return None
1688
            except:
1708
            except:
1689
                print traceback.print_exc()
1709
                print traceback.print_exc()
1690
            return user    
1710
            return user    
1691
        
1711
                
1692
    def on_post(self, req, resp):
1712
    def on_post(self, req, resp):
1693
        returned = False
1713
        returned = False
1694
        self.agentId = req.get_param("agent_id")
1714
        self.agentId = req.get_param("agent_id")
1695
        project_name = req.get_param("project_name")
1715
        project_name = req.get_param("project_name")
1696
        if project_name == 'accs_cart':
1716
        if project_name == 'accs_cart':
Line 1734... Line 1754...
1734
            if returned:
1754
            if returned:
1735
                resp.body = "{\"result\":\"success\"}"
1755
                resp.body = "{\"result\":\"success\"}"
1736
            else:
1756
            else:
1737
                resp.body = "{\"result\":\"failed\"}"
1757
                resp.body = "{\"result\":\"failed\"}"
1738
 
1758
 
-
 
1759
        if project_name == 'accs_active':
-
 
1760
                jsonReq = json.loads(req.stream.read(), encoding='utf-8')
-
 
1761
                lgr.info( "Request ----\n"  + str(jsonReq))
-
 
1762
                self.jsonReq = jsonReq
-
 
1763
                self.callType="default"
-
 
1764
                callLaterAccs = self.callLaterAccs
-
 
1765
                accsDisposition = self.accsDisposition
-
 
1766
                self.userId = int(jsonReq.get('user_id'))
-
 
1767
                try:
-
 
1768
                    self.user = session.query(UserCrmCallingData).filter_by(user_id=self.userId).filter(UserCrmCallingData.project_id==2).first()
-
 
1769
                    self.callDisposition = jsonReq.get('calldispositiontype')
-
 
1770
                    self.callHistoryCrm = CallHistoryCrm()
-
 
1771
                    self.callHistoryCrm.agent_id=self.agentId
-
 
1772
                    self.callHistoryCrm.project_id = 2
-
 
1773
                    self.callHistoryCrm.call_disposition = self.callDisposition
-
 
1774
                    self.callHistoryCrm.user_id=self.userId
-
 
1775
                    self.callHistoryCrm.duration_sec = int(jsonReq.get("callduration"))
-
 
1776
                    self.callHistoryCrm.disposition_comments = jsonReq.get('calldispositioncomments')
-
 
1777
                    self.callHistoryCrm.call_time = datetime.strptime(jsonReq.get("calltime"), '%d/%m/%Y %H:%M:%S')
-
 
1778
                    self.callHistoryCrm.mobile_number = jsonReq.get('number')
-
 
1779
                    self.inputs = jsonReq.get("inputs")
-
 
1780
                    dispositionMap = {  'call_later':callLaterAccs,
-
 
1781
                                'ringing_no_answer':callLaterAccs,
-
 
1782
                                'not_reachable':callLaterAccs,
-
 
1783
                                'switch_off':callLaterAccs,
-
 
1784
                                'technical_issue':accsDisposition,
-
 
1785
                                'pricing_issue':accsDisposition,
-
 
1786
                                'shipping_issue':accsDisposition,
-
 
1787
                                'internet_issue':accsDisposition,
-
 
1788
                                'checking_price':accsDisposition,
-
 
1789
                                'order_process':accsDisposition,
-
 
1790
                                'placed_order':accsDisposition,
-
 
1791
                                'place_order':accsDisposition
-
 
1792
                              }
-
 
1793
                    returned = dispositionMap[jsonReq.get('calldispositiontype')]()
-
 
1794
                finally:
-
 
1795
                    session.close()
-
 
1796
                
-
 
1797
                if returned:
-
 
1798
                    resp.body = "{\"result\":\"success\"}"
-
 
1799
                else:
-
 
1800
                    resp.body = "{\"result\":\"failed\"}"
-
 
1801
 
1739
    def accsDisposition(self):
1802
    def accsDisposition(self):
1740
        self.user.status='done'
1803
        self.user.status='done'
1741
        self.user.user_available = 1
1804
        self.user.user_available = 1
1742
        self.user.disposition=self.callDisposition
1805
        self.user.disposition=self.callDisposition
1743
        self.user.modified = datetime.now()
1806
        self.user.modified = datetime.now()
Line 1831... Line 1894...
1831
        return True
1894
        return True
1832
    
1895
    
1833
def insertUserCrmData(project_id):
1896
def insertUserCrmData(project_id):
1834
    if project_id==1:  
1897
    if project_id==1:  
1835
        getCartDetailsUser()
1898
        getCartDetailsUser()
-
 
1899
    if project_id==2:  
-
 
1900
        getCartTabsUser()
1836
      
1901
      
1837
def getCartDetailsUser():
1902
def getCartDetailsUser():
1838
    userList=[]
1903
    userList=[]
1839
    orderUserList=[]
1904
    orderUserList=[]
1840
    userMasterMap={}
1905
    userMasterMap={}
Line 1880... Line 1945...
1880
def addUserToTable(userList,projectId):
1945
def addUserToTable(userList,projectId):
1881
    counter=0
1946
    counter=0
1882
    for i in userList:
1947
    for i in userList:
1883
        try:
1948
        try:
1884
            userId=i[1]
1949
            userId=i[1]
1885
            if counter==20:
1950
            if counter==2:
1886
                break
1951
                break
1887
            userPresent = session.query(UserCrmCallingData).filter_by(user_id=userId).order_by(desc(UserCrmCallingData.modified)).first()
1952
            userPresent = session.query(UserCrmCallingData).filter_by(user_id=userId).order_by(desc(UserCrmCallingData.modified)).first()
1888
            if userPresent is not None:
1953
            if userPresent is not None:
1889
                if userPresent.user_available==1:
1954
                if userPresent.user_available==1:
1890
                    if userPresent.project_id==projectId:
1955
                    if userPresent.project_id==projectId:
Line 1929... Line 1994...
1929
    for r in result:
1994
    for r in result:
1930
        userMasterList.append(r)
1995
        userMasterList.append(r)
1931
    
1996
    
1932
    queryfilterVisistedCart = {"$and":
1997
    queryfilterVisistedCart = {"$and":
1933
                   [
1998
                   [
-
 
1999
                    {'user_id':{"$in":userMasterList}},
1934
                    {"url":{"$regex" : "http://api.profittill.com/cartdetails"}}
2000
                    {"url":{"$regex" : "http://api.profittill.com/cartdetails"}}
1935
                    ]
2001
                    ]
1936
                  }
2002
                  }
1937
    result = get_mongo_connection_dtr_data().User.browsinghistories.find(queryfilterVisistedCart).distinct('user_id')
2003
    result = get_mongo_connection_dtr_data().User.browsinghistories.find(queryfilterVisistedCart).distinct('user_id')   
1938
    for r in result:
2004
    for r in result:
1939
        userList.append(r)
2005
        userList.append(r)
1940
    
2006
    
1941
    myquery = "select user_id from allorder where store_id='spice' and (category='Accs' or category='Accessories') and user_id in (%s)" % ",".join(map(str,userList))
2007
    myquery = "select user_id from allorder where store_id='spice' and (category='Accs' or category='Accessories') and user_id in (%s)" % ",".join(map(str,userList)) + " UNION select id from users where lower(referrer) like 'emp%'"
1942
 
2008
 
1943
    result = fetchResult(myquery)
2009
    result = fetchResult(myquery)
1944
    for r in result:
2010
    for r in result:
1945
        if r[0] in userList:
2011
        if r[0] in userList:
1946
            continue
2012
            continue
1947
        userList.append(r[0])
2013
        userList.append(r[0])
-
 
2014
        
-
 
2015
    for r in IGNORE_USER_CART_PAGE:
-
 
2016
        if r in userList:
-
 
2017
            userList.remove(r)
1948
    
2018
    
1949
    finalUserList  = list(set(userMasterList) - set(userList))
2019
    finalUserList  = list(set(userMasterList) - set(userList))
1950
    print finalUserList
-
 
1951
    finalUserList
2020
    
1952
    queryfilternew = {"$and":
2021
    queryfilternew = {"$and":
1953
                   [
2022
                   [
1954
                    {'user_id':{"$in":finalUserList}},
2023
                    {'user_id':{"$in":finalUserList}},
1955
                    {'created':{"$gte":(to_java_date(datetime.now())-2*86400000)}},
2024
                    {'created':{"$gte":(to_java_date(datetime.now())-2*86400000)}},
1956
                    {'created':{"$lte":(to_java_date(datetime.now())- 43200000)}},
2025
                    {'created':{"$lte":(to_java_date(datetime.now())- 43200000)}},
Line 2035... Line 2104...
2035
    def on_get(self,req,resp, id):
2104
    def on_get(self,req,resp, id):
2036
        result = Mongo.getDealById(id)
2105
        result = Mongo.getDealById(id)
2037
        resp.body = dumps(result)
2106
        resp.body = dumps(result)
2038
    
2107
    
2039
def main():
2108
def main():
2040
    #tagActivatedReatilers()
-
 
2041
    #a = RetailerDetail()
2109
    a = RetailerDetail()
2042
    #retailer = a.getNotActiveRetailer()
2110
    retailer = a.getNotActiveRetailer()
2043
    #otherContacts = [r for r, in session.query(RetailerContacts.mobile_number).filter_by(retailer_id=retailer.id).order_by(RetailerContacts.contact_type).all()]
2111
    otherContacts = [r for r, in session.query(RetailerContacts.mobile_number).filter_by(retailer_id=retailer.id).order_by(RetailerContacts.contact_type).all()]
2044
    #print json.dumps(todict(getRetailerObj(retailer, otherContacts, 'fresh')), encoding='utf-8')
2112
    print json.dumps(todict(getRetailerObj(retailer, otherContacts, 'fresh')), encoding='utf-8')
2045
    #print make_tiny("AA")
-
 
2046
    a = GetUserCrmApplication()
2113
#     a = GetUserCrmApplication()
2047
    a.getUser("accs_cart", 2)
2114
#     a.getUser("accs_active", 2)
2048
    
2115
    
2049
if __name__ == '__main__':
2116
if __name__ == '__main__':
2050
    main()
2117
    main()
2051
        
2118
        
2052
2119