#coding: utf8
import xlrd
from django.core.management import BaseCommand
from gm_types.gaia import POINTS_OPERATION, POINTS_TYPE
from point.models import Points

class Command(BaseCommand):

    def handle(self, *args, **options):
        file="add_user_point.xlsx"
        data = xlrd.open_workbook(file.decode('utf-8'))
        sheet = data.sheets()[0]

        for index in range(1, sheet.nrows):
            row = sheet.row_values(index)
            if row:
                user_id= int(row[0])
                try:
                    Points.objects.get_or_create(user_id=user_id,operation=POINTS_OPERATION.ADD,reason=POINTS_TYPE.PLACE_ORDER,number=800)
                except Exception as e:
                    print "导入失败user_id:{}".format(user_id)
                    print str(e)

