Ejemplo n.º 1
0
def get_fish_cal_data(redis):
    """
    获取捕鱼的每日数据更新
    """
    curTime = convert_util.to_dateStr(datetime.now())

    log_per_day = convert_util.to_int(redis.scard(FORMAT_LOGIN_DATE_TABLE4FISH%(curTime)))
    reg_per_day = convert_util.to_int(redis.scard(FORMAT_REG_DATE_TABLE4FISH%(curTime)))
    total_member = convert_util.to_int(redis.scard(ACCOUNT4WEIXIN_SET4FISH))
    login_per_rate = convert_util.to_int(redis.get("fish:per:login:rate"))
    recharge_per_rate = convert_util.to_int(redis.get("fish:per:recharge:rate"))
    share_per_day  = convert_util.to_int(redis.scard(FISH_FIRST_SHARE_PER_DAY_SET))
    total_share    = convert_util.to_int(redis.get(FISH_SHARE_TOTAL))
    log_util.debug('[get_fish_cal_data] log_per_day[%s] reg_per_day[%s] total_member[%s] login_per_rate[%s] recharge_per_rate[%s]'\
                        %(log_per_day,reg_per_day,total_member,login_per_rate,recharge_per_rate))

    return {
            'log_per_day'        :   log_per_day,
            'reg_per_day'        :   reg_per_day,
            'total_member'       :   total_member,
            'login_per_rate'     :   login_per_rate,
            'recharge_per_rate'  :   recharge_per_rate,
            'share_per_day'      :   share_per_day,
            'total_share'        :   total_share
    }
Ejemplo n.º 2
0
def check_spring_time(redis, active_id = False):
    '''
    检查是否春节活动时间
    active_id:
        福禄双收   1
        三阳开泰   2
        红包鱼     3
        答题       4
    '''
    curTime = convert_util.to_dateStr(datetime.now())
    key = ACTIVICE_SPRING_TIME if active_id == False else ACTIVE_CONFIG_ONE_HESH % active_id

    if active_id == False:
        springTime = redis.get(key)
        springTime = json.loads(springTime)
        start_date = springTime['from']
        end_date = springTime['to']
    else:
        springTime = redis.exists(key)
        start_date, end_date = redis.hmget(key, ('start_time', 'end_time'))


    if springTime:
        s_time = time.mktime(time.strptime(start_date, '%Y-%m-%d'))  # get the seconds for specify date
        e_time = time.mktime(time.strptime(end_date, '%Y-%m-%d'))
        log_time = time.mktime(time.strptime(curTime, '%Y-%m-%d'))
        if float(log_time) < float(s_time):
            return False, '活动未开始'
        if float(log_time) > float(e_time):
            return False, '活动已结束'
        return True, '活动开放中'
    else:
        return False, '活动未开始'
Ejemplo n.º 3
0
def do_pay_record(redis, user_id, user_table, coin, price):
    """
    捕鱼支付统计
    :params redis实例
    :params user_id 用户ID
    :params coin 支付金币
    """
    today = convert_util.to_dateStr(datetime.now())
    coin = convert_util.to_int(coin)
    pipe = redis.pipeline()
    try:
        pipe.hincrby(user_table, 'coin', coin)
        try:
            pipe.hincrbyfloat(user_table, 'recharge_coin_total',
                              int(price) * 0.01)
        except:
            pipe.hincrbyfloat(user_table, 'recharge_coin_total',
                              float(price) * 0.01)
        pipe.incrbyfloat(FISH_SYSTEM_RECHARGE_TOTAL, price)
        pipe.hincrbyfloat(FISH_SYSTEM_DATE_RECHARGE_TOTAL % (today),
                          'recharge_coin_total',
                          int(price) * 0.01)
        if not redis.sismember(FISH_RECHARGE_USER_DAY_IDS, user_id):
            pipe.hincrby(FISH_SYSTEM_DATE_RECHARGE_TOTAL % (today),
                         'recharge_user_total', 1)
            pipe.sadd(FISH_RECHARGE_USER_DAY_IDS, user_id)
    except Exception, e:
        log_util.error(
            '[FUNC do_pay_record] Error userId[%s] coin[%s] reason[%s]' %
            (user_id, coin, e), True)
        return None
