reconcile_agent_card_fee.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # -*- coding: utf-8 -*-
  2. # !/usr/bin/env python
  3. import getopt
  4. import os
  5. import sys
  6. PROJECT_ROOT = os.path.join(os.path.abspath(os.path.split(os.path.realpath(__file__))[0] + "/.."), '..')
  7. sys.path.insert(0, PROJECT_ROOT)
  8. from script.base import init_env
  9. os.environ["DJANGO_SETTINGS_MODULE"] = "configs.production_local"
  10. init_env(False)
  11. from apps.web.dealer.models import DealerRechargeRecord, Dealer
  12. from apps.web.dealer.utils import create_dealer_sim_charge_verify_order
  13. from apps.web.dealer.transaction import post_sim_verify_order
  14. if __name__ == '__main__':
  15. try:
  16. options, args = getopt.getopt(sys.argv[1:], 'o:a:e:', ['order=', 'agentId=', 'earned='])
  17. except getopt.GetoptError as e:
  18. print(str(e))
  19. sys.exit()
  20. order_no = None
  21. agent_id = None
  22. earned = None
  23. for name, value in options:
  24. if name in ('-o', '--order'):
  25. order_no = value
  26. if name in ('-a', '--agentId'):
  27. agent_id = value
  28. if name in ('-e', '--earned'):
  29. earned = int(value)
  30. association_order = DealerRechargeRecord.objects(orderNo = order_no).first() # type: DealerRechargeRecord
  31. if not association_order:
  32. print('order<{}> is not exists.'.format(order_no))
  33. sys.exit(1)
  34. if association_order.product not in [DealerRechargeRecord.ProductType.AutoSimCard,
  35. DealerRechargeRecord.ProductType.SimCard]:
  36. print('order<{}> is not sim card recharge order.')
  37. sys.exit(1)
  38. my_partition = None
  39. for partition in association_order.settleInfo['partition']:
  40. if agent_id == partition['id']:
  41. my_partition = partition
  42. break
  43. if not my_partition:
  44. print('agent id param error.')
  45. sys.exit(1)
  46. if int(my_partition['earned']) + earned > association_order.totalFee:
  47. print('money param error.')
  48. sys.exit(1)
  49. dealer = Dealer.objects(id = association_order.dealerId).first()
  50. record = create_dealer_sim_charge_verify_order(dealer = dealer, partitions = [{
  51. 'id': agent_id,
  52. 'earned': earned
  53. }], recharge_order = association_order)
  54. record.succeed(wxOrderNo = '')
  55. post_sim_verify_order(dealer, record)