SysToolsController.cs 326 KB

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