SysToolsController.cs 250 KB

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