| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703 |
- /*
- * 机具激活限制信息
- */
- using System;
- using System.Web;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Threading.Tasks;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Http;
- using Microsoft.Extensions.Logging;
- using Microsoft.Extensions.Options;
- using MySystem.Models;
- using Library;
- using LitJson;
- using MySystemLib;
- using System.Text.RegularExpressions;
- using System.Security.Cryptography;
- using System.Text;
- namespace MySystem.Areas.Admin.Controllers
- {
- [Area("Admin")]
- [Route("Admin/[controller]/[action]")]
- public class SysToolsController : BaseController
- {
- public SysToolsController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
- {
- }
- #region 关联上下级
- public IActionResult RelationForUser(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public string RelationForUserDo(string MakerCode, string ParentMakerCode, int IsTeam = 1)
- {
- if (string.IsNullOrEmpty(MakerCode))
- {
- return "请输入创客编号";
- }
- if (string.IsNullOrEmpty(ParentMakerCode))
- {
- return "请输入上级创客编号";
- }
- MakerCode = MakerCode.ToUpper();
- ParentMakerCode = ParentMakerCode.ToUpper();
- Users puser = db.Users.FirstOrDefault(m => m.MakerCode == ParentMakerCode);
- if (puser != null)
- {
- Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
- if (user != null)
- {
- if (IsTeam == 1)
- {
- RelationForUserSub(user.Id, user);
- }
- user.ParentUserId = puser.Id;
- user.ParentNav = puser.ParentNav + "," + puser.Id + ",";
- db.SaveChanges();
- function.WriteLog(DateTime.Now.ToString() + ":下级:" + MakerCode + ", 上级:" + ParentMakerCode, "换线日志");
- return "success";
- }
- return "创客编号不存在";
- }
- return "上级创客编号不存在";
- }
- private void RelationForUserSub(int ParentUserId, Users puser)
- {
- var subusers = db.Users.Select(m => new { m.Id, m.ParentUserId, m.ParentNav }).Where(m => m.ParentUserId == ParentUserId).ToList();
- foreach (var subuser in subusers)
- {
- Users user = db.Users.FirstOrDefault(m => m.Id == subuser.Id);
- if (user != null)
- {
- user.ParentUserId = puser.Id;
- user.ParentNav = puser.ParentNav + "," + puser.Id + ",";
- db.SaveChanges();
- RelationForUserSub(user.Id, user);
- }
- }
- }
- #endregion
- #region 机具补录
- public IActionResult CheckMachine(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public string CheckMachineDo(string MakerCode, string PosSn, string MerNo = "", int AddActPrize = 0)
- {
- if (string.IsNullOrEmpty(MakerCode))
- {
- return "请输入创客编号";
- }
- if (string.IsNullOrEmpty(PosSn))
- {
- return "请输入机具SN";
- }
- PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
- if (pos == null)
- {
- return "机具SN不存在";
- }
- Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
- if (user == null)
- {
- return "创客编号不存在";
- }
- if (pos.BindingState == 0)
- {
- SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerSnNo == PosSn);
- if (bind != null)
- {
- pos.BindingState = 1;
- pos.BindingTime = bind.CreateTime;
- db.SaveChanges();
- MerNo = bind.MerNo;
- }
- }
- decimal CreditTrade = 0;
- bool check = spdb.TradeRecord.Any(m => m.TradeSnNo == pos.PosSn);
- if (check)
- {
- if (pos.BrandId == 1)
- {
- CreditTrade = spdb.TradeRecord.Where(m => m.TradeSnNo == pos.PosSn && m.ProductType == "1" && m.SerEntryMode != "N" && m.MerNo.StartsWith("M700")).Sum(m => m.TradeAmount) / 100;
- }
- else if (pos.BrandId == 2)
- {
- CreditTrade = spdb.TradeRecord.Where(m => m.TradeSnNo == pos.PosSn && m.ProductType == "2").Sum(m => m.TradeAmount);
- }
- else if (pos.BrandId == 3)
- {
- CreditTrade = spdb.TradeRecord.Where(m => m.TradeSnNo == pos.PosSn && m.ProductType == "1" && m.SerEntryMode != "N" && m.MerNo.StartsWith("M900")).Sum(m => m.TradeAmount) / 100;
- }
- else if (pos.BrandId == 4 || pos.BrandId == 5)
- {
- CreditTrade = spdb.TradeRecord.Where(m => m.TradeSnNo == pos.PosSn && m.ProductType == "4").Sum(m => m.TradeAmount) / 100;
- }
- else if (pos.BrandId == 6)
- {
- CreditTrade = spdb.TradeRecord.Where(m => m.TradeSnNo == pos.PosSn && m.ProductType == "6").Sum(m => m.TradeAmount) / 100;
- }
- else if (pos.BrandId == 7)
- {
- CreditTrade = spdb.TradeRecord.Where(m => m.TradeSnNo == pos.PosSn && m.ProductType == "7" && m.TradeStatus == "00").Sum(m => m.TradeAmount) / 100;
- }
- pos.CreditTrade = CreditTrade;
- db.SaveChanges();
- StatTradeAmount(pos.PosSn);
- }
- if (AddActPrize == 1)
- {
- if (pos.BuyUserId == 0)
- {
- return "机具未划拨,无法补录激活奖励";
- }
- if (string.IsNullOrEmpty(pos.SeoKeyword) || pos.SeoKeyword == "0")
- {
- bool has = spdb.ActivateRecord.Any(m => m.SnNo == pos.PosSn);
- if (has)
- {
- SpModels.ActivateRecord chkAct = spdb.ActivateRecord.Where(m => m.SnNo == pos.PosSn).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SpModels.ActivateRecord();
- pos.SeoKeyword = chkAct.SeoTitle;
- db.SaveChanges();
- }
- }
- if (pos.BindingTime != null && pos.ActivationTime != null)
- {
- TimeSpan ts = pos.ActivationTime.Value - pos.BindingTime.Value;
- if (ts.TotalDays <= 30)
- {
- AddAct(pos.Id);
- }
- }
- }
- decimal CheckMoney = 1000;
- if(pos.BrandId == 6)
- {
- CheckMoney = 5000;
- }
- if (pos.BuyUserId > 0)
- {
- if (pos.CreditTrade < CheckMoney)
- {
- return "该机具贷记卡累计交易不足" + CheckMoney;
- }
- if (pos.BindingTime != null && pos.ActivationTime != null)
- {
- TimeSpan ts = pos.ActivationTime.Value - pos.BindingTime.Value;
- if (ts.TotalDays > 30)
- {
- return "机具划拨后已超过30天";
- }
- }
- if (pos.CreditTrade >= CheckMoney && pos.ActivationState == 0)
- {
- pos.IsPurchase = 0;
- pos.ActivationState = 1;
- pos.ActivationTime = DateTime.Now;
- PosMerchantInfo mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
- if (pos.ActivationState == 1 && mer != null)
- {
- mer.ActiveStatus = 1;
- mer.MerStandardDate = DateTime.Now;
- RedisDbconn.Instance.Clear("PosMerchantInfo:" + mer.Id);
- }
- }
- else if (pos.CreditTrade >= CheckMoney && pos.ActivationState == 1)
- {
- if (AddActPrize == 1)
- {
- return "激活奖励已补录";
- }
- else
- {
- return "数据正常,无需补录";
- }
- }
- db.SaveChanges();
- RedisDbconn.Instance.Clear("PosMachinesTwo:" + pos.Id);
- return "success";
- }
- pos.UserId = user.Id;
- pos.BuyUserId = user.Id;
- if (pos.CreditTrade >= CheckMoney && pos.ActivationState == 0 && pos.BindingTime > DateTime.Now.AddDays(-30))
- {
- pos.IsPurchase = 0;
- pos.ActivationState = 1;
- pos.ActivationTime = DateTime.Now;
- }
- PosMerchantInfo merchant = new PosMerchantInfo();
- if (!string.IsNullOrEmpty(MerNo))
- {
- merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo);
- if (merchant == null)
- {
- int TopUserId = 0;
- if (!string.IsNullOrEmpty(user.ParentNav))
- {
- TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
- }
- SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerNo == MerNo);
- if (bind == null)
- {
- return "该机具尚未绑定";
- }
- SpModels.Merchants Mer = spdb.Merchants.FirstOrDefault(m => m.MerNo == MerNo);
- if (Mer == null)
- {
- return "该机具尚未绑定";
- }
- PosMerchantInfo add = db.PosMerchantInfo.Add(new PosMerchantInfo()
- {
- CreateDate = Mer.CreateTime,
- UpdateDate = Mer.UpdateTime,
- TopUserId = TopUserId,
- MerUserType = user.MerchantType,
- BrandId = int.Parse(Mer.ProductType),
- SnStoreId = pos.StoreId,
- SnType = pos.PosSnType,
- UserId = user.Id,
- 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,
- }).Entity;
- MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Mer.MerNo);
- if (forMerNo == null)
- {
- forMerNo = db.MachineForMerNo.Add(new MachineForMerNo()
- {
- MerNo = Mer.MerNo,
- SnId = pos.Id,
- }).Entity;
- }
- else
- {
- forMerNo.SnId = pos.Id;
- }
- }
- }
- else
- {
- if (pos.BindMerchantId > 0)
- {
- merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
- }
- else
- {
- return "找不到机具所属商户";
- }
- }
- merchant.UserId = user.Id;
- if (pos.ActivationState == 1)
- {
- merchant.ActiveStatus = 1;
- merchant.MerStandardDate = DateTime.Now;
- }
- if (pos.BindMerchantId == 0)
- {
- pos.BindMerchantId = merchant.Id;
- }
- db.SaveChanges();
- RedisDbconn.Instance.Clear("PosMerchantInfo:" + merchant.Id);
- RedisDbconn.Instance.Clear("PosMachinesTwo:" + pos.Id);
- return "success";
- }
- public IActionResult CheckMachine2(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public string CheckMachine2Do(string MakerCode, string PosSn, string MerNo = "", int AddActPrize = 0)
- {
- if (string.IsNullOrEmpty(MakerCode))
- {
- return "请输入创客编号";
- }
- if (string.IsNullOrEmpty(PosSn))
- {
- return "请输入机具SN";
- }
- PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
- if (pos == null)
- {
- return "机具SN不存在";
- }
- Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
- if (user == null)
- {
- return "创客编号不存在";
- }
- if (pos.BindingState == 0)
- {
- SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerSnNo == PosSn);
- if (bind != null)
- {
- pos.BindingState = 1;
- pos.BindingTime = bind.CreateTime;
- db.SaveChanges();
- MerNo = bind.MerNo;
- }
- }
- decimal CreditTrade = 0;
- bool check = spdb.TradeRecord.Any(m => m.TradeSnNo == pos.PosSn);
- if (check)
- {
- if (pos.BrandId == 1)
- {
- CreditTrade = spdb.TradeRecord.Where(m => m.TradeSnNo == pos.PosSn && m.ProductType == "1" && m.SerEntryMode != "N" && m.MerNo.StartsWith("M700")).Sum(m => m.TradeAmount) / 100;
- }
- else if (pos.BrandId == 2)
- {
- CreditTrade = spdb.TradeRecord.Where(m => m.TradeSnNo == pos.PosSn && m.ProductType == "2").Sum(m => m.TradeAmount);
- }
- else if (pos.BrandId == 3)
- {
- CreditTrade = spdb.TradeRecord.Where(m => m.TradeSnNo == pos.PosSn && m.ProductType == "1" && m.SerEntryMode != "N" && m.MerNo.StartsWith("M900")).Sum(m => m.TradeAmount) / 100;
- }
- else if (pos.BrandId == 4 || pos.BrandId == 5)
- {
- CreditTrade = spdb.TradeRecord.Where(m => m.TradeSnNo == pos.PosSn && m.ProductType == "4").Sum(m => m.TradeAmount) / 100;
- }
- else if (pos.BrandId == 6)
- {
- CreditTrade = spdb.TradeRecord.Where(m => m.TradeSnNo == pos.PosSn && m.ProductType == "6").Sum(m => m.TradeAmount) / 100;
- }
- pos.CreditTrade = CreditTrade;
- db.SaveChanges();
- StatTradeAmount(pos.PosSn);
- }
- if (AddActPrize == 1)
- {
- if (string.IsNullOrEmpty(pos.SeoKeyword) || pos.SeoKeyword == "0")
- {
- bool has = spdb.ActivateRecord.Any(m => m.SnNo == pos.PosSn);
- if (has)
- {
- SpModels.ActivateRecord chkAct = spdb.ActivateRecord.Where(m => m.SnNo == pos.PosSn).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SpModels.ActivateRecord();
- pos.SeoKeyword = chkAct.SeoTitle;
- db.SaveChanges();
- }
- }
- AddAct(pos.Id);
- }
- if (pos.BuyUserId > 0)
- {
- if (pos.CreditTrade < 1000)
- {
- pos.IsPurchase = 99;
- db.SaveChanges();
- return "该机具贷记卡累计交易不足1000";
- }
- if (pos.CreditTrade >= 1000 && pos.ActivationState == 0)
- {
- pos.IsPurchase = 0;
- pos.ActivationState = 1;
- pos.ActivationTime = DateTime.Now;
- PosMerchantInfo mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
- if (pos.ActivationState == 1 && mer != null)
- {
- mer.ActiveStatus = 1;
- mer.MerStandardDate = DateTime.Now;
- RedisDbconn.Instance.Clear("PosMerchantInfo:" + mer.Id);
- }
- }
- else if (pos.CreditTrade >= 1000 && pos.ActivationState == 1)
- {
- if (AddActPrize == 1)
- {
- return "激活奖励已补录";
- }
- else
- {
- return "数据正常,无需补录";
- }
- }
- db.SaveChanges();
- RedisDbconn.Instance.Clear("PosMachinesTwo:" + pos.Id);
- return "success";
- }
- pos.UserId = user.Id;
- pos.BuyUserId = user.Id;
- if (pos.CreditTrade < 1000)
- {
- pos.IsPurchase = 99;
- }
- else if (pos.CreditTrade >= 1000 && pos.ActivationState == 0)
- {
- pos.IsPurchase = 0;
- pos.ActivationState = 1;
- pos.ActivationTime = DateTime.Now;
- }
- PosMerchantInfo merchant = new PosMerchantInfo();
- if (!string.IsNullOrEmpty(MerNo))
- {
- merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo);
- if (merchant == null)
- {
- int TopUserId = 0;
- if (!string.IsNullOrEmpty(user.ParentNav))
- {
- TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
- }
- SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerNo == MerNo);
- if (bind == null)
- {
- return "该机具尚未绑定";
- }
- SpModels.Merchants Mer = spdb.Merchants.FirstOrDefault(m => m.MerNo == MerNo);
- if (Mer == null)
- {
- return "该机具尚未绑定";
- }
- PosMerchantInfo add = db.PosMerchantInfo.Add(new PosMerchantInfo()
- {
- CreateDate = Mer.CreateTime,
- UpdateDate = Mer.UpdateTime,
- TopUserId = TopUserId,
- MerUserType = user.MerchantType,
- BrandId = int.Parse(Mer.ProductType),
- SnStoreId = pos.StoreId,
- SnType = pos.PosSnType,
- UserId = user.Id,
- 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,
- }).Entity;
- MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Mer.MerNo);
- if (forMerNo == null)
- {
- forMerNo = db.MachineForMerNo.Add(new MachineForMerNo()
- {
- MerNo = Mer.MerNo,
- SnId = pos.Id,
- }).Entity;
- }
- else
- {
- forMerNo.SnId = pos.Id;
- }
- }
- }
- else
- {
- if (pos.BindMerchantId > 0)
- {
- merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
- }
- else
- {
- return "找不到机具所属商户";
- }
- }
- merchant.UserId = user.Id;
- if (pos.ActivationState == 1)
- {
- merchant.ActiveStatus = 1;
- merchant.MerStandardDate = DateTime.Now;
- }
- if (pos.BindMerchantId == 0)
- {
- pos.BindMerchantId = merchant.Id;
- }
- db.SaveChanges();
- RedisDbconn.Instance.Clear("PosMerchantInfo:" + merchant.Id);
- RedisDbconn.Instance.Clear("PosMachinesTwo:" + pos.Id);
- return "success";
- }
- public void AddAct(int posid = 0)
- {
- WebCMSEntities db = new WebCMSEntities();
- PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.ActivationState == 1 && !string.IsNullOrEmpty(m.SeoKeyword) && m.Id == posid);
- if (pos != null)
- {
- // PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId && !string.IsNullOrEmpty(m.MerIdcardNo));
- PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
- if (merchant != null)
- {
- // PosMerchantOtherInfo otherInfo = db.PosMerchantOtherInfo.FirstOrDefault(m => m.CertId == merchant.MerIdcardNo && m.PrizeFlag1 == 0);
- // if (otherInfo != null)
- // {
- // otherInfo.PrizeFlag1 = 1;
- // db.SaveChanges();
- string ParentNav = "";
- Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId);
- if (user != null)
- {
- int GetUserId = user.Id;
- ParentNav = user.ParentNav;
- int TopUserId = 0;
- if (!string.IsNullOrEmpty(ParentNav))
- {
- TopUserId = int.Parse(ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
- }
- decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
- if (pos.BrandId == 1 || pos.BrandId == 3 || pos.BrandId == 4 || pos.BrandId == 5 || pos.BrandId == 6)
- {
- ActPrize = ActPrize / 100;
- }
- if (ActPrize > 0)
- {
- bool check = db.ActiveReward.Any(m => m.KqSnNo == pos.PosSn && m.RewardAmount != 40);
- if (!check)
- {
- if (ActPrize == 99)
- {
- ActPrize = 100;
- }
- else if (ActPrize == 199)
- {
- ActPrize = 200;
- }
- else if (ActPrize == 299)
- {
- ActPrize = 300;
- }
- else if (ActPrize == 249)
- {
- ActPrize = 260;
- }
- Users machineUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
- db.ActiveReward.Add(new ActiveReward()
- {
- CreateDate = DateTime.Now,
- UpdateDate = DateTime.Now,
- UserId = GetUserId, //创客
- MerchantId = pos.BindMerchantId, //商户
- StandardDate = pos.ActivationTime, //达标日期
- RewardAmount = ActPrize, //奖励金额
- BrandId = pos.BrandId, //品牌
- UserNav = ParentNav, //创客父级
- DirectBuddyNo = merchant.UserId, //商户直属创客
- KqMerNo = merchant.KqMerNo, //渠道商户编号
- KqSnNo = pos.PosSn, //渠道SN号
- SnType = pos.PosSnType, //机具类型
- SnApplyUserId = pos.BuyUserId, //机具申请创客
- ActType = 0, //激活类型
- SnStoreId = pos.StoreId, //SN仓库
- RewardTips = "激活奖励", //奖励描述
- Remark = "激活奖励", //备注
- ActDate = pos.ActivationTime, //激活时间
- TopUserId = TopUserId, //顶级创客
- SeoTitle = machineUser.RealName,
- });
- db.SaveChanges();
- string IdBrand = GetUserId + "_" + 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.ActProfit += ActPrize;
- db.SaveChanges();
- RedisDbconn.Instance.Set("UserMachineData:" + IdBrand, userData);
- 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 += ActPrize;
- account.TotalAmount += ActPrize;
- 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 = 0, //变动类型
- ProductType = pos.BrandId, //产品类型
- ChangeAmount = ActPrize, //变更金额
- BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
- AfterTotalAmount = AfterTotalAmount, //变更后总金额
- BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
- AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
- BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
- AfterBalanceAmount = AfterBalanceAmount, //变更后余额
- }).Entity;
- db.SaveChanges();
- RedisDbconn.Instance.Set("UserAccount:" + GetUserId, account);
- string dateString = pos.ActivationTime.Value.ToString("yyyyMMdd");
- string monthString = pos.ActivationTime.Value.ToString("yyyyMM");
- // 激活奖励列表
- List<string> dates = RedisDbconn.Instance.GetList<string>("ActiveRewardDay:" + GetUserId + ":" + pos.BrandId);
- if (!dates.Contains(dateString))
- {
- RedisDbconn.Instance.AddList("ActiveRewardDay:" + GetUserId + ":" + pos.BrandId, dateString);
- }
- RedisDbconn.Instance.AddNumber("ActiveRewardAmt:" + GetUserId + ":" + pos.BrandId + ":" + dateString, ActPrize);
- List<string> months = RedisDbconn.Instance.GetList<string>("ActiveRewardMonth:" + GetUserId + ":" + pos.BrandId);
- if (!months.Contains(monthString))
- {
- RedisDbconn.Instance.AddList("ActiveRewardMonth:" + GetUserId + ":" + pos.BrandId, monthString);
- }
- RedisDbconn.Instance.AddNumber("ActiveRewardAmt:" + GetUserId + ":" + pos.BrandId + ":" + monthString, ActPrize);
- // 激活奖励详情
- List<int> actPrizeList = RedisDbconn.Instance.GetList<int>("ActiveRewardDetail:" + GetUserId + ":" + pos.BrandId + ":" + dateString);
- if (!actPrizeList.Contains(pos.BindMerchantId))
- {
- RedisDbconn.Instance.AddList("ActiveRewardDetail:" + GetUserId + ":" + pos.BrandId + ":" + dateString, pos.BindMerchantId);
- }
- RedisDbconn.Instance.AddNumber("ActiveRewardAmt:mer:" + pos.BindMerchantId + ":" + pos.BrandId + ":" + dateString, ActPrize);
- //收支明细
- RedisDbconn.Instance.AddList("UserAccountRecord:" + GetUserId + ":1:" + monthString, userAccountRecord);
- RedisDbconn.Instance.AddNumber("UserAccount:" + GetUserId + ":1:" + monthString, ActPrize);
- }
- }
- }
- // }
- }
- }
- db.Dispose();
- }
- //重置交易额
- public void StatTradeAmount(string PosSn)
- {
- DateTime start = DateTime.Parse(DateTime.Now.ToString("yyyy-MM") + "-01 00:00:00");
- if (DateTime.Now.Day == 1)
- {
- start = DateTime.Parse(DateTime.Now.AddMonths(-1).ToString("yyyy-MM") + "-01 00:00:00");
- }
- DateTime end = DateTime.Now;
- SycnSpTradeService.Instance.Start(PosSn, start, end);
- RedisDbconn.Instance.AddList("ResetTradeAmountList", PosSn);
- }
- #endregion
- #region 设置商户代理
- public IActionResult SetMerAgent(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public string SetMerAgentDo(string MakerCode, string PosSn, string MerNo)
- {
- if (string.IsNullOrEmpty(MakerCode))
- {
- return "请输入创客编号";
- }
- if (string.IsNullOrEmpty(PosSn))
- {
- return "请输入机具SN";
- }
- if (string.IsNullOrEmpty(MerNo))
- {
- return "请输入商户编号";
- }
- PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
- if (pos == null)
- {
- return "机具SN不存在";
- }
- Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
- if (user == null)
- {
- return "创客编号不存在";
- }
- PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo);
- if (merchant == null)
- {
- return "商户编号不存在";
- }
- pos.SeoTitle = user.Id.ToString();
- if (pos.BindMerchantId == 0)
- {
- pos.BindMerchantId = merchant.Id;
- }
- user.MerchantType = 1;
- merchant.UserId = user.Id;
- merchant.MerUserType = 1;
- db.SaveChanges();
- return "success";
- }
- #endregion
- #region 查看SP原始数据日志
- public IActionResult SeeSpLog(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- #endregion
- #region 查询机具信息
- public IActionResult SeeSnDetail(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public string SeeSnDetailDo(string PosSn)
- {
- if (string.IsNullOrEmpty(PosSn))
- {
- return "请输入机具SN";
- }
- PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
- if (pos == null)
- {
- return "机具SN不存在";
- }
- if (pos.Status == -1)
- {
- return "该机具为故障机";
- }
- string merInfo = "";
- PosMerchantInfo mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
- if (mer != null)
- {
- merInfo = mer.KqMerNo;
- }
- else
- {
- merInfo = "未找到商户";
- }
- StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == pos.StoreId) ?? new StoreHouse();
- Users posUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
- Users posSubUser = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new Users();
- int TopUserId = 0;
- if (!string.IsNullOrEmpty(posUser.ParentNav))
- {
- string[] ParentNavs = posUser.ParentNav.Trim(',').Replace(",,", ",").Split(',');
- if (ParentNavs.Length > 1)
- {
- TopUserId = int.Parse(ParentNavs[1]);
- }
- if (ParentNavs.Length == 1)
- {
- TopUserId = int.Parse(ParentNavs[0]);
- }
- }
- Users posTopUser = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
- string bindResult = "", bindTime = "";
- if (pos.BindingState == 0)
- {
- SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerSnNo == pos.PosSn);
- if (bind != null)
- {
- if (bind.Status != 1)
- {
- bindResult = "执行中";
- }
- }
- else
- {
- bindResult = "未绑定";
- }
- }
- else
- {
- bindResult = "已绑定";
- bindTime = pos.BindingTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
- }
- string activeResult = "", activeTime = "";
- if (pos.ActivationState == 0)
- {
- if (pos.CreditTrade < 1000)
- {
- activeResult = "未刷满1000";
- }
- else if (pos.TransferTime == null)
- {
- activeResult = "未激活, 需补录";
- }
- }
- else
- {
- activeResult = "已激活";
- activeTime = pos.ActivationTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
- }
- string tradeAmount = pos.CreditTrade.ToString();
- decimal Deposit = decimal.Parse(function.CheckNum(pos.SeoKeyword));
- if (pos.BrandId != 2 && pos.BrandId != 7)
- {
- Deposit = Deposit / 100;
- }
- string DepositGet = "未领取";
- string DepositUser = "";
- string DepositToUser = "";
- ActiveReward reward = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.RewardAmount != 40) ?? new ActiveReward();
- if (reward.Id > 0)
- {
- Users user = db.Users.FirstOrDefault(m => m.Id == reward.UserId) ?? new Users();
- DepositGet = "已领取";
- DepositUser = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
- }
- string DepositGet6 = "未领取";
- string DepositUser6 = "";
- ActiveReward lisreward = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.BrandId == 6 && m.RewardAmount == 40) ?? new ActiveReward();
- if (lisreward.Id > 0)
- {
- Users user = db.Users.FirstOrDefault(m => m.Id == lisreward.UserId) ?? new Users();
- DepositGet6 = "已领取";
- DepositUser6 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
- }
- string FluxGet6 = "未领取";
- string FluxUser6 = "";
- FluxProfitDetail flux = db.FluxProfitDetail.FirstOrDefault(m => m.SnNo == pos.PosSn && m.BrandId == 6) ?? 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;
- }
- Users touser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
- DepositToUser = "创客编号:" + touser.MakerCode + ",姓名:" + touser.RealName + ",手机号:" + touser.Mobile;
- string OpenUser10 = "未领取";
- string OpenUser20 = "未领取";
- var OpenRewardDetail = db.OpenRewardDetail.Where(m => m.SnNo == pos.PosSn).ToList();
- OpenRewardDetail openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 20) ?? new OpenRewardDetail();
- if (openreward.Id > 0)
- {
- Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
- OpenUser20 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
- }
- openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 10) ?? new OpenRewardDetail();
- if (openreward.Id > 0)
- {
- Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
- OpenUser10 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
- }
- MachineApply apply = db.MachineApply.FirstOrDefault(m => m.SwapSnExpand.Contains(pos.PosSn)) ?? new MachineApply();
- Orders applyorder = db.Orders.FirstOrDefault(m => m.Id == apply.QueryCount) ?? new Orders();
- MachineChangeDetail change = db.MachineChangeDetail.FirstOrDefault(m => m.OutSnNo == pos.PosSn) ?? new MachineChangeDetail();
- string RecycFlag = pos.IsPurchase == 1 ? "已申请循环" : "未申请循环";
- string SendStatus = applyorder.SendStatus == 1 ? "已发货" : "未发货";
- string ApplyDate = apply.CreateDate == null ? "" : apply.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
- string SendDate = applyorder.SendDate == null ? "" : applyorder.SendDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
- string TransferTime = pos.TransferTime == null ? "" : pos.TransferTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
- string ActiveTime = reward.CreateDate == null ? "" : reward.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
- string ActiveTime6 = lisreward.CreateDate == null ? "" : lisreward.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
- string result = "";
- result += "机具SN:" + pos.PosSn + "\n";
- result += "商户编号:" + merInfo + "\n";
- result += "商户型机器/直拓机器:创客编号:" + posSubUser.MakerCode + ",姓名:" + posSubUser.RealName + ",手机号:" + posSubUser.Mobile + "\n";
- if (change.Id > 0)
- {
- result += "换机来源机具SN:" + change.BackSnNo + "\n";
- }
- result += "机具所属人:创客编号:" + posUser.MakerCode + ",姓名:" + posUser.RealName + ",手机号:" + posUser.Mobile + "\n";
- result += "机器持有人顶级:创客编号:" + posTopUser.MakerCode + ",姓名:" + posTopUser.RealName + ",手机号:" + posTopUser.Mobile + "\n";
- result += "机器所属仓库:仓库编号:" + store.StoreNo + ",仓库名称:" + store.StoreName + "\n";
- result += "划拨时间:" + TransferTime + "\n";
- result += "绑定状态:" + bindResult + "(绑定时间:" + bindTime + ")\n";
- result += "激活状态:" + activeResult + "(激活时间:" + activeTime + ")\n";
- result += "贷记卡(总)交易额:" + tradeAmount + "\n";
- result += "是否循环:" + RecycFlag + ",申请循环时间:" + ApplyDate + "\n";
- result += "申请循环后的SN:" + applyorder.SnNos + "\n";
- result += "是否发货:" + SendStatus + ",发货时间:" + SendDate + "\n";
- result += "押金:" + Deposit + "\n";
- result += "是否返现:" + DepositGet + ",领取时间:" + ActiveTime + "\n";
- result += "押金返现应返现对象:" + DepositToUser + "\n";
- result += "押金返现实际返现对象:" + DepositUser + "\n";
- if (pos.BrandId == 6)
- {
- result += "立刷10000奖励:" + DepositGet6 + ",领取时间:" + ActiveTime6 + "\n";
- result += "立刷10000奖励发放人:" + DepositUser6 + "\n";
- }
- result += "流量费:" + FluxGet6 + "\n";
- result += "流量费发放对象:" + FluxUser6 + "\n";
- result += "开机奖20:" + OpenUser20 + "\n";
- result += "开机奖10:" + OpenUser10 + "\n";
- return result;
- }
- //解析金控日志
- // public decimal CheckLog(DateTime startDate, string PosSn)
- // {
- // bool op = true;
- // decimal result = 0;
- // DateTime today = DateTime.Now;
- // int i = 0;
- // while (op)
- // {
- // DateTime check = DateTime.Parse(startDate.ToString("yyyy-MM-dd") + " 00:00:00").AddDays(i);
- // if (check <= today)
- // {
- // string source = function.GetWebRequest("http://sp.kexiaoshuang.com/api/test/GetLog?date=" + check.Year + "-" + check.Month + "-" + check.Day);
- // MatchCollection mc = Regex.Matches(source, "{.*?2022年飞天系列-小宝电签.*?}"); //激活
- // foreach (Match sub in mc)
- // {
- // string content = sub.Value;
- // JsonData jsonObj = JsonMapper.ToObject(content);
- // decimal serviceAmount = decimal.Parse(jsonObj["serviceAmount"].ToString());
- // string posSnCheck = jsonObj["posSn"].ToString();
- // if (posSnCheck == PosSn && serviceAmount > 0)
- // {
- // result = serviceAmount / 100;
- // op = false;
- // }
- // }
- // }
- // else
- // {
- // op = false;
- // }
- // i += 1;
- // }
- // return result;
- // }
- #endregion
- #region 生成机具兑换码
- public IActionResult MakeCoupons(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public string MakeCouponsDo(int Kind, int Number)
- {
- DateTime checkTime = DateTime.Parse("1900-01-01");
- string checkTimeString = RedisDbconn.Instance.Get<string>("MakerCouponsQueueCheckTime");
- if (!string.IsNullOrEmpty(checkTimeString))
- {
- checkTime = DateTime.Parse(checkTimeString);
- }
- if (checkTime.AddHours(1) < DateTime.Now)
- {
- RedisDbconn.Instance.Set("MakerCouponsQueueCheckTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
- RedisDbconn.Instance.AddList("MakerCouponsQueue:" + Kind, Number);
- return "生成程序已执行";
- }
- return "请稍后再试";
- }
- #endregion
- #region 导出没有刷满1000的机具
- public IActionResult ExportPos(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public JsonResult ExportPosDo()
- {
- WebCMSEntities db = new WebCMSEntities();
- List<PosMachinesTwo> poses = db.PosMachinesTwo.Where(m => m.CreditTrade < 1000 && m.BindingState == 1).ToList();
- int total = poses.Count;
- int index = 0;
- List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
- foreach (PosMachinesTwo pos in poses)
- {
- index += 1;
- PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
- Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? 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, object> item = new Dictionary<string, object>();
- 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);
- RedisDbconn.Instance.Set("ExportPosCheck", index + " / " + total);
- }
- db.Dispose();
- Dictionary<string, object> result = new Dictionary<string, object>();
- result.Add("Status", "1");
- result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
- result.Add("Obj", list);
- Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
- ReturnFields.Add("TopRealName", "顶级姓名"); //顶级姓名
- ReturnFields.Add("TopMakerCode", "顶级编号"); //顶级编号
- ReturnFields.Add("UpUpRealName", "上上级姓名"); //上上级姓名
- ReturnFields.Add("UpRealName", "上级姓名"); //上级姓名
- ReturnFields.Add("RealName", "代理姓名"); //代理姓名
- ReturnFields.Add("MakerCode", "代理编号"); //代理编号
- ReturnFields.Add("Mobile", "代理手机号"); //代理手机号
- ReturnFields.Add("MerchantName", "客户姓名"); //客户姓名
- ReturnFields.Add("MerchantMobile", "客户电话"); //客户电话
- ReturnFields.Add("OpenTime", "开机日期"); //开机日期
- ReturnFields.Add("Sn", "SN"); //SN
- result.Add("Fields", ReturnFields);
- RedisDbconn.Instance.Set("ExportPosCheck", "finish");
- return Json(result);
- }
- public string ExportPosCheck()
- {
- string content = RedisDbconn.Instance.Get<string>("ExportPosCheck");
- if (content == "finish")
- {
- RedisDbconn.Instance.Clear("ExportPosCheck");
- }
- return content;
- }
- #endregion
- #region 更换机具
- public IActionResult ChangePos(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public string ChangePosDo(string OldSn, string NewSn, string BackStoreNo, string OutStoreNo, string MerNo = "")
- {
- if (string.IsNullOrEmpty(OldSn))
- {
- return "请输入原机具SN";
- }
- if (string.IsNullOrEmpty(NewSn))
- {
- return "请输入新机具SN";
- }
- string[] OldSnList = OldSn.Split('\n');
- string[] NewSnList = NewSn.Split('\n');
- if (OldSnList.Length != NewSnList.Length)
- {
- return "原机具SN数量和新机具SN数量不一致";
- }
- WebCMSEntities db = new WebCMSEntities();
- StoreForCode storeForBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
- StoreForCode storeForOut = db.StoreForCode.FirstOrDefault(m => m.Code == OutStoreNo) ?? new StoreForCode();
- StoreHouse BackStore = db.StoreHouse.FirstOrDefault(m => m.Id == storeForBack.StoreId) ?? new StoreHouse();
- StoreHouse OutStore = db.StoreHouse.FirstOrDefault(m => m.Id == storeForOut.StoreId) ?? new StoreHouse();
- string ChangeNo = "BMC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(3);
- MachineChange add = db.MachineChange.Add(new MachineChange()
- {
- CreateDate = DateTime.Now,
- UpdateDate = DateTime.Now,
- ChangeNo = ChangeNo, //转换单号
- UserId = 0, //创客
- ChangeTime = DateTime.Now, //转换时间
- BackStoreId = BackStore.Id, //退回仓库
- BackStoreName = BackStore.StoreName, //退回仓库名称
- Remark = "机具更换", //订单备注
- BackStoreUserId = BackStore.UserId, //退回仓库归属人
- OutProductType = int.Parse(OutStore.BrandId), //出库产品类型
- OutProductName = OutStore.ProductName, //出库产品名称
- OutStoreId = OutStore.Id, //出库仓库
- OutStoreName = OutStore.StoreName, //出库仓库名称
- OutStoreAreas = OutStore.Areas, //出库仓库所在地区
- OutStoreAddress = OutStore.Address, //出库仓库地址
- OutStoreManager = "", //出库仓库联系人
- OutStoreManagerMobile = OutStore.ManageMobile, //出库仓库联系人手机号
- }).Entity;
- db.SaveChanges();
- int BackProductType = 0;
- string BackProductName = "";
- string ChangeDeviceName = "";
- string ChangeSnExpand = "";
- for (int i = 0; i < OldSnList.Length; i++)
- {
- string OldSnNum = OldSnList[i];
- string NewSnNum = NewSnList[i];
- MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
- MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
- PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId);
- if (oldpos == null)
- {
- return "原机具SN不正确";
- }
- // if (oldpos.BindingState != 1)
- // {
- // return "原机具未绑定";
- // }
- PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId);
- if (oldpos == null)
- {
- return "新机具SN不正确";
- }
- KqProducts oldPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
- KqProducts newPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == newpos.BrandId) ?? new KqProducts();
- PosMerchantInfo merchant = new PosMerchantInfo();
- if (!string.IsNullOrEmpty(MerNo))
- {
- merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo) ?? new PosMerchantInfo();
- }
- else
- {
- merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == oldpos.BindMerchantId) ?? new PosMerchantInfo();
- }
- newpos.BindMerchantId = merchant.Id;
- newpos.BuyUserId = oldpos.BuyUserId;
- newpos.UserId = oldpos.UserId;
- newpos.RecycEndDate = oldpos.RecycEndDate;
- newpos.ScanQrTrade = oldpos.ScanQrTrade;
- newpos.DebitCardTrade = oldpos.DebitCardTrade;
- newpos.CreditTrade = oldpos.CreditTrade;
- newpos.PosSnType = oldpos.PosSnType;
- newpos.TransferTime = oldpos.TransferTime;
- newpos.IsPurchase = oldpos.IsPurchase;
- newpos.BindingState = oldpos.BindingState;
- newpos.ActivationState = oldpos.ActivationState;
- newpos.BindingTime = oldpos.BindingTime;
- newpos.ActivationTime = oldpos.ActivationTime;
- // bool checkActReward = db.ActiveReward.Any(m => m.KqMerNo == merchant.KqMerNo);
- // if (!checkActReward)
- // {
- newpos.SeoKeyword = oldpos.SeoKeyword;
- newpos.PrizeParams = oldpos.PrizeParams;
- newpos.LeaderUserId= oldpos.LeaderUserId;
- // }
- // oldpos.BuyUserId = 0;
- // oldpos.UserId = 0;
- oldpos.Status = -1;
- MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == merchant.KqMerNo);
- if (forMerNo != null)
- {
- forMerNo.SnId = newpos.Id;
- }
- merchant.KqSnNo = NewSn;
- db.MachineChangeDetail.Add(new MachineChangeDetail()
- {
- CreateDate = DateTime.Now,
- UpdateDate = DateTime.Now,
- ChangeNo = ChangeNo, //订单号
- ChangeId = add.Id, //订单Id
- BackProductType = oldpos.BrandId, //退回产品类型
- BackProductName = oldPosBrand.Name, //退回产品名称
- UserId = 0, //创客
- BackSnNo = oldpos.PosSn, //设备SN编号
- OutProductType = newpos.BrandId, //出库产品类型
- OutProductName = newPosBrand.Name, //出库产品名称
- OutSnNo = newpos.PosSn, //出库设备SN编号
- OutSnType = newpos.PosSnType, //出库SN机具类型
- Remark = "机具更换", //备注
- BackSnType = oldpos.PosSnType, //退回SN机具类型
- });
- db.SaveChanges();
- BackProductType = oldpos.BrandId;
- BackProductName = newPosBrand.Name;
- ChangeDeviceName = oldpos.DeviceName;
- ChangeSnExpand += oldpos.PosSn + "\n";
- PublicFunction.SycnMachineCount(oldpos.BuyUserId, oldpos.BrandId);
- }
- add.BackProductType = BackProductType; //退回产品类型
- add.BackProductName = BackProductName; //退回产品名称
- add.ChangeDeviceName = ChangeDeviceName; //转换机具名称
- add.ChangeDeviceNum = OldSnList.Length; //转换机具数量
- add.ChangeSnExpand = ChangeSnExpand; //机具SN
- db.SaveChanges();
- db.Dispose();
- return "success";
- }
- #endregion
- #region 机具解绑
- public IActionResult Unbind(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public string UnbindDo(string PosSn, string MakerCode, string MerNo)
- {
- if (string.IsNullOrEmpty(PosSn))
- {
- return "请输入机具SN";
- }
- if (string.IsNullOrEmpty(MakerCode))
- {
- return "请输入创客编号";
- }
- if (string.IsNullOrEmpty(MerNo))
- {
- return "请输入商户编号";
- }
- MachineForSnNo forSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn);
- if (forSnNo == null)
- {
- return "机具SN不存在";
- }
- UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
- if (forMakerCode == null)
- {
- return "创客不存在";
- }
- MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == MerNo);
- if (forMerNo == null)
- {
- return "商户编号不存在";
- }
- PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == forSnNo.SnId && m.Id == forMerNo.SnId);
- if (pos == null)
- {
- return "机具SN不存在";
- }
- if (pos.BuyUserId != forMakerCode.UserId)
- {
- return "机具SN和创客不匹配";
- }
- if (pos.ActivationState == 1)
- {
- return "机具已激活,不能解绑";
- }
- if (pos.BuyUserId == 0)
- {
- return "机具是仓库机,不支持解绑";
- }
- if (pos.BindingState == 0)
- {
- return "机具未绑定,不支持解绑";
- }
- if (pos.BindingTime < DateTime.Now.AddDays(-30))
- {
- return "机具绑定已超过30天,不支持解绑";
- }
- if (forMerNo != null)
- {
- db.MachineForMerNo.Remove(forMerNo);
- db.SaveChanges();
- }
- db.MachineUnBind.Add(new MachineUnBind()
- {
- CreateDate = DateTime.Now,
- SeoTitle = SysUserName + "-" + SysRealName,
- MerchantId = pos.BindMerchantId,
- AuditDate = DateTime.Now,
- AuditDesc = "平台操作解绑",
- AuditStatus = 1,
- SnNo = pos.PosSn,
- BrandId = pos.BrandId,
- UserId = pos.BuyUserId,
- ApplyNo = "U" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8),
- });
- pos.BindMerchantId = 0;
- pos.BindingState = 0;
- pos.BindingTime = DateTime.Parse("1900-01-01");
- pos.UserId = pos.BuyUserId;
- string IdBrand = pos.BuyUserId + "_" + pos.BrandId;
- db.SaveChanges();
- PublicFunction.SycnMachineCount(pos.BuyUserId, pos.BrandId);
- return "success";
- }
- #endregion
- #region 查询创客直推奖
- public IActionResult Prize100(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public Dictionary<string, string> Prize100Do(string MakerCode)
- {
- Dictionary<string, string> dic = new Dictionary<string, string>();
- string result = "";
- UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
- if (forMakerCode == null)
- {
- result += "创客编号不存在\n";
- dic.Add("code", "1");
- dic.Add("result", result);
- return dic;
- }
- int OrderCount = db.Orders.Count(m => m.UserId == forMakerCode.UserId && m.PayStatus == 1 && m.TotalPrice == 600);
- if (OrderCount == 0)
- {
- result += "该创客未下单\n";
- dic.Add("code", "1");
- dic.Add("result", result);
- return dic;
- }
- if (OrderCount > 1)
- {
- result += "该创客已不是首笔下单\n";
- dic.Add("code", "1");
- dic.Add("result", result);
- return dic;
- }
- Orders order = db.Orders.FirstOrDefault(m => m.UserId == forMakerCode.UserId && m.PayStatus == 1 && m.TotalPrice == 600) ?? new Orders();
- if (order.PayStatus < 1)
- {
- result += "未付款\n";
- dic.Add("code", "1");
- dic.Add("result", result);
- return dic;
- }
- Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId) ?? new Users();
- Users puser = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId) ?? new Users();
- result += "订单号:" + order.OrderNo + "\n";
- result += "下单创客\n创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile + "\n";
- result += "上级创客\n创客编号:" + puser.MakerCode + ",姓名:" + puser.RealName + ",手机号:" + puser.Mobile + "\n";
- int machineCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.PosSnType == 0); //判断是否拥有3台购买机
- int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
- if (machineCount + ActiveCount >= 3)
- {
- string IsGet = "未发放";
- int ToUserId = 0;
- UserAccountRecord item = db.UserAccountRecord.FirstOrDefault(m => m.QueryCount == order.Id);
- if (item == null)
- {
- DateTime start = order.PayDate.Value.AddMinutes(-2);
- DateTime end = order.PayDate.Value.AddMinutes(2);
- item = db.UserAccountRecord.FirstOrDefault(m => m.UserId == puser.Id && m.ChangeType == 112 && m.ChangeAmount == 100 && m.CreateDate >= start && m.CreateDate <= end);
- }
- if (item != null)
- {
- IsGet = "已发放(发放时间:" + item.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
- ToUserId = item.UserId;
- dic.Add("code", "1");
- }
- else
- {
- dic.Add("id", order.Id.ToString());
- dic.Add("code", "0");
- }
- Users touser = db.Users.FirstOrDefault(m => m.Id == ToUserId) ?? new Users();
- result += "是否发放:" + IsGet + "\n";
- result += "应该发放对象\n创客编号:" + puser.MakerCode + ",姓名:" + puser.RealName + ",手机号:" + puser.Mobile + "\n";
- result += "实际发放对象\n创客编号:" + touser.MakerCode + ",姓名:" + touser.RealName + ",手机号:" + touser.Mobile + "\n";
- }
- else
- {
- result += "上级创客未满足条件\n购买机:" + machineCount + "台,激活机:" + ActiveCount + "台\n";
- dic.Add("code", "1");
- }
- dic.Add("result", result);
- return dic;
- }
- public string AddPrize100(int Id)
- {
- Orders order = db.Orders.FirstOrDefault(m => m.Id == Id);
- if (order != null)
- {
- //机具券逻辑
- OrderProduct pro = db.OrderProduct.FirstOrDefault(m => m.OrderId == Id);
- if (pro != null)
- {
- //推荐下单奖励
- if (pro.ProductId == 10 || pro.ProductId == 11)
- {
- Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId);
- if (user != null)
- {
- int ParentUserId = user.ParentUserId;
- 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, //变更后余额
- QueryCount = order.Id,
- }).Entity;
- db.SaveChanges();
- RedisDbconn.Instance.Set("UserAccount:" + ParentUserId, account);
- //推荐下单上级获得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();
- return "success";
- }
- else
- {
- return "上级创客未满足条件:购买机:" + machineCount + "台,激活机:" + ActiveCount + "台";
- }
- }
- }
- }
- }
- return "操作失败";
- }
- #endregion
- #region 设置立刷费率
- public IActionResult LisFee(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public string LisFeeDo(string PosSns, decimal Fee, string Kind, string Fix)
- {
- if (string.IsNullOrEmpty(PosSns))
- {
- return "请输入机具号";
- }
- string result = SysUserName + "设置\n";
- string[] PosSnList = PosSns.Split('\n');
- int total = PosSnList.Length;
- int index = 0;
- foreach (string SubPosSn in PosSnList)
- {
- index += 1;
- string PosSn = SubPosSn.Replace("\r", "");
- result += PosSn + ":" + Fee + "\n";
- if (Kind == "M5")
- {
- result += SetLiSFee(PosSn, Fee) + "\n";
- }
- else if (Kind == "N1")
- {
- result += SetLiSDeposit(PosSn, (int)Fee);
- }
- RedisDbconn.Instance.Set("LisFeeProcess:" + SysId, index + " / " + total);
- }
- result += "\n\n";
- function.WriteLog(result, "设置立刷费率");
- return result;
- }
- public string LisFeeProcess()
- {
- return RedisDbconn.Instance.Get<string>("LisFeeProcess:" + SysId);
- }
- #region 立刷
- string LiSAgentId = "50814834";
- string LiSPrivateKey = "MIIJQwIBADANBgkqhkiG9w0BAQEFAASCCS0wggkpAgEAAoICAQDTdeLXqQmfVJM/ATVnq+TdhgpKKPp3hXcuY2s9qrN1Uws7I7jqnq/gfoBHBWBu/PnQp/z65okBoz4PEpWzJYZDF4csgh3E45He46ialNzUlOPWv6yLzgQPHuneq2pXOb7dbN4kZx+g3nEbBjH+/P9xp+lU3HCwjNxIFSr3EyBAQf2HgvNqh70u9T13fGVx3Jtd2xbIKYhvGNPH9ZCGiZNiCy+m+F+TKywgKK/xify1KQgR6otVUOVIGYvPYlXAgLJM2/V54166KX1UUFMsKRj4Kt2j4GqoHzDfRk9ibYJ/8iSDGX4+WH5+8mq/raqA77VcAD+bMrt3Bm59XmaWtjZwDY1zh5sP5jEaxu4lde2xZD80kQ6p1ZydpqnjmWm6NKXSz8j85gRkTQqNALKNANnJb6f1Yy30WirnrhMkqU2dqBzzXxtk3k/2zv9BENjYs1igrRYpwX3QRx87aTOrIk/PO6cxMaWl249LPigah0OqVyIg5yOvtnUCdU12OqaVELIw5GnZ7rTRn3tAsJ+u1om+3XktbN3GUEpw5RWAT3UAsAU7Vxt9xPCss+JXF+ogXYgo9QpEjanXOfLo5KPv2CkBuzy87d85OId71gXpYcbp0zbKz5eXKZanVP9pwn43jqiPkqtam8N1TLCCmZ4t2cd+gpW2CX/+W7bmc25HJtRPuwIDAQABAoICAE7B9GfwTGYsYN8xewuOySH8n255jrffXMFJRBLmtgo3kNJI/sFbsxPA6dQJ253a2MxvFNj57gNPInkIqfrcOgJZC/52w9GmFJlYX16bnRgMEEPWhdRYOcjL8bz+SRANsNnVh3M1eWE4GBZBm3NmFVnmeRAjPlFzVUP/pk35sKReL6g+DJ0by0lnC6qqCTp8ON2fEQAh/++o5o/uFRMWwG7ezbO5hBdTGA8uOEGU7CspChlqKtTu2UaeRSVLcbbN+BqKPgZUud5KP6Scei3TbLpZdM1pczAE1fYCwORe9yDiNdkiMJPV798mOL4FV6DIJtsKOKZ8Ibg2DAbjlwABA4rQsgBUAA4Nj+skqLE7gGnJViHzKw87zve+v3CV9NEldHV7g2a78yKye489vlmmxcLj+Ln5O/Y3OQnDwsO8mVua5Ddyp26N88oB1wW62VLUn68ePclDd3Bdub/ayiBqFOqA0cTlqI5Dvz0rqrK9dkq4Ij295EK3OfYHCjuoHN+mJP0K0+o+5ItPXu7KWRz/Bf+KPneAAgvTRaDMww+HpfbcM6sxfiZqVE0yGux39i6wjEOCcIbfO8O7wgCEk4GE/98Z6/+lp1NEaQLHcu24FlUeCgThTVaJsmcY9aHB+jFn11yBiJ6+N+RYONWto0xLDyt71qM5KXEEngYambCK8D0JAoIBAQD5tYwpTNfcessxPcYAXkdJWNAP3/8kwz97rFi9gZYsxhZJ/JCU8TUCYlpJDf91mCe0i7uayGb3FbtzoWEwHxKL4DdlL47ZaaGA2dIVNMkxksXDehEE6/bVRAcFH1fT9mZr7uB2uX1YjesFRKEEd3UXpfKSPwtm3QUQz7P7WxzL0CWpfC11vAK2biCG72inE3MelCw/z1Y7M7oo2fyflObMPKkqyuy5NGtZ5t9xpMvLaZrOzJkYbwPaIqxIvISg9rxilZhjMhIFHOW8xM0lVHMEkk2NrwwsMihxFmDaUohZf0GiyYzNEEVBmVEhAZSOV5d1JlWYQStyvDas195/IHjNAoIBAQDYyakyJbbEhgcLSrmXKtJY584y6SYFE1mOZKKkON2EfDpAlwFmJYV26dWiPb77mUsf1HUU/aIT6sfZsrh6axvs0rqqp5ltIr6AzXnJce590EMJnASWLTAdhYXK6e5Y1W8AhylP4LzZk/dy4LOaF09pMi3ugogFFJAWV8j/cv2niUsCXg/I6cQz/Co6cwVhBzOnAMIjdvZbJ2ONJ1Jy/4yS17DBFRyHxMbGVPckXEVodjZ73TAfUQIM83Z8YILxyym2d2f7lvuCyT+ZjmpEJQztdxPO8qT9MaROs4c/qVjJZndoTZ3z4i2eke9Bf3Qcd6Bfy6jPq/r73hl0w0kBo4qnAoIBAQCC8fgZJEnCPcZWAR3WzZm2VdNtr7n9TkH5GazDW7QjsJC5pa8v27k/kdHko2mGAg84N1pe1Z5hDc1p2oO7l1/DaAXEkwbm7eSaTB9FrZOf4mbAlj9chFzBA1ZnEkOdTIXzLaYZvDWF/Y30CkQhsn79srEcjeDtxRNF+JVaRzI3kuRdF1hDeB84CVIXUG5hxupEa9E0eQawLvT9PSqjiJLrIRhY72bpzBpLX61my9NuzOc4cMQLsxOjDTGpRuqJ+jlZvTbXNceLVNcIgW9OlxVlnU778IKCnp7khqatdkA4JmqF8gla86BNwRdxJoH/juFGtp6GJA6jsR0+0EjGA4I1AoIBAGl2ITNeGX2dXgvmPEcH8/CARFWMCozpjuWwm1acu1baQFRvoaSZmEXzF5SnySMIvf0sFBE0GgbqbnK/ePNE6/7XvSuMAR2Qi3CJhTe0jzrxd8tS9QBB12hlLmM6TlM08Z0mI7jSMcz/KJ/gJD9QG7enS6T+J0GhcT8NUaDDxhYcujram384CdToVXq9vd4n7L7PpaIvG0XY8ZsXiAqduzssZrZnmMuLtM+DQf+US8e3ymWTgveZJxA52GhFYy5RkWdMy28fUheb467GE3g3NgTHqwFAFXd/ENmgiKk1rxW7HVfGepLMczjy8ZvBbzDyGTjBEMyGc8DXmTauUfPUJX0CggEBAKEWyNHhEBcEfW6ppPYsaKTlIquA2Chr15KsZcSFOMIcsF/6D7TDZg2NPDYFmlALF/cdqDjRIAP/v5IMRiu3UtHyfDbRyEHx0prvucFMY0HyX9VOJnticwTb39awHi/uFJLs7txERw89eJFcLaxRRRRSpPq3PCalGFpC2i8HXsPnv3gyt+bfE92h6E2YTyP41NYmcuuXkyWM83s11YSC9ZgeilbJuvdajePHrtIAxy8cny+yTBcbnJnWw1yHtzWCA5FAw5OWSaeotbWaFEAHaOW1VG9e1I54pgmVTc5n+WixsgH1fpiz04ojlWRWRyP7hqS+GbAyGgg00KyErRrPcwc=";
- string LiSReqUrl = "https://openapi.jlpay.com/access/charge/"; //请求url
- public string LiSSign(string data)
- {
- var rsa = RSA.Create();
- var key = Convert.FromBase64String(LiSPrivateKey);
- var content = Encoding.UTF8.GetBytes(data);
- rsa.ImportPkcs8PrivateKey(key, out _);
- var result = rsa.SignData(content, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
- return Convert.ToBase64String(result);
- }
- // 设置费率
- public string SetLiSFee(string sn, decimal serviceFee)
- {
- Dictionary<string, object> dic = new Dictionary<string, object>();
- dic.Add("agentId", LiSAgentId);
- dic.Add("deviceSn", sn);
- List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
- Dictionary<string, object> item = new Dictionary<string, object>();
- item.Add("feeCalcType", "M5");
- item.Add("fixed", "0");
- item.Add("rate", serviceFee);
- feeList.Add(item);
- dic.Add("feeList", feeList);
- dic.Add("signMethod", "02");
- string content = LiSAgentId + sn + "M50" + serviceFee + "02";
- string signstr = LiSSign(content);
- dic.Add("signData", signstr);
- string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
- string result = function.PostWebRequest(LiSReqUrl + "FEE003", req, new Dictionary<string, string>(), "application/json");
- return result;
- }
- // 设置押金
- public string SetLiSDeposit(string sn, int serviceFee)
- {
- serviceFee = serviceFee * 100;
- Dictionary<string, object> dic = new Dictionary<string, object>();
- dic.Add("agentId", LiSAgentId);
- dic.Add("deviceSn", sn);
- List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
- Dictionary<string, object> item = new Dictionary<string, object>();
- item.Add("feeCalcType", "N1");
- item.Add("fixed", "1");
- item.Add("rate", serviceFee);
- feeList.Add(item);
- dic.Add("feeList", feeList);
- dic.Add("signMethod", "02");
- string content = LiSAgentId + sn + "N11" + serviceFee + "02";
- string signstr = LiSSign(content);
- dic.Add("signData", signstr);
- string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
- string result = function.PostWebRequest(LiSReqUrl + "FEE003", req, new Dictionary<string, string>(), "application/json");
- return result;
- }
- #endregion
- #endregion
- #region 查询商户型创客设置信息
- public IActionResult SeeMerchantType(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public string SeeMerchantTypeDo(string PosSn)
- {
- if (string.IsNullOrEmpty(PosSn))
- {
- return "请输入机具SN";
- }
- SetMerchantTypeRecord pos = db.SetMerchantTypeRecord.FirstOrDefault(m => m.PosSn == PosSn);
- if (pos == null)
- {
- return "查无信息";
- }
- Users setUser = db.Users.FirstOrDefault(m => m.Id == pos.FromUserId) ?? new Users();
- Users toUser = db.Users.FirstOrDefault(m => m.Id == pos.ToUserId) ?? new Users();
- string CreateDate = pos.CreateDate == null ? "" : pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
- string bindTime = pos.BindDate == null ? "" : pos.BindDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
- string activeTime = pos.ActDate == null ? "" : pos.ActDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
- string bindResult = pos.BindStatus == 1 ? "已绑定" : "未绑定";
- string activeResult = pos.ActStatus == 1 ? "已激活" : "未激活";
- string RecycFlag = pos.IsRecyc == 1 ? "已循环" : "未循环";
- string result = "";
- result += "机具SN:" + pos.PosSn + "\n";
- result += "操作人:创客编号:" + setUser.MakerCode + ",姓名:" + setUser.RealName + ",手机号:" + setUser.Mobile + "\n";
- result += "操作对象:创客编号:" + toUser.MakerCode + ",姓名:" + toUser.RealName + ",手机号:" + toUser.Mobile + "\n";
- result += "商户编号:" + pos.MerNo + "\n";
- result += "操作时间:" + pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + "\n";
- result += "绑定状态:" + bindResult + "(绑定时间:" + bindTime + ")\n";
- result += "激活状态:" + activeResult + "(激活时间:" + activeTime + ")\n";
- result += "贷记卡交易额:" + pos.CreditAmount + "\n";
- result += "是否循环:" + RecycFlag + "\n";
- return result;
- }
- #endregion
- }
- }
|