SysToolsController.cs 323 KB

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