SysToolsController.cs 331 KB

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