SysToolsController.cs 300 KB

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