Ejemplo n.º 4
0
def get_fish_sys_datas(redis,start_date,end_date):
    """
    获取捕鱼系统统计数据
    params: redis, start_date,end_date
    """
    start_date = convert_util.to_datetime(start_date)
    end_date = convert_util.to_datetime(end_date)

    one_day = timedelta(1)
    now_date = datetime.now()
    total_members = convert_util.to_int(redis.scard(ACCOUNT4WEIXIN_SET4FISH))
    total_recharge = convert_util.to_int(redis.get(FISH_SYSTEM_RECHARGE_TOTAL))
    data_list = []
    while end_date >= start_date:
        if end_date > now_date:
            end_date-=one_day
            continue
        today = convert_util.to_dateStr(end_date)
        today_reg = redis.scard(FORMAT_REG_DATE_TABLE4FISH%(today))
        today_active = convert_util.to_int(redis.scard(FORMAT_LOGIN_DATE_TABLE4FISH%(today)))
        today_sys_user_total,today_sys_coin_total = redis.hmget(FISH_SYSTEM_DATE_RECHARGE_TOTAL%(today),('recharge_user_total','recharge_coin_total'))
        today_sys_user_total = convert_util.to_int(today_sys_user_total)
        today_sys_coin_total  = convert_util.to_float(today_sys_coin_total)
        try:
            average_val = round(today_sys_coin_total/today_active,2)
        except:
            average_val = 0.00
        data_list.append({
            'today'         :   today,
            'today_reg'     :   today_reg,
            'today_active'  :   today_active,
            'today_sys_user_total' : today_sys_user_total,
            'today_sys_coin_total' : today_sys_coin_total,
            'average_val' :  average_val,
            'money_total' :  string_util.format_credit(total_recharge),
        })
        end_date-=one_day

    # 查詢奖池情况
    jackpot = redis.hgetall("fish:room:jackpot:hesh")
    if not jackpot:
        jackpot = {}

    __swit = {
        "5000": "十炮场",
        "5001": "百炮场",
        "5002": "千炮场",
        "5003": "万炮场"
    }
    result = []
    for gameId, value in jackpot.items():
        result.append({
            "name": __swit[gameId],
            "gameId": gameId,
            "value": value
        })
    timestamp = time.strftime("%Y-%m-%d", time.localtime())
    number = redis.get("fish:redpick:fish:%s:number" % timestamp) or 0
    return {'data':data_list, "water": result, "fishRedPick": number}
Ejemplo n.º 5
0
def pushNotices(redis,session,action='hall'):
    """
    将消息放进玩家的信息列表
    """
    type2Msg = {'0':'推送','1':'取消推送'}
    action = action.upper()
    timeStr = convert_util.to_dateStr(datetime.now())
    agentId  = session['id']
    active_id = request.GET.get('active_id','').strip()

    pipe = redis.pipeline()
    #超级管理员发的公告需要塞到所有玩家的信息盒子
    active_table = FORMAT_GAMEHALL_ACTIVE_TABEL%(active_id)
    senderId = redis.hget(active_table,'groupId')
    if not senderId:
        senderId = 1

    if action == 'HALL':
        memberIdList = getAgentAllMemberIds(redis,senderId)
        user_msg_table_list = FORMAT_USER_ACTIVE_LIST
    else:
        userIdKey = []
        memberIds = redis.smembers(ACCOUNT4WEIXIN_SET4FISH)
        for memberId in memberIds:
            table = FORMAT_ACCOUNT2USER_TABLE%(memberId) #从账号获得账号信息,和旧系统一样
            userIdKey.append(table)
        memberIdList = [userId.split(":")[1] for userId in redis.mget(userIdKey)]
        user_msg_table_list = FORMAT_USER_ACTIVE_FISH_LIST

    #推送所有公告
    status = convert_util.to_int(redis.hget(active_table,'status'))
    log_util.debug('[try pushNotices] agentId[%s] memberIds[%s] status[%s] action[%s]'%(agentId,memberIdList,status,action))
    try:
        if status == 0:
            for memberId in memberIdList:
                pipe.hset(FORMAT_GAMEHALL_ACTIVE_TABEL%(active_id),'time',timeStr)
                pipe.lpush(user_msg_table_list%(memberId),active_id)
            pipe.hset(active_table,'status',1)
        else:
            for memberId in memberIdList:
                pipe.lrem(user_msg_table_list%(memberId),active_id)
                pipe.srem(FORMAT_ACT_READ_SET%(active_id),memberId)
            pipe.hset(active_table,'status',0)
    except Exception,e:
        log_util.debug('[try pushNotices] ERROR agentId[%s] reason[%s]'%(agentId,e))
        return {'code':1,'msg':type2Msg[str(status)]+'失败.'}
