代理商怎么分钱???很有难度!!!!!!!!!!

txt_ly 2008-07-10 04:29:58
代理商组织结构

公司-股东-n级代理商-玩家

公司\股东\代理商表表结构
agentID 代理商id
parentAgentID 上级代理商id
rate 代理商抽成比率
玩家表表结构
玩家id
所在代理商id
投注金额

假设玩家A玩一局麻将,玩家A在游戏中投注金额为100,系统设定的抽水率为10%,则从玩家A上获取游戏投注金额利润为:100*10%=10。其中公司得佣金1,股东A得1.8,代理A得 2.16,代理B得5.04。计算公式如下
游戏佣金=10*(1-90%)=1 公司
游戏佣金=10*90%*(1-80%)=1.8 股东A 股东A游戏占成90%,由公司设定
游戏佣金=10*90%*80%*(1-70%)=2.16 代理A 代理A游戏占成80%,由股东A设定
游戏佣金=10*90%*80%*70%=5.04 代理B 代理B游戏占成70%,由代理A设定
玩家A 在游戏中投注金额为100
问题是
根据 玩家id,投注金额得到所有上级代理,股东,公司的游戏佣金,代理是N级的,要一通用的存储过程

...全文
309 29 打赏 收藏 转发到动态 举报
写回复
用AI写文章
29 条回复
切换为时间正序
请发表友善的回复…
发表回复
txt_ly 2008-07-14
  • 打赏
  • 举报
回复
多谢
wgzaaa 2008-07-12
  • 打赏
  • 举报
回复
本来想把函数与存储过程并到一起,考虑到分开设计,函数可能还有其他用,再说函数已用前人写出,好修改,分开设计更容易看清楚,也便于扩展功能。
wgzaaa 2008-07-12
  • 打赏
  • 举报
回复
declare @chen numeric(8,4)
set @chen=1.0--直接把金额放到了这里,sorry
update #fenqian set @chen=@chen*isnull(rate,100)/100.,moneys=@chen*(1-rate0/100.)*@MONEYS* @water
select * from #fenqian
思路:求出所有上级情况(用函数,是级别处理的一般处理),从你给的数据来看,是要结合下层的情况,所以用rate0直接求得,往下是累积,这样用上面的更新语句是最好的。

select *,
isnull(
(select rate from f_getParent(@agentID) B where A.level=B.level+1),0)rate0,100000.00000001 moneys
into #fenqian from f_getParent(@agentID) A order by level desc
是把函数得来的表中加了一个rate0,即下一级的比率(用了子查询),100000.00000001 是为了确定临时表的范围,保证下一部updatek 中的值不到超出范围,因为后面要更新,所以是什么都无所谓,f_getParent(@agentID)是调用函数,into #fenqian是插入临时表,以便下一步update
------------------------------
set @chen=1.0--直接把金额放到了这里,sorry
update #fenqian set @chen=@chen*isnull(rate,100)/100.,moneys=@chen*(1-rate0/100.)*@MONEYS* @water
------------------
是用变量更新值的常用写法,是分行执行,相当于游标的处理,每一行,先更新moneys,然后将@chen更新,到下一行时@chen就有了新的值,这样就实现了累积
txt_ly 2008-07-12
  • 打赏
  • 举报
回复
wgzaaa
能说一下你的思路吗

select *,
isnull(
(select rate from f_getParent(@agentID) B where A.level=B.level+1),0)rate0,100000.00000001 moneys
into #fenqian from f_getParent(@agentID) A order by level desc

这句代码看不明白

set @chen=100.0
update #fenqian set @chen=@chen*isnull(rate,100)/100.,moneys=@chen*(1-rate0/100.)* @water

这句也不怎么明白
@moneys这个变量你没用啊
txt_ly 2008-07-12
  • 打赏
  • 举报
回复
先谢了,我好好看看
wgzaaa 2008-07-12
  • 打赏
  • 举报
回复
-------------------------调用存储过程---------------------------------------------------
exec pro_fenqian 2,100--第2个id是玩家A100元
-------------------------------------------------------------------------------------
(所影响的行数为 4 行)


(所影响的行数为 4 行)

agentID parentAgentID rate Level I_add rate0 moneys
-------- ------------- --------- -------- ---------------- ---------- -----------
1 0 NULL 4 公司 90 1.00000000
2 1 90 3 股东A 80 1.80000000
4 2 80 2 股东A下代理A 70 2.16000000
8 4 70 1 股东A下代理A下代理B 0 5.04000000

(所影响的行数为 4 行)昨晚网出问题了
wgzaaa 2008-07-12
  • 打赏
  • 举报
