SysToolsController.cs 320 KB

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