def do_fish_memberKick(redis, session): """ 捕鱼会员踢出游戏接口 """ lang = getLang() fields = ('account', ) for field in fields: exec('%s = request.GET.get("%s","").strip()' % (field, field)) account2user_table = FORMAT_ACCOUNT2USER_TABLE % (account) member_table = redis.get(account2user_table) if not redis.exists(member_table): return {'code': 1, 'msg': '会员[%s]不存在' % (account)} #发送提出玩家协议给服务端 sendProtocol2AllGameService(redis, HEAD_SERVICE_PROTOCOL_KICK_MEMBER % (account), game="FISH") log_util.debug( '[try do_fish_memberKick] send protol[%s] to kick account[%s] out' % (HEAD_SERVICE_PROTOCOL_KICK_MEMBER % (account), account)) return web_util.do_response(0, '会员(%s)已被踢出游戏!' % (account), jumpUrl=BACK_PRE + '/fish/online/list')
def do_fishroom_delete(redis,session): """ 捕鱼房间列表删除接口 :params room_id 删除的房间ID """ fields = { ('room_id','房间ID','') } for field in fields: exec("%s = web_util.get_form('%s','%s','%s')"%(field[0],field[0],field[1],field[2])) try: delete_fishroom(redis,room_id) except: log_util.debug('[do_fishroom_delete] error[%s]'%(e)) return web_util.do_response(1,'删除失败!') return web_util.do_response(0,'删除成功',jumpUrl=BACK_PRE+'/fish/room/list')
def do_reward_deleteCall(redis,session): """ 删除奖品信息接口 :params reward_id 兑换奖品ID """ fields = { ('reward_id','奖品ID','') } for field in fields: exec('%s = web_util.get_form("%s","%s","%s")'%(field[0],field[0],field[1],field[2])) reward_table = FISH_REWARD_TABLE%(reward_id) if not redis.exists(reward_table): return web_util.do_response(1,'商品不存在.') reward_status = convert_util.to_int(redis.hget(reward_table,'reward_status')) if reward_status == REWARD_ONLINE: return web_util.do_response(1,'不能删除已上架的商品.') try: do_reward_delete(redis,reward_id) except Exception,e: log_util.error('[do_reward_delete] reward_id[%s] delete error.reason[%s]'%(reward_id,e)) return web_util.do_response(1,msg="删除奖品失败!")
def do_auto_charge(redis,session): """ 奖品上架接口 """ curTime = datetime.now() fields = ('reward_id',) for field in fields: exec("%s=request.forms.get('%s','').strip()"%(field,field)) if not reward_id: return {'code':1,'msg':'参数错误'} checkDesc = { 1 : '奖品ID为[%s]的商品下架成功', 0 : '奖品ID为[%s]的商品上架成功' } reward_table = FISH_REWARD_TABLE%(reward_id) reward_status,reward_now_nums,reward_nums,reward_type = redis.hmget(reward_table,('reward_status','reward_now_nums','reward_nums','reward_type')) reward_status = convert_util.to_int(reward_status) reward_now_nums = convert_util.to_int(reward_now_nums) reward_nums = convert_util.to_int(reward_nums) pipe = redis.pipeline() #auto_charge_set = redis.smembers(FISH_REWARD_AUTO_CHARGE) if reward_status == 1: pipe.hset(reward_table,'reward_status',0) pipe.lrem(FISH_REWARD_ON_SHOP_LIST,reward_id) pipe.lrem(FISH_REWARD_ON_SHOP_TYPE_LIST%(reward_type),reward_id) else: if reward_now_nums > reward_nums: return web_util.do_response(1,'该奖品期数已过期,不能上架!') pipe.hset(reward_table,'reward_status',1) pipe.lpush(FISH_REWARD_ON_SHOP_LIST,reward_id) pipe.lpush(FISH_REWARD_ON_SHOP_TYPE_LIST%(reward_type),reward_id) #更新版本号 pipe.hincrby(FISH_CONSTS_CONFIG,'exchange_shop_ver',1) pipe.execute() return {'code':0,'msg':checkDesc[reward_status]%(reward_id),'jumpUrl':BACK_PRE+'/goods/fish/reward/list'}
reward_table = FISH_REWARD_TABLE%(reward_id) if not redis.exists(reward_table): return web_util.do_response(1,'商品不存在.') reward_status = convert_util.to_int(redis.hget(reward_table,'reward_status')) if reward_status == REWARD_ONLINE: return web_util.do_response(1,'不能删除已上架的商品.') try: do_reward_delete(redis,reward_id) except Exception,e: log_util.error('[do_reward_delete] reward_id[%s] delete error.reason[%s]'%(reward_id,e)) return web_util.do_response(1,msg="删除奖品失败!") return web_util.do_response(0,msg="删除奖品成功",jumpUrl=BACK_PRE+'/goods/fish/reward/list') @admin_app.post('/goods/reward/upload') def do_file_upload(redis,session): ''' 奖品图片上传接口 @params: ''' files = request.files.get('files') try: file_name,file_ext = files.filename.split('.') except: return json.dumps({'error':'文件名称不符合规范,请不要包含特殊字符!'}) #文件新名称 new_file_name = file_name+md5.new(str(file_name)+str(time.time())).hexdigest()+"."+file_ext #文件上传路劲
def get_show_detail(redis, session): """ 获取7日的数据变化 """ SYS_HOME_DATA_SETTING = { 'FISH': { 'data': ['每日注册', '每日活跃数', '每日充值数'], 'login_datas': [], 'recharge_datas': [], 'reg_datas': [] }, 'HALL': { 'data': ['每日注册', '每日活跃数', '每日耗卡数'], 'login_datas': [], 'take_datas': [], 'reg_datas': [], } } fields = ('sys', ) for field in fields: exec('%s=request.GET.get("%s","").strip()' % (field, field)) #获取生成对象类型 show_obj = SYS_HOME_DATA_SETTING[sys] #获取当前一周日期并格式化为字符串 week_date_lists = get_week_date_list() if sys == 'HALL': for week_date in week_date_lists: show_obj['reg_datas'].append( convert_util.to_int( redis.scard(FORMAT_REG_DATE_TABLE % (week_date)))) show_obj['take_datas'].append( convert_util.to_int( redis.get(DAY_ALL_PLAY_ROOM_CARD % (week_date)))) #show_obj['login_datas'].append( # convert_util.to_int(redis.get(DAY_ALL_LOGIN_COUNT%(week_date))) #) selfUid = session['id'] data = get_active_reports(redis, week_date, week_date, selfUid) if data["data"]: show_obj['login_datas'].append( convert_util.to_int(data["data"][0]["login_count"])) else: show_obj['login_datas'].append( convert_util.to_int( redis.get(DAY_ALL_LOGIN_COUNT % (week_date)))) show_obj['series'] = [ { 'name': '每日注册', 'type': 'line', 'data': show_obj['reg_datas'] }, { 'name': '每日耗卡数', 'type': 'line', 'data': show_obj['take_datas'] }, { 'name': '每日活跃数', 'type': 'line', 'data': show_obj['login_datas'] }, ] else: for week_date in week_date_lists: show_obj['reg_datas'].append( convert_util.to_int( redis.scard(FORMAT_REG_DATE_TABLE4FISH % (week_date)))) show_obj['recharge_datas'].append( convert_util.to_int( redis.hget(FISH_SYSTEM_DATE_RECHARGE_TOTAL % (week_date), 'recharge_coin_total'))) show_obj['login_datas'].append( convert_util.to_int( redis.scard(FORMAT_LOGIN_DATE_TABLE4FISH % (week_date)))) show_obj['series'] = [ { 'name': '每日注册', 'type': 'line', 'data': show_obj['reg_datas'] }, { 'name': '每日充值数', 'type': 'line', 'data': show_obj['recharge_datas'] }, { 'name': '每日活跃数', 'type': 'line', 'data': show_obj['login_datas'] }, ] return web_util.do_response(1, msg="", jumpUrl="", data={ 'week': week_date_lists, 'series': show_obj['series'], 'legen': show_obj['data'] })
def do_agent_modify(redis, session): """ 代理修改接口 :params agentId 修改的代理ID :params account """ curTime = datetime.now() fields = ('agentId', 'account', 'unitPrice', 'shareRate', 'myRate', 'name', 'defaultRoomCard') for field in fields: exec("%s = request.forms.get('%s','').strip()" % (field, field)) if not agentId: return {'code': 1, 'msg': '非法修改代理!'} agent_type, parent_id = redis.hmget(AGENT_TABLE % (agentId), ('type', 'parent_id')) log_util.debug('[do_agModify] try to modify agentId[%s] account[%s]'\ %(agentId,account)) if unitPrice and shareRate: if float(shareRate) > float(unitPrice): return {'code': 1, 'msg': '给下级分成不能大于钻石单价!'} if myRate and shareRate: if float(shareRate) > float(myRate): return {'code': 1, 'msg': '给下级分成不能大于父代理的分成!'} pipe = redis.pipeline() adminTable = AGENT_TABLE % (agentId) agentInfo = { 'shareRate': shareRate, 'unitPrice': unitPrice, 'name': name, 'defaultRoomCard': defaultRoomCard, } if unitPrice: log_util.debug('[modify] unitPrice[%s]' % (unitPrice)) pipe.sadd(AGENT_ROOMCARD_PER_PRICE % (agentId), unitPrice) if shareRate and agent_type in ['1', '2']: unitPrice = get_user_card_money(redis, agentId) log_util.debug('[modify] agentId[%s] shareRate[%s]' % (agentId, unitPrice)) pipe.sadd(AGENT_RATE_SET % (agentId), shareRate) if unitPrice: pipe.sadd(AGENT_ROOMCARD_PER_PRICE % (agentId), unitPrice) elif myRate and agent_type in ['3']: unitPrice = get_user_card_money(redis, agentId) log_util.debug('[modify] agentId[%s] shareRate[%s]' % (agentId, unitPrice)) pipe.sadd(AGENT_RATE_SET % (agentId), myRate) pipe.sadd(AGENT_ROOMCARD_PER_PRICE % (agentId), unitPrice) pipe.hmset(adminTable, agentInfo) #为该代理重新绑定拥有的游戏 modifyAgentGames(request, redis, agentId) # 修改代理的禁用列表权限 banAgentAccessModify(redis, request, agent_type, agentId) pipe.execute() #创建成功日志 log_util.debug('[try do_agent_modify] modify success! info[%s]' % (agentInfo)) return web_util.do_response(0, '修改代理[%s]成功' % (account), jumpUrl='/admin/agent/list')
def createAgentOther(redis, session, agent_id=None): """ 创建代理操作 """ curTime = datetime.now() now_date = curTime.strftime('%Y-%m-%d') selfUid = session['id'] lang = getLang() for fields in AGENT_FIELDS: exec(POST_FORMS % (fields, fields)) parentAg = agent_id if not parentAg: return {'code': 1, 'msg': '非法创建代理!'} #当前创建的是 agent_type, is_trail, parent_unitPrice = redis.hmget( AGENT_TABLE % (parentAg), ('type', 'isTrail', 'unitPrice')) is_trail = convert_util.to_int(is_trail) #打印一下 log_util.debug('[try do_create_agent] parentAg[%s] account[%s] passwd[%s] comfirmPasswd[%s]'\ %(parentAg,account,passwd,comfirPasswd)) checkFields = [{ 'field': account, 'msg': '代理账号不能为空' }, { 'field': passwd, 'msg': '密码不能为空' }, { 'field': comfirPasswd, 'msg': '密码不能为空' }] for field in checkFields: if not field['field']: return {'code': 1, 'msg': field['msg']} if unitPrice and shareRate: if float(shareRate) > float(unitPrice): return {'code': 1, 'msg': '给下级分成不能大于钻石单价!'} if myRate and shareRate: if float(shareRate) > float(myRate): return {'code': 1, 'msg': '给下级分成不能大于自己的分成!'} agent_table = AGENT_TABLE % (agentId) if redis.exists(agent_table): return {'code': 1, 'msg': '代理ID[%s]已存在' % (agentId)} parentSetTable = AGENT_CHILD_TABLE % (parentAg) if int(parentAg) == 1: recharge, create_auth, open_auth = '1', '0', '0' else: topAgentId = getTopAgentId(redis, parentAg) recharge, create_auth = redis.hmget(AGENT_TABLE % (topAgentId), ('recharge', 'create_auth')) open_auth = '0' create_auth = convert_util.to_int(create_auth) if not recharge: recharge = '1' admimtoIdTalbel = AGENT_ACCOUNT_TO_ID % (account) pipe = redis.pipeline() if not redis.exists(admimtoIdTalbel): if not agentId: agentId = getAgentIdNo(redis) else: pipe.sadd(AGENT_ID_TABLE, agentId) agentType = int(agent_type) + 1 agentInfo = { 'id': agentId, 'account': account, 'passwd': hashlib.sha256(passwd).hexdigest(), 'name': '', 'shareRate': shareRate, 'valid': 1, 'roomcard_id': 0, 'parent_id': parentAg, 'roomcard': 0, 'regIp': '127.0.0.1', 'regDate': convert_util.to_dateStr(curTime.now(), "%Y-%m-%d %H:%M:%S"), 'lastLoginIP': 1, 'lastLoginDate': 1, 'isTrail': is_trail, 'unitPrice': unitPrice, 'recharge': recharge, 'isCreate': '1', 'create_auth': create_auth, 'open_auth': open_auth, 'type': agentType, 'defaultRoomCard': defaultRoomCard, } adminTable = AGENT_TABLE % (agentId) if unitPrice: pipe.sadd(AGENT_ROOMCARD_PER_PRICE % (agentId), unitPrice) if shareRate and agent_type in ['0', '1', '2']: if agent_type == '1': unitPrice = parent_unitPrice elif agent_type == '2': unitPrice = get_user_card_money(redis, parentAg) pipe.sadd(AGENT_RATE_SET % (agentId), shareRate) pipe.sadd(AGENT_ROOMCARD_PER_PRICE % (agentId), unitPrice) #创建日期索引 pipe.sadd(AGENT_CREATE_DATE % (now_date), agentId) pipe.hmset(adminTable, agentInfo) #创建代理账号映射id pipe.set(admimtoIdTalbel, agentId) #将该代理添加进父代理集合 pipe.set(AGENT2PARENT % (agentId), parentAg) #创建代理账号的父Id映射 pipe.sadd(parentSetTable, agentId) # 为该代理绑定拥有的游戏 setAgentGames(request, redis, parentAg, agentId) # 为该代理绑定拥有的权限(通过type) setAgentAccess(redis, agentType, agentId) # 禁止改代理的列表权限 banAgentAccess(redis, request, agentType, agentId) pipe.execute() else: log_util.debug('[try crateAgent] agent account[%s] is exists!' % (account)) return {'code': 1, 'msg': '代理账号(%s)已经存在.' % (account)} #创建成功日志 logInfo = {'datetime':curTime.strftime('%Y-%m-%d %H:%M:%S'),\ 'ip':request.remote_addr,'desc':lang.AGENT_OP_LOG_TYPE['openAgent']%(agentId)} writeAgentOpLog(redis, selfUid, logInfo) log_util.debug('[try createAgent] SUCCESS agent create success! info[%s]' % (agentInfo)) return web_util.do_response(0, msg='创建代理[%s]成功' % (account), jumpUrl='/admin/agent/list')
def do_create_agent(redis, session, agent_id=None): """ 创建代理操作 """ lang = getLang() parent_id = agent_id account = int(time.time()) / random.randint(1, 10) admimtoIdTalbel = AGENT_ACCOUNT_TO_ID % (account) parentSetTable = AGENT_CHILD_TABLE % (parent_id) target_user_id = account curTime = datetime.now() now_date = curTime.strftime('%Y-%m-%d') agent_type, is_trail, parent_unitPrice, parent_id = redis.hmget( AGENT_TABLE % (agent_id), ('type', 'isTrail', 'unitPrice', "parent_id")) pipe = redis.pipeline() shareRate = 0 id_no = getAgentIdNo(redis) is_trail = int(is_trail) if is_trail else 0 recharge, create_auth, open_auth = '1', '0', '0' agentType = int(agent_type) + 1 agentInfo = { 'id': id_no, 'account': account, 'passwd': hashlib.sha256('12345678').hexdigest(), 'name': '', 'shareRate': shareRate, 'valid': 1, 'roomcard_id': 0, 'parent_id': agent_id, 'roomcard': 0, 'regIp': '127.0.0.1', 'regDate': convert_util.to_dateStr(curTime.now(), "%Y-%m-%d %H:%M:%S"), 'lastLoginIP': 1, 'lastLoginDate': 1, 'isTrail': is_trail, 'recharge': recharge, 'isCreate': '1', 'create_auth': create_auth, 'open_auth': open_auth, 'type': agentType, 'defaultRoomCard': 0, } adminTable = AGENT_TABLE % (id_no) agent_type, is_trail, parent_unitPrice, parent_id = redis.hmget( adminTable, ('type', 'isTrail', 'unitPrice', "parent_id")) if shareRate and agent_type in ['0', '1', '2']: if agent_type == '1': unitPrice = parent_unitPrice elif agent_type == '2': unitPrice = get_user_card_money(redis, parent_id) pipe.sadd(AGENT_RATE_SET % (id_no), shareRate) pipe.sadd(AGENT_ROOMCARD_PER_PRICE % (id_no), unitPrice) # 创建日期索引 pipe.sadd(AGENT_CREATE_DATE % (now_date), id_no) pipe.hmset(adminTable, agentInfo) # 创建代理账号映射id pipe.set(admimtoIdTalbel, id_no) # 将该代理添加进父代理集合 pipe.set(AGENT2PARENT % (id_no), parent_id) # 创建代理账号的父Id映射 pipe.sadd(parentSetTable, id_no) pipe.hset(FORMAT_USER_TABLE % target_user_id, "ownAgent", id_no) securyKeys = SecretKeys(redis) pipe.hset(EXCHANGE_AGENT_FIND, id_no, securyKeys) pipe.execute() #创建成功日志 logInfo = {'datetime':curTime.strftime('%Y-%m-%d %H:%M:%S'),\ 'ip':request.remote_addr, 'desc':lang.AGENT_OP_LOG_TYPE['openAgent']%(id_no)} selfAccount, selfUid = session['account'], session['id'] writeAgentOpLog(redis, selfUid, logInfo) log_util.debug('[try createAgent] SUCCESS agent create success! info[%s]' % (agentInfo)) return web_util.do_response(0, msg='创建代理[%s]成功' % (account), jumpUrl='/admin/agent/list')