SysToolsController.cs 325 KB

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