Beispiel #1
0
def handleHttp(dictParam: dict):
    #每月VIP活动
    objResp = cResp()
    strAccountId = dictParam.get('accountId', '')
    strToken = dictParam.get('token', '')

    certifytoken.certify_token(strAccountId, strToken)
    objPlayerData = yield from classDataBaseMgr.getInstance().getPlayerData(
        strAccountId)
    objActiveData = yield from classDataBaseMgr.getInstance().getActiveData(
        strAccountId)
    if objPlayerData is None:
        raise exceptionLogic(errorLogic.player_data_not_found)
    if objActiveData is None:
        raise exceptionLogic(errorLogic.active_not_find)
    #判断活动是否完成
    objActiveItme = objActiveData.dictActiveItem.get(2001)
    if objActiveItme is None:
        raise exceptionLogic(errorLogic.active_not_find)
    if objActiveItme.iActiveState == 1:
        raise exceptionLogic(errorLogic.active_have_already_get)

    #升级需要的流水
    upWater = vipConfig.vip_config[objPlayerData.iLevel].get(
        'upGradeValidWater')
    #保级需要的流水
    keepWater = vipConfig.vip_config[objPlayerData.iLevel].get(
        'keepValidWater')
    #这个月24小时内充值存款
    payMonthly, orderTime = yield from classSqlBaseMgr.getInstance(
    ).getAccountFirstPayByDay(strAccountId)
    # 获取当月有效流水自己平台
    validWater = yield from classSqlBaseMgr.getInstance().getValidWaterMonthly(
        strAccountId)
    #获取平博当月有效流水
    pingboValidWater = yield from classSqlBaseMgr.getInstance(
    ).getAccountPinboHistoryValidWater(timeHelp.monthStartTimestamp(),
                                       timeHelp.nextMonthStartTimestamp(),
                                       strAccountId)
    pingboValidWater = 0 if pingboValidWater.get(
        'validWaterCoin') is None else pingboValidWater.get('validWaterCoin')
    data = cData()
    data.accountId = strAccountId
    #升级还需要的流水
    data.upLevelWater = "%.2f" % round(
        (upWater - objPlayerData.iLevelValidWater) / 100, 2)
    data.keepLevelWater = "%.2f" % round(
        (keepWater - (validWater + pingboValidWater)) / 100, 2)
    data.level = objPlayerData.iLevel
    data.rebate = vipConfig.vip_config[objPlayerData.iLevel].get('rebate')
    data.recharge = "%.2f" % round(payMonthly / 100, 2)
    data.activeTime = objActiveData.dictActiveItem.get(2001).iActiveTime
    data.validWater = "%.2f" % round((pingboValidWater + validWater) / 100, 2)
    data.activeId = 2001
    objResp.data = data
    return classJsonDump.dumps(objResp)
Beispiel #2
0
def calcMonthVip():
    strLastCheckTime = yield from classDataBaseMgr.getInstance().getCalcDayWaterTime()
    if strLastCheckTime is None:
        yield from classDataBaseMgr.getInstance().setCalcMonthWaterTime(timeHelp.getNow())

    iLastCheckTime = int(strLastCheckTime)

    if not timeHelp.isSameMonth(iLastCheckTime, timeHelp.getNow()):
        # 计算月流水
        yield from classDataBaseMgr.getInstance().setCalcMonthWaterTime(timeHelp.getNow())
        iLastStartTs = timeHelp.lastMonthStartTimestamp()
        iNowStartTs = timeHelp.monthStartTimestamp()

        funFuture = asyncio.ensure_future(runExecuteAll(iLastStartTs, iNowStartTs))
        listAllRet = asyncio.wait_for(funFuture,10)

        for var_ret in listAllRet:
            strAccountId = var_ret["loginId"]
            iValidCoin = var_ret["validWaterCoin"] * 100 #单位换算成分
            #拿用户数据
            if len(strAccountId) <= 0 or strAccountId is None:
                logging.error("account data not find")
                continue

            if int(iValidCoin) <= 0:
                logging.error("account [{}] validCoin [{}] not find".format(strAccountId,iValidCoin))
                continue

            objPlayerData, objPlayLock = yield from classDataBaseMgr.getInstance().getPlayerDataByLock(strAccountId)
            if objPlayerData is None:
                logging.error("account [{}] data not find")
                continue

            dictVipCfg = vip_config.get(objPlayerData.iLevel,None)
            if dictVipCfg is None:
                logging.error("accountId[{}] vipLevel[{}] cfg is not valid".format(objPlayerData.strAccountId,objPlayerData.iLevel))
                continue
                yield from classDataBaseMgr.getInstance().releasePlayerDataLock(objPlayerData.strAccountId)

            iVipLimit = dictVipCfg["keepValidWater"]
            if iValidCoin < iVipLimit:
                #降级
                if objPlayerData.iVip > 0:
                    objPlayerData.iVip -= 1
                    #TODO 自动发公告内容
                    yield from classDataBaseMgr.getInstance().setPlayerDataByLock(objPlayerData, objPlayLock)
                else:
                    #TODO bill
                    pass
            else:
                #TODO bill
                pass
Beispiel #3
0
def getVipPayRebate( strAccountId ,objActiveData, objActiveTypeItem):
    objData = cData()

    objActiveItem = objActiveData.getItemByTypeId(enumActiveType.activeVipPayRebate)
    objPlayerData = yield from classDataBaseMgr.getInstance().getPlayerData(strAccountId)
    if objPlayerData is None:
        raise exceptionLogic(errorLogic.player_data_not_found)

    objData.iCurrentVipLevel = objPlayerData.iLevel
    #跟进vip 等级 计算  iActiveId
    objData.iActiveId = getVipActiveId(objPlayerData.iLevel)

    if objActiveItem is None:
        # 还没有此类型的领取活动
        objData.iCurrentPayCoin = objActiveTypeItem.dictParam.get("activePayCoin",0)
        objData.iActiveStatus = enumActiveState.stateGet
        # 如果activepaytime 还没有 lefttime = 0
        iLeftTime = (24 * 3600 - (timeHelp.getNow() - objActiveTypeItem.dictParam.get("activePayTime",0)))
        if iLeftTime < 0:
            iLeftTime = 0
        objData.iLeftSeconds = iLeftTime

    else:

        #活动开始到现在有效流水
        validWater = yield from classSqlBaseMgr.getInstance().getValidWaterByTimeRange(objActiveItem.iActiveTime,
                                                                                       timeHelp.getNow(),
                                                                                       strAccountId)

        pingboValidWater = yield from classSqlBaseMgr.getInstance().getAccountPinboHistoryValidWater(
            objActiveItem.iActiveTime, timeHelp.getNow(), strAccountId)

        objData.iCurrentValidWater = validWater + pingboValidWater

        #当月的流水
        iLastStartTs = timeHelp.lastMonthStartTimestamp()
        iNowStartTs = timeHelp.monthStartTimestamp()
        pinboMonthValidWater = yield from classSqlBaseMgr.getInstance().getOnePinboHistoryValidWater(strAccountId, iLastStartTs, iNowStartTs)
        monthValidWater = yield from classSqlBaseMgr.getInstance().getValidWaterMonthly(strAccountId)
        objData.iCurrentMonthValidWater = pinboMonthValidWater + monthValidWater
        objData.iActiveStatus = enumActiveState.stateAward


    return objData
