|
%%%-------------------------------------------------------------------
|
|
%%% @doc 扭蛋-头文件
|
|
%%% Module : capsule_egg.hrl
|
|
%%% Created : 2020-06-24
|
|
%%% @Author : tyl
|
|
%%%-------------------------------------------------------------------
|
|
|
|
%% 抽奖池类型
|
|
-define(POOL_TYPE_DRAGON, 1). %% 龙神宝库
|
|
-define(POOL_TYPE_WEAPON, 2). %% 炫武宝库
|
|
-define(POOL_TYPE_CLOTH, 3). %% 华裳宝库
|
|
-define(POOL_TYPE_LIST, [1,2,3]). %% 所有奖池
|
|
|
|
%% 连抽次数
|
|
-define(DRAW_TIMES_LIST, [1,10,50]).
|
|
%% 单抽免费时间间隔
|
|
-define(FREE_DRAW_INTERVAL, 86400).
|
|
|
|
%% 目前所有档位 - 0/1/2/3
|
|
%% 0/1/2档划分为一类,第3档划分为二类,其他档位不上电视
|
|
%% 抽奖上电视最低档位
|
|
-define(TV_GRADE, 3).
|
|
%% 一类最低档位
|
|
-define(TV_TOP, 2).
|
|
%% 置顶档位列表
|
|
-define(TV_TOP_LIST, [1,2]).
|
|
%% 一二类记录限制条数(保底,具体看常量配置)
|
|
-define(TV_ONE, data_capsule_egg:get_capsule_egg_kv_cfg(show_num_one)).
|
|
-define(TV_TWO, data_capsule_egg:get_capsule_egg_kv_cfg(show_num_two)).
|
|
|
|
%% 临时仓库将满提醒
|
|
-define(CAPSULE_EGG_NULL_CELL, 50).
|
|
%% 全服最大幸运值
|
|
-define(SERVER_MAX_LUCKY, 999).
|
|
|
|
%% 概率加成类型
|
|
-define(RAND_ADD_PERSONAL, 1). %% 个人
|
|
-define(RAND_ADD_SERVER, 2). %% 全服
|
|
|
|
%% 积分商城兑换限制类型
|
|
-define(SCORE_STORE_LIMIT_DAILY, 1). %% 每日次数限制
|
|
-define(SCORE_STORE_LIMIT_WEEK, 2). %% 每周次数限制
|
|
-define(SCORE_STORE_LIMIT_LIFE, 3). %% 终身次数限制
|
|
|
|
%% 玩家扭蛋数据
|
|
-record(status_capsule_egg, {
|
|
capsule_egg_map = #{} %% 扭蛋数据(共三个抽奖池) #{pool_type => #capsule_egg_data{}}
|
|
,score = 0 %% 总抽奖积分,用于兑换积分商城物品
|
|
}).
|
|
|
|
%% 扭蛋抽奖数据
|
|
-record(capsule_egg_data, {
|
|
pool_type = 0 %% 抽奖池类型
|
|
,next_free_time = 0 %% 下次免费时间
|
|
,draw_times = 0 %% 抽奖次数(计算必得)
|
|
,lucky_score = 0 %% 个人幸运值, 计算动态权重(获得一二档之后清0)
|
|
,top_lucky_score= 0 %% 0当奖励的个人幸运值(获得0档之后清0)
|
|
,times_reward = [] %% 次数奖励[{times,status}...] status-1 已领取
|
|
}).
|
|
|
|
%% 全服扭蛋数据
|
|
-record(capsule_egg_state, {
|
|
lucky_score_map = #{} %% 全服幸运值 #{pool_type => server_score}
|
|
,show_lucky_map = #{} %% 展示给前端的全服幸运值 #{pool_type => show_score}
|
|
,record_map = #{} %% 二类(3档)抽奖记录 #{pool_type => [#draw_record{}]}
|
|
,top_record_map = #{} %% 一类(1/2档)抽奖记录 #{pool_type => [#draw_record{}]}
|
|
,weekly_refresh_ref = [] %% 周期清理定时器
|
|
}).
|
|
|
|
%% 抽奖记录
|
|
-record(draw_record, {
|
|
pool_type = 0 %% 抽奖池类型
|
|
,role_id = 0 %% 角色Id
|
|
,role_name = 0 %% 角色名称
|
|
,reward_cfg_id = 0 %% 奖励配置Id
|
|
,draw_time = 0 %% 抽奖时间
|
|
}).
|
|
|
|
|
|
%% ==================================== 后台配置 ===========================
|
|
%% 扭蛋基础配置表
|
|
-record(capsule_egg_kv_cfg, {
|
|
id = 0 %% Id
|
|
,key = "" %% 主键
|
|
,value = "" %% 值
|
|
,remark = "" %% 备注
|
|
}).
|
|
|
|
%% 抽奖物品配置表
|
|
-record(capsule_egg_reward_cfg, {
|
|
id = 0 %% Id
|
|
,pool_type = 0 %% 奖池类型
|
|
,color = 0 %% 档位(品质)
|
|
,reward = [] %% 奖励列表
|
|
,weight = 0 %% 权重
|
|
,client_pos = 0 %% 客户端推荐展示位置
|
|
}).
|
|
|
|
%% 动态概率配置表
|
|
-record(capsule_egg_ratio_cfg, {
|
|
pool_type = 0 %% 奖池类型
|
|
,color = 0 %% 档位
|
|
,type = 0 %% 概率类型 1-个人 2-全服
|
|
,low = 0 %% 下限(抽奖次数)
|
|
,high = 0 %% 上限
|
|
,add_weight = 0 %% 权重加成
|
|
}).
|
|
|
|
%% 次数必得配置表
|
|
-record(capsule_egg_times_cfg, {
|
|
pool_type = 0 %% 奖池类型
|
|
,draw_times = 0 %% 抽奖次数
|
|
,select_color = 0 %% 必得物品品质
|
|
}).
|
|
|
|
%% 积分商城兑换配置表
|
|
-record(capsule_egg_exchange_cfg, {
|
|
id = 0 %% 序号
|
|
,reward = [] %% 兑换物品
|
|
,cost_score = 0 %% 消耗积分
|
|
,exchange_times = 0 %% 可兑换次数
|
|
,limit_type = 0 %% 限购类型 1-日 2-周 3-终身
|
|
}).
|
|
|
|
%% 次数奖励配置表
|
|
-record(capsule_egg_times_reward_cfg, {
|
|
pool_type = 0 %% 奖池类型
|
|
,draw_times = 0 %% 抽奖次数
|
|
,reward = [] %% 奖励
|
|
}).
|
|
|
|
%% ============================= 数据库操作 =============================
|
|
%% 个人抽奖数据
|
|
-define(SQL_INSERT_CAPSULE_EGG, <<"REPLACE INTO capsule_egg_data (`role_id`, `pool_type`, `next_free_time`, `draw_times`, `lucky_score`, `top_lucky_score`) VALUES (~p, ~p, ~p, ~p, ~p, ~p)">>).
|
|
-define(SQL_SELECT_CAPSULE_EGG, <<"SELECT `pool_type`, `next_free_time`, `draw_times`, `lucky_score`, `top_lucky_score` FROM capsule_egg_data WHERE `role_id` = ~p">>).
|
|
-define(SQL_UPDATE_CAPSULE_EGG, <<"UPDATE capsule_egg_data SET `next_free_time` = ~p, `draw_times` = ~p WHERE `role_id` = ~p AND `pool_type` = ~p">>).
|
|
-define(SQL_UPDATE_FREE_TIME, <<"UPDATE capsule_egg_data SET `next_free_time` = ~p WHERE `role_id` = ~p AND `pool_type` = ~p">>).
|
|
-define(SQL_UPDATE_DRAW_TIMES, <<"UPDATE capsule_egg_data SET `draw_times`= 0">>).
|
|
|
|
%% 个人抽奖积分
|
|
-define(SQL_INSERT_CAPSULE_EGG_PERSON_SCORE, <<"REPLACE INTO capsule_egg_person_score (`role_id`, `score`) VALUES (~p, ~p)">>).
|
|
-define(SQL_SELECT_CAPSULE_EGG_PERSON_SCORE, <<"SELECT `score` FROM capsule_egg_person_score WHERE `role_id` = ~p LIMIT 1">>).
|
|
|
|
%% 全服抽奖幸运值积分
|
|
-define(SQL_INSERT_CAPSULE_EGG_SERVER_LUCKY, <<"REPLACE INTO capsule_egg_server_score (`pool_type`, `score`, `show_score`) VALUES (~p, ~p, ~p)">>).
|
|
-define(SQL_SELECT_CAPSULE_EGG_SERVER_LUCKY, <<"SELECT `pool_type`,`score`, `show_score` FROM capsule_egg_server_score">>).
|
|
|
|
%% 0档奖励全服抽奖幸运值积分(暂时未使用)
|
|
-define(SQL_INSERT_CAPSULE_EGG_TOP_SERVER_LUCKY, <<"REPLACE INTO capsule_egg_top_server_score (`pool_type`, `score`) VALUES (~p, ~p)">>).
|
|
-define(SQL_SELECT_CAPSULE_EGG_TOP_SERVER_LUCKY, <<"SELECT `pool_type`,`score` FROM capsule_egg_top_server_score">>).
|
|
|
|
%% 全服抽奖记录
|
|
-define(SQL_INSERT_CAPSULE_EGG_DRAW_LOG, <<"REPLACE INTO capsule_egg_draw_log (`pool_type`, `role_id`, `reward_cfg_id`, `color`, `time`) VALUES (~p, ~p, ~p, ~p, ~p)">>).
|
|
-define(SQL_BATCH_INSERT_CAPSULE_EGG_DRAW_LOG, <<"REPLACE INTO capsule_egg_draw_log (`pool_type`, `role_id`, `reward_cfg_id`, `color`, `time`) VALUES ~ts">>).
|
|
-define(SQL_BATCH_INSERT_CAPSULE_EGG_DRAW_LOG_VALUE, <<"(~p, ~p, ~p, ~p, ~p)">>).
|
|
-define(SQL_SELECT_CAPSULE_EGG_DRAW_LOG, <<"SELECT `pool_type`, `role_id`, `reward_cfg_id`, `color`, `time` FROM capsule_egg_draw_log WHERE `time` >= ~p AND `color` = 3 ORDER BY `time` desc LIMIT ~p">>).
|
|
-define(SQL_SELECT_TOP_CAPSULE_EGG_DRAW_LOG, <<"SELECT `pool_type`, `role_id`, `reward_cfg_id`, `color`, `time` FROM capsule_egg_draw_log WHERE `time` >= ~p AND `color` < 3 ORDER BY `time` desc LIMIT ~p">>).
|
|
|
|
%% 次数奖励
|
|
-define(SQL_INSERT_CAPSULE_EGG_TIMES_REWARD, <<"REPLACE INTO capsule_egg_times_reward (`role_id`, `pool_type`, `draw_times`, `status`) VALUES (~p, ~p, ~p, ~p)">>).
|
|
-define(SQL_SELECT_CAPSULE_EGG_TIMES_REWARD, <<"SELECT `draw_times`, `status` from capsule_egg_times_reward WHERE `role_id` = ~p AND `pool_type` = ~p">>).
|
|
-define(SQL_DELETE_CAPSULE_EGG_TIMES_REWARD, <<"TRUNCATE table capsule_egg_times_reward">>).
|
|
|
|
%% 查询玩家名称
|
|
-define(SQL_SELECT_PLAYER_NAME, <<"select nickname from player_low where id = '~w' limit 1">>).
|
|
|
|
%% capsule_egg_data, capsule_egg_person_score, capsule_egg_server_score, capsule_egg_draw_log
|