def GET(self): # 获取userids in_userids = self.req.input().get('userids', '') in_userids = filter(str.isdigit, in_userids.split(',')) in_userids = map(int, in_userids) userids = self.check_exist(set(in_userids)) userids.append(0) d0_ids = self.get_dzero_users(userids) bigmchntids = set(get_bigmchntid() or []) # 查询通道 ret = {} chnlbinds = [] with get_connection('qf_core') as db: chnlbinds = db.select( table='chnlbind', where={ 'userid': ('in', userids), 'available': 1, 'tradetype': CHNLBIND_TYPE_WX }, other='order by priority', fields='key3, mchntid, chnlid, termid, userid, priority') if not chnlbinds: return self.write(success(ret)) # 优先级 default_pri_chnlbind = {} # 默认使用的通道 chnlbind_userids = set() # 绑定了通道的userid high_pri_chnlbinds = [] # 优先级高于默认通道userid for cb in chnlbinds: cb_userid = cb['userid'] if cb_userid == 0 and not default_pri_chnlbind: default_pri_chnlbind = cb if not default_pri_chnlbind: high_pri_chnlbinds.append(cb_userid) chnlbind_userids.add(cb_userid) # 暂时无效 notbind_userids = set(userids) - chnlbind_userids default_pri_settle = self.get_settle_type(default_pri_chnlbind, d0_ids, bigmchntids) for chnlbind in chnlbinds: userid = chnlbind['userid'] # 商户绑定多个通道,默认取优先级最高的 # 用户绑定的通道优先级低,则会取默认通道 if userid == 0 or userid in ret: continue if userid not in high_pri_chnlbinds: chnlbind = default_pri_chnlbind ret[userid] = self.get_settle_type(chnlbind, d0_ids, bigmchntids) # 无效代码,防止以后再有默认结算类型 # 未绑定通道的就没有结算类型 # for notbind_user in notbind_userids: # ret[notbind_user] = default_pri_settle return self.write(success(ret))
def POST(self): params = self.req.input() push_status = params.get("push_status", '') try: push_status = int(push_status) if push_status not in (RECEIVE_PUSH, NO_RECEIVE_PUSH): raise ParamError("push_status参数错误") except: raise ParamError("push_status参数错误") userid = self.user.userid curr_time = time.strftime(DTM_FMT) try: row = self.db.select_one("mchnt_control", fields="push_master", where={"userid": int(userid), "status": 1}) if row: db_push_status = row['push_master'] # 数据库存储的转态 if db_push_status == push_status: return self.write(success(data={"result": "fail"})) self.db.update("mchnt_control", {"push_master": push_status}, where={"userid": int(userid), "status": 1}) return self.write(success(data={"result": "success"})) else: if push_status == RECEIVE_PUSH: self.db.insert("mchnt_control", values={"push_master": RECEIVE_PUSH, "userid": int(userid), "push_opuser": 0, "status": 1, "ctime": curr_time}) return self.write(success(data={"result": "success"})) else: raise ParamError("接收收银员播报已经是关闭状态") except: log.info(traceback.format_exc()) raise DBError("数据库执行出错")
def _list(): if d['mchnt_id']: where['userid'] = d['mchnt_id'] else: userids = _get_userids() if d.get('groupid'): userid_cache_list = userid_cache[d['groupid']] userids = userids & set(userid_cache_list) if not userids: return self.write(success({'list': [], 'num':0})) where['userid'] = ('in', userids) prts = self.db.select('member_actv', fields=fields, where=where, other='order by ctime desc limit %s offset %s' % (d['limit'], d['offset'])) or [] userids = set([i['userid'] for i in prts]) users = self._get_users(userids) ids = [] for prt in prts: user = users.get(prt['userid'], {}) prt['shopname'] = user.get('shopname') or '' prt['addr'] = user.get('addr') or '' prt['bg_url'] = prt['bg_url'] or config.MCHNT_AVATAR prt['start_time'] = str_to_tstamp(str(prt['start_time'])) prt['expire_time'] = str_to_tstamp(str(prt['expire_time'])) ids.append(prt['id']) MemberUtil.add_actv_pv(ids) # 获取总量 num = self.db.select_one('member_actv', where=where, fields='count(1) as num')['num'] return self.write(success({'list': prts, 'num': num}))
def POST(self): params = self.req.input() shopid = params.get("shopid", '') newpwd = params.get("newpwd", '') if not shopid or not newpwd: raise ParamError("参数错误") # 验证是否是当前商户的子商户 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("非大商户的子商户") try: apcli("changePwd", uid=shopid, password=newpwd) kick_user(int(shopid), mode = 'not_opuser') return self.write(success(data={"result": "success"})) except: log.debug(traceback.format_exc()) return self.write(success(data={"result": "fail"})) else: raise ParamError("角色错误")
def GET(self): perms_list = { 'refund': 1, 'coupon': 1, 'member': 1, 'sales': 1, 'prepaid': 1, 'card': 1, 'shop_notice': 1 } userid = int(self.user.userid) opuid = int(self.user.ses.get('opuid', 0)) if opuid: where = {'userid': userid, 'opuid': opuid} with get_connection('qf_core') as db: opuser = db.select_one(table='opuser', fields=['perms'], where=where) if opuser: try: perms = json.loads(opuser['perms']) for i in perms_list.keys(): perms_list[i] = perms.get(i, 0) except: keys = perms_list.keys() perms_list = dict.fromkeys(keys, 0) return self.write(success(perms_list)) else: return self.write(error(QFRET.PARAMERR, respmsg='操作员信息不存在')) else: return self.write(success(perms_list))
def GET(self): cids = self.req.input().get('customer_id') or '' cids = [cid for cid in cids.split(',') if cid.strip()] customer_ids = [] for cid in cids: if cid.strip(): try: customer_ids.append(hids.decode(cid)[0]) except: pass if not customer_ids: return self.write(success({'info': []})) infos = [] try: spec = json.dumps({'user_id': customer_ids}) profiles = thrift_callex(config.OPENUSER_SERVER, OpenUser, 'get_profiles', config.OPENUSER_APPID, spec) profiles = {i.user_id: i.__dict__ for i in profiles} except: log.warn('get openuser_info error:%s' % traceback.format_exc()) for customer_id in customer_ids: if customer_id in profiles: profile = profiles[customer_id] info = { i: profile[i] or '' for i in ('avatar', 'gender', 'nickname') } info['gender'] = info['gender'] or 3 info['customer_id'] = hids.encode(customer_id) infos.append(info) return self.write(success({'info': infos}))
def GET(self): # 如果是大商户或者操作员, 暂不展示 user_cate = self.get_user_cate() if user_cate in ('bigmerchant', 'opuser'): return success({}) self._runned_funcs = set() self._result = {} userid = int(self.user.userid) advice = {} seqs = self.get_advice_seqs() log.debug(seqs) for index in seqs: advice_conf = config.ADVICES[index] func_name = '_' + advice_conf.get('from', '') if func_name not in self._runned_funcs: func = getattr(self, func_name, None) if callable(func): func(userid) self._runned_funcs.add(func_name) if index in self._result: advice = self._result[index] break return success(advice)
def GET(self): # 如果是大商户或者操作员, 暂不展示 user_cate = self.get_user_cate() if user_cate in ('bigmerchant', 'opuser'): return success({'panels': []}) # 版本号 ua = self.req.environ.get('HTTP_USER_AGENT', '') self.version, self.platform = get_app_info(ua) # 根据渠道获取面板数据 default_func_names = getattr(config, 'DATA_FUNCS', data_funcs.keys()) func_names = get_qd_conf_value_ex(mode='data_func_names', key='ext', groupid=self.get_groupid(), default=default_func_names) funcs = get_value(func_names, self.platform, self.version) panels = [] if funcs: with futures.ThreadPoolExecutor(10) as executor: for panel in executor.map(self._get_panel, funcs): if panel: panels += (panel if isinstance(panel, MulType) else [panel]) panels.sort(key=lambda d: d.get('create_time'), reverse=True) return success({'panels': panels})
def GET(self): ret = {} tmp = [] d = self.validator.data mode = d['mode'] page = d['page'] pagesize = d['pagesize'] userid = d.get('userid') if not userid: userid = int(self.user.userid) else: userid_tuple = hids.decode(userid) if userid_tuple: userid = userid_tuple[0] else: if not userid.isdigit(): raise ParamError('用户编号不存在') log.debug('decoded userid={}'.format(userid)) # 操作员登录,返回空列表 if 'opuid' in self.user.ses: ret['opusers'] = [] return self.write(success(ret)) # 判断分页显示或者全部显示,根据status筛选 other = 'order by create_time desc limit {limit} offset {offset}'.format( limit=pagesize, offset=pagesize * page) if mode == 'all': other = 'order by create_time desc' where = {'userid': userid} # 获取商户下操作员 opusers = [] with get_connection('qf_core') as db: opusers = db.select(table='opuser', where=where, fields='opname, opuid, perms', other=other) for opuser in opusers: result = {} source_opuid = opuser['opuid'] prefix = (4 - len(str(source_opuid))) * '0' result['opuid'] = prefix + str(source_opuid) try: perms = json.loads(opuser['perms']) refund = perms.get('refund', 0) except: refund = 0 result['refund'] = refund result['opname'] = opuser['opname'] tmp.append(result) ret['opusers'] = tmp return self.write(success(ret))
def GET(self): default_info = { 'nickname': '微信支付顾客', 'avatar': config.HJ_AVATAR, 'gender': 3, 'num': 0, 'txamt': 0, 'last_txdtm': '' } d = self.req.inputjson() userid = int(self.user.userid) customer_id = None if d.get('customer_id'): try: customer_id = hids.decode(d['customer_id'])[0] except: if is_valid_int(d['customer_id']): customer_id = int(d['customer_id']) # 如果包含openid elif d.get('openid'): customer_id = thrift_call(OpenUser, 'get_user_id_by_openid', config.OPENUSER_SERVER, config.OPENUSER_APPID, d['openid']) if customer_id <= 0: return self.write(success(default_info)) # 获取消费者信息 r = get_member_info(customer_id) or {} member = {} with get_connection('qf_mchnt') as db: member = db.select_one('member', where={ 'userid': userid, 'customer_id': customer_id }) or {} info = {} info['nickname'] = r.get('nickname') or default_info['nickname'] info['avatar'] = r.get('avatar') or default_info['avatar'] info['gender'] = r.get('gender') or default_info['gender'] info['num'] = member.get('num') or default_info['num'] info['txamt'] = member.get('txamt') or default_info['txamt'] info['last_txdtm'] = (tstamp_to_str(member['last_txdtm']) if 'last_txdtm' in member else default_info['last_txdtm']) # 如果是储值交易 # 获取储值信息 if d.get('busicd', '').startswith('7'): balance = self.get_balance(userid, customer_id) if balance is not None: info['balance'] = balance return self.write(success(info))
def GET(self): try: # 转化input参数 d = self._trans_input() # 创建优惠劵 r = self._template(d) or {} return self.write(success(r)) except: log.warn('get activity template error: %s' % traceback.format_exc()) return self.write(success({}))
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 GET(self): userid = int(self.user.userid) with get_connection_exception('qf_marketing') as db: records = db.select('verify_record', where={'userid': userid}, other=self.get_other(fields=('ctime', )), fields='src, verify_id, activity_id, ctime') if not records: return success({'records': []}) actv_ids = [i['activity_id'] for i in records] actvs = db.select('activity_verify', where={'id': ('in', actv_ids)}, fields='id, name, img, src') or [] actv_dict = {i['id']: i for i in actvs} # 补充活动信息 tidy_records = defaultdict(list) for i in records: actv_id = i.pop('activity_id') i['name'] = '优惠' i['img'] = '' if actv_id in actv_dict: actv = actv_dict[actv_id] i['name'] = actv['name'] i['img'] = actv['img'] i['code'] = hids.encode(CodeDef.DW_CODE, i.pop('verify_id')) t = str(i['ctime'])[:10] tidy_records[t].append(i) # 获取头部信息 last_day = str(records[-1]['ctime'])[:10] first_day = str(records[0]['ctime'])[:10] sql = ( 'select DATE_FORMAT(ctime, "%%Y-%%m-%%d") as date, ' 'count(1) as num from verify_record ' 'where userid=%d and ctime>="%s 00:00:00" and ctime <= "%s 23:59:59" ' 'group by DATE_FORMAT(ctime, "%%Y%%m%%d") order by ctime desc' % (userid, last_day, first_day)) diff_days = db.query(sql) or [] ret = [] for i in diff_days: t = {} t['date'] = i['date'] t['total_num'] = i['num'] t['records'] = tidy_records.get(i['date']) or [] ret.append(t) return success({'records': 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 GET(self): privilege = config.ACTV_TIPS.get('privilege') or {} mode = self.validator.data['mode'] display = privilege.get(mode) or [] return self.write(success(display))
def POST(self): actv = None with get_connection('qf_marketing') as db: actv = db.select_one(table='activity', where={ 'id': self.validator.data['id'], 'src': ACTIVITY_SRC }, fields='id, create_mchnt_id, status') if not actv: raise ParamError('活动不存在') if actv['create_mchnt_id'] != str(self.user.userid): if actv['create_mchnt_id'] == str(self.get_big_uid()): raise ParamError('此活动为总账户创建,你无法执行修改~') raise ParamError('暂无修改此活动的权限') if actv['status'] != COUPON_RULE_STATUS_CLOSE: try: act = Activity(id=actv['id'], status=COUPON_RULE_STATUS_CLOSE, src=ACTIVITY_SRC) thrift_callex(config.QF_MARKETING_SERVERS, QFMarketing, 'activity_change', act) except: log.warn(traceback.format_exc()) raise ThirdError('关闭活动失败') return self.write(success({}))
def GET(self): userid = int(self.user.userid) data = self.validator.data actv = None with get_connection('qf_marketing') as db: big_uid = self.get_big_uid() userids = (userid, big_uid) if big_uid else (userid, ) actv = db.select_one(table='activity', where={ 'create_mchnt_id': ('in', userids), 'id': data['activity_id'], 'src': ACTIVITY_SRC }, fields='id') if not actv: raise ParamError('未查询到该活动') num, info = CouponUtil.get_customer(actid=actv['id'], limit=data['pagesize'], offset=data['pagesize'] * data['page'], raise_ex=True) return self.write(success({ 'customer_num': num, 'customer_info': info }))
def GET(self): # 访问qiantai_util 获取数据 d = self.req.input() records = [] if d.get('areaid'): with get_connection('qf_mis') as db: records = db.select_join( 'tools_brchbank tbb', 'tools_bank tb', on= {'tbb.bank_id': 'tb.id'}, where= { 'tbb.areaid': d['areaid'], 'tb.bank_display': 1, 'tbb.brchbank_status': 0 }, other= 'order by bank_no') elif ('cityid' in d and 'headbankid' in d and is_valid_int(d['cityid']) and is_valid_int(d['headbankid'])): with get_connection('qf_mis') as db: keyword = d.get('keyword', '').strip() keyword= (u" and locate('{}',brchbank_name)".format(db.escape(keyword)) if keyword else '') sql = (u'select brchbank_name name, brchbank_code code ' 'from tools_brchbank,tools_bank b,tools_areacity c ' 'where brchbank_status=0 and bank_id=b.id and ' 'areacity_id=c.id and bank_no={bankid} and ' 'city_no={cityid} {keyword} order by brchbank_no'.format( bankid= int(d['headbankid']), cityid= int(d['cityid']), keyword= keyword)) records = db.query(sql) return self.write(success({'records': records or []}))
def POST(self): params = self.req.input() sdk = params.get('sdk') or 'getui' if sdk not in ('xiaomi', 'huawei', 'getui'): raise ParamError('sdk not support') self.sdk = sdk data = {} data['userid'] = self.get_bind_id() data['apptype'] = int(params.get('app_type') or 402) data['deviceid'] = params.get('deviceid', '').strip() data['clientid'] = params.get('clientid', '').strip() data['openid'] = params.get('openid', '') data['mobile'] = params.get('mobile', 0) data['appver'] = params.get('appver', '') data['usertag'] = int(params.get('usertag', '0')) data['is_logout'] = int(params.get('is_logout') or 0) data['create_time'] = data['update_time'] = 'now()' data['token_status'] = 0 if not data['deviceid']: raise ParamError('参数错误') for i in and_bind_platform: try: getattr(self, i + '_bind')(data) except: log.warn(traceback.format_exc()) return success({})
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 POST(self): ''' 修改用户权限 ''' d = self.validator.data userid = int(self.user.userid) if not d['opuid']: raise ParamError('参数错误') if d['status'] is not None and d['status'] not in [0, 1]: raise ParamError('状态非法') if d['type'] is None: type = 'refund' else: type = d['type'] # 更新数据 where = {'userid': userid, 'opuid': int(d['opuid'])} perms = {} with get_connection('qf_core') as db: opuser = db.select_one(table='opuser', fields=['perms'], where=where) if opuser: try: perms = json.loads(opuser['perms']) perms[type] = d['status'] except: perms[type] = d['status'] finally: db.update('opuser', {'perms': json.dumps(perms)}, where) return self.write(success({})) else: return self.write(error(QFRET.PARAMERR, respmsg='操作员信息不存在'))
def POST(self): cate = self.get_cate() params = self.req.input() sub_mchnt_id = params.get('shopid', '') try: userid = self.user.userid sub_mchnt_id = int(sub_mchnt_id) if not sub_mchnt_id: raise ParamError("子商户错误") else: if cate == "bigmerchant": subids = get_linkids(userid) if sub_mchnt_id not in subids: raise ParamError("非大商户的子商户") except: log.warn('sub merchant error : %s ' % traceback.format_exc()) raise ParamError("无法识别子商户") try: thrift_callex(config.APOLLO_SERVERS, ApolloServer, 'unbindRelation', int(userid), int(sub_mchnt_id), 'merchant') except: log.warn('user ({userid}) remove sub merchant({sub_mchnt_id}) error : {reason}'.format(userid=userid, sub_mchnt_id = sub_mchnt_id, reason = traceback.format_exc())) return self.write(error(QFRET.THIRDERR)) return self.write(success(data={}))
def POST(self): d = {k: v.strip() for k, v in self.req.input().iteritems()} if d.get('mobile'): checkcode = d.get('mobile', '') if not re.match(MOBILE_PATTERN, checkcode): raise ParamError('手机号码不合法') elif d.get('email'): checkcode = d.get('email', '') if not re.match(EMAIL_PATTERN, checkcode): raise ParamError('邮箱不合法') else: raise ParamError('参数错误') code = d.get('code', '') if not code: raise ParamError('验证码为空') # 验证验证码 if check_smscode(code, checkcode): return self.write(success({})) raise ParamError('验证码错误')
def GET(self): d = {k: v.strip() for k, v in self.req.input().iteritems()} try: userid = self.user.ses['userid'] groupid = self.get_groupid() except: userid = d.get('userid') groupid = self.get_groupid(userid=userid) if not userid or not is_valid_int(userid): raise ParamError('商户ID不能为空') service_code = d.get('service_code') or d.get('code') or 'card_actv' goods_code = d.get('goods_code') mchnt_info = adjust_payinfo_ex(userid, goods_code, service_code, groupid=groupid) mchnt_info['now'] = time.strftime(DATETIME_FMT) # 登录状态时, 返回会员数 if self._ck_mode == 'sid': with get_connection('qf_mchnt') as db: mchnt_info['member_num'] = db.select_one( 'member', where={'userid': int(userid)}, fields='count(*) as num')['num'] # 是否是直营商户 mchnt_info['is_qfgroup'] = int(groupid in config.QF_GROUPIDS) return self.write(success(mchnt_info))
def POST(self): userid = int(self.user.userid) actv = None with get_connection('qf_mchnt') as db: actv = db.select_one( 'member_actv', where= { 'userid': userid, 'type': MemDefine.ACTV_TYPE_PRIVI }) if actv: raise ParamError('已经创建过特权活动了.') content = self.validator.data['content'] content = remove_emoji(content) if str_len(content) > 80: raise ParamError('活动内容不超过80字') now = int(time.time()) data = {} data['id'] = getid() data['title'] = '' data['content'] = content data['userid'] = userid data['status'] = MemDefine.ACTV_STATUS_ON data['ctime'] = data['utime'] = now data['start_time'] = now data['expire_time'] = now + 20 * 365 * 24 * 3600 data['type'] = MemDefine.ACTV_TYPE_PRIVI with get_connection('qf_mchnt') as db: db.insert('member_actv', data) return self.write(success({}))
def GET(self): ret = {} module_services = {} module_services['all'] = [] module_map = {} module_map['all'] = '全部' default_services = {} for module in MODULES: module_code = module.get('module', '') module_name = module.get('name', '') module_services[module_code] = [] module_map[module_code] = module_name for service in SYSTEM_SERVICES: if not service.get('status', 0) == 1: continue service_dict = {} service_dict['code'] = code = service.get('code', '') service_dict['name'] = name = service.get('name', '') if code in DEFAULT_SERVICES: default_services[code] = name module = service.get('module', 'default') module_code = self._get_module(module) module_services[module_code].append(service_dict) ret['module_map'] = module_map ret['module_services'] = module_services ret['default_services'] = default_services return self.write(success(ret))
def GET(self): try: userid = int(self.user.userid) results = [] with get_connection('qf_mchnt') as db: invoices = db.select( table='invoices', where={'userid': userid}, other='order by ctime desc limit 5') or [] for i in invoices: tmp = {} tmp['title'] = i.get('title', '') tmp['tax_no'] = i.get('tax_no', '') tmp['address'] = i.get('address', '') tmp['telephone'] = i.get('telephone', '') tmp['bank_name'] = i.get('bank_name', '') tmp['bank_num'] = i.get('bank_num', '') results.append(tmp) return self.write(success(data=results)) except: log.warn('error :%s' % traceback.format_exc()) return self.write(error(QFRET.SERVERERR, respmsg='内部错误'))
def POST(self): userid = self.user.userid params = {k: str(v).strip() for k, v in self.req.input().iteritems()} origin_password = params.get("origin_password", "") new_password = params.get("new_password", "") if (not origin_password) or (not new_password): raise ParamError("缺少参数") # 验证商户是否已经设置过密码 pwd_indbm, has_set = has_set_mpwd(userid) if not has_set: raise DBError("此商户尚未设置过管理密码") if not check_password(origin_password, pwd_indbm): raise DBError("原始密码输入错误") with get_connection("qf_core") as conn: try: affect_line = conn.update( "extra_mchinfo", where={"userid": userid}, values={"manage_password": enc_password(new_password)}) if not affect_line: raise DBError("更新数据失败") else: return self.write(success(data={})) except: log.debug(traceback.format_exc()) raise DBError("更新数据失败")
def GET(self): d = {k: v.strip() for k, v in self.req.input().iteritems()} data = {} # userid try: data['mchnt_id'] = hids.decode(d['mchnt_id'])[0] except: data['mchnt_id'] = int(d.get('mchnt_id') or 0) # customer_id try: data['customer_id'] = hids.decode(d['customer_id'])[0] except: if self.customer.customer_id: data['customer_id'] = self.customer.customer_id else: raise SessionError('消费者未登录') # groupid groupid = d.get('groupid') if is_valid_int(groupid): data['groupid'] = groupid # 分页信息 page, pagesize = d.get('page', 0), d.get('pagesize', 10) if not all(map(is_valid_int, (pagesize, page))): raise ParamError('分页信息错误') data['offset'], data['limit'] = int(page) * int(pagesize), int( pagesize) # 获取列表 r, total_num = self.card_list(data) return self.write(success({'cards': r, 'total_num': total_num}))
def POST(self): params = self.req.input() data = {} data['userid'] = self.get_bind_id() data['apptype'] = int(params.get('app_type') or 402) data['device_token'] = params.get('device_token', '').strip() data['openid'] = params.get('openid', '') data['mobile'] = params.get('mobile', 0) data['appver'] = params.get('appver', '') data['badge'] = int(params.get('badge', '0').strip()) data['usertag'] = int(params.get('usertag', '0')) data['token_status'] = 0 data['create_time'] = data['update_time'] = 'now()' data['is_logout'] = int(params.get('is_logout') or 0) if not data['device_token']: raise ParamError('参数错误') for i in ios_bind_platform: try: getattr(self, i + '_bind')(data) except: log.warn(traceback.format_exc()) return success({})