Home Database Mysql Tutorial 积分获取和消费的存储过程学习示例

积分获取和消费的存储过程学习示例

Jun 07, 2016 pm 04:19 PM
storage study Consumption Example integral Obtain process

这篇文章主要介绍了积分获取和消费的存储过程学习示例,这个只是学习一下存储过程的使用方法,需要的朋友可以参考下 1.GM_JF客户账户积分表 2. GM_JF_DETAIL客户账户积分消费记录 3. GM_JF_ACTION _RULES积分动作规则表 4.GM_JF_GOODS _RULES积分商品规则表 -

   这篇文章主要介绍了积分获取和消费的存储过程学习示例,这个只是学习一下存储过程的使用方法,需要的朋友可以参考下

  1.GM_JF客户账户积分表

  2. GM_JF_DETAIL客户账户积分消费记录

  3. GM_JF_ACTION _RULES积分动作规则表

  4.GM_JF_GOODS _RULES积分商品规则表

 

-- ===============测试=======================================================

/*

declare @StatusCode int = 1;

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

print @StatusCode

*/

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

/*

* 判断是否重复获取积分(首次完善个人资料,首次修改密码等等不能重复获取积分)

* 判断是根据 从GM_JF_DETAIL(详情表)查询周期内的数据条数与GM_JF_ACTION_RULES(动作规则表)内的周期重复次数对比

* 如果大于等于周期重复次数,则为重复获取积分

* 接下来

*     1.详情表的数据入库

*     2.判断总积分表是否存在对应客户的总积分 没有则插入一条新的,有 则读取其数据,并更新

*

*/

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     -- 状态码: 0:失败 1:成功 2: 不能重复获取

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,    --一个周期内允许最大次数

@realFrequency     int=0,     --实际周期

 

@USE_DATE     datetime = GETDATE();

--是否重复获取积分

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

 

if(@repetitionsCycle

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 = 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 = CONVERT(varchar(10),DATEADD(DAY,-(@repetitionsCycle-1),@USE_DATE),120)

END    

 

if(@realFrequency>=@repetitionsFrequency)    --实际周期大于周期次数

begin

set @StatusCode = 2;

return 2;

end

 

declare @count int = 0;     --数据条数

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;     --版本号

 

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(@@ERROR0)

BEGIN

set @StatusCode = 0;

ROLLBACK tran;

END

END

 

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1268
29
C# Tutorial
1246
24
Huawei will launch innovative MED storage products next year: rack capacity exceeds 10 PB and power consumption is less than 2 kW Huawei will launch innovative MED storage products next year: rack capacity exceeds 10 PB and power consumption is less than 2 kW Mar 07, 2024 pm 10:43 PM

This website reported on March 7 that Dr. Zhou Yuefeng, President of Huawei's Data Storage Product Line, recently attended the MWC2024 conference and specifically demonstrated the new generation OceanStorArctic magnetoelectric storage solution designed for warm data (WarmData) and cold data (ColdData). Zhou Yuefeng, President of Huawei's data storage product line, released a series of innovative solutions. Image source: Huawei's official press release attached to this site is as follows: The cost of this solution is 20% lower than that of magnetic tape, and its power consumption is 90% lower than that of hard disks. According to foreign technology media blocksandfiles, a Huawei spokesperson also revealed information about the magnetoelectric storage solution: Huawei's magnetoelectronic disk (MED) is a major innovation in magnetic storage media. First generation ME

Where to get Google security code Where to get Google security code Mar 30, 2024 am 11:11 AM

Google Authenticator is a tool used to protect the security of user accounts, and its key is important information used to generate dynamic verification codes. If you forget the key of Google Authenticator and can only verify it through the security code, then the editor of this website will bring you a detailed introduction on where to get the Google security code. I hope it can help you. If you want to know more Users please continue reading below! First open the phone settings and enter the settings page. Scroll down the page and find Google. Go to the Google page and click on Google Account. Enter the account page and click View under the verification code. Enter your password or use your fingerprint to verify your identity. Obtain a Google security code and use the security code to verify your Google identity.

Oracle DECODE function detailed explanation and usage examples Oracle DECODE function detailed explanation and usage examples Mar 08, 2024 pm 03:51 PM

The DECODE function in Oracle is a conditional expression that is often used to return different results based on different conditions in query statements. This article will introduce the syntax, usage and sample code of the DECODE function in detail. 1. DECODE function syntax DECODE(expr,search1,result1[,search2,result2,...,default]) expr: the expression or field to be compared. search1,

Go language indentation specifications and examples Go language indentation specifications and examples Mar 22, 2024 pm 09:33 PM

Indentation specifications and examples of Go language Go language is a programming language developed by Google. It is known for its concise and clear syntax, in which indentation specifications play a crucial role in the readability and beauty of the code. effect. This article will introduce the indentation specifications of the Go language and explain in detail through specific code examples. Indentation specifications In the Go language, tabs are used for indentation instead of spaces. Each level of indentation is one tab, usually set to a width of 4 spaces. Such specifications unify the coding style and enable teams to work together to compile

Let's learn how to input the root number in Word together Let's learn how to input the root number in Word together Mar 19, 2024 pm 08:52 PM

When editing text content in Word, you sometimes need to enter formula symbols. Some guys don’t know how to input the root number in Word, so Xiaomian asked me to share with my friends a tutorial on how to input the root number in Word. Hope it helps my friends. First, open the Word software on your computer, then open the file you want to edit, and move the cursor to the location where you need to insert the root sign, refer to the picture example below. 2. Select [Insert], and then select [Formula] in the symbol. As shown in the red circle in the picture below: 3. Then select [Insert New Formula] below. As shown in the red circle in the picture below: 4. Select [Radical Formula], and then select the appropriate root sign. As shown in the red circle in the picture below:

Git installation process on Ubuntu Git installation process on Ubuntu Mar 20, 2024 pm 04:51 PM

Git is a fast, reliable, and adaptable distributed version control system. It is designed to support distributed, non-linear workflows, making it ideal for software development teams of all sizes. Each Git working directory is an independent repository with a complete history of all changes and the ability to track versions even without network access or a central server. GitHub is a Git repository hosted on the cloud that provides all the features of distributed revision control. GitHub is a Git repository hosted on the cloud. Unlike Git which is a CLI tool, GitHub has a web-based graphical user interface. It is used for version control, which involves collaborating with other developers and tracking changes to scripts and

How to get points on QQ Music? QQ Music Points Collection Tutorial How to get points on QQ Music? QQ Music Points Collection Tutorial Mar 15, 2024 pm 10:49 PM

QQ Music is a player software with many types of music. You can search here for any type of music you want to listen to. The sound quality of all the music is very good and there are many different sound quality options. So do you know how to collect points on QQ Music? Detailed tutorial on how to collect points on QQ Music: 1. First open the [QQ Music] APP software and click the [My] function button in the bottom function bar. 2. Then click the [Activity Center] function button. 3. Then click the [Receive Points] button to receive the points. Software introduction: 1. High-quality music playback; 2. Album pictures and full-screen lyrics display; 3. Log in to QQ to synchronize my favorite songs on QQ Music on the computer; 4. Massive online

Learn the main function in Go language from scratch Learn the main function in Go language from scratch Mar 27, 2024 pm 05:03 PM

Title: Learn the main function in Go language from scratch. As a simple and efficient programming language, Go language is favored by developers. In the Go language, the main function is an entry function, and every Go program must contain the main function as the entry point of the program. This article will introduce how to learn the main function in Go language from scratch and provide specific code examples. 1. First, we need to install the Go language development environment. You can go to the official website (https://golang.org

See all articles