Sin descripción
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870
  1. <?php
  2. /**
  3. * 易优CMS
  4. * ============================================================================
  5. * 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
  6. * 网站地址: http://www.eyoucms.com
  7. * ----------------------------------------------------------------------------
  8. * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
  9. * ============================================================================
  10. * Author: 小虎哥 <1105415366@qq.com>
  11. * Date: 2018-4-3
  12. */
  13. // 关闭所有PHP错误报告
  14. use think\Db;
  15. error_reporting(0);
  16. include_once EXTEND_PATH."function.php";
  17. // 应用公共文件
  18. if (!function_exists('switch_exception'))
  19. {
  20. // 模板错误提示
  21. function switch_exception() {
  22. $web_exception = tpCache('web.web_exception');
  23. if (!empty($web_exception)) {
  24. config('ey_config.web_exception', $web_exception);
  25. error_reporting(-1);
  26. }
  27. }
  28. }
  29. if (!function_exists('adminLog'))
  30. {
  31. /**
  32. * 管理员操作记录
  33. * @param $log_url 操作URL
  34. * @param $log_info 记录信息
  35. */
  36. function adminLog($log_info = ''){
  37. // 只保留最近一个月的操作日志
  38. try {
  39. $ajaxLogic = new \app\admin\logic\AjaxLogic;
  40. $ajaxLogic->del_adminlog();
  41. $admin_id = session('admin_id');
  42. $admin_id = !empty($admin_id) ? $admin_id : -1;
  43. if ($admin_id > 0) {
  44. $add['log_time'] = getTime();
  45. $add['admin_id'] = $admin_id;
  46. $add['log_info'] = htmlspecialchars($log_info);
  47. $add['log_ip'] = clientIP();
  48. $add['log_url'] = request()->baseUrl() ;
  49. M('admin_log')->add($add);
  50. }
  51. } catch (\Exception $e) {
  52. }
  53. }
  54. }
  55. if (!function_exists('login_third_type'))
  56. {
  57. /**
  58. * 识别当前使用的扫码登录功能:1、扫微信应用登录,2、扫官方微信公众号登录
  59. * @param
  60. * @return array
  61. */
  62. function login_third_type()
  63. {
  64. $redata = [
  65. 'type' => '',
  66. 'data' => [],
  67. ];
  68. if (is_dir('./weapp/EyouGzhLogin/')) { // 是否安装【后台扫码登录】插件
  69. $EyouGzhLoginRow = model('Weapp')->getWeappList('EyouGzhLogin');
  70. $status = !empty($EyouGzhLoginRow['status']) ? intval($EyouGzhLoginRow['status']) : 0;
  71. $data = !empty($EyouGzhLoginRow['data']) ? $EyouGzhLoginRow['data'] : [];
  72. if (1 == $status && !empty($data['is_open'])) {
  73. $redata['type'] = $data['mode'];
  74. if ('EyouGzhLogin' == $data['mode']) {
  75. $data['gzh']['switch'] = 1;
  76. $redata['data'] = $data['gzh'];
  77. }
  78. else if ('WechatLogin' == $data['mode']) {
  79. $security = tpSetting('security');
  80. $redata['data'] = $security;
  81. }
  82. }
  83. }
  84. return $redata;
  85. }
  86. }
  87. if (!function_exists('tpCache'))
  88. {
  89. /**
  90. * 获取缓存或者更新缓存,只适用于config表
  91. * @param string $config_key 缓存文件名称
  92. * @param array $data 缓存数据 array('k1'=>'v1','k2'=>'v3')
  93. * @param array $options 缓存配置
  94. * @param string $lang 语言标识
  95. * @return array or string or bool
  96. */
  97. function tpCache($config_key,$data = array(), $lang = '', $options = null){
  98. $tableName = 'config';
  99. $table_db = \think\Db::name($tableName);
  100. $lang = !empty($lang) ? $lang : get_current_lang();
  101. $param = explode('.', $config_key);
  102. $cache_inc_type = "{$tableName}-{$lang}-{$param[0]}";
  103. if (empty($options['path'])) {
  104. $options['path'] = DATA_PATH.'runtime'.DS.'cache'.DS.$lang.DS;
  105. }
  106. if(empty($data)){
  107. //如$config_key=shop_info则获取网站信息数组
  108. //如$config_key=shop_info.logo则获取网站logo字符串
  109. $config = cache($cache_inc_type,'',$options);//直接获取缓存文件
  110. if(empty($config)){
  111. //缓存文件不存在就读取数据库
  112. if ($param[0] == 'global') {
  113. $param[0] = 'global';
  114. $res = $table_db->where([
  115. 'lang' => $lang,
  116. 'is_del' => 0,
  117. ])->select();
  118. } else {
  119. $res = $table_db->where([
  120. 'inc_type' => $param[0],
  121. 'lang' => $lang,
  122. 'is_del' => 0,
  123. ])->select();
  124. }
  125. if($res){
  126. foreach($res as $k=>$val){
  127. $config[$val['name']] = $val['value'];
  128. }
  129. cache($cache_inc_type,$config,$options);
  130. }
  131. // write_global_params($lang, $options);
  132. }
  133. if(!empty($param) && count($param)>1){
  134. $newKey = strtolower($param[1]);
  135. return isset($config[$newKey]) ? $config[$newKey] : '';
  136. }else{
  137. return $config;
  138. }
  139. }else{
  140. //更新缓存
  141. $result = $table_db->where([
  142. 'inc_type' => $param[0],
  143. 'lang' => $lang,
  144. 'is_del' => 0,
  145. ])->select();
  146. if($result){
  147. foreach($result as $val){
  148. $temp[$val['name']] = $val['value'];
  149. }
  150. $add_data = array();
  151. foreach ($data as $k=>$v){
  152. $newK = strtolower($k);
  153. $newArr = array(
  154. 'name'=>$newK,
  155. 'value'=>trim($v),
  156. 'inc_type'=>$param[0],
  157. 'lang' => $lang,
  158. 'update_time' => getTime(),
  159. );
  160. if(!isset($temp[$newK])){
  161. array_push($add_data, $newArr); //新key数据插入数据库
  162. }else{
  163. if ($v != $temp[$newK]) {
  164. $table_db->where([
  165. 'name' => $newK,
  166. 'lang' => $lang,
  167. ])->save($newArr);//缓存key存在且值有变更新此项
  168. }
  169. }
  170. }
  171. if (!empty($add_data)) {
  172. $table_db->insertAll($add_data);
  173. }
  174. //更新后的数据库记录
  175. $newRes = $table_db->where([
  176. 'inc_type' => $param[0],
  177. 'lang' => $lang,
  178. 'is_del' => 0,
  179. ])->select();
  180. foreach ($newRes as $rs){
  181. $newData[$rs['name']] = $rs['value'];
  182. }
  183. }else{
  184. if ($param[0] != 'global') {
  185. foreach($data as $k=>$v){
  186. $newK = strtolower($k);
  187. $newArr[] = array(
  188. 'name'=>$newK,
  189. 'value'=>trim($v),
  190. 'inc_type'=>$param[0],
  191. 'lang' => $lang,
  192. 'update_time' => getTime(),
  193. );
  194. }
  195. !empty($newArr) && $table_db->insertAll($newArr);
  196. }
  197. $newData = $data;
  198. }
  199. $result = false;
  200. $res = $table_db->where([
  201. 'lang' => $lang,
  202. 'is_del' => 0,
  203. ])->select();
  204. if($res){
  205. $global = array();
  206. foreach($res as $k=>$val){
  207. $global[$val['name']] = $val['value'];
  208. }
  209. $result = cache("{$tableName}-{$lang}-global",$global,$options);
  210. }
  211. if ($param[0] != 'global') {
  212. $result = cache($cache_inc_type,$newData,$options);
  213. }
  214. return $result;
  215. }
  216. }
  217. }
  218. if (!function_exists('tpSetting'))
  219. {
  220. /**
  221. * 获取缓存或者更新缓存,只适用于setting表
  222. * @param string $config_key 缓存文件名称
  223. * @param array $data 缓存数据 array('k1'=>'v1','k2'=>'v3')
  224. * @param array $options 缓存配置
  225. * @param string $lang 语言标识
  226. * @return array or string or bool
  227. */
  228. function tpSetting($config_key,$data = array(), $lang = '', $options = null){
  229. $tableName = 'setting';
  230. $table_db = \think\Db::name($tableName);
  231. $lang = !empty($lang) ? $lang : get_current_lang();
  232. $param = explode('.', $config_key);
  233. $cache_inc_type = "{$tableName}-{$lang}-{$param[0]}";
  234. if (empty($options['path'])) {
  235. $options['path'] = DATA_PATH.'runtime'.DS.'cache'.DS.$lang.DS;
  236. }
  237. if(empty($data)){
  238. //如$config_key=shop_info则获取网站信息数组
  239. //如$config_key=shop_info.logo则获取网站logo字符串
  240. $config = cache($cache_inc_type,'',$options);//直接获取缓存文件
  241. if(empty($config)){
  242. //缓存文件不存在就读取数据库
  243. if ($param[0] == 'global') {
  244. $param[0] = 'global';
  245. $res = $table_db->where([
  246. 'lang' => $lang,
  247. ])->select();
  248. } else {
  249. $res = $table_db->where([
  250. 'inc_type' => $param[0],
  251. 'lang' => $lang,
  252. ])->select();
  253. }
  254. if($res){
  255. foreach($res as $k=>$val){
  256. $config[$val['name']] = $val['value'];
  257. }
  258. cache($cache_inc_type,$config,$options);
  259. }
  260. // write_global_params($lang, $options);
  261. }
  262. if(!empty($param) && count($param)>1){
  263. $newKey = strtolower($param[1]);
  264. return isset($config[$newKey]) ? $config[$newKey] : '';
  265. }else{
  266. return $config;
  267. }
  268. }else{
  269. //更新缓存
  270. $result = $table_db->where([
  271. 'inc_type' => $param[0],
  272. 'lang' => $lang,
  273. ])->select();
  274. if($result){
  275. foreach($result as $val){
  276. $temp[$val['name']] = $val['value'];
  277. }
  278. $add_data = array();
  279. foreach ($data as $k=>$v){
  280. $newK = strtolower($k);
  281. $newArr = array(
  282. 'name'=>$newK,
  283. 'value'=>trim($v),
  284. 'inc_type'=>$param[0],
  285. 'lang' => $lang,
  286. 'update_time' => getTime(),
  287. );
  288. if(!isset($temp[$newK])){
  289. array_push($add_data, $newArr); //新key数据插入数据库
  290. }else{
  291. if ($v != $temp[$newK]) {
  292. $table_db->where([
  293. 'name' => $newK,
  294. 'lang' => $lang,
  295. ])->save($newArr);//缓存key存在且值有变更新此项
  296. }
  297. }
  298. }
  299. if (!empty($add_data)) {
  300. $table_db->insertAll($add_data);
  301. }
  302. //更新后的数据库记录
  303. $newRes = $table_db->where([
  304. 'inc_type' => $param[0],
  305. 'lang' => $lang,
  306. ])->select();
  307. foreach ($newRes as $rs){
  308. $newData[$rs['name']] = $rs['value'];
  309. }
  310. }else{
  311. if ($param[0] != 'global') {
  312. foreach($data as $k=>$v){
  313. $newK = strtolower($k);
  314. $newArr[] = array(
  315. 'name'=>$newK,
  316. 'value'=>trim($v),
  317. 'inc_type'=>$param[0],
  318. 'lang' => $lang,
  319. 'update_time' => time(),
  320. );
  321. }
  322. $table_db->insertAll($newArr);
  323. }
  324. $newData = $data;
  325. }
  326. $result = false;
  327. $res = $table_db->where([
  328. 'lang' => $lang,
  329. ])->select();
  330. if($res){
  331. $global = array();
  332. foreach($res as $k=>$val){
  333. $global[$val['name']] = $val['value'];
  334. }
  335. $result = cache("{$tableName}-{$lang}-global",$global,$options);
  336. }
  337. if ($param[0] != 'global') {
  338. $result = cache($cache_inc_type,$newData,$options);
  339. }
  340. return $result;
  341. }
  342. }
  343. }
  344. if (!function_exists('write_global_params'))
  345. {
  346. /**
  347. * 写入全局内置参数
  348. * @return array
  349. */
  350. function write_global_params($lang = '', $options = null)
  351. {
  352. empty($lang) && $lang = get_admin_lang();
  353. $webConfigParams = \think\Db::name('config')->where([
  354. 'inc_type' => 'web',
  355. 'lang' => $lang,
  356. 'is_del' => 0,
  357. ])->getAllWithIndex('name');
  358. $web_basehost = !empty($webConfigParams['web_basehost']) ? $webConfigParams['web_basehost']['value'] : ''; // 网站根网址
  359. $web_cmspath = !empty($webConfigParams['web_cmspath']) ? $webConfigParams['web_cmspath']['value'] : ''; // EyouCMS安装目录
  360. /*启用绝对网址,开启此项后附件、栏目连接、arclist内容等都使用http路径*/
  361. $web_multi_site = !empty($webConfigParams['web_multi_site']) ? $webConfigParams['web_multi_site']['value'] : '';
  362. if($web_multi_site == 1)
  363. {
  364. $web_mainsite = $web_basehost.$web_cmspath;
  365. }
  366. else
  367. {
  368. $web_mainsite = '';
  369. }
  370. /*--end*/
  371. /*CMS安装目录的网址*/
  372. $param['web_cmsurl'] = $web_mainsite;
  373. /*--end*/
  374. $web_tpl_theme = !empty($webConfigParams['web_tpl_theme']) ? $webConfigParams['web_tpl_theme']['value'] : ''; // 网站根网址
  375. !empty($web_tpl_theme) && $web_tpl_theme = '/'.trim($web_tpl_theme, '/');
  376. $param['web_templets_dir'] = '/template'.$web_tpl_theme; // 前台模板根目录
  377. $param['web_templeturl'] = $web_mainsite.$param['web_templets_dir']; // 前台模板根目录的网址
  378. $param['web_templets_pc'] = $web_mainsite.$param['web_templets_dir'].'/pc'; // 前台PC模板主题
  379. $param['web_templets_m'] = $web_mainsite.$param['web_templets_dir'].'/mobile'; // 前台手机模板主题
  380. $param['web_eyoucms'] = str_replace('#', '', '#h#t#t#p#:#/#/#w#w#w#.#e#y#o#u#c#m#s#.#c#o#m#'); // eyou网址
  381. /*将内置的全局变量(页面上没有入口更改的全局变量)存储到web版块里*/
  382. $inc_type = 'web';
  383. foreach ($param as $key => $val) {
  384. if (preg_match("/^".$inc_type."_(.)+/i", $key) !== 1) {
  385. $nowKey = strtolower($inc_type.'_'.$key);
  386. $param[$nowKey] = $val;
  387. }
  388. }
  389. tpCache($inc_type, $param, $lang, $options);
  390. /*--end*/
  391. }
  392. }
  393. if (!function_exists('write_html_cache'))
  394. {
  395. /**
  396. * 写入静态页面缓存
  397. */
  398. function write_html_cache($html = '', $result = []){
  399. $html_cache_status = config('HTML_CACHE_STATUS');
  400. $html_cache_arr = config('HTML_CACHE_ARR');
  401. //var_dump($html_cache_status); //bool(true)
  402. //var_dump($html_cache_arr); //array(0) { }
  403. //$html_cache_status && !empty($html_cache_arr) && !empty($html)
  404. //为了调试
  405. if ($html_cache_status && !empty($html_cache_arr) && !empty($html)) {
  406. //var_dump("开始缓存");
  407. // 多站点/多语言
  408. $home_lang = 'cn';
  409. $home_site = '';
  410. $city_switch_on = config('city_switch_on');
  411. if (!empty($city_switch_on)) {
  412. $home_site = get_home_site();
  413. } else {
  414. $home_lang = get_home_lang();
  415. }
  416. $request = \think\Request::instance();
  417. $param = input('param.');
  418. //https://www.zc10000.com/zczl/jzzc1-2
  419. //array(3) {
  420. // ["areaid"]=>
  421. // string(1) "1"
  422. // ["pa"]=>
  423. // string(1) "2"
  424. // ["tid"]=>
  425. // string(2) "38"
  426. //}
  427. //var_dump($param);
  428. /*
  429. * 补充L 分页不算 筛选 筛选是指实时的数据 还有搜索也是实时数据
  430. * 后续补充 根据页面url或者参数 不使用缓存即可 return false
  431. */
  432. /*URL模式是否启动页面缓存(排除admin后台、前台可视化装修、前台筛选)*/
  433. $uiset = input('param.uiset/s', 'off');
  434. $uiset = trim($uiset, '/');
  435. $url_screen_var = config('global.url_screen_var'); //目前没有用到前台筛选
  436. $arcrank = !empty($result['arcrank']) ? intval($result['arcrank']) : 0;
  437. $admin_id = input('param.admin_id/d');
  438. if (isset($param[$url_screen_var]) || 'on' == $uiset || 'admin' == $request->module() || -1 == $arcrank || !empty($admin_id)) {
  439. return false;
  440. }
  441. //继续
  442. $seo_pseudo = config('ey_config.seo_pseudo'); //伪静态模式
  443. //var_dump($seo_pseudo); //2是静态页面 3是伪静态 1是动态url 目前是1
  444. //var_dump(!isMobile());
  445. if (2 == $seo_pseudo && !isMobile()) { // 排除普通动态模式
  446. return false;
  447. }
  448. /*--end*/
  449. if (1 == $seo_pseudo) {
  450. //执行到这
  451. //获取栏目id
  452. isset($param['tid']) && $param['tid'] = input('param.tid/d'); //强制转换成整型
  453. } else {
  454. isset($param['tid']) && $param['tid'] = input('param.tid/s'); //强制转换成字符串类型
  455. }
  456. //获取分页
  457. isset($param['page']) && $param['page'] = input('param.page/d');
  458. // aid唯一性的处理
  459. if (isset($param['aid'])) {
  460. if (!preg_match('/^([\w\-]+)$/', $param['aid'])) {
  461. to_index();
  462. }
  463. }
  464. $m_c_a_str = $request->module().'_'.$request->controller().'_'.$request->action(); // 模块_控制器_方法
  465. $m_c_a_str = strtolower($m_c_a_str);
  466. //var_dump($m_c_a_str);
  467. //echo "<pre>";
  468. //var_dump($html_cache_arr); //开启运营模式 然后清理缓存 首次执行就会得到这个数组
  469. //echo "</pre>";
  470. //exit('write_html_cache写入缓存<br/>');
  471. foreach($html_cache_arr as $mca=>$val)
  472. {
  473. $mca = strtolower($mca);
  474. if($mca != $m_c_a_str) //不是当前 模块 控制器 方法 直接跳过
  475. continue;
  476. //现在只用到这两个 模块 控制器 方法 其他再说
  477. //home_lists_index 与 home_view_index
  478. //var_dump($mca);
  479. //手动增加参数规则
  480. //cms没办法把 筛选条件 写死 筛选条件是自定义的 有点麻烦
  481. //根据筛选条件 生成html 理论上可行的
  482. //区别 实时还是缓存而已;
  483. /*$val['p'][] = 'pa';
  484. $val['p'][] = 'areaid';
  485. $val['p'][] = 'catids';*/
  486. //把参数放进数组
  487. /*增加代码 start*/
  488. foreach ($param as $index=>$row){
  489. if(!in_array($index,$val['p'])){
  490. $val['p'][] = $index;
  491. }
  492. }
  493. /*增加代码 end*/
  494. //根据域名得到区域id
  495. //原网站已自动处理
  496. //https_cn_guangdong_mobile_56_23_1.html
  497. /*echo "<pre>";
  498. var_dump($val);
  499. echo "</pre>";*/
  500. if (empty($val['filename'])) {
  501. continue;
  502. }
  503. $cache_tag = ''; // 缓存标签
  504. $filename = '';
  505. // 组合参数
  506. if(isset($val['p']))
  507. {
  508. $tid = '';
  509. if (in_array('tid', $val['p'])) {
  510. $tid = !empty($param['tid']) ? $param['tid'] : '';
  511. if (strval(intval($tid)) != strval($tid)) {
  512. $where = [
  513. 'dirname' => $tid,
  514. ];
  515. if (empty($city_switch_on)) {
  516. $where['lang'] =$home_lang;
  517. }
  518. $tid = \think\Db::name('arctype')->where($where)->getField('id');
  519. $param['tid'] = $tid;
  520. }
  521. }
  522. foreach ($val['p'] as $k=>$v) {
  523. if (isset($param[$v])) {
  524. if (preg_match('/\/$/i', $filename)) {
  525. $filename .= $param[$v];
  526. } else {
  527. if (!empty($filename) || is_numeric($filename)) {
  528. $filename .= '_';
  529. }
  530. $filename .= $param[$v];
  531. }
  532. }
  533. }
  534. !empty($tid) && $cache_tag = $tid; // 针对列表缓存的标签
  535. !empty($param['aid']) && $cache_tag = $param['aid']; // 针对内容缓存的标签
  536. }
  537. //根据参数规则 得到的命名
  538. //var_dump($filename);
  539. empty($filename) && $filename = 'index';
  540. /*子域名(移动端域名)*/
  541. $is_mobile_domain = false;
  542. $web_mobile_domain = config('tpcache.web_mobile_domain'); //响应式还是分离式
  543. $goto = $request->param('goto');
  544. $goto = trim($goto, '/');
  545. $subDomain = $request->subDomain();
  546. if ('m' == $goto || (!empty($subDomain) && $subDomain == $web_mobile_domain)) {
  547. $is_mobile_domain = true;
  548. } else {
  549. //不考虑 不知道是什么 目前是2
  550. if (3 == $seo_pseudo) {
  551. $pathinfo = $request->pathinfo();
  552. if (!empty($pathinfo)) {
  553. $s_arr = explode('/', $pathinfo);
  554. if ('m' == $s_arr[0]) {
  555. $is_mobile_domain = true;
  556. }
  557. }
  558. }
  559. }
  560. //var_dump($is_mobile_domain); //目前false
  561. /*end*/
  562. // 多站点
  563. !empty($home_site) && $home_site = '_'.$home_site;
  564. //var_dump($home_site); //目前为空
  565. // 缓存时间
  566. $web_cmsmode = 1;//tpCache('web.web_cmsmode');
  567. // $response_type = config('ey_config.response_type'); // 0是代码适配,1:pc、移动端分离(存在pc、移动端两套模板)
  568. if (1 == intval($web_cmsmode)) { // 永久
  569. $path = HTML_ROOT.$val['filename'].DS;
  570. $new_filename = TCP_SCHEME.'_'.$home_lang.$home_site;
  571. if (isMobile() || $is_mobile_domain) {
  572. $new_filename .= "_mobile";
  573. } else {
  574. $new_filename .= "_pc";
  575. }
  576. $new_filename .= '_'.$filename;
  577. // $arr = explode('_', $filename);
  578. // $id = end($arr);
  579. // $new_filename = preg_replace('/^(.*)\_([^\_]+)$/i', '${1}', $new_filename);
  580. // $filename = md5($new_filename).'_'.$id;
  581. /*增加代码 start*/
  582. $url = request()->url();
  583. //作了序列号 详情页 不一定 唯一 只有aid参数
  584. $nurl = str_replace('/','_',$url);
  585. $domain = request()->domain();
  586. $domain = str_replace('https://','',$domain);
  587. $domain = str_replace('http://','',$domain);
  588. $ndomain = str_replace('.','_',$domain);
  589. //var_dump($nurl.$ndomain);
  590. $new_filename .= '_'.$ndomain.$nurl;
  591. /*增加代码 end*/
  592. $filename = preg_replace('/([^\w\-]+)/i', '', $new_filename);
  593. $filename = $path."{$filename}.html";
  594. //https_cn_pc_38_2_1.html
  595. //https_cn_mobile_38_2_1.html
  596. //var_dump($filename);
  597. tp_mkdir(dirname($filename));
  598. !empty($html) && file_put_contents($filename, $html);
  599. } else {
  600. $path = HTML_PATH.$val['filename'].DS.$home_lang.DS.trim($home_site, '_');
  601. if (isMobile()) {
  602. $path .= "_mobile";
  603. } else {
  604. $path .= "_pc";
  605. }
  606. $path .= '_cache'.DS;
  607. $web_htmlcache_expires_in = config('tpcache.web_htmlcache_expires_in');
  608. $options = array(
  609. 'path' => $path,
  610. 'expire'=> intval($web_htmlcache_expires_in),
  611. 'prefix' => $cache_tag,
  612. );
  613. // !empty($html) && html_cache($filename,$html,$options);
  614. }
  615. }
  616. }
  617. }
  618. }
  619. if (!function_exists('read_html_cache'))
  620. {
  621. /**
  622. * 读取静态页面缓存
  623. */
  624. function read_html_cache(){
  625. $html_cache_status = config('HTML_CACHE_STATUS');
  626. $html_cache_arr = config('HTML_CACHE_ARR');
  627. if ($html_cache_status && !empty($html_cache_arr)) {
  628. // 多站点/多语言
  629. $home_lang = 'cn';
  630. $home_site = '';
  631. $city_switch_on = config('city_switch_on');
  632. if (!empty($city_switch_on)) {
  633. $home_site = get_home_site();
  634. } else {
  635. $home_lang = get_home_lang();
  636. }
  637. $request = \think\Request::instance();
  638. $seo_pseudo = config('ey_config.seo_pseudo');
  639. $param = input('param.');
  640. /*前台筛选不进行页面缓存*/
  641. $url_screen_var = config('global.url_screen_var');
  642. if (isset($param[$url_screen_var])) {
  643. return false;
  644. }
  645. /*end*/
  646. if (1 == $seo_pseudo) {
  647. isset($param['tid']) && $param['tid'] = input('param.tid/d');
  648. } else {
  649. isset($param['tid']) && $param['tid'] = input('param.tid/s');
  650. }
  651. isset($param['page']) && $param['page'] = input('param.page/d');
  652. // aid唯一性的处理
  653. if (isset($param['aid'])) {
  654. if (!preg_match('/^([\w\-]+)$/', $param['aid'])) {
  655. to_index();
  656. }
  657. }
  658. $m_c_a_str = $request->module().'_'.$request->controller().'_'.$request->action(); // 模块_控制器_方法
  659. $m_c_a_str = strtolower($m_c_a_str);
  660. //exit('read_html_cache读取缓存<br/>');
  661. foreach($html_cache_arr as $mca=>$val)
  662. {
  663. $mca = strtolower($mca);
  664. if($mca != $m_c_a_str) //不是当前 模块 控制器 方法 直接跳过
  665. continue;
  666. if (empty($val['filename'])) {
  667. continue;
  668. }
  669. /*增加代码 start*/
  670. foreach ($param as $index=>$row){
  671. if(!in_array($index,$val['p'])){
  672. $val['p'][] = $index;
  673. }
  674. }
  675. /*增加代码 end*/
  676. $cache_tag = ''; // 缓存标签
  677. $filename = '';
  678. // 组合参数
  679. if(isset($val['p']))
  680. {
  681. $tid = '';
  682. if (in_array('tid', $val['p'])) {
  683. $tid = !empty($param['tid']) ? $param['tid'] : '';
  684. if (strval(intval($tid)) != strval($tid)) {
  685. $where = [
  686. 'dirname' => $tid,
  687. ];
  688. if (empty($city_switch_on)) {
  689. $where['lang'] =$home_lang;
  690. }
  691. $tid = \think\Db::name('arctype')->where($where)->getField('id');
  692. $param['tid'] = $tid;
  693. }
  694. }
  695. foreach ($val['p'] as $k=>$v) {
  696. if (isset($param[$v])) {
  697. if (preg_match('/\/$/i', $filename)) {
  698. $filename .= $param[$v];
  699. } else {
  700. if (!empty($filename) || is_numeric($filename)) {
  701. $filename .= '_';
  702. }
  703. $filename .= $param[$v];
  704. }
  705. }
  706. }
  707. !empty($tid) && $cache_tag = $tid; // 针对列表缓存的标签
  708. !empty($param['aid']) && $cache_tag = $param['aid']; // 针对内容缓存的标签
  709. }
  710. empty($filename) && $filename = 'index';
  711. // $filename = md5($filename);
  712. //var_dump($filename);
  713. /*子域名(移动端域名)*/
  714. $is_mobile_domain = false;
  715. $web_mobile_domain = config('tpcache.web_mobile_domain');
  716. $goto = $request->param('goto');
  717. $goto = trim($goto, '/');
  718. $subDomain = $request->subDomain();
  719. if ('m' == $goto || (!empty($subDomain) && $subDomain == $web_mobile_domain)) {
  720. $is_mobile_domain = true;
  721. } else {
  722. if (3 == $seo_pseudo) {
  723. $pathinfo = $request->pathinfo();
  724. if (!empty($pathinfo)) {
  725. $s_arr = explode('/', $pathinfo);
  726. if ('m' == $s_arr[0]) {
  727. $is_mobile_domain = true;
  728. }
  729. }
  730. }
  731. }
  732. /*end*/
  733. // 多站点
  734. !empty($home_site) && $home_site = '_'.$home_site;
  735. // 缓存时间
  736. $web_cmsmode = 1;//tpCache('web.web_cmsmode');
  737. // $response_type = config('ey_config.response_type'); // 0是代码适配,1:pc、移动端分离(存在pc、移动端两套模板)
  738. if (1 == intval($web_cmsmode)) { // 永久
  739. $path = HTML_ROOT.$val['filename'].DS;
  740. $new_filename = TCP_SCHEME.'_'.$home_lang.$home_site;
  741. if (isMobile() || $is_mobile_domain) {
  742. $new_filename .= "_mobile";
  743. } else {
  744. $new_filename .= "_pc";
  745. }
  746. $new_filename .= '_'.$filename;
  747. // $arr = explode('_', $filename);
  748. // $id = end($arr);
  749. // $new_filename = preg_replace('/^(.*)\_([^\_]+)$/i', '${1}', $new_filename);
  750. // $filename = md5($new_filename).'_'.$id;
  751. $url = request()->url();
  752. //作了序列号 详情页 不一定 唯一 只有aid参数
  753. $nurl = str_replace('/','_',$url);
  754. $domain = request()->domain();
  755. $domain = str_replace('https://','',$domain);
  756. $domain = str_replace('http://','',$domain);
  757. $ndomain = str_replace('.','_',$domain);
  758. //var_dump($nurl.$ndomain);
  759. $new_filename .= '_'.$ndomain.$nurl;
  760. $filename = preg_replace('/([^\w\-]+)/i', '', $new_filename);
  761. $filename = $path."{$filename}.html";
  762. //var_dump($filename);
  763. if(is_file($filename) && file_exists($filename))
  764. {
  765. echo file_get_contents($filename);
  766. exit();
  767. }
  768. } else {
  769. $path = HTML_PATH.$val['filename'].DS.$home_lang.DS.trim($home_site, '_');
  770. if (isMobile()) {
  771. $path .= "_mobile";
  772. } else {
  773. $path .= "_pc";
  774. }
  775. $path .= '_cache'.DS;
  776. $web_htmlcache_expires_in = config('tpcache.web_htmlcache_expires_in');
  777. $options = array(
  778. 'path' => $path,
  779. 'expire'=> intval($web_htmlcache_expires_in),
  780. 'prefix' => $cache_tag,
  781. );
  782. $html = html_cache($filename, '', $options);
  783. // $html = $html_cache->get($filename);
  784. if($html)
  785. {
  786. echo $html;
  787. exit();
  788. }
  789. }
  790. }
  791. }
  792. }
  793. }
  794. if (!function_exists('is_local_images'))
  795. {
  796. /**
  797. * 判断远程链接是否属于本地图片,并返回本地图片路径
  798. *
  799. * @param string $pic_url 图片地址
  800. * @param boolean $returnbool 返回类型,false 返回图片路径,true 返回布尔值
  801. */
  802. function is_local_images($pic_url = '', $returnbool = false)
  803. {
  804. if (stristr($pic_url, '//'.request()->host().'/')) {
  805. $picPath = parse_url($pic_url, PHP_URL_PATH);
  806. $picPath = preg_replace('#^(/[/\w\-]+)?(/public/upload/|/public/static/|/uploads/|/weapp/)#i', '$2', $picPath);
  807. if (!empty($picPath) && file_exists('.'.$picPath)) {
  808. $pic_url = ROOT_DIR.$picPath;
  809. if (true == $returnbool) {
  810. return $pic_url;
  811. }
  812. }
  813. }
  814. if (true == $returnbool) {
  815. return false;
  816. } else {
  817. return $pic_url;
  818. }
  819. }
  820. }
  821. if (!function_exists('get_head_pic'))
  822. {
  823. /**
  824. * 默认头像
  825. */
  826. function get_head_pic($pic_url = '', $is_admin = false, $sex = '保密')
  827. {
  828. if ($is_admin) {
  829. $default_pic = ROOT_DIR . '/public/static/admin/images/admint.png';
  830. } else {
  831. if ($sex == '女') {
  832. $default_pic = ROOT_DIR . '/public/static/common/images/dfgirl.png';
  833. } else {
  834. $default_pic = ROOT_DIR . '/public/static/common/images/dfboy.png';
  835. }
  836. }
  837. if (empty($pic_url)) {
  838. $pic_url = $default_pic;
  839. } else if (!is_http_url($pic_url)) {
  840. $pic_url = handle_subdir_pic($pic_url);
  841. } else if (is_http_url($pic_url)) {
  842. $pic_url = str_ireplace(['http://thirdqq.qlogo.cn','http://qzapp.qlogo.cn'], ['https://thirdqq.qlogo.cn','https://qzapp.qlogo.cn'], $pic_url);
  843. }
  844. return $pic_url;
  845. }
  846. }
  847. if (!function_exists('get_absolute_url'))
  848. {
  849. /*
  850. * 本站url转为绝对链接
  851. * $is_absolute 是否无论开启都转换为绝对路径
  852. */
  853. function get_absolute_url($str, $type = 'default',$is_absolute = false)
  854. {
  855. if (!is_http_url($str)) {
  856. static $absolute_path_open = null;
  857. if ($is_absolute){
  858. $absolute_path_open = true;
  859. }else{
  860. null === $absolute_path_open && $absolute_path_open = tpCache('web.absolute_path_open'); //是否开启绝对链接
  861. }
  862. if (!empty($absolute_path_open)) {
  863. static $domain = null;
  864. if (null == $domain) {
  865. $domain = preg_replace('/^(([^\:]+):)?(\/\/)?([^\/\:]*)(.*)$/i', '${1}${3}${4}', request()->domain());
  866. }
  867. $root_dir = $domain.ROOT_DIR;
  868. switch ($type) {
  869. case 'html':
  870. $str = preg_replace('#(.*)(\#39;|&quot;|"|\')(/[/\w\-]+)?(/public/upload/|/public/plugins|/public/static/|/uploads/)(.*)#iU', '$1$2'.$root_dir.'$4$5', $str);
  871. break;
  872. case 'url':
  873. $str = $domain.$str;
  874. break;
  875. default:
  876. if (preg_match('#^(/[/\w\-]+)?(/public/(upload|plugins|static)/|/uploads/|/weapp/)#i', $str)) {
  877. $str = preg_replace('#^(/[/\w\-]+)?(/public/(upload|plugins|static)/|/uploads/|/weapp/)#i', $root_dir.'$2', $str);
  878. } else {
  879. $str = $domain.$str;
  880. }
  881. break;
  882. }
  883. }
  884. }
  885. return $str;
  886. }
  887. }
  888. if (!function_exists('get_default_pic'))
  889. {
  890. /**
  891. * 图片不存在,显示默认无图封面
  892. * @param string $pic_url 图片路径
  893. * @param string|boolean $domain 完整路径的域名
  894. */
  895. function get_default_pic($pic_url = '', $domain = false)
  896. {
  897. if (is_http_url($pic_url)) {
  898. $pic_url = handle_subdir_pic($pic_url, 'img', $domain);
  899. }
  900. if (!is_http_url($pic_url)) {
  901. if (!$domain){
  902. static $absolute_path_open = null;
  903. null === $absolute_path_open && $absolute_path_open = tpCache('web.absolute_path_open'); //是否开启绝对链接
  904. if ($absolute_path_open && request()->module() != 'admin'){
  905. $domain = true;
  906. }
  907. }
  908. if (true === $domain) {
  909. $domain = request()->domain();
  910. } else if (false === $domain) {
  911. $domain = '';
  912. }
  913. $pic_url = preg_replace('#^(/[/\w\-]+)?(/public/upload/|/public/static/|/uploads/|/weapp/)#i', '$2', $pic_url); // 支持子目录
  914. $realpath = realpath(ROOT_PATH.trim($pic_url, '/'));
  915. if ( is_file($realpath) && file_exists($realpath) ) {
  916. $pic_url = $domain . ROOT_DIR . $pic_url;
  917. } else {
  918. $pic_url = $domain . ROOT_DIR . '/public/static/common/images/not_adv.jpg';
  919. }
  920. }
  921. return $pic_url;
  922. }
  923. }
  924. if (!function_exists('handle_subdir_pic'))
  925. {
  926. /**
  927. * 处理子目录与根目录的图片平缓切换
  928. * @param string $str 图片路径或html代码
  929. */
  930. function handle_subdir_pic($str = '', $type = 'img', $domain = false, $clear_root_dir = false)
  931. {
  932. static $request = null;
  933. if (null === $request) {
  934. $request = \think\Request::instance();
  935. }
  936. $root_dir = $add_root_dir = ROOT_DIR;
  937. if ($clear_root_dir == true && $domain == false) {
  938. $add_root_dir = '';
  939. }else{
  940. static $absolute_path_open = null;
  941. null === $absolute_path_open && $absolute_path_open = tpCache('web.absolute_path_open'); //是否开启绝对链接
  942. if ($absolute_path_open && $request->module() != 'admin'){
  943. $add_root_dir = $request->domain().$add_root_dir;
  944. $domain = false;
  945. }
  946. }
  947. switch ($type) {
  948. case 'img':
  949. if (!is_http_url($str) && !empty($str)) {
  950. $str = preg_replace('#^(/[/\w\-]+)?(/public/upload/|/public/static/|/uploads/|/weapp/)#i', $add_root_dir.'$2', $str);
  951. }else if (is_http_url($str) && !empty($str)) {
  952. $StrData = parse_url($str);
  953. if (empty($StrData['scheme']) && $request->host(true) != $StrData['host']) {
  954. $StrData['path'] = preg_replace('#^(/[/\w\-]+)?(/public/upload/|/uploads/|/public/static/)#i', '$2', $StrData['path']);
  955. if (preg_match('#^(/public/upload/|/public/static/|/uploads/|/weapp/)#i', $StrData['path']) && file_exists('.'.$StrData['path'])) {
  956. // 插件列表
  957. static $weappList = null;
  958. if (null == $weappList) {
  959. $weappList = \think\Db::name('weapp')->where([
  960. 'status' => 1,
  961. ])->cache(true, EYOUCMS_CACHE_TIME, 'weapp')
  962. ->getAllWithIndex('code');
  963. }
  964. if (!empty($weappList['Qiniuyun']) && 1 == $weappList['Qiniuyun']['status']) {
  965. $qnyData = json_decode($weappList['Qiniuyun']['data'], true);
  966. $weappConfig = json_decode($weappList['Qiniuyun']['config'], true);
  967. if (!empty($weappConfig['version']) && 'v1.0.6' <= $weappConfig['version']) {
  968. $qiniuyunModel = new \weapp\Qiniuyun\model\QiniuyunModel;
  969. $str = $qiniuyunModel->handle_subdir_pic($qnyData, $StrData, $str);
  970. } else {
  971. if ($qnyData['domain'] == $StrData['host']) {
  972. $tcp = !empty($qnyData['tcp']) ? $qnyData['tcp'] : '';
  973. switch ($tcp) {
  974. case '2':
  975. $tcp = 'https://';
  976. break;
  977. case '3':
  978. $tcp = '//';
  979. break;
  980. case '1':
  981. default:
  982. $tcp = 'http://';
  983. break;
  984. }
  985. $str = $tcp.$qnyData['domain'].$StrData['path'];
  986. }else{
  987. // 若切换了存储空间或访问域名,与数据库中存储的图片路径域名不一致时,访问本地路径,保证图片正常
  988. $str = $add_root_dir.$StrData['path'];
  989. }
  990. }
  991. }
  992. else if (!empty($weappList['AliyunOss']) && 1 == $weappList['AliyunOss']['status']) {
  993. $ossData = json_decode($weappList['AliyunOss']['data'], true);
  994. $aliyunOssModel = new \weapp\AliyunOss\model\AliyunOssModel;
  995. $str = $aliyunOssModel->handle_subdir_pic($ossData, $StrData, $str);
  996. }
  997. else if (!empty($weappList['Cos']) && 1 == $weappList['Cos']['status']) {
  998. $cosData = json_decode($weappList['Cos']['data'], true);
  999. $cosModel = new \weapp\Cos\model\CosModel;
  1000. $str = $cosModel->handle_subdir_pic($cosData, $StrData, $str);
  1001. }
  1002. else {
  1003. // 关闭
  1004. $str = $add_root_dir.$StrData['path'];
  1005. }
  1006. } else {
  1007. $str = preg_replace('/^\/\//i', $request->scheme().'://', $str);
  1008. }
  1009. }
  1010. }
  1011. break;
  1012. case 'html':
  1013. preg_match_all('/(\&lt\;|\<)img.*(\/)?(\>|\&gt\;)/iUs', $str, $imginfo);//摘出图片
  1014. $imgArr = empty($imginfo[0]) ? [] : $imginfo[0];
  1015. if (!empty($imgArr)) {
  1016. foreach ($imgArr as $key => $value) {
  1017. preg_match_all("#src=('|\")(.*)('|\")#isU", $value, $img_val);
  1018. if (isset($img_val[2][0]) && !is_http_url($img_val[2][0])) { // 是否本地图片
  1019. $handle_img = preg_replace('#(/[/\w\-]+)?(/public/upload/|/public/static/|/uploads/|/weapp/)#i', $add_root_dir.'$2', $value);
  1020. $str = str_ireplace($value, $handle_img, $str);
  1021. }
  1022. }
  1023. }
  1024. // $str = preg_replace('#(.*)(\#39;|&quot;|"|\')(/[/\w\-]+)?(/public/upload/|/public/plugins/|/uploads/)(.*)#iU', '$1$2'.$add_root_dir.'$4$5', $str);
  1025. break;
  1026. case 'soft':
  1027. if (!is_http_url($str) && !empty($str)) {
  1028. $str = preg_replace('#^(/[/\w\-]+)?(/public/upload/soft/|/uploads/soft/)#i', $add_root_dir.'$2', $str);
  1029. } else if (is_http_url($str) && !empty($str)) {
  1030. $StrData = parse_url($str);
  1031. $StrData['path'] = preg_replace('#^(/[/\w\-]+)?(/public/upload/soft/|/uploads/soft/)#i', '$2', $StrData['path']);
  1032. if ($request->host(true) != $StrData['host'] && preg_match('#^(/public/upload/soft/|/uploads/soft/)#i', $StrData['path'])) {
  1033. // 插件列表
  1034. static $weappList = null;
  1035. if (null == $weappList) {
  1036. $weappList = \think\Db::name('weapp')->where([
  1037. 'status' => 1,
  1038. ])->cache(true, EYOUCMS_CACHE_TIME, 'weapp')
  1039. ->getAllWithIndex('code');
  1040. }
  1041. if (!empty($weappList['Qiniuyun']) && 1 == $weappList['Qiniuyun']['status']) {
  1042. $qnyData = json_decode($weappList['Qiniuyun']['data'], true);
  1043. $weappConfig = json_decode($weappList['Qiniuyun']['config'], true);
  1044. if (!empty($weappConfig['version']) && 'v1.0.6' <= $weappConfig['version']) {
  1045. $qiniuyunModel = new \weapp\Qiniuyun\model\QiniuyunModel;
  1046. $str = $qiniuyunModel->handle_subdir_pic($qnyData, $StrData, $str);
  1047. } else {
  1048. if ($qnyData['domain'] == $StrData['host']) {
  1049. $tcp = !empty($qnyData['tcp']) ? $qnyData['tcp'] : '';
  1050. switch ($tcp) {
  1051. case '2':
  1052. $tcp = 'https://';
  1053. break;
  1054. case '3':
  1055. $tcp = '//';
  1056. break;
  1057. case '1':
  1058. default:
  1059. $tcp = 'http://';
  1060. break;
  1061. }
  1062. $str = $tcp.$qnyData['domain'].$StrData['path'];
  1063. }else{
  1064. // 若切换了存储空间或访问域名,与数据库中存储的图片路径域名不一致时,访问本地路径,保证图片正常
  1065. if (file_exists('.'.$StrData['path'])) {
  1066. $str = $add_root_dir.$StrData['path'];
  1067. }
  1068. }
  1069. }
  1070. }
  1071. else if (!empty($weappList['AliyunOss']) && 1 == $weappList['AliyunOss']['status']) {
  1072. $ossData = json_decode($weappList['AliyunOss']['data'], true);
  1073. $aliyunOssModel = new \weapp\AliyunOss\model\AliyunOssModel;
  1074. $str = $aliyunOssModel->handle_subdir_pic($ossData, $StrData, $str);
  1075. }
  1076. else if (!empty($weappList['Cos']) && 1 == $weappList['Cos']['status']) {
  1077. $cosData = json_decode($weappList['Cos']['data'], true);
  1078. $cosModel = new \weapp\Cos\model\CosModel;
  1079. $str = $cosModel->handle_subdir_pic($cosData, $StrData, $str);
  1080. }
  1081. }
  1082. }
  1083. break;
  1084. case 'media': //多媒体文件
  1085. if (!is_http_url($str) && !empty($str)) {
  1086. $str = preg_replace('#^(/[/\w\-]+)?(/uploads/media/)#i', $add_root_dir.'$2', $str);
  1087. }
  1088. break;
  1089. default:
  1090. # code...
  1091. break;
  1092. }
  1093. if (!empty($str) && !is_http_url($str)) {
  1094. if (false !== $domain) {
  1095. if (true === $domain) {
  1096. static $domain_new = null;
  1097. if (null === $domain_new) {
  1098. $domain_new = $request->domain();
  1099. }
  1100. $domain = $domain_new;
  1101. }
  1102. $str = $domain.$str;
  1103. }
  1104. }
  1105. return $str;
  1106. }
  1107. }
  1108. /**
  1109. * 获取阅读权限
  1110. */
  1111. if ( ! function_exists('get_arcrank_list'))
  1112. {
  1113. function get_arcrank_list()
  1114. {
  1115. $result = \think\Db::name('arcrank')->where([
  1116. 'lang' => get_admin_lang(),
  1117. ])
  1118. ->order('id asc')
  1119. ->cache(true, EYOUCMS_CACHE_TIME, "arcrank")
  1120. ->getAllWithIndex('rank');
  1121. // 等级分类
  1122. $LevelData = \think\Db::name('users_level')->field('level_name as `name`, level_value as `rank`')->order('level_value asc, level_id asc')->cache(true, EYOUCMS_CACHE_TIME, "users_level")->select();
  1123. if (!empty($LevelData)) {
  1124. $result = array_merge($result, $LevelData);
  1125. }
  1126. return $result;
  1127. }
  1128. }
  1129. if (!function_exists('thumb_img'))
  1130. {
  1131. /**
  1132. * 缩略图 从原始图来处理出来
  1133. * @param type $original_img 图片路径
  1134. * @param type $width 生成缩略图的宽度
  1135. * @param type $height 生成缩略图的高度
  1136. * @param type $thumb_mode 生成方式
  1137. */
  1138. function thumb_img($original_img = '', $width = '', $height = '', $thumb_mode = '')
  1139. {
  1140. // 缩略图配置
  1141. static $thumbConfig = null;
  1142. if (null === $thumbConfig) {
  1143. @ini_set('memory_limit', '-1'); // 内存不限制,防止图片大小过大,导致缩略图处理失败,网站打不开
  1144. $thumbConfig = tpCache('thumb');
  1145. }
  1146. $thumbextra = config('global.thumb');
  1147. if (!empty($width) || !empty($height) || !empty($thumb_mode)) { // 单独在模板里调用,不受缩略图全局开关影响
  1148. } else { // 非单独模板调用,比如内置的arclist\list标签里
  1149. if (empty($thumbConfig['thumb_open'])) {
  1150. return $original_img;
  1151. }
  1152. }
  1153. // 缩略图优先级别高于七牛云,自动把七牛云的图片路径转为本地图片路径,并且进行缩略图
  1154. $original_img = is_local_images($original_img);
  1155. // 未开启缩略图,或远程图片
  1156. if (is_http_url($original_img)) {
  1157. return $original_img;
  1158. } else if (empty($original_img)) {
  1159. return ROOT_DIR.'/public/static/common/images/not_adv.jpg';
  1160. }
  1161. // 图片文件名
  1162. $filename = '';
  1163. $imgArr = explode('/', $original_img);
  1164. $imgArr = end($imgArr);
  1165. $filename = preg_replace("/\.([^\.]+)$/i", "", $imgArr);
  1166. $file_ext = preg_replace("/^(.*)\.([^\.]+)$/i", "$2", $imgArr);
  1167. // 如果图片参数是缩略图,则直接获取到原图,并进行缩略处理
  1168. if (preg_match('/\/uploads\/thumb\/\d{1,}_\d{1,}\//i', $original_img)) {
  1169. $pattern = UPLOAD_PATH.'allimg/*/'.$filename;
  1170. if (in_array(strtolower($file_ext), ['jpg','jpeg'])) {
  1171. $pattern .= '.jp*g';
  1172. } else {
  1173. $pattern .= '.'.$file_ext;
  1174. }
  1175. $original_img_tmp = glob($pattern);
  1176. if (!empty($original_img_tmp)) {
  1177. $original_img = '/'.current($original_img_tmp);
  1178. }
  1179. } else {
  1180. if ('bmp' == $file_ext && version_compare(PHP_VERSION,'7.2.0','<')) {
  1181. return $original_img;
  1182. }
  1183. }
  1184. // --end
  1185. // $original_img1 = preg_replace('#^'.ROOT_DIR.'#i', '', handle_subdir_pic($original_img));
  1186. $original_img1 = preg_replace('#^'.ROOT_DIR.'#i', '', handle_subdir_pic($original_img, 'img',false,true));
  1187. $original_img1 = '.' . $original_img1; // 相对路径
  1188. //获取图像信息
  1189. $info = @getimagesize($original_img1);
  1190. //检测图像合法性
  1191. if (false === $info || (IMAGETYPE_GIF === $info[2] && empty($info['bits']))) {
  1192. return $original_img;
  1193. } else {
  1194. if (!empty($info['mime']) && stristr($info['mime'], 'bmp') && version_compare(PHP_VERSION,'7.2.0','<')) {
  1195. return $original_img;
  1196. }
  1197. }
  1198. // 缩略图宽高度
  1199. $is_auto_mode = 0;
  1200. if (empty($width)) {
  1201. if (is_numeric($thumbConfig['thumb_width']) && 0 == $thumbConfig['thumb_width']) {
  1202. $width = !empty($info[0]) ? $info[0] : 1000000;
  1203. $is_auto_mode = 1;
  1204. } else {
  1205. $width = !empty($thumbConfig['thumb_width']) ? $thumbConfig['thumb_width'] : $thumbextra['width'];
  1206. }
  1207. }
  1208. if (empty($height)) {
  1209. if (is_numeric($thumbConfig['thumb_height']) && 0 == $thumbConfig['thumb_height']) {
  1210. $height = !empty($info[0]) ? $info[0] : 1000000;
  1211. $is_auto_mode = 1;
  1212. } else {
  1213. $height = !empty($thumbConfig['thumb_height']) ? $thumbConfig['thumb_height'] : $thumbextra['height'];
  1214. }
  1215. }
  1216. $width = intval($width);
  1217. $height = intval($height);
  1218. //判断缩略图是否存在
  1219. $path = UPLOAD_PATH."thumb/{$width}_{$height}/";
  1220. $img_thumb_name = "{$filename}";
  1221. // 已经生成过这个比例的图片就直接返回了
  1222. if (is_file($path . $img_thumb_name . '.jpg')) return get_absolute_url(ROOT_DIR.'/' . $path . $img_thumb_name . '.jpg');
  1223. if (is_file($path . $img_thumb_name . '.jpeg')) return get_absolute_url(ROOT_DIR.'/' . $path . $img_thumb_name . '.jpeg');
  1224. if (is_file($path . $img_thumb_name . '.gif')) return get_absolute_url(ROOT_DIR.'/' . $path . $img_thumb_name . '.gif');
  1225. if (is_file($path . $img_thumb_name . '.png')) return get_absolute_url(ROOT_DIR.'/' . $path . $img_thumb_name . '.png');
  1226. if (is_file($path . $img_thumb_name . '.bmp')) return get_absolute_url(ROOT_DIR.'/' . $path . $img_thumb_name . '.bmp');
  1227. if (is_file($path . $img_thumb_name . '.webp')) return get_absolute_url(ROOT_DIR.'/' . $path . $img_thumb_name . '.webp');
  1228. if (!is_file($original_img1)) {
  1229. return get_absolute_url(ROOT_DIR.'/public/static/common/images/not_adv.jpg');
  1230. }
  1231. try {
  1232. vendor('topthink.think-image.src.Image');
  1233. vendor('topthink.think-image.src.image.Exception');
  1234. if(stristr($original_img1,'.gif'))
  1235. {
  1236. vendor('topthink.think-image.src.image.gif.Encoder');
  1237. vendor('topthink.think-image.src.image.gif.Decoder');
  1238. vendor('topthink.think-image.src.image.gif.Gif');
  1239. }
  1240. $image = \think\Image::open($original_img1);
  1241. $img_thumb_name = $img_thumb_name . '.' . $image->type();
  1242. // 生成缩略图
  1243. !is_dir($path) && mkdir($path, 0777, true);
  1244. // 填充颜色
  1245. $thumb_color = !empty($thumbConfig['thumb_color']) ? $thumbConfig['thumb_color'] : $thumbextra['color'];
  1246. // 生成方式参考 vendor/topthink/think-image/src/Image.php
  1247. if (!empty($thumb_mode)) {
  1248. $thumb_mode = intval($thumb_mode);
  1249. } else {
  1250. $thumb_mode = !empty($thumbConfig['thumb_mode']) ? $thumbConfig['thumb_mode'] : $thumbextra['mode'];
  1251. }
  1252. if (1 == $is_auto_mode) {
  1253. $thumb_mode = 1;
  1254. } else {
  1255. 1 == $thumb_mode && $thumb_mode = 6; // 按照固定比例拉伸
  1256. 2 == $thumb_mode && $thumb_mode = 2; // 填充空白
  1257. if (3 == $thumb_mode) {
  1258. $img_width = $image->width();
  1259. $img_height = $image->height();
  1260. if ($width < $img_width && $height < $img_height) {
  1261. // 先进行缩略图等比例缩放类型,取出宽高中最小的属性值
  1262. $min_width = ($img_width < $img_height) ? $img_width : 0;
  1263. $min_height = ($img_width > $img_height) ? $img_height : 0;
  1264. if ($min_width > $width || $min_height > $height) {
  1265. if (0 < intval($min_width)) {
  1266. $scale = $min_width / min($width, $height);
  1267. } else if (0 < intval($min_height)) {
  1268. $scale = $min_height / $height;
  1269. } else {
  1270. $scale = $min_width / $width;
  1271. }
  1272. $s_width = $img_width / $scale;
  1273. $s_height = $img_height / $scale;
  1274. $image->thumb($s_width, $s_height, 1, $thumb_color)->save($path . $img_thumb_name, NULL, 100); //按照原图的比例生成一个最大为$width*$height的缩略图并保存
  1275. }
  1276. }
  1277. $thumb_mode = 3; // 截减
  1278. }
  1279. }
  1280. // 参考文章 http://www.mb5u.com/biancheng/php/php_84533.html 改动参考 http://www.thinkphp.cn/topic/13542.html
  1281. $image->thumb($width, $height, $thumb_mode, $thumb_color)->save($path . $img_thumb_name, NULL, 100); //按照原图的比例生成一个最大为$width*$height的缩略图并保存
  1282. //图片水印处理
  1283. $water = tpCache('water');
  1284. if($water['is_mark']==1 && $water['is_thumb_mark'] == 1 && $image->width()>$water['mark_width'] && $image->height()>$water['mark_height']){
  1285. $imgresource = './' . $path . $img_thumb_name;
  1286. if($water['mark_type'] == 'text'){
  1287. //$image->text($water['mark_txt'],ROOT_PATH.'public/static/common/font/hgzb.ttf',20,'#000000',9)->save($imgresource);
  1288. $ttf = ROOT_PATH.'public/static/common/font/hgzb.ttf';
  1289. if (file_exists($ttf)) {
  1290. $size = $water['mark_txt_size'] ? $water['mark_txt_size'] : 30;
  1291. $color = $water['mark_txt_color'] ?: '#000000';
  1292. if (!preg_match('/^#[0-9a-fA-F]{6}$/', $color)) {
  1293. $color = '#000000';
  1294. }
  1295. $transparency = intval((100 - $water['mark_degree']) * (127/100));
  1296. $color .= dechex($transparency);
  1297. $image->open($imgresource)->text($water['mark_txt'], $ttf, $size, $color, $water['mark_sel'])->save($imgresource);
  1298. $return_data['mark_txt'] = $water['mark_txt'];
  1299. }
  1300. }else{
  1301. /*支持子目录*/
  1302. $water['mark_img'] = preg_replace('#^(/[/\w\-]+)?(/public/upload/|/uploads/)#i', '$2', $water['mark_img']); // 支持子目录
  1303. /*--end*/
  1304. //$image->water(".".$water['mark_img'],9,$water['mark_degree'])->save($imgresource);
  1305. $waterPath = "." . $water['mark_img'];
  1306. if (eyPreventShell($waterPath) && file_exists($waterPath)) {
  1307. $quality = $water['mark_quality'] ? $water['mark_quality'] : 80;
  1308. $waterTempPath = dirname($waterPath).'/temp_'.basename($waterPath);
  1309. $image->open($waterPath)->save($waterTempPath, null, $quality);
  1310. $image->open($imgresource)->water($waterTempPath, $water['mark_sel'], $water['mark_degree'])->save($imgresource);
  1311. @unlink($waterTempPath);
  1312. }
  1313. }
  1314. }
  1315. $img_url = ROOT_DIR.'/' . $path . $img_thumb_name;
  1316. $img_url = get_absolute_url($img_url);
  1317. return $img_url;
  1318. } catch (think\Exception $e) {
  1319. return $original_img;
  1320. }
  1321. }
  1322. }
  1323. if (!function_exists('get_controller_byct')) {
  1324. /**
  1325. * 根据模型ID获取控制器的名称
  1326. * @return mixed
  1327. */
  1328. function get_controller_byct($current_channel)
  1329. {
  1330. $channeltype_info = model('Channeltype')->getInfo($current_channel);
  1331. return $channeltype_info['ctl_name'];
  1332. }
  1333. }
  1334. if (!function_exists('ui_read_bidden_inc')) {
  1335. /**
  1336. * 读取被禁止外部访问的配置文件
  1337. * @param string $filename 文件路径
  1338. * @return mixed
  1339. */
  1340. function ui_read_bidden_inc($filename)
  1341. {
  1342. $data = false;
  1343. if (file_exists($filename)) {
  1344. $data = @file($filename);
  1345. $data = json_decode($data[1], true);
  1346. }
  1347. if (empty($data)) {
  1348. // -------------优先读取配置文件,不存在才读取数据表
  1349. $params = explode('/', $filename);
  1350. $page = $params[count($params) - 1];
  1351. $pagearr = explode('.', $page);
  1352. reset($pagearr);
  1353. $page = current($pagearr);
  1354. $map = array(
  1355. 'page' => $page,
  1356. 'theme_style' => THEME_STYLE_PATH,
  1357. );
  1358. $result = M('ui_config')->where($map)->cache(true,EYOUCMS_CACHE_TIME,"ui_config")->select();
  1359. if ($result) {
  1360. $dataArr = array();
  1361. foreach ($result as $key => $val) {
  1362. $k = "{$val['lang']}_{$val['type']}_{$val['name']}";
  1363. $dataArr[$k] = $val['value'];
  1364. }
  1365. $data = $dataArr;
  1366. } else {
  1367. $data = false;
  1368. }
  1369. //---------------end
  1370. if (!empty($data)) {
  1371. // ----------文件不存在,并写入文件缓存
  1372. tp_mkdir(dirname($filename));
  1373. $nowData = $data;
  1374. $setting = "<?php die('forbidden'); ?>\n";
  1375. $setting .= json_encode($nowData);
  1376. $setting = str_replace("\/", "/",$setting);
  1377. $incFile = fopen($filename, "w+");
  1378. if ($incFile != false && fwrite($incFile, $setting)) {
  1379. fclose($incFile);
  1380. }
  1381. //---------------end
  1382. }
  1383. }
  1384. return $data;
  1385. }
  1386. }
  1387. if (!function_exists('ui_write_bidden_inc')) {
  1388. /**
  1389. * 写入被禁止外部访问的配置文件
  1390. * @param array $arr 配置变量
  1391. * @param string $filename 文件路径
  1392. * @param bool $is_append false
  1393. * @return mixed
  1394. */
  1395. function ui_write_bidden_inc($data, $filename, $is_append = false)
  1396. {
  1397. $data2 = $data;
  1398. if (!empty($filename)) {
  1399. // -------------写入数据表,同时写入配置文件
  1400. reset($data2);
  1401. $value = current($data2);
  1402. $tmp_val = json_decode($value, true);
  1403. $name = $tmp_val['id'];
  1404. $type = $tmp_val['type'];
  1405. $page = $tmp_val['page'];
  1406. $lang = !empty($tmp_val['lang']) ? $tmp_val['lang'] : cookie(config('global.home_lang'));
  1407. $idcode = $tmp_val['idcode'];
  1408. if (empty($lang)) {
  1409. $lang = model('language')->order('id asc')
  1410. ->limit(1)
  1411. ->cache(true, EYOUCMS_CACHE_TIME, 'language')
  1412. ->getField('mark');
  1413. }
  1414. $theme_style = THEME_STYLE_PATH;
  1415. $md5key = md5($name.$page.$theme_style.$lang);
  1416. $savedata = array(
  1417. 'md5key' => $md5key,
  1418. 'theme_style' => $theme_style,
  1419. 'page' => $page,
  1420. 'type' => $type,
  1421. 'name' => $name,
  1422. 'value' => $value,
  1423. 'lang' => $lang,
  1424. 'idcode'=> $idcode,
  1425. );
  1426. $map = array(
  1427. 'name' => $name,
  1428. 'page' => $page,
  1429. 'theme_style' => $theme_style,
  1430. 'lang' => $lang,
  1431. );
  1432. $count = M('ui_config')->where($map)->count('id');
  1433. if ($count > 0) {
  1434. $savedata['update_time'] = getTime();
  1435. $r = M('ui_config')->where($map)->cache(true,EYOUCMS_CACHE_TIME,'ui_config')->update($savedata);
  1436. } else {
  1437. $savedata['add_time'] = getTime();
  1438. $savedata['update_time'] = getTime();
  1439. $r = M('ui_config')->insert($savedata);
  1440. \think\Cache::clear('ui_config');
  1441. }
  1442. if ($r) {
  1443. // ----------同时写入文件缓存
  1444. tp_mkdir(dirname($filename));
  1445. // 追加
  1446. if ($is_append) {
  1447. $inc = ui_read_bidden_inc($filename);
  1448. if ($inc) {
  1449. $oldarr = (array)$inc;
  1450. $data = array_merge($oldarr, $data);
  1451. }
  1452. }
  1453. $setting = "<?php die('forbidden'); ?>\n";
  1454. $setting .= json_encode($data);
  1455. $setting = str_replace("\/", "/",$setting);
  1456. $incFile = fopen($filename, "w+");
  1457. if ($incFile != false && fwrite($incFile, $setting)) {
  1458. fclose($incFile);
  1459. }
  1460. //---------------end
  1461. return true;
  1462. }
  1463. }
  1464. return false;
  1465. }
  1466. }
  1467. if (!function_exists('get_ui_inc_params')) {
  1468. /**
  1469. * 获取模板主题的美化配置参数
  1470. * @return mixed
  1471. */
  1472. function get_ui_inc_params($page)
  1473. {
  1474. $e_page = $page;
  1475. $filename = RUNTIME_PATH.'ui/'.THEME_STYLE_PATH.'/'.$e_page.'.inc.php';
  1476. $inc = ui_read_bidden_inc($filename);
  1477. return $inc;
  1478. }
  1479. }
  1480. if (!function_exists('allow_release_arctype'))
  1481. {
  1482. /**
  1483. * 允许发布文档的栏目列表
  1484. */
  1485. function allow_release_arctype($selected = 0, $allow_release_channel = array(), $selectform = true, $release_typeids = [],$users_release = false,$catid = 0)
  1486. {
  1487. //->where('a.area_id', '=', (int)$cat['area_id'])
  1488. $release_typeids_pre = [];
  1489. if ($users_release){
  1490. $release_typeids_pre = $release_typeids;
  1491. $topids = Db::name('arctype')->where([
  1492. 'id' => ['IN', $release_typeids],
  1493. 'topid' => ['gt', 0],
  1494. 'lang' => get_current_lang(),
  1495. ])->column('topid');
  1496. $topid_arr = Db::name('arctype')->where([
  1497. 'topid|id' => ['IN', $topids],
  1498. 'lang' => get_current_lang(),
  1499. ])->column('id');
  1500. $release_typeids = array_merge($release_typeids,$topid_arr);
  1501. }
  1502. $where = [];
  1503. $where['c.weapp_code'] = ''; // 回收站功能
  1504. $where['c.lang'] = get_current_lang(); // 多语言 by 小虎哥
  1505. $where['c.is_del'] = 0; // 回收站功能
  1506. $current_channel = [51];
  1507. $php_servicemeal = tpCache('php.php_servicemeal');
  1508. if (1.5 > $php_servicemeal) {
  1509. array_push($current_channel, 5);
  1510. }
  1511. $current_channel_str = implode(',', $current_channel);
  1512. $where['c.current_channel'] = ['notin', $current_channel];
  1513. /*权限控制 by 小虎哥*/
  1514. $admin_info = session('admin_info');
  1515. if (0 < intval($admin_info['role_id'])) {
  1516. $auth_role_info = $admin_info['auth_role_info'];
  1517. if(! empty($auth_role_info)){
  1518. if(! empty($auth_role_info['permission']['arctype'])){
  1519. $where['c.id'] = array('IN', $auth_role_info['permission']['arctype']);
  1520. }
  1521. }
  1522. }
  1523. /*--end*/
  1524. // 查询会员投稿指定的栏目
  1525. if (!empty($release_typeids)) $where['c.id'] = ['IN', $release_typeids];
  1526. // 默认选中的栏目
  1527. if (!is_array($selected)) $selected = [$selected];
  1528. $cacheKey = md5(json_encode($selected).json_encode($allow_release_channel).$selectform.json_encode($where));
  1529. $select_html = cache($cacheKey);
  1530. if (empty($select_html) || false == $selectform) {
  1531. /*允许发布文档的模型*/
  1532. $allow_release_channel = !empty($allow_release_channel) ? $allow_release_channel : config('global.allow_release_channel');
  1533. /*所有栏目分类*/
  1534. $where['c.status'] = 1;
  1535. $fields = "c.id, c.parent_id, c.current_channel, c.typename, c.grade, '' as children";
  1536. //存在区域
  1537. if((int)$catid > 0){
  1538. $where1 = [
  1539. 'c.area_id' => (int)$catid,
  1540. 'c.is_del' => 0,
  1541. ];
  1542. $res = $res2 = \think\Db::name('arctype')
  1543. ->field($fields)
  1544. ->alias('c')
  1545. ->where($where)
  1546. ->where('c.topid','<>',38)
  1547. ->whereOr(function($query) use ($where1){
  1548. $query->where($where1);
  1549. }) //whereOr闭包组合
  1550. ->order('c.parent_id asc, c.sort_order asc, c.id asc')
  1551. //->cache(true,EYOUCMS_CACHE_TIME,"arctype") //关闭缓存 whereOR 二选一
  1552. ->select();
  1553. }else{
  1554. $res = $res2 = \think\Db::name('arctype')
  1555. ->field($fields)
  1556. ->alias('c')
  1557. ->where($where)
  1558. ->order('c.parent_id asc, c.sort_order asc, c.id asc')
  1559. ->cache(true,EYOUCMS_CACHE_TIME,"arctype")
  1560. ->select();
  1561. }
  1562. /*--end*/
  1563. if (empty($res)) {
  1564. return '';
  1565. }
  1566. // 汇总每个栏目下的一级子栏目数量
  1567. $arctypeSublist = [];
  1568. foreach ($res as $key => $val) {
  1569. if (!empty($val['parent_id'])) {
  1570. $arctypeSublist[$val['parent_id']][] = $val['id'];
  1571. }
  1572. }
  1573. $grade_arr = [];
  1574. $i = 0;
  1575. foreach ($res as $key=>$val) {
  1576. $res[$key]['has_children'] = $res2[$key]['has_children'] = !empty($arctypeSublist[$val['id']]) ? count($arctypeSublist[$val['id']]) : 0;
  1577. $grade_arr[] = $val['grade']; // 用一个空数组来承接字段
  1578. $res2[$key]['new_sort_order'] = $i++; // 标记新的排序号
  1579. }
  1580. $max_grade = max($grade_arr); // 取最大的层级
  1581. array_multisort($grade_arr, SORT_DESC, SORT_NUMERIC, $res2); // 按层级排序,从大到小
  1582. $res3 = $new_sort_order_arr = [];
  1583. foreach ($res2 as $key=>$val) {
  1584. $res3[$val['id']] = $val;
  1585. $new_sort_order_arr[$val['id']] = $val['new_sort_order'];
  1586. }
  1587. /*过滤掉不允许发布的栏目(该栏目下包含不允许发布的栏目或没有下级)*/
  1588. for ($i=0; $i <= $max_grade; $i++) {
  1589. foreach ($res3 as $key => $val) {
  1590. if (!in_array($val['current_channel'], $allow_release_channel)) {
  1591. $tmp_val = $res3[$key];
  1592. if ( $tmp_val['has_children'] <= 0 ) {
  1593. unset($res3[$key]);
  1594. unset($new_sort_order_arr[$key]);
  1595. if (!empty($tmp_val['parent_id'])) {
  1596. if (!empty($res3[$tmp_val['parent_id']]['has_children'])) {
  1597. $res3[$tmp_val['parent_id']]['has_children'] -= 1;
  1598. }
  1599. }
  1600. }
  1601. }
  1602. }
  1603. }
  1604. /*--end*/
  1605. //只有前台会员投稿走这个判断
  1606. if ($users_release){
  1607. duplicate_removal($res3,$new_sort_order_arr,$release_typeids_pre);
  1608. if (empty($res3)){
  1609. return '';
  1610. }
  1611. }
  1612. array_multisort($new_sort_order_arr, SORT_ASC, SORT_NUMERIC, $res3); // 按设置的最新排序号,从小到大
  1613. /*所有栏目列表进行层次归类*/
  1614. $arr = group_same_key($res3, 'parent_id');
  1615. for ($i=0; $i <= $max_grade; $i++) {
  1616. foreach ($arr as $key => $val) {
  1617. foreach ($arr[$key] as $key2 => $val2) {
  1618. if (!isset($arr[$val2['id']])) {
  1619. $arr[$key][$key2]['has_children'] = 0;
  1620. continue;
  1621. }
  1622. $val2['children'] = $arr[$val2['id']];
  1623. $arr[$key][$key2] = $val2;
  1624. }
  1625. }
  1626. }
  1627. /*--end*/
  1628. $nowArr = $arr[0];
  1629. /*组装成层级下拉列表框*/
  1630. $select_html = '';
  1631. if (false == $selectform) {
  1632. $select_html = $nowArr;
  1633. } else if (true == $selectform) {
  1634. handle_arctype_data($select_html, $nowArr, $selected, $allow_release_channel,$release_typeids_pre);
  1635. cache($cacheKey, $select_html, null, 'arctype');
  1636. }
  1637. }
  1638. return $select_html;
  1639. }
  1640. }
  1641. if (!function_exists('duplicate_removal'))
  1642. {
  1643. //用于会员投稿清除下级没有选中的多余栏目
  1644. function duplicate_removal(&$data_arr = [],&$new_sort_order_arr = [],$ids = []){
  1645. $circulate = false;
  1646. foreach ($data_arr as $k => $v){
  1647. if (0 == $v['has_children'] && !in_array($v['id'],$ids)){
  1648. $circulate = true;
  1649. if (!empty($data_arr[$v['parent_id']])){
  1650. $data_arr[$v['parent_id']]['has_children'] -= 1;
  1651. }
  1652. unset($data_arr[$k]);
  1653. unset($new_sort_order_arr[$k]);
  1654. }
  1655. }
  1656. if ($circulate){
  1657. duplicate_removal($data_arr,$new_sort_order_arr,$ids);
  1658. }
  1659. }
  1660. }
  1661. if (!function_exists('handle_arctype_data'))
  1662. {
  1663. // 处理栏目数据
  1664. function handle_arctype_data(&$select_html = '', $nowArr = [], $selected = 0, $allow_release_channel = [],$release_typeids_pre = [])
  1665. {
  1666. foreach ($nowArr AS $key => $val)
  1667. {
  1668. //只有前台会员投稿走这个判断
  1669. if (!empty($release_typeids_pre) && !in_array($val['id'], $release_typeids_pre) && $val['has_children'] == 0){
  1670. continue;
  1671. }
  1672. $select_html .= '<option value="' . $val['id'] . '" data-grade="' . $val['grade'] . '" data-current_channel="' . $val['current_channel'] . '"';
  1673. $select_html .= (in_array($val['id'], $selected)) ? ' selected="true"' : '';
  1674. if ((!empty($allow_release_channel) && !in_array($val['current_channel'], $allow_release_channel)) || (!empty($release_typeids_pre) && !in_array($val['id'], $release_typeids_pre) ) ) {
  1675. $select_html .= ' disabled="true" style="background-color:#f5f5f5;"';
  1676. }
  1677. $select_html .= '>';
  1678. if ($val['grade'] > 0)
  1679. {
  1680. $select_html .= str_repeat('&nbsp;', $val['grade'] * 4);
  1681. }
  1682. $select_html .= htmlspecialchars_decode($val['typename']) . '</option>';
  1683. if (empty($val['children'])) {
  1684. continue;
  1685. }
  1686. handle_arctype_data($select_html, $val['children'], $selected, $allow_release_channel,$release_typeids_pre);
  1687. }
  1688. }
  1689. }
  1690. if (!function_exists('every_top_dirname_list'))
  1691. {
  1692. /**
  1693. * 获取一级栏目的目录名称
  1694. */
  1695. function every_top_dirname_list() {
  1696. $arctypeModel = new \app\common\model\Arctype();
  1697. $result = $arctypeModel->getEveryTopDirnameList();
  1698. return $result;
  1699. }
  1700. }
  1701. if (!function_exists('getalltype')){
  1702. /**
  1703. * 获取当前栏目的所有上级栏目
  1704. * $typeid 当前栏目id
  1705. * $field 需要获取的某一列的值的集合
  1706. */
  1707. function getalltype($typeid, $field = '')
  1708. {
  1709. $parent_list = model('Arctype')->getAllPid($typeid); // 获取当前栏目的所有父级栏目
  1710. if (!empty($field)){
  1711. $parent_list = get_arr_column($parent_list,$field);
  1712. }
  1713. return $parent_list;
  1714. }
  1715. }
  1716. if (!function_exists('gettoptype'))
  1717. {
  1718. /**
  1719. * 获取当前栏目的第一级栏目
  1720. */
  1721. function gettoptype($typeid, $field = 'typename')
  1722. {
  1723. $parent_list = model('Arctype')->getAllPid($typeid); // 获取当前栏目的所有父级栏目
  1724. $result = current($parent_list); // 第一级栏目
  1725. if (isset($result[$field]) && !empty($result[$field])) {
  1726. return handle_subdir_pic($result[$field]); // 支持子目录
  1727. } else {
  1728. return '';
  1729. }
  1730. }
  1731. }
  1732. if (!function_exists('getparenttype'))
  1733. {
  1734. /**
  1735. * 获取当前栏目的上级栏目
  1736. */
  1737. function getparenttype($typeid, $field = 'typename')
  1738. {
  1739. $parent_list = model('Arctype')->getAllPid($typeid); // 获取当前栏目的所有父级栏目
  1740. if (!empty($parent_list)) {
  1741. array_pop($parent_list);
  1742. }
  1743. $result = end($parent_list); // 上级栏目
  1744. if (isset($result[$field]) && !empty($result[$field])) {
  1745. return handle_subdir_pic($result[$field]); // 支持子目录
  1746. } else {
  1747. return '';
  1748. }
  1749. }
  1750. }
  1751. if (!function_exists('get_main_lang'))
  1752. {
  1753. /**
  1754. * 获取主体语言(语言列表里最早的一条)
  1755. */
  1756. function get_main_lang($is_force = false)
  1757. {
  1758. static $main_lang = null;
  1759. if (null === $main_lang || $is_force) {
  1760. $keys = 'common_get_main_lang';
  1761. $main_lang = \think\Cache::get($keys);
  1762. if ($is_force || empty($main_lang) || (!empty($main_lang) && !preg_match('/^[a-z]{2}$/i', $main_lang))) {
  1763. $main_lang = \think\Db::name('language')->order('id asc')
  1764. ->limit(1)
  1765. ->cache(true, EYOUCMS_CACHE_TIME, 'language')
  1766. ->getField('mark');
  1767. \think\Cache::set($keys, $main_lang);
  1768. }
  1769. $main_lang = preg_replace('/([^a-z])/i', '', $main_lang);
  1770. }
  1771. return $main_lang;
  1772. }
  1773. }
  1774. if (!function_exists('get_default_lang'))
  1775. {
  1776. /**
  1777. * 获取默认语言
  1778. */
  1779. function get_default_lang($is_force = false)
  1780. {
  1781. static $default_lang = null;
  1782. if (null === $default_lang || $is_force) {
  1783. $request = \think\Request::instance();
  1784. if (!stristr($request->baseFile(), 'index.php')) {
  1785. $default_lang = get_admin_lang($is_force);
  1786. } else {
  1787. $default_lang = \think\Config::get('ey_config.system_home_default_lang');
  1788. }
  1789. }
  1790. return $default_lang;
  1791. }
  1792. }
  1793. if (!function_exists('get_current_lang'))
  1794. {
  1795. /**
  1796. * 获取当前默认语言
  1797. */
  1798. function get_current_lang($is_force = false)
  1799. {
  1800. static $current_lang = null;
  1801. if (null === $current_lang || $is_force) {
  1802. $request = \think\Request::instance();
  1803. if (!stristr($request->baseFile(), 'index.php')) {
  1804. $current_lang = get_admin_lang($is_force);
  1805. } else {
  1806. $current_lang = get_home_lang($is_force);
  1807. }
  1808. }
  1809. return $current_lang;
  1810. }
  1811. }
  1812. if (!function_exists('get_admin_lang'))
  1813. {
  1814. /**
  1815. * 获取后台当前语言
  1816. */
  1817. function get_admin_lang($is_force = false)
  1818. {
  1819. static $admin_lang = null;
  1820. if (null === $admin_lang || $is_force) {
  1821. $keys = \think\Config::get('global.admin_lang');
  1822. $admin_lang = \think\Cookie::get($keys);
  1823. $admin_lang = addslashes($admin_lang);
  1824. if ($is_force || empty($admin_lang) || (!empty($admin_lang) && !preg_match('/^[a-z]{2}$/i', $admin_lang))) {
  1825. $admin_lang = input('param.lang/s');
  1826. empty($admin_lang) && $admin_lang = get_main_lang($is_force);
  1827. \think\Cookie::set($keys, $admin_lang);
  1828. }
  1829. $admin_lang = preg_replace('/([^a-z])/i', '', $admin_lang);
  1830. }
  1831. return $admin_lang;
  1832. }
  1833. // function get_admin_lang()
  1834. // {
  1835. // static $admin_lang = null;
  1836. // if (null === $admin_lang || $is_force) {
  1837. // $admin_lang = input('param.lang/s');
  1838. // $keys = \think\Config::get('global.admin_lang');
  1839. // if (empty($admin_lang)){
  1840. // $admin_lang = \think\Cookie::get($keys);
  1841. // $admin_lang = addslashes($admin_lang);
  1842. // if (empty($admin_lang) || (!empty($admin_lang) && !preg_match('/^[a-z]{2}$/i', $admin_lang))) {
  1843. // empty($admin_lang) && $admin_lang = get_main_lang();
  1844. // }
  1845. // }
  1846. // $admin_lang = preg_replace('/([^a-z])/i', '', $admin_lang);
  1847. // \think\Cookie::set($keys, $admin_lang);
  1848. // }
  1849. //
  1850. // return $admin_lang;
  1851. // }
  1852. }
  1853. if (!function_exists('get_home_lang'))
  1854. {
  1855. /**
  1856. * 获取前台当前语言
  1857. */
  1858. function get_home_lang($is_force = false)
  1859. {
  1860. static $home_lang = null;
  1861. if (null === $home_lang || $is_force) {
  1862. $keys = \think\Config::get('global.home_lang');
  1863. $home_lang = input('param.lang/s');
  1864. if ($is_force || empty($home_lang)){
  1865. $home_lang = \think\Cookie::get($keys);
  1866. $home_lang = addslashes($home_lang);
  1867. if ($is_force || empty($home_lang) || (!empty($home_lang) && !preg_match('/^[a-z]{2}$/i', $home_lang))) {
  1868. if ($is_force || empty($home_lang)) {
  1869. $home_lang = \think\Db::name('language')->where([
  1870. 'is_home_default' => 1,
  1871. ])->getField('mark');
  1872. }
  1873. }
  1874. }
  1875. $home_lang = preg_replace('/([^a-z])/i', '', $home_lang);
  1876. \think\Cookie::set($keys, $home_lang);
  1877. }
  1878. return $home_lang;
  1879. }
  1880. }
  1881. if (!function_exists('is_language'))
  1882. {
  1883. /**
  1884. * 是否多语言
  1885. */
  1886. function is_language()
  1887. {
  1888. static $value = null;
  1889. if (null === $value) {
  1890. $module = \think\Request::instance()->module();
  1891. if (empty($module)) {
  1892. $system_langnum = tpCache('system.system_langnum');
  1893. } else {
  1894. $system_langnum = config('ey_config.system_langnum');
  1895. }
  1896. if (1 < intval($system_langnum)) {
  1897. $value = $system_langnum;
  1898. } else {
  1899. $value = false;
  1900. }
  1901. }
  1902. return $value;
  1903. }
  1904. }
  1905. if (!function_exists('switch_language'))
  1906. {
  1907. /**
  1908. * 多语言切换(默认中文)
  1909. *
  1910. * @return void
  1911. */
  1912. function switch_language()
  1913. {
  1914. static $execute_end = false;
  1915. if (true === $execute_end) {
  1916. return true;
  1917. }
  1918. static $request = null;
  1919. if (null == $request) {
  1920. $request = \think\Request::instance();
  1921. }
  1922. $pathinfo = $request->pathinfo();
  1923. /*验证语言标识是否合法---PS:$request->param('site/s','')一定要放在$request->pathinfo()后面,非则会造成分页错误(链接带有"s"变量)*/
  1924. $var_lang = $request->param('lang/s');
  1925. $var_lang = trim($var_lang, '/');
  1926. if (!empty($var_lang)) {
  1927. if (!preg_match('/^([a-z]+)$/i', $var_lang)) {
  1928. to_index();
  1929. }
  1930. }
  1931. /*end*/
  1932. $lang_switch_on = config('lang_switch_on');
  1933. if (!$lang_switch_on) {
  1934. return true;
  1935. }
  1936. static $language_db = null;
  1937. if (null == $language_db) {
  1938. $language_db = \think\Db::name('language');
  1939. }
  1940. $is_admin = false;
  1941. if (!stristr($request->baseFile(), 'index.php')) {
  1942. $is_admin = true;
  1943. $langCookieVar = \think\Config::get('global.admin_lang');
  1944. } else {
  1945. $langCookieVar = \think\Config::get('global.home_lang');
  1946. }
  1947. \think\Lang::setLangCookieVar($langCookieVar);
  1948. /*单语言执行代码 - 排序不要乱改,影响很大*/
  1949. $langRow = $language_db->field('title,mark,is_home_default')
  1950. ->order('id asc')
  1951. ->cache(true, EYOUCMS_CACHE_TIME, 'language')
  1952. ->select();
  1953. if (1 >= count($langRow)) {
  1954. $langRow = current($langRow);
  1955. $lang = $langRow['mark'];
  1956. \think\Config::set('cache.path', CACHE_PATH.$lang.DS);
  1957. \think\Cookie::set($langCookieVar, $lang);
  1958. cookie('site_info', null);
  1959. return true;
  1960. }
  1961. /*--end*/
  1962. $current_lang = '';
  1963. /*兼容伪静态多语言切换*/
  1964. if (!empty($pathinfo)) {
  1965. $s_arr = explode('/', $pathinfo);
  1966. if ('m' == $s_arr[0]) {
  1967. $s_arr[0] = $s_arr[1];
  1968. }
  1969. $count = $language_db->where(['mark'=>$s_arr[0]])->cache(true, EYOUCMS_CACHE_TIME, 'language')->count();
  1970. if (!empty($count)) {
  1971. $current_lang = $s_arr[0];
  1972. }
  1973. }
  1974. /*--end*/
  1975. /*前后台默认语言*/
  1976. if (empty($current_lang)) {
  1977. if ($is_admin) {
  1978. $current_lang = !empty($langRow[0]['mark']) ? $langRow[0]['mark'] : 'cn';
  1979. } else {
  1980. foreach ($langRow as $key => $val) {
  1981. if (1 == $val['is_home_default']) {
  1982. $current_lang = $val['mark'];
  1983. break;
  1984. }
  1985. }
  1986. empty($current_lang) && $current_lang = !empty($langRow[0]['mark']) ? $langRow[0]['mark'] : 'cn';
  1987. }
  1988. }
  1989. /*end*/
  1990. $lang = $request->param('lang/s', $current_lang);
  1991. $lang = trim($lang, '/');
  1992. if (!empty($lang)) {
  1993. // 处理访问不存在的语言
  1994. $lang = $language_db->where('mark',$lang)->cache(true, EYOUCMS_CACHE_TIME, 'language')->getField('mark');
  1995. }
  1996. if (empty($lang)) {
  1997. if ($is_admin) {
  1998. $lang = !empty($langRow[0]['mark']) ? $langRow[0]['mark'] : 'cn';
  1999. // $lang = \think\Db::name('language')->order('id asc')->getField('mark');
  2000. } else {
  2001. to_index();
  2002. }
  2003. }
  2004. $lang_info = [];
  2005. foreach ($langRow as $key => $val) {
  2006. if ($val['mark'] == $lang) {
  2007. $lang_info['lang_title'] = $val['title'];
  2008. /*单独域名*/
  2009. $inletStr = (1 == config('ey_config.seo_inlet')) ? '' : '/index.php'; // 去掉入口文件
  2010. $url = $val['url'];
  2011. if (empty($url)) {
  2012. if (1 == $val['is_home_default']) {
  2013. $url = ROOT_DIR.'/'; // 支持子目录
  2014. } else {
  2015. $seoConfig = tpCache('seo', [], $val['mark']);
  2016. $seo_pseudo = !empty($seoConfig['seo_pseudo']) ? $seoConfig['seo_pseudo'] : config('ey_config.seo_pseudo');
  2017. if (1 == $seo_pseudo) {
  2018. $url = $request->domain().ROOT_DIR.$inletStr; // 支持子目录
  2019. if (!empty($inletStr)) {
  2020. $url .= '?';
  2021. } else {
  2022. $url .= '/?';
  2023. }
  2024. $url .= http_build_query(['lang'=>$val['mark']]);
  2025. } else {
  2026. $url = ROOT_DIR.$inletStr.'/'.$val['mark']; // 支持子目录
  2027. }
  2028. }
  2029. }
  2030. /*--end*/
  2031. $lang_info['lang_url'] = $url;
  2032. cookie('lang_info', $lang_info);
  2033. break;
  2034. }
  2035. }
  2036. \think\Config::set('cache.path', CACHE_PATH.$lang.DS);
  2037. $pre_lang = \think\Cookie::get($langCookieVar);
  2038. \think\Cookie::set($langCookieVar, $lang);
  2039. if ($pre_lang != $lang) {
  2040. if ($is_admin) {
  2041. \think\Db::name('admin')->where('admin_id', \think\Session::get('admin_id'))->update([
  2042. 'mark_lang' => $lang,
  2043. 'update_time' => getTime(),
  2044. ]);
  2045. }
  2046. }
  2047. $execute_end = true;
  2048. }
  2049. }
  2050. if (!function_exists('get_default_site'))
  2051. {
  2052. /**
  2053. * 获取默认城市站点
  2054. */
  2055. function get_default_site()
  2056. {
  2057. static $default_site = null;
  2058. if (null === $default_site) {
  2059. $default_site = \think\Config::get('ey_config.site_default_home');
  2060. if (!empty($default_site)) {
  2061. $default_site = \think\Db::name('citysite')->where(['id'=>$default_site])->getField('domain');
  2062. }
  2063. }
  2064. return $default_site;
  2065. }
  2066. }
  2067. if (!function_exists('get_home_site'))
  2068. {
  2069. /**
  2070. * 获取前台当前城市站点
  2071. */
  2072. function get_home_site()
  2073. {
  2074. static $home_site = null;
  2075. if (null === $home_site) {
  2076. $home_site = input('param.site/s');
  2077. if (empty($home_site)) {
  2078. /*支持独立域名配置*/
  2079. $subDomain = request()->subDomain();
  2080. if (!empty($subDomain) && 'www' != $subDomain) {
  2081. $siteInfo = \think\Db::name('citysite')->where('domain',$subDomain)->cache(true, EYOUCMS_CACHE_TIME, 'citysite')->find();
  2082. if (!empty($siteInfo['is_open'])) {
  2083. $home_site = $siteInfo['domain'];
  2084. }
  2085. }
  2086. /*--end*/
  2087. empty($home_site) && $home_site = get_default_site();
  2088. }
  2089. $home_site = preg_replace('/([^\w\-\_])/i', '', $home_site);
  2090. }
  2091. return $home_site;
  2092. }
  2093. }
  2094. if (!function_exists('switch_citysite'))
  2095. {
  2096. /**
  2097. * 多城市切换
  2098. *
  2099. * @return void
  2100. */
  2101. function switch_citysite()
  2102. {
  2103. static $execute_end = false;
  2104. if (true === $execute_end) {
  2105. return true;
  2106. }
  2107. $request = \think\Request::instance();
  2108. // 忽略后台
  2109. if (!stristr($request->baseFile(), 'index.php')) {
  2110. return true;
  2111. }
  2112. $pathinfo = $request->pathinfo();
  2113. /*验证二级域名、路径标识是否合法--- PS:$request->param('site/s','')一定要放在$request->pathinfo()后面,非则会造成分页错误(链接带有"s"变量)*/
  2114. $var_site = $request->param('site/s');
  2115. $var_site = trim($var_site, '/');
  2116. if (!empty($var_site)) {
  2117. if (!preg_match('/^([\w\-\_]+)$/i', $var_site)) {
  2118. to_index();
  2119. }
  2120. }
  2121. /*end*/
  2122. $lang_switch_on = config('lang_switch_on');
  2123. $city_switch_on = config('city_switch_on');
  2124. if ($lang_switch_on || !$city_switch_on) {
  2125. return true;
  2126. }
  2127. static $citysite_db = null;
  2128. if (null == $citysite_db) {
  2129. $citysite_db = \think\Db::name('citysite');
  2130. }
  2131. $current_site = '';
  2132. /*兼容伪静态多城市切换*/
  2133. if (!empty($pathinfo)) {
  2134. $s_arr = explode('/', $pathinfo);
  2135. if ('m' == $s_arr[0]) {
  2136. $s_arr[0] = $s_arr[1];
  2137. }
  2138. $count = $citysite_db->where(['domain'=>$s_arr[0]])->cache(true, EYOUCMS_CACHE_TIME, 'citysite')->count();
  2139. if (!empty($count)) {
  2140. $current_site = $s_arr[0];
  2141. }
  2142. }
  2143. /*--end*/
  2144. $site = $request->param('site/s', $current_site);
  2145. $site = trim($site, '/');
  2146. if (!empty($site)) {
  2147. // 处理访问不存在的城市
  2148. $siteInfo = $citysite_db->where('domain',$site)->cache(true, EYOUCMS_CACHE_TIME, 'citysite')->find();
  2149. if (empty($siteInfo['domain'])) {
  2150. to_index();
  2151. } else {
  2152. $site_default_home = tpCache('site.site_default_home');
  2153. if ($siteInfo['id'] == $site_default_home) { // 设为默认站点跳转
  2154. header('Location: '.ROOT_DIR.'/');
  2155. exit;
  2156. }
  2157. }
  2158. } else {
  2159. $subDomain = $request->subDomain();
  2160. $web_basehost = tpCache('web.web_basehost');
  2161. $web_subDomain = $request->subDomain('', true, $web_basehost);
  2162. if (!empty($subDomain) && !in_array($subDomain, ['www', $web_subDomain])) {
  2163. $siteInfo = $citysite_db->where('domain',$subDomain)->cache(true, EYOUCMS_CACHE_TIME, 'citysite')->find();
  2164. if (!empty($siteInfo['is_open'])) {
  2165. $site_default_home = tpCache('site.site_default_home');
  2166. if ($site_default_home == $siteInfo['id']) { // 设为默认站点跳转
  2167. $domain = preg_replace('/^(http(s)?:)?(\/\/)?([^\/\:]*)(.*)$/i', '${4}', $web_basehost);
  2168. $url = $request->scheme().'://'.$domain;
  2169. if (stristr($request->host(), ':')) {
  2170. $url .= ":".$request->port();
  2171. }
  2172. $url .= ROOT_DIR;
  2173. header('Location: '.$url);
  2174. exit;
  2175. } else {
  2176. $site = $siteInfo['domain'];
  2177. }
  2178. } else {
  2179. to_index();
  2180. }
  2181. }
  2182. empty($site) && $site = 'www';
  2183. }
  2184. \think\Config::set('cache.path', CACHE_PATH.$site.DS);
  2185. $execute_end = true;
  2186. }
  2187. }
  2188. if (!function_exists('getUsersConfigData'))
  2189. {
  2190. // 专用于获取users_config,会员配置表数据处理。
  2191. // 参数1:必须传入,传入值不同,获取数据不同:
  2192. // 例:获取配置所有数据,传入:all,
  2193. // 获取分组所有数据,传入:分组标识,如:member,
  2194. // 获取分组中的单个数据,传入:分组标识.名称标识,如:users.users_open_register
  2195. // 参数2:data数据,为空则查询,否则为添加或修改。
  2196. // 参数3:多语言标识,为空则获取当前默认语言。
  2197. function getUsersConfigData($config_key,$data=array(),$lang='', $options = null){
  2198. $tableName = 'users_config';
  2199. $table_db = \think\Db::name($tableName);
  2200. $lang = !empty($lang) ? $lang : get_current_lang();
  2201. $param = explode('.', $config_key);
  2202. $cache_inc_type = "{$tableName}-{$lang}-{$param[0]}";
  2203. if (empty($options['path'])) {
  2204. $options['path'] = DATA_PATH.'runtime'.DS.'cache'.DS.$lang.DS;
  2205. }
  2206. if(empty($data)){
  2207. //如$config_key=shop_info则获取网站信息数组
  2208. //如$config_key=shop_info.logo则获取网站logo字符串
  2209. $config = cache($cache_inc_type,'',$options);//直接获取缓存文件
  2210. if(empty($config)){
  2211. //缓存文件不存在就读取数据库
  2212. if ($param[0] == 'all') {
  2213. $param[0] = 'all';
  2214. $res = $table_db->where([
  2215. 'lang' => $lang,
  2216. ])->select();
  2217. } else {
  2218. $res = $table_db->where([
  2219. 'inc_type' => $param[0],
  2220. 'lang' => $lang,
  2221. ])->select();
  2222. }
  2223. if($res){
  2224. foreach($res as $k=>$val){
  2225. $config[$val['name']] = $val['value'];
  2226. }
  2227. cache($cache_inc_type,$config,$options);
  2228. }
  2229. }
  2230. if(!empty($param) && count($param)>1){
  2231. $newKey = strtolower($param[1]);
  2232. return isset($config[$newKey]) ? $config[$newKey] : '';
  2233. }else{
  2234. return $config;
  2235. }
  2236. }else{
  2237. //更新缓存
  2238. $result = $table_db->where([
  2239. 'inc_type' => $param[0],
  2240. 'lang' => $lang,
  2241. ])->select();
  2242. if($result){
  2243. foreach($result as $val){
  2244. $temp[$val['name']] = $val['value'];
  2245. }
  2246. $add_data = array();
  2247. foreach ($data as $k=>$v){
  2248. $newK = strtolower($k);
  2249. $newArr = array(
  2250. 'name'=>$newK,
  2251. 'value'=>trim($v),
  2252. 'inc_type'=>$param[0],
  2253. 'lang' => $lang,
  2254. 'update_time' => getTime(),
  2255. );
  2256. if(!isset($temp[$newK])){
  2257. array_push($add_data, $newArr); //新key数据插入数据库
  2258. }else{
  2259. if ($v != $temp[$newK]) {
  2260. $table_db->where([
  2261. 'name' => $newK,
  2262. 'lang' => $lang,
  2263. ])->save($newArr);//缓存key存在且值有变更新此项
  2264. }
  2265. }
  2266. }
  2267. if (!empty($add_data)) {
  2268. $table_db->insertAll($add_data);
  2269. }
  2270. //更新后的数据库记录
  2271. $newRes = $table_db->where([
  2272. 'inc_type' => $param[0],
  2273. 'lang' => $lang,
  2274. ])->select();
  2275. foreach ($newRes as $rs){
  2276. $newData[$rs['name']] = $rs['value'];
  2277. }
  2278. }else{
  2279. if ($param[0] != 'all') {
  2280. foreach($data as $k=>$v){
  2281. $newK = strtolower($k);
  2282. $newArr[] = array(
  2283. 'name'=>$newK,
  2284. 'value'=>trim($v),
  2285. 'inc_type'=>$param[0],
  2286. 'lang' => $lang,
  2287. 'update_time' => getTime(),
  2288. );
  2289. }
  2290. !empty($newArr) && $table_db->insertAll($newArr);
  2291. }
  2292. $newData = $data;
  2293. }
  2294. $result = false;
  2295. $res = $table_db->where([
  2296. 'lang' => $lang,
  2297. ])->select();
  2298. if($res){
  2299. $global = array();
  2300. foreach($res as $k=>$val){
  2301. $global[$val['name']] = $val['value'];
  2302. }
  2303. $result = cache("{$tableName}-{$lang}-all",$global,$options);
  2304. }
  2305. if ($param[0] != 'all') {
  2306. $result = cache($cache_inc_type,$newData,$options);
  2307. }
  2308. return $result;
  2309. }
  2310. }
  2311. }
  2312. if (!function_exists('send_email'))
  2313. {
  2314. /**
  2315. * 邮件发送
  2316. * @param $to 接收人
  2317. * @param string $subject 邮件标题
  2318. * @param string $content 邮件内容(html模板渲染后的内容)
  2319. * @param string $scene 使用场景
  2320. * @throws Exception
  2321. * @throws phpmailerException
  2322. */
  2323. function send_email($to='', $subject='', $data=array(), $scene=0, $smtp_config = []){
  2324. // 实例化类库,调用发送邮件
  2325. $emailLogic = new \app\common\logic\EmailLogic($smtp_config);
  2326. $res = $emailLogic->send_email($to, $subject, $data, $scene);
  2327. return $res;
  2328. }
  2329. }
  2330. if (!function_exists('sendSms'))
  2331. {
  2332. /**
  2333. * 发送短信逻辑
  2334. * @param unknown $scene
  2335. */
  2336. function sendSms($scene, $sender, $params,$unique_id=0,$sms_config = [])
  2337. {
  2338. $smsLogic = new \app\common\logic\SmsLogic($sms_config);
  2339. return $smsLogic->sendSms($scene, $sender, $params, $unique_id);
  2340. }
  2341. }
  2342. if (!function_exists('get_region_list')){
  2343. /**
  2344. * 获得全部省份列表
  2345. */
  2346. function get_region_list()
  2347. {
  2348. $result = extra_cache('global_get_region_list');
  2349. if ($result == false) {
  2350. $result = \think\Db::name('region')->field('id, name')->getAllWithIndex('id');
  2351. extra_cache('global_get_region_list', $result);
  2352. }
  2353. return $result;
  2354. }
  2355. }
  2356. if (!function_exists('get_province_list')){
  2357. /**
  2358. * 获得全部省份列表
  2359. */
  2360. function get_province_list()
  2361. {
  2362. $result = extra_cache('global_get_province_list');
  2363. if ($result == false) {
  2364. $result = \think\Db::name('region')->field('id, name')
  2365. ->where('level',1)
  2366. ->getAllWithIndex('id');
  2367. extra_cache('global_get_province_list', $result);
  2368. }
  2369. return $result;
  2370. }
  2371. }
  2372. if (!function_exists('get_city_list')){
  2373. /**
  2374. * 获得全部城市列表
  2375. */
  2376. function get_city_list()
  2377. {
  2378. $result = extra_cache('global_get_city_list');
  2379. if ($result == false) {
  2380. $result = \think\Db::name('region')->field('id, name')
  2381. ->where('level',2)
  2382. ->getAllWithIndex('id');
  2383. extra_cache('global_get_city_list', $result);
  2384. }
  2385. return $result;
  2386. }
  2387. }
  2388. if (!function_exists('get_area_list')){
  2389. /**
  2390. * 获得全部地区列表
  2391. */
  2392. function get_area_list()
  2393. {
  2394. $result = extra_cache('global_get_area_list');
  2395. if ($result == false) {
  2396. $result = \think\Db::name('region')->field('id, name')
  2397. ->where('level',3)
  2398. ->getAllWithIndex('id');
  2399. extra_cache('global_get_area_list', $result);
  2400. }
  2401. return $result;
  2402. }
  2403. }
  2404. if (!function_exists('get_region_name')){
  2405. /**
  2406. * 根据地区ID获得区域名称
  2407. */
  2408. function get_region_name($id = 0)
  2409. {
  2410. $result = get_region_list();
  2411. return empty($result[$id]['name']) ? '' : $result[$id]['name'];
  2412. }
  2413. }
  2414. if (!function_exists('get_province_name')){
  2415. /**
  2416. * 根据地区ID获得省份名称
  2417. */
  2418. function get_province_name($id = 0)
  2419. {
  2420. $result = get_province_list();
  2421. return empty($result[$id]['name']) ? '' : $result[$id]['name'];
  2422. }
  2423. }
  2424. if (!function_exists('get_city_name')){
  2425. /**
  2426. * 根据地区ID获得城市名称
  2427. */
  2428. function get_city_name($id = 0)
  2429. {
  2430. $result = get_city_list();
  2431. return empty($result[$id]['name']) ? '' : $result[$id]['name'];
  2432. }
  2433. }
  2434. if (!function_exists('get_area_name')){
  2435. /**
  2436. * 根据地区ID获得县区名称
  2437. */
  2438. function get_area_name($id = 0)
  2439. {
  2440. $result = get_area_list();
  2441. return empty($result[$id]['name']) ? '' : $result[$id]['name'];
  2442. }
  2443. }
  2444. if (!function_exists('get_citysite_list')){
  2445. /**
  2446. * 获得城市站点的全部列表
  2447. */
  2448. function get_citysite_list()
  2449. {
  2450. $result = extra_cache('global_get_citysite_list');
  2451. if (empty($result)) {
  2452. $result = \think\Db::name('citysite')->field('id, name, level, parent_id, topid, domain, initial, is_open')
  2453. ->where(['status'=>1])
  2454. ->order("sort_order asc, id asc")
  2455. ->getAllWithIndex('id');
  2456. extra_cache('global_get_citysite_list', $result);
  2457. }
  2458. return $result;
  2459. }
  2460. }
  2461. if (!function_exists('get_site_province_list')){
  2462. /**
  2463. * 获得城市站点的全部省份列表
  2464. */
  2465. function get_site_province_list()
  2466. {
  2467. $result = extra_cache('global_get_site_province_list');
  2468. if (empty($result)) {
  2469. $result = \think\Db::name('citysite')->field('id, name, domain, parent_id')
  2470. ->where(['level'=>1, 'status'=>1])
  2471. ->order("sort_order asc, id asc")
  2472. ->getAllWithIndex('id');
  2473. extra_cache('global_get_site_province_list', $result);
  2474. }
  2475. return $result;
  2476. }
  2477. }
  2478. if (!function_exists('get_site_city_list')){
  2479. /**
  2480. * 获得城市站点的全部城市列表
  2481. */
  2482. function get_site_city_list()
  2483. {
  2484. $result = extra_cache('global_get_site_city_list');
  2485. if (empty($result)) {
  2486. $result = \think\Db::name('citysite')->field('id, name, parent_id')
  2487. ->where(['level'=>2, 'status'=>1])
  2488. ->order("sort_order asc, id asc")
  2489. ->getAllWithIndex('id');
  2490. extra_cache('global_get_site_city_list', $result);
  2491. }
  2492. return $result;
  2493. }
  2494. }
  2495. if (!function_exists('get_site_area_list')){
  2496. /**
  2497. * 获得城市站点的全部地区列表
  2498. */
  2499. function get_site_area_list()
  2500. {
  2501. $result = extra_cache('global_get_site_area_list');
  2502. if (empty($result)) {
  2503. $result = \think\Db::name('citysite')->field('id, name, parent_id')
  2504. ->where(['level'=>3, 'status'=>1])
  2505. ->order("sort_order asc, id asc")
  2506. ->getAllWithIndex('id');
  2507. extra_cache('global_get_site_area_list', $result);
  2508. }
  2509. return $result;
  2510. }
  2511. }
  2512. if (!function_exists('AddOrderAction'))
  2513. {
  2514. /**
  2515. * 添加订单操作表数据
  2516. * 参数说明:
  2517. * $OrderId 订单ID或订单ID数组
  2518. * $UsersId 会员ID,若不为0,则ActionUsers为0
  2519. * $ActionUsers 操作员ID,为0,表示会员操作,反之则为管理员ID
  2520. * $OrderStatus 操作时,订单当前状态
  2521. * $ExpressStatus 操作时,订单当前物流状态
  2522. * $PayStatus 操作时,订单当前付款状态
  2523. * $ActionDesc 操作描述
  2524. * $ActionNote 操作备注
  2525. * 返回说明:
  2526. * return 无需返回
  2527. */
  2528. function AddOrderAction($OrderId, $UsersId = 0, $ActionUsers = 0, $OrderStatus = 0, $ExpressStatus = 0, $PayStatus = 0, $ActionDesc = '提交订单', $ActionNote = '会员提交订单成功')
  2529. {
  2530. if (is_array($OrderId) && 4 == $OrderStatus) {
  2531. // OrderId为数组并且订单状态为过期,则执行
  2532. foreach ($OrderId as $key => $value) {
  2533. $ActionData[] = [
  2534. 'order_id' => $value['order_id'],
  2535. 'users_id' => $UsersId,
  2536. 'action_user' => $ActionUsers,
  2537. 'order_status' => $OrderStatus,
  2538. 'express_status' => $ExpressStatus,
  2539. 'pay_status' => $PayStatus,
  2540. 'action_desc' => $ActionDesc,
  2541. 'action_note' => $ActionNote,
  2542. 'lang' => get_home_lang(),
  2543. 'add_time' => getTime(),
  2544. ];
  2545. }
  2546. // 批量添加
  2547. M('shop_order_log')->insertAll($ActionData);
  2548. } else if (is_array($OrderId)) {
  2549. // OrderId为数组则执行
  2550. foreach ($OrderId as $key => $value) {
  2551. $ActionData[] = [
  2552. 'order_id' => is_array($value) && !empty($value['order_id']) ? $value['order_id'] : $value,
  2553. 'users_id' => $UsersId,
  2554. 'action_user' => $ActionUsers,
  2555. 'order_status' => $OrderStatus,
  2556. 'express_status' => $ExpressStatus,
  2557. 'pay_status' => $PayStatus,
  2558. 'action_desc' => $ActionDesc,
  2559. 'action_note' => $ActionNote,
  2560. 'lang' => get_home_lang(),
  2561. 'add_time' => getTime(),
  2562. ];
  2563. }
  2564. // 批量添加
  2565. M('shop_order_log')->insertAll($ActionData);
  2566. } else {
  2567. // OrderId不为数组,则执行
  2568. $ActionData = [
  2569. 'order_id' => $OrderId,
  2570. 'users_id' => $UsersId,
  2571. 'action_user' => $ActionUsers,
  2572. 'order_status' => $OrderStatus,
  2573. 'express_status' => $ExpressStatus,
  2574. 'pay_status' => $PayStatus,
  2575. 'action_desc' => $ActionDesc,
  2576. 'action_note' => $ActionNote,
  2577. 'lang' => get_home_lang(),
  2578. 'add_time' => getTime(),
  2579. ];
  2580. // 单条添加
  2581. M('shop_order_log')->add($ActionData);
  2582. }
  2583. }
  2584. }
  2585. if (!function_exists('UsersMoneyAction'))
  2586. {
  2587. /**
  2588. * 添加会员余额明细表
  2589. * 参数说明:
  2590. * $OrderCode 订单编号
  2591. * $UsersId 会员ID
  2592. * $UsersMoney 记录余额
  2593. * $Cause 订单说明
  2594. * 返回说明:
  2595. * return 无需返回
  2596. */
  2597. function UsersMoneyAction($OrderCode = null, $UsersId = null, $UsersMoney = null, $Cause = '订单支付')
  2598. {
  2599. if (empty($OrderCode) || empty($UsersId) || empty($UsersMoney)) return false;
  2600. $Time = getTime();
  2601. /*使用余额支付时,同时添加一条记录到金额明细表*/
  2602. $UsersNewMoney = sprintf("%.2f", $UsersId['users_money'] -= $UsersMoney);
  2603. $MoneyData = [
  2604. 'users_id' => $UsersId['users_id'],
  2605. 'money' => $UsersMoney,
  2606. 'users_money' => $UsersNewMoney,
  2607. 'cause' => $Cause,
  2608. 'cause_type' => 3,
  2609. 'status' => 3,
  2610. 'pay_details' => '',
  2611. 'order_number' => $OrderCode,
  2612. 'add_time' => $Time,
  2613. 'update_time' => $Time,
  2614. ];
  2615. M('users_money')->add($MoneyData);
  2616. /* END */
  2617. }
  2618. }
  2619. if (!function_exists('GetEamilSendData'))
  2620. {
  2621. /**
  2622. * 获取邮箱发送数据
  2623. * 参数说明:
  2624. * $SmtpConfig 后台设置的邮箱配置信息
  2625. * $users 会员数据
  2626. * $sendContent 发送内容
  2627. * $type 发送场景
  2628. * $pay_method 支付方式
  2629. * 返回说明:
  2630. * return 邮箱发送所需参数
  2631. */
  2632. function GetEamilSendData($SmtpConfig = [], $users = [], $sendContent = [], $type = 1, $pay_method = null)
  2633. {
  2634. // 是否传入配置、用户信息、发送内容,缺一则返回结束
  2635. if (empty($SmtpConfig) || empty($users) || empty($sendContent)) return false;
  2636. // 根据类型判断场景是否开启并选择发送场景及地址
  2637. if (in_array($type, [1, 3])) {
  2638. // 查询判断是否开启邮件订单提醒
  2639. $send_scene = 1 === intval($type) ? 5 : 20;
  2640. $where = [
  2641. 'lang' => get_admin_lang(),
  2642. 'send_scene' => $send_scene
  2643. ];
  2644. $SmtpOpen = \think\Db::name('smtp_tpl')->where($where)->getField('is_open');
  2645. // 发送给后台,选择邮件配置中的邮箱地址
  2646. $email = !empty($SmtpConfig['smtp_from_eamil']) ? $SmtpConfig['smtp_from_eamil'] : null;
  2647. } else if (in_array($type, [2])) {
  2648. $send_scene = 6;
  2649. $where = [
  2650. 'lang' => get_admin_lang(),
  2651. 'send_scene' => $send_scene
  2652. ];
  2653. $SmtpOpen = \think\Db::name('smtp_tpl')->where($where)->getField('is_open');
  2654. // 发送给用户,选择用户的邮箱地址
  2655. $email = !empty($users['email']) ? $users['email'] : null;
  2656. }
  2657. // 若未开启或邮箱地址不存在则返回结束
  2658. if (empty($SmtpOpen) || empty($email)) return false;
  2659. // 发送接口及内容拼装
  2660. if (!empty($SmtpConfig['smtp_server']) && !empty($SmtpConfig['smtp_user']) && !empty($SmtpConfig['smtp_pwd'])) {
  2661. $Result = [];
  2662. $url = ROOT_DIR . '/index.php?m=user&c=Smtpmail&a=send_email&_ajax=1';
  2663. // 订单(支付、发货)发送信息
  2664. if (in_array($type, [1, 2])) {
  2665. switch ($type) {
  2666. case '1':
  2667. $title = '订单支付';
  2668. break;
  2669. case '2':
  2670. $title = '订单发货';
  2671. break;
  2672. }
  2673. $Result = [
  2674. 'url' => $url,
  2675. 'data' => [
  2676. 'email' => $email,
  2677. 'title' => $title,
  2678. 'type' => 'order_msg',
  2679. 'scene' => $send_scene,
  2680. 'data' => [
  2681. 'type' => $type,
  2682. 'nickname' => !empty($users['nickname']) ? $users['nickname'] : $users['username'],
  2683. 'pay_method' => $pay_method,
  2684. 'order_id' => !empty($sendContent['order_id']) ? $sendContent['order_id'] : '',
  2685. 'order_code' => !empty($sendContent['order_code']) ? $sendContent['order_code'] : '',
  2686. 'service_id' => !empty($sendContent['service_id']) ? $sendContent['service_id'] : ''
  2687. ],
  2688. ]
  2689. ];
  2690. }
  2691. // 会员投稿提醒
  2692. else if (in_array($type, [3])) {
  2693. $Result = [
  2694. 'url' => $url,
  2695. 'data' => [
  2696. 'email' => $email,
  2697. 'title' => '投稿提醒',
  2698. 'type' => 'usersRelease',
  2699. 'scene' => $send_scene,
  2700. 'data' => [
  2701. 'type' => $type,
  2702. 'nickname' => !empty($users['nickname']) ? $users['nickname'] : $users['username'],
  2703. 'title' => !empty($sendContent['title']) ? $sendContent['title'] : '',
  2704. 'content' => !empty($sendContent['seo_description']) ? $sendContent['seo_description'] : '',
  2705. 'add_time' => date('Y-m-d H:i:s', $sendContent['add_time']),
  2706. 'arcrank' => isset($sendContent['arcrank']) && -1 === intval($sendContent['arcrank']) ? '未审核' : '自动审核',
  2707. ],
  2708. ]
  2709. ];
  2710. }
  2711. return $Result;
  2712. }
  2713. return false;
  2714. }
  2715. }
  2716. if (!function_exists('GetMobileSendData'))
  2717. {
  2718. /**
  2719. * 获取手机发送数据
  2720. * 参数说明:
  2721. * $SmtpConfig 后台设置的短信配置信息
  2722. * $users 会员数据
  2723. * $sendContent 发送内容
  2724. * $type 发送场景
  2725. * $pay_method 支付方式
  2726. * 返回说明:
  2727. * return 手机短信发送所需参数
  2728. */
  2729. function GetMobileSendData($SmsConfig = [], $users = [], $sendContent = [], $type = 1, $pay_method = null)
  2730. {
  2731. // 是否传入配置、用户信息、订单信息,缺一则返回结束
  2732. if (empty($SmsConfig) || empty($users) || empty($sendContent)) return false;
  2733. // 查询短信配置中的使用平台
  2734. $sms_type = tpCache('sms.sms_type') ? tpCache('sms.sms_type') : 0;
  2735. // 根据类型判断场景是否开启并选择发送场景及手机号
  2736. if (in_array($type, [1, 3])) {
  2737. // 查询判断是否开启手机订单提醒
  2738. $send_scene = 1 === intval($type) ? 5 : 20;
  2739. $where = [
  2740. 'sms_type' => $sms_type,
  2741. 'lang' => get_admin_lang(),
  2742. 'send_scene' => $send_scene
  2743. ];
  2744. $SmsOpen = \think\Db::name('sms_template')->where($where)->getField('is_open');
  2745. // 发送给后台,选择邮件配置中的手机号
  2746. $mobile = !empty($SmsConfig['sms_test_mobile']) ? $SmsConfig['sms_test_mobile'] : null;
  2747. } else if (in_array($type, [2])) {
  2748. $send_scene = 6;
  2749. $where = [
  2750. 'sms_type' => $sms_type,
  2751. 'lang' => get_admin_lang(),
  2752. 'send_scene' => $send_scene
  2753. ];
  2754. $SmsOpen = \think\Db::name('sms_template')->where($where)->getField('is_open');
  2755. // 发送给用户,选择用户的手机号
  2756. $mobile = !empty($users['mobile']) ? $users['mobile'] : null;
  2757. if (empty($mobile)) {
  2758. $mobile = \think\Db::name('shop_order')->where('order_code', $sendContent['order_code'])->getField('mobile');
  2759. }
  2760. }
  2761. // 若未开启或手机号不存在则返回结束
  2762. if (empty($SmsOpen) || empty($mobile)) return false;
  2763. // 发送接口及内容拼装
  2764. if (($sms_type == 1 && !empty($SmsConfig['sms_appkey']) && !empty($SmsConfig['sms_secretkey'])) || ($sms_type == 2 && !empty($SmsConfig['sms_appkey_tx']) && !empty($SmsConfig['sms_appid_tx']))) {
  2765. $Result = [];
  2766. $url = ROOT_DIR . '/index.php?m=api&c=Ajax&a=SendMobileCode&_ajax=1';
  2767. if (in_array($type, [1, 2])) {
  2768. switch ($type) {
  2769. case '1':
  2770. $title = '订单支付';
  2771. break;
  2772. case '2':
  2773. $title = '订单发货';
  2774. break;
  2775. }
  2776. $Result = [
  2777. 'url' => $url,
  2778. 'data' => [
  2779. 'mobile' => $mobile,
  2780. 'scene' => $send_scene,
  2781. 'title' => $title,
  2782. 'type' => 'order_msg',
  2783. 'data' => [
  2784. 'type' => $type,
  2785. 'nickname' => !empty($users['nickname']) ? $users['nickname'] : $users['username'],
  2786. 'pay_method' => $pay_method,
  2787. 'order_code' => !empty($sendContent['order_code']) ? $sendContent['order_code'] : '',
  2788. ],
  2789. ]
  2790. ];
  2791. } else if (in_array($type, [3])) {
  2792. $Result = [
  2793. 'url' => $url,
  2794. 'data' => [
  2795. 'mobile' => $mobile,
  2796. 'scene' => $send_scene,
  2797. 'title' => '投稿提醒',
  2798. 'type' => 'usersRelease',
  2799. 'data' => [
  2800. 'type' => $type,
  2801. 'nickname' => !empty($users['nickname']) ? $users['nickname'] : $users['username'],
  2802. 'title' => !empty($sendContent['title']) ? $sendContent['title'] : '',
  2803. 'content' => !empty($sendContent['seo_description']) ? $sendContent['seo_description'] : '',
  2804. 'add_time' => date('Y-m-d H:i:s', $sendContent['add_time']),
  2805. 'arcrank' => isset($sendContent['arcrank']) && -1 === intval($sendContent['arcrank']) ? '未审核' : '自动审核',
  2806. ],
  2807. ]
  2808. ];
  2809. }
  2810. return $Result;
  2811. }
  2812. return false;
  2813. }
  2814. }
  2815. if (!function_exists('download_file'))
  2816. {
  2817. /**
  2818. * 下载文件
  2819. * @param $down_path 文件路径
  2820. * @param $file_mime 文件类型
  2821. */
  2822. function download_file($down_path = '', $file_mime = '', $file_name = '')
  2823. {
  2824. //设置脚本的最大执行时间,设置为0则无时间限制
  2825. function_exists('set_time_limit') && set_time_limit(0);
  2826. @ini_set('memory_limit','-1');
  2827. @ini_set('max_execution_time', '0');
  2828. $down_path = iconv("utf-8", "gb2312//IGNORE", $down_path);
  2829. /*支持子目录*/
  2830. $down_path = preg_replace('#^(/[/\w\-]+)?(/public/upload/soft/|/uploads/soft/)#i', '$2', $down_path);
  2831. /*--end*/
  2832. // 原文件名下载--部分文件名称下载异常
  2833. $filename = basename($down_path);
  2834. if (!empty($file_name)) {
  2835. $arr = explode('.', $filename);
  2836. $ext = end($arr);
  2837. $arr1 = explode('.', $file_name);
  2838. unset($arr1[count($arr1) - 1]);
  2839. $filename = implode('.', $arr1).'.'.$ext;
  2840. }
  2841. // 文件上传后系统自定义的文件名下载--目前多种文件名称类型测试均无问题
  2842. // $filename = basename($down_path);
  2843. // if (!empty($file_name)) {
  2844. // $arr = explode('.', $filename);
  2845. // $ext = end($arr);
  2846. // unset($arr[count($arr) - 1]);
  2847. // $filename = implode('.', $arr).'.'.$ext;
  2848. // }
  2849. //文件大小
  2850. preg_match("/^((\w)*:)?(\/\/).*$/", $down_path, $match);
  2851. if (empty($match)) { // 本地文件
  2852. $filesize = filesize('.'.$down_path);
  2853. } else { // 远程文件
  2854. $header_array = get_headers($down_path, true);
  2855. $filesize = !empty($header_array['Content-Length']) ? $header_array['Content-Length'] : 0;
  2856. }
  2857. //告诉浏览器这是一个文件流格式的文件
  2858. // header("Content-type: ".$file_mime);
  2859. //因为不知道文件是什么类型的,告诉浏览器输出的是字节流
  2860. header('content-type:application/octet-stream');
  2861. //请求范围的度量单位
  2862. Header("Accept-Ranges: bytes");
  2863. //Content-Length是指定包含于请求或响应中数据的字节长度
  2864. Header("Accept-Length: " . $filesize);
  2865. //用来告诉浏览器,文件是可以当做附件被下载,下载后的文件名称为$filename该变量的值。
  2866. Header("Content-Disposition: attachment; filename=" . basename($filename));
  2867. //针对大文件,规定每次读取文件的字节数为2MB,直接输出数据
  2868. $read_buffer = 1024 * 1024 * 2; // 2MB
  2869. if (is_http_url($down_path)) {
  2870. $file = fopen($down_path, 'rb');
  2871. } else {
  2872. $file = fopen('.' . $down_path, 'rb');
  2873. }
  2874. //总的缓冲的字节数
  2875. $sum_buffer = 0;
  2876. //只要没到文件尾,就一直读取
  2877. while(!feof($file) && $sum_buffer < $filesize) {
  2878. echo fread($file,$read_buffer);
  2879. $sum_buffer += $read_buffer;
  2880. }
  2881. //关闭句柄
  2882. fclose($file);
  2883. exit;
  2884. }
  2885. }
  2886. if (!function_exists('is_realdomain'))
  2887. {
  2888. /**
  2889. * 简单判断当前访问的域名是否真实
  2890. * @param string $domain 不带协议的域名
  2891. * @return boolean
  2892. */
  2893. function is_realdomain($domain = '')
  2894. {
  2895. $is_real = false;
  2896. $domain = !empty($domain) ? $domain : request()->host();
  2897. if (!preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/i', $domain) && 'localhost' != $domain && '127.0.0.1' != serverIP()) {
  2898. $is_real = true;
  2899. }
  2900. return $is_real;
  2901. }
  2902. }
  2903. if (!function_exists('img_style_wh'))
  2904. {
  2905. /**
  2906. * 追加指定内嵌样式到编辑器内容的img标签,兼容图片自动适应页面
  2907. */
  2908. function img_style_wh($content = '', $title = '')
  2909. {
  2910. if (!empty($content)) {
  2911. static $basicConfig = null;
  2912. null === $basicConfig && $basicConfig = tpCache('basic');
  2913. if (empty($basicConfig['basic_img_auto_wh']) && empty($basicConfig['basic_img_alt']) && empty($basicConfig['basic_img_title'])) {
  2914. return $content;
  2915. }
  2916. preg_match_all('/<img.*(\/)?>/iUs', $content, $imginfo);
  2917. $imginfo = !empty($imginfo[0]) ? $imginfo[0] : [];
  2918. if (!empty($imginfo)) {
  2919. $num = 1;
  2920. $appendStyle = "max-width:100%!important;height:auto!important;";
  2921. $title = preg_replace('/("|\')/i', '', $title);
  2922. foreach ($imginfo as $key => $imgstr) {
  2923. $imgstrNew = $imgstr;
  2924. if (!stristr($imgstrNew, ' src=')) {
  2925. continue;
  2926. }
  2927. $imgname = preg_replace("/<img(.*?)src(\s*)=(\s*)[\'|\"](.*?)([^\/\'\"]*)[\'|\"](.*?)[\/]?(\s*)>/i", '${5}', $imgstrNew);
  2928. $imgname = str_replace('/', '\/', $imgname);
  2929. // 是否开启图片大小自适应
  2930. if (!empty($basicConfig['basic_img_auto_wh'])) {
  2931. if (!stristr($imgstrNew, $appendStyle)) {
  2932. // 追加style属性
  2933. $imgstrNew = preg_replace('/style(\s*)=(\s*)[\'|\"]([^\'\"]*)?[\'|\"]/i', 'style="'.$appendStyle.'${3}"', $imgstrNew);
  2934. if (!preg_match('/<img(.*?)style(\s*)=(\s*)[\'|\"](.*?)[\'|\"](.*?)[\/]?(\s*)>/i', $imgstrNew)) {
  2935. // 新增style属性
  2936. $imgstrNew = str_ireplace('<img', "<img style=\"".$appendStyle."\" ", $imgstrNew);
  2937. }
  2938. }
  2939. } else {
  2940. $imgstrNew = str_ireplace([$appendStyle, $appendStyle], ['', ''], $imgstrNew);
  2941. }
  2942. // 移除img中多余的title属性
  2943. // $imgstrNew = preg_replace('/title(\s*)=(\s*)[\'|\"]([^\'\"]*)[\'|\"]/i', '', $imgstrNew);
  2944. // 追加alt属性
  2945. if (!empty($basicConfig['basic_img_alt'])) {
  2946. $altNew = $title."(图{$num})";
  2947. if (!empty($basicConfig['basic_img_alt_force'])) { // alt强制同步title
  2948. // 新增alt属性
  2949. $imgstrNew = preg_replace('/alt(\s*)=(\s*)[\'|\"]([^\'\"]*)[\'|\"]/i', '', $imgstrNew);
  2950. $imgstrNew = str_ireplace('<img', "<img alt=\"{$altNew}\" ", $imgstrNew);
  2951. } else {
  2952. $imgstrNew = preg_replace('/alt(\s*)=(\s*)[\'|\"]('.$imgname.')?[\'|\"]/i', 'alt="'.$altNew.'"', $imgstrNew);
  2953. if (!preg_match('/<img(.*?)alt(\s*)=(\s*)[\'|\"](.*?)[\'|\"](.*?)[\/]?(\s*)>/i', $imgstrNew)) {
  2954. // 新增alt属性
  2955. $imgstrNew = str_ireplace('<img', "<img alt=\"{$altNew}\" ", $imgstrNew);
  2956. }
  2957. }
  2958. }
  2959. // 追加title属性
  2960. if (!empty($basicConfig['basic_img_title'])) {
  2961. $titleNew = $title."(图{$num})";
  2962. $imgstrNew = preg_replace('/title(\s*)=(\s*)[\'|\"]('.$imgname.')?[\'|\"]/i', 'title="'.$titleNew.'"', $imgstrNew);
  2963. if (!preg_match('/<img(.*?)title(\s*)=(\s*)[\'|\"](.*?)[\'|\"](.*?)[\/]?(\s*)>/i', $imgstrNew)) {
  2964. // 新增title属性
  2965. $imgstrNew = str_ireplace('<img', "<img title=\"{$titleNew}\" ", $imgstrNew);
  2966. }
  2967. }
  2968. // 新的img替换旧的img
  2969. $content = str_ireplace($imgstr, $imgstrNew, $content);
  2970. $num++;
  2971. }
  2972. }
  2973. }
  2974. return $content;
  2975. }
  2976. }
  2977. if (!function_exists('get_archives_data'))
  2978. {
  2979. /**
  2980. * 查询文档主表信息和文档栏目表信息整合到一个数组中
  2981. * @param string $array 产品数组信息
  2982. * @param string $id 产品ID,购物车下单页传入aid,订单列表订单详情页传入product_id
  2983. * @return return array_new
  2984. */
  2985. function get_archives_data($array = [], $id = '')
  2986. {
  2987. // 目前定义订单中心和评论中使用
  2988. if (empty($array) || empty($id)) {
  2989. return false;
  2990. }
  2991. static $array_new = null;
  2992. if (null === $array_new) {
  2993. $aids = get_arr_column($array, $id);
  2994. $archivesList = \think\Db::name('archives')->field('*')->where('aid','IN',$aids)->select();
  2995. $typeids = get_arr_column($archivesList, 'typeid');
  2996. $arctypeList = \think\Db::name('arctype')->field('*')->where('id','IN',$typeids)->getAllWithIndex('id');
  2997. foreach ($archivesList as $key2 => $val2) {
  2998. $array_new[$val2['aid']] = array_merge($arctypeList[$val2['typeid']], $val2);
  2999. }
  3000. }
  3001. return $array_new;
  3002. }
  3003. }
  3004. if (!function_exists('SynchronizeQiniu'))
  3005. {
  3006. /**
  3007. * 参数说明:
  3008. * $images 本地图片地址
  3009. * $Qiniuyun 七牛云插件配置信息
  3010. * $is_tcp 是否携带协议
  3011. * 返回说明:
  3012. * return false 没有配置齐全
  3013. * return true 同步成功
  3014. */
  3015. function SynchronizeQiniu($images,$Qiniuyun=null,$is_tcp=false)
  3016. {
  3017. static $Qiniuyun = null;
  3018. // 若没有传入配信信息则读取数据库
  3019. if (null == $Qiniuyun) {
  3020. // 需要填写你的 Access Key 和 Secret Key
  3021. $data = M('weapp')->where('code','Qiniuyun')->field('data')->find();
  3022. $Qiniuyun = json_decode($data['data'], true);
  3023. }
  3024. /*支持子目录*/
  3025. $images = preg_replace('#^(/[/\w\-]+)?(/uploads/)#i', '$2', $images);
  3026. // 配置为空则返回原图片路径
  3027. if (empty($Qiniuyun) || empty($Qiniuyun['domain'])) {
  3028. return ROOT_DIR.$images;
  3029. }
  3030. //引入七牛云的相关文件
  3031. weapp_vendor('Qiniu.src.Qiniu.Auth', 'Qiniuyun');
  3032. weapp_vendor('Qiniu.src.Qiniu.Storage.UploadManager', 'Qiniuyun');
  3033. require_once ROOT_PATH.'weapp/Qiniuyun/vendor/Qiniu/autoload.php';
  3034. // 配置信息
  3035. $accessKey = $Qiniuyun['access_key'];
  3036. $secretKey = $Qiniuyun['secret_key'];
  3037. $bucket = $Qiniuyun['bucket'];
  3038. $domain = $Qiniuyun['domain'];
  3039. // 构建鉴权对象
  3040. $auth = new Qiniu\Auth($accessKey, $secretKey);
  3041. // 生成上传 Token
  3042. $token = $auth->uploadToken($bucket);
  3043. // 要上传文件的本地路径
  3044. $filePath = realpath('.'.$images);
  3045. // 上传到七牛后保存的文件名
  3046. $key = ltrim($images, '/');
  3047. // 初始化 UploadManager 对象并进行文件的上传。
  3048. $uploadMgr = new Qiniu\Storage\UploadManager;
  3049. // 调用 UploadManager 的 putFile 方法进行文件的上传。
  3050. list($ret, $err) = $uploadMgr->putFile($token, $key, $filePath);
  3051. // list($ret, $err) = $uploadMgr->put($token, $key, $filePath);
  3052. if (empty($err) || $err === null) {
  3053. $tcp = '//';
  3054. if ($is_tcp) {
  3055. $tcp = !empty($Qiniuyun['tcp']) ? $Qiniuyun['tcp'] : '';
  3056. switch ($tcp) {
  3057. case '2':
  3058. $tcp = 'https://';
  3059. break;
  3060. case '3':
  3061. $tcp = '//';
  3062. break;
  3063. case '1':
  3064. default:
  3065. $tcp = 'http://';
  3066. break;
  3067. }
  3068. }
  3069. $images = $tcp.$domain.'/'.ltrim($images, '/');
  3070. }
  3071. return [
  3072. 'state' => 'SUCCESS',
  3073. 'url' => $images,
  3074. ];
  3075. }
  3076. }
  3077. if (!function_exists('SynImageObjectBucket'))
  3078. {
  3079. /**
  3080. * 同步到第三方对象存储空间
  3081. * 参数说明:
  3082. * $images 本地图片地址
  3083. * $weappList 插件列表
  3084. */
  3085. function SynImageObjectBucket($images = '', $weappList = [], $fileziyuan = [])
  3086. {
  3087. $result = [];
  3088. if (empty($images)) {
  3089. return $result;
  3090. }
  3091. /*支持子目录*/
  3092. $images = preg_replace('#^(/[/\w\-]+)?(/uploads/|/public/static/)#i', '$2', $images);
  3093. if (empty($weappList)) {
  3094. $weappList = \think\Db::name('weapp')->where([
  3095. 'status' => 1,
  3096. ])->cache(true, EYOUCMS_CACHE_TIME, 'weapp')
  3097. ->getAllWithIndex('code');
  3098. }
  3099. if (!empty($weappList['Qiniuyun']) && 1 == $weappList['Qiniuyun']['status']) {
  3100. // 同步图片到七牛云
  3101. $weappConfig = json_decode($weappList['Qiniuyun']['config'], true);
  3102. if (!empty($weappConfig['version']) && 'v1.0.6' <= $weappConfig['version']) {
  3103. $qnyData = json_decode($weappList['Qiniuyun']['data'], true);
  3104. $qiniuyunOssModel = new \weapp\Qiniuyun\model\QiniuyunModel;
  3105. $ResultQny = $qiniuyunOssModel->Synchronize($qnyData, $images);
  3106. } else {
  3107. $ResultQny = SynchronizeQiniu($images);
  3108. }
  3109. // 数据覆盖
  3110. if (!empty($ResultQny) && is_array($ResultQny)) {
  3111. $result['local_save'] = !empty($qnyData['local_save']) ? $qnyData['local_save'] : '';
  3112. $result['state'] = !empty($ResultQny['state']) ? $ResultQny['state'] : '';
  3113. $result['url'] = !empty($ResultQny['url']) ? $ResultQny['url'] : '';
  3114. }
  3115. } else if (!empty($weappList['AliyunOss']) && 1 == $weappList['AliyunOss']['status']) {
  3116. // 同步图片到OSS
  3117. $ossData = json_decode($weappList['AliyunOss']['data'], true);
  3118. $aliyunOssModel = new \weapp\AliyunOss\model\AliyunOssModel;
  3119. $ResultOss = $aliyunOssModel->Synchronize($ossData, $images);
  3120. // 数据覆盖
  3121. if (!empty($ResultOss) && is_array($ResultOss)) {
  3122. $result['local_save'] = !empty($ossData['local_save']) ? $ossData['local_save'] : '';
  3123. $result['state'] = !empty($ResultOss['state']) ? $ResultOss['state'] : '';
  3124. $result['url'] = !empty($ResultOss['url']) ? $ResultOss['url'] : '';
  3125. }
  3126. } else if (!empty($weappList['Cos']) && 1 == $weappList['Cos']['status']) {
  3127. // 同步图片到COS
  3128. $CosData = json_decode($weappList['Cos']['data'], true);
  3129. $cosModel = new \weapp\Cos\model\CosModel;
  3130. $ResultCos = $cosModel->Synchronize($CosData, $images);
  3131. // 数据覆盖
  3132. if (!empty($ResultCos) && is_array($ResultCos)) {
  3133. $result['local_save'] = !empty($CosData['local_save']) ? $CosData['local_save'] : '';
  3134. $result['url'] = !empty($ResultCos['url']) ? $ResultCos['url'] : '';
  3135. $result['state'] = !empty($ResultCos['state']) ? $ResultCos['state'] : '';
  3136. }
  3137. }
  3138. return is_array($result) ? $result : [];
  3139. }
  3140. }
  3141. if (!function_exists('getWeappObjectBucket'))
  3142. {
  3143. /**
  3144. * 获取第三方对象存储插件的配置信息
  3145. * 参数说明:
  3146. * $weappList 插件列表
  3147. */
  3148. function getWeappObjectBucket()
  3149. {
  3150. $data = [];
  3151. $weappList = \think\Db::name('weapp')->where([
  3152. 'status' => 1,
  3153. ])->cache(true, EYOUCMS_CACHE_TIME, 'weapp')
  3154. ->getAllWithIndex('code');
  3155. if (!empty($weappList['Qiniuyun']) && 1 == $weappList['Qiniuyun']['status']) {
  3156. // 七牛云
  3157. $data = json_decode($weappList['Qiniuyun']['data'], true);
  3158. } else if (!empty($weappList['AliyunOss']) && 1 == $weappList['AliyunOss']['status']) {
  3159. // OSS
  3160. $data = json_decode($weappList['AliyunOss']['data'], true);
  3161. } else if (!empty($weappList['Cos']) && 1 == $weappList['Cos']['status']) {
  3162. // COS
  3163. $data = json_decode($weappList['Cos']['data'], true);
  3164. }
  3165. return is_array($data) ? $data : [];
  3166. }
  3167. }
  3168. if (!function_exists('getAllChild'))
  3169. {
  3170. /**
  3171. * 递归查询所有的子类
  3172. * @param array $arctype_child_all 存放所有的子栏目
  3173. * @param int $id 栏目ID 或 父栏目ID
  3174. * @param int $type 1=栏目,2=文章
  3175. */
  3176. function getAllChild(&$arctype_child_all,$id,$type = 1){
  3177. if($type == 1){
  3178. $arctype_child = \think\Db::name('arctype')->where(['is_del'=>0,'status'=>1,'parent_id'=>$id])->getfield('id',true);
  3179. }else{
  3180. $where['is_del'] = 0;
  3181. $where['status'] = 1;
  3182. $where['parent_id'] = $id;
  3183. $where['current_channel'] = array(array('neq',6),array('neq',8));
  3184. $arctype_child = \think\Db::name('arctype')->where($where)->getfield('id',true);
  3185. }
  3186. if(!empty($arctype_child)){
  3187. $arctype_child_all = array_merge($arctype_child_all,$arctype_child);
  3188. for($i=0;$i<count($arctype_child);$i++){
  3189. getAllChild($arctype_child_all,$arctype_child[$i],$type);
  3190. }
  3191. }
  3192. }
  3193. }
  3194. if (!function_exists('getAllChildByList'))
  3195. {
  3196. /**
  3197. * 生成栏目页面时获取同模型下级
  3198. * @param array $arctype_child_all 存放所有的子栏目
  3199. * @param int $id 栏目ID 或 父栏目ID
  3200. * @param int $current_channel 当前栏目的模型ID
  3201. */
  3202. function getAllChildByList(&$arctype_child_all,$id,$current_channel){
  3203. $arctype_child = \think\Db::name('arctype')->where(['is_del'=>0,'status'=>1,'parent_id'=>$id,'current_channel'=>$current_channel])->getfield('id',true);
  3204. if(!empty($arctype_child)){
  3205. $arctype_child_all = array_merge($arctype_child_all,$arctype_child);
  3206. for($i=0;$i<count($arctype_child);$i++){
  3207. getAllChild($arctype_child_all,$arctype_child[$i]);
  3208. }
  3209. }
  3210. }
  3211. }
  3212. if (!function_exists('getAllChildArctype'))
  3213. {
  3214. //递归查询所有的子类
  3215. function getAllChildArctype(&$arctype_child_all,$id){
  3216. $where['a.is_del'] = 0;
  3217. $where['a.status'] = 1;
  3218. $where['a.parent_id'] = $id;
  3219. $arctype_child = \think\Db::name('arctype')->field('c.*, a.*, a.id as typeid')
  3220. ->alias('a')
  3221. ->join('__CHANNELTYPE__ c', 'c.id = a.current_channel', 'LEFT')
  3222. ->where($where)
  3223. ->select();
  3224. if(!empty($arctype_child)){
  3225. $arctype_child_all = array_merge($arctype_child,$arctype_child_all);
  3226. for($i=0;$i<count($arctype_child);$i++){
  3227. getAllChildArctype($arctype_child_all,$arctype_child[$i]['typeid']);
  3228. }
  3229. }
  3230. }
  3231. }
  3232. if (!function_exists('getAllArctype'))
  3233. {
  3234. /*
  3235. * 递归查询所有栏目
  3236. * $home_lang 语言
  3237. * $id 栏目id 存在则获取指定的栏目,不存在获取全部
  3238. * $parent 是否获取下级栏目 true:获取,false:不获取
  3239. * $aid
  3240. */
  3241. function getAllArctype($home_lang,$id,$view_suffix,$parent = true,$aid = 0){
  3242. $map = [];
  3243. if (!empty($id)){
  3244. if (is_array($id)) {
  3245. $map['a.id'] = ['IN', $id];
  3246. } else {
  3247. $map['a.id'] = $id;
  3248. }
  3249. }
  3250. $map['a.lang'] = $home_lang;
  3251. $map['a.is_del'] = 0;
  3252. $map['a.status'] = 1;
  3253. $info = \think\Db::name('arctype')->field('c.*, a.*, a.id as typeid')
  3254. ->alias('a')
  3255. ->join('__CHANNELTYPE__ c', 'c.id = a.current_channel', 'LEFT')
  3256. ->where($map)
  3257. ->order("a.grade desc")
  3258. ->cache(true,EYOUCMS_CACHE_TIME,"arctype")
  3259. ->select();
  3260. if (!empty($id) && $parent && $aid == 0) { // $aid > 0 表示栏目生成不生成子栏目
  3261. getAllChildArctype($info,$id);
  3262. }
  3263. $info = getAllArctypeCount($home_lang,$info,$id,$view_suffix,$aid);
  3264. return $info;
  3265. }
  3266. }
  3267. if (!function_exists('arctypeAllSub'))
  3268. {
  3269. /**
  3270. * 获取所有栏目,并每个栏目都包含所有子栏目,以及自己
  3271. * @param boolean $self [description]
  3272. * @return [type] [description]
  3273. */
  3274. function arctypeAllSub($typeid = 0, $self = true)
  3275. {
  3276. $lang = get_current_lang();
  3277. $cacheKey = md5("common_arctypeAllSub_{$typeid}_{$self}_{$lang}");
  3278. $data = cache($cacheKey);
  3279. if (empty($data)) {
  3280. $where = [];
  3281. $where['c.lang'] = $lang; // 多语言 by 小虎哥
  3282. $where['c.is_del'] = 0; // 回收站功能
  3283. $where['c.status'] = 1;
  3284. /*所有栏目分类*/
  3285. $fields = "c.id, c.parent_id, c.current_channel, c.grade";
  3286. $res = $res2 = \think\Db::name('arctype')
  3287. ->field($fields)
  3288. ->alias('c')
  3289. ->where($where)
  3290. ->order('c.grade desc, c.id asc')
  3291. ->select();
  3292. if (empty($res)) return [];
  3293. $data = [];
  3294. foreach ($res as $key => $val) {
  3295. if (in_array($val['current_channel'], [51]) || !empty($val['weapp_code'])) {
  3296. continue;
  3297. }
  3298. // 当前栏目
  3299. if (!isset($data[$val['id']])) {
  3300. $data[$val['id']] = [$val['id']];
  3301. } else {
  3302. $data[$val['id']][] = $val['id'];
  3303. $data[$val['id']] = array_unique($data[$val['id']]);
  3304. }
  3305. // 父级栏目
  3306. if (!isset($data[$val['parent_id']])) {
  3307. $data[$val['parent_id']] = [$val['parent_id']];
  3308. } else {
  3309. $data[$val['parent_id']][] = $val['id'];
  3310. }
  3311. if (!empty($data[$val['id']])) {
  3312. $data[$val['parent_id']] = array_merge($data[$val['parent_id']], $data[$val['id']]);
  3313. }
  3314. $data[$val['parent_id']] = array_unique($data[$val['parent_id']]);
  3315. }
  3316. if (isset($data[0])) unset($data[0]);
  3317. if (false === $self) {
  3318. foreach ($data as $key => $val) {
  3319. $indx = array_search($key, $val);
  3320. if (false !== $indx) {
  3321. unset($val[$indx]);
  3322. }
  3323. if (!empty($val)) {
  3324. $val = array_merge($val);
  3325. }
  3326. $data[$key] = $val;
  3327. }
  3328. }
  3329. cache($cacheKey, $data, null, "arctype");
  3330. }
  3331. return !empty($typeid) ? $data[$typeid] : $data;
  3332. }
  3333. }
  3334. if (!function_exists('getAllArctypeCount'))
  3335. {
  3336. /*
  3337. * 获取所有栏目数据条数,所有aid集合
  3338. * 获取需要生成的栏目页的静态文件的个数 缓存到channel_page_total
  3339. */
  3340. function getAllArctypeCount($home_lang,$info,$id = 0,$view_suffix = ".htm",$aid = 0)
  3341. {
  3342. /**
  3343. * 这里统计每个栏目的文档数有两种方法
  3344. * 1、当文档数量少于10W时,执行第一种方法,在循环外部查询一条sql统计出栏目的文档数
  3345. * 2、当文档数量大于10W时,执行第二种方法,在循环里面每次执行一个统计当前栏目的文档数sql
  3346. * @var integer
  3347. */
  3348. $method_mode = 1; // 默认是第一种方法
  3349. $max_aid = \think\Db::name('archives')->max('aid'); // 取出文档的最大数量,已最大文档ID来大概计算
  3350. if ($max_aid > 100000) {
  3351. $method_mode = 2;
  3352. }
  3353. $map_arc = [];
  3354. // 是否更新子栏目
  3355. $seo_upnext = tpCache('seo.seo_upnext');
  3356. $web_stypeid_open = tpCache('web.web_stypeid_open'); // 是否开启副栏目
  3357. if (1 == $method_mode && $id) {
  3358. if (empty($web_stypeid_open)) {
  3359. $map_arc['typeid'] = array('in',get_arr_column($info,'typeid'));
  3360. } else {
  3361. $typeids_tmp = get_arr_column($info,'typeid');
  3362. $typeids_tmp = implode(',', $typeids_tmp);
  3363. $map_arc[] = \think\Db::raw(" ( typeid IN ({$typeids_tmp}) OR CONCAT(',', stypeid, ',') LIKE '%,{$id},%' ) ");
  3364. }
  3365. }
  3366. // 可发布文档列表的频道模型
  3367. static $new_channel = null;
  3368. if (null === $new_channel) {
  3369. $allow_release_channel = config('global.allow_release_channel');
  3370. $arctypeRow = \think\Db::name('arctype')->field('channeltype,current_channel')->select();
  3371. foreach ($arctypeRow as $key => $val) {
  3372. if (in_array($val['channeltype'], $allow_release_channel)) {
  3373. $new_channel[] = $val['channeltype'];
  3374. }
  3375. if (in_array($val['current_channel'], $allow_release_channel)) {
  3376. $new_channel[] = $val['current_channel'];
  3377. }
  3378. }
  3379. $new_channel = array_unique($new_channel);
  3380. }
  3381. !empty($new_channel) && $map_arc['a.channel'] = ['IN', $new_channel];
  3382. $map_arc['a.arcrank'] = ['egt', 0];
  3383. $map_arc['a.status'] = 1;
  3384. $map_arc['a.is_del'] = 0;
  3385. $map_arc['a.lang'] = $home_lang;
  3386. /*定时文档显示插件*/
  3387. if (is_dir('./weapp/TimingTask/')) {
  3388. $TimingTaskRow = model('Weapp')->getWeappList('TimingTask');
  3389. if (!empty($TimingTaskRow['status']) && 1 == $TimingTaskRow['status']) {
  3390. $map_arc['a.add_time'] = array('elt', getTime()); // 只显当天或之前的文档
  3391. }
  3392. }
  3393. /*end*/
  3394. if (1 == $method_mode) { // 方法1
  3395. $count_type = [];
  3396. $archivesList = \think\Db::name('archives')->alias('a')->field("typeid,stypeid")->where($map_arc)->order('typeid asc')->select();
  3397. foreach ($archivesList as $key => $val) {
  3398. if (!isset($count_type[$val['typeid']])) {
  3399. $count_type[$val['typeid']] = [
  3400. 'typeid' => $val['typeid'],
  3401. 'count' => 1,
  3402. ];
  3403. } else {
  3404. $count_type[$val['typeid']]['count']++;
  3405. }
  3406. // 开启副栏目
  3407. if (!empty($web_stypeid_open) && !empty($val['stypeid'])) {
  3408. $stypeids = explode(',', $val['stypeid']);
  3409. $arr_index = array_search($val['typeid'], $stypeids);
  3410. if (is_numeric($arr_index) && 0 <= $arr_index) {
  3411. unset($stypeids[$arr_index]);
  3412. }
  3413. foreach ($stypeids as $_k => $_v) {
  3414. if (!isset($count_type[$_v])) {
  3415. $count_type[$_v] = [
  3416. 'typeid' => $_v,
  3417. 'count' => 1,
  3418. ];
  3419. } else {
  3420. $count_type[$_v]['count']++;
  3421. }
  3422. }
  3423. }
  3424. }
  3425. }
  3426. $db = new \think\Db;
  3427. $pagetotal = 0;
  3428. $arctypeAllSub = arctypeAllSub(); // 获取所有栏目,并每个栏目都包含所有子栏目,以及自己
  3429. $info2 = $tplData = [];
  3430. $info = convert_arr_key($info,'typeid');
  3431. foreach ($info as $k => $v) {
  3432. //外链
  3433. if ($v['is_part'] == 1 || 'ask' == $v['nid']) {
  3434. $dir = ROOT_PATH . trim($v['dirpath'], '/');
  3435. if (!empty($v['dirpath']) && true == is_dir($dir)) {//判断是否生成过文件夹,文件夹存在则删除
  3436. deldir_html($dir);
  3437. }
  3438. continue;
  3439. }
  3440. if (1 == $method_mode) { // 方法1
  3441. if (!isset($info[$v['typeid']]['count'])){ //判断当前栏目的count是否已经存在
  3442. $v['count'] = 0;
  3443. }else{
  3444. $v['count'] = intval($info[$v['typeid']]['count']);
  3445. }
  3446. if (isset($count_type[$v['typeid']])){ //存在当前栏目个数
  3447. $v['count'] += $count_type[$v['typeid']]['count'];
  3448. }
  3449. //判断是否存在上级目录,且当前栏目和上级栏目都不是单页,且当前栏目和上级栏目是相同模型,则,把当前栏目的aid和count赋值给父栏目
  3450. if ($v['parent_id'] && !in_array($v['current_channel'], [6,8]) && isset($info[$v['parent_id']]) && $v['current_channel'] == $info[$v['parent_id']]['current_channel']){
  3451. if (isset($info[$v['parent_id']]['count'])) {
  3452. $info[$v['parent_id']]['count'] += intval($v['count']);
  3453. }else{
  3454. $info[$v['parent_id']]['count'] = intval($v['count']);
  3455. }
  3456. }
  3457. }
  3458. /**
  3459. * 判断是否需要更新子栏目
  3460. * 1、更新子栏目,正常处理
  3461. * 2、不更新子栏目
  3462. * (1)、选择指定栏目的情况下,判断当前栏目是否为选择栏目,如果是,走正常流程,否则,去掉当前栏目
  3463. * (2)、不选择指定栏目的情况下,判断当前栏目是否为顶级栏目,如果是,走正常流程,否则,去掉当前栏目
  3464. */
  3465. if (empty($seo_upnext) && ( (!empty($id) && $v['typeid'] != $id) || (empty($id) && !empty($v['parent_id'])) ) ){
  3466. continue;
  3467. }
  3468. $tag_attr_arr = [];
  3469. if (!isset($tplData[$v['templist']])) {
  3470. $tpl = !empty($v['templist']) ? str_replace('.'.$view_suffix, '',$v['templist']) : 'lists_'. $v['nid'];
  3471. $template_html = "./template/".TPL_THEME."pc/".$tpl.".htm";
  3472. $content = @file_get_contents($template_html);
  3473. if ($content) {
  3474. preg_match_all('/\{eyou:list(\s+)?(.*)\}/i', $content, $matchs);
  3475. if (!empty($matchs[0][0])) {
  3476. $tag_attr = !empty($matchs[2][0]) ? $matchs[2][0] : '';
  3477. if (!empty($tag_attr)) {
  3478. $tag_attr = preg_replace('/([a-z]+)(\s*)=(\s*)([\'|\"]?)([^ \f\n\r\t\v\'\"]+)([\'|\"]?)/i', '${1}=\'${5}\'', $tag_attr); // 属性引导统一设置单引号
  3479. preg_match_all('/([0-9a-z_-]+)=\'([^\']+)\'/i', $tag_attr, $attr_matchs);
  3480. $attr_keys = !empty($attr_matchs[1]) ? $attr_matchs[1] : [];
  3481. $attr_vals = !empty($attr_matchs[2]) ? $attr_matchs[2] : [];
  3482. if (!empty($attr_keys)) {
  3483. foreach ($attr_keys as $_ak => $_av) {
  3484. $tag_attr_arr[$_av] = $attr_vals[$_ak];
  3485. }
  3486. // 每页条数
  3487. if (!empty($tag_attr_arr['loop'])) $tag_attr_arr['pagesize'] = intval($tag_attr_arr['loop']);
  3488. $tag_attr_arr['pagesize'] = !empty($tag_attr_arr['pagesize']) ? intval($tag_attr_arr['pagesize']) : 10;
  3489. // 模型ID
  3490. if (!empty($tag_attr_arr['modelid'])) $tag_attr_arr['channelid'] = intval($tag_attr_arr['modelid']);
  3491. // 排序
  3492. if (empty($tag_attr_arr['ordermode'])) {
  3493. if (!empty($tag['orderWay'])) {
  3494. $tag_attr_arr['ordermode'] = $tag_attr_arr['orderWay'];
  3495. } else {
  3496. $tag_attr_arr['ordermode'] = !empty($tag_attr_arr['orderway']) ? $tag_attr_arr['orderway'] : 'desc';
  3497. }
  3498. }
  3499. }
  3500. }
  3501. $tag_attr_arr['orderby'] = !empty($tag_attr_arr['orderby']) ? $tag_attr_arr['orderby'] : "";
  3502. $tag_attr_arr['ordermode'] = !empty($tag_attr_arr['ordermode']) ? $tag_attr_arr['ordermode'] : "desc";
  3503. $tplData[$v['templist']] = $tag_attr_arr;
  3504. } else {
  3505. $tplData[$v['templist']]['count'] = -1;
  3506. }
  3507. }
  3508. }
  3509. $tplDataInfo = !empty($tplData[$v['templist']]) ? $tplData[$v['templist']] : [];
  3510. if (2 == $method_mode) { // 方法2
  3511. $map_arc2 = $map_arc;
  3512. if (empty($web_stypeid_open)) { // 没开启副栏目
  3513. $map_arc2['a.typeid'] = array('in', $arctypeAllSub[$v['typeid']]);
  3514. } else { // 开启副栏目
  3515. $stypeid_where = "";
  3516. $typeid_str = implode(',', $arctypeAllSub[$v['typeid']]);
  3517. foreach ($arctypeAllSub[$v['typeid']] as $_k => $_v) {
  3518. $stypeid_where .= " OR CONCAT(',', a.stypeid, ',') LIKE '%,{$_v},%' ";
  3519. }
  3520. $map_arc2[] = $db::raw(" (a.typeid IN ({$typeid_str}) {$stypeid_where}) ");
  3521. }
  3522. $v['count'] = 0;
  3523. if (!in_array($v['current_channel'], [6,8])) {
  3524. $v['count'] = $db::name('archives')->alias('a')->where($map_arc2)->count('aid');
  3525. }
  3526. }
  3527. if (in_array($v['current_channel'], [6,8])){
  3528. $v['pagesize'] = 1;
  3529. $v['pagetotal'] = 1;
  3530. $pagetotal += $v['pagetotal'];
  3531. }else{
  3532. if (!empty($tplDataInfo)) {
  3533. $count = !empty($tplDataInfo['count']) ? $tplDataInfo['count'] : 0;
  3534. if (-1 == $count) {
  3535. $v['count'] = 1;
  3536. } else {
  3537. $pagesize = !empty($tplDataInfo['pagesize']) ? $tplDataInfo['pagesize'] : 0;
  3538. $channelid = !empty($tplDataInfo['channelid']) ? $tplDataInfo['channelid'] : 0;
  3539. if (!empty($channelid)) {
  3540. $map_arc['a.channel'] = $channelid;
  3541. if (isset($map_arc['a.typeid'])) {
  3542. unset($map_arc['a.typeid']);
  3543. }
  3544. if (isset($map_arc[0])) {
  3545. foreach ($map_arc as $_k => $_v) {
  3546. if (is_numeric($_k) && stristr($_v, 'stypeid')) {
  3547. unset($map_arc[$_k]);
  3548. }
  3549. }
  3550. }
  3551. $v['count'] = $db::name('archives')->alias('a')->where($map_arc)->count();
  3552. }
  3553. if ($aid) {
  3554. $orderby = !empty($tplDataInfo['orderby']) ? $tplDataInfo['orderby'] : '';
  3555. $ordermode = !empty($tplDataInfo['ordermode']) ? $tplDataInfo['ordermode'] : 'desc';
  3556. }
  3557. }
  3558. }
  3559. $v['pagesize'] = !empty($pagesize) ? $pagesize : 10;
  3560. $v['pagetotal'] = !empty($v['count']) ? (int)ceil($v['count'] / $v['pagesize']) : 1;
  3561. $pagetotal += $v['pagetotal'];
  3562. }
  3563. $v['orderby'] = !empty($orderby) ? $orderby : "";
  3564. $v['ordermode'] = !empty($ordermode) ? $ordermode : "desc";
  3565. $info2[] = $v;
  3566. }
  3567. return ["info"=>$info2, "pagetotal"=>$pagetotal];
  3568. }
  3569. }
  3570. /**
  3571. * 删除文件夹
  3572. * @param $dir
  3573. * @return bool
  3574. */
  3575. if (!function_exists('deldir_html'))
  3576. {
  3577. function deldir_html($dir = '')
  3578. {
  3579. //先删除目录下的文件:
  3580. $fileArr = glob($dir.'/*.html');
  3581. if (!empty($fileArr)) {
  3582. foreach ($fileArr as $key => $val) {
  3583. !empty($val) && @unlink($val);
  3584. }
  3585. }
  3586. $fileArr = glob($dir.'/*');
  3587. if(empty($fileArr)){ //目录为空
  3588. rmdir($dir); // 删除空目录
  3589. }
  3590. return true;
  3591. }
  3592. }
  3593. /*
  3594. * 以下几个方法为生成静态时使用
  3595. * 获取所有需要生成的文档的aid集合
  3596. * $typeid 栏目id
  3597. * $startid 起始ID(空或0表示从头开始)
  3598. * $endid 结束ID(空或0表示直到结束ID)
  3599. */
  3600. if (!function_exists('getAllArchivesAid'))
  3601. {
  3602. function getAllArchivesAid($typeid = 0, $home_lang = '', $startid = 0,$endid = 0){
  3603. empty($home_lang) && $home_lang = get_current_lang();
  3604. $map = [];
  3605. if (!empty($typeid)){
  3606. $id_arr = [$typeid];
  3607. getAllChild($id_arr,$typeid,2);
  3608. $map['typeid'] = ['in',$id_arr];
  3609. }
  3610. if (!empty($startid) && !empty($endid)){
  3611. $map['aid'] = ['between',[$startid,$endid]];
  3612. }else if(!empty($startid)){
  3613. $map['aid'] = ['egt',$startid];
  3614. }else if(!empty($endid)){
  3615. $map['aid'] = ['elt',$endid];
  3616. }
  3617. // 可发布文档列表的频道模型
  3618. static $new_channel = null;
  3619. if (null === $new_channel) {
  3620. $allow_release_channel = config('global.allow_release_channel');
  3621. $arctypeRow = \think\Db::name('arctype')->field('channeltype,current_channel')->select();
  3622. foreach ($arctypeRow as $key => $val) {
  3623. if (in_array($val['channeltype'], $allow_release_channel)) {
  3624. $new_channel[] = $val['channeltype'];
  3625. }
  3626. if (in_array($val['current_channel'], $allow_release_channel)) {
  3627. $new_channel[] = $val['current_channel'];
  3628. }
  3629. }
  3630. $new_channel = array_unique($new_channel);
  3631. }
  3632. !empty($new_channel) && $map['channel'] = ['IN', $new_channel];
  3633. $map['arcrank'] = ['egt', 0];
  3634. $map['status'] = 1;
  3635. $map['is_del'] = 0;
  3636. $map['lang'] = $home_lang;
  3637. /*定时文档显示插件*/
  3638. if (is_dir('./weapp/TimingTask/')) {
  3639. $TimingTaskRow = model('Weapp')->getWeappList('TimingTask');
  3640. if (!empty($TimingTaskRow['status']) && 1 == $TimingTaskRow['status']) {
  3641. $map['add_time'] = array('elt', getTime()); // 只显当天或之前的文档
  3642. }
  3643. }
  3644. /*end*/
  3645. $row = \think\Db::name('archives')
  3646. ->field('aid,typeid,channel')
  3647. ->where($map)
  3648. ->order('aid asc')
  3649. ->select();
  3650. $aid_arr = $typeid_arr = $channel_arr = [];
  3651. foreach ($row as $key => $val) {
  3652. array_push($aid_arr, $val['aid']);
  3653. if (!in_array($val['typeid'], $typeid_arr)) {
  3654. array_push($typeid_arr, $val['typeid']);
  3655. }
  3656. $channel_arr[$val['channel']][] = $val['aid'];
  3657. }
  3658. return [
  3659. 'aid_arr' => $aid_arr,
  3660. 'typeid_arr' => $typeid_arr, // 文档所涉及的栏目ID
  3661. 'channel_arr' => $channel_arr, // 文档以模型ID分组
  3662. ];
  3663. }
  3664. }
  3665. if (!function_exists('getAllArchives'))
  3666. {
  3667. //递归查询所有栏目
  3668. function getAllArchives($home_lang,$id,$aid = ''){
  3669. $map = [];
  3670. if(!empty($aid)){
  3671. if (is_array($aid)) {
  3672. $map['a.aid'] = ['in',$aid];
  3673. } else {
  3674. $map['a.aid'] = $aid;
  3675. }
  3676. }else if (!empty($id)){
  3677. $id_arr = [$id];
  3678. getAllChild($id_arr,$id,2);
  3679. $map['a.typeid'] = ['in',$id_arr];
  3680. }
  3681. // 可发布文档列表的频道模型
  3682. $new_channel = cache("application_common_getAllArchives_new_channel");
  3683. if(empty($new_channel)){
  3684. $new_channel = [];
  3685. $allow_release_channel = config('global.allow_release_channel');
  3686. $arctypeList = \think\Db::name('arctype')->field('channeltype,current_channel')->select();
  3687. foreach ($arctypeList as $key => $val) {
  3688. if (in_array($val['channeltype'], $allow_release_channel)) {
  3689. $new_channel[] = $val['channeltype'];
  3690. }
  3691. if (in_array($val['current_channel'], $allow_release_channel)) {
  3692. $new_channel[] = $val['current_channel'];
  3693. }
  3694. }
  3695. $new_channel = array_unique($new_channel);
  3696. cache("application_common_getAllArchives_new_channel", $new_channel, null, 'arctype');
  3697. }
  3698. !empty($new_channel) && $map['a.channel'] = ['IN', $new_channel];
  3699. $map['a.is_jump'] = 0;
  3700. $map['a.status'] = 1;
  3701. $map['a.is_del'] = 0;
  3702. $map['a.lang'] = $home_lang;
  3703. $info = \think\Db::name('archives')->field('a.*')
  3704. ->alias('a')
  3705. ->where($map)
  3706. ->select();
  3707. $info = getAllContent($info);
  3708. /*栏目信息*/
  3709. $arctypeRow = cache("application_common_getAllArchives_arctypeRow");
  3710. if(empty($arctypeRow)){
  3711. $arctypeRow = \think\Db::name('arctype')->field('c.*, a.*, a.id as typeid')
  3712. ->alias('a')
  3713. ->where(['a.lang'=>$home_lang])
  3714. ->join('__CHANNELTYPE__ c', 'c.id = a.current_channel', 'LEFT')
  3715. ->getAllWithIndex('typeid');
  3716. cache("application_common_getAllArchives_arctypeRow", $arctypeRow, null, 'arctype');
  3717. }
  3718. return [
  3719. 'info' => $info,
  3720. 'arctypeRow' => $arctypeRow,
  3721. ];
  3722. }
  3723. }
  3724. if (!function_exists('getPreviousArchives'))
  3725. {
  3726. //获取上一条文章数据
  3727. function getPreviousArchives($home_lang,$id,$aid = 0){
  3728. $map = [];
  3729. if(!empty($aid)){
  3730. $map['a.aid'] = ['lt',$aid];
  3731. }
  3732. if (!empty($id)){
  3733. $id_arr = [$id];
  3734. getAllChild($id_arr,$id,2);
  3735. $map['a.typeid'] = ['in',$id_arr];
  3736. }
  3737. // 可发布文档列表的频道模型
  3738. static $new_channel = null;
  3739. if (null === $new_channel) {
  3740. $allow_release_channel = config('global.allow_release_channel');
  3741. $arctypeRow = \think\Db::name('arctype')->field('channeltype,current_channel')->select();
  3742. foreach ($arctypeRow as $key => $val) {
  3743. if (in_array($val['channeltype'], $allow_release_channel)) {
  3744. $new_channel[] = $val['channeltype'];
  3745. }
  3746. if (in_array($val['current_channel'], $allow_release_channel)) {
  3747. $new_channel[] = $val['current_channel'];
  3748. }
  3749. }
  3750. $new_channel = array_unique($new_channel);
  3751. }
  3752. !empty($new_channel) && $map['a.channel'] = ['IN', $new_channel];
  3753. $map['a.lang'] = $home_lang;
  3754. $map['a.is_jump'] = 0;
  3755. $map['a.is_del'] = 0;
  3756. $map['a.status'] = 1;
  3757. $info = \think\Db::name('archives')->field('a.*')
  3758. ->alias('a')
  3759. ->where($map)
  3760. ->order("a.aid desc")
  3761. ->limit(1)
  3762. ->select();
  3763. $info = getAllContent($info);
  3764. /*栏目信息*/
  3765. $arctypeRow = \think\Db::name('arctype')->field('c.*, a.*, a.id as typeid')
  3766. ->alias('a')
  3767. ->where(['a.lang'=>$home_lang])
  3768. ->join('__CHANNELTYPE__ c', 'c.id = a.current_channel', 'LEFT')
  3769. ->cache(true,EYOUCMS_CACHE_TIME,"arctype")
  3770. ->getAllWithIndex('typeid');
  3771. return [
  3772. 'info' => $info,
  3773. 'arctypeRow' => $arctypeRow,
  3774. ];
  3775. }
  3776. }
  3777. if (!function_exists('getNextArchives'))
  3778. {
  3779. //获取下一条文章数据
  3780. function getNextArchives($home_lang,$id,$aid = 0){
  3781. $map = [];
  3782. if(!empty($aid)){
  3783. $map['a.aid'] = ['gt',$aid];
  3784. }
  3785. if (!empty($id)){
  3786. $id_arr = [$id];
  3787. getAllChild($id_arr,$id,2);
  3788. $map['a.typeid'] = ['in',$id_arr];
  3789. }
  3790. // 可发布文档列表的频道模型
  3791. static $new_channel = null;
  3792. if (null === $new_channel) {
  3793. $allow_release_channel = config('global.allow_release_channel');
  3794. $arctypeRow = \think\Db::name('arctype')->field('channeltype,current_channel')->select();
  3795. foreach ($arctypeRow as $key => $val) {
  3796. if (in_array($val['channeltype'], $allow_release_channel)) {
  3797. $new_channel[] = $val['channeltype'];
  3798. }
  3799. if (in_array($val['current_channel'], $allow_release_channel)) {
  3800. $new_channel[] = $val['current_channel'];
  3801. }
  3802. }
  3803. $new_channel = array_unique($new_channel);
  3804. }
  3805. !empty($new_channel) && $map['a.channel'] = ['IN', $new_channel];
  3806. $map['a.lang'] = $home_lang;
  3807. $map['a.is_jump'] = 0;
  3808. $map['a.is_del'] = 0;
  3809. $map['a.status'] = 1;
  3810. $info = \think\Db::name('archives')->field('a.*')
  3811. ->alias('a')
  3812. ->where($map)
  3813. ->order("a.aid asc")
  3814. ->limit(1)
  3815. ->select();
  3816. $info = getAllContent($info);
  3817. /*栏目信息*/
  3818. $arctypeRow = \think\Db::name('arctype')->field('c.*, a.*, a.id as typeid')
  3819. ->alias('a')
  3820. ->where(['a.lang'=>$home_lang])
  3821. ->join('__CHANNELTYPE__ c', 'c.id = a.current_channel', 'LEFT')
  3822. ->cache(true,EYOUCMS_CACHE_TIME,"arctype")
  3823. ->getAllWithIndex('typeid');
  3824. return [
  3825. 'info' => $info,
  3826. 'arctypeRow' => $arctypeRow,
  3827. ];
  3828. }
  3829. }
  3830. if (!function_exists('getAllContent'))
  3831. {
  3832. //获取指定文档列表的内容附加表字段值
  3833. function getAllContent($archivesList = []){
  3834. $contentList = [];
  3835. $db = new \think\Db;
  3836. $channeltype_list = config('global.channeltype_list');
  3837. $arr = group_same_key($archivesList, 'channel');
  3838. foreach ($arr as $nid => $list) {
  3839. $table = array_search($nid, $channeltype_list);
  3840. if (!empty($table)) {
  3841. $aids = get_arr_column($list, 'aid');
  3842. $row = $db::name($table.'_content')->field('*')
  3843. ->where(['aid'=>['IN', $aids]])
  3844. ->select();
  3845. $result = [];
  3846. foreach ($row as $_k => $_v) {
  3847. unset($_v['id']);
  3848. unset($_v['add_time']);
  3849. unset($_v['update_time']);
  3850. $result[$_v['aid']] = $_v;
  3851. }
  3852. $contentList += $result;
  3853. }
  3854. }
  3855. $firstFieldData = current($contentList);
  3856. foreach ($archivesList as $key => $val) {
  3857. /*文档所属模型是不存在,或已被禁用*/
  3858. $table = array_search($val['channel'], $channeltype_list);
  3859. if (empty($table)) {
  3860. unset($archivesList[$key]);
  3861. continue;
  3862. }
  3863. /*end*/
  3864. /*文档内容表没有记录的特殊情况*/
  3865. if (!isset($contentList[$val['aid']])) {
  3866. $contentList[$val['aid']] = [];
  3867. if (!empty($firstFieldData)) {
  3868. foreach ($firstFieldData as $k2 => $v2) {
  3869. if (in_array($k2, ['aid'])) {
  3870. $contentList[$val['aid']][$k2] = $val[$k2];
  3871. } else {
  3872. $contentList[$val['aid']][$k2] = '';
  3873. }
  3874. }
  3875. }
  3876. }
  3877. /*end*/
  3878. $val = array_merge($val, $contentList[$val['aid']]);
  3879. $archivesList[$key] = $val;
  3880. }
  3881. return $archivesList;
  3882. }
  3883. }
  3884. if (!function_exists('getAllTags'))
  3885. {
  3886. //递归查询所有栏目内容
  3887. function getAllTags($aid_arr = []){
  3888. $map = [];
  3889. $info = [];
  3890. if (!empty($aid_arr)){
  3891. $map['aid'] = ['in',$aid_arr];
  3892. }
  3893. $result = \think\Db::name('taglist')->field("aid,tag")->where($map)->select();
  3894. if ($result) {
  3895. foreach ($result as $key => $val) {
  3896. if (!isset($info[$val['aid']])) $info[$val['aid']] = array();
  3897. array_push($info[$val['aid']], $val['tag']);
  3898. }
  3899. }
  3900. return $info;
  3901. }
  3902. }
  3903. if (!function_exists('getAllAttrInfo'))
  3904. {
  3905. /**
  3906. * 查询所有文档的其他页面内容
  3907. * @param array $channel_aids_arr [以模型ID分组的文档ID]
  3908. * @return [type] [description]
  3909. */
  3910. function getAllAttrInfo($channel_aids_arr = []){
  3911. $info = [];
  3912. foreach ($channel_aids_arr as $channel => $aids) {
  3913. if (2 == $channel) {
  3914. $ProductImg = new \app\home\model\ProductImg;
  3915. $info['product_img'] = $ProductImg->getProImg($aids);
  3916. $ProductAttr = new \app\home\model\ProductAttr;
  3917. $info['product_attr'] = $ProductAttr->getProAttr($aids);
  3918. } else if (3 == $channel) {
  3919. $ImagesUpload = new \app\home\model\ImagesUpload;
  3920. $info['images_upload'] = $ImagesUpload->getImgUpload($aids);
  3921. } else if (4 == $channel) {
  3922. $DownloadFile = new \app\home\model\DownloadFile;
  3923. $info['download_file'] = $DownloadFile->getDownFile($aids);
  3924. }
  3925. }
  3926. return $info;
  3927. }
  3928. }
  3929. if (!function_exists('getOneAttrInfo'))
  3930. {
  3931. /**
  3932. * 与getAllAttrInfo方法结合使用
  3933. * @param array $info [getAllAttrInfo方法返回的值]
  3934. * @param integer $aid [文档ID]
  3935. * @return [type] [description]
  3936. */
  3937. function getOneAttrInfo($info = [], $aid = 0){
  3938. $arr = [];
  3939. if (isset($info['product_img'][$aid])) {
  3940. $arr['product_img'][$aid] = $info['product_img'][$aid];
  3941. }
  3942. if (isset($info['product_attr'][$aid])) {
  3943. $arr['product_attr'][$aid] = $info['product_attr'][$aid];
  3944. }
  3945. if (isset($info['images_upload'][$aid])) {
  3946. $arr['images_upload'][$aid] = $info['images_upload'][$aid];
  3947. }
  3948. if (isset($info['download_file'][$aid])) {
  3949. $arr['download_file'][$aid] = $info['download_file'][$aid];
  3950. }
  3951. return $arr;
  3952. }
  3953. }
  3954. if (!function_exists('getOrderBy'))
  3955. {
  3956. // 特别注意:如新增排序规则,请加上括号里的内容!!! (, a.add_time desc)
  3957. //根据tags-list规则,获取查询排序,用于标签文件 TagArclist / TagList
  3958. function getOrderBy($orderby,$ordermode,$isrand=false){
  3959. switch ($orderby) {
  3960. case 'hot':
  3961. case 'click':
  3962. $orderby = "a.click {$ordermode}, a.add_time desc";
  3963. break;
  3964. case 'real_sales':
  3965. $orderby = "a.sales_num {$ordermode}, a.add_time desc";
  3966. break;
  3967. case 'sales_num':
  3968. $orderby = "a.sales_all {$ordermode}, a.add_time desc";
  3969. break;
  3970. case 'users_price':
  3971. $orderby = "a.users_price {$ordermode}, a.add_time desc";
  3972. break;
  3973. case 'id': // 兼容写法
  3974. case 'aid':
  3975. $orderby = "a.aid {$ordermode}";
  3976. break;
  3977. case 'now':
  3978. case 'new': // 兼容写法
  3979. case 'pubdate': // 兼容写法
  3980. case 'add_time':
  3981. $orderby = "a.add_time {$ordermode}";
  3982. break;
  3983. case 'update_time':
  3984. $orderby = "a.update_time {$ordermode}";
  3985. break;
  3986. case 'sortrank': // 兼容写法
  3987. case 'weight': // 兼容写法
  3988. case 'sort_order':
  3989. $orderby = "a.sort_order {$ordermode}, a.add_time desc";
  3990. break;
  3991. case 'rand':
  3992. if (true === $isrand) {
  3993. $orderby = "rand()";
  3994. } else {
  3995. $orderby = "a.add_time {$ordermode}";
  3996. }
  3997. break;
  3998. default:
  3999. {
  4000. if (empty($orderby)) {
  4001. $orderby = 'a.sort_order asc, a.add_time desc';
  4002. } elseif (trim($orderby) != 'rand()') {
  4003. $orderbyArr = explode(',', $orderby);
  4004. foreach ($orderbyArr as $key => $val) {
  4005. $val = trim($val);
  4006. if (preg_match('/^([a-z]+)\./i', $val) == 0) {
  4007. $val = 'a.'.$val;
  4008. $orderbyArr[$key] = $val;
  4009. }
  4010. }
  4011. $orderby = implode(',', $orderbyArr);
  4012. }
  4013. break;
  4014. }
  4015. }
  4016. return $orderby;
  4017. }
  4018. }
  4019. if (!function_exists('getLocationPages'))
  4020. {
  4021. /*
  4022. * 获取当前文章属于栏目第几条
  4023. */
  4024. function getLocationPages($tid,$aid,$order){
  4025. $map_arc = [];
  4026. if (!empty($tid)){
  4027. $id_arr = [$tid];
  4028. getAllChild($id_arr,$tid,2);
  4029. $map_arc['typeid'] = ['in',$id_arr];
  4030. }
  4031. $map_arc['is_del'] = 0;
  4032. $map_arc['status'] = 1;
  4033. $result = \think\Db::name('archives')->alias('a')->field("a.aid")->where($map_arc)->orderRaw($order)->select();
  4034. foreach ($result as $key=>$val){
  4035. if ($aid == $val['aid']){
  4036. return $key + 1;
  4037. }
  4038. }
  4039. return false;
  4040. }
  4041. }
  4042. if (!function_exists('auto_hide_index'))
  4043. {
  4044. /**
  4045. * URL中隐藏index.php入口文件(适用后台显示前台的URL)
  4046. */
  4047. function auto_hide_index($url, $seo_inlet = null) {
  4048. static $web_adminbasefile = null;
  4049. if (null === $web_adminbasefile) {
  4050. $web_adminbasefile = tpCache('web.web_adminbasefile');
  4051. $web_adminbasefile = !empty($web_adminbasefile) ? $web_adminbasefile : ROOT_DIR.'/login.php'; // 支持子目录
  4052. }
  4053. $url = str_replace($web_adminbasefile, ROOT_DIR.'/index.php', $url); // 支持子目录
  4054. null === $seo_inlet && $seo_inlet = config('ey_config.seo_inlet');
  4055. if (1 == $seo_inlet) {
  4056. $url = str_replace('/index.php/', '/', $url);
  4057. }
  4058. return $url;
  4059. }
  4060. }
  4061. if (!function_exists('getArchivesField'))
  4062. {
  4063. /**
  4064. * 获取指定文档的字段值
  4065. */
  4066. function getArchivesField($aid = 0, $fieldName = 'aid') {
  4067. $value = '';
  4068. if (0 < intval($aid)) {
  4069. if ('arcurl' == $fieldName) {
  4070. $row = \think\Db::name('archives')->where(['aid'=>$aid])->find();
  4071. $value = get_arcurl($row);
  4072. } else {
  4073. $value = \think\Db::name('archives')->where(['aid'=>$aid])->getField($fieldName);
  4074. if ('litpic' == $fieldName) {
  4075. $value = handle_subdir_pic($value); // 支持子目录
  4076. }
  4077. }
  4078. }
  4079. return $value;
  4080. }
  4081. }
  4082. if (!function_exists('GetUsersLatestData'))
  4083. {
  4084. /**
  4085. * 获取登录的会员最新数据
  4086. */
  4087. function GetUsersLatestData($users_id = null)
  4088. {
  4089. $users_id = empty($users_id) ? session('users_id') : $users_id;
  4090. if(!empty($users_id)) {
  4091. // 查询会员数据
  4092. $field = 'b.*, b.discount as level_discount, a.*';
  4093. $users = \think\Db::name('users')->field($field)
  4094. ->alias('a')
  4095. ->join('__USERS_LEVEL__ b', 'a.level = b.level_id', 'LEFT')
  4096. ->where([
  4097. 'a.users_id' => $users_id,
  4098. 'a.is_activation' => 1,
  4099. 'a.is_del' => 0,
  4100. ])->find();
  4101. // 会员不存在则返回空
  4102. if (empty($users)) return false;
  4103. // 删除登录密码及支付密码
  4104. unset($users['paypwd']);
  4105. // 去掉余额小数点多余的0
  4106. $users['users_money'] = unifyPriceHandle($users['users_money']);
  4107. // 头像处理
  4108. $users['head_pic'] = get_head_pic(htmlspecialchars_decode($users['head_pic']), false, $users['sex']);
  4109. // 昵称处理
  4110. $users['nickname'] = empty($users['nickname']) ? $users['username'] : $users['nickname'];
  4111. // 密码为空并且存在openid则表示微信注册登录,密码字段更新为0,可重置密码一次。
  4112. $users['password'] = empty($users['password']) && !empty($users['thirdparty']) ? 1 : 1;
  4113. // 会员级别处理
  4114. $LevelData = [];
  4115. if (intval($users['level_maturity_days']) >= 36600) {
  4116. $users['maturity_code'] = 1;
  4117. $users['maturity_date'] = '终身';
  4118. } else if (0 === intval($users['open_level_time']) && 0 === intval($users['level_maturity_days'])) {
  4119. $users['maturity_code'] = 0;
  4120. $users['maturity_date'] = '未升级会员';
  4121. } else {
  4122. // 计算剩余天数后取整
  4123. $days = $users['open_level_time'] + (intval($users['level_maturity_days']) * 86400);
  4124. $days = ceil(($days - getTime()) / 86400);
  4125. if (0 >= $days) {
  4126. // 更新会员的级别
  4127. $LevelData = model('EyouUsers')->UpUsersLevelData($users_id);
  4128. $users['maturity_code'] = 2;
  4129. $users['maturity_date'] = '未升级会员';
  4130. } else {
  4131. $users['maturity_code'] = 3;
  4132. $users['maturity_date'] = $days . ' 天';
  4133. }
  4134. }
  4135. // 如果安装了分销插件则执行
  4136. if (is_dir('./weapp/DealerPlugin/')) {
  4137. // 开启分销插件则执行
  4138. $data = model('Weapp')->getWeappList('DealerPlugin');
  4139. if (!empty($data['status']) && 1 == $data['status']) {
  4140. // 如果当前会员有顶级会员则不允许申请成为分销商
  4141. $users['allowApply'] = (empty($users['is_dealer']) && !empty($users['top_users_id']) && !empty($users['top_dealer_id'])) ? 0 : 1;
  4142. // 查询分销商信息
  4143. if (!empty($users['users_id'])) {
  4144. $where = [
  4145. 'users_id' => $users['users_id'],
  4146. ];
  4147. $dealer = \think\Db::name('weapp_dealer')->where($where)->find();
  4148. $users['dealer'] = !empty($dealer) ? $dealer : false;
  4149. }
  4150. // 分销商绑定客户处理
  4151. if (isMobile()/* && isWeixin()*/) {
  4152. $dealerParam = cookie('dealerParam') ? cookie('dealerParam') : session('dealerParam');
  4153. if (!empty($dealerParam)) {
  4154. $dealerPluginLogic = new \app\plugins\logic\DealerPluginLogic($users);
  4155. $dealerPluginLogic->dealerAction('h5', 'bindUsers');
  4156. }
  4157. // 分销插件图标
  4158. $users['dealer']['dealer_pic'] = get_default_pic($data['config']['litpic']);
  4159. }
  4160. }
  4161. }
  4162. // 订单核销插件
  4163. $users['verify'] = [];
  4164. $weappInfo = model('ShopPublicHandle')->getWeappVerifyInfo();
  4165. if (!empty($weappInfo)) {
  4166. // 调用订单核销逻辑层方法
  4167. $verifyLogic = new \app\plugins\logic\VerifyLogic($users);
  4168. $users['verify'] = $verifyLogic->getVerifyStaff($weappInfo);
  4169. }
  4170. // 登录赠送积分
  4171. $scoreConfig = getUsersConfigData('score');
  4172. if (!empty($scoreConfig['score_login_points_open']) && 1 == $scoreConfig['score_login_points_open'] && !empty($users_id)) {
  4173. // 当前时间戳
  4174. $times = getTime();
  4175. // 当前年月日
  4176. $log_time = date('Ymd');
  4177. // 查询会员登录日志
  4178. $usersLoginLog = Db::name('users_login_log')->where(['users_id'=>$users_id])->find();
  4179. // 如果没有日志或日志时间不是今天则执行添加赠送积分,并且更新日志时间
  4180. if (empty($usersLoginLog) || intval($log_time) !== intval($usersLoginLog['log_time'])) {
  4181. // 登录赠送积分
  4182. $insert = [
  4183. 'type' => 10,
  4184. 'users_id' => $users_id,
  4185. 'score' => $scoreConfig['score_login_points_value'],
  4186. 'info' => '登录赠送' . $scoreConfig['score_name'],
  4187. 'remark' => '登录赠送' . $scoreConfig['score_name'],
  4188. ];
  4189. addConsumObtainScores($insert, 2, true);
  4190. // 添加或更新登录日志
  4191. if (!empty($usersLoginLog['log_id'])) {
  4192. $update = [
  4193. 'users_id' => $users_id,
  4194. 'log_time' => $log_time,
  4195. 'log_count' => Db::Raw('log_count+1'),
  4196. 'update_time' => $times,
  4197. ];
  4198. Db::name('users_login_log')->where(['log_id' => $usersLoginLog['log_id']])->update($update);
  4199. } else {
  4200. $insert = [
  4201. 'users_id' => $users_id,
  4202. 'log_time' => $log_time,
  4203. 'log_count' => 1,
  4204. 'add_time' => $times,
  4205. 'update_time' => $times,
  4206. ];
  4207. Db::name('users_login_log')->insert($insert);
  4208. }
  4209. // 增加会员积分
  4210. $users['scores'] = intval($users['scores']) + intval($scoreConfig['score_login_points_value']);
  4211. }
  4212. }
  4213. // 合并数据
  4214. $LatestData = array_merge($users, $LevelData);
  4215. // 更新session
  4216. session('users', $LatestData);
  4217. session('users_id', $LatestData['users_id']);
  4218. cookie('users_id', $LatestData['users_id']);
  4219. // 返回数据
  4220. return $LatestData;
  4221. } else {
  4222. // session中不存在会员ID则返回空
  4223. session('users_id', null);
  4224. session('users', null);
  4225. cookie('users_id', null);
  4226. return false;
  4227. }
  4228. }
  4229. }
  4230. if (!function_exists('GetTotalArc'))
  4231. {
  4232. /**
  4233. * 统计栏目文章数
  4234. */
  4235. function GetTotalArc($typeid = 0)
  4236. {
  4237. if (empty($typeid)) {
  4238. return 0;
  4239. } else {
  4240. $cache_key = md5("common-GetTotalArc-{$typeid}");
  4241. $count = cache($cache_key);
  4242. if (empty($count)) {
  4243. $row = model('Arctype')->getHasChildren($typeid);
  4244. if (empty($row)) return 0;
  4245. $typeids = array_keys($row);
  4246. $allow_release_channel = config('global.allow_release_channel');
  4247. $condition = [
  4248. 'typeid' => ['IN', $typeids],
  4249. 'channel' => ['IN', $allow_release_channel],
  4250. 'arcrank' => ['gt', -1],
  4251. 'status' => 1,
  4252. 'is_del' => 0,
  4253. ];
  4254. /*定时文档显示插件*/
  4255. if (is_dir('./weapp/TimingTask/')) {
  4256. $TimingTaskRow = model('Weapp')->getWeappList('TimingTask');
  4257. if (!empty($TimingTaskRow['status']) && 1 == $TimingTaskRow['status']) {
  4258. $condition['add_time'] = ['elt', getTime()]; // 只显当天或之前的文档
  4259. }
  4260. }
  4261. /*end*/
  4262. $count = \think\Db::name('archives')->where($condition)->count('aid');
  4263. cache($cache_key, $count, null, 'archives');
  4264. }
  4265. return intval($count);
  4266. }
  4267. }
  4268. }
  4269. if (!function_exists('GetTagIndexRanking'))
  4270. {
  4271. /**
  4272. * 统计栏目文章数
  4273. */
  4274. function GetTagIndexRanking($limit = 5, $field = 'id, tag')
  4275. {
  4276. $order = 'weekcc desc, monthcc desc';
  4277. $limit = '0, ' . $limit;
  4278. $list = \think\Db::name('tagindex')->field($field)->order($order)->limit($limit)->select();
  4279. return $list;
  4280. }
  4281. }
  4282. if (!function_exists('weapptaglib'))
  4283. {
  4284. /**
  4285. * 通用 - 插件模板标签
  4286. */
  4287. function weapptaglib($weapp_code = '', $act = '', $vars = [])
  4288. {
  4289. $list = '';
  4290. if (empty($weapp_code) || empty($act) || !is_dir("./weapp/{$weapp_code}/")) {
  4291. return '';
  4292. }
  4293. $is_exist = false;
  4294. if (file_exists("./weapp/{$weapp_code}/logic/{$weapp_code}Logic.php")) {
  4295. $class = '\weapp\\'.$weapp_code.'\logic\\'.$weapp_code.'Logic';
  4296. if (method_exists($class, $act)) {
  4297. $is_exist = true;
  4298. $ctl = new $class();
  4299. $list = $ctl->$act($vars);
  4300. }
  4301. }
  4302. if (!$is_exist) {
  4303. $class = '\weapp\\'.$weapp_code.'\controller\\'.$weapp_code;
  4304. $ctl = new $class();
  4305. $list = $ctl->$act($vars);
  4306. }
  4307. return $list;
  4308. }
  4309. }
  4310. if (!function_exists('rand_username'))
  4311. {
  4312. /**
  4313. * 生成随机用户名,确保唯一性
  4314. */
  4315. function rand_username($username = '', $prefix = 'U', $includenumber = 2)
  4316. {
  4317. if (empty($username)) {
  4318. $username = $prefix . get_rand_str(6, 0, $includenumber);
  4319. }
  4320. $count = \think\Db::name('users')->where('username', $username)->count();
  4321. if (!empty($count)) {
  4322. $username = $prefix . get_rand_str(6, 0, $includenumber);
  4323. return rand_username($username, $prefix, $includenumber);
  4324. }
  4325. return $username;
  4326. }
  4327. }
  4328. if (!function_exists('update_username')) {
  4329. /**
  4330. * 修改用户名为U+用户id,用户id不足6位补0
  4331. * @param [type] $users_id [用户id]
  4332. * @return [type] [description]
  4333. */
  4334. function update_username($users_id, $is_update = true)
  4335. {
  4336. $username = '';
  4337. if (!empty($users_id)) {
  4338. if (6 > strlen($users_id)) {
  4339. $users_id = sprintf("%06d", $users_id); // 不足6位补0
  4340. }
  4341. $username = 'U'.$users_id;
  4342. $username = rand_username($username);
  4343. if ($is_update) {
  4344. \think\Db::name('users')->where('users_id', $users_id)->update(['username'=>$username,'update_time'=>getTime()]);
  4345. }
  4346. }
  4347. return $username;
  4348. }
  4349. }
  4350. if (!function_exists('pay_success_logic'))
  4351. {
  4352. /**
  4353. * 支付成功的后置业务逻辑
  4354. */
  4355. function pay_success_logic($users_id = 0, $order_code = '', $pay_details = [], $paycode = 'alipay', $notify = true, $users = [])
  4356. {
  4357. $pay_method_arr = config('global.pay_method_arr');
  4358. $where = [
  4359. 'order_code' => $order_code,
  4360. ];
  4361. !empty($users_id) && $where['users_id'] = intval($users_id);
  4362. $orderData = \think\Db::name('shop_order')->where($where)->find();
  4363. if (empty($orderData)) {
  4364. return [
  4365. 'code' => 0,
  4366. 'msg' => '该订单不存在!',
  4367. ];
  4368. }
  4369. else if (0 == $orderData['order_status']) {
  4370. $saveData = [
  4371. 'order_status' => 1,
  4372. 'pay_details' => serialize($pay_details),
  4373. 'pay_time' => getTime(),
  4374. 'update_time' => getTime(),
  4375. ];
  4376. if ('wechat' != $paycode) {
  4377. $saveData['pay_name'] = $paycode;
  4378. $saveData['wechat_pay_type'] = ''; // 清空微信标志
  4379. }
  4380. $where = [
  4381. 'order_id' => $orderData['order_id'],
  4382. 'users_id' => $orderData['users_id'],
  4383. ];
  4384. $ret = \think\Db::name('shop_order')->where($where)->update($saveData);
  4385. if (false !== $ret) {
  4386. // 更新订单变量,保存最新数据
  4387. $orderData = array_merge($orderData, $saveData);
  4388. if (!empty($paycode) && isset($pay_method_arr[$paycode])){
  4389. $orderData['pay_method'] = $pay_method_arr[$paycode];
  4390. $actionNote = "使用{$pay_method_arr[$paycode]}完成支付";
  4391. } else {
  4392. $orderData['pay_method'] = '';
  4393. $actionNote = "完成支付";
  4394. }
  4395. // 添加订单操作记录
  4396. AddOrderAction($orderData['order_id'], $orderData['users_id'], 0, 1, 0, 1, "支付成功", $actionNote);
  4397. // 发送站内信给后台
  4398. SendNotifyMessage($orderData, 5, 1, 0);
  4399. // 虚拟自动发货
  4400. $PayModel = new \app\user\model\Pay;
  4401. $autoSendGoods = $PayModel->afterVirtualProductPay($orderData);
  4402. $data = [];
  4403. if (false === $autoSendGoods && true === $notify) {
  4404. $users = !empty($users) ? $users : \think\Db::name('users')->field('*')->find($orderData['users_id']);
  4405. // 邮箱发送
  4406. $data['email'] = GetEamilSendData(tpCache('smtp'), $users, $orderData, 1, $paycode);
  4407. // 手机发送
  4408. $data['mobile'] = GetMobileSendData(tpCache('sms'), $users, $orderData, 1, $paycode);
  4409. }
  4410. // 余额支付则追加会员余额明细表
  4411. if ('balance' == $paycode) {
  4412. $users = !empty($users) ? $users : \think\Db::name('users')->field('*')->find($orderData['users_id']);
  4413. UsersMoneyRecording($order_code, $users, $orderData['order_amount'], '商品购买', 3);
  4414. }
  4415. // 订单操作完成,返回跳转
  4416. $url = url('user/Shop/shop_centre');
  4417. if (true === $autoSendGoods) {
  4418. $msg = '支付订单完成!';
  4419. } else {
  4420. $msg = '支付成功,处理订单完成!';
  4421. }
  4422. return [
  4423. 'code' => 1,
  4424. 'msg' => $msg,
  4425. 'url' => $url,
  4426. 'data' => $data,
  4427. ];
  4428. }
  4429. else {
  4430. return [
  4431. 'code' => 0,
  4432. 'msg' => '支付成功,处理订单失败!',
  4433. ];
  4434. }
  4435. }
  4436. else if (1 <= $orderData['order_status'] && $orderData['order_status'] <= 3) {
  4437. return [
  4438. 'code' => 1,
  4439. 'msg' => '已支付',
  4440. ];
  4441. }
  4442. else if (4 == $orderData['order_status']) {
  4443. return [
  4444. 'code' => 0,
  4445. 'msg' => '该订单已过期!',
  4446. ];
  4447. }
  4448. else {
  4449. return [
  4450. 'code' => 0,
  4451. 'msg' => '该订单不存在或已关闭!',
  4452. ];
  4453. }
  4454. }
  4455. }
  4456. if (!function_exists('OrderServiceLog'))
  4457. {
  4458. /**
  4459. * 订单服务记录表
  4460. * 参数说明:
  4461. * $ServiceId 订单服务信息ID
  4462. * $OrderId 订单ID
  4463. * $UsersId 会员ID
  4464. * $AdminId 管理员ID
  4465. * $LogNote 记录信息
  4466. * 返回说明:
  4467. * return 无需返回
  4468. */
  4469. function OrderServiceLog($ServiceId = null, $OrderId = null, $UsersId = 0, $AdminId = 0, $LogNote = '会员提交退换货申请')
  4470. {
  4471. if (empty($ServiceId) || empty($OrderId)) return false;
  4472. /*使用余额支付时,同时添加一条记录到金额明细表*/
  4473. $Time = getTime();
  4474. $LogData = [
  4475. 'service_id' => $ServiceId,
  4476. 'order_id' => $OrderId,
  4477. 'users_id' => $UsersId,
  4478. 'admin_id' => $AdminId,
  4479. 'log_note' => empty($LogNote) ? '' : $LogNote,
  4480. 'add_time' => $Time,
  4481. 'update_time' => $Time,
  4482. ];
  4483. M('shop_order_service_log')->add($LogData);
  4484. /* END */
  4485. }
  4486. }
  4487. if (!function_exists('UsersMoneyRecording'))
  4488. {
  4489. /**
  4490. * 添加会员余额明细表
  4491. * 参数说明:
  4492. * $OrderCode 订单编号
  4493. * $Users 会员信息
  4494. * $UsersMoney 记录余额
  4495. * $Cause 订单状态,如过期,取消,退款,退货等
  4496. * 返回说明:
  4497. * return 无需返回
  4498. * $CauseType global.pay_cause_type_arr
  4499. */
  4500. function UsersMoneyRecording($OrderCode = null, $Users = [], $UsersMoney = null, $Cause = '商品退换货', $CauseType = 2)
  4501. {
  4502. if (empty($OrderCode) || empty($Users) || empty($UsersMoney)) return false;
  4503. $Time = getTime();
  4504. $pay_method = '';
  4505. // 使用余额支付时,同时添加一条记录到金额明细表
  4506. if (2 == $CauseType) {
  4507. $Status = 3;
  4508. $Cause = $Cause . ',退还使用余额,订单号:' . $OrderCode;
  4509. $UsersNewMoney = !empty($Users['users_money']) ? sprintf("%.2f", $Users['users_money'] += $UsersMoney) : 0;
  4510. $pay_method = 'balance';
  4511. } else if (3 == $CauseType) {
  4512. $Status = 2;
  4513. $Cause = $Cause . ',使用余额支付,订单号:' . $OrderCode;
  4514. $UsersNewMoney = !empty($Users['users_money']) ? sprintf("%.2f", $Users['users_money'] -= $UsersMoney) : 0;
  4515. $pay_method = 'balance';
  4516. }
  4517. $UsersNewMoney = !empty($Users['users_money']) ? $UsersNewMoney : Db::name('users')->where('users_id', $Users['users_id'])->value('users_money');
  4518. $MoneyData = [
  4519. 'users_id' => $Users['users_id'],
  4520. 'money' => $UsersMoney,
  4521. 'users_money' => $UsersNewMoney,
  4522. 'cause' => $Cause,
  4523. 'cause_type' => $CauseType,
  4524. 'status' => $Status,
  4525. 'pay_method' => $pay_method,
  4526. 'pay_details' => '',
  4527. 'order_number' => $OrderCode,
  4528. 'add_time' => $Time,
  4529. 'update_time' => $Time,
  4530. ];
  4531. Db::name('users_money')->insert($MoneyData);
  4532. }
  4533. }
  4534. if (!function_exists('GetScoreArray')) {
  4535. /**
  4536. * 评价转换星级评分
  4537. */
  4538. function GetScoreArray($total_score = 0)
  4539. {
  4540. $Result = 0;
  4541. if (empty($total_score)) return $Result;
  4542. if (in_array($total_score, [1])) {
  4543. $Result = 5;
  4544. } else if (in_array($total_score, [2])) {
  4545. $Result = 3;
  4546. } else if (in_array($total_score, [3])) {
  4547. $Result = 1;
  4548. }
  4549. return $Result;
  4550. }
  4551. }
  4552. if (!function_exists('getTrueTypeid')) {
  4553. /**
  4554. * 在typeid传值为目录名称的情况下,获取栏目ID
  4555. */
  4556. function getTrueTypeid($typeid = '')
  4557. {
  4558. /*tid为目录名称的情况下*/
  4559. if (!empty($typeid) && strval($typeid) != strval(intval($typeid))) {
  4560. $typeid = \think\Db::name('arctype')->where([
  4561. 'dirname' => $typeid,
  4562. 'lang' => get_current_lang(),
  4563. ])->cache(true,EYOUCMS_CACHE_TIME,"arctype")
  4564. ->getField('id');
  4565. }
  4566. /*--end*/
  4567. return $typeid;
  4568. }
  4569. }
  4570. if (!function_exists('getTrueAid')) {
  4571. /**
  4572. * 在aid传值为自定义文件名的情况下,获取真实aid
  4573. */
  4574. function getTrueAid($aid = '')
  4575. {
  4576. /*aid为自定义文件名的情况下*/
  4577. if (!empty($aid) && strval($aid) != strval(intval($aid))) {
  4578. $aid = \think\Db::name('archives')->where([
  4579. 'htmlfilename' => $aid,
  4580. 'lang' => get_current_lang(),
  4581. ])->cache(true,EYOUCMS_CACHE_TIME,"archives")
  4582. ->getField('aid');
  4583. }
  4584. /*--end*/
  4585. return intval($aid);
  4586. }
  4587. }
  4588. if (!function_exists('SendNotifyMessage'))
  4589. {
  4590. /**
  4591. * 发送站内信通知
  4592. * 参数说明:
  4593. * $ContentArr 需要存入的通知内容
  4594. * $SendScene 发送来源
  4595. * $UsersID 会员ID
  4596. * $Cause 订单状态,如过期,取消,退款,退货等
  4597. * 返回说明:
  4598. * return 无需返回
  4599. */
  4600. function SendNotifyMessage($GetContentArr = [], $SendScene = 0, $AdminID = 0, $UsersID = 0, $UsersName = null)
  4601. {
  4602. // 存储数据为空则返回结束
  4603. if (empty($GetContentArr) || empty($SendScene)) return false;
  4604. // 查询通知模板信息
  4605. $tpl_where = [
  4606. // 'lang' => get_home_lang(),
  4607. 'send_scene' => $SendScene
  4608. ];
  4609. $Notice = M('users_notice_tpl')->where($tpl_where)->find();
  4610. $times = getTime();
  4611. $homeLang = get_home_lang();
  4612. // 通知模板存在并且开启则执行
  4613. if (!empty($Notice) && !empty($Notice['tpl_title']) && 1 === intval($Notice['is_open'])) {
  4614. if (in_array($SendScene, [1, 5, 20])) {
  4615. $ContentArr = [];
  4616. // 留言表单
  4617. if (1 === intval($SendScene)) {
  4618. $ContentArr = $GetContentArr;
  4619. }
  4620. // 订单付款
  4621. else if (5 === intval($SendScene)) {
  4622. $ContentArr = [
  4623. '订单编号:' . $GetContentArr['order_code'],
  4624. '订单总额:' . $GetContentArr['order_amount'],
  4625. '支付方式:' . $GetContentArr['pay_method'],
  4626. '手机号:' . $GetContentArr['mobile']
  4627. ];
  4628. }
  4629. // 会员投稿
  4630. else if (20 === intval($SendScene)) {
  4631. $arcrank = isset($GetContentArr['arcrank']) && -1 === intval($GetContentArr['arcrank']) ? '未审核' : '自动审核';
  4632. $ContentArr = [
  4633. '文档标题:' . $GetContentArr['title'],
  4634. '文档内容:' . $GetContentArr['seo_description'],
  4635. '投稿时间:' . date('Y-m-d H:i:s', $GetContentArr['add_time']),
  4636. '文档审核:' . $arcrank,
  4637. ];
  4638. }
  4639. $Content = !empty($ContentArr) ? implode('<br/>', $ContentArr) : '';
  4640. $ContentData = [
  4641. 'source' => $SendScene,
  4642. 'admin_id' => $AdminID,
  4643. 'users_id' => $UsersID,
  4644. 'content_title' => $Notice['tpl_title'],
  4645. 'content' => !empty($Content) ? $Content : '',
  4646. 'is_read' => 0,
  4647. 'lang' => $homeLang,
  4648. 'add_time' => $times,
  4649. 'update_time' => $times
  4650. ];
  4651. M('users_notice_tpl_content')->add($ContentData);
  4652. }
  4653. // 订单发货
  4654. else if (6 === intval($SendScene)) {
  4655. $ContentArr = [
  4656. '快递公司:' . $GetContentArr['express_name'],
  4657. '快递单号:' . $GetContentArr['express_order'],
  4658. '发货时间:' . date('Y-m-d H:i:s', $GetContentArr['express_time']),
  4659. ];
  4660. $Content = !empty($ContentArr) ? implode('<br/>', $ContentArr) : '';
  4661. $ContentData = [
  4662. 'title' => $Notice['tpl_title'],
  4663. 'users_id' => $UsersID,
  4664. 'usernames' => $UsersName,
  4665. 'remark' => $Content,
  4666. 'lang' => $homeLang,
  4667. 'add_time' => $times,
  4668. 'update_time' => $times
  4669. ];
  4670. M('users_notice')->add($ContentData);
  4671. }
  4672. }
  4673. }
  4674. }
  4675. if (!function_exists('usershomeurl'))
  4676. {
  4677. /**
  4678. * 个人主页URL
  4679. * @param [type] $users_id [description]
  4680. * @return [type] [description]
  4681. */
  4682. function usershomeurl($users_id)
  4683. {
  4684. $usershomeurl = '';
  4685. static $is_users_weapp = null;
  4686. static $users_seo_pseudo = 1;
  4687. if (is_dir('./weapp/Users/') && null === $is_users_weapp) {
  4688. $weappInfo = \think\Db::name('weapp')->field('data,status')->where(['code' => 'Users'])->find();
  4689. if (!empty($weappInfo['status'])) {
  4690. $is_users_weapp = true;
  4691. $weappInfo['data'] = unserialize($weappInfo['data']);
  4692. $users_seo_pseudo = !empty($weappInfo['data']['seo_pseudo']) ? intval($weappInfo['data']['seo_pseudo']) : 1;
  4693. }
  4694. }
  4695. if (true === $is_users_weapp) {
  4696. $usershomeurl = url('plugins/Users/userask', ['id'=>$users_id], true, false, $users_seo_pseudo);
  4697. }
  4698. return $usershomeurl;
  4699. }
  4700. }
  4701. if (!function_exists('restric_type_logic')) {
  4702. /**
  4703. * 文章模型 付费限制模式与之前三个字段 arc_level_id、 users_price、 users_free 组合逻辑兼容
  4704. * 下载模型/视频模型 付费限制模式与之前三个字段 arc_level_id、 users_price、 no_vip_pay 组合逻辑兼容
  4705. * @param array $post [description]
  4706. */
  4707. function restric_type_logic(&$post = [], $channel = 0)
  4708. {
  4709. if (isset($post['restric_type'])) {
  4710. if (!isset($post['no_vip_pay'])) $post['no_vip_pay'] = 0;
  4711. // 文章模型 、 视频模型
  4712. if (in_array($channel, [1,5])) {
  4713. if (empty($post['restric_type'])) { // 免费
  4714. $post['arc_level_id'] = 0;
  4715. $post['users_price'] = 0;
  4716. $post['no_vip_pay'] = 0;
  4717. $post['users_free'] = 0;
  4718. } else if (1 == $post['restric_type']) { // 付费
  4719. $post['arc_level_id'] = 0;
  4720. $post['no_vip_pay'] = 0;
  4721. $post['users_free'] = 0;
  4722. if (empty($post['users_price']) || $post['users_price'] == 0) {
  4723. return ['code' => 0, 'msg' => '购买价格不能为空!'];
  4724. }
  4725. } else if (2 == $post['restric_type']) { // 指定会员
  4726. if (!empty($post['no_vip_pay'])) {
  4727. if (empty($post['users_price']) || $post['users_price'] == 0) {
  4728. return ['code' => 0, 'msg' => '购买价格不能为空!'];
  4729. }
  4730. if ($post['arc_level_id'] > 0) {
  4731. $post['users_free'] = 1;
  4732. }
  4733. } else {
  4734. if ($post['arc_level_id'] > 0) {
  4735. $post['users_price'] = 0;
  4736. $post['users_free'] = 1;
  4737. }
  4738. }
  4739. } else if (3 == $post['restric_type']) { // 会员付费
  4740. $post['no_vip_pay'] = 0;
  4741. $post['users_free'] = 0;
  4742. if (empty($post['users_price']) || $post['users_price'] == 0) {
  4743. return ['code' => 0, 'msg' => '购买价格不能为空!'];
  4744. }
  4745. }
  4746. }
  4747. // 下载模型
  4748. else if (4 == $channel) {
  4749. if (empty($post['restric_type'])) { // 免费
  4750. $post['arc_level_id'] = 0;
  4751. $post['users_price'] = 0;
  4752. $post['no_vip_pay'] = 0;
  4753. $post['users_free'] = 0; // 用不上
  4754. } else if (1 == $post['restric_type']) { // 付费
  4755. $post['arc_level_id'] = 0;
  4756. $post['no_vip_pay'] = 0;
  4757. $post['users_free'] = 0; // 用不上
  4758. if (empty($post['users_price']) || $post['users_price'] == 0) {
  4759. return ['code' => 0, 'msg' => '购买价格不能为空!'];
  4760. }
  4761. } else if (2 == $post['restric_type']) { // 指定会员
  4762. if (!empty($post['no_vip_pay'])) {
  4763. if (empty($post['users_price']) || $post['users_price'] == 0) {
  4764. return ['code' => 0, 'msg' => '购买价格不能为空!'];
  4765. }
  4766. if ($post['arc_level_id'] > 0) {
  4767. $post['users_free'] = 1; // 用不上
  4768. }
  4769. } else {
  4770. if ($post['arc_level_id'] > 0) {
  4771. $post['users_price'] = 0;
  4772. $post['users_free'] = 1; // 用不上
  4773. }
  4774. }
  4775. } else if (3 == $post['restric_type']) { // 会员付费
  4776. $post['no_vip_pay'] = 0;
  4777. $post['users_free'] = 0; // 用不上
  4778. if (empty($post['users_price']) || $post['users_price'] == 0) {
  4779. return ['code' => 0, 'msg' => '购买价格不能为空!'];
  4780. }
  4781. }
  4782. }
  4783. }
  4784. return true;
  4785. }
  4786. }
  4787. if (!function_exists('clear_session_file'))
  4788. {
  4789. /**
  4790. * 清理过期的data/session文件
  4791. * @param array $post [description]
  4792. */
  4793. function clear_session_file()
  4794. {
  4795. $path = \think\Config::get('session.path');
  4796. if (!empty($path) && file_exists($path)) {
  4797. if ('data/session' != $path && is_dir('data/session')) {
  4798. delFile('./data/session', true);
  4799. }
  4800. $time = getTime();
  4801. $web_login_expiretime = tpCache('web.web_login_expiretime');
  4802. empty($web_login_expiretime) && $web_login_expiretime = config('login_expire');
  4803. $files = glob($path.'/sess_*');
  4804. foreach ($files as $key => $file) {
  4805. clearstatcache(); // 清除文件状态缓存
  4806. $filemtime = filemtime($file);
  4807. if (false === $filemtime) {
  4808. $filemtime = $time;
  4809. }
  4810. $filesize = filesize($file);
  4811. if (false === $filesize) {
  4812. $filesize = 1;
  4813. }
  4814. if (empty($filesize) || (($time - $filemtime) > ($web_login_expiretime + 300))) {
  4815. $referurl = '';
  4816. if (isset($_SERVER['HTTP_REFERER'])) {
  4817. $referurl = $_SERVER['HTTP_REFERER'];
  4818. }
  4819. @unlink($file);
  4820. }
  4821. }
  4822. }
  4823. }
  4824. }
  4825. if (!function_exists('func_thumb_img'))
  4826. {
  4827. /**
  4828. * 压缩图 - 从原始图来处理出来
  4829. * @param type $original_img 图片路径
  4830. * @param type $width 生成缩略图的宽度
  4831. * @param type $height 生成缩略图的高度
  4832. * @param type $quality 压缩系数
  4833. */
  4834. function func_thumb_img($original_img = '', $width = '', $height = '', $quality = 75)
  4835. {
  4836. // 缩略图配置
  4837. static $thumbextra = null;
  4838. static $thumbConfig = null;
  4839. if (null === $thumbextra) {
  4840. @ini_set('memory_limit', '-1'); // 内存不限制,防止图片大小过大,导致缩略图处理失败,网站打不开
  4841. $thumbConfig = tpCache('thumb');
  4842. $thumbextra = config('global.thumb');
  4843. empty($thumbConfig['thumb_width']) && $thumbConfig['thumb_width'] = $thumbextra['width'];
  4844. empty($thumbConfig['thumb_height']) && $thumbConfig['thumb_height'] = $thumbextra['height'];
  4845. }
  4846. $c_width = !empty($width) ? intval($width) : intval($thumbConfig['thumb_width']);
  4847. $c_height = !empty($height) ? intval($height) : intval($thumbConfig['thumb_height']);
  4848. if ((empty($c_width) && empty($c_height)) || stristr($original_img,'.gif')) {
  4849. return $original_img;
  4850. }
  4851. $original_img_new = handle_subdir_pic($original_img, 'img', false, true);
  4852. $original_img_new = trim($original_img_new, '/');
  4853. //获取图像信息
  4854. $info = @getimagesize('./'.$original_img_new);
  4855. $img_width = !empty($info[0]) ? intval($info[0]) : 0;
  4856. $img_height = !empty($info[1]) ? intval($info[1]) : 0;
  4857. // 过滤实际图片大小比设置最大宽高小的,直接忽视
  4858. if (!empty($img_width) && !empty($img_height) && $img_width <= $c_width && $img_height <= $c_height) {
  4859. return $original_img;
  4860. }
  4861. //检测图像合法性
  4862. if (false === $info || (IMAGETYPE_GIF === $info[2] && empty($info['bits']))) {
  4863. return $original_img;
  4864. } else {
  4865. if (!empty($info['mime']) && stristr($info['mime'], 'bmp') && version_compare(PHP_VERSION,'7.2.0','<')) {
  4866. return $original_img;
  4867. }
  4868. }
  4869. try {
  4870. vendor('topthink.think-image.src.Image');
  4871. vendor('topthink.think-image.src.image.Exception');
  4872. $image = \think\Image::open('./'.$original_img_new);
  4873. $image->thumb($c_width, $c_height, 1)->save($original_img_new, NULL, $quality); //按照原图的比例生成一个最大为$width*$height的缩略图并保存
  4874. } catch (think\Exception $e) {}
  4875. return $original_img;
  4876. }
  4877. }
  4878. if (!function_exists('pc_to_mobile_url'))
  4879. {
  4880. /**
  4881. * 生成静态模式下且PC和移动端模板分离,自动获取移动端URL
  4882. * @access public
  4883. */
  4884. function pc_to_mobile_url($pageurl = '', $tid = '', $aid = '')
  4885. {
  4886. $url = '';
  4887. $webData = tpCache('web');
  4888. if (file_exists('./template/'.TPL_THEME.'mobile')) { // 分离式模板
  4889. $domain = request()->host(true);
  4890. /*是否开启手机站域名,并且配置*/
  4891. if (!empty($webData['web_mobile_domain_open']) && !empty($webData['web_mobile_domain'])) {
  4892. $domain = $webData['web_mobile_domain'] . '.' . request()->rootDomain();
  4893. }
  4894. /*end*/
  4895. if (!empty($aid)) { // 内容页
  4896. $url = url('home/View/index', ['aid' => $aid], true, $domain, 1, 1, 0);
  4897. } else if (!empty($tid)) { // 列表页
  4898. $url = url('home/Lists/index', ['tid' => $tid], true, $domain, 1, 1, 0);
  4899. } else { // 首页
  4900. $url = request()->scheme().'://'. $domain . ROOT_DIR . '/index.php';
  4901. }
  4902. } else { // 响应式模板
  4903. // 开启手机站域名,且配置
  4904. if (!empty($webData['web_mobile_domain_open']) && !empty($webData['web_mobile_domain'])) {
  4905. if (empty($pageurl)) {
  4906. $url = request()->subDomain($webData['web_mobile_domain']) . ROOT_DIR . '/index.php';
  4907. } else {
  4908. $url = !preg_match('/^(http(s?):)?\/\/(.*)$/i', $pageurl) ? request()->domain() . $pageurl : $pageurl;
  4909. $url = preg_replace('/^(.*)(\/\/)([^\/]*)(\.?)(' . request()->rootDomain() . ')(.*)$/i', '${1}${2}' . $webData['web_mobile_domain'] . '.${5}${6}', $url);
  4910. }
  4911. }
  4912. }
  4913. return $url;
  4914. }
  4915. }
  4916. if (!function_exists('GetSortData'))
  4917. {
  4918. /**
  4919. * list/arclist标签的排序处理
  4920. * @param string $orderby [description]
  4921. * @param array $Param [description]
  4922. */
  4923. function GetSortData($orderby = '', $Param = [])
  4924. {
  4925. if (empty($Param)) {
  4926. $Param = request()->param();
  4927. }
  4928. $sort_asc = !empty($Param['sort_asc']) ? $Param['sort_asc'] : 'desc';
  4929. if (!empty($Param['sort']) && 'sales' == $Param['sort']) {
  4930. $orderby = 'a.sales_all ' . $sort_asc . ', ' . $orderby;
  4931. } else if (!empty($Param['sort']) && 'price' == $Param['sort']) {
  4932. $orderby = 'a.users_price ' . $sort_asc . ', ' . $orderby;
  4933. } else if (!empty($Param['sort']) && 'appraise' == $Param['sort']) {
  4934. $orderby = 'a.appraise ' . $sort_asc . ', ' . $orderby;
  4935. } else if (!empty($Param['sort']) && 'new' == $Param['sort']) {
  4936. $orderby = 'a.add_time ' . $sort_asc . ', ' . $orderby;
  4937. } else if (!empty($Param['sort']) && 'collection' == $Param['sort']) {
  4938. $orderby = 'a.collection ' . $sort_asc . ', ' . $orderby;
  4939. } else if (!empty($Param['sort']) && 'click' == $Param['sort']) {
  4940. $orderby = 'a.click ' . $sort_asc . ', ' . $orderby;
  4941. } else if (!empty($Param['sort']) && 'download' == $Param['sort']) {
  4942. $orderby = 'a.downcount ' . $sort_asc . ', ' . $orderby;
  4943. }
  4944. return $orderby;
  4945. }
  4946. }
  4947. if (!function_exists('set_tagseotitle'))
  4948. {
  4949. /**
  4950. * 设置Tag标题
  4951. */
  4952. function set_tagseotitle($tag = '', $seo_title = '', $site_info = [])
  4953. {
  4954. $page = I('param.page/d', 1);
  4955. static $lang = null;
  4956. $lang === null && $lang = get_home_lang();
  4957. static $seoConfig = null;
  4958. null === $seoConfig && $seoConfig = tpCache('seo');
  4959. $seo_title_symbol = isset($seoConfig['seo_title_symbol']) ? htmlspecialchars_decode($seoConfig['seo_title_symbol']) : '_';
  4960. if (empty($seo_title)) { // 针对没有自定义SEO标题的Tag
  4961. $web_name = tpCache('web.web_name');
  4962. if ($page > 1) {
  4963. if (in_array($lang, ['cn'])) {
  4964. $tag .= "{$seo_title_symbol}第{$page}页";
  4965. } else {
  4966. $tag .= "{$seo_title_symbol}{$page}";
  4967. }
  4968. }
  4969. $seo_title = $tag.'_'.$web_name;
  4970. } else {
  4971. if ($page > 1) {
  4972. if (in_array($lang, ['cn'])) {
  4973. $seo_title .= "{$seo_title_symbol}第{$page}页";
  4974. } else {
  4975. $seo_title .= "{$seo_title_symbol}{$page}";
  4976. }
  4977. }
  4978. }
  4979. // 城市分站的seo
  4980. if (empty($site_info)) {
  4981. $site_info = cookie('site_info');
  4982. $site_info = json_decode($site_info, true);
  4983. }
  4984. $seo_title = site_seo_handle($seo_title, $site_info);
  4985. return $seo_title;
  4986. }
  4987. }
  4988. if (!function_exists('spellLabel'))
  4989. {
  4990. /**
  4991. * 会员价格拼标签
  4992. */
  4993. function spellLabel( $value = '' )
  4994. {
  4995. $value = '<span id="users_price_1640658971">'.$value.'</span>';
  4996. return $value;
  4997. }
  4998. }
  4999. if (!function_exists('get_discount_price'))
  5000. {
  5001. /**
  5002. * 获取会员折扣价格
  5003. */
  5004. function get_discount_price( $discount = 100 , $price = 0 )
  5005. {
  5006. if (0 < $price){
  5007. // static $discount = null;
  5008. // if (null === $discount) {
  5009. // $discount = \think\Db::name('users_level')->where(['level_id'=>$level_id])->value('discount');
  5010. // }
  5011. if (!empty($discount)) {
  5012. $price = round($price * ($discount/100),2);
  5013. } else {
  5014. $price = 0;
  5015. }
  5016. }
  5017. return $price;
  5018. }
  5019. }
  5020. if (!function_exists('site_seo_handle'))
  5021. {
  5022. /**
  5023. * 转换多站点的区域seo标题、关键字、描述
  5024. */
  5025. function site_seo_handle($value = '', $site_info = [])
  5026. {
  5027. if (!empty($value)) {
  5028. if (!config('city_switch_on')) {
  5029. $value = str_ireplace(['{region}','{regionAll}','{parent}','{top}'], '', $value);
  5030. } else {
  5031. if (empty($site_info)) {
  5032. $site_info = [
  5033. 'name' => '',
  5034. 'topid' => 0,
  5035. 'parent_id' => 0,
  5036. 'level' => 0,
  5037. ];
  5038. }
  5039. if (stristr($value, "{region}")) {
  5040. $name = !empty($site_info['name']) ? $site_info['name'] : '';
  5041. $value = str_ireplace('{region}', $name, $value);
  5042. }
  5043. if (stristr($value, "{regionAll}") || stristr($value, "{parent}") || stristr($value, "{top}")) {
  5044. static $citysiteList = null;
  5045. if (null === $citysiteList) {
  5046. $citysiteList = get_citysite_list();
  5047. }
  5048. $topName = !empty($citysiteList[$site_info['topid']]) ? $citysiteList[$site_info['topid']]['name'] : '';
  5049. $parentName = !empty($citysiteList[$site_info['parent_id']]) ? $citysiteList[$site_info['parent_id']]['name'] : '';
  5050. if (1 == $site_info['level']) {
  5051. $topName = $parentName = '';
  5052. } else if (2 == $site_info['level']) {
  5053. $topName = '';
  5054. } else {
  5055. $topName = !empty($citysiteList[$site_info['topid']]) ? $citysiteList[$site_info['topid']]['name'] : '';
  5056. $parentName = !empty($citysiteList[$site_info['parent_id']]) ? $citysiteList[$site_info['parent_id']]['name'] : '';
  5057. }
  5058. $regionAll = $topName.$parentName.$site_info['name'];
  5059. $value = str_ireplace(['{parent}','{top}','{regionAll}'], [$parentName,$topName,$regionAll], $value);
  5060. }
  5061. }
  5062. }
  5063. return $value;
  5064. }
  5065. }
  5066. if (!function_exists('adminLoginAfter')) {
  5067. /**
  5068. * 管理员登录成功后的后置业务逻辑
  5069. * @return [type] [description]
  5070. */
  5071. function adminLoginAfter($admin_id = 0, $session_id = '', $third_type = '')
  5072. {
  5073. if (!empty($admin_id)) {
  5074. $admin_info = \think\Db::name('admin')->where(['admin_id'=>$admin_id])->find();
  5075. $role_id = !empty($admin_info['role_id']) ? $admin_info['role_id'] : -1;
  5076. $auth_role_info = array();
  5077. $is_founder = 0;
  5078. if (!empty($admin_info['parent_id'])) {
  5079. $role_name = '超级管理员';
  5080. } else {
  5081. $is_founder = 1;
  5082. $role_name = '创始人';
  5083. }
  5084. $admin_info['is_founder'] = $is_founder;
  5085. if (0 < intval($role_id)) {
  5086. $auth_role_info = \think\Db::name('auth_role')
  5087. ->field("a.*, a.name AS role_name")
  5088. ->alias('a')
  5089. ->where('a.id','eq', $role_id)
  5090. ->find();
  5091. if (!empty($auth_role_info)) {
  5092. $auth_role_info['language'] = unserialize($auth_role_info['language']);
  5093. $auth_role_info['cud'] = unserialize($auth_role_info['cud']);
  5094. $auth_role_info['permission'] = unserialize($auth_role_info['permission']);
  5095. $role_name = $auth_role_info['name'];
  5096. }
  5097. }
  5098. $admin_info['auth_role_info'] = $auth_role_info;
  5099. $admin_info['role_name'] = $role_name;
  5100. $last_login_time = getTime();
  5101. $last_login_ip = clientIP();
  5102. $login_cnt = $admin_info['login_cnt'] + 1;
  5103. \think\Db::name('admin')->where(['admin_id'=>$admin_info['admin_id']])->save(array('last_login'=>$last_login_time, 'last_ip'=>$last_login_ip, 'login_cnt'=>$login_cnt, 'session_id'=>$session_id));
  5104. $admin_info['last_login'] = $last_login_time;
  5105. $admin_info['last_ip'] = $last_login_ip;
  5106. // 头像
  5107. empty($admin_info['head_pic']) && $admin_info['head_pic'] = get_head_pic($admin_info['head_pic'], true);
  5108. // 多语言
  5109. $langRow = \think\Db::name('language')->order('id asc')
  5110. ->cache(true, EYOUCMS_CACHE_TIME, 'language')
  5111. ->select();
  5112. // 重置登录错误次数
  5113. $login_errnum_key = 'adminlogin_'.md5('login_errnum_'.$admin_info['user_name'].$last_login_ip);
  5114. $login_errtime_key = 'adminlogin_'.md5('login_errtime_'.$admin_info['user_name'].$last_login_ip);
  5115. $login_lock_key = 'adminlogin_'.md5('login_lock_'.$admin_info['user_name'].$last_login_ip); // 是否被锁定
  5116. foreach ($langRow as $key => $val) {
  5117. tpSetting('adminlogin', [$login_errnum_key=>0, $login_errtime_key=>0, $login_lock_key=>0], $val['mark']);
  5118. }
  5119. // 二次安全验证 - 每次登录后,如果没设置同IP不验证,则清除答案验证成功的IP记录
  5120. $security = tpSetting('security');
  5121. if (isset($security['security_ask_ip_open']) && empty($security['security_ask_ip_open'])) {
  5122. foreach ($langRow as $key => $val) {
  5123. tpSetting('security', ['security_answerverify_ip'=>''], $val['mark']);
  5124. }
  5125. }
  5126. // 第三方扫码登录
  5127. if (in_array($third_type, ['WechatLogin','EyouGzhLogin'])) {
  5128. $map = ['admin_id'=>$admin_id];
  5129. if ('EyouGzhLogin' == $third_type) {
  5130. $map['type'] = 1;
  5131. } else if ('WechatLogin' == $third_type) {
  5132. $map['type'] = 2;
  5133. }
  5134. $admin_info['openid'] = \think\Db::name('admin_wxlogin')->where($map)->value('openid');
  5135. }
  5136. $admin_info_new = $admin_info;
  5137. /*过滤存储在session文件的敏感信息*/
  5138. foreach (['user_name','true_name','password'] as $key => $val) {
  5139. unset($admin_info_new[$val]);
  5140. }
  5141. /*--end*/
  5142. // 保存后台session
  5143. session('admin_id', $admin_info['admin_id']);
  5144. session('admin_info', $admin_info_new);
  5145. session('admin_login_expire', getTime()); // 登录有效期
  5146. return $admin_info_new;
  5147. }
  5148. else {
  5149. session('admin_id', null);
  5150. session('admin_info', null);
  5151. session('admin_login_expire', null);
  5152. return false;
  5153. }
  5154. }
  5155. }
  5156. if (!function_exists('get_form_read_value')){
  5157. /**
  5158. * 表单数据类型转换
  5159. * $field_value 字段值
  5160. * $field_type 字段类型
  5161. * $domain 图片文件是否完整链接
  5162. */
  5163. function get_form_read_value($field_value,$field_type,$domain = false){
  5164. static $region_arr = null;
  5165. if (null === $region_arr) {
  5166. $region_arr = get_region_list();
  5167. }
  5168. if ('checkbox' == $field_type && !empty($field_value)) {
  5169. $field_value = str_replace(',', '] [', '['.$field_value.']');
  5170. }else if('region' == $field_type && !empty($field_value)){
  5171. if (is_string($field_value)) {
  5172. $field_value_arr = explode(',', $field_value);
  5173. } else {
  5174. $field_value_arr = $field_value;
  5175. }
  5176. $attr_value = [];
  5177. foreach ($field_value_arr as $key => $val) {
  5178. $attr_value[] = !empty($region_arr[$val]['name']) ? $region_arr[$val]['name'] : '';
  5179. }
  5180. $field_value = implode('',$attr_value);
  5181. }elseif (('file' == $field_type || 'img' == $field_type) && !empty($field_value)){
  5182. static $file_type = null;
  5183. null === $file_type && $file_type = tpCache('basic.file_type');
  5184. if(preg_match('/(\.(jpg|gif|png|bmp|jpeg|ico|webp))$/i', $field_value)){
  5185. if (!stristr($field_value, '|')) {
  5186. $field_value = handle_subdir_pic($field_value,'img',$domain);
  5187. $field_value = "<a href='{$field_value}' target='_blank'><img src='{$field_value}' width='60' height='60' style='float: unset;cursor: pointer;' /></a>";
  5188. }
  5189. }else if(preg_match('/(\.('.$file_type.'))$/i', $field_value)){
  5190. static $current_domain = null;
  5191. null === $current_domain && $current_domain = request()->domain();
  5192. if (!stristr($field_value, '|')) {
  5193. $field_value = handle_subdir_pic($field_value,'img',$domain);
  5194. $domain_new = "";
  5195. if ($domain){
  5196. $domain_new = $current_domain;
  5197. }
  5198. $field_value = "<a href='{$field_value}' download='".time()."'><img src=\"{$domain_new}".ROOT_DIR."/public/static/common/images/file.png\" alt=\"\" style=\"width: 16px;height: 16px;\">点击下载</a>";
  5199. }
  5200. }
  5201. }
  5202. return $field_value;
  5203. }
  5204. }
  5205. if (!function_exists('del_all_dir')){
  5206. //完整删除目录,以及目录下面所有文件(相比于rmdir不会产生错误报告)
  5207. function del_all_dir($path){
  5208. $path = rtrim($path, '/').'/';
  5209. //如果是目录则继续
  5210. if(is_dir($path)){
  5211. //扫描一个文件夹内的所有文件夹和文件并返回数组
  5212. $p = scandir($path);
  5213. //如果 $p 中有两个以上的元素则说明当前 $path 不为空
  5214. if(count($p)>2){
  5215. foreach($p as $val){
  5216. //排除目录中的.和..
  5217. if($val !="." && $val !=".."){
  5218. //如果是目录则递归子目录,继续操作
  5219. if(is_dir($path.$val)){
  5220. //子目录中操作删除文件夹和文件
  5221. del_all_dir($path.$val.'/');
  5222. }else{
  5223. //如果是文件直接删除
  5224. unlink($path.$val);
  5225. }
  5226. }
  5227. }
  5228. }
  5229. }
  5230. //删除目录
  5231. return @rmdir($path);
  5232. }
  5233. }
  5234. if (!function_exists('get_image_type')){
  5235. //获取图片的类型
  5236. function get_image_type($image)
  5237. {
  5238. if (function_exists('exif_imagetype')) {
  5239. return exif_imagetype($image);
  5240. }
  5241. try {
  5242. $info = getimagesize($image);
  5243. return $info ? $info[2] : false;
  5244. } catch (\Exception $e) {
  5245. return false;
  5246. }
  5247. }
  5248. }
  5249. if (!function_exists('get_all_arctype')){
  5250. /*
  5251. *
  5252. */
  5253. function get_all_arctype(){
  5254. $arctype_list = Db::name('arctype')->field("id,parent_id,dirname")->where([
  5255. 'is_del' => 0,
  5256. 'lang' => get_current_lang()
  5257. ])->order("grade asc")->getAllWithIndex("id");
  5258. return $arctype_list;
  5259. }
  5260. }
  5261. if (!function_exists('get_all_parent_dirpath')){
  5262. /*
  5263. *
  5264. */
  5265. function get_all_parent_dirpath($id,$arctype_list,&$parent_dir = ''){
  5266. !empty($arctype_list[$id]['dirname']) && $parent_dir = $arctype_list[$id]['dirname']."/".$parent_dir;
  5267. if (!empty($arctype_list[$id]['parent_id'])){
  5268. $parent_dir = get_all_parent_dirpath($arctype_list[$id]['parent_id'],$arctype_list,$parent_dir);
  5269. }
  5270. return $parent_dir;
  5271. }
  5272. }
  5273. if (!function_exists('clearHtmlCache')) {
  5274. /**
  5275. * 清理文档和相关页面缓存、数据
  5276. */
  5277. function clearHtmlCache($aids = [], $typeids = [])
  5278. {
  5279. $filelist = [];
  5280. $seoData = tpCache('seo');
  5281. if (!empty($aids)) {
  5282. $archivesList = \think\Db::name('archives')->field('aid,typeid,stypeid')->where(['aid'=>['IN', $aids]])->select();
  5283. foreach ($archivesList as $_k => $_v) {
  5284. $typeids[] = $_v['typeid'];
  5285. $_v['stypeid'] = trim($_v['stypeid'], ',');
  5286. $stypeid = explode(',', $_v['stypeid']);
  5287. foreach ($stypeid as $_k2 => $_v2) {
  5288. $typeids[] = $_v2;
  5289. }
  5290. }
  5291. if (!isset($seoData['seo_uphtml_after_pernext13']) || !empty($seoData['seo_uphtml_after_pernext13'])) {
  5292. // 文档
  5293. foreach ($aids as $_k => $_v) {
  5294. $arr = glob(HTML_ROOT.'view'.DS."*_{$_v}.html");
  5295. if (is_array($arr)) {
  5296. $filelist = array_merge($filelist, $arr);
  5297. }
  5298. }
  5299. // tag标签
  5300. $tagids = \think\Db::name('taglist')->where(['aid'=>['IN', $aids]])->group('tid')->column('tid');
  5301. foreach ($tagids as $_k => $_v) {
  5302. $arr = glob(HTML_ROOT.'tags'.DS."*_{$_v}.html");
  5303. if (is_array($arr)) {
  5304. $filelist = array_merge($filelist, $arr);
  5305. }
  5306. }
  5307. }
  5308. }
  5309. // 文档涉及的所有相关栏目ID
  5310. if (!empty($typeids)) {
  5311. if (!isset($seoData['seo_uphtml_after_channel13']) || !empty($seoData['seo_uphtml_after_channel13'])) {
  5312. $arctypeM = new \app\common\model\Arctype;
  5313. $typeid_list = $arctypeM->getAllPidByids($typeids);
  5314. foreach ($typeid_list as $_k => $_v) {
  5315. $arr = glob(HTML_ROOT.'lists'.DS."*_{$_v['id']}.html");
  5316. if (is_array($arr)) {
  5317. $filelist = array_merge($filelist, $arr);
  5318. }
  5319. }
  5320. }
  5321. }
  5322. // 删除页面缓存文件
  5323. if (!empty($filelist)) {
  5324. foreach ($filelist as $_k => $_v) {
  5325. @unlink($_v);
  5326. }
  5327. \think\Cache::clear();
  5328. }
  5329. if (!empty($aids)) {
  5330. if (!isset($seoData['seo_uphtml_after_home13']) || !empty($seoData['seo_uphtml_after_home13'])) {
  5331. delFile(HTML_ROOT.'index');
  5332. }
  5333. }
  5334. }
  5335. }
  5336. if (!function_exists('getToutiaoAccessToken'))
  5337. {
  5338. /**
  5339. * 返回字节小程序 access_token
  5340. * @param string $appid [description]
  5341. * @return [type] [description]
  5342. */
  5343. function getToutiaoAccessToken($appid = '', $secret = '', $salt = '', $resetToken = false)
  5344. {
  5345. // $data = tpSetting("OpenMinicode.conf_toutiao");
  5346. // $data = !empty($data) ? json_decode($data, true) : [];
  5347. // dump($data);
  5348. // exit;
  5349. $data = [
  5350. 'salt' => $salt,
  5351. 'appid' => $appid,
  5352. 'secret' => $secret,
  5353. ];
  5354. if (empty($data['appid'])) {
  5355. return [
  5356. 'code' => 0,
  5357. 'msg' => '请先完成字节小程序配置',
  5358. ];
  5359. }
  5360. // if (false === $resetToken && !empty($data['access_token']) && $data['expire_time'] > getTime()) {
  5361. // return [
  5362. // 'code' => 1,
  5363. // 'access_token' => $data['access_token'],
  5364. // ];
  5365. // }
  5366. $url = "https://developer.toutiao.com/api/apps/v2/token";
  5367. $postData = [
  5368. 'appid' => $data['appid'],
  5369. 'secret' => $data['secret'],
  5370. 'grant_type' => "client_credential",
  5371. ];
  5372. $headers = array("content-type: application/json");
  5373. $response = httpRequest($url, 'POST', json_encode($postData), $headers);
  5374. $params = json_decode($response, true);
  5375. if (!empty($params['data']['access_token'])) {
  5376. $data['access_token'] = $access_token = $params['data']['access_token'];
  5377. $data['expire_time'] = getTime() + $params['data']['expires_in'] - 1000;
  5378. tpSetting('OpenMinicode', ['conf_toutiao' => json_encode($data)]);
  5379. return [
  5380. 'code' => 1,
  5381. 'access_token' => $access_token,
  5382. 'appid' => !empty($data['appid']) ? $data['appid'] : '',
  5383. ];
  5384. }
  5385. // if (!empty($params['err_no'])) {
  5386. // $params = [
  5387. // 'errcode' => "-1",
  5388. // 'errmsg' => $params['err_tips'],
  5389. // ];
  5390. // }
  5391. return [
  5392. 'code' => 0,
  5393. 'msg' => !empty($params['errmsg']) ? $params['errmsg'] : '请检查小程序appid和secret是否正确',
  5394. ];
  5395. }
  5396. }
  5397. if (!function_exists('sitemap_auto'))
  5398. {
  5399. /**
  5400. * 自动生成引擎sitemap
  5401. */
  5402. function sitemap_auto()
  5403. {
  5404. $globalConfig = tpCache('global');
  5405. if (isset($globalConfig['sitemap_auto']) && $globalConfig['sitemap_auto'] > 0) {
  5406. sitemap_all();
  5407. }
  5408. }
  5409. }
  5410. if (!function_exists('sitemap_all'))
  5411. {
  5412. /**
  5413. * 生成全部引擎sitemap
  5414. */
  5415. function sitemap_all($type = 'all')
  5416. {
  5417. sitemap_xml($type);
  5418. }
  5419. }
  5420. if (!function_exists('sitemap_xml'))
  5421. {
  5422. /**
  5423. * 生成xml形式的sitemap,分页(入口页面、首页、栏目页、内容页、tags、问答)
  5424. * <mobile:mobile/> :移动网页
  5425. * <mobile:mobile type="mobile"/> :移动网页
  5426. * <mobile:mobile type="pc,mobile"/>:自适应网页 一个域名一个模板,
  5427. * <mobile:mobile type="htmladapt"/>:代码适配 一个域名两个模板,手机端浏览和pc端浏览显示内容不一样(根据硬件判断)
  5428. */
  5429. function sitemap_xml($type = 'all'){
  5430. $globalConfig = tpCache('global');
  5431. if (empty($globalConfig['sitemap_xml']) && empty($globalConfig['sitemap_txt'])) {
  5432. return '';
  5433. }
  5434. $response_type = config('ey_config.response_type'); // 0是代码适配,1:pc、移动端分离(存在pc、移动端两套模板)
  5435. $web_mobile_domain_open = $globalConfig['web_mobile_domain_open']; //是否开启手机端域名
  5436. $web_mobile_domain = $globalConfig['web_mobile_domain']; //手机端域名
  5437. $lang = get_current_lang();
  5438. $default_lang = get_default_lang();
  5439. $langRow = \think\Db::name('language')->field('is_home_default')->where(['mark'=>$lang])->find();
  5440. if (!empty($langRow['is_home_default'])) {
  5441. $filename = ROOT_PATH . "sitemap.xml";
  5442. $filename_txt = ROOT_PATH . "sitemap.txt";
  5443. } else {
  5444. $filename = ROOT_PATH . "sitemap_{$lang}.xml";
  5445. $filename_txt = ROOT_PATH . "sitemap_{$lang}.txt";
  5446. }
  5447. /* 分类列表(用于生成列表链接的sitemap) */
  5448. $map = array(
  5449. 'status' => 1,
  5450. 'is_del' => 0,
  5451. 'lang' => $lang,
  5452. );
  5453. if (is_array($globalConfig)) {
  5454. // 过滤隐藏栏目
  5455. if (isset($globalConfig['sitemap_not1']) && $globalConfig['sitemap_not1'] > 0) {
  5456. $map['is_hidden'] = 0;
  5457. }
  5458. // 过滤外部模块
  5459. if (isset($globalConfig['sitemap_not2']) && $globalConfig['sitemap_not2'] > 0) {
  5460. $map['is_part'] = 0;
  5461. }
  5462. }
  5463. $result_arctype = M('arctype')->field("*, id AS loc, add_time AS lastmod, 'hourly' AS changefreq, '0.8' AS priority")
  5464. ->where($map)
  5465. ->order('sort_order asc, id asc')
  5466. ->getAllWithIndex('id');
  5467. /* 文章列表(用于生成文章详情链接的sitemap) */
  5468. if (!isset($globalConfig['sitemap_archives_num']) || $globalConfig['sitemap_archives_num'] === '') {
  5469. $sitemap_archives_num = 1000;
  5470. } else {
  5471. $sitemap_archives_num = intval($globalConfig['sitemap_archives_num']);
  5472. }
  5473. $result_archives = [];
  5474. if (0 < $sitemap_archives_num) {
  5475. $map = array(
  5476. 'channel' => ['IN', config('global.allow_release_channel')],
  5477. 'arcrank' => array('gt', -1),
  5478. 'status' => 1,
  5479. 'is_del' => 0,
  5480. 'lang' => $lang,
  5481. );
  5482. if (is_array($globalConfig)) {
  5483. // 过滤外部模块
  5484. if (isset($globalConfig['sitemap_not2']) && $globalConfig['sitemap_not2'] > 0) {
  5485. $map['is_jump'] = 0;
  5486. }
  5487. }
  5488. /*定时文档显示插件*/
  5489. if (is_dir('./weapp/TimingTask/')) {
  5490. $weappModel = new \app\admin\model\Weapp;
  5491. $TimingTaskRow = $weappModel->getWeappList('TimingTask');
  5492. if (!empty($TimingTaskRow['status']) && 1 == $TimingTaskRow['status']) {
  5493. $map['add_time'] = ['elt', getTime()]; // 只显当天或之前的文档
  5494. }
  5495. }
  5496. /*end*/
  5497. $field = "aid, channel, is_jump, jumplinks, htmlfilename,province_id,city_id,area_id, add_time, update_time, typeid, aid AS loc, add_time AS lastmod, 'daily' AS changefreq, '0.5' AS priority";
  5498. $result_archives = M('archives')->field($field)
  5499. ->where($map)
  5500. ->order('aid desc')
  5501. ->limit($sitemap_archives_num)
  5502. ->select();
  5503. }
  5504. $urls_txt = []; // 记录sitemap里包含的URL,用于生成sitemap.txt文件
  5505. // header('Content-Type: text/xml');//这行很重要,php默认输出text/html格式的文件,所以这里明确告诉浏览器输出的格式为xml,不然浏览器显示不出xml的格式
  5506. $xml_wrapper = <<<XML
  5507. <?xml version='1.0' encoding='utf-8'?>
  5508. <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0">
  5509. </urlset>
  5510. XML;
  5511. if (function_exists('simplexml_load_string')) {
  5512. $xml = @simplexml_load_string($xml_wrapper);
  5513. } else if (class_exists('SimpleXMLElement')) {
  5514. $xml = new SimpleXMLElement($xml_wrapper);
  5515. }
  5516. if (!$xml) {
  5517. return true;
  5518. }
  5519. if($web_mobile_domain_open){
  5520. if (function_exists('simplexml_load_string')) {
  5521. $xml_mobile = @simplexml_load_string($xml_wrapper);
  5522. } else if (class_exists('SimpleXMLElement')) {
  5523. $xml_mobile = new SimpleXMLElement($xml_wrapper);
  5524. }
  5525. $urls_txt_mobile = [];
  5526. $filename_mobile = str_replace('sitemap','sitemap_'.$web_mobile_domain,$filename);
  5527. $filename_txt_mobile = str_replace('sitemap','sitemap_'.$web_mobile_domain,$filename_txt);
  5528. }
  5529. // 更新频率
  5530. $sitemap_changefreq_index = !empty($globalConfig['sitemap_changefreq_index']) ? $globalConfig['sitemap_changefreq_index'] : 'always';
  5531. $sitemap_changefreq_list = !empty($globalConfig['sitemap_changefreq_list']) ? $globalConfig['sitemap_changefreq_list'] : 'hourly';
  5532. $sitemap_changefreq_view = !empty($globalConfig['sitemap_changefreq_view']) ? $globalConfig['sitemap_changefreq_view'] : 'daily';
  5533. // 优先级别
  5534. $sitemap_priority_index = !empty($globalConfig['sitemap_priority_index']) ? $globalConfig['sitemap_priority_index'] : '1.0';
  5535. $sitemap_priority_list = !empty($globalConfig['sitemap_priority_list']) ? $globalConfig['sitemap_priority_list'] : '0.8';
  5536. $sitemap_priority_view = !empty($globalConfig['sitemap_priority_view']) ? $globalConfig['sitemap_priority_view'] : '0.5';
  5537. $langRow = \think\Db::name('language')
  5538. ->where(['status'=>1])
  5539. ->order('id asc')
  5540. ->cache(true, EYOUCMS_CACHE_TIME, 'language')
  5541. ->select();
  5542. // 去掉入口文件
  5543. $inletStr = '/index.php';
  5544. $seo_inlet = config('ey_config.seo_inlet');
  5545. 1 == intval($seo_inlet) && $inletStr = '';
  5546. $now = date('Y-m-d');
  5547. // 首页
  5548. if ($lang == $default_lang) {
  5549. foreach ($langRow as $key => $val) {
  5550. $mark = $val['mark'];
  5551. if (empty($globalConfig['web_language_switch']) && $lang != $mark) { // 关闭多语言
  5552. continue;
  5553. }
  5554. /*单独域名*/
  5555. $url = $val['url'];
  5556. if (empty($url)) {
  5557. if (1 == $val['is_home_default']) {
  5558. $url = request()->domain().ROOT_DIR.'/';
  5559. } else {
  5560. if ($mark != $default_lang) {
  5561. $url = request()->domain().ROOT_DIR."/sitemap_{$mark}.xml";
  5562. } else {
  5563. $global_config_tmp = tpCache('global', [], $mark);
  5564. $seo_pseudo = !empty($global_config_tmp['seo_pseudo']) ? $global_config_tmp['seo_pseudo'] : config('ey_config.seo_pseudo');
  5565. if (1 == $seo_pseudo) {
  5566. $url = request()->domain().ROOT_DIR.$inletStr;
  5567. if (!empty($inletStr)) {
  5568. $url .= '?';
  5569. } else {
  5570. $url .= '/?';
  5571. }
  5572. $url .= http_build_query(['lang'=>$mark]);
  5573. } else {
  5574. $url = request()->domain().ROOT_DIR.$inletStr.'/'.$mark;
  5575. }
  5576. }
  5577. }
  5578. } else {
  5579. if (0 == $val['is_home_default']) {
  5580. $url = $url.ROOT_DIR."/sitemap_{$mark}.xml";
  5581. }
  5582. }
  5583. /*--end*/
  5584. if ($web_mobile_domain_open){ //两个域名,生成两次,移动端添加标签:<mobile:mobile type="mobile"/>
  5585. $xml = join_xml($xml,$url,$now,$sitemap_changefreq_index,$sitemap_priority_index,'pc');
  5586. array_push($urls_txt, str_replace('.xml', '.txt', htmlspecialchars_decode($url)));
  5587. if($xml_mobile){
  5588. $url = pc_to_mobile_url($url);
  5589. $xml_mobile = join_xml($xml_mobile,$url,$now,$sitemap_changefreq_index,$sitemap_priority_index,'mobile');
  5590. if (!in_array($url, $urls_txt_mobile)) {
  5591. array_push($urls_txt_mobile, str_replace('.xml', '.txt', htmlspecialchars_decode($url)));
  5592. }
  5593. }
  5594. }else{ //一个域名
  5595. if ($response_type){ //pc、移动端分离 <mobile:mobile type="htmladapt"/>
  5596. $xml = join_xml($xml,$url,$now,$sitemap_changefreq_index,$sitemap_priority_index,'htmladapt');
  5597. }else{ //代码适配 <mobile:mobile type="pc,mobile"/>
  5598. $xml =join_xml($xml,$url,$now,$sitemap_changefreq_index,$sitemap_priority_index,'pc,mobile');
  5599. }
  5600. array_push($urls_txt, htmlspecialchars_decode($url));
  5601. }
  5602. }
  5603. }
  5604. else {
  5605. foreach ($langRow as $key => $val) {
  5606. $mark = $val['mark'];
  5607. if (empty($globalConfig['web_language_switch']) || $lang != $mark) { // 关闭多语言
  5608. continue;
  5609. }
  5610. /*单独域名*/
  5611. $url = $val['url'];
  5612. if (empty($url)) {
  5613. $global_config_tmp = tpCache('global', [], $mark);
  5614. $seo_pseudo = !empty($global_config_tmp['seo_pseudo']) ? $global_config_tmp['seo_pseudo'] : config('ey_config.seo_pseudo');
  5615. if (1 == $seo_pseudo) {
  5616. $url = request()->domain().ROOT_DIR.$inletStr;
  5617. if (!empty($inletStr)) {
  5618. $url .= '?';
  5619. } else {
  5620. $url .= '/?';
  5621. }
  5622. $url .= http_build_query(['lang'=>$mark]);
  5623. } else {
  5624. $url = request()->domain().ROOT_DIR.$inletStr.'/'.$mark;
  5625. }
  5626. }
  5627. /*--end*/
  5628. /*--end*/
  5629. if ($web_mobile_domain_open){ //两个域名,生成两次,移动端添加标签:<mobile:mobile type="mobile"/>
  5630. $xml = join_xml($xml,$url,$now,$sitemap_changefreq_index,$sitemap_priority_index,'pc');
  5631. array_push($urls_txt, htmlspecialchars_decode($url));
  5632. if($xml_mobile){
  5633. $url = pc_to_mobile_url($url);
  5634. $xml_mobile = join_xml($xml_mobile,$url,$now,$sitemap_changefreq_index,$sitemap_priority_index,'mobile');
  5635. array_push($urls_txt_mobile, str_replace('.xml', '.txt', htmlspecialchars_decode($url)));
  5636. }
  5637. }else{ //一个域名
  5638. if ($response_type){ //pc、移动端分离 <mobile:mobile type="pc,mobile"/>
  5639. $xml = join_xml($xml,$url,$now,$sitemap_changefreq_index,$sitemap_priority_index,'htmladapt');
  5640. }else{ //代码适配 <mobile:mobile type="htmladapt"/>
  5641. $xml =join_xml($xml,$url,$now,$sitemap_changefreq_index,$sitemap_priority_index,'pc,mobile');
  5642. }
  5643. array_push($urls_txt, htmlspecialchars_decode($url));
  5644. }
  5645. }
  5646. }
  5647. /*--end*/
  5648. /*所有栏目*/
  5649. foreach ($result_arctype as $sub) {
  5650. if (is_array($sub)) {
  5651. if ($sub['is_part'] == 1) {
  5652. $url = $sub['typelink'];
  5653. } else {
  5654. $url = get_typeurl($sub, false);
  5655. }
  5656. $url = str_replace('&amp;', '&', $url);
  5657. $url = str_replace('&', '&amp;', $url);
  5658. if ($web_mobile_domain_open){ //两个域名,生成两次,移动端添加标签:<mobile:mobile type="mobile"/>
  5659. $xml = join_xml($xml,$url,$now,$sitemap_changefreq_list,$sitemap_priority_list,'pc');
  5660. array_push($urls_txt, htmlspecialchars_decode($url));
  5661. if($xml_mobile){
  5662. $url = get_typeurl($sub, false,'mobile'); //pc_to_mobile_url($url,$sub['id']);
  5663. $url = str_replace('&amp;', '&', $url);
  5664. $url = str_replace('&', '&amp;', $url);
  5665. $xml_mobile = join_xml($xml_mobile,$url,$now,$sitemap_changefreq_index,$sitemap_priority_index,'mobile');
  5666. array_push($urls_txt_mobile, str_replace('.xml', '.txt', htmlspecialchars_decode($url)));
  5667. }
  5668. }else{ //一个域名
  5669. if ($response_type){ //pc、移动端分离 <mobile:mobile type="pc,mobile"/>
  5670. $xml = join_xml($xml,$url,$now,$sitemap_changefreq_list,$sitemap_priority_list,'htmladapt');
  5671. }else{ //代码适配 <mobile:mobile type="htmladapt"/>
  5672. $xml =join_xml($xml,$url,$now,$sitemap_changefreq_list,$sitemap_priority_list,'pc,mobile');
  5673. }
  5674. array_push($urls_txt, htmlspecialchars_decode($url));
  5675. }
  5676. }
  5677. }
  5678. /*--end*/
  5679. /*所有文档*/
  5680. foreach ($result_archives as $val) {
  5681. if (is_array($val) && isset($result_arctype[$val['typeid']])) {
  5682. $val = array_merge($result_arctype[$val['typeid']], $val);
  5683. if ($val['is_jump'] == 1) {
  5684. $url = $val['jumplinks'];
  5685. } else {
  5686. $url = get_arcurl($val, false);
  5687. }
  5688. $url = str_replace('&amp;', '&', $url);
  5689. $url = str_replace('&', '&amp;', $url);
  5690. $lastmod_time = empty($val['update_time']) ? $val['add_time'] : $val['update_time'];
  5691. $time_row = date('Y-m-d', $lastmod_time);
  5692. if ($web_mobile_domain_open){ //两个域名,生成两次,移动端添加标签:<mobile:mobile type="mobile"/>
  5693. $xml = join_xml($xml,$url,$time_row,$sitemap_changefreq_view,$sitemap_priority_view,'pc');
  5694. array_push($urls_txt, htmlspecialchars_decode($url));
  5695. if($xml_mobile){
  5696. $url = get_arcurl($val, false,'mobile'); //pc_to_mobile_url($url,$val['typeid'],$val['aid']);
  5697. $url = str_replace('&amp;', '&', $url);
  5698. $url = str_replace('&', '&amp;', $url);
  5699. $xml_mobile = join_xml($xml_mobile,$url,$now,$sitemap_changefreq_index,$sitemap_priority_index,'mobile');
  5700. array_push($urls_txt_mobile, str_replace('.xml', '.txt', htmlspecialchars_decode($url)));
  5701. }
  5702. }else{ //一个域名
  5703. if ($response_type){ //pc、移动端分离 <mobile:mobile type="pc,mobile"/>
  5704. $xml = join_xml($xml,$url,$time_row,$sitemap_changefreq_view,$sitemap_priority_view,'htmladapt');
  5705. }else{ //代码适配 <mobile:mobile type="htmladapt"/>
  5706. $xml =join_xml($xml,$url,$time_row,$sitemap_changefreq_view,$sitemap_priority_view,'pc,mobile');
  5707. }
  5708. array_push($urls_txt, htmlspecialchars_decode($url));
  5709. }
  5710. }
  5711. }
  5712. /*--end*/
  5713. /*所有Tag*/
  5714. /* Tag列表(用于生成Tag标签链接的sitemap) */
  5715. //判断模板文件是否存在
  5716. if (!isset($globalConfig['sitemap_tags_num']) || $globalConfig['sitemap_tags_num'] === '') {
  5717. $sitemap_tags_num = 1000;
  5718. } else {
  5719. $sitemap_tags_num = intval($globalConfig['sitemap_tags_num']);
  5720. }
  5721. $web_tpl_theme = !empty($globalConfig['web_tpl_theme']) ? "/".$globalConfig['web_tpl_theme'] : '';
  5722. if (is_file('./template'.$web_tpl_theme.'/pc/lists_tags.htm') && $sitemap_tags_num > 0){
  5723. $result_tags = [];
  5724. if (0 < $sitemap_tags_num) {
  5725. $map = array(
  5726. 'lang' => $lang,
  5727. );
  5728. $field = "id, add_time, id AS loc, add_time AS lastmod, 'daily' AS changefreq, '0.5' AS priority";
  5729. $result_tags = M('tagindex')->field($field)
  5730. ->where($map)
  5731. ->order('add_time desc')
  5732. ->limit($sitemap_tags_num)
  5733. ->select();
  5734. }
  5735. foreach ($result_tags as $val) {
  5736. if (is_array($val)) {
  5737. $url = get_tagurl($val['id']);
  5738. $url = str_replace('&amp;', '&', $url);
  5739. $url = str_replace('&', '&amp;', $url);
  5740. $lastmod_time = empty($val['update_time']) ? $val['add_time'] : $val['update_time'];
  5741. $time_row = date('Y-m-d', $lastmod_time);
  5742. if ($web_mobile_domain_open){ //两个域名,生成两次,移动端添加标签:<mobile:mobile type="mobile"/>
  5743. $xml = join_xml($xml,$url,$time_row,$sitemap_changefreq_view,$sitemap_priority_view,'pc');
  5744. array_push($urls_txt, htmlspecialchars_decode($url));
  5745. if($xml_mobile){
  5746. $url = get_tagurl($val['id'],'mobile');
  5747. $url = str_replace('&amp;', '&', $url);
  5748. $url = str_replace('&', '&amp;', $url);
  5749. $xml_mobile = join_xml($xml_mobile,$url,$now,$sitemap_changefreq_index,$sitemap_priority_index,'mobile');
  5750. array_push($urls_txt_mobile, str_replace('.xml', '.txt', htmlspecialchars_decode($url)));
  5751. }
  5752. }else{ //一个域名
  5753. if ($response_type){ //pc、移动端分离 <mobile:mobile type="pc,mobile"/>
  5754. $xml = join_xml($xml,$url,$time_row,$sitemap_changefreq_view,$sitemap_priority_view,'htmladapt');
  5755. }else{ //代码适配 <mobile:mobile type="htmladapt"/>
  5756. $xml =join_xml($xml,$url,$time_row,$sitemap_changefreq_view,$sitemap_priority_view,'pc,mobile');
  5757. }
  5758. array_push($urls_txt, htmlspecialchars_decode($url));
  5759. }
  5760. }
  5761. }
  5762. }
  5763. /*--end*/
  5764. /*--问答插件begin*/
  5765. if (is_dir('./weapp/Ask/')){
  5766. try{
  5767. $Askow = \think\Db::name("weapp")->where(['code'=>'Ask'])->field("status,data")->find();
  5768. if (!empty($Askow['status']) && 1 == $Askow['status']) {
  5769. $ask_map = [
  5770. 'is_review' =>1,
  5771. ];
  5772. $mobile_domain = tpCache('global.web_mobile_domain');
  5773. $ask_seo_pseudo = 1;
  5774. $Askow['data'] = unserialize($Askow['data']);
  5775. if (!empty($Askow['data']['seo_pseudo'])) {
  5776. $ask_seo_pseudo = intval($Askow['data']['seo_pseudo']);
  5777. }
  5778. //问答首页
  5779. $ask_list[] = [
  5780. 'url' => auto_hide_index(url('plugins/Ask/index', [], true, true, $ask_seo_pseudo)),
  5781. 'title' => "问答首页",
  5782. 'add_time' =>time(),
  5783. 'mobile_url' => auto_hide_index(url('plugins/Ask/index', [], true, $mobile_domain, $ask_seo_pseudo)),
  5784. ];
  5785. //问答栏目
  5786. $result_ask_type = \think\Db::name("weapp_ask_type")->field("type_id,type_name,update_time")->order('sort_order asc')->select();
  5787. foreach ($result_ask_type as $val){
  5788. $ask_list[] = [
  5789. 'url' => auto_hide_index(url('plugins/Ask/index', ['type_id'=>$val['type_id']],true,true,$ask_seo_pseudo)),
  5790. 'title' => $val['type_name'],
  5791. 'update_time' =>$val['update_time'],
  5792. 'mobile_url' => auto_hide_index(url('plugins/Ask/index', ['type_id'=>$val['type_id']],true,$mobile_domain,$ask_seo_pseudo)),
  5793. ];
  5794. }
  5795. //问答内容
  5796. $result_ask = \think\Db::name('weapp_ask')->field('ask_id,type_id,ask_title,update_time')
  5797. ->where($ask_map)
  5798. ->order('ask_id desc')
  5799. ->select();
  5800. foreach ($result_ask as $val){
  5801. $ask_list[] = [
  5802. 'url' => auto_hide_index(url('plugins/Ask/details', ['ask_id'=>$val['ask_id']],true,true,$ask_seo_pseudo)),
  5803. 'title' => $val['ask_title'],
  5804. 'update_time' =>$val['update_time'],
  5805. 'mobile_url' => auto_hide_index(url('plugins/Ask/details', ['ask_id'=>$val['ask_id']],true,$mobile_domain,$ask_seo_pseudo)),
  5806. ];
  5807. }
  5808. foreach ($ask_list as $val) {
  5809. if (is_array($val)) {
  5810. $url = $val['url'];
  5811. $url = str_replace('&amp;', '&', $url);
  5812. $url = str_replace('&', '&amp;', $url);
  5813. $lastmod_time = empty($val['update_time']) ? $val['add_time'] : $val['update_time'];
  5814. $time_row = date('Y-m-d', $lastmod_time);
  5815. if ($web_mobile_domain_open){ //两个域名,生成两次,移动端添加标签:<mobile:mobile type="mobile"/>
  5816. $xml = join_xml($xml,$url,$time_row,$sitemap_changefreq_view,$sitemap_priority_view,'pc');
  5817. array_push($urls_txt, htmlspecialchars_decode($url));
  5818. if($xml_mobile){
  5819. $url = $val['mobile_url'];
  5820. $url = str_replace('&amp;', '&', $url);
  5821. $url = str_replace('&', '&amp;', $url);
  5822. $xml_mobile = join_xml($xml_mobile,$url,$now,$sitemap_changefreq_index,$sitemap_priority_index,'mobile');
  5823. array_push($urls_txt_mobile, str_replace('.xml', '.txt', htmlspecialchars_decode($url)));
  5824. }
  5825. }else{ //一个域名
  5826. if ($response_type){ //pc、移动端分离 <mobile:mobile type="pc,mobile"/>
  5827. $xml = join_xml($xml,$url,$time_row,$sitemap_changefreq_view,$sitemap_priority_view,'htmladapt');
  5828. }else{ //代码适配 <mobile:mobile type="htmladapt"/>
  5829. $xml =join_xml($xml,$url,$time_row,$sitemap_changefreq_view,$sitemap_priority_view,'pc,mobile');
  5830. }
  5831. array_push($urls_txt, htmlspecialchars_decode($url));
  5832. }
  5833. }
  5834. }
  5835. }
  5836. }catch (\Exception $e){}
  5837. }
  5838. /*--end*/
  5839. if ($type == 'xml' || (!empty($globalConfig['sitemap_xml']) && in_array($type, ['all','xml']))) {
  5840. if($xml && $filename){
  5841. $content = $xml->asXML(); //用asXML方法输出xml,默认只构造不输出。
  5842. @file_put_contents($filename, $content);
  5843. }
  5844. if(!empty($xml_mobile) && !empty($filename_mobile)){
  5845. $content = $xml_mobile->asXML(); //用asXML方法输出xml,默认只构造不输出。
  5846. @file_put_contents($filename_mobile, $content);
  5847. }
  5848. }
  5849. if ($type == 'txt' || (!empty($globalConfig['sitemap_txt']) && in_array($type, ['all','txt']))) {
  5850. if($urls_txt && $filename_txt){
  5851. $content = implode(PHP_EOL, $urls_txt);
  5852. @file_put_contents($filename_txt, $content);
  5853. }
  5854. if(!empty($urls_txt_mobile) && !empty($filename_txt_mobile)){
  5855. $content = implode(PHP_EOL, $urls_txt_mobile);
  5856. @file_put_contents($filename_txt_mobile, $content);
  5857. }
  5858. }
  5859. }
  5860. }
  5861. if (!function_exists('join_xml'))
  5862. {
  5863. /**
  5864. * 拼接xml
  5865. */
  5866. function join_xml($xml,$loc,$lastmod,$changefreq,$priority,$model = 'pc')
  5867. {
  5868. $item = $xml->addChild('url'); //使用addChild添加节点
  5869. foreach (['loc','lastmod','changefreq','priority'] as $key1) {
  5870. if ('loc' == $key1) {
  5871. $row = $loc;
  5872. } else if ('lastmod' == $key1) {
  5873. $row = $lastmod;
  5874. } else if ('changefreq' == $key1) {
  5875. $row = $changefreq;
  5876. } else if ('priority' == $key1) {
  5877. $row = $priority;
  5878. }
  5879. try {
  5880. $node = $item->addChild($key1, $row);
  5881. } catch (\Exception $e) {}
  5882. if (isset($attribute_array[$key1]) && is_array($attribute_array[$key1])) {
  5883. foreach ($attribute_array[$key1] as $akey => $aval) {//设置属性值,我这里为空
  5884. $node->addAttribute($akey, $aval);
  5885. }
  5886. }
  5887. }
  5888. if ($model == 'mobile'){ //移动端
  5889. $item->addChild('mobile','','http://www.google.com/schemas/sitemap-mobile/1.0')->addAttribute("type","mobile");
  5890. }else if($model == 'pc,mobile'){
  5891. $item->addChild('mobile','','http://www.google.com/schemas/sitemap-mobile/1.0')->addAttribute("type","pc,mobile");
  5892. }else if($model == 'htmladapt'){
  5893. $item->addChild('mobile','','http://www.google.com/schemas/sitemap-mobile/1.0')->addAttribute("type","htmladapt");
  5894. }
  5895. return $xml;
  5896. }
  5897. }
  5898. if (!function_exists('to_index'))
  5899. {
  5900. function to_index($code="404"){
  5901. header('HTTP/1.1 301 Moved Permanently');
  5902. // 设置新的位置为主页URL
  5903. header('Location: https://www.zc10000.com');
  5904. // 确保之后的代码不会执行
  5905. exit();
  5906. //abort(404,'页面不存在') 批量替换成 to_index();
  5907. }
  5908. }
  5909. if (!function_exists('get_typeurl'))
  5910. {
  5911. /**
  5912. * 获取栏目链接
  5913. *
  5914. * @param array $arctype_info 栏目信息
  5915. * @param boolean $admin 后台访问链接,还是前台链接
  5916. * $domain_type mobile:手机端
  5917. */
  5918. function get_typeurl($arctype_info = array(), $admin = true,$domain_type = '')
  5919. {
  5920. /*问答模型*/
  5921. if ($arctype_info['current_channel'] == 51) {
  5922. $typeurl = get_askurl("home/Ask/index");
  5923. // 自动隐藏index.php入口文件
  5924. $typeurl = auto_hide_index($typeurl);
  5925. return $typeurl;
  5926. }
  5927. /*end*/
  5928. $domain = null; //static $domain = null; //pc移动交替生成时候混乱
  5929. null === $domain && $domain = request()->domain();
  5930. if ($domain_type == 'mobile'){
  5931. $web_mobile_domain = tpCache('global.web_mobile_domain');
  5932. if (!empty($web_mobile_domain)){
  5933. $subDomain = request()->subDomain();
  5934. $domain = str_replace($subDomain,$web_mobile_domain,$domain);
  5935. }
  5936. }
  5937. /*兼容采集没有归属栏目的文档*/
  5938. if (empty($arctype_info['current_channel'])) {
  5939. $channelRow = \think\Db::name('channeltype')->field('id as channel')
  5940. ->where('id',1)
  5941. ->find();
  5942. $arctype_info = array_merge($arctype_info, $channelRow);
  5943. }
  5944. /*--end*/
  5945. static $result = null;
  5946. null === $result && $result = model('Channeltype')->getAll('id, ctl_name', array(), 'id');
  5947. $ctl_name = '';
  5948. if ($result) {
  5949. $ctl_name = $result[$arctype_info['current_channel']]['ctl_name'];
  5950. }
  5951. static $seo_pseudo = null;
  5952. static $seo_dynamic_format = null;
  5953. if (null === $seo_pseudo || null === $seo_dynamic_format) {
  5954. $globalConfig = tpCache('global');
  5955. $seo_pseudo = !empty($globalConfig['seo_pseudo']) ? $globalConfig['seo_pseudo'] : config('ey_config.seo_pseudo');
  5956. $seo_dynamic_format = !empty($globalConfig['seo_dynamic_format']) ? $globalConfig['seo_dynamic_format'] : config('ey_config.seo_dynamic_format');
  5957. }
  5958. if (2 == $seo_pseudo && $admin) {
  5959. static $lang = null;
  5960. null === $lang && $lang = input('param.lang/s', 'cn');
  5961. $typeurl = ROOT_DIR."/index.php?m=home&c=Lists&a=index&tid={$arctype_info['id']}&lang={$lang}&t=".getTime();
  5962. } else {
  5963. $typeurl = typeurl("home/{$ctl_name}/lists", $arctype_info, true, $domain, $seo_pseudo, $seo_dynamic_format);
  5964. // 自动隐藏index.php入口文件
  5965. $typeurl = auto_hide_index($typeurl);
  5966. }
  5967. return $typeurl;
  5968. }
  5969. }
  5970. if (!function_exists('get_askurl'))
  5971. {
  5972. /**
  5973. * 获取问答链接
  5974. *
  5975. * @param array $arctype_info 栏目信息
  5976. * @param boolean $admin 后台访问链接,还是前台链接
  5977. */
  5978. function get_askurl($url = '', $ask_info = array(), $admin = true)
  5979. {
  5980. static $domain = null;
  5981. null === $domain && $domain = request()->domain();
  5982. static $seo_pseudo = null;
  5983. static $seo_dynamic_format = null;
  5984. if (null === $seo_pseudo || null === $seo_dynamic_format) {
  5985. $globalConfig = tpCache('global');
  5986. $seo_pseudo = !empty($globalConfig['seo_pseudo']) ? $globalConfig['seo_pseudo'] : config('ey_config.seo_pseudo');
  5987. $seo_dynamic_format = !empty($globalConfig['seo_dynamic_format']) ? $globalConfig['seo_dynamic_format'] : config('ey_config.seo_dynamic_format');
  5988. }
  5989. $askurl = askurl($url, $ask_info, true, $domain, $seo_pseudo, $seo_dynamic_format);
  5990. // 自动隐藏index.php入口文件
  5991. $askurl = auto_hide_index($askurl);
  5992. return $askurl;
  5993. }
  5994. }
  5995. if (!function_exists('get_arcurl'))
  5996. {
  5997. /**
  5998. * 获取文档链接
  5999. *
  6000. * @param array $arctype_info 栏目信息
  6001. * @param boolean $admin 后台访问链接,还是前台链接
  6002. * @param string $domain_type mobile:手机端
  6003. */
  6004. function get_arcurl($arcview_info = array(), $admin = true,$domain_type = '')
  6005. {
  6006. $domain = null; //static $domain = null; //pc移动交替生成时候混乱
  6007. null === $domain && $domain = request()->domain();
  6008. if ($domain_type == 'mobile'){
  6009. $web_mobile_domain = tpCache('global.web_mobile_domain');
  6010. if (!empty($web_mobile_domain)){
  6011. $subDomain = request()->subDomain();
  6012. $domain = str_replace($subDomain,$web_mobile_domain,$domain);
  6013. }
  6014. }
  6015. /*兼容采集没有归属栏目的文档*/
  6016. if (!empty($arcview_info) && empty($arcview_info['channel'])) {
  6017. $channelRow = \think\Db::name('channeltype')->field('id as channel')
  6018. ->where('id',1)
  6019. ->find();
  6020. $arcview_info = array_merge($arcview_info, $channelRow);
  6021. }
  6022. /*--end*/
  6023. static $result = null;
  6024. null === $result && $result = model('Channeltype')->getAll('id, ctl_name', array(), 'id');
  6025. $ctl_name = '';
  6026. if ($result) {
  6027. $ctl_name = $result[$arcview_info['channel']]['ctl_name'];
  6028. }
  6029. static $seo_pseudo = null;
  6030. static $seo_dynamic_format = null;
  6031. if (null === $seo_pseudo || null === $seo_dynamic_format) {
  6032. $globalConfig = tpCache('global');
  6033. $seo_pseudo = !empty($globalConfig['seo_pseudo']) ? $globalConfig['seo_pseudo'] : config('ey_config.seo_pseudo');
  6034. $seo_dynamic_format = !empty($globalConfig['seo_dynamic_format']) ? $globalConfig['seo_dynamic_format'] : config('ey_config.seo_dynamic_format');
  6035. }
  6036. if ($admin) {
  6037. if (2 == $seo_pseudo) {
  6038. static $lang = null;
  6039. null === $lang && $lang = input('param.lang/s', 'cn');
  6040. $arcurl = ROOT_DIR."/index.php?m=home&c=View&a=index&aid={$arcview_info['aid']}&lang={$lang}&admin_id=".session('admin_id');
  6041. } else {
  6042. $arcurl = arcurl("home/{$ctl_name}/view", $arcview_info, true, $domain, $seo_pseudo, $seo_dynamic_format);
  6043. if (config('city_switch_on')) {
  6044. $url_path = parse_url($arcurl, PHP_URL_PATH);
  6045. $url_path = str_replace('.html', '', $url_path);
  6046. $url_path = '/'.trim($url_path, '/').'/';
  6047. preg_match_all('/\/site\/([^\/]+)\//', $url_path, $matches);
  6048. $site_domain = !empty($matches[1][0]) ? $matches[1][0] : '';
  6049. if (!empty($site_domain)) {
  6050. $url_path_new = str_replace("/site/{$site_domain}/", '', $url_path);
  6051. $root_dir_str = str_replace('/', '\/', ROOT_DIR);
  6052. $url_path_new = preg_replace("/^{$root_dir_str}\//", ROOT_DIR."/{$site_domain}/", $url_path_new);
  6053. $arcurl = str_replace(rtrim($url_path, '/'), $url_path_new, $arcurl);
  6054. }
  6055. }
  6056. // 自动隐藏index.php入口文件
  6057. $arcurl = auto_hide_index($arcurl);
  6058. if (stristr($arcurl, '?')) {
  6059. $arcurl .= '&admin_id='.session('admin_id');
  6060. } else {
  6061. $arcurl .= '?admin_id='.session('admin_id');
  6062. }
  6063. }
  6064. } else {
  6065. $arcurl = arcurl("home/{$ctl_name}/view", $arcview_info, true, $domain, $seo_pseudo, $seo_dynamic_format);
  6066. if (config('city_switch_on')) {
  6067. $url_path = parse_url($arcurl, PHP_URL_PATH);
  6068. $url_path = str_replace('.html', '', $url_path);
  6069. $url_path = '/'.trim($url_path, '/').'/';
  6070. preg_match_all('/\/site\/([^\/]+)\//', $url_path, $matches);
  6071. $site_domain = !empty($matches[1][0]) ? $matches[1][0] : '';
  6072. if (!empty($site_domain)) {
  6073. $url_path_new = str_replace("/site/{$site_domain}/", '', $url_path);
  6074. $root_dir_str = str_replace('/', '\/', ROOT_DIR);
  6075. $url_path_new = preg_replace("/^{$root_dir_str}\//", ROOT_DIR."/{$site_domain}/", $url_path_new);
  6076. $arcurl = str_replace(rtrim($url_path, '/'), $url_path_new, $arcurl);
  6077. }
  6078. }
  6079. // 自动隐藏index.php入口文件
  6080. $arcurl = auto_hide_index($arcurl);
  6081. }
  6082. return $arcurl;
  6083. }
  6084. }
  6085. if (!function_exists('get_tagurl'))
  6086. {
  6087. /**
  6088. * 获取标签链接
  6089. *
  6090. * @param array $tagid 标签ID
  6091. */
  6092. function get_tagurl($tagid = '',$domain_type = '')
  6093. {
  6094. if ($domain_type == 'mobile'){
  6095. $domain = tpCache('global.web_mobile_domain');
  6096. }else{
  6097. static $domain = null;
  6098. null === $domain && $domain = true;
  6099. }
  6100. $tagurl = tagurl("home/Tags/lists", ['tagid'=>$tagid], true, $domain);
  6101. // static $seo_pseudo = null;
  6102. // static $seo_dynamic_format = null;
  6103. // if (null === $seo_pseudo || null === $seo_dynamic_format) {
  6104. // $globalConfig = tpCache('global');
  6105. // $seo_pseudo = !empty($globalConfig['seo_pseudo']) ? $globalConfig['seo_pseudo'] : config('ey_config.seo_pseudo');
  6106. // $seo_dynamic_format = !empty($globalConfig['seo_dynamic_format']) ? $globalConfig['seo_dynamic_format'] : config('ey_config.seo_dynamic_format');
  6107. // }
  6108. // $tagurl = tagurl("home/Tags/lists", ['tagid'=>$tagid], true, $domain, $seo_pseudo, $seo_dynamic_format);
  6109. // 自动隐藏index.php入口文件
  6110. $tagurl = auto_hide_index($tagurl);
  6111. return $tagurl;
  6112. }
  6113. }
  6114. if (!function_exists('handleEyouDataValidate'))
  6115. {
  6116. /**
  6117. * 处理数据验证
  6118. * $required 必填项字段
  6119. * $token 验证token名称
  6120. * $post 提交验证的数组
  6121. * $error 必填项不存在时的错误提示
  6122. */
  6123. function handleEyouDataValidate($required = '', $token = '', $post = [], $error = '数据不存在!')
  6124. {
  6125. if (empty($required)) return '请传入必填项字段';
  6126. if (empty($token)) return '请传入验证token名称';
  6127. if (empty($post)) return '请传入提交验证的数组';
  6128. $rule = [
  6129. $required => 'require|token:'.$token.'',
  6130. ];
  6131. $message = [
  6132. $required . '.require' => $error,
  6133. ];
  6134. $validate = new \think\Validate($rule, $message);
  6135. if (!$validate->batch()->check($post)) {
  6136. $getError = $validate->getError();
  6137. $errorMsg = array_values($getError);
  6138. $resultMsg = (empty($errorMsg[0]) || $errorMsg[0] == '令牌数据无效') ? '表单校验失败,请检查站点权限问题' : $errorMsg[0];
  6139. }
  6140. return !empty($resultMsg) ? $resultMsg : false;
  6141. }
  6142. }
  6143. if (!function_exists('handleEyouFilterStr'))
  6144. {
  6145. /**
  6146. * 处理数据验证
  6147. * $required 必填项字段
  6148. * $token 验证token名称
  6149. * $post 提交验证的数组
  6150. * $error 必填项不存在时的错误提示
  6151. */
  6152. function handleEyouFilterStr($resultStr = '')
  6153. {
  6154. if (empty($resultStr)) return '请传入字符串';
  6155. $resultStr = htmlspecialchars_decode($resultStr);
  6156. $filterStr = ['javascript', 'vbscript', 'expression', 'applet', 'meta', 'xml', 'blink', 'link', 'style', 'script', 'embed', 'object', 'iframe', 'frame', 'frameset', 'ilayer', 'layer', 'bgsound', 'title', 'base', 'svg'];
  6157. foreach ($filterStr as $value) {
  6158. $resultStr = preg_replace('/<(\s*)\b'.$value.'\b/i', '<', $resultStr);
  6159. }
  6160. $resultStr = htmlspecialchars($resultStr);
  6161. return !empty($resultStr) ? $resultStr : false;
  6162. }
  6163. }
  6164. if (!function_exists('auto_bind_wechatlogin'))
  6165. {
  6166. /**
  6167. * 在微信端登录,非微站点用户自动静默补充openid和union_id
  6168. * @param integer $users_id [description]
  6169. * @return [type] [description]
  6170. */
  6171. function auto_bind_wechatlogin($users = [], &$referurl = '')
  6172. {
  6173. // 是否绑定了微站点,否则自动绑定
  6174. if (isMobile() && isWeixin() && 0 === intval($users['thirdparty'])) {
  6175. $open_id = model('ShopPublicHandle')->weChatauthorizeCookie($users['users_id']);
  6176. if (empty($open_id)) {
  6177. // $shopMicro = getUsersConfigData('shop.shop_micro');
  6178. $weChatLoginConfig = getUsersConfigData('wechat.wechat_login_config');
  6179. $weChatLoginConfig = !empty($weChatLoginConfig) ? unserialize($weChatLoginConfig) : [];
  6180. if (!empty($weChatLoginConfig['appid']) && !empty($weChatLoginConfig['appsecret'])/* && !empty($shopMicro)*/) {
  6181. // $callBack = urlencode(url('user/Shop/weChatAuthorizeAction', ['action' => 'authorize'], true, true));
  6182. $callBack = urlencode(url('user/Users/auto_bind_wechat_info', '', true, true));
  6183. $referurl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" . $weChatLoginConfig['appid'] . "&redirect_uri=" . $callBack . "&response_type=code&scope=snsapi_base&state=eyoucms&#wechat_redirect";
  6184. }
  6185. } else {
  6186. // dump($open_id);exit;
  6187. }
  6188. // $shop_config = getUsersConfigData('shop');
  6189. // $auto_bind_wechat_info = session('auto_bind_wechat_info');
  6190. // if (empty($auto_bind_wechat_info)/* && !empty($shop_config['shop_micro'])*/) {
  6191. // $wxlogin_info = [];
  6192. // if (is_dir('./weapp/WxLogin/')) {
  6193. // $wxlogin_info = \think\Db::name("weapp_wxlogin")->where(['users_id'=>$users['users_id']])->find();
  6194. // }
  6195. // if (empty($users['open_id']) || (isset($wxlogin_info['openid']) && $users['open_id'] == $wxlogin_info['openid'])) {
  6196. // $wechat_login_config = getUsersConfigData('wechat.wechat_login_config');
  6197. // $WeChatLoginConfig = !empty($wechat_login_config) ? unserialize($wechat_login_config) : [];
  6198. // // 微信授权登陆
  6199. // if (!empty($WeChatLoginConfig['appid']) && !empty($WeChatLoginConfig['appsecret'])) {
  6200. // // 判断登陆成功跳转的链接,若为空则默认会员中心链接并存入session
  6201. // if (empty($referurl)) {
  6202. // $referurl = url('user/Users/index', '', true, true);
  6203. // session('eyou_referurl', $referurl);
  6204. // }
  6205. // // 获取微信配置授权登陆
  6206. // $appid = $WeChatLoginConfig['appid'];
  6207. // $NewUrl = urlencode(url('user/Users/auto_bind_wechat_info', '', true, true));
  6208. // $ReturnUrl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" . $appid . "&redirect_uri=" . $NewUrl . "&response_type=code&scope=snsapi_base&state=eyoucms&#wechat_redirect";
  6209. // if (request()->isAjax()) {
  6210. // $referurl = $ReturnUrl;
  6211. // } else {
  6212. // header('Location: '.$ReturnUrl);
  6213. // exit;
  6214. // }
  6215. // }
  6216. // }
  6217. // }
  6218. }
  6219. }
  6220. }
  6221. if (!function_exists('getConsumObtainScores'))
  6222. {
  6223. /**
  6224. * 消费获得积分
  6225. * 参数说明:
  6226. * $order 订单数据
  6227. * $usersConfig 积分设置
  6228. * $isReturn 是否返回赠送积分数
  6229. * 返回说明:
  6230. * return int
  6231. */
  6232. function getConsumObtainScores($order = [], $usersConfig = [], $isReturn = false)
  6233. {
  6234. // 如果开启消费送积分则执行
  6235. $addScores = 0;
  6236. if (!empty($usersConfig['score_consume_status']) && 1 === intval($usersConfig['score_consume_status'])) {
  6237. // 可赠送积分的金额(订单商品实际金额)
  6238. $addScoresMoney = !empty($order['order_total_amount']) ? floatval($order['order_total_amount']) : 0;
  6239. // 消费一元获得多少个积分数
  6240. $scoreConsumeMoney = !empty($usersConfig['score_consume_money']) ? intval($usersConfig['score_consume_money']) : 0;
  6241. // 计算赠送的积分数
  6242. $addScores = intval(floatval($addScoresMoney) * floatval($scoreConsumeMoney));
  6243. if (empty($isReturn)) {
  6244. // 待添加逻辑...
  6245. }
  6246. }
  6247. if (!empty($isReturn)) return intval($addScores);
  6248. }
  6249. }
  6250. if (!function_exists('addConsumObtainScores')) {
  6251. /**
  6252. * type 类型:1-提问,2-回答,3-最佳答案4-悬赏退回,5-每日签到,6-管理员编辑,
  6253. * 7-问题悬赏/获得悬赏,8-消费赠送积分,9-积分兑换/退回,10-登录赠送积分
  6254. * 11-积分商城订单支付 12-积分商城订单退回 13-抽奖 (99-用户定制积分兑换余额)
  6255. * 积分赠送
  6256. * $rule 默认2-增加 1-减少
  6257. */
  6258. function addConsumObtainScores($data = [], $rule = 2, $update = true)
  6259. {
  6260. $insert = [
  6261. 'type' => $data['type'], //必填
  6262. 'users_id' => $data['users_id'], //必填
  6263. 'score' => 2 === intval($rule) ? '+' . $data['score'] : '-' . $data['score'], //必填
  6264. 'info' => !empty($data['info']) ? $data['info'] : '',
  6265. 'remark' => !empty($data['remark']) ? $data['remark'] : '',
  6266. 'admin_id' => !empty($data['admin_id']) ? $data['admin_id'] : 0,
  6267. 'add_time' => getTime(),
  6268. 'update_time' => getTime()
  6269. ];
  6270. $id = Db::name('users_score')->insertGetId($insert);
  6271. if (!empty($id)) {
  6272. if (!empty($update)) {
  6273. if (2 == $rule) {
  6274. //增加
  6275. $update_score = Db::Raw('scores + '.$data['score']);
  6276. } else {
  6277. //减少
  6278. $update_score = Db::Raw('scores - '.$data['score']);
  6279. }
  6280. Db::name('users')->where('users_id', $data['users_id'])->update(['scores'=>$update_score,'update_time'=>getTime()]);
  6281. }
  6282. $current_score = Db::name('users')->where('users_id', $data['users_id'])->value('scores');
  6283. Db::name('users_score')->where('id', $id)->update(['current_score' => $current_score, 'update_time' => getTime()]);
  6284. }
  6285. }
  6286. }
  6287. if (!function_exists('get_weixin_access_token'))
  6288. {
  6289. /**
  6290. * 返回微信小程序 access_token
  6291. * @param string $appid [description]
  6292. * @return [type] [description]
  6293. */
  6294. function get_weixin_access_token($resetToken = false, $applets = 'openSource')
  6295. {
  6296. if (is_dir('./weapp/DiyminiproMall/') && 'visualization' == $applets) {
  6297. $where = [
  6298. 'name' => 'setting',
  6299. ];
  6300. $settingValue = \think\Db::name('weapp_diyminipro_mall_setting')->where($where)->getField('value');
  6301. $settingValue = !empty($settingValue) ? json_decode($settingValue, true) : [];
  6302. if (!empty($settingValue['appId']) && !empty($settingValue['appSecret'])) {
  6303. $data = [
  6304. 'appid' => $settingValue['appId'],
  6305. 'appsecret' => $settingValue['appSecret']
  6306. ];
  6307. } else {
  6308. return [
  6309. 'code' => 0,
  6310. 'msg' => '101: 请先完成可视化微信商城小程序配置',
  6311. ];
  6312. }
  6313. } else if ('openSource' == $applets) {
  6314. $data = tpSetting("OpenMinicode.conf_weixin");
  6315. $data = !empty($data) ? json_decode($data, true) : [];
  6316. if (empty($data['appid'])) {
  6317. return [
  6318. 'code' => 0,
  6319. 'msg' => '102: 请先完成小程序API中的微信小程序配置',
  6320. ];
  6321. }
  6322. }
  6323. if (false === $resetToken && !empty($data['access_token']) && !empty($data['expire_time']) && $data['expire_time'] > getTime()) {
  6324. return [
  6325. 'code' => 1,
  6326. 'access_token' => $data['access_token'],
  6327. ];
  6328. }
  6329. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$data['appid']."&secret=".$data['appsecret'];
  6330. $response = httpRequest($url);
  6331. $params = json_decode($response, true);
  6332. if (!isset($params['access_token']) && 'openSource' == $applets) {
  6333. get_weixin_access_token(true, 'visualization');
  6334. } else if (isset($params['access_token'])) {
  6335. $access_token = $params['access_token'];
  6336. $data['access_token'] = $params['access_token'];
  6337. $data['expire_time'] = getTime() + $params['expires_in'] - 1000;
  6338. if (is_dir('./weapp/DiyminiproMall/') && 'visualization' == $applets) {
  6339. // tpSetting('OpenMinicode', ['conf_weixin_mall' => json_encode($data)]);
  6340. } else if ('openSource' == $applets) {
  6341. tpSetting('OpenMinicode', ['conf_weixin' => json_encode($data)]);
  6342. }
  6343. return [
  6344. 'code' => 1,
  6345. 'access_token' => $access_token,
  6346. 'appid' => !empty($data['appid']) ? $data['appid'] : '',
  6347. ];
  6348. }
  6349. return [
  6350. 'code' => 0,
  6351. 'msg' => !empty($params['errmsg']) ? $params['errmsg'] : '请检查小程序AppId和AppSecret是否正确',
  6352. ];
  6353. }
  6354. }
  6355. if (!function_exists('get_wechat_access_token'))
  6356. {
  6357. /**
  6358. * 返回微信公众号 access_token
  6359. * @param string $appid [description]
  6360. * @return [type] [description]
  6361. */
  6362. function get_wechat_access_token($resetToken = false)
  6363. {
  6364. $data = tpSetting("OpenMinicode.conf_wechat");
  6365. $data = !empty($data) ? json_decode($data, true) : [];
  6366. if (empty($data['appid'])) {
  6367. return [
  6368. 'code' => 0,
  6369. 'msg' => '请先完成微信公众号配置',
  6370. ];
  6371. }
  6372. if (false === $resetToken && !empty($data['access_token']) && !empty($data['expire_time']) && $data['expire_time'] > getTime()) {
  6373. return [
  6374. 'code' => 1,
  6375. 'access_token' => $data['access_token'],
  6376. ];
  6377. }
  6378. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$data['appid']."&secret=".$data['appsecret'];
  6379. $response = httpRequest($url);
  6380. $params = json_decode($response, true);
  6381. if (isset($params['access_token'])) {
  6382. $access_token = $params['access_token'];
  6383. $data['access_token'] = $params['access_token'];
  6384. $data['expire_time'] = getTime() + $params['expires_in'] - 1000;
  6385. tpSetting('OpenMinicode', ['conf_wechat' => json_encode($data)]);
  6386. return [
  6387. 'code' => 1,
  6388. 'access_token' => $access_token,
  6389. 'appid' => !empty($data['appid']) ? $data['appid'] : '',
  6390. ];
  6391. }
  6392. return [
  6393. 'code' => 0,
  6394. 'errcode' => !empty($params['errcode']) ? $params['errcode'] : 0,
  6395. 'msg' => !empty($params['errmsg']) ? $params['errmsg'] : '请检查微信公众号AppId和AppSecret是否正确',
  6396. ];
  6397. }
  6398. }
  6399. if (!function_exists('eyou_send_notice'))
  6400. {
  6401. /**
  6402. * 发送消息通知
  6403. * @return [type] [description]
  6404. */
  6405. function eyou_send_notice($send_scene, $params = [])
  6406. {
  6407. // 引入模型
  6408. $apiModel = new \app\api\model\v1\Api;
  6409. // 表主表id值,可以是订单id、积分明细的id等,通过这个id可以查到整条记录
  6410. $result_id = !empty($params['result_id']) ? $params['result_id'] : 0;
  6411. // 会员ID
  6412. $users_id = !empty($params['users_id']) ? intval($params['users_id']) : 0;
  6413. // 订单付款通知
  6414. if ($send_scene == 9) {
  6415. // 公众号通知
  6416. $admin_list = Db::name('admin')->where(['wechat_followed'=>1])->select();
  6417. foreach ($admin_list as $key => $admin_info) {
  6418. $apiModel->sendWechatNotice($result_id, $send_scene, $admin_info);
  6419. }
  6420. }
  6421. // 订单发货通知
  6422. else if ($send_scene == 7) {
  6423. // 小程序通知
  6424. $data = [
  6425. 'users_id' => $users_id,
  6426. ];
  6427. $apiModel->sendAppletsNotice($result_id, $send_scene, $data);
  6428. }
  6429. return ['code'=>1, 'msg'=>'success'];
  6430. }
  6431. }
  6432. if (!function_exists('eyou_statistics_data')) {
  6433. /**
  6434. * 记录统计数据
  6435. * $change 金额/数量的变化
  6436. * 1-浏览量 2-订单 3-销售额(传money) 4-新增会员 5-充值金额 6-商品数
  6437. * $action = inc 增加 dec 减少
  6438. */
  6439. function eyou_statistics_data($type = 1,$change = 0,$now_time='',$action = 'inc')
  6440. {
  6441. try {
  6442. $lang = get_current_lang();
  6443. //不传时间的话就默认改动今天的
  6444. if (empty($now_time)){
  6445. $now_time = date('Y-m-d');
  6446. $now_time = strtotime($now_time);
  6447. }
  6448. //不是统计金额的情况默认数量给1
  6449. if (!in_array($type,[3,5]) && empty($change)){
  6450. $change = 1;
  6451. }
  6452. $is_have = Db::name('statistics_data')->where(['date'=>$now_time,'type'=>$type,'lang'=>$lang])->find();
  6453. if (!empty($is_have)){
  6454. if ('inc' == $action){ //增加
  6455. //已经存在
  6456. if (in_array($type,[3,5])){
  6457. Db::name('statistics_data')->where(['date'=>$now_time,'type'=>$type,'lang'=>$lang])->setInc('total',$change);
  6458. }else{
  6459. Db::name('statistics_data')->where(['date'=>$now_time,'type'=>$type,'lang'=>$lang])->setInc('num',$change);
  6460. }
  6461. }else{//减少
  6462. if (in_array($type,[3,5])){
  6463. Db::name('statistics_data')->where(['date'=>$now_time,'type'=>$type,'lang'=>$lang])->setDec('total',$change);
  6464. }else{
  6465. Db::name('statistics_data')->where(['date'=>$now_time,'type'=>$type,'lang'=>$lang])->setDec('num',$change);
  6466. }
  6467. }
  6468. }else{
  6469. if ('inc' == $action){ //增加
  6470. //不存在
  6471. $insert = [
  6472. 'date'=>$now_time,
  6473. 'type'=>$type,
  6474. 'lang'=>$lang,
  6475. ];
  6476. if (in_array($type,[3,5])){
  6477. $insert['total'] = $change;
  6478. }else{
  6479. $insert['num'] = $change;
  6480. }
  6481. Db::name('statistics_data')->insert($insert);
  6482. }
  6483. }
  6484. } catch (\Exception $e) {
  6485. }
  6486. return true;
  6487. }
  6488. }
  6489. if (!function_exists('del_statistics_data'))
  6490. {
  6491. /**
  6492. * 删除文档后减少统计数
  6493. * @param [type] $type [description]
  6494. * @param string $del_aid [description]
  6495. * @return [type] [description]
  6496. */
  6497. function del_statistics_data($type, $del_aid = '')
  6498. {
  6499. $del_aid = is_array($del_aid) ? $del_aid : [$del_aid];
  6500. if (!empty($type) && !empty($del_aid)) {
  6501. $ystd_count = $td_count = 0;
  6502. $today = strtotime(date('Y-m-d'));
  6503. $yesterday = $today - 86400;
  6504. $where = [
  6505. 'aid' => ['IN', $del_aid],
  6506. 'add_time' => ['egt', $yesterday],
  6507. ];
  6508. $list = \think\Db::name('archives')->field('aid,add_time')->where($where)->select();
  6509. foreach ($list as $key => $val) {
  6510. if ($val['add_time'] < $today) { // 昨天统计
  6511. $ystd_count++;
  6512. } else if ($val['add_time'] >= $today) { // 今天统计
  6513. $td_count++;
  6514. }
  6515. }
  6516. //写入统计 减去
  6517. if ($td_count > 0){
  6518. eyou_statistics_data($type, $td_count,'','dec');//今天的
  6519. }
  6520. if ($ystd_count > 0){
  6521. $ystd = strtotime('-1 day');
  6522. eyou_statistics_data($type, $ystd_count,$ystd,'dec');//昨天的
  6523. }
  6524. }
  6525. }
  6526. }
  6527. if (!function_exists('equal_pop_login'))
  6528. {
  6529. /**
  6530. * 等保测评助手,引入等保加密相关js
  6531. */
  6532. function equal_pop_login($type = 'default')
  6533. {
  6534. $str = '';
  6535. if (is_dir('./weapp/Equal/')) {
  6536. $equalLogic = new \weapp\Equal\logic\EqualLogic;
  6537. $str = $equalLogic->popLogin($type);
  6538. }
  6539. return $str;
  6540. }
  6541. }
  6542. /*function get_tid_url2($tid){
  6543. return $tid;
  6544. }*/
  6545. //获取顶级域名
  6546. function getTopHost($url)
  6547. {
  6548. $url = strtolower($url); //首先转成小写
  6549. $hosts = parse_url($url);
  6550. $host = $hosts['host'];
  6551. //查看是几级域名
  6552. $data = explode('.', $host);
  6553. $n = count($data);
  6554. //判断是否是双后缀
  6555. $preg = '/[\w].+\.(com|net|org|gov|edu)\.cn$/';
  6556. if (($n > 2) && preg_match($preg, $host)) {
  6557. //双后缀取后3位
  6558. $host = $data[$n - 3] . '.' . $data[$n - 2] . '.' . $data[$n - 1];
  6559. } else {
  6560. //非双后缀取后两位
  6561. $host = $data[$n - 2] . '.' . $data[$n - 1];
  6562. }
  6563. return $host;
  6564. }
  6565. /**
  6566. * @description: 获取tid对应的map
  6567. * @return {*}
  6568. */
  6569. function get_tid_map_1($host = '') {
  6570. $tid_map = [
  6571. 'zczl' => '38',
  6572. '38' => 'zczl',
  6573. 'gonglve' => '117',
  6574. '117' => 'gonglve',
  6575. 'zclw' => '116',
  6576. '116' => 'zclw',
  6577. 'lwck' => '127',
  6578. '127' => 'lwck',
  6579. 'anli' => '120',
  6580. '120' => 'anli',
  6581. 'zcsb' => '118',
  6582. '118' => 'zcsb',
  6583. 'xgwt' => '122',
  6584. '122' => 'xgwt',
  6585. 'fpzn' => '131',
  6586. '131' => 'fpzn',
  6587. 'zcdb' => '132',
  6588. '132' => 'zcdb',
  6589. 'lnzt' => '133',
  6590. '133' => 'lnzt',
  6591. 'wthz' => '111',
  6592. '111' => 'wthz',
  6593. 'zlwd' => '125',
  6594. '125' => 'zlwd',
  6595. 'zcbt' => '306',
  6596. '306' => 'zcbt',
  6597. 'zccl' => '126',
  6598. '126' => 'zccl',
  6599. 'zx' => '1231',
  6600. '1231' => 'zx',
  6601. 'zc' => '1232',
  6602. '1232' => 'zc',
  6603. 'cl' => '1233',
  6604. '1233' => 'cl',
  6605. 'cp' => '1234',
  6606. '1234' => 'cp',
  6607. 'zhengce' => '115',
  6608. '115' => 'zhengce',
  6609. '134' => 'https://zczl.'.$host
  6610. ];
  6611. return $tid_map;
  6612. }
  6613. /**
  6614. * @description: 获取tid对应的url
  6615. * @param {*} $tid
  6616. * @param {*} $aid
  6617. * @return {*}
  6618. */
  6619. function get_tid_url_2($url = '',$catid = 0,$stypeid = '0',$level='0',$type='',$topid=0,$area_id=0,$city_id=0) {
  6620. //return $url;
  6621. if($url == ''){
  6622. return false;
  6623. }
  6624. //获取域名
  6625. //$web_basehost = \think\Db::table('ey_config')->where('name','web_basehost')->value('value');
  6626. //$web_basehost = 'https://www.zc10000.com';
  6627. $web_basehost = \think\Config::get('web_basehost');
  6628. //$web_basehost = parse_url($web_basehost);
  6629. // $host = $web_basehost['host'];
  6630. $host = getTopHost($web_basehost);
  6631. //默认值
  6632. //array(4) { ["/?m"]=> string(4) "home" ["c"]=> string(5) "Lists" ["a"]=> string(5) "index" ["tid"]=> string(3) "116" }
  6633. $url_info = parse_url($url);
  6634. parse_str($url_info['query'], $params);
  6635. $module = $params['m']?$params['m']:'home';
  6636. $controller = $params['c']?$params['c']:'Lists';
  6637. $action = $params['a']?$params['a']:'index';
  6638. $tid = $params['tid']?$params['tid']:0;
  6639. $aid = $params['aid']?$params['aid']:0;
  6640. $site = $params['site']?$params['site']:0;
  6641. $domain = $params['domain']?$params['domain']:0;
  6642. $sitepid = $params['sitepid']?$params['sitepid']:0;
  6643. //return $url_info;
  6644. //return json_encode($params);
  6645. /*
  6646. if ($tid <= 0) {
  6647. return false;
  6648. }*/
  6649. $tid_map = get_tid_map_1($host);
  6650. $module = strtolower($module);
  6651. $controller = strtolower($controller);
  6652. $action = strtolower($action);
  6653. //处理城市
  6654. if($site !== 0 && $domain !== 0){
  6655. $domain = 'https://'.$domain.'.'.$host.'/'.$site;
  6656. return $domain;
  6657. }else if($site !== 0 && $sitepid > 0){
  6658. //查找上一级
  6659. $domain = \think\Db::table('ey_citysite')->where('id',$sitepid)->value('domain');
  6660. $domain = 'https://'.$domain.'.'.$host.'/'.$site;
  6661. return $domain;
  6662. }
  6663. // 存在aid
  6664. if ($aid > 0) {
  6665. //自动获取$tid
  6666. //$catid
  6667. $cat = \think\Db::table('ey_arctype')->field('id,parent_id,topid')->where('id',$catid)->find();
  6668. //职称
  6669. $is_pro = 0;
  6670. if($cat['topid'] == 38){
  6671. $is_pro = 1;
  6672. if($cat['parent_id'] == 38){
  6673. //二级职称分类
  6674. $tid = 38;
  6675. }else{
  6676. //三级职称分类
  6677. $tid = $catid;
  6678. }
  6679. //后续改为别名
  6680. if($level == '初级'){
  6681. return $web_basehost.'/id'.$aid.'m01';
  6682. }else if($level == '中级'){
  6683. return $web_basehost.'/id'.$aid.'m02';
  6684. }else if($level == '高级'){
  6685. return $web_basehost.'/id'.$aid.'m03';
  6686. }else{
  6687. return $web_basehost.'/id'.$aid.'m01';
  6688. }
  6689. }else{
  6690. //次要类目判断
  6691. if($cat['parent_id'] == 119){
  6692. $tid = $catid;
  6693. }else if($cat['parent_id'] == 67){
  6694. //扩展类目 文章型
  6695. $tid = $catid;
  6696. }else if($cat['parent_id'] == 1230){
  6697. //新增栏目 文章型
  6698. $tid = $catid;
  6699. }else{
  6700. $tid = $cat['parent_id'];
  6701. }
  6702. /*
  6703. * else if($cat['parent_id'] == 125){
  6704. //扩展类目 文档
  6705. $tid = $catid;
  6706. }
  6707. * **/
  6708. }
  6709. //return $tid;
  6710. if ($module == 'home' && $controller == 'view' && $action == 'index') {
  6711. //return '888';
  6712. if (array_key_exists($tid, $tid_map)) {
  6713. switch ($tid_map[$tid]) {
  6714. case 'zczl':
  6715. return $web_basehost."/" . $tid_map[$tid] . "/jzzc" . $aid;
  6716. break;
  6717. case 'gonglve':
  6718. // 要么具有 城市 要么没有
  6719. //www.gdczfw.com/gonglve1
  6720. /*
  6721. if(strpos($url, 'site=') !== false){
  6722. $domain_id = \think\Db::table('ey_citysite')->where('domain',$site)->value('parent_id');
  6723. $domain = \think\Db::table('ey_citysite')->where('id',$domain_id)->value('domain');
  6724. //guangdong.zc10000.com/guangzhou/gonglve1—N
  6725. return 'https://'.$domain.'.'.$host.'/'.$site.'/gonglve1—'.$aid;
  6726. }else{
  6727. return "/" . $tid_map[$tid].$aid;
  6728. }*/
  6729. //复制政策资讯的
  6730. if(strpos($url, 'site=') !== false){
  6731. //城市级
  6732. //guangdong.zc10000.com/guangzhou/zhengce/cms1
  6733. /*$domain_id = \think\Db::table('ey_citysite')->field('id,parent_id')->where('domain',$site)->find();
  6734. $domain = \think\Db::table('ey_citysite')->where('id',(int)$domain_id['parent_id'])->value('domain');*/
  6735. $domain = \think\Db::table('ey_citysite')->where('id',(int)$area_id)->value('domain');
  6736. //将id转为 序号
  6737. $number = \think\Db::table('ey_seo_number')
  6738. ->where('type',2)
  6739. ->where('tid','=',117)
  6740. ->where('topid',0)
  6741. ->where('parentid',0)
  6742. ->where('aid',$aid)
  6743. //->where('area_id',(int)$domain_id['parent_id'])
  6744. //->where('city_id',(int)$domain_id['id'])
  6745. ->where('area_id',(int)$area_id)
  6746. ->where('city_id',(int)$city_id)
  6747. //->fetchSql(true)
  6748. ->value('number');
  6749. //var_dump($number);
  6750. return 'https://'.$domain.'.'.$host.'/'.$site.'/gonglve1-'.$number;
  6751. }else if('https://'.$url_info['host'] !== $host && $url_info['host'] != ''){
  6752. //二级域名
  6753. //guangdong.zc10000.com/zhengce/cms1
  6754. //将id转为 序号
  6755. $number = \think\Db::table('ey_seo_number')
  6756. ->where('type',2)
  6757. ->where('tid','=',117)
  6758. ->where('topid',0)
  6759. ->where('parentid',0)
  6760. ->where('aid',$aid)
  6761. ->where('area_id',(int)$area_id)
  6762. ->where('city_id',(int)$city_id)
  6763. ->value('number');
  6764. return 'https://'.$url_info['host'].'/gonglve1-'.$number;
  6765. }else{
  6766. $number = \think\Db::table('ey_seo_number')
  6767. ->where('type',2)
  6768. ->where('tid','=',117)
  6769. ->where('topid',0)
  6770. ->where('parentid',0)
  6771. ->where('aid',$aid)
  6772. ->where('area_id',(int)$area_id)
  6773. ->where('city_id',(int)$city_id)
  6774. ->value('number');
  6775. //普通域名
  6776. //www.gdczfw.com/zczl/jzzc/1 //多加个筛选 优先主站 //序号和主站一致 不作特殊处理了
  6777. //这个要做处理 那么编辑时 不能更改
  6778. if(!empty($stypeid)){
  6779. $stypeid = $stypeid.',0';
  6780. $stypeid = explode(',',$stypeid);
  6781. //这个又区分 主站 省 市
  6782. //$stypeid[0] 每个省都不一样 相当于一个集合
  6783. //判断区域 决定 域名
  6784. //与序列号无关
  6785. //jzgv 表示攻略
  6786. return '/zczl/jzgv'.$stypeid[0].'/'.$number;
  6787. }else{
  6788. //既没有区域 也没有关联 职称分类 那就默认一个 职称分类
  6789. //现改为属于主站
  6790. return $web_basehost.'/gonglve1-'.$number;
  6791. }
  6792. }
  6793. break;
  6794. case 'zlwd':
  6795. //资料文档
  6796. /*if(!empty($site)){
  6797. return "/".$site.'/'. $tid_map[$tid].$aid;
  6798. }else{
  6799. return "/" . $tid_map[$tid].$aid;
  6800. }*/
  6801. if(strpos($url, 'site=') !== false){
  6802. //城市级
  6803. //guangdong.zc10000.com/guangzhou/zhengce/cms1
  6804. $domain_id = \think\Db::table('ey_citysite')->where('domain',$site)->value('parent_id');
  6805. $domain = \think\Db::table('ey_citysite')->where('id',$domain_id)->value('domain');
  6806. if($stypeid > 0){
  6807. return 'https://'.$domain.'.'.$host.'/'.$site.'/zlwd/zccp'.$stypeid.'/cms'.$aid;
  6808. }else{
  6809. return 'https://'.$domain.'.'.$host.'/'.$site.'/zlwd/cms'.$aid;
  6810. }
  6811. }else if('https://'.$url_info['host'] !== $host && $url_info['host'] != ''){
  6812. //二级域名 省级
  6813. //guangdong.zc10000.com/zhengce/cms1
  6814. if($stypeid > 0){
  6815. return 'https://'.$url_info['host'].'/zlwd/zccp'.$stypeid.'/cms'.$aid;
  6816. }else{
  6817. //现在基本存在这种
  6818. $number = \think\Db::table('ey_seo_number')
  6819. ->where('type',5)
  6820. ->where('tid','=',$catid)
  6821. ->where('topid',0)
  6822. ->where('parentid',0)
  6823. ->where('aid',$aid)
  6824. ->where('area_id',$area_id)
  6825. ->value('number');
  6826. $tyname = [126=>'zlwd',825=>'zcwj',826=>'ckwj'];
  6827. return 'https://'.$url_info['host'].'/'.$tyname[$catid].'/cms'.$number;
  6828. }
  6829. }else{
  6830. //普通域名
  6831. //www.gdczfw.com/zczl/jzzc/1
  6832. /*if(!empty($stypeid)){
  6833. $stypeid = $stypeid.',0';
  6834. $stypeid = explode(',',$stypeid);
  6835. return '/zczl/jzzc'.$stypeid[0].'/'.$aid;
  6836. }else{
  6837. //既没有区域 也没有关联 职称分类 那就默认一个 职称分类
  6838. return '/zczl/jzzc47/'.$aid;
  6839. }*/
  6840. /* if($stypeid > 0){
  6841. return $web_basehost."/".$tid_map[$tid].'/zccp'.$stypeid.'/cms'.$aid;
  6842. }else{
  6843. return $web_basehost."/".$tid_map[$tid].'/cms'.$aid;
  6844. }*/
  6845. //现在基本存在这种
  6846. $number = \think\Db::table('ey_seo_number')
  6847. ->where('type',5)
  6848. ->where('tid','=',$catid)
  6849. ->where('topid',0)
  6850. ->where('parentid',0)
  6851. ->where('aid',$aid)
  6852. ->where('area_id',$area_id)
  6853. ->value('number');
  6854. $tyname = [126=>'zlwd',825=>'zcwj',826=>'ckwj'];
  6855. return 'https://www.zc10000.com/'.$tyname[$catid].'/cms'.$number;
  6856. }
  6857. break;
  6858. case 'lwck':
  6859. //将id转为 序号
  6860. $number = \think\Db::table('ey_seo_number')
  6861. ->where('type',4)
  6862. ->where('tid','=',127)
  6863. ->where('topid',0)
  6864. ->where('parentid',0)
  6865. ->where('aid',$aid)
  6866. ->where('area_id',0)
  6867. ->value('number');
  6868. return $web_basehost."/" . $tid_map[$tid].'/cankao'.$number;
  6869. break;
  6870. case 'zclw':
  6871. //www.gdczfw.com/zclw/lunwen1
  6872. //将id转为 序号
  6873. $number = \think\Db::table('ey_seo_number')
  6874. ->where('type',4)
  6875. ->where('tid','=',116)
  6876. ->where('topid',0)
  6877. ->where('parentid',0)
  6878. ->where('aid',$aid)
  6879. ->where('area_id',0)
  6880. ->value('number');
  6881. return $web_basehost."/" . $tid_map[$tid].'/lunwen'.$number;
  6882. break;
  6883. case 'wthz':
  6884. //常见问题
  6885. //将id转为 序号
  6886. /*$number = \think\Db::table('ey_seo_number')
  6887. ->where('type',2)
  6888. ->where('tid','=',111)
  6889. ->where('topid',0)
  6890. ->where('parentid',0)
  6891. ->where('aid',$aid)
  6892. ->where('area_id',0)
  6893. ->value('number');
  6894. return $web_basehost."/" . $tid_map[$tid] . $number;*/
  6895. if(strpos($url, 'site=') !== false){
  6896. //城市级
  6897. //guangdong.zc10000.com/guangzhou/zhengce/cms1
  6898. /*$domain_id = \think\Db::table('ey_citysite')->field('id,parent_id')->where('domain',$site)->find();
  6899. $domain = \think\Db::table('ey_citysite')->where('id',(int)$domain_id['parent_id'])->value('domain');*/
  6900. $domain = \think\Db::table('ey_citysite')->where('id',(int)$area_id)->value('domain');
  6901. //将id转为 序号
  6902. $number = \think\Db::table('ey_seo_number')
  6903. ->where('type',2)
  6904. ->where('tid','=',111)
  6905. ->where('topid',0)
  6906. ->where('parentid',0)
  6907. ->where('aid',$aid)
  6908. //->where('area_id',(int)$domain_id['parent_id'])
  6909. //->where('city_id',(int)$domain_id['id'])
  6910. ->where('area_id',(int)$area_id)
  6911. ->where('city_id',(int)$city_id)
  6912. //->fetchSql(true)
  6913. ->value('number');
  6914. //var_dump($number);
  6915. return 'https://'.$domain.'.'.$host.'/'.$site.'/wthz'.$number;
  6916. }else if('https://'.$url_info['host'] !== $host && $url_info['host'] != ''){
  6917. //二级域名
  6918. //guangdong.zc10000.com/zhengce/cms1
  6919. //将id转为 序号
  6920. $number = \think\Db::table('ey_seo_number')
  6921. ->where('type',2)
  6922. ->where('tid','=',111)
  6923. ->where('topid',0)
  6924. ->where('parentid',0)
  6925. ->where('aid',$aid)
  6926. ->where('area_id',(int)$area_id)
  6927. ->where('city_id',(int)$city_id)
  6928. ->value('number');
  6929. return 'https://'.$url_info['host'].'/wthz'.$number;
  6930. }else{
  6931. $number = \think\Db::table('ey_seo_number')
  6932. ->where('type',2)
  6933. ->where('tid','=',111)
  6934. ->where('topid',0)
  6935. ->where('parentid',0)
  6936. ->where('aid',$aid)
  6937. ->where('area_id',(int)$area_id)
  6938. ->where('city_id',(int)$city_id)
  6939. ->value('number');
  6940. //普通域名
  6941. //www.gdczfw.com/zczl/jzzc/1 //多加个筛选 优先主站 //序号和主站一致 不作特殊处理了
  6942. //这个要做处理 那么编辑时 不能更改
  6943. if(!empty($stypeid)){
  6944. $stypeid = $stypeid.',0';
  6945. $stypeid = explode(',',$stypeid);
  6946. //这个又区分 主站 省 市
  6947. //$stypeid[0] 每个省都不一样 相当于一个集合
  6948. //判断区域 决定 域名
  6949. //与序列号无关
  6950. //jzgv 表示攻略
  6951. return '/zczl/jzgv'.$stypeid[0].'/'.$number;
  6952. }else{
  6953. //既没有区域 也没有关联 职称分类 那就默认一个 职称分类
  6954. //现改为属于主站
  6955. return $web_basehost.'/wthz'.$number;
  6956. }
  6957. }
  6958. break;
  6959. case 'zcbt':
  6960. //常见问题
  6961. //将id转为 序号
  6962. $number = \think\Db::table('ey_seo_number')
  6963. ->where('type',2)
  6964. ->where('tid','=',306)
  6965. ->where('topid',0)
  6966. ->where('parentid',0)
  6967. ->where('aid',$aid)
  6968. ->where('area_id',0)
  6969. ->value('number');
  6970. return $web_basehost."/" . $tid_map[$tid] . $number;
  6971. break;
  6972. case 'xgwt':
  6973. //将id转为 序号
  6974. $number = \think\Db::table('ey_seo_number')
  6975. ->where('type',2)
  6976. ->where('tid','=',122)
  6977. ->where('topid',0)
  6978. ->where('parentid',0)
  6979. ->where('aid',$aid)
  6980. ->where('area_id',0)
  6981. ->value('number');
  6982. return $web_basehost."/" . $tid_map[$tid] . $number;
  6983. break;
  6984. case 'zcsb':
  6985. //将id转为 序号
  6986. $number = \think\Db::table('ey_seo_number')
  6987. ->where('type',2)
  6988. ->where('tid','=',118)
  6989. ->where('topid',0)
  6990. ->where('parentid',0)
  6991. ->where('aid',$aid)
  6992. ->where('area_id',0)
  6993. ->value('number');
  6994. return $web_basehost."/" . $tid_map[$tid] . $number;
  6995. break;
  6996. case 'anli':
  6997. //将id转为 序号
  6998. $number = \think\Db::table('ey_seo_number')
  6999. ->where('type',2)
  7000. ->where('tid','=',120)
  7001. ->where('topid',0)
  7002. ->where('parentid',0)
  7003. ->where('aid',$aid)
  7004. ->where('area_id',0)
  7005. ->value('number');
  7006. return $web_basehost."/" . $tid_map[$tid] . $number;
  7007. break;
  7008. case 'fpzn':
  7009. $number = \think\Db::table('ey_seo_number')
  7010. ->where('type',2)
  7011. ->where('tid','=',131)
  7012. ->where('topid',0)
  7013. ->where('parentid',0)
  7014. ->where('aid',$aid)
  7015. ->where('area_id',0)
  7016. ->value('number');
  7017. return $web_basehost."/" . $tid_map[$tid] .'/cms'. $number;
  7018. break;
  7019. case 'zcdb':
  7020. $number = \think\Db::table('ey_seo_number')
  7021. ->where('type',2)
  7022. ->where('tid','=',132)
  7023. ->where('topid',0)
  7024. ->where('parentid',0)
  7025. ->where('aid',$aid)
  7026. ->where('area_id',0)
  7027. ->value('number');
  7028. return $web_basehost."/" . $tid_map[$tid] .'1-'. $number;
  7029. break;
  7030. case 'lnzt':
  7031. $number = \think\Db::table('ey_seo_number')
  7032. ->where('type',2)
  7033. ->where('tid','=',133)
  7034. ->where('topid',0)
  7035. ->where('parentid',0)
  7036. ->where('aid',$aid)
  7037. ->where('area_id',0)
  7038. ->value('number');
  7039. return $web_basehost."/" . $tid_map[$tid] .'/cms'. $number;
  7040. break;
  7041. case 'cp':
  7042. //将id转为 序号
  7043. $number = \think\Db::table('ey_seo_number')
  7044. ->where('type',2)
  7045. ->where('tid','=',1234)
  7046. ->where('topid',0)
  7047. ->where('parentid',0)
  7048. ->where('aid',$aid)
  7049. ->where('area_id',0)
  7050. ->value('number');
  7051. return $web_basehost."/" . $tid_map[$tid].$number;
  7052. break;
  7053. case 'zx':
  7054. //将id转为 序号
  7055. $number = \think\Db::table('ey_seo_number')
  7056. ->where('type',2)
  7057. ->where('tid','=',1231)
  7058. ->where('topid',0)
  7059. ->where('parentid',0)
  7060. ->where('aid',$aid)
  7061. ->where('area_id',0)
  7062. ->value('number');
  7063. return $web_basehost."/" . $tid_map[$tid].$number;
  7064. break;
  7065. case 'cl':
  7066. //将id转为 序号
  7067. $number = \think\Db::table('ey_seo_number')
  7068. ->where('type',2)
  7069. ->where('tid','=',1233)
  7070. ->where('topid',0)
  7071. ->where('parentid',0)
  7072. ->where('aid',$aid)
  7073. ->where('area_id',0)
  7074. ->value('number');
  7075. return $web_basehost."/" . $tid_map[$tid].'/'.$number;
  7076. break;
  7077. case 'zc':
  7078. //将id转为 序号
  7079. $number = \think\Db::table('ey_seo_number')
  7080. ->where('type',2)
  7081. ->where('tid','=',1232)
  7082. ->where('topid',0)
  7083. ->where('parentid',0)
  7084. ->where('aid',$aid)
  7085. ->where('area_id',(int)$area_id) //$area_id可能是0
  7086. ->value('number');
  7087. if((int)$area_id === 0){
  7088. return $web_basehost."/" . $tid_map[$tid].'/'.$number;
  7089. }else{
  7090. $domain = \think\Db::table('ey_citysite')->where('id',(int)$area_id)->value('domain');
  7091. return $web_basehost."/" . $tid_map[$tid].'/'.$domain.'/'.$number;
  7092. }
  7093. break;
  7094. case 'zhengce':
  7095. //$tid = 115 职称评审政策
  7096. //一篇政策 文档 最多有4种url
  7097. //从主页入口
  7098. //优先 城市 > 省
  7099. //默认全国 主域名 职称分类链接从
  7100. //从指定列表页
  7101. //return json_encode($url_info);
  7102. //return $url_info['host'];
  7103. if(strpos($url, 'site=') !== false){
  7104. //城市级
  7105. //guangdong.zc10000.com/guangzhou/zhengce/cms1
  7106. /*$domain_id = \think\Db::table('ey_citysite')->field('id,parent_id')->where('domain',$site)->find();
  7107. $domain = \think\Db::table('ey_citysite')->where('id',(int)$domain_id['parent_id'])->value('domain');*/
  7108. $domain = \think\Db::table('ey_citysite')->where('id',(int)$area_id)->value('domain');
  7109. //将id转为 序号
  7110. $number = \think\Db::table('ey_seo_number')
  7111. ->where('type',2)
  7112. ->where('tid','=',115)
  7113. ->where('topid',0)
  7114. ->where('parentid',0)
  7115. ->where('aid',$aid)
  7116. //->where('area_id',(int)$domain_id['parent_id'])
  7117. //->where('city_id',(int)$domain_id['id'])
  7118. ->where('area_id',(int)$area_id)
  7119. ->where('city_id',(int)$city_id)
  7120. //->fetchSql(true)
  7121. ->value('number');
  7122. //var_dump($number);
  7123. return 'https://'.$domain.'.'.$host.'/'.$site.'/zhengce/cms'.$number;
  7124. }else if('https://'.$url_info['host'] !== $host && $url_info['host'] != ''){
  7125. //二级域名
  7126. //guangdong.zc10000.com/zhengce/cms1
  7127. //将id转为 序号
  7128. $number = \think\Db::table('ey_seo_number')
  7129. ->where('type',2)
  7130. ->where('tid','=',115)
  7131. ->where('topid',0)
  7132. ->where('parentid',0)
  7133. ->where('aid',$aid)
  7134. ->where('area_id',(int)$area_id)
  7135. ->where('city_id',(int)$city_id)
  7136. ->value('number');
  7137. return 'https://'.$url_info['host'].'/zhengce/cms'.$number;
  7138. }else{
  7139. $number = \think\Db::table('ey_seo_number')
  7140. ->where('type',2)
  7141. ->where('tid','=',115)
  7142. ->where('topid',0)
  7143. ->where('parentid',0)
  7144. ->where('aid',$aid)
  7145. ->where('area_id',(int)$area_id)
  7146. ->where('city_id',(int)$city_id)
  7147. ->value('number');
  7148. //普通域名
  7149. //www.gdczfw.com/zczl/jzzc/1 //多加个筛选 优先主站 //序号和主站一致 不作特殊处理了
  7150. //这个要做处理 那么编辑时 不能更改
  7151. if(!empty($stypeid)){
  7152. $stypeid = $stypeid.',0';
  7153. $stypeid = explode(',',$stypeid);
  7154. //这个又区分 主站 省 市
  7155. //$stypeid[0] 每个省都不一样 相当于一个集合
  7156. //判断区域 决定 域名
  7157. //与序列号无关
  7158. //jzzc 表示政策资讯
  7159. return '/zczl/jzzc'.$stypeid[0].'/'.$number;
  7160. }else{
  7161. //既没有区域 也没有关联 职称分类 那就默认一个 职称分类
  7162. //现改为属于主站
  7163. return $web_basehost.'/zhengce/cms'.$number;
  7164. }
  7165. }
  7166. //原来的返回 没有区分 多种场景和域名
  7167. //return "/" . $tid_map[$tid] . "/cms" . $aid;
  7168. }
  7169. }else{
  7170. //不在规则列表里面
  7171. /* if(strpos($url, 'jzgczc') !== false){
  7172. return '/jzgczc'.$aid;
  7173. }*/
  7174. return $cat['parent_id'];
  7175. return '/jzgczc'.$aid;
  7176. return '666';
  7177. }
  7178. }
  7179. } else {
  7180. //return '777';
  7181. if ($module == 'home' && $controller == 'lists' && $action == 'index') {
  7182. if (array_key_exists($tid, $tid_map)) {
  7183. if($area_id > 0 && empty($city_id)){
  7184. //存在区域
  7185. $domain = \think\Db::table('ey_citysite')->where('id',(int)$area_id)->value('domain');
  7186. return 'https://'.$domain.'.'.$host.'/'.$tid_map[$tid];
  7187. }
  7188. if($city_id > 0 && strpos($url, 'site=') !== false){
  7189. //存在城市
  7190. $domain = \think\Db::table('ey_citysite')->where('id',(int)$area_id)->value('domain');
  7191. return 'https://'.$domain.'.'.$host.'/'.$site.'/'.$tid_map[$tid];
  7192. }
  7193. if(strpos($tid_map[$tid], 'http') !== false){
  7194. //二级域名
  7195. return $tid_map[$tid];
  7196. }else{
  7197. return $web_basehost."/" . $tid_map[$tid];
  7198. }
  7199. }else{
  7200. //不在预定的规则里面
  7201. //查找栏目顶级id
  7202. //https://www.zc10000.com/zczl/jzzc47
  7203. //后续改为参数 不查询
  7204. //$topid = \think\Db::table('ey_arctype')->where('id',$tid)->value('topid');
  7205. /*if($tid_map[$topid] == 'zczl'){
  7206. //职称分类
  7207. //www.gdczfw.com/zczl/jzzc jzzc是变量
  7208. return "/zczl/jzzc".$tid;
  7209. }*/
  7210. /*
  7211. * 产品的逻辑是定制 这个没用了 写死的
  7212. */
  7213. if($topid == 38){
  7214. if($type === '产品'){
  7215. //return $web_basehost."/id".$tid;
  7216. if((int)$area_id === 10000){
  7217. $domain = 'www';
  7218. }else{
  7219. $domain = \think\Db::table('ey_citysite')->where('id',$area_id)->value('domain');
  7220. }
  7221. //将id转为 序号
  7222. $number = \think\Db::table('ey_seo_number')
  7223. ->where('type',1)
  7224. ->where('topid',38)
  7225. ->where('parentid',38)
  7226. ->where('aid',$tid)
  7227. ->where('area_id',$area_id)
  7228. ->value('number');
  7229. return 'https://'.$domain.'.'.$host.'/id'.$number;
  7230. }else{
  7231. //return $web_basehost."/zczl/jzzc".$tid;
  7232. //改为返回 产品id
  7233. //return $web_basehost."/zczl/jzzc".$area_id;
  7234. //查询区域域名
  7235. if((int)$area_id === 10000){
  7236. $domain = 'www';
  7237. }else{
  7238. $domain = \think\Db::table('ey_citysite')->where('id',$area_id)->value('domain');
  7239. }
  7240. //将id转为 序号
  7241. $number = \think\Db::table('ey_seo_number')
  7242. ->where('type',1)
  7243. ->where('topid',38)
  7244. ->where('parentid',38)
  7245. ->where('aid',$tid)
  7246. ->where('area_id',$area_id)
  7247. ->value('number');
  7248. return 'https://'.$domain.'.'.$host.'/id'.$number;
  7249. }
  7250. }
  7251. return '555';
  7252. }
  7253. }
  7254. }
  7255. return false;
  7256. }
  7257. /**
  7258. * ------------- 此行代码请保持最底部 --------------
  7259. */
  7260. if (!function_exists('function_1601946443'))
  7261. {
  7262. /**
  7263. * 引入插件公共函数
  7264. */
  7265. function function_1601946443()
  7266. {
  7267. $file_1601946443 = glob('weapp/*/function.php');
  7268. foreach ($file_1601946443 as $key => $val) {
  7269. include_once ROOT_PATH.$val;
  7270. }
  7271. }
  7272. }
  7273. // function_1601946443();