SysToolsController.cs 297 KB

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