'src': getattr(config, 'CONSTANTS_SRC', 'mchnt_api') }, fields='code, value') if not cons: return ret = {} for con in cons: try: ret[con['code']] = json.loads(con['value']) except: ret[con['code']] = con['value'] return ret qfcache.set_value('language_constant', None, load_constants, getattr(config, 'CONSTANTS_CACHE', 3600)) def get_constant(code=None, language=None, default_self=True): ''' 返回常量 如果code为空, 返回所有的常量, 否则返回指定的常量 ''' default = code if default_self else None cons = qfcache.get_data('language_constant') if not code: return cons
load_fields = [ 'protocol', 'qrcode', 'csinfo', 'promotion_url', 'service', 'ext' ] for conf in qdconfs: t = {i: conf[i] for i in ('name', 'qd_uid', 'wx_pub')} for field in load_fields: try: t[field] = json.loads(conf[field]) except: t[field] = None ret[conf['qd_uid']] = t return ret qfcache.set_value('qd_conf', None, load_qd_conf, 3600) def get_qd_conf(): return qfcache.get_data('qd_conf') def get_qd_conf_value(userid=None, mode='coupon', key='promotion_url', **kw): '''获取物料的链接 会区分渠道id返回url Args: userid: 商户userid. mode: coupon,红包的物料链接; card,集点的物料链接. key: qd_conf的key值
def load_shop_cates(data=None): cates = None with get_connection('qf_mchnt') as db: cates = db.select('shop_category', where={ 'status': 1, 'create_time': '2016-05-18 06:59:59' }, fields='id, parent_id, name, weight', other='order by weight desc') return cates qfcache.set_value('kuma_shop_cates', None, load_shop_cates, getattr(config, 'KUMA_SHOP_CATE_CACHE', 3600)) def analysis_list(cates, pid=0): ''' 递归, 讲店铺类型分类 ''' r = [i for i in cates[::] if i['parent_id'] == pid] for i in r: i['shoptypes'] = analysis_list(cates, i['id']) return r def get_shop_cates(pid=0): all_cates = qfcache.get_data('kuma_shop_cates') or []
def load_relations(relation=None): ''' 获取所有关系 ''' relations = apcli_ex('getRelationDict', [], 'merchant') r = {} for userid, linkids in relations.iteritems(): for linkid in linkids: r[linkid] = userid return r qfcache.set_value('relation', None, load_relations, 3600) def get_relations(): return qfcache.get_data('relation') def check_smscode(code, mobile, mode=0): '''验证验证码 通过captcha服务验证验证码 Params: code: 验证码 mobile: 手机号 mode: 0 验证后不删除, 1:验证后删除code, 2:验证后删除ucode下的所有code