12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274 |
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Data;
- using System.Threading.Tasks;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Logging;
- using MySystem.PxcModels;
- using System.Threading;
- using Library;
- using LitJson;
- namespace MySystem.Controllers
- {
- public class HomeController : Controller
- {
- private readonly ILogger<HomeController> _logger;
- public HomeController(ILogger<HomeController> logger)
- {
- _logger = logger;
- }
- public IActionResult Index()
- {
- return View();
- }
- public IActionResult Error()
- {
- string isapi = Request.Headers["Api"].ToString();
- if (isapi != "1")
- {
- if (Response.StatusCode == 500)
- {
- return Redirect("/public/errpage/pc/500.html");
- }
- else if (Response.StatusCode == 502)
- {
- return Redirect("/public/errpage/pc/502.html");
- }
- else if (Response.StatusCode == 404)
- {
- return Redirect("/public/errpage/pc/404.html");
- }
- }
- return View();
- }
- private static object o = new object();
- public string addmer(string mid, int k = 0)
- {
- MerchantConfirmService.Instance.Start(mid, k);
- return "ok";
- }
- public string setqrcode(int uid = 0)
- {
- return "ok";
- }
- public string userqrcode(int uid)
- {
- WebCMSEntities db = new WebCMSEntities();
- Users user = db.Users.FirstOrDefault(m => m.Id == uid);
- if (user != null)
- {
- MakeReferenceQrCodeService.Instance.Start(user.Id.ToString());
- return "ok";
- }
- db.Dispose();
- return "fail";
- }
- public string getqrcode(int uid, int pid)
- {
- WebCMSEntities db = new WebCMSEntities();
- Users user = db.Users.FirstOrDefault(m => m.Id == uid);
- if (user != null)
- {
- return MakeReferenceQrCodeService.Instance.MergeQrCode(user, pid);
- }
- db.Dispose();
- return "fail";
- }
- private void th1()
- {
- Thread th = new Thread(th1do);
- th.IsBackground = true;
- th.Start();
- }
- private void th1do()
- {
- WebCMSEntities db = new WebCMSEntities();
- Users user = db.Users.FirstOrDefault(m => m.Id == 2);
- if (user != null)
- {
- user.SeoTitle = "111111";
- Thread.Sleep(5000);
- user.SeoDescription = "222222";
- db.SaveChanges();
- }
- db.Dispose();
- }
- private void th2()
- {
- Thread th = new Thread(th2do);
- th.IsBackground = true;
- th.Start();
- }
- private void th2do()
- {
- Thread.Sleep(2000);
- WebCMSEntities db = new WebCMSEntities();
- Users user = db.Users.FirstOrDefault(m => m.Id == 2);
- if (user != null)
- {
- user.SeoKeyword = "看看有没有值写入";
- db.SaveChanges();
- }
- db.Dispose();
- }
- // 补激活奖励
- public string setmeruser(string date)
- {
- StatService.Instance.dosomething1(date);
- return "ok";
- }
- // 补流量费奖励
- public string addflux(string date)
- {
- StatService.Instance.doFluxRecord(date);
- return "ok";
- }
- public string addflux2(string date)
- {
- StatService.Instance.CheckFluxForTrade(date);
- return "ok";
- }
- // 补发小盟主15000返现
- public string LeaderBack(int oid)
- {
- WebCMSEntities db = new WebCMSEntities();
- Orders order = db.Orders.FirstOrDefault(m => m.Id == oid);
- if(order != null)
- {
- AlipayPayBack2Service.Instance.LeaderBack(db, order);
- }
- db.Dispose();
- return "ok";
- }
- public string chkactprize(int Id = 0)
- {
- if (Id > 0)
- {
- StatService.Instance.dosomething3(Id);
- }
- return "ok";
- }
- public string chkactprize2(int Id = 0)
- {
- if (Id > 0)
- {
- StatService.Instance.activePrizeWithoutDeposit(Id);
- }
- return "ok";
- }
- public string mutilactprize()
- {
- List<int> ids = new List<int>();
- WebCMSEntities db = new WebCMSEntities();
- SpModels.WebCMSEntities spdb = new SpModels.WebCMSEntities();
- foreach (int id in ids)
- {
- PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == id);
- if (pos != null)
- {
- SpModels.ActivateRecord act = spdb.ActivateRecord.FirstOrDefault(m => m.SnNo == pos.PosSn && m.SeoTitle != "0" && !string.IsNullOrEmpty(m.SeoTitle));
- if (act != null)
- {
- pos.SeoKeyword = act.SeoTitle;
- db.SaveChanges();
- StatService.Instance.dosomething3(pos.Id);
- }
- }
- }
- db.Dispose();
- spdb.Dispose();
- return "ok";
- }
- public string scanBind()
- {
- SpModels.WebCMSEntities spdb = new SpModels.WebCMSEntities();
- PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
- var Binds = spdb.BindRecord.Select(m => new { m.Id, m.CreateTime, m.Status, m.MerNo, m.MerSnNo }).OrderBy(m => m.Id).ToList();
- foreach (var Bind in Binds)
- {
- var tran = db.Database.BeginTransaction();
- try
- {
- PxcModels.MachineForSnNo posFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == Bind.MerSnNo) ?? new PxcModels.MachineForSnNo();
- PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
- if (pos != null)
- {
- if (pos.BindingState == 0)
- {
- pos.BindingState = 1;
- pos.BindingTime = Bind.CreateTime;
- PxcModels.MachineForMerNo merFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Bind.MerNo);
- if (merFor == null)
- {
- merFor = db.MachineForMerNo.Add(new PxcModels.MachineForMerNo()
- {
- MerNo = Bind.MerNo,
- SnId = pos.Id,
- }).Entity;
- }
- db.SaveChanges();
- tran.Commit();
- function.WriteLog(pos.PosSn, "补充绑定数据");
- }
- }
- }
- catch (Exception ex)
- {
- tran.Rollback();
- function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n" + Bind.Id, "同步SP绑定数据到MAIN异常");
- }
- tran.Dispose();
- }
- spdb.SaveChanges();
- spdb.Dispose();
- db.SaveChanges();
- db.Dispose();
- return "ok";
- }
- public string scanMerchant()
- {
- SpModels.WebCMSEntities spdb = new SpModels.WebCMSEntities();
- PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
- var Mers = spdb.Merchants.OrderBy(m => m.Id).ToList();
- foreach (var Mer in Mers)
- {
- var tran = db.Database.BeginTransaction();
- try
- {
- PxcModels.MachineForMerNo posFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Mer.MerNo) ?? new PxcModels.MachineForMerNo();
- PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId) ?? new PxcModels.PosMachinesTwo();
- if (pos.BindingState == 1)
- {
- PxcModels.Users user = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new PxcModels.Users();
- int TopUserId = 0;
- if (!string.IsNullOrEmpty(user.ParentNav))
- {
- TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
- }
- int BrandId = int.Parse(Mer.ProductType);
- if (Mer.MerNo.StartsWith("M900"))
- {
- BrandId = 3;
- }
- bool check = db.PosMerchantInfo.Any(m => m.KqMerNo == Mer.MerNo);
- if (!check)
- {
- PxcModels.PosMerchantInfo add = db.PosMerchantInfo.Add(new PxcModels.PosMerchantInfo()
- {
- CreateDate = Mer.CreateTime,
- UpdateDate = Mer.UpdateTime,
- TopUserId = TopUserId,
- MerUserType = user.MerchantType,
- BrandId = BrandId,
- SnStoreId = pos.StoreId,
- SnType = pos.PosSnType,
- UserId = pos.UserId,
- MgrName = Mer.AgentName,
- MerStatus = 1,
- KqSnNo = Mer.SnNo,
- KqMerNo = Mer.MerNo,
- MerIdcardNo = Mer.MerIdcardNo,
- MerRealName = Mer.MerRealName,
- MerchantMobile = Mer.MerMobile,
- MerchantName = Mer.MerName,
- MerchantNo = Mer.MerNo.Length > 16 ? Mer.MerNo.Substring(0, 16) : Mer.MerNo,
- }).Entity;
- db.SaveChanges();
- pos.BindMerchantId = add.Id;
- db.SaveChanges();
- tran.Commit();
- function.WriteLog(Mer.MerNo, "补充商户数据");
- }
- }
- }
- catch (Exception ex)
- {
- tran.Rollback();
- function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n" + Mer.Id, "同步SP商户数据到MAIN异常");
- }
- tran.Dispose();
- }
- spdb.Dispose();
- db.Dispose();
- return "ok";
- }
- public string scanTrade()
- {
- SpModels.WebCMSEntities spdb = new SpModels.WebCMSEntities();
- PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
- IQueryable<SpModels.TradeRecord> trades = spdb.TradeRecord.OrderBy(m => m.Id);
- foreach (SpModels.TradeRecord trade in trades.ToList())
- {
- bool op = true;
- if (trade.SerEntryMode == "N")
- {
- if (trade.TradeAmount == 9900 || trade.TradeAmount == 19900 || trade.TradeAmount == 29900)
- {
- op = false;
- PxcModels.MachineForMerNo posFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == trade.MerNo) ?? new PxcModels.MachineForMerNo();
- PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
- if (pos != null)
- {
- if (trade.SerEntryMode == "N" && trade.ProductType == "1")
- {
- pos.SeoKeyword = trade.TradeAmount.ToString("f2");
- db.SaveChanges();
- }
- }
- }
- }
- if (op)
- {
- PxcModels.MachineForMerNo posFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == trade.MerNo) ?? new PxcModels.MachineForMerNo();
- PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
- if (pos != null)
- {
- if (pos.BindMerchantId > 0)
- {
- PxcModels.Users user = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new PxcModels.Users();
- int TopUserId = 0;
- if (!string.IsNullOrEmpty(user.ParentNav))
- {
- TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
- }
- bool check = db.TradeRecord.Any(m => m.RecordNo == trade.TradeSerialNo);
- if (!check)
- {
- decimal TradeAmount = trade.TradeAmount;
- int BankCardType = -1;
- int QrPayFlag = 0;
- if (pos.BrandId == 1 || pos.BrandId == 3)
- {
- TradeAmount = TradeAmount / 100;
- BankCardType = int.Parse(trade.BankCardType);
- if (trade.TradeType == "02") QrPayFlag = 1;
- }
- else if (pos.BrandId == 2)
- {
- if (trade.TradeType == "CREDIT_BY_CARD")
- {
- BankCardType = 1;
- }
- else if (trade.TradeType == "DEBIT_BY_CARD")
- {
- BankCardType = 0;
- }
- if (trade.TradeType == "CLOUD_PAY") QrPayFlag = 1;
- }
- int BrandId = int.Parse(trade.ProductType);
- if (trade.MerNo.StartsWith("M900"))
- {
- BrandId = 3;
- }
- db.TradeRecord.Add(new PxcModels.TradeRecord()
- {
- CreateDate = trade.CreateDate,
- UpdateDate = trade.UpdateDate,
- RecordNo = trade.TradeSerialNo, //单号
- UserId = pos.UserId, //创客
- MerchantId = pos.BindMerchantId, //商户
- MerNo = trade.MerNo, //渠道商户编号
- MerHelpFlag = 0, //是否属于扶持周期内商户
- HelpMonthCount = 0, //扶持第几个月
- MerBuddyType = user.MerchantType, //商户创客类型
- SnNo = trade.TradeSnNo, //渠道SN号
- // TradeDate = DateTime.Parse(trade.TradeTime), //交易日期
- TradeSerialNo = trade.ChannelSerial, //交易流水号
- TradeAmount = TradeAmount, //交易金额
- BankCardType = BankCardType, //银行卡类型
- QrPayFlag = QrPayFlag, //云闪付标识
- BrandId = BrandId, //品牌
- Remark = trade.Remark, //备注
- TopUserId = TopUserId, //顶级创客
- MerUserId = pos.UserId, //商户直属创客
- ParentNav = user.ParentNav,
- });
- if (BankCardType == 1)
- {
- pos.CreditTrade += TradeAmount;
- }
- else if (BankCardType == 0)
- {
- pos.DebitCardTrade += TradeAmount;
- }
- else if (pos.CreditTrade >= 1000 && pos.ActivationState == 0 && pos.BindingTime > DateTime.Now.AddDays(-20))
- {
- // pos.IsPurchase = 0;
- pos.ActivationState = 1;
- pos.ActivationTime = DateTime.Now;
- PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
- if (merchant != null)
- {
- merchant.ActiveStatus = 1;
- merchant.MerStandardDate = DateTime.Now;
- db.SaveChanges();
- }
- }
- db.SaveChanges();
- function.WriteLog(trade.Id.ToString(), "补充交易数据");
- }
- }
- }
- }
- }
- spdb.Dispose();
- db.Dispose();
- return "ok";
- }
- // public string add100()
- // {
- // WebCMSEntities db = new WebCMSEntities();
- // List<int> uids = new List<int>();
- // uids.Add(1053);
- // foreach (int uid in uids)
- // {
- // int ParentUserId = uid;
- // int machineCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.PosSnType == 0); //判断是否拥有3台购买机
- // int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
- // if (machineCount + ActiveCount >= 3)
- // {
- // UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == ParentUserId);
- // if (account == null)
- // {
- // account = db.UserAccount.Add(new UserAccount()
- // {
- // Id = ParentUserId,
- // UserId = ParentUserId,
- // }).Entity;
- // db.SaveChanges();
- // }
- // decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
- // decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
- // decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
- // account.BalanceAmount += 100;
- // account.TotalAmount += 100;
- // 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 = ParentUserId, //创客
- // ChangeType = 112, //变动类型
- // ChangeAmount = 100, //变更金额
- // BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
- // AfterTotalAmount = AfterTotalAmount, //变更后总金额
- // BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
- // AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
- // BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
- // AfterBalanceAmount = AfterBalanceAmount, //变更后余额
- // }).Entity;
- // db.SaveChanges();
- // //推荐下单上级获得30天的机具循环天数
- // var posList = db.PosMachinesTwo.Select(m => new { m.Id, m.UserId, m.BindingState, m.RecycEndDate }).Where(m => m.UserId == ParentUserId && m.BindingState == 0 && m.RecycEndDate != null).ToList();
- // foreach (var subPos in posList)
- // {
- // PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == subPos.Id);
- // if (pos != null)
- // {
- // pos.RecycEndDate = pos.RecycEndDate.Value.AddDays(30);
- // }
- // }
- // db.SaveChanges();
- // }
- // }
- // db.Dispose();
- // return "finish";
- // }
- //交易不到1000的机具,顶级姓名-代理姓名-客户姓名-客户电话-开机日期-SN // TODO:做到BS后台导出,按绑定时间查
- public IActionResult PosTable()
- {
- WebCMSEntities db = new WebCMSEntities();
- List<PosMachinesTwo> poses = db.PosMachinesTwo.Where(m => m.CreditTrade < 1000 && m.BindingState == 1).ToList();
- List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
- foreach (PosMachinesTwo pos in poses)
- {
- PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
- Users user = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new Users();
- Users puser = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId) ?? new Users();
- Users ppuser = db.Users.FirstOrDefault(m => m.Id == puser.ParentUserId) ?? new Users();
- Dictionary<string, string> item = new Dictionary<string, string>();
- string TopRealName = "";
- string TopMakerCode = "";
- string TopMobile = "";
- string ParentNav = user.ParentNav;
- if (!string.IsNullOrEmpty(ParentNav))
- {
- string[] navlist = ParentNav.Trim(',').Replace(",,", ",").Split(',');
- if (navlist.Length > 1)
- {
- int TopId = int.Parse(function.CheckInt(navlist[1]));
- Users tuser = db.Users.FirstOrDefault(m => m.Id == TopId) ?? new Users();
- TopRealName = tuser.RealName;
- TopMakerCode = tuser.MakerCode;
- TopMobile = tuser.Mobile;
- }
- }
- item.Add("TopRealName", TopRealName); //顶级姓名
- item.Add("TopMakerCode", TopMakerCode); //顶级编号
- item.Add("UpUpRealName", ppuser.RealName); //上上级姓名
- item.Add("UpRealName", puser.RealName); //上级姓名
- item.Add("RealName", user.RealName); //代理姓名
- item.Add("MakerCode", user.MakerCode); //代理编号
- item.Add("Mobile", user.Mobile); //代理手机号
- item.Add("MerchantName", merchant.MerchantName); //客户姓名
- item.Add("MerchantMobile", merchant.MerchantMobile); //客户电话
- item.Add("OpenTime", pos.BindingTime == null ? "" : pos.BindingTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); //开机日期
- item.Add("Sn", pos.PosSn); //SN
- list.Add(item);
- }
- db.Dispose();
- ViewBag.list = list;
- return View();
- }
-
- public string resetpos(int uid, int kind)
- {
- WebCMSEntities db = new WebCMSEntities();
- string IdBrand = uid + "_" + kind;
- UserMachineData machineData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
- if (machineData == null)
- {
- machineData = db.UserMachineData.Add(new UserMachineData()
- {
- IdBrand = IdBrand
- }).Entity;
- db.SaveChanges();
- }
- machineData.BindCount = db.PosMachinesTwo.Count(m => m.Status > -1 && m.BuyUserId == uid && m.BrandId == kind && m.BindingState == 1);
- machineData.UnBindCount = db.PosMachinesTwo.Count(m => m.Status > -1 && m.BuyUserId == uid && m.BrandId == kind && m.BindingState == 0);
- machineData.TotalMachineCount = machineData.BindCount + machineData.UnBindCount;
- db.SaveChanges();
- db.Dispose();
- return "finish";
- }
- // 更新分仓库存
- public string resetstorestock()
- {
- WebCMSEntities db = new WebCMSEntities();
- DataTable dt = dbconn.dtable("select s.Id,LaveNum,count(p.Id) as CurLaveNum from StoreHouse s left join PosMachinesTwo p on s.Id=p.StoreId and s.BrandId=p.BrandId and p.UserId=0 group by s.Id HAVING LaveNum!=count(p.Id)");
- foreach (DataRow dr in dt.Rows)
- {
- int Id = int.Parse(function.CheckInt(dr["Id"].ToString()));
- int CurLaveNum = int.Parse(function.CheckInt(dr["CurLaveNum"].ToString()));
- StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == Id);
- if (store != null)
- {
- store.LaveNum = CurLaveNum;
- db.SaveChanges();
- }
- }
- db.Dispose();
- return "ok";
- }
- public string resetstorestock2(int id)
- {
- WebCMSEntities db = new WebCMSEntities();
- DataTable dt = dbconn.dtable("select Id,LaveNum,(select count(Id) from PosMachinesTwo where StoreId=s.Id and UserId=0) as CurLaveNum from StoreHouse s where Id=" + id);
- foreach (DataRow dr in dt.Rows)
- {
- int Id = int.Parse(function.CheckInt(dr["Id"].ToString()));
- int CurLaveNum = int.Parse(function.CheckInt(dr["CurLaveNum"].ToString()));
- StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == Id);
- if (store != null)
- {
- store.LaveNum = CurLaveNum;
- db.SaveChanges();
- }
- }
- db.Dispose();
- return "ok";
- }
- public string chkpwd(string pwd)
- {
- return function.MD532(pwd);
- }
- //重置本月团队交易额
- public string resetMonthTrade()
- {
- return "";
- }
- public string traderecord(int kind, int id = 0)
- {
- OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["Pxc1SqlConnStr"].ToString();
- if (kind == 1)
- {
- OtherMySqlConn.op("delete from TradeRecordTest;insert into TradeRecordTest (Sort,QueryCount,Status,Version,CreateDate,UpdateDate,CreateMan,UpdateMan,SeoTitle,SeoKeyword,SeoDescription,MerUserId,TopUserId,Remark,BrandId,DirectFlag,CapFlag,QrPayFlag,BankCardType,TradeAmount,TradeSerialNo,ClearDate,TradeDate,SnNo,MerBuddyType,HelpMonthCount,MerHelpFlag,MerNo,MerchantId,UserId,RecordNo) select Sort,QueryCount,Status,Version,CreateDate,UpdateDate,CreateMan,UpdateMan,SeoTitle,SeoKeyword,SeoDescription,MerUserId,TopUserId,Remark,BrandId,DirectFlag,CapFlag,QrPayFlag,BankCardType,TradeAmount,TradeSerialNo,ClearDate,TradeDate,SnNo,MerBuddyType,HelpMonthCount,MerHelpFlag,MerNo,MerchantId,UserId,RecordNo from TradeRecord order by CreateDate;");
- }
- else if (kind == 2)
- {
- OtherMySqlConn.op("delete from TradeRecord where Id<" + id + ";insert into TradeRecord (Id,Sort,QueryCount,Status,Version,CreateDate,UpdateDate,CreateMan,UpdateMan,SeoTitle,SeoKeyword,SeoDescription,MerUserId,TopUserId,Remark,BrandId,DirectFlag,CapFlag,QrPayFlag,BankCardType,TradeAmount,TradeSerialNo,ClearDate,TradeDate,SnNo,MerBuddyType,HelpMonthCount,MerHelpFlag,MerNo,MerchantId,UserId,RecordNo) select Id,Sort,QueryCount,Status,Version,CreateDate,UpdateDate,CreateMan,UpdateMan,SeoTitle,SeoKeyword,SeoDescription,MerUserId,TopUserId,Remark,BrandId,DirectFlag,CapFlag,QrPayFlag,BankCardType,TradeAmount,TradeSerialNo,ClearDate,TradeDate,SnNo,MerBuddyType,HelpMonthCount,MerHelpFlag,MerNo,MerchantId,UserId,RecordNo from TradeRecordTest order by Id;");
- }
- // OtherMySqlConn.connstr = ;
- return "ok";
- }
- public string test()
- {
- string result = "ok";
- OtherMySqlConn.connstr = "server=47.109.31.237;port=3306;user=KxsMainServer;password=Rw2imhXQQt5ODWIF;database=KxsMainServer;charset=utf8;";
- DataTable dt = OtherMySqlConn.dtable("select * from ProfitSubsidyDetail where TradeMonth='202204'");
- WebCMSEntities db = new WebCMSEntities();
- foreach (DataRow dr in dt.Rows)
- {
- int BrandId = int.Parse(function.CheckInt(dr["BrandId"].ToString()));
- int MerchantId = int.Parse(function.CheckInt(dr["MerchantId"].ToString()));
- int SubsidyUserId = int.Parse(function.CheckInt(dr["SubsidyUserId"].ToString()));
- int SubsidyType = int.Parse(function.CheckInt(dr["SubsidyType"].ToString()));
- ulong MerHelpFlag = ulong.Parse(function.CheckInt(dr["MerHelpFlag"].ToString()));
- decimal SubsidyProfitRate = decimal.Parse(function.CheckNum(dr["SubsidyProfitRate"].ToString()));
- decimal CreditTradeAmt = decimal.Parse(function.CheckNum(dr["CreditTradeAmt"].ToString()));
- decimal QrCreditTradeAmt = decimal.Parse(function.CheckNum(dr["QrCreditTradeAmt"].ToString()));
- decimal NonQrCreditTradeAmt = decimal.Parse(function.CheckNum(dr["NonQrCreditTradeAmt"].ToString()));
- decimal CreditProfitRate = decimal.Parse(function.CheckNum(dr["CreditProfitRate"].ToString()));
- decimal SubsidyProfit = decimal.Parse(function.CheckNum(dr["SubsidyProfit"].ToString()));
- string TradeMonth = dr["TradeMonth"].ToString();
- string SnNo = dr["SnNo"].ToString();
- string MerNo = dr["MerNo"].ToString();
- string RecordNo = dr["RecordNo"].ToString();
- MachineForSnNo forSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SnNo) ?? new MachineForSnNo();
- PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == forSnNo.SnId) ?? new PosMachinesTwo();
- PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == MerchantId) ?? new PosMerchantInfo();
- ProfitSubsidyDetail item = db.ProfitSubsidyDetail.FirstOrDefault(m => m.SubsidyUserId == SubsidyUserId && m.TradeMonth == TradeMonth && m.MerchantId == MerchantId && m.SnNo == SnNo);
- if (item == null)
- {
- db.ProfitSubsidyDetail.Add(new ProfitSubsidyDetail()
- {
- CreateDate = DateTime.Now,
- UpdateDate = DateTime.Now,
- RecordNo = RecordNo, //流水号
- BrandId = BrandId, //品牌
- ProductName = RelationClass.GetKqProductBrandInfo(BrandId), //产品名称
- TradeMonth = TradeMonth, //交易月份
- MerchantId = MerchantId, //商户
- MerNo = MerNo, //渠道商户编号
- SnNo = SnNo, //渠道SN号
- MerRegTime = pos.BindingTime, //渠道注册时间
- MerStandardDate = merchant.MerStandardDate, //商户激活时间
- BelongUserId = merchant.UserId, //商户归属人
- MerHelpFlag = MerHelpFlag, //是否属于扶持周期内商户
- SubsidyUserId = SubsidyUserId, //补贴人
- SubsidyType = SubsidyType, //分润补贴类型
- SubsidyProfitRate = SubsidyProfitRate, //创客活动期内直营商户分润万分之十
- CreditTradeAmt = CreditTradeAmt, //商户贷记卡交易总金额
- QrCreditTradeAmt = QrCreditTradeAmt, //商户(云闪付)贷记卡交易总金额
- NonQrCreditTradeAmt = NonQrCreditTradeAmt, //商户(非云闪付)贷记卡交易总金额
- CreditProfitRate = CreditProfitRate, //(非云闪付)贷记卡交易分润比例
- SubsidyProfit = SubsidyProfit, //商户(非云闪付)贷记卡交易分润补贴金额
- });
- // db.SaveChanges();
- result += "增加--SubsidyUserId:" + SubsidyUserId + ";SnNo" + SnNo + ";SubsidyProfit" + SubsidyProfit + ";";
- }
- else
- {
- if (item.SubsidyProfit < SubsidyProfit)
- {
- item.SubsidyProfitRate = SubsidyProfitRate; //创客活动期内直营商户分润万分之十
- item.SubsidyProfit = SubsidyProfit; //商户(非云闪付)贷记卡交易分润补贴金额
- result += "更新--SubsidyUserId:" + SubsidyUserId + ";SnNo" + SnNo + ";SubsidyProfit" + SubsidyProfit + ";";
- // db.SaveChanges();
- }
- }
- }
- // OtherMySqlConn.connstr = ;
- db.Dispose();
- return result;
- }
- public string test2()
- {
- string result = "ok";
- OtherMySqlConn.connstr = "server=47.108.231.170;port=3306;user=KxsMainServer;password=Rw2imhXQQt5ODWIF;database=KxsMainServer;charset=utf8;";
- DataTable dt = OtherMySqlConn.dtable("select SubsidyUserId,BrandId,sum(SubsidyProfitRate) as SubsidyProfit from ProfitSubsidyDetail where TradeMonth='202204' and SubsidyUserId>0 GROUP BY SubsidyUserId,BrandId");
- WebCMSEntities db = new WebCMSEntities();
- DateTime checkDate = DateTime.Parse("2022-05-20 00:00:00");
- foreach (DataRow dr in dt.Rows)
- {
- int BrandId = int.Parse(function.CheckInt(dr["BrandId"].ToString()));
- int SubsidyUserId = int.Parse(function.CheckInt(dr["SubsidyUserId"].ToString()));
- decimal SubsidyProfit = decimal.Parse(function.CheckNum(dr["SubsidyProfit"].ToString()));
- UserAccountRecord userAccountRecord = db.UserAccountRecord.FirstOrDefault(m => m.Id > 86538 && m.CreateDate > checkDate && m.UserId == SubsidyUserId && m.ProductType == BrandId && m.ChangeType == 111);
- if (userAccountRecord == null)
- {
- UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == SubsidyUserId);
- if (account == null)
- {
- account = db.UserAccount.Add(new UserAccount()
- {
- Id = SubsidyUserId,
- UserId = SubsidyUserId,
- }).Entity;
- db.SaveChanges();
- }
- decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
- decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
- decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
- // account.BalanceAmount += SubsidyProfit;
- // account.TotalAmount += SubsidyProfit;
- decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
- decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
- decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
- userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
- {
- CreateDate = DateTime.Now,
- UpdateDate = DateTime.Now,
- UserId = SubsidyUserId, //创客
- ProductType = BrandId,
- ChangeType = 111, //变动类型
- ChangeAmount = SubsidyProfit, //变更金额
- BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
- AfterTotalAmount = AfterTotalAmount, //变更后总金额
- BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
- AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
- BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
- AfterBalanceAmount = AfterBalanceAmount, //变更后余额
- Remark = "直拓商户补贴",
- }).Entity;
- db.SaveChanges();
- }
- else
- {
- userAccountRecord.ChangeAmount = SubsidyProfit;
- db.SaveChanges();
- }
- }
- // OtherMySqlConn.connstr = ;
- db.Dispose();
- return result;
- }
- // 翻倍奖888
- public string prize888v2()
- {
- WebCMSEntities maindb = new WebCMSEntities();
- List<int> userIdList = new List<int>();
- string html = "<table>";
- DateTime StartDate = DateTime.Parse(DateTime.Now.AddMonths(-1).ToString("yyyy-MM") + "-01 00:00:00");
- DateTime EndDate = StartDate.AddMonths(1);
- var orders = maindb.Orders.Select(m => new { m.UserId, m.TotalPrice, m.Status, m.PayDate }).Where(m => m.PayDate >= StartDate && m.PayDate < EndDate && m.TotalPrice == 88 && m.Status > 0).ToList();
- foreach (var order in orders)
- {
- userIdList.Add(order.UserId);
- }
- foreach (int UserId in userIdList)
- {
- Users myuser = maindb.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
- var lastmonth = DateTime.Now.AddMonths(-2).ToString("yyyyMM");
- var thismonth = DateTime.Now.AddMonths(-1).ToString("yyyyMM");
- DateTime start = DateTime.Now.AddDays(1 - DateTime.Now.Day).Date;
- DateTime end = DateTime.Now.AddDays(1 - DateTime.Now.Day).Date.AddMonths(1).AddSeconds(-1);
- string UserIdString = "," + UserId + ",";
- List<Users> users = maindb.Users.Where(m => m.ParentNav.Contains(UserIdString) || m.Id == UserId).ToList();
- List<int> uids = new List<int>();
- List<int> uids2 = new List<int>();
- foreach (var user in users)
- {
- uids.Add(user.Id);
- }
- var suborders = orders.Where(m => uids.Contains(m.UserId)).ToList();
- foreach (var suborder in suborders)
- {
- uids2.Add(suborder.UserId);
- }
- users = users.Where(m => uids2.Contains(m.Id)).ToList();
- List<ProgressUserList> list = new List<ProgressUserList>();
- foreach (Users user in users)
- {
- int IsOk = 0;//是否达标(0-否 1-是)
- decimal lastMonthAmt = maindb.TradeDaySummary.Where(m => m.TradeMonth == lastmonth && m.SeoTitle == "team" && m.UserId == user.Id).Sum(m => m.HelpNonDirectTradeAmt + m.NotHelpNonDirectTradeAmt);
- decimal thisMonthAmt = maindb.TradeDaySummary.Where(m => m.TradeMonth == thismonth && m.SeoTitle == "team" && m.UserId == user.Id).Sum(m => m.HelpNonDirectTradeAmt + m.NotHelpNonDirectTradeAmt);
- if (thisMonthAmt >= lastMonthAmt * 2 && thisMonthAmt >= 2000000)
- {
- IsOk = 1;
- }
- ProgressUserList item = new ProgressUserList()
- {
- LastMonth = lastMonthAmt,
- ThisMonth = thisMonthAmt,
- UserId = user.Id,
- ParentNav = user.ParentNav,
- IsOk = IsOk,
- };
- list.Add(item);
- }
- list = list.OrderBy(m => m.ParentNav).ToList();
- int index = 0;
- decimal selfTrade = 0; // 自己的本月交易额
- decimal lastTrade = 0; // 自己的上月交易额
- decimal totalTrade = 0; // 自己的本月目标交易额
- string selfNav = ""; // 自己的ParentNav
- List<string> ParentNavs = new List<string>();
- if (list.Count > 0)
- {
- foreach (ProgressUserList sub in list)
- {
- index += 1;
- if (index == 1)
- {
- selfTrade = sub.ThisMonth;
- lastTrade = sub.LastMonth;
- totalTrade = lastTrade * 2;
- selfNav = sub.ParentNav + "," + sub.UserId + ",";
- }
- else
- {
- bool op = true; //是否满足条件
- string ParentNav = sub.ParentNav + "," + sub.UserId + ",";
- foreach (string subNav in ParentNavs)
- {
- if (ParentNavs.Contains(ParentNav) && ParentNav != subNav)
- {
- op = false;
- }
- }
- if (op)
- {
- if (sub.IsOk == 1)
- {
- selfTrade -= sub.ThisMonth;
- totalTrade -= sub.ThisMonth;
- }
- }
- ParentNavs.Add(ParentNav);
- }
- }
- }
- if (lastTrade * 2 < 2000000 || selfTrade == 0 || totalTrade < 2000000)
- {
- totalTrade = 2000000;
- }
- html += "<tr>";
- html += "<td>" + myuser.MakerCode + "</td>";
- html += "<td>" + myuser.RealName + "</td>";
- html += "<td>" + selfTrade + "</td>";
- html += "<td>" + lastTrade + "</td>";
- html += "<td>" + totalTrade + "</td>";
- if (selfTrade >= totalTrade)
- {
- html += "<td>满足条件</td>";
- }
- else
- {
- html += "<td>未满足条件</td>";
- }
- html += "</tr>";
- }
- html += "</table>";
- maindb.Dispose();
- return html;
- }
- // 大盟主标记扫描
- public string leaderflag()
- {
- WebCMSEntities db = new WebCMSEntities();
- List<int> ids = new List<int>();
- // List<PosCouponRecord> records = db.PosCouponRecord.Where(m => m.FromUserId == 597).ToList();
- // foreach(PosCouponRecord record in records)
- // {
- // ids.Add(record.PosCouponId);
- // }
- ids.Add(6843);
- List<PosCoupons> coupons = db.PosCoupons.Where(m => ids.Contains(m.Id) && m.IsUse == 1).ToList();
- foreach (PosCoupons coupon in coupons)
- {
- PosSns.Add(coupon.ExchangeCode);
- }
- foreach (PosCoupons coupon in coupons)
- {
- ChildNo(db, coupon.ExchangeCode, coupon.ExchangeCode, coupon.LeaderUserId);
- }
- // db.SaveChanges();
- db.Dispose();
- return "ok";
- }
- List<string> nos = new List<string>();
- private void ChildNo(WebCMSEntities db, string RootCheckNo, string CheckNo, int LeaderUserId)
- {
- MachineApply apply = db.MachineApply.FirstOrDefault(m => m.SwapSnExpand.Contains(CheckNo));
- if(apply != null)
- {
- int len = 0;
- string[] SnList = apply.SwapSnExpand.TrimEnd('\n').Split('\n');
- foreach(string sn in SnList)
- {
- if(PosSns.Contains(sn.Split(':')[0]) || nos.Contains(sn.Split(':')[0]))
- {
- len += 1;
- }
- }
- Orders order = db.Orders.FirstOrDefault(m => m.Id == apply.QueryCount);
- if(order != null)
- {
- if(!string.IsNullOrEmpty(order.SnNos))
- {
- if(order.SnNos.Contains(","))
- {
- string[] SwapSnExpands = order.SnNos.TrimEnd(',').Split(',');
- int index = 0;
- foreach(string no in SwapSnExpands)
- {
- if(!nos.Contains(no) && index < len)
- {
- index += 1;
- nos.Add(no);
- ChildNo(db, RootCheckNo, no, LeaderUserId);
- }
- }
- }
- else
- {
- string[] SwapSnExpands = order.SnNos.TrimEnd('\n').Split('\n');
- int index = 0;
- foreach(string no in SwapSnExpands)
- {
- if(!nos.Contains(no) && index < len)
- {
- index += 1;
- nos.Add(no);
- ChildNo(db, RootCheckNo, no, LeaderUserId);
- }
- }
- }
- }
- else
- {
- MachineForSnNo forSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == CheckNo) ?? new MachineForSnNo();
- PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == forSnNo.SnId);
- if(pos != null)
- {
- // pos.LeaderUserId = LeaderUserId;
- // Library.function.WriteLog(LeaderUserId + ":" + pos.PosSn + ":" + apply.SwapSnExpand.TrimEnd('\n').Split('\n').Length, "大盟主奖励标记机具");
- Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
- Library.function.WriteLog(pos.PosSn + ":" + RootCheckNo + ":" + user.MakerCode + ":" + user.RealName, "大盟主奖励标记机具");
- }
- }
- }
- }
- else
- {
- MachineForSnNo forSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == CheckNo) ?? new MachineForSnNo();
- PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m=>m.Id == forSnNo.SnId);
- if(pos != null)
- {
- // pos.LeaderUserId = LeaderUserId;
- // Library.function.WriteLog(LeaderUserId + ":" + pos.PosSn, "大盟主奖励标记机具");
- Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
- Library.function.WriteLog(pos.PosSn + ":" + RootCheckNo + ":" + user.MakerCode + ":" + user.RealName, "大盟主奖励标记机具");
- }
- }
- }
- List<string> PosSns = new List<string>();
- public string ScanNos()
- {
- PosSns = new List<string>();
- PosSns.Add("00005002681889125851");
- WebCMSEntities db = new WebCMSEntities();
- foreach(string PosSn in PosSns)
- {
- ChildNo(db, PosSn, PosSn, 0);
- }
- db.Dispose();
- return "ok";
- }
-
- //补推荐奖励
- public string AddDirectPrice(int oid = 0)
- {
- WebCMSEntities db = new WebCMSEntities();
- List<int> uids = new List<int>(); //领取过的下单创客
- IQueryable<Orders> orders = db.Orders.Where(m => m.Status > 1 && m.UserId > 1 && m.TotalPrice % 600 == 0 && m.Sort == 0);
- if(oid > 0)
- {
- orders = orders.Where(m => m.Id == oid);
- }
- foreach (Orders order in orders.ToList())
- {
- if(!uids.Contains(order.UserId))
- {
- bool checkPrize = db.UserAccountRecord.Any(m => m.QueryCount == oid && m.ChangeType == 112);
- if(checkPrize)
- {
- uids.Add(order.UserId);
- }
- else
- {
- OrderProduct pro = db.OrderProduct.FirstOrDefault(m => m.OrderId == oid) ?? new OrderProduct();
- if (pro.ProductId == 10 || pro.ProductId == 11)
- {
- Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId);
- if (user != null)
- {
- bool directPrize = false; //直推奖标记
- int ParentUserId = user.ParentUserId;
- List<int> proids = new List<int>();
- proids.Add(10);
- proids.Add(11);
- while (ParentUserId > 0)
- {
- Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
- int machineCount = db.PosMachinesTwo.Count(m => m.BuyUserId == ParentUserId && m.PosSnType == 0 && m.ActivationState == 0); //判断是否拥有3台购买机
- int ActiveCount = db.PosMachinesTwo.Count(m => m.BuyUserId == ParentUserId && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
- int couponCount = db.PosCoupons.Count(m => m.UserId == ParentUserId && m.IsUse == 0); //判断是否拥有3张券
- if ((machineCount + ActiveCount + couponCount >= 3 || puser.LeaderLevel > 0) && !directPrize)
- {
- function.WriteLog("满足条件", "推荐下单奖励监控日志");
- if (puser.LeaderLevel == 0) // 非盟主直推奖励,每个创客第一次下单,上级可得
- {
- List<int> oids = new List<int>();
- var orderpros = db.OrderProduct.Select(m => new { m.OrderId, m.UserId, m.ProductId }).Where(m => m.UserId == order.UserId && proids.Contains(m.ProductId)).ToList();
- foreach (var orderpro in orderpros)
- {
- oids.Add(orderpro.OrderId);
- }
- bool check = db.Orders.Any(m => oids.Contains(m.Id) && m.Status > 0);
- if (check)
- {
- // AlipayPayBack2Service.Instance.DirectPrize(db, order.Id, ParentUserId, pro.ProductCount);
- function.WriteLog(order.Id + "," + ParentUserId + "," + pro.ProductCount, "没发的推荐奖励");
- directPrize = true;
- }
- }
- else
- {
- // 盟主直推奖励,可以每次下单获得
- // AlipayPayBack2Service.Instance.DirectPrize(db, order.Id, ParentUserId, pro.ProductCount);
- function.WriteLog(order.Id + "," + ParentUserId + "," + pro.ProductCount + "--盟主", "没发的推荐奖励");
- directPrize = true;
- }
- //推荐下单上级获得30天的机具循环天数
- var posList = db.PosMachinesTwo.Select(m => new { m.Id, m.UserId, m.BindingState, m.RecycEndDate }).Where(m => m.UserId == ParentUserId && m.BindingState == 0 && m.RecycEndDate != null).ToList();
- foreach (var subPos in posList)
- {
- PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == subPos.Id);
- if (pos != null)
- {
- pos.RecycEndDate = pos.RecycEndDate.Value.AddDays(30);
- }
- }
- db.SaveChanges();
- }
- if(directPrize)
- {
- ParentUserId = 0;
- }
- else
- {
- ParentUserId = puser.ParentUserId;
- }
- }
- }
- }
- }
- }
- }
- return "ok";
- }
- public string checkLeaderOrder(int OrderId)
- {
- WebCMSEntities db = new WebCMSEntities();
- Orders order = db.Orders.FirstOrDefault(m => m.Id == OrderId);
- if (order != null)
- {
- OrderProduct pro = db.OrderProduct.FirstOrDefault(m => m.OrderId == OrderId);
- if (pro != null)
- {
- //推荐下单奖励
- if (pro.ProductId == 10 || pro.ProductId == 11)
- {
- bool checkPrize = db.UserAccountRecord.Any(m => m.QueryCount == OrderId && m.ChangeType == 112);
- function.WriteLog("OrderId:" + OrderId, "推荐下单奖励监控日志");
- function.WriteLog("checkPrize:" + checkPrize, "推荐下单奖励监控日志");
- if (!checkPrize)
- {
- Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId);
- if (user != null)
- {
- bool directPrize = false; //直推奖标记
- bool buyPrize = false; //返100购机奖励标记
- int leaderFlag = 0; //返600备用金标记
- if(user.LeaderLevel > 0)
- {
- UserAccount acccount = db.UserAccount.FirstOrDefault(m => m.Id == order.UserId) ?? new UserAccount();
- if(acccount.LeaderReserve >= order.TotalPrice)
- {
- if(order.PayMode == 4)
- {
- //扣减备用金
- AlipayPayBack2Service.Instance.OpReserve(db, order, order.UserId, order.TotalPrice, 2, 0, "商城购机");
- //返回到余额
- // OpAccount(db, order, order.UserId, order.TotalPrice / pro.ProductCount, pro.ProductCount);
- }
- }
- //获得100元奖励
- AlipayPayBack2Service.Instance.OpAccount(db, order, order.UserId, 100, pro.ProductCount);
- //推荐奖励
- AlipayPayBack2Service.Instance.DirectPrize(db, order.Id, order.UserId, pro.ProductCount);
- //推荐下单上级获得30天的机具循环天数
- var posList = db.PosMachinesTwo.Select(m => new { m.Id, m.UserId, m.BindingState, m.RecycEndDate }).Where(m => m.UserId == order.UserId && m.BindingState == 0 && m.RecycEndDate != null).ToList();
- foreach (var subPos in posList)
- {
- PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == subPos.Id);
- if (pos != null)
- {
- pos.RecycEndDate = pos.RecycEndDate.Value.AddDays(30);
- }
- }
- db.SaveChanges();
- if(user.LeaderLevel != 2)
- {
- int PUserId = user.ParentUserId;
- while(PUserId > 0)
- {
- Users puser = db.Users.FirstOrDefault(m => m.Id == PUserId) ?? new Users();
- if(puser.LeaderLevel == 2)
- {
- UserAccount acc = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id) ?? new UserAccount();
- if(acc.LeaderReserve >= order.TotalPrice)
- {
- //扣减备用金
- AlipayPayBack2Service.Instance.OpReserve(db, order, puser.Id, order.TotalPrice, 2, order.UserId, "购机奖励");
- //返回到余额
- AlipayPayBack2Service.Instance.OpAccount(db, order, puser.Id, order.TotalPrice / pro.ProductCount, pro.ProductCount);
- }
- PUserId = 0;
- }
- else
- {
- PUserId = puser.ParentUserId;
- }
- }
- }
- return "自己就是盟主,发放成功";
- }
- int ParentUserId = user.ParentUserId;
- // List<int> proids = new List<int>();
- // proids.Add(10);
- // proids.Add(11);
- while(ParentUserId > 0)
- {
- Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
- int machineCount = db.PosMachinesTwo.Count(m => m.BuyUserId == ParentUserId && m.PosSnType == 0 && m.ActivationState == 0); //判断是否拥有3台购买机
- int ActiveCount = db.PosMachinesTwo.Count(m => m.BuyUserId == ParentUserId && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
- int couponCount = db.PosCoupons.Count(m => m.UserId == ParentUserId && m.IsUse == 0); //判断是否拥有3张券
- if ((machineCount + ActiveCount + couponCount >= 3 || puser.LeaderLevel > 0) && !directPrize)
- {
- // 盟主直推奖励,可以每次下单获得
- AlipayPayBack2Service.Instance.DirectPrize(db, order.Id, ParentUserId, pro.ProductCount);
- directPrize = true;
- //推荐下单上级获得30天的机具循环天数
- var posList = db.PosMachinesTwo.Select(m => new { m.Id, m.UserId, m.BindingState, m.RecycEndDate }).Where(m => m.UserId == ParentUserId && m.BindingState == 0 && m.RecycEndDate != null).ToList();
- foreach (var subPos in posList)
- {
- PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == subPos.Id);
- if (pos != null)
- {
- pos.RecycEndDate = pos.RecycEndDate.Value.AddDays(30);
- }
- }
- db.SaveChanges();
- }
- if(puser.LeaderLevel > 0)
- {
- UserAccount acccount = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id) ?? new UserAccount();
- if(acccount.LeaderReserve >= order.TotalPrice && !buyPrize)
- {
- //购机奖励
- AlipayPayBack2Service.Instance.OpAccount(db, order, puser.Id, 100, pro.ProductCount);
- buyPrize = true;
- }
- if(acccount.LeaderReserve >= order.TotalPrice && puser.LeaderLevel > leaderFlag)
- {
- //扣减备用金
- AlipayPayBack2Service.Instance.OpReserve(db, order, puser.Id, order.TotalPrice, 2, order.UserId, "购机奖励");
- //返回到余额
- AlipayPayBack2Service.Instance.OpAccount(db, order, puser.Id, order.TotalPrice / pro.ProductCount, pro.ProductCount);
- leaderFlag = puser.LeaderLevel;
- }
- }
- ParentUserId = puser.ParentUserId;
- }
- return "找到上级盟主,发放成功";
- }
- }
- }
- }
- }
- return "失败";
- }
-
-
- public string setdeposit()
- {
- // List<string> ordernos = new List<string>();
- // ordernos.Add("17343379");
- string content = "";
- // foreach(string orderno in ordernos)
- // {
- // content += SetDepositPostService.Instance.QueryFee(orderno) + "\n";
- // }
- // List<string> snnos = new List<string>();
- // foreach(string snno in snnos)
- // {
- // content += SetDepositPostService.Instance.ModifyFee(snno, 0.0006M) + "\n";
- // }
- content = SetDepositPostService.Instance.SetFeeForSft("38888910", "0.63");
- return content;
- }
- public string putdata()
- {
- WebCMSEntities db = new WebCMSEntities();
- var list = db.PosMachinesFeeChangeRecord.Where(m => m.Sort == 2 && m.Status == 0).ToList();
- foreach(var sub in list)
- {
- Users user = db.Users.FirstOrDefault(m => m.Id == sub.UserId) ?? new Users();
- string info = "{\"RecordId\":\"" + sub.Id + "\",\"PosId\":\"" + sub.PosId + "\",\"Fee\": \"0.6\",\"Kind\": \"2\",\"OpMan\": \"" + user.MakerCode + "\"}";
- RedisDbconn.Instance.AddList("SetDepositQueue", info);
- }
- db.Dispose();
- return "ok";
- }
-
- public string test3()
- {
- WebCMSEntities db = new WebCMSEntities();
- // StoreApplyHelper.Instance.DoSomething(db, 89);
- AlipayPayBack2Service.Instance.DoOrderV2(db, 94525);
- return "ok";
- }
- }
- }
|