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

import json

from account.models import LensmanInfo
from utils.redis.connect import r
from utils.redis.rkeys import LENSMAN_PHOTO_PRICE_FIXED


# 最新 APP 相关


def set_lensman_price_fixed(user_id):
    """ 设置摄影师价格设定 """
    try:
        lensman = LensmanInfo.objects.get(lensman_id=user_id)
    except LensmanInfo.DoesNotExist:
        lensman = None

    price_fixed = {
        'nomark': (lensman and lensman.nomark) or 299,
        'origin': (lensman and lensman.origin) or 999,
    }

    r.set(LENSMAN_PHOTO_PRICE_FIXED % user_id, json.dumps(price_fixed))

    return price_fixed


def get_lensman_price_fixed(user_id):
    """ 获取摄影师价格设定 """
    return json.loads(r.get(LENSMAN_PHOTO_PRICE_FIXED % user_id) or '{}') or set_lensman_price_fixed(user_id)