SysToolsController.cs 324 KB

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