def GET(self): userid = self.req.input().get('userid') if not is_valid_int(userid): raise ParamError('userid为空') customer_id = self.req.input().get('customer_id') if not is_valid_int(customer_id): raise ParamError('商户id为空') cardno = None with get_connection_exception('qf_mchnt') as db: member = db.select_one( 'member', where= { 'userid': userid, 'customer_id': customer_id } ) if member: cardno = member['id'] else: self.be_member(userid, customer_id, MemDefine.MEMBER_SRC_CARD) cardno = getattr(self, '_cardno', '') return self.write(success({'cardno': cardno}))
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 _trans_input(self): d = {k:v.strip() for k, v in self.req.input().iteritems()} log.info('d:%s' % d) r = {} try: r['customer_id'] = hids.decode(d.get('customer_id'))[0] except: if self.customer.customer_id: r['customer_id'] = self.customer.customer_id else: r['customer_id'] = -1 r['mode'] = d.get('mode', '') r['userid'] = d.get('userid', '') if is_valid_int(d.get('groupid')): r['groupid'] = d.get('groupid') if r['mode'] not in ('info', 'list'): raise ParamError('请求参数错误') elif r['mode'] == 'info': r['userid'] = int(r['userid']) elif r['mode'] == 'list': r['mchnt_id'] = int(d.get('mchnt_id') or 0) if r['customer_id'] == -1: raise ParamError('消费者id不正确') page, pagesize = d.get('page', 0), d.get('pagesize', 10) if not all(map(is_valid_int, (pagesize, page))): raise ParamError('分页信息错误') r['offset'], r['limit'] = int(page)*int(pagesize), int(pagesize) return r
def get_mchnt_mccstr(mcc=None, lang=None, langconf=None): """根据mcc获取对应的中文mcc""" mcc_str = '' if not mcc: return mcc_str if not is_valid_int(mcc): return mcc_str mcc = int(mcc) with get_connection_exception('qf_mis') as db: ret = db.select_one('tools_mcc', where={'id': mcc, 'mcc_display': 1}) if not ret: with get_connection_exception('qf_mis') as db: ret = db.select_one('tools_mcca', where={ 'id': mcc, 'mcca_display': 1 }) if ret: mcc_str = ret['mcca_name'] else: mcc_str = ret['mcc_name'] if lang == 'en': for i in PRIMARY_MCC: if mcc_str == i['name']: mcc = i['id'] for i in getattr(langconf, 'PRIMARY_MCC'): if mcc == i['id']: mcc_str = i['name'] return mcc_str
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 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 _trans_input(self): d = {k: v.strip() for k, v in self.req.input().iteritems()} r = {} # 修改值 update_data = {} if 'status' in d: if d['status'] not in map(str, PROMO_CODE_STATUS.values()): raise ParamError('修改的状态不对') update_data['status'] = d['status'] if 'use_limit' in d: if not is_valid_int(d['use_limit']): raise ParamError('推广码的限制次数为数字') update_data['use_limit'] = d['use_limit'] if not update_data: raise ParamError('渠道推广码未做任何修改') update_data['utime'] = int(time.time()) r['update_data'] = update_data # 商户userid r['code'] = d.get('code') if not r['code']: raise ParamError('渠道推广码不能为空') return r
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 _trans_input(self): d = {k: v.strip() for k, v in self.req.input().iteritems()} r = {} # 修改值 update_data = {} if 'status' in d: if d['status'] not in map(str, PROMO_STATUS.values()): raise ParamError('修改的状态不对') update_data['status'] = d['status'] if 'balance' in d: if d['mode'] not in ('fixed', 'addon'): raise ParamError('修改余额的模式不对') if not is_valid_int(d['balance']): raise ParamError('余额必须为数字') if d['mode'] == 'fixed': update_data['balance'] = d['balance'] else: update_data['balance'] = DBFunc('balance+%d' % int(d['balance'])) if not update_data: raise ParamError('商户未做任何修改') update_data['utime'] = int(time.time()) r['update_data'] = update_data # 商户userid r['userid'] = d.get('userid') if not r['userid']: raise ParamError('渠道商户ID不能为空') return r
def get_big_uid(self): params = self.req.input() src = self.get_src() log.debug('src:%s' % src) # 验证登录 if not self.check_login(): raise SessionError('用户未登录') if src == 'salesman': if not is_valid_int(params.get('big_uid')): raise ParamError('参数错误') sm_uid = self.user.userid cates = apcli('getUserCategory', int(sm_uid), '') or [] cates = [i.code for i in cates] if 'saleman' not in cates and 'qudao' not in cates: raise ParamError('该用户非业务员') big_cates = apcli('getUserCategory', int(params['big_uid']), '') or [] big_cates = [i.code for i in big_cates] if 'bigmerchant' not in big_cates: raise ParamError('非大商户') return int(params['big_uid']) else: if self.get_cate() != 'bigmerchant': raise ParamError('非大商户') return int(self.user.userid)
def GET(self): pid = self.req.input().get('pid', '0').strip() if not is_valid_int(pid): raise ParamError('param error') pid = int(pid) return success({'shop_types': get_shop_cates(pid)})
def _trans_input(self): d = {k: v.strip() for k, v in self.req.input().iteritems()} r = {'aid': d.get('id', '')} r['mchnt_id'] = self._userid if not is_valid_int(r['aid']): raise ParamError('活动id不合法') return r
def _get_userids(): # 过去消费过的店铺 userids = self.db.select('member', where={'customer_id': d['customer_id']}, fields='userid') userids = [i['userid'] for i in userids or []] if is_valid_int(d['userid']): userids.append(int(d['userid'])) return set(userids)
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_query_groupid(self, params): if 'groupid' not in params or not is_valid_int(params['groupid']): return None groupid = int(params['groupid']) member_groupids = constants_cache['_mchnt_api_member_groupid'] or [] return groupid if groupid in member_groupids else None
def fen_to_yuan(amt): ''' 将分转化为元 ''' if not is_valid_int(amt): raise ParamError('amt必须为整数') yuan = amt / 100.0 return str(int(yuan)) if int(yuan) == yuan else str(yuan)
def open_pt(userid): if not is_valid_int(userid): raise ParamError('商户不存在') with get_connection_exception('qf_mchnt') as db: user = db.select_one( 'mchnt_control', where = {'userid' : int(userid)} ) if not user or not user['pt_rule']: raise ParamError('该商户暂未开通积分功能') return user
def get_query_userids(self, params): if is_valid_int(params.get('userid')): return [ int(params['userid']), ] groupid = self.get_query_groupid(params) if groupid: return userid_cache[groupid] or [] return None
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_userid(self, params): userid = None if params.get('enuserid'): userids = hids.decode(params['enuserid']) or [ None, ] userid = userids[0] elif is_valid_int(params.get('userid')): userid = int(params['userid']) if not userid: raise ParamError('商户不存在') return userid
def _get_province(self, provinceid): '''由provinceid获取省份''' if not provinceid or not is_valid_int(provinceid[:2]): return '' area = None with get_connection('qf_mis') as db: area = db.select_one('tools_area', where={ 'area_no': int(provinceid[:2]), 'area_display': 1, }, fields='area_name') area = (area or {}).get('area_name', '') return unicode_to_utf8_ex(area)
def check_customer(self, mobile): ''' 消费者补充会员休息 ''' enuserid = self.req.input().get('enuserid') if enuserid: try: userid = hids.decode(enuserid)[0] except: if not is_valid_int(enuserid): return userid = int(enuserid) user = apcli('findUserBriefById', userid) if user: self._groupid = user.groupid
def _trans_input(self): d = {k:v.strip() for k, v in self.req.input().iteritems()} # 活动id r = {'id' : d.get('id', '')} if not is_valid_int(r['id']): raise ParamError('活动id不合法') try: r['customer_id'] = hids.decode(d.get('customer_id'))[0] except: if self.customer.customer_id: r['customer_id'] = self.customer.customer_id else: raise ParamError('消费者id不正确') return r
def GET(self): # customer_id customer_id = self.get_customer_id() # 活动id activity_id = self.req.input().get('activity_id') if not is_valid_int(activity_id): raise ParamError('集点活动不存在') activity_id = int(activity_id) # 活动信息 actv = None with get_connection('qf_mchnt') as db: actv = db.select_one('card_actv', where={'id': activity_id}) if not actv: raise ParamError('活动不存在') with get_connection_exception('qf_mchnt') as db: where = {'activity_id': activity_id, 'customer_id': customer_id} customer = db.select_one('member_pt', where=where) # 若未有集点卡记录 if not customer: raise ParamError('未领取集点卡') # 消费者records现有的兑换码 where['status'] = CODE_STATUS_CREATE codes = db.select(table='exchange_record', where=where, other='order by ctime desc') or [] codes = self.tidy_codes(codes, customer, actv) return success({ 'codes': [{ 'id': str(i['id']), 'code': '{:0>4d}'.format(i['code']), 'qrcode': ''.join([ self.pre_code, hids.encode(i['code'], actv['id'], i['id']) ]) } for i in codes], 'card_info': self.card_info(actv) })
def GET(self): userid = self.req.input().get('userid') if not is_valid_int(userid): raise ParamError('userid为空') content = '' with get_connection('qf_mchnt') as db: privilege = db.select_one( 'member_actv', where= { 'userid': userid, 'type': MemDefine.ACTV_TYPE_PRIVI } ) or {} content = privilege.get('content') or '' return self.write(success({'content': content}))
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 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 GET(self): where = {'status': CODE_STATUS_EXCHANGED} params = self.req.input() if is_valid_int(params.get('id')): where['id'] = int(params['id']) elif 'code' in params: try: code = params['code'] encode = code[len(self.pre_code):] code, actv_id, code_id = hids.decode(encode) code = '{:0>4d}'.format(code) where['id'] = code_id except: raise ParamError('兑换码不存在') else: raise ParamError('兑换码不存在') with get_connection_exception('qf_mchnt') as db: r = db.select_one('exchange_record', where=where) return success({'exchanged': int(bool(r))})
def _get_city(self, provinceid): '''由provinceid获取市''' if not provinceid or not is_valid_int(provinceid): return '' city = None with get_connection('qf_mis') as db: city = db.select_join_one('tools_areacity tac', 'tools_area ta', on={'tac.area_id': 'ta.id'}, where={ 'area_display': 1, 'city_display': 1, 'ta.area_no': int(provinceid[:2]), 'tac.city_no': ('in', (provinceid[:2], provinceid[:4], provinceid)) }, fields='city_name') city = (city or {}).get('city_name', '') return unicode_to_utf8_ex(city)
def POST(self): params = self.req.input() if not is_valid_int(params.get('txamt')): raise ParamError('txmat is must') for i in ('openid', 'out_trade_no', 'userid'): if not params.get(i): raise ParamError('%s is must' % i) pay_type = params.get('pay_type', '800207') if pay_type not in ('800207', '800213'): raise ParamError('暂不支持该支付类型') # 校验是否开通积分功能 open_pt(params['userid']) data = { 'txamt' : int(params['txamt']), 'sub_openid' : params['openid'], 'pay_type' : pay_type, 'txcurrcd' : 'CNY', 'out_trade_no' : params['out_trade_no'], 'txdtm' : time.strftime(DTM_FMT), 'goods_name' : params.get('goods_name', ''), 'mchid' : hids.encode(config.WXY_QT2_CONF['app_uid'], int(params['userid'])) } if is_valid_datetime(params.get('txdtm')): data['txdtm'] = params['txdtm'] ret = qt2_requests('/trade/v1/payment', data, 'post') resperr = ret.pop('resperr', '') ret.pop('respmsg', '') return success(ret, resperr)