SysToolsController.cs 219 KB

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