SysToolsController.cs 324 KB

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