SysToolsController.cs 248 KB

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