|
|
@@ -1715,180 +1715,434 @@ namespace MySystem.Areas.Admin.Controllers
|
|
|
}
|
|
|
result += "开机奖20:" + OpenUser20 + "\n";
|
|
|
result += "开机奖10:" + OpenUser10 + "\n";
|
|
|
+ dic.Add("id", pos.Id.ToString());
|
|
|
+ dic.Add("code", "0");
|
|
|
dic.Add("result", result);
|
|
|
return dic;
|
|
|
}
|
|
|
public string AddOpenPrize(int Id)
|
|
|
{
|
|
|
- PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.ActivationState == 1 && !string.IsNullOrEmpty(m.SeoKeyword) && m.SeoKeyword != "0");
|
|
|
+ PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Id && m.ActivationState == 1);
|
|
|
if (pos == null)
|
|
|
{
|
|
|
-
|
|
|
+ return "机具未激活";
|
|
|
}
|
|
|
- if (pos.BindingTime > DateTime.Now.AddDays(-30))
|
|
|
+ if (pos.BindingTime > DateTime.Now.AddDays(-30))
|
|
|
+ {
|
|
|
+ return "绑定已超过30天";
|
|
|
+ }
|
|
|
+ decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
|
|
|
+ if (ActPrize == 0)
|
|
|
+ {
|
|
|
+ return "机具无押金";
|
|
|
+ }
|
|
|
+ PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
|
|
|
+ if (merchant == null)
|
|
|
+ {
|
|
|
+ return "商户不存在";
|
|
|
+ }
|
|
|
+ bool check = db.OpenRewardDetail.Any(m => m.SnNo == pos.PosSn);
|
|
|
+ if(check)
|
|
|
+ {
|
|
|
+ return "开机奖励已发放,请勿重复操作";
|
|
|
+ }
|
|
|
+ // 从机具所属人上级开始分开机奖励
|
|
|
+ Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId);
|
|
|
+ if (user != null)
|
|
|
+ {
|
|
|
+ if (!string.IsNullOrEmpty(user.ParentNav))
|
|
|
{
|
|
|
-
|
|
|
- }
|
|
|
- decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
|
|
|
- if (ActPrize > 0)
|
|
|
+ decimal Prize = 20;
|
|
|
+ string[] ParentNavs = user.ParentNav.Trim(',').Replace(",,", ",").Split(',');
|
|
|
+ for (int i = ParentNavs.Length - 1; i >= 0; i--)
|
|
|
{
|
|
|
- PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
|
|
|
- if (merchant != null)
|
|
|
+ int UserId = int.Parse(ParentNavs[i]);
|
|
|
+ Users puser = db.Users.FirstOrDefault(m => m.Id == UserId && m.AuthFlag == 1);
|
|
|
+ if (puser != null && Prize > 0)
|
|
|
{
|
|
|
- // 从机具所属人上级开始分开机奖励
|
|
|
- Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId);
|
|
|
- if (user != null)
|
|
|
+ int machineCount = db.PosMachinesTwo.Count(m => m.BuyUserId == puser.Id && m.PosSnType == 0); //判断是否拥有3台购买机
|
|
|
+ int ActiveCount = db.PosMachinesTwo.Count(m => m.BuyUserId == puser.Id && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
|
|
|
+ int couponCount = db.PosCoupons.Count(m => m.UserId == puser.Id && m.IsUse == 0); //判断是否拥有3张券
|
|
|
+ if (machineCount + ActiveCount + couponCount >= 3)
|
|
|
{
|
|
|
- if (!string.IsNullOrEmpty(user.ParentNav))
|
|
|
+ int pTopUserId = 0;
|
|
|
+ if (!string.IsNullOrEmpty(puser.ParentNav))
|
|
|
+ {
|
|
|
+ pTopUserId = int.Parse(puser.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
|
|
|
+ }
|
|
|
+ Users machineUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
|
|
|
+ OpenRewardDetail detail = db.OpenRewardDetail.Add(new OpenRewardDetail()
|
|
|
+ {
|
|
|
+ CreateDate = DateTime.Now,
|
|
|
+ UpdateDate = DateTime.Now,
|
|
|
+ TradeMonth = DateTime.Now.ToString("yyyyMM"), //交易月
|
|
|
+ TradeDate = pos.ActivationTime, //达标日期
|
|
|
+ UserId = puser.Id, //创客
|
|
|
+ BrandId = pos.BrandId, //品牌
|
|
|
+ ProductName = RelationClass.GetKqProductBrandInfo(pos.BrandId), //产品名称
|
|
|
+ MerchantId = pos.BindMerchantId, //商户
|
|
|
+ DirectUserId = merchant.UserId, //商户直属人
|
|
|
+ SnNo = pos.PosSn, //SN号
|
|
|
+ MerNo = merchant.KqMerNo, //渠道商户号
|
|
|
+ SnType = pos.PosSnType, //机具类型
|
|
|
+ StandardDate = pos.ActivationTime, //商户的激活日期
|
|
|
+ SnStoreId = pos.StoreId, //SN仓库
|
|
|
+ MerBuddyType = puser.MerchantType, //商户创客类型
|
|
|
+ RewardType = 1, //奖励类型 1-开机直接奖励,2-开机间接奖励
|
|
|
+ RewardTips = "开机奖励", //奖励描述
|
|
|
+ CreditTradeAmt = pos.CreditTrade, //贷记卡交易总金额
|
|
|
+ DebitTradeAmt = pos.DebitCardTrade, //借记卡交易总金额
|
|
|
+ CreditRewardAmount = Prize, //贷记卡交易奖励金额
|
|
|
+ RewardDesc = "开机奖励", //奖励描述
|
|
|
+ TopUserId = pTopUserId, //顶级创客
|
|
|
+ SeoTitle = machineUser.RealName,
|
|
|
+ }).Entity;
|
|
|
+ db.OpenReward.Add(new OpenReward()
|
|
|
{
|
|
|
- decimal Prize = 20;
|
|
|
- string[] ParentNavs = user.ParentNav.Trim(',').Replace(",,", ",").Split(',');
|
|
|
- for (int i = ParentNavs.Length - 1; i >= 0; i--)
|
|
|
+ CreateDate = DateTime.Now,
|
|
|
+ UpdateDate = DateTime.Now,
|
|
|
+ TradeMonth = DateTime.Now.ToString("yyyyMM"), //交易月
|
|
|
+ TradeDate = DateTime.Now, //达标日期
|
|
|
+ UserId = puser.Id, //创客
|
|
|
+ BrandId = pos.BrandId, //品牌
|
|
|
+ RewardType = 2, //奖励类型
|
|
|
+ CreditTradeAmt = pos.CreditTrade, //贷记卡交易总金额
|
|
|
+ DebitTradeAmt = pos.DebitCardTrade, //借记卡交易总金额
|
|
|
+ CreditRewardAmount = Prize, //贷记卡交易奖励金额
|
|
|
+ RewardDesc = "开机奖励", //奖励描述
|
|
|
+ TopUserId = pTopUserId, //顶级创客
|
|
|
+ });
|
|
|
+ string IdBrand = puser.Id + "_" + pos.BrandId;
|
|
|
+ UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
|
|
|
+ if (userData == null)
|
|
|
+ {
|
|
|
+ userData = db.UserMachineData.Add(new UserMachineData()
|
|
|
{
|
|
|
- int UserId = int.Parse(ParentNavs[i]);
|
|
|
- Users puser = db.Users.FirstOrDefault(m => m.Id == UserId && m.AuthFlag == 1);
|
|
|
- if (puser != null && Prize > 0)
|
|
|
- {
|
|
|
- int machineCount = db.PosMachinesTwo.Count(m => m.BuyUserId == puser.Id && m.PosSnType == 0); //判断是否拥有3台购买机
|
|
|
- int ActiveCount = db.PosMachinesTwo.Count(m => m.BuyUserId == puser.Id && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
|
|
|
- int couponCount = db.PosCoupons.Count(m => m.UserId == puser.Id && m.IsUse == 0); //判断是否拥有3张券
|
|
|
- // int BigCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.BrandId == 3); //判断是否拥有2台大机
|
|
|
- // int BigActiveCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.ActivationState == 1 && m.BrandId == 3); //判断是否拥有2台激活大机(不限购买或赠送)
|
|
|
- if (machineCount + ActiveCount + couponCount >= 3)
|
|
|
- {
|
|
|
- int pTopUserId = 0;
|
|
|
- if (!string.IsNullOrEmpty(puser.ParentNav))
|
|
|
- {
|
|
|
- pTopUserId = int.Parse(puser.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
|
|
|
- }
|
|
|
- Users machineUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
|
|
|
- OpenRewardDetail detail = db.OpenRewardDetail.Add(new OpenRewardDetail()
|
|
|
- {
|
|
|
- CreateDate = DateTime.Now,
|
|
|
- UpdateDate = DateTime.Now,
|
|
|
- TradeMonth = yesterday.ToString("yyyyMM"), //交易月
|
|
|
- TradeDate = yesterday, //达标日期
|
|
|
- UserId = puser.Id, //创客
|
|
|
- BrandId = pos.BrandId, //品牌
|
|
|
- ProductName = RelationClass.GetKqProductsInfo(pos.BrandId), //产品名称
|
|
|
- MerchantId = pos.BindMerchantId, //商户
|
|
|
- DirectUserId = merchant.UserId, //商户直属人
|
|
|
- SnNo = pos.PosSn, //SN号
|
|
|
- MerNo = merchant.KqMerNo, //渠道商户号
|
|
|
- SnType = pos.PosSnType, //机具类型
|
|
|
- StandardDate = pos.ActivationTime, //商户的激活日期
|
|
|
- SnStoreId = pos.StoreId, //SN仓库
|
|
|
- MerBuddyType = puser.MerchantType, //商户创客类型
|
|
|
- RewardType = 1, //奖励类型 1-开机直接奖励,2-开机间接奖励
|
|
|
- RewardTips = "开机奖励", //奖励描述
|
|
|
- CreditTradeAmt = pos.CreditTrade, //贷记卡交易总金额
|
|
|
- DebitTradeAmt = pos.DebitCardTrade, //借记卡交易总金额
|
|
|
- CreditRewardAmount = Prize, //贷记卡交易奖励金额
|
|
|
- RewardDesc = "开机奖励", //奖励描述
|
|
|
- TopUserId = pTopUserId, //顶级创客
|
|
|
- SeoTitle = machineUser.RealName,
|
|
|
- }).Entity;
|
|
|
- db.OpenReward.Add(new OpenReward()
|
|
|
- {
|
|
|
- CreateDate = DateTime.Now,
|
|
|
- UpdateDate = DateTime.Now,
|
|
|
- TradeMonth = yesterday.ToString("yyyyMM"), //交易月
|
|
|
- TradeDate = DateTime.Now, //达标日期
|
|
|
- UserId = puser.Id, //创客
|
|
|
- BrandId = pos.BrandId, //品牌
|
|
|
- RewardType = 2, //奖励类型
|
|
|
- CreditTradeAmt = pos.CreditTrade, //贷记卡交易总金额
|
|
|
- DebitTradeAmt = pos.DebitCardTrade, //借记卡交易总金额
|
|
|
- CreditRewardAmount = Prize, //贷记卡交易奖励金额
|
|
|
- RewardDesc = "开机奖励", //奖励描述
|
|
|
- TopUserId = pTopUserId, //顶级创客
|
|
|
- });
|
|
|
- string IdBrand = puser.Id + "_" + pos.BrandId;
|
|
|
- UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
|
|
|
- if (userData == null)
|
|
|
- {
|
|
|
- userData = db.UserMachineData.Add(new UserMachineData()
|
|
|
- {
|
|
|
- IdBrand = IdBrand,
|
|
|
- }).Entity;
|
|
|
- db.SaveChanges();
|
|
|
- }
|
|
|
- userData.OpenProfit += Prize;
|
|
|
- db.SaveChanges();
|
|
|
- RedisDbconn.Instance.Set("UserMachineData:" + IdBrand, userData);
|
|
|
- //账户入库
|
|
|
- UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id);
|
|
|
- if (account == null)
|
|
|
- {
|
|
|
- account = db.UserAccount.Add(new UserAccount()
|
|
|
- {
|
|
|
- Id = puser.Id,
|
|
|
- UserId = puser.Id,
|
|
|
- }).Entity;
|
|
|
- db.SaveChanges();
|
|
|
- }
|
|
|
- //收支明细入库
|
|
|
- decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
|
|
|
- decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
|
|
|
- decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
|
|
|
- account.BalanceAmount += Prize;
|
|
|
- account.TotalAmount += Prize;
|
|
|
- decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
|
|
|
- decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
|
|
|
- decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
|
|
|
- UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
|
|
|
- {
|
|
|
- CreateDate = DateTime.Now,
|
|
|
- UpdateDate = DateTime.Now,
|
|
|
- UserId = puser.Id, //创客
|
|
|
- ChangeType = 50, //变动类型
|
|
|
- ProductType = pos.BrandId, //产品类型
|
|
|
- ChangeAmount = Prize, //变更金额
|
|
|
- BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
|
|
|
- AfterTotalAmount = AfterTotalAmount, //变更后总金额
|
|
|
- BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
|
|
|
- AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
|
|
|
- BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
|
|
|
- AfterBalanceAmount = AfterBalanceAmount, //变更后余额
|
|
|
- }).Entity;
|
|
|
- db.SaveChanges();
|
|
|
- RedisDbconn.Instance.Set("UserAccount:" + puser.Id, account);
|
|
|
-
|
|
|
- string dateString = yesterday.ToString("yyyyMMdd");
|
|
|
- string monthString = yesterday.ToString("yyyyMM");
|
|
|
- // 开机奖励列表
|
|
|
- List<string> dates = RedisDbconn.Instance.GetList<string>("OpenRewardDay:" + puser.Id + ":" + pos.BrandId);
|
|
|
- if (!dates.Contains(dateString))
|
|
|
- {
|
|
|
- RedisDbconn.Instance.AddList("OpenRewardDay:" + puser.Id + ":" + pos.BrandId, dateString);
|
|
|
- }
|
|
|
- RedisDbconn.Instance.AddNumber("OpenRewardAmt:" + puser.Id + ":" + pos.BrandId + ":" + dateString, Prize);
|
|
|
-
|
|
|
- List<string> months = RedisDbconn.Instance.GetList<string>("OpenRewardMonth:" + puser.Id + ":" + pos.BrandId);
|
|
|
- if (!months.Contains(monthString))
|
|
|
- {
|
|
|
- RedisDbconn.Instance.AddList("OpenRewardMonth:" + puser.Id + ":" + pos.BrandId, monthString);
|
|
|
- }
|
|
|
- RedisDbconn.Instance.AddNumber("OpenRewardAmt:" + puser.Id + ":" + pos.BrandId + ":" + monthString, Prize);
|
|
|
-
|
|
|
- // 开机奖励详情
|
|
|
- RedisDbconn.Instance.AddList("OpenRewardDetail:" + puser.Id + ":" + pos.BrandId + ":" + dateString, detail);
|
|
|
-
|
|
|
- //收支明细
|
|
|
- RedisDbconn.Instance.AddList("UserAccountRecord:" + puser.Id + ":1:" + monthString, userAccountRecord);
|
|
|
- RedisDbconn.Instance.AddNumber("UserAccount:" + puser.Id + ":1:" + monthString, Prize);
|
|
|
-
|
|
|
- Prize -= 10;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ IdBrand = IdBrand,
|
|
|
+ }).Entity;
|
|
|
+ db.SaveChanges();
|
|
|
+ }
|
|
|
+ userData.OpenProfit += Prize;
|
|
|
+ db.SaveChanges();
|
|
|
+ RedisDbconn.Instance.Set("UserMachineData:" + IdBrand, userData);
|
|
|
+ //账户入库
|
|
|
+ UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id);
|
|
|
+ if (account == null)
|
|
|
+ {
|
|
|
+ account = db.UserAccount.Add(new UserAccount()
|
|
|
+ {
|
|
|
+ Id = puser.Id,
|
|
|
+ UserId = puser.Id,
|
|
|
+ }).Entity;
|
|
|
+ db.SaveChanges();
|
|
|
}
|
|
|
+ //收支明细入库
|
|
|
+ decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
|
|
|
+ decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
|
|
|
+ decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
|
|
|
+ account.BalanceAmount += Prize;
|
|
|
+ account.TotalAmount += Prize;
|
|
|
+ decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
|
|
|
+ decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
|
|
|
+ decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
|
|
|
+ UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
|
|
|
+ {
|
|
|
+ CreateDate = DateTime.Now,
|
|
|
+ UpdateDate = DateTime.Now,
|
|
|
+ UserId = puser.Id, //创客
|
|
|
+ ChangeType = 50, //变动类型
|
|
|
+ ProductType = pos.BrandId, //产品类型
|
|
|
+ ChangeAmount = Prize, //变更金额
|
|
|
+ BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
|
|
|
+ AfterTotalAmount = AfterTotalAmount, //变更后总金额
|
|
|
+ BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
|
|
|
+ AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
|
|
|
+ BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
|
|
|
+ AfterBalanceAmount = AfterBalanceAmount, //变更后余额
|
|
|
+ }).Entity;
|
|
|
+ db.SaveChanges();
|
|
|
+ RedisDbconn.Instance.Set("UserAccount:" + puser.Id, account);
|
|
|
+
|
|
|
+ string dateString = DateTime.Now.ToString("yyyyMMdd");
|
|
|
+ string monthString = DateTime.Now.ToString("yyyyMM");
|
|
|
+ // 开机奖励列表
|
|
|
+ List<string> dates = RedisDbconn.Instance.GetList<string>("OpenRewardDay:" + puser.Id + ":" + pos.BrandId);
|
|
|
+ if (!dates.Contains(dateString))
|
|
|
+ {
|
|
|
+ RedisDbconn.Instance.AddList("OpenRewardDay:" + puser.Id + ":" + pos.BrandId, dateString);
|
|
|
+ }
|
|
|
+ RedisDbconn.Instance.AddNumber("OpenRewardAmt:" + puser.Id + ":" + pos.BrandId + ":" + dateString, Prize);
|
|
|
+
|
|
|
+ List<string> months = RedisDbconn.Instance.GetList<string>("OpenRewardMonth:" + puser.Id + ":" + pos.BrandId);
|
|
|
+ if (!months.Contains(monthString))
|
|
|
+ {
|
|
|
+ RedisDbconn.Instance.AddList("OpenRewardMonth:" + puser.Id + ":" + pos.BrandId, monthString);
|
|
|
+ }
|
|
|
+ RedisDbconn.Instance.AddNumber("OpenRewardAmt:" + puser.Id + ":" + pos.BrandId + ":" + monthString, Prize);
|
|
|
+
|
|
|
+ // 开机奖励详情
|
|
|
+ RedisDbconn.Instance.AddList("OpenRewardDetail:" + puser.Id + ":" + pos.BrandId + ":" + dateString, detail);
|
|
|
+
|
|
|
+ //收支明细
|
|
|
+ RedisDbconn.Instance.AddList("UserAccountRecord:" + puser.Id + ":1:" + monthString, userAccountRecord);
|
|
|
+ RedisDbconn.Instance.AddNumber("UserAccount:" + puser.Id + ":1:" + monthString, Prize);
|
|
|
+
|
|
|
+ Prize -= 10;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return "发放成功";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ db.Dispose();
|
|
|
+ return "操作失败";
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 查询机具流量费分佣
|
|
|
+
|
|
|
+ public IActionResult FluxPrize(string right)
|
|
|
+ {
|
|
|
+ ViewBag.RightInfo = RightInfo;
|
|
|
+ ViewBag.right = right;
|
|
|
+
|
|
|
+ return View();
|
|
|
+ }
|
|
|
+
|
|
|
+ [HttpPost]
|
|
|
+ public Dictionary<string, string> FluxPrizeDo(string PosSn)
|
|
|
+ {
|
|
|
+ Dictionary<string, string> dic = new Dictionary<string, string>();
|
|
|
+ string result = "";
|
|
|
+ PosMachinesTwo pos = db.PosMachinesTwo .FirstOrDefault(m => m.PosSn == PosSn);
|
|
|
+ if (pos == null)
|
|
|
+ {
|
|
|
+ result += "机具SN号不存在\n";
|
|
|
+ dic.Add("code", "1");
|
|
|
+ dic.Add("result", result);
|
|
|
+ return dic;
|
|
|
+ }
|
|
|
+ if(pos.BindingState == 0)
|
|
|
+ {
|
|
|
+ result += "机具未绑定\n";
|
|
|
+ dic.Add("code", "1");
|
|
|
+ dic.Add("result", result);
|
|
|
+ return dic;
|
|
|
+ }
|
|
|
+ if(pos.ActivationState == 0)
|
|
|
+ {
|
|
|
+ result += "机具未激活\n";
|
|
|
+ dic.Add("code", "1");
|
|
|
+ dic.Add("result", result);
|
|
|
+ return dic;
|
|
|
+ }
|
|
|
+ PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
|
|
|
+ if (merchant == null)
|
|
|
+ {
|
|
|
+ result += "商户不存在\n";
|
|
|
+ dic.Add("code", "1");
|
|
|
+ dic.Add("result", result);
|
|
|
+ return dic;
|
|
|
+ }
|
|
|
+ Users buyuser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
|
|
|
+ result += "机具号:" + PosSn + "\n";
|
|
|
+ result += "机具所属人:\n创客编号:" + buyuser.MakerCode + ",姓名:" + buyuser.RealName + ",手机号:" + buyuser.Mobile + "\n";
|
|
|
+ result += "商户信息\n商户编号:" + merchant.KqMerNo + ",姓名:" + merchant.MerchantName + ",手机号:" + merchant.MerchantMobile + "\n";
|
|
|
+ string FluxGet6 = "未领取";
|
|
|
+ string FluxUser6 = "";
|
|
|
+ FluxProfitDetail flux = db.FluxProfitDetail.FirstOrDefault(m => m.SnNo == pos.PosSn) ?? new FluxProfitDetail();
|
|
|
+ if (flux.Id > 0)
|
|
|
+ {
|
|
|
+ Users user = db.Users.FirstOrDefault(m => m.Id == flux.UserId) ?? new Users();
|
|
|
+ FluxGet6 = "已领取(领取时间:" + flux.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
|
|
|
+ FluxUser6 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
|
|
|
+ }
|
|
|
+ result += "流量费:" + FluxGet6 + "\n";
|
|
|
+ result += "流量费发放对象:" + FluxUser6 + "\n";
|
|
|
+ dic.Add("id", pos.Id.ToString());
|
|
|
+ dic.Add("code", "0");
|
|
|
+ dic.Add("result", result);
|
|
|
+ return dic;
|
|
|
+ }
|
|
|
+ public string AddFluxPrize(int Id)
|
|
|
+ {
|
|
|
+ PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Id && m.ActivationState == 1);
|
|
|
+ if (pos == null)
|
|
|
+ {
|
|
|
+ return "机具未激活";
|
|
|
+ }
|
|
|
+ if (pos.BindingTime > DateTime.Now.AddDays(-30))
|
|
|
+ {
|
|
|
+ return "绑定已超过30天";
|
|
|
+ }
|
|
|
+ decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
|
|
|
+ if (ActPrize == 0)
|
|
|
+ {
|
|
|
+ return "机具无押金";
|
|
|
+ }
|
|
|
+ PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
|
|
|
+ if (merchant == null)
|
|
|
+ {
|
|
|
+ return "商户不存在";
|
|
|
+ }
|
|
|
+ if(pos.BrandId == 6)
|
|
|
+ {
|
|
|
+ return "立刷不支持流量费分佣";
|
|
|
+ }
|
|
|
+ if(decimal.Parse(function.CheckNum(pos.SeoKeyword)) <= 0)
|
|
|
+ {
|
|
|
+ return "无押金机,不支持流量费分佣";
|
|
|
+ }
|
|
|
+ bool check = db.FluxProfitDetail.Any(m => m.MerNo == merchant.KqMerNo);
|
|
|
+ if(check)
|
|
|
+ {
|
|
|
+ return "开机奖励已发放,请勿重复操作";
|
|
|
+ }
|
|
|
+ SpModels.TradeFluxRecord trade = spdb.TradeFluxRecord.FirstOrDefault(m => m.TradeSnNo == pos.PosSn);
|
|
|
+ if(trade != null)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ string OrderNo = trade.TradeSerialNo; //单号
|
|
|
+ DateTime TradeDate = trade.CreateDate.Value;
|
|
|
+ string TradeMonth = TradeDate.ToString("yyyyMM");
|
|
|
+ decimal FeeAmount = trade.FeeAmount; //流量费
|
|
|
+ if (trade.ProductType == "1" || trade.ProductType == "4" || trade.ProductType == "6" || trade.ProductType == "8" || trade.ProductType == "9")
|
|
|
+ {
|
|
|
+ FeeAmount = FeeAmount / 100;
|
|
|
+ }
|
|
|
+ string TradeSnNo = trade.TradeSnNo; //机具SN
|
|
|
+ decimal FluxProfit = 0;
|
|
|
+ if (trade.ProductType == "1" && FeeAmount == 60)
|
|
|
+ {
|
|
|
+ FluxProfit = 24;
|
|
|
+ }
|
|
|
+ else if (trade.ProductType == "7" && FeeAmount == 46)
|
|
|
+ {
|
|
|
+ FluxProfit = 10;
|
|
|
+ }
|
|
|
+ else if (trade.ProductType != "1" && FeeAmount == 48)
|
|
|
+ {
|
|
|
+ FluxProfit = 12;
|
|
|
+ }
|
|
|
+ if (FluxProfit > 0)
|
|
|
+ {
|
|
|
+ Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
|
|
|
+ int GetUserId = user.Id;
|
|
|
+ int TopUserId = 0;
|
|
|
+ string ParentNav = user.ParentNav;
|
|
|
+ if (!string.IsNullOrEmpty(ParentNav))
|
|
|
+ {
|
|
|
+ string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
|
|
|
+ if (ParentNavList.Length > 1)
|
|
|
+ {
|
|
|
+ TopUserId = int.Parse(ParentNavList[1]);
|
|
|
}
|
|
|
- // }
|
|
|
+ else if (ParentNavList.Length == 1)
|
|
|
+ {
|
|
|
+ TopUserId = int.Parse(ParentNavList[0]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ FluxProfitSummary fluxProfit = db.FluxProfitSummary.FirstOrDefault(m => m.UserId == GetUserId && m.BrandId == pos.BrandId && m.TradeMonth == TradeMonth);
|
|
|
+ if (fluxProfit == null)
|
|
|
+ {
|
|
|
+ fluxProfit = db.FluxProfitSummary.Add(new FluxProfitSummary()
|
|
|
+ {
|
|
|
+ CreateDate = DateTime.Now,
|
|
|
+ UpdateDate = DateTime.Now,
|
|
|
+ UserId = GetUserId, //创客
|
|
|
+ BrandId = pos.BrandId,
|
|
|
+ TopUserId = TopUserId, //顶级创客
|
|
|
+ TradeMonth = TradeMonth, //交易月
|
|
|
+ MerUserType = user.MerchantType, //商户创客类型
|
|
|
+ Remark = "流量卡分佣", //备注
|
|
|
+ }).Entity;
|
|
|
+ db.SaveChanges();
|
|
|
}
|
|
|
+ fluxProfit.FluxProfitAmt += FluxProfit; //流量分润总金额
|
|
|
+ db.FluxProfitDetail.Add(new FluxProfitDetail()
|
|
|
+ {
|
|
|
+ CreateDate = DateTime.Now,
|
|
|
+ UpdateDate = DateTime.Now,
|
|
|
+ RecordNo = OrderNo, //单号
|
|
|
+ TradeDate = TradeDate.ToString("yyyyMMdd"), //交易日期
|
|
|
+ TradeTime = TradeDate.ToString("HHmmss"), //交易时间
|
|
|
+ TradeMonth = TradeMonth, //交易月
|
|
|
+ UserId = GetUserId, //创客
|
|
|
+ MerchantId = pos.BindMerchantId, //商户
|
|
|
+ MerchantUserId = pos.UserId, //商户直属人
|
|
|
+ MerNo = merchant.KqMerNo, //渠道商户编号
|
|
|
+ SnNo = pos.PosSn, //渠道SN号
|
|
|
+ FluxOrderNo = OrderNo, //流量扣费单号
|
|
|
+ TradeOrderNo = OrderNo, //交易流水号
|
|
|
+ TradeAmt = trade.TradeAmount, //商户交易额
|
|
|
+ FluxFeeAmt = FeeAmount, //流量费
|
|
|
+ FluxProfitAmt = FluxProfit, //流量分润总金额
|
|
|
+ PosType = pos.PosSnType.ToString(), //POS类型
|
|
|
+ Remark = "流量卡分佣", //备注
|
|
|
+ BrandId = pos.BrandId, //品牌
|
|
|
+ TopUserId = TopUserId, //顶级创客
|
|
|
+ MerUserType = user.MerchantType, //商户创客类型
|
|
|
+ });
|
|
|
+ string IdBrand = user.Id + "_" + pos.BrandId;
|
|
|
+ UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
|
|
|
+ if (userData == null)
|
|
|
+ {
|
|
|
+ userData = db.UserMachineData.Add(new UserMachineData()
|
|
|
+ {
|
|
|
+ IdBrand = IdBrand,
|
|
|
+ }).Entity;
|
|
|
+ db.SaveChanges();
|
|
|
+ }
|
|
|
+ userData.FluxProfit += FluxProfit;
|
|
|
+ db.SaveChanges();
|
|
|
+ RedisDbconn.Instance.Clear("UserMachineData:" + IdBrand);
|
|
|
+ UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == GetUserId);
|
|
|
+ if (account == null)
|
|
|
+ {
|
|
|
+ account = db.UserAccount.Add(new UserAccount()
|
|
|
+ {
|
|
|
+ Id = GetUserId,
|
|
|
+ UserId = GetUserId,
|
|
|
+ }).Entity;
|
|
|
+ db.SaveChanges();
|
|
|
+ }
|
|
|
+ decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
|
|
|
+ decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
|
|
|
+ decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
|
|
|
+ account.BalanceAmount += FluxProfit;
|
|
|
+ account.TotalAmount += FluxProfit;
|
|
|
+ decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
|
|
|
+ decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
|
|
|
+ decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
|
|
|
+ UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
|
|
|
+ {
|
|
|
+ CreateDate = DateTime.Now,
|
|
|
+ UpdateDate = DateTime.Now,
|
|
|
+ UserId = GetUserId, //创客
|
|
|
+ ChangeType = 60, //变动类型
|
|
|
+ ProductType = pos.BrandId, //产品类型
|
|
|
+ ChangeAmount = FluxProfit, //变更金额
|
|
|
+ BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
|
|
|
+ AfterTotalAmount = AfterTotalAmount, //变更后总金额
|
|
|
+ BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
|
|
|
+ AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
|
|
|
+ BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
|
|
|
+ AfterBalanceAmount = AfterBalanceAmount, //变更后余额
|
|
|
+ }).Entity;
|
|
|
+ db.SaveChanges();
|
|
|
+ spdb.Dispose();
|
|
|
+ db.Dispose();
|
|
|
+ return "发放成功";
|
|
|
}
|
|
|
}
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ function.WriteLog(DateTime.Now.ToString() + "\n$" + trade.Id + "$\n" + ex.ToString(), "流量卡分佣异常");
|
|
|
+ }
|
|
|
}
|
|
|
+ spdb.Dispose();
|
|
|
db.Dispose();
|
|
|
return "操作失败";
|
|
|
}
|