%% ---------------------------------------------------------
%% Author:  xyj
%% Email:   156702030@qq.com
%% Created: 2011-12-13
%% Description: 物品装备SQL定义
%% --------------------------------------------------------

%% --------------------------------- 生成物品%% ---------------------------------
-define(SQL_GOODS_INSERT,
        <<"insert into goods set id=~p, role_id=~p, goods_id=~p, type=~p, subtype=~p, location=~p, cell=~p,
           num=~p, create_time=UNIX_TIMESTAMP(), expire_time=~p, bind=~p, extra_data='~ts' ">>).

%% --------------------------------- 获取物品 ---------------------------------
-define(SQL_GOODS_LIST_DEFAULT,
    <<"select id, role_id, goods_id, type, subtype, location, cell, num, create_time, expire_time, bind, extra_data">>).

-define(SQL_GOODS_SELECT_BY_ID,     <<?SQL_GOODS_LIST_DEFAULT/binary,
    <<" from `goods` where id=~p and role_id = ~p">>/binary >>).

-define(SQL_GOODS_LIST_BY_LOCATION, <<?SQL_GOODS_LIST_DEFAULT/binary,
    <<" from `goods` where role_id = ~p and location = ~p">>/binary >>).

%% --------------------------------- 物品更改 ---------------------------------
-define(SQL_GOODS_UPDATE_NUM,
    <<"update `goods` set num = ~p where id = ~p and role_id = ~p">>).
-define(SQL_GOODS_UPDATE_LOCATION_CELL,
    <<"update `goods` set location = ~p, cell = ~p, extra_data='~ts' where id = ~p and role_id = ~p">>).
-define(SQL_GOODS_UPDATE_LOCATION_CELL_BIND,
    <<"update `goods` set location = ~p, cell = ~p, bind=~p, extra_data='~ts' where id = ~p and role_id = ~p">>).
-define(SQL_GOODS_UPDATE_OTHER,
    <<"update `goods` set extra_data = '~ts' where id = ~p and role_id = ~p">>).
-define(SQL_GOODS_UPDATE_EXPIRE,
    <<"update `goods` set expire_time = ~p where id = ~p and role_id = ~p">>).
-define(SQL_GOODS_UPDATE_EXTRA, <<"update `goods_extra` set stren = ~p, exp = ~p, stage = ~p, dstone = '~s', stren_expend = ~p where gid = ~p">>).

-define(SQL_GOODS_UPDATE_INFO,
    <<"update goods set goods_id=~p,type=~p,subtype=~p,create_time=UNIX_TIMESTAMP(),extra_data='~ts' where id=~p and role_id=~p">>).

%% --------------------------------- 物品删除 ---------------------------------
-define(SQL_GOODS_DELETE_BY_ID,
    <<"delete from `goods` where `id` = ~p and `role_id` = ~p">>).

%% --------------------------------- 背包操作 ---------------------------------
-define(SQL_PLAYER_UPDATE_CELL,     <<"update `player_attr` set cell_num=~p where id=~p">>).
-define(SQL_PLAYER_UPDATE_STORAGE_NUM, <<"update `player_attr` set storage_num=~p where id=~p">>).

%% --------------------------------- 虚拟货币 ---------------------------------
-define (SQL_INSERT_CURRENCY,                   <<"INSERT INTO `player_special_currency`(`player_id`, `currency_id`, `num`) VALUES (~p, ~p, ~p)">>).

-define (SQL_UPDATE_CURRENCY,                   <<"UPDATE `player_special_currency` SET `num`=~p WHERE `player_id` = ~p AND `currency_id` = ~p">>).

-define (LOAD_CURRENCY,                         <<"SELECT `currency_id`, `num` FROM `player_special_currency` WHERE `player_id` = ~p">>).





%% --------------------------------- 礼包 ---------------------------------
-define(SQL_GIFT_QUEUE_DELETE,                  <<"delete from `gift_list` where player_id=~p ">>).

%% gift_card
-define(SQL_GIFT_CARD_INSERT,                   <<"insert into `gift_card` set player_id=~p, card_no='~s', type=~p, time=~p, status=1 ">>).
-define(SQL_GIFT_CARD_SELECT,                   <<"select status from `gift_card` where card_no='~s' ">>).
-define(SQL_GIFT_CARD_BASE_SELECT,              <<"select card_no from `base_gift_card` where accname='~s' limit 1 ">>).

-define(SQL_CHARGE_SELECT,                      <<"select id from `charge` where player_id=~p and status=1 limit 1 ">>).


