%%%---------------------------------------------------------------------
%%% 充值相关define定义
%%%---------------------------------------------------------------------


%% ============================= 商品大类 =============================
-define(PRODUCT_TYPE_NORMAL,    1).    %% 普通充值(含充值返利)
-define(PRODUCT_TYPE_WELFARE,   2).    %% 福利卡
-define(PRODUCT_TYPE_DAILY_GIFT,3).    %% 每日礼包
-define(PRODUCT_TYPE_GIFT,      4).    %% 直购礼包
-define(PRODUCT_TYPE_FIRST_GIFT,5).    %% 首充礼包
-define(PRODDUCT_TYPE_CONTRACT, 6).    %% 契约直购


-define(PRODUCT_TYPE_VERIFY,    99).   %% 审核专用


%% ============================= 商品子类 =============================

%% 福利卡－－－－－－－－－－－－
-define(WELFARE_SUBTYPE_QUARTER, 3).    %% 季度卡
-define(WELFARE_SUBTYPE_MONTH,   2).    %% 月卡
-define(WELFARE_SUBTYPE_WEEK,    1).    %% 周卡
-define(QUARTER_MAX, 1).    %% 每日最大购买季度卡次数
-define(MONTH_MAX,   2).    %% 每日最大购买月卡次数
-define(WEEK_MAX,    3).    %% 每日最大购买周卡次数
-define(WELFARE_MONTH_AND_QUARTER_ADD, 6).    %% 月卡+季度卡幻魔橙装掉率加成
-define(WELFARE_QUARTER_ADD,   4).     %% 季度卡幻魔橙装掉率加成
-define(WELFARE_MONTH_ADD,     2).     %% 月卡幻魔橙装掉率加成
-define(PRODUCT_TYPE_SELLSWORDS_RESUPPLY, 5).    %% 佣兵补给

%% ============================= 返利类型 =============================
-define(RETURN_TYPE_NO,             0).	%% 返利类型：无返利
-define(RETURN_TYPE_LIFE_FIRST,     1).	%% 返利类型：终生首次
-define(RETURN_TYPE_ACT_FIRST,      2).	%% 返利类型：活动时间首次

%% ============================= 限购类型 =============================
-define(PRODUCT_LIMIT_DAILY,   1).    %% 日限购
-define(PRODUCT_LIMIT_WEEK,    2).    %% 周限购
-define(PRODUCT_LIMIT_LIFE,    3).    %% 终生限购
-define(PRODUCT_LIMIT_MONTH,   4).    %% 月限购

-define(PAY_TOTAL_RECHARGE(RoleId), lists:concat(["recharge_total_gold_", RoleId])).
%% ===================================================================
%% 充值后更新同账号的总充值金额-元宝
-define(sql_acc_charge_update_total,<<"UPDATE acc_share_data SET total_charge = total_charge + ~p WHERE accid=~p and accname = '~s'">>).

%% 充值统计-查询总充值金额-元宝
-define(sql_recharge_get_total,     <<"SELECT `total_gold` FROM player_recharge_rfmt WHERE role_id=~p">>).
%% 充值统计-取出玩家指定期间的充值总额(是人民币)
-define(sql_get_pay_rmb_sum,        <<"SELECT total_money FROM player_recharge_rfmt WHERE role_id=~p">>).
%% 充值统计-取出统计
-define(sql_get_recharge_statistic,
        <<"select last_pay_time,total_money,total_gold,recency,frequency,monetary,top from player_recharge_rfmt where role_id=~p">>).
%% 充值统计-保存充值
-define(sql_save_recharge_statistic,
        <<"replace into player_recharge_rfmt(role_id,last_pay_time,total_money,total_gold,recency,frequency,monetary,top) values(~p,~p,~p,~p,~p,~p,~p,~p)">>).
%% 充值统计-取出总充值金额在一定数量以上的玩家
-define(sql_pay_gold_player_id,      <<"SELECT `role_id` FROM player_recharge_rfmt WHERE `total_gold` >= ~p ">>).

%% 写入充值订单(只用于秘籍)
-define(sql_pay_insert_gm,          <<"INSERT INTO `charge`(`type`,pay_no,accname,player_id,nickname,product_id,money,gold,ctime,status,lv)  VALUES(~p, ~p, '~s', ~p, '~ts', ~p, ~p, ~p, ~p, ~p, ~p)" >>).
%% 取出充值待处理的记录
-define(sql_pay_fetch_all,          <<"SELECT `id`, `player_id`, `ctime` FROM `charge` WHERE `status`=0">>).
%% 更新充值待处理的记录的状态为已处理
-define(sql_pay_update_recharge,    <<"UPDATE `charge` SET `status`=1 WHERE id=~p AND `status`=0">>).
%% 取出指定玩家所有待处理的充值记录
-define(sql_pay_fetch_all_of_user,  <<"SELECT `id`, `type`, `product_id`, `money`, `gold`, `ctime`, `pay_no` FROM `charge` WHERE `player_id`=~p AND `status`=0 ORDER BY `id`">>).
%% 取出一定时间内玩家的充值总额
-define(sql_pay_task_get_gold,      <<"SELECT SUM(gold) FROM recharge_log WHERE player_id=~p AND time >= ~p AND time < ~p">>).

%% 取出指定时间范围，充值玩家的充值额
-define(SQL_SELECT_PAY_ROLES_GOLD, <<"SELECT player_id,SUM(gold) FROM recharge_log WHERE time >= ~p AND time < ~p GROUP BY player_id">>).
%% 取出指定时间范围，充值玩家的id列表
-define(SQL_SELECT_PAY_ROLE_IDS, <<"SELECT DISTINCT player_id FROM recharge_log WHERE time >= ~p AND time < ~p">>).

%% 取出充值元宝道具使用总额
-define(sql_gold_goods_total,       <<"SELECT SUM(gold) FROM recharge_log WHERE `player_id`=~p AND `type`=2 AND time >= ~p AND time < ~p">>).
%% 根据充值日志取出最后充值时间
-define(sql_get_last_pay_time,      <<"SELECT `time` FROM `recharge_log` WHERE `player_id`=~p ORDER BY `time` DESC LIMIT 1">>).

%% 更新玩家最后充值时间
-define(sql_update_last_pay_time,   <<"update player_login set last_pay_time=~p where id=~p">>).

%% 插入充值日志（根据charge的记录插入，以及元宝卡）
-define(sql_insert_recharge_log,
        <<"insert into `recharge_log`(`accid`, `accname`, `player_id`, `type`, `product_id`, `money`, `gold`, `time`) values(~p, '~s', ~p, ~p, ~p, ~p, ~p, ~p)">>).

-define(sql_delete_recharge_log,
        <<"delete from recharge_log where player_id = ~p and `id` = ~p">>).

%% 获得充值数据 - 最大取一千条记录
-define(sql_get_recharge_list,
        <<"SELECT `time`, `type`, `money`, `gold` FROM `recharge_log` WHERE `accid`=~p AND `accname`='~s' AND `player_id`=~p AND `time`>=~p order by `time` desc limit 1000">>).

-define(sql_get_recharge_list_by_player_id,
        <<"SELECT `time`, `type`, `money`, `gold` FROM `recharge_log` WHERE `player_id`=~p AND `time`>=~p order by `time` desc limit 1000">>).
