示例#1
0
文件: tools.py 项目: Heyff12/vueMuch
def call_captcha(func, *args, **kwargs):
    log.info('req captcha func=%s|args=%s|kwargs=%s', func, args, kwargs)
    client = ThriftClient(CAPTCHA_SERVER, CaptchaServer)
    client.raise_except = True
    ret = client.call(func, *args, **kwargs)
    log.info('req captcha func=%s|ret=%s', func, ret)
    return ret
示例#2
0
文件: tools.py 项目: Heyff12/vueMuch
def call_fenqi_api(func, *args, **kwargs):
    log.info('<<<< req fenqi_api func=%s | args=%s | kwargs=%s', func, args,
             kwargs)
    client = ThriftClient(FENQI_SERVER, FenqiServer, framed=True)
    client.raise_except = True
    ret = client.call(func, *args, **kwargs)
    log.info('>>>> resp fenqi_api func=%s | result=%s', func, ret)
    return ret
示例#3
0
def start(_ds):
    now = int(time.time())
    userids = []
    with get_connection('wxmp_customer') as db:
        _sql = " select appid,nick_name from `mp_conf` where status = 1 and appid != '' "
        userids = db.query(_sql)
    if not userids: return

    today = datetime.date.today()
    yesterday = _ds
    _table_name = "record_%s" % str(str(yesterday).replace("-", ""))[0:6]

    client = ThriftClient(config.WX_SERVER, QFMP, framed=False)
    client.raise_except = True

    #获取微信数据
    for xy in userids:

        try:
            _data = client.call('access_token', xy['appid'])
            _token = _data.access_token

            #总粉丝数
            r = Urllib2Client().get(
                "https://api.weixin.qq.com/cgi-bin/user/get?access_token=%s&next_openid="
                % _token)
            r_j = json.loads(r)
            xy['allfan'] = r_j["total"]

            #新增粉丝数
            _params = {
                "begin_date": str(yesterday).replace("-", ''),
                "end_date": str(yesterday).replace("-", '')
            }
            r = Urllib2Client().post_json(
                "https://api.weixin.qq.com/datacube/getusersummary?access_token=%s"
                % _token,
                _params,
                escape=False)
            r_j = json.loads(r)
            newfan = 0
            cuser = 0
            for gcc in r_j['list']:
                if gcc['user_source'] == 51:
                    newfan = gcc['new_user']
                    cuser = gcc['cancel_user']

            auser = newfan - cuser

            xy['newfan'] = newfan
            xy['cuser'] = cuser
            xy['auser'] = auser
        except Exception, e:
            print e
            xy['allfan'] = 0
            xy['newfan'] = 0
            xy['cuser'] = 0
            xy['auser'] = 0
示例#4
0
    def POST(self):
        d = self.req.input()
        userid = d.get('userid', '').strip()
        type = d.get('type', '').strip()
        name = d.get('name', '').strip()
        licensenumber = d.get('licensenumber', '').strip()
        licensephoto = d.get('licensephoto', '').strip()
        checkstand = d.get('checkstand', '').strip()
        checkin = d.get('checkin', '').strip()
        sls_uid = int(self.user.userid)
        usertype = d.get('usertype', '').strip()
        nickname = d.get('nickname', '').strip()
        shopphoto = d.get('shopphoto', '').strip()

        if not usertype:
            usertype = 0

        if (not userid) or (not type) or (not name) or (not licensenumber) or \
           (not licensephoto) or (not checkstand) or (not checkin) or (not nickname) or (not shopphoto):
            raise ParamError('参数错误')

        client = ThriftClient(config.AUDIT_SERVERS, AuditServer)
        client.raise_except = True

        ret = client.call('update_sales',
                          userid=int(userid),
                          type=int(type),
                          name=str(name),
                          licensenumber=str(licensenumber),
                          licensephoto=str(licensephoto),
                          checkstand=str(checkstand),
                          checkin=str(checkin),
                          sls_uid=sls_uid,
                          nickname=nickname,
                          usertype=int(usertype),
                          shopphoto=shopphoto)

        if ret == 0:
            return self.write(success({}))
        else:
            raise ParamError('覆盖商户信息失败')
