SysToolsController.cs 211 KB

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