# -*- coding: utf-8 -*- # !/usr/bin/env python import getopt import os import sys PROJECT_ROOT = os.path.join(os.path.abspath(os.path.split(os.path.realpath(__file__))[0] + "/.."), '..') sys.path.insert(0, PROJECT_ROOT) from script.base import init_env os.environ["DJANGO_SETTINGS_MODULE"] = "configs.production_local" init_env(False) from apps.web.dealer.models import DealerRechargeRecord, Dealer from apps.web.dealer.utils import create_dealer_sim_charge_verify_order from apps.web.dealer.transaction import post_sim_verify_order if __name__ == '__main__': try: options, args = getopt.getopt(sys.argv[1:], 'o:a:e:', ['order=', 'agentId=', 'earned=']) except getopt.GetoptError as e: print(str(e)) sys.exit() order_no = None agent_id = None earned = None for name, value in options: if name in ('-o', '--order'): order_no = value if name in ('-a', '--agentId'): agent_id = value if name in ('-e', '--earned'): earned = int(value) association_order = DealerRechargeRecord.objects(orderNo = order_no).first() # type: DealerRechargeRecord if not association_order: print('order<{}> is not exists.'.format(order_no)) sys.exit(1) if association_order.product not in [DealerRechargeRecord.ProductType.AutoSimCard, DealerRechargeRecord.ProductType.SimCard]: print('order<{}> is not sim card recharge order.') sys.exit(1) my_partition = None for partition in association_order.settleInfo['partition']: if agent_id == partition['id']: my_partition = partition break if not my_partition: print('agent id param error.') sys.exit(1) if int(my_partition['earned']) + earned > association_order.totalFee: print('money param error.') sys.exit(1) dealer = Dealer.objects(id = association_order.dealerId).first() record = create_dealer_sim_charge_verify_order(dealer = dealer, partitions = [{ 'id': agent_id, 'earned': earned }], recharge_order = association_order) record.succeed(wxOrderNo = '') post_sim_verify_order(dealer, record)