SysToolsController.cs 302 KB

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