def _get_user(self, userid): try: r = Apollo(config.APOLLO_SERVERS).user_by_id(userid) if r: return {k:v or '' for k, v in r.iteritems()} except: log.warn('get userinfo error:%s' % traceback.format_exc()) return {k:v or '' for k, v in User().__dict__.iteritems()}
def GET(self): ret = {} ret['user_service'] = self._get_user_service() # 用户基础信息 userinfo = Apollo(config.APOLLO_SERVERS).user_by_id(self.user.userid) # 线下店铺信息 user_ext = apcli_ex('getUserExt', int(userinfo['uid'])) ret.update(UserUtil.ret_userinfo(userinfo, user_ext)) return self.write(success(ret))
def _get_user_service(self): # 用户服务列表, 最少返回默认的列表 user_service = Apollo(config.APOLLO_SERVERS).user_service( self.user.userid) user_service = {}.fromkeys([i['code'] for i in user_service] + config.DEFAULT_SERVICES).keys() # 获取版本号 log.debug('user_agent:%s' % self.req.environ.get('HTTP_USER_AGENT', '')) version, platform = get_app_info( self.req.environ.get('HTTP_USER_AGENT', '')) log.info('version:%s platform:%s' % (version, platform)) # 根据版本号和平台获取服务列表 services = get_services(version, platform) services.sort(key=lambda x: x.get('weight', 0), reverse=True) scodes = [i['code'] for i in services] return [i for i in scodes if i in user_service]
def GET(self): userid = self.user.userid ret = {} # 获取九宫格模块 ret['modules'] = self._get_modules(userid) # 是否允许余额 ret['balance_enable'] = int('balance' in self._user_service) # 用户基础信息 userinfo = Apollo(config.APOLLO_SERVERS).user_by_id(userid) # 线下店铺信息 user_ext = apcli_ex('getUserExt', int(userid)) ret.update(UserUtil.ret_userinfo(userinfo, user_ext)) # 获取审核信息 ret.update(self.get_audit_info()) return self.write(success(ret))
import config import redis import hashids from qfcommon.qfpay.apolloclient import Apollo from qfcommon.qfpay.presmsclient import PreSms from qfcommon.web import cache as qf_cache qfcache = qf_cache.install() # hids hids = hashids.Hashids(config.QRCODE_SALT) # redis连接池 redis_conf = config.CACHE_CONF['redis_conf'] redis_pool = redis.Redis(host=redis_conf['host'], port=redis_conf['port'], password=redis_conf['password']) # mmwd redis cli ms_redis_pool = redis.Redis(**config.MMWD_SOCIAL_REDIS) # apollo cli apcli = Apollo(config.APOLLO_SERVERS) # 短信服务 cli smscli = PreSms(config.PRESMS_SERVERS) # geo redis cli geo_redis_pool = redis.Redis(**config.GEO_REDIS_CONF)
def _handle(self): cid = self.customer.customer_id wx_info = tools.get_weixin_profile(cid) log.info('cid %s weixin info ::: %s', cid, wx_info) if not wx_info: return self.request_finish(RESP_CODE.INNER_SERVICE_ERR, resperr='微信信息获取错误') cid_user_ids = tools.query_cid_user(cid) if cid_user_ids: cid_user_info = tools.get_cid_user(cid_user_ids) log.info('func=user_info|cid_user_info=%s', cid_user_info) role_type = cid_user_info.role base = { 'nick_name': wx_info['nickname'], 'head_url': wx_info['avatar'], 'role_type': role_type, 'mobile': cid_user_info.mobile, } info = [] # 借款人基本信息查询 if role_type == fenqi_api_ttypes.USER_ROLE.BORROWER: borrower_ids = tools.query_borrower(cid) borrower_info = tools.get_borrower(borrower_ids) base.update({ 'status': borrower_info.user_status, 'real_name': '', 'idnumber': '' }) # 销售基本信息查询 elif role_type == fenqi_api_ttypes.USER_ROLE.OPUSER: opuser_ids = tools.query_opuser(cid) opuser_info = tools.get_opuser(opuser_ids) base.update({ 'status': opuser_info.status, 'real_name': opuser_info.name, 'idnumber': opuser_info.idnumber }) store_ids = tools.query_store(store_mgr_uids=opuser_info.userid) store_info = tools.get_store(store_ids) client = Apollo(APOLLO_SERVER) profile = client.userprofile_by_id(store_info.userid) if not profile: return self.request_finish(RESP_CODE.PARAM_ERROR, resperr='查询用户信息失败') district_info = tools.get_district([store_info.district_id]) info.append({ "district_name": district_info.name, "role_name": "销售员", "store_name": profile['user']['shopname'], "address": store_info.address }) # 门店管理人基本信息查询 elif role_type == fenqi_api_ttypes.USER_ROLE.STORE_MGR: store_mgr_ids = tools.query_store_mgr(cid) store_mgr_info = tools.get_store_mgr(store_mgr_ids) base.update({ 'status': store_mgr_info.status, 'real_name': store_mgr_info.name, 'idnumber': store_mgr_info.idnumber }) store_ids = tools.query_store(store_mgr_uids=store_mgr_info.userid) store_info = tools.get_store(store_ids) client = Apollo(APOLLO_SERVER) profile = client.userprofile_by_id(store_info.userid) if not profile: return self.request_finish(RESP_CODE.PARAM_ERROR, resperr='查询用户信息失败') district_info = tools.get_district([store_info.district_id]) info.append({ "district_name": district_info.name, "role_name": "门店管理人", "store_name": profile['user']['shopname'], "address": store_info.address }) # 大区负责人信息查询 elif role_type == fenqi_api_ttypes.USER_ROLE.DISTRICT_MGR: district_mgr_ids = tools.query_district_mgr(cid) district_mgr_info = tools.get_district_mgr(district_mgr_ids) base.update({ 'status': district_mgr_info.status, 'real_name': district_mgr_info.name, 'idnumber': district_mgr_info.idnumber }) district_ids = tools.query_district(district_mgr_uids=district_mgr_info.userid) district_info = tools.get_district(district_ids) info.append({ 'district_name': district_info.name, 'role_name': '大区负责人', }) else: return self.request_finish(RESP_CODE.DATA_ERROR, resperr='暂不支持该类型用户查询') return self.request_finish(RESP_CODE.SUCCESS, data={'base': base, 'info': info}) else: return self.request_finish(RESP_CODE.DATA_ERROR, resperr='用户没有绑定手机号')