SysToolsController.cs 324 KB

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