SysToolsController.cs 321 KB

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