Beispiel #4
0
def handleHttp(request: dict):
    """财务报表-平台费"""
    objRep = cResp()

    agentId = request.get('agentId', '')
    startTime = int(request.get('startTime', 0))
    endTime = int(request.get('endTime', 0))

    if not all([startTime, endTime]):
        startTime = timeHelp.monthStartTimestamp()
        endTime = timeHelp.getNow()
    agentConfig = yield from getAgentConfig()
    pinboAllWinLoss = yield from classSqlBaseMgr.getInstance().getAccountPingboAllWinLoss(agentId, startTime, endTime)
    probetAllWinLoss = yield from classSqlBaseMgr.getInstance().getAccountProbetAllWinCoin(agentId, startTime, endTime)
    probetWinLoss = round(probetAllWinLoss)
    pinboWinLoss = round(pinboAllWinLoss * 100)
    # 平台费
    if pinboWinLoss >= 0:
        pingboPlatformCost = 0
    else:
        pingboPlatformCost = round(-pinboWinLoss * agentConfig['平博体育'])
    if probetWinLoss >= 0:
        probetPlatformCost = 0
    else:
        probetPlatformCost = round(-probetWinLoss * agentConfig['电竞竞猜'])

    pinboSurvey = {}
    probetSurvey = {}

    pinboSurvey['project'] = '平博体育'
    pinboSurvey['winLoss'] = '%.2f'%(-pinboAllWinLoss)
    pinboSurvey['rate'] = '{}%'.format(agentConfig['平博体育']*100)
    pinboSurvey['platformCost'] = '%.2f' % round(pingboPlatformCost/ 100,2)

    probetSurvey['project'] = '电竞竞猜'
    probetSurvey['winLoss'] = '%.2f'%round(-probetAllWinLoss/100,2)
    probetSurvey['rate'] = '{}%'.format(agentConfig['电竞竞猜']*100)
    probetSurvey['platformCost'] = '%.2f' % round(probetPlatformCost/100,2)

    objRep.data.append(pinboSurvey)
    objRep.data.append(probetSurvey)
    return classJsonDump.dumps(objRep)
Beispiel #5
0
def handleHttp(request: dict):
    """财务报表"""
    objRep = cResp()

    agentId = request.get('agentId', '')
    startTime = request.get('startTime', 0)
    endTime = request.get('endTime', 0)

    if not all([startTime, endTime]):
        startTime = timeHelp.monthStartTimestamp()
        endTime = timeHelp.getNow()
    try:
        agentConfig = yield from getAgentConfig()
        if not agentConfig:
            raise exceptionLogic(errorLogic.data_not_valid)
        # allAccountNum = yield from classSqlBaseMgr.getInstance().getAccountCountByAgent(agentId)
        # activelyAccountNum = yield from classSqlBaseMgr.getInstance().getActivelyAccount(agentId, startTime, endTime)
        depositNum = yield from classSqlBaseMgr.getInstance(
        ).getAccountAllDeposit(agentId, startTime, endTime)
        drawingNum = yield from classSqlBaseMgr.getInstance(
        ).getAccountAllDrawing(agentId, startTime, endTime)
        # balanceNum = yield from classSqlBaseMgr.getInstance().getAccountAllCoin(agentId, startTime, endTime)
        pingboBackWater = yield from classSqlBaseMgr.getInstance(
        ).getAccountPinboBackWater(agentId, startTime, endTime)
        probetBackWater = yield from classSqlBaseMgr.getInstance(
        ).getAccountProbetBackWater(agentId, startTime, endTime)
        activetyBonus = yield from classSqlBaseMgr.getInstance(
        ).getAccountActivetyBonus(agentId, startTime, endTime)
        pinboAllWinLoss = yield from classSqlBaseMgr.getInstance(
        ).getAccountPingboAllWinLoss(agentId, startTime, endTime)
        probetAllWinLoss = yield from classSqlBaseMgr.getInstance(
        ).getAccountProbetAllWinCoin(agentId, startTime, endTime)
        probetWinLoss = round(probetAllWinLoss)
        pinboWinLoss = round(pinboAllWinLoss * 100)
        # 平台费
        if pinboWinLoss >= 0:
            pingboPlatformCost = 0
        else:
            pingboPlatformCost = round(-pinboWinLoss * agentConfig['平博体育'])
        if probetWinLoss >= 0:
            probetPlatformCost = 0
        else:
            probetPlatformCost = round(-probetWinLoss * agentConfig['电竞竞猜'])
        platformCost = probetPlatformCost + pingboPlatformCost

        agentSurvey = {}
        allWinLoss = probetWinLoss + pinboWinLoss
        dividend = round(pingboBackWater + probetBackWater + activetyBonus)
        depositDrawingPoundage = yield from getDepositDrawingPoundage(
            agentId, startTime, endTime)
        netWin = allWinLoss + platformCost + dividend + depositDrawingPoundage

        # agentSurvey['allAccountNum'] = allAccountNum
        # agentSurvey['activelyAccountNum'] = activelyAccountNum
        agentSurvey['depositNum'] = '%.2f' % round(depositNum / 100, 2)
        agentSurvey['drawingNum'] = '%.2f' % round(drawingNum / 100, 2)
        agentSurvey['allWinLoss'] = '%.2f' % round(-allWinLoss / 100, 2)
        agentSurvey['netWin'] = '%.2f' % round(-netWin / 100, 2)
        agentSurvey['platformCost'] = '%.2f' % round(platformCost / 100, 2)
        agentSurvey['dividend'] = '%.2f' % (dividend / 100)
        agentSurvey['poundage'] = '%.2f' % (depositDrawingPoundage / 100)

        objRep.data.append(agentSurvey)
        return classJsonDump.dumps(objRep)

    except Exception as e:
        logging.exception(e)