示例#5
0
def start():
    now = int(time.time())
    userids = []
    userids.append({"appid": "wxeb6e671f5571abce", "nickname": u"好近"})

    today = datetime.date.today()
    yesterday = today - datetime.timedelta(days=1)
    bfore_yesterday = today - datetime.timedelta(days=2)

    client = ThriftClient(config.WX_SERVER, QFMP, framed=False)
    client.raise_except = True
    open_ids = []

    b_30 = today - datetime.timedelta(days=60)

    tlist = []

    newfans = []
    with get_connection('qf_mis') as db:
        sql = "select channelid,channelname from channel_crm where channelid = 20395 "
        newfans = db.query(sql)

    print newfans
    exit(-1)

    # newfans = []
    # with get_connection('open_user') as db:
    #     sql = "select count(1) as newfan, userid as uid,appid,`chnluserid` as mchnt_id from `subscribe` where ctime between '2018-06-14 00:00:00' and '2018-06-14 23:59:59' and userid in (2104049) group by userid,appid,chnluserid "
    #     newfans = db.query(sql)
    #
    # print newfans
    # exit(-1)

    # r = Urllib2Client().get("http://192.20.20.12:8097/findChnlInfo")
    # r_j = json.loads(r)
    # ls = r_j['data']
    #
    # for xy in ls:
    #     tlist.append(xy['chnlTypeCode'])
    #
    # tlist = set(tlist)
    # print tlist  2235043

    # qudao_list = []
    # with get_connection('qf_core') as db:
    #
    #     #sql = "update profile set user_state = 1 where userid = 2235043  "
    #     sql = "select userid,idenddate from profile where userid = 2235826  "
    #
    #     # sql = "update apply set usertype = 1 where user in (1322810,1659877,1680586,2118907,2125555,2128594,2138725,2199637,2217508,2218048,2222098,2224777,2224822,2224864);"
    #     qudao_list = db.query(sql)
    #
    # print qudao_list
    #
    # exit(-1)

    # qudao_list = []
    # with get_connection('qf_audit') as db:
    #     sql = "select userid,ext,id from salesman_event where ext like '%\"oldusertype\": null%'  "
    #     #sql = "update apply set usertype = 1 where user in (1322810,1659877,1680586,2118907,2125555,2128594,2138725,2199637,2217508,2218048,2222098,2224777,2224822,2224864);"
    #     qudao_list = db.query(sql)
    #
    # print qudao_list

    deals = []
    with get_connection('qf_solar') as db:
        _sql = "select * from `mchnt_list` where  ctime between 20180613 and 20180613   and uid in (1987190)"
        deals = db.query(_sql)
    print deals

    exit(-1)

    # _data = client.call('access_token','wx2af0f30b8b10de0a')
    # _token = _data.access_token
    #
    # print _token
    # exit(-1)

    #获取微信数据
    # for xy in userids:
    #
    #     _data = client.call('access_token',xy['appid'])
    #     _token = _data.access_token
    #
    #     #总粉丝数
    #     r = Urllib2Client().get("https://api.weixin.qq.com/cgi-bin/user/get?access_token=%s&next_openid=" % _token)
    #     r_j = json.loads(r)
    #     xy['allfan'] = r_j["total"]
    #     open_ids = r_j['data']['openid']
    #
    #     #新增粉丝数
    #     _params = {"begin_date":str(yesterday).replace("-",''),"end_date":str(yesterday).replace("-",'')}
    #     r = Urllib2Client().post_json("https://api.weixin.qq.com/datacube/getusersummary?access_token=%s" % _token, _params,escape=False )
    #     r_j = json.loads(r)
    #     print r_j
    #     newfan = 0
    #     if r_j['list'][-1]:
    #         newfan = r_j['list'][-1]["new_user"]
    #
    #     xy['newfan'] = newfan
    # print userids
    #exit(-1)

    # #查看来源
    #
    # for jc in open_ids:
    #
    #     r = Urllib2Client().get("https://api.weixin.qq.com/cgi-bin/user/info?access_token=%s&openid=%s&lang=zh_CN" % (_token,str(jc)))
    #     r_j = json.loads(r)
    #     print r_j["subscribe_scene"]  2230180

    #获取交易笔数

    # deals = []
    # with get_connection('qf_audit') as db:
    #     _sql = "select userid,ext,state,type from `salesman_event` where type =2 and userid = 2192593  "
    #     deals = db.query(_sql)
    #
    # print deals
    # exit(-1)
    #
    # newfans = []
    # with get_connection('qf_solar') as db:
    #     #sql = "select count(1) as newfan, userid as uid,appid,`chnluserid` as mchnt_id from `subscribe` where DATE_FORMAT(ctime,'%%Y-%%m-%%d') = '2018-06-11'  group by userid,appid,chnluserid limit 10"
    #     #sql = "select * from salesman_event where userid = 2230180 and type = 1 "
    #     sql = "select chnlcode from app_rule   "
    #     newfans = db.query(sql)
    #
    # print newfans
    # exit(-1)
    #
    #
    # with get_connection('open_user') as db:
    #     #sql = "select count(1) as newfan, userid as uid,appid,`chnluserid` as mchnt_id from `subscribe` where DATE_FORMAT(ctime,'%%Y-%%m-%%d') = '2018-06-11'  group by userid,appid,chnluserid limit 10"
    #     sql = "select * from `subscribe` where chnluserid != '' order by userid desc limit 2"
    #     newfans = db.query(sql)
    #
    # print newfans
    # exit(-1)

    # deals = []
    # with get_connection('qf_solar') as db:
    #     _sql = "select * from `mchnt_list` where   ctime between 20180610 and 20180610   and uid in (1572440)"
    #     deals = db.query(_sql)
    #
    # print deals
    # exit(-1)

    # 获取交易笔数
    # deals = []
    # with get_connection('qf_solar') as db:
    #     _sql = "select count(DISTINCT `mchnt_id`) from `mchnt_list` where   id != 0  and ctime between 20180412 and 20180523 "
    #     deals = db.query(_sql)
    #
    # print deals
    # exit(-1)

    # deals = []
    # with get_connection('qf_audit') as db:
    #     _sql = "select userid,ext,state from `salesman_event` where userid = 1587465  "
    #     deals = db.query(_sql)
    #
    # print deals
    # exit(-1)1668004

    #slist = [1322810,1659877,1680586,2118907,2125555,2128594,2138725,2199637,2217508,2218048,2222098,2224777,2224822,2224864]
    slist = [2224858, 1709404, 2224648, 2075924, 2224402, 2209915, 2200336]

    # for xy in slist:
    #
    #
    #     with get_connection('qf_mis') as db:
    #         sql = "select userid,name,imgname from mis_voucher_history where userid =  %s and name = 'shopphoto' order by id desc limit 1 " % xy
    #         qudao_list = db.query(sql)
    #
    #     print qudao_list
    #
    #
    #     with get_connection('qf_mis') as db:
    #         sql = "update mis_upgrade_voucher set imgname = '%s' where user_id =  %s and name = 'shopphoto' " % (qudao_list[0]['imgname'],qudao_list[0]['userid'])
    #         db.query(sql)
    #
    # exit(-1)

    #
    # qudao_list = []
    # with get_connection('qf_audit') as db:
    #     sql = "select userid,ext,id from salesman_event where ext like '%\"oldusertype\": null%'"
    #     #sql = "update apply set usertype = 1 where user in (1322810,1659877,1680586,2118907,2125555,2128594,2138725,2199637,2217508,2218048,2222098,2224777,2224822,2224864);"
    #     qudao_list = db.query(sql)
    #
    # for xy in qudao_list:
    #     _ext = json.loads(xy['ext'])
    #     del _ext['oldusertype']
    #     _ext = json.dumps(_ext,ensure_ascii=False)
    #     _sql = "update salesman_event set ext = '%s' where id = %s " % (_ext,xy['id'])
    #     db.query(_sql)
    #
    # print qudao_list
    # exit(-1)
    #
    # deals = []
    # with get_connection('qf_trade') as db:
    #     sql = "select count(1) as deal,userid as uid,chnluserid as mchnt_id,chnlid from `%s` where sysdtm between '2018-05-31 00:00:00' and '2018-05-31 23:59:59'  and `status` = 1 and `busicd` in ('800201','800207','800208') and chnluserid = '226801000004003759372'  " % (
    #     'record_201805')
    #     print sql
    #     deals = db.query(sql)
    #
    #
    #
    # print deals
    # exit(-1)

    # deals = []
    # with get_connection('qf_mis') as db:
    #     _sql = "select user,ext,state from `salesman_event` where userid = 1587465  "
    #     deals = db.query(_sql)
    #
    # print deals
    # exit(-1)
    #
    # #2108593
    #
    #
    # with get_connection('qf_mis') as db:
    #     _sql = "select user_id,`name`,imgname from  `mis_upgrade_voucher` where user_id in (2170012) and name in ('checkstand_alipay','checkstand_weixin','checkin_weixin','checkin_alipay','licensephoto','goodsphoto','shopphoto')"
    #     img_list = db.query(_sql)
    #
    # def replace_img(imgname, userid):
    #     ret = 'http://pic.qfpay.com/userprofile/%d/%d/%s' % (int(userid) / 10000, int(userid), imgname)
    #     return ret
    #
    # dict_img = {'checkstand_alipay': '收银台照片_支付宝蓝海', 'checkstand_weixin': '收银台照片_微信绿洲'
    #     , 'checkin_weixin': '餐饮平台入驻照_微信绿洲', 'checkin_alipay': '餐饮平台入驻照_支付宝蓝海', 'goodsphoto': '店铺内景照片'
    #     , 'shopphoto': '店铺外景照片', 'licensephoto': '营业执照'}
    #
    # CUR_PATH = '../static/common/zip'
    #
    # for xy in img_list:
    #     img_src = replace_img(xy['imgname'], xy['user_id'])
    #     print img_src
    #     try:
    #         urllib.urlretrieve(img_src, "%s/%s_%s.jpg" % (CUR_PATH, str(xy['user_id']), dict_img[xy['name']]))
    #     except Exception, e:
    #         print e
    #         log.debug(str(e))
    # exit(-1)

    # deals = []
    # with get_connection('qf_mis') as db:
    #     _sql = "select user_id,`name`,imgname from  `mis_upgrade_voucher` where user_id in (2170012) and name in ('checkstand_alipay','checkstand_weixin','checkin_weixin','checkin_alipay','licensephoto','goodsphoto','shopphoto')"
    #     deals = db.query(_sql)
    #
    # print deals
    # exit(-1)
    #
    # deals = []
    # with get_connection('qf_core') as db:
    #     _sql = "select userid,feeratio from account where userid in (2206156) "
    #     deals = db.query(_sql)
    #
    # print deals
    # exit(-1)

    # deals = []
    # with get_connection('qf_audit') as db:
    #     _sql = "update `salesman_event` set state = 2,memo = '测试失败' where userid in (1993892,2086667)  "
    #     deals = db.query(_sql)
    #
    # print deals
    # exit(-1)

    #print yesterday

    # 获取交易笔数
    # deals = []
    # with get_connection('qf_mis') as db:
    #     _sql = "select user_id,detail from mis_oplog where admin_id = 320293 and action_time between '2018-04-25 00:00:00' and '2018-04-25 23:59:59'"
    #     deals = db.query(_sql)
    #
    # for xy in deals:
    #     _str = "%s|%s" % (xy['user_id'],xy['detail'])
    #     w = file('/home/qfpay/solar/1/bin/scripts/jobs.txt','a')
    #     w.write("%s\n" % _str)
    #     w.close()
    #
    # print deals

    # newfans = []
    # with get_connection('open_user') as db:
    #     sql = "select count(1) as newfan, userid as uid,appid,customer_id from `subscribe` where DATE_FORMAT(ctime,'%%Y-%%m-%%d') = '%s' and userid = 2086718 group by userid,appid,customer_id " % (
    #     yesterday)
    #     newfans = db.query(sql)
    #
    # print newfans

    #select `uid`,`id` from `mchnt_list` where   id != 0  and ctime between 20180411 and 20180411   and uid in (451869)

    # deals = []
    # with get_connection('qf_weifutong') as db:
    #      _sql = "select userid as uid,MAX(`ctime`) as stime  from `amchnl_bind` where userid = 2070263 and `state` = 1 group by userid order by stime desc "
    #      deals = db.query(_sql)

    #
    #  deals = []
    # with get_connection('open_user') as db:
    #     sql = "select count(1) as deal,userid as uid,ctime as dtime,`appid` from `open_user`.`subscribe` where ctime between '%s 00:00:00' and '%s 23:59:59' and userid = 2070263  group by userid order by ctime desc" % (
    #     b_30, yesterday)
    #     deals = db.query(sql)
    #
    # print deals

    #
    #  userids = []
    # with get_connection('wxmp_customer') as db:
    #     _sql = " select appid,nick_name from `mp_conf` where status = 1 and nick_name = '' "
    #     userids = db.query(_sql)
    # print userids  800100090148461

    # userids = [{'appid':'wxeb6e671f5571abce','name':u'好近'}]
    #
    # deals = []
    # with get_connection('qf_trade') as db:
    #     sql = "select count(1) as deal,userid as uid,chnluserid as mchnt_id,chnlid,`busicd`,`paydtm` from `%s` where  DATE_FORMAT(paydtm,'%%Y-%%m-%%d') = '2018-05-08'  and `status` = 1  and `busicd` in ('800201','800207','800208') group by mchnt_id " % (
    #     "record_201805")
    #     print sql
    #     deals = db.query(sql)
    #
    # _mchids = ""
    # for xy in deals:
    #     _mchids += "'%s'," % str(xy['mchnt_id'])
    # _mchids = _mchids.rstrip(",")
    #
    # newfans = []
    # with get_connection('qf_weifutong') as db:
    #     sql = "select `mchnt_id`,`subscribe_appid` as appid from `amchnl_bind` where  state = 1 and subscribe_appid != '' and mchnt_id in (%s)  group by  `mchnt_id`,`subscribe_appid` " % (
    #     _mchids)
    #     newfans = db.query(sql)
    #
    # for xy in userids:
    #     xy['mchnt_id'] = []
    #     for jx in newfans:
    #         if xy['appid'] == jx['appid']:
    #             xy['mchnt_id'].append(jx['mchnt_id'])
    #
    # for xy in userids:
    #     _shop = 0
    #     _deal = 0
    #
    #     _shop = len(xy['mchnt_id'])
    #
    #     for jx in deals:
    #         for jc in xy['mchnt_id']:
    #             if str(jc) == str(jx['mchnt_id']):
    #                 _deal += int(jx['deal'])
    #     xy['deal'] = _deal
    #     xy['shop'] = _shop
    #
    # print userids
    #
    #
    # exit(-1)

    #
    #  deals = []
    # with get_connection('qf_weifutong') as db:
    #      _sql = "select userid,mchnt_id from `amchnl_bind` where mchnt_id = '800100090148461' and `state` = 1 "
    #      deals = db.query(_sql)
    #
    # print deals

    # newfans = []
    # with get_connection('open_user') as db:
    #     sql = "select count(*) as newfan,userid as uid from (select * from (select openid,appid,userid from `subscribe` where DATE_FORMAT(ctime,'%%Y-%%m-%%d') = '%s' and userid = %s group by userid,appid) a WHERE NOT EXISTS  (select appid,userid from `subscribe` where DATE_FORMAT(ctime,'%%Y-%%m-%%d') <= '%s' and userid = %s group by userid,appid  ) ) c " % (
    #     yesterday,1336107, bfore_yesterday,1336107)
    #     print sql
    #     newfans = db.query(sql)
    # print newfans

    #1722811

    # newfans = []
    # with get_connection('qf_core') as db:
    #     sql = "select code,name from `channel`"
    #     newfans = db.query(sql)
    # print newfans

    # deals1 = []
    #
    # with get_connection('qf_weifutong') as db:
    #      _sql = "select `subscribe_appid`,`ctime` from `amchnl_bind` where `state` = 1 and userid = 2070263 order by ctime desc "
    #      deals1 = db.query(_sql)
    #
    # print deals1

    # ops = ''
    # for xy in open_ids:
    #     ops += "'%s'," % xy
    # ops = ops.rstrip(",")
    #
    # deals_openid = []
    # with get_connection('open_user') as db:
    #     _sql = "select openid,userid,appid from `subscribe` where DATE_FORMAT(ctime,'%%Y-%%m-%%d') = '%s' and openid in (%s) group by openid " % (str(yesterday),str(ops))
    #     deals_openid = db.query(_sql)
    exit(-1)

    for xy in userids:
        _shop = 0
        _deal = 0
        for jx in deals:
            if xy['appid'] == jx['appid']:
                _shop = int(jx['shop'])
                _deal = int(jx['deal'])
        if _deal == 0:
            _fan = "0%"
        else:
            _fan = "%s%%" % str(round(int(xy['newfan']) / int(_deal), 4))

        xy['shop'] = _shop
        xy['deal'] = _deal
        xy['fan'] = _fan
