| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441 |
- <?php
- namespace App\JsonRpc;
- // use ___PHPSTORM_HELPERS\object;
- use _PHPStan_62c6a0a8b\OndraM\CiDetector\Env;
- use App\Model\BlackWord;
- use App\Model\Department;
- use App\Model\District;
- use App\Model\LetterOfComplaint;
- use App\Model\LetterType;
- use App\Model\LevelUser;
- use App\Model\UserLevel;
- use App\Tools\Result;
- use Hyperf\DbConnection\Db;
- use Hyperf\Di\Annotation\Inject;
- use Hyperf\RpcServer\Annotation\RpcService;
- use App\Service\MinioService;
- use Hyperf\Redis\Redis;
- use Overtrue\ChineseCalendar\Calendar;
- use App\Model\TemplateClass;
- use App\Model\Template;
- use App\Model\WebsiteTemplate;
- use App\Model\WebsiteTemplateInfo;
- use App\Model\Sector;
- use App\Model\Component;
- use App\Model\Link;
- use App\Model\FooterCategory;
- use App\Model\Size;
- use function Hyperf\Support\retry;
- use Hyperf\Paginator\Paginator;
- use App\Model\User;
- use App\Model\Website;
- use App\Constants\ErrorCode;
- use GuzzleHttp\Client;
- use GuzzleHttp\Exception\GuzzleException;
- use App\Model\SectorPlace;
- use App\Model\ComponentType;
- use App\Model\Article;
- use App\Model\WebsiteCategory;
- use App\Model\AdPlace;
- use App\Model\Company;
- use App\Model\WebsiteImg;
- use App\Model\SectorComponent;
- use App\Model\ComponentImg;
- use App\Model\TemplateRule;
- use App\Model\SectorType;
- use App\Model\Level;
- use App\Model\StyleCode;
- use think\controller\Rest;
- use App\Model\Aichat;
- use App\Model\AichatSession;
- use App\Model\TemplateDraftbox;
- #[RpcService(name: "PublicRpcService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
- class PublicRpcService implements PublicRpcServiceInterface
- {
- #[Inject]
- protected Redis $redis;
- /**
- * @param array $data
- * @return array
- */
- public function getDistrictList(array $data): array
- {
- $where = [];
- if (isset($data['keyWord'])) {
- $where = [
- ['name', 'like', '%' . $data['keyWord'] . '%']
- ];
- }
- $result = [];
- if (isset($data['pageSize'])) {
- $rep = District::where($where)->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("code", "asc")->get();
- $count = District::where($where)->count();
- $result = [
- 'rows' => $rep,
- 'count' => $count
- ];
- } else {
- $result = District::where($data)->orderBy("code", "asc")->get();
- }
- return $result ? Result::success($result) : Result::error("没有查到数据");
- }
- /**
- * @param array $data
- * @return array
- */
- public function getUserLevelList(array $data): array
- {
- $where = [];
- if (isset($data['keyWord'])) {
- $where = [
- ['name', 'like', '%' . $data['keyWord'] . '%'],
- ];
- }
- $result = [];
- if (isset($data['pageSize'])) {
- $rep = UserLevel::where($where)->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("id", "asc")->get();
- $count = UserLevel::where($where)->count();
- $result = [
- 'rows' => $rep,
- 'count' => $count,
- ];
- } else {
- $result = UserLevel::orderBy("id", "asc")->get();
- }
- return $result ? Result::success($result) : Result::error("没有查到数据");
- }
- /**
- * 添加用户等级
- * @param array $data
- * @return array
- */
- public function addUserLevel(array $data): array
- {
- LevelUser::insertGetId($data);
- return Result::success([]);
- }
- /**
- * 更新等级
- * @param array $data
- * @return array
- */
- public function updateUserLevel(array $data): array
- {
- $result = LevelUser::where(['id' => $data['id']])->update($data);
- if ($result) {
- return Result::success($result);
- }
- return Result::error("更新失败");
- }
- /**
- * 删除等级
- * @param array $data
- * @return array
- */
- public function delUserLevel(array $data): array
- {
- $result = LevelUser::where(['id' => $data['id']])->delete();
- if ($result) {
- return Result::success($result);
- }
- return Result::error("删除失败");
- }
- /**
- * 查询投诉举报信息
- * @param array $data
- * @return array
- */
- public function getLetterOfComplaint(array $data = []): array
- {
- var_dump("====");
- $where = [];
- if (isset($data['user_id']) && !empty($data['user_id'])) {
- array_push($where, ['letter_of_complaint.user_id', '=', $data['user_id']]);
- }
- if (isset($data['nature']) && !empty($data['nature'])) {
- array_push($where, ['letter_of_complaint.nature', '=', $data['nature']]);
- }
- if (isset($data['nature_level0']) && !empty($data['nature_level0'])) {
- array_push($where, ['letter_of_complaint.nature_level0', '=', $data['nature_level0']]);
- }
- if (isset($data['status']) && !empty($data['status'])) {
- array_push($where, ['letter_of_complaint.status', '=', $data['status']]);
- }
- $result = [];
- if (isset($data['pageSize'])) {
- $rep = LetterOfComplaint::where($where)
- ->leftJoin("letter_type as type_a", "letter_of_complaint.nature", "type_a.id")
- ->leftJoin("letter_type as type_c", "letter_of_complaint.nature_level0", "type_c.id")
- ->leftJoin("letter_type as type_b", "letter_of_complaint.nature_level1", "type_b.id")
- ->leftJoin("letter_type as type_e", "letter_of_complaint.nature_level3", "type_e.id")
- ->leftJoin("letter_type as type_d", "letter_of_complaint.status", "type_d.id")
- ->select(
- "letter_of_complaint.*",
- "type_a.type_name as nature_name",
- "type_b.type_name as nature_name1",
- "type_c.type_name as nature_name0",
- "type_d.type_name as status_name",
- "type_e.type_name as nature_name3"
- )
- ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("letter_of_complaint.id", "desc")->get();
- $count = LetterOfComplaint::where($where)->count();
- if ($rep) {
- foreach ($rep as $val) {
- if ($val['judgment']) {
- $val['judgment'] = json_decode($val['judgment']);
- }
- if ($val['audio_and_video']) {
- $val['audio_and_video'] = json_decode($val['audio_and_video']);
- }
- if ($val['contract']) {
- $val['contract'] = json_decode($val['contract']);
- }
- if ($val['qualifications']) {
- $val['qualifications'] = json_decode($val['qualifications']);
- }
- }
- }
- $result = [
- 'rows' => $rep,
- 'count' => $count,
- ];
- } else {
- $result = LetterOfComplaint::where($where)
- ->leftJoin("letter_type as type_a", "letter_of_complaint.nature", "type_a.id")
- ->leftJoin("letter_type as type_c", "letter_of_complaint.nature_level0", "type_c.id")
- ->leftJoin("letter_type as type_b", "letter_of_complaint.nature_level1", "type_b.id")
- ->leftJoin("letter_type as type_e", "letter_of_complaint.nature_level3", "type_e.id")
- ->leftJoin("letter_type as type_d", "letter_of_complaint.status", "type_d.id")
- ->select(
- "letter_of_complaint.*",
- "type_a.type_name as nature_name",
- "type_b.type_name as nature_name1",
- "type_c.type_name as nature_name0",
- "type_d.type_name as status_name",
- "type_e.type_name as nature_name3"
- )
- ->orderBy("letter_of_complaint.id", "desc")->get();
- }
- return $result ? Result::success($result) : Result::error("没有查到数据");
- }
- /**
- * 添加投诉举报信息
- * @param array $data
- * @return array
- */
- public function addLetterOfComplaint(array $data): array
- {
- $data['judgment'] = $data['judgment'] ? json_encode($data['judgment']) : '';
- $data['audio_and_video'] = $data['audio_and_video'] ? json_encode($data['audio_and_video']) : '';
- $data['contract'] = $data['contract'] ? json_encode($data['contract']) : '';
- $data['qualifications'] = $data['qualifications'] ? json_encode($data['qualifications']) : '';
- unset($data['id']);
- $result = LetterOfComplaint::insertGetId($data);
- if (empty($result)) {
- return Result::error("创建失败", 0);
- } else {
- return Result::success(["id" => $result]);
- }
- }
- /**
- * 用户端更新投诉举报
- * @param array $data
- * @return array
- */
- public function userUpLetterOfComplaint(array $data): array
- {
- $data['judgment'] = $data['judgment'] ? json_encode($data['judgment']) : '';
- $data['audio_and_video'] = $data['audio_and_video'] ? json_encode($data['audio_and_video']) : '';
- $data['contract'] = $data['contract'] ? json_encode($data['contract']) : '';
- $data['qualifications'] = $data['qualifications'] ? json_encode($data['qualifications']) : '';
- $result = LetterOfComplaint::where(['id' => $data['id']])->update($data);
- if (empty($result)) {
- return Result::error("创建失败", 0);
- } else {
- return Result::success(["id" => $result]);
- }
- }
- /**
- * 管理后台更新投诉举报信息
- * @param array $data
- * @return array
- */
- public function upLetterOfComplaint(array $data): array
- {
- var_dump("admin:", $data);
- $where = [
- 'id' => $data['id'],
- ];
- $filtered_array = array_filter($data, function ($value) {
- return $value !== "" && $value !== null && $value !== false && !is_array($value) || !empty($value);
- });
- $filtered_array['judgment'] = isset($filtered_array['judgment']) ? json_encode($filtered_array['judgment']) : '';
- $filtered_array['audio_and_video'] = isset($filtered_array['audio_and_video']) ? json_encode($filtered_array['audio_and_video']) : '';
- $filtered_array['contract'] = isset($filtered_array['contract']) ? json_encode($filtered_array['contract']) : '';
- $filtered_array['qualifications'] = isset($filtered_array['qualifications']) ? json_encode($filtered_array['qualifications']) : '';
- unset($filtered_array['nature_name']);
- unset($filtered_array['type_name']);
- unset($filtered_array['nature_level_name']);
- unset($filtered_array['status_name']);
- unset($filtered_array['is_admin']);
- unset($filtered_array['type_level_name']);
- $result = LetterOfComplaint::where($where)->update($filtered_array);
- if ($result) {
- return Result::success($result);
- }
- return Result::error("更新失败", 0);
- }
- /**
- * 查询投诉举报记录
- * @param array $data
- * @return array
- */
- public function getLetterOfComplaintInfo(array $data): array
- {
- $where = [
- 'letter_of_complaint.id' => $data['id'],
- ];
- if (isset($data['user_id']) && !empty($data['user_id'])) {
- array_push($where, ['letter_of_complaint.user_id', '=', $data['user_id']]);
- }
- $result = LetterOfComplaint::where($where)
- ->leftJoin("letter_type as type_a", "letter_of_complaint.nature", "type_a.id")
- ->leftJoin("letter_type as type_c", "letter_of_complaint.nature_level0", "type_c.id")
- ->leftJoin("letter_type as type_b", "letter_of_complaint.nature_level1", "type_b.id")
- ->leftJoin("letter_type as type_e", "letter_of_complaint.nature_level3", "type_e.id")
- ->leftJoin("letter_type as type_d", "letter_of_complaint.status", "type_d.id")
- ->select(
- "letter_of_complaint.*",
- "type_a.type_name as nature_name",
- "type_b.type_name as nature_name1",
- "type_c.type_name as nature_name0",
- "type_d.type_name as status_name",
- "type_e.type_name as nature_name3"
- )
- ->first();
- return Result::success($result);
- }
- /**
- * 删除投诉举报信息
- * @param array $data
- * @return array
- */
- public function delLetterOfComplaint(array $data): array
- {
- $result = LetterOfComplaint::when($data, function ($query) use ($data) {
- if (isset($data['id']) && !empty($data['id'])) {
- $query->where(['id' => $data['id']]);
- }
- if (isset($data['user_id']) && !empty($data['user_id'])) {
- $query->where(['user_id' => $data['user_id']]);
- }
- })->delete();
- if (empty($result)) {
- return Result::error("删除失败", 0);
- } else {
- return Result::success();
- }
- }
- /**
- * 获取举报信息类型
- * @param array $data
- * @return array
- */
- public function getLetterType(array $data): array
- {
- $where = [];
- if (isset($data['type'])) {
- array_push($where, ['type', '=', $data['type']]);
- }
- if (isset($data['pid']) && $data['pid'] > 0) {
- array_push($where, ['pid', '=', $data['pid']]);
- }
- $result = LetterType::where($where)->orderBy('sort', 'asc')->get();
- return $result ? Result::success($result) : Result::error("没有查到数据");
- }
- /**
- * 更新举报类型
- * @param array $data
- * @return array
- */
- public function upLetterType(array $data): array
- {
- return [];
- }
- /**
- * 添加举报类型
- * @param array $data
- * @return array
- */
- public function addLetterType(array $data): array
- {
- $result = LetterType::insertGetId($data);
- if (empty($result)) {
- return Result::error("创建失败", 0);
- } else {
- return Result::success(["id" => $result]);
- }
- }
- /**
- * 删除举报类型
- * @param array $data
- * @return array
- */
- public function delLetterType(array $data): array
- {
- $result = LetterType::where('id', $data['id'])->delete();
- if (empty($result)) {
- return Result::error("删除失败", 0);
- } else {
- return Result::success();
- }
- }
- /**
- * 检测是否已经被接案
- * @param array $data
- * @return array
- */
- public function checkMeasure(array $data): array
- {
- $where = [
- 'id' => $data['id'],
- ];
- $letterOfComplaintInfo = LetterOfComplaint::where($where)->first();
- var_dump("查询数据:", $letterOfComplaintInfo['admin_id'], $data['user_id']);
- //操作人和当前登陆用户id 相等说明是当前人接收的案件
- if (($letterOfComplaintInfo['admin_id'] == $data['user_id']) || empty($letterOfComplaintInfo['admin_id'])) {
- return Result::success();
- } else {
- return Result::error("您不能处理其他人已经接过的案件", 0);
- }
- }
- /**
- * 后台获取职能部门
- * @param array $data
- * @return array
- */
- public function getZhinengbumenList(array $data): array
- {
- // 获取分页参数,默认每页 10 条记录
- $page = isset($data['page']) ? (int) $data['page'] : 1;
- $perPage = isset($data['pagesize']) ? (int) $data['pagesize'] : 10;
- // 查询数据并分页
- $query = Department::query();
- // 可以在这里添加更多的查询条件
- if (isset($data['search'])) {
- $query->where('name', 'like', '%' . $data['search'] . '%');
- }
- // 执行分页查询
- $result = $query->paginate($perPage, ['*'], 'page', $page);
- // 返回分页结果
- return Result::success([
- 'count' => $result->total(),
- 'current_page' => $result->currentPage(),
- 'last_page' => $result->lastPage(),
- 'pagesize' => $result->perPage(),
- 'rows' => $result->items(),
- ]);
- }
- /**
- * 添加获取职能部门
- * @param array $data
- * @return array
- */
- public function addZhinengbumen(array $data): array
- {
- $result = Department::insertGetId($data);
- if (empty($result)) {
- return Result::error("创建失败", 0);
- } else {
- return Result::success(["id" => $result]);
- }
- }
- public function delZhinengbumen(array $data): array
- {
- $result = Department::where('id', $data['id'])->delete();
- if (empty($result)) {
- return Result::error("删除失败", 0);
- } else {
- return Result::success();
- }
- }
- public function getZhinengbumen(array $data): array
- {
- $result = Department::where('id', $data['id'])
- ->orderBy('department', 'desc')
- ->first();
- return Result::success($result);
- }
- public function getPidZhinengbumen(array $data): array
- {
- if (empty($data['pid'])) {
- $data['pid'] = 0;
- }
- $result = Department::where('pid', $data['pid'])->get();
- return Result::success($result);
- }
- public function modZhinengbumen(array $data): array
- {
- $result = Department::where('id', $data['id'])->update($data);
- if (empty($result)) {
- return Result::error("修改失败", 0);
- } else {
- return Result::success();
- }
- }
- /**
- * 查询职能列表
- * @param array $data
- * @return array
- */
- public function getDepartment(array $data): array
- {
- $where = [];
- if (isset($data['pid'])) {
- $where = [
- 'pid' => $data['pid'] ?? 0
- ];
- }
- $result = Department::when(!empty($where), function ($query) use ($where) {
- $query->where($where);
- })->orderBy("sort", "desc")->get();
- if (empty($result)) {
- return Result::error("查询失败", 0);
- } else {
- return Result::success($result);
- }
- }
- /**
- * 获取所有的buckets
- * @param array $data
- * @return array
- */
- public function getBuckets(array $data): array
- {
- $result = new MinioService();
- // 调用服务层的方法获取存储桶列表
- $bucketsResponse = $result->listBuckets();
- // 直接返回服务层生成的响应
- return Result::success($bucketsResponse['data']);
- }
- /**
- * 上传文件
- * @param array $data
- * @return array
- */
- public function uploadFile(array $data): array
- {
- $result = new MinioService();
- $rep = $result->uploadFile($data);
- if ($rep['code'] == 200) {
- return Result::success($rep['data']);
- } else {
- return Result::error("上传失败!");
- }
- }
- /**
- * 黑名单管理
- * @param array $data
- * @return array
- */
- public function getBlackWordList(array $data): array
- {
- $result = BlackWord::when($data, function ($query) use ($data) {
- if (isset($data['name']) && $data['name']) {
- $query->where('black_word.name', 'like', '%' . $data['name'] . '%');
- }
- })->orderBy('black_word.id', 'desc')
- ->paginate(
- intval($data['pageSize']),
- [
- 'black_word.*',
- ],
- 'page',
- intval($data['page'])
- );
- $count = $result->total();
- $returnData = [
- 'rows' => $result->items(),
- 'count' => $count
- ];
- return Result::success($returnData);
- }
- /**
- * 添加黑名单
- * @param array $data
- * @return array
- */
- public function addBlackWord(array $data): array
- {
- Db::beginTransaction();
- try {
- $info = BlackWord::where(['name' => $data['name']])->first();
- if ($info) {
- Db::rollBack();
- return Result::error("该黑名单已存在", 0);
- }
- $data['type'] = 10;
- $result = BlackWord::insertGetId($data);
- $redisKey = 'black_word';
- $this->redis->sAdd($redisKey, $data['name']);
- Db::commit();
- return Result::success(["id" => $result]);
- } catch (\Exception $e) {
- Db::rollBack();
- return Result::error("创建失败" . $e->getMessage(), 0);
- }
- }
- /**
- * 删除黑名单
- * @param array $data
- * @return array
- */
- public function delBlackWord(array $data): array
- {
- Db::beginTransaction();
- try {
- BlackWord::where(['name' => $data['name']])->delete();
- $redisKey = 'black_word';
- $this->redis->sRem($redisKey, $data['name']);
- Db::commit();
- return Result::success([]);
- } catch (\Exception $e) {
- Db::rollBack();
- return Result::error("删除失败" . $e->getMessage(), 0);
- }
- }
- /**
- * 修改违禁词
- * @param array $data
- * @return array
- */
- public function upBlackWord(array $data): array
- {
- Db::beginTransaction();
- try {
- $checkInfo = BlackWord::where(['name' => $data['name']])->first();
- if ($checkInfo) {
- Db::rollBack();
- return Result::error("该违禁词已经存在", 0);
- }
- $blackWordInfo = BlackWord::where(['id' => $data['id']])->first();
- if ($blackWordInfo) {
- //先删除redis
- $blackWordInfo = $blackWordInfo->toArray();
- $redisKey = 'black_word';
- $this->redis->sRem($redisKey, $blackWordInfo['name']);
- $this->redis->sAdd($redisKey, $data['name']);
- BlackWord::where(['id' => $data['id']])->update(['name' => $data['name']]);
- Db::commit();
- return Result::success([]);
- } else {
- Db::rollBack();
- return Result::error("系统错误", 0);
- }
- } catch (\Exception $e) {
- Db::rollBack();
- return Result::error("修改失败" . $e->getMessage(), 0);
- }
- }
- /**
- * 获取风格
- * @return void
- */
- public function getTemplateClassList(array $data): array
- {
- $where = [];
- if (isset($data['name']) && $data['name']) {
- array_push($where, ['template_class.name', 'like', '%' . $data['name'] . '%']);
- }
- if (isset($data['keyword']) && $data['keyword']) {
- array_push($where, ['template_class.keyword', 'like', '%' . $data['keyword'] . '%']);
- }
- $template = TemplateClass::when($where, function ($query) use ($where) {
- $query->where($where);
- });
- $count = $template->count();
- // $countQuery = clone $template;
- $row = $template
- ->leftJoin('template', function ($join) {
- $join->on('template_class.class_id', '=', 'template.template_class_id');
- })
- ->select('template_class.*', DB::raw('COUNT(template.template_class_id) as template_count'))
- ->groupBy('template_class.id')
- ->orderBy('template_class.id', 'desc')
- ->offset(($data['page'] - 1) * $data['pageSize'])
- ->limit($data['pageSize'])
- ->get();
- $result = [
- 'rows' => $row,
- 'count' => $count,
- ];
- if ($row->isEmpty()) {
- return Result::error("暂无风格", 0);
- } else {
- return Result::success($result);
- }
- }
- /**
- * 添加风格
- * @param
- * @return void
- */
- public function addTemplateClass(array $data): array
- {
- $data['keyword'] = json_encode($data['keyword']);
- $template_class = TemplateClass::where('name', $data['name'])
- ->orWhere('class_id', $data['class_id'])
- ->first();
- if ($template_class) {
- return Result::error("风格名称或者风格编号已存在,不可添加!", 0);
- }
- $result = TemplateClass::insertGetId($data);
- if (empty($result)) {
- return Result::error("创建风格失败", 0);
- } else {
- return Result::success(["id" => $result]);
- }
- }
- /**
- * 更新风格
- * @param array $data
- * @return array
- */
- public function upTemplateClass(array $data): array
- {
- $where = [
- 'id' => $data['id'],
- ];
- $template_class = TemplateClass::where($where)->first();
- if (empty($template_class)) {
- return Result::error("未查询到风格", 0);
- }
- if ($template_class->type == 1) {
- return Result::error("默认风格不能修改", 0);
- }
- $template = TemplateClass::where('id', '!=', $data['id'])
- // ->where(['name' => $data['name']])
- // ->orWhere(['class_id' => $data['class_id']])
- ->where(function ($query) use ($data) {
- $query->where('name', $data['name'])
- ->orWhere('class_id', $data['class_id']);
- })
- ->first();
- if ($template) {
- return Result::error("风格名称或者风格编号已存在,不可编辑!", 0);
- }
- if(is_string($data['keyword'])){
- $keyword = json_decode($data['keyword'],true) ?? $data['keyword'];
- }
- if(is_array($keyword)){
- $keyword = json_encode($keyword);
- }
- $updateData = [
- 'name' => $data['name'],
- 'keyword' => $keyword,
- 'class_id' => $data['class_id'],
- ];
- $result = TemplateClass::where($where)->update($updateData);
- if (empty($result)) {
- return Result::error("更新失败", 0);
- } else {
- return Result::success($result);
- }
- }
- /**
- * 删除风格
- * @param array $data
- * @return array
- */
- public function delTemplateClass(array $data): array
- {
- $where = [
- 'id' => $data['id'],
- ];
- $template_class = TemplateClass::where($where)->first();
- if (empty($template_class)) {
- return Result::error("未查询到风格", 0);
- }
- if ($template_class->type == 1) {
- return Result::error("默认风格不能删除", 0);
- }
- $template = Template::where('template_class_id', $template_class['class_id'])->get();
- if (!empty($template->all())) {
- try {
- // 默认风格 1
- Db::beginTransaction();
- $template = Template::where('template_class_id', $template['class_id'])->update(['template_class_id' => 1]);
- if (empty($template)) {
- Db::rollBack();
- return Result::error("删除失败", 0);
- }
- $result = TemplateClass::where($where)->delete();
- } catch (\Exception $e) {
- return Result::error("删除失败" . $e->getMessage(), 0);
- }
- } else {
- $result = TemplateClass::where('id', $data['id'])->delete();
- }
- if (empty($result)) {
- return Result::error("删除失败", 0);
- }
- return Result::success($result);
- }
- /**
- * 根据风格名称-获取获取所有风格
- * @param array $data
- * @return array
- */
- public function getTemplateClass(array $data): array
- {
- $where = [];
- if (!empty($data['template_name'])) {
- $where['name'] = $data['template_name'];
- }
- $result = TemplateClass::where($where)->get();
- if (empty($result)) {
- return Result::error("暂无风格", 0);
- }
- return Result::success($result);
- }
- /**
- * 获取皮肤列表
- * @param array $data
- * @return array
- */
- public function getTemplateList(array $data): array
- {
- $where = [];
- if (!empty($data['template_class_id'])) {
- $where['template_class_id'] = $data['template_class_id'];
- }
- if (!empty($data['template_name'])) {
- array_push($where, ['template_name', 'like', '%' . $data['template_name'] . '%']);
- }
- if (!empty($data['template_keyword'])) {
- array_push($where, ['template_keyword', 'like', '%' . $data['template_keyword'] . '%']);
- }
- $result = Template::where($where)
- ->leftJoin('template_class', 'template.template_class_id', 'template_class.class_id')
- ->select('template.*', 'template_class.name as template_class_name')
- ->orderBy('template.template_id', 'desc')
- ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
- if (empty($result)) {
- return Result::error("暂无皮肤", 0);
- }
- return Result::success($result);
- }
- public function getTemplateInfo(array $data): array
- {
- $result = Template::where('template.id', $data['id'])
- ->leftJoin('template_class', 'template.template_class_id', 'template_class.class_id')
- ->select('template.*', 'template_class.name as template_class_name')
- ->first();
- if (empty($result)) {
- return Result::error("暂无皮肤", 0);
- }
- return Result::success($result);
- }
- /**
- * 添加皮肤
- * @param array $data
- * @return array
- */
- public function addTemplate(array $data): array
- {
- var_dump($data);
- unset($data['user_id']);
- $template = Template::where('template_name', $data['template_name'])
- ->orWhere('template_id', $data['template_id'])
- ->first();
- if ($template) {
- return Result::error("皮肤名称或者皮肤编号已存在,不可添加!", 0);
- }
- $data['template_keyword'] = array_map('trim', $data['template_keyword']);
- $data['template_keyword'] = json_encode($data['template_keyword']) ?? '';
- $page_type = json_decode($data['page_type'], true);
- $data['page_type'] = json_encode(array_values(array_unique($page_type)));
- $result = Template::insertGetId($data);
- if (empty($result)) {
- return Result::error("创建失败", 0);
- } else {
- return Result::success($result);
- }
- }
- /**
- * 删除皮肤
- * @param array $data
- * @return array
- */
- public function delTemplate(array $data): array
- {
- $rector = Sector::where('template_id', $data['id'])->first();
- if (!empty($rector)) {
- return Result::error("此皮肤已被绑定通栏,不可删除", 0);
- }
- $template = Template::where('id', $data['id'])->first();
- if(empty($template)){
- return Result::error("此皮肤不存在!", 0);
- }
- $web_template = WebsiteTemplateInfo::where('template_id', $template['template_id'])->first();
- if (!empty($web_template)) {
- return Result::error("此皮肤已被绑定网站,不可删除", 0);
- }
- // if ($template->type == 1) {
- // return Result::error("默认皮肤不能删除", 0);
- // }
- $component_img = ComponentImg::where('template_id', $template['template_id'])->get();
- if (!empty($component_img) && $component_img->count() > 0) {
- return Result::error('此皮肤已绑定组件预览图,不可删除!' . $component_img);
- }
- $result = Template::where('id', $data['id'])->delete();
- var_dump($result, '-------------------delete');
- if ($result) {
- return Result::success($result);
- } else {
- return Result::error("删除失败", 0);
- }
- }
- /**
- * 更新皮肤
- * @param array $data
- * @return array
- */
- public function updateTemplate(array $data): array
- {
- unset($data['user_id']);
- $template = Template::where('id', $data['id'])
- ->first();
- if (empty($template)) {
- return Result::error("此皮肤不存在!", 0);
- }
- $template = Template::where('id', '!=', $data['id'])
- ->where(function ($query) use ($data) {
- $query->where('template_name', $data['template_name'])
- ->orWhere('template_id', $data['template_id']);
- })
- ->first();
- if ($template) {
- return Result::error("皮肤名称或者皮肤编号已存在,不可编辑!", 0);
- }
- $data['template_keyword'] = array_map('trim', $data['template_keyword']);
- $data['template_keyword'] = json_encode($data['template_keyword']) ?? '';
- $page_type = json_decode($data['page_type'], true);
- $data['page_type'] = json_encode(array_values(array_unique($page_type)));
- $result = Template::where('id', $data['id'])->update($data);
- var_dump($result, '-------------------update');
- if (!$result) {
- return Result::error("更新失败", 0);
- } else {
- return Result::success('更新成功');
- }
- }
- /**
- * 获取所有尺寸
- * @param array $data
- * @return array
- */
- public function getAllSize(array $data): array
- {
- if(isset($data['id']) && !empty($data['id'])){
- $result = Size::where('id', $data['id'])->get()->all();
- }else{
- $result = Size::get()->all();
- }
- if(empty($result)){
- return Result::error("暂无尺寸", 0);
- }
- return Result::success($result);
- }
- /**
- * 根据皮肤名称-获取所有皮肤
- * @param array $data
- * @return array
- */
- public function getAllTemplate(array $data): array
- {
- $where = [];
- if (isset($data['template_class_id']) && !empty($data['template_class_id'])) {
- $where[] = ['template_class_id', $data['template_class_id']];
- }
- if (isset($data['template_name']) && !empty($data['template_name'])) {
- $where[] = ['template_name', 'like', '%' . $data['template_name'] . '%'];
- }
- $result = Template::where($where)->get()->all();
- if (empty($result)) {
- return Result::error("暂无皮肤", 0);
- }
- return Result::success($result);
- }
- /**
- * 获取通栏列表
- * @param array $data
- * @return array
- */
- public function getSectorList(array $data): array
- {
- $where = [];
- if (isset($data['template_class_id']) && !empty($data['template_class_id'])) {
- $where['template.template_class_id'] = $data['template_class_id'];
- }
- if (isset($data['template_id']) && !empty($data['template_id'])) {
- array_push($where, ['template.template_id', $data['template_id']]);
- }
- if (isset($data['sector_name']) && !empty($data['sector_name'])) {
- array_push($where, ['sector.sector_name', 'like', '%' . $data['sector_name'] . '%']);
- }
- if (isset($data['height']) && !empty($data['height'])) {
- array_push($where, ['sector.pic_height', 'like', '%' . $data['height'] . '%']);
- }
- if (isset($data['page_type']) && !empty($data['page_type'])) {
- array_push($where, ['sector.page_type', 'like', '%' . $data['page_type'] . '%']);
- }
- $result = Sector::leftJoin('template', 'template.template_id', '=', 'sector.template_id')
- ->leftJoin('template_class', 'template_class.class_id', '=', 'template.template_class_id')
- ->leftJoin('sector_place', 'sector_place.sector_type', '=', 'sector.place_type')
- ->where($where)
- ->where(function ($query) {
- $query->where('sector_place.type_id', 1)
- ->orWhereNull('sector_place.type_id');
- })
- ->select(
- 'sector.*',
- 'template_class.name as class_name',
- 'template_class.class_id',
- 'template.template_name',
- 'sector_place.name as place_name',
- 'sector_place.sector_img as place_img'
- )
- ->orderBy('sector.id', 'desc')
- ->paginate($data['page_size'], ['*'], 'page', $data['page']);
- if(empty($result)){
- return Result::error('暂无通栏!');
- }
- return Result::success($result);
- }
- /**
- * 获取通栏详情
- * @param array $data
- * @return array
- */
- public function getSectorInfo(array $data): array
- {
- // $where = [];
- $where[] = ['sector.id', '=', $data['id']];
- $result = Sector::where($where)
- ->leftJoin('template', 'template.template_id', '=', 'sector.template_id')
- ->select('sector.*', 'template.template_name', 'template.template_id')
- ->orderBy('sector.id', 'desc')
- ->first();
- $result['component'] = SectorComponent::where('sector_component.sector_id', $data['id'])
- ->leftJoin('component', 'component.component_type', '=', 'sector_component.component_id')
- ->select('component.component_type', 'sector_component.sort_id', 'component.component_name')
- ->get()->all();
- // $sorts = array_values(array_unique(array_column($components, 'sort_id')));
- // $result['component'] = $components;
- $result['place'] = SectorPlace::where('sector_place.sector_type', $result['place_type'])
- ->where('sector_place.type_id', 1)
- ->select('sector_place.sector_img', 'sector_place.map')
- ->first();
- if (empty($result)) {
- return Result::error('此通栏不存在!');
- }
- return Result::success($result);
- }
- /**
- * 获取经纬度信息
- * @return void
- */
- public function getIpInfo(array $data): array
- {
- if (empty($data['ip'])) {
- // 在RPC服务中,依赖$_SERVER是不可靠的,强制要求调用方传入IP
- return Result::error('IP地址不能为空!');
- }
- $client_ip = $data['ip'];
- try {
- // 直接从容器获取 Guzzle 客户端实例
- /** @var \GuzzleHttp\Client $client */
- $client = \Hyperf\Context\ApplicationContext::getContainer()->get(Client::class);
- // 使用新的 GeoJS API 地址
- $api_url = "https://get.geojs.io/v1/ip/geo/{$client_ip}.json";
- // 将 timeout 作为请求选项传递
- $response = $client->get($api_url, ['timeout' => 5]);
- if ($response->getStatusCode() !== 200) {
- return Result::error('IP查询接口请求失败,状态码:' . $response->getStatusCode());
- }
- $ip_info = json_decode($response->getBody()->getContents(), true);
- // GeoJS 的成功响应不包含 'status' 字段,直接检查关键数据是否存在
- if ($ip_info && isset($ip_info['latitude']) && isset($ip_info['longitude'])) {
- // GeoJS 返回的经纬度是字符串,转换为浮点数
- $ip_info['latitude'] = floatval($ip_info['latitude']);
- $ip_info['longitude'] = floatval($ip_info['longitude']);
- return Result::success($ip_info);
- }
- // 如果返回的数据不符合预期,提供一个通用错误
- $errorMessage = $ip_info['message'] ?? '获取IP地理位置信息失败';
- return Result::error($errorMessage);
- } catch (GuzzleException $e) {
- // 这个异常会给出详细的网络错误信息,如超时、无法解析域名等
- return Result::error('请求IP查询接口异常: ' . $e->getMessage());
- } catch (\Throwable $e) {
- return Result::error('获取IP信息时发生未知错误: ' . $e->getMessage());
- }
- }
- /**
- * 获取天气
- * @param array $data
- * @return array
- */
- public function getWeatherInfo(array $data): array
- {
- $month = $data['month'] ?? date('m');
- $day = $data['day'] ?? date('d');
- // 使用缓存键
- $cacheKey = "tsbb_data_weather_{$month}_{$day}";
- // 尝试从缓存获取数据
- $container = \Hyperf\Context\ApplicationContext::getContainer();
- $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
- if ($cachedData = $cache->get($cacheKey)) {
- return Result::success(unserialize($cachedData));
- }
- $location = $data['latitude'] . ":" . $data['longitude'];
- $api_url = "https://api.seniverse.com/v3/weather/now.json?key=" . \Hyperf\Support\env('WEATHER_KEY') . "&location=" . $location . "&language=zh-Hans&unit=c";
- $ch = curl_init($api_url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- $response = curl_exec($ch);
- curl_close($ch);
- // 解析 JSON 响应
- $WeatherInfo = json_decode($response, true);
- // 缓存结果,设置1小时过期
- $cache->set($cacheKey, serialize($WeatherInfo), 3600);
- if ($WeatherInfo) {
- return Result::success($WeatherInfo);
- } else {
- return Result::error("获取天气失败", 0);
- }
- }
- /**
- * 获取农历信息
- * @return void
- */
- public function getCalendar(array $data): array
- {
- $calendar = new Calendar();
- $result = $calendar->solar($data['year'], $data['month'], $data['day'], $data['hour']); // 阳历
- return Result::success($result);
- }
- /**
- * 添加通栏
- * @param array $data
- * @return array
- */
- public function addSector(array $data): array
- {
- unset($data['user_id']);
- // 对传入的 page_type 数组进行去重、转换为整数并重新索引
- $data['page_type'] = array_values(array_unique(array_map('intval', $data['page_type'])));
- $data['page_type'] = json_encode($data['page_type']);
- $template = Template::where('template_id', $data['template_id'])
- ->first();
- if (empty($template)) {
- return Result::error('皮肤不存在!');
- }
- $sector_query = Sector::where('template_id', $data['template_id']);
- if (!empty($sector_query->where('sector_id', $data['sector_id'])->first())) {
- return Result::error('通栏编号已存在!');
- }
- if(!empty($sector_query->where('sector_type', $data['place_type'])->where('component_code',$data['component_code'])->first())){
- return Result::error('通栏位置已存在!');
- }
- $sector_place = SectorPlace::where('sector_type', $data['place_type'])->get();
- if (empty($sector_place)) {
- return Result::error('位置不存在!');
- }
- $sort = json_decode($data['component_code'], true);
- $sector = 0;
- // $flattened = [];
- // $sector = [];
- $component = Component::whereIn('component_type', $sort)
- ->leftJoin('component_type','component.type_id','component_type.id')
- ->select('component.*','component_type.cat_num')
- ->get()->all();
-
- // return Result::success($data);
- if (empty($component)) {
- return Result::error('组件不存在!');
- }
- $data['cat_num'] = array_sum(array_column($component, 'cat_num'));
- $sector_component = [];
- foreach ($sort as $key => $subArray) {
- foreach ($subArray as $k => $item) {
- // // $component[] = $item;
- $sector_component[] = [
- 'sector_id' => $data['sector_id'],
- 'component_id' => $subArray[$k],
- 'sort_id' => $key + 1,
- 'place_id' => $data['place_type'],
- // 'sectorid' => $data['id'],
- ];
- // // // ---------同步通栏的sort_id到组件之中,目前已废弃,涉及到批量修改------
- // // $componentTypes[] = $item;
- // // $components[] = [
- // // 'sort_id' => $key + 1,
- // // 'component_type' => $item,
- // // ];
- // // $place_ids[] = $data['place_type'];
- }
- }
- // $component_num = count($component);
- // $count = count(array_unique($component));
- // 使用array_map批量替换sector_id
- // return Result::success($sector_component);
- if (count($sort) != $data['component_num']) {
- return Result::error('组件关联错误!');
- }
- // 通栏分类:1:资讯类:2:通栏广告类;3:混合类;4:头条类;5:轮播图类;
- $sector_code = [
- $data['sector_id'] => [
- 'sectorName' => $data['sector_name'],
- 'sectorHeight' => $data['pic_height'],
- 'sectorImg' => $data['sector_img'],
- ]
- ];
- // return Result::success($sector_code);
- $data['sector_code'] = json_encode($sector_code);
- Db::beginTransaction();
- try {
- $sector = Sector::insertGetId($data);
- if (empty($sector)) {
- Db::rollBack();
- return Result::error('添加失败');
- }
- $sector_com = array_map(function ($item) use ($sector) {
- // 替换当前记录的sector_id为变量值(保留其他字段不变)
- $item['sectorid'] = $sector;
- return $item;
- }, $sector_component);
- // Db::rollBack();
- // return Result::success($sector_com);
- $com_sector = SectorComponent::insert($sector_com);
- if (empty($com_sector)) {
- Db::rollBack();
- return Result::error('通栏关联组件失败!');
- }
- // ---------同步通栏的sort_id到组件之中,目前已废弃,涉及到批量修改------
- // 查询数据库中已存在的component_type(只保留存在的记录)
- // $existingTypes = Component::whereIn('component_type', $componentTypes)
- // ->pluck('component_type') // 提取存在的component_type
- // ->toArray();
- // if(empty($existingTypes)){
- // Db::rollBack();
- // return Result::error('组件不存在!');
- // }
- // // var_dump($existingTypes);
- // // 3. 过滤$components数组,只保留数据库中已存在的记录(核心:避免新增)
- // $updateData = array_filter($components, function ($item) use ($existingTypes) {
- // return in_array($item['component_type'], $existingTypes);
- // });
- // // 4. 执行upsert(此时$updateData中只有已存在的记录,不会新增)
- // if (!empty($updateData)) {
- // $component_sort = Component::upsert($updateData,['component_type'],['sort_id']);
- // }
- // if(empty($component_sort)){
- // Db::rollBack();
- // return Result::error('组件位置关联失败!');
- // }
- Db::commit();
- return Result::success($sector);
- } catch (\Exception $e) {
- Db::rollBack();
- return Result::error($e->getMessage());
- }
- }
- /**
- * 删除通栏
- * @param array $data
- * @return array
- */
- public function delSector(array $data): array
- {
- $sector = Sector::where('id', $data['id'])->first();
- if (empty($sector)) {
- return Result::error('通栏不存在!');
- }
- Db::beginTransaction();
- try {
- $component_id = SectorComponent::where('sectorid', $data['id'])->delete();
- if (empty($component_id)) {
- Db::rollBack();
- return Result::error('解除相关组件关联关系失败!');
- }
- $result = Sector::where('id', $data['id'])->delete();
- if (empty($result)) {
- Db::rollBack();
- return Result::error('通栏删除失败!');
- }
- Db::commit();
- return Result::success('通栏删除成功!');
- } catch (\Exception $e) {
- Db::rollBack();
- return Result::error($e->getMessage());
- }
- }
- /**
- * 修改通栏
- * @param array $data
- * @return array
- */
- public function updateSector(array $data): array
- {
- unset($data['user_id']);
- $sector = Sector::where('id', $data['id'])->first();
- if (empty($sector)) {
- return Result::error('通栏不存在!');
- }
- if ($sector['sector_id'] != $data['sector_id']) {
- $sector_id = Sector::where('sector_id', $data['sector_id'])->where('template_id', $data['template_id'])->first();
- if (!empty($sector_id)) {
- return Result::error('通栏编号已存在!');
- }
- }
- $sector_code = [
- $data['sector_id'] => [
- 'sectorName' => $data['sector_name'],
- 'sectorHeight' => $data['pic_height'],
- 'sectorImg' => $data['sector_img'],
- ]
- ];
- // return Result::success($sector_code);
- $data['sector_code'] = json_encode($sector_code);
- // 对传入的 page_type 数组进行去重、转换为整数并重新索引
- $data['page_type'] = array_values(array_unique(array_map('intval', $data['page_type'])));
- $data['page_type'] = json_encode($data['page_type']);
- $template = Template::where('template_id', $data['template_id'])
- ->whereRaw("JSON_CONTAINS(template.page_type, ?)", [$data['page_type']])
- ->first();
- if (empty($template)) {
- return Result::error('皮肤不存在!');
- }
- // 将嵌套二维数组展平为唯一值的一维数组
- $sort = json_decode($data['component_code'], true);
- $component_id = array_values(array_unique(array_merge(...$sort)));
- $component = Component::whereIn('component_type', $component_id)
- ->leftJoin('component_type','component.type_id','component_type.id')
- ->select('component.*','component_type.cat_num')
- ->get()->all();
- // return Result::success($data);
- if (empty($component)) {
- return Result::error('组件不存在!');
- }
- $data['cat_num'] = array_sum(array_column($component, 'cat_num'));
- $sector_component = [];
- foreach ($sort as $key => $subArray) {
- foreach ($subArray as $k => $item) {
- // // $component[] = $item;
- $sector_component[] = [
- 'sector_id' => $data['sector_id'],
- 'component_id' => $subArray[$k],
- 'sort_id' => $key + 1,
- 'place_id' => $data['place_type'],
- 'sectorid' => $data['id'],
- ];
- // // // ---------同步通栏的sort_id到组件之中,目前已废弃,涉及到批量修改------
- // // $componentTypes[] = $item;
- // // $components[] = [
- // // 'sort_id' => $key + 1,
- // // 'component_type' => $item,
- // // ];
- // // $place_ids[] = $data['place_type'];
- }
- }
- if (count($sort) != $data['component_num']) {
- return Result::error('组件关联错误!');
- }
- $data['sector_code'] = json_encode($sector_code);
- Db::beginTransaction();
- try {
- $com_sector = SectorComponent::where('sectorid', $data['id'])->pluck('component_id');
- if (empty($com_sector)) {
- Db::rollBack();
- return Result::error('通栏解除组件关联失败!');
- }
- $del_SectorComponent = SectorComponent::where('sectorid', $data['id'])->delete();
- if (empty($del_SectorComponent)) {
- Db::rollBack();
- return Result::error('通栏解除组件关联失败!1');
- }
- $sector = Sector::where('id', $data['id'])->update($data);
- if (empty($sector)) {
- Db::rollBack();
- return Result::error('修改失败');
- }
- $sector_com = array_map(function ($item) use ($data) {
- // 替换当前记录的sector_id为变量值(保留其他字段不变)
- $item['sectorid'] = $data['id'];
- return $item;
- }, $sector_component);
- // var_dump($sector_com);
- $com_sector = SectorComponent::insert($sector_com);
- if (empty($com_sector)) {
- Db::rollBack();
- return Result::error('通栏关联组件失败!');
- }
- // ---------同步通栏的sort_id到组件之中,目前已废弃,涉及到批量修改------
- // $up_component = Component::whereIn('component_id',$sector_component['component_type'])
- // ->update(['status' => 2,]);
- // if(empty($up_component)){
- // Db::rollBack();
- // return Result::error('通栏关联组件失败!');
- // }
- // 2. 查询数据库中已存在的component_type(只保留存在的记录)
- // $existingTypes = Component::whereIn('component_type', $componentTypes)
- // ->pluck('component_type') // 提取存在的component_type
- // ->toArray();
- // // 3. 过滤$components数组,只保留数据库中已存在的记录(核心:避免新增)
- // $updateData = array_filter($components, function ($item) use ($existingTypes) {
- // return in_array($item['component_type'], $existingTypes);
- // });
- // // 4. 执行upsert(此时$updateData中只有已存在的记录,不会新增)
- // if (!empty($updateData)) {
- // $component_sort = Component::upsert($updateData,['component_type'],['sort_id']);
- // }
- // if(empty($component_sort)){
- // Db::rollBack();
- // return Result::error('组件位置关联失败!');
- // }
- Db::commit();
- return Result::success($sector);
- } catch (\Exception $e) {
- Db::rollBack();
- return Result::error($e->getMessage());
- }
- }
- public function getComponentList(array $data): array
- {
- $where = [];
- if (isset($data['component_name']) && !empty($data['component_name'])) {
- array_push($where, ['component.component_name', 'like', '%' . $data['component_name'] . '%']);
- }
- if (isset($data['width']) && !empty($data['width']) && isset($data['height']) && !empty($data['height'])) {
- array_push($where, ['component.component_width', 'like', '%' . $data['width'] . '%']);
- array_push($where, ['component.component_height', 'like', '%' . $data['height'] . '%']);
- } else if (isset($data['width']) && !empty($data['width'])) {
- array_push($where, ['component.component_width', 'like', '%' . $data['width'] . '%']);
- } else if (isset($data['height']) && !empty($data['height'])) {
- array_push($where, ['component.component_height', 'like', '%' . $data['height'] . '%']);
- } else {
- }
- if(isset($data['type_id']) && !empty($data['type_id'])){
- $where['component.type_id'] = $data['type_id'];
- }
- $result = Component::where($where)
- ->leftJoin('component_type', 'component_type.id', '=', 'component.type_id')
- ->leftJoin('component_img', 'component.component_type', '=', 'component_img.component_id')
- ->select(
- 'component.*',
- 'component_type.com_typename',
- DB::raw('COUNT(component_img.id) as img_count')
- )
- ->groupBy('component.id') // 按组件ID分组,确保统计每个组件的图片数量
- ->orderBy('component.updated_at', 'desc')
- ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
- if(empty($result)){
- return Result::error('暂无数据');
- }
- return Result::success($result);
- }
- public function getComponentInfo(array $data): array
- {
- $where = ['component.id'=>$data['id']];
- $result = Component::where($where)
- ->leftJoin('component_type','component_type.id','=','component.type_id')
- ->select( 'component.*','component_type.com_typename')
- ->get();
- if(empty($result)){
- return Result::error('暂无数据');
- }
- return Result::success($result);
- }
- /*
- 新增组件
- */
- public function addComponent(array $data): array
- {
- unset($data['user_id']);
- $component_id = Component::where('component_type',$data['component_type'])->first();
- if(!empty($component_id)){
- return Result::error('组件编号已存在!');
- }
- $component_type = ComponentType::where('id',$data['type_id'])->first();
- if(empty($component_type)){
- return Result::error('组件分类不存在!');
- }
- // '组件分类:1:资讯-头条组件;2:资讯-轮播组件;3:资讯-推荐图类组件;4:资讯-最新类组件;5:资讯-推荐类;6:资讯-热点类组件;7:资讯-栏目类组件;
- // 8:列表类组件;9:详情类组件;10:二级导航栏类组件;11:广告类;12:静态资源类;13:底部导航类;14:广告资讯混合类
- $data['type_id'] = intval($data['type_id']);
- $add_arr = [
- // 'template_id' => intval($data['template_id']),
- 'component_type' => intval($data['component_type']),
- 'component_name' => $data['component_name'],
- 'component_img' => $data['component_img'],
- 'component_width' => $data['component_width'],
- 'component_height' => $data['component_height'],
- 'type_id' => intval($data['type_id']),
- 'component_keyword' => $data['component_keyword'],
- ];
- $component_head_code = [
- 'component_id' => $add_arr['component_type'],
- 'component_type' => $add_arr['type_id'],
- 'component_name' => $add_arr['component_name'],
- 'component_style' => 1,
- ];
- $add_arr['component_code'] = json_encode($component_head_code, true);
- $type = $data['type_id'];
- switch ($type) {
- case 19: //19:选项卡-资讯-推荐图类组件;
- $type = 3;
- break;
- case 20: //20:选项卡-资讯-最新类组件;
- $type = 4;
- break;
- case 21: //21:选项卡-资讯-推荐类组件;
- $type = 5;
- break;
- case 22: //22:选项卡-资讯-热点类组件;
- $type = 6;
- break;
- case 23: //23:选项卡-资讯-栏目类组件;
- $type = 7;
- break;
- case 24: //24:选项卡-资讯-广告混合类组件;
- $type = 14;
- break;
- }
- switch ($type) {
- case 1: //1:资讯-头条组件;
- case 2: //2:资讯-轮播组件;
- case 3: //3:资讯-推荐图类组件;
- case 4: //4:资讯-最新类组件;
- case 5: //5:资讯-推荐类组件;
- case 6: //6:资讯-热点类组件;
- $add_arr['level'] = $data['type_id'];
- $add_arr['img_num'] = intval($data['img_num']);
- $add_arr['text_num'] = intval($data['text_num']);
- $component_data['componentData'] = [
- // 'category_id' => '',
- 'level' => $add_arr['level'],
- 'name' => '',
- // 'category_arr' => [],
- 'imgSize' => $data['img_num'] ?? '',
- 'textSize' => $data['text_num'] ?? '',
- 'child' => [
- 'id' => '',
- 'imgSize' => '',
- 'textSize' => ''
- ]
- ];
- if ($data['type_id'] == 4) {
- $component_data['componentData']['name'] = '最新资讯';
- }
- if ($data['type_id'] == 5 || $data['type_id'] == 6) {
- $component_data['componentData']['name'] = '热点精选';
- }
- $add_arr['component_data'] = json_encode($component_data, true);
- $add_arr['component_column'] = $component_type['com_code'] ?? '';
- break;
- case 7: //7:资讯-栏目类组件;
- case 15: //15:滚动图文类;
- $add_arr['img_num'] = intval($data['img_num']);
- $add_arr['text_num'] = intval($data['text_num']);
- $add_arr['child_imgnum'] = intval($data['child_imgnum'] ?? null);
- $add_arr['child_textnum'] = intval($data['child_textnum'] ?? null);
- $component_data['componentData'] = [
- 'category_id' => '',
- 'level' => '',
- 'name' => '',
- 'category_arr' => [],
- 'imgSize' => $add_arr['img_num'] ?? '',
- 'textSize' => $add_arr['text_num'] ?? '',
- 'child' => [
- 'id' => '',
- 'imgSize' => $add_arr['child_imgnum'] ?? '',
- 'textSize' => $add_arr['child_textnum'] ?? '',
- ]
- ];
- $add_arr['component_data'] = json_encode($component_data,true);
- $add_arr['component_column'] = $component_type['com_code'] ?? '';
- break;
-
- case 8: //8:列表类组件;
- $add_arr['pageSize'] = intval($data['pageSize']);
- $component_data['componentData'] = [
- 'category_id' => '',
- 'pageType' => [
- 'page' => 1,
- 'pageSize' => $add_arr['pageSize'] ?? '',
- ]
- ];
- $add_arr['component_data'] = json_encode($component_data,true);
- $add_arr['component_column'] = $component_type['com_code'] ?? '';
- break;
- case 9: //9:详情类组件;
- $component_data['componentData'] = [
- 'article_id' => '',
- ];
- $add_arr['component_data'] = json_encode($component_data,true);
- $add_arr['component_column'] = $component_type['com_code'] ?? '';
- break;
- case 10: //10:二级导航类组件;
- $add_arr['cate_place'] = 1;
- $add_arr['num'] = intval($data['num']);
- $component_data['componentData'] = [
- 'pid' => '',
- 'placeid' => 1,
- 'num' => $add_arr['num'],
- ];
- $add_arr['component_data'] = json_encode($component_data,true);
- $add_arr['component_column'] = $component_type['com_code'] ?? '';
- break;
- case 11: //11:广告类;
- $add_arr['ad_width'] = intval($data['ad_width']);
- $add_arr['ad_height'] = intval($data['ad_height']);
- $add_arr['component_width'] = intval($data['ad_width']);
- $add_arr['component_height'] = intval($data['ad_height']);
- $add_arr['ad_type'] = intval($data['ad_type']);
- // $add_arr['ad_img'] = $data['ad_img'];
- $ad = [
- 'width' => $add_arr['ad_width'],
- 'height' => $add_arr['ad_height'],
- 'name' => '',
- 'price' => '',
- 'introduce' => '',
- 'website_id' => '',
- // 'thumb' => $add_arr['ad_img'],
- 'typeid' => $add_arr['ad_type'],
- 'ad_tag' => '',
- ];
- $add_arr['ad'] = json_encode($ad,true);
- $add_arr['component_column'] = $component_type['com_code'] ?? '';
- // $add_arr['adimg_info'] = $data['img_info'];
- // $ad_imginfo = json_decode($data['img_info'],true);
- break;
- // case 13: //13:底部导航类;
- case 17: //17:单页列表类;
- case 18: //18:单页详情类;
- $component_data['componentData'] = [
- 'fcat_id' => '',
- ];
- $add_arr['component_data'] = json_encode($component_data,true);
- $add_arr['component_column'] = $component_type['com_code'] ?? '';
- break;
- case 14: //14:栏目资讯-广告混合类;
- $add_arr['ad_width'] = intval($data['ad_width']);
- $add_arr['ad_height'] = intval($data['ad_height']);
- $add_arr['component_width'] = intval($data['component_width']);
- $add_arr['component_height'] = intval($data['component_height']);
- $add_arr['ad_type'] = intval($data['ad_type']);
- $add_arr['ad_img'] = $data['ad_img'];
- $add_arr['img_num'] = intval($data['img_num']);
- $add_arr['text_num'] = intval($data['text_num']);
- $add_arr['child_imgnum'] = intval($data['child_imgnum'] ?? null);
- $add_arr['child_textnum'] = intval($data['child_textnum'] ?? null);
- $component_data['componentData'] = [
- 'category_id' => '',
- 'level' => '',
- 'name' => '',
- 'category_arr' => [],
- 'imgSize' => $data['img_num'] ?? '',
- 'textSize' => $data['text_num'] ?? '',
- 'child' => [
- 'id' => '',
- 'imgSize' => $data['child_imgnum'] ?? '',
- 'textSize' => $data['child_textnum'] ?? '',
- ]
- ];
- $ad = [
- 'width' => $add_arr['ad_width'],
- 'height' => $add_arr['ad_height'],
- 'name' => '',
- 'price' => '',
- 'introduce' => '',
- 'website_id' => '',
- 'thumb' => $add_arr['ad_img'],
- 'typeid' => $add_arr['ad_type'],
- 'ad_tag' => '',
- ];
- $add_arr['ad'] = json_encode($ad,true);
- $add_arr['component_data'] = json_encode($component_data,true);
- $add_arr['component_column'] = $component_type['com_code'] ?? '';
- // $add_arr['adimg_info'] = $data['img_info'];
- // $ad_imginfo = json_decode($data['img_info'],true);
- break;
- default:
- break;
- }
- if($data['type_id'] == 24){
- unset($add_arr['ad']);
- $add_arr['ad'][0] = $ad;
- $add_arr['ad'][1] = $ad;
- $add_arr['ad'] = json_encode($add_arr['ad'],true);
- }
- // if----带广告的特殊处理(广告位默认图上传静态资源的处理---已废弃)
- // if ($data['type_id'] == 11 || $data['type_id'] == 14) {
- // Db::beginTransaction();
- // try {
- // // $website_img = WebsiteImg::insertGetId($ad_imginfo);
- // // var_dump($website_img);
- // // $add_arr['ad_imgid'] = $website_img;
- // // if(empty($website_img)){
- // // Db::rollBack();
- // // return Result::error('广告默认图上传失败!');
- // // }
- // $result = Component::insertGetId($add_arr);
- // if (empty($result)) {
- // Db::rollBack();
- // return Result::error('添加失败!');
- // }
- // Db::commit();
- // } catch (\Exception $e) {
- // Db::rollback();
- // return Result::error('添加失败!');
- // }
- // }
- // else {
- // return Result::success($add_arr);
- $result = Component::insertGetId($add_arr);
- if (empty($result)) {
- return Result::error('添加组件失败!');
- }
- // }
- return Result::success($result);
- }
- public function delComponent(array $data): array
- {
- $component = Component::where('id', $data['id'])->first();
- if(empty($component)){
- return Result::error('组件不存在!');
- }
- $component_id = SectorComponent::where('component_id', $component['component_type'])->first();
- if (!empty($component_id)) {
- return Result::error('请先解除相关组件关联关系!');
- }
- Db::beginTransaction();
- try{
- // if($component['type_id'] == 11 || $component['type_id'] == 14){
- // $ad_img = WebsiteImg::where('id',$component['ad_imgid'])->first();
- // if(!empty($ad_img)){
- // $ad_img = WebsiteImg::where('id',$component['ad_imgid'])->delete();
- // if(empty($ad_img)){
- // Db::rollBack();
- // return Result::error('删除广告默认图失败!');
- // }
- // }
- // }
- $component_img = ComponentImg::where('component_id',$component['component_type'])->first();
- if(!empty($component_img)){
- $del_img = ComponentImg::where('component_id',$component['component_type'])->delete();
- if(empty($del_img)){
- Db::rollBack();
- return Result::error('删除组件预览图失败!');
- }
- }
- $result = Component::where('id',$data['id'])->delete();
- if(empty($result)){
- Db::rollBack();
- return Result::error('删除失败!');
- }
- Db::commit();
- return Result::success($result);
- }catch(\Exception $e){
- Db::rollback();
- return Result::error('删除失败!');
- }
-
- }
- public function updateComponent(array $data): array
- {
- unset($data['user_id']);
- $id = $data['id'];
- unset($data['id']);
- $component_id = Component::where('id','!=',$id)->where('component_type',$data['component_type'])->first();
- if(!empty($component_id) || $component_id != null){
- return Result::error('组件编号已存在!');
- }
- $component_type = ComponentType::where('id',$data['type_id'])->first();
- if(empty($component_type)){
- return Result::error('组件分类不存在!');
- }
- $component = Component::where('id',$id)->first();
- if(empty($component)){
- return Result::error('组件不存在!');
- }
- // 组件分类:1:资讯-头条组件;2:资讯-轮播组件;3:资讯-推荐图类组件;4:资讯-最新类组件;5:资讯-推荐类;6:资讯-热点类组件;
- // 7:资讯-栏目类组件;8:列表类组件;9:详情类组件;10:二级导航栏类组件;11:广告类;12:静态资源类;13:底部导航类;
- $data['type_id'] = intval($data['type_id']);
- $add_arr = [
- // 'template_id' => intval($data['template_id']),
- 'component_type' => intval($data['component_type']),
- 'component_name' => $data['component_name'],
- 'component_img' => $data['component_img'],
- 'component_width' => $data['component_width'],
- 'component_height' => $data['component_height'],
- 'type_id' => intval($data['type_id']),
- 'component_keyword' => $data['component_keyword'],
- ];
- $component_head_code = [
- 'component_id' => $add_arr['component_type'],
- 'component_type' => $add_arr['type_id'],
- 'component_name' => $add_arr['component_name'],
- 'component_style' => 1,
- ];
- $add_arr['component_code'] = json_encode($component_head_code, true);
- $type = $data['type_id'];
- switch ($type) {
- case 19: //19:选项卡-资讯-推荐图类组件;
- $type = 3;
- break;
- case 20: //20:选项卡-资讯-最新类组件;
- $type = 4;
- break;
- case 21: //21:选项卡-资讯-推荐类组件;
- $type = 5;
- break;
- case 22: //22:选项卡-资讯-热点类组件;
- $type = 6;
- break;
- case 23: //23:选项卡-资讯-栏目类组件;
- $type = 7;
- break;
- case 24: //24:选项卡-资讯-广告混合类组件;
- $type = 14;
- break;
- }
- switch ($type) {
- case 1: //1:资讯-头条组件;
- case 2: //2:资讯-轮播组件;
- case 3: //3:资讯-推荐图类组件;
- case 4: //4:资讯-最新类组件;
- case 5: //5:资讯-推荐类组件;
- case 6: //6:资讯-热点类组件;
- // $component_data['componentData']['name'] = '';
- $add_arr['level'] = $data['type_id'];
- $add_arr['img_num'] = intval($data['img_num']);
- $add_arr['text_num'] = intval($data['text_num']);
- $component_data['componentData'] = [
- // 'category_id' => '',
- 'level' => $add_arr['level'],
- // 'category_arr' => [],
- 'name' => '',
- 'imgSize' => $data['img_num'] ?? '',
- 'textSize' => $data['text_num'] ?? '',
- 'child' => [
- 'id' => '',
- 'imgSize' => '',
- 'textSize' => ''
- ]
- ];
- if ($data['type_id'] == 4) {
- $component_data['componentData']['name'] = '最新资讯';
- }
- if ($data['type_id'] == 5 || $data['type_id'] == 6) {
- $component_data['componentData']['name'] = '热点精选';
- }
- $add_arr['component_data'] = json_encode($component_data, true);
- $add_arr['component_column'] = $component_type['com_code'] ?? '';
- break;
- case 7: //7:资讯-栏目类组件;
- case 15: //15:滚动图文类;
- $add_arr['img_num'] = intval($data['img_num']);
- $add_arr['text_num'] = intval($data['text_num']);
- $add_arr['child_imgnum'] = intval($data['child_imgnum'] ?? null);
- $add_arr['child_textnum'] = intval($data['child_textnum'] ?? null);
- $component_data['componentData'] = [
- 'category_id' => '',
- 'level' => '',
- 'name' => '',
- 'category_arr' => [],
- 'imgSize' => $add_arr['img_num'] ?? '',
- 'textSize' => $add_arr['text_num'] ?? '',
- 'child' => [
- 'id' => '',
- 'imgSize' => $add_arr['child_imgnum'] ?? '',
- 'textSize' => $add_arr['child_textnum'] ?? '',
- ]
- ];
- $add_arr['component_data'] = json_encode($component_data,true);
- $add_arr['component_column'] = $component_type['com_code'] ?? '';
- break;
- case 8: //8:列表类组件;
- $add_arr['pageSize'] = intval($data['pageSize']);
- $component_data['componentData'] = [
- 'category_id' => '',
- 'pageType' => [
- 'page' => 1,
- 'pageSize' => $add_arr['pageSize'] ?? '',
- ]
- ];
- $add_arr['component_data'] = json_encode($component_data,true);
- $add_arr['component_column'] = $component_type['com_code'] ?? '';
- break;
- case 9: //9:详情类组件;
- $component_data['componentData'] = [
- 'article_id' => '',
- ];
- $add_arr['component_data'] = json_encode($component_data,true);
- $add_arr['component_column'] = $component_type['com_code'] ?? '';
- break;
- case 10: //10:二级导航类组件;
- $add_arr['cate_place'] = 1;
- $add_arr['num'] = intval($data['num']);
- $component_data['componentData'] = [
- 'pid' => '',
- 'placeid' => 1,
- 'num' => $add_arr['num'],
- ];
- $add_arr['component_data'] = json_encode($component_data,true);
- $add_arr['component_column'] = $component_type['com_code'] ?? '';
- break;
- case 11: //11:广告类;
- $add_arr['ad_width'] = intval($data['ad_width']);
- $add_arr['ad_height'] = intval($data['ad_height']);
- $add_arr['component_width'] = intval($data['ad_width']);
- $add_arr['component_height'] = intval($data['ad_height']);
- $add_arr['ad_type'] = intval($data['ad_type']);
- // $add_arr['ad_img'] = $data['ad_img'];
- $ad = [
- 'width' => $add_arr['ad_width'],
- 'height' => $add_arr['ad_height'],
- 'name' => '',
- 'price' => '',
- 'introduce' => '',
- 'website_id' => '',
- 'thumb' => $add_arr['ad_img'],
- // 'typeid' => $add_arr['ad_type'],
- 'ad_tag' => '',
- ];
- $add_arr['ad'] = json_encode($ad, true);
- $add_arr['component_column'] = $component_type['com_code'] ?? '';
- // $add_arr['adimg_info'] = $data['img_info'];
- // $ad_imginfo = json_decode($data['img_info'],true);
- break;
- // case 13: //13:底部导航类;
- case 17: //17:单页列表类;
- case 18: //18:单页详情类;
- $component_data['componentData'] = [
- 'fcat_id' => '',
- ];
- $add_arr['component_data'] = json_encode($component_data,true);
- $add_arr['component_column'] = $component_type['com_code'] ?? '';
- break;
- case 14:
- $add_arr['ad_width'] = intval($data['ad_width']);
- $add_arr['ad_height'] = intval($data['ad_height']);
- $add_arr['component_width'] = intval($data['component_width']);
- $add_arr['component_height'] = intval($data['component_height']);
- $add_arr['ad_type'] = intval($data['ad_type']);
- $add_arr['ad_img'] = $data['ad_img'];
- $add_arr['img_num'] = intval($data['img_num']);
- $add_arr['text_num'] = intval($data['text_num']);
- $add_arr['child_imgnum'] = intval($data['child_imgnum'] ?? null);
- $add_arr['child_textnum'] = intval($data['child_textnum'] ?? null);
- $component_data['componentData'] = [
- 'category_id' => '',
- 'level' => '',
- 'name' => '',
- 'category_arr' => [],
- 'imgSize' => $data['img_num'] ?? '',
- 'textSize' => $data['text_num'] ?? '',
- 'child' => [
- 'id' => '',
- 'imgSize' => $data['child_imgnum'] ?? '',
- 'textSize' => $data['child_textnum'] ?? '',
- ]
- ];
- $ad = [
- 'width' => $add_arr['ad_width'],
- 'height' => $add_arr['ad_height'],
- 'name' => '',
- 'price' => '',
- 'introduce' => '',
- 'website_id' => '',
- 'thumb' => $add_arr['ad_img'],
- 'typeid' => $add_arr['ad_type'],
- 'ad_tag' => '',
- ];
- $add_arr['ad'] = json_encode($ad,true);
- $add_arr['component_data'] = json_encode($component_data,true);
- $add_arr['component_column'] = $component_type['com_code'] ?? '';
- // $add_arr['adimg_info'] = $data['img_info'];
- // $ad_imginfo = json_decode($data['img_info'],true);
- break;
- default:
- break;
- }
- // var_dump("ad_imginfo:",$ad_imginfo);
- $cll_column = [
- 'img_num' => null,
- 'text_num' => null,
- 'child_imgnum' => null,
- 'child_textnum' => null,
- 'category_id' => null,
- 'child_id' => null,
- 'num' => null,
- 'level' => null,
- 'fcatid' => null,
- 'article_id' => null,
- 'cate_place' => null,
- 'pageSize' => null,
- // 'ad_img' => null,
- 'ad_width' => null,
- 'ad_height' => null,
- 'ad' => '',
- 'ad_type' => null,
- // 'ad_imgid' => null,
- 'adimg_info' => '[]',
- ];
- if($data['type_id'] == 24){
- unset($add_arr['ad']);
- $add_arr['ad'][0] = $ad;
- $add_arr['ad'][1] = $ad;
- $add_arr['ad'] = json_encode($add_arr['ad'],true);
- }
- Db::beginTransaction();
- try{
- // return Result::success($add_arr);
- // if(($component['type_id'] == 11 || $component['type_id'] == 14) && ($data['type_id'] != 11 && $data['type_id'] != 14)){
- // // $website_img = WebsiteImg::where('id',$component['ad_imgid'])->delete();
- // if(empty($website_img)){
- // Db::rollBack();
- // return Result::error('广告默认图删除失败!');
- // }
- // var_dump("删除",$website_img);
- // }
- // if(($data['type_id'] == 11 || $data['type_id'] == 14) && ($component['type_id'] != 11 && $component['type_id'] != 14)){
- // $website_img = WebsiteImg::insertGetId($ad_imginfo);
- // $add_arr['ad_imgid'] = $website_img;
- // if(empty($website_img)){
- // Db::rollBack();
- // return Result::error('广告默认图上传失败!');
- // }
- // var_dump("上传",$website_img);
- // }
- // if(($component['type_id'] == 11 || $component['type_id'] == 14) && ($data['type_id'] == 11 || $data['type_id'] == 14)){
- // $website_img = WebsiteImg::where('id',$component['ad_imgid'])->first();
- // if(empty($website_img)){
- // $website_img = WebsiteImg::insertGetId($ad_imginfo);
- // $add_arr['ad_imgid'] = $website_img;
- // }else{
- // $website_img = WebsiteImg::where('id',$component['ad_imgid'])->update($ad_imginfo);
- // $add_arr['ad_imgid'] = $component['ad_imgid'];
- // }
- // if(empty($website_img)){
- // Db::rollBack();
- // return Result::error('广告默认图修改失败!');
- // }
- // }
- $add_arr = array_merge($cll_column,$add_arr);
- $result = Component::where('id',$id)->update($add_arr);
- if(empty($result)){
- Db::rollBack();
- return Result::error('修改失败!');
- }
- Db::commit();
- }catch(\Exception $e){
- Db::rollBack();
- return Result::error('修改失败!');
- }
- return Result::success($result);
- }
- public function getWebsiteTemplateInfo(array $data)
- {
- $where = [];
- if (isset($data['id'])) {
- $where[] = ['id', '=', $data['id']];
- }
- $result = WebsiteTemplateInfo::where($where)
- ->leftJoin('website', 'website_template_info.website_id', '=', 'website.id')
- ->leftJoin('website_template', 'website_template_info.template_id', '=', 'website_template.id')
- ->select('website_template_info.*', 'website.website_name')
- ->get();
- if ($result) {
- return Result::success($result);
- } else {
- return Result::error('暂无数据');
- }
- }
- /**
- * 自助建站----1.获取页面类型回显
- * @param array $data
- * @return array
- */
- public function getWebPageType(array $data): array
- {
- // 1:图片 2:文字 3:底部
- $friend_link = Link::where('website_id', $data['website_id'])->where('type', 3)->get();
- if (empty($friend_link->toArray())) {
- return Result::error('暂无友情链接数据!');
- }
- $footer_category = FooterCategory::where('website_id', $data['website_id'])->get();
- if (empty($footer_category->toArray())) {
- return Result::error('暂无底部导航数据!');
- }
- $page_type = WebsiteTemplateInfo::where('website_id', $data['website_id'])->value('page_type');
- if (empty($page_type)) {
- $page_type = [];
- } else {
- $page_type = json_decode($page_type, true);
- }
- // '网站页面类型(存数组)1:首页 2:分类页 3:列表页 4:详情页 5:搜索页 6:特殊列表 7:特殊详情页
- if (isset($page_type) && in_array(5, $page_type)) {
- $page_type = 1;
- } else {
- $page_type = 0;
- }
- $result = [
- 'friend_link' => $friend_link,
- 'footer_category' => $footer_category,
- 'page_type' => $page_type,
- ];
- return Result::success($result);
- }
- /**
- * 自助建站----2.添加页面类型
- * @param array $data
- * @return array
- */
- public function addWebPageType(array $data): array
- {
- // return Result::success($data);
- // 1:首页 2:频道页 3:列表页 4:详情页 5:搜索页 6:特殊列表 7:特殊详情页'
- if ($data['is_search'] == 1) {
- $page_type = json_encode([1,2,3,4,5,6,7]);
- } else {
- $page_type = json_encode([1,2,3,4,6,7]);
- }
- // 0:未构建;1:已填写基础信息;2:已选择模板; action_id
- $website_template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
- $website_template = WebsiteTemplate::where('website_id', $data['website_id'])->first();
- Db::beginTransaction();
- try{
- if (empty($website_template_info)) {
- $result['template_info'] = WebsiteTemplateInfo::insertGetId([
- 'website_id' => $data['website_id'],
- 'page_type' => $page_type,
- 'user_id' => $data['user_id'],
- 'status' => 0,
- 'action_id' => 1,
- ]);
- } else {
- if ($website_template_info['status'] == 2) {
- Db::rollBack();
- return Result::error('网站已应用,不可再次修改!');
- }
- $result['template_info'] = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['page_type' => $page_type, 'action_id' => 1, 'user_id' => $data['user_id']]);
- }
- if (!$result['template_info']) {
- Db::rollBack();
- return Result::error('网站所选页面添加失败');
- }
- if(empty($website_template)){
- $result['template'] = WebsiteTemplate::insertGetId([
- 'website_id' => $data['website_id'],
- 'page_type' => $page_type,
- 'user_id' => $data['user_id'],
- ]);
- }else{
- $result['template'] = WebsiteTemplate::where('website_id', $data['website_id'])->update([
- 'page_type' => $page_type,
- ]);
- }
- if(!$result['template']){
- Db::rollBack();
- return Result::error('添加网站预制模版信息失败!');
- }
- Db::commit();
- return Result::success($result);
- }catch(\Exception $e){
- Db::rollBack();
- return Result::error('添加失败');
- }
-
- }
- /**
- * 自助建站---流程---3.选择皮肤列表
- * @param array $data
- * @return array
- */
- public function getWebsiteTemplateList(array $data): array
- {
- $where = [];
- if (isset($data['template_class_id']) && $data['template_class_id']) {
- $where[] = ['template_class_id', '=', $data['template_class_id']];
- }
- // 0:未构建 1:未应用 2:已应用 status
- $templste_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
- if (empty($templste_info)) {
- return Result::error('请先填写网站基础信息!');
- }
- if ($templste_info['status'] == 2) {
- return Result::error('网站已应用,不可再次修改!');
- }
- if (isset($data['keyword']) && !empty($data['keyword'])) {
- if (is_array($data['keyword'])) {
- // 拼接多个模糊查询条件
- $query = Template::query();
- foreach ($data['keyword'] as $kw) {
- $escapedKw = addcslashes($kw, '%_'); // 转义通配符
- $query->WhereRaw("JSON_EXTRACT(template_keyword, '$[*]') LIKE ?", ["%$escapedKw%"]);
- }
- } else {
- $escapedKeyword = addcslashes($data['keyword'], '%_'); // 转义通配符
- $where[] = [DB::raw("JSON_EXTRACT(template_keyword, '$[*]') LIKE ?"), "%$escapedKeyword%"];
- }
- } else {
- $query = Template::where($where);
- }
- $template_id = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first(['template_id', 'page_type']);
- // return Result::success($template_id);
- if (!empty($template_id['page_type']) && $templste_info['page_type'] != '[]' && is_string($templste_info['page_type'])) {
- $template_page = is_string($templste_info['page_type']) ? json_decode($templste_info['page_type'], true) : [];
- } else {
- $template_page = [];
- }
- if (!empty($template_id['template_id'])) {
- $result['template_id'] = $templste_info['template_id'];
- }
- // 确保 $template_page 为有效数据,避免 SQL 注入风险,这里使用参数绑定
- $template_page_str = json_encode($template_page);
- $result['template'] = $query->where($where)
- ->whereRaw("JSON_CONTAINS(template.page_type, ?)", [$template_page_str])
- ->orderBy('template.template_id', 'desc')
- ->paginate($data['page_size'], ['*'], 'page', $data['page']);
- if (empty($result['template'])) {
- $result['template'] = Template::orderBy('template.template_id', 'desc')
- ->paginate($data['page_size'], ['*'], 'page', $data['page']);
- }
- $template = WebsiteTemplateInfo::where('website_id', $data['website_id'])->value('template_id');
- if ($template) {
- $result['template_id'] = $template;
- } else {
- $result['template_id'] = 0;
- }
- return Result::success($result);
- }
- /**
- * 自助建站---流程---4.选择皮肤
- * @param array $data
- * @return array
- */
- public function chooseWebsiteTemplate(array $data): array
- {
- $website_template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
- if (empty($website_template_info)) {
- return Result::error('请先填写网站基础信息!');
- }
- // 0:未构建 1:未应用 2:已应用 status
- if ($website_template_info['status'] == 2) {
- return Result::error('网站已应用,不可再次修改!');
- }
- $template = Template::where('template_id', $data['template_id'])->first();
- if (empty($template)) {
- return Result::error('未查询到皮肤!');
- }
- // 0:未构建;1:已填写基础信息;2:已选择模板; action_id
- // 分别更新 WebsiteTemplateInfo 和 WebsiteTemplate 表
- Db::beginTransaction();
- try {
- if($data['template_id'] != $website_template_info['template_id']){
- $info_data = [
- 'template_id' => $data['template_id'],
- 'status' => 0,
- 'action_id' => 2,
- 'user_id'=> $data['user_id']
- ];
- $template = [
- 'template_id' => $data['template_id'],
- 'user_id'=> $data['user_id'],
- 'template_data' => null,
- 'canvas_data' => null
- ];
- }else{
- $info_data = [
- 'template_id' => $data['template_id'],
- 'user_id'=> $data['user_id'],
- 'action_id' => 2,
- ];
- $template = [
- 'template_id' => $data['template_id'],
- 'user_id'=> $data['user_id']
- ];
- }
- $result['template_info'] = WebsiteTemplateInfo::where('website_id', $data['website_id'])
- ->update($info_data);
- if(empty($result['template_info'])){
- Db::rollBack();
- return Result::error('选择皮肤失败!');
- }
- $result['template'] = WebsiteTemplate::where('website_id', $data['website_id'])
- ->update($template);
- if(empty($result['template'])){
- Db::rollBack();
- return Result::error('网站模版选择皮肤失败!');
- }
- Db::commit();
- return Result::success($result);
- } catch (\Exception $e) {
- Db::rollBack();
- return Result::error('选择皮肤失败!');
- }
- }
- /**
- * 自助建站---流程---5.保存模版
- * @param array $data
- * @return array
- */
- public function saveWebsiteTemplate(array $data): array
- {
- // return Result::success($data);
- $website_template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
- if (empty($website_template_info) || empty($website_template_info->template_id) || empty($website_template_info->page_type)) {
- return Result::error('请先填写网站基础信息!');
- }
- // 0:未构建 1:未应用 2:已应用 status
- if ($website_template_info['status'] == 2) {
- return Result::error('网站已应用,不可再次保存!');
- }
- if ($website_template_info['action_id'] != 2) {
- return Result::error('请完成之前的步骤!');
- }
- $template_info = WebsiteTemplate::where('website_id', $data['website_id'])->first();
- // var_dump($data['template_data']);
- try {
- Db::beginTransaction();
- if (empty($template_info)) {
- Db::rollback();
- return Result::error('该网站不存在已保存的模版!');
- } else {
- $template = WebsiteTemplate::where('website_id', $data['website_id'])->update(
- [
- 'template_data' => $data['template_data'],
- 'user_id' => $data['user_id'],
- 'canvas_data' => $data['canvas_data'],
- ]
- );
- }
- if (empty($template)) {
- Db::rollback();
- return Result::error('保存失败!');
- } else {
- $tempalte_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['status' => 1]);
- if (empty($tempalte_info)) {
- Db::rollback();
- return Result::error('网站搭建状态保存失败!');
- }
- Db::commit();
- }
- } catch (\Exception $e) {
- return Result::error('模版数据格式错误!');
- }
- return Result::success($template);
- }
- /**
- * 自助建站---流程---6.返显保存的模版
- * @param array $data
- * @return array
- */
- public function getWebsiteTemplate(array $data): array
- {
- $web = Website::where('id', $data['website_id'])->first();
- if (empty($web)) {
- return Result::error('未查询到网站信息!');
- }
- $template = WebsiteTemplate::where('website_id', $data['website_id'])
- ->first(['website_id', 'template_id', 'page_type', 'template_data', 'canvas_data']);
- if (empty($template)) {
- return Result::error('未查询到模版!');
- }
- $template['page_type'] = json_decode($template['page_type'],true);
- return Result::success($template);
- }
- /**
- * 通栏版式管理-获取通栏版式列表
- */
- public function getSectorPlaceList(array $data): array
- {
- $where['sector_place.type_id'] = $data['type_id'];
- if(isset($data['component_num']) && !empty($data['component_num'])){
- $where['sector_place.component_num'] = $data['component_num'];
- }
- if(isset($data['sector_type']) && !empty($data['sector_type'])){
- $where['sector_place.sector_type'] = $data['sector_type'];
- }
- // if(isset($data['component_type']) && !empty($data['component_type'])){
- // $where['sector_place.component_type'] = $data['component_type'];
- // }
- if(isset($data['name']) && !empty($data['name'])){
- array_push($where,['sector_place.name', 'like', '%'.$data['name'].'%']);
- }
- if (isset($data['width']) && !empty($data['width']) && isset($data['height']) && !empty($data['height'])){
- array_push($where,['sector_place.width','like','%'.$data['width'].'%']);
- array_push($where,['sector_place.height','like','%'.$data['height'].'%']);
- } else if( isset($data['width']) && !empty($data['width'])){
- array_push($where,['sector_place.width','like','%'.$data['width'].'%']);
- }else if( isset($data['height']) && !empty($data['height'])){
- array_push($where,['sector_place.height','like','%'.$data['height'].'%']);
- }else{
- $size_id = [];
- }
- $sector_place = SectorPlace::where($where)
- ->select('sector_place.*');
- $result['count'] = $sector_place->count();
- $result['row'] = $sector_place->paginate($data['page_size'], ['*'], 'page', $data['page']);
- if($data['type_id'] == 2){
- $result['map_json'] = SectorPlace::where('sector_type', $data['sector_type'])->where('type_id', 1)->pluck('map');
- }
- if (empty($result['count'])) {
- return Result::error("暂无相关版式数据!");
- }
- return Result::success($result);
- }
- /**
- * 通栏版式管理-添加通栏版式
- */
- public function addSectorPlace(array $data): array
- {
- unset($data['user_id']);
- // 1:通栏;2:组件;
- if ($data['type_id'] == 1) {
- $sector_place = SectorPlace::where('sector_type', $data['sector_type'])->first();
- if (!empty($sector_place)) {
- return Result::error('通栏版式类别编号已存在!');
- }
- $data['sort_id'] = 0;
- } else {
- $sector_type = SectorPlace::where('sector_type', $data['sector_type'])->where('type_id', 1)->first();
- if (empty($sector_type)) {
- return Result::error('通栏版式类别不存在!');
- }
- $component = SectorPlace::where('type_id', 2)->where('sector_type', $data['sector_type'])->get()->all();
- if(!empty($component)){
- if(count($component) >= $sector_type['component_num']){
- return Result::error('通栏版式组件数量已达上限!');
- }
- if(in_array($data['sort_id'], array_column($component, 'sort_id')) && in_array($data['line_num'], array_column($component, 'line_num')) && in_array($data['column_num'], array_column($component, 'column_num'))){
- return Result::error('组件版式位置已存在!');
- }
- if(in_array($data['component_type'], array_column($component, 'component_type'))){
- return Result::error('组件版式编号已存在!');
- }
- $data['component_num'] = 0;
- }
- if(in_array($data['type'],[23,24])){
- $data['cat_num'] = 2;
- }else if(in_array($data['type'],[7,14])){
- $data['cat_num'] = 1;
- }else{
- $data['cat_num'] = 0;
- }
- }
- Db::beginTransaction();
- try{
- $result = SectorPlace::insertGetId($data);
- if (empty($result)) {
- Db::rollBack();
- return Result::error('添加失败!');
- }
- if($data['type_id'] == 2 && count($component)+1 == $sector_type['component_num']){
- $map = $this->changeSectorPlaceJson($sector_type['sector_type']);
- $sector_place_map = SectorPlace::where('sector_type', $sector_type['sector_type'])
- ->where('type_id', 1)->update(['map' => json_encode($map['map_json']),'cat_num'=>$map['cat_num']]);
- if($sector_place_map === false){
- Db::rollBack();
- return Result::error('通栏版式画布数据更新失败!');
- }
- }
- Db::commit();
- return Result::success($result);
- }catch(\Exception $e){
- Db::rollBack();
- return Result::error($e->getMessage());
- }
-
- }
- /**
- * 通栏版式管理-版式画布
- * @param array $data
- * @return array
- */
- public function changeSectorPlaceJson($sector_type)
- {
- $component = SectorPlace::where('type_id', 2)->where('sector_type', $sector_type)->get()->all();
- // $component[count($component)] = $data;
- $sector_type_info = SectorPlace::where('sector_type', $sector_type)->where('type_id', 1)->first();
- if (empty($sector_type_info)) {
- return Result::error('通栏版式类别不存在!');
- }
- $row_num = 1;
- $cat_num = 0;
- $row_width = [];
- $map = [];
- if(count($component) == $sector_type_info['component_num']){
- foreach($component as $key => $val){
- if(in_array($val['type'],[23,24])){
- $cat_num = $cat_num + 2;
- }
- if(in_array($val['type'],[7,14])){
- $cat_num = $cat_num + 1;
- }
- if(!isset($map[$val['column_num'] - 1]['col_data']['row_num'])){
- $row_num = 1;
- $map[$val['column_num'] - 1]['col_data']['row_num'] = $row_num;
- }else{
- $map[$val['column_num'] - 1]['col_data']['row_num'] = $row_num +1;
- }
- // 原代码使用 $sector_type['width'] 有误,应该使用 $sector_type_info
- $width = number_format((($val['width'] / $sector_type_info['width']) * 100 - 1.5), 2);
- $height = number_format((($val['height'] / $sector_type_info['height']) * 100 - 2.5), 2);
- $row_key = intval($val['line_num'] - 1);
- $map[$val['column_num'] - 1]['col_data']['row_data'][$row_key] = [
- 'row_width' => $width.'%',
- 'row_height' => $height.'%',
- 'component_sort' => $val['sort_id'],
- ];
- $map[$val['column_num'] - 1]['col_data']['col_width'] = $width.'%';
-
- }
- }
- $map_data = [
- 'map_json'=>$map ?? [],
- 'component'=>count($component),
- 'row_num'=>$row_num ?? 0,
- 'cat_num'=>$cat_num ?? 0,
- 'component_info'=>$component,
- ];
- return $map_data;
- }
- /**
- * 通栏版式管理-修改通栏版式
- */
- public function upSectorPlace($data): array
- {
- unset($data['user_id']);
- // return Result::success($data);
- // $id = $data['id'];
- // 1:通栏;2:组件;
- if ($data['type_id'] == 1) {
- $sector_type = SectorPlace::where('id', $data['id'])
- ->where('type_id',1)
- ->first();
- if (empty($sector_type)) {
- return Result::error('通栏版式不存在!');
- }
- unset($data['sort_id']);
- unset($data['component_type']);
- unset($data['type']);
- // return Result::success($map);
- $sector_place_id = SectorPlace::where('id', '!=', $data['id'])->where('sector_type', $data['sector_type'])->where('type_id', 1)->first();
- if (!empty($sector_place_id)) {
- return Result::error('通栏版式编号已存在!');
- }
- $map = $this->changeSectorPlaceJson($sector_type['sector_type']) ?? [];
- if($data['component_num'] == $map['component']){
- $data['cat_num'] = $map['cat_num'];
- $data['map'] = json_encode($map['map_json']);
- }else{
- $data['cat_num'] = $map['cat_num'];
- $data['map'] = '';
- }
- if($data['sector_type'] != $sector_type['sector_type'] && $map['component'] != 0){
- $com_place = SectorPlace::where('sector_type', $sector_type['sector_type'])
- ->where('type_id', 2)
- ->update(['sector_type'=>$data['sector_type']]);
- if(empty($com_place)){
- return Result::error('组件版式编号同步更新失败!');
- }
- }
- $map = $this->changeSectorPlaceJson($data['sector_type']) ?? [];
- $data['cat_num'] = $map['cat_num'] ?? 0;
- $map = json_encode($map['map_json'] ?? []);
- $result = SectorPlace::where('id', $data['id'])->update($data);
- } else {
- $component_type = SectorPlace::where('id', $data['id'])->where('type_id', 2)->first();
- if (empty($component_type)) {
- return Result::error('组件版式不存在!');
- }
- unset($data['component_num']);
- unset($data['map']);
- $component = SectorPlace::where('sector_type', $data['sector_type'])
- ->where(function($query)use($data){
- $query->where('component_type', $data['component_type'])
- ->Orwhere('sort_id', $data['sort_id']);
- })
- ->where('id', '!=', $data['id'])
- ->where('type_id', 2)
- ->get()->all();
- if (!empty($component)) {
- return Result::error('组件版式编号或位置已存在!');
- }
- if(in_array($data['type'],[23,24])){
- $data['cat_num'] = 2;
- }else if(in_array($data['type'],[7,14])){
- $data['cat_num'] = 1;
- }else{
- $data['cat_num'] = 0;
- }
- $result['component'] = SectorPlace::where('id', $data['id'])->update($data);
- $map = $this->changeSectorPlaceJson($data['sector_type']) ?? [];
- $data['cat_num'] = $map['cat_num'] ?? 0;
- $map = json_encode($map['map_json'] ?? []);
- $result['map'] = SectorPlace::where('sector_type', $data['sector_type'])
- ->where('type_id', 1)
- ->update(['map'=>$map,'cat_num'=>$data['cat_num']]);
- }
-
- if (empty($result)) {
- return Result::error('修改失败!');
- }
- // $update_result['sector_place'] = SectorPlace::where('id',$data['id'])->first();
- // $update_result['map'] = $map;
- return Result::success([
- 'result'=>$result,
- ]);
- }
- /**
- * 通栏版式管理-删除通栏版式
- */
- public function delSectorPlace(array $data): array
- {
- $sector_place = SectorPlace::where('id', $data['id'])->first();
- if (empty($sector_place)) {
- return Result::error('通栏版式不存在!');
- }
- $sector = Sector::where('place_type', $sector_place['sector_type'])->first();
- if (!empty($sector)) {
- return Result::error('通栏版式分类已应用,暂不可删除!');
- }
- Db::beginTransaction();
- try{
- if($sector_place['type_id'] == 1){
-
- $where = ['sector_type'=>$sector_place['sector_type']];
- }else{
- $update_result = SectorPlace::where('sector_type', $sector_place['sector_type'])
- ->where('type_id', 1)
- ->whereNotNull('map')
- ->update(['map' => null]);
- if ($update_result === false) {
- Db::rollBack();
- return Result::error('通栏版式画布数据清空失败!');
- }
- $where = ['id'=>$data['id']];
- }
- $result = SectorPlace::where($where)->delete();
- if (empty($result)) {
- Db::rollBack();
- return Result::error('删除失败!');
- }
- Db::commit();
- return Result::success('删除成功!');
- }catch(\Exception $e){
- Db::rollBack();
- return Result::error($e->getMessage());
- }
-
-
- }
- /**
- * 自助建站-通栏版式管理-获取通栏版式详情
- */
- public function getSectorPlaceInfo(array $data): array
- {
- $result = SectorPlace::where('sector_place.id',$data['id'])
- ->leftJoin('size','sector_place.size_id','=','size.id')
- ->select('sector_place.*','size.width','size.height')
- ->first();
- if(empty($result)){
- return Result::error('通栏版式不存在!');
- }
- return Result::success($result);
- }
- /**
- * 自助建站-通栏版式管理-获取通栏版式列表
- */
- public function getSectorPlaceSort(array $data): array
- {
- $sector = SectorPlace::where('sector_type',$data['sector_type'])->first();
- if(empty($sector)){
- return Result::error('通栏版式不存在!');
- }
- $component = SectorPlace::where('type_id',2)->where('sector_type',$sector['sector_type'])->pluck('sort_id')->toArray();
- if(count($component) < $sector['component_num']){
- // 根据 $sector['component_num'] 的值生成对应元素数量的数组
- if (isset($sector['component_num']) && is_numeric($sector['component_num'])) {
- $num = intval($sector['component_num']);
- if ($num > 0 && $num <= 10) {
- // 使用 range 函数生成一个从 1 到 $num 的连续整数数组,存储到 $sector_arr 中
- $sector_arr = range(1, $num);
- } else {
- $sector_arr = [];
- }
- } else {
- $sector_arr = [];
- }
- // 获取 $sector_arr 中不在 $component 里的元素
- $sort = array_diff($sector_arr, $component);
- // return Result::success($sort);
- }
- if(!empty($sort)){
- $sort = array_values(array_map(function($value) {
- return ['id' => $value];
- }, $sort));
- }else{
- return Result::error("组件版式数量已达上限!");
- }
- return Result::success($sort);
- }
- /**
- * 获取所有通栏版式
- */
- public function getAllSectorPlace(array $data): array
- {
- $where['type_id'] = $data['type_id'];
- // if($data['type_id'] == 1){
- // $where['status'] = 1;
- // }
- $component_num = null;
- if (isset($data['sector_type']) && !empty($data['sector_type'])) {
- $where['sector_type'] = $data['sector_type'];
- }
- if(isset($data['component_num']) && !empty($data['component_num'])){
- $where['component_num'] = $data['component_num'];
- }
- $sector_place = SectorPlace::where($where)
- ->when($data['type_id'] == 2, function ($query) use ($data) {
- $query->orderBy('sort_id', 'asc');
- })
- ->when(isset($data['component_num']) && !empty($data['component_num']), function ($query) use ($data) {
- // 子查询:统计每个 sector_type 下 type_id=2 的子级数量
- $sub = SectorPlace::selectRaw('sector_type, COUNT(*) as child_count')
- ->where('type_id', 2)
- ->groupBy('sector_type');
- // 关联子查询,并保证子级数量等于传入的 component_num
- $query->leftJoinSub($sub, 'component_place', function ($join) {
- $join->on('sector_place.sector_type', '=', 'component_place.sector_type');
- })->whereRaw('component_place.child_count = ?', [$data['component_num']]);
- })
- ->get()->all();
- if($data['type_id'] == 2){
- foreach($sector_place as $key => $value){
- $sector_place[$key]['component'] = Component::where('type_id',$value['type'])
- ->where('component_width',$value['width'])
- ->where('component_height',$value['height'])
- ->get()->all();
- }
- }
- if(empty($sector_place)){
- return Result::error('通栏版式不存在!');
- }
- return Result::success($sector_place);
- }
- /**
- * 组件管理-获取组件类型
- */
- public function getComponentType(array $data): array
- {
- $where = [];
- if(isset($data['id']) && !empty($data['id'])){
- $where['id'] = $data['id'];
- }
- $component_type = ComponentType::where($where)->get()->all();
- if(empty($component_type)){
- return Result::error('组件类型不存在!');
- }
- if(count($component_type) == 1){
- $all_code = json_decode($component_type[0]['com_code'] ?? '',true);
- $component_type[0]['all_code'] = $all_code['listType'] ?? [];
- $result = $component_type[0];
- }else{
- $result = $component_type;
- }
- if(empty($component_type)){
- return Result::error('组件类型不存在!');
- }
- return Result::success($component_type);
- }
- /**
- * 组件管理-获取所有组件
- */
- public function getAllComponent(array $data): array
- {
- $where = [];
- if ((isset($data['sector_id']) && !empty($data['sector_id'])) || (isset($data['sort_id']) && !empty($data['sort_id']))) {
- $sector_id['sector.sector_id'] = $data['sector_id'];
- $sector['sector_component.sort_id'] = $data['sort_id'];
- $sectors = Sector::where($sector_id)
- ->where('sector.template_id', $data['template_id'])
- ->leftJoin('sector_component', 'sector.id', 'sector_component.sectorid')
- ->where($sector)
- ->select('sector.template_id', 'sector_component.component_id')
- ->get()->all();
- // return Result::success($sectors);
- $component_id = array_column($sectors, 'component_id');
- $template = ['template_id' => $sectors[0]['template_id']];
- $component = ComponentImg::whereIn('component_id', $component_id)
- ->where($template)
- ->select('img_id', 'img_name', 'img_url', 'template_id')
- ->orderBy('component_img.img_id', 'asc')
- ->get()->all();
- } else {
- if (isset($data['type_id']) && !empty($data['type_id'])) {
- $where['component.type_id'] = $data['type_id'];
- }
- if(isset($data['width']) && !empty($data['width'])){
- $where['component.component_width'] = $data['width'];
- }
- if(isset($data['height']) && !empty($data['height'])){
- $where['component.component_height'] = $data['height'];
- }
- $component = Component::where($where)
- ->leftJoin('component_img', 'component.component_id', '=', 'component_img.component_id')
- ->select('component.*', 'component_img.img_id', 'component_img.img_url', 'component_img.img_name')
- // ->orderBy('component_img.template_id')
- ->orderBy('component_img.img_id', 'asc')
- ->get()->all();
- }
- if(empty($component)){
- return Result::error('组件不存在!');
- }
- return Result::success($component);
- }
- /**
- * 自助建站-流程管理-获取所有通栏
- */
- public function getAllSector(array $data): array
- {
- $where = [];
- if (isset($data['template_id']) && !empty($data['template_id'])) {
- $where['sector.template_id'] = $data['template_id'];
- }
- if (isset($data['page_type']) && !empty($data['page_type'])) {
- array_push($where, ['sector.page_type', 'like', '%' . $data['page_type'] . '%']);
- }
- $sector = Sector::where($where)
- ->leftJoin('sector_component', 'sector.id', '=', 'sector_component.sectorid')
- ->leftJoin('component', 'sector_component.component_id', '=', 'component.component_type')
- ->when(isset($data['template_id']), function ($query) use ($data) {
- // 当 type_id 等于 11 时,关联查询 component_img 表并添加 img_url 字段
- return $query->leftJoin('component_img', function ($join) use ($data) {
- $join->on('component.component_type', '=', 'component_img.component_id')
- ->where('component_img.template_id', $data['template_id'])
- ->where('component.type_id', 11);
- });
- })
- ->select(
- 'sector.sector_name',
- 'sector.sector_id',
- 'component.*',
- 'component_img.img_url',
- 'sector.pic_height',
- 'sector.sector_img',
- 'sector_component.sort_id'
- )
- ->orderBy('sector_component.sort_id')
- ->orderBy('sector_component.sector_id')
- ->get()->all();
- if(empty($sector)){
- return Result::error('通栏不存在!');
- }
- $com_num = array_count_values(array_column($sector, 'sector_id'));
- // 使用 array_keys 和 array_diff 函数,不使用循环将值不为 1 的字段键提取到 $sectors_key 中
- $sectors_key = array_keys(array_diff($com_num, [1]));
- // return Result::success($sector);
- $num = 0;
- $array_key = 0;
- foreach ($sector as $key => $value) {
- $sector_id = $value['sector_id'];
- $sectors[$key] = $value['sector_id'];
- // if(isset($comlist_key) && !empty($comlist_key)){
- // $sector_arr_key[$key] = array_keys($comlist_key);
- // }
- if (in_array($sector_id, $sectors_key) && in_array($sector_id, $sectors)) {
- $array_key = array_search($sector_id, $sectors);
- if (isset($sectors) && !in_array($sector_id, $sectors)) {
- $array_key++;
- }
- $num++;
- $array_key++;
- } else {
- $array_key++;
- }
- // var_dump($array_key);
- // var_dump(in_array($sector_id,$sectors_key));
- $comlist_key[$array_key][$sector_id]['sectorName'] = $value['sector_name'];
- $comlist_key[$array_key][$sector_id]['sectorHeight'] = $value['pic_height'];
- $comlist_key[$array_key][$sector_id]['sectorImg'] = $value['sector_img'];
- $componentList['component_style'] = 1;
- $componentList['sort'] = $value['sort_id'];
- // 1:资讯;2:广告;3:静态;
- $component_data = empty($value['component_data']) ? null : (json_decode($value['component_data']) ?? []);
- // 检查 $value['component_column'] 是否为非空字符串,避免传递 null 给 json_decode
- $listType = empty($value['component_column']) ? null : (json_decode($value['component_column']) ?? []);;
- // $page[$key][$setor_id]['componentList'] =
- // 组件分类:1:资讯-头条组件;2:资讯-轮播组件;3:资讯-推荐图类组件;4:资讯-最新类组件;5:资讯-推荐类;6:资讯-热点类组件;7:资讯-栏目类组件;8:列表类组件;9:详情类组件;
- // 10:二级导航栏类组件;11:广告类;12:静态资源类;13:单页导航类;14:广告资讯混合类;15:滚动图文;16:搜索框类;17:单页列表类;18:单页详情类;
- if (in_array($value['type_id'], [1, 2, 3, 4, 5, 6, 7, 8, 9, 15, 17, 18])) {
- $type = 1;
- $componentList['component_type'] = $type;
- if (in_array($value['type_id'], [7, 15]) && $data['page_type'] == 1) {
- $component_data->componentData->name = '请选择导航..';
- } else if (in_array($value['type_id'], [7, 15]) && $data['page_type'] == 2) {
- $component_data->componentData->name = '自动生成';
- } else if ($data['page_type'] == 3) {
- if ($value['type_id'] == 4) {
- $component_data->componentData->name = '最新资讯';
- }
- if ($value['type_id'] == 6) {
- $component_data->componentData->name = '热点精选';
- }
- } else {
- unset($component_data->componentData->name);
- }
- $componentData = $component_data->componentData;
- $componentList['componentData'] = is_object($componentData) ? (array)$componentData ?? [] : $componentData ?? [];
- // $page_listType = is_object($listType) ? (array)$listType->listType ?? [] : $listType['listType'] ?? [];
- $componentList['componentData']['listType'] = $listType->listType;
- } else if (in_array($value['type_id'], [10, 12, 13, 16])) {
- $type = 3;
- $componentList['component_type'] = $type;
- $componentList['componentData'] = (object)[];
- } else if ($value['type_id'] == 11) {
- $type = 2;
- $componentList['component_type'] = $type;
- $componentList['componentData'] = (object)[];
- $ad = json_decode($value['ad']) ?? [];
- if (is_object($ad)) {
- $ad->thumb = $value['img_url'];
- } else {
- $ad['thumb'] = $value['img_url'];
- }
- $comlist_key[$array_key][$sector_id]['ad'] = is_object($ad) ? (array)$ad ?? [] : $ad ?? [];
- // 在 $page[$key][$setor_id] 中增加一个键值为 ad 的数组
- // $page[$key][$setor_id]['ad'] = is_object($ad) ? (array)$ad->ad ?? [] : $ad['ad'] ?? [];
- } else if ($value['type_id'] == 14) {
- $type = 1;
- $componentList['component_type'] = $type;
- if ($data['page_type'] == 1) {
- $component_data->componentData->name = '请选择导航..';
- }
- $componentData = $component_data->componentData;
- $componentList['componentData'] = is_object($componentData) ? (array)$componentData ?? [] : $componentData ?? [];
- $componentList['componentData']['listType'] = $listType->listType;
- $ad = json_decode($value['ad']) ?? [];
- $comlist_key[$array_key][$sector_id]['ad'] = is_object($ad) ? (array)$ad ?? [] : $ad ?? [];
- } else {
- }
- if (in_array($sector_id, $sectors_key)) {
- $comlist_key[$array_key][$sector_id]['componentList'][$num - 1] = $componentList;
- $comlist_key[$array_key][$sector_id]['componentList'] = array_values($comlist_key[$array_key][$sector_id]['componentList']);
- } else {
- $comlist_key[$array_key][$sector_id]['componentList'] = $componentList;
- }
- $keys[$key] = $key;
- }
- // return Result::success($sector_arr_key);
- // $page[$keys] = array_column($page,$sectors_key[0]);
- $comlist_key = array_values($comlist_key);
- // $sector_page = json_encode($comlist_key);
- if (empty($comlist_key)) {
- return Result::error('通栏不存在!');
- }
- return Result::success($comlist_key);
- // return Result::success(gettype($listType));
- }
- /**
- * 自助建站-组件管理-获取组件预览图列表
- */
- public function getComponentImgList(array $data): array
- {
- $where['component_img.component_id'] = $data['component_id'];
- if(isset($data['template_id']) && !empty($data['template_id'])){
- $where['component_img.template_id'] = $data['template_id'];
- }
- $component_img = ComponentImg::where($where)
- ->leftJoin('template', 'component_img.template_id', '=', 'template.template_id')
- ->leftJoin('component', 'component_img.component_id', '=', 'component.component_type')
- ->select('component_img.*', 'template.template_name', 'component.component_name')
- ->orderBy('component_img.template_id')
- ->orderBy('component_img.img_id')
- ->paginate($data['page_size'], ['*'], 'page', $data['page']);
- if($component_img->isEmpty()){
- return Result::error('组件预览图不存在!');
- }
- $component_img = [
- 'data' => $component_img->items(),
- 'total' => $component_img->total(),
- ];
- return Result::success($component_img);
- }
- /**
- * 自助建站-组件管理-添加组件预览图
- */
- public function addComponentImg(array $data): array
- {
- unset($data['user_id']);
- $component = Component::where('component_type',$data['component_id'])->first();
- if(empty($component)){
- return Result::error('组件不存在!');
- }
- if($component['type_id'] == 11){
- $img = ComponentImg::where('component_id',$data['component_id'])->where('template_id',$data['template_id'])->get()->all();
- if(!empty($img)){
- return Result::error('该组件已存在此皮肤的预览图!');
- }
- }
- $component = ComponentImg::where('template_id', $data['template_id'])->where('component_id', $data['component_id']);
- if (!empty($component->where('img_id', $data['img_id'])->first())) {
- return Result::error('组件预览图编号已存在!');
- }
- if(!empty($component->where('img_name', $data['img_name'])->first())){
- return Result::error('组件预览图名称已存在!');
- }
- $component_img = ComponentImg::insertGetId($data);
- if(empty($component_img)){
- return Result::error('添加失败!');
- }
- return Result::success($component_img);
- }
- /**
- * 自助建站-组件管理-删除组件预览图
- */
- public function delComponentImg(array $data): array
- {
- $component_img = ComponentImg::where('id', $data['id'])->delete();
- if (empty($component_img)) {
- return Result::error('删除失败!');
- }
- return Result::success($component_img);
- }
- /**
- * 自助建站-组件管理-更新组件预览图
- */
- public function updateComponentImg(array $data): array
- {
- $component = Component::where('component_type',$data['component_id'])->first();
- if(empty($component)){
- return Result::error('组件不存在!');
- }
- if($component['type_id'] == 11){
- $img = ComponentImg::where('id','!=',$data['id'])->where('component_id',$data['component_id'])->where('template_id',$data['template_id'])->get()->all();
- if(!empty($img)){
- return Result::error('该组件已存在此皮肤的预览图!');
- }
- }
- $component = ComponentImg::where('id', '!=', $data['id'])->where('component_id', $data['component_id'])->where('template_id', $data['template_id']);
- if (!empty($component->where('img_id', $data['img_id'])->first())) {
- return Result::error('组件预览图编号已存在!');
- }
- if(!empty($component->where('img_name', $data['img_name'])->first())){
- return Result::error('组件预览图名称已存在!');
- }
- // return Result::success($component);
- unset($data['user_id']);
- // unset($data['updated_at']);
- $id = $data['id'];
- unset($data['id']);
- // return Result::success($data);
- $component_img = ComponentImg::where('id',$id)->update($data);
- if(empty($component_img)){
- return Result::error('更新失败!');
- }
- return Result::success($component_img);
- }
- /**
- * 自助建站-获取通栏类型
- */
- public function getSectorType(array $data): array
- {
- $sector = SectorType::get()->all();
- if(empty($sector)){
- return Result::error('通栏类型不存在!');
- }
- return Result::success($sector);
- }
- /**
- * 自助建站-随机获取模板
- */
- public function randomWebTemplate(array $data): array
- {
- $web = Website::where('id',$data['website_id'])->first();
- if(empty($web)){
- return Result::error('此网站不存在!');
- }
- $template = Template:: where('template_id',$data['template_id'])->first();
- if(empty($template)){
- return Result::error('此皮肤不存在!');
- }
- $rule = TemplateRule::first();
- if(isset($data['page']) && !empty($data['page'])){
- switch ($data['page']) {
- case 1:
- $rule = json_decode($rule['index_rule']);
- break;
- case 2:
- $rule = json_decode($rule['class_rule']);
- break;
- case 3:
- $rule = json_decode($rule['list_rule']);
- break;
- case 4:
- $rule = json_decode($rule['info_rule']);
- break;
- case 5:
- $rule = json_decode($rule['search_rule']);
- break;
- case 6:
- $rule = json_decode($rule['footerlist_rule']);
- break;
- case 7:
- $rule = json_decode($rule['footerinfo_rule']);
- break;
- default:
- break;
- }
- }
- $query = WebsiteCategory::where('website_id', $data['website_id']);
- $cate_num = $query->where('is_show', 1)->count();
- if ($cate_num < 5) {
- return Result::error('此网站栏目过少,无法进行随机模板!');
- }
- $cate_num = min($cate_num, 24);
- // return Result::success($data);
- // $tempalte['index'] = $this->randomWeb($data,$index_rule);
- if(isset($data['page']) && !empty($data['page'])){
- $tempalte['index'] = $this->randomPage($data,$cate_num,$rule);
- }else{
- $data['page'] = 1;
- $ruleIndex = json_decode($rule->index_rule);
- $tempalte['index'] = $this->randomPage($data, $cate_num, $ruleIndex);
- $data['page'] = 2;
- $ruleClass = json_decode($rule->class_rule);
- // $class_cate_num = $query->where('pid','!=',0)->groupBy('pid')->selectRaw('pid, count(*) as count')->get()->pluck('count','pid');
- // $cate_num = max($class_cate_num);
- $tempalte['class'] = $this->randomPage($data, $cate_num, $ruleClass);
- $data['page'] = 3;
- $ruleList = json_decode($rule->list_rule);
- $tempalte['list'] = $this->randomPage($data,$cate_num,$ruleList);
- $data['page'] = 4;
- $ruleInfo = json_decode($rule->info_rule);
- $tempalte['info'] = $this->randomPage($data,$cate_num,$ruleInfo);
- $data['page'] = 5;
- $ruleSearch = json_decode($rule->search_rule);
- $tempalte['search'] = $this->randomPage($data,$cate_num,$ruleSearch);
- $data['page'] = 6;
- $ruleFooterlist = json_decode($rule->footerlist_rule);
- $tempalte['footerlist'] = $this->randomPage($data,$cate_num,$ruleFooterlist);
- $data['page'] = 7;
- $ruleFooterinfo = json_decode($rule->footerinfo_rule);
- $tempalte['footerinfo'] = $this->randomPage($data,$cate_num,$ruleFooterinfo);
- }
- // $index = $this->randomPage($data);
- return Result::success($tempalte);
- }
- public function randomPage($data, $cate_num, $rule)
- {
- // return $rule;
- $page = $data['page'];
- $sectors = Sector::where('sector.template_id', $data['template_id'])
- ->where('sector.page_type', 'like', '%' . $page . '%')
- ->leftJoin('sector_place', function ($join) {
- $join->on('sector.place_type', '=', 'sector_place.sector_type')
- ->where('sector_place.type_id', 1);
- })
- ->whereNotNull('sector_place.sector_type')
- ->select(
- 'sector.sector_name',
- 'sector.sector_id',
- 'sector.pic_height',
- 'sector.sector_img',
- 'sector.sector_type',
- 'sector.sector_code',
- 'sector.id',
- 'sector.sector_width',
- 'sector.component_num',
- 'sector.cat_num',
- )
- ->orderBy('id')
- ->get()->all();
- if (empty($sectors)) {
- return Result::error('通栏不存在!');
- }
- // return $sectors;
- // 获取每个类别的通栏数量
- // $type_num = array_count_values(array_column($sectors, 'sector_type'));
- // 此页面通栏的所有类别
- // $all_sector_types = array_keys($type_num);
- //获取每个通栏类别在其中的位置 -------暂时不考虑先,应该是必需通栏类型或者非必需通栏类型,每个类型应该取一个,其余取可重复的通栏
- $all_sector_type = array_column($sectors, 'sector_type');
- $grouped = array_reduce(
- array_keys($sectors),
- function ($carry, $idx) use ($sectors) {
- $carry[$sectors[$idx]['sector_type']][] = $idx;
- return $carry;
- },
- );
- // 对 all_sector_type 去重后,每个类型随机挑一个 sector 索引
- $unipue_sector_keys = array_combine(
- array_keys($grouped),
- array_map(
- function ($type) use ($grouped) {
- // 随机取一个索引
- return $grouped[$type][array_rand($grouped[$type])];
- },
- array_keys($grouped)
- )
- );
- // 1. 必需通栏:同一类型只随机保留一条
- $rule_must_type = $rule->must_type;
- $sector_num = $rule->max_num;
- $unique_sector_type = array_flip($unipue_sector_keys);
- $must_type = array_unique(array_intersect($unique_sector_type,$rule_must_type));
- // 先求交集,去重后统计
- $is_must = count($must_type);
- if ($is_must != count(array_unique($must_type))) {
- return '此页面缺少必要通栏!';
- }
- // 先按类型把 sectors 分组,key 为 sector_type,value 为对应 sector 数组
-
- // return [
- // 'unipue_sector_keys'=>$unipue_sector_keys,
- // 'grouped'=>$grouped,
- // ];
- // 最终保留的 must_type 数组(去重且随机保留一个)
- // return [
- // 'must_key'=>$must_key,'must_type'=>$must_type,
- // 'must_sector_keys'=>$must_sector_keys
- // ];
- // $must_sector_keys = array_intersect_key($unipue_sector_keys,$must_type);
- $must_sector = array_values(array_intersect_key($sectors,$must_type));
- $must_count = count($must_sector);
- // return $sector_comnum;
- // $must_sector = array_column($must_sector,'sector_type');
- // 目前按照首页必需通栏的数量进行处理,若是存在必需通栏的数量大于查询到的通栏数量,则返回必需通栏的数量
- if ($must_count > $sector_num) {
- return $must_sector;
- }
- // 必需通栏中的栏目数量
- if($page == 1){
- $must_cat_num = array_sum(array_column($must_sector,'cat_num'));
- if($must_cat_num>$cate_num){
- return '栏目数量过少,无法完成必需通栏随机!';
- }
- }
-
- // var_dump(['must_cat_num'=>$must_cat_num,'cate_num'=>$cate_num]);
- // 2.非必须通栏的随机处理
- $not_must_type = array_unique(array_diff($unique_sector_type, $must_type));
- $total = count($not_must_type);
- $randomCount = mt_rand(0, $total); // 可能为0(无元素)或任意数量,最多等于数组长度
- $and_type = $rule->and_type ?? [];
- // return $not_must_type;
- if ($randomCount === 0) {
- $random_sector = [];
- $rand_count = 0;
- } else {
- // 随机获取指定数量的键名(保留原键)
- $randomKeys = array_rand($not_must_type, $randomCount);
- // 处理单元素情况(array_rand返回字符串,需转为数组)
- if (!is_array($randomKeys)) {
- $randomKeys = [$randomKeys];
- }
- // 通栏关联性规则暂时无法实现---------------即若是随机了头条通栏必须要有轮播图通栏(皆为非必须通栏)
- // 假设 $oneDimensionalArray 是一维数组,$randomKeys 是随机数组
- // 判断 $oneDimensionalArray 是否为一维数组
- // if (isset($and_type) && is_array($and_type) && !array_is_list(array_filter($and_type, 'is_array'))) {
- // 判断是否存在有关联通栏的交集
- // if (isset($and_type) && !empty($and_type) && count(array_intersect($and_type, $randomKeys)) > 0) {
- // // var_dump("11111",$and_type);
- // // var_dump("22222",$randomKeys);
- // // 将一维数组中的值都放到随机数组中
- // $randomKeys = array_merge($randomKeys, $and_type);
- // }
- // var_dump(count(array_intersect($and_type, $randomKeys)));
- // }
- // -----------------------------
- // 根据随机键名提取元素(保留原键值关系)
- // $randomKeys = array_intersect($sector_type_keys,$randomKeys);
- // var_dump("randomKeys",$randomKeys);
- $random_sector = array_values(array_intersect_key($sectors, array_flip($randomKeys)));
- $rand_count = count($random_sector);
- }
- if($page == 1){
- $random_cat_num = array_sum(array_column($random_sector,'cat_num'));
- $random_cat_num += $must_cat_num;
- if($random_cat_num>$cate_num){
- return '栏目数量过少,无法完成随机!';
- }
- }
- // var_dump("randomKeys",$randomKeys);
- // var_dump("random_sector",$random_sector);
- // var_dump("rand_count", $rand_count);
- // var_dump("random_cat_num", $random_cat_num);
- // return $random_sector;
- // var_dump("must_sector",$must_sector);
- // var_dump("sector_num",$sector_num);
- // var_dump("must_count",$must_count);
- // return ['random_sector'=>$random_sector,'random_cat_num'=>$random_cat_num,'cate_num'=>$cate_num];
- // 3.计算随机之后减去必需的通栏,查询重复通栏可用数量;(目前的这些通栏没有重复的同类别通栏)
- $repeat_num = $sector_num - $rand_count - $must_count;
- // 组合起来通栏
- $sector_zuhe1 = array_merge($must_sector, $random_sector);
- $sector_zuhe1_type = array_column($sector_zuhe1, 'sector_type');
- $sector_ids = array_column($sector_zuhe1, 'id');
- if($repeat_num > 0){
- $rule_repeat = (array)$rule->type_max;
- $sector_zuhe1_type = array_count_values(array_column($sector_zuhe1,'sector_type'));
- // $sector_arr = array_intersect_key($rule_repeat,$sector_zuhe1_type);
- foreach ($rule_repeat as $key => $value) {
- if (in_array($key, array_keys($sector_zuhe1_type))) {
- $rule_repeat[$key] = $value - 1;
- }
- }
- // var_dump("repeat_num", $repeat_num);
- // 剩余通栏进行重复处理
- $rule_repeat = (array)$rule->type_max;
- // 取到可以重复的通栏类别
- $rule_repaet_type = array_keys($rule_repeat);
- $repeat_type = array_intersect($rule_repaet_type, $unique_sector_type);
- // 获取可以随机重复的通栏
- $repaet_key = 0;
- $type = [];
- // return $rule_repaet_type;
- // 防止无限循环,设置最大迭代次数
- $max_iterations = 10;
- $iteration_count = 0;
- // 剩余的栏目数量
- if($page == 1){
- $sector_cate_comnum = $cate_num - $random_cat_num;
- if($sector_cate_comnum < 0){
- return '栏目数量过少,无法完成随机!';
- }
- }
-
- // return [
- // // 'repeat_type'=>$repeat_type,
- // // 'repeat_num'=>$repeat_num,
- // 'must_count'=>$must_count,
- // 'rand_count'=>$rand_count,
- // 'repeat_num'=>$repeat_num,
- // 'sector_num'=>$sector_num,
- // 'cate_num'=>$cate_num,
- // 'sector_comnum'=>$sector_cate_comnum,
- // 'random_cat_num'=>$random_cat_num,
- // // 'rule_repeat'=>$rule_repeat,
- // // 'unique_sector_type'=>$unique_sector_type,
- // // 'all_sector_type'=>$all_sector_type,
- // // 'sector_zuhe1' =>$sector_zuhe1
- // ];
-
- // -----新添加的代码-----
- $re_sector = array_intersect($all_sector_type,$repeat_type);
- $re_sector_key = array_keys($re_sector);
- $every_repeattype_num = array_count_values($re_sector);
- // $re_sector_key = array_keys($re_sector,1);
- $repaet_key = 0;
- $re_type_keys = [];
- $one_sector_key = array_search(1,$re_sector);
- $two_sector_key = array_search(2,$re_sector);
- $three_sector_key = array_search(3,$re_sector);
- $all_cat_num = array_column($sectors,'cat_num');
- $repeat_sector_key = [];
- // $rule_repeat['1'] = 1;
- // return $rule_repeat;
- // $three_sector_key = array_search(3,$re_sector);
- // $min_one_sector = max(array_column('cat_num',$all_sector));
- // 随机重复通栏-----
- // $rule_repeat['1'] = 1;
- // // 找出 all_sector_type 中值为 1 的键
- while ($repaet_key <= $repeat_num-1 && $iteration_count < $max_iterations) {
- // 剩余通栏数量>0 若不是首页则继续;若是首页则需要判断剩余栏目数量是否>3
- if ($repeat_num-$repaet_key > 0 && ($page != 1 || (isset($sector_cate_comnum) && $sector_cate_comnum > 3))) {
- foreach($repeat_type as $key => $value){
- $type_key = strval($value);
- if(!isset($re_type_keys[$value])){
- $re_type_keys[$value] = [];
- }
- // 剩余的通栏数量>0 并且 剩余的此类通栏数量>0
- if($repeat_num-$repaet_key > 0 && $rule_repeat[$type_key]- count($re_type_keys[$value]) > 0 && ($page != 1 || (isset($sector_cate_comnum) && $sector_cate_comnum > 3))){
- // var_dump("0000",array_keys($re_sector,$value));
- $one_sector_type = array_keys($re_sector,$value);
- // 若是此类通栏的数量>1 则随机取一个对应的键值
- if(count($one_sector_type) > 1){
- // 从 $one_sector_type 数组中随机取一个键名,并取其对应值
- $cat_key = $one_sector_type[array_rand($one_sector_type)];
- }else{
- $cat_key = $one_sector_type[0];
- }
- $repeat_sector_key[$repaet_key] = $cat_key;
- $repaet_key++;
- // var_dump("1115----------cat_key",$cat_key);
- if($page == 1){
- $sector_cate_comnum -= $all_cat_num[$cat_key];
- }
- if(!in_array($repaet_key,$re_type_keys[$value])){
- $re_type_keys[$value][] = $repaet_key;
- // var_dump("1117----------re_type_keys",$re_type_keys);
- }
- }else{
- break;
- }
- }
- } else {
- break;
- }
- $iteration_count++;
- }
- // var_dump("num", $num);
- // var_dump("repeat_sector_key", $repeat_sector_key);
- // 若是首页的通栏没有到10个,栏目还有剩余1~3个,则继续随机(已知当剩余栏目为4还会随机)
- if($page == 1 && count($repeat_sector_key) < $repeat_num && $sector_cate_comnum > 0){
- if($sector_cate_comnum == 1){
- array_push($repeat_sector_key,$one_sector_key);
- }else if($sector_cate_comnum == 2){
- array_push($repeat_sector_key,$two_sector_key);
- }else{
- array_push($repeat_sector_key,$three_sector_key);
- }
- }
- // 随机的重复通栏键值转换成真正的通栏
- $repeat_sector = [];
- if (isset($repeat_sector_key) && !empty($repeat_sector_key) && is_array($repeat_sector_key)) {
- foreach ($repeat_sector_key as $key => $value) {
- if (isset($sectors[$value])) {
- $repeat_sector[$key] = $sectors[$value];
- }else{
- continue;
- }
- }
- }
- $repeat_count = count($repeat_sector);
- // var_dump("repeat_count", $repeat_count);
- // return [
- // 'not_repeat_num'=>$rand_count + $must_count,
- // // 'repeat_count'=>$repeat_count,
- // 'repeat_num'=>$repeat_num,
- // 'repeat_sector'=>$repeat_sector,
- // 'repeat_type'=>$repeat_type,
- // '$repaet_key'=>$repaet_key,
- // 'all_sector_type'=>$all_sector_type,
- // 're_sector'=>$re_sector,
- // 're_sector_key'=>$re_sector_key,
- // 'resdfddd'=>$every_repeattype_num,
- // 'repeat_sector_key'=>$repeat_sector_key,
- // // 'ddd'=>$ddd,
- // // 'sector_num'=>$sector_num,
- // // 'sector_zuhe1'=>count($sector_zuhe1),
- // // // 'repeat_sector'=>$repeat_sector,
- // // 'cate_num'=>$cate_num,
- // // 'random_cat_num'=>$random_cat_num,
- // 'rule_repeat' => $rule_repeat
- // ];
- // // var_dump("repeat_sector", $repeat_sector);
- // return $repeat_sector;
- $sector = array_merge($repeat_sector,$sector_zuhe1);
- }else{
- $sector = $sector_zuhe1;
- }
- // var_dump("sector_ids",$sector_ids);
- //
- // 各类型通栏最大数量数量限制 = 规则最大数量-已经存在的通栏数量(目前的通栏不会有重复的,所以只是-1)
- // var_dump("sector",$sector);
- // 处理头条及轮播图在随机通栏中的特殊位置特殊处理
- $sector_specal_sort = array_column($sector,'sector_type');
- if(in_array(6,$sector_specal_sort) || in_array(7,$sector_specal_sort) || in_array(5,$sector_specal_sort)){
- $toutiao_key = array_search(6,$sector_specal_sort) ?? null;
- $pic_key = array_search(7,$sector_specal_sort) ?? null;
- $cat_key = array_search(5,$sector_specal_sort) ?? null;
- $toutiao = $sector[$toutiao_key];
- $pic = $sector[$pic_key];
- $cat = $sector[$cat_key];
- $sort_1 = $sector[0];
- $sort_2 = $sector[1];
- $sort_3 = $sector[2];
- // return $sector_specal_sort;
- // return [
- // 'sector_ids' => array_column($sector_zuhe1,'id'),
- // // 'repeat_sector' => $repeat_sector,
- // 'sector_id' => array_column($sector,'id'),
- // 'array_intersect' => count(array_intersect($sector,$must_sector)),
- // 'old' => [ $toutiao_key,$pic_key,$cat_key],
- // 'new' => [ $sort_1,$sort_2,$sort_3]
- // ];
- if($data['page'] == 1 || $data['page'] == '1'){
- if($toutiao_key && $pic_key){
- $sector[0] = $toutiao;
- $sector[$toutiao_key] = $sort_1;
- $sector[1] = $pic;
- $sector[$pic_key] = $sort_2;
- }else if($pic_key){
- $sector[0] = $pic;
- $sector[$pic_key] = $sort_1;
- }else{
- $sector[0] = $toutiao;
- $sector[$toutiao_key] = $sort_1;
- }
- }
- if ($data['page'] == '2' || $data['page'] == 2 || in_array(5, $sector_specal_sort)) {
- $sector[0] = $cat;
- $sector[$cat_key] = $sort_1;
- if ($toutiao_key && $pic_key) {
- $sector[1] = $toutiao;
- $sector[$toutiao_key] = $sort_2;
- $sector[2] = $pic;
- $sector[$pic_key] = $sort_3;
- }else if ($pic_key) {
- $sector[1] = $pic;
- $sector[$pic_key] = $sort_2;
- }else if($toutiao_key){
- $sector[1] = $toutiao;
- $sector[$toutiao_key] = $sort_2;
- }
- }
-
- }
- $sector_id = array_column($sector,'id');
- // if(count(array_intersect($sector,$must_sector)) != count($must_sector)){
- // return '此页面缺少必要通栏!';
- // }
- // return Result::success([
- // // 'sector_id'=>$sector_id,
- // 'sector'=>$sector,
- // // 'cate_num'=>$cate_num,
- // ]);
- // $data['page'] = $page;
- $component[] = $this->randomComponent($sector_id,$data,$sector);
- var_dump("sector_id",$sector_id);
- return [
- // 'sector'=>$sector,
- // 'must_sector'=>$must_sector,
- // 'sector_count'=>count($sector),
- // 'sectors'=>$sectors,
- // 'sector_comnum'=>$sector_comnum,
- // 'com_num'=>$com_num,
- // 'cate_num'=>$cate_num,
- // '$sector_zuhe1_comnum'=>$sector_zuhe1_comnum+$com_num,
- 'component'=>$component,
- // 'sector'=>$sector,
- ];
- }
- public function randomComponent($sector_id, $data, $sector)
- {
- $rawResults = SectorComponent::whereIn('sector_component.sectorid', $sector_id)
- ->leftJoin('component', 'component.component_type', 'sector_component.component_id')
- ->leftJoin('component_img', function ($join) use ($data) {
- $join->on('component_img.component_id', '=', 'component.component_type')
- ->where('component_img.template_id', '=', $data['template_id'] ?? 0);
- })
- ->select(
- 'component.*',
- 'component_img.img_name',
- 'component_img.img_id',
- 'component_img.img_url',
- 'sector_component.sort_id',
- 'sector_component.sectorid'
- )
- ->orderBy('sector_component.sort_id')
- ->orderBy('component.component_type')
- ->get()->all();
- // return $rawResults;
- $img_key = 0;
- $com_key = 0;
- foreach( $rawResults as $key => $value){
- $component_id = $value['component_type'];
- $sort_id = $value['sort_id']-1;
- $img_id = intval($value['img_id']);
- $sector_id = $value['sectorid'];
- $component_data = json_decode($value['component_data'] ?? '[]',true);
- $component_column = json_decode($value['component_column'] ?? '[]',true);
- $component_json['componentData'] = $component_data['componentData'] ?? [];
- // 组件类型:1:头条;2:轮播图;3:推荐图;4:最新资讯;5:推荐资讯;6:热点资讯;7:栏目资讯类;
- // 8:列表类;9:详情类;10:二级导航栏类;11:广告类;12:静态类;13:单页导航类;14:资讯广告混合类;
- // 15:滚动图文类;16:搜索框类;17:单页列表类;18:单页详情类;19-24:选项卡3-7
- if(!in_array($value['type_id'],[10,11,12,16,])){
- $component_json['componentData']['listType'] = $component_column['listType'] ?? '';
- }
- if(!isset($component_img[$component_id])){
- $component_img[$component_id] = [];
- $com_key = 0;
- }else{
- $com_key++;
- }
- if(!isset($component_img[$component_id][$sort_id])){
- $component_img[$component_id][$sort_id] = [];
- $img_key = 0;
- }else{
- $img_key++;
- }
- if(!empty($img_id)){
- $component_img[$component_id][$sort_id][$img_key] =
- [
- 'component_id' => $value['component_type'],
- 'img_id' => $value['img_id'],
- 'component_imgurl' => $value['img_url'],
- ];
- }
- // else{
- // $component_img[$component_id][$sort_id][$img_key] = [];
- // }
- // $component_img = array_values($component_img[$component_id][$sort_id]);
- if(in_array($value['type_id'],[19, 20, 21, 22, 23, 24])){
- $groupedResults[$sector_id][$sort_id] =
- [
- 'component_type' => $component_id,
- 'sort' => $value['sort_id'],
- 'type_id' => $value['type_id'],
- 'componentData' => [
- $component_json['componentData'],
- $component_json['componentData'],
- ],
- 'images' => $component_img[$component_id][$sort_id]
- ];
- }else{
- $groupedResults[$sector_id][$sort_id] =
- [
- 'component_type' => $component_id,
- 'sort' => $value['sort_id'],
- 'type_id' => $value['type_id'],
- 'componentData' => $component_json['componentData'],
- 'images' => $component_img[$component_id][$sort_id]
- ];
- }
-
- if(in_array($value['type_id'],[11,14,24])){
- $groupedResults[$sector_id][$sort_id]['ad'] = json_decode($value['ad'],JSON_UNESCAPED_UNICODE);
- }
- // [$img_id-1] = $value['img_id'];
- }
- // return ['groupedResults'=>$groupedResults,
- // 'component_data'=>$component_data];
- $y_num = 0;
- foreach ($sector as $key => $value) {
- // array_push($value['sort_id'],$key);
- // $sector_id_ = $value['sector_id'];
- $sectorid = $value['id'];
- $template_data[$key] = [
- 'sectorName' => $value['sector_id'],
- 'sort' => $key + 1,
- ];
- $date = date('mdHisu'); // 获取时分秒微秒,转换为纯数字格式
- // $date = 11010630021;
- if (substr($date, 0, 1) == 0) {
- $date = substr($date, 0, 10); // 截取前9位
- } else {
- $date = substr($date, 0, 9); // 截取前9位
- }
- $random_num = intval(intval($date) . rand(1000, 9999)); // 拼接4位随机数,组成13位随机数
- $y_num = $y_num + $value['pic_height'];
- $sector_width = $value['sector_width'] / 100;
- $canvas_data[$key] = [
- 'i' => $random_num,
- 'x' => 0,
- 'y' => $y_num,
- 'w' => $sector_width,
- 'h' => $value['pic_height'],
- 'type' => $value['sector_id'],
- 'content' => [
- 'sectorName' => $value['sector_id'],
- ]
- ];
- // $sector_key[$key] = array_keys($value );
- $sector_component = [];
- if (isset($groupedResults[$sectorid]) && !empty($groupedResults[$sectorid]) && is_array($groupedResults[$sectorid])) {
- $componet_key = 0;
- foreach ($groupedResults[$sectorid] as $sortId => $components) {
- // // // // 通栏某一位置的随机组件
- // if (count($components) > 1) {
- // $componentIds = count($components);
- // $selectedComponentId = rand(0, $componentIds - 1);
- // } else {
- // $selectedComponentId = 0;
- // }
- // // var_dump($components[$selectedComponentId]);
- // $Component = $components;
- $Component['component_type'] = $components['component_type'] ?? 0;
- $Component['sort'] = $components['sort'] ?? 1;
- $Component['type_id'] = $components['type_id'] ?? 0;
- // // 通栏某一位置的随机组件样式图
- // // 检查 $Component['images'] 是否存在且为数组
- if (isset($components['images']) && is_array($components['images'])) {
- // var_dump('action1-------------------------------------sortId',$sortId);
- $images = count($components['images']);
- $selectedImage = 0;
- if ($images > 1) {
- $selectedImage = rand(0, $images - 1);
- }
- if (isset($components['images'][$selectedImage])) {
- $Component['component_style'] = is_object($components['images'][$selectedImage]) ? $components['images'][$selectedImage]->img_id : $components['images'][$selectedImage]['img_id'];
- }
- }
- if(isset($components['images'][$selectedImage])){
- $image_info[$key] = is_object($components['images'][$selectedImage]) ? $components['images'][$selectedImage] : $components['images'][$selectedImage];
- }
- // var_dump($images);
- // if(isset($components['type_id']) && in_array($components['type_id'], [19, 20, 21, 22, 23, 24])){
- // // $Component['componentData'][0] = $components['componentData'] ?? [];
- // // $Component['componentData'][1] = $components['componentData'] ?? [];
- // }else{
- $Component['componentData'] = $components['componentData'] ?? [];
- // }
- if ($data['page'] == 1 && (isset($components['type_id']) && in_array($components['type_id'], [7, 14, 15, 23, 24]))) {
- if(in_array($components['type_id'], [23, 24])){
- $Component['componentData'][0]['name'] = '请选择栏目';
- $Component['componentData'][1]['name'] = '请选择栏目';
- }else{
- $Component['componentData']['name'] = '请选择栏目';
- }
- }
- if ($data['page'] == 2 && (isset($components['type_id']) && in_array($components['type_id'], [7, 14, 15, 23, 24]))) {
- if(in_array($components['type_id'], [23, 24])){
- $Component['componentData'][0]['name'] = '自动生成';
- $Component['componentData'][1]['name'] = '自动生成';
- }else{
- $Component['componentData']['name'] = '自动生成';
- }
- }
- if (isset($components['type_id']) && $components['type_id'] == 11) {
- $ad = $components['ad'];
- $ad['thumb'] = $image_info[$key]['component_imgurl'] ?? '';
- $template_data[$key]['ad'] = $ad;
- $canvas_adinfo[$key] = $ad;
- $canvas_data[$key]['content']['ad'] = $canvas_adinfo[$key];
- // // 确保 $ad 和 $canvas_adinfo[$key] 元素数量一致,直接组合
- // $canvas_data[$key]['ad'] = array_combine($ad, $canvas_adinfo[$key]);
- $Component['componentData'] = [];
- }
- if (isset($components['type_id']) && $components['type_id'] == 14) {
- $ad = $components['ad'];
- $ad['thumb'] = $image_info[$key]['component_imgurl'] ?? '';
- $template_data[$key]['ad'] = $ad;
- $canvas_adinfo[$key] = $ad;
- $canvas_data[$key]['content']['ad'] = $canvas_adinfo[$key];
- // $canvas_data[$key]['ad'] = array_combine($ad, $canvas_adinfo[$key]);
- // // $Component['componentData'] = [];
- }
- if (isset($components['type_id']) && $components['type_id'] == 24) {
- $ad = $components['ad'][0];
- // $ad['thumb'] = $image_info[$key]['component_imgurl'] ?? '';
- $template_data[$key]['ad'][0] = $ad;
- $template_data[$key]['ad'][1] = $ad;
- $canvas_adinfo[$key] = $ad;
- $canvas_data[$key]['content']['ad'][0] = $canvas_adinfo[$key];
- $canvas_data[$key]['content']['ad'][1] = $canvas_adinfo[$key];
-
- // $canvas_data[$key]['ad'] = array_combine($ad, $canvas_adinfo[$key]);
- // // $Component['componentData'] = [];
- }
- // // var_dump('---------------------------',$components[$selectedComponentId]);
- $sector_component[$componet_key] = $Component;
- $componet_key++;
- }
- // var_dump("image",$image);
- }
- $template_data[$key]['componentList'] = $sector_component;
- $canvas_data[$key]['content']['componentList'] = $sector_component;
- // $canvas_data[$key]['ad'] = $key;
- $canvas_data[$key]['dataSort'] = $key;
- $canvas_data[$key]['moved'] = false;
- // $page['template'][$key][$sector_key]['componentData'] = $result[$sectorId];
- }
- // return $canvas_data;
- return [
- 'template_data' => $template_data,
- 'canvas_data' => $canvas_data,
- ];
- }
- // public function randomWeb($data,$index_rule)
- // {
- // // 在使用 with 方法关联查询其他表时限制查询字段,不需要修改 Sector 的 model 文件,
- // // 可以直接在查询时通过 select 方法指定要查询的字段。以下是修改后的代码:
- // $component_img = Sector::select('sector.id', 'sector.template_id', 'sector.page_type','sector.sector_id','sector.component_num'
- // ,'sector.sector_name','sector.sector_type')
- // ->where('sector.template_id', $data['template_id'])
- // ->where('sector.page_type', 'like', '%' . $data['page'] . '%')
- // ->with([
- // 'sectorComponents' => function ($query) use ($data) {
- // $query->select('sectorid', 'sort_id', 'component_id')
- // ->with([
- // 'component' => function ($q) use ($data) {
- // $q->select('id', 'component_type', 'component_data', 'component_code', 'component_column', 'ad','type_id')
- // ->with([
- // 'componentImgs' => function ($subQ) use ($data) {
- // $subQ
- // ->where('template_id', $data['template_id'])
- // // ->select('id', 'img_id', 'img_name', 'img_url', 'template_id')
- // ;
- // }
- // ]);
- // }
- // ]);
- // }
- // ])
- // ->get()
- // ->all();
- // // 通栏类别:1:资讯类:2:广告类;3:混合类;4:搜索框类;5:导航类;6:头条类;
- // // 7:轮播图类;8:静态资源类;9:单页(列表)类;10:单页(详情)类;11:列表类;12:详情类;13:栏目轮播图类;',
- // // {"max_num": 10, "min_num": 6, "and_type": [6, 7],
- // // "type_max": {"1": 20, "2": 4, "3": 3}, "must_type": [1, 2]}
- // $rule = is_array($index_rule) ? $index_rule : (array)$index_rule;
- // // return gettype($rule);
- // $must_num = count($rule['must_type']);
- // $sector_type = array_column($component_img,'sector_type');
- // $notmust_sectortype = count(array_diff(array_unique(array_column($component_img,'sector_type')),$rule['must_type']));
- // $notmust_num = random_int(0,$notmust_sectortype);
- // $min_num = $notmust_sectortype+$must_num;
- // $max_num = $rule['max_num'];
- // $index_num = random_int($min_num, $max_num);
- // $repeat_num = $index_num - $must_num - $notmust_num;
- // $category_num = WebsiteCategory::where('website_id',$data['website_id'])
- // ->where('is_show',1)
- // ->get()
- // ->all();
- // $num = 0;
- // $sector_ids = [];
- // $sector_sortids = [];
- // foreach($components as $key => $value){
- // if(!in_array($value['sectorid'],$sector_ids)){
- // $num = 0;
- // }
- // if($value['type_id'] == 7 && !in_array($value['sort_id'],$sector_sortids[$value['sectorid']])){
- // $num++;
- // }
- // $sector_typenum[$value['sectorid']]['num'] = $num;
- // $sector_typenum[$value['sectorid']][$value['sort_id']] = $num;
- // $sector_ids[$key] = $value['sectorid'];
- // $sector_sortids[$value['sectorid']][$key] = $value['sort_id'];
- // // }
- // foreach($sector_type as $key => $value){
- // if($value == 1){
- // $sector_type[$key] = 1;
- // }
- // }
- // return [
- // 'index_num' => $index_num,
- // 'min_num' => $min_num,
- // '$sector_type' => $sector_type,
- // 'notmust_sectortype' => $notmust_sectortype,
- // 'must_num' => $must_num,
- // 'notmust_num' => $notmust_num,
- // 'repeat_num' => $repeat_num,
- // // '$sector_typenum' => $sector_typenum,
- // ];
- // return $component_img;
- // }
- /**
- * 自助建站-获取所有通栏、组件、组件样式
- */
- public function getAllSectorComponentStyle(array $data): array
- {
- $sector_component_style = Sector::where('sector.template_id',$data['template_id'])
- ->leftJoin('sector_component','sector.id','sector_component.sectorid')
- ->leftJoin('component', 'component.component_type', 'sector_component.component_id')
- ->leftJoin('component_img', 'component_img.component_id', 'component.component_type')
- // ->leftJoin('sector', 'sector.id', 'sector_component.sectorid')
- ->where('component_img.template_id', '=', $data['template_id'])
- ->select(
- 'sector.sector_id',
- 'sector.sector_keyword',
- 'sector.component_num',
- 'sector.sector_width',
- 'sector.sector_height',
- 'sector.pic_height',
- 'component.component_type',
- 'component.component_keyword',
- 'component.component_data',
- 'component.component_column',
- 'component.ad',
- 'component.type_id',
- 'component_img.img_name',
- 'component_img.img_id',
- 'component_img.img_url',
- 'sector_component.sort_id',
- 'sector_component.sectorid',
- )
- ->orderBy('sector_component.sort_id')
- ->orderBy('component.component_type')
- ->get()->all();
- $groupedResults = [];
- $sort_ids = [];
- $sector_ids = [];
- $component_list = [];
- $component_ids = [];
- $img_ids = [];
- // return Result::success($sector_component_style);
- foreach ($sector_component_style as $key => $item) {
- $sectorId = $item->sectorid;
- $sortId = $item->sort_id;
- $sector_type = $item->sector_type;
- $component_num = $item->component_num;
- $componentId = $item->component_type;
- $component_data = $item->component_data;
- $component_column = $item->component_column;
- $component_keyword = $item->component_keyword;
- $component_type = $item->type_id;
- $component_ad = $item->ad;
- $imgId = $item->img_id;
- $sector_height = $item->sector_height;
- $pic_height = $item->pic_height;
- $sectorName = $item->sector_id;
- if (!isset($groupedResults[$sectorId])) {
- $groupedResults[$sectorId] = [];
- }
- $componentData = !empty($component_data) && is_string($component_data) ? json_decode($component_data, true) : [];
- $component_listtype = !empty($component_column) && is_string($component_column) ? json_decode($component_column, true) : [];
- $component_code = !empty($component_code) && is_string($component_code) ? json_decode($component_code, true) : [];
- $component_ad = !empty($component_ad) && is_string($component_ad) ? json_decode($component_ad, true) : [];
- // 确保 $componentData['componentData'] 是数组,避免 array_push 传入 null
- if (!isset($componentData['componentData']) || !is_array($componentData['componentData'])) {
- $componentData['componentData'] = [];
- }
- $componentData['componentData'] += $component_listtype;
- $component_code = $componentData;
- $component_list[$key] = $component_code;
- // $component_list[$key]['listType'] = $component_listtype;
- // }
- if(!in_array($sectorId,$sector_ids)){
- $groupedResults[$sectorId] = [
- 'sector_id' => $sectorName,
- 'sector_keyword' => $item->sector_keyword,
- 'component_num' => $component_num,
- 'sector_width' => $item->sector_width,
- 'sector_height' => $sector_height,
- 'pic_height' => $pic_height,
- ];
- }
- $sort_id = intval($sortId - 1);
- if (!isset($com_key) || !in_array($sectorId, $sector_ids) || !isset($sort_ids[$sectorId]) || !in_array($sortId, $sort_ids[$sectorId])) {
- $com_key = 0;
- $img_key = 0;
- } else if (in_array($sortId, $sort_ids[$sectorId]) && in_array($sectorId, $sector_ids) && !in_array($componentId, $component_ids)) {
- $com_key++;
- }
- if (in_array($componentId, $component_ids) && !in_array($imgId, $img_ids[$componentId])) {
- $img_key++;
- } else {
- $img_key = 0;
- }
- if (!in_array($componentId, $component_ids)) {
- $groupedResults[$sectorId]['component_list'][$sort_id][$com_key] = [
- 'component_type' => $item->component_type,
- 'type_id' => $component_type,
- 'sort' => $sortId,
- ];
- }
- if($component_type == 11){
- $groupedResults[$sectorId]['component_list'][$sort_id][$com_key]['component_style_data'][$img_key] = [
- 'img_name' => $item->img_name,
- 'img_id' => $imgId,
- 'img_url' => $item->img_url,
- ];
- }else{
- $groupedResults[$sectorId]['component_list'][$sort_id][$com_key]['component_style_data'][$img_key] = [
- 'img_name' => $item->img_name,
- 'img_id' => $imgId,
- ];
- }
- $com_key = 0;
- // }
- // 组件分类:1.头条资讯;2.轮播图资讯;3.推荐图;4.最新资讯;5.推荐资讯;6.热点资讯;7.栏目资讯;8.列表类;9.详情类;
- // 10.二级导航类;11.广告类;12.静态类;13.单页导航类;14.资讯广告混合类;15.滚动图文类;16.搜索框类;17.单页列表类;18.单页详情类;
- // 19:选项卡-推荐图类;20:选项卡-最新资讯类;21:选项卡-推荐资讯类;22:选项卡-热点资讯类;23:选项卡-栏目资讯类;24:选项卡-栏目广告混合类;
- if (is_scalar($sectorId) && is_scalar($sort_id)) {
- if (!in_array($component_type, [10, 12, 16])) {
- if ($component_type == 11 || $component_type == 14 || $component_type == 24) {
- $groupedResults[(int)$sectorId]['component_list'][(int)$sort_id][$com_key]['ad'] = $component_ad;
- $groupedResults[(int)$sectorId]['component_list'][(int)$sort_id][$com_key]['ad']['website_id'] = $data['website_id'];
- }
- if ($component_type != 11) {
- $groupedResults[(int)$sectorId]['component_list'][(int)$sort_id][$com_key]['componentData'] = $component_code['componentData'];
- }
- } else {
- $groupedResults[(int)$sectorId]['component_list'][(int)$sort_id][$com_key]['componentData'] = [];
- }
- } else {
- // 处理非法键类型的情况,可根据实际需求修改错误处理逻辑
- trigger_error('Illegal offset type for $sectorId or $sort_id', E_USER_WARNING);
- }
- // // 判断此组件是否存在数组中的依据(若是有重复的组件,一定是组件样式重复)
- $component_ids[$key] = $componentId;
- if (!isset($sort_ids[$sectorId])) {
- $sort_ids[$sectorId] = [];
- }
- if (!in_array($sortId, $sort_ids[$sectorId])) {
- $sort_ids[$sectorId][] = $sortId;
- }
- if (!isset($img_ids[$componentId])) {
- $img_ids[$componentId] = [];
- }
- if (!in_array($imgId, $img_ids[$componentId])) {
- $img_ids[$componentId][] = $imgId;
- }
- $sector_ids[$key] = $sectorId;
- $sort_ids[$sectorId][$sort_id] = $sort_id;
- // $img_ids[$componentId] = $imgId;
- }
- // return Result::success($groupedResults);
- if (empty($groupedResults)) {
- return Result::error('通栏组件样式不存在!');
- }
- $groupedResults = array_values($groupedResults);
- return Result::success($groupedResults);
- }
- /**
- * 自助建站-ai会话-获取会话列表
- */
- public function getAiSessionList(array $data): array
- {
- $where['user_id'] = $data['user_id'];
- if(isset($data['website_id']) && !empty($data['website_id'])){
- $where['website_id'] = $data['website_id'];
- }
- if(isset($data['template_id']) && !empty($data['template_id'])){
- $where['template_id'] = $data['template_id'];
- }
- $result = AichatSession::where($where)->get()->all();
- if(empty($result)){
- return Result::error('会话不存在!');
- }
- return Result::success($result);
- }
- /**
- * 自助建站-ai会话-创建会话
- */
- public function addAiSession(array $data): array
- {
- $website = Website::where('id',$data['website_id'])->first();
- if(empty($website)){
- return Result::error('网站不存在!');
- }
- $template = Template::where('template_id',$data['template_id'])->first();
- if(empty($template)){
- return Result::error('皮肤不存在!');
- }
- $date = date('Hisms');
- // $date = 1631191019
- $rand_num = rand(1000,9999);
- $data['session_id'] = $date.$rand_num;
- // $data['session_id'] = 16320610069512
- $ai_sessions = AichatSession::where('user_id',$data['user_id'])->pluck('session_id')->all();
- if(!empty($data['session_id']) && in_array($data['session_id'],$ai_sessions)){
- $rand_num = rand(1000,9999);
- $data['session_id'] = $date.$rand_num;
- }
- $result = AichatSession::insert($data);
- if(empty($result)){
- return Result::error('创建会话失败!');
- }
- return Result::success($result);
- }
- /**
- * 自助建站-ai会话-修改会话
- */
- public function upAiSession(array $data): array
- {
- $where['user_id'] = $data['user_id'];
- $where['session_id'] = $data['session_id'];
- // return Result::success($where);
- $aichat_session = AichatSession::where($where)->first();
- if(empty($aichat_session)){
- return Result::error('会话不存在!');
- }
- unset($data['session_id']);
- // 会话状态:1-开启,0-关闭
- if(isset($data['is_active']) && $aichat_session['is_active'] == $data['is_active']){
- return Result::success('会话状态已为'.$data['is_active'].'!');
- }
- if(isset($data['is_active']) && ($data['is_active'] == 0 || $data['is_active'] == '0')){
- $data['end_time'] = date('Y-m-d H:i:s');
- }
- $result = AichatSession::where($where)->update($data);
- if(empty($result)){
- return Result::error('修改会话失败!');
- }
- return Result::success($result);
- }
- /**
- * 自助建站-ai会话-删除会话
- */
- public function delAiSession(array $data): array
- {
- $where['user_id'] = $data['user_id'];
- $where['session_id'] = $data['session_id'];
- // 删除会话
- Db::beginTransaction();
- try{
- $result['ai_chat_session'] = AichatSession::where($where)->delete();
- if(empty($result['ai_chat_session'])){
- Db::rollBack();
- return Result::error('删除会话消息失败!');
- }
- // 删除会话消息
- $aichat = Aichat::where($where)->get()->all();
- if(!empty($aichat)){
- $result['ai_chat_message'] = Aichat::where($where)->delete();
- if(empty($result['ai_chat_message'])){
- Db::rollBack();
- return Result::error('删除会话消息失败!');
- }
- }
- // 删除草稿模板
- $template_draftbox = TemplateDraftbox::where($where)->get()->all();
- if(!empty($template_draftbox)){
- $result['template_draftbox'] = TemplateDraftbox::where($where)->delete();
- if(empty($result['template_draftbox'])){
- Db::rollBack();
- return Result::error('删除草稿模板失败!');
- }
- }
- Db::commit();
- return Result::success($result);
- }catch(\Exception $e){
- Db::rollBack();
- return Result::error($e->getMessage());
- }
- }
- /**
- * 自助建站-ai会话-发送消息
- */
- public function sendAiMessage(array $data): array
- {
- $where['user_id'] = $data['user_id'];
- $where['session_id'] = $data['session_id'];
- $where['is_active'] = 1;
- $aichat_session = AichatSession::where($where)->first();
- if(empty($aichat_session)){
- return Result::error('会话不存在!');
- }
- $data['message_type'] = empty($data['message_type']) ? 'text' : $data['message_type'];
- $result = Aichat::insertGetId($data);
- if(empty($result)){
- return Result::error('发送消息失败!');
- }
- return Result::success($result);
- }
- /**
- * 自助建站-ai会话-获取消息列表
- */
- public function getAiMessageList(array $data): array
- {
- $where['user_id'] = $data['user_id'];
- $where['session_id'] = $data['session_id'];
- $where['is_active'] = 1;
- $session = AichatSession::where($where)->first();
- if(empty($session)){
- return Result::error('会话不存在!');
- }
- $aichat = Aichat::where('user_id',$data['user_id'])
- ->where('session_id',$data['session_id'])
- ->orderBy('send_time','desc')
- ->get()->all();
- if(empty($aichat)){
- return Result::error('消息不存在!');
- }
- return Result::success($aichat);
- }
- /**
- * 自助建站-ai会话-添加模板草稿
- */
- public function addTemplateDraftbox(array $data): array
- {
- $where['session_id'] = $data['session_id'];
- $where['user_id'] = $data['user_id'];
- // 后续若是用来对应会话记录,则此项需要修改
- $session = AichatSession::where($where)->first();
- if(empty($session)){
- return Result::error('会话不存在!');
- }
- $data['website_id'] = $session['website_id'];
- $data['template_id'] = $session['template_id'];
- $template_draftbox = TemplateDraftbox::where($where)->first();
- if(!empty($template_draftbox)){
- return Result::error('草稿模板已存在!');
- }
- $result = TemplateDraftbox::insert($data);
- if(empty($result)){
- return Result::error('添加草稿模板失败!');
- }
- return Result::success($result);
- }
- /**
- * 自助建站-ai会话-修改模板草稿
- */
- public function upTemplateDraftbox(array $data): array
- {
- $where['session_id'] = $data['session_id'];
- $where['user_id'] = $data['user_id'];
- $session = AichatSession::where($where)->first();
- if(empty($session)){
- return Result::error('会话不存在!');
- }
- if(isset($data['chat_id']) && !empty($data['chat_id'])){
- $chat = Aichat::where($where)->where('chat_id',$data['chat_id'])->first();
- if(empty($chat)){
- return Result::error('消息不存在!');
- }
- }
- // 后续若是用来对应会话记录,则此项需要修改
- $template_draftbox = TemplateDraftbox::where($where)->first();
- if(empty($template_draftbox)){
- return Result::error('草稿模板不存在!');
- }
- unset($data['session_id']);
- $result = TemplateDraftbox::where($where)->update($data);
- if(empty($result)){
- return Result::error('修改草稿模板失败!');
- }
- return Result::success($result);
- }
- /**
- * 自助建站-ai会话-获取模板草稿列表
- */
- public function getTemplateDraftboxList(array $data): array
- {
- $where['session_id'] = $data['session_id'];
- $where['user_id'] = $data['user_id'];
- if(isset($data['website_id']) && !empty($data['website_id'])){
- $where['website_id'] = $data['website_id'];
- }
- if(isset($data['template_id']) && !empty($data['template_id'])){
- $where['template_id'] = $data['template_id'];
- }
- if(isset($data['status'])){
- $where['status'] = $data['status'];
- }
- if(isset($data['chat_id']) && !empty($data['chat_id'])){
- $where['chat_id'] = $data['chat_id'];
- }
- $template_draftbox = TemplateDraftbox::where($where)->get()->all();
- if(empty($template_draftbox)){
- return Result::error('草稿模板不存在!');
- }
- return Result::success($template_draftbox);
- }
- /**
- * 自助建站-验证关键词填写重复问题
- */
- public function checkRepeatKeyword(array $data): array
- {
- if(empty($data['keyword']) || $data['keyword'] == '' || $data['keyword'] == '[]'){
- return Result::success('关键词为空');
- }
- $arr_keyword = json_decode(stripslashes($data['keyword']), true) ?: [];
- if(is_array($arr_keyword) && count($arr_keyword) > 0){
- $keyword = array_map('trim', $arr_keyword);
- if(count($keyword) != count(array_unique($keyword))){
- return Result::error('关键词不能重复!');
- }
- }
- $where['id'] = $data['id'] ?? null;
- if($data['type'] == 'style'){
- $type = '风格';
- $all_keywords = TemplateClass::when(!empty($where),function($query)use($where){
- $query->where('id','!=',$where['id']);
- })->pluck('keyword')->toArray();
-
- }
- if($data['type'] == 'skin'){
- $type = '皮肤';
- $all_keywords = Template::when(!empty($where),function($query)use($where){
- $query->where('id','!=',$where['id']);
- })->pluck('template_keyword')->toArray();
- }
- if($data['type'] == 'sector'){
- $type = '通栏';
- $all_keywords = Sector::when(!empty($where),function($query)use($where){
- $query->where('id','!=',$where['id']);
- })->where('template_id',$data['template_id'])->pluck('sector_keyword')->toArray();
- }
- if($data['type'] == 'component'){
- $type = '组件';
- $all_keywords = Component::when(!empty($where),function($query)use($where){
- $query->where('id','!=',$where['id']);
- })->pluck('component_keyword')->toArray();
- }
- foreach($all_keywords as $key => $value){
- $value_keyword = json_decode($value ?? '[]',true);
- if(is_array($value_keyword) && count($value_keyword) > 0){
- $repeat_keywords = array_intersect($arr_keyword,$value_keyword);
- if(count($repeat_keywords) == count($keyword) && count($repeat_keywords) == count($value_keyword)){
- return Result::error('此'.$type.'关键词已存在!');
- }
- }
- }
- return Result::success(['验证通过']);
- }
- /**
- * 自助建站-验证网站模板相关类型
- * 版本1----在构建网站首页之后使用
- */
- public function checkWebTemplate(array $data): array
- {
- // 网站id (是否存在该网站)
- // (若是只传这个字段会判断是否关联导航池;)
- // (再判断是否有三种类型的友情链接)
- // (头部信息是否填写)
- // (两种类型的底部导航)
- $website = Website::where('id',$data['website_id'])->first();
- if(empty($website)){
- return Result::error('网站不存在!');
- }
- $template_data = json_decode($data['template_data'],true);
- if(empty($template_data)){
- return Result::error('模板数据不能为空!');
- }
- return Result::success($template_data);
- if(!isset($template_data['website_id']) || empty($template_data['website_id'])){
- return Result::error('网站ID不能为空!');
- }
- if(!isset($template_data['template_id']) || empty($template_data['template_id'])){
- return Result::error('模板ID不能为空!');
- }
- return Result::success($template_data);
- }
- public function getAITemplate(array $data): array
- {
- $result['template'] = Template::select('id','template_id','template_name','template_keyword','page_type',
- 'template_class_id','template_img','updated_at')
- ->get()->all();
- if (empty($result)) {
- return Result::error("暂无皮肤", 0);
- }
- // $num = 1;
- // 确保 $result 是数组且包含数据
- if (!is_array($result) || empty($result)) {
- return Result::error('模板数据异常');
- }
- // 初始化最新更新时间
- $latestUpdate = null;
- foreach ($result['template'] as $key => $value) {
- $templateImg = json_decode($value['template_img'], true);
- $result['template'][$key]['template_img'] = $templateImg;
- // 更新最新时间:取最大的 updated_at
- if ($latestUpdate === null || $value['updated_at'] > $latestUpdate) {
- $latestUpdate = $value['updated_at'];
- }
- // unset($result[$key]['updated_at']);
- }
- // 将最新时间放入返回结果,若无数据则返回当前时间
- $result['update_time'] = date('Y-m-d H:i:s', strtotime($latestUpdate));
- return Result::success($result);
- }
- }
|