Beispiel #6
0
def handleHttp(request: dict):
    """财务报表-存提手续费"""
    objRep = cResp()

    agentId = request.get('agentId', '')
    startTime = request.get('startTime', 0)
    endTime = request.get('endTime', 0)

    if not all([startTime, endTime]):
        startTime = timeHelp.monthStartTimestamp()
        endTime = timeHelp.getNow()
    agentConfig = yield from getAgentConfig()

    BankTransferDeposit = yield from classSqlBaseMgr.getInstance(
    ).getBankTransfer(agentId, startTime, endTime)
    UnionpayDeposit = yield from classSqlBaseMgr.getInstance().getUnionpay(
        agentId, startTime, endTime)
    QQpayDeposit = yield from classSqlBaseMgr.getInstance().getQQpay(
        agentId, startTime, endTime)
    AlipayDeposit = yield from classSqlBaseMgr.getInstance().getAlipay(
        agentId, startTime, endTime)
    AlipayTransferDeposit = yield from classSqlBaseMgr.getInstance(
    ).getAlipayTransfer(agentId, startTime, endTime)
    # WeixinDeposit = yield from classSqlBaseMgr.getInstance().getWeixinPay(agentId, startTime, endTime)
    WeixinTransferDeposit = yield from classSqlBaseMgr.getInstance(
    ).getWeixinTransfer(agentId, startTime, endTime)
    drawingNum = yield from classSqlBaseMgr.getInstance().getAccountAllDrawing(
        agentId, startTime, endTime)
    BankTransfer = {}
    Unionpay = {}
    QQpay = {}
    Alipay = {}
    AlipayTransfer = {}
    Weixinpay = {}
    WeixinTransfer = {}
    drawing = {}

    drawingAllNum = '%.2f' % round(drawingNum / 100, 2)
    BankTransferAllDeposit = '%.2f' % round(BankTransferDeposit / 100, 2)
    UnionpayAllDeposit = '%.2f' % round(UnionpayDeposit / 100, 2)
    QQpayAllDeposit = '%.2f' % round(QQpayDeposit / 100, 2)
    AlipayAllDeposit = '%.2f' % round(AlipayDeposit / 100, 2)
    AlipayTransferAllDeposit = '%.2f' % round(AlipayTransferDeposit / 100, 2)
    # WeixinAllDeposit = '%.2f' % round(WeixinDeposit / 100, 2)
    WeixinTransferAllDeposit = '%.2f' % round(WeixinTransferDeposit / 100, 2)

    drawingPoundage = '%.2f' % (round(drawingNum) * agentConfig['提款'] / 100)
    BankTransferPoundage = '%.2f' % (round(BankTransferDeposit) *
                                     agentConfig['银行卡转账'] / 100)
    UnionpayPoundage = '%.2f' % (round(UnionpayDeposit) * agentConfig['银联扫码'] /
                                 100)
    QQpayPoundage = '%.2f' % (round(QQpayDeposit) * agentConfig['QQ扫码'] / 100)
    AlipayPoundage = '%.2f' % (round(AlipayDeposit) * agentConfig['支付宝扫码'] /
                               100)
    AlipayTransferPoundage = '%.2f' % (round(AlipayTransferDeposit) *
                                       agentConfig['支付宝转账'] / 100)
    # WeixinPoundage = '%.2f' % (round(WeixinDeposit) * agentConfig['微信扫码']/ 100)
    WeixinTransferPoundage = '%.2f' % (round(WeixinTransferDeposit) *
                                       agentConfig['微信转账'] / 100)

    drawing['type'] = '提款'
    drawing['coin'] = drawingAllNum
    drawing['rate'] = '{}%'.format(agentConfig['提款'] * 100)
    drawing['poundage'] = drawingPoundage

    BankTransfer['type'] = '银行卡转账'
    BankTransfer['coin'] = BankTransferAllDeposit
    BankTransfer['rate'] = '{}%'.format(agentConfig['银行卡转账'] * 100)
    BankTransfer['poundage'] = BankTransferPoundage

    Unionpay['type'] = '银联扫码'
    Unionpay['coin'] = UnionpayAllDeposit
    Unionpay['rate'] = '{}%'.format(agentConfig['银联扫码'] * 100)
    Unionpay['poundage'] = QQpayPoundage

    QQpay['type'] = 'qq支付'
    QQpay['coin'] = QQpayAllDeposit
    QQpay['rate'] = '{}%'.format(agentConfig['QQ扫码'] * 100)
    QQpay['poundage'] = UnionpayPoundage

    Alipay['type'] = '支付宝扫码'
    Alipay['coin'] = AlipayAllDeposit
    Alipay['rate'] = '{}%'.format(agentConfig['支付宝扫码'] * 100)
    Alipay['poundage'] = AlipayPoundage

    AlipayTransfer['type'] = '支付宝转账'
    AlipayTransfer['coin'] = AlipayTransferAllDeposit
    AlipayTransfer['rate'] = '{}%'.format(agentConfig['支付宝转账'] * 100)
    AlipayTransfer['poundage'] = AlipayTransferPoundage

    # Weixinpay['type'] = '微信扫码'
    # Weixinpay['coin'] = WeixinAllDeposit
    # Weixinpay['rate'] = '{}%'.format(agentConfig['微信扫码'] * 100)
    # Weixinpay['poundage'] = WeixinPoundage

    WeixinTransfer['type'] = '微信转账'
    WeixinTransfer['coin'] = WeixinTransferAllDeposit
    WeixinTransfer['rate'] = '{}%'.format(agentConfig['微信转账'] * 100)
    WeixinTransfer['poundage'] = WeixinTransferPoundage

    objRep.data.append(BankTransfer)
    objRep.data.append(Unionpay)
    objRep.data.append(QQpay)
    objRep.data.append(Alipay)
    objRep.data.append(AlipayTransfer)
    # objRep.data.append(Weixinpay)
    objRep.data.append(WeixinTransfer)
    objRep.data.append(drawing)
    return classJsonDump.dumps(objRep)
