SysToolsController.cs 209 KB

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