示例#6
0
def thrift_callex_framed(server_config, mod, func, *args, **kwargs):
    client = ThriftClient(server_config, mod, framed=True)
    client.raise_except = True
    return client.call(func, *args, **kwargs)
示例#7
0
    def GET(self):
        uname = self.get_cookie('uname')
        data = {}
        data['uname'] = uname
        conf_name = APP_CUSTOM

        # app_id = 48
        # conf_id = 13
        # conf_dict = get_app_conf_dict(app_id, conf_id, app_conf=conf_name)
        # print conf_dict

        import redis
        # 连接,可选不同数据库
        r = redis.Redis(host='172.100.102.101', port=6379, db=7)

        data = {'id': '123'}

        r.hset('rekey', 123, data)

        all_audits = r.hgetall('rekey')

        # for (d,x) in all_audits.items():
        #     print x


        # -------------------------------------------
        # 看信息
        #keys = r.keys()
        #print type(keys)
        #print r.exists('appcustom_appid12_confid39_dict')
        #print r.hget('appcustom_appid12_confid39_dict')

        # with get_connection('qf_core') as db:
        #     profiles = db.select(
        #         table='profile',
        #         fields='userid',
        #         where={'userid': (' = ',10516)}
        #     )
        #     userids = [i['userid'] for i in profiles or []]
        # print len(userids)

        #keys = r.keys()
        #print type(keys)

        #[{'addr': ('172.100.101.107', 6900), 'timeout': 2000}, ]

        #client = ThriftClient([{'addr': ('127.0.0.1',7100), 'timeout': 6000}, ], AuditServer)
        #client = ThriftClient([{'addr': ('172.100.101.110', 7100), 'timeout': 6000}, ], AuditServer)

        #client = ThriftClient([{'addr': ('172.100.101.107', 6900), 'timeout': 2000}, ], ApolloServer)

        _info = '{"usertype":"1","mobile":"18650005057","nickname":"萌宠乐园宠物用品店","licensenumber":"92350205MA2YNJ287E","legalperson":"法人代表","idnumber":"350204199411150028","dishonestyinfo":"0","idnumbertime":"2017-01-01到2017-01-09","src":"签约宝","shoptype":"分店","otherid":"业务员","nickname":"收据名称","mcc":"1005","shop_province":"北京","shop_city":"北京","shop_address":"厦门市沧林东一里573号","telephone":"1231231","email":"*****@*****.**","banktype":"1","bankuser":"******","account_province":"北京","account_city":"北京","headbankname":"北京银行","bankname":"北京银行","bankcode":"12312","channel_type":"合伙人","salesmanname":"你好","salesmanname":"你好","channel_name":"你好","channel_province":"北京","channel_city":"北京","memo":"无","risk_level":"123","risk_level":"123","alipay_ratio": 0.0038,"qqpay_ratio": 0.0038,"tenpay_ratio": 0.0038,"jdpay_ratio": 0.006,"fee_ratio": 0.006,"credit_ratio": 0.006,"bankaccount":6217231510001346967,"cardstart":"2017-03-05","cardend":"2017-05-01","usertags":["123","456"],"salesman_memo":"234","audit_record":[{"operator":"0","audit_result":"自动审核成功","audit_time":"2017-10-01","audit_memo":"自动审核成功"}],"piclist":[{"name":"idcardfront","src":"http://pic.qfpay.com/userprofile/205/2053691/middle_5fb259576ad455e4949f6767f20ca297.jpg"},{"name":"idcardback","src":"http://pic.qfpay.com/userprofile/205/2053691/middle_5fb259576ad455e4949f6767f20ca297.jpg"}]}'

        #client.raise_except = True
        #re = client.call('add_audit', Audit(audit_type='signup',userid=10516,groupid=10,info=_info))
        _m = '{"nickname":"123","usertags":["777"],"audit_record":{"operator":"123","audit_result":"123","audit_time":"123","audit_memo":"123"}}'
        #re = client.call('audit_api',id='6366572138127548259',type='4',modify=_m)


        #re = thrift_callex([{'addr': ('172.100.101.110',7100), 'timeout': 6000}, ], AuditServer, 'ping')

        #client = ThriftClient([{'addr': ('172.100.108.65',7100), 'timeout': 16000}, ], AuditServer,framed=False)


        _info = {}

        _piclist = []


        # for i in range(20):
        #     _piclist.append({"name": str('123'), "src": str('至'), "cert_type": str(100)})

        # _info["piclist"] = _piclist
        # _info["nickname"] = '123123你好'
        # _info["mcc"] = "12313"
        # _info["src"] = u"12313"
        # _info["tenpay_ratio"] = "12313"
        # _info["alipay_ratio"] = "12313"
        # _info = byteify(_info)
        # _info = json.dumps(_info,ensure_ascii=False)

        #测试成都
        #101.204.228.105:6221

        # from qfcommon.thriftclient.weifutong.ttypes import WechatConf,WechatConfUpdateItem,WechatConfUpdateArg,CHNLCODE
        #
        # client = ThriftClient([{'addr':('101.204.228.105',6221),'timeout': 8000},],weifutong,framed=True)
        # client.raise_except = True
        # s_list = []
        # _wc = WechatConf(jsapipath='["http://123"]',sub_appid='wx087a3fc3f3757766',subscribe_appid='wx087a3fc3f3757766')
        # _va = WechatConfUpdateItem(userid=21006662,wechat_conf=_wc,chnlcode=9)
        # s_list.append(_va)
        # client.call('wechatconf_update',arg=WechatConfUpdateArg(batch_id='1231234567899090123',src='audit.1',wechatconf_list=s_list))

        client = ThriftClient([{'addr': ('172.100.101.110', 7100), 'timeout': 8000}, ], AuditServer, framed=False)
        #client = ThriftClient([{'addr': ('172.100.101.107', 7200), 'timeout': 8000}, ], AuditServer, framed=False)
        #client = ThriftClient([{'addr': ('127.0.0.1',7100), 'timeout': 6000}, ],AuditServer, framed=False)
        # client = ThriftClient([{'addr': ('192.10.2.150',7201), 'timeout': 6000}, ], AuditServer, framed=False)
        # client.raise_except = True
        list = client.call('app_api',[704263],5)
        print list

        #测试威富通通道结果
        from qfcommon.thriftclient.weifutong import weifutong
        from qfcommon.thriftclient.weifutong.ttypes import CHNLCODE, QueryMeta, AddMchntQueryArg

        TONGDAOS = [CHNLCODE.CITIC, CHNLCODE.ZXWC, CHNLCODE.FUIOU, CHNLCODE.HUIYI, CHNLCODE.HYQK,
                    CHNLCODE.WANGSHANG,
                    CHNLCODE.DAZEPOINT,
                    CHNLCODE.YEEPAY,
                    CHNLCODE.HUITONG,
                    CHNLCODE.WEIXIN,
                    CHNLCODE.FUIOU_LVZHOU,
                    CHNLCODE.HELIBAO
                    ]

        client = ThriftClient([{'addr': ('192.10.2.150', 6221), 'timeout': 2000}, ], weifutong, framed=True)
        client.raise_except = True

        _uids = [2202982]

        merchant_dic = {}
        queryMeta = QueryMeta()
        queryMeta.offset = 0
        queryMeta.count = 10
        queryMeta.orderby = 'utime desc'

        addMchntQueryArg = AddMchntQueryArg()
        addMchntQueryArg.query_meta = queryMeta
        addMchntQueryArg.userid_list = _uids
        addMchntQueryArg.chnlcode_list = TONGDAOS
        record_ids_l = client.call('addmchnt_query', addMchntQueryArg)

        addMchntRecord_d = client.call('addmchnt_get', record_ids_l)
        l1 = []
        for (key, ve) in addMchntRecord_d.items():
            l1.append({'state':ve.state,'errmsg':ve.errmsg,'chnlcode':ve.chnlcode,'ctime':ve.ctime})
        l1.sort(key=lambda k: (k.get('ctime', 0)),reverse=True)
        l4 = []
        l4.append(l1[0])
        for dict in l1:
            # print len(l4)
            k = 0
            for item in l4:
                # print 'item'
                if dict['chnlcode'] != item['chnlcode']:
                    k = k + 1
                    # continue
                else:
                    break
                if k == len(l4):
                    l4.append(dict)
        print l1


        #print addMchntRecord_d[6389763976217181206].chnlcode




        #client = ThriftClient([{'addr': ('172.100.101.107', 7200), 'timeout': 8000}, ], AuditServer, framed=False)

        #client = ThriftClient([{'addr': ('127.0.0.1',7100), 'timeout': 6000}, ], AuditServer, framed=False)

        #re = client.call('ping')
        #re = client.call('add_audit', Audit(audit_type='signup', userid=10516, groupid=10,info=_info))


        #client = ThriftClient([{'addr':('192.30.2.173', 8001), 'timeout':50000}], QudaoServer, framed=True)
        #client.raise_except = True
        #QudaoBaseInfo = client.call('qd_get_hierarchy',[1764616,1778227],1)

        #list = client.call('app_api',[21006662])
        #print list['wx087a3fc3f3757766'].jsapipath
        #from qfcommon.thriftclient.audit.ttypes import AppInfo
        #AppInfo = list[0]
        #print AppInfo.pay_appid
        #print AppInfo.appid
        #print AppInfo.jsapipath
        #print AppInfo.uid

        # _zhi = {'id': 1, 'type': 123}
        #
        # json_data = json.dumps(_zhi)
        #
        # r.lpush("1",json_data)
        #
        # data1 = r.brpop("1")
        #
        # print data1

        #r.set("name",'123')


        # with get_connection('open_user') as db:
        #     userids = db.select(
        #         table='amchnl_bind',
        #         fields='subscribe_appid,ctime')


        # from qfcommon.thriftclient.qf_wxmp import QFMP
        # from qfcommon.thriftclient.qf_wxmp.ttypes import WXToken
        #
        # weixin_server = [{'addr': ('192.30.2.168', 6150), 'timeout': 8000},]
        # weixin_server = [{'addr': ('172.100.101.107', 6120), 'timeout': 8000},]
        #
        # client = ThriftClient(weixin_server,QFMP,framed=False)
        # client.raise_except = True
        # _data = client.call('access_token','wx087a3fc3f3757766')
        #
        # print _data.access_token


        return json.dumps({'data': '123'}, ensure_ascii=False)
