SysToolsController.cs 167 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390
  1. /*
  2. * 机具激活限制信息
  3. */
  4. using System;
  5. using System.Web;
  6. using System.Collections.Generic;
  7. using System.Diagnostics;
  8. using System.Linq;
  9. using System.Threading.Tasks;
  10. using Microsoft.AspNetCore.Mvc;
  11. using Microsoft.AspNetCore.Http;
  12. using Microsoft.Extensions.Logging;
  13. using Microsoft.Extensions.Options;
  14. using MySystem.Models;
  15. using Library;
  16. using LitJson;
  17. using MySystemLib;
  18. using System.Text.RegularExpressions;
  19. using System.Security.Cryptography;
  20. using System.Security.Cryptography.X509Certificates;
  21. using System.Text;
  22. using System.Net;
  23. using System.Net.Security;
  24. using System.IO;
  25. namespace MySystem.Areas.Admin.Controllers
  26. {
  27. [Area("Admin")]
  28. [Route("Admin/[controller]/[action]")]
  29. public class SysToolsController : BaseController
  30. {
  31. public SysToolsController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  32. {
  33. }
  34. #region 关联上下级
  35. public IActionResult RelationForUser(string right)
  36. {
  37. ViewBag.RightInfo = RightInfo;
  38. ViewBag.right = right;
  39. return View();
  40. }
  41. [HttpPost]
  42. public string RelationForUserDo(string MakerCode, string ParentMakerCode, int IsTeam = 1)
  43. {
  44. if (string.IsNullOrEmpty(MakerCode))
  45. {
  46. return "请输入创客编号";
  47. }
  48. if (string.IsNullOrEmpty(ParentMakerCode))
  49. {
  50. return "请输入上级创客编号";
  51. }
  52. MakerCode = MakerCode.ToUpper();
  53. ParentMakerCode = ParentMakerCode.ToUpper();
  54. Users puser = db.Users.FirstOrDefault(m => m.MakerCode == ParentMakerCode);
  55. if (puser != null)
  56. {
  57. Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
  58. if (user != null)
  59. {
  60. user.ParentUserId = puser.Id;
  61. user.ParentNav = puser.ParentNav + "," + puser.Id + ",";
  62. if (IsTeam == 1)
  63. {
  64. RelationForUserSub(db, user.Id, user);
  65. }
  66. db.SaveChanges();
  67. function.WriteLog(DateTime.Now.ToString() + ":下级:" + MakerCode + ", 上级:" + ParentMakerCode, "换线日志");
  68. return "success";
  69. }
  70. return "创客编号不存在";
  71. }
  72. return "上级创客编号不存在";
  73. }
  74. private void RelationForUserSub(WebCMSEntities dbnew, int ParentUserId, Users puser)
  75. {
  76. var subusers = dbnew.Users.Select(m => new { m.Id, m.ParentUserId, m.ParentNav }).Where(m => m.ParentUserId == ParentUserId).ToList();
  77. foreach (var subuser in subusers)
  78. {
  79. Users user = dbnew.Users.FirstOrDefault(m => m.Id == subuser.Id);
  80. if (user != null)
  81. {
  82. user.ParentUserId = puser.Id;
  83. user.ParentNav = puser.ParentNav + "," + puser.Id + ",";
  84. RelationForUserSub(dbnew, user.Id, user);
  85. }
  86. }
  87. }
  88. #endregion
  89. #region 机具补录
  90. public IActionResult CheckMachine(string right)
  91. {
  92. ViewBag.RightInfo = RightInfo;
  93. ViewBag.right = right;
  94. return View();
  95. }
  96. [HttpPost]
  97. public string CheckMachineDo(string MakerCode, string PosSn, string MerNo = "", int AddActPrize = 0, int IsPre = 0, int IsSend = 0)
  98. {
  99. if (string.IsNullOrEmpty(MakerCode))
  100. {
  101. return "请输入创客编号";
  102. }
  103. if (string.IsNullOrEmpty(PosSn))
  104. {
  105. return "请输入机具SN";
  106. }
  107. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  108. KqProducts kqProducts = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId);
  109. if (pos == null)
  110. {
  111. return "机具SN不存在";
  112. }
  113. Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
  114. if (user == null)
  115. {
  116. return "创客编号不存在";
  117. }
  118. if (IsPre == 1)
  119. {
  120. if (pos.BuyUserId == 0)
  121. {
  122. pos.BuyUserId = user.Id;
  123. }
  124. if (pos.UserId == 0)
  125. {
  126. pos.UserId = user.Id;
  127. }
  128. }
  129. if (pos.BindingState == 0)
  130. {
  131. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerSnNo == PosSn);
  132. if (bind != null)
  133. {
  134. pos.BindingState = 1;
  135. pos.BindingTime = bind.CreateTime;
  136. db.SaveChanges();
  137. MerNo = bind.MerNo;
  138. }
  139. }
  140. decimal CreditTrade = 0;
  141. string BindingTime = pos.BindingTime == null ? DateTime.Now.AddMonths(-1).ToString("yyyyMM") : pos.BindingTime.Value.ToString("yyyyMM");
  142. string SpTradeRecordId = function.ReadInstance("/PublicParams/SpTradeRecordId" + BindingTime + ".txt");
  143. int StartId = int.Parse(function.CheckInt(SpTradeRecordId));
  144. bool check = spdb.TradeRecord.Any(m => m.Id > StartId && m.TradeSnNo == pos.PosSn);
  145. if (check)
  146. {
  147. if (pos.BrandId == 1)
  148. {
  149. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "1" && m.SerEntryMode != "N" && m.MerNo.StartsWith("M700")).Sum(m => m.TradeAmount) / 100;
  150. }
  151. else if (pos.BrandId == 2)
  152. {
  153. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "2").Sum(m => m.TradeAmount);
  154. }
  155. else if (pos.BrandId == 3)
  156. {
  157. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "1" && m.SerEntryMode != "N" && m.MerNo.StartsWith("M900")).Sum(m => m.TradeAmount) / 100;
  158. }
  159. else if (pos.BrandId == 4 || pos.BrandId == 5)
  160. {
  161. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "4").Sum(m => m.TradeAmount) / 100;
  162. }
  163. else if (pos.BrandId == 6)
  164. {
  165. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "6").Sum(m => m.TradeAmount) / 100;
  166. }
  167. else if (pos.BrandId == 7)
  168. {
  169. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "7" && m.TradeStatus == "00").Sum(m => m.TradeAmount) / 100;
  170. }
  171. else if (pos.BrandId == 8)
  172. {
  173. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "8").Sum(m => m.TradeAmount) / 100;
  174. }
  175. else if (pos.BrandId == 9)
  176. {
  177. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "9").Sum(m => m.TradeAmount) / 100;
  178. }
  179. pos.CreditTrade = CreditTrade;
  180. db.SaveChanges();
  181. StatTradeAmount(pos.PosSn, StartId);
  182. }
  183. if (AddActPrize == 1)
  184. {
  185. if (pos.BuyUserId == 0)
  186. {
  187. return "机具未划拨,无法补录激活奖励";
  188. }
  189. if (string.IsNullOrEmpty(pos.SeoKeyword) || pos.SeoKeyword == "0")
  190. {
  191. bool has = spdb.ActivateRecord.Any(m => m.SnNo == pos.PosSn);
  192. if (has)
  193. {
  194. SpModels.ActivateRecord chkAct = spdb.ActivateRecord.Where(m => m.SnNo == pos.PosSn).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SpModels.ActivateRecord();
  195. pos.SeoKeyword = chkAct.SeoTitle;
  196. db.SaveChanges();
  197. }
  198. }
  199. if (pos.BindingTime != null && pos.ActivationTime != null)
  200. {
  201. TimeSpan ts = pos.ActivationTime.Value - pos.BindingTime.Value;
  202. if (ts.TotalDays <= 30 || SysUserName == "admin")
  203. {
  204. AddAct(pos.Id);
  205. }
  206. }
  207. }
  208. decimal CheckMoney = 1000;
  209. if (pos.BrandId == 6)
  210. {
  211. CheckMoney = 5000;
  212. }
  213. if (pos.BuyUserId > 0)
  214. {
  215. if (pos.CreditTrade < CheckMoney)
  216. {
  217. return "该机具贷记卡累计交易不足" + CheckMoney;
  218. }
  219. if (pos.BindingTime != null && pos.ActivationTime != null)
  220. {
  221. TimeSpan ts = pos.ActivationTime.Value - pos.BindingTime.Value;
  222. if (ts.TotalDays > 30 && SysUserName != "admin")
  223. {
  224. return "机具划拨后已超过30天";
  225. }
  226. }
  227. if (pos.CreditTrade >= CheckMoney && pos.ActivationState == 0)
  228. {
  229. pos.ActivationState = 1;
  230. pos.ActivationTime = DateTime.Now;
  231. PosMerchantInfo mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  232. if (pos.ActivationState == 1 && mer != null)
  233. {
  234. mer.ActiveStatus = 1;
  235. mer.MerStandardDate = DateTime.Now;
  236. }
  237. }
  238. else if (pos.CreditTrade >= CheckMoney && pos.ActivationState == 1)
  239. {
  240. if (AddActPrize == 1)
  241. {
  242. if (IsSend == 1)
  243. {
  244. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  245. {
  246. UserId = pos.BuyUserId, //接收创客
  247. MsgType = 2,
  248. Title = "补录成功通知", //标题
  249. Summary = "您的 " + kqProducts.Name + " SN:" + pos.PosSn + "已经成功补录,请查收。",
  250. CreateDate = DateTime.Now,
  251. }));
  252. }
  253. return "激活奖励已补录";
  254. }
  255. else
  256. {
  257. return "数据正常,无需补录";
  258. }
  259. }
  260. db.SaveChanges();
  261. return "success";
  262. }
  263. pos.UserId = user.Id;
  264. pos.BuyUserId = user.Id;
  265. if (pos.CreditTrade >= CheckMoney && pos.ActivationState == 0 && (pos.BindingTime > DateTime.Now.AddDays(-30) || SysUserName == "admin"))
  266. {
  267. // pos.IsPurchase = 0;
  268. pos.ActivationState = 1;
  269. pos.ActivationTime = DateTime.Now;
  270. }
  271. PosMerchantInfo merchant = new PosMerchantInfo();
  272. if (!string.IsNullOrEmpty(MerNo))
  273. {
  274. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo);
  275. if (merchant == null)
  276. {
  277. int TopUserId = 0;
  278. if (!string.IsNullOrEmpty(user.ParentNav))
  279. {
  280. TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  281. }
  282. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerNo == MerNo);
  283. if (bind == null)
  284. {
  285. return "该机具尚未绑定";
  286. }
  287. SpModels.Merchants Mer = spdb.Merchants.FirstOrDefault(m => m.MerNo == MerNo);
  288. if (Mer == null)
  289. {
  290. return "该机具尚未绑定";
  291. }
  292. PosMerchantInfo add = db.PosMerchantInfo.Add(new PosMerchantInfo()
  293. {
  294. CreateDate = Mer.CreateTime,
  295. UpdateDate = Mer.UpdateTime,
  296. TopUserId = TopUserId,
  297. MerUserType = user.MerchantType,
  298. BrandId = int.Parse(Mer.ProductType),
  299. SnStoreId = pos.StoreId,
  300. SnType = pos.PosSnType,
  301. UserId = user.Id,
  302. MgrName = Mer.AgentName,
  303. MerStatus = 1,
  304. KqSnNo = Mer.SnNo,
  305. KqMerNo = Mer.MerNo,
  306. MerIdcardNo = Mer.MerIdcardNo,
  307. MerRealName = Mer.MerRealName,
  308. MerchantMobile = Mer.MerMobile,
  309. MerchantName = Mer.MerName,
  310. MerchantNo = Mer.MerNo,
  311. }).Entity;
  312. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Mer.MerNo);
  313. if (forMerNo == null)
  314. {
  315. forMerNo = db.MachineForMerNo.Add(new MachineForMerNo()
  316. {
  317. MerNo = Mer.MerNo,
  318. SnId = pos.Id,
  319. }).Entity;
  320. }
  321. else
  322. {
  323. forMerNo.SnId = pos.Id;
  324. }
  325. }
  326. }
  327. else
  328. {
  329. if (pos.BindMerchantId > 0)
  330. {
  331. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  332. }
  333. else
  334. {
  335. return "找不到机具所属商户";
  336. }
  337. }
  338. merchant.UserId = user.Id;
  339. if (pos.ActivationState == 1)
  340. {
  341. merchant.ActiveStatus = 1;
  342. merchant.MerStandardDate = DateTime.Now;
  343. }
  344. if (pos.BindMerchantId == 0)
  345. {
  346. pos.BindMerchantId = merchant.Id;
  347. }
  348. // var makerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
  349. // var prePos = db.PreSendStockDetail.FirstOrDefault(m => m.ToUserId == makerCode.UserId && m.SnId == pos.Id && m.CreateDate < DateTime.Now.AddDays(-30) && m.AuthFlag == 1 && m.ApplyFlag == 0) ?? new PreSendStockDetail();
  350. // if (makerCode.UserId > 0 && prePos.Id > 0)
  351. // {
  352. // if (prePos.CreateDate <= DateTime.Now.AddDays(-30))
  353. // {
  354. // var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == prePos.BrandId);
  355. // var amount = 0;
  356. // if (brandInfo.Name.Contains("电签"))
  357. // {
  358. // amount = 200;
  359. // }
  360. // if (brandInfo.Name.Contains("大POS"))
  361. // {
  362. // amount = 300;
  363. // }
  364. // var userAccount = db.UserAccount.FirstOrDefault(m => m.Id == makerCode.UserId) ?? new UserAccount();
  365. // if (userAccount.Id > 0)
  366. // {
  367. // userAccount.SmallStoreDeposit -= amount;
  368. // var add = db.UserAccountRecord.Add(new UserAccountRecord()
  369. // {
  370. // CreateDate = DateTime.Now,
  371. // Remark = "小分仓押金退还",
  372. // ChangeType = 65,
  373. // BeforeBalanceAmount = userAccount.SmallStoreDeposit + amount, //变更前小分仓押金
  374. // AfterBalanceAmount = userAccount.SmallStoreDeposit, //变更后小分仓押金
  375. // ChangeAmount = amount,//变动金额
  376. // UserId = userAccount.Id,
  377. // }).Entity;
  378. // db.SaveChanges();
  379. // }
  380. // }
  381. // }
  382. db.SaveChanges();
  383. function.WriteLog(DateTime.Now.ToString() + "\n" + SysUserName + "\nMakerCode:" + MakerCode + ", PosSn:" + PosSn + ", MerNo:" + MerNo + ", AddActPrize:" + AddActPrize + ", IsPre:" + IsPre, "机具补录日志");
  384. return "success";
  385. }
  386. public IActionResult CheckMachine2(string right)
  387. {
  388. ViewBag.RightInfo = RightInfo;
  389. ViewBag.right = right;
  390. return View();
  391. }
  392. [HttpPost]
  393. public string CheckMachine2Do(string MakerCode, string PosSn, string MerNo = "", int AddActPrize = 0)
  394. {
  395. if (string.IsNullOrEmpty(MakerCode))
  396. {
  397. return "请输入创客编号";
  398. }
  399. if (string.IsNullOrEmpty(PosSn))
  400. {
  401. return "请输入机具SN";
  402. }
  403. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  404. if (pos == null)
  405. {
  406. return "机具SN不存在";
  407. }
  408. Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
  409. if (user == null)
  410. {
  411. return "创客编号不存在";
  412. }
  413. if (pos.BindingState == 0)
  414. {
  415. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerSnNo == PosSn);
  416. if (bind != null)
  417. {
  418. pos.BindingState = 1;
  419. pos.BindingTime = bind.CreateTime;
  420. db.SaveChanges();
  421. MerNo = bind.MerNo;
  422. }
  423. }
  424. decimal CreditTrade = 0;
  425. bool check = spdb.TradeRecord.Any(m => m.TradeSnNo == pos.PosSn);
  426. if (check)
  427. {
  428. string BindingTime = pos.BindingTime == null ? DateTime.Now.AddMonths(-1).ToString("yyyyMM") : pos.BindingTime.Value.ToString("yyyyMM");
  429. string SpTradeRecordId = function.ReadInstance("/PublicParams/SpTradeRecordId" + BindingTime + ".txt");
  430. int StartId = int.Parse(function.CheckInt(SpTradeRecordId));
  431. if (pos.BrandId == 1)
  432. {
  433. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "1" && m.SerEntryMode != "N" && m.MerNo.StartsWith("M700")).Sum(m => m.TradeAmount) / 100;
  434. }
  435. else if (pos.BrandId == 2)
  436. {
  437. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "2").Sum(m => m.TradeAmount);
  438. }
  439. else if (pos.BrandId == 3)
  440. {
  441. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "1" && m.SerEntryMode != "N" && m.MerNo.StartsWith("M900")).Sum(m => m.TradeAmount) / 100;
  442. }
  443. else if (pos.BrandId == 4 || pos.BrandId == 5)
  444. {
  445. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "4").Sum(m => m.TradeAmount) / 100;
  446. }
  447. else if (pos.BrandId == 6)
  448. {
  449. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "6").Sum(m => m.TradeAmount) / 100;
  450. }
  451. else if (pos.BrandId == 8)
  452. {
  453. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "8").Sum(m => m.TradeAmount) / 100;
  454. }
  455. else if (pos.BrandId == 9)
  456. {
  457. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "9").Sum(m => m.TradeAmount) / 100;
  458. }
  459. pos.CreditTrade = CreditTrade;
  460. db.SaveChanges();
  461. StatTradeAmount(pos.PosSn);
  462. }
  463. if (AddActPrize == 1)
  464. {
  465. if (string.IsNullOrEmpty(pos.SeoKeyword) || pos.SeoKeyword == "0")
  466. {
  467. bool has = spdb.ActivateRecord.Any(m => m.SnNo == pos.PosSn);
  468. if (has)
  469. {
  470. SpModels.ActivateRecord chkAct = spdb.ActivateRecord.Where(m => m.SnNo == pos.PosSn).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SpModels.ActivateRecord();
  471. pos.SeoKeyword = chkAct.SeoTitle;
  472. db.SaveChanges();
  473. }
  474. }
  475. AddAct(pos.Id);
  476. }
  477. if (pos.BuyUserId > 0)
  478. {
  479. if (pos.CreditTrade < 1000)
  480. {
  481. // pos.IsPurchase = 99;
  482. db.SaveChanges();
  483. return "该机具贷记卡累计交易不足1000";
  484. }
  485. if (pos.CreditTrade >= 1000 && pos.ActivationState == 0)
  486. {
  487. // pos.IsPurchase = 0;
  488. pos.ActivationState = 1;
  489. pos.ActivationTime = DateTime.Now;
  490. PosMerchantInfo mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  491. if (pos.ActivationState == 1 && mer != null)
  492. {
  493. mer.ActiveStatus = 1;
  494. mer.MerStandardDate = DateTime.Now;
  495. }
  496. }
  497. else if (pos.CreditTrade >= 1000 && pos.ActivationState == 1)
  498. {
  499. if (AddActPrize == 1)
  500. {
  501. return "激活奖励已补录";
  502. }
  503. else
  504. {
  505. return "数据正常,无需补录";
  506. }
  507. }
  508. db.SaveChanges();
  509. return "success";
  510. }
  511. pos.UserId = user.Id;
  512. pos.BuyUserId = user.Id;
  513. // if (pos.CreditTrade < 1000)
  514. // {
  515. // pos.IsPurchase = 99;
  516. // }
  517. if (pos.CreditTrade >= 1000 && pos.ActivationState == 0)
  518. {
  519. // pos.IsPurchase = 0;
  520. pos.ActivationState = 1;
  521. pos.ActivationTime = DateTime.Now;
  522. }
  523. PosMerchantInfo merchant = new PosMerchantInfo();
  524. if (!string.IsNullOrEmpty(MerNo))
  525. {
  526. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo);
  527. if (merchant == null)
  528. {
  529. int TopUserId = 0;
  530. if (!string.IsNullOrEmpty(user.ParentNav))
  531. {
  532. TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  533. }
  534. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerNo == MerNo);
  535. if (bind == null)
  536. {
  537. return "该机具尚未绑定";
  538. }
  539. SpModels.Merchants Mer = spdb.Merchants.FirstOrDefault(m => m.MerNo == MerNo);
  540. if (Mer == null)
  541. {
  542. return "该机具尚未绑定";
  543. }
  544. PosMerchantInfo add = db.PosMerchantInfo.Add(new PosMerchantInfo()
  545. {
  546. CreateDate = Mer.CreateTime,
  547. UpdateDate = Mer.UpdateTime,
  548. TopUserId = TopUserId,
  549. MerUserType = user.MerchantType,
  550. BrandId = int.Parse(Mer.ProductType),
  551. SnStoreId = pos.StoreId,
  552. SnType = pos.PosSnType,
  553. UserId = user.Id,
  554. MgrName = Mer.AgentName,
  555. MerStatus = 1,
  556. KqSnNo = Mer.SnNo,
  557. KqMerNo = Mer.MerNo,
  558. MerIdcardNo = Mer.MerIdcardNo,
  559. MerRealName = Mer.MerRealName,
  560. MerchantMobile = Mer.MerMobile,
  561. MerchantName = Mer.MerName,
  562. MerchantNo = Mer.MerNo,
  563. }).Entity;
  564. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Mer.MerNo);
  565. if (forMerNo == null)
  566. {
  567. forMerNo = db.MachineForMerNo.Add(new MachineForMerNo()
  568. {
  569. MerNo = Mer.MerNo,
  570. SnId = pos.Id,
  571. }).Entity;
  572. }
  573. else
  574. {
  575. forMerNo.SnId = pos.Id;
  576. }
  577. }
  578. }
  579. else
  580. {
  581. if (pos.BindMerchantId > 0)
  582. {
  583. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  584. }
  585. else
  586. {
  587. return "找不到机具所属商户";
  588. }
  589. }
  590. merchant.UserId = user.Id;
  591. if (pos.ActivationState == 1)
  592. {
  593. merchant.ActiveStatus = 1;
  594. merchant.MerStandardDate = DateTime.Now;
  595. }
  596. if (pos.BindMerchantId == 0)
  597. {
  598. pos.BindMerchantId = merchant.Id;
  599. }
  600. db.SaveChanges();
  601. return "success";
  602. }
  603. public void AddAct(int posid = 0)
  604. {
  605. WebCMSEntities db = new WebCMSEntities();
  606. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.ActivationState == 1 && !string.IsNullOrEmpty(m.SeoKeyword) && m.Id == posid);
  607. if (pos != null)
  608. {
  609. // PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId && !string.IsNullOrEmpty(m.MerIdcardNo));
  610. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  611. if (merchant != null)
  612. {
  613. // PosMerchantOtherInfo otherInfo = db.PosMerchantOtherInfo.FirstOrDefault(m => m.CertId == merchant.MerIdcardNo && m.PrizeFlag1 == 0);
  614. // if (otherInfo != null)
  615. // {
  616. // otherInfo.PrizeFlag1 = 1;
  617. // db.SaveChanges();
  618. string ParentNav = "";
  619. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId);
  620. if (user != null)
  621. {
  622. int GetUserId = user.Id;
  623. ParentNav = user.ParentNav;
  624. int TopUserId = 1;
  625. if (!string.IsNullOrEmpty(ParentNav))
  626. {
  627. string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  628. if (ParentNavList.Length > 1)
  629. {
  630. TopUserId = int.Parse(ParentNavList[1]);
  631. }
  632. else if (ParentNavList.Length == 1)
  633. {
  634. TopUserId = int.Parse(ParentNavList[0]);
  635. }
  636. }
  637. List<decimal> prizes = new List<decimal>();
  638. decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  639. if (pos.BrandId == 1 || pos.BrandId == 3 || pos.BrandId == 4 || pos.BrandId == 5 || pos.BrandId == 6 || pos.BrandId == 8 || pos.BrandId == 9)
  640. {
  641. ActPrize = ActPrize / 100;
  642. }
  643. if (ActPrize > 0)
  644. {
  645. if (ActPrize == 99)
  646. {
  647. ActPrize = 100;
  648. }
  649. else if (ActPrize == 199)
  650. {
  651. ActPrize = 200;
  652. }
  653. else if (ActPrize == 299)
  654. {
  655. ActPrize = 300;
  656. }
  657. else if (ActPrize == 249)
  658. {
  659. ActPrize = 260;
  660. }
  661. prizes.Add(ActPrize);
  662. if (pos.BrandId == 6 && pos.ActivationState == 1 && pos.CreditTrade >= 10000 && pos.BindingTime > DateTime.Now.AddDays(-60))
  663. {
  664. prizes.Add(40);
  665. }
  666. }
  667. else if (pos.BrandId == 6 && ActPrize == 0)
  668. {
  669. prizes.Add(50);
  670. }
  671. foreach (decimal prize in prizes)
  672. {
  673. int ChangeType = prize == 40 ? 12 : 0;
  674. bool check = db.ActiveReward.Any(m => m.KqSnNo == pos.PosSn && m.RewardAmount == prize);
  675. if (!check)
  676. {
  677. Users machineUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  678. db.ActiveReward.Add(new ActiveReward()
  679. {
  680. CreateDate = DateTime.Now,
  681. UpdateDate = DateTime.Now,
  682. UserId = GetUserId, //创客
  683. MerchantId = pos.BindMerchantId, //商户
  684. StandardDate = pos.ActivationTime, //达标日期
  685. RewardAmount = prize, //奖励金额
  686. BrandId = pos.BrandId, //品牌
  687. UserNav = ParentNav, //创客父级
  688. DirectBuddyNo = merchant.UserId, //商户直属创客
  689. KqMerNo = merchant.KqMerNo, //渠道商户编号
  690. KqSnNo = pos.PosSn, //渠道SN号
  691. SnType = pos.PosSnType, //机具类型
  692. SnApplyUserId = pos.BuyUserId, //机具申请创客
  693. ActType = 0, //激活类型
  694. SnStoreId = pos.StoreId, //SN仓库
  695. RewardTips = "激活奖励", //奖励描述
  696. Remark = "激活奖励", //备注
  697. ActDate = pos.ActivationTime, //激活时间
  698. TopUserId = TopUserId, //顶级创客
  699. SeoTitle = machineUser.RealName,
  700. });
  701. db.SaveChanges();
  702. string IdBrand = GetUserId + "_" + pos.BrandId;
  703. UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
  704. if (userData == null)
  705. {
  706. userData = db.UserMachineData.Add(new UserMachineData()
  707. {
  708. IdBrand = IdBrand,
  709. }).Entity;
  710. db.SaveChanges();
  711. }
  712. userData.ActProfit += prize;
  713. db.SaveChanges();
  714. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == GetUserId);
  715. if (account == null)
  716. {
  717. account = db.UserAccount.Add(new UserAccount()
  718. {
  719. Id = GetUserId,
  720. UserId = GetUserId,
  721. }).Entity;
  722. db.SaveChanges();
  723. }
  724. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  725. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  726. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  727. account.BalanceAmount += prize;
  728. account.TotalAmount += prize;
  729. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  730. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  731. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  732. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  733. {
  734. CreateDate = DateTime.Now,
  735. UpdateDate = DateTime.Now,
  736. UserId = GetUserId, //创客
  737. ChangeType = ChangeType, //变动类型
  738. ProductType = pos.BrandId, //产品类型
  739. ChangeAmount = prize, //变更金额
  740. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  741. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  742. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  743. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  744. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  745. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  746. }).Entity;
  747. db.SaveChanges();
  748. RedisDbconn.Instance.Set("UserAccount:" + GetUserId, account);
  749. string dateString = pos.ActivationTime.Value.ToString("yyyyMMdd");
  750. string monthString = pos.ActivationTime.Value.ToString("yyyyMM");
  751. // 激活奖励列表
  752. List<string> dates = RedisDbconn.Instance.GetList<string>("ActiveRewardDay:" + GetUserId + ":" + pos.BrandId);
  753. if (!dates.Contains(dateString))
  754. {
  755. RedisDbconn.Instance.AddList("ActiveRewardDay:" + GetUserId + ":" + pos.BrandId, dateString);
  756. }
  757. RedisDbconn.Instance.AddNumber("ActiveRewardAmt:" + GetUserId + ":" + pos.BrandId + ":" + dateString, prize);
  758. List<string> months = RedisDbconn.Instance.GetList<string>("ActiveRewardMonth:" + GetUserId + ":" + pos.BrandId);
  759. if (!months.Contains(monthString))
  760. {
  761. RedisDbconn.Instance.AddList("ActiveRewardMonth:" + GetUserId + ":" + pos.BrandId, monthString);
  762. }
  763. RedisDbconn.Instance.AddNumber("ActiveRewardAmt:" + GetUserId + ":" + pos.BrandId + ":" + monthString, prize);
  764. // 激活奖励详情
  765. List<int> actPrizeList = RedisDbconn.Instance.GetList<int>("ActiveRewardDetail:" + GetUserId + ":" + pos.BrandId + ":" + dateString);
  766. if (!actPrizeList.Contains(pos.BindMerchantId))
  767. {
  768. RedisDbconn.Instance.AddList("ActiveRewardDetail:" + GetUserId + ":" + pos.BrandId + ":" + dateString, pos.BindMerchantId);
  769. }
  770. RedisDbconn.Instance.AddNumber("ActiveRewardAmt:mer:" + pos.BindMerchantId + ":" + pos.BrandId + ":" + dateString, prize);
  771. //收支明细
  772. RedisDbconn.Instance.AddList("UserAccountRecord:" + GetUserId + ":1:" + monthString, userAccountRecord);
  773. RedisDbconn.Instance.AddNumber("UserAccount:" + GetUserId + ":1:" + monthString, prize);
  774. }
  775. }
  776. }
  777. // }
  778. }
  779. }
  780. db.Dispose();
  781. }
  782. //重置交易额
  783. public void StatTradeAmount(string PosSn, int StartId = 0)
  784. {
  785. DateTime start = DateTime.Parse(DateTime.Now.ToString("yyyy-MM") + "-01 00:00:00");
  786. if (DateTime.Now.Day == 1)
  787. {
  788. start = DateTime.Parse(DateTime.Now.AddMonths(-1).ToString("yyyy-MM") + "-01 00:00:00");
  789. }
  790. DateTime end = DateTime.Now;
  791. SycnSpTradeService.Instance.Start(PosSn, start, end, StartId);
  792. RedisDbconn.Instance.AddList("ResetTradeAmountList", PosSn);
  793. }
  794. #endregion
  795. #region 设置商户代理
  796. public IActionResult SetMerAgent(string right)
  797. {
  798. ViewBag.RightInfo = RightInfo;
  799. ViewBag.right = right;
  800. return View();
  801. }
  802. [HttpPost]
  803. public string SetMerAgentDo(string MakerCode, string PosSn, string MerNo, int IsSend = 0)
  804. {
  805. if (string.IsNullOrEmpty(MakerCode))
  806. {
  807. return "请输入创客编号";
  808. }
  809. if (string.IsNullOrEmpty(PosSn))
  810. {
  811. return "请输入机具SN";
  812. }
  813. if (string.IsNullOrEmpty(MerNo))
  814. {
  815. return "请输入商户编号";
  816. }
  817. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  818. KqProducts kqProducts = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId);
  819. if (pos == null)
  820. {
  821. return "机具SN不存在";
  822. }
  823. Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
  824. if (user == null)
  825. {
  826. return "创客编号不存在";
  827. }
  828. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo);
  829. if (merchant == null)
  830. {
  831. return "商户编号不存在";
  832. }
  833. pos.SeoTitle = user.Id.ToString();
  834. pos.UserId = user.Id;
  835. if (pos.BindMerchantId == 0)
  836. {
  837. pos.BindMerchantId = merchant.Id;
  838. if (IsSend == 1)
  839. {
  840. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  841. {
  842. UserId = pos.BuyUserId, //接收创客
  843. MsgType = 2,
  844. Title = "商户型代理设置成功", //标题
  845. Summary = "您的 " + kqProducts.Name + " SN:" + pos.PosSn + "已经成功给下级代理" + user.RealName + "" + MakerCode + ",设置为商户型代理,设置成功后的新增交易的分润归商户型代理所有",
  846. CreateDate = DateTime.Now,
  847. }));
  848. }
  849. }
  850. user.MerchantType = 1;
  851. merchant.UserId = user.Id;
  852. merchant.MerUserType = 1;
  853. db.SetMerchantTypeRecord.Add(new SetMerchantTypeRecord()
  854. {
  855. CreateDate = DateTime.Now,
  856. IsRecyc = (ulong)pos.IsPurchase,
  857. CreditAmount = pos.CreditTrade,
  858. PosSnType = pos.PosSnType,
  859. ActDate = pos.ActivationTime,
  860. BindDate = pos.BindingTime,
  861. ActStatus = (ulong)pos.ActivationState,
  862. BindStatus = (ulong)pos.BindingState,
  863. MerNo = MerNo,
  864. PosSn = pos.PosSn,
  865. Note = "后台设置商户型创客",
  866. ToUserId = user.Id,
  867. FromUserId = pos.BuyUserId,
  868. });
  869. db.SaveChanges();
  870. return "success";
  871. }
  872. #endregion
  873. #region 取消商户代理
  874. public IActionResult CancelMerAgent(string right)
  875. {
  876. ViewBag.RightInfo = RightInfo;
  877. ViewBag.right = right;
  878. return View();
  879. }
  880. [HttpPost]
  881. public string CancelMerAgentDo(string MakerCode, string PosSn, int IsSend = 0)
  882. {
  883. if (string.IsNullOrEmpty(MakerCode))
  884. {
  885. return "请输入创客编号";
  886. }
  887. if (string.IsNullOrEmpty(PosSn))
  888. {
  889. return "请输入机具SN";
  890. }
  891. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  892. KqProducts kqProducts = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId);
  893. if (pos == null)
  894. {
  895. return "机具SN不存在";
  896. }
  897. Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
  898. if (user == null)
  899. {
  900. return "创客编号不存在";
  901. }
  902. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == PosSn);
  903. pos.UserId = pos.BuyUserId;
  904. merchant.UserId = pos.BuyUserId;
  905. merchant.MerUserType = 0;
  906. user.MerchantType = 0;
  907. db.SaveChanges();
  908. if (pos.BindMerchantId == 0)
  909. {
  910. pos.BindMerchantId = merchant.Id;
  911. if (IsSend == 1)
  912. {
  913. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  914. {
  915. UserId = pos.BuyUserId, //接收创客
  916. MsgType = 2,
  917. Title = "商户型代理取消成功", //标题
  918. Summary = "您的 " + kqProducts.Name + " SN:" + pos.PosSn + "已给下级代理" + user.RealName + "" + MakerCode + "取消成功",
  919. CreateDate = DateTime.Now,
  920. }));
  921. }
  922. }
  923. string text = string.Format("取消商户代理,创客编号: " + user.MakerCode + ",机具SN:" + pos.PosSn + ",操作人:" + SysRealName + ",Time:" + DateTime.Now + "");
  924. function.WriteLog(text, "CancelMerAgent");//取消商户型代理日志
  925. return "success";
  926. }
  927. #endregion
  928. #region 查看SP原始数据日志
  929. public IActionResult SeeSpLog(string right)
  930. {
  931. ViewBag.RightInfo = RightInfo;
  932. ViewBag.right = right;
  933. return View();
  934. }
  935. #endregion
  936. #region 查询机具信息
  937. public IActionResult SeeSnDetail(string right)
  938. {
  939. ViewBag.RightInfo = RightInfo;
  940. ViewBag.right = right;
  941. return View();
  942. }
  943. [HttpPost]
  944. public string SeeSnDetailDo(string PosSn)
  945. {
  946. if (string.IsNullOrEmpty(PosSn))
  947. {
  948. return "请输入机具SN";
  949. }
  950. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  951. if (pos == null)
  952. {
  953. return "机具SN不存在";
  954. }
  955. if (pos.Status == -1)
  956. {
  957. Users posUsers = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  958. decimal Deposits = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  959. if (pos.BrandId != 2 && pos.BrandId != 7)
  960. {
  961. Deposits = Deposits / 100;
  962. }
  963. string DepositGets = "未领取";
  964. string DepositUsers = "";
  965. ActiveReward rewards = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.RewardAmount != 40) ?? new ActiveReward();
  966. if (rewards.Id > 0)
  967. {
  968. Users user = db.Users.FirstOrDefault(m => m.Id == rewards.UserId) ?? new Users();
  969. DepositGets = "已领取";
  970. DepositUsers = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  971. }
  972. string ActiveTimes = rewards.CreateDate == null ? "" : rewards.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  973. string results = "该机具为故障机" + "\n";
  974. results += "押金返现实际返现对象:" + DepositUsers + "\n";
  975. results += "押金:" + Deposits + "\n";
  976. results += "是否返现:" + DepositGets + ",领取时间:" + ActiveTimes + "\n";
  977. return results;
  978. }
  979. string merInfo = "";
  980. string merName = "";
  981. PosMerchantInfo mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  982. if (mer != null)
  983. {
  984. merInfo = mer.KqMerNo;
  985. merName = mer.MerchantName;
  986. }
  987. else
  988. {
  989. merInfo = "未找到商户";
  990. }
  991. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == pos.StoreId) ?? new StoreHouse();
  992. Users posUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  993. Users posSubUser = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new Users();
  994. int TopUserId = 0;
  995. if (!string.IsNullOrEmpty(posUser.ParentNav))
  996. {
  997. string[] ParentNavs = posUser.ParentNav.Trim(',').Replace(",,", ",").Split(',');
  998. if (ParentNavs.Length > 1)
  999. {
  1000. TopUserId = int.Parse(ParentNavs[1]);
  1001. }
  1002. if (ParentNavs.Length == 1)
  1003. {
  1004. TopUserId = int.Parse(ParentNavs[0]);
  1005. }
  1006. }
  1007. Users posTopUser = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
  1008. string bindResult = "", bindTime = "";
  1009. if (pos.BindingState == 0)
  1010. {
  1011. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerSnNo == pos.PosSn);
  1012. if (bind != null)
  1013. {
  1014. if (bind.Status != 1)
  1015. {
  1016. bindResult = "执行中";
  1017. }
  1018. }
  1019. else
  1020. {
  1021. bindResult = "未绑定";
  1022. }
  1023. }
  1024. else
  1025. {
  1026. bindResult = "已绑定";
  1027. bindTime = pos.BindingTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1028. }
  1029. string activeResult = "", activeTime = "";
  1030. if (pos.ActivationState == 0)
  1031. {
  1032. if (pos.CreditTrade < 1000)
  1033. {
  1034. activeResult = "未刷满1000";
  1035. }
  1036. else if (pos.TransferTime == null)
  1037. {
  1038. activeResult = "未激活, 需补录";
  1039. }
  1040. }
  1041. else
  1042. {
  1043. activeResult = "已激活";
  1044. activeTime = pos.ActivationTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1045. }
  1046. string tradeAmount = pos.CreditTrade.ToString();
  1047. decimal Deposit = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  1048. if (pos.BrandId != 2 && pos.BrandId != 7)
  1049. {
  1050. Deposit = Deposit / 100;
  1051. }
  1052. string DepositGet = "未领取";
  1053. string DepositUser = "";
  1054. string DepositToUser = "";
  1055. decimal headAmount = 0;
  1056. decimal footAmount = 0;
  1057. ActiveReward reward = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.RewardAmount != 40) ?? new ActiveReward();
  1058. if (reward.Id > 0)
  1059. {
  1060. Users user = db.Users.FirstOrDefault(m => m.Id == reward.UserId) ?? new Users();
  1061. DepositGet = "已领取";
  1062. DepositUser = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  1063. var fAmount = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.ActType == 0);
  1064. if (fAmount != null)
  1065. {
  1066. headAmount = fAmount.RewardAmount;
  1067. }
  1068. var lAmount = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.ActType == 1);
  1069. if (lAmount != null)
  1070. {
  1071. footAmount = lAmount.RewardAmount;
  1072. }
  1073. }
  1074. string DepositGet6 = "未领取";
  1075. string DepositUser6 = "";
  1076. ActiveReward lisreward = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.BrandId == 6 && m.RewardAmount == 40) ?? new ActiveReward();
  1077. if (lisreward.Id > 0)
  1078. {
  1079. Users user = db.Users.FirstOrDefault(m => m.Id == lisreward.UserId) ?? new Users();
  1080. DepositGet6 = "已领取";
  1081. DepositUser6 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  1082. }
  1083. string FluxGet6 = "未领取";
  1084. string FluxUser6 = "";
  1085. FluxProfitDetail flux = db.FluxProfitDetail.FirstOrDefault(m => m.SnNo == pos.PosSn) ?? new FluxProfitDetail();
  1086. if (flux.Id > 0)
  1087. {
  1088. Users user = db.Users.FirstOrDefault(m => m.Id == flux.UserId) ?? new Users();
  1089. FluxGet6 = "已领取(领取时间:" + flux.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
  1090. FluxUser6 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  1091. }
  1092. Users touser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  1093. DepositToUser = "创客编号:" + touser.MakerCode + ",姓名:" + touser.RealName + ",手机号:" + touser.Mobile;
  1094. string OpenUser10 = "未领取";
  1095. string OpenUser20 = "未领取";
  1096. var OpenRewardDetail = db.OpenRewardDetail.Where(m => m.SnNo == pos.PosSn).ToList();
  1097. OpenRewardDetail openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 20) ?? new OpenRewardDetail();
  1098. if (openreward.Id > 0)
  1099. {
  1100. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  1101. OpenUser20 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  1102. }
  1103. openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 10) ?? new OpenRewardDetail();
  1104. if (openreward.Id > 0)
  1105. {
  1106. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  1107. OpenUser10 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  1108. }
  1109. MachineApply apply = db.MachineApply.FirstOrDefault(m => m.SwapSnExpand.Contains(pos.PosSn)) ?? new MachineApply();
  1110. Orders applyorder = db.Orders.FirstOrDefault(m => m.Id == apply.QueryCount) ?? new Orders();
  1111. MachineChangeDetail change = db.MachineChangeDetail.FirstOrDefault(m => m.OutSnNo == pos.PosSn) ?? new MachineChangeDetail();
  1112. string RecycFlag = pos.IsPurchase == 1 ? "已申请循环" : "未申请循环";
  1113. string SendStatus = applyorder.SendStatus == 1 ? "已发货" : "未发货";
  1114. string ApplyDate = apply.CreateDate == null ? "" : apply.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1115. string SendDate = applyorder.SendDate == null ? "" : applyorder.SendDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1116. string CreateDate = pos.CreateDate == null ? "" : pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1117. string TransferTime = pos.TransferTime == null ? "" : pos.TransferTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1118. string RecycEndDate = pos.RecycEndDate == null ? "" : pos.RecycEndDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1119. string ActiveTime = reward.CreateDate == null ? "" : reward.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1120. string ActiveTime6 = lisreward.CreateDate == null ? "" : lisreward.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1121. string result = "";
  1122. result += "机具SN:" + pos.PosSn + "\n";
  1123. result += "商户编号:" + merInfo + ",商户姓名:" + merName + "\n";
  1124. result += "商户型机器/直拓机器:创客编号:" + posSubUser.MakerCode + ",姓名:" + posSubUser.RealName + ",手机号:" + posSubUser.Mobile + "\n";
  1125. if (change.Id > 0)
  1126. {
  1127. result += "换机来源机具SN:" + change.BackSnNo + "\n";
  1128. }
  1129. result += "机具所属人:创客编号:" + posUser.MakerCode + ",姓名:" + posUser.RealName + ",手机号:" + posUser.Mobile + "\n";
  1130. result += "机器持有人顶级:创客编号:" + posTopUser.MakerCode + ",姓名:" + posTopUser.RealName + ",手机号:" + posTopUser.Mobile + "\n";
  1131. result += "机器所属仓库:仓库编号:" + store.StoreNo + ",仓库名称:" + store.StoreName + "\n";
  1132. if (pos.PreUserId > 0)
  1133. {
  1134. Users smallStoreUser = db.Users.FirstOrDefault(m => m.Id == pos.PreUserId) ?? new Users();
  1135. PreSendStockDetail preSend = db.PreSendStockDetail.FirstOrDefault(m => m.SnId == pos.Id && m.ToUserId == pos.PreUserId && m.Status == 1) ?? new PreSendStockDetail();
  1136. string preSendDate = preSend.CreateDate == null ? "" : preSend.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1137. result += "机具所属小分仓:创客编号:" + smallStoreUser.MakerCode + ",姓名:" + smallStoreUser.RealName + ",手机号:" + smallStoreUser.Mobile + ",预发时间:" + preSendDate + "\n";
  1138. }
  1139. else
  1140. {
  1141. result += "机具所属小分仓:暂无小分仓\n";
  1142. }
  1143. result += "入库时间:" + CreateDate + "\n";
  1144. result += "循环到期时间:" + RecycEndDate + "\n";
  1145. result += "划拨时间:" + TransferTime + "\n";
  1146. result += "绑定状态:" + bindResult + "(绑定时间:" + bindTime + ")\n";
  1147. result += "激活状态:" + activeResult + "(激活时间:" + activeTime + ")\n";
  1148. result += "贷记卡(总)交易额:" + tradeAmount + "\n";
  1149. result += "是否循环:" + RecycFlag + ",申请循环时间:" + ApplyDate + "\n";
  1150. result += "申请循环后的SN:" + applyorder.SnNos + "\n";
  1151. result += "是否发货:" + SendStatus + ",发货时间:" + SendDate + "\n";
  1152. result += "押金:" + Deposit + "\n";
  1153. result += "是否返现:" + DepositGet + ",领取时间:" + ActiveTime + "\n";
  1154. result += "返现金额:" + headAmount + " " + " " + footAmount + "\n";//TODO: 添加返现金额和额外奖励
  1155. result += "押金返现应返现对象:" + DepositToUser + "\n";
  1156. result += "押金返现实际返现对象:" + DepositUser + "\n";
  1157. if (pos.BrandId == 6)
  1158. {
  1159. result += "立刷10000奖励:" + DepositGet6 + ",领取时间:" + ActiveTime6 + "\n";
  1160. result += "立刷10000奖励发放人:" + DepositUser6 + "\n";
  1161. }
  1162. result += "流量费:" + FluxGet6 + "\n";
  1163. result += "流量费发放对象:" + FluxUser6 + "\n";
  1164. result += "开机奖20:" + OpenUser20 + "\n";
  1165. result += "开机奖10:" + OpenUser10 + "\n";
  1166. return result;
  1167. }
  1168. //解析金控日志
  1169. // public decimal CheckLog(DateTime startDate, string PosSn)
  1170. // {
  1171. // bool op = true;
  1172. // decimal result = 0;
  1173. // DateTime today = DateTime.Now;
  1174. // int i = 0;
  1175. // while (op)
  1176. // {
  1177. // DateTime check = DateTime.Parse(startDate.ToString("yyyy-MM-dd") + " 00:00:00").AddDays(i);
  1178. // if (check <= today)
  1179. // {
  1180. // string source = function.GetWebRequest("http://sp.kexiaoshuang.com/api/test/GetLog?date=" + check.Year + "-" + check.Month + "-" + check.Day);
  1181. // MatchCollection mc = Regex.Matches(source, "{.*?2022年飞天系列-小宝电签.*?}"); //激活
  1182. // foreach (Match sub in mc)
  1183. // {
  1184. // string content = sub.Value;
  1185. // JsonData jsonObj = JsonMapper.ToObject(content);
  1186. // decimal serviceAmount = decimal.Parse(jsonObj["serviceAmount"].ToString());
  1187. // string posSnCheck = jsonObj["posSn"].ToString();
  1188. // if (posSnCheck == PosSn && serviceAmount > 0)
  1189. // {
  1190. // result = serviceAmount / 100;
  1191. // op = false;
  1192. // }
  1193. // }
  1194. // }
  1195. // else
  1196. // {
  1197. // op = false;
  1198. // }
  1199. // i += 1;
  1200. // }
  1201. // return result;
  1202. // }
  1203. #endregion
  1204. #region 生成机具兑换码
  1205. public IActionResult MakeCoupons(string right)
  1206. {
  1207. ViewBag.RightInfo = RightInfo;
  1208. ViewBag.right = right;
  1209. return View();
  1210. }
  1211. [HttpPost]
  1212. public string MakeCouponsDo(int Kind, int Number)
  1213. {
  1214. DateTime checkTime = DateTime.Parse("1900-01-01");
  1215. string checkTimeString = RedisDbconn.Instance.Get<string>("MakerCouponsQueueCheckTime");
  1216. if (!string.IsNullOrEmpty(checkTimeString))
  1217. {
  1218. checkTime = DateTime.Parse(checkTimeString);
  1219. }
  1220. if (checkTime.AddHours(1) < DateTime.Now)
  1221. {
  1222. RedisDbconn.Instance.Set("MakerCouponsQueueCheckTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  1223. RedisDbconn.Instance.AddList("MakerCouponsQueue:" + Kind, Number);
  1224. return "生成程序已执行";
  1225. }
  1226. return "请稍后再试";
  1227. }
  1228. #endregion
  1229. #region 导出没有刷满1000的机具
  1230. public IActionResult ExportPos(string right)
  1231. {
  1232. ViewBag.RightInfo = RightInfo;
  1233. ViewBag.right = right;
  1234. return View();
  1235. }
  1236. [HttpPost]
  1237. public JsonResult ExportPosDo()
  1238. {
  1239. WebCMSEntities db = new WebCMSEntities();
  1240. List<PosMachinesTwo> poses = db.PosMachinesTwo.Where(m => m.CreditTrade < 1000 && m.BindingState == 1).ToList();
  1241. int total = poses.Count;
  1242. int index = 0;
  1243. List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
  1244. foreach (PosMachinesTwo pos in poses)
  1245. {
  1246. index += 1;
  1247. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
  1248. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  1249. Users puser = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId) ?? new Users();
  1250. Users ppuser = db.Users.FirstOrDefault(m => m.Id == puser.ParentUserId) ?? new Users();
  1251. Dictionary<string, object> item = new Dictionary<string, object>();
  1252. string TopRealName = "";
  1253. string TopMakerCode = "";
  1254. string TopMobile = "";
  1255. string ParentNav = user.ParentNav;
  1256. if (!string.IsNullOrEmpty(ParentNav))
  1257. {
  1258. string[] navlist = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  1259. if (navlist.Length > 1)
  1260. {
  1261. int TopId = int.Parse(function.CheckInt(navlist[1]));
  1262. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopId) ?? new Users();
  1263. TopRealName = tuser.RealName;
  1264. TopMakerCode = tuser.MakerCode;
  1265. TopMobile = tuser.Mobile;
  1266. }
  1267. }
  1268. item.Add("TopRealName", TopRealName); //顶级姓名
  1269. item.Add("TopMakerCode", TopMakerCode); //顶级编号
  1270. item.Add("UpUpRealName", ppuser.RealName); //上上级姓名
  1271. item.Add("UpRealName", puser.RealName); //上级姓名
  1272. item.Add("RealName", user.RealName); //代理姓名
  1273. item.Add("MakerCode", user.MakerCode); //代理编号
  1274. item.Add("Mobile", user.Mobile); //代理手机号
  1275. item.Add("MerchantName", merchant.MerchantName); //客户姓名
  1276. item.Add("MerchantMobile", merchant.MerchantMobile); //客户电话
  1277. item.Add("OpenTime", pos.BindingTime == null ? "" : pos.BindingTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); //开机日期
  1278. item.Add("Sn", pos.PosSn); //SN
  1279. list.Add(item);
  1280. RedisDbconn.Instance.Set("ExportPosCheck", index + " / " + total);
  1281. }
  1282. db.Dispose();
  1283. Dictionary<string, object> result = new Dictionary<string, object>();
  1284. result.Add("Status", "1");
  1285. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  1286. result.Add("Obj", list);
  1287. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  1288. ReturnFields.Add("TopRealName", "顶级姓名"); //顶级姓名
  1289. ReturnFields.Add("TopMakerCode", "顶级编号"); //顶级编号
  1290. ReturnFields.Add("UpUpRealName", "上上级姓名"); //上上级姓名
  1291. ReturnFields.Add("UpRealName", "上级姓名"); //上级姓名
  1292. ReturnFields.Add("RealName", "代理姓名"); //代理姓名
  1293. ReturnFields.Add("MakerCode", "代理编号"); //代理编号
  1294. ReturnFields.Add("Mobile", "代理手机号"); //代理手机号
  1295. ReturnFields.Add("MerchantName", "客户姓名"); //客户姓名
  1296. ReturnFields.Add("MerchantMobile", "客户电话"); //客户电话
  1297. ReturnFields.Add("OpenTime", "开机日期"); //开机日期
  1298. ReturnFields.Add("Sn", "SN"); //SN
  1299. result.Add("Fields", ReturnFields);
  1300. RedisDbconn.Instance.Set("ExportPosCheck", "finish");
  1301. return Json(result);
  1302. }
  1303. public string ExportPosCheck()
  1304. {
  1305. string content = RedisDbconn.Instance.Get<string>("ExportPosCheck");
  1306. if (content == "finish")
  1307. {
  1308. RedisDbconn.Instance.Clear("ExportPosCheck");
  1309. }
  1310. return content;
  1311. }
  1312. #endregion
  1313. #region 更换机具
  1314. public IActionResult ChangePos(string right)
  1315. {
  1316. ViewBag.RightInfo = RightInfo;
  1317. ViewBag.right = right;
  1318. return View();
  1319. }
  1320. [HttpPost]
  1321. public string ChangePosDo(string OldSn, string NewSn, string BackStoreNo, string OutStoreNo, string MerNo = "", int IsSend = 0)
  1322. {
  1323. if (string.IsNullOrEmpty(OldSn))
  1324. {
  1325. return "请输入原机具SN";
  1326. }
  1327. if (string.IsNullOrEmpty(NewSn))
  1328. {
  1329. return "请输入新机具SN";
  1330. }
  1331. string[] OldSnList = OldSn.Split('\n');
  1332. string[] NewSnList = NewSn.Split('\n');
  1333. if (OldSnList.Length != NewSnList.Length)
  1334. {
  1335. return "原机具SN数量和新机具SN数量不一致";
  1336. }
  1337. WebCMSEntities db = new WebCMSEntities();
  1338. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == OldSn);
  1339. StoreForCode storeForBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  1340. StoreForCode storeForOut = db.StoreForCode.FirstOrDefault(m => m.Code == OutStoreNo) ?? new StoreForCode();
  1341. StoreHouse BackStore = db.StoreHouse.FirstOrDefault(m => m.Id == storeForBack.StoreId) ?? new StoreHouse();
  1342. StoreHouse OutStore = db.StoreHouse.FirstOrDefault(m => m.Id == storeForOut.StoreId) ?? new StoreHouse();
  1343. string ChangeNo = "BMC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(3);
  1344. KqProducts oldPosBrand = new KqProducts();
  1345. KqProducts newPosBrand = new KqProducts();
  1346. MachineChange add = db.MachineChange.Add(new MachineChange()
  1347. {
  1348. CreateDate = DateTime.Now,
  1349. UpdateDate = DateTime.Now,
  1350. CreateMan = SysUserName + "-" + SysRealName,
  1351. ChangeNo = ChangeNo, //转换单号
  1352. UserId = 0, //创客
  1353. ChangeTime = DateTime.Now, //转换时间
  1354. BackStoreId = BackStore.Id, //退回仓库
  1355. BackStoreName = BackStore.StoreName, //退回仓库名称
  1356. Remark = "机具更换", //订单备注
  1357. BackStoreUserId = BackStore.UserId, //退回仓库归属人
  1358. OutProductType = int.Parse(OutStore.BrandId), //出库产品类型
  1359. OutProductName = OutStore.ProductName, //出库产品名称
  1360. OutStoreId = OutStore.Id, //出库仓库
  1361. OutStoreName = OutStore.StoreName, //出库仓库名称
  1362. OutStoreAreas = OutStore.Areas, //出库仓库所在地区
  1363. OutStoreAddress = OutStore.Address, //出库仓库地址
  1364. OutStoreManager = "", //出库仓库联系人
  1365. OutStoreManagerMobile = OutStore.ManageMobile, //出库仓库联系人手机号
  1366. }).Entity;
  1367. db.SaveChanges();
  1368. int BackProductType = 0;
  1369. string BackProductName = "";
  1370. string ChangeDeviceName = "";
  1371. string ChangeSnExpand = "";
  1372. for (int i = 0; i < OldSnList.Length; i++)
  1373. {
  1374. string OldSnNum = OldSnList[i];
  1375. string NewSnNum = NewSnList[i];
  1376. MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  1377. MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
  1378. PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId);
  1379. if (oldpos == null)
  1380. {
  1381. return "原机具SN不正确";
  1382. }
  1383. // if (oldpos.BindingState != 1)
  1384. // {
  1385. // return "原机具未绑定";
  1386. // }
  1387. PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId);
  1388. if (newpos == null)
  1389. {
  1390. return "新机具SN不正确";
  1391. }
  1392. oldPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1393. newPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == newpos.BrandId) ?? new KqProducts();
  1394. PosMerchantInfo merchant = new PosMerchantInfo();
  1395. if (!string.IsNullOrEmpty(MerNo))
  1396. {
  1397. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo) ?? new PosMerchantInfo();
  1398. }
  1399. else
  1400. {
  1401. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == oldpos.BindMerchantId) ?? new PosMerchantInfo();
  1402. }
  1403. newpos.BindMerchantId = merchant.Id;
  1404. newpos.BuyUserId = oldpos.BuyUserId;
  1405. newpos.UserId = oldpos.UserId;
  1406. newpos.RecycEndDate = oldpos.RecycEndDate;
  1407. newpos.ScanQrTrade = oldpos.ScanQrTrade;
  1408. newpos.DebitCardTrade = oldpos.DebitCardTrade;
  1409. newpos.CreditTrade = oldpos.CreditTrade;
  1410. newpos.PosSnType = oldpos.PosSnType;
  1411. newpos.TransferTime = oldpos.TransferTime;
  1412. newpos.IsPurchase = oldpos.IsPurchase;
  1413. newpos.BindingState = oldpos.BindingState;
  1414. newpos.ActivationState = oldpos.ActivationState;
  1415. newpos.BindingTime = oldpos.BindingTime;
  1416. newpos.ActivationTime = oldpos.ActivationTime;
  1417. newpos.IsFirst = oldpos.IsFirst;
  1418. // bool checkActReward = db.ActiveReward.Any(m => m.KqMerNo == merchant.KqMerNo);
  1419. // if (!checkActReward)
  1420. // {
  1421. newpos.SeoKeyword = oldpos.SeoKeyword;
  1422. newpos.PrizeParams = oldpos.PrizeParams;
  1423. newpos.LeaderUserId = oldpos.LeaderUserId;
  1424. // }
  1425. // oldpos.BuyUserId = 0;
  1426. // oldpos.UserId = 0;
  1427. oldpos.Status = -1;
  1428. //对应调整客小爽企业版数据
  1429. var posInfo = db.BusinessPartnerPos.FirstOrDefault(m => m.PosId == oldpos.Id);
  1430. if (posInfo != null)
  1431. {
  1432. posInfo.PosSn = newpos.PosSn;
  1433. posInfo.PosId = newpos.Id;
  1434. db.SaveChanges();
  1435. }
  1436. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == merchant.KqMerNo);
  1437. if (forMerNo != null)
  1438. {
  1439. forMerNo.SnId = newpos.Id;
  1440. }
  1441. merchant.KqSnNo = NewSn;
  1442. db.MachineChangeDetail.Add(new MachineChangeDetail()
  1443. {
  1444. CreateDate = DateTime.Now,
  1445. UpdateDate = DateTime.Now,
  1446. CreateMan = SysUserName + "-" + SysRealName,
  1447. ChangeNo = ChangeNo, //订单号
  1448. ChangeId = add.Id, //订单Id
  1449. BackProductType = oldpos.BrandId, //退回产品类型
  1450. BackProductName = oldPosBrand.Name, //退回产品名称
  1451. UserId = 0, //创客
  1452. BackSnNo = oldpos.PosSn, //设备SN编号
  1453. OutProductType = newpos.BrandId, //出库产品类型
  1454. OutProductName = newPosBrand.Name, //出库产品名称
  1455. OutSnNo = newpos.PosSn, //出库设备SN编号
  1456. OutSnType = newpos.PosSnType, //出库SN机具类型
  1457. Remark = "机具更换", //备注
  1458. BackSnType = oldpos.PosSnType, //退回SN机具类型
  1459. });
  1460. db.SaveChanges();
  1461. BackProductType = oldpos.BrandId;
  1462. BackProductName = newPosBrand.Name;
  1463. ChangeDeviceName = oldpos.DeviceName;
  1464. ChangeSnExpand += oldpos.PosSn + "\n";
  1465. PublicFunction.SycnMachineCount(oldpos.BuyUserId, oldpos.BrandId);
  1466. }
  1467. add.BackProductType = BackProductType; //退回产品类型
  1468. add.BackProductName = BackProductName; //退回产品名称
  1469. add.ChangeDeviceName = ChangeDeviceName; //转换机具名称
  1470. add.ChangeDeviceNum = OldSnList.Length; //转换机具数量
  1471. add.ChangeSnExpand = ChangeSnExpand; //机具SN
  1472. BackStore.LaveNum += OldSnList.Length; //退回仓库库存
  1473. OutStore.LaveNum -= OldSnList.Length; //出货仓库库存
  1474. db.SaveChanges();
  1475. db.Dispose();
  1476. if (IsSend == 1)
  1477. {
  1478. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  1479. {
  1480. UserId = pos.BuyUserId, //接收创客
  1481. MsgType = 2,
  1482. Title = "换绑成功通知", //标题
  1483. Summary = "您的 " + oldPosBrand.Name + " SN:" + OldSn + "已经成功为客户换绑为" + newPosBrand.Name + "SN:" + NewSn + "请告知客户进行绑定。",
  1484. CreateDate = DateTime.Now,
  1485. }));
  1486. }
  1487. return "success";
  1488. }
  1489. #endregion
  1490. #region 坏机换新
  1491. public IActionResult ChangeBadPos(string right)
  1492. {
  1493. ViewBag.RightInfo = RightInfo;
  1494. ViewBag.right = right;
  1495. return View();
  1496. }
  1497. [HttpPost]
  1498. public string ChangeBadPosDo(string ChangeType, string MakerCode, string StoreCode, string OldSn, string NewSn, string FromStoreNo, string BackStoreNo, int IsSend = 0)
  1499. {
  1500. string[] OldSnList;
  1501. string[] NewSnList;
  1502. decimal amount = 0;
  1503. //创客坏机换新
  1504. if (ChangeType == "0")
  1505. {
  1506. if (string.IsNullOrEmpty(MakerCode))
  1507. {
  1508. return "请输入创客编号";
  1509. }
  1510. if (string.IsNullOrEmpty(OldSn))
  1511. {
  1512. return "请输入坏机SN";
  1513. }
  1514. if (string.IsNullOrEmpty(NewSn))
  1515. {
  1516. return "请输入新机SN";
  1517. }
  1518. if (string.IsNullOrEmpty(FromStoreNo))
  1519. {
  1520. return "请输入新机发货仓库编号";
  1521. }
  1522. if (string.IsNullOrEmpty(BackStoreNo))
  1523. {
  1524. return "请输入坏机退回仓库编号";
  1525. }
  1526. OldSnList = OldSn.Split('\n');
  1527. NewSnList = NewSn.Split('\n');
  1528. if (OldSnList.Length != NewSnList.Length)
  1529. {
  1530. return "原机具SN数量和新机具SN数量不一致";
  1531. }
  1532. for (int i = 0; i < OldSnList.Length; i++)
  1533. {
  1534. string OldSnNum = OldSnList[i];
  1535. string NewSnNum = NewSnList[i];
  1536. UserForMakerCode userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
  1537. StoreForCode storeForCodeFrom = db.StoreForCode.FirstOrDefault(m => m.Code == FromStoreNo) ?? new StoreForCode();
  1538. if (storeForCodeFrom.StoreId == 0)
  1539. {
  1540. return "您输入的新机发货仓库编号不存在";
  1541. }
  1542. StoreForCode storeForCodeBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  1543. if (storeForCodeBack.StoreId == 0)
  1544. {
  1545. return "您输入的坏机退回仓库编号不存在";
  1546. }
  1547. MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  1548. MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
  1549. PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId && m.BindingState == 0 && m.BuyUserId == userForMakerCode.UserId) ?? new PosMachinesTwo();
  1550. if (oldpos.Id == 0)
  1551. {
  1552. return "您输入的坏机SN不存在或者不在" + MakerCode + "名下";
  1553. }
  1554. PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId && m.BindingState == 0) ?? new PosMachinesTwo();
  1555. if (newpos.Id == 0)
  1556. {
  1557. return "您输入的新机SN不存在";
  1558. }
  1559. StoreHouse storeFrom = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeFrom.StoreId);
  1560. if (Convert.ToInt32(storeFrom.BrandId) != Convert.ToInt32(newpos.BrandId))
  1561. {
  1562. return "您输入的新机发货仓库不符新机机具对应品牌";
  1563. }
  1564. if (newpos.StoreId != storeFrom.Id)
  1565. {
  1566. return "您输入的新机SN不在新机发货仓库";
  1567. }
  1568. StoreHouse storeBack = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeBack.StoreId);
  1569. if (Convert.ToInt32(storeBack.BrandId) != Convert.ToInt32(oldpos.BrandId))
  1570. {
  1571. return "您输入的坏机退回仓库不符坏机机具对应品牌";
  1572. }
  1573. if (Convert.ToInt32(storeBack.BrandId) != Convert.ToInt32(storeFrom.BrandId))
  1574. {
  1575. return "您输入的新机发货仓库和坏机退回仓库品牌类型不同";
  1576. }
  1577. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1578. if (brandInfo.Name.Contains("大POS"))
  1579. {
  1580. amount = 300;
  1581. }
  1582. if (brandInfo.Name.Contains("电签"))
  1583. {
  1584. amount = 200;
  1585. }
  1586. // var storeUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == store.UserId) ?? new UserAccount();
  1587. var storeFromUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeFrom.UserId) ?? new UserAccount();
  1588. var storeBackUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeBack.UserId) ?? new UserAccount();
  1589. // storeUserAcount.ValidAmount += amount;
  1590. storeFromUserAcount.ValidAmount += amount;
  1591. storeBackUserAcount.ValidAmount -= amount;
  1592. newpos.BuyUserId = oldpos.BuyUserId;
  1593. newpos.UserId = oldpos.UserId;
  1594. newpos.RecycEndDate = oldpos.RecycEndDate;
  1595. newpos.ScanQrTrade = oldpos.ScanQrTrade;
  1596. newpos.DebitCardTrade = oldpos.DebitCardTrade;
  1597. newpos.CreditTrade = oldpos.CreditTrade;
  1598. newpos.PosSnType = oldpos.PosSnType;
  1599. newpos.TransferTime = oldpos.TransferTime;
  1600. newpos.IsPurchase = oldpos.IsPurchase;
  1601. newpos.BindingState = oldpos.BindingState;
  1602. newpos.ActivationState = oldpos.ActivationState;
  1603. newpos.BindingTime = oldpos.BindingTime;
  1604. newpos.ActivationTime = oldpos.ActivationTime;
  1605. newpos.IsFirst = oldpos.IsFirst;
  1606. newpos.SeoKeyword = oldpos.SeoKeyword;
  1607. newpos.PrizeParams = oldpos.PrizeParams;
  1608. newpos.LeaderUserId = oldpos.LeaderUserId;
  1609. newpos.BindMerchantId = oldpos.BindMerchantId;
  1610. newpos.StoreId = oldpos.StoreId;
  1611. newpos.UserId = oldpos.UserId;
  1612. newpos.PreUserId = oldpos.PreUserId;
  1613. oldpos.StoreId = storeBack.Id;
  1614. oldpos.BuyUserId = 0;
  1615. oldpos.UserId = 0;
  1616. oldpos.Status = -1;
  1617. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == newpos.BindMerchantId);
  1618. if (merchant != null)
  1619. {
  1620. merchant.KqSnNo = newpos.PosSn;
  1621. merchant.ActiveStatus = newpos.ActivationState;
  1622. }
  1623. db.SaveChanges();
  1624. BrokenMachineChange add = db.BrokenMachineChange.Add(new BrokenMachineChange()
  1625. {
  1626. CreateDate = DateTime.Now,
  1627. CreateMan = SysUserName + "-" + SysRealName,
  1628. ChangeNo = "BPC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(3), //转换单号
  1629. OutStoreId = storeFrom.Id,
  1630. BackStoreId = storeBack.Id,
  1631. OutProductType = newpos.BrandId,
  1632. BackProductType = oldpos.BrandId,
  1633. UserId = userForMakerCode.UserId, //创客
  1634. }).Entity;
  1635. db.SaveChanges();
  1636. BrokenMachineChangeDetail adds = db.BrokenMachineChangeDetail.Add(new BrokenMachineChangeDetail()
  1637. {
  1638. CreateDate = DateTime.Now,
  1639. CreateMan = SysUserName + "-" + SysRealName,
  1640. OutSnNo = OldSnNum,
  1641. BackSnNo = NewSnNum,
  1642. ChangeNo = add.ChangeNo, //转换单号
  1643. ChangeId = add.Id, //转换记录Id
  1644. UserId = add.UserId, //创客
  1645. }).Entity;
  1646. db.SaveChanges();
  1647. var oldPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1648. if (IsSend == 1)
  1649. {
  1650. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  1651. {
  1652. UserId = userForMakerCode.UserId, //接收创客
  1653. MsgType = 2,
  1654. Title = "坏机换新成功通知", //标题
  1655. Summary = "您的坏机 " + oldPosBrand.Name + " SN:" + OldSnNum + "已经成功为您换为" + oldPosBrand.Name + "SN:" + NewSnNum + "。",
  1656. CreateDate = DateTime.Now,
  1657. }));
  1658. }
  1659. }
  1660. }
  1661. //仓库坏机换新
  1662. else
  1663. {
  1664. if (string.IsNullOrEmpty(StoreCode))
  1665. {
  1666. return "请输入仓库编号";
  1667. }
  1668. if (string.IsNullOrEmpty(OldSn))
  1669. {
  1670. return "请输入坏机SN";
  1671. }
  1672. if (string.IsNullOrEmpty(NewSn))
  1673. {
  1674. return "请输入新机SN";
  1675. }
  1676. if (string.IsNullOrEmpty(FromStoreNo))
  1677. {
  1678. return "请输入新机发货仓库编号";
  1679. }
  1680. if (string.IsNullOrEmpty(BackStoreNo))
  1681. {
  1682. return "请输入坏机退回仓库编号";
  1683. }
  1684. OldSnList = OldSn.Split('\n');
  1685. NewSnList = NewSn.Split('\n');
  1686. if (OldSnList.Length != NewSnList.Length)
  1687. {
  1688. return "原机具SN数量和新机具SN数量不一致";
  1689. }
  1690. for (int i = 0; i < OldSnList.Length; i++)
  1691. {
  1692. string OldSnNum = OldSnList[i];
  1693. string NewSnNum = NewSnList[i];
  1694. StoreHouse store = new StoreHouse();
  1695. StoreForCode storeForBadCode = db.StoreForCode.FirstOrDefault(m => m.Code == StoreCode) ?? new StoreForCode();
  1696. if (storeForBadCode.StoreId > 0)
  1697. {
  1698. store = db.StoreHouse.FirstOrDefault(m => m.Id == storeForBadCode.StoreId);
  1699. }
  1700. StoreForCode storeForCodeFrom = db.StoreForCode.FirstOrDefault(m => m.Code == FromStoreNo) ?? new StoreForCode();
  1701. if (storeForCodeFrom.StoreId == 0)
  1702. {
  1703. return "您输入的新机发货仓库编号不存在";
  1704. }
  1705. StoreForCode storeForCodeBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  1706. if (storeForCodeBack.StoreId == 0)
  1707. {
  1708. return "您输入的坏机退回仓库编号不存在";
  1709. }
  1710. MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  1711. MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
  1712. PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId && m.BindingState == 0 && m.StoreId == storeForBadCode.StoreId) ?? new PosMachinesTwo();
  1713. if (oldpos.Id == 0)
  1714. {
  1715. return "您输入的坏机SN不存在或者不在仓库" + StoreCode + "中";
  1716. }
  1717. PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId && m.BindingState == 0) ?? new PosMachinesTwo();
  1718. if (newpos.Id == 0)
  1719. {
  1720. return "您输入的新机SN不存在";
  1721. }
  1722. StoreHouse storeFrom = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeFrom.StoreId);
  1723. if (Convert.ToInt32(storeFrom.BrandId) != Convert.ToInt32(oldpos.BrandId))
  1724. {
  1725. return "您输入的新机发货仓库不符新机机具对应品牌";
  1726. }
  1727. if (newpos.StoreId != storeFrom.Id)
  1728. {
  1729. return "您输入的新机SN不在新机发货仓库";
  1730. }
  1731. StoreHouse storeBack = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeBack.StoreId);
  1732. if (Convert.ToInt32(storeBack.BrandId) != Convert.ToInt32(oldpos.BrandId))
  1733. {
  1734. return "您输入的坏机退回仓库不符坏机机具对应品牌";
  1735. }
  1736. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1737. if (brandInfo.Name.Contains("大POS"))
  1738. {
  1739. amount = 300;
  1740. }
  1741. if (brandInfo.Name.Contains("电签"))
  1742. {
  1743. amount = 200;
  1744. }
  1745. var storeUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == store.UserId) ?? new UserAccount();
  1746. var storeFromUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeFrom.UserId) ?? new UserAccount();
  1747. var storeBackUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeBack.UserId) ?? new UserAccount();
  1748. // storeUserAcount.ValidAmount += amount;
  1749. storeFromUserAcount.ValidAmount += amount;
  1750. storeBackUserAcount.ValidAmount -= amount;
  1751. newpos.StoreId = oldpos.StoreId;
  1752. newpos.BuyUserId = oldpos.BuyUserId;
  1753. newpos.UserId = oldpos.UserId;
  1754. newpos.LeaderUserId = oldpos.LeaderUserId;
  1755. newpos.PreUserId = oldpos.PreUserId;
  1756. newpos.IsFirst = oldpos.IsFirst;
  1757. newpos.TransferTime = oldpos.TransferTime;
  1758. oldpos.StoreId = storeBack.Id;
  1759. oldpos.BuyUserId = 0;
  1760. oldpos.UserId = 0;
  1761. oldpos.Status = -1;
  1762. db.SaveChanges();
  1763. BrokenMachineChange add = db.BrokenMachineChange.Add(new BrokenMachineChange()
  1764. {
  1765. CreateDate = DateTime.Now,
  1766. CreateMan = SysUserName + "-" + SysRealName,
  1767. ChangeNo = "BPC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(3), //转换单号
  1768. OutStoreId = storeFrom.Id,
  1769. BackStoreId = storeBack.Id,
  1770. OutProductType = newpos.BrandId,
  1771. BackProductType = oldpos.BrandId,
  1772. UserId = store.UserId, //创客
  1773. }).Entity;
  1774. db.SaveChanges();
  1775. BrokenMachineChangeDetail adds = db.BrokenMachineChangeDetail.Add(new BrokenMachineChangeDetail()
  1776. {
  1777. CreateDate = DateTime.Now,
  1778. CreateMan = SysUserName + "-" + SysRealName,
  1779. OutSnNo = OldSnNum,
  1780. BackSnNo = NewSnNum,
  1781. ChangeNo = add.ChangeNo, //转换单号
  1782. ChangeId = add.Id, //转换记录Id
  1783. UserId = add.UserId, //创客
  1784. }).Entity;
  1785. db.SaveChanges();
  1786. var oldPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1787. if (IsSend == 1)
  1788. {
  1789. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  1790. {
  1791. UserId = store.UserId, //接收创客
  1792. MsgType = 2,
  1793. Title = "坏机换新成功通知", //标题
  1794. Summary = "您的坏机 " + oldPosBrand.Name + " SN:" + OldSnNum + "已经成功为您换为" + oldPosBrand.Name + "SN:" + NewSnNum + "。",
  1795. CreateDate = DateTime.Now,
  1796. }));
  1797. }
  1798. }
  1799. }
  1800. // for (int i = 0; i < OldSnList.Length; i++)
  1801. // {
  1802. // string OldSnNum = OldSnList[i];
  1803. // string NewSnNum = NewSnList[i];
  1804. // StoreForCode storeForCode = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  1805. // MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  1806. // MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
  1807. // StoreHouse oldStore = new StoreHouse();
  1808. // PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId && m.BindingState == 0);
  1809. // if (storeForCode.StoreId > 0)
  1810. // {
  1811. // StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCode.StoreId);
  1812. // if (Convert.ToInt32(store.BrandId) != Convert.ToInt32(oldpos.BrandId))
  1813. // {
  1814. // return "您输入的仓库不符机具对应品牌";
  1815. // }
  1816. // oldStore = db.StoreHouse.FirstOrDefault(m => m.Id == oldpos.StoreId);
  1817. // oldpos.Status = -1;
  1818. // oldpos.StoreId = store.Id;
  1819. // }
  1820. // if (oldpos == null)
  1821. // {
  1822. // return "原机具SN不正确或者不符合换机条件";
  1823. // }
  1824. // PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId && m.BuyUserId == 0 && m.UserId == 0 && m.BindingState == 0);
  1825. // if (newpos == null)
  1826. // {
  1827. // return "新机具SN不正确或者不为仓库机";
  1828. // }
  1829. // if (oldpos.BrandId != newpos.BrandId)
  1830. // {
  1831. // return "新机具和旧机具品牌不相同";
  1832. // }
  1833. // var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == newpos.BrandId) ?? new KqProducts();
  1834. // if (brandInfo.Name.Contains("大POS"))
  1835. // {
  1836. // amount = 300;
  1837. // }
  1838. // if (brandInfo.Name.Contains("电签"))
  1839. // {
  1840. // amount = 200;
  1841. // }
  1842. // var storehouse = db.StoreHouse.FirstOrDefault(m => m.Id == newpos.StoreId) ?? new StoreHouse();
  1843. // storehouse.LaveNum -= 1;
  1844. // var userAcount = db.UserAccount.FirstOrDefault(m => m.Id == storehouse.UserId) ?? new UserAccount();
  1845. // if (oldpos.StoreId != newpos.StoreId)
  1846. // {
  1847. // userAcount.ValidAmount += amount;
  1848. // newpos.StoreId = oldpos.StoreId;
  1849. // newpos.BuyUserId = oldpos.BuyUserId;
  1850. // newpos.UserId = oldpos.UserId;
  1851. // newpos.LeaderUserId = oldpos.LeaderUserId;
  1852. // newpos.PreUserId = oldpos.PreUserId;
  1853. // newpos.IsFirst = oldpos.IsFirst;
  1854. // newpos.TransferTime = oldpos.TransferTime;
  1855. // }
  1856. // else
  1857. // {
  1858. // newpos.BuyUserId = oldpos.BuyUserId;
  1859. // newpos.UserId = oldpos.UserId;
  1860. // newpos.LeaderUserId = oldpos.LeaderUserId;
  1861. // newpos.PreUserId = oldpos.PreUserId;
  1862. // newpos.IsFirst = oldpos.IsFirst;
  1863. // newpos.TransferTime = oldpos.TransferTime;
  1864. // }
  1865. // db.SaveChanges();
  1866. // var oldPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1867. // var newPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == newpos.BrandId) ?? new KqProducts();
  1868. // var UserId = 0;
  1869. // if (oldpos.BuyUserId == 0)
  1870. // {
  1871. // UserId = oldStore.UserId;
  1872. // }
  1873. // else
  1874. // {
  1875. // UserId = oldpos.BuyUserId;
  1876. // }
  1877. // BrokenMachineChange add = db.BrokenMachineChange.Add(new BrokenMachineChange()
  1878. // {
  1879. // CreateDate = DateTime.Now,
  1880. // CreateMan = SysUserName + "-" + SysRealName,
  1881. // ChangeNo = "BPC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(3), //转换单号
  1882. // UserId = UserId, //创客
  1883. // }).Entity;
  1884. // db.SaveChanges();
  1885. // BrokenMachineChangeDetail adds = db.BrokenMachineChangeDetail.Add(new BrokenMachineChangeDetail()
  1886. // {
  1887. // CreateDate = DateTime.Now,
  1888. // CreateMan = SysUserName + "-" + SysRealName,
  1889. // OutSnNo = OldSnNum,
  1890. // BackSnNo = NewSnNum,
  1891. // ChangeNo = add.ChangeNo, //转换单号
  1892. // ChangeId = add.Id, //转换记录Id
  1893. // UserId = add.UserId, //创客
  1894. // }).Entity;
  1895. // db.SaveChanges();
  1896. // if (IsSend == 1)
  1897. // {
  1898. // RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  1899. // {
  1900. // UserId = UserId, //接收创客
  1901. // MsgType = 2,
  1902. // Title = "坏机换新成功通知", //标题
  1903. // Summary = "您的坏机 " + oldPosBrand.Name + " SN:" + OldSn + "已经成功为您换为" + newPosBrand.Name + "SN:" + NewSn + "。",
  1904. // CreateDate = DateTime.Now,
  1905. // }));
  1906. // }
  1907. // }
  1908. return "success";
  1909. }
  1910. #endregion
  1911. #region 机具解绑
  1912. public IActionResult Unbind(string right)
  1913. {
  1914. ViewBag.RightInfo = RightInfo;
  1915. ViewBag.right = right;
  1916. return View();
  1917. }
  1918. [HttpPost]
  1919. public string UnbindDo(string PosSn, string MakerCode, string MerNo, int IsSend = 0)
  1920. {
  1921. if (string.IsNullOrEmpty(PosSn))
  1922. {
  1923. return "请输入机具SN";
  1924. }
  1925. if (string.IsNullOrEmpty(MakerCode))
  1926. {
  1927. return "请输入创客编号";
  1928. }
  1929. MachineForSnNo forSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn);
  1930. if (forSnNo == null)
  1931. {
  1932. return "机具SN不存在";
  1933. }
  1934. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == forSnNo.SnId);
  1935. if (pos == null)
  1936. {
  1937. return "机具SN不存在";
  1938. }
  1939. if (string.IsNullOrEmpty(MerNo) && pos.BrandId != 1 && pos.BrandId != 3)
  1940. {
  1941. return "请输入商户编号";
  1942. }
  1943. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  1944. if (forMakerCode == null)
  1945. {
  1946. return "创客不存在";
  1947. }
  1948. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == MerNo);
  1949. if (forMerNo == null && pos.BrandId != 1 && pos.BrandId != 3)
  1950. {
  1951. return "商户编号不存在";
  1952. }
  1953. if (pos.BuyUserId != forMakerCode.UserId)
  1954. {
  1955. return "机具SN和创客不匹配";
  1956. }
  1957. if (pos.ActivationState == 1)
  1958. {
  1959. return "机具已激活,不能解绑";
  1960. }
  1961. if (pos.BuyUserId == 0)
  1962. {
  1963. return "机具是仓库机,不支持解绑";
  1964. }
  1965. if (pos.BindingState == 0)
  1966. {
  1967. return "机具未绑定,不支持解绑";
  1968. }
  1969. if (pos.BindingTime < DateTime.Now.AddDays(-30) && SysUserName != "admin")
  1970. {
  1971. return "机具绑定已超过30天,不支持解绑";
  1972. }
  1973. if (forMerNo != null)
  1974. {
  1975. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  1976. if (merchant != null)
  1977. {
  1978. //机具解绑删除客小爽企业版对应数据
  1979. var merInfo = db.BusinessPartnerMerchant.FirstOrDefault(m => m.MerchantId == merchant.Id);
  1980. if (merInfo != null)
  1981. {
  1982. db.BusinessPartnerMerchant.Remove(merInfo);
  1983. }
  1984. var posInfo = db.BusinessPartnerPos.FirstOrDefault(m => m.PosId == pos.Id);
  1985. if (posInfo != null)
  1986. {
  1987. db.BusinessPartnerPos.Remove(posInfo);
  1988. }
  1989. db.PosMerchantInfo.Remove(merchant);
  1990. }
  1991. db.MachineForMerNo.Remove(forMerNo);
  1992. db.SaveChanges();
  1993. }
  1994. db.MachineUnBind.Add(new MachineUnBind()
  1995. {
  1996. CreateDate = DateTime.Now,
  1997. SeoTitle = SysUserName + "-" + SysRealName,
  1998. MerchantId = pos.BindMerchantId,
  1999. AuditDate = DateTime.Now,
  2000. AuditDesc = "平台操作解绑",
  2001. AuditStatus = 1,
  2002. SnNo = pos.PosSn,
  2003. BrandId = pos.BrandId,
  2004. UserId = pos.BuyUserId,
  2005. ApplyNo = "U" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8),
  2006. });
  2007. pos.BindMerchantId = 0;
  2008. pos.BindingState = 0;
  2009. pos.BindingTime = DateTime.Parse("1900-01-01");
  2010. pos.UserId = pos.BuyUserId;
  2011. string IdBrand = pos.BuyUserId + "_" + pos.BrandId;
  2012. db.SaveChanges();
  2013. PublicFunction.SycnMachineCount(pos.BuyUserId, pos.BrandId);
  2014. if (IsSend == 1)
  2015. {
  2016. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  2017. {
  2018. UserId = pos.BuyUserId, //接收创客
  2019. MsgType = 2,
  2020. Title = "解绑成功通知", //标题
  2021. Summary = "" + PosSn + "机具已成功解绑,当前机具如需绑定同一客户请再2个工作日后再进行绑定,直接绑定会导致数控异常,相关损失由您本人承担。",
  2022. CreateDate = DateTime.Now,
  2023. }));
  2024. }
  2025. return "success";
  2026. }
  2027. #endregion
  2028. #region 通过券码修改盟主标记
  2029. public IActionResult ChangeSignQuan(string right)
  2030. {
  2031. ViewBag.RightInfo = RightInfo;
  2032. ViewBag.right = right;
  2033. return View();
  2034. }
  2035. [HttpPost]
  2036. public string ChangeSignQuanDo(string Coupons, string MakerCode)
  2037. {
  2038. if (string.IsNullOrEmpty(Coupons))
  2039. {
  2040. return "请输入机具券码,多个券码用回车分隔";
  2041. }
  2042. if (string.IsNullOrEmpty(MakerCode))
  2043. {
  2044. return "请输入创客编号";
  2045. }
  2046. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  2047. if (forMakerCode == null)
  2048. {
  2049. return "创客不存在";
  2050. }
  2051. string[] SnList = Coupons.Split('\n');
  2052. foreach (var item in SnList)
  2053. {
  2054. var coupos = db.PosCoupons.FirstOrDefault(m => m.ExchangeCode == item && m.LeaderUserId == 0);
  2055. if (coupos == null)
  2056. {
  2057. return "机具券不存在";
  2058. }
  2059. else
  2060. {
  2061. coupos.LeaderUserId = forMakerCode.UserId;
  2062. }
  2063. }
  2064. db.SaveChanges();
  2065. return "success";
  2066. }
  2067. #endregion
  2068. #region 通过机具SN修改盟主标记
  2069. public IActionResult ChangeSignSn(string right)
  2070. {
  2071. ViewBag.RightInfo = RightInfo;
  2072. ViewBag.right = right;
  2073. return View();
  2074. }
  2075. [HttpPost]
  2076. public string ChangeSignSnDo(string PosSn, string MakerCode)
  2077. {
  2078. if (string.IsNullOrEmpty(PosSn))
  2079. {
  2080. return "请输入机具SN,多个SN用回车分隔";
  2081. }
  2082. if (string.IsNullOrEmpty(MakerCode))
  2083. {
  2084. return "请输入创客编号";
  2085. }
  2086. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  2087. if (forMakerCode == null)
  2088. {
  2089. return "创客不存在";
  2090. }
  2091. string[] SnList = PosSn.Split('\n');
  2092. foreach (var item in SnList)
  2093. {
  2094. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == item && m.LeaderUserId == 0);
  2095. if (pos == null)
  2096. {
  2097. return "该机具不存在";
  2098. }
  2099. else
  2100. {
  2101. pos.LeaderUserId = forMakerCode.UserId;
  2102. }
  2103. }
  2104. db.SaveChanges();
  2105. return "success";
  2106. }
  2107. #endregion
  2108. #region 机具循环列表
  2109. /// <summary>
  2110. /// 根据条件查询机具循环列表
  2111. /// </summary>
  2112. /// <returns></returns>
  2113. public IActionResult Loop(string right, string SwapSnExpand, string SnNos)
  2114. {
  2115. ViewBag.RightInfo = RightInfo;
  2116. ViewBag.right = right;
  2117. ViewBag.SwapSnExpand = SwapSnExpand;
  2118. ViewBag.SnNos = SnNos;
  2119. return View();
  2120. }
  2121. #endregion
  2122. #region 根据条件查询机具循环列表
  2123. /// <summary>
  2124. /// 机具循环列表
  2125. /// </summary>
  2126. /// <returns></returns>
  2127. public IActionResult LoopData(string SwapSnExpand, string SnNos, int page = 1, int limit = 30)
  2128. {
  2129. Dictionary<string, string> Fields = new Dictionary<string, string>();
  2130. Fields.Add("SwapSnExpand", "1"); //申请机具SN
  2131. Fields.Add("SnNos", "1"); //发货机具SN
  2132. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  2133. if (!string.IsNullOrEmpty(SwapSnExpand))
  2134. {
  2135. var apply = db.MachineApply.FirstOrDefault(m => m.Status > -1 && m.SwapSnExpand.Contains(SwapSnExpand)) ?? new MachineApply();
  2136. var order = db.Orders.FirstOrDefault(m => m.Id == apply.QueryCount) ?? new Orders();
  2137. var user = db.Users.FirstOrDefault(m => m.Id == apply.UserId) ?? new Users();
  2138. string[] SnNoList = function.CheckNull(apply.SwapSnExpand).TrimEnd('\n').Split('\n');
  2139. string[] OrderSnNo = function.CheckNull(order.SnNos).Split(',');
  2140. for (int i = 0; i < SnNoList.Length; i++)
  2141. {
  2142. Dictionary<string, object> data = new Dictionary<string, object>();
  2143. data["ApplyNo"] = apply.ApplyNo;
  2144. data["OrderNo"] = order.OrderNo;
  2145. data["MakerCode"] = user.MakerCode;
  2146. data["RealName"] = user.RealName;
  2147. if (SnNoList.Length > i)
  2148. {
  2149. string SourceSn = SnNoList[i].Split(':')[0];
  2150. data["ComeSn"] = SnNoList[i];
  2151. data["ComeSnParam"] = SourceSn;
  2152. MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SourceSn) ?? new MachineForSnNo();
  2153. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
  2154. if (pos.LeaderUserId > 0)
  2155. {
  2156. Users leader = db.Users.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new Users();
  2157. data["ComeSnMakerCode"] = leader.MakerCode;
  2158. data["ComeSnRealName"] = leader.RealName;
  2159. }
  2160. }
  2161. if (OrderSnNo.Length > i)
  2162. {
  2163. string SendSn = OrderSnNo[i];
  2164. data["SendSn"] = OrderSnNo[i];
  2165. MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SendSn) ?? new MachineForSnNo();
  2166. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
  2167. if (pos.LeaderUserId > 0)
  2168. {
  2169. Users leader = db.Users.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new Users();
  2170. data["SendSnMakerCode"] = leader.MakerCode;
  2171. data["SendSnRealName"] = leader.RealName;
  2172. }
  2173. }
  2174. data["CreateDate"] = apply.CreateDate == null ? "" : apply.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  2175. data["Status"] = order.Status == 2 ? "已发货" : "未发货";
  2176. dataList.Add(data);
  2177. }
  2178. }
  2179. else if (!string.IsNullOrEmpty(SnNos))
  2180. {
  2181. var order = db.Orders.FirstOrDefault(m => m.Status > -1 && m.SnNos.Contains(SnNos)) ?? new Orders();
  2182. var apply = db.MachineApply.FirstOrDefault(m => m.Id == order.Sort) ?? new MachineApply();
  2183. var user = db.Users.FirstOrDefault(m => m.Id == apply.UserId) ?? new Users();
  2184. string[] SnNoList = function.CheckNull(apply.SwapSnExpand).TrimEnd('\n').Split('\n');
  2185. string[] OrderSnNo = function.CheckNull(order.SnNos).Split(',');
  2186. for (int i = 0; i < OrderSnNo.Length; i++)
  2187. {
  2188. Dictionary<string, object> data = new Dictionary<string, object>();
  2189. data["ApplyNo"] = apply.ApplyNo;
  2190. data["OrderNo"] = order.OrderNo;
  2191. data["MakerCode"] = user.MakerCode;
  2192. data["RealName"] = user.RealName;
  2193. if (SnNoList.Length > i)
  2194. {
  2195. string SourceSn = SnNoList[i].Split(':')[0];
  2196. data["ComeSn"] = SnNoList[i];
  2197. data["ComeSnParam"] = SourceSn;
  2198. MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SourceSn) ?? new MachineForSnNo();
  2199. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
  2200. if (pos.LeaderUserId > 0)
  2201. {
  2202. Users leader = db.Users.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new Users();
  2203. data["ComeSnMakerCode"] = leader.MakerCode;
  2204. data["ComeSnRealName"] = leader.RealName;
  2205. }
  2206. }
  2207. if (OrderSnNo.Length > i)
  2208. {
  2209. string SendSn = OrderSnNo[i];
  2210. data["SendSn"] = OrderSnNo[i];
  2211. MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SendSn) ?? new MachineForSnNo();
  2212. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
  2213. if (pos.LeaderUserId > 0)
  2214. {
  2215. Users leader = db.Users.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new Users();
  2216. data["SendSnMakerCode"] = leader.MakerCode;
  2217. data["SendSnRealName"] = leader.RealName;
  2218. }
  2219. }
  2220. data["CreateDate"] = apply.CreateDate == null ? "" : apply.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  2221. data["Status"] = order.Status == 2 ? "已发货" : "未发货";
  2222. dataList.Add(data);
  2223. }
  2224. }
  2225. Dictionary<string, object> obj = new Dictionary<string, object>();
  2226. obj.Add("code", 0);
  2227. obj.Add("msg", "");
  2228. obj.Add("count", dataList.Count);
  2229. obj.Add("data", dataList);
  2230. return Json(obj);
  2231. }
  2232. #endregion
  2233. #region 查询创客直推奖
  2234. public IActionResult Prize100(string right)
  2235. {
  2236. ViewBag.RightInfo = RightInfo;
  2237. ViewBag.right = right;
  2238. return View();
  2239. }
  2240. [HttpPost]
  2241. public Dictionary<string, string> Prize100Do(string MakerCode)
  2242. {
  2243. Dictionary<string, string> dic = new Dictionary<string, string>();
  2244. string result = "";
  2245. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  2246. if (forMakerCode == null)
  2247. {
  2248. result += "创客编号不存在\n";
  2249. dic.Add("code", "1");
  2250. dic.Add("result", result);
  2251. return dic;
  2252. }
  2253. int OrderCount = db.Orders.Count(m => m.UserId == forMakerCode.UserId && m.PayStatus == 1 && m.TotalPrice == 600);
  2254. if (OrderCount == 0)
  2255. {
  2256. result += "该创客未下单\n";
  2257. dic.Add("code", "1");
  2258. dic.Add("result", result);
  2259. return dic;
  2260. }
  2261. if (OrderCount > 1)
  2262. {
  2263. result += "该创客已不是首笔下单\n";
  2264. dic.Add("code", "1");
  2265. dic.Add("result", result);
  2266. return dic;
  2267. }
  2268. Orders order = db.Orders.FirstOrDefault(m => m.UserId == forMakerCode.UserId && m.PayStatus == 1 && m.TotalPrice == 600) ?? new Orders();
  2269. if (order.PayStatus < 1)
  2270. {
  2271. result += "未付款\n";
  2272. dic.Add("code", "1");
  2273. dic.Add("result", result);
  2274. return dic;
  2275. }
  2276. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId) ?? new Users();
  2277. Users puser = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId) ?? new Users();
  2278. result += "订单号:" + order.OrderNo + "\n";
  2279. result += "下单创客\n创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile + "\n";
  2280. result += "上级创客\n创客编号:" + puser.MakerCode + ",姓名:" + puser.RealName + ",手机号:" + puser.Mobile + "\n";
  2281. int machineCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.PosSnType == 0); //判断是否拥有3台购买机
  2282. int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  2283. if (machineCount + ActiveCount >= 3)
  2284. {
  2285. string IsGet = "未发放";
  2286. int ToUserId = 0;
  2287. UserAccountRecord item = db.UserAccountRecord.FirstOrDefault(m => m.QueryCount == order.Id && m.ChangeType == 112);
  2288. if (item == null)
  2289. {
  2290. DateTime start = order.PayDate.Value.AddMinutes(-2);
  2291. DateTime end = order.PayDate.Value.AddMinutes(2);
  2292. item = db.UserAccountRecord.FirstOrDefault(m => m.UserId == puser.Id && m.ChangeType == 112 && m.ChangeAmount == 100 && m.CreateDate >= start && m.CreateDate <= end);
  2293. }
  2294. if (item != null)
  2295. {
  2296. IsGet = "已发放(发放时间:" + item.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
  2297. ToUserId = item.UserId;
  2298. dic.Add("code", "1");
  2299. }
  2300. else
  2301. {
  2302. dic.Add("id", order.Id.ToString());
  2303. dic.Add("code", "0");
  2304. }
  2305. Users touser = db.Users.FirstOrDefault(m => m.Id == ToUserId) ?? new Users();
  2306. result += "是否发放:" + IsGet + "\n";
  2307. result += "应该发放对象\n创客编号:" + puser.MakerCode + ",姓名:" + puser.RealName + ",手机号:" + puser.Mobile + "\n";
  2308. result += "实际发放对象\n创客编号:" + touser.MakerCode + ",姓名:" + touser.RealName + ",手机号:" + touser.Mobile + "\n";
  2309. }
  2310. else
  2311. {
  2312. result += "上级创客未满足条件\n购买机:" + machineCount + "台,激活机:" + ActiveCount + "台\n";
  2313. dic.Add("code", "1");
  2314. }
  2315. dic.Add("result", result);
  2316. return dic;
  2317. }
  2318. public string AddPrize100(int Id)
  2319. {
  2320. Orders order = db.Orders.FirstOrDefault(m => m.Id == Id);
  2321. if (order != null)
  2322. {
  2323. //机具券逻辑
  2324. OrderProduct pro = db.OrderProduct.FirstOrDefault(m => m.OrderId == Id);
  2325. if (pro != null)
  2326. {
  2327. //推荐下单奖励
  2328. if (pro.ProductId == 10 || pro.ProductId == 11)
  2329. {
  2330. int OrderId = order.Id;
  2331. bool checkPrize = db.UserAccountRecord.Any(m => m.QueryCount == OrderId && m.ChangeType == 112);
  2332. if (!checkPrize)
  2333. {
  2334. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId);
  2335. if (user != null)
  2336. {
  2337. bool directPrize = false; //直推奖标记
  2338. int ParentUserId = user.ParentUserId;
  2339. // List<int> proids = new List<int>();
  2340. // proids.Add(10);
  2341. // proids.Add(11);
  2342. while (ParentUserId > 0)
  2343. {
  2344. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  2345. int machineCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.PosSnType == 0); //判断是否拥有3台购买机
  2346. int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  2347. int couponCount = db.PosCoupons.Count(m => m.UserId == ParentUserId && m.IsUse == 0); //判断是否拥有3张券
  2348. if ((machineCount + ActiveCount + couponCount >= 3 || puser.LeaderLevel > 0) && !directPrize)
  2349. {
  2350. DirectPrize(db, order.Id, ParentUserId, pro.ProductCount);
  2351. directPrize = true;
  2352. db.SaveChanges();
  2353. return "发放成功";
  2354. }
  2355. ParentUserId = puser.ParentUserId;
  2356. }
  2357. }
  2358. }
  2359. return "已发放,请勿重复发放";
  2360. }
  2361. }
  2362. }
  2363. return "操作失败";
  2364. }
  2365. public void DirectPrize(WebCMSEntities db, int OrderId, int UserId, int Count = 1)
  2366. {
  2367. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId);
  2368. if (account == null)
  2369. {
  2370. account = db.UserAccount.Add(new UserAccount()
  2371. {
  2372. Id = UserId,
  2373. UserId = UserId,
  2374. }).Entity;
  2375. db.SaveChanges();
  2376. }
  2377. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  2378. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  2379. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  2380. account.BalanceAmount += 100 * Count;
  2381. account.TotalAmount += 100 * Count;
  2382. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  2383. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  2384. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  2385. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  2386. {
  2387. CreateDate = DateTime.Now,
  2388. UpdateDate = DateTime.Now,
  2389. UserId = UserId, //创客
  2390. ChangeType = 112, //变动类型
  2391. ChangeAmount = 100 * Count, //变更金额
  2392. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  2393. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  2394. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  2395. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  2396. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  2397. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  2398. QueryCount = OrderId,
  2399. }).Entity;
  2400. db.SaveChanges();
  2401. }
  2402. #endregion
  2403. #region 查询机具开机奖
  2404. public IActionResult OpenPrize(string right)
  2405. {
  2406. ViewBag.RightInfo = RightInfo;
  2407. ViewBag.right = right;
  2408. return View();
  2409. }
  2410. [HttpPost]
  2411. public Dictionary<string, string> OpenPrizeDo(string PosSn)
  2412. {
  2413. Dictionary<string, string> dic = new Dictionary<string, string>();
  2414. string result = "";
  2415. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  2416. if (pos == null)
  2417. {
  2418. result += "机具SN号不存在\n";
  2419. dic.Add("code", "1");
  2420. dic.Add("result", result);
  2421. return dic;
  2422. }
  2423. if (pos.BindingState == 0)
  2424. {
  2425. result += "机具未绑定\n";
  2426. dic.Add("code", "1");
  2427. dic.Add("result", result);
  2428. return dic;
  2429. }
  2430. if (pos.ActivationState == 0)
  2431. {
  2432. result += "机具未激活\n";
  2433. dic.Add("code", "1");
  2434. dic.Add("result", result);
  2435. return dic;
  2436. }
  2437. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  2438. if (merchant == null)
  2439. {
  2440. result += "商户不存在\n";
  2441. dic.Add("code", "1");
  2442. dic.Add("result", result);
  2443. return dic;
  2444. }
  2445. Users buyuser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  2446. result += "机具号:" + PosSn + "\n";
  2447. result += "机具所属人:\n创客编号:" + buyuser.MakerCode + ",姓名:" + buyuser.RealName + ",手机号:" + buyuser.Mobile + "\n";
  2448. result += "商户信息\n商户编号:" + merchant.KqMerNo + ",姓名:" + merchant.MerchantName + ",手机号:" + merchant.MerchantMobile + "\n";
  2449. string OpenUser10 = "未领取";
  2450. string OpenUser20 = "未领取";
  2451. var OpenRewardDetail = db.OpenRewardDetail.Where(m => m.SnNo == pos.PosSn).ToList();
  2452. OpenRewardDetail openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 20) ?? new OpenRewardDetail();
  2453. if (openreward.Id > 0)
  2454. {
  2455. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  2456. OpenUser20 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  2457. }
  2458. openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 10) ?? new OpenRewardDetail();
  2459. if (openreward.Id > 0)
  2460. {
  2461. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  2462. OpenUser10 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  2463. }
  2464. result += "开机奖20:" + OpenUser20 + "\n";
  2465. result += "开机奖10:" + OpenUser10 + "\n";
  2466. dic.Add("id", pos.Id.ToString());
  2467. dic.Add("code", "0");
  2468. dic.Add("result", result);
  2469. return dic;
  2470. }
  2471. public string AddOpenPrize(int Id)
  2472. {
  2473. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Id && m.ActivationState == 1);
  2474. if (pos == null)
  2475. {
  2476. return "机具未激活";
  2477. }
  2478. if (pos.BindingTime < DateTime.Now.AddDays(-30))
  2479. {
  2480. return "绑定已超过30天";
  2481. }
  2482. decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  2483. if (ActPrize == 0)
  2484. {
  2485. return "机具无押金";
  2486. }
  2487. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  2488. if (merchant == null)
  2489. {
  2490. return "商户不存在";
  2491. }
  2492. bool check = db.OpenRewardDetail.Any(m => m.SnNo == pos.PosSn);
  2493. if (check)
  2494. {
  2495. return "开机奖励已发放,请勿重复操作";
  2496. }
  2497. // 从机具所属人上级开始分开机奖励
  2498. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId);
  2499. if (user != null)
  2500. {
  2501. if (!string.IsNullOrEmpty(user.ParentNav))
  2502. {
  2503. decimal Prize = 20;
  2504. List<string> PrizeFlag = new List<string>();
  2505. string[] ParentNavs = user.ParentNav.Trim(',').Replace(",,", ",").Split(',');
  2506. for (int i = ParentNavs.Length - 1; i >= 0; i--)
  2507. {
  2508. int UserId = int.Parse(ParentNavs[i]);
  2509. Users puser = db.Users.FirstOrDefault(m => m.Id == UserId && m.AuthFlag == 1);
  2510. if (puser != null && Prize > 0)
  2511. {
  2512. int machineCount = db.PosMachinesTwo.Count(m => m.BuyUserId == puser.Id && m.PosSnType == 0); //判断是否拥有3台购买机
  2513. int ActiveCount = db.PosMachinesTwo.Count(m => m.BuyUserId == puser.Id && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  2514. int couponCount = db.PosCoupons.Count(m => m.UserId == puser.Id && m.IsUse == 0); //判断是否拥有3张券
  2515. if (machineCount + ActiveCount + couponCount >= 3)
  2516. {
  2517. int pTopUserId = 0;
  2518. if (!string.IsNullOrEmpty(puser.ParentNav))
  2519. {
  2520. pTopUserId = int.Parse(puser.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  2521. }
  2522. Users machineUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  2523. OpenRewardDetail detail = db.OpenRewardDetail.Add(new OpenRewardDetail()
  2524. {
  2525. CreateDate = DateTime.Now,
  2526. UpdateDate = DateTime.Now,
  2527. TradeMonth = DateTime.Now.ToString("yyyyMM"), //交易月
  2528. TradeDate = pos.ActivationTime, //达标日期
  2529. UserId = puser.Id, //创客
  2530. BrandId = pos.BrandId, //品牌
  2531. ProductName = RelationClass.GetKqProductBrandInfo(pos.BrandId), //产品名称
  2532. MerchantId = pos.BindMerchantId, //商户
  2533. DirectUserId = merchant.UserId, //商户直属人
  2534. SnNo = pos.PosSn, //SN号
  2535. MerNo = merchant.KqMerNo, //渠道商户号
  2536. SnType = pos.PosSnType, //机具类型
  2537. StandardDate = pos.ActivationTime, //商户的激活日期
  2538. SnStoreId = pos.StoreId, //SN仓库
  2539. MerBuddyType = puser.MerchantType, //商户创客类型
  2540. RewardType = 1, //奖励类型 1-开机直接奖励,2-开机间接奖励
  2541. RewardTips = "开机奖励", //奖励描述
  2542. CreditTradeAmt = pos.CreditTrade, //贷记卡交易总金额
  2543. DebitTradeAmt = pos.DebitCardTrade, //借记卡交易总金额
  2544. CreditRewardAmount = Prize, //贷记卡交易奖励金额
  2545. RewardDesc = "开机奖励", //奖励描述
  2546. TopUserId = pTopUserId, //顶级创客
  2547. SeoTitle = machineUser.RealName,
  2548. }).Entity;
  2549. db.OpenReward.Add(new OpenReward()
  2550. {
  2551. CreateDate = DateTime.Now,
  2552. UpdateDate = DateTime.Now,
  2553. TradeMonth = DateTime.Now.ToString("yyyyMM"), //交易月
  2554. TradeDate = DateTime.Now, //达标日期
  2555. UserId = puser.Id, //创客
  2556. BrandId = pos.BrandId, //品牌
  2557. RewardType = 2, //奖励类型
  2558. CreditTradeAmt = pos.CreditTrade, //贷记卡交易总金额
  2559. DebitTradeAmt = pos.DebitCardTrade, //借记卡交易总金额
  2560. CreditRewardAmount = Prize, //贷记卡交易奖励金额
  2561. RewardDesc = "开机奖励", //奖励描述
  2562. TopUserId = pTopUserId, //顶级创客
  2563. });
  2564. string IdBrand = puser.Id + "_" + pos.BrandId;
  2565. UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
  2566. if (userData == null)
  2567. {
  2568. userData = db.UserMachineData.Add(new UserMachineData()
  2569. {
  2570. IdBrand = IdBrand,
  2571. }).Entity;
  2572. db.SaveChanges();
  2573. }
  2574. userData.OpenProfit += Prize;
  2575. db.SaveChanges();
  2576. //账户入库
  2577. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id);
  2578. if (account == null)
  2579. {
  2580. account = db.UserAccount.Add(new UserAccount()
  2581. {
  2582. Id = puser.Id,
  2583. UserId = puser.Id,
  2584. }).Entity;
  2585. db.SaveChanges();
  2586. }
  2587. //收支明细入库
  2588. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  2589. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  2590. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  2591. account.BalanceAmount += Prize;
  2592. account.TotalAmount += Prize;
  2593. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  2594. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  2595. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  2596. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  2597. {
  2598. CreateDate = DateTime.Now,
  2599. UpdateDate = DateTime.Now,
  2600. UserId = puser.Id, //创客
  2601. ChangeType = 50, //变动类型
  2602. ProductType = pos.BrandId, //产品类型
  2603. ChangeAmount = Prize, //变更金额
  2604. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  2605. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  2606. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  2607. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  2608. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  2609. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  2610. }).Entity;
  2611. db.SaveChanges();
  2612. RedisDbconn.Instance.Set("UserAccount:" + puser.Id, account);
  2613. string dateString = DateTime.Now.ToString("yyyyMMdd");
  2614. string monthString = DateTime.Now.ToString("yyyyMM");
  2615. // 开机奖励列表
  2616. List<string> dates = RedisDbconn.Instance.GetList<string>("OpenRewardDay:" + puser.Id + ":" + pos.BrandId);
  2617. if (!dates.Contains(dateString))
  2618. {
  2619. RedisDbconn.Instance.AddList("OpenRewardDay:" + puser.Id + ":" + pos.BrandId, dateString);
  2620. }
  2621. RedisDbconn.Instance.AddNumber("OpenRewardAmt:" + puser.Id + ":" + pos.BrandId + ":" + dateString, Prize);
  2622. List<string> months = RedisDbconn.Instance.GetList<string>("OpenRewardMonth:" + puser.Id + ":" + pos.BrandId);
  2623. if (!months.Contains(monthString))
  2624. {
  2625. RedisDbconn.Instance.AddList("OpenRewardMonth:" + puser.Id + ":" + pos.BrandId, monthString);
  2626. }
  2627. RedisDbconn.Instance.AddNumber("OpenRewardAmt:" + puser.Id + ":" + pos.BrandId + ":" + monthString, Prize);
  2628. // 开机奖励详情
  2629. RedisDbconn.Instance.AddList("OpenRewardDetail:" + puser.Id + ":" + pos.BrandId + ":" + dateString, detail);
  2630. //收支明细
  2631. RedisDbconn.Instance.AddList("UserAccountRecord:" + puser.Id + ":1:" + monthString, userAccountRecord);
  2632. RedisDbconn.Instance.AddNumber("UserAccount:" + puser.Id + ":1:" + monthString, Prize);
  2633. Prize -= 10;
  2634. PrizeFlag.Add(Prize.ToString("f0"));
  2635. }
  2636. }
  2637. }
  2638. string result = "";
  2639. if (!PrizeFlag.Contains("20"))
  2640. {
  2641. result += "20元奖励未发,请检查上级是否满足条件\n";
  2642. }
  2643. if (!PrizeFlag.Contains("10"))
  2644. {
  2645. result += "10元奖励未发,请检查上级是否满足条件\n";
  2646. }
  2647. if (string.IsNullOrEmpty(result))
  2648. {
  2649. return "发放成功";
  2650. }
  2651. return result;
  2652. }
  2653. }
  2654. db.Dispose();
  2655. return "操作失败";
  2656. }
  2657. #endregion
  2658. #region 查询机具流量费分佣
  2659. public IActionResult FluxPrize(string right)
  2660. {
  2661. ViewBag.RightInfo = RightInfo;
  2662. ViewBag.right = right;
  2663. return View();
  2664. }
  2665. [HttpPost]
  2666. public Dictionary<string, string> FluxPrizeDo(string PosSn)
  2667. {
  2668. Dictionary<string, string> dic = new Dictionary<string, string>();
  2669. string result = "";
  2670. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  2671. if (pos == null)
  2672. {
  2673. result += "机具SN号不存在\n";
  2674. dic.Add("code", "1");
  2675. dic.Add("result", result);
  2676. return dic;
  2677. }
  2678. if (pos.BindingState == 0)
  2679. {
  2680. result += "机具未绑定\n";
  2681. dic.Add("code", "1");
  2682. dic.Add("result", result);
  2683. return dic;
  2684. }
  2685. if (pos.ActivationState == 0)
  2686. {
  2687. result += "机具未激活\n";
  2688. dic.Add("code", "1");
  2689. dic.Add("result", result);
  2690. return dic;
  2691. }
  2692. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  2693. if (merchant == null)
  2694. {
  2695. result += "商户不存在\n";
  2696. dic.Add("code", "1");
  2697. dic.Add("result", result);
  2698. return dic;
  2699. }
  2700. Users buyuser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  2701. result += "机具号:" + PosSn + "\n";
  2702. result += "机具所属人:\n创客编号:" + buyuser.MakerCode + ",姓名:" + buyuser.RealName + ",手机号:" + buyuser.Mobile + "\n";
  2703. result += "商户信息\n商户编号:" + merchant.KqMerNo + ",姓名:" + merchant.MerchantName + ",手机号:" + merchant.MerchantMobile + "\n";
  2704. string FluxGet6 = "未领取";
  2705. string FluxUser6 = "";
  2706. FluxProfitDetail flux = db.FluxProfitDetail.FirstOrDefault(m => m.SnNo == pos.PosSn) ?? new FluxProfitDetail();
  2707. if (flux.Id > 0)
  2708. {
  2709. Users user = db.Users.FirstOrDefault(m => m.Id == flux.UserId) ?? new Users();
  2710. FluxGet6 = "已领取(领取时间:" + flux.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
  2711. FluxUser6 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  2712. }
  2713. result += "流量费:" + FluxGet6 + "\n";
  2714. result += "流量费发放对象:" + FluxUser6 + "\n";
  2715. dic.Add("id", pos.Id.ToString());
  2716. dic.Add("code", "0");
  2717. dic.Add("result", result);
  2718. return dic;
  2719. }
  2720. public string AddFluxPrize(int Id)
  2721. {
  2722. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Id && m.ActivationState == 1);
  2723. if (pos == null)
  2724. {
  2725. return "机具未激活";
  2726. }
  2727. if (pos.BindingTime < DateTime.Now.AddDays(-30))
  2728. {
  2729. return "绑定已超过30天";
  2730. }
  2731. decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  2732. if (ActPrize == 0)
  2733. {
  2734. return "机具无押金";
  2735. }
  2736. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  2737. if (merchant == null)
  2738. {
  2739. return "商户不存在";
  2740. }
  2741. if (pos.BrandId == 6)
  2742. {
  2743. return "立刷不支持流量费分佣";
  2744. }
  2745. if (decimal.Parse(function.CheckNum(pos.SeoKeyword)) <= 0)
  2746. {
  2747. return "无押金机,不支持流量费分佣";
  2748. }
  2749. bool check = db.FluxProfitDetail.Any(m => m.MerNo == merchant.KqMerNo);
  2750. if (check)
  2751. {
  2752. return "开机奖励已发放,请勿重复操作";
  2753. }
  2754. SpModels.TradeFluxRecord trade = spdb.TradeFluxRecord.FirstOrDefault(m => m.TradeSnNo == pos.PosSn);
  2755. if (trade != null)
  2756. {
  2757. try
  2758. {
  2759. string OrderNo = trade.TradeSerialNo; //单号
  2760. DateTime TradeDate = trade.CreateDate.Value;
  2761. string TradeMonth = TradeDate.ToString("yyyyMM");
  2762. decimal FeeAmount = trade.FeeAmount; //流量费
  2763. if (trade.ProductType == "1" || trade.ProductType == "4" || trade.ProductType == "6" || trade.ProductType == "8" || trade.ProductType == "9")
  2764. {
  2765. FeeAmount = FeeAmount / 100;
  2766. }
  2767. string TradeSnNo = trade.TradeSnNo; //机具SN
  2768. decimal FluxProfit = 0;
  2769. if (trade.ProductType == "1" && FeeAmount == 60)
  2770. {
  2771. FluxProfit = 24;
  2772. }
  2773. else if (trade.ProductType == "7" && FeeAmount == 46)
  2774. {
  2775. FluxProfit = 10;
  2776. }
  2777. else if (trade.ProductType != "1" && FeeAmount == 48)
  2778. {
  2779. FluxProfit = 12;
  2780. }
  2781. if (FluxProfit > 0)
  2782. {
  2783. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  2784. int GetUserId = user.Id;
  2785. int TopUserId = 0;
  2786. string ParentNav = user.ParentNav;
  2787. if (!string.IsNullOrEmpty(ParentNav))
  2788. {
  2789. string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  2790. if (ParentNavList.Length > 1)
  2791. {
  2792. TopUserId = int.Parse(ParentNavList[1]);
  2793. }
  2794. else if (ParentNavList.Length == 1)
  2795. {
  2796. TopUserId = int.Parse(ParentNavList[0]);
  2797. }
  2798. }
  2799. FluxProfitSummary fluxProfit = db.FluxProfitSummary.FirstOrDefault(m => m.UserId == GetUserId && m.BrandId == pos.BrandId && m.TradeMonth == TradeMonth);
  2800. if (fluxProfit == null)
  2801. {
  2802. fluxProfit = db.FluxProfitSummary.Add(new FluxProfitSummary()
  2803. {
  2804. CreateDate = DateTime.Now,
  2805. UpdateDate = DateTime.Now,
  2806. UserId = GetUserId, //创客
  2807. BrandId = pos.BrandId,
  2808. TopUserId = TopUserId, //顶级创客
  2809. TradeMonth = TradeMonth, //交易月
  2810. MerUserType = user.MerchantType, //商户创客类型
  2811. Remark = "流量卡分佣", //备注
  2812. }).Entity;
  2813. db.SaveChanges();
  2814. }
  2815. fluxProfit.FluxProfitAmt += FluxProfit; //流量分润总金额
  2816. db.FluxProfitDetail.Add(new FluxProfitDetail()
  2817. {
  2818. CreateDate = DateTime.Now,
  2819. UpdateDate = DateTime.Now,
  2820. RecordNo = OrderNo, //单号
  2821. TradeDate = TradeDate.ToString("yyyyMMdd"), //交易日期
  2822. TradeTime = TradeDate.ToString("HHmmss"), //交易时间
  2823. TradeMonth = TradeMonth, //交易月
  2824. UserId = GetUserId, //创客
  2825. MerchantId = pos.BindMerchantId, //商户
  2826. MerchantUserId = pos.UserId, //商户直属人
  2827. MerNo = merchant.KqMerNo, //渠道商户编号
  2828. SnNo = pos.PosSn, //渠道SN号
  2829. FluxOrderNo = OrderNo, //流量扣费单号
  2830. TradeOrderNo = OrderNo, //交易流水号
  2831. TradeAmt = trade.TradeAmount, //商户交易额
  2832. FluxFeeAmt = FeeAmount, //流量费
  2833. FluxProfitAmt = FluxProfit, //流量分润总金额
  2834. PosType = pos.PosSnType.ToString(), //POS类型
  2835. Remark = "流量卡分佣", //备注
  2836. BrandId = pos.BrandId, //品牌
  2837. TopUserId = TopUserId, //顶级创客
  2838. MerUserType = user.MerchantType, //商户创客类型
  2839. });
  2840. string IdBrand = user.Id + "_" + pos.BrandId;
  2841. UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
  2842. if (userData == null)
  2843. {
  2844. userData = db.UserMachineData.Add(new UserMachineData()
  2845. {
  2846. IdBrand = IdBrand,
  2847. }).Entity;
  2848. db.SaveChanges();
  2849. }
  2850. userData.FluxProfit += FluxProfit;
  2851. db.SaveChanges();
  2852. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == GetUserId);
  2853. if (account == null)
  2854. {
  2855. account = db.UserAccount.Add(new UserAccount()
  2856. {
  2857. Id = GetUserId,
  2858. UserId = GetUserId,
  2859. }).Entity;
  2860. db.SaveChanges();
  2861. }
  2862. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  2863. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  2864. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  2865. account.BalanceAmount += FluxProfit;
  2866. account.TotalAmount += FluxProfit;
  2867. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  2868. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  2869. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  2870. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  2871. {
  2872. CreateDate = DateTime.Now,
  2873. UpdateDate = DateTime.Now,
  2874. UserId = GetUserId, //创客
  2875. ChangeType = 60, //变动类型
  2876. ProductType = pos.BrandId, //产品类型
  2877. ChangeAmount = FluxProfit, //变更金额
  2878. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  2879. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  2880. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  2881. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  2882. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  2883. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  2884. }).Entity;
  2885. db.SaveChanges();
  2886. spdb.Dispose();
  2887. db.Dispose();
  2888. return "发放成功";
  2889. }
  2890. }
  2891. catch (Exception ex)
  2892. {
  2893. function.WriteLog(DateTime.Now.ToString() + "\n$" + trade.Id + "$\n" + ex.ToString(), "流量卡分佣异常");
  2894. }
  2895. }
  2896. spdb.Dispose();
  2897. db.Dispose();
  2898. return "操作失败";
  2899. }
  2900. #endregion
  2901. #region 设置立刷费率
  2902. public IActionResult LisFee(string right)
  2903. {
  2904. ViewBag.RightInfo = RightInfo;
  2905. ViewBag.right = right;
  2906. return View();
  2907. }
  2908. [HttpPost]
  2909. public string LisFeeDo(string PosSns, decimal Fee, string Kind, string Fix)
  2910. {
  2911. if (string.IsNullOrEmpty(PosSns))
  2912. {
  2913. return "请输入机具号";
  2914. }
  2915. string result = SysUserName + "设置\n";
  2916. string[] PosSnList = PosSns.Split('\n');
  2917. int total = PosSnList.Length;
  2918. int index = 0;
  2919. foreach (string SubPosSn in PosSnList)
  2920. {
  2921. index += 1;
  2922. string PosSn = SubPosSn.Replace("\r", "");
  2923. result += PosSn + ":" + Fee + "\n";
  2924. if (Kind == "M5")
  2925. {
  2926. result += SetLiSFee(PosSn, Fee) + "\n";
  2927. }
  2928. else if (Kind == "N1")
  2929. {
  2930. result += SetLiSDeposit(PosSn, (int)Fee);
  2931. }
  2932. RedisDbconn.Instance.Set("LisFeeProcess:" + SysId, index + " / " + total);
  2933. }
  2934. result += "\n\n";
  2935. function.WriteLog(result, "设置立刷费率");
  2936. return result;
  2937. }
  2938. public string LisFeeProcess()
  2939. {
  2940. return RedisDbconn.Instance.Get<string>("LisFeeProcess:" + SysId);
  2941. }
  2942. #region 立刷
  2943. string LiSAgentId = "50814834";
  2944. 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=";
  2945. string LiSReqUrl = "https://openapi.jlpay.com/access/charge/"; //请求url
  2946. public string LiSSign(string data)
  2947. {
  2948. var rsa = RSA.Create();
  2949. var key = Convert.FromBase64String(LiSPrivateKey);
  2950. var content = Encoding.UTF8.GetBytes(data);
  2951. rsa.ImportPkcs8PrivateKey(key, out _);
  2952. var result = rsa.SignData(content, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  2953. return Convert.ToBase64String(result);
  2954. }
  2955. // 设置费率
  2956. public string SetLiSFee(string sn, decimal serviceFee)
  2957. {
  2958. Dictionary<string, object> dic = new Dictionary<string, object>();
  2959. dic.Add("agentId", LiSAgentId);
  2960. dic.Add("deviceSn", sn);
  2961. List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
  2962. Dictionary<string, object> item = new Dictionary<string, object>();
  2963. item.Add("feeCalcType", "M5");
  2964. item.Add("fixed", "0");
  2965. item.Add("rate", serviceFee);
  2966. feeList.Add(item);
  2967. dic.Add("feeList", feeList);
  2968. dic.Add("signMethod", "02");
  2969. string content = LiSAgentId + sn + "M50" + serviceFee + "02";
  2970. string signstr = LiSSign(content);
  2971. dic.Add("signData", signstr);
  2972. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  2973. string result = function.PostWebRequest(LiSReqUrl + "FEE003", req, new Dictionary<string, string>(), "application/json");
  2974. return result;
  2975. }
  2976. // 设置押金
  2977. public string SetLiSDeposit(string sn, int serviceFee)
  2978. {
  2979. serviceFee = serviceFee * 100;
  2980. Dictionary<string, object> dic = new Dictionary<string, object>();
  2981. dic.Add("agentId", LiSAgentId);
  2982. dic.Add("deviceSn", sn);
  2983. List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
  2984. Dictionary<string, object> item = new Dictionary<string, object>();
  2985. item.Add("feeCalcType", "N1");
  2986. item.Add("fixed", "1");
  2987. item.Add("rate", serviceFee);
  2988. feeList.Add(item);
  2989. dic.Add("feeList", feeList);
  2990. dic.Add("signMethod", "02");
  2991. string content = LiSAgentId + sn + "N11" + serviceFee + "02";
  2992. string signstr = LiSSign(content);
  2993. dic.Add("signData", signstr);
  2994. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  2995. string result = function.PostWebRequest(LiSReqUrl + "FEE003", req, new Dictionary<string, string>(), "application/json");
  2996. return result;
  2997. }
  2998. #endregion
  2999. #endregion
  3000. #region 查询商户型创客设置信息
  3001. public IActionResult SeeMerchantType(string right)
  3002. {
  3003. ViewBag.RightInfo = RightInfo;
  3004. ViewBag.right = right;
  3005. return View();
  3006. }
  3007. [HttpPost]
  3008. public string SeeMerchantTypeDo(string PosSn)
  3009. {
  3010. if (string.IsNullOrEmpty(PosSn))
  3011. {
  3012. return "请输入机具SN或者创客编号";
  3013. }
  3014. SetMerchantTypeRecord pos = new SetMerchantTypeRecord();
  3015. if (PosSn.StartsWith("K"))
  3016. {
  3017. UserForMakerCode userfor = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == PosSn) ?? new UserForMakerCode();
  3018. bool check = db.SetMerchantTypeRecord.Any(m => m.ToUserId == userfor.UserId);
  3019. if (check)
  3020. {
  3021. pos = db.SetMerchantTypeRecord.Where(m => m.ToUserId == userfor.UserId).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SetMerchantTypeRecord();
  3022. }
  3023. }
  3024. else
  3025. {
  3026. bool check = db.SetMerchantTypeRecord.Any(m => m.PosSn == PosSn);
  3027. if (check)
  3028. {
  3029. pos = db.SetMerchantTypeRecord.Where(m => m.PosSn == PosSn).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SetMerchantTypeRecord();
  3030. }
  3031. }
  3032. if (pos.Id == 0)
  3033. {
  3034. return "查无信息";
  3035. }
  3036. Users setUser = db.Users.FirstOrDefault(m => m.Id == pos.FromUserId) ?? new Users();
  3037. Users toUser = db.Users.FirstOrDefault(m => m.Id == pos.ToUserId) ?? new Users();
  3038. string CreateDate = pos.CreateDate == null ? "" : pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  3039. string bindTime = pos.BindDate == null ? "" : pos.BindDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  3040. string activeTime = pos.ActDate == null ? "" : pos.ActDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  3041. string bindResult = pos.BindStatus == 1 ? "已绑定" : "未绑定";
  3042. string activeResult = pos.ActStatus == 1 ? "已激活" : "未激活";
  3043. string RecycFlag = pos.IsRecyc == 1 ? "已循环" : "未循环";
  3044. string result = "";
  3045. result += "机具SN:" + pos.PosSn + "\n";
  3046. result += "操作人:创客编号:" + setUser.MakerCode + ",姓名:" + setUser.RealName + ",手机号:" + setUser.Mobile + "\n";
  3047. result += "操作对象:创客编号:" + toUser.MakerCode + ",姓名:" + toUser.RealName + ",手机号:" + toUser.Mobile + "\n";
  3048. result += "商户编号:" + pos.MerNo + "\n";
  3049. result += "操作时间:" + pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + "\n";
  3050. result += "绑定状态:" + bindResult + "(绑定时间:" + bindTime + ")\n";
  3051. result += "激活状态:" + activeResult + "(激活时间:" + activeTime + ")\n";
  3052. result += "贷记卡交易额:" + pos.CreditAmount + "\n";
  3053. result += "是否循环:" + RecycFlag + "\n";
  3054. return result;
  3055. }
  3056. #endregion
  3057. #region 三要素验证
  3058. public IActionResult CheckThreeElements(string right)
  3059. {
  3060. ViewBag.RightInfo = RightInfo;
  3061. ViewBag.right = right;
  3062. return View();
  3063. }
  3064. [HttpPost]
  3065. public string CheckThreeElementsDo(string bankcard, string idcard, string name)
  3066. {
  3067. var host = "https://bankcard3c.shumaidata.com";
  3068. var path = "/bankcard3c";
  3069. var method = "GET";
  3070. var appcode = "8e5704921ca3422f80f0deb935a7ddc6";
  3071. if (string.IsNullOrEmpty(bankcard))
  3072. {
  3073. return "结算银行卡号";
  3074. }
  3075. if (string.IsNullOrEmpty(idcard))
  3076. {
  3077. return "身份证号";
  3078. }
  3079. if (string.IsNullOrEmpty(name))
  3080. {
  3081. return "真实姓名";
  3082. }
  3083. WebCMSEntities maindb = new WebCMSEntities();
  3084. bool checkCertId = maindb.Users.Any(m => m.CertId == idcard);
  3085. if (checkCertId)
  3086. {
  3087. return "您输入的身份证号已经认证过了,请更换身份证";
  3088. }
  3089. String querys = "bankcard=" + bankcard + "&idcard=" + idcard + "&name=" + name;
  3090. function.WriteLog(DateTime.Now.ToString(), "验证三要素日志");
  3091. function.WriteLog(querys, "验证三要素日志");
  3092. String bodys = "";
  3093. String url = host + path;
  3094. HttpWebRequest httpRequest = null;
  3095. HttpWebResponse httpResponse = null;
  3096. if (0 < querys.Length)
  3097. {
  3098. url = url + "?" + querys;
  3099. }
  3100. if (host.Contains("https://"))
  3101. {
  3102. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  3103. httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
  3104. }
  3105. else
  3106. {
  3107. httpRequest = (HttpWebRequest)WebRequest.Create(url);
  3108. }
  3109. httpRequest.Method = method;
  3110. httpRequest.Headers.Add("Authorization", "APPCODE " + appcode);
  3111. if (0 < bodys.Length)
  3112. {
  3113. byte[] data = Encoding.UTF8.GetBytes(bodys);
  3114. using (Stream stream = httpRequest.GetRequestStream())
  3115. {
  3116. stream.Write(data, 0, data.Length);
  3117. }
  3118. }
  3119. try
  3120. {
  3121. httpResponse = (HttpWebResponse)httpRequest.GetResponse();
  3122. }
  3123. catch (WebException ex)
  3124. {
  3125. httpResponse = (HttpWebResponse)ex.Response;
  3126. }
  3127. Stream st = httpResponse.GetResponseStream();
  3128. StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
  3129. string result = reader.ReadToEnd();
  3130. JsonData jsonObj = JsonMapper.ToObject(result);
  3131. result = jsonObj["data"]["desc"].ToString();
  3132. function.WriteLog(result, "验证三要素日志");
  3133. function.WriteLog("\n\n", "验证三要素日志");
  3134. return result;
  3135. }
  3136. #endregion
  3137. #region 四要素验证
  3138. public IActionResult CheckFourElements(string right)
  3139. {
  3140. ViewBag.RightInfo = RightInfo;
  3141. ViewBag.right = right;
  3142. return View();
  3143. }
  3144. [HttpPost]
  3145. public string CheckFourElementsDo(string bankcard, string idcard, string mobile, string name)
  3146. {
  3147. var host = "https://bankcard4c.shumaidata.com";
  3148. var path = "/bankcard4c";
  3149. var method = "GET";
  3150. var appcode = "8e5704921ca3422f80f0deb935a7ddc6";
  3151. if (string.IsNullOrEmpty(bankcard))
  3152. {
  3153. return "请输入结算银行卡号";
  3154. }
  3155. if (string.IsNullOrEmpty(idcard))
  3156. {
  3157. return "请输入身份证号";
  3158. }
  3159. if (string.IsNullOrEmpty(mobile))
  3160. {
  3161. return "请输入银行预留手机号";
  3162. }
  3163. if (string.IsNullOrEmpty(name))
  3164. {
  3165. return "请输入真实姓名";
  3166. }
  3167. WebCMSEntities maindb = new WebCMSEntities();
  3168. bool checkCertId = maindb.Users.Any(m => m.CertId == idcard);
  3169. if (checkCertId)
  3170. {
  3171. return "您输入的身份证号已经认证过了,请更换身份证";
  3172. }
  3173. String querys = "bankcard=" + bankcard + "&idcard=" + idcard + "&mobile=" + mobile + "&name=" + name;
  3174. function.WriteLog(DateTime.Now.ToString(), "验证四要素日志");
  3175. function.WriteLog(querys, "验证四要素日志");
  3176. String bodys = "";
  3177. String url = host + path;
  3178. HttpWebRequest httpRequest = null;
  3179. HttpWebResponse httpResponse = null;
  3180. if (0 < querys.Length)
  3181. {
  3182. url = url + "?" + querys;
  3183. }
  3184. if (host.Contains("https://"))
  3185. {
  3186. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  3187. httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
  3188. }
  3189. else
  3190. {
  3191. httpRequest = (HttpWebRequest)WebRequest.Create(url);
  3192. }
  3193. httpRequest.Method = method;
  3194. httpRequest.Headers.Add("Authorization", "APPCODE " + appcode);
  3195. if (0 < bodys.Length)
  3196. {
  3197. byte[] data = Encoding.UTF8.GetBytes(bodys);
  3198. using (Stream stream = httpRequest.GetRequestStream())
  3199. {
  3200. stream.Write(data, 0, data.Length);
  3201. }
  3202. }
  3203. try
  3204. {
  3205. httpResponse = (HttpWebResponse)httpRequest.GetResponse();
  3206. }
  3207. catch (WebException ex)
  3208. {
  3209. httpResponse = (HttpWebResponse)ex.Response;
  3210. }
  3211. Stream st = httpResponse.GetResponseStream();
  3212. StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
  3213. string result = reader.ReadToEnd();
  3214. JsonData jsonObj = JsonMapper.ToObject(result);
  3215. result = jsonObj["data"]["desc"].ToString();
  3216. function.WriteLog(result, "验证四要素日志");
  3217. function.WriteLog("\n\n", "验证四要素日志");
  3218. return result;
  3219. }
  3220. #endregion
  3221. public bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
  3222. {
  3223. return true;
  3224. }
  3225. }
  3226. }