SysToolsController.cs 351 KB

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