|
@@ -30,6 +30,7 @@ namespace MySystem
|
|
|
// dosomething2(doDate);
|
|
|
StartEverDay(doDate);
|
|
|
dosomething4(doDate);
|
|
|
+ ListenFluxRecord(doDate);
|
|
|
}
|
|
|
string Msg = "success";
|
|
|
jobInfo.Status = Msg == "success" ? 1 : 0;
|
|
@@ -957,6 +958,224 @@ namespace MySystem
|
|
|
}
|
|
|
|
|
|
|
|
|
+ // 4. 前一天的流量卡记录和匹配
|
|
|
+ public void ListenFluxRecord(string date)
|
|
|
+ {
|
|
|
+ Thread th = new Thread(CheckFluxForTrade);
|
|
|
+ th.IsBackground = true;
|
|
|
+ th.Start(date);
|
|
|
+ }
|
|
|
+ public void doFluxRecord(string date)
|
|
|
+ {
|
|
|
+ function.WriteLog(DateTime.Now.ToString(), "执行流量费返佣");
|
|
|
+ SpModels.WebCMSEntities spdb = new SpModels.WebCMSEntities();
|
|
|
+ WebCMSEntities db = new WebCMSEntities();
|
|
|
+ DateTime yesterday = DateTime.Parse(date + " 00:00:00");
|
|
|
+ DateTime today = DateTime.Parse(DateTime.Parse(date).AddDays(1).ToString("yyyy-MM-dd") + " 00:00:00");
|
|
|
+ List<SpModels.TradeFluxRecord> trades = spdb.TradeFluxRecord.Where(m => m.CreateDate >= yesterday && m.CreateDate < today && m.Status == 1).ToList();
|
|
|
+ foreach (SpModels.TradeFluxRecord trade in trades)
|
|
|
+ {
|
|
|
+ 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")
|
|
|
+ {
|
|
|
+ FeeAmount = FeeAmount / 100;
|
|
|
+ }
|
|
|
+ string TradeSnNo = trade.TradeSnNo; //机具SN
|
|
|
+ decimal FluxProfit = 0;
|
|
|
+ if (trade.ProductType == "1" && FeeAmount == 60)
|
|
|
+ {
|
|
|
+ FluxProfit = 24;
|
|
|
+ }
|
|
|
+ else if (trade.ProductType != "1" && FeeAmount == 48)
|
|
|
+ {
|
|
|
+ FluxProfit = 12;
|
|
|
+ }
|
|
|
+ if (FluxProfit > 0)
|
|
|
+ {
|
|
|
+ MachineForSnNo forSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == TradeSnNo) ?? new MachineForSnNo();
|
|
|
+ PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == forSnNo.SnId) ?? new PosMachinesTwo();
|
|
|
+ PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
|
|
|
+ bool checkExist = db.FluxProfitDetail.Any(m => m.MerNo == merchant.KqMerNo);
|
|
|
+ if (!checkExist)
|
|
|
+ {
|
|
|
+ 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();
|
|
|
+ RedisDbconn.Instance.Clear("UserAccount:" + GetUserId);
|
|
|
+ }
|
|
|
+ SpModels.TradeFluxRecord edit = spdb.TradeFluxRecord.FirstOrDefault(m => m.Id == trade.Id);
|
|
|
+ if (edit != null)
|
|
|
+ {
|
|
|
+ edit.Status = 2;
|
|
|
+ spdb.SaveChanges();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ function.WriteLog(DateTime.Now.ToString() + "\n$" + trade.Id + "$\n" + ex.ToString(), "流量卡分佣异常");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ spdb.Dispose();
|
|
|
+ db.Dispose();
|
|
|
+ function.WriteLog(DateTime.Now.ToString() + "\n", "执行流量费返佣");
|
|
|
+ }
|
|
|
+ public void CheckFluxForTrade(object sender)
|
|
|
+ {
|
|
|
+ string date = sender.ToString();
|
|
|
+ function.WriteLog(DateTime.Now.ToString(), "扫描金控交易记录中的流量费");
|
|
|
+ SpModels.WebCMSEntities spdb = new SpModels.WebCMSEntities();
|
|
|
+ DateTime start = DateTime.Parse(date + " 00:00:00");
|
|
|
+ DateTime end = start.AddDays(1);
|
|
|
+ var list = spdb.TradeRecord.Select(m => new { m.Id, m.CreateDate, m.ProductType }).Where(m => m.CreateDate > start && m.CreateDate < end && m.ProductType == "1").OrderBy(m => m.CreateDate);
|
|
|
+ foreach (var sub in list.ToList())
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ SpModels.TradeRecord trade = spdb.TradeRecord.FirstOrDefault(m => m.Id == sub.Id);
|
|
|
+ if (trade != null)
|
|
|
+ {
|
|
|
+ string content = trade.SeoDescription;
|
|
|
+ if (!string.IsNullOrEmpty(content))
|
|
|
+ {
|
|
|
+ content = System.Web.HttpUtility.UrlDecode(content);
|
|
|
+ JsonData jsonObj = JsonMapper.ToObject(content);
|
|
|
+ decimal terminalDataFlowFee = decimal.Parse(function.CheckNum(jsonObj["terminalDataFlowFee"].ToString()));
|
|
|
+ if (terminalDataFlowFee > 0)
|
|
|
+ {
|
|
|
+ spdb.TradeFluxRecord.Add(new SpModels.TradeFluxRecord()
|
|
|
+ {
|
|
|
+ SeoDescription = trade.TradeSerialNo,
|
|
|
+ FeeAmount = terminalDataFlowFee,
|
|
|
+ TradeSerialNo = function.MD5_16(trade.TradeSerialNo),
|
|
|
+ CreateDate = trade.CreateDate,
|
|
|
+ TradeSnNo = trade.TradeSnNo,
|
|
|
+ ProductType = trade.ProductType,
|
|
|
+ Status = 1,
|
|
|
+ });
|
|
|
+ spdb.SaveChanges();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ function.WriteLog(DateTime.Now.ToString() + "\n$" + sub.Id + "$\n" + ex.ToString(), "扫描金控交易记录中的流量费异常");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ spdb.Dispose();
|
|
|
+ function.WriteLog(DateTime.Now.ToString() + "\n", "扫描金控交易记录中的流量费");
|
|
|
+
|
|
|
+ doFluxRecord(date);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|