SysToolsController.cs 321 KB

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