SysToolsController.cs 293 KB

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