SysToolsController.cs 239 KB

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