SysToolsController.cs 331 KB

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