暫無描述
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.

common.php 268KB

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