示例#8
0
def thrift_callex(server, thriftmod, funcname, *args, **kwargs):
    client = ThriftClient(server, thriftmod)
    client.raise_except = True

    return client.call(funcname, *args, **kwargs)
示例#9
0
    def GET(self):
        d = self.req.input()
        page = d.get('page', 0)
        pagesize = d.get('pagesize', 10)
        userid = self.user.userid

        paging = (int(pagesize), int(pagesize) * int(page))
        other = 'order by create_time desc limit {} offset {}'.format(*paging)
        ret = {'records': []}

        # 查询交易记录和消费品名称
        records = []
        titles = []
        titles_dict = {}
        with get_connection_exception('qf_marketing') as db:
            records = db.select(
                table='record',
                fields=['customer_id', 'create_time', 'activity_id', 'xx_id'],
                where={
                    'type': RECORD_STATUS_USE,
                    'xx_type': ACTIVITY_SHARE_TYPE_GOODS_COUPON,
                    'use_mchnt_id': userid,
                },
                other=other)

            if not records:
                return self.write(success(ret))

            act_ids = [record.get('activity_id') for record in records]

            titles = db.select(table='activity',
                               fields=['title', 'id'],
                               where={'id': ('in', act_ids)})
            if not titles:
                raise ParamError('获取兑换商品失败')

            titles_dict = {title['id']: title['title'] for title in titles}

        # 查询消费者信息
        cids = {i['customer_id'] for i in records}
        spec = json.dumps({'user_id': list(cids)})

        client = ThriftClient(config.OPENUSER_SERVER, OpenUser)
        client.raise_except = True
        infos = []
        try:
            infos = client.call('get_profiles', config.OPENUSER_APPID, spec)
            infos = {i.user_id: i.__dict__ for i in infos}
        except:
            log.warn(traceback.format_exc())
            raise ThirdError('获取用户信息失败')

        # 整理信息
        for i in records:
            cust_id = int(i['customer_id'])
            cust_info = infos.get(cust_id) or {}
            avatar_str = cust_info.get('avatar') or ''
            i['avatar_url'] = avatar_str.split(':', 1)[-1]
            i['gender'] = cust_info.get('gender') or 0
            i['nickname'] = cust_info.get('nickname') or '微信支付顾客'
            i['exchange_time'] = i['create_time'].strftime('%H:%M:%S')
            i['goods_name'] = titles_dict.get(i.pop('activity_id'), '未知商品')
            i['exchange_code'] = hids.encode(i.pop('xx_id'))

        date_records = defaultdict(list)
        for i in records:
            t = i.pop('create_time').strftime(DATE_FMT)
            date_records[t].append(i)

        # 查询每日的交易数量
        sql = (
            'select FROM_UNIXTIME(create_time, "%%Y-%%m-%%d") as date, '
            'count(id) as num from record '
            'where use_mchnt_id=%s and xx_type=%s and type=%d '
            'group by FROM_UNIXTIME(create_time, "%%Y%%m%%d") '
            'order by create_time desc' %
            (str(userid), ACTIVITY_SHARE_TYPE_GOODS_COUPON, RECORD_STATUS_USE))
        data_infos = []
        with get_connection('qf_marketing') as db:
            data_infos = db.query(sql)
        if not data_infos:
            raise ParamError('获取消费者数量失败')

        # 整理返回信息
        ret = []
        for i in data_infos:
            date = i['date']
            tmp = {}
            tmp['date'] = i['date']
            tmp['use_cnt'] = i['num']
            tmp['customers'] = date_records.get(date) or []
            ret.append(tmp)
        return self.write(success({'records': ret}))
