# # coding=utf-8
#
# from django.core.management.base import NoArgsCommand
# from api.models import Order
# from api.models import ORDER_SOURCE
# from api.models import OrderOperation
# from api.models import RefundOrder
# from api.models import Person
# from api.models import WechatOrder
# from api.models import ORDER_OPERATION_ROLE
# from api.models import ORDER_OPERATION_TYPE
# from api.models import REFUND_STATUS
# from django.db import transaction
# from django.db.models import Q, Count
# from pay.models import Wechat
# from django.conf import settings
# import datetime
# from api.models import SettlementItem
# from api.models import Order
# from api.models import Settlement
# from api.models import ORDER_STATUS
#
# start_time = datetime.datetime.strptime('2015-11-12 00:35:49', '%Y-%m-%d %H:%M:%S')
#
#
# class Command(NoArgsCommand):
#     def handle(self, *args, **options):
#         # settlements = Settlement.objects.filter(created_at__gt=start_time)
#         # has_refund_settlements = settlements.filter(Q(items__order__status=ORDER_STATUS.WAIT_REFUNDED)|Q(items__order__status=ORDER_STATUS.REFUNDED))
#         #
#         # used_coupon = settlements.filter(coupon__isnull=False)
#         # has_refund_and_used_coupon_settlements = has_refund_settlements.filter(coupon__isnull=False)
#         # print u'结算单总数%d' %settlements.count()
#         # print u'已退款结算单总数%d' %has_refund_settlements.count()
#         #
#         # print u'已使用满减券的结算单数 %d' %used_coupon.count()
#         # print u'已退款其中已使用满减券的结算单数 %d' %has_refund_and_used_coupon_settlements.count()
#         #
#         #
#         #
#         # orders = Order.objects.filter(created_time__gt=start_time)
#         # has_refund_orders = orders.filter(Q(status=ORDER_STATUS.WAIT_REFUNDED)|Q(status=ORDER_STATUS.REFUNDED))
#         #
#         # used_coupon_orders = orders.filter(settlementitem__settlement__coupon__isnull=False)
#         # has_refund_and_used_coupon_orders = has_refund_orders.filter(settlementitem__settlement__coupon__isnull=False)
#         # print u'订单总数 %d' %orders.count()
#         # print u'已退款订单总数%d' %has_refund_orders.count()
#         #
#         # print u'已使用满减券订单总数%d' %used_coupon_orders.count()
#         # print u'已退款中已使用满减券订单总数%d' %has_refund_and_used_coupon_orders.count()
#
#         # settlements.objects.values('settlement').annotate(settlement_count=Count('settlement_id')).filter(settlement_count__gt=1)
#
#         settlement_ids = [
#             100532300692,
#             566789123654,
#             989959651656,
#             800361418372,
#             422628022139,
#             533488681870,
#             893645920369,
#             188507691166,
#             819160207755,
#             376453602127,
#             927712716969,
#             320174483787,
#             799021026429,
#             682664506151,
#             583646996732,
#             494765421229,
#             239840671680,
#             918425820234,
#             763088019635,
#             780249102484,
#             848575056317,
#             834295899763,
#             640019239319,
#             462605502141,
#             423244161346,
#             326366268392,
#             662252118351,
#             819451840978,
#             621640758845,
#             956157477844,
#             321365211941,
#             127146967222,
#             889590277233,
#             224222795092,
#             312605103132,
#             357725956139,
#             795762571232,
#             559652527224,
#             337597819070,
#         ]
#
#         settlements = SettlementItem.objects.filter(settlement_id__in=settlement_ids).values('settlement').annotate(settlement_count=Count('settlement_id'))