123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- from base import init_env
- init_env(interactive = True)
- from apps.web.dealer.models import Dealer
- from apps.web.dealer.proxy import DealerIncomeProxy
- from apps.web.common.models import WithdrawRecord
- from apps.web.user.models import RechargeRecord
- agentId = "5d857a130030483f797808b5"
- dealers = Dealer.objects.filter(agentId=agentId)
- counter = dict()
- def get_income(dealerId):
- s = 0
- ips = DealerIncomeProxy.objects.filter(dealerIds=dealerId)
- for r in ips:
- s += float(str(r.actualAmountMap.get(dealerId, 0)))
- return s
- def get_withdraw(dealerId):
- m = 0
- records = WithdrawRecord.objects.filter(ownerId=dealerId, status=1)
- m = sum([float(str(r.amount)) for r in records])
- return m
- def get_recharge_record(dealerId):
- records = RechargeRecord.objects.filter(ownerId=dealerId, result="success", via__in=["recharge", "chargeCard"])
- return sum([float(str(r.money)) for r in records])
- for dealer in dealers:
- print dealer.id
- counter["{}-{}".format(dealer.nickname, dealer.username)] = dict()
- counter["{}-{}".format(dealer.nickname, dealer.username)]["balance"] = dealer.total_balance
- counter["{}-{}".format(dealer.nickname, dealer.username)]["income"] = get_income(str(dealer.id))
- counter["{}-{}".format(dealer.nickname, dealer.username)]["w"] = get_withdraw(str(dealer.id))
- counter["{}-{}".format(dealer.nickname, dealer.username)]["r"] = get_recharge_record(str(dealer.id))
- from pprint import pprint
- pprint(counter)
- import csv
- with open("changyuan.txt", "w") as f:
- s = ""
- a1 = 0
- a2 = 0
- a3 = 0
- a4 = 0
- for k, v in counter.items():
- s += "{}\t\t".format(k)
- s += "{}\t\t".format(v.get("balance", 0))
- s += "{}\t\t".format(v.get("w", 0))
- s += "{}\n".format(v.get("income", 0))
-
- a1 += float(str(v.get("balance", 0)))
- a2 += float(str(v.get("w", 0)))
- a4 += float(str(v.get("income", 0)))
- s = "{}\n\n{}\t\t{}\t\t{}".format(s, a1, a2, a4)
- f.write(s)
|