SysToolsController.cs 239 KB

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