check_fake_order.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # -*- coding: utf-8 -*-
  2. # !/usr/bin/env python
  3. """
  4. 生成报表
  5. """
  6. import datetime
  7. from apps.web.user.models import RechargeRecord
  8. from base import init_env, get_logger
  9. logger = get_logger(__name__)
  10. import os
  11. os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'configs.testing')
  12. init_env(interactive = False)
  13. def get_date_processed_recharge_record(y, m, d):
  14. rs = RechargeRecord.objects(
  15. result='success',
  16. via='recharge',
  17. dateTimeAdded__gte=datetime.datetime(y, m, d, 0, 0, 0),
  18. dateTimeAdded__lte=datetime.datetime(y, m, d, 23, 59, 59)
  19. ).only('orderNo', 'ownerId', 'openId', 'money')
  20. print rs.count()
  21. return rs
  22. def get_threshold_data(data, threshold):
  23. arr = []
  24. for _ in data:
  25. if int(_.money) >= threshold:
  26. arr.append(_.orderNo + ',' + _.ownerId + ',' + _.openId + ',' + str(_.money))
  27. print len(arr)
  28. return arr
  29. def statistic_from_threshold_data(data):
  30. bbb = []
  31. for _ in data:
  32. bbc = _.split(',')
  33. tempStr = bbc[1] + bbc[2]
  34. bbb.append(tempStr)
  35. www = []
  36. for _ in bbb:
  37. www.append(_ + ',' + str(bbb.count(_)))
  38. www = list(set(www))
  39. return www
  40. # 执行函数, 拿到的是dealerId和openId以及单日次数的汇总,通过此数据可以排查出异常经销商
  41. def check_fake_order_main(y, m, d, threshold):
  42. rs = get_date_processed_recharge_record(y, m, d)
  43. arr = get_threshold_data(rs, threshold)
  44. return statistic_from_threshold_data(arr)