SysToolsController.cs 325 KB

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