SysToolsController.cs 322 KB

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