SysToolsController.cs 347 KB

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