SysToolsController.cs 326 KB

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