open_charge_switch.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # -*- coding: utf-8 -*-
  2. # !/usr/bin/env python
  3. import os,sys
  4. PROJECT_ROOT = os.path.join(os.path.abspath(os.path.split(os.path.realpath(__file__))[0] + "/.."), '..')
  5. sys.path.insert(0, PROJECT_ROOT)
  6. os.environ.update({"DJANGO_SETTINGS_MODULE": "configs.production"})
  7. import django
  8. django.setup()
  9. from apps.web.dealer.models import Dealer
  10. from apps.web.device.models import Device
  11. from apps.web.device.models import Group
  12. agentBlackList = ['15888766630','13966711825']
  13. dealerBlackList = ['13827102928','18674568321','13930448219','15854515805']
  14. #黑名单中的关闭掉
  15. # agentIds = [str(agent.id) for agent in Agent.objects.filter(username__in = agentBlackList)]
  16. # dealerIds = [dealer for dealer in Dealer.objects.filter(agentId__in = agentIds)]
  17. dealerIds = [dealer for dealer in Dealer.objects.filter(username = '15854515805')]
  18. # dealerIds2 = [dealer for dealer in Dealer.objects.filter(username__in = dealerBlackList)]
  19. # dealerIds.extend(dealerIds2)
  20. groupIds = [str(_.id) for _ in Group.objects.filter(ownerId__in = dealerIds)]
  21. for groupId in groupIds:
  22. group = Group.get_group(groupId)
  23. if not group.get('beforeChargeUnpay',False):
  24. continue
  25. Group.update_group(groupId,beforeChargeUnpay = False)
  26. dealers = [dealer for dealer in Dealer.objects.all().only('id','username')]
  27. count = 0
  28. dealerIds = []
  29. for dealer in dealers:
  30. if dealer.username in blackList:
  31. continue
  32. devCount = Device.objects.filter(ownerId = str(dealer.id)).count()
  33. if devCount > 10:
  34. continue
  35. dealerIds.append(str(dealer.id))
  36. print 'dealer id num',len(dealerIds)
  37. groupIds = [str(_.id) for _ in Group.objects.filter(ownerId__in = dealerIds)]
  38. for groupId in groupIds:
  39. group = Group.get_group(groupId)
  40. if not group.get('beforeChargeUnpay',False):
  41. continue
  42. Group.update_group(groupId,beforeChargeUnpay = False)
  43. print 'finished'