changyuan_duizhang.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. from base import init_env
  2. init_env(interactive = True)
  3. from apps.web.dealer.models import Dealer
  4. from apps.web.dealer.proxy import DealerIncomeProxy
  5. from apps.web.common.models import WithdrawRecord
  6. from apps.web.user.models import RechargeRecord
  7. agentId = "5d857a130030483f797808b5"
  8. dealers = Dealer.objects.filter(agentId=agentId)
  9. counter = dict()
  10. def get_income(dealerId):
  11. s = 0
  12. ips = DealerIncomeProxy.objects.filter(dealerIds=dealerId)
  13. for r in ips:
  14. s += float(str(r.actualAmountMap.get(dealerId, 0)))
  15. return s
  16. def get_withdraw(dealerId):
  17. m = 0
  18. records = WithdrawRecord.objects.filter(ownerId=dealerId, status=1)
  19. m = sum([float(str(r.amount)) for r in records])
  20. return m
  21. def get_recharge_record(dealerId):
  22. records = RechargeRecord.objects.filter(ownerId=dealerId, result="success", via__in=["recharge", "chargeCard"])
  23. return sum([float(str(r.money)) for r in records])
  24. for dealer in dealers:
  25. print dealer.id
  26. counter["{}-{}".format(dealer.nickname, dealer.username)] = dict()
  27. counter["{}-{}".format(dealer.nickname, dealer.username)]["balance"] = dealer.total_balance
  28. counter["{}-{}".format(dealer.nickname, dealer.username)]["income"] = get_income(str(dealer.id))
  29. counter["{}-{}".format(dealer.nickname, dealer.username)]["w"] = get_withdraw(str(dealer.id))
  30. counter["{}-{}".format(dealer.nickname, dealer.username)]["r"] = get_recharge_record(str(dealer.id))
  31. from pprint import pprint
  32. pprint(counter)
  33. import csv
  34. with open("changyuan.txt", "w") as f:
  35. s = ""
  36. a1 = 0
  37. a2 = 0
  38. a3 = 0
  39. a4 = 0
  40. for k, v in counter.items():
  41. s += "{}\t\t".format(k)
  42. s += "{}\t\t".format(v.get("balance", 0))
  43. s += "{}\t\t".format(v.get("w", 0))
  44. s += "{}\n".format(v.get("income", 0))
  45. a1 += float(str(v.get("balance", 0)))
  46. a2 += float(str(v.get("w", 0)))
  47. a4 += float(str(v.get("income", 0)))
  48. s = "{}\n\n{}\t\t{}\t\t{}".format(s, a1, a2, a4)
  49. f.write(s)