123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- # -*- coding: utf-8 -*-
- # !/usr/bin/env python
- """
- 生成报表
- """
- import datetime
- from apps.web.user.models import RechargeRecord
- from base import init_env, get_logger
- logger = get_logger(__name__)
- import os
- os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'configs.testing')
- init_env(interactive = False)
- def get_date_processed_recharge_record(y, m, d):
- rs = RechargeRecord.objects(
- result='success',
- via='recharge',
- dateTimeAdded__gte=datetime.datetime(y, m, d, 0, 0, 0),
- dateTimeAdded__lte=datetime.datetime(y, m, d, 23, 59, 59)
- ).only('orderNo', 'ownerId', 'openId', 'money')
- print rs.count()
- return rs
- def get_threshold_data(data, threshold):
- arr = []
- for _ in data:
- if int(_.money) >= threshold:
- arr.append(_.orderNo + ',' + _.ownerId + ',' + _.openId + ',' + str(_.money))
- print len(arr)
- return arr
- def statistic_from_threshold_data(data):
- bbb = []
- for _ in data:
- bbc = _.split(',')
- tempStr = bbc[1] + bbc[2]
- bbb.append(tempStr)
- www = []
- for _ in bbb:
- www.append(_ + ',' + str(bbb.count(_)))
- www = list(set(www))
- return www
- # 执行函数, 拿到的是dealerId和openId以及单日次数的汇总,通过此数据可以排查出异常经销商
- def check_fake_order_main(y, m, d, threshold):
- rs = get_date_processed_recharge_record(y, m, d)
- arr = get_threshold_data(rs, threshold)
- return statistic_from_threshold_data(arr)
|