예제 #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)
예제 #2
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)
예제 #3
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)
예제 #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()

    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)
예제 #5
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()
    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)
예제 #6
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)
예제 #7
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
예제 #8
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)
예제 #9
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))
예제 #10
0
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
예제 #11
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)
    agentConfig = yield from getAgentConfig()
    try:
        accountList, count = yield from classSqlBaseMgr.getInstance().getAccountDataByAgent(agentId, startTime, endTime, pn)
        if len(accountList) <= 0:
            return classJsonDump.dumps(objRep)
        else:
            accountDataList = []
            for accountData in accountList:
                accountDataDict = {}
                accountId = accountData['accountId']
                regTime = accountData['regTime']
                loginTime = accountData['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)
                probetWinLoss = round(probetAllWinLoss)
                pinboWinLoss = round(pinboAllWinLoss * 100)
                #返利
                allDividend = yield from classSqlBaseMgr.getInstance().getAccountDividend(accountId, startTime,endTime)
                dividend = round(allDividend)
                #存提手续费
                depositDrawingPoundage = yield from getAccountDepositDrawingPoundage(accountId, startTime, endTime)
                #平台费
                if pinboWinLoss>=0:
                    pingboPlatformCost = 0
                else:
                    pingboPlatformCost = round(-pinboWinLoss * agentConfig['平博体育'])
                if probetWinLoss >= 0:
                    probetPlatformCost = 0
                else:
                    probetPlatformCost = round(-probetWinLoss * agentConfig['电竞竞猜'])
                if deposit > 0:
                    isDeposit = '是'
                else:
                    isDeposit = '否'

                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['netWin'] = "%.2f"%round((pinboWinLoss+probetWinLoss+dividend+depositDrawingPoundage+pingboPlatformCost+probetPlatformCost)/100, 2)
                accountDataDict['depositUser'] = isDeposit
                accountDataList.append(accountDataDict)
            objRep.data = accountDataList
            objRep.count = count
            if pn==1:
                fileName = __name__
                nameList = fileName.split('.')
                methodName = nameList.pop()
                # 日志
                dictActionBill = {
                    'billType': 'adminActionBill',
                    'accountId': request.get('accountId', ''),
                    'action': "查询代理下线详情",
                    'actionTime': getNow(),
                    'actionMethod': methodName,
                    'actionDetail': "查询代理:{} 下线详情".format(agentId),
                    'actionIp': request.get('srcIp', ''),
                }
                logging.getLogger('bill').info(json.dumps(dictActionBill))
            return classJsonDump.dumps(objRep)
    except Exception as e:
        logging.exception(e)
예제 #12
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, agentId]):
        raise exceptionLogic(errorLogic.client_param_invalid)

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

        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)

        pinboSurvey = {}
        probetSurvey = {}

        pingboNetProfit = pinboWinLoss + pingboPlatformCost + round(
            pingboBackWater)
        pinboSurvey['project'] = '平博体育'
        pinboSurvey['winLoss'] = '%.2f' % pinboAllWinLoss
        pinboSurvey['platformCost'] = '%.2f' % round(pingboPlatformCost / 100,
                                                     2)
        pinboSurvey['netProfit'] = '%.2f' % round(pingboNetProfit / 100, 2)
        pinboSurvey['dividend'] = '%.2f' % round(pingboBackWater / 100, 2)

        probetNetProfit = probetWinLoss + probetPlatformCost + round(
            probetBackWater + activetyBonus)
        probetSurvey['project'] = '电竞竞猜'
        probetSurvey['winLoss'] = '%.2f' % round(probetAllWinLoss / 100, 2)
        probetSurvey['platformCost'] = '%.2f' % round(probetPlatformCost / 100,
                                                      2)
        probetSurvey['netProfit'] = '%.2f' % round(probetNetProfit / 100, 2)
        probetSurvey['dividend'] = '%.2f' % round(
            (probetBackWater + activetyBonus) / 100, 2)

        objRep.data.append(pinboSurvey)
        objRep.data.append(probetSurvey)
        fileName = __name__
        nameList = fileName.split('.')
        methodName = nameList.pop()
        # 日志
        dictActionBill = {
            'billType': 'adminActionBill',
            'accountId': request.get('accountId', ''),
            'action': "查询代理佣金详情",
            'actionTime': getNow(),
            'actionMethod': methodName,
            'actionDetail': "查询代理:{} 佣金详情".format(agentId),
            'actionIp': request.get('srcIp', ''),
        }
        logging.getLogger('bill').info(json.dumps(dictActionBill))
        return classJsonDump.dumps(objRep)
    except Exception as e:
        logging.error(repr(e))
        raise e
예제 #13
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