当前位置: 移动技术网 > IT编程>数据库>MSSQL > 做购物车系统时利用到得几个sqlserver 存储过程

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

2017年12月12日  | 移动技术网IT编程  | 我要评论

坏蛋是怎样炼成的3曹三少,稳压二极管封装,君如陌上尘txt下载

即以游客身份登录网站时以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

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网