Beispiel #1
0
def handleHttp(request: dict):
    """佣金计划"""
    objRep = cResp()

    agentConfig = yield from getAgentConfig()
    for var_value in commission_config.values():
        level = var_value['level']
        proportion = agentConfig[level]
        var_value['proportion'] = '{}%'.format(proportion * 100)

    objRep.data.append(commission_config[1])
    objRep.data.append(commission_config[2])
    objRep.data.append(commission_config[3])
    objRep.data.append(commission_config[4])
    objRep.data.append(commission_config[5])
    return classJsonDump.dumps(objRep)
Beispiel #2
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 #3
0
def handleHttp(request: dict):
    """每月实时佣金账单"""
    objRsp = cResp()

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

    year = datetime.now().year
    month = datetime.now().month

    begin = datetime(year, month, 1)
    if month == 12:
        end = datetime(year + 1, 1, 1)
    else:
        end = datetime(year, month + 1, 1)
    startTime = timeHelp.date2timestamp(begin)
    endTime = timeHelp.date2timestamp(end)

    if month <= 1:
        preYear = year - 1
        preMonth = 12
    else:
        preYear = year
        preMonth = month - 1

    agentConfig = yield from getAgentConfig()
    probetRate = agentConfig['电竞竞猜']
    pingboRate = agentConfig['平博体育']
    try:
        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['电竞竞猜'])
        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 = probetWinLoss + pingboPlatformCost + pinboWinLoss + probetPlatformCost + 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['一档']

        # 总输赢
        winLoss = pinboWinLoss + probetWinLoss
        # 平台费
        platformCost = pingboPlatformCost + probetPlatformCost

        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())
            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, 3)

            yield from classDataBaseMgr.getInstance().addAgentCommissionData(
                objAgentCommissionData)
        else:
            for var in result:
                billId = var.billId
            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, 3)

            yield from classDataBaseMgr.getInstance().addAgentCommissionData(
                objAgentCommissionData, billId)
        yield from asyncio.sleep(1)
        sql = "select * from dj_agent_commission where agentId=%s and dateYear=%s and dateMonth=%s "
        params = [agentId, year, month]
        with (yield from classSqlBaseMgr.getInstance().objDbMysqlMgr) as conn:
            result = yield from conn.execute(sql, params)
            if result.rowcount <= 0:
                return classJsonDump.dumps(objRsp)
            else:
                for var_row in result:
                    commissionDict = {}
                    commissionDict['date'] = str(var_row.dateYear) + '/' + str(
                        var_row.dateMonth)
                    commissionDict[
                        'activelyAccountNum'] = var_row.activeAccount
                    commissionDict['winLoss'] = '%.2f' % round(
                        -var_row.winLoss / 100, 2)
                    commissionDict['dividend'] = '%.2f' % round(
                        (var_row.backWater + var_row.bonus) / 100, 2)
                    commissionDict['pingboWinLoss'] = '%.2f' % round(
                        var_row.pingboWinLoss / 100, 2)
                    commissionDict['probetWinLoss'] = '%.2f' % round(
                        var_row.probetWinLoss / 100, 2)
                    commissionDict['pingboCost'] = '%.2f' % round(
                        var_row.pingboCost / 100, 2)
                    commissionDict['probetCost'] = '%.2f' % round(
                        var_row.probetCost / 100, 2)
                    commissionDict['pingboRate'] = '{}%'.format(
                        var_row.probetRate * 100)
                    commissionDict['probetRate'] = '{}%'.format(
                        var_row.pingboRate * 100)
                    commissionDict['depositDrawingCost'] = '%.2f' % round(
                        var_row.depositDrawingCost / 100, 2)
                    commissionDict['backWater'] = '%.2f' % round(
                        var_row.backWater / 100, 2)
                    commissionDict['bonus'] = '%.2f' % round(
                        var_row.bonus / 100, 2)
                    commissionDict['netProfit'] = '%.2f' % round(
                        var_row.netProfit / 100, 2)
                    commissionDict['balance'] = '%.2f' % round(
                        -(var_row.preBalance / 100), 2)
                    commissionDict['commissionRate'] = '{}%'.format(
                        var_row.commissionRate * 100)
                    commissionDict['commission'] = '%.2f' % round(
                        var_row.commission / 100, 2)
                    commissionDict['status'] = var_row.status
                    objRsp.data.append(commissionDict)
        return classJsonDump.dumps(objRsp)
    except Exception as e:
        logging.exception(e)
        raise e