def handleHttp(request: dict):
    """存提"""
    objRep = cResp()

    agentId = request.get('agentId', '')
    accountId = request.get('accountId', '')
    startTime = request.get('startTime', 0)
    endTime = request.get('endTime', 0)
    pn = request.get('pn', 1)

    if not pn:
        raise exceptionLogic(errorLogic.client_param_invalid)

    if not all([startTime, endTime]):
        startTime = timeHelp.monthStartTimestamp()
        endTime = timeHelp.getNow()
    try:
        agentConfig = yield from getAgentConfig()
        with (yield from classSqlBaseMgr.getInstance().objDbMysqlMgr) as conn:
            if accountId:
                sql_count = "select count(orderId) from dj_coin_history where accountId=%s and (tradeType=1 or tradeType=2) and tradeState=1 and orderTime between %s and %s"
                sql = "select orderId,orderTime,coinNum,balance,tradeType,tradeState,transFrom,accountId from dj_coin_history where accountId=%s and (tradeType=1 or tradeType=2) and tradeState=1 and orderTime between %s and %s order by orderTime desc limit %s offset %s"
                sql_count_params = [accountId, startTime, endTime]
                sql_params = [accountId, startTime, endTime, 10, (pn - 1) * 10]
            else:
                userIds = yield from classSqlBaseMgr.getInstance(
                ).getAccountByAgent(agentId)
                if len(userIds) == 0:
                    return classJsonDump.dumps(objRep)
                sql_count = "select count(orderId) from dj_coin_history where accountId in (%s) and (tradeType=1 or tradeType=2) and tradeState=1 " % ",".join(
                    ["%s"] * len(userIds))
                sql_count = sql_count + " and orderTime between %s and %s"
                params = userIds + [startTime, endTime]
                sql_count_params = params
                sql = "select orderId,orderTime,coinNum,balance,tradeType,tradeState,transFrom,accountId from dj_coin_history where accountId in (%s) and (tradeType=1 or tradeType=2) and tradeState=1 " % ",".join(
                    ["%s"] * len(userIds))
                sql = sql + " and orderTime between %s and %s order by orderTime desc limit %s offset %s"
                sql_params = params + [10, (pn - 1) * 10]
            ret = yield from conn.execute(sql_count, sql_count_params)
            result = yield from conn.execute(sql, sql_params)
            if ret.rowcount <= 0:
                return classJsonDump.dumps(objRep)
            else:
                for var in ret:
                    count = var[0]
                desipotDrawingList = []
                for var_row in result:
                    desipotDrawingDict = {}
                    rate = var_row.transFrom
                    desipotDrawingDict['orderId'] = var_row.orderId
                    desipotDrawingDict['orderTime'] = var_row.orderTime
                    desipotDrawingDict['coinNum'] = "%.2f" % round(
                        var_row.coinNum / 100, 2)
                    desipotDrawingDict['tradeType'] = var_row.tradeType
                    desipotDrawingDict['accountId'] = var_row.accountId
                    desipotDrawingDict['balance'] = "%.2f" % round(
                        var_row.balance / 100, 2)
                    if rate in RATE_LIST:
                        desipotDrawingDict['cost'] = "%.2f" % round(
                            (var_row.coinNum * agentConfig[rate]) / 100, 2)
                        desipotDrawingDict['transFrom'] = var_row.transFrom
                    else:
                        desipotDrawingDict['cost'] = "%.2f" % round(
                            (var_row.coinNum * agentConfig['提款']) / 100, 2)
                        desipotDrawingDict['transFrom'] = '提款成功'
                    desipotDrawingList.append(desipotDrawingDict)
            objRep.data = desipotDrawingList
            objRep.count = count
            return classJsonDump.dumps(objRep)
    except Exception as e:
        logging.exception(e)
Beispiel #8
0
def handleHttp(request: dict):
    """代理每月下线用户信息,用于代理后台首页展示"""
    objRep = cResp()

    agentId = request.get('agentId', '')
    pn = request.get('pn', 1)

    if not pn:
        raise exceptionLogic(errorLogic.client_param_invalid)

    start_time = timeHelp.monthStartTimestamp()
    startTime = timeHelp.getNow() - 30 * 86400
    endTime = timeHelp.getNow()

    agentConfig = yield from getAgentConfig()
    allAccountNum = yield from classSqlBaseMgr.getInstance(
    ).getAccountCountByAgent(agentId)
    newAccountNum = yield from classSqlBaseMgr.getInstance(
    ).getNewAccountCount(agentId, start_time, endTime)
    activelyAccountNum = yield from classSqlBaseMgr.getInstance(
    ).getActivelyAccount(agentId, startTime, endTime)
    pinboAllWinLoss = yield from classSqlBaseMgr.getInstance(
    ).getAccountPingboAllWinLoss(agentId, start_time, endTime)
    probetAllWinLoss = yield from classSqlBaseMgr.getInstance(
    ).getAccountProbetAllWinCoin(agentId, start_time, endTime)
    probetWinLoss = round(probetAllWinLoss)
    pinboWinLoss = round(pinboAllWinLoss * 100)
    # 平台费
    if pinboWinLoss >= 0:
        pingboPlatformCost = 0
    else:
        pingboPlatformCost = round(-pinboWinLoss * agentConfig['平博体育'])
    if probetWinLoss >= 0:
        probetPlatformCost = 0
    else:
        probetPlatformCost = round(-probetWinLoss * agentConfig['电竞竞猜'])
    pingboBackWater = yield from classSqlBaseMgr.getInstance(
    ).getAccountPinboBackWater(agentId, start_time, endTime)
    probetBackWater = yield from classSqlBaseMgr.getInstance(
    ).getAccountProbetBackWater(agentId, start_time, endTime)
    activetyBonus = yield from classSqlBaseMgr.getInstance(
    ).getAccountActivetyBonus(agentId, start_time, endTime)

    # 反水
    backWater = round(pingboBackWater + probetBackWater)
    # 返奖
    activetyBonus = round(activetyBonus)
    # 存提手续费
    depositDrawingPoundage = yield from getDepositDrawingPoundage(
        agentId, start_time, endTime)

    # 净利润,净输赢
    netProfit = probetWinLoss + pingboPlatformCost + pinboWinLoss + probetPlatformCost + depositDrawingPoundage + activetyBonus + backWater
    if netProfit <= 0:
        netProfit = -netProfit
        for var_value in commission_config.values():
            if var_value['leastNetWin'] <= netProfit <= var_value['mostNetWin']:
                level = var_value['level']
                proportion = agentConfig[level]
    else:
        proportion = agentConfig['一档']

    objRep.data = cData()
    objRep.data.proportion = '{}%'.format(proportion * 100)
    objRep.data.allAccount = allAccountNum
    objRep.data.newAccount = newAccountNum
    objRep.data.activelyAccount = activelyAccountNum
    objRep.data.netProfit = '%.2f' % round(-netProfit / 100, 2)
    objRep.data.appProportion = proportion
    return classJsonDump.dumps(objRep)
