做購物車系統(tǒng)時利用到得幾個sqlserver 存儲過程
發(fā)布日期:2022-01-30 14:51 | 文章來源:源碼中國
其中涉及到的存儲過程主要如下:
一:已登錄會員添加商品到購物車功能:
復制代碼 代碼如下:
/* @store_sum表示要添加的商品數(shù)量,添加同時確認購物車中自己已有的數(shù)量與將要加入的數(shù)量之和是否超過庫存 */
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
版權聲明:本站文章來源標注為YINGSOO的內容版權均為本站所有,歡迎引用、轉載,請保持原文完整并注明來源及原文鏈接。禁止復制或仿造本網站,禁止在非maisonbaluchon.cn所屬的服務器上建立鏡像,否則將依法追究法律責任。本站部分內容來源于網友推薦、互聯(lián)網收集整理而來,僅供學習參考,不代表本站立場,如有內容涉嫌侵權,請聯(lián)系alex-e#qq.com處理。
相關文章
關注官方微信