SysToolsController.cs 280 KB

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