SysToolsController.cs 300 KB

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