finishedPay_card.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # -*- coding: utf-8 -*-
  2. #!/usr/bin/env python
  3. import os
  4. import sys
  5. PROJECT_ROOT = os.path.join(os.path.abspath(os.path.split(os.path.realpath(__file__))[0] + "/.."), '..')
  6. sys.path.insert(0, PROJECT_ROOT)
  7. # 引入项目环境和日志
  8. from script.base import init_env, get_logger
  9. init_env(interactive=True)
  10. logger = get_logger(__name__)
  11. from bson.objectid import ObjectId
  12. from apps.web.user.models import CardRechargeOrder, RechargeRecord
  13. from apps.web.dealer.models import Dealer
  14. from apps.web.agent.models import Agent
  15. from apps.web.dealer.proxy import DealerIncomeProxy
  16. agentIds = [str(_.id) for _ in Agent.objects(customizedWechatCashflowAllowable=False, customizedAlipayCashflowAllowable=False)]
  17. cardOrders = CardRechargeOrder.objects(__raw__={'status':'finishedPay','rechargeNo':{'$ne': None}})
  18. tempCardOrders = [str(_.id) for _ in cardOrders]
  19. trueCardOrders = []
  20. for _ in cardOrders:
  21. r = RechargeRecord.objects(id=str(_.rechargeNo)).first()
  22. if r is None or r.ownerId == '' or r.ownerId is None:
  23. logger.error('invalid rechargeNo=%s' % _.rechargeNo)
  24. continue
  25. p = DealerIncomeProxy.objects(ref_id=ObjectId(r.id)).first()
  26. # 如果有分账就不记录
  27. if p is not None:
  28. continue
  29. d = Dealer.objects(id=r.ownerId).first()
  30. if d is None:
  31. logger.error('undefined Dealer=%s' % r.ownerId)
  32. continue
  33. # 如果有资金池就不记录
  34. if d.agentId not in agentIds:
  35. continue
  36. else:
  37. trueCardOrders.append(str(_.id))
  38. print(len(trueCardOrders), len(tempCardOrders))
  39. total = 0
  40. for _ in trueCardOrders:
  41. c = CardRechargeOrder.objects(id=_).first()
  42. total += int(c.money)
  43. print(total)