SysToolsController.cs 327 KB

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