# -*- coding: utf-8 -*-

from isoweek import Week
from TimeConvert import TimeConvert as tc

from utils.redis.connect import r
from utils.redis.rkeys import TODAY_INCOME, TOTAL_INCOME, WEEK_INCOME, WEEK_SOLD


def set_brief_info(uid, ptype, fee, dt=None):
    """ 更新简报信息 """
    ymd, week = (tc.local_string(tc.to_local_datetime(dt), format='%Y%m%d'), Week.withdate(dt)) if dt else (tc.local_string(format='%Y%m%d'), Week.thisweek().isoformat())

    # 总收入
    r.incr(TOTAL_INCOME % (uid, ptype), fee)
    # 周收入
    r.incr(WEEK_INCOME % (uid, ptype, week), fee)
    # 日收入
    r.incr(TODAY_INCOME % (uid, ptype, ymd), fee)

    # 周售出
    r.incr(WEEK_SOLD % (uid, ptype, week))