Beispiel #9
0
def handleHttp(request: dict):
    """财务报表-总输赢"""
    objRep = cResp()

    agentId = request.get('agentId', '')
    startTime = request.get('startTime', 0)
    endTime = request.get('endTime', 0)

    if not all([startTime, endTime]):
        startTime = timeHelp.monthStartTimestamp()
        endTime = timeHelp.getNow()
    agentConfig = yield from getAgentConfig()
    #输赢
    pinboAllWinLoss = yield from classSqlBaseMgr.getInstance(
    ).getAccountPingboAllWinLoss(agentId, startTime, endTime)
    probetAllWinLoss = yield from classSqlBaseMgr.getInstance(
    ).getAccountProbetAllWinCoin(agentId, startTime, endTime)
    #流水
    pinboAllWater = yield from classSqlBaseMgr.getInstance(
    ).getAccountPingboWater(agentId, startTime, endTime)
    probetAllWater = yield from classSqlBaseMgr.getInstance(
    ).getAccountProbetWater(agentId, startTime, endTime)
    #反水红利
    pingboBackWater = yield from classSqlBaseMgr.getInstance(
    ).getAccountPinboBackWater(agentId, startTime, endTime)
    probetBackWater = yield from classSqlBaseMgr.getInstance(
    ).getAccountProbetBackWater(agentId, startTime, endTime)
    activetyBonus = yield from classSqlBaseMgr.getInstance(
    ).getAccountActivetyBonus(agentId, startTime, endTime)

    probetWinLoss = round(probetAllWinLoss)
    pinboWinLoss = round(pinboAllWinLoss * 100)
    # 平台费
    if pinboWinLoss >= 0:
        pingboPlatformCost = 0
    else:
        pingboPlatformCost = round(-pinboWinLoss * agentConfig['平博体育'])
    if probetWinLoss >= 0:
        probetPlatformCost = 0
    else:
        probetPlatformCost = round(-probetWinLoss * agentConfig['电竞竞猜'])
    pinboSurvey = {}
    probetSurvey = {}
    # 反水
    backWater = round(pingboBackWater + probetBackWater)
    # 返奖
    activetyBonus = round(activetyBonus)
    # 存提手续费
    depositDrawingPoundage = yield from getDepositDrawingPoundage(
        agentId, startTime, endTime)
    # 净利润,净输赢
    netProfit = probetWinLoss - pingboPlatformCost + pinboWinLoss - probetPlatformCost + depositDrawingPoundage + backWater + activetyBonus
    if netProfit <= 0:
        netProfit = -netProfit
        for var_value in commission_config.values():
            if var_value['leastNetWin'] <= netProfit <= var_value['mostNetWin']:
                level = var_value['level']
                proportion = agentConfig[level]
    else:
        proportion = agentConfig['一档']

    # 平台净输赢
    pingboNetWinLoss = pinboWinLoss + pingboPlatformCost + round(
        pingboBackWater)
    probetNetWinLoss = probetWinLoss + probetPlatformCost + round(
        probetBackWater + activetyBonus)
    if pingboNetWinLoss >= 0:
        pingboCommission = 0
    else:
        pingboCommission = -pingboNetWinLoss * proportion
    if probetNetWinLoss >= 0:
        probetCommission = 0
    else:
        probetCommission = -probetNetWinLoss * proportion

    pinboSurvey['project'] = '平博体育'
    pinboSurvey['winLoss'] = '%.2f' % (-pinboAllWinLoss)
    pinboSurvey['rate'] = '{}%'.format(agentConfig['平博体育'] * 100)
    pinboSurvey['platformCost'] = '%.2f' % round(pingboPlatformCost / 100, 2)
    pinboSurvey['waterCoin'] = '%.2f' % pinboAllWater
    pinboSurvey['backWater'] = '%.2f' % round(pingboBackWater / 100, 2)
    pinboSurvey['commission'] = '%.2f' % round(pingboCommission / 100, 2)

    probetSurvey['project'] = '电竞竞猜'
    probetSurvey['winLoss'] = '%.2f' % round(-probetAllWinLoss / 100, 2)
    probetSurvey['rate'] = '{}%'.format(agentConfig['电竞竞猜'] * 100)
    probetSurvey['platformCost'] = '%.2f' % round(probetPlatformCost / 100, 2)
    probetSurvey['waterCoin'] = '%.2f' % round(probetAllWater / 100, 2)
    probetSurvey['backWater'] = '%.2f' % round(probetBackWater / 100, 2)
    probetSurvey['commission'] = '%.2f' % round(probetCommission / 100, 2)

    objRep.data.append(pinboSurvey)
    objRep.data.append(probetSurvey)
    objRep.water = '%.2f' % round(
        (int(pinboAllWater * 100) + probetAllWater) / 100, 2)
    objRep.allWinLoss = '%.2f' % (-(pinboWinLoss + probetWinLoss) / 100)
    objRep.allBackWater = '%.2f' % round(
        (pingboBackWater + probetBackWater) / 100, 2)
    return classJsonDump.dumps(objRep)
