SysToolsController.cs 226 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752
  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. else if (pos.BrandId == 10 || pos.BrandId == 11)
  180. {
  181. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "10").Sum(m => m.TradeAmount);
  182. }
  183. pos.CreditTrade = CreditTrade;
  184. db.SaveChanges();
  185. }
  186. if (AddActPrize == 1)
  187. {
  188. if (pos.BuyUserId == 0)
  189. {
  190. return "机具未划拨,无法补录激活奖励";
  191. }
  192. if (string.IsNullOrEmpty(pos.SeoKeyword) || pos.SeoKeyword == "0")
  193. {
  194. bool has = spdb.ActivateRecord.Any(m => m.SnNo == pos.PosSn);
  195. if (has)
  196. {
  197. SpModels.ActivateRecord chkAct = spdb.ActivateRecord.Where(m => m.SnNo == pos.PosSn).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SpModels.ActivateRecord();
  198. pos.SeoKeyword = chkAct.SeoTitle;
  199. db.SaveChanges();
  200. }
  201. }
  202. if (pos.BindingTime != null && pos.ActivationTime != null)
  203. {
  204. TimeSpan ts = pos.ActivationTime.Value - pos.BindingTime.Value;
  205. if (ts.TotalDays <= 30 || SysUserName == "admin")
  206. {
  207. AddAct(pos.Id);
  208. }
  209. }
  210. }
  211. decimal CheckMoney = 1000;
  212. if (pos.BrandId == 6)
  213. {
  214. CheckMoney = 5000;
  215. }
  216. if (pos.BuyUserId > 0)
  217. {
  218. if (pos.CreditTrade < CheckMoney)
  219. {
  220. return "该机具贷记卡累计交易不足" + CheckMoney;
  221. }
  222. if (pos.BindingTime != null && pos.ActivationTime != null)
  223. {
  224. TimeSpan ts = pos.ActivationTime.Value - pos.BindingTime.Value;
  225. if (ts.TotalDays > 30 && SysUserName != "admin")
  226. {
  227. return "机具划拨后已超过30天";
  228. }
  229. }
  230. if (pos.CreditTrade >= CheckMoney && pos.ActivationState == 0)
  231. {
  232. pos.ActivationState = 1;
  233. pos.ActivationTime = DateTime.Now;
  234. PosMerchantInfo mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  235. if (pos.ActivationState == 1 && mer != null)
  236. {
  237. mer.ActiveStatus = 1;
  238. mer.MerStandardDate = DateTime.Now;
  239. }
  240. }
  241. else if (pos.CreditTrade >= CheckMoney && pos.ActivationState == 1)
  242. {
  243. if (AddActPrize == 1)
  244. {
  245. if (IsSend == 1)
  246. {
  247. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  248. {
  249. UserId = pos.BuyUserId, //接收创客
  250. MsgType = 2,
  251. Title = "补录成功通知", //标题
  252. Summary = "您的 " + kqProducts.Name + " SN:" + pos.PosSn + "已经成功补录,请查收。",
  253. CreateDate = DateTime.Now,
  254. }));
  255. }
  256. return "激活奖励已补录";
  257. }
  258. else
  259. {
  260. return "数据正常,无需补录";
  261. }
  262. }
  263. db.SaveChanges();
  264. return "success";
  265. }
  266. pos.UserId = user.Id;
  267. pos.BuyUserId = user.Id;
  268. if (pos.CreditTrade >= CheckMoney && pos.ActivationState == 0 && (pos.BindingTime > DateTime.Now.AddDays(-30) || SysUserName == "admin"))
  269. {
  270. // pos.IsPurchase = 0;
  271. pos.ActivationState = 1;
  272. pos.ActivationTime = DateTime.Now;
  273. }
  274. PosMerchantInfo merchant = new PosMerchantInfo();
  275. if (!string.IsNullOrEmpty(MerNo))
  276. {
  277. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo);
  278. if (merchant == null)
  279. {
  280. int TopUserId = 0;
  281. if (!string.IsNullOrEmpty(user.ParentNav))
  282. {
  283. TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  284. }
  285. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerNo == MerNo);
  286. if (bind == null)
  287. {
  288. return "该机具尚未绑定";
  289. }
  290. SpModels.Merchants Mer = spdb.Merchants.FirstOrDefault(m => m.MerNo == MerNo);
  291. if (Mer == null)
  292. {
  293. return "该机具尚未绑定";
  294. }
  295. PosMerchantInfo add = db.PosMerchantInfo.Add(new PosMerchantInfo()
  296. {
  297. CreateDate = Mer.CreateTime,
  298. UpdateDate = Mer.UpdateTime,
  299. TopUserId = TopUserId,
  300. MerUserType = user.MerchantType,
  301. BrandId = int.Parse(Mer.ProductType),
  302. SnStoreId = pos.StoreId,
  303. SnType = pos.PosSnType,
  304. UserId = user.Id,
  305. MgrName = Mer.AgentName,
  306. MerStatus = 1,
  307. KqSnNo = Mer.SnNo,
  308. KqMerNo = Mer.MerNo,
  309. MerIdcardNo = Mer.MerIdcardNo,
  310. MerRealName = Mer.MerRealName,
  311. MerchantMobile = Mer.MerMobile,
  312. MerchantName = Mer.MerName,
  313. MerchantNo = Mer.MerNo,
  314. }).Entity;
  315. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Mer.MerNo);
  316. if (forMerNo == null)
  317. {
  318. forMerNo = db.MachineForMerNo.Add(new MachineForMerNo()
  319. {
  320. MerNo = Mer.MerNo,
  321. SnId = pos.Id,
  322. }).Entity;
  323. }
  324. else
  325. {
  326. forMerNo.SnId = pos.Id;
  327. }
  328. }
  329. }
  330. else
  331. {
  332. if (pos.BindMerchantId > 0)
  333. {
  334. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  335. }
  336. else
  337. {
  338. return "找不到机具所属商户";
  339. }
  340. }
  341. merchant.UserId = user.Id;
  342. if (pos.ActivationState == 1)
  343. {
  344. merchant.ActiveStatus = 1;
  345. merchant.MerStandardDate = DateTime.Now;
  346. }
  347. if (pos.BindMerchantId == 0)
  348. {
  349. pos.BindMerchantId = merchant.Id;
  350. }
  351. // var makerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
  352. // 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();
  353. // if (makerCode.UserId > 0 && prePos.Id > 0)
  354. // {
  355. // if (prePos.CreateDate <= DateTime.Now.AddDays(-30))
  356. // {
  357. // var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == prePos.BrandId);
  358. // var amount = 0;
  359. // if (brandInfo.Name.Contains("电签"))
  360. // {
  361. // amount = 200;
  362. // }
  363. // if (brandInfo.Name.Contains("大POS"))
  364. // {
  365. // amount = 300;
  366. // }
  367. // var userAccount = db.UserAccount.FirstOrDefault(m => m.Id == makerCode.UserId) ?? new UserAccount();
  368. // if (userAccount.Id > 0)
  369. // {
  370. // userAccount.SmallStoreDeposit -= amount;
  371. // var add = db.UserAccountRecord.Add(new UserAccountRecord()
  372. // {
  373. // CreateDate = DateTime.Now,
  374. // Remark = "小分仓押金退还",
  375. // ChangeType = 65,
  376. // BeforeBalanceAmount = userAccount.SmallStoreDeposit + amount, //变更前小分仓押金
  377. // AfterBalanceAmount = userAccount.SmallStoreDeposit, //变更后小分仓押金
  378. // ChangeAmount = amount,//变动金额
  379. // UserId = userAccount.Id,
  380. // }).Entity;
  381. // db.SaveChanges();
  382. // }
  383. // }
  384. // }
  385. db.SaveChanges();
  386. function.WriteLog(DateTime.Now.ToString() + "\n" + SysUserName + "\nMakerCode:" + MakerCode + ", PosSn:" + PosSn + ", MerNo:" + MerNo + ", AddActPrize:" + AddActPrize + ", IsPre:" + IsPre, "机具补录日志");
  387. return "success";
  388. }
  389. public IActionResult CheckMachine2(string right)
  390. {
  391. ViewBag.RightInfo = RightInfo;
  392. ViewBag.right = right;
  393. return View();
  394. }
  395. [HttpPost]
  396. public string CheckMachine2Do(string MakerCode, string PosSn, string MerNo = "", int AddActPrize = 0)
  397. {
  398. if (string.IsNullOrEmpty(MakerCode))
  399. {
  400. return "请输入创客编号";
  401. }
  402. if (string.IsNullOrEmpty(PosSn))
  403. {
  404. return "请输入机具SN";
  405. }
  406. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  407. if (pos == null)
  408. {
  409. return "机具SN不存在";
  410. }
  411. Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
  412. if (user == null)
  413. {
  414. return "创客编号不存在";
  415. }
  416. if (pos.BindingState == 0)
  417. {
  418. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerSnNo == PosSn);
  419. if (bind != null)
  420. {
  421. pos.BindingState = 1;
  422. pos.BindingTime = bind.CreateTime;
  423. db.SaveChanges();
  424. MerNo = bind.MerNo;
  425. }
  426. }
  427. decimal CreditTrade = 0;
  428. bool check = spdb.TradeRecord.Any(m => m.TradeSnNo == pos.PosSn);
  429. if (check)
  430. {
  431. string BindingTime = pos.BindingTime == null ? DateTime.Now.AddMonths(-1).ToString("yyyyMM") : pos.BindingTime.Value.ToString("yyyyMM");
  432. string SpTradeRecordId = function.ReadInstance("/PublicParams/SpTradeRecordId" + BindingTime + ".txt");
  433. int StartId = int.Parse(function.CheckInt(SpTradeRecordId));
  434. if (pos.BrandId == 1)
  435. {
  436. 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;
  437. }
  438. else if (pos.BrandId == 2)
  439. {
  440. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "2").Sum(m => m.TradeAmount);
  441. }
  442. else if (pos.BrandId == 3)
  443. {
  444. 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;
  445. }
  446. else if (pos.BrandId == 4 || pos.BrandId == 5)
  447. {
  448. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "4").Sum(m => m.TradeAmount) / 100;
  449. }
  450. else if (pos.BrandId == 6)
  451. {
  452. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "6").Sum(m => m.TradeAmount) / 100;
  453. }
  454. else if (pos.BrandId == 8)
  455. {
  456. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "8").Sum(m => m.TradeAmount) / 100;
  457. }
  458. else if (pos.BrandId == 9)
  459. {
  460. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "9").Sum(m => m.TradeAmount) / 100;
  461. }
  462. else if (pos.BrandId == 10 || pos.BrandId == 11)
  463. {
  464. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "10").Sum(m => m.TradeAmount);
  465. }
  466. pos.CreditTrade = CreditTrade;
  467. db.SaveChanges();
  468. }
  469. if (AddActPrize == 1)
  470. {
  471. if (string.IsNullOrEmpty(pos.SeoKeyword) || pos.SeoKeyword == "0")
  472. {
  473. bool has = spdb.ActivateRecord.Any(m => m.SnNo == pos.PosSn);
  474. if (has)
  475. {
  476. SpModels.ActivateRecord chkAct = spdb.ActivateRecord.Where(m => m.SnNo == pos.PosSn).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SpModels.ActivateRecord();
  477. pos.SeoKeyword = chkAct.SeoTitle;
  478. db.SaveChanges();
  479. }
  480. }
  481. AddAct(pos.Id);
  482. }
  483. if (pos.BuyUserId > 0)
  484. {
  485. if (pos.CreditTrade < 1000)
  486. {
  487. // pos.IsPurchase = 99;
  488. db.SaveChanges();
  489. return "该机具贷记卡累计交易不足1000";
  490. }
  491. if (pos.CreditTrade >= 1000 && pos.ActivationState == 0)
  492. {
  493. // pos.IsPurchase = 0;
  494. pos.ActivationState = 1;
  495. pos.ActivationTime = DateTime.Now;
  496. PosMerchantInfo mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  497. if (pos.ActivationState == 1 && mer != null)
  498. {
  499. mer.ActiveStatus = 1;
  500. mer.MerStandardDate = DateTime.Now;
  501. }
  502. }
  503. else if (pos.CreditTrade >= 1000 && pos.ActivationState == 1)
  504. {
  505. if (AddActPrize == 1)
  506. {
  507. return "激活奖励已补录";
  508. }
  509. else
  510. {
  511. return "数据正常,无需补录";
  512. }
  513. }
  514. db.SaveChanges();
  515. return "success";
  516. }
  517. pos.UserId = user.Id;
  518. pos.BuyUserId = user.Id;
  519. // if (pos.CreditTrade < 1000)
  520. // {
  521. // pos.IsPurchase = 99;
  522. // }
  523. if (pos.CreditTrade >= 1000 && pos.ActivationState == 0)
  524. {
  525. // pos.IsPurchase = 0;
  526. pos.ActivationState = 1;
  527. pos.ActivationTime = DateTime.Now;
  528. }
  529. PosMerchantInfo merchant = new PosMerchantInfo();
  530. if (!string.IsNullOrEmpty(MerNo))
  531. {
  532. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo);
  533. if (merchant == null)
  534. {
  535. int TopUserId = 0;
  536. if (!string.IsNullOrEmpty(user.ParentNav))
  537. {
  538. TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  539. }
  540. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerNo == MerNo);
  541. if (bind == null)
  542. {
  543. return "该机具尚未绑定";
  544. }
  545. SpModels.Merchants Mer = spdb.Merchants.FirstOrDefault(m => m.MerNo == MerNo);
  546. if (Mer == null)
  547. {
  548. return "该机具尚未绑定";
  549. }
  550. PosMerchantInfo add = db.PosMerchantInfo.Add(new PosMerchantInfo()
  551. {
  552. CreateDate = Mer.CreateTime,
  553. UpdateDate = Mer.UpdateTime,
  554. TopUserId = TopUserId,
  555. MerUserType = user.MerchantType,
  556. BrandId = int.Parse(Mer.ProductType),
  557. SnStoreId = pos.StoreId,
  558. SnType = pos.PosSnType,
  559. UserId = user.Id,
  560. MgrName = Mer.AgentName,
  561. MerStatus = 1,
  562. KqSnNo = Mer.SnNo,
  563. KqMerNo = Mer.MerNo,
  564. MerIdcardNo = Mer.MerIdcardNo,
  565. MerRealName = Mer.MerRealName,
  566. MerchantMobile = Mer.MerMobile,
  567. MerchantName = Mer.MerName,
  568. MerchantNo = Mer.MerNo,
  569. }).Entity;
  570. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Mer.MerNo);
  571. if (forMerNo == null)
  572. {
  573. forMerNo = db.MachineForMerNo.Add(new MachineForMerNo()
  574. {
  575. MerNo = Mer.MerNo,
  576. SnId = pos.Id,
  577. }).Entity;
  578. }
  579. else
  580. {
  581. forMerNo.SnId = pos.Id;
  582. }
  583. }
  584. }
  585. else
  586. {
  587. if (pos.BindMerchantId > 0)
  588. {
  589. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  590. }
  591. else
  592. {
  593. return "找不到机具所属商户";
  594. }
  595. }
  596. merchant.UserId = user.Id;
  597. if (pos.ActivationState == 1)
  598. {
  599. merchant.ActiveStatus = 1;
  600. merchant.MerStandardDate = DateTime.Now;
  601. }
  602. if (pos.BindMerchantId == 0)
  603. {
  604. pos.BindMerchantId = merchant.Id;
  605. }
  606. db.SaveChanges();
  607. return "success";
  608. }
  609. public void AddAct(int posid = 0)
  610. {
  611. WebCMSEntities db = new WebCMSEntities();
  612. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.ActivationState == 1 && !string.IsNullOrEmpty(m.SeoKeyword) && m.Id == posid);
  613. if (pos != null)
  614. {
  615. // PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId && !string.IsNullOrEmpty(m.MerIdcardNo));
  616. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  617. if (merchant != null)
  618. {
  619. // PosMerchantOtherInfo otherInfo = db.PosMerchantOtherInfo.FirstOrDefault(m => m.CertId == merchant.MerIdcardNo && m.PrizeFlag1 == 0);
  620. // if (otherInfo != null)
  621. // {
  622. // otherInfo.PrizeFlag1 = 1;
  623. // db.SaveChanges();
  624. string ParentNav = "";
  625. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId);
  626. if (user != null)
  627. {
  628. int GetUserId = user.Id;
  629. ParentNav = user.ParentNav;
  630. int TopUserId = 1;
  631. if (!string.IsNullOrEmpty(ParentNav))
  632. {
  633. string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  634. if (ParentNavList.Length > 1)
  635. {
  636. TopUserId = int.Parse(ParentNavList[1]);
  637. }
  638. else if (ParentNavList.Length == 1)
  639. {
  640. TopUserId = int.Parse(ParentNavList[0]);
  641. }
  642. }
  643. List<decimal> prizes = new List<decimal>();
  644. decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  645. if (pos.BrandId == 1 || pos.BrandId == 3 || pos.BrandId == 4 || pos.BrandId == 5 || pos.BrandId == 6 || pos.BrandId == 8 || pos.BrandId == 9)
  646. {
  647. ActPrize = ActPrize / 100;
  648. }
  649. if (ActPrize > 0)
  650. {
  651. if (ActPrize == 99)
  652. {
  653. ActPrize = 100;
  654. }
  655. else if (ActPrize == 199)
  656. {
  657. ActPrize = 200;
  658. }
  659. else if (ActPrize == 299)
  660. {
  661. ActPrize = 300;
  662. }
  663. else if (ActPrize == 249)
  664. {
  665. ActPrize = 260;
  666. }
  667. prizes.Add(ActPrize);
  668. if (pos.BrandId == 6 && pos.ActivationState == 1 && pos.CreditTrade >= 10000 && pos.BindingTime > DateTime.Now.AddDays(-60))
  669. {
  670. prizes.Add(40);
  671. }
  672. }
  673. else if (pos.BrandId == 6 && ActPrize == 0) //立刷首台无押金机返50
  674. {
  675. prizes.Add(50);
  676. }
  677. else if((pos.BrandId == 10 || pos.BrandId == 11) && pos.IsFirst == 1 && ActPrize == 0) //联动首台无押金机返50
  678. {
  679. prizes.Add(50);
  680. }
  681. foreach (decimal prize in prizes)
  682. {
  683. int ChangeType = prize == 40 ? 12 : 0;
  684. bool check = db.ActiveReward.Any(m => m.KqSnNo == pos.PosSn && m.RewardAmount == prize);
  685. if (!check)
  686. {
  687. Users machineUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  688. db.ActiveReward.Add(new ActiveReward()
  689. {
  690. CreateDate = DateTime.Now,
  691. UpdateDate = DateTime.Now,
  692. UserId = GetUserId, //创客
  693. MerchantId = pos.BindMerchantId, //商户
  694. StandardDate = pos.ActivationTime, //达标日期
  695. RewardAmount = prize, //奖励金额
  696. BrandId = pos.BrandId, //品牌
  697. UserNav = ParentNav, //创客父级
  698. DirectBuddyNo = merchant.UserId, //商户直属创客
  699. KqMerNo = merchant.KqMerNo, //渠道商户编号
  700. KqSnNo = pos.PosSn, //渠道SN号
  701. SnType = pos.PosSnType, //机具类型
  702. SnApplyUserId = pos.BuyUserId, //机具申请创客
  703. ActType = 0, //激活类型
  704. SnStoreId = pos.StoreId, //SN仓库
  705. RewardTips = "激活奖励", //奖励描述
  706. Remark = "激活奖励", //备注
  707. ActDate = pos.ActivationTime, //激活时间
  708. TopUserId = TopUserId, //顶级创客
  709. SeoTitle = machineUser.RealName,
  710. });
  711. db.SaveChanges();
  712. string IdBrand = GetUserId + "_" + pos.BrandId;
  713. UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
  714. if (userData == null)
  715. {
  716. userData = db.UserMachineData.Add(new UserMachineData()
  717. {
  718. IdBrand = IdBrand,
  719. }).Entity;
  720. db.SaveChanges();
  721. }
  722. userData.ActProfit += prize;
  723. db.SaveChanges();
  724. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == GetUserId);
  725. if (account == null)
  726. {
  727. account = db.UserAccount.Add(new UserAccount()
  728. {
  729. Id = GetUserId,
  730. UserId = GetUserId,
  731. }).Entity;
  732. db.SaveChanges();
  733. }
  734. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  735. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  736. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  737. account.BalanceAmount += prize;
  738. account.TotalAmount += prize;
  739. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  740. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  741. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  742. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  743. {
  744. CreateDate = DateTime.Now,
  745. UpdateDate = DateTime.Now,
  746. UserId = GetUserId, //创客
  747. ChangeType = ChangeType, //变动类型
  748. ProductType = pos.BrandId, //产品类型
  749. ChangeAmount = prize, //变更金额
  750. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  751. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  752. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  753. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  754. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  755. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  756. }).Entity;
  757. db.SaveChanges();
  758. RedisDbconn.Instance.Set("UserAccount:" + GetUserId, account);
  759. string dateString = pos.ActivationTime.Value.ToString("yyyyMMdd");
  760. string monthString = pos.ActivationTime.Value.ToString("yyyyMM");
  761. // 激活奖励列表
  762. List<string> dates = RedisDbconn.Instance.GetList<string>("ActiveRewardDay:" + GetUserId + ":" + pos.BrandId);
  763. if (!dates.Contains(dateString))
  764. {
  765. RedisDbconn.Instance.AddList("ActiveRewardDay:" + GetUserId + ":" + pos.BrandId, dateString);
  766. }
  767. RedisDbconn.Instance.AddNumber("ActiveRewardAmt:" + GetUserId + ":" + pos.BrandId + ":" + dateString, prize);
  768. List<string> months = RedisDbconn.Instance.GetList<string>("ActiveRewardMonth:" + GetUserId + ":" + pos.BrandId);
  769. if (!months.Contains(monthString))
  770. {
  771. RedisDbconn.Instance.AddList("ActiveRewardMonth:" + GetUserId + ":" + pos.BrandId, monthString);
  772. }
  773. RedisDbconn.Instance.AddNumber("ActiveRewardAmt:" + GetUserId + ":" + pos.BrandId + ":" + monthString, prize);
  774. // 激活奖励详情
  775. List<int> actPrizeList = RedisDbconn.Instance.GetList<int>("ActiveRewardDetail:" + GetUserId + ":" + pos.BrandId + ":" + dateString);
  776. if (!actPrizeList.Contains(pos.BindMerchantId))
  777. {
  778. RedisDbconn.Instance.AddList("ActiveRewardDetail:" + GetUserId + ":" + pos.BrandId + ":" + dateString, pos.BindMerchantId);
  779. }
  780. RedisDbconn.Instance.AddNumber("ActiveRewardAmt:mer:" + pos.BindMerchantId + ":" + pos.BrandId + ":" + dateString, prize);
  781. //收支明细
  782. RedisDbconn.Instance.AddList("UserAccountRecord:" + GetUserId + ":1:" + monthString, userAccountRecord);
  783. RedisDbconn.Instance.AddNumber("UserAccount:" + GetUserId + ":1:" + monthString, prize);
  784. }
  785. }
  786. }
  787. // }
  788. }
  789. }
  790. db.Dispose();
  791. }
  792. #endregion
  793. #region 设置商户代理
  794. public IActionResult SetMerAgent(string right)
  795. {
  796. ViewBag.RightInfo = RightInfo;
  797. ViewBag.right = right;
  798. return View();
  799. }
  800. [HttpPost]
  801. public string SetMerAgentDo(string MakerCode, string PosSn, string MerNo, int IsSend = 0)
  802. {
  803. if (string.IsNullOrEmpty(MakerCode))
  804. {
  805. return "请输入创客编号";
  806. }
  807. if (string.IsNullOrEmpty(PosSn))
  808. {
  809. return "请输入机具SN";
  810. }
  811. if (string.IsNullOrEmpty(MerNo))
  812. {
  813. return "请输入商户编号";
  814. }
  815. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  816. KqProducts kqProducts = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId);
  817. if (pos == null)
  818. {
  819. return "机具SN不存在";
  820. }
  821. Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
  822. if (user == null)
  823. {
  824. return "创客编号不存在";
  825. }
  826. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo);
  827. if (merchant == null)
  828. {
  829. return "商户编号不存在";
  830. }
  831. pos.SeoTitle = user.Id.ToString();
  832. pos.UserId = user.Id;
  833. if (pos.BindMerchantId == 0)
  834. {
  835. pos.BindMerchantId = merchant.Id;
  836. if (IsSend == 1)
  837. {
  838. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  839. {
  840. UserId = pos.BuyUserId, //接收创客
  841. MsgType = 2,
  842. Title = "商户型代理设置成功", //标题
  843. Summary = "您的 " + kqProducts.Name + " SN:" + pos.PosSn + "已经成功给下级代理" + user.RealName + "" + MakerCode + ",设置为商户型代理,设置成功后的新增交易的分润归商户型代理所有",
  844. CreateDate = DateTime.Now,
  845. }));
  846. }
  847. }
  848. user.MerchantType = 1;
  849. merchant.UserId = user.Id;
  850. merchant.MerUserType = 1;
  851. db.SetMerchantTypeRecord.Add(new SetMerchantTypeRecord()
  852. {
  853. CreateDate = DateTime.Now,
  854. IsRecyc = (ulong)pos.IsPurchase,
  855. CreditAmount = pos.CreditTrade,
  856. PosSnType = pos.PosSnType,
  857. ActDate = pos.ActivationTime,
  858. BindDate = pos.BindingTime,
  859. ActStatus = (ulong)pos.ActivationState,
  860. BindStatus = (ulong)pos.BindingState,
  861. MerNo = MerNo,
  862. PosSn = pos.PosSn,
  863. Note = "后台设置商户型创客",
  864. ToUserId = user.Id,
  865. FromUserId = pos.BuyUserId,
  866. });
  867. db.SaveChanges();
  868. return "success";
  869. }
  870. #endregion
  871. #region 取消商户代理
  872. public IActionResult CancelMerAgent(string right)
  873. {
  874. ViewBag.RightInfo = RightInfo;
  875. ViewBag.right = right;
  876. return View();
  877. }
  878. [HttpPost]
  879. public string CancelMerAgentDo(string MakerCode, string PosSn, int IsSend = 0)
  880. {
  881. if (string.IsNullOrEmpty(MakerCode))
  882. {
  883. return "请输入创客编号";
  884. }
  885. if (string.IsNullOrEmpty(PosSn))
  886. {
  887. return "请输入机具SN";
  888. }
  889. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  890. KqProducts kqProducts = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId);
  891. if (pos == null)
  892. {
  893. return "机具SN不存在";
  894. }
  895. Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
  896. if (user == null)
  897. {
  898. return "创客编号不存在";
  899. }
  900. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == PosSn);
  901. pos.UserId = pos.BuyUserId;
  902. merchant.UserId = pos.BuyUserId;
  903. merchant.MerUserType = 0;
  904. user.MerchantType = 0;
  905. db.SaveChanges();
  906. if (pos.BindMerchantId == 0)
  907. {
  908. pos.BindMerchantId = merchant.Id;
  909. if (IsSend == 1)
  910. {
  911. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  912. {
  913. UserId = pos.BuyUserId, //接收创客
  914. MsgType = 2,
  915. Title = "商户型代理取消成功", //标题
  916. Summary = "您的 " + kqProducts.Name + " SN:" + pos.PosSn + "已给下级代理" + user.RealName + "" + MakerCode + "取消成功",
  917. CreateDate = DateTime.Now,
  918. }));
  919. }
  920. }
  921. string text = string.Format("取消商户代理,创客编号: " + user.MakerCode + ",机具SN:" + pos.PosSn + ",操作人:" + SysRealName + ",Time:" + DateTime.Now + "");
  922. function.WriteLog(text, "CancelMerAgent");//取消商户型代理日志
  923. return "success";
  924. }
  925. #endregion
  926. #region 查看SP原始数据日志
  927. public IActionResult SeeSpLog(string right)
  928. {
  929. ViewBag.RightInfo = RightInfo;
  930. ViewBag.right = right;
  931. return View();
  932. }
  933. #endregion
  934. #region 查询机具信息
  935. public IActionResult SeeSnDetail(string right)
  936. {
  937. ViewBag.RightInfo = RightInfo;
  938. ViewBag.right = right;
  939. return View();
  940. }
  941. [HttpPost]
  942. public string SeeSnDetailDo(string PosSn)
  943. {
  944. if (string.IsNullOrEmpty(PosSn))
  945. {
  946. return "请输入机具SN";
  947. }
  948. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  949. if (pos == null)
  950. {
  951. return "机具SN不存在";
  952. }
  953. if (pos.Status == -1)
  954. {
  955. Users posUsers = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  956. decimal Deposits = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  957. if (pos.BrandId != 2 && pos.BrandId != 7 && pos.BrandId != 10 && pos.BrandId != 11)
  958. {
  959. Deposits = Deposits / 100;
  960. }
  961. string DepositGets = "未领取";
  962. string DepositUsers = "";
  963. ActiveReward rewards = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.RewardAmount != 40) ?? new ActiveReward();
  964. if (rewards.Id > 0)
  965. {
  966. Users user = db.Users.FirstOrDefault(m => m.Id == rewards.UserId) ?? new Users();
  967. DepositGets = "已领取";
  968. DepositUsers = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName;
  969. // DepositUsers = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  970. }
  971. string ActiveTimes = rewards.CreateDate == null ? "" : rewards.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  972. var storeInfo = db.StoreHouse.FirstOrDefault(m => m.Id == pos.StoreId) ?? new StoreHouse();
  973. string results = "该机具为故障机" + "\n";
  974. results += "所在仓库:" + storeInfo.StoreNo + "\n";
  975. results += "仓库名称:" + storeInfo.StoreName + "\n";
  976. results += "押金返现实际返现对象:" + DepositUsers + "\n";
  977. results += "押金:" + Deposits + "\n";
  978. results += "是否返现:" + DepositGets + ",领取时间:" + ActiveTimes + "\n";
  979. return results;
  980. }
  981. string merInfo = "";
  982. string merName = "";
  983. PosMerchantInfo mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  984. if (mer != null)
  985. {
  986. merInfo = mer.KqMerNo;
  987. merName = mer.MerchantName;
  988. }
  989. else
  990. {
  991. merInfo = "未找到商户";
  992. }
  993. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == pos.StoreId) ?? new StoreHouse();
  994. Users posUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  995. Users posSubUser = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new Users();
  996. int TopUserId = 0;
  997. if (!string.IsNullOrEmpty(posUser.ParentNav))
  998. {
  999. string[] ParentNavs = posUser.ParentNav.Trim(',').Replace(",,", ",").Split(',');
  1000. if (ParentNavs.Length > 1)
  1001. {
  1002. TopUserId = int.Parse(ParentNavs[1]);
  1003. }
  1004. if (ParentNavs.Length == 1)
  1005. {
  1006. TopUserId = int.Parse(ParentNavs[0]);
  1007. }
  1008. }
  1009. Users posTopUser = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
  1010. string bindResult = "", bindTime = "";
  1011. if (pos.BindingState == 0)
  1012. {
  1013. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerSnNo == pos.PosSn);
  1014. if (bind != null)
  1015. {
  1016. if (bind.Status != 1)
  1017. {
  1018. bindResult = "执行中";
  1019. }
  1020. }
  1021. else
  1022. {
  1023. bindResult = "未绑定";
  1024. }
  1025. }
  1026. else
  1027. {
  1028. bindResult = "已绑定";
  1029. bindTime = pos.BindingTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1030. }
  1031. string activeResult = "", activeTime = "";
  1032. if (pos.ActivationState == 0)
  1033. {
  1034. if (pos.CreditTrade < 1000)
  1035. {
  1036. activeResult = "未刷满1000";
  1037. }
  1038. else if (pos.TransferTime == null)
  1039. {
  1040. activeResult = "未激活, 需补录";
  1041. }
  1042. }
  1043. else
  1044. {
  1045. activeResult = "已激活";
  1046. activeTime = pos.ActivationTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1047. }
  1048. string tradeAmount = pos.CreditTrade.ToString();
  1049. decimal Deposit = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  1050. if (pos.BrandId != 2 && pos.BrandId != 7 && pos.BrandId != 10 && pos.BrandId != 11)
  1051. {
  1052. Deposit = Deposit / 100;
  1053. }
  1054. string DepositGet = "未领取";
  1055. string DepositUser = "";
  1056. string DepositToUser = "";
  1057. decimal headAmount = 0;
  1058. decimal footAmount = 0;
  1059. ActiveReward reward = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.RewardAmount != 40) ?? new ActiveReward();
  1060. if (reward.Id > 0)
  1061. {
  1062. Users user = db.Users.FirstOrDefault(m => m.Id == reward.UserId) ?? new Users();
  1063. DepositGet = "已领取";
  1064. DepositUser = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName;
  1065. // DepositUser = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  1066. var fAmount = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.ActType == 0);
  1067. if (fAmount != null)
  1068. {
  1069. headAmount = fAmount.RewardAmount;
  1070. }
  1071. var lAmount = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.ActType == 1);
  1072. if (lAmount != null)
  1073. {
  1074. footAmount = lAmount.RewardAmount;
  1075. }
  1076. }
  1077. string DepositGet6 = "未领取";
  1078. string DepositUser6 = "";
  1079. ActiveReward lisreward = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.BrandId == 6 && m.RewardAmount == 40) ?? new ActiveReward();
  1080. if (lisreward.Id > 0)
  1081. {
  1082. Users user = db.Users.FirstOrDefault(m => m.Id == lisreward.UserId) ?? new Users();
  1083. DepositGet6 = "已领取";
  1084. DepositUser6 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName;
  1085. // DepositUser6 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  1086. }
  1087. string FluxGet6 = "未领取";
  1088. string FluxUser6 = "";
  1089. FluxProfitDetail flux = db.FluxProfitDetail.FirstOrDefault(m => m.SnNo == pos.PosSn) ?? new FluxProfitDetail();
  1090. if (flux.Id > 0)
  1091. {
  1092. Users user = db.Users.FirstOrDefault(m => m.Id == flux.UserId) ?? new Users();
  1093. FluxGet6 = "已领取(领取时间:" + flux.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
  1094. FluxUser6 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName;
  1095. // FluxUser6 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  1096. }
  1097. Users touser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  1098. DepositToUser = "创客编号:" + touser.MakerCode + ",姓名:" + touser.RealName;
  1099. // DepositToUser = "创客编号:" + touser.MakerCode + ",姓名:" + touser.RealName + ",手机号:" + touser.Mobile;
  1100. string OpenUser10 = "未领取";
  1101. string OpenUser20 = "未领取";
  1102. string Leader10 = "未领取";
  1103. string YYZX5 = "未领取";
  1104. var OpenRewardDetail = db.OpenRewardDetail.Where(m => m.SnNo == pos.PosSn).ToList();
  1105. OpenRewardDetail openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 20) ?? new OpenRewardDetail();
  1106. if (openreward.Id > 0)
  1107. {
  1108. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  1109. OpenUser20 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName;
  1110. // OpenUser20 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  1111. }
  1112. openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 10) ?? new OpenRewardDetail();
  1113. if (openreward.Id > 0)
  1114. {
  1115. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  1116. OpenUser10 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName;
  1117. // OpenUser10 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  1118. }
  1119. var leader10 = db.UserAccountRecord.FirstOrDefault(m => m.QueryCount == pos.Id && m.ChangeType == 116) ?? new UserAccountRecord();
  1120. if (leader10.Id > 0)
  1121. {
  1122. Users user = db.Users.FirstOrDefault(m => m.Id == leader10.UserId) ?? new Users();
  1123. Leader10 = "金额:" + leader10.ChangeAmount + ",创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",发奖时间:" + leader10.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1124. // Leader10 = "金额:" + leader10.ChangeAmount + ",创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  1125. }
  1126. var yyzx5 = db.UserAccountRecord.FirstOrDefault(m => m.QueryCount == pos.Id && m.ChangeType == 121) ?? new UserAccountRecord();
  1127. if (yyzx5.Id > 0)
  1128. {
  1129. Users user = db.Users.FirstOrDefault(m => m.Id == yyzx5.UserId) ?? new Users();
  1130. YYZX5 = "金额:" + yyzx5.ChangeAmount + ",创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",发奖时间:" + yyzx5.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1131. // YYZX5 = "金额:" + yyzx5.ChangeAmount + ",创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  1132. }
  1133. MachineApply apply = db.MachineApply.FirstOrDefault(m => m.SwapSnExpand.Contains(pos.PosSn)) ?? new MachineApply();
  1134. Orders applyorder = db.Orders.FirstOrDefault(m => m.Id == apply.QueryCount) ?? new Orders();
  1135. MachineChangeDetail change = db.MachineChangeDetail.FirstOrDefault(m => m.OutSnNo == pos.PosSn) ?? new MachineChangeDetail();
  1136. string RecycFlag = pos.IsPurchase == 1 ? "已申请循环" : "未申请循环";
  1137. string SendStatus = applyorder.SendStatus == 1 ? "已发货" : "未发货";
  1138. string ApplyDate = apply.CreateDate == null ? "" : apply.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1139. string SendDate = applyorder.SendDate == null ? "" : applyorder.SendDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1140. string CreateDate = pos.CreateDate == null ? "" : pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1141. string TransferTime = pos.TransferTime == null ? "" : pos.TransferTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1142. string RecycEndDate = pos.RecycEndDate == null ? "" : pos.RecycEndDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1143. string ActiveTime = reward.CreateDate == null ? "" : reward.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1144. string ActiveTime6 = lisreward.CreateDate == null ? "" : lisreward.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1145. string result = "";
  1146. result += "机器持有人顶级:创客编号:" + posTopUser.MakerCode + ",姓名:" + posTopUser.RealName + "\n";
  1147. result += "\n";
  1148. result += "机具SN:" + pos.PosSn + "\n";
  1149. string PosSnType = pos.PosSnType == 0 ? "兑换机" : "循环机";
  1150. result += "机具类型:" + PosSnType + "\n";
  1151. result += "商户编号:" + merInfo + ",商户姓名:" + merName + "\n";
  1152. result += "商户型机器/直拓机器:创客编号:" + posSubUser.MakerCode + ",姓名:" + posSubUser.RealName + "\n";
  1153. // result += "商户型机器/直拓机器:创客编号:" + posSubUser.MakerCode + ",姓名:" + posSubUser.RealName + ",手机号:" + posSubUser.Mobile + "\n";
  1154. if (change.Id > 0)
  1155. {
  1156. result += "换机来源机具SN:" + change.BackSnNo + "\n";
  1157. }
  1158. result += "机具所属人:创客编号:" + posUser.MakerCode + ",姓名:" + posUser.RealName + "\n";
  1159. // result += "机具所属人:创客编号:" + posUser.MakerCode + ",姓名:" + posUser.RealName + ",手机号:" + posUser.Mobile + "\n";
  1160. // result += "机器持有人顶级:创客编号:" + posTopUser.MakerCode + ",姓名:" + posTopUser.RealName + ",手机号:" + posTopUser.Mobile + "\n";
  1161. result += "机器所属仓库:仓库编号:" + store.StoreNo + ",仓库名称:" + store.StoreName + "\n";
  1162. if (pos.PreUserId > 0)
  1163. {
  1164. Users smallStoreUser = db.Users.FirstOrDefault(m => m.Id == pos.PreUserId) ?? new Users();
  1165. PreSendStockDetail preSend = db.PreSendStockDetail.FirstOrDefault(m => m.SnId == pos.Id && m.ToUserId == pos.PreUserId && m.Status == 1) ?? new PreSendStockDetail();
  1166. string preSendDate = preSend.CreateDate == null ? "" : preSend.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1167. result += "机具所属小分仓:创客编号:" + smallStoreUser.MakerCode + ",姓名:" + smallStoreUser.RealName + ",预发时间:" + preSendDate + "\n";
  1168. // result += "机具所属小分仓:创客编号:" + smallStoreUser.MakerCode + ",姓名:" + smallStoreUser.RealName + ",手机号:" + smallStoreUser.Mobile + ",预发时间:" + preSendDate + "\n";
  1169. }
  1170. else
  1171. {
  1172. result += "机具所属小分仓:暂无小分仓\n";
  1173. }
  1174. result += "入库时间:" + CreateDate + "\n";
  1175. result += "循环到期时间:" + RecycEndDate + "\n";
  1176. result += "划拨时间:" + TransferTime + "\n";
  1177. result += "绑定状态:" + bindResult + "(绑定时间:" + bindTime + ")\n";
  1178. result += "激活状态:" + activeResult + "(激活时间:" + activeTime + ")\n";
  1179. result += "贷记卡(总)交易额:" + tradeAmount + "\n";
  1180. result += "是否循环:" + RecycFlag + ",申请循环时间:" + ApplyDate + "\n";
  1181. result += "申请循环后的SN:" + applyorder.SnNos + "\n";
  1182. result += "是否发货:" + SendStatus + ",发货时间:" + SendDate + "\n";
  1183. result += "押金:" + Deposit + "\n";
  1184. result += "是否返现:" + DepositGet + ",领取时间:" + ActiveTime + "\n";
  1185. result += "返现金额:" + headAmount + " " + " " + footAmount + "\n";
  1186. result += "押金返现应返现对象:" + DepositToUser + "\n";
  1187. result += "押金返现实际返现对象:" + DepositUser + "\n";
  1188. if (pos.BrandId == 6)
  1189. {
  1190. result += "立刷10000奖励:" + DepositGet6 + ",领取时间:" + ActiveTime6 + "\n";
  1191. result += "立刷10000奖励发放人:" + DepositUser6 + "\n";
  1192. }
  1193. result += "流量费:" + FluxGet6 + "\n";
  1194. result += "流量费发放对象:" + FluxUser6 + "\n";
  1195. result += "开机奖20:" + OpenUser20 + "\n";
  1196. // result += "开机奖10:" + OpenUser10 + "\n";
  1197. result += "盟主奖:" + Leader10 + "\n";
  1198. result += "运营中心奖:" + YYZX5 + "\n";
  1199. return result;
  1200. }
  1201. //解析金控日志
  1202. // public decimal CheckLog(DateTime startDate, string PosSn)
  1203. // {
  1204. // bool op = true;
  1205. // decimal result = 0;
  1206. // DateTime today = DateTime.Now;
  1207. // int i = 0;
  1208. // while (op)
  1209. // {
  1210. // DateTime check = DateTime.Parse(startDate.ToString("yyyy-MM-dd") + " 00:00:00").AddDays(i);
  1211. // if (check <= today)
  1212. // {
  1213. // string source = function.GetWebRequest("http://sp.kexiaoshuang.com/api/test/GetLog?date=" + check.Year + "-" + check.Month + "-" + check.Day);
  1214. // MatchCollection mc = Regex.Matches(source, "{.*?2022年飞天系列-小宝电签.*?}"); //激活
  1215. // foreach (Match sub in mc)
  1216. // {
  1217. // string content = sub.Value;
  1218. // JsonData jsonObj = JsonMapper.ToObject(content);
  1219. // decimal serviceAmount = decimal.Parse(jsonObj["serviceAmount"].ToString());
  1220. // string posSnCheck = jsonObj["posSn"].ToString();
  1221. // if (posSnCheck == PosSn && serviceAmount > 0)
  1222. // {
  1223. // result = serviceAmount / 100;
  1224. // op = false;
  1225. // }
  1226. // }
  1227. // }
  1228. // else
  1229. // {
  1230. // op = false;
  1231. // }
  1232. // i += 1;
  1233. // }
  1234. // return result;
  1235. // }
  1236. #endregion
  1237. #region 生成机具兑换码
  1238. public IActionResult MakeCoupons(string right)
  1239. {
  1240. ViewBag.RightInfo = RightInfo;
  1241. ViewBag.right = right;
  1242. return View();
  1243. }
  1244. [HttpPost]
  1245. public string MakeCouponsDo(int Kind, int Number)
  1246. {
  1247. DateTime checkTime = DateTime.Parse("1900-01-01");
  1248. string checkTimeString = RedisDbconn.Instance.Get<string>("MakerCouponsQueueCheckTime");
  1249. if (!string.IsNullOrEmpty(checkTimeString))
  1250. {
  1251. checkTime = DateTime.Parse(checkTimeString);
  1252. }
  1253. if (checkTime.AddHours(1) < DateTime.Now)
  1254. {
  1255. RedisDbconn.Instance.Set("MakerCouponsQueueCheckTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  1256. RedisDbconn.Instance.AddList("MakerCouponsQueue:" + Kind, Number);
  1257. return "生成程序已执行";
  1258. }
  1259. return "请稍后再试";
  1260. }
  1261. #endregion
  1262. #region 导出没有刷满1000的机具
  1263. public IActionResult ExportPos(string right)
  1264. {
  1265. ViewBag.RightInfo = RightInfo;
  1266. ViewBag.right = right;
  1267. return View();
  1268. }
  1269. [HttpPost]
  1270. public JsonResult ExportPosDo()
  1271. {
  1272. WebCMSEntities db = new WebCMSEntities();
  1273. List<PosMachinesTwo> poses = db.PosMachinesTwo.Where(m => m.CreditTrade < 1000 && m.BindingState == 1).ToList();
  1274. int total = poses.Count;
  1275. int index = 0;
  1276. List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
  1277. foreach (PosMachinesTwo pos in poses)
  1278. {
  1279. index += 1;
  1280. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
  1281. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  1282. Users puser = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId) ?? new Users();
  1283. Users ppuser = db.Users.FirstOrDefault(m => m.Id == puser.ParentUserId) ?? new Users();
  1284. Dictionary<string, object> item = new Dictionary<string, object>();
  1285. string TopRealName = "";
  1286. string TopMakerCode = "";
  1287. string TopMobile = "";
  1288. string ParentNav = user.ParentNav;
  1289. if (!string.IsNullOrEmpty(ParentNav))
  1290. {
  1291. string[] navlist = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  1292. if (navlist.Length > 1)
  1293. {
  1294. int TopId = int.Parse(function.CheckInt(navlist[1]));
  1295. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopId) ?? new Users();
  1296. TopRealName = tuser.RealName;
  1297. TopMakerCode = tuser.MakerCode;
  1298. TopMobile = tuser.Mobile;
  1299. }
  1300. }
  1301. item.Add("TopRealName", TopRealName); //顶级姓名
  1302. item.Add("TopMakerCode", TopMakerCode); //顶级编号
  1303. item.Add("UpUpRealName", ppuser.RealName); //上上级姓名
  1304. item.Add("UpRealName", puser.RealName); //上级姓名
  1305. item.Add("RealName", user.RealName); //代理姓名
  1306. item.Add("MakerCode", user.MakerCode); //代理编号
  1307. item.Add("Mobile", user.Mobile); //代理手机号
  1308. item.Add("MerchantName", merchant.MerchantName); //客户姓名
  1309. item.Add("MerchantMobile", merchant.MerchantMobile); //客户电话
  1310. item.Add("OpenTime", pos.BindingTime == null ? "" : pos.BindingTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); //开机日期
  1311. item.Add("Sn", pos.PosSn); //SN
  1312. list.Add(item);
  1313. RedisDbconn.Instance.Set("ExportPosCheck", index + " / " + total);
  1314. }
  1315. db.Dispose();
  1316. Dictionary<string, object> result = new Dictionary<string, object>();
  1317. result.Add("Status", "1");
  1318. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  1319. result.Add("Obj", list);
  1320. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  1321. ReturnFields.Add("TopRealName", "顶级姓名"); //顶级姓名
  1322. ReturnFields.Add("TopMakerCode", "顶级编号"); //顶级编号
  1323. ReturnFields.Add("UpUpRealName", "上上级姓名"); //上上级姓名
  1324. ReturnFields.Add("UpRealName", "上级姓名"); //上级姓名
  1325. ReturnFields.Add("RealName", "代理姓名"); //代理姓名
  1326. ReturnFields.Add("MakerCode", "代理编号"); //代理编号
  1327. ReturnFields.Add("Mobile", "代理手机号"); //代理手机号
  1328. ReturnFields.Add("MerchantName", "客户姓名"); //客户姓名
  1329. ReturnFields.Add("MerchantMobile", "客户电话"); //客户电话
  1330. ReturnFields.Add("OpenTime", "开机日期"); //开机日期
  1331. ReturnFields.Add("Sn", "SN"); //SN
  1332. result.Add("Fields", ReturnFields);
  1333. RedisDbconn.Instance.Set("ExportPosCheck", "finish");
  1334. return Json(result);
  1335. }
  1336. public string ExportPosCheck()
  1337. {
  1338. string content = RedisDbconn.Instance.Get<string>("ExportPosCheck");
  1339. if (content == "finish")
  1340. {
  1341. RedisDbconn.Instance.Clear("ExportPosCheck");
  1342. }
  1343. return content;
  1344. }
  1345. #endregion
  1346. #region 更换机具
  1347. public IActionResult ChangePos(string right)
  1348. {
  1349. ViewBag.RightInfo = RightInfo;
  1350. ViewBag.right = right;
  1351. return View();
  1352. }
  1353. [HttpPost]
  1354. public string ChangePosDo(string OldSn, string NewSn, string BackStoreNo, string OutStoreNo, string MerNo = "", int IsSend = 0)
  1355. {
  1356. if (string.IsNullOrEmpty(OldSn))
  1357. {
  1358. return "请输入原机具SN";
  1359. }
  1360. if (string.IsNullOrEmpty(NewSn))
  1361. {
  1362. return "请输入新机具SN";
  1363. }
  1364. if (string.IsNullOrEmpty(MerNo))
  1365. {
  1366. return "请输入商户编号";
  1367. }
  1368. string[] OldSnList = OldSn.Split('\n');
  1369. string[] NewSnList = NewSn.Split('\n');
  1370. if (OldSnList.Length != NewSnList.Length)
  1371. {
  1372. return "原机具SN数量和新机具SN数量不一致";
  1373. }
  1374. WebCMSEntities db = new WebCMSEntities();
  1375. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == OldSn);
  1376. StoreForCode storeForBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  1377. StoreForCode storeForOut = db.StoreForCode.FirstOrDefault(m => m.Code == OutStoreNo) ?? new StoreForCode();
  1378. StoreHouse BackStore = db.StoreHouse.FirstOrDefault(m => m.Id == storeForBack.StoreId) ?? new StoreHouse();
  1379. StoreHouse OutStore = db.StoreHouse.FirstOrDefault(m => m.Id == storeForOut.StoreId) ?? new StoreHouse();
  1380. string ChangeNo = "BMC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(3);
  1381. KqProducts oldPosBrand = new KqProducts();
  1382. KqProducts newPosBrand = new KqProducts();
  1383. MachineChange add = db.MachineChange.Add(new MachineChange()
  1384. {
  1385. CreateDate = DateTime.Now,
  1386. UpdateDate = DateTime.Now,
  1387. CreateMan = SysUserName + "-" + SysRealName,
  1388. ChangeNo = ChangeNo, //转换单号
  1389. UserId = 0, //创客
  1390. ChangeTime = DateTime.Now, //转换时间
  1391. BackStoreId = BackStore.Id, //退回仓库
  1392. BackStoreName = BackStore.StoreName, //退回仓库名称
  1393. Remark = "机具更换", //订单备注
  1394. BackStoreUserId = BackStore.UserId, //退回仓库归属人
  1395. OutProductType = int.Parse(OutStore.BrandId), //出库产品类型
  1396. OutProductName = OutStore.ProductName, //出库产品名称
  1397. OutStoreId = OutStore.Id, //出库仓库
  1398. OutStoreName = OutStore.StoreName, //出库仓库名称
  1399. OutStoreAreas = OutStore.Areas, //出库仓库所在地区
  1400. OutStoreAddress = OutStore.Address, //出库仓库地址
  1401. OutStoreManager = "", //出库仓库联系人
  1402. OutStoreManagerMobile = OutStore.ManageMobile, //出库仓库联系人手机号
  1403. }).Entity;
  1404. db.SaveChanges();
  1405. int BackProductType = 0;
  1406. string BackProductName = "";
  1407. string ChangeDeviceName = "";
  1408. string ChangeSnExpand = "";
  1409. for (int i = 0; i < OldSnList.Length; i++)
  1410. {
  1411. string OldSnNum = OldSnList[i];
  1412. string NewSnNum = NewSnList[i];
  1413. MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  1414. MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
  1415. PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId);
  1416. if (oldpos == null)
  1417. {
  1418. return "原机具SN不正确";
  1419. }
  1420. // if (oldpos.BindingState != 1)
  1421. // {
  1422. // return "原机具未绑定";
  1423. // }
  1424. PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId && m.PreUserId == 0);//添加新机是否为预发机判断
  1425. if (newpos == null)
  1426. {
  1427. return "新机具SN不正确或不满足条件";
  1428. }
  1429. oldPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1430. newPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == newpos.BrandId) ?? new KqProducts();
  1431. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo);
  1432. if (merchant == null)
  1433. {
  1434. CustomerSqlConn.op("insert into PosMerchantInfo select * from PosMerchantInfoBak where KqMerNo='" + MerNo + "'", MysqlConn.connstr);
  1435. }
  1436. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo) ?? new PosMerchantInfo();
  1437. newpos.BindMerchantId = merchant.Id;
  1438. newpos.BuyUserId = oldpos.BuyUserId;
  1439. newpos.UserId = oldpos.UserId;
  1440. newpos.RecycEndDate = oldpos.RecycEndDate;
  1441. newpos.ScanQrTrade = oldpos.ScanQrTrade;
  1442. newpos.DebitCardTrade = oldpos.DebitCardTrade;
  1443. newpos.CreditTrade = oldpos.CreditTrade;
  1444. newpos.PosSnType = oldpos.PosSnType;
  1445. newpos.TransferTime = oldpos.TransferTime;
  1446. newpos.IsPurchase = oldpos.IsPurchase;
  1447. newpos.BindingState = oldpos.BindingState;
  1448. newpos.ActivationState = oldpos.ActivationState;
  1449. newpos.BindingTime = oldpos.BindingTime;
  1450. newpos.ActivationTime = oldpos.ActivationTime;
  1451. newpos.IsFirst = oldpos.IsFirst;
  1452. // bool checkActReward = db.ActiveReward.Any(m => m.KqMerNo == merchant.KqMerNo);
  1453. // if (!checkActReward)
  1454. // {
  1455. newpos.SeoKeyword = oldpos.SeoKeyword;
  1456. newpos.PrizeParams = oldpos.PrizeParams;
  1457. newpos.LeaderUserId = oldpos.LeaderUserId;
  1458. // }
  1459. // oldpos.BuyUserId = 0;
  1460. // oldpos.UserId = 0;
  1461. oldpos.Status = -1;
  1462. //对应调整客小爽企业版数据
  1463. var posInfo = db.BusinessPartnerPos.FirstOrDefault(m => m.PosId == oldpos.Id);
  1464. if (posInfo != null)
  1465. {
  1466. posInfo.PosSn = newpos.PosSn;
  1467. posInfo.PosId = newpos.Id;
  1468. db.SaveChanges();
  1469. }
  1470. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == merchant.KqMerNo);
  1471. if (forMerNo != null)
  1472. {
  1473. forMerNo.SnId = newpos.Id;
  1474. }
  1475. merchant.KqSnNo = NewSn;
  1476. merchant.ActiveStatus = newpos.ActivationState;
  1477. merchant.MerStandardDate = newpos.ActivationTime;
  1478. db.MachineChangeDetail.Add(new MachineChangeDetail()
  1479. {
  1480. CreateDate = DateTime.Now,
  1481. UpdateDate = DateTime.Now,
  1482. CreateMan = SysUserName + "-" + SysRealName,
  1483. ChangeNo = ChangeNo, //订单号
  1484. ChangeId = add.Id, //订单Id
  1485. BackProductType = oldpos.BrandId, //退回产品类型
  1486. BackProductName = oldPosBrand.Name, //退回产品名称
  1487. UserId = 0, //创客
  1488. BackSnNo = oldpos.PosSn, //设备SN编号
  1489. OutProductType = newpos.BrandId, //出库产品类型
  1490. OutProductName = newPosBrand.Name, //出库产品名称
  1491. OutSnNo = newpos.PosSn, //出库设备SN编号
  1492. OutSnType = newpos.PosSnType, //出库SN机具类型
  1493. Remark = "机具更换", //备注
  1494. BackSnType = oldpos.PosSnType, //退回SN机具类型
  1495. });
  1496. db.SaveChanges();
  1497. BackProductType = oldpos.BrandId;
  1498. BackProductName = newPosBrand.Name;
  1499. ChangeDeviceName = oldpos.DeviceName;
  1500. ChangeSnExpand += oldpos.PosSn + "\n";
  1501. PublicFunction.SycnMachineCount(oldpos.BuyUserId, oldpos.BrandId);
  1502. }
  1503. add.BackProductType = BackProductType; //退回产品类型
  1504. add.BackProductName = BackProductName; //退回产品名称
  1505. add.ChangeDeviceName = ChangeDeviceName; //转换机具名称
  1506. add.ChangeDeviceNum = OldSnList.Length; //转换机具数量
  1507. add.ChangeSnExpand = ChangeSnExpand; //机具SN
  1508. BackStore.LaveNum += OldSnList.Length; //退回仓库库存
  1509. OutStore.LaveNum -= OldSnList.Length; //出货仓库库存
  1510. db.SaveChanges();
  1511. db.Dispose();
  1512. if (IsSend == 1)
  1513. {
  1514. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  1515. {
  1516. UserId = pos.BuyUserId, //接收创客
  1517. MsgType = 2,
  1518. Title = "换绑成功通知", //标题
  1519. Summary = "您的 " + oldPosBrand.Name + " SN:" + OldSn + "已经成功为客户换绑为" + newPosBrand.Name + "SN:" + NewSn + "请告知客户进行绑定。",
  1520. CreateDate = DateTime.Now,
  1521. }));
  1522. }
  1523. return "success";
  1524. }
  1525. #endregion
  1526. #region 坏机换新
  1527. public IActionResult ChangeBadPos(string right)
  1528. {
  1529. ViewBag.RightInfo = RightInfo;
  1530. ViewBag.right = right;
  1531. return View();
  1532. }
  1533. [HttpPost]
  1534. public string ChangeBadPosDo(string ChangeType, string MakerCode, string StoreCode, string OldSn, string NewSn, string FromStoreNo, string BackStoreNo, int IsSend = 0)
  1535. {
  1536. string[] OldSnList;
  1537. string[] NewSnList;
  1538. decimal amount = 0;
  1539. List<string> opData = new List<string>();
  1540. //创客坏机换新
  1541. if (ChangeType == "0")
  1542. {
  1543. if (string.IsNullOrEmpty(MakerCode))
  1544. {
  1545. return "请输入创客编号";
  1546. }
  1547. if (string.IsNullOrEmpty(OldSn))
  1548. {
  1549. return "请输入坏机SN";
  1550. }
  1551. if (string.IsNullOrEmpty(NewSn))
  1552. {
  1553. return "请输入新机SN";
  1554. }
  1555. if (string.IsNullOrEmpty(FromStoreNo))
  1556. {
  1557. return "请输入新机发货仓库编号";
  1558. }
  1559. if (string.IsNullOrEmpty(BackStoreNo))
  1560. {
  1561. return "请输入坏机退回仓库编号";
  1562. }
  1563. OldSnList = OldSn.Split('\n');
  1564. NewSnList = NewSn.Split('\n');
  1565. if (OldSnList.Length != NewSnList.Length)
  1566. {
  1567. return "原机具SN数量和新机具SN数量不一致";
  1568. }
  1569. for (int i = 0; i < OldSnList.Length; i++)
  1570. {
  1571. string OldSnNum = OldSnList[i];
  1572. string NewSnNum = NewSnList[i];
  1573. UserForMakerCode userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
  1574. StoreForCode storeForCodeFrom = db.StoreForCode.FirstOrDefault(m => m.Code == FromStoreNo) ?? new StoreForCode();
  1575. if (storeForCodeFrom.StoreId == 0)
  1576. {
  1577. return "您输入的新机发货仓库编号不存在";
  1578. }
  1579. StoreForCode storeForCodeBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  1580. if (storeForCodeBack.StoreId == 0)
  1581. {
  1582. return "您输入的坏机退回仓库编号不存在";
  1583. }
  1584. MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  1585. MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
  1586. PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId && m.BindingState == 0 && m.BuyUserId == userForMakerCode.UserId) ?? new PosMachinesTwo();
  1587. if (oldpos.Id == 0)
  1588. {
  1589. return "您输入的坏机SN不存在或者不在" + MakerCode + "名下";
  1590. }
  1591. PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId && m.BindingState == 0 && m.PreUserId == 0) ?? new PosMachinesTwo();
  1592. if (newpos.Id == 0)
  1593. {
  1594. return "您输入的新机SN不存在或不满足条件";
  1595. }
  1596. StoreHouse storeFrom = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeFrom.StoreId);
  1597. if (Convert.ToInt32(storeFrom.BrandId) != Convert.ToInt32(newpos.BrandId))
  1598. {
  1599. return "您输入的新机发货仓库不符新机机具对应品牌";
  1600. }
  1601. if (newpos.StoreId != storeFrom.Id)
  1602. {
  1603. return "您输入的新机SN不在新机发货仓库";
  1604. }
  1605. StoreHouse storeBack = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeBack.StoreId);
  1606. if (Convert.ToInt32(storeBack.BrandId) != Convert.ToInt32(oldpos.BrandId))
  1607. {
  1608. return "您输入的坏机退回仓库不符坏机机具对应品牌";
  1609. }
  1610. if (Convert.ToInt32(storeBack.BrandId) != Convert.ToInt32(storeFrom.BrandId))
  1611. {
  1612. return "您输入的新机发货仓库和坏机退回仓库品牌类型不同";
  1613. }
  1614. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1615. if (brandInfo.Name.Contains("大POS"))
  1616. {
  1617. amount = 300;
  1618. }
  1619. if (brandInfo.Name.Contains("电签"))
  1620. {
  1621. amount = 200;
  1622. }
  1623. // var storeUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == store.UserId) ?? new UserAccount();
  1624. var storeFromUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeFrom.UserId) ?? new UserAccount();
  1625. var storeBackUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeBack.UserId) ?? new UserAccount();
  1626. // storeUserAcount.ValidAmount += amount;
  1627. storeFromUserAcount.ValidAmount += amount;
  1628. storeBackUserAcount.ValidAmount -= amount;
  1629. newpos.BuyUserId = oldpos.BuyUserId;
  1630. newpos.UserId = oldpos.UserId;
  1631. newpos.RecycEndDate = oldpos.RecycEndDate;
  1632. newpos.ScanQrTrade = oldpos.ScanQrTrade;
  1633. newpos.DebitCardTrade = oldpos.DebitCardTrade;
  1634. newpos.CreditTrade = oldpos.CreditTrade;
  1635. newpos.PosSnType = oldpos.PosSnType;
  1636. newpos.TransferTime = oldpos.TransferTime;
  1637. newpos.IsPurchase = oldpos.IsPurchase;
  1638. newpos.BindingState = oldpos.BindingState;
  1639. newpos.ActivationState = oldpos.ActivationState;
  1640. newpos.BindingTime = oldpos.BindingTime;
  1641. newpos.ActivationTime = oldpos.ActivationTime;
  1642. newpos.IsFirst = oldpos.IsFirst;
  1643. newpos.SeoKeyword = oldpos.SeoKeyword;
  1644. newpos.PrizeParams = oldpos.PrizeParams;
  1645. newpos.LeaderUserId = oldpos.LeaderUserId;
  1646. newpos.BindMerchantId = oldpos.BindMerchantId;
  1647. newpos.StoreId = oldpos.StoreId;
  1648. newpos.UserId = oldpos.UserId;
  1649. newpos.PreUserId = oldpos.PreUserId;
  1650. if (!opData.Contains(oldpos.BuyUserId + ":" + oldpos.BrandId))
  1651. {
  1652. opData.Add(oldpos.BuyUserId + ":" + oldpos.BrandId);
  1653. }
  1654. oldpos.StoreId = storeBack.Id;
  1655. oldpos.QueryCount = 0;
  1656. oldpos.UpdateDate = null;
  1657. oldpos.ActivityList = null;
  1658. oldpos.SeoKeyword = null;
  1659. oldpos.SeoDescription = null;
  1660. oldpos.OrderId = 0;
  1661. oldpos.RecycEndDate = null;
  1662. oldpos.RecycBackCount = 0;
  1663. oldpos.PrizeParams = null;
  1664. oldpos.ScanQrTrade = 0;
  1665. oldpos.BindMerchantId = 0;
  1666. oldpos.CreditTrade = 0;
  1667. oldpos.DebitCardTrade = 0;
  1668. oldpos.IsVip = 0;
  1669. oldpos.UserNav = null;
  1670. oldpos.TransferTime = null;
  1671. oldpos.IsPurchase = 0;
  1672. oldpos.Detail = null;
  1673. oldpos.BindingTime = null;
  1674. oldpos.BindingState = 0;
  1675. oldpos.ActivationTime = null;
  1676. oldpos.ActivationState = 0;
  1677. oldpos.LeaderUserId = 0;
  1678. oldpos.PreUserId = 0;
  1679. oldpos.IsFirst = 0;
  1680. oldpos.DownFeeMan = null;
  1681. oldpos.DownFeeFlag = 0;
  1682. oldpos.DownFeeDate = null;
  1683. oldpos.UpFeeMan = null;
  1684. oldpos.UpFeeFlag = 0;
  1685. oldpos.UpFeeDate = null;
  1686. oldpos.OpReserve1 = 0;
  1687. oldpos.OpReserve2 = 0;
  1688. oldpos.OpReserve3 = 0;
  1689. oldpos.OpId = 0;
  1690. oldpos.RecycStartDate = null;
  1691. oldpos.SourcePosSn = null;
  1692. oldpos.BuyUserId = 0;
  1693. oldpos.UserId = 0;
  1694. oldpos.Status = -1;
  1695. PublicFunction.ClearPosHistory(db, oldpos.PosSn); //清除机具历史记录
  1696. db.SaveChanges();
  1697. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == newpos.BindMerchantId);
  1698. if (merchant != null)
  1699. {
  1700. merchant.KqSnNo = newpos.PosSn;
  1701. merchant.ActiveStatus = newpos.ActivationState;
  1702. }
  1703. db.SaveChanges();
  1704. BrokenMachineChange add = db.BrokenMachineChange.Add(new BrokenMachineChange()
  1705. {
  1706. CreateDate = DateTime.Now,
  1707. CreateMan = SysUserName + "-" + SysRealName,
  1708. ChangeNo = "BPC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(3), //转换单号
  1709. OutStoreId = storeFrom.Id,
  1710. BackStoreId = storeBack.Id,
  1711. OutProductType = newpos.BrandId,
  1712. BackProductType = oldpos.BrandId,
  1713. UserId = userForMakerCode.UserId, //创客
  1714. }).Entity;
  1715. db.SaveChanges();
  1716. BrokenMachineChangeDetail adds = db.BrokenMachineChangeDetail.Add(new BrokenMachineChangeDetail()
  1717. {
  1718. CreateDate = DateTime.Now,
  1719. CreateMan = SysUserName + "-" + SysRealName,
  1720. OutSnNo = OldSnNum,
  1721. BackSnNo = NewSnNum,
  1722. ChangeNo = add.ChangeNo, //转换单号
  1723. ChangeId = add.Id, //转换记录Id
  1724. UserId = add.UserId, //创客
  1725. }).Entity;
  1726. db.SaveChanges();
  1727. var oldPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1728. if (IsSend == 1)
  1729. {
  1730. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  1731. {
  1732. UserId = userForMakerCode.UserId, //接收创客
  1733. MsgType = 2,
  1734. Title = "坏机换新成功通知", //标题
  1735. Summary = "您的坏机 " + oldPosBrand.Name + " SN:" + OldSnNum + "已经成功为您换为" + oldPosBrand.Name + "SN:" + NewSnNum + "。",
  1736. CreateDate = DateTime.Now,
  1737. }));
  1738. }
  1739. }
  1740. }
  1741. //仓库坏机换新
  1742. else
  1743. {
  1744. if (string.IsNullOrEmpty(StoreCode))
  1745. {
  1746. return "请输入仓库编号";
  1747. }
  1748. if (string.IsNullOrEmpty(OldSn))
  1749. {
  1750. return "请输入坏机SN";
  1751. }
  1752. if (string.IsNullOrEmpty(NewSn))
  1753. {
  1754. return "请输入新机SN";
  1755. }
  1756. if (string.IsNullOrEmpty(FromStoreNo))
  1757. {
  1758. return "请输入新机发货仓库编号";
  1759. }
  1760. if (string.IsNullOrEmpty(BackStoreNo))
  1761. {
  1762. return "请输入坏机退回仓库编号";
  1763. }
  1764. OldSnList = OldSn.Split('\n');
  1765. NewSnList = NewSn.Split('\n');
  1766. if (OldSnList.Length != NewSnList.Length)
  1767. {
  1768. return "原机具SN数量和新机具SN数量不一致";
  1769. }
  1770. for (int i = 0; i < OldSnList.Length; i++)
  1771. {
  1772. string OldSnNum = OldSnList[i];
  1773. string NewSnNum = NewSnList[i];
  1774. StoreHouse store = new StoreHouse();
  1775. StoreForCode storeForBadCode = db.StoreForCode.FirstOrDefault(m => m.Code == StoreCode) ?? new StoreForCode();
  1776. if (storeForBadCode.StoreId > 0)
  1777. {
  1778. store = db.StoreHouse.FirstOrDefault(m => m.Id == storeForBadCode.StoreId);
  1779. }
  1780. StoreForCode storeForCodeFrom = db.StoreForCode.FirstOrDefault(m => m.Code == FromStoreNo) ?? new StoreForCode();
  1781. if (storeForCodeFrom.StoreId == 0)
  1782. {
  1783. return "您输入的新机发货仓库编号不存在";
  1784. }
  1785. StoreForCode storeForCodeBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  1786. if (storeForCodeBack.StoreId == 0)
  1787. {
  1788. return "您输入的坏机退回仓库编号不存在";
  1789. }
  1790. MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  1791. MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
  1792. PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId && m.BindingState == 0 && m.StoreId == storeForBadCode.StoreId) ?? new PosMachinesTwo();
  1793. if (oldpos.Id == 0)
  1794. {
  1795. return "您输入的坏机SN不存在或者不在仓库" + StoreCode + "中";
  1796. }
  1797. PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId && m.BindingState == 0 && m.PreUserId == 0) ?? new PosMachinesTwo();
  1798. if (newpos.Id == 0)
  1799. {
  1800. return "您输入的新机SN不存在或不满足条件";
  1801. }
  1802. StoreHouse storeFrom = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeFrom.StoreId);
  1803. if (Convert.ToInt32(storeFrom.BrandId) != Convert.ToInt32(oldpos.BrandId))
  1804. {
  1805. return "您输入的新机发货仓库不符新机机具对应品牌";
  1806. }
  1807. if (newpos.StoreId != storeFrom.Id)
  1808. {
  1809. return "您输入的新机SN不在新机发货仓库";
  1810. }
  1811. StoreHouse storeBack = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeBack.StoreId);
  1812. if (Convert.ToInt32(storeBack.BrandId) != Convert.ToInt32(oldpos.BrandId))
  1813. {
  1814. return "您输入的坏机退回仓库不符坏机机具对应品牌";
  1815. }
  1816. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1817. if (brandInfo.Name.Contains("大POS"))
  1818. {
  1819. amount = 300;
  1820. }
  1821. if (brandInfo.Name.Contains("电签"))
  1822. {
  1823. amount = 200;
  1824. }
  1825. var storeUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == store.UserId) ?? new UserAccount();
  1826. var storeFromUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeFrom.UserId) ?? new UserAccount();
  1827. var storeBackUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeBack.UserId) ?? new UserAccount();
  1828. // storeUserAcount.ValidAmount += amount;
  1829. storeFromUserAcount.ValidAmount += amount;
  1830. storeBackUserAcount.ValidAmount -= amount;
  1831. newpos.StoreId = oldpos.StoreId;
  1832. newpos.BuyUserId = oldpos.BuyUserId;
  1833. newpos.UserId = oldpos.UserId;
  1834. newpos.LeaderUserId = oldpos.LeaderUserId;
  1835. newpos.PreUserId = oldpos.PreUserId;
  1836. newpos.IsFirst = oldpos.IsFirst;
  1837. newpos.TransferTime = oldpos.TransferTime;
  1838. if (!opData.Contains(oldpos.BuyUserId + ":" + oldpos.BrandId))
  1839. {
  1840. opData.Add(oldpos.BuyUserId + ":" + oldpos.BrandId);
  1841. }
  1842. oldpos.StoreId = storeBack.Id;
  1843. oldpos.QueryCount = 0;
  1844. oldpos.UpdateDate = null;
  1845. oldpos.ActivityList = null;
  1846. oldpos.SeoKeyword = null;
  1847. oldpos.SeoDescription = null;
  1848. oldpos.OrderId = 0;
  1849. oldpos.RecycEndDate = null;
  1850. oldpos.RecycBackCount = 0;
  1851. oldpos.PrizeParams = null;
  1852. oldpos.ScanQrTrade = 0;
  1853. oldpos.BindMerchantId = 0;
  1854. oldpos.CreditTrade = 0;
  1855. oldpos.DebitCardTrade = 0;
  1856. oldpos.IsVip = 0;
  1857. oldpos.UserNav = null;
  1858. oldpos.TransferTime = null;
  1859. oldpos.IsPurchase = 0;
  1860. oldpos.Detail = null;
  1861. oldpos.BindingTime = null;
  1862. oldpos.BindingState = 0;
  1863. oldpos.ActivationTime = null;
  1864. oldpos.ActivationState = 0;
  1865. oldpos.LeaderUserId = 0;
  1866. oldpos.PreUserId = 0;
  1867. oldpos.IsFirst = 0;
  1868. oldpos.DownFeeMan = null;
  1869. oldpos.DownFeeFlag = 0;
  1870. oldpos.DownFeeDate = null;
  1871. oldpos.UpFeeMan = null;
  1872. oldpos.UpFeeFlag = 0;
  1873. oldpos.UpFeeDate = null;
  1874. oldpos.OpReserve1 = 0;
  1875. oldpos.OpReserve2 = 0;
  1876. oldpos.OpReserve3 = 0;
  1877. oldpos.OpId = 0;
  1878. oldpos.RecycStartDate = null;
  1879. oldpos.SourcePosSn = null;
  1880. oldpos.BuyUserId = 0;
  1881. oldpos.UserId = 0;
  1882. oldpos.Status = -1;
  1883. PublicFunction.ClearPosHistory(db, oldpos.PosSn); //清除机具历史记录
  1884. db.SaveChanges();
  1885. BrokenMachineChange add = db.BrokenMachineChange.Add(new BrokenMachineChange()
  1886. {
  1887. CreateDate = DateTime.Now,
  1888. CreateMan = SysUserName + "-" + SysRealName,
  1889. ChangeNo = "BPC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(3), //转换单号
  1890. OutStoreId = storeFrom.Id,
  1891. BackStoreId = storeBack.Id,
  1892. OutProductType = newpos.BrandId,
  1893. BackProductType = oldpos.BrandId,
  1894. UserId = store.UserId, //创客
  1895. }).Entity;
  1896. db.SaveChanges();
  1897. BrokenMachineChangeDetail adds = db.BrokenMachineChangeDetail.Add(new BrokenMachineChangeDetail()
  1898. {
  1899. CreateDate = DateTime.Now,
  1900. CreateMan = SysUserName + "-" + SysRealName,
  1901. OutSnNo = OldSnNum,
  1902. BackSnNo = NewSnNum,
  1903. ChangeNo = add.ChangeNo, //转换单号
  1904. ChangeId = add.Id, //转换记录Id
  1905. UserId = add.UserId, //创客
  1906. }).Entity;
  1907. db.SaveChanges();
  1908. var oldPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1909. if (IsSend == 1)
  1910. {
  1911. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  1912. {
  1913. UserId = store.UserId, //接收创客
  1914. MsgType = 2,
  1915. Title = "坏机换新成功通知", //标题
  1916. Summary = "您的坏机 " + oldPosBrand.Name + " SN:" + OldSnNum + "已经成功为您换为" + oldPosBrand.Name + "SN:" + NewSnNum + "。",
  1917. CreateDate = DateTime.Now,
  1918. }));
  1919. }
  1920. }
  1921. }
  1922. // for (int i = 0; i < OldSnList.Length; i++)
  1923. // {
  1924. // string OldSnNum = OldSnList[i];
  1925. // string NewSnNum = NewSnList[i];
  1926. // StoreForCode storeForCode = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  1927. // MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  1928. // MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
  1929. // StoreHouse oldStore = new StoreHouse();
  1930. // PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId && m.BindingState == 0);
  1931. // if (storeForCode.StoreId > 0)
  1932. // {
  1933. // StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCode.StoreId);
  1934. // if (Convert.ToInt32(store.BrandId) != Convert.ToInt32(oldpos.BrandId))
  1935. // {
  1936. // return "您输入的仓库不符机具对应品牌";
  1937. // }
  1938. // oldStore = db.StoreHouse.FirstOrDefault(m => m.Id == oldpos.StoreId);
  1939. // oldpos.Status = -1;
  1940. // oldpos.StoreId = store.Id;
  1941. // }
  1942. // if (oldpos == null)
  1943. // {
  1944. // return "原机具SN不正确或者不符合换机条件";
  1945. // }
  1946. // PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId && m.BuyUserId == 0 && m.UserId == 0 && m.BindingState == 0);
  1947. // if (newpos == null)
  1948. // {
  1949. // return "新机具SN不正确或者不为仓库机";
  1950. // }
  1951. // if (oldpos.BrandId != newpos.BrandId)
  1952. // {
  1953. // return "新机具和旧机具品牌不相同";
  1954. // }
  1955. // var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == newpos.BrandId) ?? new KqProducts();
  1956. // if (brandInfo.Name.Contains("大POS"))
  1957. // {
  1958. // amount = 300;
  1959. // }
  1960. // if (brandInfo.Name.Contains("电签"))
  1961. // {
  1962. // amount = 200;
  1963. // }
  1964. // var storehouse = db.StoreHouse.FirstOrDefault(m => m.Id == newpos.StoreId) ?? new StoreHouse();
  1965. // storehouse.LaveNum -= 1;
  1966. // var userAcount = db.UserAccount.FirstOrDefault(m => m.Id == storehouse.UserId) ?? new UserAccount();
  1967. // if (oldpos.StoreId != newpos.StoreId)
  1968. // {
  1969. // userAcount.ValidAmount += amount;
  1970. // newpos.StoreId = oldpos.StoreId;
  1971. // newpos.BuyUserId = oldpos.BuyUserId;
  1972. // newpos.UserId = oldpos.UserId;
  1973. // newpos.LeaderUserId = oldpos.LeaderUserId;
  1974. // newpos.PreUserId = oldpos.PreUserId;
  1975. // newpos.IsFirst = oldpos.IsFirst;
  1976. // newpos.TransferTime = oldpos.TransferTime;
  1977. // }
  1978. // else
  1979. // {
  1980. // newpos.BuyUserId = oldpos.BuyUserId;
  1981. // newpos.UserId = oldpos.UserId;
  1982. // newpos.LeaderUserId = oldpos.LeaderUserId;
  1983. // newpos.PreUserId = oldpos.PreUserId;
  1984. // newpos.IsFirst = oldpos.IsFirst;
  1985. // newpos.TransferTime = oldpos.TransferTime;
  1986. // }
  1987. // db.SaveChanges();
  1988. // var oldPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1989. // var newPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == newpos.BrandId) ?? new KqProducts();
  1990. // var UserId = 0;
  1991. // if (oldpos.BuyUserId == 0)
  1992. // {
  1993. // UserId = oldStore.UserId;
  1994. // }
  1995. // else
  1996. // {
  1997. // UserId = oldpos.BuyUserId;
  1998. // }
  1999. // BrokenMachineChange add = db.BrokenMachineChange.Add(new BrokenMachineChange()
  2000. // {
  2001. // CreateDate = DateTime.Now,
  2002. // CreateMan = SysUserName + "-" + SysRealName,
  2003. // ChangeNo = "BPC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(3), //转换单号
  2004. // UserId = UserId, //创客
  2005. // }).Entity;
  2006. // db.SaveChanges();
  2007. // BrokenMachineChangeDetail adds = db.BrokenMachineChangeDetail.Add(new BrokenMachineChangeDetail()
  2008. // {
  2009. // CreateDate = DateTime.Now,
  2010. // CreateMan = SysUserName + "-" + SysRealName,
  2011. // OutSnNo = OldSnNum,
  2012. // BackSnNo = NewSnNum,
  2013. // ChangeNo = add.ChangeNo, //转换单号
  2014. // ChangeId = add.Id, //转换记录Id
  2015. // UserId = add.UserId, //创客
  2016. // }).Entity;
  2017. // db.SaveChanges();
  2018. // if (IsSend == 1)
  2019. // {
  2020. // RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  2021. // {
  2022. // UserId = UserId, //接收创客
  2023. // MsgType = 2,
  2024. // Title = "坏机换新成功通知", //标题
  2025. // Summary = "您的坏机 " + oldPosBrand.Name + " SN:" + OldSn + "已经成功为您换为" + newPosBrand.Name + "SN:" + NewSn + "。",
  2026. // CreateDate = DateTime.Now,
  2027. // }));
  2028. // }
  2029. // }
  2030. foreach (string sub in opData)
  2031. {
  2032. string[] datalist = sub.Split(":");
  2033. PublicFunction.SycnMachineCount(int.Parse(datalist[0]), int.Parse(datalist[1]));
  2034. }
  2035. return "success";
  2036. }
  2037. #endregion
  2038. // #region 机具解绑
  2039. // public IActionResult Unbind(string right)
  2040. // {
  2041. // ViewBag.RightInfo = RightInfo;
  2042. // ViewBag.right = right;
  2043. // return View();
  2044. // }
  2045. // [HttpPost]
  2046. // public string UnbindDo(string PosSn, string MakerCode, string MerNo, int IsSend = 0)
  2047. // {
  2048. // if (string.IsNullOrEmpty(PosSn))
  2049. // {
  2050. // return "请输入机具SN";
  2051. // }
  2052. // if (string.IsNullOrEmpty(MakerCode))
  2053. // {
  2054. // return "请输入创客编号";
  2055. // }
  2056. // MachineForSnNo forSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn);
  2057. // if (forSnNo == null)
  2058. // {
  2059. // return "机具SN不存在";
  2060. // }
  2061. // PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == forSnNo.SnId);
  2062. // if (pos == null)
  2063. // {
  2064. // return "机具SN不存在";
  2065. // }
  2066. // if (string.IsNullOrEmpty(MerNo) && pos.BrandId != 1 && pos.BrandId != 3)
  2067. // {
  2068. // return "请输入商户编号";
  2069. // }
  2070. // UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  2071. // if (forMakerCode == null)
  2072. // {
  2073. // return "创客不存在";
  2074. // }
  2075. // MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == MerNo);
  2076. // if (forMerNo == null && pos.BrandId != 1 && pos.BrandId != 3)
  2077. // {
  2078. // return "商户编号不存在";
  2079. // }
  2080. // if (pos.BuyUserId != forMakerCode.UserId)
  2081. // {
  2082. // return "机具SN和创客不匹配";
  2083. // }
  2084. // if (pos.ActivationState == 1)
  2085. // {
  2086. // return "机具已激活,不能解绑";
  2087. // }
  2088. // if (pos.BuyUserId == 0)
  2089. // {
  2090. // return "机具是仓库机,不支持解绑";
  2091. // }
  2092. // if (pos.BindingState == 0)
  2093. // {
  2094. // return "机具未绑定,不支持解绑";
  2095. // }
  2096. // if (pos.BindingTime < DateTime.Now.AddDays(-30) && SysUserName != "admin")
  2097. // {
  2098. // return "机具绑定已超过30天,不支持解绑";
  2099. // }
  2100. // if (pos.CreditTrade > 0 || !string.IsNullOrEmpty(pos.SeoKeyword))
  2101. // {
  2102. // return "该机具已交易,无法解绑";
  2103. // }
  2104. // if (forMerNo != null)
  2105. // {
  2106. // PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  2107. // if (merchant != null)
  2108. // {
  2109. // //机具解绑删除客小爽企业版对应数据
  2110. // var merInfo = db.BusinessPartnerMerchant.FirstOrDefault(m => m.MerchantId == merchant.Id);
  2111. // if (merInfo != null)
  2112. // {
  2113. // db.BusinessPartnerMerchant.Remove(merInfo);
  2114. // }
  2115. // var posInfo = db.BusinessPartnerPos.FirstOrDefault(m => m.PosId == pos.Id);
  2116. // if (posInfo != null)
  2117. // {
  2118. // db.BusinessPartnerPos.Remove(posInfo);
  2119. // }
  2120. // db.PosMerchantInfo.Remove(merchant);
  2121. // }
  2122. // db.MachineForMerNo.Remove(forMerNo);
  2123. // db.SaveChanges();
  2124. // }
  2125. // db.MachineUnBind.Add(new MachineUnBind()
  2126. // {
  2127. // CreateDate = DateTime.Now,
  2128. // SeoTitle = SysUserName + "-" + SysRealName,
  2129. // MerchantId = pos.BindMerchantId,
  2130. // AuditDate = DateTime.Now,
  2131. // AuditDesc = "平台操作解绑",
  2132. // AuditStatus = 1,
  2133. // SnNo = pos.PosSn,
  2134. // BrandId = pos.BrandId,
  2135. // UserId = pos.BuyUserId,
  2136. // ApplyNo = "U" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8),
  2137. // });
  2138. // pos.BindMerchantId = 0;
  2139. // pos.BindingState = 0;
  2140. // pos.BindingTime = DateTime.Parse("1900-01-01");
  2141. // pos.UserId = pos.BuyUserId;
  2142. // string IdBrand = pos.BuyUserId + "_" + pos.BrandId;
  2143. // db.SaveChanges();
  2144. // PublicFunction.SycnMachineCount(pos.BuyUserId, pos.BrandId);
  2145. // if (IsSend == 1)
  2146. // {
  2147. // RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  2148. // {
  2149. // UserId = pos.BuyUserId, //接收创客
  2150. // MsgType = 2,
  2151. // Title = "解绑成功通知", //标题
  2152. // Summary = "" + PosSn + "机具已成功解绑,当前机具如需绑定同一客户请再2个工作日后再进行绑定,直接绑定会导致数控异常,相关损失由您本人承担。",
  2153. // CreateDate = DateTime.Now,
  2154. // }));
  2155. // }
  2156. // return "success";
  2157. // }
  2158. // #endregion
  2159. #region 机具解绑
  2160. public IActionResult Unbind(string right)
  2161. {
  2162. ViewBag.RightInfo = RightInfo;
  2163. ViewBag.right = right;
  2164. return View();
  2165. }
  2166. [HttpPost]
  2167. public string UnbindDo(string PosSn, string MakerCode, string MerNo, int IsSend = 0)
  2168. {
  2169. if (string.IsNullOrEmpty(PosSn))
  2170. {
  2171. return "请输入机具SN";
  2172. }
  2173. MachineForSnNo forSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn);
  2174. if (forSnNo == null)
  2175. {
  2176. return "机具SN不存在";
  2177. }
  2178. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == forSnNo.SnId);
  2179. if (pos == null)
  2180. {
  2181. return "机具SN不存在";
  2182. }
  2183. if (pos.ActivationState == 1)
  2184. {
  2185. return "机具已激活,不能解绑";
  2186. }
  2187. if (pos.BuyUserId == 0)
  2188. {
  2189. return "机具是仓库机,不支持解绑";
  2190. }
  2191. if (pos.BindingState == 0)
  2192. {
  2193. return "机具未绑定,不支持解绑";
  2194. }
  2195. if (pos.BindingTime < DateTime.Now.AddDays(-30) && SysUserName != "admin")
  2196. {
  2197. return "机具绑定已超过30天,不支持解绑";
  2198. }
  2199. if (pos.CreditTrade > 0 || !string.IsNullOrEmpty(pos.SeoKeyword))
  2200. {
  2201. return "该机具已交易,无法解绑";
  2202. }
  2203. if (pos.BrandId != 10 || pos.BrandId != 11)
  2204. {
  2205. if (string.IsNullOrEmpty(MakerCode))
  2206. {
  2207. return "请输入创客编号";
  2208. }
  2209. // if (string.IsNullOrEmpty(MerNo) && pos.BrandId != 1 && pos.BrandId != 3)
  2210. if (string.IsNullOrEmpty(MerNo))
  2211. {
  2212. return "请输入商户编号";
  2213. }
  2214. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  2215. if (forMakerCode == null)
  2216. {
  2217. return "创客不存在";
  2218. }
  2219. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == MerNo);
  2220. // if (forMerNo == null && pos.BrandId != 1 && pos.BrandId != 3)
  2221. if (forMerNo == null)
  2222. {
  2223. return "商户编号不存在";
  2224. }
  2225. if (pos.BuyUserId != forMakerCode.UserId)
  2226. {
  2227. return "机具SN和创客不匹配";
  2228. }
  2229. if (forMerNo != null)
  2230. {
  2231. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  2232. if (merchant != null)
  2233. {
  2234. //机具解绑删除客小爽企业版对应数据
  2235. var merInfo = db.BusinessPartnerMerchant.FirstOrDefault(m => m.MerchantId == merchant.Id);
  2236. if (merInfo != null)
  2237. {
  2238. db.BusinessPartnerMerchant.Remove(merInfo);
  2239. }
  2240. var posInfo = db.BusinessPartnerPos.FirstOrDefault(m => m.PosId == pos.Id);
  2241. if (posInfo != null)
  2242. {
  2243. db.BusinessPartnerPos.Remove(posInfo);
  2244. }
  2245. db.PosMerchantInfo.Remove(merchant);
  2246. }
  2247. db.MachineForMerNo.Remove(forMerNo);
  2248. db.SaveChanges();
  2249. }
  2250. }
  2251. else
  2252. {
  2253. var posMerchantInfo = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
  2254. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == MerNo);
  2255. if (forMerNo != null && posMerchantInfo != null)
  2256. {
  2257. //机具解绑删除客小爽企业版对应数据
  2258. var merInfo = db.BusinessPartnerMerchant.FirstOrDefault(m => m.MerchantId == posMerchantInfo.Id);
  2259. if (merInfo != null)
  2260. {
  2261. db.BusinessPartnerMerchant.Remove(merInfo);
  2262. }
  2263. var posInfo = db.BusinessPartnerPos.FirstOrDefault(m => m.PosId == pos.Id);
  2264. if (posInfo != null)
  2265. {
  2266. db.BusinessPartnerPos.Remove(posInfo);
  2267. }
  2268. db.PosMerchantInfo.Remove(posMerchantInfo);
  2269. db.MachineForMerNo.Remove(forMerNo);
  2270. db.SaveChanges();
  2271. }
  2272. }
  2273. db.MachineUnBind.Add(new MachineUnBind()
  2274. {
  2275. CreateDate = DateTime.Now,
  2276. SeoTitle = SysUserName + "-" + SysRealName,
  2277. MerchantId = pos.BindMerchantId,
  2278. AuditDate = DateTime.Now,
  2279. AuditDesc = "平台操作解绑",
  2280. AuditStatus = 1,
  2281. SnNo = pos.PosSn,
  2282. BrandId = pos.BrandId,
  2283. UserId = pos.BuyUserId,
  2284. ApplyNo = "U" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8),
  2285. });
  2286. pos.BindMerchantId = 0;
  2287. pos.BindingState = 0;
  2288. pos.BindingTime = DateTime.Parse("1900-01-01");
  2289. pos.UserId = pos.BuyUserId;
  2290. string IdBrand = pos.BuyUserId + "_" + pos.BrandId;
  2291. db.SaveChanges();
  2292. PublicFunction.SycnMachineCount(pos.BuyUserId, pos.BrandId);
  2293. if (IsSend == 1)
  2294. {
  2295. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  2296. {
  2297. UserId = pos.BuyUserId, //接收创客
  2298. MsgType = 2,
  2299. Title = "解绑成功通知", //标题
  2300. Summary = "" + PosSn + "机具已成功解绑,当前机具如需绑定同一客户请再2个工作日后再进行绑定,直接绑定会导致数控异常,相关损失由您本人承担。",
  2301. CreateDate = DateTime.Now,
  2302. }));
  2303. }
  2304. return "success";
  2305. }
  2306. #endregion
  2307. #region 通过券码修改盟主标记
  2308. public IActionResult ChangeSignQuan(string right)
  2309. {
  2310. ViewBag.RightInfo = RightInfo;
  2311. ViewBag.right = right;
  2312. return View();
  2313. }
  2314. [HttpPost]
  2315. public string ChangeSignQuanDo(string Coupons, string MakerCode)
  2316. {
  2317. if (string.IsNullOrEmpty(Coupons))
  2318. {
  2319. return "请输入机具券码,多个券码用回车分隔";
  2320. }
  2321. if (string.IsNullOrEmpty(MakerCode))
  2322. {
  2323. return "请输入创客编号";
  2324. }
  2325. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  2326. if (forMakerCode == null)
  2327. {
  2328. return "创客不存在";
  2329. }
  2330. string[] SnList = Coupons.Split('\n');
  2331. foreach (var item in SnList)
  2332. {
  2333. var coupos = db.PosCoupons.FirstOrDefault(m => m.ExchangeCode == item && m.LeaderUserId == 0);
  2334. if (coupos == null)
  2335. {
  2336. return "机具券不存在";
  2337. }
  2338. else
  2339. {
  2340. coupos.LeaderUserId = forMakerCode.UserId;
  2341. }
  2342. }
  2343. db.SaveChanges();
  2344. return "success";
  2345. }
  2346. #endregion
  2347. #region 通过机具SN修改盟主标记
  2348. public IActionResult ChangeSignSn(string right)
  2349. {
  2350. ViewBag.RightInfo = RightInfo;
  2351. ViewBag.right = right;
  2352. return View();
  2353. }
  2354. [HttpPost]
  2355. public string ChangeSignSnDo(string PosSn, string MakerCode)
  2356. {
  2357. if (string.IsNullOrEmpty(PosSn))
  2358. {
  2359. return "请输入机具SN,多个SN用回车分隔";
  2360. }
  2361. if (string.IsNullOrEmpty(MakerCode))
  2362. {
  2363. return "请输入创客编号";
  2364. }
  2365. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  2366. if (forMakerCode == null)
  2367. {
  2368. return "创客不存在";
  2369. }
  2370. string[] SnList = PosSn.Split('\n');
  2371. foreach (var item in SnList)
  2372. {
  2373. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == item && m.LeaderUserId == 0);
  2374. if (pos == null)
  2375. {
  2376. return "该机具不存在";
  2377. }
  2378. else
  2379. {
  2380. pos.LeaderUserId = forMakerCode.UserId;
  2381. }
  2382. }
  2383. db.SaveChanges();
  2384. return "success";
  2385. }
  2386. #endregion
  2387. #region 机具循环列表
  2388. /// <summary>
  2389. /// 根据条件查询机具循环列表
  2390. /// </summary>
  2391. /// <returns></returns>
  2392. public IActionResult Loop(string right, string SwapSnExpand, string SnNos)
  2393. {
  2394. ViewBag.RightInfo = RightInfo;
  2395. ViewBag.right = right;
  2396. ViewBag.SwapSnExpand = SwapSnExpand;
  2397. ViewBag.SnNos = SnNos;
  2398. return View();
  2399. }
  2400. #endregion
  2401. #region 根据条件查询机具循环列表
  2402. /// <summary>
  2403. /// 机具循环列表
  2404. /// </summary>
  2405. /// <returns></returns>
  2406. public IActionResult LoopData(string SwapSnExpand, string SnNos, int page = 1, int limit = 30)
  2407. {
  2408. Dictionary<string, string> Fields = new Dictionary<string, string>();
  2409. Fields.Add("SwapSnExpand", "1"); //申请机具SN
  2410. Fields.Add("SnNos", "1"); //发货机具SN
  2411. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  2412. if (!string.IsNullOrEmpty(SwapSnExpand))
  2413. {
  2414. var apply = db.MachineApply.FirstOrDefault(m => m.Status > -1 && m.SwapSnExpand.Contains(SwapSnExpand)) ?? new MachineApply();
  2415. var order = db.Orders.FirstOrDefault(m => m.Id == apply.QueryCount) ?? new Orders();
  2416. var user = db.Users.FirstOrDefault(m => m.Id == apply.UserId) ?? new Users();
  2417. string[] SnNoList = function.CheckNull(apply.SwapSnExpand).TrimEnd('\n').Split('\n');
  2418. string[] OrderSnNo = function.CheckNull(order.SnNos).Split(',');
  2419. for (int i = 0; i < SnNoList.Length; i++)
  2420. {
  2421. Dictionary<string, object> data = new Dictionary<string, object>();
  2422. data["ApplyNo"] = apply.ApplyNo;
  2423. data["OrderNo"] = order.OrderNo;
  2424. data["MakerCode"] = user.MakerCode;
  2425. data["RealName"] = user.RealName;
  2426. if (SnNoList.Length > i)
  2427. {
  2428. string SourceSn = SnNoList[i].Split(':')[0];
  2429. data["ComeSn"] = SnNoList[i];
  2430. data["ComeSnParam"] = SourceSn;
  2431. MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SourceSn) ?? new MachineForSnNo();
  2432. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
  2433. if (pos.LeaderUserId > 0)
  2434. {
  2435. Users leader = db.Users.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new Users();
  2436. data["ComeSnMakerCode"] = leader.MakerCode;
  2437. data["ComeSnRealName"] = leader.RealName;
  2438. }
  2439. }
  2440. if (OrderSnNo.Length > i)
  2441. {
  2442. string SendSn = OrderSnNo[i];
  2443. data["SendSn"] = OrderSnNo[i];
  2444. MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SendSn) ?? new MachineForSnNo();
  2445. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
  2446. if (pos.LeaderUserId > 0)
  2447. {
  2448. Users leader = db.Users.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new Users();
  2449. data["SendSnMakerCode"] = leader.MakerCode;
  2450. data["SendSnRealName"] = leader.RealName;
  2451. }
  2452. }
  2453. data["CreateDate"] = apply.CreateDate == null ? "" : apply.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  2454. data["Status"] = order.Status == 2 ? "已发货" : "未发货";
  2455. dataList.Add(data);
  2456. }
  2457. }
  2458. else if (!string.IsNullOrEmpty(SnNos))
  2459. {
  2460. var order = db.Orders.FirstOrDefault(m => m.Status > -1 && m.SnNos.Contains(SnNos)) ?? new Orders();
  2461. var apply = db.MachineApply.FirstOrDefault(m => m.Id == order.Sort) ?? new MachineApply();
  2462. var user = db.Users.FirstOrDefault(m => m.Id == apply.UserId) ?? new Users();
  2463. string[] SnNoList = function.CheckNull(apply.SwapSnExpand).TrimEnd('\n').Split('\n');
  2464. string[] OrderSnNo = function.CheckNull(order.SnNos).Split(',');
  2465. for (int i = 0; i < OrderSnNo.Length; i++)
  2466. {
  2467. Dictionary<string, object> data = new Dictionary<string, object>();
  2468. data["ApplyNo"] = apply.ApplyNo;
  2469. data["OrderNo"] = order.OrderNo;
  2470. data["MakerCode"] = user.MakerCode;
  2471. data["RealName"] = user.RealName;
  2472. if (SnNoList.Length > i)
  2473. {
  2474. string SourceSn = SnNoList[i].Split(':')[0];
  2475. data["ComeSn"] = SnNoList[i];
  2476. data["ComeSnParam"] = SourceSn;
  2477. MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SourceSn) ?? new MachineForSnNo();
  2478. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
  2479. if (pos.LeaderUserId > 0)
  2480. {
  2481. Users leader = db.Users.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new Users();
  2482. data["ComeSnMakerCode"] = leader.MakerCode;
  2483. data["ComeSnRealName"] = leader.RealName;
  2484. }
  2485. }
  2486. if (OrderSnNo.Length > i)
  2487. {
  2488. string SendSn = OrderSnNo[i];
  2489. data["SendSn"] = OrderSnNo[i];
  2490. MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SendSn) ?? new MachineForSnNo();
  2491. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
  2492. if (pos.LeaderUserId > 0)
  2493. {
  2494. Users leader = db.Users.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new Users();
  2495. data["SendSnMakerCode"] = leader.MakerCode;
  2496. data["SendSnRealName"] = leader.RealName;
  2497. }
  2498. }
  2499. data["CreateDate"] = apply.CreateDate == null ? "" : apply.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  2500. data["Status"] = order.Status == 2 ? "已发货" : "未发货";
  2501. dataList.Add(data);
  2502. }
  2503. }
  2504. Dictionary<string, object> obj = new Dictionary<string, object>();
  2505. obj.Add("code", 0);
  2506. obj.Add("msg", "");
  2507. obj.Add("count", dataList.Count);
  2508. obj.Add("data", dataList);
  2509. return Json(obj);
  2510. }
  2511. #endregion
  2512. #region 查询机具循环
  2513. /// <summary>
  2514. /// 根据条件查询机具来源机具和券码
  2515. /// </summary>
  2516. /// <returns></returns>
  2517. public IActionResult SourceLoop(string right, string SnNos)
  2518. {
  2519. ViewBag.RightInfo = RightInfo;
  2520. ViewBag.right = right;
  2521. ViewBag.SnNos = SnNos;
  2522. return View();
  2523. }
  2524. #endregion
  2525. #region 根据条件查询机具来源机具和券码
  2526. /// <summary>
  2527. /// 机具循环列表
  2528. /// </summary>
  2529. /// <returns></returns>
  2530. public string SourceLoopData(string SnNo, int page = 1, int limit = 30)
  2531. {
  2532. var result = "";
  2533. var machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SnNo) ?? new MachineForSnNo();
  2534. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId) ?? new PosMachinesTwo();
  2535. if (pos.Id == 0)
  2536. {
  2537. return "机具:" + SnNo + "不存在";
  2538. }
  2539. else
  2540. {
  2541. var stattime = pos.RecycStartDate == null ? "" : pos.RecycStartDate.Value.ToString("yyyy-MM-dd hh:mm:ss");
  2542. var endtime = pos.RecycEndDate == null ? "" : pos.RecycEndDate.Value.ToString("yyyy-MM-dd hh:mm:ss");
  2543. result += "循环开始时间:" + stattime + "\n";
  2544. result += "循环结束时间:" + endtime + "\n";
  2545. result += "来源机具/券:" + pos.SourcePosSn + "\n";
  2546. }
  2547. return result;
  2548. }
  2549. #endregion
  2550. #region 查询创客直推奖
  2551. public IActionResult Prize100(string right)
  2552. {
  2553. ViewBag.RightInfo = RightInfo;
  2554. ViewBag.right = right;
  2555. return View();
  2556. }
  2557. [HttpPost]
  2558. public Dictionary<string, string> Prize100Do(string MakerCode)
  2559. {
  2560. Dictionary<string, string> dic = new Dictionary<string, string>();
  2561. string result = "";
  2562. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  2563. if (forMakerCode == null)
  2564. {
  2565. result += "创客编号不存在\n";
  2566. dic.Add("code", "1");
  2567. dic.Add("result", result);
  2568. return dic;
  2569. }
  2570. int OrderCount = db.Orders.Count(m => m.UserId == forMakerCode.UserId && m.PayStatus == 1 && m.TotalPrice == 600);
  2571. if (OrderCount == 0)
  2572. {
  2573. result += "该创客未下单\n";
  2574. dic.Add("code", "1");
  2575. dic.Add("result", result);
  2576. return dic;
  2577. }
  2578. if (OrderCount > 1)
  2579. {
  2580. result += "该创客已不是首笔下单\n";
  2581. dic.Add("code", "1");
  2582. dic.Add("result", result);
  2583. return dic;
  2584. }
  2585. Orders order = db.Orders.FirstOrDefault(m => m.UserId == forMakerCode.UserId && m.PayStatus == 1 && m.TotalPrice == 600) ?? new Orders();
  2586. if (order.PayStatus < 1)
  2587. {
  2588. result += "未付款\n";
  2589. dic.Add("code", "1");
  2590. dic.Add("result", result);
  2591. return dic;
  2592. }
  2593. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId) ?? new Users();
  2594. Users puser = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId) ?? new Users();
  2595. result += "订单号:" + order.OrderNo + "\n";
  2596. result += "下单创客\n创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile + "\n";
  2597. result += "上级创客\n创客编号:" + puser.MakerCode + ",姓名:" + puser.RealName + ",手机号:" + puser.Mobile + "\n";
  2598. int machineCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.PosSnType == 0); //判断是否拥有3台兑换机
  2599. int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  2600. if (machineCount + ActiveCount >= 3)
  2601. {
  2602. string IsGet = "未发放";
  2603. int ToUserId = 0;
  2604. UserAccountRecord item = db.UserAccountRecord.FirstOrDefault(m => m.QueryCount == order.Id && m.ChangeType == 112);
  2605. if (item == null)
  2606. {
  2607. DateTime start = order.PayDate.Value.AddMinutes(-2);
  2608. DateTime end = order.PayDate.Value.AddMinutes(2);
  2609. item = db.UserAccountRecord.FirstOrDefault(m => m.UserId == puser.Id && m.ChangeType == 112 && m.ChangeAmount == 100 && m.CreateDate >= start && m.CreateDate <= end);
  2610. }
  2611. if (item != null)
  2612. {
  2613. IsGet = "已发放(发放时间:" + item.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
  2614. ToUserId = item.UserId;
  2615. dic.Add("code", "1");
  2616. }
  2617. else
  2618. {
  2619. dic.Add("id", order.Id.ToString());
  2620. dic.Add("code", "0");
  2621. }
  2622. Users touser = db.Users.FirstOrDefault(m => m.Id == ToUserId) ?? new Users();
  2623. result += "是否发放:" + IsGet + "\n";
  2624. result += "应该发放对象\n创客编号:" + puser.MakerCode + ",姓名:" + puser.RealName + ",手机号:" + puser.Mobile + "\n";
  2625. result += "实际发放对象\n创客编号:" + touser.MakerCode + ",姓名:" + touser.RealName + ",手机号:" + touser.Mobile + "\n";
  2626. }
  2627. else
  2628. {
  2629. result += "上级创客未满足条件\n兑换机:" + machineCount + "台,激活机:" + ActiveCount + "台\n";
  2630. dic.Add("code", "1");
  2631. }
  2632. dic.Add("result", result);
  2633. return dic;
  2634. }
  2635. public string AddPrize100(int Id)
  2636. {
  2637. Orders order = db.Orders.FirstOrDefault(m => m.Id == Id);
  2638. if (order != null)
  2639. {
  2640. //机具券逻辑
  2641. OrderProduct pro = db.OrderProduct.FirstOrDefault(m => m.OrderId == Id);
  2642. if (pro != null)
  2643. {
  2644. //推荐下单奖励
  2645. if (pro.ProductId == 10 || pro.ProductId == 11)
  2646. {
  2647. int OrderId = order.Id;
  2648. bool checkPrize = db.UserAccountRecord.Any(m => m.QueryCount == OrderId && m.ChangeType == 112);
  2649. if (!checkPrize)
  2650. {
  2651. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId);
  2652. if (user != null)
  2653. {
  2654. bool directPrize = false; //直推奖标记
  2655. int ParentUserId = user.ParentUserId;
  2656. // List<int> proids = new List<int>();
  2657. // proids.Add(10);
  2658. // proids.Add(11);
  2659. while (ParentUserId > 0)
  2660. {
  2661. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  2662. int machineCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.PosSnType == 0); //判断是否拥有3台兑换机
  2663. int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  2664. int couponCount = db.PosCoupons.Count(m => m.UserId == ParentUserId && m.IsUse == 0); //判断是否拥有3张券
  2665. if ((machineCount + ActiveCount + couponCount >= 3 || puser.LeaderLevel > 0) && !directPrize)
  2666. {
  2667. DirectPrize(db, order.Id, ParentUserId, pro.ProductCount);
  2668. directPrize = true;
  2669. db.SaveChanges();
  2670. return "发放成功";
  2671. }
  2672. ParentUserId = puser.ParentUserId;
  2673. }
  2674. }
  2675. }
  2676. return "已发放,请勿重复发放";
  2677. }
  2678. }
  2679. }
  2680. return "操作失败";
  2681. }
  2682. public void DirectPrize(WebCMSEntities db, int OrderId, int UserId, int Count = 1)
  2683. {
  2684. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId);
  2685. if (account == null)
  2686. {
  2687. account = db.UserAccount.Add(new UserAccount()
  2688. {
  2689. Id = UserId,
  2690. UserId = UserId,
  2691. }).Entity;
  2692. db.SaveChanges();
  2693. }
  2694. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  2695. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  2696. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  2697. account.BalanceAmount += 100 * Count;
  2698. account.TotalAmount += 100 * Count;
  2699. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  2700. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  2701. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  2702. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  2703. {
  2704. CreateDate = DateTime.Now,
  2705. UpdateDate = DateTime.Now,
  2706. UserId = UserId, //创客
  2707. ChangeType = 112, //变动类型
  2708. ChangeAmount = 100 * Count, //变更金额
  2709. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  2710. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  2711. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  2712. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  2713. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  2714. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  2715. QueryCount = OrderId,
  2716. }).Entity;
  2717. db.SaveChanges();
  2718. }
  2719. #endregion
  2720. #region 查询机具开机奖
  2721. public IActionResult OpenPrize(string right)
  2722. {
  2723. ViewBag.RightInfo = RightInfo;
  2724. ViewBag.right = right;
  2725. return View();
  2726. }
  2727. [HttpPost]
  2728. public Dictionary<string, string> OpenPrizeDo(string PosSn)
  2729. {
  2730. Dictionary<string, string> dic = new Dictionary<string, string>();
  2731. string result = "";
  2732. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  2733. if (pos == null)
  2734. {
  2735. result += "机具SN号不存在\n";
  2736. dic.Add("code", "1");
  2737. dic.Add("result", result);
  2738. return dic;
  2739. }
  2740. if (pos.BindingState == 0)
  2741. {
  2742. result += "机具未绑定\n";
  2743. dic.Add("code", "1");
  2744. dic.Add("result", result);
  2745. return dic;
  2746. }
  2747. if (pos.ActivationState == 0)
  2748. {
  2749. result += "机具未激活\n";
  2750. dic.Add("code", "1");
  2751. dic.Add("result", result);
  2752. return dic;
  2753. }
  2754. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  2755. if (merchant == null)
  2756. {
  2757. result += "商户不存在\n";
  2758. dic.Add("code", "1");
  2759. dic.Add("result", result);
  2760. return dic;
  2761. }
  2762. Users buyuser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  2763. result += "机具号:" + PosSn + "\n";
  2764. result += "机具所属人:\n创客编号:" + buyuser.MakerCode + ",姓名:" + buyuser.RealName + ",手机号:" + buyuser.Mobile + "\n";
  2765. result += "商户信息\n商户编号:" + merchant.KqMerNo + ",姓名:" + merchant.MerchantName + ",手机号:" + merchant.MerchantMobile + "\n";
  2766. string OpenUser10 = "未领取";
  2767. string OpenUser20 = "未领取";
  2768. var OpenRewardDetail = db.OpenRewardDetail.Where(m => m.SnNo == pos.PosSn).ToList();
  2769. OpenRewardDetail openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 20) ?? new OpenRewardDetail();
  2770. if (openreward.Id > 0)
  2771. {
  2772. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  2773. OpenUser20 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  2774. }
  2775. openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 10) ?? new OpenRewardDetail();
  2776. if (openreward.Id > 0)
  2777. {
  2778. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  2779. OpenUser10 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  2780. }
  2781. result += "开机奖20:" + OpenUser20 + "\n";
  2782. // result += "开机奖10:" + OpenUser10 + "\n";
  2783. dic.Add("id", pos.Id.ToString());
  2784. dic.Add("code", "0");
  2785. dic.Add("result", result);
  2786. return dic;
  2787. }
  2788. public string AddOpenPrize(int Id)
  2789. {
  2790. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Id && m.ActivationState == 1);
  2791. if (pos == null)
  2792. {
  2793. return "机具未激活";
  2794. }
  2795. if (pos.BindingTime <= pos.TransferTime)
  2796. {
  2797. return "补录机,不能补发开机奖";
  2798. }
  2799. // if (pos.BindingTime < DateTime.Now.AddDays(-30))
  2800. // {
  2801. // return "绑定已超过30天";
  2802. // }
  2803. decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  2804. if (ActPrize == 0)
  2805. {
  2806. return "机具无押金";
  2807. }
  2808. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  2809. if (merchant == null)
  2810. {
  2811. return "商户不存在";
  2812. }
  2813. bool check = db.OpenRewardDetail.Any(m => m.SnNo == pos.PosSn);
  2814. if (check)
  2815. {
  2816. return "开机奖励已发放,请勿重复操作";
  2817. }
  2818. // 从机具所属人上级开始分开机奖励
  2819. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId);
  2820. if (user != null)
  2821. {
  2822. if (!string.IsNullOrEmpty(user.ParentNav))
  2823. {
  2824. decimal Prize = 20;
  2825. List<string> PrizeFlag = new List<string>();
  2826. string[] ParentNavs = user.ParentNav.Trim(',').Replace(",,", ",").Split(',');
  2827. for (int i = ParentNavs.Length - 1; i >= 0; i--)
  2828. {
  2829. int UserId = int.Parse(ParentNavs[i]);
  2830. Users puser = db.Users.FirstOrDefault(m => m.Id == UserId && m.AuthFlag == 1);
  2831. if (puser != null && Prize > 0)
  2832. {
  2833. int machineCount = db.PosMachinesTwo.Count(m => m.BuyUserId == puser.Id && m.PosSnType == 0); //判断是否拥有3台兑换机
  2834. int ActiveCount = db.PosMachinesTwo.Count(m => m.BuyUserId == puser.Id && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  2835. int couponCount = db.PosCoupons.Count(m => m.UserId == puser.Id && m.IsUse == 0); //判断是否拥有3张券
  2836. if (machineCount + ActiveCount + couponCount >= 3)
  2837. {
  2838. int pTopUserId = 0;
  2839. if (!string.IsNullOrEmpty(puser.ParentNav))
  2840. {
  2841. pTopUserId = int.Parse(puser.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  2842. }
  2843. Users machineUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  2844. OpenRewardDetail detail = db.OpenRewardDetail.Add(new OpenRewardDetail()
  2845. {
  2846. CreateDate = DateTime.Now,
  2847. UpdateDate = DateTime.Now,
  2848. TradeMonth = DateTime.Now.ToString("yyyyMM"), //交易月
  2849. TradeDate = pos.ActivationTime, //达标日期
  2850. UserId = puser.Id, //创客
  2851. BrandId = pos.BrandId, //品牌
  2852. ProductName = RelationClass.GetKqProductBrandInfo(pos.BrandId), //产品名称
  2853. MerchantId = pos.BindMerchantId, //商户
  2854. DirectUserId = merchant.UserId, //商户直属人
  2855. SnNo = pos.PosSn, //SN号
  2856. MerNo = merchant.KqMerNo, //渠道商户号
  2857. SnType = pos.PosSnType, //机具类型
  2858. StandardDate = pos.ActivationTime, //商户的激活日期
  2859. SnStoreId = pos.StoreId, //SN仓库
  2860. MerBuddyType = puser.MerchantType, //商户创客类型
  2861. RewardType = 1, //奖励类型 1-开机直接奖励,2-开机间接奖励
  2862. RewardTips = "开机奖励", //奖励描述
  2863. CreditTradeAmt = pos.CreditTrade, //贷记卡交易总金额
  2864. DebitTradeAmt = pos.DebitCardTrade, //借记卡交易总金额
  2865. CreditRewardAmount = Prize, //贷记卡交易奖励金额
  2866. RewardDesc = "开机奖励", //奖励描述
  2867. TopUserId = pTopUserId, //顶级创客
  2868. SeoTitle = machineUser.RealName,
  2869. }).Entity;
  2870. db.OpenReward.Add(new OpenReward()
  2871. {
  2872. CreateDate = DateTime.Now,
  2873. UpdateDate = DateTime.Now,
  2874. TradeMonth = DateTime.Now.ToString("yyyyMM"), //交易月
  2875. TradeDate = DateTime.Now, //达标日期
  2876. UserId = puser.Id, //创客
  2877. BrandId = pos.BrandId, //品牌
  2878. RewardType = 2, //奖励类型
  2879. CreditTradeAmt = pos.CreditTrade, //贷记卡交易总金额
  2880. DebitTradeAmt = pos.DebitCardTrade, //借记卡交易总金额
  2881. CreditRewardAmount = Prize, //贷记卡交易奖励金额
  2882. RewardDesc = "开机奖励", //奖励描述
  2883. TopUserId = pTopUserId, //顶级创客
  2884. });
  2885. string IdBrand = puser.Id + "_" + pos.BrandId;
  2886. UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
  2887. if (userData == null)
  2888. {
  2889. userData = db.UserMachineData.Add(new UserMachineData()
  2890. {
  2891. IdBrand = IdBrand,
  2892. }).Entity;
  2893. db.SaveChanges();
  2894. }
  2895. userData.OpenProfit += Prize;
  2896. db.SaveChanges();
  2897. //账户入库
  2898. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id);
  2899. if (account == null)
  2900. {
  2901. account = db.UserAccount.Add(new UserAccount()
  2902. {
  2903. Id = puser.Id,
  2904. UserId = puser.Id,
  2905. }).Entity;
  2906. db.SaveChanges();
  2907. }
  2908. //收支明细入库
  2909. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  2910. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  2911. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  2912. account.BalanceAmount += Prize;
  2913. account.TotalAmount += Prize;
  2914. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  2915. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  2916. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  2917. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  2918. {
  2919. CreateDate = DateTime.Now,
  2920. UpdateDate = DateTime.Now,
  2921. UserId = puser.Id, //创客
  2922. ChangeType = 50, //变动类型
  2923. ProductType = pos.BrandId, //产品类型
  2924. ChangeAmount = Prize, //变更金额
  2925. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  2926. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  2927. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  2928. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  2929. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  2930. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  2931. }).Entity;
  2932. db.SaveChanges();
  2933. RedisDbconn.Instance.Set("UserAccount:" + puser.Id, account);
  2934. string dateString = DateTime.Now.ToString("yyyyMMdd");
  2935. string monthString = DateTime.Now.ToString("yyyyMM");
  2936. // 开机奖励列表
  2937. List<string> dates = RedisDbconn.Instance.GetList<string>("OpenRewardDay:" + puser.Id + ":" + pos.BrandId);
  2938. if (!dates.Contains(dateString))
  2939. {
  2940. RedisDbconn.Instance.AddList("OpenRewardDay:" + puser.Id + ":" + pos.BrandId, dateString);
  2941. }
  2942. RedisDbconn.Instance.AddNumber("OpenRewardAmt:" + puser.Id + ":" + pos.BrandId + ":" + dateString, Prize);
  2943. List<string> months = RedisDbconn.Instance.GetList<string>("OpenRewardMonth:" + puser.Id + ":" + pos.BrandId);
  2944. if (!months.Contains(monthString))
  2945. {
  2946. RedisDbconn.Instance.AddList("OpenRewardMonth:" + puser.Id + ":" + pos.BrandId, monthString);
  2947. }
  2948. RedisDbconn.Instance.AddNumber("OpenRewardAmt:" + puser.Id + ":" + pos.BrandId + ":" + monthString, Prize);
  2949. // 开机奖励详情
  2950. RedisDbconn.Instance.AddList("OpenRewardDetail:" + puser.Id + ":" + pos.BrandId + ":" + dateString, detail);
  2951. //收支明细
  2952. RedisDbconn.Instance.AddList("UserAccountRecord:" + puser.Id + ":1:" + monthString, userAccountRecord);
  2953. RedisDbconn.Instance.AddNumber("UserAccount:" + puser.Id + ":1:" + monthString, Prize);
  2954. Prize = 0;
  2955. PrizeFlag.Add(Prize.ToString("f0"));
  2956. }
  2957. }
  2958. }
  2959. string result = "";
  2960. // if (!PrizeFlag.Contains("20"))
  2961. // {
  2962. // result += "20元奖励未发,请检查上级是否满足条件\n";
  2963. // }
  2964. // if (!PrizeFlag.Contains("10"))
  2965. // {
  2966. // result += "10元奖励未发,请检查上级是否满足条件\n";
  2967. // }
  2968. if (string.IsNullOrEmpty(result))
  2969. {
  2970. return "发放成功";
  2971. }
  2972. return result;
  2973. }
  2974. }
  2975. db.Dispose();
  2976. return "操作失败";
  2977. }
  2978. #endregion
  2979. #region 查询机具流量费分佣
  2980. public IActionResult FluxPrize(string right)
  2981. {
  2982. ViewBag.RightInfo = RightInfo;
  2983. ViewBag.right = right;
  2984. return View();
  2985. }
  2986. [HttpPost]
  2987. public Dictionary<string, string> FluxPrizeDo(string PosSn)
  2988. {
  2989. Dictionary<string, string> dic = new Dictionary<string, string>();
  2990. string result = "";
  2991. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  2992. if (pos == null)
  2993. {
  2994. result += "机具SN号不存在\n";
  2995. dic.Add("code", "1");
  2996. dic.Add("result", result);
  2997. return dic;
  2998. }
  2999. if (pos.BindingState == 0)
  3000. {
  3001. result += "机具未绑定\n";
  3002. dic.Add("code", "1");
  3003. dic.Add("result", result);
  3004. return dic;
  3005. }
  3006. if (pos.ActivationState == 0)
  3007. {
  3008. result += "机具未激活\n";
  3009. dic.Add("code", "1");
  3010. dic.Add("result", result);
  3011. return dic;
  3012. }
  3013. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  3014. if (merchant == null)
  3015. {
  3016. result += "商户不存在\n";
  3017. dic.Add("code", "1");
  3018. dic.Add("result", result);
  3019. return dic;
  3020. }
  3021. Users buyuser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  3022. result += "机具号:" + PosSn + "\n";
  3023. result += "机具所属人:\n创客编号:" + buyuser.MakerCode + ",姓名:" + buyuser.RealName + ",手机号:" + buyuser.Mobile + "\n";
  3024. result += "商户信息\n商户编号:" + merchant.KqMerNo + ",姓名:" + merchant.MerchantName + ",手机号:" + merchant.MerchantMobile + "\n";
  3025. string FluxGet6 = "未领取";
  3026. string FluxUser6 = "";
  3027. FluxProfitDetail flux = db.FluxProfitDetail.FirstOrDefault(m => m.SnNo == pos.PosSn) ?? new FluxProfitDetail();
  3028. if (flux.Id > 0)
  3029. {
  3030. Users user = db.Users.FirstOrDefault(m => m.Id == flux.UserId) ?? new Users();
  3031. FluxGet6 = "已领取(金额:" + flux.FluxFeeAmt + ",领取时间:" + flux.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
  3032. FluxUser6 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  3033. }
  3034. result += "流量费:" + FluxGet6 + "\n";
  3035. result += "流量费发放对象:" + FluxUser6 + "\n";
  3036. dic.Add("id", pos.Id.ToString());
  3037. dic.Add("code", "0");
  3038. dic.Add("result", result);
  3039. return dic;
  3040. }
  3041. public string AddFluxPrize(int Id)
  3042. {
  3043. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Id && m.ActivationState == 1);
  3044. if (pos == null)
  3045. {
  3046. return "机具未激活";
  3047. }
  3048. // if (pos.BindingTime < DateTime.Now.AddDays(-30))
  3049. // {
  3050. // return "绑定已超过30天";
  3051. // }
  3052. decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  3053. if (ActPrize == 0)
  3054. {
  3055. return "机具无押金";
  3056. }
  3057. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  3058. if (merchant == null)
  3059. {
  3060. return "商户不存在";
  3061. }
  3062. if (pos.BrandId == 6)
  3063. {
  3064. return "立刷不支持流量费分佣";
  3065. }
  3066. if (decimal.Parse(function.CheckNum(pos.SeoKeyword)) <= 0)
  3067. {
  3068. return "无押金机,不支持流量费分佣";
  3069. }
  3070. bool check = db.FluxProfitDetail.Any(m => m.MerNo == merchant.KqMerNo);
  3071. if (check)
  3072. {
  3073. return "流量费奖励已发放,请勿重复操作";
  3074. }
  3075. SpModels.TradeFluxRecord trade = spdb.TradeFluxRecord.FirstOrDefault(m => m.TradeSnNo == pos.PosSn);
  3076. if (trade != null)
  3077. {
  3078. try
  3079. {
  3080. string OrderNo = trade.TradeSerialNo; //单号
  3081. DateTime TradeDate = trade.CreateDate.Value;
  3082. string TradeMonth = TradeDate.ToString("yyyyMM");
  3083. decimal FeeAmount = trade.FeeAmount; //流量费
  3084. if (trade.ProductType == "1" || trade.ProductType == "4" || trade.ProductType == "6" || trade.ProductType == "8" || trade.ProductType == "9")
  3085. {
  3086. FeeAmount = FeeAmount / 100;
  3087. }
  3088. string TradeSnNo = trade.TradeSnNo; //机具SN
  3089. decimal FluxProfit = 0;
  3090. if (trade.ProductType == "1" && FeeAmount == 60)
  3091. {
  3092. FluxProfit = 24;
  3093. }
  3094. else if (trade.ProductType == "7" && FeeAmount == 46)
  3095. {
  3096. FluxProfit = 10;
  3097. }
  3098. else if (trade.ProductType != "1" && FeeAmount == 48)
  3099. {
  3100. FluxProfit = 12;
  3101. }
  3102. if (FluxProfit > 0)
  3103. {
  3104. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  3105. int GetUserId = user.Id;
  3106. int TopUserId = 0;
  3107. string ParentNav = user.ParentNav;
  3108. if (!string.IsNullOrEmpty(ParentNav))
  3109. {
  3110. string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  3111. if (ParentNavList.Length > 1)
  3112. {
  3113. TopUserId = int.Parse(ParentNavList[1]);
  3114. }
  3115. else if (ParentNavList.Length == 1)
  3116. {
  3117. TopUserId = int.Parse(ParentNavList[0]);
  3118. }
  3119. }
  3120. FluxProfitSummary fluxProfit = db.FluxProfitSummary.FirstOrDefault(m => m.UserId == GetUserId && m.BrandId == pos.BrandId && m.TradeMonth == TradeMonth);
  3121. if (fluxProfit == null)
  3122. {
  3123. fluxProfit = db.FluxProfitSummary.Add(new FluxProfitSummary()
  3124. {
  3125. CreateDate = DateTime.Now,
  3126. UpdateDate = DateTime.Now,
  3127. UserId = GetUserId, //创客
  3128. BrandId = pos.BrandId,
  3129. TopUserId = TopUserId, //顶级创客
  3130. TradeMonth = TradeMonth, //交易月
  3131. MerUserType = user.MerchantType, //商户创客类型
  3132. Remark = "流量卡分佣", //备注
  3133. }).Entity;
  3134. db.SaveChanges();
  3135. }
  3136. fluxProfit.FluxProfitAmt += FluxProfit; //流量分润总金额
  3137. db.FluxProfitDetail.Add(new FluxProfitDetail()
  3138. {
  3139. CreateDate = DateTime.Now,
  3140. UpdateDate = DateTime.Now,
  3141. RecordNo = OrderNo, //单号
  3142. TradeDate = TradeDate.ToString("yyyyMMdd"), //交易日期
  3143. TradeTime = TradeDate.ToString("HHmmss"), //交易时间
  3144. TradeMonth = TradeMonth, //交易月
  3145. UserId = GetUserId, //创客
  3146. MerchantId = pos.BindMerchantId, //商户
  3147. MerchantUserId = pos.UserId, //商户直属人
  3148. MerNo = merchant.KqMerNo, //渠道商户编号
  3149. SnNo = pos.PosSn, //渠道SN号
  3150. FluxOrderNo = OrderNo, //流量扣费单号
  3151. TradeOrderNo = OrderNo, //交易流水号
  3152. TradeAmt = trade.TradeAmount, //商户交易额
  3153. FluxFeeAmt = FeeAmount, //流量费
  3154. FluxProfitAmt = FluxProfit, //流量分润总金额
  3155. PosType = pos.PosSnType.ToString(), //POS类型
  3156. Remark = "流量卡分佣", //备注
  3157. BrandId = pos.BrandId, //品牌
  3158. TopUserId = TopUserId, //顶级创客
  3159. MerUserType = user.MerchantType, //商户创客类型
  3160. });
  3161. string IdBrand = user.Id + "_" + pos.BrandId;
  3162. UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
  3163. if (userData == null)
  3164. {
  3165. userData = db.UserMachineData.Add(new UserMachineData()
  3166. {
  3167. IdBrand = IdBrand,
  3168. }).Entity;
  3169. db.SaveChanges();
  3170. }
  3171. userData.FluxProfit += FluxProfit;
  3172. db.SaveChanges();
  3173. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == GetUserId);
  3174. if (account == null)
  3175. {
  3176. account = db.UserAccount.Add(new UserAccount()
  3177. {
  3178. Id = GetUserId,
  3179. UserId = GetUserId,
  3180. }).Entity;
  3181. db.SaveChanges();
  3182. }
  3183. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  3184. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  3185. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  3186. account.BalanceAmount += FluxProfit;
  3187. account.TotalAmount += FluxProfit;
  3188. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  3189. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  3190. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  3191. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  3192. {
  3193. CreateDate = DateTime.Now,
  3194. UpdateDate = DateTime.Now,
  3195. UserId = GetUserId, //创客
  3196. ChangeType = 60, //变动类型
  3197. ProductType = pos.BrandId, //产品类型
  3198. ChangeAmount = FluxProfit, //变更金额
  3199. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  3200. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  3201. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  3202. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  3203. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  3204. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  3205. }).Entity;
  3206. db.SaveChanges();
  3207. spdb.Dispose();
  3208. db.Dispose();
  3209. return "发放成功";
  3210. }
  3211. }
  3212. catch (Exception ex)
  3213. {
  3214. function.WriteLog(DateTime.Now.ToString() + "\n$" + trade.Id + "$\n" + ex.ToString(), "流量卡分佣异常");
  3215. }
  3216. }
  3217. spdb.Dispose();
  3218. db.Dispose();
  3219. return "操作失败";
  3220. }
  3221. #endregion
  3222. #region 设置立刷费率
  3223. public IActionResult LisFee(string right)
  3224. {
  3225. ViewBag.RightInfo = RightInfo;
  3226. ViewBag.right = right;
  3227. return View();
  3228. }
  3229. [HttpPost]
  3230. public string LisFeeDo(string PosSns, decimal Fee, string Kind, string Fix)
  3231. {
  3232. if (string.IsNullOrEmpty(PosSns))
  3233. {
  3234. return "请输入机具号";
  3235. }
  3236. string result = SysUserName + "设置\n";
  3237. string[] PosSnList = PosSns.Split('\n');
  3238. int total = PosSnList.Length;
  3239. int index = 0;
  3240. foreach (string SubPosSn in PosSnList)
  3241. {
  3242. index += 1;
  3243. string PosSn = SubPosSn.Replace("\r", "");
  3244. result += PosSn + ":" + Fee + "\n";
  3245. if (Kind == "M5")
  3246. {
  3247. result += SetLiSFee(PosSn, Fee) + "\n";
  3248. }
  3249. else if (Kind == "N1")
  3250. {
  3251. result += SetLiSDeposit(PosSn, (int)Fee);
  3252. }
  3253. RedisDbconn.Instance.Set("LisFeeProcess:" + SysId, index + " / " + total);
  3254. }
  3255. result += "\n\n";
  3256. function.WriteLog(result, "设置立刷费率");
  3257. return result;
  3258. }
  3259. public string LisFeeProcess()
  3260. {
  3261. return RedisDbconn.Instance.Get<string>("LisFeeProcess:" + SysId);
  3262. }
  3263. #region 立刷
  3264. string LiSAgentId = "50814834";
  3265. 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=";
  3266. string LiSReqUrl = "https://openapi.jlpay.com/access/charge/"; //请求url
  3267. public string LiSSign(string data)
  3268. {
  3269. var rsa = RSA.Create();
  3270. var key = Convert.FromBase64String(LiSPrivateKey);
  3271. var content = Encoding.UTF8.GetBytes(data);
  3272. rsa.ImportPkcs8PrivateKey(key, out _);
  3273. var result = rsa.SignData(content, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  3274. return Convert.ToBase64String(result);
  3275. }
  3276. // 设置费率
  3277. public string SetLiSFee(string sn, decimal serviceFee)
  3278. {
  3279. Dictionary<string, object> dic = new Dictionary<string, object>();
  3280. dic.Add("agentId", LiSAgentId);
  3281. dic.Add("deviceSn", sn);
  3282. List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
  3283. Dictionary<string, object> item = new Dictionary<string, object>();
  3284. item.Add("feeCalcType", "M5");
  3285. item.Add("fixed", "0");
  3286. item.Add("rate", serviceFee);
  3287. feeList.Add(item);
  3288. dic.Add("feeList", feeList);
  3289. dic.Add("signMethod", "02");
  3290. string content = LiSAgentId + sn + "M50" + serviceFee + "02";
  3291. string signstr = LiSSign(content);
  3292. dic.Add("signData", signstr);
  3293. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  3294. string result = function.PostWebRequest(LiSReqUrl + "FEE003", req, new Dictionary<string, string>(), "application/json");
  3295. return result;
  3296. }
  3297. // 设置押金
  3298. public string SetLiSDeposit(string sn, int serviceFee)
  3299. {
  3300. serviceFee = serviceFee * 100;
  3301. Dictionary<string, object> dic = new Dictionary<string, object>();
  3302. dic.Add("agentId", LiSAgentId);
  3303. dic.Add("deviceSn", sn);
  3304. List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
  3305. Dictionary<string, object> item = new Dictionary<string, object>();
  3306. item.Add("feeCalcType", "N1");
  3307. item.Add("fixed", "1");
  3308. item.Add("rate", serviceFee);
  3309. feeList.Add(item);
  3310. dic.Add("feeList", feeList);
  3311. dic.Add("signMethod", "02");
  3312. string content = LiSAgentId + sn + "N11" + serviceFee + "02";
  3313. string signstr = LiSSign(content);
  3314. dic.Add("signData", signstr);
  3315. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  3316. string result = function.PostWebRequest(LiSReqUrl + "FEE003", req, new Dictionary<string, string>(), "application/json");
  3317. return result;
  3318. }
  3319. #endregion
  3320. #endregion
  3321. #region 查询商户型创客设置信息
  3322. public IActionResult SeeMerchantType(string right)
  3323. {
  3324. ViewBag.RightInfo = RightInfo;
  3325. ViewBag.right = right;
  3326. return View();
  3327. }
  3328. [HttpPost]
  3329. public string SeeMerchantTypeDo(string PosSn)
  3330. {
  3331. if (string.IsNullOrEmpty(PosSn))
  3332. {
  3333. return "请输入机具SN或者创客编号";
  3334. }
  3335. SetMerchantTypeRecord pos = new SetMerchantTypeRecord();
  3336. if (PosSn.StartsWith("K"))
  3337. {
  3338. UserForMakerCode userfor = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == PosSn) ?? new UserForMakerCode();
  3339. bool check = db.SetMerchantTypeRecord.Any(m => m.ToUserId == userfor.UserId);
  3340. if (check)
  3341. {
  3342. pos = db.SetMerchantTypeRecord.Where(m => m.ToUserId == userfor.UserId).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SetMerchantTypeRecord();
  3343. }
  3344. }
  3345. else
  3346. {
  3347. bool check = db.SetMerchantTypeRecord.Any(m => m.PosSn == PosSn);
  3348. if (check)
  3349. {
  3350. pos = db.SetMerchantTypeRecord.Where(m => m.PosSn == PosSn).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SetMerchantTypeRecord();
  3351. }
  3352. }
  3353. if (pos.Id == 0)
  3354. {
  3355. return "查无信息";
  3356. }
  3357. Users setUser = db.Users.FirstOrDefault(m => m.Id == pos.FromUserId) ?? new Users();
  3358. Users toUser = db.Users.FirstOrDefault(m => m.Id == pos.ToUserId) ?? new Users();
  3359. string CreateDate = pos.CreateDate == null ? "" : pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  3360. string bindTime = pos.BindDate == null ? "" : pos.BindDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  3361. string activeTime = pos.ActDate == null ? "" : pos.ActDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  3362. string bindResult = pos.BindStatus == 1 ? "已绑定" : "未绑定";
  3363. string activeResult = pos.ActStatus == 1 ? "已激活" : "未激活";
  3364. string RecycFlag = pos.IsRecyc == 1 ? "已循环" : "未循环";
  3365. string result = "";
  3366. result += "机具SN:" + pos.PosSn + "\n";
  3367. result += "操作人:创客编号:" + setUser.MakerCode + ",姓名:" + setUser.RealName + ",手机号:" + setUser.Mobile + "\n";
  3368. result += "操作对象:创客编号:" + toUser.MakerCode + ",姓名:" + toUser.RealName + ",手机号:" + toUser.Mobile + "\n";
  3369. result += "商户编号:" + pos.MerNo + "\n";
  3370. result += "操作时间:" + pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + "\n";
  3371. result += "绑定状态:" + bindResult + "(绑定时间:" + bindTime + ")\n";
  3372. result += "激活状态:" + activeResult + "(激活时间:" + activeTime + ")\n";
  3373. result += "贷记卡交易额:" + pos.CreditAmount + "\n";
  3374. result += "是否循环:" + RecycFlag + "\n";
  3375. return result;
  3376. }
  3377. #endregion
  3378. #region 三要素验证
  3379. public IActionResult CheckThreeElements(string right)
  3380. {
  3381. ViewBag.RightInfo = RightInfo;
  3382. ViewBag.right = right;
  3383. return View();
  3384. }
  3385. [HttpPost]
  3386. public string CheckThreeElementsDo(string bankcard, string idcard, string name)
  3387. {
  3388. var host = "https://bankcard3c.shumaidata.com";
  3389. var path = "/bankcard3c";
  3390. var method = "GET";
  3391. var appcode = "8e5704921ca3422f80f0deb935a7ddc6";
  3392. if (string.IsNullOrEmpty(bankcard))
  3393. {
  3394. return "结算银行卡号";
  3395. }
  3396. if (string.IsNullOrEmpty(idcard))
  3397. {
  3398. return "身份证号";
  3399. }
  3400. if (string.IsNullOrEmpty(name))
  3401. {
  3402. return "真实姓名";
  3403. }
  3404. String querys = "bankcard=" + bankcard + "&idcard=" + idcard + "&name=" + name;
  3405. function.WriteLog(DateTime.Now.ToString(), "验证三要素日志");
  3406. function.WriteLog(querys, "验证三要素日志");
  3407. String bodys = "";
  3408. String url = host + path;
  3409. HttpWebRequest httpRequest = null;
  3410. HttpWebResponse httpResponse = null;
  3411. if (0 < querys.Length)
  3412. {
  3413. url = url + "?" + querys;
  3414. }
  3415. if (host.Contains("https://"))
  3416. {
  3417. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  3418. httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
  3419. }
  3420. else
  3421. {
  3422. httpRequest = (HttpWebRequest)WebRequest.Create(url);
  3423. }
  3424. httpRequest.Method = method;
  3425. httpRequest.Headers.Add("Authorization", "APPCODE " + appcode);
  3426. if (0 < bodys.Length)
  3427. {
  3428. byte[] data = Encoding.UTF8.GetBytes(bodys);
  3429. using (Stream stream = httpRequest.GetRequestStream())
  3430. {
  3431. stream.Write(data, 0, data.Length);
  3432. }
  3433. }
  3434. try
  3435. {
  3436. httpResponse = (HttpWebResponse)httpRequest.GetResponse();
  3437. }
  3438. catch (WebException ex)
  3439. {
  3440. httpResponse = (HttpWebResponse)ex.Response;
  3441. }
  3442. Stream st = httpResponse.GetResponseStream();
  3443. StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
  3444. string result = reader.ReadToEnd();
  3445. JsonData jsonObj = JsonMapper.ToObject(result);
  3446. result = jsonObj["data"]["desc"].ToString();
  3447. function.WriteLog(result, "验证三要素日志");
  3448. function.WriteLog("\n\n", "验证三要素日志");
  3449. return result;
  3450. }
  3451. #endregion
  3452. #region 四要素验证
  3453. public IActionResult CheckFourElements(string right)
  3454. {
  3455. ViewBag.RightInfo = RightInfo;
  3456. ViewBag.right = right;
  3457. return View();
  3458. }
  3459. [HttpPost]
  3460. public string CheckFourElementsDo(string bankcard, string idcard, string mobile, string name)
  3461. {
  3462. var host = "https://bankcard4c.shumaidata.com";
  3463. var path = "/bankcard4c";
  3464. var method = "GET";
  3465. var appcode = "8e5704921ca3422f80f0deb935a7ddc6";
  3466. if (string.IsNullOrEmpty(bankcard))
  3467. {
  3468. return "请输入结算银行卡号";
  3469. }
  3470. if (string.IsNullOrEmpty(idcard))
  3471. {
  3472. return "请输入身份证号";
  3473. }
  3474. if (string.IsNullOrEmpty(mobile))
  3475. {
  3476. return "请输入银行预留手机号";
  3477. }
  3478. if (string.IsNullOrEmpty(name))
  3479. {
  3480. return "请输入真实姓名";
  3481. }
  3482. String querys = "bankcard=" + bankcard + "&idcard=" + idcard + "&mobile=" + mobile + "&name=" + name;
  3483. function.WriteLog(DateTime.Now.ToString(), "验证四要素日志");
  3484. function.WriteLog(querys, "验证四要素日志");
  3485. String bodys = "";
  3486. String url = host + path;
  3487. HttpWebRequest httpRequest = null;
  3488. HttpWebResponse httpResponse = null;
  3489. if (0 < querys.Length)
  3490. {
  3491. url = url + "?" + querys;
  3492. }
  3493. if (host.Contains("https://"))
  3494. {
  3495. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  3496. httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
  3497. }
  3498. else
  3499. {
  3500. httpRequest = (HttpWebRequest)WebRequest.Create(url);
  3501. }
  3502. httpRequest.Method = method;
  3503. httpRequest.Headers.Add("Authorization", "APPCODE " + appcode);
  3504. if (0 < bodys.Length)
  3505. {
  3506. byte[] data = Encoding.UTF8.GetBytes(bodys);
  3507. using (Stream stream = httpRequest.GetRequestStream())
  3508. {
  3509. stream.Write(data, 0, data.Length);
  3510. }
  3511. }
  3512. try
  3513. {
  3514. httpResponse = (HttpWebResponse)httpRequest.GetResponse();
  3515. }
  3516. catch (WebException ex)
  3517. {
  3518. httpResponse = (HttpWebResponse)ex.Response;
  3519. }
  3520. Stream st = httpResponse.GetResponseStream();
  3521. StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
  3522. string result = reader.ReadToEnd();
  3523. JsonData jsonObj = JsonMapper.ToObject(result);
  3524. result = jsonObj["data"]["desc"].ToString();
  3525. function.WriteLog(result, "验证四要素日志");
  3526. function.WriteLog("\n\n", "验证四要素日志");
  3527. return result;
  3528. }
  3529. #endregion
  3530. public bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
  3531. {
  3532. return true;
  3533. }
  3534. #region 根据机具号同步商户激活状态
  3535. public IActionResult SyncMerchantStatus(string right)
  3536. {
  3537. ViewBag.RightInfo = RightInfo;
  3538. ViewBag.right = right;
  3539. return View();
  3540. }
  3541. [HttpPost]
  3542. public string SyncMerchantStatusDo(string PosSn)
  3543. {
  3544. if (string.IsNullOrEmpty(PosSn))
  3545. {
  3546. return "请输入机具号";
  3547. }
  3548. var pos = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn) ?? new MachineForSnNo();
  3549. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == pos.SnId) ?? new PosMachinesTwo();
  3550. var posMerchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == posInfo.BindMerchantId) ?? new PosMerchantInfo();
  3551. if (posInfo.Id == 0)
  3552. {
  3553. return "机具" + PosSn + "不存在";
  3554. }
  3555. if (posMerchant.Id == 0)
  3556. {
  3557. return "机具绑定商户不存在";
  3558. }
  3559. else
  3560. {
  3561. posMerchant.ActiveStatus = 1;
  3562. posMerchant.UpdateDate = DateTime.Now;
  3563. posMerchant.MerStandardDate = posInfo.ActivationTime;
  3564. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + PosSn + ":" + SysUserName + "-" + SysRealName, "根据机具号同步商户激活状态");
  3565. db.SaveChanges();
  3566. }
  3567. return "success";
  3568. }
  3569. #endregion
  3570. #region 根据机具号补发开机奖励
  3571. public IActionResult PosRewardReissued(string right)
  3572. {
  3573. ViewBag.RightInfo = RightInfo;
  3574. ViewBag.right = right;
  3575. return View();
  3576. }
  3577. [HttpPost]
  3578. public string PosRewardReissuedDo(string PosSn)
  3579. {
  3580. if (string.IsNullOrEmpty(PosSn))
  3581. {
  3582. return "请输入机具SN";
  3583. }
  3584. string[] PosSnList = PosSn.Replace("\r", "").Split('\n');
  3585. var PosId = "";
  3586. var error = "";
  3587. foreach (var item in PosSnList)
  3588. {
  3589. var pos = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == item) ?? new MachineForSnNo();
  3590. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == pos.SnId) ?? new PosMachinesTwo();
  3591. bool checkExist = db.OpenRewardDetail.Any(m => m.SnNo == item);
  3592. if (checkExist)
  3593. {
  3594. error += "以下操作失败" + item + ',' + "该机具开机奖励已发,请勿再次操作" + '\n';
  3595. }
  3596. else
  3597. {
  3598. if (posInfo.Id > 0)
  3599. {
  3600. PosId += posInfo.Id + ",";
  3601. }
  3602. }
  3603. }
  3604. if (!string.IsNullOrEmpty(error))
  3605. {
  3606. return "Warning|" + error;
  3607. }
  3608. PosId = PosId.TrimEnd(',');
  3609. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + PosId + ":" + SysUserName + "-" + SysRealName, "根据机具号补发开机奖励");
  3610. RedisDbconn.Instance.AddList("OpenRewardQueue", PosId);
  3611. return "success";
  3612. }
  3613. #endregion
  3614. #region 根据机具号设置费率
  3615. public IActionResult SetPosFee(string right)
  3616. {
  3617. ViewBag.RightInfo = RightInfo;
  3618. ViewBag.right = right;
  3619. return View();
  3620. }
  3621. [HttpPost]
  3622. public string SetPosFeeDo(string PosSn, string FeeType)
  3623. {
  3624. if (string.IsNullOrEmpty(PosSn))
  3625. {
  3626. return "请输入机具SN";
  3627. }
  3628. if (string.IsNullOrEmpty(FeeType))
  3629. {
  3630. return "请输入选择费率";
  3631. }
  3632. if (FeeType == "0")
  3633. {
  3634. FeeType = "0.6";
  3635. }
  3636. if (FeeType == "1")
  3637. {
  3638. FeeType = "0.63";
  3639. }
  3640. string[] PosSnList = PosSn.Split('\n');
  3641. var PosId = "";
  3642. var RecordId = "";
  3643. var error = "";
  3644. foreach (var item in PosSnList)
  3645. {
  3646. var pos = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == item) ?? new MachineForSnNo();
  3647. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == pos.SnId) ?? new PosMachinesTwo();
  3648. if (posInfo.Id > 0)
  3649. {
  3650. var query = db.PosMachinesFeeChangeRecord.Add(new PosMachinesFeeChangeRecord()
  3651. {
  3652. Sort = posInfo.BrandId,
  3653. CreateDate = DateTime.Now,
  3654. PosId = posInfo.Id,
  3655. PosSn = posInfo.PosSn,
  3656. PosUserId = posInfo.UserId,
  3657. MerchantId = posInfo.BindMerchantId,
  3658. UserId = posInfo.UserId,
  3659. ChangeFee = decimal.Parse(FeeType),
  3660. }).Entity;
  3661. db.SaveChanges();
  3662. PosId += posInfo.Id + ",";
  3663. RecordId += query.Id + ",";
  3664. }
  3665. else
  3666. {
  3667. error += "机具" + PosSn + "不存在";
  3668. }
  3669. }
  3670. if (!string.IsNullOrEmpty(error))
  3671. {
  3672. return "Warning|" + error;
  3673. }
  3674. PosId = PosId.TrimEnd(',');
  3675. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + PosId + ":" + SysUserName + "-" + SysRealName, "根据机具号设置费率");
  3676. string data = "{\"RecordId\":\"" + RecordId + "\",\"PosId\":\"" + PosId + "\",\"Fee\": \"" + FeeType + "\",\"Kind\": \"2\",\"OpMan\": \"系统\"}";
  3677. RedisDbconn.Instance.AddList("SetDepositPostQueue", data);
  3678. return "success";
  3679. }
  3680. #endregion
  3681. #region 根据机具号、商户号、商户姓名关联商户和机具信息
  3682. public IActionResult RelationPosAndMerchant(string right)
  3683. {
  3684. ViewBag.RightInfo = RightInfo;
  3685. ViewBag.right = right;
  3686. return View();
  3687. }
  3688. [HttpPost]
  3689. public string RelationPosAndMerchantDo(string PosSn, string MerchantNo, string MerchantName)
  3690. {
  3691. if (string.IsNullOrEmpty(PosSn))
  3692. {
  3693. return "请输入机具SN";
  3694. }
  3695. if (string.IsNullOrEmpty(MerchantNo))
  3696. {
  3697. return "请输入商户编号";
  3698. }
  3699. if (string.IsNullOrEmpty(MerchantName))
  3700. {
  3701. return "请输入商户姓名";
  3702. }
  3703. var query = PosSn + "," + MerchantNo + "," + MerchantName;
  3704. var posMerchant = db.PosMerchantInfo.FirstOrDefault(m => m.MerchantNo == MerchantNo && m.MerchantName == MerchantName) ?? new PosMerchantInfo();
  3705. var machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == posMerchant.KqSnNo) ?? new MachineForSnNo();
  3706. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId) ?? new PosMachinesTwo();
  3707. if (posMerchant.Id == 0)
  3708. {
  3709. return "商户" + MerchantNo + "不存在";
  3710. }
  3711. else if (pos.Id == 0)
  3712. {
  3713. return "机具" + PosSn + "不存在";
  3714. }
  3715. else
  3716. {
  3717. pos.BindMerchantId = posMerchant.Id;
  3718. db.SaveChanges();
  3719. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + query + ":" + SysUserName + "-" + SysRealName, "根据机具号、商户号、商户姓名关联");
  3720. }
  3721. return "success";
  3722. }
  3723. #endregion
  3724. #region 设置商户信息
  3725. public IActionResult SetMerchantInfo(string right)
  3726. {
  3727. ViewBag.RightInfo = RightInfo;
  3728. ViewBag.right = right;
  3729. return View();
  3730. }
  3731. [HttpPost]
  3732. public string SetMerchantInfoDo(string PosSn, string MerchantNo, string MerchantName, string MerIdcardNo, string MerchantMobile)
  3733. {
  3734. if (string.IsNullOrEmpty(PosSn))
  3735. {
  3736. return "请输入机具SN";
  3737. }
  3738. if (string.IsNullOrEmpty(MerchantNo))
  3739. {
  3740. return "请输入商户编号";
  3741. }
  3742. if (string.IsNullOrEmpty(MerchantName))
  3743. {
  3744. return "请输入商户姓名";
  3745. }
  3746. if (string.IsNullOrEmpty(MerIdcardNo))
  3747. {
  3748. return "请输入商户身份证号";
  3749. }
  3750. if (string.IsNullOrEmpty(MerchantMobile))
  3751. {
  3752. return "请输入商户手机号";
  3753. }
  3754. var posMerchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerchantNo && m.KqSnNo == PosSn && m.MerchantName.StartsWith(MerchantName.Substring(0, 1))) ?? new PosMerchantInfo();
  3755. var query = "";
  3756. query += "修改前:" + posMerchant.KqSnNo + "," + posMerchant.MerchantNo + "," + posMerchant.MerchantName + "," + posMerchant.MerIdcardNo + "," + posMerchant.MerchantMobile;
  3757. query += "修改后:" + PosSn + "," + MerchantNo + "," + MerchantName + "," + MerIdcardNo + "," + MerchantMobile;
  3758. if (posMerchant.Id == 0)
  3759. {
  3760. return "商户" + MerchantNo + "不存在或不在" + MerchantName + "名下";
  3761. }
  3762. else
  3763. {
  3764. posMerchant.MerIdcardNo = MerIdcardNo;
  3765. posMerchant.MerchantName = MerchantName;
  3766. posMerchant.MerchantMobile = MerchantMobile;
  3767. db.SaveChanges();
  3768. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + query + ":" + SysUserName + "-" + SysRealName, "设置商户信息");
  3769. }
  3770. return "success";
  3771. }
  3772. #endregion
  3773. #region 认证创客
  3774. public IActionResult AuthMaker(string right)
  3775. {
  3776. ViewBag.RightInfo = RightInfo;
  3777. ViewBag.right = right;
  3778. return View();
  3779. }
  3780. [HttpPost]
  3781. public string AuthMakerDo(string MakerCode, string RealName, string CertId, string BackCard, string BackName)
  3782. {
  3783. if (string.IsNullOrEmpty(MakerCode))
  3784. {
  3785. return "请输入创客编号";
  3786. }
  3787. if (string.IsNullOrEmpty(RealName))
  3788. {
  3789. return "请输入真实姓名";
  3790. }
  3791. if (string.IsNullOrEmpty(CertId))
  3792. {
  3793. return "请输入身份证号";
  3794. }
  3795. if (string.IsNullOrEmpty(BackCard))
  3796. {
  3797. return "请输入银行卡号";
  3798. }
  3799. if (string.IsNullOrEmpty(BackName))
  3800. {
  3801. return "请输入银行名称";
  3802. }
  3803. var query = MakerCode + "," + RealName + "," + CertId + "," + BackCard + "," + BackName;
  3804. var userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
  3805. var userInfo = db.Users.FirstOrDefault(m => m.Id == userForMakerCode.UserId) ?? new Users();
  3806. if (userInfo.AuthFlag == 1)
  3807. {
  3808. return "已认证";
  3809. }
  3810. else
  3811. {
  3812. userInfo.UpdateDate = DateTime.Now;
  3813. userInfo.RealName = RealName;
  3814. userInfo.AuthFlag = 1;
  3815. if (userInfo.AuthDate == null)
  3816. {
  3817. userInfo.AuthDate = DateTime.Now;
  3818. }
  3819. userInfo.CertId = CertId;
  3820. userInfo.SettleBankCardNo = BackCard;
  3821. userInfo.SettleBankCardName = BackName;
  3822. db.SaveChanges();
  3823. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + query + ":" + SysUserName + "-" + SysRealName, "认证创客");
  3824. }
  3825. return "success";
  3826. }
  3827. #endregion
  3828. #region 划拨创客机具
  3829. public IActionResult TransferPos(string right)
  3830. {
  3831. ViewBag.RightInfo = RightInfo;
  3832. ViewBag.right = right;
  3833. return View();
  3834. }
  3835. [HttpPost]
  3836. public string TransferPosDo(string PosSn, string FromMakerCode, string ToMakerCode)
  3837. {
  3838. if (string.IsNullOrEmpty(PosSn))
  3839. {
  3840. return "请输入机具SN";
  3841. }
  3842. if (string.IsNullOrEmpty(FromMakerCode))
  3843. {
  3844. return "请输入机具来源创客编号";
  3845. }
  3846. if (string.IsNullOrEmpty(ToMakerCode))
  3847. {
  3848. return "请输入划拨对象创客编号";
  3849. }
  3850. var query = PosSn + "," + FromMakerCode + "," + ToMakerCode;
  3851. var machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn) ?? new MachineForSnNo();
  3852. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId) ?? new PosMachinesTwo();
  3853. if (posInfo.Id == 0)
  3854. {
  3855. return "机具" + PosSn + "不存在";
  3856. }
  3857. var user = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == FromMakerCode) ?? new UserForMakerCode();
  3858. var tuser = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == ToMakerCode) ?? new UserForMakerCode();
  3859. var fUserId = db.Users.FirstOrDefault(m => m.Id == user.UserId) ?? new Users();
  3860. if (fUserId.Id == 0)
  3861. {
  3862. return "来源创客" + FromMakerCode + "不存在";
  3863. }
  3864. var tUserId = db.Users.FirstOrDefault(m => m.Id == tuser.UserId) ?? new Users();
  3865. if (tUserId.Id == 0)
  3866. {
  3867. return "划拨创客" + ToMakerCode + "不存在";
  3868. }
  3869. if (posInfo.BindingState == 0)
  3870. {
  3871. if (posInfo.UserId == 0 || posInfo.BuyUserId == posInfo.UserId)
  3872. {
  3873. posInfo.BuyUserId = tUserId.Id;
  3874. posInfo.UserId = tUserId.Id;
  3875. }
  3876. else
  3877. {
  3878. posInfo.BuyUserId = tUserId.Id;
  3879. }
  3880. var fUserPos = db.UserMachineData.FirstOrDefault(m => m.IdBrand == fUserId.Id + "_" + posInfo.BrandId) ?? new UserMachineData();
  3881. var tUserPos = db.UserMachineData.FirstOrDefault(m => m.IdBrand == tUserId.Id + "_" + posInfo.BrandId) ?? new UserMachineData();
  3882. fUserPos.TotalMachineCount -= 1;
  3883. fUserPos.UnBindCount -= 1;
  3884. tUserPos.TotalMachineCount += 1;
  3885. tUserPos.UnBindCount += 1;
  3886. db.SaveChanges();
  3887. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + query + ":" + SysUserName + "-" + SysRealName, "划拨创客机具");
  3888. }
  3889. else
  3890. {
  3891. return "机具" + PosSn + "已使用";
  3892. }
  3893. return "success";
  3894. }
  3895. #endregion
  3896. #region 还原提现订单状态
  3897. public IActionResult RestoreStatus(string right)
  3898. {
  3899. ViewBag.RightInfo = RightInfo;
  3900. ViewBag.right = right;
  3901. return View();
  3902. }
  3903. [HttpPost]
  3904. public string RestoreStatusDo(string OrderNo)
  3905. {
  3906. if (string.IsNullOrEmpty(OrderNo))
  3907. {
  3908. return "请输入提现订单编号";
  3909. }
  3910. string[] OrderNoList = OrderNo.Replace("\r", "").Split('\n');
  3911. var error = "";
  3912. foreach (var item in OrderNoList)
  3913. {
  3914. var cash = db.UserCashRecord.FirstOrDefault(m => m.CashOrderNo == item) ?? new UserCashRecord();
  3915. if (cash.Id > 0)
  3916. {
  3917. cash.QueryCount = 0;
  3918. cash.Status = 0;
  3919. db.SaveChanges();
  3920. }
  3921. else
  3922. {
  3923. error += "订单" + item + "不存在" + '\n';
  3924. }
  3925. }
  3926. if (!string.IsNullOrEmpty(error))
  3927. {
  3928. return "Warning|" + error;
  3929. }
  3930. return "success";
  3931. }
  3932. #endregion
  3933. #region 查询创客循环资格
  3934. public IActionResult SeeUserLoop(string right)
  3935. {
  3936. ViewBag.RightInfo = RightInfo;
  3937. ViewBag.right = right;
  3938. return View();
  3939. }
  3940. [HttpPost]
  3941. public string SeeUserLoopDo(string MakerCode)
  3942. {
  3943. var userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
  3944. var user = db.Users.FirstOrDefault(m => m.Id == userForMakerCode.UserId) ?? new Users();
  3945. var pos = db.PosMachinesTwo.Where(m => m.Status > -1 && m.BuyUserId == user.Id).ToList();
  3946. var brandList = db.KqProducts.ToList();
  3947. var info = "";
  3948. foreach (var item in brandList)
  3949. {
  3950. var brand = item.Name;
  3951. //已过期
  3952. var overdue = pos.Count(m => m.RecycEndDate < DateTime.Now && m.BrandId == item.Id && m.PosSnType == 0);
  3953. //可申请
  3954. var use = pos.Count(m => m.IsPurchase == 0 && m.RecycEndDate > DateTime.Now && m.BrandId == item.Id && m.PosSnType == 0);
  3955. //已使用
  3956. // var used = pos.Count(m => m.IsPurchase == 1 && m.BrandId == item.Id && m.PosSnType == 0);
  3957. // info += "品牌:" + brand + ",已过期:" + overdue + ",可申请:" + use + ",已使用:" + used + "\n";
  3958. info += "品牌:" + brand + ",已过期:" + overdue + ",可申请:" + use + "\n";
  3959. }
  3960. return info;
  3961. }
  3962. #endregion
  3963. #region 提交到代付排除的创客名单
  3964. public IActionResult CashWithoutUser(string right)
  3965. {
  3966. ViewBag.RightInfo = RightInfo;
  3967. ViewBag.right = right;
  3968. return View();
  3969. }
  3970. public string CashWithoutUserDo(string Content)
  3971. {
  3972. CustomTagSet set = db.CustomTagSet.FirstOrDefault(m => m.Tags == "CashWithoutUser");
  3973. if (set == null)
  3974. {
  3975. set = db.CustomTagSet.Add(new CustomTagSet()
  3976. {
  3977. Tags = "CashWithoutUser",
  3978. Title = "提交到代付排除的创客名单"
  3979. }).Entity;
  3980. db.SaveChanges();
  3981. }
  3982. set.Contents = Content;
  3983. db.SaveChanges();
  3984. db.Dispose();
  3985. return "success";
  3986. }
  3987. #endregion
  3988. #region 坏机回仓
  3989. public IActionResult BadPosToStore(string right)
  3990. {
  3991. ViewBag.RightInfo = RightInfo;
  3992. ViewBag.right = right;
  3993. return View();
  3994. }
  3995. [HttpPost]
  3996. public string BadPosToStoreDo(string OldSn)
  3997. {
  3998. string[] OldSnList;
  3999. OldSnList = OldSn.Replace("\r", "").Split('\n');
  4000. string error = "";
  4001. List<string> opData = new List<string>();
  4002. for (int i = 0; i < OldSnList.Length; i++)
  4003. {
  4004. string OldSnNum = OldSnList[i];
  4005. MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  4006. PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId) ?? new PosMachinesTwo();
  4007. // var store = db.StoreHouse.FirstOrDefault(m => m.Id == oldpos.StoreId) ?? new StoreHouse();
  4008. // if (store.UserId != 142237)//判断是否是属于坏机仓的机具
  4009. // {
  4010. // error += "以下操作失败" + OldSnNum + ',' + "该机具不在坏机仓或不存在" + '\n';
  4011. // }
  4012. if (!opData.Contains(oldpos.BuyUserId + ":" + oldpos.BrandId))
  4013. {
  4014. opData.Add(oldpos.BuyUserId + ":" + oldpos.BrandId);
  4015. }
  4016. oldpos.Status = 1;
  4017. oldpos.PosSnType= 0;
  4018. oldpos.QueryCount = 0;
  4019. oldpos.UpdateDate = null;
  4020. oldpos.ActivityList = null;
  4021. oldpos.SeoKeyword = null;
  4022. oldpos.SeoDescription = null;
  4023. oldpos.OrderId = 0;
  4024. oldpos.RecycEndDate = null;
  4025. oldpos.RecycBackCount = 0;
  4026. oldpos.PrizeParams = null;
  4027. oldpos.ScanQrTrade = 0;
  4028. oldpos.BindMerchantId = 0;
  4029. oldpos.CreditTrade = 0;
  4030. oldpos.DebitCardTrade = 0;
  4031. oldpos.IsVip = 0;
  4032. oldpos.UserNav = null;
  4033. oldpos.TransferTime = null;
  4034. oldpos.IsPurchase = 0;
  4035. oldpos.Detail = null;
  4036. oldpos.BindingTime = null;
  4037. oldpos.BindingState = 0;
  4038. oldpos.ActivationTime = null;
  4039. oldpos.ActivationState = 0;
  4040. oldpos.LeaderUserId = 0;
  4041. oldpos.PreUserId = 0;
  4042. oldpos.IsFirst = 0;
  4043. oldpos.DownFeeMan = null;
  4044. oldpos.DownFeeFlag = 0;
  4045. oldpos.DownFeeDate = null;
  4046. oldpos.UpFeeMan = null;
  4047. oldpos.UpFeeFlag = 0;
  4048. oldpos.UpFeeDate = null;
  4049. oldpos.OpReserve1 = 0;
  4050. oldpos.OpReserve2 = 0;
  4051. oldpos.OpReserve3 = 0;
  4052. oldpos.OpId = 0;
  4053. oldpos.RecycStartDate = null;
  4054. oldpos.SourcePosSn = null;
  4055. oldpos.BuyUserId = 0;
  4056. oldpos.UserId = 0;
  4057. PublicFunction.ClearPosHistory(db, oldpos.PosSn); //清除机具历史记录
  4058. }
  4059. if (!string.IsNullOrEmpty(error))
  4060. {
  4061. return "Warning|" + error;
  4062. }
  4063. db.SaveChanges();
  4064. foreach (string sub in opData)
  4065. {
  4066. string[] datalist = sub.Split(":");
  4067. PublicFunction.SycnMachineCount(int.Parse(datalist[0]), int.Parse(datalist[1]));
  4068. }
  4069. return "success";
  4070. }
  4071. #endregion
  4072. #region 划拨创客机具券
  4073. public IActionResult TransferPosCoupon(string right)
  4074. {
  4075. ViewBag.RightInfo = RightInfo;
  4076. ViewBag.right = right;
  4077. return View();
  4078. }
  4079. public string TransferPosCouponDo(string PosCouponCodes, string FromMakerCode, string ToMakerCode, string LeaderMakerCode = "")
  4080. {
  4081. if (string.IsNullOrEmpty(PosCouponCodes))
  4082. {
  4083. return "请输入机具券码";
  4084. }
  4085. if (string.IsNullOrEmpty(FromMakerCode))
  4086. {
  4087. return "请输入机具来源创客编号";
  4088. }
  4089. if (string.IsNullOrEmpty(ToMakerCode))
  4090. {
  4091. return "请输入划拨对象创客编号";
  4092. }
  4093. var user = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == FromMakerCode) ?? new UserForMakerCode();
  4094. var tuser = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == ToMakerCode) ?? new UserForMakerCode();
  4095. var fUserId = db.Users.FirstOrDefault(m => m.Id == user.UserId) ?? new Users();
  4096. if (fUserId.Id == 0)
  4097. {
  4098. return "来源创客" + FromMakerCode + "不存在";
  4099. }
  4100. var tUserId = db.Users.FirstOrDefault(m => m.Id == tuser.UserId) ?? new Users();
  4101. if (tUserId.Id == 0)
  4102. {
  4103. return "划拨创客" + ToMakerCode + "不存在";
  4104. }
  4105. int LeaderUserId = 0;
  4106. if (!string.IsNullOrEmpty(LeaderMakerCode))
  4107. {
  4108. UserForMakerCode leaderuser = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == LeaderMakerCode) ?? new UserForMakerCode();
  4109. Users LeaderUserItem = db.Users.FirstOrDefault(m => m.Id == leaderuser.UserId) ?? new Users();
  4110. if (LeaderUserItem.Id == 0)
  4111. {
  4112. return "大盟主创客编号" + LeaderMakerCode + "不存在";
  4113. }
  4114. LeaderUserId = leaderuser.UserId;
  4115. }
  4116. var query = PosCouponCodes + "\n" + FromMakerCode + "," + ToMakerCode;
  4117. string[] PosCouponList = PosCouponCodes.Replace("\r", "").Replace("\n", ",").Split(',');
  4118. foreach (string PosCouponCode in PosCouponList)
  4119. {
  4120. PosCoupons item = db.PosCoupons.FirstOrDefault(m => m.ExchangeCode == PosCouponCode) ?? new PosCoupons();
  4121. if (item.UserId != fUserId.Id)
  4122. {
  4123. return "机具券" + PosCouponCode + "不在创客" + FromMakerCode + "名下";
  4124. }
  4125. if (item.Id == 0)
  4126. {
  4127. return "机具券" + PosCouponCode + "不存在";
  4128. }
  4129. if (item.IsUse == 1)
  4130. {
  4131. return "机具券" + PosCouponCode + "已使用";
  4132. }
  4133. item.UserId = tUserId.Id;
  4134. if (LeaderUserId > 0 && item.LeaderUserId == 0)
  4135. {
  4136. item.LeaderUserId = LeaderUserId;
  4137. }
  4138. }
  4139. db.SaveChanges();
  4140. db.Dispose();
  4141. return "success";
  4142. }
  4143. #endregion
  4144. #region 机具回仓退款
  4145. public IActionResult RefundPosFee(string right)
  4146. {
  4147. ViewBag.RightInfo = RightInfo;
  4148. ViewBag.right = right;
  4149. return View();
  4150. }
  4151. [HttpPost]
  4152. public string RefundPosFeeDo(string PosSn, string BackStoreNo, int IsBack = 0)
  4153. {
  4154. if (string.IsNullOrEmpty(PosSn))
  4155. {
  4156. return "请输入机具SN";
  4157. }
  4158. if (IsBack == 1)
  4159. {
  4160. if (string.IsNullOrEmpty(BackStoreNo))
  4161. {
  4162. return "请输入仓库编号";
  4163. }
  4164. }
  4165. string[] PosSnList = PosSn.Replace("\r", "").Split('\n');
  4166. WebCMSEntities db = new WebCMSEntities();
  4167. DateTime time = DateTime.Parse(DateTime.Now.ToString(("yyyy-MM-dd") + " 00:00:00"));
  4168. var endTime = time.AddDays(20 - time.Day).AddDays(-60);
  4169. StoreForCode storeForBack = new StoreForCode();
  4170. StoreHouse BackStore = new StoreHouse();
  4171. List<string> opData = new List<string>();
  4172. foreach (var item in PosSnList)
  4173. {
  4174. MachineForSnNo machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == item) ?? new MachineForSnNo();
  4175. if (machineForSnNo.SnId == 0)
  4176. {
  4177. return "未找到机具" + item + "关联数据";
  4178. }
  4179. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId && m.Status > -1 && m.RecycEndDate < endTime && m.BindingState == 0) ?? new PosMachinesTwo();
  4180. if (pos.Id == 0)
  4181. {
  4182. return "机具" + item + "不存在或者不满足条件";
  4183. }
  4184. if (IsBack == 1)
  4185. {
  4186. storeForBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  4187. if (storeForBack.StoreId == 0)
  4188. {
  4189. return "未找到" + BackStoreNo + "关联数据";
  4190. }
  4191. BackStore = db.StoreHouse.FirstOrDefault(m => m.Status > -1 && m.Id == storeForBack.StoreId && m.BrandId == pos.BrandId.ToString()) ?? new StoreHouse();
  4192. if (BackStore.Id == 0)
  4193. {
  4194. return "仓库" + BackStoreNo + "不存在或与机具品牌不符";
  4195. }
  4196. }
  4197. var userAccount = db.UserAccount.FirstOrDefault(m => m.Id == BackStore.UserId) ?? new UserAccount();
  4198. var refundUserAccount = db.UserAccount.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new UserAccount();
  4199. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId) ?? new KqProducts();
  4200. var amount = 0;
  4201. if (brandInfo.Name.Contains("电签"))
  4202. {
  4203. amount = 200;
  4204. }
  4205. if (brandInfo.Name.Contains("大POS"))
  4206. {
  4207. amount = 300;
  4208. }
  4209. if (IsBack == 1)
  4210. {
  4211. userAccount.ValidAmount -= amount;//扣减分仓可用额度
  4212. StoreStockChange stockchange = db.StoreStockChange.Add(new StoreStockChange()
  4213. {
  4214. CreateDate = DateTime.Now,
  4215. CreateMan = SysUserName,
  4216. StoreId = pos.StoreId, //出货仓库
  4217. BrandId = pos.BrandId, //产品类型
  4218. ProductName = RelationClass.GetKqProductBrandInfo(pos.BrandId), //产品名称
  4219. TransType = 5, //交易类型
  4220. SnNo = item, //SN编号
  4221. StockOpDirect = 0, //库存操作方向
  4222. SnStatus = 1, //SN状态
  4223. DeviceVendor = pos.DeviceName, //设备厂商
  4224. DeviceModel = pos.DeviceKind, //设备型号
  4225. DeviceType = pos.DeviceType, //设备类型
  4226. FromUserId = pos.BuyUserId, //来源创客
  4227. ToRemark = "过期机具回仓退款", //入库备注
  4228. ToStoreId = BackStore.Id, //退货收货仓库
  4229. SourceStoreId = pos.SourceStoreId, //源仓库编号
  4230. BrandType = pos.DeviceType, //品牌类型
  4231. }).Entity;
  4232. string ChangeNo = "HCTK";
  4233. int StoreStockChangeId = stockchange.Id;
  4234. string StoreStockChangeIdString = StoreStockChangeId.ToString();
  4235. for (int j = 0; j < 18 - StoreStockChangeId.ToString().Length; j++)
  4236. {
  4237. StoreStockChangeIdString = "0" + StoreStockChangeIdString;
  4238. }
  4239. ChangeNo += StoreStockChangeIdString;
  4240. stockchange.ChangeNo = ChangeNo; //交易流水编号
  4241. db.StoreChangeHistory.Add(new StoreChangeHistory()
  4242. {
  4243. CreateDate = DateTime.Now,
  4244. BrandId = pos.BrandId, //产品类型
  4245. ChangeRecordNo = ChangeNo, //变更记录单号
  4246. TransType = 5, //交易类型
  4247. SnNo = item, //SN编号
  4248. SnType = pos.PosSnType, //SN机具类型
  4249. StockOpDirect = 0, //库存操作方向
  4250. DeviceVendor = pos.DeviceName, //设备厂商
  4251. DeviceModel = pos.DeviceKind, //设备型号
  4252. DeviceType = pos.DeviceType, //设备类型
  4253. FromUserId = pos.BuyUserId, //来源创客
  4254. ToRemark = "过期机具回仓退款", //入库备注
  4255. SourceStoreId = pos.SourceStoreId, //源仓库
  4256. StoreId = pos.StoreId, //出货仓库
  4257. });
  4258. db.MachineReturn.Add(new MachineReturn()
  4259. {
  4260. CreateDate = DateTime.Now,
  4261. Operator = SysUserName + "_" + SysRealName,//操作人
  4262. BrandId = pos.BrandId, //产品类型
  4263. DeviceSnNos = pos.PosSn,
  4264. ToStoreId = BackStore.Id,
  4265. ApplyNo = ChangeNo, //变更记录单号
  4266. UserId = pos.BuyUserId, //来源创客
  4267. Remark = "过期机具回仓退款", //入库备注
  4268. });
  4269. if (pos.ScanQrTrade > 0)
  4270. {
  4271. decimal ChangeAmount = 0;
  4272. decimal BeforeBalanceAmount = 0;
  4273. decimal AfterBalanceAmount = 0;
  4274. if (pos.ScanQrTrade == 999)
  4275. {
  4276. refundUserAccount.BalanceAmount += amount;//退还创客机具货款
  4277. BeforeBalanceAmount = refundUserAccount.BalanceAmount;
  4278. AfterBalanceAmount = refundUserAccount.BalanceAmount + pos.ScanQrTrade;
  4279. ChangeAmount = amount;
  4280. }
  4281. else
  4282. {
  4283. refundUserAccount.BalanceAmount += pos.ScanQrTrade;//退还创客机具货款
  4284. BeforeBalanceAmount = refundUserAccount.BalanceAmount;
  4285. AfterBalanceAmount = refundUserAccount.BalanceAmount + pos.ScanQrTrade;
  4286. ChangeAmount = pos.ScanQrTrade;
  4287. }
  4288. db.UserAccountRecord.Add(new UserAccountRecord()
  4289. {
  4290. CreateDate = DateTime.Now,
  4291. UpdateDate = DateTime.Now,
  4292. UserId = pos.BuyUserId, //创客
  4293. ChangeType = 126, //变动类型(机具货款退还)
  4294. ProductType = 0, //产品类型
  4295. ChangeAmount = ChangeAmount, //变更金额
  4296. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  4297. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  4298. });
  4299. }
  4300. var bInfo = BackStore.UserId + "_" + pos.BrandId;
  4301. var userMachineData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == bInfo) ?? new UserMachineData();
  4302. userMachineData.TotalMachineCount += 1;
  4303. userMachineData.UnBindCount += 1;
  4304. BackStore.LaveNum += 1;
  4305. BackStore.TotalNum += 1;
  4306. var fInfo = pos.BuyUserId + "_" + pos.BrandId;
  4307. var userMachineDatas = db.UserMachineData.FirstOrDefault(m => m.IdBrand == fInfo) ?? new UserMachineData();
  4308. userMachineDatas.TotalMachineCount -= 1;
  4309. userMachineDatas.UnBindCount -= 1;
  4310. if (!opData.Contains(pos.BuyUserId + ":" + pos.BrandId))
  4311. {
  4312. opData.Add(pos.BuyUserId + ":" + pos.BrandId);
  4313. }
  4314. pos.StoreId = BackStore.Id;//变更机具所属仓库,重置为仓库机
  4315. pos.Status = 1;
  4316. pos.QueryCount = 0;
  4317. pos.UpdateDate = null;
  4318. pos.ActivityList = null;
  4319. pos.SeoKeyword = null;
  4320. pos.SeoDescription = null;
  4321. pos.OrderId = 0;
  4322. pos.RecycEndDate = null;
  4323. pos.RecycBackCount = 0;
  4324. pos.PrizeParams = null;
  4325. pos.ScanQrTrade = 0;
  4326. pos.BindMerchantId = 0;
  4327. pos.CreditTrade = 0;
  4328. pos.DebitCardTrade = 0;
  4329. pos.IsVip = 0;
  4330. pos.UserNav = null;
  4331. pos.TransferTime = null;
  4332. pos.IsPurchase = 0;
  4333. pos.Detail = null;
  4334. pos.BindingTime = null;
  4335. pos.BindingState = 0;
  4336. pos.ActivationTime = null;
  4337. pos.ActivationState = 0;
  4338. pos.LeaderUserId = 0;
  4339. pos.PreUserId = 0;
  4340. pos.IsFirst = 0;
  4341. pos.DownFeeMan = null;
  4342. pos.DownFeeFlag = 0;
  4343. pos.DownFeeDate = null;
  4344. pos.UpFeeMan = null;
  4345. pos.UpFeeFlag = 0;
  4346. pos.UpFeeDate = null;
  4347. pos.OpReserve1 = 0;
  4348. pos.OpReserve2 = 0;
  4349. pos.OpReserve3 = 0;
  4350. pos.OpId = 0;
  4351. pos.RecycStartDate = null;
  4352. pos.SourcePosSn = null;
  4353. pos.BuyUserId = 0;
  4354. pos.UserId = 0;
  4355. PublicFunction.ClearPosHistory(db, pos.PosSn); //清除机具历史记录
  4356. }
  4357. else
  4358. {
  4359. if (pos.ScanQrTrade > 0)
  4360. {
  4361. decimal ChangeAmount = 0;
  4362. decimal BeforeBalanceAmount = 0;
  4363. decimal AfterBalanceAmount = 0;
  4364. if (pos.ScanQrTrade == 999)
  4365. {
  4366. refundUserAccount.BalanceAmount += amount;//退还创客机具货款
  4367. BeforeBalanceAmount = refundUserAccount.BalanceAmount;
  4368. AfterBalanceAmount = refundUserAccount.BalanceAmount + pos.ScanQrTrade;
  4369. ChangeAmount = amount;
  4370. }
  4371. else
  4372. {
  4373. refundUserAccount.BalanceAmount += pos.ScanQrTrade;//退还创客机具货款
  4374. BeforeBalanceAmount = refundUserAccount.BalanceAmount;
  4375. AfterBalanceAmount = refundUserAccount.BalanceAmount + pos.ScanQrTrade;
  4376. ChangeAmount = pos.ScanQrTrade;
  4377. }
  4378. pos.ScanQrTrade = 0;
  4379. db.UserAccountRecord.Add(new UserAccountRecord()
  4380. {
  4381. CreateDate = DateTime.Now,
  4382. UpdateDate = DateTime.Now,
  4383. UserId = pos.BuyUserId, //创客
  4384. ChangeType = 126, //变动类型(机具货款退还)
  4385. ProductType = 0, //产品类型
  4386. ChangeAmount = ChangeAmount, //变更金额
  4387. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  4388. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  4389. });
  4390. }
  4391. }
  4392. }
  4393. db.SaveChanges();
  4394. foreach (string sub in opData)
  4395. {
  4396. string[] datalist = sub.Split(":");
  4397. PublicFunction.SycnMachineCount(int.Parse(datalist[0]), int.Parse(datalist[1]));
  4398. }
  4399. return "success";
  4400. }
  4401. #endregion
  4402. #region 添加商户信息
  4403. public IActionResult AddMerchantnfo(string right)
  4404. {
  4405. ViewBag.RightInfo = RightInfo;
  4406. ViewBag.right = right;
  4407. return View();
  4408. }
  4409. [HttpPost]
  4410. public string AddMerchantnfoDo(string PosSn, string MerSn)
  4411. {
  4412. if (string.IsNullOrEmpty(PosSn))
  4413. {
  4414. return "请输入机具号";
  4415. }
  4416. if (string.IsNullOrEmpty(MerSn))
  4417. {
  4418. return "请输入商户号";
  4419. }
  4420. var machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn) ?? new MachineForSnNo();
  4421. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId) ?? new PosMachinesTwo();
  4422. var merchantInfo = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
  4423. if (machineForSnNo.SnId == 0)
  4424. {
  4425. return "未找到机具" + PosSn + "关联数据";
  4426. }
  4427. if (pos.Id == 0)
  4428. {
  4429. return "未找到机具" + PosSn;
  4430. }
  4431. if (merchantInfo.Id > 0)
  4432. {
  4433. return "机具" + PosSn + "以经存在绑定商户";
  4434. }
  4435. var spInfo = spdb.BindRecord.FirstOrDefault(m => m.MerNo == MerSn && m.MerSnNo == PosSn) ?? new SpModels.BindRecord();
  4436. if (spInfo.Id > 0)
  4437. {
  4438. var MerUserType = 0;
  4439. var ActiveStatus = 0;
  4440. if (pos.BuyUserId != pos.UserId)
  4441. {
  4442. MerUserType = 1;
  4443. }
  4444. if (string.IsNullOrEmpty(pos.ActivationTime.ToString()))
  4445. {
  4446. ActiveStatus = 1;
  4447. }
  4448. PosMerchantInfo posMerchantInfo = db.PosMerchantInfo.Add(new PosMerchantInfo()
  4449. {
  4450. CreateDate = pos.BindingTime,
  4451. TopUserId = 1,
  4452. BrandId = pos.BrandId,
  4453. SnStoreId = pos.StoreId,
  4454. MerStandardDate = pos.ActivationTime,
  4455. SnType = pos.PosSnType,
  4456. MerUserType = MerUserType,
  4457. UserId = pos.UserId,
  4458. ActiveStatus = ActiveStatus,
  4459. MerStatus = 1,
  4460. KqSnNo = PosSn,
  4461. KqMerNo = MerSn,
  4462. MerIdcardNo = spInfo.SeoKeyword,
  4463. MerchantMobile = spInfo.MerNewSnNo,
  4464. MerchantName = spInfo.MerName,
  4465. MerchantNo = spInfo.MerNo,
  4466. }).Entity;
  4467. db.SaveChanges();
  4468. string text = string.Format("设置商户信息,机具Sn: " + PosSn + ",商户编号: " + MerSn + ",操作人:" + SysUserName + "_" + SysRealName + ",时间:" + DateTime.Now + "");
  4469. function.WriteLog(text, "设置商户信息");
  4470. }
  4471. return "success";
  4472. }
  4473. #endregion
  4474. }
  4475. }