SysToolsController.cs 265 KB

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