def uninterrupted_Record(join_status, uninterrupted): """ 间断记录,超过十次不参加,则自动退出, # 表结构:用户iD 间断次数 续费补交 最后一次参加场次 ,超过十次 活跃状态置为不活跃 :param join_status: :param uninterrupted: :return: """ # todo 每次参加置为 0 ,不参加增加 1 ,超过 10 次 需计算续费补交,未超过补交为0 if join_status == "未参加": discontinuous_number = database.Search().discontinuous_number(uninterrupted["user_Id"]) discontinuous_number = discontinuous_number + 1 uninterrupted["discontinuous_number"] = discontinuous_number # 写入间断次数 database.Insert().ten_even_activities(uninterrupted) # discontinuous_number 大于10 用户置为不活跃 if discontinuous_number >= 10: database.Update().active_status(uninterrupted["user_Id"],'不活跃') else: uninterrupted["discontinuous_number"] = 0 database.Insert().ten_even_activities(uninterrupted) # discontinuous_number 小于10 用户置为活跃 database.Update().active_status(uninterrupted["user_Id"])
def five_even_activity(): """ 五连活动 连续5次没有捡到空投抽取10% :return: """ end_session = database.Search().end_session() continuously_list = database.Search().financial_accounts(end_session) activation_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) history_total = database.Search().total_income() # 结余 remaining_funds = history_total["remaining_funds"] for continuously in continuously_list: continuously["time"] = activation_time continuously["settlement_session"] = continuously["end_session"] continuously["settlement_status"] ="未结算" continuously["settlement_cost"] = remaining_funds* 0.1 database.Insert().five_even_activity(continuously)
def user_settlement(): """ 用户结算,更新用户基本信息表 :return: """ user_id_name, expenditure, revenue, surplus = database.Search().user_expenses_revenue_income() for user_Id,user_expenditure in expenditure.items(): total_sessions = len(user_expenditure) user_revenue = sum(revenue[user_Id]) user_surplus = sum(surplus[user_Id]) database.Update().basic_user_information(user_Id, total_sessions, sum(user_expenditure), user_revenue, user_surplus)
def settlement_five_even_activity(user_Id = 1,settlement_cost = 0): """ 结算连续5次未捡到空投 1.用户信息 + 3.个人账单 2.资金账单 - 4.连续未捡到 :return: """ # # settlement_cost = database.Search().uncleared_continuous_airdrop() # 更新 five_even_activity 表 database.Update().clearing_continuous_airdrop() history_total = database.Search().total_income() # 总收入 total_income = history_total["total_income"] # 总支出 total_expenditure = history_total["total_expenditure"] # 结余 remaining_funds = history_total["remaining_funds"] sessions = "{0}{1}".format(time.strftime('%Y%m%d', time.localtime(time.time())), 0) activation_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) bills = {"sessions": sessions, "settlement_status": "未结算", "creation_time": activation_time, "expenditure":0, "user_Id": user_Id, "revenue": settlement_cost, "surplus": settlement_cost} print( total_expenditure , settlement_cost) financial_account = {"sessions": sessions, "total_income": total_income , "total_expenditure": total_expenditure + settlement_cost, "remaining_funds": remaining_funds - settlement_cost, "current_period_income": 0, "period_expenditure": settlement_cost, "settlement_type": "连续五局未捡空投", "settlement_time": activation_time } financialAccount(financial_account) database.Insert().signal_gun_activity(bills)
def ten_even_activities(user_Id): """ 续费记录 中断后需续费补足奖池 10%金额 方可继续参加 :param user_Id: :return: """ last_session = database.Search().last_session(user_Id) uninterrupted = {"user_Id":user_Id, "renewal":0, "discontinuous_number":0, "last_session":last_session, "time": time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))} database.Insert().ten_even_activities(uninterrupted) # todo 间断记录表的间断次数置为 0,补交金额置为 0,用户基本信息中活跃状态置为活跃,财务账目注入资金增加10,视为一次财务结算 pass
def personalBills(json_user_Ids ,flare_gun_user_Ids, session): """ 个人账单 :param json_user_Ids: :param flare_gun_user_Ids: :param session: :return: """ # 表结构:场次 用户ID 支出 收入 结算状态 创建时间 # todo 根据创建时间+结算状态 进行批量结算 history_total = database.Search().total_income() all_user_id = database.Search().user_Id() sessions = "{0}{1}".format(time.strftime('%Y%m%d', time.localtime(time.time())), session) activation_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) # 总收入 total_income = history_total["total_income"] # 总支出 total_expenditure = history_total["total_expenditure"] # 结余 remaining_funds = history_total["remaining_funds"] # 本期收入 current_period_income = 0 # 本期支出 period_expenditure = 0 bills = {"sessions": sessions, "settlement_status": "未结算", "creation_time": activation_time} for json_user_Id in json_user_Ids: user_leve = database.Search().user_leve(json_user_Id) bills["expenditure"] = user_leve bills["user_Id"] = json_user_Id bills["revenue"] = 0 bills["surplus"] = 0 - user_leve activation_record(json_user_Id, session) database.Insert().signal_gun_activity(bills) # 投币 current_period_income = current_period_income + user_leve all_user_id.remove(json_user_Id) for flare_gun_user_Id in flare_gun_user_Ids: # 避免重复加钱 兜底 if flare_gun_user_Id not in json_user_Ids: user_leve = database.Search().user_leve(flare_gun_user_Id) # 投币 current_period_income = current_period_income + user_leve for flare_gun_user_Id in flare_gun_user_Ids: revenue = (remaining_funds + current_period_income) / (2 * len(flare_gun_user_Ids)) revenue = math.floor(revenue) user_leve = database.Search().user_leve(flare_gun_user_Id) bills["expenditure"] = user_leve bills["user_Id"] = flare_gun_user_Id bills["revenue"] = revenue bills["surplus"] = revenue - user_leve period_expenditure = period_expenditure + revenue activation_record(flare_gun_user_Id, session,flareGun = "获取空投枪") if flare_gun_user_Id in all_user_id: all_user_id.remove(flare_gun_user_Id) print(all_user_id,flare_gun_user_Id) database.Insert().signal_gun_activity(bills) # 没有参加的用户 for user_id in all_user_id: activation_record(user_id, session, "未参加") # 本期后的资金结余 remaining_funds = remaining_funds + current_period_income - period_expenditure financial_account = {"sessions":sessions, "total_income":total_income + current_period_income, "total_expenditure":total_expenditure + period_expenditure, "remaining_funds":remaining_funds, "current_period_income":current_period_income, "period_expenditure":period_expenditure, "settlement_type": "活动结算", "settlement_time": activation_time } financialAccount(financial_account)
def settlement(user_Id = 999, settlement_type = "活动结算",payment_coefficient = 0.1): # todo 根据结算类型(间断补费、活动结算)进行结算,输出时间范围内的每个用户的支出和收入总和,进行结算。 history_total = database.Search().total_income() # 连续5次没有捡到空投抽取10% five_even_activity() settlement_cost = database.Search().uncleared_continuous_airdrop() if settlement_cost != 0: settlement_five_even_activity(settlement_cost = settlement_cost) # 结余 remaining_funds = history_total["remaining_funds"] payment = remaining_funds * payment_coefficient if settlement_type == "活动结算": settlement, user_id_name, detail = database.Search().surplus() for user_id, amount in settlement.items(): print("用户名:{0} 结算金额:{1}元".format(user_id_name[user_id],amount)) # for no_settlement in detail[user_id]: # print(" 用户名:{0} 场次:{1} 参赛日期:{2} 本场收支:{3}元".format(user_id_name[user_id], no_settlement[3], no_settlement[4], no_settlement[2])) # print() # 结算 database.Update().signal_gun_activity() discontinuous_user_Id = database.Search().settlement_discontinuous_number() for user_id in discontinuous_user_Id: database.Update().ten_even_activities(payment, user_id) print("用户名:{0} 补缴金额:{1}元".format(user_id_name[user_id],payment)) elif settlement_type == "间断补费" : activation_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) database.Update().continuous_payment(activation_time, user_Id) sessions = "{0}{1}".format(time.strftime('%Y%m%d', time.localtime(time.time())), 0) # 总收入 total_income = history_total["total_income"] # 总支出 total_expenditure = history_total["total_expenditure"] # 结余 remaining_funds = history_total["remaining_funds"] financial_account = {"sessions": sessions, "total_income": total_income + payment, "total_expenditure": total_expenditure, "remaining_funds": remaining_funds + payment, "current_period_income": payment, "period_expenditure": 0, "settlement_type": "间断补费", "settlement_time": activation_time } financialAccount(financial_account) # 补费后 用户置为活跃 database.Update().active_status(user_Id) # 用户结算 user_settlement()
def fund_settlement(start_session=0, ten_sett_list=''): """ 入账 :return: """ if ten_sett_list == '': ten_sett_list = [] else: ten_sett_list = ten_sett_list.split(',') if start_session == 0: start_session = "{0}{1}".format( time.strftime('%Y%m%d', time.localtime(time.time())), 0) # 范围的场次 no_settlement_sessions = database.Search( ).greater_than_settlement_sessions(start_session) # 结算时间 person_bill = defaultdict(list) for session in no_settlement_sessions: # 获取信号枪活动未结算的信息 no_settlement_signalgun_activity = database.Search( ).get_no_settlement_signalgun_activity(session) signalgun_person = PersonBill.session_signalgun_settlement( no_settlement_signalgun_activity, session) for person, _signalgun in signalgun_person.items(): for _ in _signalgun: person_bill[person].append(_) # 获取五连活动未结算的信息 no_settlement_five_activity = database.Search( ).get_no_settlement_five_activity(session) five_person = PersonBill.session_five_settlement( no_settlement_five_activity, session) for person, _five in five_person.items(): for _ in _five: person_bill[person].append(_) # 获取十连连活动未结算的信息 if len(ten_sett_list) != 0: # 获取十连连活动未结算的信息 print(ten_sett_list, ), len(ten_sett_list) no_settlement_ten_activity = database.Search( ).get_no_settlement_ten_activity_session( session, ten_sett_list) ten_person = PersonBill.session_ten_settlement( no_settlement_ten_activity, session) for person, _ten in ten_person.items(): for _ in _ten: person_bill[person].append(_) # 更新五连活动 结算状态 database.Update().settlement_five_even_activity(session) # 更新信号枪活动 结算状态 database.Update().settlement_signal_gun_activity(session) # 更新十连活动 结算状态 if len(ten_sett_list) != 0: database.Update().settlement_ten_even_activity(session) # 更新活动记录 结算状态 database.Update().settlement_active_record(session) all_user_name = database.Search().get_users_name() for person, bill in person_bill.items(): expenditure = sum([b['expenditure'] for b in bill]) revenue = sum([b['revenue'] for b in bill]) surplus = sum([b['surplus'] for b in bill]) print("玩家昵称:{0} ,本次结算总支出:{1} ,本次结算总收入:{2},本次结算净收入:{3}".format( all_user_name[person], expenditure, revenue, surplus)) print(" 【详情】:") for _ in bill: log = " 活动名称:【{0}】, 场次:{1}, 本场支出{2}, 本场收入{3}, 本场净收入{4}".format( _['msg'], _['session'], _['expenditure'], _['revenue'], _['surplus']) if _['surplus'] < 0: Common.incolorprint(log, 'yellow') if _['surplus'] > 0: Common.incolorprint(log, 'green')
def fund_settlement_pre(only_session, ten_sett_list=''): """ 入账 :return: """ no_settlement_sessions = [] if ten_sett_list == '': ten_sett_list = [] else: ten_sett_list = ten_sett_list.split(',') if len(only_session) != 0: no_settlement_sessions.append(only_session) # 结算时间 activation_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) for session in no_settlement_sessions: # 获取最近一次 history_total = database.Search().total_income() # 总收入 total_income = history_total["total_income"] # 总支出 total_expenditure = history_total["total_expenditure"] # 结余 remaining_funds = history_total["remaining_funds"] # 获取信号枪活动未结算的信息 no_settlement_signalgun_activity = database.Search( ).get_no_settlement_signalgun_activity(session) signalgun = FundBill.session_signalgun_settlement( no_settlement_signalgun_activity, session) # 获取五连活动未结算的信息 no_settlement_five_activity = database.Search( ).get_no_settlement_five_activity(session) five = FundBill.session_five_settlement( no_settlement_five_activity, session) if len(ten_sett_list) != 0: # 获取十连连活动未结算的信息 获取未结算的 no_settlement_ten_activity = database.Search( ).get_no_settlement_ten_activity(ten_sett_list) ten = FundBill.session_ten_settlement( no_settlement_ten_activity, session) for user in ten_sett_list: # 设置结算场次,根据这个场次来判断 该部门划入那个场次结算。 database.Update( ).settlement_ten_even_activity_last_session(session, user) else: ten = FundBill.settlement_base() period_income = signalgun["revenue"] + five["revenue"] + ten[ "revenue"] period_expenditure = signalgun["expenditure"] + five[ "expenditure"] + ten["expenditure"] settlement_type = "{0},{1},{2}".format(signalgun["msg"], ten["msg"], five["msg"]).strip(',') settlement_account = { "sessions": session, "total_income": total_income + period_income, "total_expenditure": total_expenditure + period_expenditure, "remaining_funds": remaining_funds + period_income - period_expenditure, "current_period_income": period_income, "period_expenditure": period_expenditure, "settlement_type": settlement_type, "settlement_time": activation_time } database.Insert().financial_accounts(settlement_account)