Beispiel #10
0
def handleHttp(request: dict):
    """用户信息"""
    objRep = cResp()

    agentId = request.get('agentId', '')
    accountId = request.get('accountId', '')
    startTime = request.get('startTime', 0)
    endTime = request.get('endTime', 0)
    pn = request.get('pn', 1)

    if not pn:
        raise exceptionLogic(errorLogic.client_param_invalid)

    if not all([startTime, endTime]):
        startTime = timeHelp.monthStartTimestamp()
        endTime = timeHelp.getNow()
    if accountId:
        sql_count = "select count(accountId) from dj_account where agentId=%s and accountId=%s and loginTime between %s and %s"
        sql = "select accountId,regTime,loginTime from dj_account where agentId=%s and accountId=%s and loginTime between %s and %s "
        sql_count_params = [agentId, accountId, startTime, endTime]
        sql_params = [agentId, accountId, startTime, endTime]
    else:
        sql_count = "select count(accountId) from dj_account where agentId=%s and loginTime between %s and %s "
        sql = "select accountId,regTime,loginTime from dj_account where agentId=%s and loginTime between %s and %s order by loginTime desc limit %s offset %s"
        sql_count_params = [agentId, startTime, endTime]
        sql_params = [agentId, startTime, endTime, 10, (pn - 1) * 10]
    try:
        with (yield from classSqlBaseMgr.getInstance().objDbMysqlMgr) as conn:
            ret = yield from conn.execute(sql_count, sql_count_params)
            result = yield from conn.execute(sql, sql_params)
            if ret.rowcount <= 0:
                return classJsonDump.dumps(objRep)
            else:
                for var in ret:
                    count = var[0]
                accountDataList = []
                for var_row in result:
                    accountDataDict = {}
                    accountId = var_row.accountId
                    regTime = var_row.regTime
                    loginTime = var_row.loginTime
                    balance = yield from classSqlBaseMgr.getInstance(
                    ).getAccountAllBalance(accountId)
                    deposit = yield from classSqlBaseMgr.getInstance(
                    ).getAccountDeposit(accountId, startTime, endTime)
                    drawing = yield from classSqlBaseMgr.getInstance(
                    ).getAccountDrawing(accountId, startTime, endTime)

                    pinboAllWinLoss = yield from classSqlBaseMgr.getInstance(
                    ).getAccountPingboWinLoss(accountId, startTime, endTime)
                    probetAllWinLoss = yield from classSqlBaseMgr.getInstance(
                    ).getAccountProbetWinCoin(accountId, startTime, endTime)
                    pingboWinLoss = round(pinboAllWinLoss * 100)

                    accountDataDict['accountId'] = accountId
                    accountDataDict['regTime'] = regTime
                    accountDataDict['loginTime'] = loginTime
                    accountDataDict['balance'] = "%.2f" % round(
                        balance / 100, 2)
                    accountDataDict['deposit'] = "%.2f" % round(
                        deposit / 100, 2)
                    accountDataDict['drawing'] = "%.2f" % round(
                        drawing / 100, 2)
                    accountDataDict['lossWin'] = "%.2f" % round(
                        (pingboWinLoss + probetAllWinLoss) / 100, 2)
                    accountDataList.append(accountDataDict)
            objRep.data = accountDataList
            objRep.count = count
            return classJsonDump.dumps(objRep)
    except Exception as e:
        logging.exception(e)
