def handleHttp(request: dict): """获取渠道LTV数据""" channel = request.get('channel', '') startTime = request.get('startTime', 0) endTime = request.get('endTime', 0) objRep = cResp() if not all([startTime,endTime]): logging.debug(errorLogic.client_param_invalid) raise exceptionLogic(errorLogic.client_param_invalid) if (not checkIsInt(startTime)) or (not checkIsInt(endTime)): logging.debug(errorLogic.client_param_invalid) raise exceptionLogic(errorLogic.client_param_invalid) try: # conn=classSqlBaseMgr.getInstance(instanceName='probet_oss') with (yield from classSqlBaseMgr.getInstance().objDbMysqlMgr) as conn: over_all_data=cData() #todo return classJsonDump.dumps(objRep) except Exception as e: logging.exception(e) raise exceptionLogic(errorLogic.db_error)
def handleHttp(dict_param: dict): """提款""" objRsp = cResp() strAccountId = dict_param.get("accountId", "") strCardNum = str(dict_param.get("cardNum", "")) TradePwd = dict_param.get("tradePwd", "") money = dict_param.get("money", "") if not all([strCardNum, money]): raise exceptionLogic(errorLogic.client_param_invalid) if cpv.checkIsString(money): raise exceptionLogic(errorLogic.client_param_invalid) fMoney = float(money) if not cpv.checkIsFloat(fMoney): raise exceptionLogic(errorLogic.client_param_invalid) iCoin = int(fMoney * 100) if not cpv.checkIsInt(iCoin): raise exceptionLogic(errorLogic.client_param_invalid) strTradePwd = PwdEncrypt().create_md5(TradePwd) objPlayerData, objLock = yield from classDataBaseMgr.getInstance( ).getPlayerDataByLock(strAccountId) if not objPlayerData.strTradePassword: raise exceptionLogic(errorLogic.trade_pwde_not_bind) if strTradePwd != objPlayerData.strTradePassword: raise exceptionLogic(errorLogic.trade_pwde_not_valid) # 获取可提现额度 drawinglimit = round( (objPlayerData.iCoin - objPlayerData.iNotDrawingCoin) / 100, 2) Coin = round(iCoin / 100) if not cpv.checkIsInt(Coin): raise exceptionLogic(errorLogic.player_drawing_coin_not_int) if Coin > drawinglimit: raise exceptionLogic(errorLogic.player_drawing_not_enough) if objPlayerData.iCoin < iCoin: raise exceptionLogic(errorLogic.player_coin_not_enough) else: balance = objPlayerData.iCoin - iCoin # redis 事务操作以及余额的处理 objPlayerData.iCoin -= iCoin yield from classDataBaseMgr.getInstance().setPlayerDataByLock( objPlayerData, objLock) yield from addPlayerBill(strAccountId, iCoin, balance, CoinOp.coinOpDraw, 2, "中心钱包", strCardNum) newdrawinglimit = drawinglimit - Coin objRsp.data = cData() objRsp.data.iCoin = "%.2f" % round(objPlayerData.iCoin / 100, 2) objRsp.data.newDrawingLimit = newdrawinglimit return classJsonDump.dumps(objRsp)
def handleHttp(dict_param: dict): """ 后台查询历史系统消息 """ objRsp = cResp() pn = dict_param.get("pn", 1) if not checkIsInt(pn): logging.debug(errorLogic.client_param_invalid) raise exceptionLogic(errorLogic.client_param_invalid) conn = classSqlBaseMgr.getInstance() # 去重获取msgId sql = "select distinct msgId from dj_all_msg WHERE type=3 " listRest = yield from conn._exeCute(sql) msgIds = yield from listRest.fetchall() if len(msgIds) == 0: return classJsonDump.dumps(objRsp) else: ids = [] for x in msgIds: ids.append(x[0]) # 根据id获取消息 for x in msgIds: sql = "select msgId,msgTime,msgDetail,msgTitle,sendFrom,sendTo from dj_all_msg WHERE msgId='{}' ".format( x[0]) listRest = yield from conn._exeCute(sql) msgs = yield from listRest.fetchall() if len(msgs) == 0: return classJsonDump.dumps(objRsp) if len(msgs) > 5: # 全体发送 data = cData() data.msgId = msgs[0]['msgId'] data.msgTime = msgs[0]['msgTime'] data.detail = msgs[0]['msgDetail'] data.title = msgs[0]['msgTitle'] data.sendFrom = msgs[0]['sendFrom'] data.receiver = '全体' objRsp.data.append(data) continue else: for x in msgs: data = cData() data.msgId = x['msgId'] data.msgTime = x['msgTime'] data.detail = x['msgDetail'] data.title = x['msgTitle'] data.receiver = x['sendTo'] data.sendFrom = x['sendFrom'] objRsp.data.append(data) objRsp.count = len(objRsp.data) objRsp.data = sorted(objRsp.data, key=lambda data: data.msgTime, reverse=True) objRsp.data = objRsp.data[(pn - 1) * MSG_PAGE_COUNT:pn * MSG_PAGE_COUNT:] return classJsonDump.dumps(objRsp)
def handleHttp(request: dict): # 获取充值账户下的待处理账单 transTo = request.get('transTo', '') money = request.get('money', '') if not transTo: logging.debug(errorLogic.client_param_invalid) raise exceptionLogic(errorLogic.client_param_invalid) try: conn = classSqlBaseMgr.getInstance() if money: if cpv.checkIsString(money): raise exceptionLogic(errorLogic.client_param_invalid) fMoney = float(money) if not cpv.checkIsFloat(fMoney): raise exceptionLogic(errorLogic.client_param_invalid) iCoin = int(fMoney * 100) if not cpv.checkIsInt(iCoin): raise exceptionLogic(errorLogic.client_param_invalid) ids_sql = "select orderId from dj_coin_history WHERE transTo='{}' AND coinNum={} AND tradeState=2 AND tradeType=1 ".format( transTo, iCoin) else: ids_sql = "select orderId from dj_coin_history WHERE transTo='{}' AND tradeState=2 AND tradeType=1 ".format( transTo) sql = "select * from dj_pay_order WHERE payOrder IN (" + ids_sql + ") and orderTime between {} and {} order by status desc,orderTime desc".format( getNow() - 3600 * 24, getNow()) listRest = yield from conn._exeCute(sql) pay_list = yield from listRest.fetchall() resp = cResp() for x in pay_list: data = cData() data.payOrder = x['payOrder'] data.payChannel = x['payChannel'] data.accountId = x['accountId'] data.orderTime = x['orderTime'] data.buyCoin = "%.2f" % round(x['buyCoin'] / 100, 2) data.ip = x['ip'] data.status = x['status'] resp.data.append(data) resp.ret = errorLogic.success[0] return classJsonDump.dumps(resp) except exceptionLogic as e: logging.error(repr(e)) raise e except Exception as e: logging.exception(e) raise exceptionLogic(errorLogic.db_error)
def handleHttp(request: dict): userId = request.get('userId', '') kind = request.get('kind', '') money = request.get('money', 0) reason = request.get('reason', '') wallet = request.get('wallet', '') if not all([userId, money, kind, reason]): logging.debug(errorLogic.client_param_invalid) raise exceptionLogic(errorLogic.client_param_invalid) if cpv.checkIsString(money): raise exceptionLogic(errorLogic.client_param_invalid) fMoney = float(money) if not cpv.checkIsFloat(fMoney): raise exceptionLogic(errorLogic.client_param_invalid) iCoin = int(fMoney * 100) if not cpv.checkIsInt(iCoin): raise exceptionLogic(errorLogic.client_param_invalid) if kind not in ['recharge', 'deductions']: logging.debug(errorLogic.client_param_invalid) raise exceptionLogic(errorLogic.client_param_invalid) try: objPlayerData, objLock = yield from classDataBaseMgr.getInstance( ).getPlayerDataByLock(userId) if objPlayerData is None: raise exceptionLogic(errorLogic.player_data_not_found) objUserCoinHis = classUserCoinHistory() objUserCoinHis.strOrderId = str(uuid.uuid1()) objUserCoinHis.iTime = timeHelp.getNow() objUserCoinHis.iCoin = iCoin objUserCoinHis.iTradeState = 1 objUserCoinHis.strAccountId = userId objUserCoinHis.strIp = request.get('srcIp', '') objUserCoinHis.iEndTime = timeHelp.getNow() objUserCoinHis.strTransFrom = '后台' objUserCoinHis.strTransTo = '中心钱包' objUserCoinHis.strReviewer = request.get('accountId', '') objUserCoinHis.strReason = reason if kind == 'recharge': objUserCoinHis.iTradeType = 11 objPlayerData.iCoin += iCoin objNewPayOrder = classPayData() objNewPayOrder.strPayOrder = objUserCoinHis.strOrderId objNewPayOrder.strAccountId = userId objNewPayOrder.iBuyCoin = iCoin objNewPayOrder.iOrderTime = timeHelp.getNow() objNewPayOrder.strIp = request.get( "srcIp", "") # str(dictParam.get("srcIp", "")) objNewPayOrder.strPayChannel = '后台' yield from classDataBaseMgr.getInstance().setPayOrderByLock( objNewPayOrder, save=False, new=True) walletName = 'center' coin = objPlayerData.iCoin else: if wallet not in ['center', 'pingboCoin', 'betCoin', 'shabaCoin']: logging.debug(errorLogic.client_param_invalid) raise exceptionLogic(errorLogic.client_param_invalid) objUserCoinHis.iTradeType = 6 objUserCoinHis.strTransTo = '后台' if wallet == "center": objPlayerData.iCoin -= iCoin objUserCoinHis.strTransFrom = '中心钱包' coin = objPlayerData.iCoin elif wallet == "pingboCoin": status = yield from deposit(kind='withdraw', accountId=userId, amount=fMoney) if status != 1: yield from classDataBaseMgr.getInstance( ).releasePlayerDataLock(userId, objLock) logging.debug(errorLogic.third_deductions_failed) raise exceptionLogic(errorLogic.third_deductions_failed) coin = objPlayerData.iPingboCoin if objPlayerData.iPingboCoin - iCoin < 0: logging.debug(errorLogic.third_deductions_failed) raise exceptionLogic(errorLogic.third_deductions_failed) objPlayerData.iPingboCoin -= iCoin objUserCoinHis.strTransFrom = '平博钱包' elif wallet == "betCoin": coin = objPlayerData.iGuessCoin objPlayerData.iGuessCoin -= iCoin objUserCoinHis.strTransFrom = '竞猜钱包' else: coin = objPlayerData.iShabaCoin objPlayerData.iShabaCoin -= iCoin #todo 调用沙巴扣钱api objUserCoinHis.strTransFrom = '沙巴钱包' walletName = wallet yield from classDataBaseMgr.getInstance().addPlayerCoinRecord( userId, objUserCoinHis) yield from classDataBaseMgr.getInstance().setPlayerDataByLock( objPlayerData, objLock) # 推送用户金币 yield from coroPushPlayerCenterCoin(objPlayerData.strAccountId, coin, walletName) yield from asyncio.sleep(1) sql = "select * from dj_account WHERE accountId='{}' ".format(userId) conn = classSqlBaseMgr.getInstance() listRest = yield from conn._exeCute(sql) user = yield from listRest.fetchone() objRsp = cResp() data = cData() data.accountId = user['accountId'] data.phone = user['phone'] data.coin = "%.2f" % round(user['coin'] / 100, 2) data.guessCoin = "%.2f" % round(user['guessCoin'] / 100, 2) data.pinboCoin = "%.2f" % round(user['pingboCoin'] / 100, 2) #todo data.coin188 = "%.2f" % round(123123 / 100, 2) data.regTime = user['regTime'] data.email = user['email'] data.loginTime = user['loginTime'] data.loginIp = [user['loginIp'], user['loginAddress']] data.logoutTime = user['logoutTime'] data.level = user['level'] data.status = [user['status'], user['lockEndTime'], user['lockReason']] data.bankcard = ast.literal_eval(user['bankcard']) data.loginDeviceUdid = user['loginDeviceUdid'] data.realName = user['realName'] objRsp.data.append(data) fileName = __name__ nameList = fileName.split('.') methodName = nameList.pop() # 日志 dictActionBill = { 'billType': 'adminActionBill', 'accountId': request.get('accountId', ''), 'action': "给用户充值/补发" if kind == 'recharge' else "给用户扣款", 'actionTime': timeHelp.getNow(), 'actionMethod': methodName, 'actionDetail': "给用户:{},充值/补发:{},单号:{}".format(userId, money, objUserCoinHis.strOrderId) if kind == 'recharge' else "给用户:{},扣款{},单号:{}".format( userId, money, objUserCoinHis.strOrderId), 'actionIp': request.get('srcIp', ''), } logging.getLogger('bill').info(json.dumps(dictActionBill)) return classJsonDump.dumps(objRsp) except Exception as e: logging.exception(e) raise e
def handleHttp(request: dict): """查询日志数据""" adminAccount = request.get('adminAccount', '') startTime = request.get('startTime', 0) endTime = request.get('endTime', 0) pn = request.get('pn', 1) try: pn = int(pn) except Exception as e: logging.error(repr(e)) raise exceptionLogic(errorLogic.client_param_invalid) objRep = cResp() if not all([startTime, endTime]): logging.debug(errorLogic.client_param_invalid) raise exceptionLogic(errorLogic.client_param_invalid) if (not checkIsInt(startTime)) or (not checkIsInt(endTime)): logging.debug(errorLogic.client_param_invalid) raise exceptionLogic(errorLogic.client_param_invalid) log_sql = "select * from dj_admin_action_bill WHERE actionTime BETWEEN {} AND {} ".format( startTime, endTime) if adminAccount: log_sql = log_sql + "and accountId='{}' ".format(adminAccount) log_count_sql = log_sql.replace(r'*', 'count(id)', 1) try: with (yield from classSqlBaseMgr.getInstance( instanceName='probet_oss').objDbMysqlMgr) as conn: countRet = yield from conn.execute(log_count_sql) count = yield from countRet.fetchone() objRep.count = count[0] log_sql = log_sql + "order by actionTime desc limit {} offset {}".format( MSG_PAGE_COUNT, (pn - 1) * MSG_PAGE_COUNT) logRet = yield from conn.execute(log_sql) logList = yield from logRet.fetchall() probet_conn = classSqlBaseMgr.getInstance() for x in logList: data = cData() data.accountId = x['accountId'] data.time = x['actionTime'] data.logDetail = x['actionDetail'] role_name_sql = "select role_name from dj_admin_role WHERE id=(SELECT role_id FROM dj_admin_account WHERE accountId='{}')".format( x['accountId']) roleNameRet = yield from probet_conn._exeCute(role_name_sql) roleNameList = yield from roleNameRet.fetchone() data.roleName = "该管理员不在系统中" if roleNameList is None else roleNameList[ 0] objRep.data.append(data) if pn == 1: fileName = __name__ nameList = fileName.split('.') methodName = nameList.pop() # 日志 dictActionBill = { 'billType': 'adminActionBill', 'accountId': request.get('accountId', ''), 'action': "查询日志数据", 'actionTime': getNow(), 'actionMethod': methodName, 'actionDetail': "查询日志数据", 'actionIp': request.get('srcIp', ''), } logging.getLogger('bill').info(json.dumps(dictActionBill)) return classJsonDump.dumps(objRep) except Exception as e: logging.exception(e) raise exceptionLogic(errorLogic.db_error)
def handleHttp(request: dict): """根据时间,渠道获取综合数据""" channel = request.get('channel', '') startTime = request.get('startTime', 0) endTime = request.get('endTime', 0) pn = request.get('pn', 1) objRep = cResp() if not all([startTime, endTime]): logging.debug(errorLogic.client_param_invalid) raise exceptionLogic(errorLogic.client_param_invalid) if (not checkIsInt(startTime)) or (not checkIsInt(endTime)) or ( not checkIsInt(pn)): logging.debug(errorLogic.client_param_invalid) raise exceptionLogic(errorLogic.client_param_invalid) try: conn = classSqlBaseMgr.getInstance(instanceName='probet_oss') endTime = endTime + 24 * 3600 days = (endTime - startTime) / (24 * 3600) days = int(days) # 获取综合数据查询 for x in range((pn - 1) * MSG_PAGE_COUNT, pn * MSG_PAGE_COUNT): if x >= days: break data = cData() #1.获取截止当前这天的总注册、新增用户、 登录人数、存款、取款、投注收入、 if channel: sql = "select count(DISTINCT(accountId)) from dj_regbill WHERE dj_regbill.agentId='{}' AND dj_regbill.regTime <={} ".format( channel, startTime + x * 24 * 3600) else: sql = "select count(DISTINCT(accountId)) from dj_regbill WHERE dj_regbill.regTime <={} ".format( startTime + x * 24 * 3600) listRest = yield from conn._exeCute(sql) idList = yield from listRest.fetchone() # 总注册量 reg_count = idList[0] data.totalReg = reg_count #时间 data.time = startTime + x * 24 * 3600 #新增用户:当天 if channel: sql = "select count(id) from dj_regbill WHERE dj_regbill.regTime BETWEEN {} AND {} AND dj_regbill.agentId='{}' ".format( startTime + x * 24 * 3600, startTime + (x + 1) * 24 * 3600, channel) else: sql = "select count(id) from dj_regbill WHERE dj_regbill.regTime BETWEEN {} AND {} ".format( startTime + x * 24 * 3600, startTime + (x + 1) * 24 * 3600) listRest = yield from conn._exeCute(sql) newAccount = yield from listRest.fetchone() data.newAccount = newAccount[0] #登录人数:当天 if channel: sql = "select count(DISTINCT(accountId)) from dj_loginbill WHERE dj_loginbill.loginTime BETWEEN {} AND {} AND dj_loginbill.agentId='{}'".format( startTime + x * 24 * 3600, startTime + (x + 1) * 24 * 3600, channel) else: sql = "select count(DISTINCT(accountId)) from dj_loginbill WHERE dj_loginbill.loginTime BETWEEN {} AND {} ".format( startTime + x * 24 * 3600, startTime + (x + 1) * 24 * 3600) listRest = yield from conn._exeCute(sql) login_count = yield from listRest.fetchone() data.loginCount = login_count[0] #存款:当天 if channel: sql = "select sum(payCoin) from dj_paybill WHERE dj_paybill.payTime BETWEEN {} AND {} AND dj_paybill.agentId='{}' ".format( startTime + x * 24 * 3600, startTime + (x + 1) * 24 * 3600, channel) else: sql = "select sum(payCoin) from dj_paybill WHERE dj_paybill.payTime BETWEEN {} AND {} ".format( startTime + x * 24 * 3600, startTime + (x + 1) * 24 * 3600) listRest = yield from conn._exeCute(sql) totalRecharge = yield from listRest.fetchone() data.recharge = 0 if totalRecharge[0] is None else int( totalRecharge[0]) / 100 #提款:当天 if channel: sql = "select sum(withdrawalCoin) from dj_withdrawalbill WHERE dj_withdrawalbill.withdrawalTime BETWEEN {} AND {} AND dj_withdrawalbill.accountId='{}'".format( startTime + x * 24 * 3600, startTime + (x + 1) * 24 * 3600, channel) else: sql = "select sum(withdrawalCoin) from dj_withdrawalbill WHERE dj_withdrawalbill.withdrawalTime BETWEEN {} AND {} ".format( startTime + x * 24 * 3600, startTime + (x + 1) * 24 * 3600) listRest = yield from conn._exeCute(sql) deduction = yield from listRest.fetchone() data.deduction = 0 if deduction[0] is None else int( deduction[0]) / 100 # 投注收入:总投注的金钱 if channel: sql = "select sum(betCoinNum),sum(winCoin) from dj_betresultbill WHERE dj_betresultbill.resultTime BETWEEN {} AND {} AND dj_betresultbill.agentId='{}' ".format( startTime + x * 24 * 3600, startTime + (x + 1) * 24 * 3600, channel) else: sql = "select sum(betCoinNum),sum(winCoin) from dj_betresultbill WHERE dj_betresultbill.resultTime BETWEEN {} AND {} ".format( startTime + x * 24 * 3600, startTime + (x + 1) * 24 * 3600) pingbo_bet_sql = "select sum(toRisk),sum(CASE WHEN winLoss>0 THEN winLoss ELSE 0 END) from dj_pingbobetbill WHERE wagerDateFm BETWEEN {} AND {} AND status='SETTLED' ".format( startTime + x * 24 * 3600, startTime + (x + 1) * 24 * 3600) listRest = yield from conn._exeCute(sql) ret = yield from listRest.fetchone() result = yield from conn._exeCute(pingbo_bet_sql) res = yield from result.fetchone() probetAvail = 0 if ret[0] is None else int(ret[0]) / 100 proAwardNum = 0 if ret[1] is None else int(ret[1]) / 100 pinBetAvail = 0 if res[0] is None else res[0] pinAwardNum = 0 if res[1] is None else res[1] data.betAvail = round((probetAvail + pinBetAvail), 2) data.awardNum = round((proAwardNum + pinAwardNum), 2) #todo ACU----APU data.ACU = 0 data.PCU = 0 # 存款人数 if channel: sql = "select count(DISTINCT(accountId)) from dj_paybill WHERE dj_paybill.payTime BETWEEN {} AND {} AND dj_paybill.agentId='{}' ".format( startTime + x * 24 * 3600, startTime + (x + 1) * 24 * 3600, channel) else: sql = "select count(DISTINCT(accountId)) from dj_paybill WHERE dj_paybill.payTime BETWEEN {} AND {} ".format( startTime + x * 24 * 3600, startTime + (x + 1) * 24 * 3600) listRest = yield from conn._exeCute(sql) rechargeCount = yield from listRest.fetchone() data.rechargeCount = rechargeCount[0] # 首存人数:非当天注册 if channel: sql = "select count(DISTINCT(accountId)) from dj_paybill WHERE dj_paybill.firstPayTime BETWEEN {} AND {} AND dj_paybill.agentId='{}' ".format( startTime + x * 24 * 3600, startTime + (x + 1) * 24 * 3600, channel) else: sql = "select count(DISTINCT(accountId)) from dj_paybill WHERE dj_paybill.firstPayTime BETWEEN {} AND {} ".format( startTime + x * 24 * 3600, startTime + (x + 1) * 24 * 3600) listRest = yield from conn._exeCute(sql) firstRechargeCount = yield from listRest.fetchone() data.firstRechargeCount = firstRechargeCount[0] #新增存款人数:今日注册参与存款的用户 if channel: sql_reg = "select accountId from dj_regbill WHERE dj_regbill.regTime BETWEEN {} AND {} AND dj_regbill.agentId='{}' ".format( startTime + x * 24 * 3600, startTime + (x + 1) * 24 * 3600, channel) else: sql_reg = "select accountId from dj_regbill WHERE dj_regbill.regTime BETWEEN {} AND {} ".format( startTime + x * 24 * 3600, startTime + (x + 1) * 24 * 3600) listRest = yield from conn._exeCute(sql_reg) idList = yield from listRest.fetchall() if len(idList) == 0: data.newRechargeCount = 0 else: sql = "select count(DISTINCT(accountId)) from dj_paybill WHERE dj_paybill.payTime BETWEEN {} AND {} ".format( startTime + x * 24 * 3600, startTime + (x + 1) * 24 * 3600) sql = sql + " AND dj_paybill.accountId in (" + sql_reg + ")" listRest = yield from conn._exeCute(sql) newRechargeCount = yield from listRest.fetchone() data.newRechargeCount = newRechargeCount[0] #付费渗透:存款人数/登录人数 data.payPenetration = "%.2f" % round( 0, 2) if data.loginCount == 0 else "%.2f" % round( data.rechargeCount / data.loginCount, 2) #付费转换:新增付费人数/新增用户 data.payConversion = "%.2f" % round( 0, 2) if data.newAccount == 0 else "%.2f" % round( data.newRechargeCount / data.newAccount, 2) #总流水 data.totalWater = data.betAvail #有效流水:赔率在1.5倍以上的投注单 todo 亚赔,欧赔,平博和自己平台不一样 if channel: sql = "select sum(betCoinNum) from dj_betresultbill WHERE dj_betresultbill.rate>=1.5 AND dj_betresultbill.resultTime BETWEEN {} AND {} AND dj_betresultbill.agentId='{}' ".format( startTime + x * 24 * 3600, startTime + (x + 1) * 24 * 3600, channel) else: sql = "select sum(betCoinNum) from dj_betresultbill WHERE dj_betresultbill.rate>=1.5 AND dj_betresultbill.resultTime BETWEEN {} AND {} ".format( startTime + x * 24 * 3600, startTime + (x + 1) * 24 * 3600) listRest = yield from conn._exeCute(sql) validWater = yield from listRest.fetchone() #pingbo有效流水 if channel: pinValidWater = yield from getPingboValidWaterByParams( loginIds=None, startTime=(startTime + x * 24 * 3600), endTime=(startTime + (x + 1) * 24 * 3600), agentId=channel) else: pinValidWater = yield from getPingboValidWaterByParams( loginIds=None, startTime=(startTime + x * 24 * 3600), endTime=(startTime + (x + 1) * 24 * 3600)) proValidWater = 0 if validWater[0] is None else int( validWater[0]) / 100 data.validWater = round(proValidWater + pinValidWater, 2) #抽水:投注*抽水比 todo data.pumpingWater = round(data.betAvail * 0.15, 2) #盈亏:投注收入-派奖 data.profitLoss = round(data.betAvail - data.awardNum, 2) #盈亏比:盈亏/投注收入 data.profitLossRatio = "%.2f" % round( 0, 2) if data.betAvail == 0 else "%.2f" % round( data.profitLoss / data.betAvail, 2) objRep.data.append(data) objRep.count = days if pn == 1: fileName = __name__ nameList = fileName.split('.') methodName = nameList.pop() # 日志 dictActionBill = { 'billType': 'adminActionBill', 'accountId': request.get('accountId', ''), 'action': "综合数据查询", 'actionTime': getNow(), 'actionMethod': methodName, 'actionDetail': "综合数据查询", 'actionIp': request.get('srcIp', ''), } logging.getLogger('bill').info(json.dumps(dictActionBill)) return classJsonDump.dumps(objRep) except Exception as e: logging.exception(e) raise exceptionLogic(errorLogic.db_error)
def handleHttp(request: dict): """根据时间,渠道获取充值数据""" channel = request.get('channel', '') startTime = request.get('startTime', 0) endTime = request.get('endTime', 0) pn = request.get('pn', 1) objRep = cResp() if not all([startTime,endTime]): logging.debug(errorLogic.client_param_invalid) raise exceptionLogic(errorLogic.client_param_invalid) if (not checkIsInt(startTime)) or (not checkIsInt(endTime)) or (not checkIsInt(pn)): logging.debug(errorLogic.client_param_invalid) raise exceptionLogic(errorLogic.client_param_invalid) try: conn=classSqlBaseMgr.getInstance(instanceName='probet_oss') #1.获取startTime注册账号量及accountId if channel: ids_sql = "select accountId from dj_regbill WHERE dj_regbill.channel='{}' ".format(channel) else: ids_sql="select accountId from dj_regbill" #更据id,时间获取充值订单, sql = "select COUNT(orderId) from dj_paybill WHERE dj_paybill.accountId IN ("+ids_sql+") AND dj_paybill.payTime BETWEEN {} AND {} ".format(startTime,endTime) listRest = yield from conn._exeCute(sql) count = yield from listRest.fetchone() count=count[0] sql="select * from dj_paybill WHERE dj_paybill.accountId IN ("+ids_sql+") AND dj_paybill.payTime BETWEEN {} AND {} limit {} offset {}".format( startTime,endTime,MSG_PAGE_COUNT,(pn-1)*MSG_PAGE_COUNT) listRest=yield from conn._exeCute(sql) orders=yield from listRest.fetchall() if len(orders)==0: return classJsonDump.dumps(objRep) for x in orders: data=cData() data.payTime=x['payTime'] data.orderId=x['orderId'] data.accountId=x['accountId'] data.payCoin="%.2f"%round(x['payCoin']/100,2) data.payChannel=x['payChannel'] data.orderState=x['orderState'] data.thirdPayOrder=x['thirdPayOrder'] objRep.data.append(data) 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': "充值数据查询", 'actionIp': request.get('srcIp', ''), } logging.getLogger('bill').info(json.dumps(dictActionBill)) return classJsonDump.dumps(objRep) except Exception as e: logging.exception(e) raise exceptionLogic(errorLogic.db_error)
def handleHttp(dict_param: dict): """存款""" objRsp = cResp() strAccountId = dict_param.get("accountId", "") strToken = dict_param.get("token", "") strPayType = dict_param.get("payType", "") # iTradeType = dict_param.get("tradeType", 0) money = dict_param.get("money", "") if not all([strAccountId, strToken, money]): raise exceptionLogic(errorLogic.client_param_invalid) if cpv.checkIsString(money): raise exceptionLogic(errorLogic.client_param_invalid) fMoney = float(money) if not cpv.checkIsFloat(fMoney): raise exceptionLogic(errorLogic.client_param_invalid) iCoin = int(fMoney * 100) if not cpv.checkIsInt(iCoin): raise exceptionLogic(errorLogic.client_param_invalid) certifytoken.certify_token(strAccountId, strToken) objPlayerData = yield from classDataBaseMgr.getInstance().getPlayerData(strAccountId) if objPlayerData is None: raise exceptionLogic(errorLogic.player_data_not_found) if strToken != objPlayerData.strToken: raise exceptionLogic(errorLogic.login_token_not_valid) PayTypeList = [] for var in constants.DEPOSIT_LIST: PayTypeList.append(var["desc"]) if strPayType not in PayTypeList: raise exceptionLogic(errorLogic.pay_type_not_valid) if strPayType == enumPayType.BankTransfer: # 银行转账 accountInfoList = yield from classSqlBaseMgr.getInstance().getAllBankInfo() objRsp.data = cData() objRsp.data.iCoin = "%.2f" % round(objPlayerData.iCoin / 100, 2) objRsp.data.iSaveCoin = "%.2f" % round(iCoin / 100, 2) try: objRsp.data.payeeCardInfo = random.choice(accountInfoList) except Exception as e: logging.error(repr(e)) raise exceptionLogic(errorLogic.pay_channel_not_support) orderId=orderGeneral.generalOrderId() yield from generalPayOrder(orderId,"","",strAccountId,iCoin,dict_param.get("srcIp",""),"银行卡转账", objRsp.data.payeeCardInfo["accountId"]) # 构造回包 objRsp.data.payOrder = orderId return classJsonDump.dumps(objRsp) elif strPayType == enumPayType.AlipayTransfer: # 支付宝转账 accountInfoList = yield from classSqlBaseMgr.getInstance().getAllAlipayInfo() objRsp.data = cData() objRsp.data.iCoin = "%.2f" % round(objPlayerData.iCoin / 100, 2) objRsp.data.iSaveCoin = "%.2f" % round(iCoin / 100, 2) try: objRsp.data.payeeCardInfo = random.choice(accountInfoList) except Exception as e: logging.error(repr(e)) raise exceptionLogic(errorLogic.pay_channel_not_support) orderId = orderGeneral.generalOrderId() yield from generalPayOrder(orderId, "","", strAccountId, iCoin, dict_param.get("srcIp", ""), "支付宝转账",objRsp.data.payeeCardInfo["accountId"]) objRsp.data.payOrder = orderId return classJsonDump.dumps(objRsp) elif strPayType == enumPayType.WeixinTransfer: # 微信转账 accountInfoList = yield from classSqlBaseMgr.getInstance().getAllWeixinInfo() objRsp.data = cData() objRsp.data.iCoin = "%.2f" % round(objPlayerData.iCoin / 100, 2) objRsp.data.iSaveCoin = "%.2f" % round(iCoin / 100, 2) try: objRsp.data.payeeCardInfo = random.choice(accountInfoList) except Exception as e: logging.error(repr(e)) raise exceptionLogic(errorLogic.pay_channel_not_support) orderId = orderGeneral.generalOrderId() yield from generalPayOrder(orderId, "","", strAccountId, iCoin, dict_param.get("srcIp", ""), "微信转账",objRsp.data.payeeCardInfo["accountId"]) objRsp.data.payOrder = orderId return classJsonDump.dumps(objRsp)
def handleHttp(request: dict): """根据时间,渠道获取投注信息""" channel = request.get('channel', '') startTime = request.get('startTime', 0) endTime = request.get('endTime', 0) objRep = cResp() if not all([startTime, endTime]): logging.debug(errorLogic.client_param_invalid) raise exceptionLogic(errorLogic.client_param_invalid) if (not checkIsInt(startTime)) or (not checkIsInt(endTime)): logging.debug(errorLogic.client_param_invalid) raise exceptionLogic(errorLogic.client_param_invalid) try: conn = classSqlBaseMgr.getInstance(instanceName='probet_oss') over_all_data = cData1() #登录用户数 login_count_sql = "select count(DISTINCT(accountId)) from dj_loginbill WHERE loginTime BETWEEN {} AND {} ".format( startTime, endTime) #新增用户数 new_reg_count_sql = "select count(id) from dj_regbill WHERE regTime BETWEEN {} AND {} ".format( startTime, endTime) #投注用户数 总投注笔数 总流水 返奖金额 bet_count_sql = "select count(DISTINCT(accountId)),COUNT(id),SUM(betCoinNum),SUM(winCoin) from dj_betresultbill WHERE resultTime BETWEEN {} AND {} ".format( startTime, endTime) #1.查询时间之前下过注的账号 before_users_sql = "SELECT DISTINCT(accountId) FROM dj_betresultbill WHERE resultTime<{} ".format( startTime) #2.获取查询开始时间之后的所有用户 after_users_sql = "select accountId from dj_regbill WHERE accountId not in {}" #有效流水 valid_water_sql = "select sum(betCoinNum) from dj_betresultbill WHERE rate>=1.5 AND resultTime BETWEEN {} AND {} ".format( startTime, endTime) #中奖注单数 win_bet_count_sql = "select count(id) from dj_betresultbill WHERE winCoin>0" # 获取所有盘口数据 gameNames = [] sql = "select DISTINCT(GuessName) from dj_betresultbill" listRest = yield from conn._exeCute(sql) names = yield from listRest.fetchall() for x in names: gameNames.append(x[0]) gameNames.append('平博') #todo if channel: for game in gameNames: handicap_data = cData2() handicap_data.gameName = game # 下注人数,总下注额,注单数 handicap_sql = "select COUNT(DISTINCT(accountId)),sum(betCoinNum),COUNT(id) from dj_betresultbill WHERE agentId='{}' AND resultTime BETWEEN {} AND {} AND guessName='{}' ".format( channel, startTime, endTime, game) if game == '平博': handicap_sql = "select COUNT(DISTINCT(loginId)),sum(toRisk),COUNT(wagerId) from dj_pingbobetbill WHERE agentId='{}' AND wagerDateFm BETWEEN {} AND {} ".format( channel, startTime, endTime) listRest = yield from conn._exeCute(handicap_sql) result = yield from listRest.fetchone() handicap_data.betUsers = result[0] handicap_data.betCoin = 0 if result[1] is None else int( result[1]) / 100 handicap_data.betCount = result[2] handicap_data.avgBetCount = 0 if handicap_data.betUsers == 0 else handicap_data.betCount / handicap_data.betUsers # todo 盘口抽水 handicap_data.handicapWater = handicap_data.betCoin * 0.15 objRep.handicapData.append(handicap_data) login_count_sql = login_count_sql + " AND agentId='{}' ".format( channel) new_reg_count_sql = new_reg_count_sql + " AND agentId='{}' ".format( channel) bet_count_sql = bet_count_sql + " AND agentId='{}' ".format( channel) before_users_sql = before_users_sql + " AND agentId='{}' ".format( channel) after_users_sql = after_users_sql + " AND agentId='" + channel + "' " valid_water_sql = valid_water_sql + " AND agentId='{}' ".format( channel) win_bet_count_sql = win_bet_count_sql + " AND agentId='{}' ".format( channel) else: for game in gameNames: handicap_data = cData2() handicap_data.gameName = game # 下注人数,总下注额,注单数 handicap_sql = "select COUNT(DISTINCT(accountId)),sum(betCoinNum),COUNT(id) from dj_betresultbill WHERE resultTime BETWEEN {} AND {} AND guessName='{}' ".format( startTime, endTime, game) if game == '平博': handicap_sql = "select COUNT(DISTINCT(loginId)),sum(toRisk),COUNT(wagerId) from dj_pingbobetbill WHERE wagerDateFm BETWEEN {} AND {} ".format( startTime, endTime) listRest = yield from conn._exeCute(handicap_sql) result = yield from listRest.fetchone() handicap_data.betUsers = result[0] handicap_data.betCoin = 0 if result[1] is None else int( result[1]) handicap_data.betCount = result[2] handicap_data.avgBetCount = 0 if handicap_data.betUsers == 0 else round( handicap_data.betCount / handicap_data.betUsers, 2) #todo 盘口抽水 handicap_data.handicapWater = round( handicap_data.betCoin * 0.15, 2) objRep.handicapData.append(handicap_data) listRest = yield from conn._exeCute(login_count_sql) login_count = yield from listRest.fetchone() over_all_data.loginCount = login_count[0] listRest = yield from conn._exeCute(new_reg_count_sql) reg_count = yield from listRest.fetchone() over_all_data.regCount = reg_count[0] listRest = yield from conn._exeCute(bet_count_sql) bet_count = yield from listRest.fetchone() over_all_data.betCount = bet_count[0] over_all_data.totalBetCount = bet_count[1] over_all_data.totalWater = 0 if bet_count[2] is None else int( bet_count[2]) / 100 over_all_data.returnAwardCoin = 0 if bet_count[3] is None else int( bet_count[3]) / 100 listRest = yield from conn._exeCute(before_users_sql) before_users = yield from listRest.fetchall() before_accountIds = [] for x in before_users: before_accountIds.append(x[0]) if len(before_accountIds) == 0: #todo 可以优化 after_users_sql = "select accountId from dj_betresultbill WHERE resultTime BETWEEN {} AND {} ".format( startTime, endTime) if channel: after_users_sql = "select accountId from dj_betresultbill WHERE agentId='{}' AND resultTime BETWEEN {} AND {} ".format( channel, startTime, endTime) elif len(before_accountIds) == 1: before_accountIds = str(tuple(before_accountIds)).replace(r',', '') after_users_sql = after_users_sql.format(before_accountIds) else: before_accountIds = tuple(before_accountIds) after_users_sql = after_users_sql.format(before_accountIds) listRest = yield from conn._exeCute(after_users_sql) after_users = yield from listRest.fetchall() after_accountIds = [] for x in after_users: after_accountIds.append(x[0]) if len(after_accountIds) == 0: over_all_data.newBetCount = 0 elif len(after_accountIds) == 1: after_accountIds = str(tuple(after_accountIds)).replace(r',', '') # 新增投注用户数 new_bet_count_sql = "select COUNT(accountId) from dj_betresultbill WHERE accountId in {} AND resultTime BETWEEN {} AND {}".format( after_accountIds, startTime, endTime) listRest = yield from conn._exeCute(new_bet_count_sql) new_bet_count = yield from listRest.fetchone() over_all_data.newBetCount = new_bet_count[0] else: after_accountIds = tuple(after_accountIds) # 新增投注用户数 new_bet_count_sql = "select COUNT(accountId) from dj_betresultbill WHERE accountId in {} AND resultTime BETWEEN {} AND {}".format( after_accountIds, startTime, endTime) listRest = yield from conn._exeCute(new_bet_count_sql) new_bet_count = yield from listRest.fetchone() over_all_data.newBetCount = new_bet_count[0] listRest = yield from conn._exeCute(valid_water_sql) valid_water = yield from listRest.fetchone() over_all_data.validWater = 0 if valid_water[0] is None else int( valid_water[0]) / 100 listRest = yield from conn._exeCute(win_bet_count_sql) win_bet_count = yield from listRest.fetchone() win_bet_count = win_bet_count[0] #todo 盘口抽水 over_all_data.handicapWater = over_all_data.totalWater * 0.15 #平均投注笔数 over_all_data.avgBetCount = 0 if over_all_data.betCount == 0 else round( over_all_data.totalBetCount / over_all_data.betCount, 2) #盈亏 over_all_data.profitLoss = over_all_data.totalWater - over_all_data.returnAwardCoin #盈亏比 over_all_data.profitLossRatio = 0 if over_all_data.totalWater == 0 else "%.3f" % round( over_all_data.profitLoss / over_all_data.totalWater, 3) #注单中奖率 over_all_data.betWinRate = 0 if over_all_data.totalBetCount == 0 else win_bet_count / over_all_data.totalBetCount objRep.overAllData = over_all_data fileName = __name__ nameList = fileName.split('.') methodName = nameList.pop() # 日志 dictActionBill = { 'billType': 'adminActionBill', 'accountId': request.get('accountId', ''), 'action': "投注数据查询", 'actionTime': getNow(), 'actionMethod': methodName, 'actionDetail': "投注数据查询", 'actionIp': request.get('srcIp', ''), } logging.getLogger('bill').info(json.dumps(dictActionBill)) return classJsonDump.dumps(objRep) except Exception as e: logging.exception(e) raise exceptionLogic(errorLogic.db_error)
def handleGuessBet(objHead: classSSHead, objFbReq: dict): objResp = protoGuessBetResp() try: # 查找用户数据 if cpv.checkStringEmpty(objHead.strAccountId): raise exceptionLogic(errorLogic.player_account_id_empty) if not cpv.checkIsString(objHead.strToken): raise exceptionLogic(errorLogic.client_param_invalid) if cpv.checkStringEmpty(objHead.strToken): raise exceptionLogic(errorLogic.client_param_invalid) # 将客户端发来的请求参数及值经过处理后获取相应值 iBetCoin, strMatchId, strBetChooseId, strGuessId, fBetRate, iBetRateIgnore = cpv.getDictStrParam( objFbReq, 'iBetCoin', 'strMatchId', 'strChooseId', "strGuessId", "fBetRate", "iBetRateIgnore") if not cpv.checkIsInt(iBetCoin): raise exceptionLogic(errorLogic.client_param_invalid) #默认转成元单位 iBetCoin *= 100 if not cpv.checkIsString(strMatchId): raise exceptionLogic(errorLogic.client_param_invalid) if not cpv.checkIsString(strBetChooseId): raise exceptionLogic(errorLogic.client_param_invalid) if not cpv.checkIsString(strGuessId): raise exceptionLogic(errorLogic.client_param_invalid) if fBetRate is not None: fBetRate = float(fBetRate) if not cpv.checkIsFloat(fBetRate): raise exceptionLogic(errorLogic.client_param_invalid) if iBetRateIgnore is not None: if not cpv.checkIsInt(iBetRateIgnore): raise exceptionLogic(errorLogic.client_param_invalid) except: raise exceptionLogic(errorLogic.client_param_invalid) # 查看最小押注额度 if iBetCoin < 1000 or iBetCoin > 200000: raise exceptionLogic(errorLogic.guess_bet_num_min_limit) # 查看是否限制本题的竞猜 iAlreadyBetNum = yield from classDataBaseMgr.getInstance( ).getAccountGuessBet(objHead.strAccountId, strGuessId) objPlayerData, strPlayerDataLock, objMatchData, objGuess, strGuessLock = yield from classDataBaseMgr.getInstance( ).getBetData(objHead.strAccountId, strMatchId, strGuessId) try: if objPlayerData is None: # 用户不存在 raise exceptionLogic(errorLogic.player_data_not_found) """ if objPlayerData.strToken != objHead.strToken: # 鉴权信息已过期 raise exceptionLogic(errorLogic.login_token_not_valid) """ if objMatchData is None: # 比赛不存在 raise exceptionLogic(errorLogic.match_data_not_found) if objMatchData.iMatchState >= 3: # 比赛已结束 raise exceptionLogic(errorLogic.match_state_close) if objGuess is None: raise exceptionLogic(errorLogic.match_guess_not_found) # 竞猜不存在 else: if objGuess.iGuessState >= 1: raise exceptionLogic( errorLogic.match_guess_state_close) # 本竞猜已封盘 if (iAlreadyBetNum + iBetCoin) > objGuess.iLimitPerAccount: raise exceptionLogic([ errorLogic.guess_bet_num_max_limit[0], errorLogic.guess_bet_num_max_limit[1].format(iAlreadyBetNum) ]) if strBetChooseId not in objGuess.dictCTR: raise exceptionLogic(errorLogic.match_guess_not_found) # 竞猜未找到 if objPlayerData.iGuessCoin < iBetCoin: raise exceptionLogic(errorLogic.player_coin_not_enough) # 用户金币不足 fCurrentRate = round(objGuess.dictCTR[strBetChooseId].fRate, 2) # 不忽略赔率变化 iBillCoinBeforeBet = objPlayerData.iBetCoin objPlayerData.iGuessCoin -= iBetCoin objNewBetHis = classUserBetHistory() # 竞猜id由 uuid4组成 objNewBetHis.strGuessUId = orderGeneral.generalOrderId() objNewBetHis.iBetCoin = iBetCoin objNewBetHis.strMatchId = strMatchId objNewBetHis.strMatchType = objMatchData.strMatchType objNewBetHis.strGuessId = strGuessId objNewBetHis.strGuessName = objGuess.strGuessName objNewBetHis.iRoundNum = objGuess.iRoundNum objNewBetHis.iTime = timeHelp.getNow() objNewBetHis.strChooseId = strBetChooseId objNewBetHis.strAccountId = objPlayerData.strAccountId objNewBetHis.strTeamAName = objMatchData.strTeamAName objNewBetHis.strTeamBName = objMatchData.strTeamBName # 竞猜id,竞猜信息 for var_id, var_crt in objGuess.dictCTR.items(): objBetCTR = classBetCTR() objBetCTR.strId = var_id objBetCTR.fRate = var_crt.fRate objBetCTR.strChooseName = var_crt.strChooseName objNewBetHis.dictCTR[var_id] = objBetCTR objGuess.dictCTR[strBetChooseId].iTotalCoin += iBetCoin objGuess.dictCTR[strBetChooseId].iTotalBetNum += 1 objGuess.dictCTR[strBetChooseId].iReturnCoin += ( iBetCoin * objGuess.dictCTR[strBetChooseId].fRate) except: # 要把锁都还回去 if objPlayerData is not None: yield from classDataBaseMgr.getInstance().releasePlayerDataLock( objPlayerData.strAccountId, strPlayerDataLock) if objGuess is not None: yield from classDataBaseMgr.getInstance().releaseGuessLock( objGuess.strGuessId, strGuessLock) raise # 将当前用户的竞猜信息插入DB iNowTime = timeHelp.getNow() yield from classDataBaseMgr.getInstance().addBetData( strBetChooseId, objGuess, objPlayerData, strGuessLock, strPlayerDataLock, objNewBetHis, iNowTime) # 推送用户当前的金币 #yield from pushPlayerCoin(objPlayerData.strAccountId,objPlayerData.iCoin) # 添加后台统计柱状图,统一去重用户的押注量,押注用户统计 fGraphIndex = gmProtocol.getGraphIndex(fCurrentRate) yield from classDataBaseMgr.getInstance().addGraphBetRange( objPlayerData.strAccountId, strMatchId, strGuessId, iBetCoin, fGraphIndex, strBetChooseId, iNowTime, fCurrentRate) # 写入金币消耗日志 if objGuess.iRoundNum == 0: coinHisDes = "本场比赛\n {}\n {}".format( objGuess.strGuessName, objGuess.dictCTR[strBetChooseId].strChooseName) else: coinHisDes = "{}局\n {}\n {}".format( objGuess.iRoundNum, objGuess.strGuessName, objGuess.dictCTR[strBetChooseId].strChooseName) #gmProtocol.gameTypeMap.get(objMatchData.strMatchType) # 给用户推送一下投注单 yield from pushPlayerData(objPlayerData, objNewBetHis) logging.getLogger('logic').info("bet account[{}] ip[{}]".format( objPlayerData.strAccountId, objHead.strClientIp)) dictBill = { 'billType': "betBill", 'betHisUId': objNewBetHis.strGuessUId, 'accountId': objPlayerData.strAccountId, 'agentId': objPlayerData.strAgentId, #'nick': objPlayerData.strNick, 'matchId': objMatchData.strMatchId, 'guessId': objGuess.strGuessId, 'roundNum': objGuess.iRoundNum, 'supportType': strBetChooseId, 'betCoinNum': iBetCoin, #竞猜金额 'coinBeforeBet': iBillCoinBeforeBet, 'coinAfterBet': objPlayerData.iBetCoin, 'projectType': objMatchData.strMatchType, 'betTime': timeHelp.getNow(), } logging.getLogger('bill').info(json.dumps(dictBill)) return objResp
def handleHttp(request: dict): """获取新增用户数据""" objRep = cResp() channel = request.get('channel', '') startTime = request.get('startTime', 0) endTime = request.get('endTime', 0) pn = request.get('pn', 1) if not all([startTime, endTime]): logging.debug(errorLogic.client_param_invalid) raise exceptionLogic(errorLogic.client_param_invalid) if (not checkIsInt(startTime)) or (not checkIsInt(endTime)) or ( not checkIsInt(pn)): logging.debug(errorLogic.client_param_invalid) raise exceptionLogic(errorLogic.client_param_invalid) try: conn = classSqlBaseMgr.getInstance(instanceName='probet_oss') endTime = endTime + 24 * 3600 days = (endTime - startTime) / (24 * 3600) days = int(days) for x in range((pn - 1) * MSG_PAGE_COUNT, pn * MSG_PAGE_COUNT): if x >= days: break data = cData() #时间 data.time = startTime + x * 24 * 3600 if channel: new_sql = "select accountId from dj_regbill WHERE dj_regbill.regTime BETWEEN {} AND {} AND dj_regbill.agentId='{}' ".format( startTime + x * 24 * 3600, startTime + (x + 1) * 24 * 3600, channel) else: new_sql = "select accountId from dj_regbill WHERE dj_regbill.regTime BETWEEN {} AND {} ".format( startTime + x * 24 * 3600, startTime + (x + 1) * 24 * 3600) listRest = yield from conn._exeCute(new_sql) idList = yield from listRest.fetchall() #新增用户 data.newAccountCount = len(idList) pinboNewIds = ['probet.' + accountId[0] for accountId in idList] #新增登陆数 sql = "select count(DISTINCT(accountId)) from dj_loginbill WHERE dj_loginbill.accountId in (" + new_sql + ") AND dj_loginbill.loginTime BETWEEN {} AND {} ".format( startTime + x * 24 * 3600, startTime + (x + 1) * 24 * 3600) listRest = yield from conn._exeCute(sql) newLoginCount = yield from listRest.fetchone() data.newLoginCount = newLoginCount[0] #新增用户充值人数 sql = "select count(DISTINCT(accountId)) from dj_paybill WHERE dj_paybill.accountId in (" + new_sql + ") AND dj_paybill.payTime BETWEEN {} AND {} ".format( startTime + x * 24 * 3600, startTime + (x + 1) * 24 * 3600) listRest = yield from conn._exeCute(sql) rechargeCount = yield from listRest.fetchone() data.rechargeCount = rechargeCount[0] #付费渗透 data.payPenetration = "%.2f" % round( 0, 2) if data.newLoginCount == 0 else "%.2f" % round( data.rechargeCount / data.newLoginCount, 2) #新增用户总流水,派奖金额 sql = "select sum(betCoinNum),sum(winCoin) from dj_betresultbill WHERE dj_betresultbill.accountId in (" + new_sql + ") AND dj_betresultbill.resultTime BETWEEN {} AND {} ".format( startTime + x * 24 * 3600, startTime + (x + 1) * 24 * 3600) if len(pinboNewIds) == 0: pin_water = 0 pin_award = 0 pin_valid_water = 0 else: if len(pinboNewIds) == 1: pinNewIds = str(tuple(pinboNewIds)).replace(r',', '', 1) else: pinNewIds = tuple(pinboNewIds) pin_water_sql = "select sum(toRisk),sum(CASE WHEN winLoss>0 THEN winLoss ELSE 0 END) from dj_pingbobetbill WHERE loginId in {} AND status='SETTLED' AND wagerDateFm BETWEEN {} AND {} ".format( pinNewIds, startTime + x * 24 * 3600, startTime + (x + 1) * 24 * 3600) pinRet = yield from conn._exeCute(pin_water_sql) pin_water_win = yield from pinRet.fetchone() pin_water = 0 if pin_water_win[0] is None else pin_water_win[0] pin_award = 0 if pin_water_win[1] is None else pin_water_win[1] pin_valid_water = yield from getPingboValidWaterByParams( loginIds=pinboNewIds, startTime=(startTime + x * 24 * 3600), endTime=(startTime + (x + 1) * 24 * 3600)) listRest = yield from conn._exeCute(sql) totalWater = yield from listRest.fetchone() pro_water = round(0, 2) if totalWater[0] is None else round( int(totalWater[0]) / 100, 2) pro_award = round(0, 2) if totalWater[1] is None else round( int(totalWater[1]) / 100, 2) data.awardNum = pro_award + pin_award data.newTotalWater = pro_water + pin_water #新增用户有效流水:赔率在1.5倍以上的投注单 todo 亚赔,欧赔,平博和自己平台不一样 sql = "select sum(betCoinNum) from dj_betresultbill WHERE dj_betresultbill.rate>=1.5 AND dj_betresultbill.accountId IN (" + new_sql + ") AND dj_betresultbill.resultTime BETWEEN {} AND {} ".format( startTime + x * 24 * 3600, startTime + (x + 1) * 24 * 3600) listRest = yield from conn._exeCute(sql) validWater = yield from listRest.fetchone() pro_valid_water = round(0, 2) if validWater[0] is None else round( int(validWater[0]) / 100, 2) data.newValidWater = pin_valid_water + pro_valid_water #新增用户抽水 todo data.newPumpingWater = "%.2f" % round(data.newTotalWater * 0.15, 2) #新增用户存款 sql = "select sum(payCoin) from dj_paybill WHERE dj_paybill.accountId in (" + new_sql + ") AND dj_paybill.payTime BETWEEN {} AND {} ".format( startTime + x * 24 * 3600, startTime + (x + 1) * 24 * 3600) listRest = yield from conn._exeCute(sql) newRecharge = yield from listRest.fetchone() data.newRecharge = round(0, 2) if newRecharge[0] is None else round( int(newRecharge[0]) / 100, 2) #新增用户提款 sql = "select sum(withdrawalCoin) from dj_withdrawalbill WHERE dj_withdrawalbill.accountId in (" + new_sql + ") AND dj_withdrawalbill.withdrawalTime BETWEEN {} AND {} ".format( startTime + x * 24 * 3600, startTime + (x + 1) * 24 * 3600) listRest = yield from conn._exeCute(sql) newWithdrawal = yield from listRest.fetchone() data.newWithdrawal = 0 if newWithdrawal[0] is None else int( newWithdrawal[0]) / 100 #投注收入=总流水 data.betAvail = data.newTotalWater #盈亏 data.profitLoss = data.betAvail - data.awardNum #盈亏比 # 盈亏比:盈亏/投注收入 data.profitLossRatio = "%.2f" % round( 0, 2) if data.betAvail == 0 else "%.2f" % round( data.profitLoss / data.betAvail, 2) #LTV:新增用户存款/新增用户数 data.LTV = "%.2f" % round( 0, 2) if data.newAccountCount == 0 else "%.2f" % round( data.newRecharge / data.newAccountCount, 2) objRep.data.append(data) objRep.count = days if pn == 1: fileName = __name__ nameList = fileName.split('.') methodName = nameList.pop() # 日志 dictActionBill = { 'billType': 'adminActionBill', 'accountId': request.get('accountId', ''), 'action': "查询新增账户数据", 'actionTime': getNow(), 'actionMethod': methodName, 'actionDetail': "查询新增账户数据", 'actionIp': request.get('srcIp', ''), } logging.getLogger('bill').info(json.dumps(dictActionBill)) return classJsonDump.dumps(objRep) except Exception as e: logging.exception(e) raise exceptionLogic(errorLogic.db_error)
def handleHttp(request: dict): """获取实时数据""" days=request.get('days',0) startTime = getTimeOClockOfToday() endTime = getNow() objRep = cResp() if not checkIsInt(days): logging.debug(errorLogic.client_param_invalid) raise exceptionLogic(errorLogic.client_param_invalid) if days not in [0,3,5,7,30]: logging.debug(errorLogic.client_param_invalid) raise exceptionLogic(errorLogic.client_param_invalid) if days: if days==30: startTime=monthStartTimestamp() else: startTime=startTime-days*24*3600 #运营实时数据sql reg_count_sql="select count(id) from dj_regbill" today_login_sql="select count(DISTINCT(accountId)) from dj_loginbill WHERE loginTime BETWEEN {} AND {}".format(startTime,endTime) today_new_sql="select count(id) from dj_regbill where regTime BETWEEN {} AND {}".format(startTime,endTime) recharge_sql="select count(DISTINCT(accountId)) from dj_paybill" today_recharge_sql="select count(DISTINCT(accountId)) from dj_paybill WHERE payTime BETWEEN {} AND {}".format(startTime,endTime) today_pro_water_award_sql="select sum(betCoinNum),sum(winCoin) from dj_betresultbill WHERE resultTime BETWEEN {} AND {}".format(startTime,endTime) today_pin_water_award_sql="select sum(toRisk),sum(CASE WHEN winLoss>0 THEN winLoss ELSE 0 END) from dj_pingbobetbill WHERE wagerDateFm BETWEEN {} AND {} AND status='SETTLED'".format(startTime,endTime) pro_valid_water_sql="select sum(betCoinNum) from dj_betresultbill WHERE resultTime BETWEEN {} AND {} AND rate>=1.5".format(startTime,endTime) withdrawal_sql="select sum(withdrawalCoin) from dj_withdrawalbill WHERE withdrawalTime BETWEEN {} AND {}".format(startTime,endTime) total_recharge_sql="select sum(payCoin) from dj_paybill WHERE payTime BETWEEN {} AND {} ".format(startTime,endTime) new_recharge_sql="select DISTINCT(accountId) from dj_paybill WHERE accountId not IN (SELECT accountId from dj_paybill WHERE payTime<{}) AND payTime BETWEEN {} AND {}".format(startTime,startTime,endTime) new_recharge_coin_sql="select sum(payCoin) from dj_paybill WHERE accountId IN ("+new_recharge_sql+") and payTime between {} and {} ".format(startTime,endTime) #代理实时数据sql agent_count_sql="select count(agentId) from dj_agent" agent_new_sql="select count(agentId) from dj_agent WHERE regTime BETWEEN {} AND {}".format(startTime,endTime) today_new_offline_sql="select count(accountId) from dj_regbill WHERE agentId!='' AND regTime BETWEEN {} AND {}".format(startTime,endTime) #线下总输赢 vip_win_loss_sql="select sum(betCoinNum),sum(winCoin) from dj_betresultbill WHERE agentId!='' AND resultTime BETWEEN {} AND {}".format(startTime,endTime) agent_bet_award_sql="select sum(betCoinNum),sum(winCoin) from dj_betresultbill WHERE agentId!='' AND resultTime BETWEEN {} AND {}".format(startTime,endTime) agent_withdrawal_sql="select sum(withdrawalCoin) from dj_withdrawalbill WHERE userType=2 AND withdrawalTime BETWEEN {} AND {}".format(startTime,endTime) try: operation_data=cData1() agent_data=cData2() with (yield from classSqlBaseMgr.getInstance(instanceName='probet_oss').objDbMysqlMgr) as conn: #注册总数 reg_count=yield from conn.execute(reg_count_sql) reg_total_count=yield from reg_count.fetchone() operation_data.totalReg=reg_total_count[0] #今日登录数 today_login=yield from conn.execute(today_login_sql) login_count=yield from today_login.fetchone() operation_data.todayLogin=login_count[0] #今日新增数 today_reg=yield from conn.execute(today_new_sql) new_reg=yield from today_reg.fetchone() operation_data.todayNew=new_reg[0] #充值总数 recharge_count=yield from conn.execute(recharge_sql) total_recharge=yield from recharge_count.fetchone() operation_data.RechargeCount=total_recharge[0] #今日充值数 today_recharge_count=yield from conn.execute(today_recharge_sql) today_recharge=yield from today_recharge_count.fetchone() operation_data.todayRecharge=today_recharge[0] #今日流水:平博今日流水+Probet流水 today_pro_water_award=yield from conn.execute(today_pro_water_award_sql) pro_water_award=yield from today_pro_water_award.fetchone() today_pin_water_award=yield from conn.execute(today_pin_water_award_sql) pin_water_award=yield from today_pin_water_award.fetchone() pin_water=0 if pin_water_award[0] is None else pin_water_award[0] pro_water=0 if pro_water_award[0] is None else int(pro_water_award[0])/100 operation_data.todayWater=round(pin_water+pro_water,2) #今日有效流水:平博有效流水+Probet有效流水 欧赔+亚赔 pinValidWater=yield from getPingboValidWaterByParams(loginIds=None,startTime=startTime,endTime=endTime) today_pro_valid_water=yield from conn.execute(pro_valid_water_sql) pro_valid_water=yield from today_pro_valid_water.fetchone() proValidWater=0 if pro_valid_water[0] is None else int(pro_valid_water[0])/100 operation_data.todayValidWater=round(pinValidWater+proValidWater,2) #今日抽水:总流水*0.15 todo operation_data.todayPumping=round(operation_data.todayWater*0.15,2) #总充值数 total_recharge_ret=yield from conn.execute(total_recharge_sql) totalRechargeRes=yield from total_recharge_ret.fetchone() operation_data.totalRecharge=0 if totalRechargeRes[0] is None else int(totalRechargeRes[0])/100 #新增充值人数 new_recharge_ret=yield from conn.execute(new_recharge_sql) newRechargeRes=yield from new_recharge_ret.fetchall() operation_data.newRecharge=len(newRechargeRes) #新增充值人数充值额度 new_recharge_coin_ret=yield from conn.execute(new_recharge_coin_sql) newRechargeCoinRes=yield from new_recharge_coin_ret.fetchone() operation_data.newRechargeCoin=0 if newRechargeCoinRes[0] is None else int(newRechargeCoinRes[0])/100 #今日派奖 pin_award=0 if pin_water_award[1] is None else pin_water_award[1] pro_award=0 if pro_water_award[1] is None else int(pro_water_award[1])/100 operation_data.todayAward=round(pin_award+pro_award,2) #提款 withdrawal=yield from conn.execute(withdrawal_sql) withdrawal_count=yield from withdrawal.fetchone() operation_data.withdrawal=0 if withdrawal_count[0] is None else int(withdrawal_count[0])/100 #盈亏:总投注-总派奖 operation_data.winLoss=round(operation_data.todayWater-operation_data.todayAward,2) #vip总输赢 vip_win_loss=yield from conn.execute(vip_win_loss_sql) vip_total_win=yield from vip_win_loss.fetchone() vip_bet_total=0 if vip_total_win[0] is None else int(vip_total_win[0])/100 vip_win_total=0 if vip_total_win[1] is None else int(vip_total_win[1])/100 agent_data.vipWinLoss=vip_bet_total-vip_win_total #代理提款 agent_withdrawal=yield from conn.execute(agent_withdrawal_sql) agentWithdrawal=yield from agent_withdrawal.fetchone() agent_data.withdrawal=0 if agentWithdrawal[0] is None else int(agentWithdrawal[0])/100 #代理总输赢:总投注-总派奖 agent_total_win=yield from conn.execute(agent_bet_award_sql) ag_total_win=yield from agent_total_win.fetchone() ag_bet_total=0 if ag_total_win[0] is None else int(ag_total_win[0])/100 ag_award_total=0 if ag_total_win[1] is None else int(ag_total_win[1])/100 agent_data.winLoss=ag_bet_total-ag_award_total #今日新增线下 today_new_offline=yield from conn.execute(today_new_offline_sql) new_offline=yield from today_new_offline.fetchone() agent_data.vipNew=new_offline[0] with(yield from classSqlBaseMgr.getInstance().objDbMysqlMgr) as connect: #代理数据1.代理总数 agent_count=yield from connect.execute(agent_count_sql) total_agent=yield from agent_count.fetchone() agent_data.agentCount=total_agent[0] #新增代理 new_agent=yield from connect.execute(agent_new_sql) new_agents=yield from new_agent.fetchone() agent_data.agentNew=new_agents[0] objRep.agentData = agent_data objRep.operationData = operation_data if days==0: fileName = __name__ nameList = fileName.split('.') methodName = nameList.pop() # 日志 dictActionBill = { 'billType': 'adminActionBill', 'accountId': request.get('accountId', ''), 'action': "查询实时数据", 'actionTime': getNow(), 'actionMethod': methodName, 'actionDetail': "查询实时数据", 'actionIp': request.get('srcIp', ''), } logging.getLogger('bill').info(json.dumps(dictActionBill)) return classJsonDump.dumps(objRep) except Exception as e: logging.exception(e) raise exceptionLogic(errorLogic.db_error)
def handleHttp(dict_param: dict): """转账""" objRsp = cResp() strAccountId = dict_param.get("accountId", "") TurnOut = dict_param.get("Turnout", "") TurnIn = dict_param.get("Turnin", "") money = dict_param.get("money", "") if not all([TurnOut, TurnIn, money]): raise exceptionLogic(errorLogic.client_param_invalid) if cpv.checkIsString(money): raise exceptionLogic(errorLogic.client_param_invalid) fMoney = float(money) if not cpv.checkIsFloat(fMoney): raise exceptionLogic(errorLogic.client_param_invalid) fMoney = float("%.2f" % fMoney) iCoin = int(fMoney * 100) if not cpv.checkIsInt(iCoin): raise exceptionLogic(errorLogic.client_param_invalid) if TurnOut != "中心钱包" and TurnIn != "中心钱包": raise exceptionLogic(errorLogic.client_param_invalid) objPlayerData, objLock = yield from classDataBaseMgr.getInstance( ).getPlayerDataByLock(strAccountId) tradeData = None if TurnOut == "中心钱包" and TurnIn == "平博钱包": if iCoin > int(objPlayerData.iCoin): raise exceptionLogic(errorLogic.player_coin_not_enough) objPlayerData.iCoin -= iCoin iBalance = objPlayerData.iCoin - iCoin # 触发另一个平台的转账功能 status = yield from pinboDeposit.deposit(kind='deposit', accountId=strAccountId, amount=fMoney) if status == 1: objPlayerData.iPingboCoin += iCoin yield from classDataBaseMgr.getInstance().setPlayerDataByLock( objPlayerData, objLock) tradeData = yield from addPlayerBill(strAccountId, iCoin, iBalance, CoinOp.coinOpTrans, status, TurnOut, TurnIn) elif TurnOut == "中心钱包" and TurnIn == "电竞钱包": if iCoin > int(objPlayerData.iCoin): raise exceptionLogic(errorLogic.player_coin_not_enough) objPlayerData.iCoin -= iCoin objPlayerData.iGuessCoin += iCoin iBalance = objPlayerData.iCoin - iCoin yield from classDataBaseMgr.getInstance().setPlayerDataByLock( objPlayerData, objLock) tradeData = yield from addPlayerBill(strAccountId, iCoin, iBalance, CoinOp.coinOpTrans, 1, TurnOut, TurnIn) elif TurnIn == "中心钱包" and TurnOut == "平博钱包": # 触发另一个平台的转账功能 status = yield from pinboDeposit.deposit(kind='withdraw', accountId=strAccountId, amount=fMoney) if status == 1: objPlayerData.iCoin += iCoin objPlayerData.iPingboCoin -= iCoin iBalance = objPlayerData.iCoin + iCoin yield from classDataBaseMgr.getInstance().setPlayerDataByLock( objPlayerData, objLock) tradeData = yield from addPlayerBill(strAccountId, iCoin, iBalance, CoinOp.coinOpTrans, status, TurnOut, TurnIn) elif TurnIn == "中心钱包" and TurnOut == "电竞钱包": if iCoin > int(objPlayerData.iGuessCoin): raise exceptionLogic(errorLogic.player_coin_not_enough) objPlayerData.iCoin += iCoin objPlayerData.iGuessCoin -= iCoin iBalance = objPlayerData.iCoin + iCoin yield from classDataBaseMgr.getInstance().setPlayerDataByLock( objPlayerData, objLock) tradeData = yield from addPlayerBill(strAccountId, iCoin, iBalance, CoinOp.coinOpTrans, 1, TurnOut, TurnIn) else: logging.error("unkown trun way {} {}".format(TurnIn, TurnOut)) objRsp.data = cData() objRsp.data.iCoin = "%.2f" % round(objPlayerData.iCoin / 100, 2) objRsp.data.iGuessCoin = "%.2f" % round(objPlayerData.iGuessCoin / 100, 2) tradeData.iCoin = float("%.2f" % round(tradeData.iCoin / 100, 2)) objRsp.data.orderdata = tradeData return classJsonDump.dumps(objRsp)
def handleHttp(request: dict): """玩法数据查询""" objRep = cResp() game = request.get('game', '') startTime = request.get('startTime', 0) endTime = request.get('endTime', 0) playName = request.get('playName', '') channel = request.get('channel') pn = request.get('pn', 1) if (not startTime) and (not endTime): logging.debug(errorLogic.client_param_invalid) raise exceptionLogic(errorLogic.client_param_invalid) if (not checkIsInt(startTime)) or (not checkIsInt(endTime)): logging.debug(errorLogic.client_param_invalid) raise exceptionLogic(errorLogic.client_param_invalid) try: conn = classSqlBaseMgr.getInstance(instanceName='probet_oss') resp_list = [] # 没传查全部游戏 gameNames = [] if game == '': gameNames.extend(gameType) gameNames.append("pingbo") else: gameNames.append(game) #游戏名称 for gameName in gameNames: playTypes = [] if playName: playTypes.append(playName) else: if gameName == "pingbo": for playType in pingboBetType.keys(): playTypes.append(playType) else: #查probet全部玩法 sql = "select DISTINCT(playType) from dj_betresultbill WHERE dj_betresultbill.GuessName='{}' ".format( gameName) listRest = yield from conn._exeCute(sql) play_types = yield from listRest.fetchall() if len(play_types) == 0: continue for playType in play_types: playTypes.append(playType[0]) for x in playTypes: data = cData() #游戏名 data.gameName = gameName #玩法名称 data.playType = x if gameName == "pingbo": data.playType = pingboBetType[int(x)] part1_sql = "select count(wagerId),COUNT(DISTINCT(loginId)),SUM(toRisk),SUM(CASE WHEN winLoss>0 THEN winLoss ELSE 0 END) from dj_pingbobetbill WHERE betType={} AND wagerDateFm BETWEEN {} AND {} AND status='SETTLED'".format( x, startTime, endTime) pingboValidWater = yield from getPingboValidWaterByParams( loginIds=None, startTime=startTime, endTime=endTime, betType=x) part3_sql = "select count(wagerId),COUNT(DISTINCT(loginId)) from dj_pingbobetbill WHERE winLoss>0 AND betType={} AND wagerDateFm BETWEEN {} AND {} ".format( x, startTime, endTime) if channel: pingboValidWater = yield from getPingboValidWaterByParams( loginIds=None, startTime=startTime, endTime=endTime, agentId=channel, betType=x) part1_sql = part1_sql + " and agentId='{}' ".format( channel) part3_sql = part3_sql + " and agentId='{}' ".format( channel) else: part1_sql = "select count(id),COUNT(DISTINCT(accountId)),SUM(betCoinNum),SUM(winCoin) from dj_betresultbill WHERE dj_betresultbill.GuessName='{}' AND dj_betresultbill.playType='{}' AND dj_betresultbill.resultTime BETWEEN {} AND {}".format( gameName, x, startTime, endTime) part2_sql = "select SUM(betCoinNum) from dj_betresultbill WHERE dj_betresultbill.GuessName='{}' AND dj_betresultbill.playType='{}' AND dj_betresultbill.resultTime BETWEEN {} AND {} AND dj_betresultbill.rate>=1.5".format( gameName, x, startTime, endTime) part3_sql = "select count(id),COUNT(DISTINCT(accountId)) from dj_betresultbill WHERE dj_betresultbill.winCoin>0 AND dj_betresultbill.GuessName='{}' AND dj_betresultbill.playType='{}' AND dj_betresultbill.resultTime BETWEEN {} AND {} ".format( gameName, x, startTime, endTime) if channel: part1_sql = part1_sql + " and agentId='{}' ".format( channel) part2_sql = part2_sql + " and agentId='{}' ".format( channel) part3_sql = part3_sql + " and agentId='{}' ".format( channel) # 总投注单数,总投注人数,总投注金额,派奖金额 listRest = yield from conn._exeCute(part1_sql) results = yield from listRest.fetchone() data.totalBet = results[0] data.totalAccount = results[1] if gameName == 'pingbo': data.totalBetCoin = 0 if results[2] is None else results[2] data.awardNum = 0 if results[3] is None else round( results[3], 2) #总有效投注额 data.totalValidCoin = pingboValidWater else: data.totalBetCoin = 0 if results[2] is None else int( results[2]) / 100 data.awardNum = 0 if results[3] is None else int( results[3]) / 100 # 总有效投注金额 listRest = yield from conn._exeCute(part2_sql) ret = yield from listRest.fetchone() data.totalValidCoin = 0 if ret[0] is None else int( ret[0]) / 100 # 注单均值 data.avgBetCoin = 0 if data.totalBet == 0 else round( data.totalBetCoin / data.totalBet, 2) #中奖注单数,中奖人数 listRest = yield from conn._exeCute(part3_sql) winCount = yield from listRest.fetchone() #注单中奖率 data.betRate = 0 if data.totalBet == 0 else int( winCount[0]) / data.totalBet #用户中奖率 data.userRate = 0 if data.totalAccount == 0 else int( winCount[1]) / data.totalAccount #中奖额占注额比重 data.winCoinRate = 0 if data.totalBetCoin == 0 else data.awardNum / data.totalBetCoin #盈亏 data.profitLoss = round((data.totalBetCoin - data.awardNum), 2) #盈亏比 data.profitLossRatio = 0 if data.totalBetCoin == 0 else data.profitLoss / data.totalBetCoin resp_list.append(data) objRep.count = len(resp_list) objRep.data = resp_list[(pn - 1) * MSG_PAGE_COUNT:pn * MSG_PAGE_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': "玩法数据查询", 'actionIp': request.get('srcIp', ''), } logging.getLogger('bill').info(json.dumps(dictActionBill)) return classJsonDump.dumps(objRep) except Exception as e: logging.exception(e) raise exceptionLogic(errorLogic.db_error)
def handleHttp(request: dict): """新增、删除,修改平台,存取款费率""" name = request.get('name', '') kind = request.get('kind') rate = request.get('rate', 0) action = request.get('action', '') if not all([name, action]): logging.debug(errorLogic.client_param_invalid) raise exceptionLogic(errorLogic.client_param_invalid) if action not in ['del', 'add']: logging.debug(errorLogic.client_param_invalid) raise exceptionLogic(errorLogic.client_param_invalid) try: if action == 'del': #删除 if not name: logging.debug(errorLogic.client_param_invalid) raise exceptionLogic(errorLogic.client_param_invalid) ret = yield from classDataBaseMgr.getInstance().delAgentConfig( name) if ret <= 0: logging.debug(errorLogic.data_not_valid) raise exceptionLogic(errorLogic.data_not_valid) else: #新增或修改 if not all([name, rate, kind]): logging.debug(errorLogic.client_param_invalid) raise exceptionLogic(errorLogic.client_param_invalid) if not checkIsInt(rate): logging.debug(errorLogic.client_param_invalid) raise exceptionLogic(errorLogic.client_param_invalid) agentConfigClass = classConfig() agentConfigClass.strName = name agentConfigClass.iRate = rate agentConfigClass.iKind = kind yield from classDataBaseMgr.getInstance().addAgentConfig( agentConfigClass) resp = cResp() fileName = __name__ nameList = fileName.split('.') methodName = nameList.pop() # 日志 dictActionBill = { 'billType': 'adminActionBill', 'accountId': request.get('accountId', ''), 'action': "新增/修改:{} 费率:{}".format(name, rate) if action == 'add' else "删除:{} 费率".format(name), 'actionTime': timeHelp.getNow(), 'actionMethod': methodName, 'actionDetail': "新增/修改:{} 费率 :{}".format(name, rate) if action == 'add' else "删除:{} 费率".format(name), 'actionIp': request.get('srcIp', ''), } logging.getLogger('bill').info(json.dumps(dictActionBill)) return classJsonDump.dumps(resp) except exceptionLogic as e: logging.error(repr(e)) raise e
def handleHttp(request: dict): """根据时间,渠道获取留存数据""" channel = request.get('channel', '') startTime = request.get('startTime', 0) endTime = request.get('endTime', 0) objRep = cResp() #TODO Warning: Truncated incorrect DOUBLE value: 'test1' if not all([startTime, endTime]): logging.debug(errorLogic.client_param_invalid) raise exceptionLogic(errorLogic.client_param_invalid) if (not checkIsInt(startTime)) or (not checkIsInt(endTime)): logging.debug(errorLogic.client_param_invalid) raise exceptionLogic(errorLogic.client_param_invalid) try: conn = classSqlBaseMgr.getInstance(instanceName='probet_oss') endTime = endTime + 24 * 3600 days = (endTime - startTime) / (24 * 3600) days = int(days) # 获取登录时间 留存:次日登录账号(在注册的账号中的)/当日注册的账号 for x in range(days): data = cData() #1.获取startTime注册账号量及accountId if channel: sql = "select accountId from dj_regbill WHERE dj_regbill.agentId='{}' AND dj_regbill.regTime BETWEEN {} AND {} ".format( channel, startTime + x * 24 * 3600, startTime + (x + 1) * 24 * 3600) else: sql = "select accountId from dj_regbill WHERE dj_regbill.regTime BETWEEN {} AND {} ".format( startTime + x * 24 * 3600, startTime + (x + 1) * 24 * 3600) listRest = yield from conn._exeCute(sql) idList = yield from listRest.fetchall() if len(idList) == 0: data.time = startTime + x * 24 * 3600 else: ids = [] for a in idList: ids.append(a[0]) if len(ids) == 1: ids = str(tuple(ids)).replace(r',', '') else: ids = tuple(ids) #注册量 reg_count = len(idList) data.regCount = reg_count data.time = startTime + x * 24 * 3600 # todo 60天后留存 90天后留存 day60_sql = "select count(DISTINCT(accountId)) from dj_loginbill WHERE dj_loginbill.accountId in {} AND dj_loginbill.loginTime BETWEEN {} AND {} ".format( ids, startTime + 60 * 24 * 3600, startTime + 61 * 24 * 3600) day90_sql = "select count(DISTINCT(accountId)) from dj_loginbill WHERE dj_loginbill.accountId in {} AND dj_loginbill.loginTime BETWEEN {} AND {} ".format( ids, startTime + 90 * 24 * 3600, startTime + 91 * 24 * 3600) day60Ret = yield from conn._exeCute(day60_sql) day60Res = yield from day60Ret.fetchone() data.day60 = "%.2f" % round( (day60Res[0] / reg_count) * 100, 2) + '%' day90Ret = yield from conn._exeCute(day90_sql) day90Res = yield from day90Ret.fetchone() data.day90 = "%.2f" % round( (day90Res[0] / reg_count) * 100, 2) + '%' loop_count = 1 loop_befor_count = 0 dtObj = datetime.fromtimestamp(startTime) month = dtObj.month while True: timeStamp = startTime - loop_befor_count * 24 * 3600 loop_now_month = datetime.fromtimestamp(timeStamp).month if loop_now_month != month: break data.retainRate.insert(0, [ startTime - loop_befor_count * 24 * 3600, "%.2f" % round(0, 2) + '%' ]) loop_befor_count += 1 while True: timeStamp = startTime + loop_count * 24 * 3600 loop_now_month = datetime.fromtimestamp(timeStamp).month if loop_now_month != month: #不是本月 break else: #是本月 sql = "select count(DISTINCT(accountId)) from dj_loginbill WHERE dj_loginbill.accountId in {} AND dj_loginbill.loginTime BETWEEN {} AND {} ".format( ids, startTime + loop_count * 24 * 3600, startTime + (loop_count + 1) * 24 * 3600) listRest = yield from conn._exeCute(sql) login_count = yield from listRest.fetchone() data.retainRate.append([ startTime + loop_count * 24 * 3600, "%.2f" % round( (login_count[0] / reg_count) * 100, 2) + '%' ]) loop_count += 1 objRep.data.append(data) objRep.count = days fileName = __name__ nameList = fileName.split('.') methodName = nameList.pop() # 日志 dictActionBill = { 'billType': 'adminActionBill', 'accountId': request.get('accountId', ''), 'action': "查询留存信息", 'actionTime': getNow(), 'actionMethod': methodName, 'actionDetail': "查询:{} 留存信息".format(channel), 'actionIp': request.get('srcIp', ''), } logging.getLogger('bill').info(json.dumps(dictActionBill)) return classJsonDump.dumps(objRep) except Exception as e: logging.exception(e) raise exceptionLogic(errorLogic.db_error)