123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- # -*- coding: utf-8 -*-
- # !/usr/bin/env python
- import datetime
- import os
- import time
- from base import init_env
- from apps.web.services.bluetooth.service import ActionBtDeviceBuilder
- os.environ.setdefault("DJANGO_SETTINGS_MODULE", "configs.testing")
- init_env(interactive = False)
- from apps import serviceCache
- from django.conf import settings
- from apps.web.constant import RechargeRecordVia
- from apps.web.core.db import copy_document_classes
- from apps.web.dealer.proxy import DealerIncomeProxy
- from apilib.monetary import RMB
- from apps.web.user.models import RechargeRecord
- from bson import ObjectId
- from apps.web.common.models import WithdrawRecord, WithdrawRefundRecord
- from apps.web.dealer.models import Dealer
- # from apps.web.dealer.tasks import generate_business_stats_report_by_dealer
- #
- # filePath = 'uploaded/reports/20301215/test.xlsx'
- # queryAttrs = {"kind": "income", "dealerId": "5b9ae99ad89a177846459999", "dateTimeAdded__lte": 1639583999.0, "dateTimeAdded__gte": 1613318400.0}
- # generate_business_stats_report_by_dealer(filePath = filePath, queryAttrs = queryAttrs)
- # ownerId = '607677150030485278a2de64'
- #
- # devNoList = [dev.devNo for dev in Device.objects(ownerId = ownerId)]
- #
- # dataList = []
- #
- # for item in SerialTimeOut.objects(devNo__in = devNoList):
- # dev = Device.get_dev(devNo = item.devNo) # type: DeviceDict
- #
- # tempData = OrderedDict([
- # (u"logicalCode", item.logicalCode),
- # (u"devNo", item.devNo),
- # (u'softVer', dev.softVer),
- # (u'dVer', dev.driverVersion),
- # (u"time", item.dateTimeAdded.strftime("%Y-%m-%d %H:%M:%S")),
- # (u"packet", item.packet)
- # ])
- #
- # dataList.append(tempData)
- #
- # dataForm = pandas.DataFrame(dataList)
- # writer = pandas.ExcelWriter(u"统计.xlsx")
- # dataForm.to_excel(writer, sheet_name = u"统计", index = False)
- # writer.save()
- #
- # from apps.web.device.timescale import PowerManager
- #
- # port = '3'
- # eTime = datetime.datetime.now()
- # sTime = eTime - datetime.timedelta(hours = 10)
- # print PowerManager.instence().get_raw(devNo = '868739054076587', port = port, sTime = sTime, eTime = eTime)
- # print json_dumps("aaa")
- # 5fb88e09c3631dd06e3dd35a_devList '{groupId}_devList'
- # partner_group_ids_5bdff2f51748b31ab827cfca
- # ctr_868739059936207
- # group_616145ec1dcf2fe43e27b4c4
- # 868739059936207_online
- # Device.get_dev_by_l(logicalCode = '25619')
- # ownerId = '60c4ba9700304825e46ad1c0'
- #
- # his_model_cls = copy_document_classes(DealerIncomeProxy, '{}_his'.format(DealerIncomeProxy.__name__), 'report_his')
- # his_data = his_model_cls.sum_by_dealer(dealerId = ownerId)
- #
- # now_data = DealerIncomeProxy.sum_by_dealer(dealerId = ownerId, **{'dateTimeAdded__gte': datetime.datetime(2021,10,1)})
- # print 'his = {}'.format(float(str(his_data)))
- # print 'now = {}'.format(float(str(now_data)))
- # print 'total = {}'.format(float(str(his_data)) + float(str(now_data)))
- #
- # withdraw_value = WithdrawRecord.objects(ownerId = ownerId, refunded = False).sum('amount')
- # print 'withdraw = {}'.format(withdraw_value)
- #
- # dealer = Dealer.objects(id = ownerId).first() # type: Dealer
- # print 'left = {}'.format(dealer.sub_balance("device"))
- #
- # start_month = 1
- # end_month = 2
- #
- # month_income = RMB(0)
- #
- # skip = 0
- # loop = 2000
- #
- #
- #
- # while True:
- # start_time = int(time.time())
- #
- # 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)
- # if len(items) == 0:
- # break
- #
- # ref_ids = {item.ref_id: item for item in items}
- #
- # rechargs = RechargeRecord.get_collection().find({'_id':{'$in': ref_ids.keys()}}, {'via', 'money', 'result', 'withdrawSourceKey'})
- # for recharge in rechargs: # type: RechargeRecord
- # if recharge['result'] != 'success':
- # print 'recharge {} result is wrong.'.format(str(recharge['_id']))
- # continue
- #
- # if settings.MY_PRIMARY_AGENT_ID not in recharge['withdrawSourceKey']:
- # # print 'recharge {} is not my.'.format(str(['_id']))
- # continue
- #
- # if recharge['via'] not in [RechargeRecordVia.VirtualCard, RechargeRecordVia.Card, RechargeRecordVia.Balance, RechargeRecordVia.Cash, RechargeRecordVia.Insurance, RechargeRecordVia.MonthlyPackage]:
- # print 'recharge {} is wrong via.'.format(str(['_id']))
- # continue
- #
- # income_proxy = ref_ids.get(ObjectId(recharge['_id'])) # type: DealerIncomeProxy
- #
- # month_income += RMB(income_proxy.totalAmount)
- #
- # skip = skip + loop
- #
- # end_time = int(time.time())
- #
- # print 'time is: {}'.format(end_time - start_time)
- #
- # print month_income
- # print serviceCache.get('58.243.250.169-2022-01-19')
- # from binascii import *
- # import crcmod
- # import random
- # def crc16Add(read):
- # crc16 = crcmod.mkCrcFun(0x18005, rev=True, initCrc=0xFFFF, xorOut=0x0000)
- # data = read.replace(" ", "") #消除空格
- # readcrcout = hex(crc16(unhexlify(data))).upper()
- # str_list = list(readcrcout)
- # # print(str_list)
- # if len(str_list) == 5:
- # str_list.insert(2, '0') # 位数不足补0,因为一般最少是5个
- # crc_data = "".join(str_list) #用""把数组的每一位结合起来 组成新的字符串
- # # print(crc_data)
- # read = read.strip() + ' ' + crc_data[4:] + ' ' + crc_data[2:4] #把源代码和crc校验码连接起来
- # # print('CRC16校验:', crc_data[4:] + ' ' + crc_data[2:4])
- # print(read)
- # return crc_data[2:4] + crc_data[4:]
- #
- # print crc16Add('22200000013201060011030801020F30322E37302E3130000101010101010101010104')
- # from apps.web.core.networking import MessageSender
- # msg = {"IMEI": "866250061275610", "cmd": 210, "data": "00", "funCode": "01","port":8771}
- # MessageSender.send_car_tcpip('127.0.0.1', 50000, msg)
- # from apps.web.core.adapter.base import string_to_ascstring
- # print string_to_ascstring('192.168.224.25',32)
- # from apps.web.device.models import Device
- # from apps.web.core.helpers import ActionDeviceBuilder
- # dev = Device.get_dev(devNo = '32010600291765')
- #
- # box = ActionDeviceBuilder.create_action_device(dev)
- # box.update_charger(1,40960,'211.159.224.10',21,'ftpuser','123456','/data',1,10)
- #
- # print 'ddd'
- from apps.web.core.payment.base import WithdrawGateway
- record = WithdrawRecord.objects(order='20220926162612WDA177846459999AZK').first()
- withdraw_gateway = WithdrawGateway.from_withdraw_gateway_key(record.withdrawGatewayKey, record.extras.get('gateway_version', 'v1'))
- query_result = withdraw_gateway.get_transfer_result_via_changes(record.order)
|