Beispiel #11
0
def handleHttp(request: dict):
    """获取实时数据"""
    days=request.get('days',0)
    startTime = getTimeOClockOfToday()
    endTime = getNow()

    objRep = cResp()

    if not checkIsInt(days):
        logging.debug(errorLogic.client_param_invalid)
        raise exceptionLogic(errorLogic.client_param_invalid)
    if days not in [0,3,5,7,30]:
        logging.debug(errorLogic.client_param_invalid)
        raise exceptionLogic(errorLogic.client_param_invalid)

    if days:
        if days==30:
            startTime=monthStartTimestamp()
        else:
            startTime=startTime-days*24*3600
    #运营实时数据sql
    reg_count_sql="select count(id) from dj_regbill"
    today_login_sql="select count(DISTINCT(accountId)) from dj_loginbill WHERE loginTime BETWEEN {} AND {}".format(startTime,endTime)
    today_new_sql="select count(id) from dj_regbill where regTime BETWEEN {} AND {}".format(startTime,endTime)
    recharge_sql="select count(DISTINCT(accountId)) from dj_paybill"
    today_recharge_sql="select count(DISTINCT(accountId)) from dj_paybill WHERE payTime BETWEEN {} AND {}".format(startTime,endTime)
    today_pro_water_award_sql="select sum(betCoinNum),sum(winCoin) from dj_betresultbill WHERE resultTime BETWEEN {} AND {}".format(startTime,endTime)
    today_pin_water_award_sql="select sum(toRisk),sum(CASE WHEN winLoss>0 THEN winLoss ELSE 0 END) from dj_pingbobetbill WHERE wagerDateFm BETWEEN {} AND {} AND status='SETTLED'".format(startTime,endTime)
    pro_valid_water_sql="select sum(betCoinNum) from dj_betresultbill WHERE resultTime BETWEEN {} AND {} AND rate>=1.5".format(startTime,endTime)
    withdrawal_sql="select sum(withdrawalCoin) from dj_withdrawalbill WHERE withdrawalTime BETWEEN {} AND {}".format(startTime,endTime)
    total_recharge_sql="select sum(payCoin) from dj_paybill WHERE payTime BETWEEN {} AND {} ".format(startTime,endTime)
    new_recharge_sql="select DISTINCT(accountId) from dj_paybill WHERE accountId not IN (SELECT accountId from dj_paybill WHERE payTime<{}) AND payTime BETWEEN {} AND {}".format(startTime,startTime,endTime)
    new_recharge_coin_sql="select sum(payCoin) from dj_paybill WHERE accountId IN ("+new_recharge_sql+") and payTime between {} and {} ".format(startTime,endTime)

    #代理实时数据sql
    agent_count_sql="select count(agentId) from dj_agent"
    agent_new_sql="select count(agentId) from dj_agent WHERE regTime BETWEEN {} AND {}".format(startTime,endTime)
    today_new_offline_sql="select count(accountId) from dj_regbill WHERE agentId!='' AND regTime BETWEEN {} AND {}".format(startTime,endTime)
    #线下总输赢
    vip_win_loss_sql="select sum(betCoinNum),sum(winCoin) from dj_betresultbill WHERE agentId!='' AND resultTime BETWEEN {} AND {}".format(startTime,endTime)
    agent_bet_award_sql="select sum(betCoinNum),sum(winCoin) from dj_betresultbill WHERE agentId!='' AND resultTime BETWEEN {} AND {}".format(startTime,endTime)
    agent_withdrawal_sql="select sum(withdrawalCoin) from dj_withdrawalbill WHERE userType=2 AND withdrawalTime BETWEEN {} AND {}".format(startTime,endTime)


    try:
        operation_data=cData1()
        agent_data=cData2()
        with (yield from classSqlBaseMgr.getInstance(instanceName='probet_oss').objDbMysqlMgr) as conn:
            #注册总数
            reg_count=yield from conn.execute(reg_count_sql)
            reg_total_count=yield from reg_count.fetchone()
            operation_data.totalReg=reg_total_count[0]
            #今日登录数
            today_login=yield from conn.execute(today_login_sql)
            login_count=yield from today_login.fetchone()
            operation_data.todayLogin=login_count[0]
            #今日新增数
            today_reg=yield from conn.execute(today_new_sql)
            new_reg=yield from today_reg.fetchone()
            operation_data.todayNew=new_reg[0]
            #充值总数
            recharge_count=yield from conn.execute(recharge_sql)
            total_recharge=yield from recharge_count.fetchone()
            operation_data.RechargeCount=total_recharge[0]
            #今日充值数
            today_recharge_count=yield from conn.execute(today_recharge_sql)
            today_recharge=yield from today_recharge_count.fetchone()
            operation_data.todayRecharge=today_recharge[0]
            #今日流水:平博今日流水+Probet流水
            today_pro_water_award=yield from conn.execute(today_pro_water_award_sql)
            pro_water_award=yield from today_pro_water_award.fetchone()
            today_pin_water_award=yield from conn.execute(today_pin_water_award_sql)
            pin_water_award=yield from today_pin_water_award.fetchone()
            pin_water=0 if pin_water_award[0] is None else pin_water_award[0]
            pro_water=0 if pro_water_award[0] is None else int(pro_water_award[0])/100
            operation_data.todayWater=round(pin_water+pro_water,2)
            #今日有效流水:平博有效流水+Probet有效流水 欧赔+亚赔
            pinValidWater=yield from getPingboValidWaterByParams(loginIds=None,startTime=startTime,endTime=endTime)

            today_pro_valid_water=yield from conn.execute(pro_valid_water_sql)
            pro_valid_water=yield from today_pro_valid_water.fetchone()
            proValidWater=0 if pro_valid_water[0] is None else int(pro_valid_water[0])/100
            operation_data.todayValidWater=round(pinValidWater+proValidWater,2)
            #今日抽水:总流水*0.15   todo
            operation_data.todayPumping=round(operation_data.todayWater*0.15,2)
            #总充值数
            total_recharge_ret=yield from conn.execute(total_recharge_sql)
            totalRechargeRes=yield from total_recharge_ret.fetchone()
            operation_data.totalRecharge=0 if totalRechargeRes[0] is None else int(totalRechargeRes[0])/100
            #新增充值人数
            new_recharge_ret=yield from conn.execute(new_recharge_sql)
            newRechargeRes=yield from new_recharge_ret.fetchall()
            operation_data.newRecharge=len(newRechargeRes)
            #新增充值人数充值额度
            new_recharge_coin_ret=yield from conn.execute(new_recharge_coin_sql)
            newRechargeCoinRes=yield from new_recharge_coin_ret.fetchone()
            operation_data.newRechargeCoin=0 if newRechargeCoinRes[0] is None else int(newRechargeCoinRes[0])/100
            #今日派奖
            pin_award=0 if pin_water_award[1] is None else pin_water_award[1]
            pro_award=0 if pro_water_award[1] is None else int(pro_water_award[1])/100
            operation_data.todayAward=round(pin_award+pro_award,2)
            #提款
            withdrawal=yield from conn.execute(withdrawal_sql)
            withdrawal_count=yield from withdrawal.fetchone()
            operation_data.withdrawal=0 if withdrawal_count[0] is None else int(withdrawal_count[0])/100
            #盈亏:总投注-总派奖
            operation_data.winLoss=round(operation_data.todayWater-operation_data.todayAward,2)

            #vip总输赢
            vip_win_loss=yield from conn.execute(vip_win_loss_sql)
            vip_total_win=yield from vip_win_loss.fetchone()
            vip_bet_total=0 if vip_total_win[0] is None else int(vip_total_win[0])/100
            vip_win_total=0 if vip_total_win[1] is None else int(vip_total_win[1])/100
            agent_data.vipWinLoss=vip_bet_total-vip_win_total
            #代理提款
            agent_withdrawal=yield from conn.execute(agent_withdrawal_sql)
            agentWithdrawal=yield from agent_withdrawal.fetchone()
            agent_data.withdrawal=0 if agentWithdrawal[0] is None else int(agentWithdrawal[0])/100
            #代理总输赢:总投注-总派奖
            agent_total_win=yield from conn.execute(agent_bet_award_sql)
            ag_total_win=yield from agent_total_win.fetchone()
            ag_bet_total=0 if ag_total_win[0] is None else int(ag_total_win[0])/100
            ag_award_total=0 if ag_total_win[1] is None else int(ag_total_win[1])/100
            agent_data.winLoss=ag_bet_total-ag_award_total
            #今日新增线下
            today_new_offline=yield from conn.execute(today_new_offline_sql)
            new_offline=yield from today_new_offline.fetchone()
            agent_data.vipNew=new_offline[0]

        with(yield from classSqlBaseMgr.getInstance().objDbMysqlMgr) as connect:
            #代理数据1.代理总数
            agent_count=yield from connect.execute(agent_count_sql)
            total_agent=yield from agent_count.fetchone()
            agent_data.agentCount=total_agent[0]
            #新增代理
            new_agent=yield from connect.execute(agent_new_sql)
            new_agents=yield from new_agent.fetchone()
            agent_data.agentNew=new_agents[0]

        objRep.agentData = agent_data
        objRep.operationData = operation_data
        if days==0:
            fileName = __name__
            nameList = fileName.split('.')
            methodName = nameList.pop()
            # 日志
            dictActionBill = {
                'billType': 'adminActionBill',
                'accountId': request.get('accountId', ''),
                'action': "查询实时数据",
                'actionTime': getNow(),
                'actionMethod': methodName,
                'actionDetail': "查询实时数据",
                'actionIp': request.get('srcIp', ''),
            }
            logging.getLogger('bill').info(json.dumps(dictActionBill))
        return classJsonDump.dumps(objRep)
    except Exception as e:
        logging.exception(e)
        raise exceptionLogic(errorLogic.db_error)