Ejemplo n.º 6
0
def pushNotices(redis,session,action='hall'):
    """
    将消息放进玩家的信息列表
    """
    type2Msg = {'0':'推送','1':'取消推送'}
    action = action.upper()
    timeStr = convert_util.to_dateStr(datetime.now())
    agentId  = session['id']
    noticId = request.GET.get('id','').strip()

    pipe = redis.pipeline()
    #超级管理员发的公告需要塞到所有玩家的信息盒子
    noticeTable = FORMAT_GAMEHALL_NOTIC_TABLE%(noticId)
    senderId = redis.hget(noticeTable,'groupId')
    if not senderId:
        senderId = 1
    memberIds = getAgentAllMemberIds(redis,senderId)

    if action == 'HALL':
        user_msg_table_list = FORMAT_USER_MESSAGE_LIST
    else:
        user_msg_table_list = FORMAT_USER_MSG_FISH_LIST

    #推送所有公告
    status = convert_util.to_int(redis.hget(noticeTable,'status'))
    log_util.debug('[try pushNotices] agentId[%s] memberIds[%s] status[%s] action[%s]'%(agentId,memberIds,status,action))
    try:
        if status == 0:
            for memberId in memberIds:
                pipe.hset(FORMAT_GAMEHALL_NOTIC_TABLE%(noticId),'time',timeStr)
                pipe.lpush(user_msg_table_list%(memberId),noticId)
            pipe.hset(noticeTable,'status','1')
        else:
            for memberId in memberIds:
                pipe.lrem(user_msg_table_list%(memberId),noticId)
                pipe.srem(FORMAT_MSG_READ_SET%(noticId),memberId)
            pipe.hset(noticeTable,'status','0')
    except Exception,e:
        log_util.debug('[try pushNotices] ERROR agentId[%s] reason[%s]'%(agentId,e))
        return {'code':1,'msg':type2Msg[str(status)]+'失败.'}
Ejemplo n.º 7
0
def get_fish_sys_datas(redis,start_date,end_date):
    """
    获取捕鱼系统统计数据
    params: redis, start_date,end_date
    """
    start_date = convert_util.to_datetime(start_date)
    end_date = convert_util.to_datetime(end_date)

    one_day = timedelta(1)
    now_date = datetime.now()
    total_members = convert_util.to_int(redis.scard(ACCOUNT4WEIXIN_SET4FISH))
    total_recharge = convert_util.to_int(redis.get(FISH_SYSTEM_RECHARGE_TOTAL))
    data_list = []
    while end_date >= start_date:
        if end_date > now_date:
            end_date-=one_day
            continue
        today = convert_util.to_dateStr(end_date)
        today_reg = redis.scard(FORMAT_REG_DATE_TABLE4FISH%(today))
        today_active = convert_util.to_int(redis.scard(FORMAT_LOGIN_DATE_TABLE4FISH%(today)))
        today_sys_user_total,today_sys_coin_total = redis.hmget(FISH_SYSTEM_DATE_RECHARGE_TOTAL%(today),('recharge_user_total','recharge_coin_total'))
        today_sys_user_total = convert_util.to_int(today_sys_user_total)
        today_sys_coin_total  = convert_util.to_float(today_sys_coin_total)
        try:
            average_val = round(today_sys_coin_total/today_active,2)
        except:
            average_val = 0.00
        data_list.append({
            'today'         :   today,
            'today_reg'     :   today_reg,
            'today_active'  :   today_active,
            'today_sys_user_total' : today_sys_user_total,
            'today_sys_coin_total' : today_sys_coin_total,
            'average_val' :  average_val,
            'money_total' :  string_util.format_credit(total_recharge),
        })
        end_date-=one_day

    return {'data':data_list}
