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 username_mchnt(self): '''商户预注册''' d = {k: v.strip() for k, v in self.req.input().iteritems()} self.req.inputjson()['password'] = '******' # 验证用户名 username = d.get('username', '') if not username: raise ParamError('用户名为空') # 验证验证码 code = d.get('code', '') if not check_smscode(code, username): raise ParamError('验证码错误') # 验证是否注册 if UserUtil.check_profile(**{'auth_user.username': username}): raise ParamError('商户已经注册') # 获取userid user = None with get_connection('qf_core') as db: user = db.select_one('auth_user', where={'mobile': username}, fields='id, password') log.debug(user) if user: if (user['password'] and not check_password( d.get('password', ''), user['password'])): raise SessionError('该账号已经设置密码') return d['username'], user['id'] return d['username'], None
def _trans_input(self): r = {} r['userid'] = int(self.user.ses.get('userid', '')) # 商户付费情况 r['mchnt_info'] = UserUtil.get_recharge_info(r['userid'], self.get_groupid()) return r
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(self): ret = {} max_opuid = UserUtil.get_max_opuid(int(self.user.userid)) if not max_opuid: ret['opuid'] = '0001' return self.write(success(ret)) # 新的uid增长一 max_opuid = max_opuid + 1 prefix = (4 - len(str(max_opuid))) * '0' ret['opuid'] = prefix + str(max_opuid) return self.write(success(ret))
def check_opuid(self, userid): ''' 检查传入的opuid是否已经存在 ''' data = self.validator.data if not is_valid_int(data['opuid'] or 0): raise ParamError('opuid 错误') max_opuid = int(UserUtil.get_max_opuid(int(userid)) or 0) if not data['opuid']: opuid = max_opuid + 1 else: if max_opuid and int(data['opuid']) <= max_opuid: raise ParamError('收银员编号:{}已经存在'.format(data['opuid'])) opuid = int(data['opuid']) return opuid
def GET(self, userid=None): # 微信通道实名商户 wx_oauth_mchnt, chnlbind = 0, {} with get_connection('qf_core') as db: chnlbind = db.select_one('chnlbind', where={ 'userid': ('in', (0, userid)), 'available': 1, 'tradetype': UserDefine.CHNLBIND_TYPE }, other='order by priority', fields='key3, mchntid, chnlid, termid') # 微信通道下实名商户为微信特约商户 if (chnlbind['chnlid'] == config.WX_CHNLID and chnlbind['key3'] != 'wxeb6e671f5571abce'): wx_oauth_mchnt = 1 # T1或者D1 settle_type = UserDefine.SETTLE_TYPE_T1 bigmchntids = set(get_bigmchntid() or []) if not chnlbind or not bigmchntids: settle_type = UserDefine.SETTLE_TYPE_T1 elif (chnlbind['chnlid'] in config.D1_CHNLIDS and '{}_{}'.format( chnlbind['mchntid'], chnlbind['termid']) not in bigmchntids): settle_type = UserDefine.SETTLE_TYPE_D1 else: settle_type = UserDefine.SETTLE_TYPE_T1 # period # 若是t1需要获取账期 period = {} if settle_type == UserDefine.SETTLE_TYPE_T1: td = time.strftime(DATE_FMT) period = UserUtil.get_periods(td) or {} return success({ 'wx_oauth_mchnt': wx_oauth_mchnt, 'settle_type': settle_type, 'period': period })
def GET(self): userid = self.user.userid groupid = self.get_groupid() ret = {} # 获取商户付费情况 ret['mchnt_info'] = UserUtil.get_recharge_info(userid, groupid) # 获取功能模块 ret['services'] = self.get_services() # 获取审核信息 ret.update(self.get_audit_info()) # 是否允许余额 ret['balance_enable'] = int('balance' in self._user_service) # 是否是直营 ret['is_qfgroup'] = int(self.get_groupid() in config.QF_GROUPIDS) return success(ret)
def POST(self): d = self.req.input() mobile = d.get('username', '').strip() mode = d.get('mode', '').strip() if not mobile: raise ParamError('参数错误') ret = {} resperr = '' if mode == 'user': ret['is_signup'] = UserUtil.check_profile( **{'auth_user.mobile': mobile}) resperr = '用户已注册' if ret['is_signup'] else '' else: ret.update(check_user(mobile)) resperr = '非业务员' if ret['is_saleman'] else '' ret = { k: v for k, v in ret.iteritems() if k in ('is_signup', 'is_saleman') } return self.write(success(ret, resperr))
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))
def adjust_ret(self, userid): data = self._data ret = {} try: # 存储session user = ApolloUser(userid, expire=86400 * 7) user.ses['chnlid'] = 0 user.ses['groupid'] = data['groupid'] user.ses['udid'] = data.get('udid', '') user.login(userid) user.ses.save() sessionid = user.ses._sesid # 用户信息 userinfo = { i: data.get(i, '') for i in ('shopname', 'province', 'city', 'address', 'username') } userinfo['groupid'] = data['groupid'] userinfo['mobile'] = userinfo['username'] userinfo['uid'] = userid userinfo['jointime'] = time.strftime('%Y-%m-%d %H:%M:%S') userinfo['telephone'] = data.get('landline') or '' # 返回登录的信息 ret = UserUtil.ret_userinfo(userinfo, sessionid=sessionid, is_creat_shop=0) ret['shop_info']['head_img'] = (data.get('head_img', '') or config.APP_DEFAULT_AVATR) ret['shop_info']['logo_url'] = data.get('logo_url') or '' except: log.debug(traceback.format_exc()) ret = {} return ret
def POST(self): params = self.req.input() username = params['username'] password = params['password'] udid = params.get('udid') opuid = params.get('opuid') params['password'] = '******' user = self.get_user(username) opinfo = None self.check_user(user['userid'], opuid) if opuid: opinfo = self.check_op(user['userid'], password, opuid) else: if not check_password(password, user['password']): self.password_error(user['userid'], password) raise UserError('账号或密码有误,请重新输入') # 获取用户信息 userinfo = apcli.user_by_id(user['userid']) if not userinfo: log.debug('[username:{} pwd:{}]'.format(username, password)) raise ThirdError('账号或密码有误,请重新输入') # 线下店铺信息 user_ext = apcli_ex('getUserExt', int(userinfo['uid'])) cf = {} # 线下店铺信息 cf['cate'] = self.get_cate(userinfo['uid'], userinfo['userCates']) # 如果禁止大商户登录 if (not getattr(config, 'BIGMCHNT_LOGIN_ALLOWED', True) and cf['cate'] == 'bigmerchant'): raise ParamError('商户角色错误') # 获取渠道信息 cf['qdinfo'] = self._qdinfo = get_qudaoinfo(userinfo['groupid']) # 设置用户session sid = self.set_session(udid=udid, userinfo=userinfo, opuid=opuid, cate=cf['cate'], language=self._qdinfo['language']) # 支持刷卡设备获取terminalids terminalids = [] user_agent = self.req.environ.get('HTTP_USER_AGENT', '').upper() if any(True for i in config.UA_CARD if i in user_agent): terms = None with get_connection('qf_core') as db: terms = db.select('termbind', where={'userid': user['userid']}, fields='terminalid') terminalids = [i['terminalid'] for i in terms or []] ret = UserUtil.ret_userinfo(userinfo, user_ext, sessionid=sid, opinfo=opinfo, terminalids=terminalids, **cf) self.resp.set_cookie('sessionid', sid, **config.COOKIE_CONFIG) conf_group_client_url = config.GROUP_CONF_CLIENT_URL.get( str(userinfo['groupid']), config.DEFAULT_CLIENT_URL) ret['pay_url'] = conf_group_client_url.get( "pay_url", config.DEFAULT_CLIENT_URL.get("pay_url")) ret['pay_trade_query_url'] = conf_group_client_url.get( "pay_trade_query_url", config.DEFAULT_CLIENT_URL.get("pay_url")) _, has_set = has_set_mpwd(user['userid']) ret['has_set_mpwd'] = 1 if has_set else 0 return success(ret)
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)
def check_entry(self): data = {k: v.strip() for k, v in self.req.input().iteritems()} # 默认数据 self._data = { 'groupid': config.SIGNUP_GROUPID, 'saleman_uid': 0, 'src': '好近自主注册', 'cate': 'mchnt', 'password': '', } # 凭证字段 voucher_fields = ['shopphoto', 'goodsphoto'] # 地址字段 addr_fields = [ 'province', 'city', 'address', 'location', 'shopname', 'shoptype_id' ] # 必传字段 for i in ('username', 'idnumber', 'headbankname', 'bankuser', 'bankaccount', 'bankprovince', 'bankcity', 'bankname', 'bankcode'): if i not in data: raise ParamError('请将账户信息填充完整') else: self._data[i] = data[i] # 非必传字段 for i in [ 'name', 'landline', 'longitude', 'latitude', 'banktype', 'bankmobile', 'idstatdate', 'idenddate', 'provinceid', 'location', 'regionid', 'address', 'udid', 'head_img', 'logo_url', 'legalperson', 'password', 'licensenumber', 'subshopdesc', 'authedcardfront', 'authedcardback', 'idcardfront', 'idcardback', 'idcardinhand' ] + addr_fields + voucher_fields: self._data[i] = data.get(i, '') # 处理密码 if not data.get('password'): self._data['password'] = re.sub('\D', 'X', data['idnumber'][-6:], 6) if not 6 <= len(self._data['password']) <= 20: raise ParamError('密码应在6到20位!') # 验证是否注册 if UserUtil.check_profile(**{'auth_user.username': data['username']}): raise ParamError('该用户已经注册') # 商户shoptype_id if not is_valid_int(self._data['shoptype_id']): self._data['shoptype_id'] = UserDefine.DEFAULT_SHOPTYPE_ID else: self._data['shoptype_id'] = int(self._data['shoptype_id']) # 商户类型 usertype = data.get('usertype', UserDefine.SIGNUP_USERTYPE_TINY) if int(usertype) not in UserDefine.SIGNUP_USERTYPES: raise ParamError('商户注册类型错误') self._data['usertype'] = int(usertype) self._mode = data.get('mode', 'mchnt') func = getattr(self, 'check_' + self._mode) if not func: raise ParamError('注册模式不支持') func(data) name = (self._data['name'] or self._data['legalperson'] or self._data['bankuser'] or self._data['shopname']) # 如果是注册成为商户 # voucher_fields 和 addr_fields 是必填字段 if self._data['cate'] == 'mchnt': for i in voucher_fields: if not data.get(i): raise ParamError('凭证请上传完整') for i in addr_fields: if i not in data: raise ParamError('请将店铺地址相关信息上传完整') self._data['name'] = name # 注册成为业务员 else: self._data['name'] = name self._data['shopname'] = '业务员' + (data.get('shopname') or name) # 省名,城市名 self._data['province'] = (data.get('province') or self._get_province( data.get('provinceid'))) self._data['city'] = (data.get('city') or self._get_city(data.get('provinceid'))) self._data['bankprovince'] = (data.get('bankprovince') or self._data['province'])