Beispiel #4
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 #5
0
def handleHttp(request: dict):
    """代理概况查询"""
    objRep = cResp()
    agentId = request.get('agentId', '')
    startTime = request.get('startTime', 0)
    endTime = request.get('endTime', 0)
    pn = request.get('pn', 1)

    if not all([startTime, endTime, pn]):
        raise exceptionLogic(errorLogic.client_param_invalid)
    year = timeHelp.getYear(startTime)
    month = timeHelp.getMonth(startTime)
    if month <= 1:
        preYear = year - 1
        preMonth = 12
    else:
        preYear = year
        preMonth = month - 1

    try:
        agentConfig = yield from getAgentConfig()
        if not agentConfig:
            raise exceptionLogic(errorLogic.data_not_valid)

        agentList, count = yield from classSqlBaseMgr.getInstance(
        ).getAgentData(agentId, pn)
        for agentId in agentList:
            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
            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)

            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 = 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)

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

            # 净利润,净输赢
            netWin = probetWinLoss + pingboPlatformCost + pinboWinLoss + probetPlatformCost + depositDrawingPoundage + activetyBonus + backWater
            if netWin <= 0:
                a = -netWin
            else:
                a = netWin
            for var_value in commission_config.values():
                if var_value['leastNetWin'] <= a <= var_value['mostNetWin']:
                    level = var_value['level']
                    proportion = agentConfig[level]
            iBalance = netWin + preBalance
            if iBalance < 0:
                # 佣金
                commission = round(-iBalance * proportion)
            else:
                commission = 0

            agentSurvey = {}
            agentSurvey['agentId'] = agentId
            agentSurvey['allAccountNum'] = allAccountNum
            agentSurvey['activelyAccountNum'] = activelyAccountNum
            agentSurvey['depositNum'] = '%.2f' % round(depositNum / 100, 2)
            agentSurvey['drawingNum'] = '%.2f' % round(drawingNum / 100, 2)
            agentSurvey['balanceNum'] = '%.2f' % round(balanceNum / 100, 2)
            agentSurvey['netWin'] = '%.2f' % round(netWin / 100, 2)
            agentSurvey['platformCost'] = '%.2f' % round(platformCost / 100, 2)
            agentSurvey['depositdrawingCost'] = '%.2f' % round(
                depositDrawingPoundage / 100, 2)
            agentSurvey['commission'] = '%.2f' % round(commission / 100, 2)
            agentSurvey['commissionRate'] = proportion
            agentSurvey['dividend'] = '%.2f' % (
                (backWater + activetyBonus) / 100)
            agentSurvey['preBalance'] = '%.2f' % (preBalance / 100)
            objRep.data.append(agentSurvey)
        if pn == 1:
            fileName = __name__
            nameList = fileName.split('.')
            methodName = nameList.pop()
            # 日志
            dictActionBill = {
                'billType': 'adminActionBill',
                'accountId': request.get('accountId', ''),
                'action': "代理概况查询",
                'actionTime': timeHelp.getNow(),
                'actionMethod': methodName,
                'actionDetail': "代理:{}概况查询".format(agentId),
                'actionIp': request.get('srcIp', ''),
            }
            logging.getLogger('bill').info(json.dumps(dictActionBill))
        objRep.count = count
        return classJsonDump.dumps(objRep)

    except Exception as e:
        logging.error(repr(e))
def handleHttp(request: dict):
    """生成佣金报表单"""

    agentId = request.get('agentId', '')
    year = request.get('year', 0)
    month = request.get('month', 0)

    if not all([year, month]):
        logging.debug(errorLogic.client_param_invalid)
        raise exceptionLogic(errorLogic.client_param_invalid)
    begin = datetime(year, month, 1)
    if month == 12:
        end = datetime(year + 1, 1, 1)
    else:
        end = datetime(year, month + 1, 1)
    startTime = timeHelp.date2timestamp(begin)
    endTime = timeHelp.date2timestamp(end)

    if month <= 1:
        preYear = year - 1
        preMonth = 12
    else:
        preYear = year
        preMonth = month - 1

    agentConfig = yield from getAgentConfig()
    probetRate = agentConfig['电竞竞猜']
    pingboRate = agentConfig['平博体育']
    if agentId:
        try:
            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
        except Exception as e:
            logging.error(repr(e))
            raise e
        objPlayerData = yield from classDataBaseMgr.getInstance(
        ).getPlayerData(agentId)
        if objPlayerData is None:
            raise exceptionLogic(errorLogic.agent_data_not_found)
        if objPlayerData.iUserType != 2:
            raise exceptionLogic(errorLogic.agent_data_not_found)
        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)
        objRsp = cResp()
        return classJsonDump.dumps(objRsp)
    else:
        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)
            objRsp = cResp()
            return classJsonDump.dumps(objRsp)
        except Exception as e:
            logging.exception(e)
            raise e
Beispiel #7
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