Ejemplo n.º 8
0
def agent_addchild(redis, session):
    "新增下级公会"
    agent_id = request.forms.get("agent_id", '').strip()
    user_id  = request.forms.get("user_id", '').strip()
    target_user_id = int(time.time()) / random.randint(1, 10)
    shareRate = 0 
    defaultRoomCard = 0 
    curTime = datetime.now()
    now_date = curTime.strftime('%Y-%m-%d')

    userTable = "users:%s" % user_id
    adminTable = AGENT_TABLE%(agent_id)
    if not redis.exists(userTable):
        return {'code':-5,'msg':'该用户不存在'}

    if not (redis.exists(adminTable)):
        return {'code':-1, 'msg':'公会不存在'}

    managerUser = redis.smembers("agent:%s:manager:member:set" % agent_id)
    if user_id not in managerUser:
        return {"code": -1, "msg": "你没有权限操作该工会"}
    myRate = 0
    myRate = 0
    parentAg = agent_id
    agent_type,is_trail,parent_unitPrice, parent_id = redis.hmget(AGENT_TABLE%(agent_id),('type','isTrail','unitPrice', "parent_id"))
    parent_id = int(parent_id) if parent_id else 0
    if parent_id != 1:
        return {"code":1, "msg": "你不属于一级工会,不能添加工会"}

    account =  target_user_id
    admimtoIdTalbel = AGENT_ACCOUNT_TO_ID%(account)
    parentSetTable  =  AGENT_CHILD_TABLE%(parentAg)
    # 查看下级代理
    SetTables = redis.smembers(parentSetTable)
    if len(SetTables) > 10:
        return {"code": 1, "msg": "你的下级公会超过了上限"}

    pipe = redis.pipeline()
    unitPrice     = 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("ertyjklzc").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,
            'unitPrice'             :           unitPrice,
            'recharge'              :           recharge,
            'isCreate'              :           '1',
            'create_auth'           :           create_auth,
            'open_auth'             :           open_auth,
            'type'                  :           agentType,
            'defaultRoomCard'       :           defaultRoomCard,
            "super_manager"         :           target_user_id,
    }

    adminTable  =  AGENT_TABLE%(id_no)
    if unitPrice:
        pipe.sadd(AGENT_ROOMCARD_PER_PRICE%(id_no),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,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)
    extendCode = SecretKeys(redis)
    
    intoCode   = SecretKeysInto(redis, id_no)
    
    pipe.hset(EXCHANGE_AGENT_FIND, id_no, extendCode)
    pipe.execute()
    return {"code": 0, "msg": "成功", "extendCode": extendCode, "agent_id": id_no, "exchangeIntoCode": intoCode}
Ejemplo n.º 9
0
def getSystemInfoPage(redis, session):
    """
    获取系统信息页面
    """
    lang = getLang()
    selfUid = session['id']
    curTime = convert_util.to_dateStr(datetime.now())

    fields = ('sys', )
    for field in fields:
        exec('%s=request.GET.get("%s","").strip()' % (field, field))

    home_info = {
        'title': '首页',
        'STATIC_LAYUI_PATH': STATIC_LAYUI_PATH,
        'STATIC_ADMIN_PATH': STATIC_ADMIN_PATH,
        'show_data_url': '/admin/getHomePageData?sys=%s' % (sys),
    }

    if sys == 'HALL':
        # 当日注册人数
        regist_total = convert_util.to_int(
            redis.scard(FORMAT_REG_DATE_TABLE % (curTime)))
        if int(selfUid) == 1:
            member_total = convert_util.to_int(redis.scard(ACCOUNT4WEIXIN_SET))
            login_total = convert_util.to_int(
                redis.get(DAY_ALL_LOGIN_COUNT % (curTime)))
            play_room_total = convert_util.to_int(
                redis.get(DAY_ALL_PLAY_ROOM_CARD % (curTime)))

        else:
            member_total = convert_util.to_int(
                getAgentMemberTotal(redis, session['id']))
            regist_total = 0
            login_total = convert_util.to_int(
                getAgentMemberLogin(redis, session['id'], curTime))
            play_room_total = convert_util.to_int(
                getAgentRoomByDay(redis, session['id'], curTime))

        home_info['member_total'] = member_total
        home_info['login_per_day'] = login_total
        home_info['regist_per_day'] = regist_total
        home_info['play_room_per_day'] = play_room_total
    else:
        member_total = convert_util.to_int(
            redis.scard(ACCOUNT4WEIXIN_SET4FISH))
        regist_total = convert_util.to_int(
            redis.scard(FORMAT_REG_DATE_TABLE4FISH % (curTime)))
        login_total = convert_util.to_int(
            redis.scard(FORMAT_LOGIN_DATE_TABLE4FISH % (curTime)))
        recharge_total = convert_util.to_int(
            redis.hget(FISH_SYSTEM_DATE_RECHARGE_TOTAL % (curTime),
                       'recharge_coin_total'))
        home_info['member_total'] = member_total
        home_info['regist_per_day'] = regist_total
        home_info['login_per_day'] = login_total
        home_info['recharge_total'] = recharge_total

    return template('admin_home',
                    info=home_info,
                    lang=lang,
                    session=session,
                    sys=sys,
                    RES_VERSION=RES_VERSION)
Ejemplo n.º 10
0
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')
Ejemplo n.º 11
0
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')