回复
-----------------------搭建数据环境-------------------------------------------
create table tb_a(agentID int,parentAgentID int,rate int,I_add varchar(30))--drop table tb_a
insert tb_a select 1,0,null,'公司'
insert tb_a select 2,1,90,'股东A'
insert tb_a select 3,1,33,'股东B'
insert tb_a select 4,2,80,'股东A下代理A'
insert tb_a select 5,2,13,'股东A下代理B'
insert tb_a select 6,3,17,'股东B下代理A'
insert tb_a select 7,4,23,'股东A下代理A下代理A'
insert tb_a select 8,4,70,'股东A下代理A下代理B'
create table tb_b(id int,agentID int,moneys int,I_add varchar(30))
insert tb_b select 1,7,2000,'玩家B'
insert tb_b select 2,8,100,'玩家A'
insert tb_b select 3,4,5000,'玩家C'
SELECT * FROM tb_a SELECT * FROM tb_B
-----------------------先建一函数-------------------------------------------
alter function f_getParent(@agentID int)
returns @t table(agentID INT,parentAgentID int,rate int,Level INT,I_add varchar(30))as
begin
declare @i int
set @i=1
insert @t select agentID,parentAgentID,rate,@i,I_add from tb_a where agentID=@agentID
while @@rowcount<>0
begin
set @i=@i+1
insert @t select a.agentID,a.parentAgentID,a.rate,@i,a.I_add from tb_a a,@t b
where a.agentID=b.parentAgentID and b.Level= @i-1
end
return
end
-----------------------再建一存储过程-------------------------------------------
create proc pro_fenqian @id int,@moneys int as--给定条件----玩家id,玩家金额
declare @water numeric(5,2) --抽水率
set @water=0.1 --系统设定,放在表中可直接查表,若在前台,则应放到给定条件中
declare @agentID int--客户直接上级代理商
select @agentID=agentID from tb_b where ID=@id
if exists(select 0 from tempdb..sysobjects where name like '#fenqian%')
drop table #fenqian
select *,isnull((select rate from dbo.f_getParent(@agentID) B where A.level=B.level+1),0)rate0,100000.00000001 moneys
into #fenqian from dbo.f_getParent(@agentID) A order by level desc
declare @chen numeric(8,4)
set @chen=100.0
update #fenqian set @chen=@chen*isnull(rate,100)/100.,moneys=@chen*(1-rate0/100.)* @water
select * from #fenqian
wwd252 2008-07-11
  • 打赏
  • 举报
回复
关注中
utpcb 2008-07-11
  • 打赏
  • 举报
回复
MARK
hero_girl 2008-07-11
  • 打赏
  • 举报
回复
踩个脚印
txt_ly 2008-07-11
  • 打赏
  • 举报
回复
自己再顶,这个问题把我愁死了
hanjs 2008-07-11
  • 打赏
  • 举报
回复
路过。。。
Clove 2008-07-11
  • 打赏
  • 举报
回复
描述的太不明白了
玩家A,代理A和代理B什么关系
70%和1-70%都怎么出来的,lz你就没说清楚
wgzaaa 2008-07-11
  • 打赏
  • 举报
回复
--我先建表,大家上
create table tb_a(agentID int,parentAgentID int,rate int)--drop table tb_b
insert tb_a select 1,1,null
insert tb_a select 2,1,90--股东A+++++++++++++++++++
insert tb_a select 3,1,33--股东B
insert tb_a select 4,2,80--股东A下代理A++++++++++++
insert tb_a select 5,2,13--股东A下代理B
insert tb_a select 6,3,17--股东B代理A
insert tb_a select 7,4,23--股东A下代理A下代理A
insert tb_a select 8,4,70--股东A下代理A下代理B++++++
create table tb_b(id int,agentID int,moneys int)
insert tb_b select 1,7,2000
insert tb_b select 2,8,100
insert tb_b select 3,4,5000
lxuan_025 2008-07-11
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 hery2002 的回复:]
引用 2 楼 pt1314917 的回复:
有点难度。。
[/Quote]
dobear_0922 2008-07-11
  • 打赏
  • 举报
回复
这个不好搞,帮顶
alisafan123 2008-07-11
  • 打赏
  • 举报
回复
up
txt_ly 2008-07-11
  • 打赏
  • 举报
回复
加分啦,哪位大哥支个招
zhouhan0048 2008-07-11
  • 打赏
  • 举报
回复
很有难度..关注


UP
三下鱼 2008-07-10
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 hery2002 的回复:]
引用 2 楼 pt1314917 的回复:
有点难度。。

[/Quote]
加载更多回复(9)

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