SysToolsController.cs 320 KB

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