Beispiel #12
0
def calcMonthCommission():
    strLastCheckTime = yield from classDataBaseMgr.getInstance().getCalcMonthCommissionTime()
    if strLastCheckTime is None:
        yield from classDataBaseMgr.getInstance().setCalcMonthCommissionTime(timeHelp.getNow())

    iLastCheckTime = int(strLastCheckTime)

    if not timeHelp.isSameMonth(iLastCheckTime, timeHelp.getNow()):
        # 计算月佣金
        yield from classDataBaseMgr.getInstance().setCalcMonthCommissionTime(timeHelp.getNow())
        startTime = timeHelp.lastMonthStartTimestamp()
        endTime = timeHelp.monthStartTimestamp()
        year = timeHelp.getYear(startTime)
        month = timeHelp.getMonth(startTime)
        if month <= 1:
            preYear = year - 1
            preMonth = 12
        else:
            preYear = year
            preMonth = month - 1
        agentConfig = yield from getAgentConfig()
        probetRate = agentConfig['电竞竞猜']
        pingboRate = agentConfig['平博体育']
        try:
            sql = "select agentId from dj_agent"
            result = yield from classSqlBaseMgr.getInstance()._exeCute(sql)
            if result.rowcount <= 0:
                logging.info(repr("无代理用户"))
            else:
                for var in result:
                    agentId = var.agentId
                    with (yield from classSqlBaseMgr.getInstance().objDbMysqlMgr) as conn:
                        sql = "select balance from dj_agent_commission where agentId=%s and dateYear=%s and dateMonth=%s"
                        result = yield from conn.execute(sql, [agentId, preYear, preMonth])
                        if result.rowcount <= 0:
                            preBalance = 0
                        else:
                            for var_row in result:
                                preBalance = var_row.balance
                    newAccountNum = yield from classSqlBaseMgr.getInstance().getNewAccountCount(agentId, startTime,endTime)
                    activelyAccountNum = yield from classSqlBaseMgr.getInstance().getActivelyAccount(agentId, startTime,endTime)
                    pinboAllWinLoss = yield from classSqlBaseMgr.getInstance().getAccountPingboAllWinLoss(agentId,startTime,endTime)
                    probetAllWinLoss = yield from classSqlBaseMgr.getInstance().getAccountProbetAllWinCoin(agentId,startTime,endTime)
                    probetWinLoss = round(probetAllWinLoss)
                    pinboWinLoss = round(pinboAllWinLoss * 100)
                    # 平台费
                    if pinboWinLoss >= 0:
                        pingboPlatformCost = 0
                    else:
                        pingboPlatformCost = round(-pinboWinLoss * agentConfig['平博体育'])
                    if probetWinLoss >= 0:
                        probetPlatformCost = 0
                    else:
                        probetPlatformCost = round(-probetWinLoss * agentConfig['电竞竞猜'])
                    # 总输赢
                    winLoss = pinboWinLoss + probetWinLoss
                    # 平台费
                    platformCost = pingboPlatformCost + probetPlatformCost
                    pingboBackWater = yield from classSqlBaseMgr.getInstance().getAccountPinboBackWater(agentId,startTime,endTime)
                    probetBackWater = yield from classSqlBaseMgr.getInstance().getAccountProbetBackWater(agentId,startTime,endTime)
                    activetyBonus = yield from classSqlBaseMgr.getInstance().getAccountActivetyBonus(agentId, startTime,endTime)

                    pinboAllWater = yield from classSqlBaseMgr.getInstance().getAccountPingboWater(agentId, startTime,endTime)
                    probetAllWater = yield from classSqlBaseMgr.getInstance().getAccountProbetWater(agentId, startTime,endTime)
                    pingboWater = round(pinboAllWater * 100)
                    probetWater = round(probetAllWater)
                    allWater = pingboWater + probetWater
                    # 反水
                    backWater = round(pingboBackWater + probetBackWater)
                    activetyBonus = round(activetyBonus)
                    # 存提手续费
                    depositDrawingPoundage = yield from getDepositDrawingPoundage(agentId, startTime, endTime)

                    # 净利润,净输赢
                    netProfit = winLoss + platformCost + depositDrawingPoundage + activetyBonus + backWater
                    # 月结余
                    iBalance = netProfit + preBalance
                    if netProfit <= 0:
                        netProfit = -netProfit
                        for var_value in commission_config.values():
                            if var_value['leastNetWin'] <= netProfit <= var_value['mostNetWin']:
                                level = var_value['level']
                                proportion = agentConfig[level]
                    else:
                        netProfit = -netProfit
                        proportion = agentConfig['一档']

                    if iBalance < 0:
                        commission = round(-iBalance * proportion)
                        iBalance = 0
                    else:
                        commission = 0

                    sql = "select billId from dj_agent_commission where dateYear={} and dateMonth={} and agentId='{}'".format(
                        year, month, agentId)
                    result = yield from classSqlBaseMgr.getInstance()._exeCute(sql)
                    if result.rowcount <= 0:
                        billId = str(uuid.uuid1())
                        if commission <= 0:
                            status = 2
                        else:
                            status = 1
                        objAgentCommissionData = yield from addCommissionBill(billId, agentId, year, month,
                                                                      newAccountNum,
                                                                      activelyAccountNum, probetWinLoss,
                                                                      pinboWinLoss, winLoss,probetRate,pingboRate,
                                                                      probetPlatformCost, pingboPlatformCost,
                                                                      platformCost, depositDrawingPoundage,
                                                                      backWater,activetyBonus, allWater,
                                                                      netProfit,preBalance,iBalance, proportion, commission, status)

                        yield from classDataBaseMgr.getInstance().addAgentCommissionData(objAgentCommissionData)
                    else:
                        for var in result:
                            billId = var.billId
                        if commission <= 0:
                            status = 2
                        else:
                            status = 1
                        objAgentCommissionData = yield from addCommissionBill(billId, agentId, year, month,
                                                                      newAccountNum,
                                                                      activelyAccountNum, probetWinLoss,
                                                                      pinboWinLoss, winLoss,probetRate,pingboRate,
                                                                      probetPlatformCost, pingboPlatformCost,
                                                                      platformCost, depositDrawingPoundage,
                                                                      backWater,activetyBonus, allWater,
                                                                      netProfit,preBalance,iBalance, proportion, commission, status)

                        yield from classDataBaseMgr.getInstance().addAgentCommissionData(objAgentCommissionData, billId)
        except Exception as e:
            #logging.exception(e)
            logging.exception(e)
            raise e