做购物车系统时利用到得几个sqlserver 存储过程

2022-05-24 0 1,182

即以游客身份登录网站时以cookie的方式存储购物车,而以登录用户的身份进入时将购物车信息存储到数据库中去,若是先以游客身份完成购物再登录继续购物,则将cookies购物车存入数据库;

其中涉及到的存储过程主要如下:

一:已登录会员添加商品到购物车功能:


复制代码 代码如下:

/* @store_sum表示要添加的商品数量,添加同时确认购物车中自己已有的数量与将要加入的数量之和是否超过库存 */

CREATE proc ncp_Cart_Add

(

@store_id int,

@store_sum int=1,

@member_id int

)

as

DECLARE @Amount int

DECLARE @NowAmount int

Begin

select @Amount=(select amount from ncp_store where id=@store_id)

IF EXISTS(SELECT 1 FROM [ncp_cart] WHERE store_id=@store_id and member_id=@member_id)

Begin

select @NowAmount=(select store_sum+@store_sum from ncp_cart WHERE store_id=@store_id and member_id=@member_id)

if @NowAmount>@Amount

return 0

else

UPDATE [ncp_cart] SET store_sum=store_sum+@store_sum,addtime=getDate() where store_id=@store_id and member_id=@member_id

return 1

End

ELSE

Begin

select @NowAmount=(select store_sum from ncp_cart WHERE store_id=@store_id and member_id=@member_id)

if @NowAmount>@Amount

return 0

else

INSERT INTO [ncp_cart](store_id,store_sum,member_id) values(@store_id,@store_sum,@member_id)

return 1

END

End

GO

二:购物车的删除功能

复制代码 代码如下:

/* type 为1是全部删 0时只删一个 */

CREATE PROCEDURE ncp_Cart_Del

@type int=0,

@store_id int ,

@member_id int

AS

begin

if @type=0

delete from [ncp_cart] where store_id=@store_id and member_id=@member_id

else

delete from [ncp_cart] where member_id=@member_id

End

GO

免责声明:
1、本网站所有发布的源码、软件和资料均为收集各大资源网站整理而来;仅限用于学习和研究目的,您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。 不得使用于非法商业用途,不得违反国家法律。否则后果自负!

2、本站信息来自网络,版权争议与本站无关。一切关于该资源商业行为与www.niceym.com无关。
如果您喜欢该程序,请支持正版源码、软件,购买注册,得到更好的正版服务。
如有侵犯你版权的,请邮件与我们联系处理(邮箱:skknet@qq.com),本站将立即改正。

NICE源码网 MsSql 做购物车系统时利用到得几个sqlserver 存储过程 https://www.niceym.com/59976.html