SysToolsController.cs 321 KB

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