test2.py 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. # -*- coding: utf-8 -*-
  2. # !/usr/bin/env python
  3. import datetime
  4. import os
  5. import time
  6. from base import init_env
  7. from apps.web.services.bluetooth.service import ActionBtDeviceBuilder
  8. os.environ.setdefault("DJANGO_SETTINGS_MODULE", "configs.testing")
  9. init_env(interactive = False)
  10. from apps import serviceCache
  11. from django.conf import settings
  12. from apps.web.constant import RechargeRecordVia
  13. from apps.web.core.db import copy_document_classes
  14. from apps.web.dealer.proxy import DealerIncomeProxy
  15. from apilib.monetary import RMB
  16. from apps.web.user.models import RechargeRecord
  17. from bson import ObjectId
  18. from apps.web.common.models import WithdrawRecord, WithdrawRefundRecord
  19. from apps.web.dealer.models import Dealer
  20. # from apps.web.dealer.tasks import generate_business_stats_report_by_dealer
  21. #
  22. # filePath = 'uploaded/reports/20301215/test.xlsx'
  23. # queryAttrs = {"kind": "income", "dealerId": "5b9ae99ad89a177846459999", "dateTimeAdded__lte": 1639583999.0, "dateTimeAdded__gte": 1613318400.0}
  24. # generate_business_stats_report_by_dealer(filePath = filePath, queryAttrs = queryAttrs)
  25. # ownerId = '607677150030485278a2de64'
  26. #
  27. # devNoList = [dev.devNo for dev in Device.objects(ownerId = ownerId)]
  28. #
  29. # dataList = []
  30. #
  31. # for item in SerialTimeOut.objects(devNo__in = devNoList):
  32. # dev = Device.get_dev(devNo = item.devNo) # type: DeviceDict
  33. #
  34. # tempData = OrderedDict([
  35. # (u"logicalCode", item.logicalCode),
  36. # (u"devNo", item.devNo),
  37. # (u'softVer', dev.softVer),
  38. # (u'dVer', dev.driverVersion),
  39. # (u"time", item.dateTimeAdded.strftime("%Y-%m-%d %H:%M:%S")),
  40. # (u"packet", item.packet)
  41. # ])
  42. #
  43. # dataList.append(tempData)
  44. #
  45. # dataForm = pandas.DataFrame(dataList)
  46. # writer = pandas.ExcelWriter(u"统计.xlsx")
  47. # dataForm.to_excel(writer, sheet_name = u"统计", index = False)
  48. # writer.save()
  49. #
  50. # from apps.web.device.timescale import PowerManager
  51. #
  52. # port = '3'
  53. # eTime = datetime.datetime.now()
  54. # sTime = eTime - datetime.timedelta(hours = 10)
  55. # print PowerManager.instence().get_raw(devNo = '868739054076587', port = port, sTime = sTime, eTime = eTime)
  56. # print json_dumps("aaa")
  57. # 5fb88e09c3631dd06e3dd35a_devList '{groupId}_devList'
  58. # partner_group_ids_5bdff2f51748b31ab827cfca
  59. # ctr_868739059936207
  60. # group_616145ec1dcf2fe43e27b4c4
  61. # 868739059936207_online
  62. # Device.get_dev_by_l(logicalCode = '25619')
  63. # ownerId = '60c4ba9700304825e46ad1c0'
  64. #
  65. # his_model_cls = copy_document_classes(DealerIncomeProxy, '{}_his'.format(DealerIncomeProxy.__name__), 'report_his')
  66. # his_data = his_model_cls.sum_by_dealer(dealerId = ownerId)
  67. #
  68. # now_data = DealerIncomeProxy.sum_by_dealer(dealerId = ownerId, **{'dateTimeAdded__gte': datetime.datetime(2021,10,1)})
  69. # print 'his = {}'.format(float(str(his_data)))
  70. # print 'now = {}'.format(float(str(now_data)))
  71. # print 'total = {}'.format(float(str(his_data)) + float(str(now_data)))
  72. #
  73. # withdraw_value = WithdrawRecord.objects(ownerId = ownerId, refunded = False).sum('amount')
  74. # print 'withdraw = {}'.format(withdraw_value)
  75. #
  76. # dealer = Dealer.objects(id = ownerId).first() # type: Dealer
  77. # print 'left = {}'.format(dealer.sub_balance("device"))
  78. #
  79. # start_month = 1
  80. # end_month = 2
  81. #
  82. # month_income = RMB(0)
  83. #
  84. # skip = 0
  85. # loop = 2000
  86. #
  87. #
  88. #
  89. # while True:
  90. # start_time = int(time.time())
  91. #
  92. # items = DealerIncomeProxy.objects(dateTimeAdded__gte = datetime.datetime(2021,start_month,1,0,0,0), dateTimeAdded__lt = datetime.datetime(2022,end_month,1,0,0,0)).skip(skip).limit(loop)
  93. # if len(items) == 0:
  94. # break
  95. #
  96. # ref_ids = {item.ref_id: item for item in items}
  97. #
  98. # rechargs = RechargeRecord.get_collection().find({'_id':{'$in': ref_ids.keys()}}, {'via', 'money', 'result', 'withdrawSourceKey'})
  99. # for recharge in rechargs: # type: RechargeRecord
  100. # if recharge['result'] != 'success':
  101. # print 'recharge {} result is wrong.'.format(str(recharge['_id']))
  102. # continue
  103. #
  104. # if settings.MY_PRIMARY_AGENT_ID not in recharge['withdrawSourceKey']:
  105. # # print 'recharge {} is not my.'.format(str(['_id']))
  106. # continue
  107. #
  108. # if recharge['via'] not in [RechargeRecordVia.VirtualCard, RechargeRecordVia.Card, RechargeRecordVia.Balance, RechargeRecordVia.Cash, RechargeRecordVia.Insurance, RechargeRecordVia.MonthlyPackage]:
  109. # print 'recharge {} is wrong via.'.format(str(['_id']))
  110. # continue
  111. #
  112. # income_proxy = ref_ids.get(ObjectId(recharge['_id'])) # type: DealerIncomeProxy
  113. #
  114. # month_income += RMB(income_proxy.totalAmount)
  115. #
  116. # skip = skip + loop
  117. #
  118. # end_time = int(time.time())
  119. #
  120. # print 'time is: {}'.format(end_time - start_time)
  121. #
  122. # print month_income
  123. # print serviceCache.get('58.243.250.169-2022-01-19')
  124. # from binascii import *
  125. # import crcmod
  126. # import random
  127. # def crc16Add(read):
  128. # crc16 = crcmod.mkCrcFun(0x18005, rev=True, initCrc=0xFFFF, xorOut=0x0000)
  129. # data = read.replace(" ", "") #消除空格
  130. # readcrcout = hex(crc16(unhexlify(data))).upper()
  131. # str_list = list(readcrcout)
  132. # # print(str_list)
  133. # if len(str_list) == 5:
  134. # str_list.insert(2, '0') # 位数不足补0,因为一般最少是5个
  135. # crc_data = "".join(str_list) #用""把数组的每一位结合起来 组成新的字符串
  136. # # print(crc_data)
  137. # read = read.strip() + ' ' + crc_data[4:] + ' ' + crc_data[2:4] #把源代码和crc校验码连接起来
  138. # # print('CRC16校验:', crc_data[4:] + ' ' + crc_data[2:4])
  139. # print(read)
  140. # return crc_data[2:4] + crc_data[4:]
  141. #
  142. # print crc16Add('22200000013201060011030801020F30322E37302E3130000101010101010101010104')
  143. # from apps.web.core.networking import MessageSender
  144. # msg = {"IMEI": "866250061275610", "cmd": 210, "data": "00", "funCode": "01","port":8771}
  145. # MessageSender.send_car_tcpip('127.0.0.1', 50000, msg)
  146. # from apps.web.core.adapter.base import string_to_ascstring
  147. # print string_to_ascstring('192.168.224.25',32)
  148. # from apps.web.device.models import Device
  149. # from apps.web.core.helpers import ActionDeviceBuilder
  150. # dev = Device.get_dev(devNo = '32010600291765')
  151. #
  152. # box = ActionDeviceBuilder.create_action_device(dev)
  153. # box.update_charger(1,40960,'211.159.224.10',21,'ftpuser','123456','/data',1,10)
  154. #
  155. # print 'ddd'
  156. from apps.web.core.payment.base import WithdrawGateway
  157. record = WithdrawRecord.objects(order='20220926162612WDA177846459999AZK').first()
  158. withdraw_gateway = WithdrawGateway.from_withdraw_gateway_key(record.withdrawGatewayKey, record.extras.get('gateway_version', 'v1'))
  159. query_result = withdraw_gateway.get_transfer_result_via_changes(record.order)