def POST(self): params = self.req.input() userid = int(self.user.userid) new_username = params.get('new_username', '').strip() if not new_username: raise ParamError('新账号不能为空') # 验证grant_code grant_code = params.get('grant_code') or '' self.check_grant_code(userid, grant_code) # 验证verify_code verify_code = params.get('verify_code') or '' if not check_smscode(verify_code, new_username, mode=1): raise ParamError('验证信息错误') # 验证新账号是否被占用 with get_connection_exception('qf_core') as db: new_user = db.select_one('auth_user', where={'username': new_username}) if new_user: raise ParamError('新账号已经被占用') # apollo接口修改username try: apcli_ex('changeUsername', userid, new_username) except ApolloException as e: raise ThirdError(e.respmsg) # 将现有设备踢下线 kick_user(userid, mode='all') return success({})
def get_shopinfo(self, userid): user = apcli_ex('findUserBriefById', userid) if not user: raise ParamError('商户不存在') shopinfo = { 'shopname': user.shopname, 'mobile': user.mobile, 'addr': user.address, 'head_img': '', 'logo_url': '', 'trade_total_num': 0 } # 获取交易笔数 rkey = '_paycell_trade_stat_{}_'.format(time.strftime('%Y%m')) shopinfo['trade_total_num'] = int(redis_pool.hget(rkey, userid) or 0) user_ext = apcli_ex('getUserExt', userid) if user_ext: shopinfo['head_img'] = user_ext.head_img shopinfo['logo_url'] = user_ext.logo_url if not shopinfo['head_img']: shopinfo['head_img'] = get_qd_conf_value_ex( groupid=user.groupid, mode='default_head_img', key='ext') or '' if not shopinfo['logo_url']: shopinfo['logo_url'] = get_qd_conf_value_ex( groupid=user.groupid, mode='default_logo_url', key='ext') or '' return shopinfo
def get_cards(self, customer_id, groupid=None, offset=0, limit=10): '''获取会员卡''' self._cards_total_num = 0 mems = None with get_connection('qf_mchnt') as db: mems = db.select('member', where={'customer_id': customer_id}, fields='userid', other='order by ctime desc') if not mems: return [] # 获取关系列表 # 子商户全转化为大商户userid relations = get_relations() or {} userids = [] for mem in mems: userid = relations.get(mem['userid'], mem['userid']) if userid not in userids: userids.append(userid) if is_valid_int(groupid): userid_cache_list = userid_cache[groupid] userids = list(set(userids) & set(userid_cache_list)) self._cards_total_num = len(userids) userids = userids[offset:offset + limit] if not userids: return [] user_exts = apcli_ex('getUserExts', userids) user_exts = {i.uid: i for i in user_exts} apollo_shops = apcli_ex('findUserBriefsByIds', userids) or {} if apollo_shops: apollo_shops = {shop.uid: shop for shop in apollo_shops} bg_urls = config.CARDS_BG_URLS cards = [] for userid in userids: card = { 'userid': hids.encode(int(userid)), 'nickname': '', 'bg_url': bg_urls[userid % 10 % len(bg_urls)], } user = apollo_shops.get(userid) if user: card['nickname'] = user.shopname user_ext = user_exts.get(userid) if user_ext: card['logo_url'] = user_ext.logo_url card['head_img'] = user_ext.head_img if (not card.get('head_img') or card['head_img'] == config.DEFAULT_HJ_HEAD_IMG): card['head_img'] = config.DEFAULT_SHOP_HEAD_IMG if not card.get('logo_url'): card['logo_url'] = config.DEFAULT_SHOP_LOGO_URL cards.append(card) return cards
def GET(self): userid = int(self.user.userid) ret = {} userinfo = apcli('findUserByid', userid).__dict__ ret['shopinfo'] = {} ret['shopinfo']['shopname'] = userinfo.get('shopname') ret['shopinfo']['city'] = userinfo.get('city') ret['shopinfo']['province'] = userinfo.get('province') ret['shopinfo']['telephone'] = userinfo.get('telephone') ret['shopinfo']['address'] = userinfo.get('address') # 同步审核后的商户名称 apply_info = {} with get_connection('qf_mis') as db: apply_info = db.select_one(table='merchant_change_apply', where={ 'userid': userid, 'changetype': 2, 'status': 3 }, fields='applyjson', other='order by modifytime desc') val = {} if apply_info: apply_dict = json.loads(apply_info['applyjson']) val['shopname'] = unicode_to_utf8( apply_dict['change_apply']['nickname']) if val['shopname'] != ret['shopinfo']['shopname']: apcli_ex('updateUser', int(userinfo['uid']), User(**val)) ret['shopinfo']['shopname'] = val['shopname'] return success(ret)
def get_sub_list(self, params): ret = {'shops': [], 'total_num': 0} # 大商户userid big_uid = hids.decode(params.get('code')) if not big_uid: return success(ret) big_uid = big_uid[0] # 子商户userid relates = apcli_ex('getUserRelation', int(big_uid), 'merchant') or [] link_ids = [i.userid for i in relates] ret['total_num'] = len(relates) limit, offset = self.get_pageinfo() link_ids = link_ids[offset:offset + limit] if not link_ids: return success(ret) users = apcli_ex('findUserBriefsByIds', link_ids) or [] user_dict = {user.uid: user.__dict__ for user in users} user_exts = apcli_ex('getUserExts', link_ids) or [] user_ext_dict = {i.uid: i.__dict__ for i in user_exts} shops = [] for link_id in link_ids: tmp = {} user = user_dict.get(link_id, {}) tmp['shopname'] = user.get('shopname', '') tmp['mobile'] = user.get('mobile', '') tmp['address'] = user.get('address', '') tmp['enuserid'] = hids.encode(link_id) user_ext = user_ext_dict.get(link_id, {}) tmp['head_img'] = user_ext.get('head_img', '') tmp['logo_url'] = user_ext.get('logo_url', '') if not tmp['head_img']: tmp['head_img'] = get_qd_conf_value_ex(groupid=user.get( 'groupid' or 0), mode='default_head_img', key='ext') or '' if not tmp['logo_url']: tmp['logo_url'] = get_qd_conf_value_ex(groupid=user.get( 'groupid', 0), mode='default_logo_url', key='ext') or '' shops.append(tmp) ret['shops'] = shops return success(ret)
def add_user_ext(self, userid): data = self._data user_ext = UserExt( uid=int(userid), shoptype_id=data['shoptype_id'], contact=data.get('landline', ''), head_img=data.get('head_img'), logo_url=data.get('logo_url'), ) if is_valid_int(data.get('regionid')): user_ext.regionid = int(data['regionid']) apcli_ex('bindUserExt', user_ext)
def get_shops(self, userid, offset=0, limit=5): ''' 获取门店列表 ''' self._shop_num = 0 relations = get_relations() or {} relations_re = defaultdict(list) for linkid, uid in relations.iteritems(): relations_re[uid].append(linkid) if userid not in relations_re: return [] self._shop_num = len(relations_re[userid]) userids = relations_re[userid][offset:limit] if not userids: return [] user_exts = apcli_ex('getUserExts', userids) user_exts = {i.uid: i for i in user_exts} apollo_shops = apcli_ex('findUserBriefsByIds', userids) or {} if apollo_shops: apollo_shops = {shop.uid: shop for shop in apollo_shops} # 店铺信息 shops = [] for uid in userids: shopinfo = {} shopinfo['userid'] = hids.encode(int(uid)) user = apollo_shops.get(uid) if user: shopinfo['address'] = user.address shopinfo['mobile'] = user.mobile shopinfo['shopname'] = user.shopname user_ext = user_exts.get(uid) if user_ext: shopinfo['head_img'] = user_ext.head_img shopinfo['logo_url'] = user_ext.logo_url shopinfo['mobile'] = user_ext.contact if (not shopinfo.get('head_img') or shopinfo['head_img'] == config.DEFAULT_HJ_HEAD_IMG): shopinfo['head_img'] = config.DEFAULT_SHOP_HEAD_IMG if not shopinfo.get('logo_url'): shopinfo['logo_url'] = config.DEFAULT_SHOP_LOGO_URL shops.append(shopinfo) return shops
def POST(self): mode = self.req.inputjson().get('mode', 'mchnt') userid = None # 普通商户预注册 # 验证验证码 if mode == 'mchnt': username, userid = self.username_mchnt() # 大商户预注册子商户 # 验证登录状态 elif mode == 'bigmchnt': username = self.username_bigmchnt() else: raise ParamError('该摸式不支持预注册') if not userid: userid = apcli_ex('preRegister', username, '', '') if not userid: raise DBError('预注册失败') enuserid = UserUtil.o2_syssn_encode( int(userid) + UserDefine.o2_BASE_MAGIC_NUMBER) return success({'userid': enuserid, 'username': username})
def check_allow_query(self, aid): '''验证能否查看集点活动 能查看的情况 1. 自己创建的活动 2. 自己参与的活动 3. 自己子商户的活动 ''' userid = self.user.userid # 子商户可以查看大商户活动 with get_connection_exception('qf_mchnt') as db: actv = db.select_one('card_actv', where={'id': aid}) if not actv: raise ParamError('活动不存在') if actv['userid'] != int(userid): # 参与活动能查看 try: mchnt_id_list = json.loads(actv['mchnt_id_list']) except: mchnt_id_list = [] if str(userid) in mchnt_id_list: return actv # 活动创建商户的大商户能查看 re_relates = apcli_ex('getUserReverseRelation', actv['userid'], 'merchant') or [] userids = [i.userid for i in re_relates] if int(userid) not in userids: raise ParamError('活动不存在') return actv
def check_allow_change(self, aid): '''验证能否修改集点活动 Params: aid: 集点活动id Returns: 返回活动信息 ''' userid = self.user.userid cate = self.get_cate() actv = None with get_connection_exception('qf_mchnt') as db: actv = db.select_one('card_actv', where={'id': aid}) if not actv: raise ParamError('活动不存在') if actv['userid'] != int(userid): # 判断登录角色 cate = self.get_cate() if cate in ('merchant', 'submerchant'): raise ParamError('子商户不能修改大商户创建的活动') # 活动的大商户是否是登录商户 re_relates = apcli_ex('getUserReverseRelation', actv['userid'], 'merchant') or [] userids = [i.userid for i in re_relates] if int(userid) not in userids: raise ParamError('活动不存在') now = datetime.datetime.now() if actv['expire_time'] < now: raise ParamError('活动已停止') return actv
def GET(self): params = self.req.input() userid = int(params.get('userid') or self.user.userid) opuid = int(params.get('opuid') or 0) self.check_relation(userid) ret = {'shopname': '', 'opname': ''} user = apcli_ex('findUserBriefById', int(userid)) if user: ret['shopname'] = user.shopname if not opuid: ret['opname'] = getattr(config, 'MASTER_OP_NAME', '主账号') else: with get_connection('qf_core') as db: opuser = db.select_one(table='opuser', where={ 'userid': userid, 'opuid': int(opuid), }, fields='opname, status, mobile') if not opuser: raise DBError('操作员不存在') ret['opname'] = opuser['opname'] return success(ret)
def trade_push(self, actv, member, code_info): '''推送''' customer_id = member['customer_id'] appid, hj_appid = self.get_appid() try: p = {} p['appid'] = appid # 获取openid p['openid'] = thrift_callex(config.OPENUSER_SERVER, OpenUser, 'get_openids_by_user_ids', hj_appid, [ customer_id, ])[0] # 店铺名 user = apcli_ex('findUserBriefById', int(self.user.userid)) p['shopname'] = user.shopname if user else '' p['exchange_num'] = member['exchange_num'] + 1 p['exchange_pt'] = actv['exchange_pt'] p['obtain_amt'] = actv['obtain_amt'] p['busicd'] = 'card_actv_exchange' p['goods_amt'] = actv['goods_amt'] p['goods_name'] = actv['goods_name'] p['code'] = code_info['code'] p['customer_id'] = hids.encode(customer_id) p['activity_id'] = actv['id'] p['card_id'] = member['id'] p = { unicode_to_utf8(k): unicode_to_utf8(v) for k, v in p.iteritems() } HttpClient(config.TRADE_PUSH_SERVER).post('/push/v2/push', params=p) except: log.warn('error:%s' % traceback.format_exc())
def update_apollo(self, data): val = {} for k in ('telephone', 'shopname', 'longitude', 'latitude'): if data[k]: val[k] = data[k] # 店铺地址 if data['address'] or data['location']: addr = ((data['location'] or '') + (data['address'] or '')) if not addr.startswith(self._user.city or ''): addr = (self._user.city or '') + addr val['businessaddr'] = val['address'] = addr if not val: return apcli_ex('updateUser', int(self.user.userid), User(**val))
def _get_tips(self, userid, customer_id): limit = 3 all_sales = SpecialApi.get_all_sales() or [] # 当前店铺创建的特卖 consumed_sales = [sale for sale in all_sales if str(sale['qf_uid']) == userid ] if consumed_sales: return {'title' : config.CONSUMED_SALE_TITLE, 'sales' : SpecialApi.tidy_sales(consumed_sales, 'consumed')[:limit]} # 置顶特卖 head_sales = SpecialApi.get_head_sales() or [] # 附近特卖 user = apcli_ex('findUserByid', int(userid)) near_sales = [] if user and user.longitude and user.latitude: near_sales = SpecialApi.tidy_sales(all_sales, mode='near', lng=user.longitude, lat=user.latitude) or [] near_sales.sort(key=lambda x: x['dist']) sales = head_sales + near_sales if sales: return {'title' : config.NEAR_SALE_TITLE, 'sales' : sales[:3]} else: return {'title' : '', 'sales' : []}
def card_list(self, d): with get_connection_exception('qf_mchnt') as db: where = { 'mp.customer_id': d['customer_id'], 'ca.expire_time': ('>', int(time.time())) } if d.get('groupid') and not userid_cache[d['groupid']]: return [], 0 if d['mchnt_id']: link_ids = apcli.userids_by_linkid(int(d['mchnt_id']), 'merchant') or [] link_ids = {i.userid for i in link_ids} link_ids.add(d['mchnt_id']) where['ca.userid'] = ('in', link_ids) elif d.get('groupid') and userid_cache[d['groupid']]: where['ca.userid'] = ('in', userid_cache[d['groupid']]) on = {'mp.activity_id': 'ca.id'} fields = ['mp.' + i for i in ('cur_pt', 'id', 'activity_id')] fields += [ 'ca.' + i for i in ('obtain_amt', 'obtain_limit', 'start_time', 'expire_time', 'exchange_pt', 'goods_amt', 'goods_name', 'status', 'userid') ] r = db.select_join('member_pt mp', 'card_actv ca', on=on, where=where, fields=fields, other=('order by mp.cur_pt desc ' 'limit {} offset {}'.format( d['limit'], d['offset']))) or [] total_num = db.select_join_one('member_pt mp', 'card_actv ca', on=on, where=where, fields='count(1) as num')['num'] if not r: return r, total_num # 用户信息 userids = [i['userid'] for i in r] users = apcli_ex('findUserBriefsByIds', userids) users = {i.uid: i.__dict__ for i in users} for i in r: t = users.get(i['userid']) or {} i['id'] = str(i['id']) i['activity_id'] = str(i['activity_id']) i['shopname'] = t.get('shopname') or '' i['addr'] = t.get('address') or '' i['diff_exchange'] = max( i['exchange_pt'] - i['cur_pt'] % i['exchange_pt'], 0) i['exchange'] = i['cur_pt'] / i['exchange_pt'] i['start_time'] = str_to_tstamp(str(i['start_time'])) i['expire_time'] = str_to_tstamp(str(i['expire_time'])) return r, total_num
def check_grant_code(self, userid, code): # 通过什么方式验证 mode = self.req.input().get('mode', 'mobile') if mode == 'mobile': user = apcli_ex('findUserBriefById', userid) if not user: raise ParamError('商户不存在') if not check_smscode(code, user.username, mode=1): raise ParamError('验证信息错误') else: user = apcli_ex('findUserByid', userid) if not user: raise ParamError('商户不存在') if (user.idnumber or '').upper() != code.upper(): raise ParamError('身份证验证失败')
def POST(self): params = {k: v.strip() for k, v in self.req.input().iteritems()} userid = self.user.userid user = apcli.userprofile_by_id(int(userid)) user_ext = UserExt( uid=int(userid), shoptype_id=int(params['typeid'] or UserDefine.DEFAULT_SHOPTYPE_ID), contact=params.get('landline', user['user']['telephone']), head_img=params.get('head_img'), logo_url=params.get('logo_url'), ) if is_valid_int(params.get('regionid')): user_ext.regionid = int(params['regionid']) apcli_ex('bindUserExt', user_ext) return success({})
def check_modify_username_grant(self, mobile): userid = int(self.user.userid) user = apcli_ex('findUserBriefById', userid) if not user: raise ParamError('商户不存在') if mobile != user.mobile: raise ParamError('账号信息错误, 联系客服更改') self._groupid = user.groupid
def POST(self): # 验证并获取用户和业务员信息 self.check_entry() # apollo signup userprofile = self.get_UserProfile() userid, respmsg = apcli.signup(userprofile, self._data['saleman_uid']) # 如果调apollo失败 if respmsg: raise ThirdError(respmsg) # 如果注册成功 elif userid: # 如果是大商户 # 需要自动绑定子商户 if self._mode == 'bigmchnt': apcli_ex('setUserRelation', int(self._big_uid), [UserRelation(int(userid), 'merchant')]) # 添加补充信息 self.add_user_ext(userid) # 自动过审 self.auto_apply(userid) # 绑定渠道商户关系 self.relate_mchnt(userid) # 添加注册标志 self.add_sign_tag(self._data['groupid'], userid) # 分发注册成功信息 publish( config.SIGNUP_MSGPASS_KEY, json.dumps({'userid': userid}), ) return success(self.adjust_ret(userid)) else: raise ParamError('用户注册失败')
def check_modify_username_verify(self, mobile): with get_connection_exception('qf_core') as db: new_user = db.select_one('auth_user', where={'mobile': mobile}) if new_user: raise ParamError('该手机已经注册') userid = int(self.user.userid) user = apcli_ex('findUserBriefById', userid) if not user: raise ParamError('商户不存在') self._groupid = user.groupid
def set_user_linkids(self): link_ids = [] try: relats = apcli_ex('getUserRelation', int(self.user.userid), 'merchant') or [] link_ids = [i.userid for i in relats] self.user.ses.data['link_ids'] = link_ids except: log.warn(traceback.format_exc()) return link_ids
def get_actv_card(self, userid, customer_id): actv = {'desc': '暂无集点活动进行', 'title': '集点状态', 'link': ''} # 大商户的子商户userid relates = apcli_ex('getUserRelation', userid, 'merchant') or [] userids = [i.userid for i in relates] userids.append(userid) infos = pt = None with get_connection('qf_mchnt') as db: actvs = db.select('card_actv', where={ 'start_time': ('<=', int(time.time())), 'expire_time': ('>', int(time.time())), 'userid': ('in', userids) }, fields='exchange_pt, id') or [] infos = {i['id']: i['exchange_pt'] for i in actvs} if infos: pt = db.select('member_pt', where={ 'customer_id': customer_id, 'activity_id': ('in', infos.keys()) }, fields='cur_pt, activity_id, id') or [] if infos: actv['link'] = getattr(config, 'MEMBER_CARD_LINK', '').format(hids.encode(int(customer_id))) # 若仅有一张集点卡 if len(pt) == 1: cur_pt = pt[0]['cur_pt'] exc_pt = infos[pt[0]['activity_id']] actv['desc'] = ('已集点{}/{}'.format(cur_pt, exc_pt) if cur_pt < exc_pt else '有{}个礼品可兑换'.format( cur_pt / exc_pt)) # 如果返回mp_id, 前端将自己跳转至详细页 actv['activity_id'] = str(pt[0]['activity_id']) actv['mp_id'] = str(pt[0]['id']) # 若有多张集点卡 elif len(pt) > 1: actv['desc'] = '有{}张集点卡'.format(len(pt)) else: actv['desc'] = '有0张集点卡' if len(actvs) == 1: exc_pt = actvs[0]['exchange_pt'] actv['desc'] = '已集点0/{}'.format(exc_pt) return actv
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_mchnt_id_list(self, mchnt_id_list, aid=None): ''' 获取mchnt_id_list''' userid = int(self.user.userid) if self.get_cate() != 'bigmerchant': return json.dumps([str(userid)]) mchnt_id_list = [i for i in mchnt_id_list if i] # 获取适用门店列表 link_ids = apcli.userids_by_linkid(userid, 'merchant') link_ids = {i.userid for i in link_ids} if not mchnt_id_list: mchnt_ids = link_ids else: mchnt_ids = set() for i in mchnt_id_list: try: mchnt_ids.add(hids.decode(i)[0]) except: pass if mchnt_ids - link_ids: raise ParamError('包含了非自己的子商户') with get_connection_exception('qf_mchnt') as db: userids = list(mchnt_ids) + [userid] actvs = db.select('card_actv', where={ 'expire_time': ('>', int(time.time())), 'userid': ('in', userids) }, fields='userid, mchnt_id_list, id') for actv in actvs: if aid == actv['id']: continue try: uids = json.loads(actv['mchnt_id_list']) uids = {int(i) for i in uids} except: uids = set() onuids = uids & mchnt_ids if onuids: mchnt = apcli_ex('findUserBriefsByIds', [list(onuids)[0]]) or [] shopname = mchnt[0].shopname if mchnt else '' raise ParamError('{}等子商户有正在进行的集点活动'.format(shopname)) return json.dumps([str(i) for i in mchnt_ids])
def card_info(self, actv): r = {} # 活动信息 fields = ('goods_name', 'goods_amt', 'exchange_pt', 'obtain_amt', 'obtain_limit', 'status', 'start_time', 'expire_time') for i in fields: r[i] = actv.get(i) or '' r['start_time'] = str_to_tstamp(str(r['start_time']), DATETIME_FMT) r['expire_time'] = str_to_tstamp(str(r['expire_time']), DATETIME_FMT) # 店铺信息 user = apcli_ex('findUserBriefById', actv['userid']) r['shopname'] = getattr(user, 'shopname', '') r['addr'] = getattr(user, 'address', '') return r
def POST(self): idnumber = self.req.input().get('idnumber', '').strip() if not idnumber: raise ParamError('身份证号码必填') userid = int(self.user.userid) user = apcli_ex('findUserByid', int(self.user.userid)) if not user: raise DBError('商户不存在') if (user.idnumber or '').upper() != idnumber.upper(): raise ParamError('身份证不匹配') code = hids.encode(userid, int(time.time())) return success({'code': code})
def GET(self): params = self.req.input() shopid = params.get("shopid", '') if not shopid: raise ParamError("商户id参数错误") # 验证是否是当前商户的子商户 userid = self.user.userid cate = self.get_cate() if cate == "bigmerchant": subids = get_linkids(userid) shopid = int(shopid) if shopid not in subids: raise ParamError("非大商户的子商户") else: pass try: res = {} user_ext = apcli_ex('getUserExt', int(shopid)) user_detail_info = get_user_detail_info(shopid) audit_info = re_audit_info(shopid).get(shopid) res['audit_str'], res['audit_flag'], res['audit_fail_reason'] = audit_info.get('audit_str'), audit_info.get('audit_flag'), audit_info.get('audit_fail_reason') res['login_account'] = user_detail_info.get("mobile", '') if user_detail_info else '' res['shopname'] = user_detail_info.get("shopname", '') if user_detail_info else '' res['logo'] = user_ext.logo_url or config.DEFAULT_SHOP_LOGO_URL res['register_time'] = user_detail_info.get("jointime", '') if user_detail_info else '' res['telephone'] = user_detail_info.get('telephone', '') if user_detail_info else '' res['address'] = user_detail_info.get("address", '') if user_detail_info else '' # 获取银行信息 bank_info = get_user_bank_info(shopid) res['payee'] = bank_info.get("bankuser", '') if bank_info else '' bank_account = bank_info.get("bankaccount", '') if bank_info else '' res['bank_account'] = self.del_cardno(bank_account) res['branch_bank_name'] = bank_info.get("bankname", '') if bank_info else '' return self.write(success(data=res)) except: log.warn('Get shop detail error:%s' % traceback.format_exc()) raise DBError('获取商户详细信息失败')
def GET(self): data = self.validator.data values = {k: v for k, v in data.iteritems() if v is not None} if not values: return self.write(success({})) userid = int(self.user.userid) user = apcli_ex('findUserBriefById', userid) if not user: user = UserBrief(city='', uid=userid, province='') userids = [] with get_connection('qf_mis') as db: userids = db.select( table='merchant_change_apply', where={ 'userid': ('in', [int(userid)]), 'changetype': ('in', [int(2)]) }, fields='userid,applyjson,status,createtime,modifytime,auditmemo' ) ret = userids if ret: ret = ret[0] else: return self.write(success({'status': 3})) _applyjson = json.loads(ret['applyjson']) log.info("userid :%s", userid) if ret['status'] == 2: ret['status'] = 1 return self.write( success({ 'change': _applyjson['change_apply']['nickname'], 'auditmemo': ret['auditmemo'], 'createtime': ret['createtime'], 'audittime': ret['modifytime'], 'status': ret['status'] }))
def get_slsm_info(self, userid): try: client = ThriftClient(config.QUDAO_SERVERS, QudaoServer, framed=True) mchnts = client.mchnt_get([ userid, ]) if not mchnts: return None slsm_info = apcli_ex('findUserByid', mchnts[0].slsm_uid) if slsm_info: return slsm_info.__dict__ except: log.warn(traceback.format_exc()) return None
def set_session(self, udid, userinfo, opuid=None, cate=None, **kw): ''' 设置登录session session包含: cate: bigmerchant|submerchant|merchant 商户角色 opuid: 有表示为操作员, 无即是普通商户 groupid: 渠道id language: 语言 udid: 设备识别码 userid: 商户userid ''' user = ApolloUser(userinfo['uid'], expire=86400 * 3) # 设置user session user.ses['udid'] = udid user.ses['groupid'] = userinfo['groupid'] user.ses['chnlid'] = 0 #设置登录时间 user.ses['login_time'] = int(time.time()) user.ses['cate'] = cate if hasattr(self, '_big_uid') and self._big_uid: user.ses['big_uid'] = self._big_uid # 如果是大商户, 存下他的连锁店id if cate == 'bigmerchant': relats = apcli_ex('getUserRelation', int(userinfo['uid']), 'merchant') or [] link_ids = [i.userid for i in relats] user.ses['link_ids'] = link_ids if opuid: user.ses['opuid'] = str(opuid) for k, v in kw.iteritems(): user.ses[k] = v user.login(userinfo['uid']) user.ses.save() return user.ses._sesid