Friday, January 22, 2010

userwin.cs

using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
//该源码下载自www.51aspx.com(51aspx.com)

public class userwin
{
private string u_id;//用户id
private decimal win_money;//赢的资金+输或者是赢,有可能是负数

private DataTable user_dt;//返回用户的数据表
private DataRow this_dr;//该用户的数据行

private string maxP_uid;//该用户向上的最高一级代理用户id
private decimal maxP_gufen;//该用户向上的最高一级代理
private decimal maxP_pay;//该用户向上的最高一级代理抽水


private string[] allParen_uid;//所有我的父级代理名
private string[] allParen_gufen;//所有我的父级代理股份
private string[] allParen_pay;//所有我的父级代理抽水


public string sq="";

private string log;//操作日志
private string doone = "";

///
/// 预处理函数
///

public userwin()
{

init();
}
///
/// 预处理函数
///

private void init()
{
}

///
/// 结算
///

public void domoney(string uid,decimal winmo)
{
this.u_id = uid;
this.win_money = winmo;

//取得用户表
user_dt = Sp.SQLServerDAL.DbHelperSQL.Query("select * from Sp_user").Tables[0];

this_dr = user_dt.Select("id=" + u_id)[0];

//开始递归,的到代理参数
Parent_agent();
sq += reSqlStr();
Sp.SQLServerDAL.DbHelperSQL.ExecuteSql(sq);

}
///
/// 查看该会员是否需要抽水
///

///
private bool isneedchoushui()
{ //内部会员不抽水
bool b1 = this_dr["Prentid"].ToString() != "-1";
return b1;
}
///
/// 得到需要执行的sql语句
/// 返回sql语句字符串
///

///
private string reSqlStr()
{ //资金大于0 就抽水,否则不抽
decimal mymoney=win_money;
decimal paymoney = 0;
if (win_money > 0)
{
mymoney = win_money * (1 - maxP_pay / 100);
paymoney = win_money - mymoney;
}


//更改当前用户的的资金
string sql1 = "update sp_user set Truemoney=Truemoney+"+mymoney+" where id="+u_id+";";
sql1 += Sp.SQLServerDAL.Sp_Money_log.readdsql(mymoney.ToString(), u_id, "系统结算", "游戏输赢");
//把抽的水中的差分配给该用户所属的代理
//Sp.Functions.ResT("
k:"+allParen_pay.Length.ToString());
for (int i = allParen_pay.Length - 2; i >0 ; i--)
{
decimal pc = decimal.Parse(allParen_pay[i]) - decimal.Parse(allParen_pay[i-1]);
decimal tmoney = win_money * ( pc / 100);
sql1 += "update sp_user set Truemoney=Truemoney+" + tmoney + " where id=" + allParen_uid[i] + ";";
sql1 += Sp.SQLServerDAL.Sp_Money_log.readdsql(tmoney.ToString(), allParen_uid[i], "系统结算", "游戏抽水代理分成");
}



return sql1;

}

///
/// 递归出所有上级代理
///

private string temp1 = "0,";
private string temp2 = "0,";
private string temp3 = "0,";
private void Parent_agent()
{
string my_prentid = string.Empty;
my_prentid = this_dr["parentid"].ToString();

DrParent(my_prentid);
allParen_uid = temp1.Split(',');
allParen_gufen = temp2.Split(',');
allParen_pay = temp3.Split(',');


maxP_uid=allParen_uid[allParen_uid.Length-1];
//Sp.Functions.ResT(temp1);
maxP_gufen = decimal.Parse(allParen_gufen[allParen_gufen.Length - 2]);
maxP_pay = decimal.Parse(allParen_pay[allParen_pay.Length - 2]);

}
///
/// 执行递归
///

private void DrParent(string uid)
{
DataRow[] srows = user_dt.Select("id=" + uid);
if (srows.Length >0)
{
temp1 += srows[0]["id"] + ",";
temp2 += srows[0]["gufen"] + ",";
temp3 += srows[0]["pay"] + ",";

DrParent(srows[0]["parentid"].ToString());
}
else
{ return; }

}
///
/// 返回与我相关的代理需要添加或修改的值
///

private string up_agent()
{
throw new System.NotImplementedException();
}

}

No comments:

Post a Comment