SysToolsController.cs 321 KB

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