%%%------------------------------------
%%% @Module  : flower.hrl
%%% @Author  : zengzy
%%% @Created : 2017-06-30
%%% @Description: 花语和鲜花
%%%------------------------------------

-define(FLOWER_RECORD_NUM_LIMIT,    30).            %% 送花记录保存上限
-define(RECORD_VAILD_TIME,          3 * 86400).     %% 送花记录有效期3天

-define(CODE_SEND_FLOWER,           1).             %% 送礼
-define(CODE_RECEIVE_FLOWER,        2).             %% 收礼

-define(RECORD_NEW,                 1).             %% 有新记录
-define(RECORD_OLD,                 2).             %% 没有新纪录
%% 鲜花礼物配置
-record(flower_gift_cfg, {
    goods_id = 0,
    type = 0,                   %% 是否是特殊礼品
    intimacy = 0,               %% 增加的亲密度
    charm = 0,                  %% 增加的魅力(人气)值
    fame = 0,                   %% 增加的慷慨值
    need_lv = 0,
    need_vip = 0,
    is_sell = 0,
    is_tv = 0,
    effect_type = 0,
    effect = undefined
    }).

-record(fame_lv_cfg, {
    lv = 0,
    color = 0,
    name = "",
    fame = 0,
    attr = []
    }).

-record (flower_egg_cfg, {
    egg_id = 0,
    egg_name = "",
    min_lv = 0,
    vip_lv = 0,
    limit_time = 0,
    cost = [],
    charm_value = 0,
    effect = ""
    }).

%% 特殊礼品配置
-record(base_flower_sp_gift, {
    goods_id = 0,               %% 特殊礼品物品id
    my_back_reward = [],        %% 我的所得
    my_day = 0,                 %% 我的持续天数
    friend_back_reward = [],    %% 对方所得
    friend_day = 0,             %% 对方的持续天数
    limit_count = 0             %% 每日限购次数
    }).

%% 人物送礼数据
-record(flower, {
    flower_num = 0,         %% 鲜花数量
    charm = 0,              %% 魅力值
    fame = 0,               %% 名誉(慷慨值)
    week_charm = 0,         %% 周人气
    update_time = 0,        %% 周人气更新时间
    attr = [],              %% 属性
    sp_gift = []            %% [#sp_gift{},...]
    }).

-record(sp_gift, {
    key = undefined,        %% 主键
    start_time = 0,         %% 开始时间
    day = 0,                %% 持续天数
    sender = 0,             %% 赠送者 如果和玩家id相同,则是自己赠送所得到的特殊奖励领取机会
    goods_id = 0,           %% 物品id
    receive_times = []      %% 领取时间列表
    }).

%%鲜花榜
-record(flower_rank, {
    id = 0,
    rank = 0,
    sex = 0,
    goods_reward = [],
    name_reward = 0,
    red_packet_reward = 0,
    guild_reward = []
    }).

%%花语等级记录
-record(flower_level, {
    grade_id = 0,
    color = undefined,
    flower_name = undefined,
    % need_value_min = 0,
    need_value_max = 0,
    attr_list = [],
    add_power = 0
    }).

%% 鲜花礼物记录
-record(flower_gift_record, {
    id = 0,
    role_id = 0,
    other_id = 0,
    goods_id = 0,
    num = 0,
    anonymous = 0,
    time = 0,
    code = 0,
    thank = 0
    }).

%%查询语句
-define(sql_get_gift_record, 
    <<"select id, role_id, other_id, goods_id, num, anonymous, time, code, thank from flower_gift_record where role_id = ~p order by id desc limit ~p">>).
-define(sql_sel_role_flower_data, 
    <<"select charm, fame, flower_num, week_charm, update_time from `flower` where role_id = ~p limit 1">>).
-define(sql_select_week_charm, 
    <<"select week_charm from flower where role_id = ~p">>).
-define(sql_get_gift_record_count, 
    <<"select count(id) from flower_gift_record where role_id = ~p">>).
-define(sql_get_gift_record_min_id, 
    <<"select min(id) from flower_gift_record where role_id = ~p">>).
-define(sql_get_sp_gift,
    <<"select start_time, sender, day, goods_id, receive_time from role_flower_sp_gift where role_id = ~p">>).

%%删除语句
-define(sql_del_gift_record_by_id, 
    <<"delete from `flower_gift_record` where id = ~p">>).
-define(sql_del_gift_record_out_time, 
    <<"delete from `flower_gift_record` where time <= ~p">>).
-define(sql_del_sp_gift,
    <<"delete from `role_flower_sp_gift` where role_id = ~p and start_time = ~p and sender = ~p">>).

%%更新语句
-define(sql_insert_flower_gift_record, 
    <<"insert into `flower_gift_record` (id, role_id, other_id, goods_id, num, anonymous, time, code, thank) values (~p, ~p, ~p, ~p, ~p, ~p, ~p, ~p, ~p)">>).
-define(sql_update_flower_gift_record,
    <<"update `flower_gift_record` set thank = ~p where id = ~p">>).
-define(sql_insert_flower, 
    <<"insert into `flower` (role_id, charm, fame, flower_num, week_charm, update_time) values(~p, ~p, ~p, ~p, ~p, ~p)">>).
-define(sql_update_flower_data, 
    <<"update `flower` set charm = ~p, fame = ~p, flower_num = ~p where role_id = ~p">>).
-define(sql_update_charm, 
    <<"update `flower` set charm = ~p where role_id = ~p">>).
-define(sql_update_fame, 
    <<"update `flower` set fame = ~p where role_id = ~p">>).
-define(sql_replace_flower, 
    <<"replace into flower set role_id = ~p, flower_num = ~p, charm = ~p, fame = ~p, week_charm = ~p, update_time = ~p">>).

-define(sql_update_sp_gift,
    <<"update role_flower_sp_gift set receive_time = ~ts where role_id = ~p and start_time = ~p and sender = ~p">>).
-define(sql_replace_sp_gift,
    <<"replace into role_flower_sp_gift set role_id = ~p, start_time = ~p, sender = ~p, day = ~p, goods_id = ~p, receive_time = ~ts">>).