積分獲取和消費(fèi)的存儲(chǔ)過(guò)程學(xué)習(xí)示例
來(lái)源:易賢網(wǎng) 閱讀:938 次 日期:2014-05-12 14:54:24
溫馨提示:易賢網(wǎng)小編為您整理了“積分獲取和消費(fèi)的存儲(chǔ)過(guò)程學(xué)習(xí)示例”,方便廣大網(wǎng)友查閱!

1.GM_JF客戶(hù)賬戶(hù)積分表

2. GM_JF_DETAIL客戶(hù)賬戶(hù)積分消費(fèi)記錄

3. GM_JF_ACTION _RULES積分動(dòng)作規(guī)則表

4.GM_JF_GOODS _RULES積分商品規(guī)則表

代碼如下:

-- ===============測(cè)試=======================================================

/*

declare @StatusCode int = 1;

exec sp_GM_JF_AddScore 'admin','AN_JF_001_001',1,5,0,'',@StatusCode output

print @StatusCode

*/

-- ===========================================================================

/*

* 判斷是否重復(fù)獲取積分(首次完善個(gè)人資料,首次修改密碼等等不能重復(fù)獲取積分)

* 判斷是根據(jù) 從GM_JF_DETAIL(詳情表)查詢(xún)周期內(nèi)的數(shù)據(jù)條數(shù)與GM_JF_ACTION_RULES(動(dòng)作規(guī)則表)內(nèi)的周期重復(fù)次數(shù)對(duì)比

* 如果大于等于周期重復(fù)次數(shù),則為重復(fù)獲取積分

* 接下來(lái)

* 1.詳情表的數(shù)據(jù)入庫(kù)

* 2.判斷總積分表是否存在對(duì)應(yīng)客戶(hù)的總積分 沒(méi)有則插入一條新的,有 則讀取其數(shù)據(jù),并更新

*

*/

ALTER PROCEDURE [dbo].[sp_GM_JF_AddScore]

@ACCOUNT_ID varchar(30),

@JF_CategoryNumber varchar(15),

@CARD_NUM int,

@HQ_JF_AMOUNT int,

@State varchar(16),

@USE_DESC varchar(400),

@StatusCode int output -- 狀態(tài)碼: 0:失敗 1:成功 2: 不能重復(fù)獲取

AS

BEGIN

-- SET NOCOUNT ON added to prevent extra result sets from

-- interfering with SELECT statements.

SET NOCOUNT ON;

declare

@repetitionsCycle float=0, --周期(天)

@repetitionsCycle_second int=0,--周期(秒)

@repetitionsFrequency int=0, --一個(gè)周期內(nèi)允許最大次數(shù)

@realFrequency int=0, --實(shí)際周期

@USE_DATE datetime = GETDATE();

--是否重復(fù)獲取積分

select top(1) @repetitionsCycle=RepetitionsCycle,@repetitionsFrequency=RepetitionsFrequency from GM_JF_ACTION_RULES where AN_CategoryNumber=@JF_CategoryNumber;

if(@repetitionsCycle<1)

BEGIN

set @repetitionsCycle_second = (@repetitionsCycle-1)*24*60*60;

select @realFrequency=COUNT(1) from GM_JF_DETAIL where ACCOUNT_ID=@ACCOUNT_ID and JF_CategoryNumber=@JF_CategoryNumber and USE_DATE <= @USE_DATE and USE_DATE >= CONVERT(varchar(19),DATEADD(SECOND,-@repetitionsCycle_second,@USE_DATE),120)

END

ELSE

BEGIN

select @realFrequency=COUNT(1) from GM_JF_DETAIL where ACCOUNT_ID=@ACCOUNT_ID and JF_CategoryNumber=@JF_CategoryNumber and USE_DATE <= @USE_DATE and USE_DATE >= CONVERT(varchar(10),DATEADD(DAY,-(@repetitionsCycle-1),@USE_DATE),120)

END

if(@realFrequency>=@repetitionsFrequency) --實(shí)際周期大于周期次數(shù)

begin

set @StatusCode = 2;

return 2;

end

declare @count int = 0; --數(shù)據(jù)條數(shù)

declare @temp_table table --表變量

(

ACCOUNT_ID varchar(30),

JF_AMOUNT decimal(16,2),

TTL_JF_AMOUNT decimal(16,2),

Last_Update_Time datetime,

[Version] int

);

begin tran;

--插入詳情

insert into GM_JF_DETAIL

(ACCOUNT_ID,JF_CategoryNumber,CARD_NUM,HQ_JF_AMOUNT,[State],USE_DESC)

values

(@ACCOUNT_ID,@JF_CategoryNumber,@CARD_NUM,@HQ_JF_AMOUNT,@State,@USE_DESC)

--填充表變量

insert into @temp_table select ACCOUNT_ID,JF_AMOUNT,TTL_JF_AMOUNT,Last_Update_Time,[Version] from GM_JF where ACCOUNT_ID=@ACCOUNT_ID

select @count = count(1) from @temp_table;

--判斷并更新總積分(0:添加 其他:修改)

IF(@count=0)

begin

insert into GM_JF(ACCOUNT_ID,JF_AMOUNT,TTL_JF_AMOUNT)

values

(@ACCOUNT_ID,@HQ_JF_AMOUNT,@HQ_JF_AMOUNT)

end

else

begin

declare @JF_AMOUNT int, --總積分

@TTL_JF_AMOUNT int, --可用積分

@Version int; --版本號(hào)

select @JF_AMOUNT=JF_AMOUNT,@TTL_JF_AMOUNT=TTL_JF_AMOUNT,@Version=[Version] from @temp_table where ACCOUNT_ID=@ACCOUNT_ID;

update GM_JF set JF_AMOUNT=(@JF_AMOUNT+@HQ_JF_AMOUNT),TTL_JF_AMOUNT=(@TTL_JF_AMOUNT+@HQ_JF_AMOUNT),Last_Update_Time=GETDATE(),[Version]=(@Version+1) where ACCOUNT_ID=@ACCOUNT_ID

end

Commit tran;

set @StatusCode = 1;

IF(@@ERROR<>0)

BEGIN

set @StatusCode = 0;

ROLLBACK tran;

END

END

更多信息請(qǐng)查看IT技術(shù)專(zhuān)欄

更多信息請(qǐng)查看數(shù)據(jù)庫(kù)
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢(xún)回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門(mén)公布的正式信息和咨詢(xún)?yōu)闇?zhǔn)!

2025國(guó)考·省考課程試聽(tīng)報(bào)名

  • 報(bào)班類(lèi)型
  • 姓名
  • 手機(jī)號(hào)
  • 驗(yàn)證碼
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢(xún) | 簡(jiǎn)要咨詢(xún)須知 | 加入群交流 | 手機(jī)站點(diǎn) | 投訴建議
工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
云南網(wǎng)警備案專(zhuān)用圖標(biāo)
聯(lián)系電話(huà):0871-65099533/13759567129 獲取招聘考試信息及咨詢(xún)關(guān)注公眾號(hào):hfpxwx
咨詢(xún)QQ:526150442(9:00—18:00)版權(quán)所有:易賢網(wǎng)
云南網(wǎng)警報(bào)警專(zhuān)用圖標(biāo)