不实用,之所以写,一为领导的要求,另外也熟悉下写代码,代码多写点也没什么坏处,并且写了之后发现临时表还挺容易用的,数据量小的时候,并显不出临时表速度不行的问题.
代码如下:
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
/*
Name:游戏中四人数据同时更新
Designed By :whbo
Designed At :2005-10-12
Modified By :
Modified At :
Memo:
*/
ALTER PROC [PrMoney_UpdateCash2]
@chvModeName varchar(16),
@chvSourceName varchar(64),
@chvRemark varchar(128),
@intUserID1 int,
@intUserID2 int,
@intUserID3 int,
@intUserID4 int,
@intWantedAmount1 int,
@intWantedAmount2 int,
@intWantedAmount3 int,
@intWantedAmount4 int,
@chvIPAddress1 varchar(15),
@chvIPAddress2 varchar(15),
@chvIPAddress3 varchar(15),
@chvIPAddress4 varchar(15),
@inyLog tinyint
as
set nocount on
set xact_abort on
Declare @intCashAmount1 int,@intCashAmount2 int,@intCashAmount3 int,@intCashAmount4 int
Declare @FRate float,@FTemp float
Declare @bNeedReCalc bit --0:不用重算 ;1:需要重算
set @FRate=1.0
set @FTemp=1.0
set @bNeedReCalc=0
Declare @FTemp1 float,@FTemp2 float,@FTemp3 float,@FTemp4 float
--这里要注意,更新用户现金取数据库中的数据,跟游戏服务器能否保持一致
--取得用户现金
select @intCashAmount1=[Amount] from [dbo].[Money] where [UserID]=@intUserID1
select @intCashAmount2=[Amount] from [dbo].[Money] where [UserID]=@intUserID2
select @intCashAmount3=[Amount] from [dbo].[Money] where [UserID]=@intUserID3
select @intCashAmount4=[Amount] from [dbo].[Money] where [UserID]=@intUserID4
Create Table #Temp1(TTemp float)
if @intCashAmount1+@intWantedAmount1<0
begin
set @FTemp=-@intCashAmount1/@intWantedAmount1
insert into #temp1 values(@FTemp)
end
if @intCashAmount2+@intWantedAmount2<0
begin
set @FTemp=-@intCashAmount2/@intWantedAmount2
insert into #temp1 values(@FTemp)
end
if @intCashAmount3+@intWantedAmount3<0
begin
set @FTemp=-@intCashAmount3/@intWantedAmount3
insert into #temp1 values(@FTemp)
end
if @intCashAmount4+@intWantedAmount4<0
begin
set @FTemp=-@intCashAmount4/@intWantedAmount4
insert into #temp1 values(@FTemp)
end
set @FTemp=(select min(@FTemp) from #temp)
drop table #temp1
if @FTemp<@FRate
begin
set @FRate=@FTemp
set @BNeedReCalc=1
end
if @BNeedReCalc=1
begin
set @intWantedAmount1=@intWantedAmount1*@FRate
set @intWantedAmount2=@intWantedAmount2*@FRate
set @intWantedAmount3=@intWantedAmount3*@FRate
set @intWantedAmount4=@intWantedAmount4*@FRate
end
begin tran
exec [prMoney_UpdateCash]
@chvModeName, -- 通过什么方式,如'WEB'、'GameServer'等
@chvSourceName, -- 方式的源,如'金币麻将服务器'、'虚拟股市'等
@chvRemark, -- 其它信息 注释.
@intUserID1, -- 用户ID
0, -- 相关的用户ID
@intWantedAmount1, -- 希望更新的数量(0 加金, <0 扣金)
0, -- 税金(税金0,要在现金中扣除,游戏服务器可以置为0)
@chvIPAddress1, -- IP地址
0, -- 机器码
1 -- 是否做Log,如果0,则表示做Log,否则不做Log
exec [prMoney_UpdateCash]
@chvModeName, -- 通过什么方式,如'WEB'、'GameServer'等
@chvSourceName, -- 方式的源,如'金币麻将服务器'、'虚拟股市'等
@chvRemark, -- 其它信息 注释.
@intUserID2, -- 用户ID
0, -- 相关的用户ID
@intWantedAmount2, -- 希望更新的数量(0 加金, <0 扣金)
0, -- 税金(税金0,要在现金中扣除,游戏服务器可以置为0)
@chvIPAddress2, -- IP地址
0, -- 机器码
1 -- 是否做Log,如果0,则表示做Log,否则不做Log
exec [prMoney_UpdateCash]