SysToolsController.cs 321 KB

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