SysToolsController.cs 218 KB

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