SysToolsController.cs 214 KB

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