|
@@ -332,24 +332,25 @@ namespace MySystem
|
|
|
|
|
|
public void StartListenProfitDo()
|
|
public void StartListenProfitDo()
|
|
{
|
|
{
|
|
- while(true)
|
|
|
|
- {
|
|
|
|
- if(DateTime.Now.Day == 1 && DateTime.Now.Hour > 0)
|
|
|
|
- {
|
|
|
|
|
|
+ // while(true)
|
|
|
|
+ // {
|
|
|
|
+ // if(DateTime.Now.Day == 1 && DateTime.Now.Hour > 0)
|
|
|
|
+ // {
|
|
DoProfit();
|
|
DoProfit();
|
|
- Thread.Sleep(600000);
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- Thread.Sleep(3600000);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ // Thread.Sleep(600000);
|
|
|
|
+ // }
|
|
|
|
+ // else
|
|
|
|
+ // {
|
|
|
|
+ // Thread.Sleep(3600000);
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
}
|
|
}
|
|
|
|
|
|
//分润算法
|
|
//分润算法
|
|
public void DoProfit()
|
|
public void DoProfit()
|
|
{
|
|
{
|
|
string TradeMonth = DateTime.Now.ToString("yyyyMM");
|
|
string TradeMonth = DateTime.Now.ToString("yyyyMM");
|
|
|
|
+ KxsMainModels.WebCMSEntities kxsdb = new KxsMainModels.WebCMSEntities();
|
|
WebCMSEntities dbnew = new WebCMSEntities();
|
|
WebCMSEntities dbnew = new WebCMSEntities();
|
|
DataTable dt = CustomerSqlConn.dtable("select IsAct,UserId,sum(TotalAmount) from UserAmountSummary where TradeMonth='" + TradeMonth + "' and SeoTitle='self' group by IsAct,UserId", MysqlConn.SqlConnStr);
|
|
DataTable dt = CustomerSqlConn.dtable("select IsAct,UserId,sum(TotalAmount) from UserAmountSummary where TradeMonth='" + TradeMonth + "' and SeoTitle='self' group by IsAct,UserId", MysqlConn.SqlConnStr);
|
|
foreach(DataRow dr in dt.Rows)
|
|
foreach(DataRow dr in dt.Rows)
|
|
@@ -359,7 +360,7 @@ namespace MySystem
|
|
decimal TotalAmount = decimal.Parse(dr[2].ToString());
|
|
decimal TotalAmount = decimal.Parse(dr[2].ToString());
|
|
List<ProfitUsers> users = new List<ProfitUsers>();
|
|
List<ProfitUsers> users = new List<ProfitUsers>();
|
|
int TopUserId = 0; //顶级创客Id
|
|
int TopUserId = 0; //顶级创客Id
|
|
- Users us = dbnew.Users.FirstOrDefault(a => a.Id == UserId);
|
|
|
|
|
|
+ KxsMainModels.Users us = kxsdb.Users.FirstOrDefault(a => a.Id == UserId);
|
|
if (us != null)
|
|
if (us != null)
|
|
{
|
|
{
|
|
string uidstring = us.Id.ToString();
|
|
string uidstring = us.Id.ToString();
|
|
@@ -373,7 +374,7 @@ namespace MySystem
|
|
foreach (string uidstr in uidlist)
|
|
foreach (string uidstr in uidlist)
|
|
{
|
|
{
|
|
int puid = int.Parse(function.CheckInt(uidstr));
|
|
int puid = int.Parse(function.CheckInt(uidstr));
|
|
- Users pus = dbnew.Users.FirstOrDefault(a => a.Id == puid);
|
|
|
|
|
|
+ KxsMainModels.Users pus = kxsdb.Users.FirstOrDefault(a => a.Id == puid);
|
|
if (pus != null)
|
|
if (pus != null)
|
|
{
|
|
{
|
|
users.Add(new ProfitUsers()
|
|
users.Add(new ProfitUsers()
|
|
@@ -387,71 +388,67 @@ namespace MySystem
|
|
}
|
|
}
|
|
}
|
|
}
|
|
List<ProfitResult> list = new List<ProfitResult>();
|
|
List<ProfitResult> list = new List<ProfitResult>();
|
|
- list = StartProft(dbnew, TotalAmount, 1, users, IsActive);
|
|
|
|
- using (var tran = dbnew.Database.BeginTransaction())
|
|
|
|
|
|
+ list = StartProft(TotalAmount, 1, users, IsActive);
|
|
|
|
+ try
|
|
{
|
|
{
|
|
- try
|
|
|
|
|
|
+ foreach (ProfitResult sub in list)
|
|
{
|
|
{
|
|
- foreach (ProfitResult sub in list)
|
|
|
|
|
|
+ if (sub.Message == "分红奖励")
|
|
|
|
+ {
|
|
|
|
+ UserAccountRecord accountRecord = dbnew.UserAccountRecord.Add(new UserAccountRecord()
|
|
|
|
+ {
|
|
|
|
+ CreateDate = DateTime.Now,
|
|
|
|
+ UpdateDate = DateTime.Now,
|
|
|
|
+ UserId = sub.UserId, //创客
|
|
|
|
+ ChangeType = 11, //变动类型
|
|
|
|
+ ProductType = 1, //产品类型
|
|
|
|
+ ChangeAmount = sub.Money, //变更金额
|
|
|
|
+ Status = -1,
|
|
|
|
+ }).Entity;
|
|
|
|
+ dbnew.SaveChanges();
|
|
|
|
+ }
|
|
|
|
+ else
|
|
{
|
|
{
|
|
- if (sub.Message == "分红奖励")
|
|
|
|
- {
|
|
|
|
- UserAccountRecord accountRecord = dbnew.UserAccountRecord.Add(new UserAccountRecord()
|
|
|
|
|
|
+ int ProfitType = sub.UserId == UserId ? 0 : 1;
|
|
|
|
+ ProfitRewardRecord editprofitrecord = dbnew.ProfitRewardRecord.FirstOrDefault(m => m.UserId == sub.UserId && m.BrandId == 1 && m.ProfitType == ProfitType && m.TradeMonth == TradeMonth);
|
|
|
|
+ if (editprofitrecord == null)
|
|
|
|
+ {
|
|
|
|
+ editprofitrecord = dbnew.ProfitRewardRecord.Add(new ProfitRewardRecord()
|
|
{
|
|
{
|
|
CreateDate = DateTime.Now,
|
|
CreateDate = DateTime.Now,
|
|
- UpdateDate = DateTime.Now,
|
|
|
|
UserId = sub.UserId, //创客
|
|
UserId = sub.UserId, //创客
|
|
- ChangeType = 11, //变动类型
|
|
|
|
- ProductType = 1, //产品类型
|
|
|
|
- ChangeAmount = sub.Money, //变更金额
|
|
|
|
- Status = -1,
|
|
|
|
|
|
+ BrandId = 1, //品牌
|
|
|
|
+ ProfitType = ProfitType, //创客分润类型
|
|
|
|
+ TradeMonth = TradeMonth, //交易月
|
|
|
|
+ TopUserId = TopUserId, //顶级创客
|
|
}).Entity;
|
|
}).Entity;
|
|
dbnew.SaveChanges();
|
|
dbnew.SaveChanges();
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- int ProfitType = sub.UserId == UserId ? 0 : 1;
|
|
|
|
- ProfitRewardRecord editprofitrecord = dbnew.ProfitRewardRecord.FirstOrDefault(m => m.UserId == sub.UserId && m.BrandId == 1 && m.ProfitType == ProfitType && m.TradeMonth == TradeMonth);
|
|
|
|
- if (editprofitrecord == null)
|
|
|
|
|
|
+ string RecordNo = "KPM";
|
|
|
|
+ int RecordId = editprofitrecord.Id;
|
|
|
|
+ string RecordIdString = RecordId.ToString();
|
|
|
|
+ for (int i = 0; i < 14 - RecordId.ToString().Length; i++)
|
|
{
|
|
{
|
|
- editprofitrecord = dbnew.ProfitRewardRecord.Add(new ProfitRewardRecord()
|
|
|
|
- {
|
|
|
|
- CreateDate = DateTime.Now,
|
|
|
|
- UserId = sub.UserId, //创客
|
|
|
|
- BrandId = 1, //品牌
|
|
|
|
- ProfitType = ProfitType, //创客分润类型
|
|
|
|
- TradeMonth = TradeMonth, //交易月
|
|
|
|
- TopUserId = TopUserId, //顶级创客
|
|
|
|
- }).Entity;
|
|
|
|
- dbnew.SaveChanges();
|
|
|
|
- string RecordNo = "KPM";
|
|
|
|
- int RecordId = editprofitrecord.Id;
|
|
|
|
- string RecordIdString = RecordId.ToString();
|
|
|
|
- for (int i = 0; i < 14 - RecordId.ToString().Length; i++)
|
|
|
|
- {
|
|
|
|
- RecordIdString = "0" + RecordIdString;
|
|
|
|
- }
|
|
|
|
- RecordNo += RecordIdString;
|
|
|
|
- editprofitrecord.RecordNo = RecordNo;
|
|
|
|
- dbnew.SaveChanges();
|
|
|
|
|
|
+ RecordIdString = "0" + RecordIdString;
|
|
}
|
|
}
|
|
- editprofitrecord.TradeAmt += TotalAmount; //商户交易总额
|
|
|
|
- editprofitrecord.DebitCapTradeNum += 1; //商户借记卡封顶交易总笔数
|
|
|
|
- decimal ProfitMoney = sub.Money;
|
|
|
|
|
|
+ RecordNo += RecordIdString;
|
|
|
|
+ editprofitrecord.RecordNo = RecordNo;
|
|
dbnew.SaveChanges();
|
|
dbnew.SaveChanges();
|
|
}
|
|
}
|
|
|
|
+ editprofitrecord.TradeAmt += TotalAmount; //商户交易总额
|
|
|
|
+ editprofitrecord.DebitCapTradeNum += 1; //商户借记卡封顶交易总笔数
|
|
|
|
+ decimal ProfitMoney = sub.Money;
|
|
|
|
+ dbnew.SaveChanges();
|
|
}
|
|
}
|
|
- dbnew.SaveChanges();
|
|
|
|
- tran.Commit();
|
|
|
|
- }
|
|
|
|
- catch (Exception ex)
|
|
|
|
- {
|
|
|
|
- tran.Rollback();
|
|
|
|
- function.WriteLog(ex.ToString(), "分润异常");
|
|
|
|
}
|
|
}
|
|
|
|
+ dbnew.SaveChanges();
|
|
|
|
+ }
|
|
|
|
+ catch (Exception ex)
|
|
|
|
+ {
|
|
|
|
+ function.WriteLog(ex.ToString(), "分润异常");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
dbnew.Dispose();
|
|
dbnew.Dispose();
|
|
|
|
+ kxsdb.Dispose();
|
|
}
|
|
}
|
|
|
|
|
|
public void DoActives(WebCMSEntities dbnew, TradeRecord trade_record)
|
|
public void DoActives(WebCMSEntities dbnew, TradeRecord trade_record)
|
|
@@ -719,17 +716,17 @@ namespace MySystem
|
|
|
|
|
|
|
|
|
|
#region 分润算法
|
|
#region 分润算法
|
|
- public List<ProfitResult> StartProft(WebCMSEntities dbnew, decimal TotalAmount, int LevelKindId, List<ProfitUsers> users, bool IsActive = true)
|
|
|
|
|
|
+ public List<ProfitResult> StartProft(decimal TotalAmount, int LevelKindId, List<ProfitUsers> users, bool IsActive = true)
|
|
{
|
|
{
|
|
- int BrandId = 1;
|
|
|
|
- List<UserLevelSet> levels = RedisDbconn.Instance.GetList<UserLevelSet>("pobjlevel");
|
|
|
|
|
|
+ string Month = DateTime.Now.AddMonths(-1).ToString("yyyyMM");
|
|
|
|
+ WebCMSEntities db = new WebCMSEntities();
|
|
|
|
+ List<UserLevelSet> levels = db.UserLevelSet.ToList();
|
|
List<ProfitResult> result = new List<ProfitResult>();
|
|
List<ProfitResult> result = new List<ProfitResult>();
|
|
- ProfitObjects obj = RedisDbconn.Instance.Get<ProfitObjects>("pobj" + BrandId);
|
|
|
|
|
|
+ ProfitObjects obj = db.ProfitObjects.FirstOrDefault();
|
|
if (obj.Status == 1) //判断分润是否开启
|
|
if (obj.Status == 1) //判断分润是否开启
|
|
{
|
|
{
|
|
int maxLevel = obj.MaxLevel; //最大等级
|
|
int maxLevel = obj.MaxLevel; //最大等级
|
|
int maxFloor = obj.MaxFloor; //最大层级
|
|
int maxFloor = obj.MaxFloor; //最大层级
|
|
- int maxContinueFloor = RedisDbconn.Instance.Get<int>("pobjconc" + BrandId); //最大继续分润层级
|
|
|
|
decimal diffLevelProfit = 0; //等级级差
|
|
decimal diffLevelProfit = 0; //等级级差
|
|
// decimal diffDiviProfit = 0; //分红级差
|
|
// decimal diffDiviProfit = 0; //分红级差
|
|
int curLevel = 0; //当前层级的会员等级
|
|
int curLevel = 0; //当前层级的会员等级
|
|
@@ -740,13 +737,8 @@ namespace MySystem
|
|
{
|
|
{
|
|
user = users[curFloor - 1];
|
|
user = users[curFloor - 1];
|
|
}
|
|
}
|
|
- int UserLevel = 1; //user.UserLevel; //当前会员等级
|
|
|
|
- decimal utrade = RedisDbconn.Instance.Get<decimal>("TeamTradeStat:" + user.UserId + ":" + BrandId + ":" + DateTime.Now.ToString("yyMM"));
|
|
|
|
- UserLevelSet checklevel = levels.Where(m => m.UpLevelIntegral < utrade).OrderBy(m => m.Id).FirstOrDefault();
|
|
|
|
- if (checklevel != null)
|
|
|
|
- {
|
|
|
|
- UserLevel = checklevel.Id + 1;
|
|
|
|
- }
|
|
|
|
|
|
+ SubUser selfUser = GetUser(user.UserId, Month) ?? new SubUser();
|
|
|
|
+ int UserLevel = selfUser.PreUserLevel > selfUser.UserLevel ? selfUser.PreUserLevel : selfUser.UserLevel; //当前会员等级
|
|
//判断当前创客是否有直推的激活机具,并且在活动时间内
|
|
//判断当前创客是否有直推的激活机具,并且在活动时间内
|
|
if (UserLevel == maxLevel && UserLevel == curLevel)
|
|
if (UserLevel == maxLevel && UserLevel == curLevel)
|
|
{
|
|
{
|
|
@@ -754,7 +746,7 @@ namespace MySystem
|
|
}
|
|
}
|
|
if (UserLevel <= maxLevel && UserLevel > curLevel)
|
|
if (UserLevel <= maxLevel && UserLevel > curLevel)
|
|
{
|
|
{
|
|
- ProfitObjectLevels objlevel = RedisDbconn.Instance.Get<ProfitObjectLevels>("pobjlv" + LevelKindId + ":" + UserLevel); //获取当前等级参数
|
|
|
|
|
|
+ ProfitObjectLevels objlevel = db.ProfitObjectLevels.FirstOrDefault(m => m.Id == UserLevel); //获取当前等级参数
|
|
if (objlevel != null)
|
|
if (objlevel != null)
|
|
{
|
|
{
|
|
decimal getLevelProfit = 0; //等级分润
|
|
decimal getLevelProfit = 0; //等级分润
|
|
@@ -788,8 +780,30 @@ namespace MySystem
|
|
curLevel = UserLevel;
|
|
curLevel = UserLevel;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ db.Dispose();
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public SubUser GetUser(int UserId, string Month)
|
|
|
|
+ {
|
|
|
|
+ SubUser user = new SubUser();
|
|
|
|
+ DataTable dt = GetDataTable("select * from Users" + Month + " where Id=" + UserId);
|
|
|
|
+ if(dt.Rows.Count > 0)
|
|
|
|
+ {
|
|
|
|
+ user.Id = int.Parse(dt.Rows[0]["Id"].ToString());
|
|
|
|
+ user.ParentUserId = int.Parse(dt.Rows[0]["ParentUserId"].ToString());
|
|
|
|
+ user.ParentNav = dt.Rows[0]["ParentNav"].ToString();
|
|
|
|
+ user.UserLevel = int.Parse(dt.Rows[0]["UserLevel"].ToString());
|
|
|
|
+ user.PreUserLevel = int.Parse(dt.Rows[0]["PreUserLevel"].ToString());
|
|
|
|
+ }
|
|
|
|
+ return user;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public DataTable GetDataTable(string sqlstr)
|
|
|
|
+ {
|
|
|
|
+ DataTable dt = CustomerSqlConn.dtable(sqlstr, Library.ConfigurationManager.AppSettings["KxsStatSqlConnStr"].ToString());
|
|
|
|
+ return dt;
|
|
|
|
+ }
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
#region 活动奖励算法
|
|
#region 活动奖励算法
|