SysToolsController.cs 321 KB

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