SysToolsController.cs 351 KB

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