示例#10
0
    def auto_apply(self, userid):
        data = self._data
        td, now = time.strftime(DATE_FMT), time.strftime(DATETIME_FMT)
        #新审核系统预设参数
        info = {}
        #凭证参数
        piclist = []

        # 字典转码
        def byteify(input):
            if isinstance(input, dict):
                return {
                    byteify(key): byteify(value)
                    for key, value in input.iteritems()
                }
            elif isinstance(input, list):
                return [byteify(element) for element in input]
            elif isinstance(input, unicode):
                return input.encode('utf-8')
            else:
                return input

        # 写入凭证
        with get_connection('qf_mis') as db:
            d = {k: v.strip() for k, v in self.req.input().iteritems()}
            cert_types = UserDefine.CERT_TYPE
            for code in UserDefine.CERT_TYPE_LIST:
                if (code not in d or not d[code] or code not in cert_types):
                    continue
                insert_data = {
                    'user_id': userid,
                    'upgrade_id': 0,
                    'apply_level': 0,
                    'cert_type': cert_types[code],
                    'name': code,
                    'submit_time': now,
                    'state': 1,
                    'input_state': 1,
                    'typist_user': 0,
                    'typist_time': now,
                    'imgname': d[code]
                }

                try:
                    piclist.append({
                        "name": str(code),
                        "src": str(d[code]),
                        "cert_type": str(cert_types[code])
                    })
                    db.insert('mis_upgrade_voucher', insert_data)
                except:
                    log.debug(traceback.format_exc())

        info["piclist"] = piclist

        # 写入审核
        version, platform = get_app_info(
            self.req.environ.get('HTTP_USER_AGENT', ''))
        src = ''.join([data['src'], platform, version])
        idstatdate = (data['idstatdate'] if is_valid_date(
            data.get('idstatdate')) else td)
        idenddate = (data['idenddate']
                     if is_valid_date(data.get('idenddate')) else td)

        # mcc
        if data['cate'] == 'saleman' and not data['shoptype_id']:
            mcc = UserDefine.DEFAULT_SALEMAN_MCC
        else:
            mcc = UserUtil.get_mcc(data['shoptype_id'])

        apply_values = {
            'user': int(userid),
            'usertype': data['usertype'],
            'legalperson': data['legalperson'] or data['bankuser'],
            'name': data['name'],
            'idnumber': data['idnumber'],
            'idstatdate': idstatdate,
            'idenddate': idenddate,
            'telephone': data['landline'],
            'idphoto1': data['idcardfront'],
            'idphoto2': data['idcardback'],
            'licenseend_date': td,
            'licensephoto': '',
            'taxenddate': td,
            'longitude': covert(data['longitude'], float),
            'latitude': covert(data['latitude'], float),
            'address':
            ''.join([data['city'], data['location'], data['address']]),
            'city': data['city'],
            'province': data['province'],
            'mobile': data['username'],
            'headbankname': data['headbankname'],
            'banktype': (2 if data['banktype'] == '2' else 1),
            'bankname': data['bankname'],
            'bankuser': data['bankuser'],
            'bankProvince': data['bankprovince'],
            'bankCity': data['bankcity'],
            'bankaccount': data['bankaccount'].replace(' ', ''),
            'state': 4,
            'brchbank_code': data['bankcode'],
            'mcc': mcc,
            'nickname': data['shopname'],
            'src': src,
            'groupid': data['groupid'],
            'srctype': UserDefine.SIGNUP_SRCTYPE_TINY,  # 先固定为小微商户
            'edu': 1,
            'monthincome': 0,
            'monthexpense': 0,
            'tid': '',
            'terminalcount': 1,
            'last_admin': 0,
            'allowarea': 0,
            'needauth': 2,
            'passcheck': 2,
            'last_modify': now,
            'post': '',
            'provision': '',
            'bankmobile': data['bankmobile'],
            'monthtradeamount': 1,
            'founddate': td,
            'area': 100,
            'payment_type': 1,
            'rent_count': 0,
            'pertradeamount': 1,
            'rent_total_amt': -1,
            'utime': now,
            'uploadtime': now,
            "licensenumber": data.get("licensenumber", "")
        }

        # 获取上传费率
        apply_values['ratio'] = self.get_ratio() or ''

        #收集后台需要的字段,摒弃废弃字段,后期只用下面的字段
        userid = int(userid)
        groupid = int(data['groupid'])

        info["usertype"] = data['usertype']
        info["mobile"] = data['username']
        info["name"] = data['name']
        info["cardstart"] = data['idstatdate']
        info["cardend"] = data['idenddate']
        info["legalperson"] = data['legalperson'] or data['bankuser']
        info["src"] = data['src']
        info["licensenumber"] = data['licensenumber']
        info["mcc"] = mcc
        info["risk_level"] = "54"
        info["telephone"] = data['landline']
        info["nickname"] = data['shopname']
        info["bankaccount"] = data['bankaccount'].replace(' ', '')
        info["shop_province"] = data['province']
        info["shop_city"] = data['city']
        info["shop_address"] = data['address']
        info["banktype"] = (2 if data['banktype'] == '2' else 1)
        info["bankname"] = data['bankname']
        info["bankuser"] = data['bankuser']
        info["headbankname"] = data['headbankname']
        info["bankcode"] = data['bankcode']

        fee = self.get_ratio() or ''
        if fee != '':
            fee = json.loads(fee)
            for (k, v) in fee.items():
                info[k] = v

        info = byteify(info)
        info = json.dumps(info, ensure_ascii=False)

        #指定的灰度渠道下商户进入新审核逻辑
        if groupid in config.NEW_AUDIT_GROUP:
            client = ThriftClient(config.AUDIT_SERVERS,
                                  AuditServer,
                                  framed=False)
            client.raise_except = True
            re = client.call(
                'add_audit',
                audit_api(audit_type='signup',
                          userid=userid,
                          groupid=groupid,
                          info=info))

        #其他渠道的商户继续老的审核系统
        else:
            with get_connection('qf_mis') as db:
                db.insert('apply', apply_values)

        self.set_cache_audit(userid, 2)