# # coding=utf-8
# import datetime
# from django.core.management import BaseCommand
# from django.db.models import Count
# from api.models import CouponInfo
# from api.models import User
# from api.models import Coupon
# from api.models import Points
# from api.models import POINTS_TYPE
# from api.models import BUSINESS_CHANNEL
# from api.models import COUPON_TYPE
#
# # COUPON_ID = '1290' #PROD
# COUPON_ID = '1285'  # TEST
#
# start_time = datetime.datetime.strptime('2015-10-01 00:00:00', '%Y-%m-%d %H:%M:%S')
#
# claimed_time = datetime.datetime.strptime('2015-12-29 20:00:00', '%Y-%m-%d %H:%M:%S')
#
#
# class Command(BaseCommand):
#     def handle(self, *args, **options):
#         the_count = 0
#         coupon = Coupon.objects.get(pk=COUPON_ID)
#         assert coupon.value == 50
#         user_activate_points = Points.objects.values('user').annotate(user_count=Count('user_id')).filter(reason=POINTS_TYPE.LOGIN).filter(add_time__gt=start_time)
#         for user_activate_point in user_activate_points:
#             user_id = user_activate_point['user']
#             try:
#                 CouponInfo.objects.get(coupon=coupon, user_id=user_id)
#                 continue
#             except CouponInfo.DoesNotExist:
#                 pass
#             CouponInfo.objects.create(coupon=coupon,
#                                              value=coupon.value,
#                                              claimed_time=claimed_time,
#                                              channel=BUSINESS_CHANNEL.NEWYEAR,
#                                              user_id = user_id,
#                                              status=COUPON_TYPE.CLAIMED
#                                              )
#             the_count += 1
#             if the_count % 100 == 0:
#                 print the_count