upgrade_20180509_agent.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # -*- coding: utf-8 -*-
  2. #!/usr/bin/env python
  3. """
  4. 支付宝自主收款和微信自主收款并无关联
  5. """
  6. import os
  7. import sys
  8. from bson.objectid import ObjectId
  9. #: current_dir - 2
  10. PROJECT_ROOT = os.path.join(os.path.abspath(os.path.split(os.path.realpath(__file__))[0] + "/.."), '..')
  11. sys.path.insert(0, PROJECT_ROOT)
  12. from script.base import init_env, get_logger
  13. logger = get_logger(__name__)
  14. init_env(interactive=True)
  15. from apps.web.agent.models import Agent
  16. agentCollection = Agent.get_collection()
  17. agents = agentCollection.find({'customizedCashflowAllowable': True})
  18. if not agents: print 'no agents to operate on'
  19. for a in agents:
  20. if a.get('appid'):
  21. print 'writing wechat cashflow allowable to agent(%s)' % (str(a['_id'],))
  22. updated0 = agentCollection.update({'_id': ObjectId(a['_id'])},
  23. {'$set': {'customizedWechatCashflowAllowable':True}})
  24. assert updated0, 'customizeWechatCashflowAllowable update error, agent=%s' % (str(a.id),)
  25. if a.get('alipay_appid'):
  26. print 'writing alipay cashflow allowable to agent(%s)' % (str(a['_id'],))
  27. updated1 = agentCollection.update({'_id': ObjectId(a['_id'])},
  28. {'$set':{'customizedAlipayCashflowAllowable': True}})
  29. assert updated1, 'customizeAlipayCashflowAllowable update error agent=%s' % (str(a.id),)
  30. print 'start deleting customizedCashflowAllowable field'
  31. agentCollection.update({}, {'$unset': {'customizedCashflowAllowable': ''}}, multi=True)
  32. print 'finished'