WebsiteService.php 137 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478
  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Model\Article;
  4. use App\Model\Ad;
  5. use App\Model\Category;
  6. use App\Model\AdPlace;
  7. use App\Model\Department;
  8. use App\Model\District;
  9. use App\Model\FooterCategory;
  10. use App\Model\FooterContent;
  11. use App\Model\WebsiteTemplateInfo;
  12. use App\Model\Link;
  13. use App\Model\LetterOfComplaint;
  14. use App\Model\TemplateClass;
  15. use App\Model\Template;
  16. use App\Model\User;
  17. use App\Model\UserInfo;
  18. use App\Model\WebsiteRole;
  19. use App\Model\WebsiteRoleUser;
  20. use App\Model\Website;
  21. use App\Model\WebsiteColumn;
  22. use App\Model\Good;
  23. use App\Model\Book;
  24. use App\Model\ChatRecords;
  25. use App\Model\ChatTopic;
  26. use App\Model\JobRecruiting;
  27. use App\Model\JobHunting;
  28. use App\Model\Notice;
  29. use App\Model\Complaint;
  30. use App\Model\Order;
  31. use App\Model\WebsiteImg;
  32. use App\Model\Company;
  33. use App\Model\Project;
  34. use App\Model\ChatTopicsReply;
  35. use Hyperf\HttpServer\Contract\RequestInterface;
  36. use Hyperf\DbConnection\Db;
  37. use Hyperf\RpcServer\Annotation\RpcService;
  38. use App\Tools\Result;
  39. use Carbon\Carbon;
  40. use App\Model\WebsiteCategory;
  41. use App\Model\WebsiteGroup;
  42. use App\Model\WebsiteTemplate;
  43. use App\Model\Sector;
  44. use PhpParser\Node\Stmt\Return_;
  45. use SimpleKafkaClient\Metadata\Topic;
  46. use function PHPUnit\Framework\isNull;
  47. use Overtrue\Pinyin\Pinyin;
  48. use App\Tools\buildTree;
  49. use App\Model\WhiteRouter;
  50. use App\Model\Size;
  51. use App\Tools\PinyinHelper;
  52. use Hyperf\HttpServer\Annotation\AutoController;
  53. use Hyperf\Utils\Parallel;
  54. use Hyperf\Coroutine\Concurrent;
  55. use function Hyperf\Coroutine\batch;
  56. use Swoole\Coroutine;
  57. use Fukuball\Jieba\Jieba;
  58. use Fukuball\Jieba\Finalseg;
  59. #[RpcService(name: "WebsiteService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  60. class WebsiteService implements WebsiteServiceInterface
  61. {
  62. /**
  63. * 获取网站列表
  64. * @param string $keyword
  65. * @param int $page
  66. * @param int $pageSize
  67. * @return array
  68. */
  69. public function getWebsitetList(array $data): array
  70. {
  71. // 构建查询
  72. $query = Website::when($data, function ($query) use ($data) {
  73. if (isset($data['keyword']) && !empty($data['keyword'])) {
  74. $query->where('website.website_name', 'like', '%' . trim($data['keyword']) . '%');
  75. }
  76. if (isset($data['website_column_id']) && !empty($data['website_column_id'])) {
  77. $query->whereJsonContains("website.website_column_arr_id", intval($data['website_column_id']));
  78. }
  79. if (isset($data['web_type']) && !empty($data['web_type'])) {
  80. $query->where('website.web_type', intval($data['web_type']));
  81. }
  82. if (isset($data['is_core']) && !empty($data['is_core'])) {
  83. $query->where('website.is_core', intval($data['is_core']));
  84. }
  85. });
  86. $column_name = WebsiteColumn::pluck('column_name', 'id')->all();
  87. $queryWithJoins = $query->leftJoin("website_column", "website.website_column_id", "website_column.id");
  88. $count = $queryWithJoins->count();
  89. $result = $queryWithJoins->select("website.*", "website_column.column_name")
  90. ->limit($data['pageSize'])
  91. ->offset(($data['page'] - 1) * $data['pageSize'])
  92. ->orderBy("website.updated_at", "desc")
  93. ->get()
  94. ->all();
  95. foreach ($result as $key => $value) {
  96. $column_arr = json_decode($value['website_column_arr_id']);
  97. $result[$key]['website_url'] = json_decode($value['website_url']);
  98. $result[$key]['website_column_arr_id'] = $column_arr;
  99. $result[$key]['city_arr_id'] = json_decode($value['city_arr_id'] ?? '[]', true);
  100. if(count($column_arr) > 1){
  101. $result[$key]['column_name'] = implode('/', array_intersect_key($column_name, array_flip($column_arr)));
  102. }
  103. }
  104. if (empty($result)) {
  105. return Result::error("没有数据", 0);
  106. }
  107. $data = [
  108. 'rows' => $result,
  109. 'count' => $count,
  110. ];
  111. return Result::success($data);
  112. }
  113. /**
  114. * @param array $data
  115. */
  116. public function createWebsite(array $data): array
  117. {
  118. var_dump("网站数据:", $data);
  119. // $wzbs = $this->getWebsitetAdkey($data);
  120. // return Result::success($wzbs);
  121. $web = Website::where('ad_key', $data['ad_key'])->first();
  122. if (!empty($web)) {
  123. return Result::error("网站名称简写重复,请填写", 0);
  124. }
  125. $insertData = [
  126. 'website_name' => $data['website_name'],
  127. 'logo' => $data['logo'] ?? '',
  128. 'website_url' => $data['website_url'] ?? '',
  129. //'city_id'=>$data['city_id']??0,
  130. 'website_column_id' => $data['website_column_id'],
  131. 'title' => $data['title'] ?? '',
  132. 'keywords' => $data['keywords'] ?? '',
  133. 'description' => $data['description'] ?? '',
  134. 'status' => $data['status'] ?? 1,
  135. 'website_column_arr_id' => $data['website_column_arr_id'],
  136. //'city_arr_id'=>$data['city_arr_id']??[0],
  137. 'template_id' => $data['template_id'] ?? 0,
  138. 'suffix' => $data['suffix'] ?? "",
  139. 'ad_key' => $data['ad_key'] ?? "",
  140. 'index_img' => $data['index_img'] ?? '',
  141. 'qr_code' => $data['qr_code'] ?? '',
  142. 'web_type' => $data['web_type'] ?? 0,
  143. 'is_core' => $data['is_core'] ?? 0,
  144. ];
  145. $result = Website::insertGetId($insertData);
  146. if (empty($result)) {
  147. return Result::error("创建网站失败", 0);
  148. } else {
  149. return Result::success(["id" => $result]);
  150. }
  151. }
  152. /**
  153. * 修改网站头部基础信息
  154. * @param array $data
  155. */
  156. public function updateWebsite(int $id, array $data): array
  157. {
  158. $website = Website::where('id', $id)->first();
  159. if (empty($website)) {
  160. return Result::error("网站不存在", 0);
  161. }
  162. $insertData = [
  163. 'website_name' => $data['website_name'],
  164. 'logo' => $data['logo'] ?? '',
  165. 'website_url' => $data['website_url'] ?? '',
  166. // 'city_id'=>$data['city_id']??0,
  167. 'website_column_id' => $data['website_column_id'],
  168. 'title' => $data['title'] ?? '',
  169. 'keywords' => $data['keywords'] ?? '',
  170. 'description' => $data['description'] ?? '',
  171. // 'status' => $data['status'] ?? 0,
  172. 'website_column_arr_id' => $data['website_column_arr_id'],
  173. // 'city_arr_id'=>$data['city_arr_id']??[0],
  174. 'template_id' => $data['template_id'] ?? 0,
  175. 'suffix' => $data['suffix'] ?? "",
  176. 'ad_key' => $data['ad_key'] ?? "",
  177. 'index_img' => $data['index_img'] ?? '',
  178. 'qr_code' => $data['qr_code'] ?? '',
  179. 'web_type' => $data['web_type'] ?? 0,
  180. 'is_core' => $data['is_core'] ?? 0,
  181. ];
  182. // $web_templsate = WebsiteTemplateInfo::where('website_id', $data['id'])->first();
  183. // `status` tinyint(1) DEFAULT '0' COMMENT '0:未构建 1:未应用 2:已应用',
  184. // if (!empty($web_templsate) && $web_templsate['status'] == 2) {
  185. // return Result::error("此网站已应用,不可修改基本信息", 0);
  186. // }
  187. Db::beginTransaction();
  188. try {
  189. if ($data['ad_key'] != $website['ad_key']) {
  190. $web = Website::where(function ($query) use ($data) {
  191. $query->where('id', '!=', $data['id'])
  192. ->where('ad_key', $data['ad_key']);
  193. })->first();
  194. if (!empty($web)) {
  195. Db::rollBack();
  196. return Result::error("网站名称简写重复,请填写", 0);
  197. }
  198. $ad_place = AdPlace::where('website_id', $data['id'])->select('ad_tag', 'id')->get()->toArray();
  199. if (!empty($ad_place)) {
  200. foreach ($ad_place as $key => $val) {
  201. $ad_keys = explode('_', $val['ad_tag']);
  202. $ad_keys[0] = $data['ad_key'];
  203. $ad_place[$key]['ad_tag'] = implode('_', $ad_keys);
  204. // $up_adtags = AdPlace::where('id', $val['id'])->update(['ad_tag' => $ad_tags[$key]]);
  205. }
  206. $up_adtags = AdPlace::upsert($ad_place, ['id'], ['ad_tag']);
  207. if (empty($up_adtags)) {
  208. Db::rollBack();
  209. return Result::error('广告位标识同步失败', 0);
  210. }
  211. }
  212. $template = WebsiteTemplate::where('website_id', $data['id'])->first();
  213. if (!empty($template)) {
  214. // Eloquent 没有 replace 方法,推测你可能是想替换模板中的字符串,假设是更新 content 字段
  215. $uptemplate = WebsiteTemplate::where('website_id', $data['id'])->update([
  216. 'template_data' => DB::raw("REPLACE(template_data, '{$website['ad_key']}', '{$data['ad_key']}')")
  217. ]);
  218. if (empty($uptemplate)) {
  219. Db::rollBack();
  220. return Result::error("更新模板失败!", 0);
  221. }
  222. }
  223. }
  224. // return Result::success($UP_template);
  225. $result = Website::where('id', $data['id'])->update($insertData);
  226. if (empty($result)) {
  227. Db::rollBack();
  228. return Result::error("更新网站失败!", 0);
  229. }
  230. Db::commit();
  231. return Result::success("更新成功");
  232. } catch (\Exception $e) {
  233. Db::rollBack();
  234. return Result::error($e->getMessage(), 0);
  235. }
  236. }
  237. /**
  238. * @param int $id
  239. * @return array
  240. */
  241. public function delWebsite(int $id): array
  242. {
  243. $result = Website::where('id', $id)->delete();
  244. if (empty($result)) {
  245. return Result::error("删除失败", 0);
  246. } else {
  247. return Result::success();
  248. }
  249. }
  250. /**
  251. * @param int $id
  252. * @return array
  253. */
  254. public function getWebsiteInfo(int $id): array
  255. {
  256. $where = [
  257. ['website.id', '=', $id],
  258. ];
  259. $result = Website::where($where)
  260. ->leftJoin("template", "template.id", "website.template_id")
  261. ->select("website.*", "template.template_name", "template.template_img")
  262. ->first();
  263. if (empty($result)) {
  264. return Result::error("数据不存在", 0);
  265. } else {
  266. return Result::success($result->toArray());
  267. }
  268. }
  269. /**
  270. * 查询所有的站点栏目
  271. * @return array
  272. */
  273. public function getWebsiteColumn(array $data): array
  274. {
  275. $result = WebsiteColumn::where($data)->get();
  276. if (empty($result)) {
  277. return Result::error("数据不存在", 0);
  278. } else {
  279. return Result::success($result->toArray());
  280. }
  281. }
  282. /**
  283. * @param string $keyword
  284. * @param int $page
  285. * @param int $pageSize
  286. * @return array
  287. */
  288. public function getWebsiteColumnList(array $data): array
  289. {
  290. $where = [];
  291. if (isset($data['keyword']) && $data['keyword']) {
  292. array_push($where, ['website_column.column_name', 'like', '%' . $data['keyword'] . '%']);
  293. }
  294. $result = WebsiteColumn::where($where)
  295. ->leftJoin("website_column as wc", "website_column.pid", "wc.id")
  296. ->select("website_column.*", "wc.column_name as parent_column_name")
  297. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->get();
  298. $count = WebsiteColumn::where($where)->count();
  299. if (empty($result)) {
  300. return Result::error("没有数据", 0);
  301. }
  302. $data = [
  303. 'rows' => $result->toArray(),
  304. 'count' => $count,
  305. ];
  306. return Result::success($data);
  307. }
  308. /**
  309. * @param array $data
  310. * @return array
  311. */
  312. public function createWebsiteColumn(array $data): array
  313. {
  314. $insertData = [
  315. 'column_name' => $data['column_name'],
  316. 'pid' => $data['pid'] ?? '',
  317. 'column_arr_id' => $data['column_arr_id'] ?? [0],
  318. 'sort' => $data['sort'] ?? 0,
  319. 'remark' => $data['remark'] ?? '',
  320. ];
  321. $result = WebsiteColumn::insertGetId($insertData);
  322. if (empty($result)) {
  323. return Result::error("创建失败", 0);
  324. } else {
  325. return Result::success(["id" => $result]);
  326. }
  327. }
  328. /**
  329. * @param int $id
  330. * @param array $data
  331. * @return array
  332. */
  333. public function updateWebsiteColumn(int $id, array $data): array
  334. {
  335. $insertData = [
  336. 'column_name' => $data['column_name'],
  337. 'pid' => $data['pid'] ?? '',
  338. 'column_arr_id' => $data['column_arr_id'] ?? [0],
  339. 'sort' => $data['sort'] ?? 0,
  340. 'remark' => $data['remark'] ?? '',
  341. ];
  342. $result = WebsiteColumn::where('id', $id)->update($insertData);
  343. if (empty($result)) {
  344. return Result::error("更新失败", 0);
  345. } else {
  346. return Result::success();
  347. }
  348. }
  349. /**
  350. * @param int $id
  351. * @return array
  352. */
  353. public function delWebsiteColumn(int $id): array
  354. {
  355. $list = WebsiteColumn::where(['pid' => $id])->get();
  356. if ($list) {
  357. return Result::error("存在子网系,不能删除,请先删除子网系", 0);
  358. }
  359. $result = WebsiteColumn::where('id', $id)->delete();
  360. if (empty($result)) {
  361. return Result::error("删除失败", 0);
  362. } else {
  363. return Result::success();
  364. }
  365. }
  366. /**
  367. * @param string $keyword
  368. * @param int $page
  369. * @param int $pageSize
  370. * @return array
  371. */
  372. public function getWebsiteRoleList(string $keyword, int $page, int $pageSize, int $websiteId): array
  373. {
  374. $where = [
  375. ['role.role_name', 'like', '%' . $keyword . '%'],
  376. ['website_role.website_id', '=', $websiteId],
  377. ];
  378. $result = WebsiteRole::where($where)
  379. ->leftJoin("role", "role.id", "website_role.role_id")
  380. ->select("role.*", "website_role.type", "website_role.role_id", "website_role.id as website_role_id", "website_role.website_id")
  381. ->limit($pageSize)->offset(($page - 1) * $pageSize)->get();
  382. $count = WebsiteRole::where($where)->leftJoin("role", "role.id", "website_role.role_id")->count();
  383. if (empty($result)) {
  384. return Result::error("没有数据", 0);
  385. }
  386. $data = [
  387. 'rows' => $result->toArray(),
  388. 'count' => $count,
  389. ];
  390. return Result::success($data);
  391. }
  392. /**
  393. * @param array $data
  394. * @return array
  395. */
  396. public function createWebsiteRole(array $data): array
  397. {
  398. $insertData = [
  399. 'website_id' => $data['website_id'],
  400. 'role_id' => $data['role_id'] ?? '',
  401. ];
  402. $info = WebsiteRole::where($insertData)->first();
  403. if ($info) {
  404. return Result::error("不能重复添加角色", 0);
  405. }
  406. $insertData['admin_user_id'] = $data['admin_user_id'] ?? '';
  407. $insertData['type'] = $data['type'] ?? '';
  408. $result = WebsiteRole::insertGetId($insertData);
  409. if (empty($result)) {
  410. return Result::error("创建失败", 0);
  411. } else {
  412. return Result::success(["id" => $result]);
  413. }
  414. }
  415. /**
  416. * 暂时用不上
  417. * @param int $id
  418. * @param array $data
  419. * @return array
  420. */
  421. public function updateWebsiteRole(int $id, array $data): array
  422. {
  423. $insertData = [
  424. 'website_id' => $data['website_id'],
  425. 'type' => $data['type'] ?? '',
  426. ];
  427. $result = WebsiteRole::where('id', $id)->update($insertData);
  428. if (empty($result)) {
  429. return Result::error("更新失败", 0);
  430. } else {
  431. return Result::success();
  432. }
  433. }
  434. /**
  435. * @param int $id
  436. * @return array
  437. */
  438. public function delWebsiteRole(int $id): array
  439. {
  440. $result = WebsiteRole::where('id', $id)->delete();
  441. if (empty($result)) {
  442. return Result::error("删除失败", 0);
  443. } else {
  444. return Result::success();
  445. }
  446. }
  447. /**
  448. * @param string $keyword
  449. * @param int $page
  450. * @param int $pageSize
  451. * @return array
  452. */
  453. public function getWebsiteRoleUserList(string $keyword, int $page, int $pageSize, int $websiteId, int $roleId): array
  454. {
  455. $where = [
  456. ['website_role_user.website_id', '=', $websiteId],
  457. ['website_role_user.role_id', '=', $roleId],
  458. ];
  459. $count = WebsiteRoleUser::where($where)->count();
  460. $where[] = ['u.user_name', 'like', '%' . $keyword . '%'];
  461. $result = WebsiteRoleUser::where($where)
  462. ->leftJoin("user as u", "website_role_user.user_id", "u.id")
  463. ->leftJoin("website as w", "website_role_user.website_id", "u.id")
  464. ->leftJoin("role as r", "website_role_user.role_id", "r.id")
  465. ->select("u.*", "u.user_name", 'w.website_name', 'r.role_name', 'website_role_user.id as website_role_user_id', 'website_role_user.updated_at as user_update_at')
  466. ->limit($pageSize)->offset(($page - 1) * $pageSize)->get();
  467. if (empty($result)) {
  468. return Result::error("没有数据", 0);
  469. }
  470. $data = [
  471. 'rows' => $result->toArray(),
  472. 'count' => $count,
  473. ];
  474. return Result::success($data);
  475. }
  476. /**
  477. * @param array $data
  478. * @return array
  479. */
  480. public function createWebsiteRoleUser(array $data): array
  481. {
  482. $insertData = [
  483. 'website_id' => $data['website_id'],
  484. 'user_id' => $data['user_id'] ?? '',
  485. ];
  486. $info = WebsiteRoleUser::where($insertData)->first();
  487. if ($info) {
  488. return Result::error("不能重复添加角色用户", 0);
  489. }
  490. $insertData['role_id'] = $data['role_id'] ?? '';
  491. $insertData['admin_user_id'] = $data['admin_user_id'] ?? '';
  492. $insertData['type'] = $data['type'] ?? '';
  493. $result = WebsiteRoleUser::insertGetId($insertData);
  494. if (empty($result)) {
  495. return Result::error("创建失败", 0);
  496. } else {
  497. return Result::success(["id" => $result]);
  498. }
  499. }
  500. /**
  501. * @param int $id
  502. * @param array $data
  503. * @return array
  504. */
  505. public function updateWebsiteRoleUser(int $id, array $data): array
  506. {
  507. $insertData = [
  508. 'website_id' => $data['website_id'],
  509. 'type' => $data['type'] ?? '',
  510. 'type_id' => $data['type_id'] ?? '',
  511. 'role_id' => $data['role_id'] ?? '',
  512. ];
  513. $result = WebsiteRoleUser::where('id', $id)->update($insertData);
  514. if (empty($result)) {
  515. return Result::error("更新失败", 0);
  516. } else {
  517. return Result::success();
  518. }
  519. }
  520. /**
  521. * @param int $id
  522. * @return array
  523. */
  524. public function delWebsiteRoleUser(int $id): array
  525. {
  526. $result = WebsiteRoleUser::where('id', $id)->delete();
  527. if (empty($result)) {
  528. return Result::error("删除失败", 0);
  529. } else {
  530. return Result::success();
  531. }
  532. }
  533. /**
  534. * 根据域名获取网站 站点id
  535. * @param array $data
  536. * @return array
  537. */
  538. public function getWebsiteId(array $data): array
  539. {
  540. $result = Website::whereJsonContains('website_url', $data['website_url'])->first();
  541. if (empty($result)) {
  542. return Result::error("查询站点失败", 0);
  543. } else {
  544. return Result::success($result);
  545. }
  546. }
  547. /**
  548. *各省市查询
  549. * @param array $data
  550. * @return array
  551. */
  552. public function selectWebsiteArea()
  553. {
  554. // return Result::success($data);
  555. $pid = $data['pid'] ?? 0;
  556. $result = District::leftJoin('district as district2', 'district.pid', '=', 'district2.id')
  557. ->where('district.pid', $pid)
  558. ->where('district.status', 1)
  559. ->select('district.*', 'district2.name as pid_name')
  560. ->orderBy('district.code')->get();
  561. if (empty($result)) {
  562. return Result::error("未查询到此地区", 0);
  563. } else {
  564. return Result::success($result);
  565. }
  566. }
  567. /**
  568. * 获取友情链接
  569. * @param array $data
  570. * @return array
  571. */
  572. public function selectWebsiteLinks(array $data): array
  573. {
  574. $where = [
  575. 'website_id' => $data['website_id'],
  576. 'status' => 1,
  577. 'type' => $data['type'],
  578. ];
  579. $num = $data['num'];
  580. $result = Link::where($where)->orderBy('sort')->limit($num)->get();
  581. if (!empty($result)) {
  582. return Result::success($result);
  583. } else {
  584. return Result::error("本网站暂无此类型友情链接", 0);
  585. }
  586. }
  587. /**
  588. *
  589. * @param array $data
  590. * @return array
  591. */
  592. /**网站行政职能搜索 */
  593. public function selectWebsiteDepartment(array $data): array
  594. {
  595. $depart = Department::where('pid', 0)->orderBy('id', 'asc')->get();
  596. if (isset($data['keyword']) && !empty($data['keyword'])) {
  597. $departments = Department::where('name', 'like', '%' . $data['keyword'] . '%')->get();
  598. if (empty($departments)) {
  599. $result['message'] = "未查询到与此相关职能部门";
  600. } else {
  601. $count = Department::where('name', 'like', "%{$data['keyword']}%")->count();
  602. $m = [
  603. 'department' => $depart,
  604. 'type' => $departments,
  605. 'count' => $count,
  606. ];
  607. }
  608. $result['sele'] = $m;
  609. return Result::success($result['sele']);
  610. }
  611. $result = $depart;
  612. return Result::success($result);
  613. }
  614. /**
  615. * 网站首页数据统计, 管理员
  616. * @return void
  617. */
  618. public function getAdminIndex(array $data): array
  619. {
  620. var_dump("用户类型:", $data);
  621. switch ($data['type_id']) {
  622. case 10000:
  623. $res = [];
  624. //网站
  625. $res['website']['count'] = 0;
  626. $res['website']['growth_rate'] = 0;
  627. //资讯
  628. $res['article']['count'] = 0;
  629. $res['article']['growth_rate'] = 0;
  630. //导航池
  631. $res['category']['count'] = 0;
  632. $res['category']['growth_rate'] = 0;
  633. //商品
  634. $res['good']['count'] = 0;
  635. $res['book']['count'] = 0;
  636. $res['jobHunting']['count'] = 0;
  637. $res['jobRecruiting']['count'] = 0;
  638. //近一月数据
  639. $res['monthArticle'] = [];
  640. //用户类型
  641. $res['userType'] = [];
  642. $res['website']['count'] = Website::where([])->count();
  643. $res['article']['count'] = Article::whereIn('status', [1])->count();
  644. $res['category']['count'] = Category::where([])->count();
  645. $res['good']['count'] = Good::whereIn('status', [2])->count();
  646. $res['book']['count'] = Book::whereIn('status', [2])->count();
  647. $res['jobHunting']['count'] = JobHunting::whereIn('status', [2])->count();
  648. $res['jobRecruiting']['count'] = JobRecruiting::whereIn('status', [1])->count();
  649. $res['complaint']['count'] = Complaint::whereIn('status', [2])->count();
  650. $res['notice']['count'] = Notice::whereIn('status', [2])->count();
  651. //已审核数量
  652. $res['company']['count'] = Company::whereIn('status', [1])->count();
  653. $res['project']['count'] = Project::whereIn('status', [1])->count();
  654. // $res['monthArticle'] = Db::select('SELECT DATE(created_at) AS date,COUNT(*) AS total_count FROM article WHERE created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(created_at) ORDER BY date ASC;');
  655. $res['monthArticle'] = Db::select(' SELECT DATE(article.created_at) AS date,COUNT(*) AS count ,user.type_id FROM article left JOIN user on article.admin_user_id = user.id WHERE
  656. article.status =1 and article.created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(article.created_at),`user`.type_id ORDER BY date ASC');
  657. $res['monthGood'] = Db::select(' SELECT DATE(good.created_at) AS date,COUNT(*) AS count ,user.type_id FROM good left JOIN user on good.user_id = user.id WHERE
  658. good.status =2 and good.created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(good.created_at),`user`.type_id ORDER BY date ASC');
  659. $res['monthBook'] = Db::select(' SELECT DATE(book.created_at) AS date,COUNT(*) AS count ,user.type_id FROM book left JOIN user on book.user_id = user.id WHERE book.status =2 and book.created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(book.created_at),`user`.type_id ORDER BY date ASC');
  660. $res['monthJobHunting'] = Db::select(' SELECT DATE(job_hunting.created_at) AS date,COUNT(*) AS count ,user.type_id FROM job_hunting left JOIN user on job_hunting.user_id = user.id WHERE job_hunting.status =2 and job_hunting.created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(job_hunting.created_at),`user`.type_id ORDER BY date ASC');
  661. $res['monthJobRecruiting'] = Db::select(' SELECT DATE(job_recruiting.created_at) AS date,COUNT(*) AS count ,user.type_id FROM job_recruiting left JOIN user on job_recruiting.user_id = user.id WHERE job_recruiting.status =1 and job_recruiting.created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(job_recruiting.created_at),`user`.type_id ORDER BY date ASC');
  662. //company project 1 已审核
  663. $res['monthCompany'] = Db::select(' SELECT DATE(company.created_at) AS date,COUNT(*) AS count ,user.type_id FROM company left JOIN user on company.user_id = user.id WHERE company.status =1 and company.created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(company.created_at),`user`.type_id ORDER BY date ASC');
  664. $res['monthProject'] = Db::select(' SELECT DATE(project.created_at) AS date,COUNT(*) AS count ,user.type_id FROM project left JOIN user on project.user_id = user.id WHERE project.status =1 and project.created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(project.created_at),`user`.type_id ORDER BY date ASC');
  665. $res['userType'] = User::where([])->selectRaw("count(*) as counts,type_id")->groupBy('type_id')->get();
  666. //待审核数据
  667. $res['apply']['article'] = Article::where(['status' => 0])->count(); //
  668. $res['apply']['good'] = Good::where(['status' => 1])->count();
  669. $res['apply']['book'] = Book::where(['status' => 1])->count();
  670. $res['apply']['jobHunting'] = JobHunting::where(['status' => 1])->count();
  671. $res['apply']['jobRecruiting'] = JobRecruiting::where(['status' => 0])->count();
  672. $res['apply']['complaint'] = Complaint::where(['status' => 1])->count();
  673. $res['apply']['notice'] = Notice::where(['status' => 1])->count(); //订单状态:1:通过;2:驳回;3:撤回;4:修改;5:过期;6:待审核;7:结束',
  674. $res['apply']['order'] = Order::where(['status' => 6])->count();
  675. $res['apply']['company'] = Company::where(['status' => 0])->count();
  676. $res['apply']['project'] = Project::where(['status' => 0])->count();
  677. return Result::success($res);
  678. case 1:
  679. case 2:
  680. case 3:
  681. case 4:
  682. $res = [];
  683. if ($data['type_id'] == 4) {
  684. $result = Db::select('SELECT DATE(created_at) AS date,COUNT(*) AS total_count FROM letter_of_complaint WHERE created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(created_at) ORDER BY date ASC;');
  685. $res = [];
  686. //查询已审核文章
  687. $user_id = $data['user_id'];
  688. $article = Article::where('status', 1)
  689. ->where('admin_user_id', $user_id)
  690. ->orderBy('updated_at', 'desc')
  691. ->limit(10)
  692. ->get();
  693. $res['letterOfComplaintList'] = $result;
  694. $res['article'] = $article;
  695. }
  696. //查询已审核文章
  697. $user_id = $data['user_id'];
  698. $now = Carbon::now();
  699. // 系统提醒审核消息
  700. $sys_msg = [];
  701. $article = Article::where('status', 0)
  702. ->where('admin_user_id', $user_id)
  703. ->orderBy('updated_at', 'desc')
  704. ->limit(5)
  705. ->get(['id', 'title', 'updated_at'])
  706. ->map(function ($item) use ($now) {
  707. $item->class = '资讯';
  708. $item->formatted_updated_at = $this->timeAgo($item->updated_at, $now);
  709. return $item;
  710. });
  711. var_dump($article, '---1--');
  712. $good = Good::where('status', 1)
  713. ->where('user_id', $user_id)
  714. ->orderBy('updated_at', 'desc')
  715. ->get(['id', 'name as title', 'updated_at'])
  716. ->map(function ($item) use ($now) {
  717. //去掉name的属性
  718. $item->class = '商品';
  719. $item->formatted_updated_at = $this->timeAgo($item->updated_at, $now);
  720. return $item;
  721. });
  722. $book = Book::query()
  723. ->where('status', 1)
  724. ->where('user_id', $user_id)
  725. ->orderBy('updated_at', 'desc')
  726. ->get(['id', 'title', 'updated_at'])
  727. ->map(function ($item) use ($now) {
  728. //去掉name的属性
  729. $item->class = '书刊';
  730. $item->formatted_updated_at = $this->timeAgo($item->updated_at, $now);
  731. return $item;
  732. });
  733. //招聘 求职
  734. $jobhunting = JobHunting::query()
  735. ->where('status', 1)
  736. ->where('user_id', $user_id)
  737. ->orderBy('updated_at', 'desc')
  738. ->get(['id', 'name as title', 'updated_at'])
  739. ->map(function ($item) use ($now) {
  740. //去掉name的属性
  741. $item->class = '求职';
  742. $item->formatted_updated_at = $this->timeAgo($item->updated_at, $now);
  743. return $item;
  744. });
  745. $jobrecruiting = JobRecruiting::query()
  746. ->where('status', 0)
  747. ->where('user_id', $user_id)
  748. ->orderBy('updated_at', 'desc')
  749. ->get(['id', 'title', 'updated_at'])
  750. ->map(function ($item) use ($now) {
  751. //去掉name的属性
  752. $item->class = '招聘';
  753. $item->formatted_updated_at = $this->timeAgo($item->updated_at, $now);
  754. return $item;
  755. });
  756. //通知 投诉
  757. $notice = Notice::query()
  758. ->where('status', 1)
  759. ->where('user_id', $user_id)
  760. ->orderBy('updated_at', 'desc')
  761. ->get(['id', 'title', 'updated_at'])
  762. ->map(function ($item) use ($now) {
  763. //去掉name的属性
  764. $item->class = $item->type == 1 ? "通知" : "公告";
  765. $item->formatted_updated_at = $this->timeAgo($item->updated_at, $now);
  766. return $item;
  767. });
  768. $complaint = Complaint::query()
  769. ->where('status', 1)
  770. ->where('user_id', $user_id)
  771. ->orderBy('updated_at', 'desc')
  772. ->get(['id', 'title', 'updated_at'])
  773. ->map(function ($item) use ($now) {
  774. //去掉name的属性
  775. $item->class = "投诉";
  776. $item->formatted_updated_at = $this->timeAgo($item->updated_at, $now);
  777. return $item;
  778. });
  779. //项目 公司 待审核 :0:未审核;1:已审核;2:已拒绝
  780. $project = Project::query()
  781. ->where('status', 0)
  782. ->where('user_id', $user_id)
  783. ->orderBy('updated_at', 'desc')
  784. ->get(['id', 'title', 'updated_at'])
  785. ->map(function ($item) use ($now) {
  786. //去掉name的属性
  787. $item->class = "项目";
  788. $item->formatted_updated_at = $this->timeAgo($item->updated_at, $now);
  789. return $item;
  790. });
  791. $company = Company::query()
  792. ->where('status', 0)
  793. ->where('user_id', $user_id)
  794. ->orderBy('updated_at', 'desc')
  795. ->get(['id', 'title', 'updated_at'])
  796. ->map(function ($item) use ($now) {
  797. //去掉name的属性
  798. $item->class = "公司";
  799. $item->formatted_updated_at = $this->timeAgo($item->updated_at, $now);
  800. return $item;
  801. });
  802. // var_dump($jobrecruiting, '-1--------------------11111111111111--');
  803. // var_dump($good, '-3--');
  804. // $s = $article->toArray();
  805. // var_dump($s, '=====31111111111111111');
  806. // 合并两个集合
  807. // 合并两个集合,并按 updated_at 倒序排序
  808. // $combined = $article->merge($good)->sortByDesc('updated_at');
  809. $combined = $article
  810. ->concat($good)
  811. ->concat($book)
  812. ->concat($jobhunting)
  813. ->concat($jobrecruiting)
  814. ->concat($notice)
  815. ->concat($complaint)
  816. ->concat($project)
  817. ->concat($company)
  818. ->sortByDesc(function ($item) {
  819. return Carbon::createFromFormat('Y-m-d H:i:s', $item->updated_at);
  820. });
  821. // ->sortBy('updated_at');
  822. // var_dump($combined, '--4--');
  823. // 转换为数组输出
  824. $res['sys_msg'] = $combined->values()->all();
  825. // 互动消息
  826. $chat_msg = [];
  827. // 通知投诉
  828. $notice_msg = [];
  829. // $res['sys_msg'] = $sys_msg;
  830. $chat_single_msg = ChatRecords::where('user_id', $user_id)
  831. ->where('is_read', 0)
  832. ->where('talk_type', 1)
  833. ->orderBy('updated_at', 'desc')
  834. ->limit(5)
  835. ->get(['id', 'content', 'updated_at'])
  836. ->map(function ($item) use ($now) {
  837. $item->class = "单聊";
  838. $item->formatted_updated_at = $this->timeAgo($item->updated_at, $now);
  839. return $item;
  840. });
  841. $chat_group_msg = ChatRecords::where('user_id', $user_id)
  842. ->where('is_read', 0)
  843. ->where('talk_type', 2)
  844. ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  845. ->orderBy('updated_at', 'desc')
  846. ->limit(5)
  847. ->get(['chat_records.id', 'content as content1', 'chat_records.updated_at', 'chat_groups.group_name as content'])
  848. ->map(function ($item) use ($now) {
  849. $item->class = "群聊";
  850. $item->formatted_updated_at = $this->timeAgo($item->updated_at, $now);
  851. return $item;
  852. });
  853. $topic_msg = ChatTopic::where('chat_topics.user_id', $user_id)
  854. ->whereNotNull('chat_topics_reply.updated_at')
  855. ->leftJoin('chat_topics_reply', 'chat_topics.id', '=', 'chat_topics_reply.topic_id')
  856. ->select('chat_topics.id', 'chat_topics.title as content', 'chat_topics_reply.updated_at as updated_at')
  857. ->orderBy('updated_at', 'desc')
  858. ->limit(5)
  859. ->get(['chat_topics.id', 'chat_topics.content', 'chat_topics.updated_at'])
  860. ->map(function ($item) use ($now) {
  861. $item->class = "话题";
  862. // $item->content = $item->content;
  863. $item->formatted_updated_at = $this->timeAgo($item->updated_at, $now);
  864. return $item;
  865. });
  866. // 合并单聊和群聊消息
  867. $chat_msg = $chat_single_msg
  868. ->concat($chat_group_msg)
  869. ->concat($topic_msg)
  870. ->sortByDesc(function ($item) {
  871. return Carbon::createFromFormat('Y-m-d H:i:s', $item->updated_at);
  872. })->values()->all();
  873. $res['chat_msg'] = $chat_msg;
  874. //未读消息
  875. $notce_recieve_msg = Notice::where('status', 1)
  876. ->whereJsonContains('re_user_ids', $user_id)
  877. ->where(function ($query) use ($user_id) {
  878. $query->whereNull('read_id')
  879. ->orWhereRaw('NOT JSON_CONTAINS(`read_id`, ?)', [$user_id]);
  880. })
  881. ->orderBy('updated_at', 'desc')
  882. ->limit(5)
  883. ->get(['id', 'title', 'updated_at'])
  884. ->map(function ($item) use ($now) {
  885. $item->class = "通知";
  886. $item->formatted_updated_at = $this->timeAgo($item->updated_at, $now);
  887. return $item;
  888. });
  889. $complaint_recieve_msg = Complaint::where('status', 1)
  890. ->whereJsonContains('re_user_ids', $user_id)
  891. ->where(function ($query) use ($user_id) {
  892. $query->whereNull('read_id')
  893. ->orWhereRaw('NOT JSON_CONTAINS(`read_id`, ?)', [$user_id]);
  894. })
  895. ->orderBy('updated_at', 'desc')
  896. ->limit(5)
  897. ->get(['id', 'title', 'updated_at'])
  898. ->map(function ($item) use ($now) {
  899. $item->class = "投诉";
  900. $item->formatted_updated_at = $this->timeAgo($item->updated_at, $now);
  901. return $item;
  902. });
  903. // 合并消息
  904. $notice_msg = $notce_recieve_msg
  905. ->concat($complaint_recieve_msg)
  906. ->sortByDesc(function ($item) {
  907. return Carbon::createFromFormat('Y-m-d H:i:s', $item->updated_at);
  908. })->values()->all();
  909. $res['notice_msg'] = $notice_msg;
  910. // $res['article'] = $article;
  911. $res['website']['count'] = Website::where([])->count();
  912. $res['article']['count'] = Article::whereIn('status', [1])->where('admin_user_id', $user_id)->count();
  913. $res['category']['count'] = Category::where([])->count();
  914. $res['good']['count'] = Good::whereIn('status', [2])
  915. ->where('user_id', $user_id)->count();
  916. $res['book']['count'] = Book::whereIn('status', [2])
  917. ->where('user_id', $user_id)->count();
  918. $res['jobHunting']['count'] = JobHunting::whereIn('status', [2])
  919. ->where('user_id', $user_id)->count();
  920. $res['jobRecruiting']['count'] = JobRecruiting::whereIn('status', [1])
  921. ->where('user_id', $user_id)->count();
  922. $res['complaint']['count'] = Complaint::whereIn('status', [2])
  923. ->where('user_id', $user_id)->count();
  924. $res['notice']['count'] = Notice::whereIn('status', [2])
  925. ->where('user_id', $user_id)->count();
  926. //company project 0 待审核 1 已审核
  927. $res['company']['count'] = Company::whereIn('status', [1])
  928. ->where('user_id', $user_id)->count();
  929. $res['project']['count'] = Project::whereIn('status', [1])
  930. ->where('user_id', $user_id)->count();
  931. //待处理的complaint
  932. $res['complaint_deal']['count'] = Complaint::where(['status' => 2])
  933. ->where('deal', 1)
  934. // ->where('user_id', $user_id)
  935. ->whereJsonContains('re_user_ids', $user_id)
  936. ->count();
  937. //待审核数据
  938. $res['apply']['article'] = Article::where(['status' => 0])->where('admin_user_id', $user_id)->count(); //
  939. $res['apply']['good'] = Good::where(['status' => 1])->where('user_id', $user_id)->count();
  940. $res['apply']['book'] = Book::where(['status' => 1])->where('user_id', $user_id)->count();
  941. $res['apply']['jobHunting'] = JobHunting::where(['status' => 1])->where('user_id', $user_id)->count();
  942. $res['apply']['jobRecruiting'] = JobRecruiting::where(['status' => 0])->where('user_id', $user_id)->count();
  943. $res['apply']['complaint'] = Complaint::where(['status' => 1])->where('user_id', $user_id)->count();
  944. $res['apply']['notice'] = Notice::where(['status' => 1])->where('user_id', $user_id)->count();
  945. //project company
  946. $res['apply']['project'] = Project::whereIn('status', [0])
  947. ->where('user_id', $user_id)->count();
  948. $res['apply']['company'] = Company::whereIn('status', [0])
  949. ->where('user_id', $user_id)->count();
  950. return Result::success($res);
  951. }
  952. return [];
  953. }
  954. private function timeAgo(string $date, Carbon $now): string
  955. {
  956. $diff = (new Carbon($date))->diffInMinutes($now);
  957. if ($diff < 1) {
  958. return '刚刚';
  959. } elseif ($diff < 60) {
  960. return "{$diff} 分钟前";
  961. } elseif ($diff < 1440) {
  962. return (int)($diff / 60) . " 小时前";
  963. } elseif ($diff < 2880) { // 两天内
  964. return "1 天前";
  965. } elseif ($diff < 7 * 1440) {
  966. return (int)($diff / 1440) . " 天前";
  967. } else {
  968. return (new Carbon($date))->format('Y-m-d');
  969. }
  970. }
  971. /**
  972. * 获取分类下的模板
  973. * @param array $data
  974. * @return array
  975. */
  976. public function getTemplate(array $data): array
  977. {
  978. $page = $data['page'];
  979. $pageSize = $data['pageSize'];
  980. $where = [];
  981. if (isset($data['template_class_id']) && $data['template_class_id']) {
  982. array_push($where, ['template_class_id', '=', $data['template_class_id']]);
  983. }
  984. $result = Template::where($where)
  985. ->limit($pageSize)->offset(($page - 1) * $pageSize)->get();
  986. $count = Template::where($where)->count();
  987. if (empty($result)) {
  988. return Result::error("没有数据", 0);
  989. }
  990. $data = [
  991. 'rows' => $result->toArray(),
  992. 'count' => $count,
  993. ];
  994. return Result::success($data);
  995. }
  996. /**
  997. * 创建模板
  998. * @param
  999. * @return void
  1000. */
  1001. public function addTemplate(array $data): array
  1002. {
  1003. $insertData = [
  1004. 'template_name' => $data['template_name'],
  1005. 'template_img' => json_encode($data['template_img']),
  1006. 'template_class_id' => $data['template_class_id'],
  1007. ];
  1008. $result = Template::insertGetId($insertData);
  1009. if (empty($result)) {
  1010. return Result::error("创建模板失败", 0);
  1011. } else {
  1012. return Result::success(["id" => $result]);
  1013. }
  1014. }
  1015. /**
  1016. * 更新模板
  1017. * @param array $data
  1018. * @return array
  1019. */
  1020. public function upTemplate(array $data): array
  1021. {
  1022. $where = [
  1023. 'id' => $data['id'],
  1024. ];
  1025. $insertData = [
  1026. 'template_name' => $data['template_name'],
  1027. 'template_img' => json_encode($data['template_img']),
  1028. 'template_class_id' => $data['template_class_id'],
  1029. ];
  1030. $result = Template::where($where)->update($insertData);
  1031. if (empty($result)) {
  1032. return Result::error("更新模板失败", 0);
  1033. } else {
  1034. return Result::success();
  1035. }
  1036. }
  1037. /**
  1038. * 删除模板
  1039. * @param array $data
  1040. * @return array
  1041. */
  1042. public function delTemplate(array $data): array
  1043. {
  1044. $where = [
  1045. 'id' => $data['id'],
  1046. ];
  1047. $result = Template::where($where)->delete();
  1048. if (empty($result)) {
  1049. return Result::error("删除模板失败", 0);
  1050. } else {
  1051. return Result::success();
  1052. }
  1053. }
  1054. /**
  1055. * 搜索网站
  1056. * @param array $data
  1057. * @return array
  1058. */
  1059. public function websiteList(array $data): array
  1060. {
  1061. $where = [];
  1062. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1063. array_push($where, ['website.website_name', 'like', '%' . $data['keyword'] . '%']);
  1064. }
  1065. $result = Website::where($where)->get();
  1066. if (isset($data['website_column_id'])) {
  1067. $target = $data['website_column_id'];
  1068. $result = $result->filter(function ($item) use ($target) {
  1069. $arr = json_decode($item->website_column_arr_id, true);
  1070. return !in_array($target, $arr);
  1071. });
  1072. }
  1073. if ($result) {
  1074. return Result::success($result);
  1075. } else {
  1076. return Result::error("没有网站", 0);
  1077. }
  1078. }
  1079. public function addWebsiteCategory(array $data): array
  1080. {
  1081. $website_id = $data['website_id'];
  1082. $category_arr_id = $data['category_arr_id'];
  1083. $categoryList = Category::whereIn('id', $category_arr_id)->get();
  1084. $categoryListIds = [];
  1085. if ($categoryList) {
  1086. foreach ($categoryList->toArray() as $val) {
  1087. array_push($categoryListIds, $val['id']);
  1088. }
  1089. }
  1090. $arr = [];
  1091. if ($categoryListIds) {
  1092. foreach ($categoryListIds as $v) {
  1093. $ids = $this->getUnderlingUIds(intval($v));
  1094. $ids_arr = explode(",", $ids);
  1095. array_push($arr, $ids_arr);
  1096. }
  1097. }
  1098. $mergedArray = [];
  1099. foreach ($arr as $subarray) {
  1100. $mergedArray = array_merge($mergedArray, $subarray);
  1101. }
  1102. var_dump("所有:", $arr, $mergedArray);
  1103. //查询出所有的分类进行分割插入 组装数据
  1104. $categoryListData = Category::whereIn('id', $mergedArray)->get();
  1105. $categoryListData = $categoryListData->toArray();
  1106. $insertData = [];
  1107. if ($categoryListData) {
  1108. foreach ($categoryListData as $key => $value) {
  1109. $insertData[$key]['website_id'] = $website_id;
  1110. $insertData[$key]['name'] = $value['name'];
  1111. $insertData[$key]['sort'] = $value['sort'];
  1112. $insertData[$key]['pid'] = $value['pid'];
  1113. $insertData[$key]['pid_arr'] = $value['pid_arr'];
  1114. $insertData[$key]['seo_title'] = $value['seo_title'];
  1115. $insertData[$key]['seo_keywords'] = $value['seo_keywords'];
  1116. $insertData[$key]['seo_description'] = $value['seo_description'];
  1117. $insertData[$key]['alias'] = $value['name'];
  1118. $insertData[$key]['category_id'] = $value['id'];
  1119. }
  1120. }
  1121. $result = WebsiteCategory::insert($insertData);
  1122. var_dump("插入数据状态:", $result);
  1123. if ($result) {
  1124. return Result::success($result);
  1125. } else {
  1126. return Result::error("创建失败", 0);
  1127. }
  1128. }
  1129. /**
  1130. * 删除网站导航
  1131. * @param array $data
  1132. * @return array
  1133. */
  1134. public function delWebsiteCategory(array $data): array
  1135. {
  1136. $website_id = $data['website_id'] ?? 0;
  1137. $category_id = $data['category_id'] ?? 0;
  1138. $ids = $this->getUnderlingUIds(intval($category_id));
  1139. $ids_arr = explode(",", $ids);
  1140. $result = WebsiteCategory::where(['website_id' => $website_id])->whereIn("category_id", $ids_arr)->delete();
  1141. if ($result) {
  1142. return Result::success($result);
  1143. } else {
  1144. return Result::error("删除失败", 0);
  1145. }
  1146. }
  1147. /**
  1148. * 获取网站导航
  1149. * @param array $data
  1150. * @return array
  1151. */
  1152. public function getAdminWebsiteCategory(array $data): array
  1153. {
  1154. $where = [
  1155. 'website_id' => $data['website_id'],
  1156. ];
  1157. $result = WebsiteCategory::where($where)->orderBy('sort', 'asc')->get();
  1158. $list = [];
  1159. if ($result) {
  1160. foreach ($result->toArray() as $val) {
  1161. array_push($list, json_decode($val['category_arr_id']));
  1162. }
  1163. }
  1164. if ($result) {
  1165. return Result::success($list);
  1166. } else {
  1167. return Result::error("查询失败", 0);
  1168. }
  1169. }
  1170. /**
  1171. * 更新网站导航
  1172. * @param array $data
  1173. * @return array
  1174. */
  1175. public function upWebsiteCategory(array $data): array
  1176. {
  1177. $pinyin = new Pinyin();
  1178. var_dump("更新数据:", $data);
  1179. Db::beginTransaction();
  1180. try {
  1181. if (!empty($data['category_arr_id'])) {
  1182. $websiteId = $data['website_id'];
  1183. // 1. 获取旧的 category_id 列表
  1184. $oldCategoryListIds = WebsiteCategory::where('website_id', $websiteId)->pluck('category_id')->toArray();
  1185. // 2. 获取新的 category_id 列表(去重)
  1186. $newCategoryListIds = [];
  1187. foreach ($data['category_arr_id'] as $arr) {
  1188. $lastId = end($arr);
  1189. $newCategoryListIds[] = $lastId;
  1190. }
  1191. $newCategoryListIds = array_unique($newCategoryListIds);
  1192. // 3. 需要删除的 category_id
  1193. $toDelete = array_diff($oldCategoryListIds, $newCategoryListIds);
  1194. if (!empty($toDelete)) {
  1195. WebsiteCategory::where('website_id', $websiteId)
  1196. ->whereIn('category_id', $toDelete)
  1197. ->delete();
  1198. }
  1199. // 4. 批量查出所有需要的 category 信息
  1200. $categories = Category::whereIn('id', $newCategoryListIds)->get()->keyBy('id');
  1201. // 5. 组装 upsertData,确保 category_id 不重复
  1202. $upsertData = [];
  1203. $handledCategoryIds = [];
  1204. foreach ($data['category_arr_id'] as $arr) {
  1205. $categoryId = end($arr);
  1206. if (!isset($categories[$categoryId]) || in_array($categoryId, $handledCategoryIds)) continue;
  1207. $info = $categories[$categoryId];
  1208. $aLIas_pinyin = $pinyin->permalink($info->name, '');
  1209. $upsertData[] = [
  1210. 'website_id' => $websiteId,
  1211. 'category_id' => $categoryId,
  1212. 'name' => $info->name ?? '',
  1213. 'alias' => $info->name ?? '',
  1214. 'aLIas_pinyin' => $aLIas_pinyin ?? '',
  1215. 'sort' => $info->sort ?? 0,
  1216. 'pid' => $info->pid ?? 0,
  1217. 'pid_arr' => $info->pid_arr ?? json_encode([]),
  1218. 'seo_title' => $info->seo_title ?? "",
  1219. 'seo_keywords' => $info->seo_keywords ?? "",
  1220. 'seo_description' => $info->seo_description ?? "",
  1221. 'is_url' => $info->is_url ?? 0,
  1222. 'web_url' => $info->web_url ?? '',
  1223. 'type' => $info->type ?? 1,
  1224. 'category_arr_id' => json_encode($arr)
  1225. ];
  1226. $handledCategoryIds[] = $categoryId;
  1227. }
  1228. // 6. upsert
  1229. if (!empty($upsertData)) {
  1230. WebsiteCategory::upsert(
  1231. $upsertData,
  1232. ['website_id', 'category_id'],
  1233. [
  1234. 'aLIas_pinyin',
  1235. 'pid',
  1236. 'pid_arr',
  1237. 'is_url',
  1238. 'web_url',
  1239. 'category_arr_id'
  1240. ]
  1241. );
  1242. }
  1243. }
  1244. //处理所有path
  1245. var_dump($data, '--------111----');
  1246. $website_id = $data['website_id'];
  1247. //获取所有数据
  1248. $result = WebsiteCategory::where(['website_id' => $websiteId, 'path' => NULL])->get()->toArray();
  1249. if (empty($result)) {
  1250. // return Result::error("没有数据", 0);
  1251. }
  1252. //处理path
  1253. foreach ($result as $key => $value) {
  1254. $array_category_arr_id = json_decode($value['category_arr_id'], true);
  1255. $result[$key]['path'] = WebsiteCategory::where('website_id', $websiteId)
  1256. ->orderByRaw('FIELD(category_id, ' . implode(',', $array_category_arr_id) . ')')
  1257. ->whereIn('category_id', $array_category_arr_id)
  1258. ->pluck('aLIas_pinyin')
  1259. ->implode('/');
  1260. }
  1261. //批量更新数据path
  1262. $updateData = [];
  1263. foreach ($result as $item) {
  1264. $updateData[] = [
  1265. 'id' => $item['id'],
  1266. 'path' => $item['path']
  1267. ];
  1268. }
  1269. //批量更新
  1270. DB::beginTransaction();
  1271. try {
  1272. foreach ($result as $item) {
  1273. WebsiteCategory::where('id', $item['id'])->update(['path' => $item['path']]);
  1274. }
  1275. DB::commit();
  1276. } catch (\Exception $e) {
  1277. DB::rollBack();
  1278. throw $e; // 或者返回错误信息
  1279. }
  1280. //更换级别操作 形成新的上下级;
  1281. $website_all = WebsiteCategory::where('website_id', $website_id)
  1282. ->where('pid', '>', 0)
  1283. ->get()->toArray();
  1284. foreach ($website_all as $key => $value) {
  1285. $category_arr_id = json_decode($value['category_arr_id'], true);
  1286. $validPids = [];
  1287. $pid = 0;
  1288. foreach ($category_arr_id as $pidid => $pid) {
  1289. $exists = WebsiteCategory::where('website_id', $website_id)
  1290. ->where('category_id', $pid)->exists();
  1291. if ($exists) {
  1292. $validPids[] = $pid;
  1293. }
  1294. }
  1295. $pid = $validPids[0];
  1296. if (count($validPids) != count($category_arr_id)) {
  1297. if (count($validPids) == 1) {
  1298. $pid = 0;
  1299. }
  1300. // $category_arr_id = array_push($validPids, $value['category_id']);
  1301. WebsiteCategory::where('id', $value['id'])->update([
  1302. 'real_category_arr_id' => json_encode($validPids),
  1303. 'real_pid' => $pid,
  1304. 'path' => WebsiteCategory::where('website_id', $website_id)
  1305. ->orderByRaw('FIELD(category_id, ' . implode(',', $validPids) . ')')
  1306. ->whereIn('category_id', $validPids)
  1307. ->pluck('aLIas_pinyin')
  1308. ->implode('/'),
  1309. ]);
  1310. } else {
  1311. WebsiteCategory::where('id', $value['id'])->update([
  1312. 'real_category_arr_id' => null,
  1313. 'real_pid' => null,
  1314. 'path' => WebsiteCategory::where('website_id', $website_id)
  1315. ->orderByRaw('FIELD(category_id, ' . implode(',', $validPids) . ')')
  1316. ->whereIn('category_id', $validPids)
  1317. ->pluck('aLIas_pinyin')
  1318. ->implode('/'),
  1319. ]);
  1320. }
  1321. }
  1322. Db::commit();
  1323. var_dump("更新数据1:", $data);
  1324. return Result::success();
  1325. } catch (\Throwable $ex) {
  1326. Db::rollBack();
  1327. return Result::error("修改失败" . $ex->getMessage(), 0);
  1328. }
  1329. }
  1330. /**
  1331. * 获取网站列表
  1332. * @param array $data
  1333. * @return array
  1334. */
  1335. public function getWebsiteCategoryList(array $data): array
  1336. {
  1337. $where = [];
  1338. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1339. array_push($where, ['website.website_name', 'like', '%' . $data['keyword'] . '%']);
  1340. }
  1341. if (isset($data['website_column_id']) && !empty($data['website_column_id'])) {
  1342. array_push($where, ['website.website_column_id', '=', $data['website_column_id']]);
  1343. }
  1344. $result = Website::where($where)
  1345. ->with(["websiteCategory" => function ($query) {
  1346. $query->where(['pid' => 0])->select('website_id', 'name', 'alias', 'category_id');
  1347. }])
  1348. ->limit($data['pageSize'])->orderBy("updated_at", "desc")->offset(($data['page'] - 1) * $data['pageSize'])
  1349. ->get();
  1350. $count = Website::where($where)->count();
  1351. if (empty($result)) {
  1352. return Result::error("没有数据", 0);
  1353. }
  1354. $data = [
  1355. 'rows' => $result->toArray(),
  1356. 'count' => $count,
  1357. ];
  1358. if ($result) {
  1359. return Result::success($data);
  1360. } else {
  1361. return Result::error("查询失败", 0);
  1362. }
  1363. }
  1364. /**
  1365. * 删除网站下的所有导航
  1366. * @param array $data
  1367. * @return array
  1368. */
  1369. public function delWebsiteAllCategory(array $data): array
  1370. {
  1371. $website_id = $data['website_id'];
  1372. $result = WebsiteCategory::where(['website_id' => $website_id])->delete();
  1373. if ($result) {
  1374. return Result::success($result);
  1375. } else {
  1376. return Result::error("删除失败", 0);
  1377. }
  1378. }
  1379. /**
  1380. * 获取网站下的某一个导航
  1381. * @param array $data
  1382. * @return array
  1383. */
  1384. public function getWebsiteCategoryOnes(array $data): array
  1385. {
  1386. $website_id = $data['website_id'];
  1387. $category_id = $data['category_id'];
  1388. $result = WebsiteCategory::where(['website_category.website_id' => $website_id, 'website_category.category_id' => $category_id])
  1389. ->first();
  1390. if ($result) {
  1391. return Result::success($result);
  1392. } else {
  1393. return Result::error("查询失败", 0);
  1394. }
  1395. }
  1396. /**
  1397. * 更新网闸下的某一个导航
  1398. * @param array $data
  1399. * @return array
  1400. */
  1401. public function upWebsiteCategoryones(array $data): array
  1402. {
  1403. //处理所有数据
  1404. //获取所有数据
  1405. if (isset($data['all']) && $data['all'] == 'all') {
  1406. $result = WebsiteCategory::get();
  1407. $result = $result->toArray();
  1408. var_dump($result, '------------');
  1409. $pinyin = new Pinyin();
  1410. $letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  1411. for ($i = 0; $i < count($result); $i++) {
  1412. // $randss = substr(str_shuffle($letters), 0, 4);
  1413. $result[$i]['aLIas_pinyin'] = $pinyin->permalink($result[$i]['alias'], '');
  1414. WebsiteCategory::where(['id' => $result[$i]['id']])->update(['aLIas_pinyin' => $result[$i]['aLIas_pinyin']]);
  1415. }
  1416. var_dump($result, '--------222----');
  1417. if ($result) {
  1418. return Result::success($result);
  1419. } else {
  1420. return Result::error("更新失败", 0);
  1421. }
  1422. }
  1423. //处理所有path
  1424. if (isset($data['pathone']) && $data['pathone'] == 'pathone') {
  1425. var_dump($data, '--------111----');
  1426. $website_id = $data['website_id'];
  1427. //获取所有数据
  1428. $result = WebsiteCategory::where(['website_id' => $website_id, 'path' => NULL])->get()->toArray();
  1429. if (empty($result)) {
  1430. return Result::error("没有数据", 0);
  1431. }
  1432. //处理path
  1433. foreach ($result as $key => $value) {
  1434. $array_category_arr_id = json_decode($value['category_arr_id'], true);
  1435. $result[$key]['path'] = WebsiteCategory::where('website_id', $website_id)
  1436. ->orderByRaw('FIELD(category_id, ' . implode(',', $array_category_arr_id) . ')')
  1437. ->whereIn('category_id', $array_category_arr_id)
  1438. ->pluck('aLIas_pinyin')
  1439. ->implode('/');
  1440. }
  1441. //批量更新数据path
  1442. $updateData = [];
  1443. foreach ($result as $item) {
  1444. $updateData[] = [
  1445. 'id' => $item['id'],
  1446. 'path' => $item['path']
  1447. ];
  1448. }
  1449. //批量更新
  1450. DB::beginTransaction();
  1451. try {
  1452. foreach ($result as $item) {
  1453. WebsiteCategory::where('id', $item['id'])->update(['path' => $item['path']]);
  1454. }
  1455. DB::commit();
  1456. } catch (\Exception $e) {
  1457. DB::rollBack();
  1458. throw $e; // 或者返回错误信息
  1459. }
  1460. return Result::success($result);
  1461. }
  1462. if (isset($data['pathall']) && $data['pathall'] == 'pathall') {
  1463. //获取所有数据
  1464. $result = WebsiteCategory::where(['path' => NULL])->get()->toArray();
  1465. if (empty($result)) {
  1466. return Result::error("没有数据", 0);
  1467. }
  1468. //处理path
  1469. foreach ($result as $key => $value) {
  1470. if (empty($value['category_arr_id'])) continue;
  1471. if ($key >= 4) { // 改为 >= 4 如果你想处理最多4个元素
  1472. // break;
  1473. }
  1474. $array_category_arr_id = json_decode($value['category_arr_id'], true);
  1475. $result[$key]['path'] = WebsiteCategory::where('website_id', $value['website_id'])
  1476. ->orderByRaw('FIELD(category_id, ' . implode(',', $array_category_arr_id) . ')')
  1477. ->whereIn('category_id', $array_category_arr_id)
  1478. ->pluck('aLIas_pinyin')
  1479. ->implode('/');
  1480. }
  1481. //批量更新数据path
  1482. $updateData = [];
  1483. foreach ($result as $item) {
  1484. $updateData[] = [
  1485. 'id' => $item['id'],
  1486. 'category_arr_id' => $item['category_arr_id'],
  1487. 'path' => $item['path']
  1488. ];
  1489. }
  1490. // var_dump($updateData);
  1491. // return Result::success($updateData);
  1492. //批量更新
  1493. DB::beginTransaction();
  1494. try {
  1495. foreach ($result as $item) {
  1496. WebsiteCategory::where('id', $item['id'])->update(['path' => $item['path']]);
  1497. }
  1498. DB::commit();
  1499. } catch (\Exception $e) {
  1500. DB::rollBack();
  1501. throw $e; // 或者返回错误信息
  1502. }
  1503. return Result::success($result);
  1504. }
  1505. $where = [
  1506. 'website_id' => $data['website_id'],
  1507. 'category_id' => $data['category_id'],
  1508. ];
  1509. $alias = $data['alias'];
  1510. $pinyin = new Pinyin();
  1511. $aLIas_pinyin = $pinyin->permalink($alias, '');
  1512. //从WebsiteCategory取出alis ,并转成拼音存放到aLIas_pinyin
  1513. $result = WebsiteCategory::where($where)->first();
  1514. if (empty($result)) {
  1515. return Result::error("没有数据", 0);
  1516. }
  1517. $result = $result->toArray();
  1518. $oldAliasPinyin = $data['alias_pinyin']; // 修正键名大小写
  1519. var_dump($oldAliasPinyin, $result, '----old-new---');
  1520. //+四位随机字母
  1521. $letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  1522. // 打乱字符串顺序并截取前四位
  1523. // $randss = substr(str_shuffle($letters), 0, 4);
  1524. $data['aLIas_pinyin'] = $aLIas_pinyin;
  1525. //数据库先更新一下,再改path
  1526. WebsiteCategory::where($where)->update(['aLIas_pinyin' => $data['aLIas_pinyin']]);
  1527. //处理path
  1528. $category_arr_id = json_decode($result['category_arr_id'], true);
  1529. //取出来设置path
  1530. $path = WebsiteCategory::where('website_id', $data['website_id'])
  1531. ->orderByRaw('FIELD(category_id, ' . implode(',', $category_arr_id) . ')')
  1532. ->whereIn('category_id', $category_arr_id)
  1533. ->pluck('aLIas_pinyin')
  1534. ->implode('/');
  1535. $data['path'] = $path;
  1536. //处理包含此id的所有path
  1537. // 取出category_arr_id包含此id的所有数据
  1538. $all_other = WebsiteCategory::where('website_id', $data['website_id'])
  1539. ->whereJsonContains('category_arr_id', $data['category_id'])
  1540. ->get();
  1541. // var_dump($all_other, '------------');
  1542. // 遍历所有数据,更新path
  1543. $newAliasPinyin = $aLIas_pinyin; // 添加空值判断
  1544. // 收集需要更新的ID和路径
  1545. $updateData = [];
  1546. foreach ($all_other as $item) {
  1547. $newPath = str_replace($oldAliasPinyin, $newAliasPinyin, $item->path);
  1548. var_dump($newPath, '---------zz--', $item->path, $oldAliasPinyin, $newAliasPinyin);
  1549. if ($newPath !== $item->path) { // 仅在路径变化时更新
  1550. $updateData[] = [
  1551. 'id' => $item->id,
  1552. // 'category_id' => $item->category_id,
  1553. 'path' => $newPath
  1554. ];
  1555. }
  1556. }
  1557. var_dump($updateData, '-----------1-');
  1558. // 批量更新提高性能
  1559. if (!empty($updateData)) {
  1560. // 假设模型对应的数据表为 'table_name',请替换为实际表名
  1561. // WebsiteCategory::upsert($updateData, ['id'], ['path']);
  1562. foreach ($updateData as $datapath) {
  1563. WebsiteCategory::updateOrInsert(
  1564. ['id' => $datapath['id']], // 匹配条件
  1565. ['path' => $datapath['path']] // 更新字段
  1566. );
  1567. }
  1568. }
  1569. $result = WebsiteCategory::where($where)->update($data);
  1570. if ($result) {
  1571. return Result::success($result);
  1572. } else {
  1573. return Result::error("更新失败", 0);
  1574. }
  1575. }
  1576. /**
  1577. * 获取网站下的所有导航(包含子导航)
  1578. * @param array $data
  1579. * @return array
  1580. */
  1581. public function getWebsiteAllCategory(array $data): array
  1582. {
  1583. $where = [];
  1584. var_dump($data, '---1');
  1585. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1586. array_push($where, ['website_category.website_id', '=', $data['website_id']]);
  1587. }
  1588. // if (isset($data['name']) && !empty($data['name'])) {
  1589. // array_push($where, ['website_category.name', 'like', '%' . $data['name'] . '%']);
  1590. // }
  1591. // if (isset($data['alias']) && !empty($data['alias'])) {
  1592. // array_push($where, ['website_category.alias', 'like', '%' . $data['alias'] . '%']);
  1593. // }
  1594. // if (isset($data['department_id']) && !empty($data['department_id'])) {
  1595. // array_push($where, ['category.department_id', '=', $data['department_id']]);
  1596. // }
  1597. // if (isset($data['city_id']) && !empty($data['city_id'])) {
  1598. // array_push($where, ['category.city_id', '=', $data['city_id']]);
  1599. // }
  1600. if (isset($data['is_show'])) {
  1601. array_push($where, ['website_category.is_show', '=', $data['is_show']]);
  1602. }
  1603. var_dump($where, '---2');
  1604. $result_real = WebsiteCategory::where($where)
  1605. // ->where('website_category.is_show', 1) //显示
  1606. ->whereNotNull('website_category.real_pid') //只显示顶级
  1607. ->leftJoin("category", 'website_category.category_id', 'category.id')
  1608. ->select(
  1609. "website_category.*",
  1610. DB::raw('real_pid AS pid'),
  1611. DB::raw('real_category_arr_id AS category_arr_id'),
  1612. "category.name as name"
  1613. )
  1614. ->orderBy("sort", "asc")
  1615. ->orderBy("updated_at", "desc")
  1616. ->get()->toArray();
  1617. $result = WebsiteCategory::where($where)
  1618. // ->where('website_category.is_show', 1) //显示
  1619. ->whereNull('website_category.real_pid') //只显示顶级
  1620. ->leftJoin("category", 'website_category.category_id', 'category.id')
  1621. ->select(
  1622. "website_category.*",
  1623. // DB::raw('real_pid AS pid'),
  1624. // DB::raw('real_category_arr_id AS category_arr_id'),
  1625. "category.name as name"
  1626. )
  1627. // ->leftJoin("category", 'website_category.category_id', 'category.id')
  1628. // ->leftJoin("department", 'category.department_id', 'department.id')
  1629. // ->leftJoin("district", 'category.city_id', 'district.id')
  1630. // ->select("website_category.*", "department.name as department_name", "district.name as city_name")
  1631. // ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])
  1632. ->orderBy("sort", "asc")
  1633. ->orderBy("updated_at", "desc")
  1634. ->get()->toArray();
  1635. $result = array_merge($result, $result_real);
  1636. // var_dump($result, '-----------1-');
  1637. if (empty($result)) {
  1638. return Result::error("没有数据", 0);
  1639. }
  1640. if ($result) {
  1641. return Result::success($result);
  1642. } else {
  1643. return Result::error("查询失败", 0);
  1644. }
  1645. }
  1646. /**
  1647. * 递归查询数据
  1648. * @param $id
  1649. * @param $ids
  1650. * @return string
  1651. */
  1652. public function getUnderlingUIds($id, $ids = '')
  1653. {
  1654. $back = Category::where(['pid' => $id])->get();
  1655. $back = $back->toArray();
  1656. if (!empty($back) && is_array($back)) {
  1657. foreach ($back as $v) {
  1658. //防止当前人的ID重复去查询,形成恶性循环
  1659. if ($v['id'] == $id) {
  1660. continue;
  1661. }
  1662. $back2 = Category::where(['pid' => $id])->count('id');
  1663. if ($back2 > 0) {
  1664. $ids = $this->getUnderlingUIds($v['id'], $ids);
  1665. } else {
  1666. $ids .= ',' . $v['id'];
  1667. }
  1668. }
  1669. }
  1670. $ids = $id . ',' . $ids . ',';
  1671. $ids = str_replace(',,', ",", $ids);
  1672. $ids = trim($ids, ',');
  1673. return $ids;
  1674. }
  1675. /**
  1676. * 检测网站名称是否重复
  1677. * @param array $data
  1678. * @return array
  1679. */
  1680. public function checkWebsiteName(array $data): array
  1681. {
  1682. if (isset($data['id'])) {
  1683. $data[] = ['id', "!=", $data['id']];
  1684. unset($data['id']);
  1685. }
  1686. $websiteInfo = Website::query()->where($data)->first();
  1687. if (empty($websiteInfo)) {
  1688. return Result::error("找不到网站", 0);
  1689. }
  1690. return Result::success($websiteInfo->toArray());
  1691. }
  1692. /**
  1693. * 检测网站url是否重复
  1694. * @param array $data
  1695. * @return array
  1696. */
  1697. public function checkWebsiteUrl(array $data): array
  1698. {
  1699. $whereData = [];
  1700. if (isset($data['id'])) {
  1701. $whereData = [['id', "!=", $data['id']]];
  1702. unset($data['id']);
  1703. }
  1704. $websiteInfo = Website::query()->where($whereData)->whereJsonContains('website_url', $data['website_url'])->first();
  1705. if (empty($websiteInfo)) {
  1706. return Result::error("找不到URL", 0);
  1707. }
  1708. return Result::success($websiteInfo->toArray());
  1709. }
  1710. /*
  1711. * 搜索网站二级导航
  1712. * @param array $data
  1713. * @return array
  1714. * */
  1715. public function selectWebsiteCategory(array $data): array
  1716. {
  1717. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1718. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1719. if (empty($website)) {
  1720. return Result::error("暂无该网站", 0);
  1721. }
  1722. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id')->all();
  1723. // return Result::success($category);
  1724. if (empty($category)) {
  1725. return Result::error("暂无此导航", 0);
  1726. }
  1727. $query = Category::whereIn('id', $category);
  1728. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1729. $cityid = District::where('id', $data['cityid'])->first();
  1730. if (empty($cityid)) {
  1731. return Result::error("暂无此城市", 0);
  1732. } else {
  1733. $city_category = $query->whereRaw('JSON_CONTAINS(city_arr_id,?)', [$data['cityid']])->pluck('id');
  1734. // $where[] = ['JSON_CONTAINS(city_arr_id, ?)', $data['cityid']];
  1735. if (empty($city_category)) {
  1736. return Result::error("暂无此城市下的导航", 0);
  1737. }
  1738. $result['catid'] = $city_category;
  1739. $city = 1;
  1740. // var_dump("城市====================",$result);
  1741. }
  1742. }
  1743. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1744. $departmentid = Department::where('id', $data['department_id'])->first();
  1745. if (empty($departmentid)) {
  1746. return Result::error("暂无此部门", 0);
  1747. } else {
  1748. $depart_category = $query->whereRaw('JSON_CONTAINS(department_arr_id,?)', [$data['department_id']])->pluck('id');
  1749. if (empty($depart_category)) {
  1750. return Result::error("暂无此部门下的导航", 0);
  1751. }
  1752. $result['catid'] = $depart_category;
  1753. // var_dump("职能部门*******************",$result);
  1754. $department = 1;
  1755. }
  1756. }
  1757. if (!empty($city) && !empty($department)) {
  1758. // var_dump("城市和职能部门----------------------",$result);
  1759. $sel_category = $query->whereRaw('JSON_CONTAINS(city_arr_id,?)', [$data['cityid']])->whereRaw('JSON_CONTAINS(department_arr_id,?)', [$data['department_id']])->pluck('id');
  1760. if (empty($sel_category)) {
  1761. return Result::error("暂无此城市和职能部门下的导航", 0);
  1762. }
  1763. $result['catid'] = $sel_category;
  1764. }
  1765. if (empty($result)) {
  1766. return Result::error("暂无导航", 0);
  1767. }
  1768. // department_id
  1769. } else {
  1770. return Result::error("参数错误", 0);
  1771. }
  1772. return Result::success($result);
  1773. }
  1774. // 自助建站--fr-------------------
  1775. /**
  1776. * 获取并搜索 网站模板信息
  1777. * @param array $data
  1778. * @return array
  1779. */
  1780. public function getWebsiteintel(array $data): array
  1781. {
  1782. //查询所有网站模板信息
  1783. $query = Website::leftJoin("website_template_info", "website_template_info.website_id", "website.id")
  1784. ->leftJoin("template", "template.template_id", "website_template_info.template_id")
  1785. ->leftJoin("template_class", "template_class.class_id", "template.template_class_id")
  1786. ->leftJoin('website_column', 'website_column.id', 'website.website_column_id')
  1787. ->leftJoin('website_column as parent_column', function ($join) {
  1788. $join->on('website_column.pid', '=', 'parent_column.id')
  1789. ->where('website_column.pid', 2);
  1790. })
  1791. ->whereRaw('NOT JSON_CONTAINS(website_column_arr_id, \'3\')')
  1792. ->select(
  1793. "website_template_info.id",
  1794. "template_class.name",
  1795. "website.id as website_id",
  1796. "website.website_name",
  1797. "website.website_url",
  1798. "website_template_info.action_id",
  1799. "website_template_info.created_at",
  1800. "website_template_info.updated_at",
  1801. "website_template_info.page_type",
  1802. 'website_column.column_name',
  1803. 'parent_column.column_name as parent_column_name',
  1804. DB::raw("COALESCE(website_template_info.status, 0) as template_status"),
  1805. "template.template_name"
  1806. );
  1807. //若存在条件;则在$query的基础上进行筛选
  1808. if (isset($data['website_name']) && !empty($data['website_name'])) {
  1809. $query->where('website.website_name', 'like', '%' . $data['website_name'] . '%');
  1810. }
  1811. if (isset($data['status']) && !empty($data['status'])) {
  1812. $query->where('website_template_info.status', $data['status']);
  1813. }
  1814. $count = $query->count();
  1815. $query->limit($data['pageSize'])
  1816. ->offset(($data['page'] - 1) * $data['pageSize'])
  1817. ->orderBy("website_template_info.updated_at", "desc");
  1818. $rep = $query->get();
  1819. if ($rep->count() == 0) {
  1820. return Result::error("没有查找到相关数据", 0);
  1821. } else {
  1822. $rep->each(function ($item) {
  1823. if (!empty($item->page_type)) {
  1824. $pageTypeArray = json_decode($item->page_type, true);
  1825. if (is_array($pageTypeArray)) {
  1826. $item->page_type = $pageTypeArray;
  1827. }
  1828. }
  1829. });
  1830. $result = [
  1831. "rows" => $rep->toArray(),
  1832. "count" => $count,
  1833. ];
  1834. return Result::success($result);
  1835. }
  1836. // return Result::success($result);
  1837. }
  1838. /**
  1839. * 自助建站-验证搭建网站
  1840. * @param array $data
  1841. * @return array
  1842. */
  1843. public function checkWebsiteBuild(array $data): array
  1844. {
  1845. $website = Website::where('website.id', $data['website_id'])->first();
  1846. if (empty($website)) {
  1847. return Result::error("请输入正确的网站id!", 0);
  1848. }
  1849. if (empty($website['website_column_id'])) {
  1850. return Result::error("请先关联导航池!", 0);
  1851. }
  1852. // 获取此网站的底部导航 类型 type: 0:内容型底部导航(只有一条详情内容);1:列表型底部导航(可以有多条详情内容)
  1853. $foot_type = FooterCategory::where('website_id', $data['website_id'])->pluck('type')->toArray();
  1854. if (empty($foot_type)) {
  1855. return Result::error("请先关联单页!", 0);
  1856. }
  1857. // if (!in_array(1, $foot_type) ) {
  1858. // $missingTypes[] = "列表型底部导航";
  1859. // }
  1860. if (!in_array(0, $foot_type) ) {
  1861. $missingTypes = "单页(详情)";
  1862. }
  1863. if (!empty($missingTypes)) {
  1864. $errorMessage = "请先添加" . $missingTypes . "!";
  1865. return Result::error($errorMessage, 0);
  1866. }
  1867. $result['foot_type'] = $foot_type;
  1868. // 友情链接类型'1:图片 2:文字 3:底部';
  1869. $types = Link::where('website_id', $data['website_id'])->pluck('type')->toArray();
  1870. $missingTypes = [];
  1871. if (!in_array(1, $types)) {
  1872. $missingTypes[] = "文字链接";
  1873. }
  1874. if (!in_array(2, $types)) {
  1875. $missingTypes[] = "图片链接";
  1876. }
  1877. if (!in_array(3, $types)) {
  1878. $missingTypes[] = "底部链接";
  1879. }
  1880. if (!empty($missingTypes)) {
  1881. $errorMessage = "请先添加 " . implode(" 和 ", $missingTypes) . "!";
  1882. return Result::error($errorMessage, 0);
  1883. }
  1884. return Result::success($result);
  1885. }
  1886. /**
  1887. * 自助建站-验证编辑网站
  1888. * @return array
  1889. *
  1890. */
  1891. public function checkWebsiteEdit(array $data): array
  1892. {
  1893. $result = WebsiteTemplateInfo::where('website_template_info.website_id', $data['website_id'])->first();
  1894. if (empty($result)) {
  1895. return Result::error("请输入正确的网站id!", 0);
  1896. }
  1897. // 0:未构建 1:未应用 2:已应用
  1898. if ($result['status'] == 2) {
  1899. return Result::error("此网站的模板正在应用中,暂不可编辑!", 0);
  1900. }
  1901. // 订单状态:1:通过;2:驳回;3:撤回;4:修改;5:过期;6:待审核;7:结束
  1902. $order = Order::where('website_id', $data['website_id'])->where('status', 1)->first();
  1903. if (!empty($order)) {
  1904. return Result::error("此网站的广告位正在使用中,暂不可编辑!", 0);
  1905. }
  1906. $check = $this->checkWebsiteBuild($data);
  1907. if ($check['code'] != 200) {
  1908. return Result::error($check['message'], 0);
  1909. }
  1910. // return Result::success($check);
  1911. if ($result['page_type']) {
  1912. $result['page_type'] = json_decode($result['page_type'], true);
  1913. return Result::success('网站编辑验证通过!');
  1914. } else {
  1915. return Result::error("请先选择网站页面类型!", 0);
  1916. }
  1917. }
  1918. /**
  1919. * 修改网站基础信息
  1920. *
  1921. * @return array
  1922. */
  1923. public function upWebsiteTemplateintel(array $data): array
  1924. {
  1925. $web = Website::where('website.id', $data['website_id'])->first();
  1926. if (empty($web)) {
  1927. return Result::error("请输入正确的网站id!", 0);
  1928. }
  1929. $where = ['website_id' => $data['website_id']];
  1930. $result = WebsiteTemplateInfo::where($where)->first();
  1931. if (empty($result)) {
  1932. return Result::error("请先添加网站基础信息!", 0);
  1933. } else {
  1934. unset($data['website_id']);
  1935. // 删除重复元素
  1936. $data['page_type'] = array_unique($data['page_type']);
  1937. // 重新索引数组
  1938. $data['page_type'] = array_values($data['page_type']);
  1939. // 数组中同时包含值为 1(首页) 和值为 7 (底部导航详情页)的元素
  1940. if (in_array(1, $data['page_type']) && in_array(7, $data['page_type'])) {
  1941. // 将数组转换为 JSON 字符串
  1942. $data['page_type'] = json_encode($data['page_type']) ?? '';
  1943. try {
  1944. $result = WebsiteTemplateInfo::where($where)->update($data);
  1945. } catch (\Exception $e) {
  1946. if ($e->getCode() == 22001) {
  1947. $errorMessage = $e->getMessage();
  1948. return Result::error("请检查表单,某个字段超出了长度限制!");
  1949. } else {
  1950. // 处理其他类型的数据库错误
  1951. return Result::error("修改操作失败: " . $e->getMessage());
  1952. }
  1953. return Result::error("修改失败!", 0);
  1954. }
  1955. } else {
  1956. return Result::error("请先选择首页和单页(详情)!", 0);
  1957. }
  1958. }
  1959. if (empty($result)) {
  1960. return Result::error("修改失败!", 0);
  1961. } else {
  1962. return Result::success($result);
  1963. }
  1964. }
  1965. /**
  1966. * 获取所有网站风格信息
  1967. *
  1968. * @return array
  1969. */
  1970. public function getAllTemplateClass(array $data): array
  1971. {
  1972. $result = TemplateClass::all();
  1973. if (empty($result)) {
  1974. return Result::error("没有查找到相关数据!", 0);
  1975. } else {
  1976. return Result::success($result);
  1977. }
  1978. }
  1979. /**
  1980. * 搜索并获取网站模板信息
  1981. * @param array $data
  1982. * @return array
  1983. */
  1984. public function getWebsiteTemplateList(array $data): array
  1985. {
  1986. $website = Website::where('website.id', $data['website_id'])->first();
  1987. if (empty($website)) {
  1988. return Result::error("请输入正确的网站id!", 0);
  1989. } else {
  1990. $page_type = WebsiteTemplateInfo::where('website_id', $data['website_id'])->select('page_type')->first();
  1991. if (empty($page_type)) {
  1992. return Result::error("此网站还未添加基础信息!", 0);
  1993. } else {
  1994. $where = json_decode($page_type['page_type'], true);
  1995. // $where = $data["page_type"];
  1996. if (isset($data['template_class_id']) && !empty($data['template_class_id'])) {
  1997. $template_class = TemplateClass::where('id', $data['template_class_id'])->first();
  1998. if (empty($template_class)) {
  1999. return Result::error("请输入正确的模板风格id!", 0);
  2000. } else {
  2001. // 获取指定风格下的模板
  2002. $rep = Template::where('template_class_id', $data['template_class_id'])
  2003. ->where(function ($query) use ($where) {
  2004. foreach ($where as $value) {
  2005. $query->whereJsonContains('template_img', ['value' => $value]);
  2006. }
  2007. })
  2008. ->limit($data['pageSize'])
  2009. ->offset(($data['page'] - 1) * $data['pageSize'])
  2010. ->orderBy("template.updated_at", "desc")
  2011. ->get();
  2012. $count = Template::where('template_class_id', $data['template_class_id'])
  2013. ->where(function ($query) use ($where) {
  2014. foreach ($where as $value) {
  2015. $query->whereJsonContains('template_img', ['value' => $value]);
  2016. }
  2017. })->count();
  2018. }
  2019. } else {
  2020. //获取所有模板
  2021. $rep = Template::where(function ($query) use ($where) {
  2022. foreach ($where as $value) {
  2023. $query->whereJsonContains('template_img', ['value' => $value]);
  2024. }
  2025. })
  2026. ->limit($data['pageSize'])
  2027. ->offset(($data['page'] - 1) * $data['pageSize'])
  2028. ->orderBy("template.updated_at", "desc")
  2029. ->get();
  2030. $count = Template::where(function ($query) use ($where) {
  2031. foreach ($where as $value) {
  2032. $query->whereJsonContains('template_img', ['value' => $value]);
  2033. }
  2034. })->count();
  2035. }
  2036. if (empty($rep) || $rep->count() == 0) {
  2037. return Result::error("没有查找到相关数据!", 0);
  2038. } else {
  2039. // 过滤 template_img 字段 只获取 基础信息中 包含的模板图片
  2040. // $rep->each(function ($item) use ($where) {
  2041. // $template_img = json_decode($item->template_img, true);
  2042. // if(is_array($template_img)){
  2043. // $filtered_img = array_filter($template_img, function ($img) use ($where) {
  2044. // return isset($img['value']) && in_array($img['value'], $where);
  2045. // });
  2046. // }
  2047. // $item->template_img = $filtered_img;
  2048. // });
  2049. // $result = [
  2050. // "rows" => $rep->toArray(),
  2051. // "count" => $count
  2052. // ];
  2053. $rep->each(function ($item) use ($where) {
  2054. $template_img = json_decode($item->template_img, true);
  2055. if (is_array($template_img)) {
  2056. $filtered_img = array_filter($template_img, function ($img) use ($where) {
  2057. return isset($img['value']) && in_array($img['value'], $where);
  2058. });
  2059. // 对过滤后的数组进行重新排序
  2060. $sorted_img = array_values($filtered_img);
  2061. $item->template_img = $sorted_img;
  2062. } else {
  2063. $item->template_img = []; // 如果无法解码为数组,则设置为空数组
  2064. }
  2065. });
  2066. $result = [
  2067. "rows" => $rep->toArray(),
  2068. "count" => $count,
  2069. ];
  2070. }
  2071. }
  2072. }
  2073. return Result::success($result);
  2074. }
  2075. /**
  2076. * 添加网站模板
  2077. * @param array $data
  2078. */
  2079. public function addWebsiteTemplateclassintel(array $data): array
  2080. {
  2081. $template = Template::where('id', $data['template_id'])->first();
  2082. $web = Website::where('id', $data['website_id'])->first();
  2083. if (empty($template)) {
  2084. return Result::error("请输入正确的模板id", 0);
  2085. }
  2086. if (empty($web)) {
  2087. return Result::error("请输入正确的网站id", 0);
  2088. }
  2089. $result = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['template_id' => $data['template_id'], 'action_id' => 2]);
  2090. if (empty($result)) {
  2091. return Result::error("添加失败", 0);
  2092. } else {
  2093. return Result::success($result);
  2094. }
  2095. }
  2096. /**
  2097. * 获取网站模板信息
  2098. * @param array $data
  2099. */
  2100. public function getWebsiteTemplateclassintel(array $data): array
  2101. {
  2102. // return Result::success($data);
  2103. $template = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  2104. if (empty($template)) {
  2105. return Result::error("请输入正确的搭建网站id", 0);
  2106. }
  2107. $page_type = json_decode($template['page_type'], true);
  2108. // 获取指定网站下的基础信息和模板及风格信息
  2109. $result = WebsiteTemplateInfo::where([
  2110. ['website_template_info.website_id', $data['website_id']],
  2111. ['website_template_info.template_id', '!=', null],
  2112. ])
  2113. ->leftJoin('template', 'template.id', 'website_template_info.template_id')
  2114. ->leftJoin('template_class', 'template_class.id', 'template.template_class_id')
  2115. ->where(function ($query) use ($page_type) {
  2116. // 假设 $data['page_type'] 是一个数组,包含需要匹配的 page_type 值
  2117. foreach ($page_type as $pageType) {
  2118. $query->orWhereJsonContains('template.template_img', ['value' => $pageType]);
  2119. }
  2120. })
  2121. ->select(
  2122. 'template.template_name',
  2123. 'template.template_img',
  2124. 'template.id as tid',
  2125. 'template_class.name',
  2126. 'template_class.id as class_id',
  2127. 'website_template_info.page_type',
  2128. 'website_template_info.website_id'
  2129. )
  2130. ->first();
  2131. if (empty($result)) {
  2132. return Result::error("没有查找到相关数据", 0);
  2133. }
  2134. // return Result::success($result);
  2135. // 过滤 template_img 字段 只获取 基础信息中 包含的模板图片
  2136. $template_img = $result['template_img'] !== null ? json_decode($result['template_img'], true) : [];
  2137. $page_type = $result['page_type'] !== null ? json_decode($result['page_type'], true) : [];
  2138. foreach ($template_img as $key => $value) {
  2139. if (!in_array($value['value'], $page_type)) {
  2140. unset($template_img[$key]);
  2141. }
  2142. }
  2143. // return Result::success($result);
  2144. $result['template_img'] = array_values($template_img);
  2145. $result['page_type'] = $page_type;
  2146. // $templateList = $this->getWebsiteTemplateList($data);
  2147. // $count = $templateList['data']['count']??'';
  2148. // $pages = $count / $data['pageSize'];
  2149. // $found = false;
  2150. // while ($pages && !$found) {
  2151. // $templates = $this->getWebsiteTemplateList($pages,$data['pageSize']);
  2152. // $index = array_search($template['template_id'], array_column($templates['rows'], 'id'));
  2153. // if ($index !== false) {
  2154. // $found = true;
  2155. // $result['page'] = $pages;
  2156. // $pages = 0;
  2157. // // echo "查询到的 template 在第 $page 页";
  2158. // }
  2159. // $pages--;
  2160. // }
  2161. return Result::success($result);
  2162. }
  2163. /**
  2164. * 获取网站模板下的板块信息
  2165. * @param array $data
  2166. */
  2167. public function getWebsiteSectorList(array $data): array
  2168. {
  2169. $website = Website::where('id', $data['website_id'])->first();
  2170. if (empty($website)) {
  2171. return Result::error("请输入正确的网站id", 0);
  2172. }
  2173. $template = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  2174. if (empty($template['template_id'])) {
  2175. return Result::error("请先添加网站模板", 0);
  2176. }
  2177. $query = Sector::where('template_id', $template['template_id']);
  2178. if ($query->count() == 0) {
  2179. return Result::error("没有查找到相关板块数据", 0);
  2180. } elseif ($query->count() == 1) {
  2181. $sector = $query->first();
  2182. } else {
  2183. $sector = $query->get();
  2184. }
  2185. $result['page_type'] = $template['page_type'];
  2186. $result['tid'] = $template['template_id'];
  2187. $result = [
  2188. "tid" => $template['template_id'],
  2189. "page_type" => $template['page_type'],
  2190. "sector" => $sector,
  2191. ];
  2192. return Result::success($result);
  2193. }
  2194. // 自助建站---------------fr---------------
  2195. // 网站底基础信息--fr-------------------
  2196. /**
  2197. * 添加网站底基础信息
  2198. * @param array $data
  2199. */
  2200. public function addWebFootInfo(array $data): array
  2201. {
  2202. $website = Website::where('id', $data['website_id'])->first();
  2203. if (empty($website)) {
  2204. return Result::error("请输入正确的网站id!", 0);
  2205. }
  2206. $info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  2207. if (!empty($info)) {
  2208. return Result::error("该网站已经添加过了!", 0);
  2209. }
  2210. $result = WebsiteTemplateInfo::where('website_id', $data['website_id'])->insertGetId($data);
  2211. if (empty($result)) {
  2212. return Result::error("请先添加网站基础信息!", 0);
  2213. } else {
  2214. return Result::success($result);
  2215. }
  2216. }
  2217. /**
  2218. * 获取网站底基础信息
  2219. * @param array $data
  2220. */
  2221. public function getWebFootInfo(array $data): array
  2222. {
  2223. $website = Website::where('id', $data['website_id'])->first();
  2224. if (empty($website)) {
  2225. return Result::error("请输入正确的网站id!", 0);
  2226. }
  2227. $result = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  2228. if (empty($result)) {
  2229. return Result::error("请先添加网站基础信息!", 0);
  2230. }
  2231. return Result::success($result);
  2232. }
  2233. /**
  2234. * 修改网站底基础信息
  2235. * @param array $data
  2236. */
  2237. public function upWebFootInfo(array $data): array
  2238. {
  2239. // return Result::success($data);
  2240. $website = Website::where('id', $data['website_id'])->first();
  2241. if (empty($website)) {
  2242. return Result::error("请输入正确的网站id!", 0);
  2243. }
  2244. $web = $data['website_id'];
  2245. unset($data['website_id']);
  2246. $where = ['website_id' => $web];
  2247. // return Result::success($data);
  2248. $result = WebsiteTemplateInfo::where($where)->first();
  2249. if (empty($result)) {
  2250. $data['website_id'] = $web;
  2251. $result = WebsiteTemplateInfo::insertGetId($data);
  2252. // return Result::error("请先添加网站基础信息!",0);
  2253. } else {
  2254. $result = WebsiteTemplateInfo::where($where)->update($data);
  2255. }
  2256. // $where = ['website_id'=>$data['website_id']];
  2257. // unset($data['website_id']);
  2258. // $result = WebsiteTemplateInfo::updateOrInsert($where, $data);
  2259. if (empty($result)) {
  2260. return Result::error("修改失败!", 0);
  2261. }
  2262. return Result::success($result);
  2263. }
  2264. /*
  2265. * 获取父级/子级栏目------路由
  2266. * @param array $data
  2267. * @return array
  2268. * */
  2269. public function getWebsiteParentCategory(array $data): array
  2270. {
  2271. // return Result::success($data);
  2272. if (isset($data['website_id']) && !empty($data['website_id'])) {
  2273. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  2274. }
  2275. if (empty($website)) {
  2276. return Result::error("暂无该网站", 0);
  2277. }
  2278. // 在 Hyperf 中,查询构建器(Builder)没有 `map` 方法,`map` 方法是集合(Collection)的方法。
  2279. // 因此,需要先调用 `get()` 方法获取查询结果集合,再使用 `map` 方法进行处理。
  2280. $category['parent'] = WebsiteCategory::where('website_id', $data['website_id'])
  2281. ->where('pid', 0)
  2282. ->selectRaw("category_id as cid, alias as name, CONCAT('/', '', aLIas_pinyin, '/') as path")
  2283. ->get() // 添加 get() 方法获取结果集合
  2284. ->all();
  2285. // 提前查询所有父级栏目,避免在 map 中多次查询
  2286. // 提前查询所有父级栏目信息并以 category_id 作为键存储
  2287. $parentCategories = WebsiteCategory::where('website_id', $data['website_id'])
  2288. ->where('pid', 0)
  2289. ->select('category_id', 'aLIas_pinyin')
  2290. ->get()
  2291. ->keyBy('category_id');
  2292. // 直接查询子栏目信息
  2293. $child = WebsiteCategory::where('website_id', $data['website_id'])
  2294. ->where('pid', '!=', 0)
  2295. ->select('alias', 'category_id', 'aLIas_pinyin', 'pid')
  2296. ->get();
  2297. // 使用集合的 map 方法处理子栏目信息
  2298. $category['child'] = $child->map(function ($item) use ($parentCategories) {
  2299. $alias = $item->alias;
  2300. $category_id = $item->category_id;
  2301. $aLIas_pinyin = $item->aLIas_pinyin;
  2302. $parent = $parentCategories->get($item->pid);
  2303. $parentAlias = $parent ? $parent->aLIas_pinyin : '';
  2304. $result = [
  2305. 'name' => $alias,
  2306. 'cid' => $category_id
  2307. ];
  2308. if (!empty($aLIas_pinyin) && !empty($parentAlias)) {
  2309. $result['path'] = "/{$parentAlias}/{$aLIas_pinyin}/";
  2310. }
  2311. return $result;
  2312. })->values()->all();
  2313. if (empty($category)) {
  2314. return Result::error("暂无此导航", 0);
  2315. }
  2316. return Result::success($category);
  2317. }
  2318. //20250212 网站标识
  2319. public function addWebsiteGroup(array $data): array
  2320. {
  2321. //判斷name是不是重复
  2322. $websiteGroupInfo = WebsiteGroup::query()->where('name', $data['name'])->first();
  2323. if (!empty($websiteGroupInfo)) {
  2324. return Result::error("网站标识重复", 0);
  2325. }
  2326. //添加信息
  2327. $result = WebsiteGroup::insertGetId($data);
  2328. var_dump($result);
  2329. if (empty($result)) {
  2330. return Result::error("创建失败", 0);
  2331. } else {
  2332. return Result::success($result);
  2333. }
  2334. }
  2335. public function getWebsiteGroupList(array $data): array
  2336. {
  2337. $where = [];
  2338. if (isset($data['name']) && !empty($data['name'])) {
  2339. array_push($where, ['website_group.name', 'like', '%' . $data['name'] . '%']);
  2340. }
  2341. $result = WebsiteGroup::where($where)
  2342. ->limit($data['pageSize'])->orderBy("id", "desc")->offset(($data['page'] - 1) * $data['pageSize'])
  2343. ->get();
  2344. foreach ($result as $websiteGroup) {
  2345. $webIds = json_decode($websiteGroup->web_ids, true);
  2346. $websites = Website::whereIn('id', $webIds)->get();
  2347. $websiteNames = $websites->pluck('website_name', 'id')->toArray();
  2348. $websiteGroup->website_names = $websiteNames;
  2349. $websiteGroup->website_names1 = implode(',', array_values($websiteNames));
  2350. }
  2351. $count = WebsiteGroup::where($where)->count();
  2352. if (empty($result)) {
  2353. return Result::error("没有数据", 0);
  2354. }
  2355. return Result::success(['list' => $result->toArray(), 'count' => $count]);
  2356. }
  2357. public function getWebsiteGroupInfo(array $data): array
  2358. {
  2359. $websiteInfo = WebsiteGroup::query()->where('id', $data['id'])->first();
  2360. $webIds = json_decode($websiteInfo->web_ids, true);
  2361. $websites = Website::whereIn('id', $webIds)->get();
  2362. $websiteNames = $websites->pluck('website_name', 'id')->toArray();
  2363. $websiteInfo->website_names = $websiteNames;
  2364. $websiteInfo->website_names1 = implode(',', array_values($websiteNames));
  2365. if (empty($websiteInfo)) {
  2366. return Result::error("找不到URL", 0);
  2367. }
  2368. return Result::success($websiteInfo->toArray());
  2369. }
  2370. public function updateWebsiteGroup(array $data): array
  2371. {
  2372. $where = [
  2373. 'id' => $data['id'],
  2374. ];
  2375. $insertData = [
  2376. 'name' => $data['name'],
  2377. 'web_ids' => $data['web_ids'],
  2378. ];
  2379. //判斷name是不是重复
  2380. $websiteGroupInfo = WebsiteGroup::query()->where('name', $data['name'])->first();
  2381. if (!empty($websiteGroupInfo) && $websiteGroupInfo->id != $data['id']) {
  2382. return Result::error("网站标识重复", 0);
  2383. }
  2384. $result = WebsiteGroup::where($where)->update($insertData);
  2385. var_dump($result, '------更新');
  2386. if (empty($result)) {
  2387. return Result::error("更新失败", 0);
  2388. } else {
  2389. return Result::success();
  2390. }
  2391. }
  2392. public function deleteWebsiteGroup(array $data): array
  2393. {
  2394. $where = [
  2395. 'id' => $data['id'],
  2396. ];
  2397. //看看user表是不是有这个id
  2398. $userGroup = User::query()->where('sszq', $data['id'])->first();
  2399. if (!empty($userGroup)) {
  2400. return Result::error("有用户在使用该网站标识,不能删除", 0);
  2401. }
  2402. $result = WebsiteGroup::where($where)->delete();
  2403. if (empty($result)) {
  2404. return Result::error("删除失败", 0);
  2405. } else {
  2406. return Result::success();
  2407. }
  2408. }
  2409. public function getWebsiteNavList(array $data): array
  2410. {
  2411. $data['type'] = isset($data['type']) ? $data['type'] : 1;
  2412. $where = [];
  2413. if (isset($data['website_id']) && !empty($data['website_id'])) {
  2414. array_push($where, ['website_id', '=', $data['website_id']]);
  2415. }
  2416. if (isset($data['pid'])) {
  2417. array_push($where, ['pid', '=', $data['pid']]);
  2418. }
  2419. if (isset($data['type']) && !empty($data['type'])) {
  2420. array_push($where, ['type', '=', $data['type']]);
  2421. }
  2422. // 根据站点和type获取websiteCategory 中的id
  2423. $websiteCategoryids = WebsiteCategory::query()
  2424. ->where('website_id', '=', $data['website_id'])
  2425. ->where('type', '=', $data['type'])
  2426. ->pluck('category_arr_id')->toArray();
  2427. var_dump($websiteCategoryids, '------获取websiteCategory 中的id');
  2428. //合并去重
  2429. $category_ids = [];
  2430. foreach ($websiteCategoryids as $key => $value) {
  2431. $v = json_decode($value, true);
  2432. $category_ids = array_unique(array_merge($category_ids, $v));
  2433. }
  2434. // var_dump($category_ids, '------获取websiteCategory 中的id');
  2435. $realList = WebsiteCategory::query()
  2436. ->where('website_id', '=', $data['website_id'])
  2437. ->where('is_url', '!=', 1)
  2438. ->where('real_pid', '=', $data['pid'])
  2439. ->select(
  2440. '*',
  2441. DB::raw('real_pid AS pid'),
  2442. DB::raw('real_category_arr_id AS category_arr_id')
  2443. )
  2444. ->whereIn('category_id', $category_ids)
  2445. ->get();
  2446. //根据pid取出所有的websiteCategory 中的id
  2447. $list = WebsiteCategory::query()
  2448. ->where('website_id', '=', $data['website_id'])
  2449. ->where('is_url', '!=', 1)
  2450. ->where('pid', '=', $data['pid'])
  2451. ->whereIn('category_id', $category_ids)
  2452. ->get();
  2453. $list = $list->merge($realList);
  2454. if (empty($list)) {
  2455. return Result::error("获取失败", 0);
  2456. } else {
  2457. return Result::success($list);
  2458. }
  2459. }
  2460. // 20250307 根据网站标识获和导航获取站点
  2461. public function getWebsiteNavPoolSite(array $data): array
  2462. {
  2463. $where = [];
  2464. if (isset($data['category_id']) && !empty($data['category_id'])) {
  2465. array_push($where, ['category_id', '=', $data['category_id']]);
  2466. }
  2467. if($data['article_id'] != 0){
  2468. $list = Article::where('article.id', $data['article_id'])
  2469. ->leftJoin('website_category', 'article.catid', '=', 'website_category.category_id')
  2470. // WebsiteCategory::query()->where($where)
  2471. ->leftJoin('website', 'website.id', '=', 'website_category.website_id')
  2472. ->leftJoinSub(function ($query) use ($data) {
  2473. $query->from('article_ignore')
  2474. ->where('article_ignore.article_id', $data['article_id']);
  2475. }, 'article_ignore', function ($join) {
  2476. $join->on('website_category.website_id', '=', 'article_ignore.website_id');
  2477. })
  2478. ->select('website_category.*', 'website.website_name', DB::raw('IFNULL(article_ignore.c_show_time, "") as c_show_time')) // 选择需要的字段,不存在记录时 c_show_time 为空字符串
  2479. ->distinct('website.website_name') // 使用DISTINCT关键字按website_name过滤重复数据
  2480. ->get();
  2481. // ->array_map(function ($item) {
  2482. // $item['c_show_time'] = json_decode($item['category_arr_id'], true);
  2483. // return $item;
  2484. // })
  2485. ;
  2486. }else{
  2487. $list = WebsiteCategory::query()->where($where)
  2488. ->leftJoin('website', 'website.id', '=', 'website_category.website_id')
  2489. ->select('website_category.*', 'website.website_name')
  2490. ->distinct()
  2491. ->get();
  2492. }
  2493. if (empty($list)) {
  2494. return Result::error("获取失败", 0);
  2495. } else {
  2496. return Result::success($list);
  2497. }
  2498. }
  2499. public function getWebsiteNavPool(array $data): array
  2500. {
  2501. // 初始化查询条件数组
  2502. $query = WebsiteCategory::query();
  2503. // 如果传入了 websiteids,则添加到查询条件中
  2504. if (isset($data['websiteids']) && !empty($data['websiteids'])) {
  2505. $query->whereIn('website_id', $data['websiteids']);
  2506. }
  2507. // 如果传入了 pid,则添加到查询条件中
  2508. if (isset($data['pid'])) {
  2509. $query->where('pid', '=', $data['pid']);
  2510. }
  2511. // 执行查询 唯一性 id
  2512. $list = $query->distinct()->get();
  2513. // 根据查询结果返回相应的结果
  2514. if ($list->isEmpty()) {
  2515. return Result::error("获取失败", 0);
  2516. } else {
  2517. return Result::success($list->toArray());
  2518. }
  2519. }
  2520. /**
  2521. *
  2522. * @param array $data
  2523. * @return array
  2524. */
  2525. public function getAllCategory(array $data): array
  2526. {
  2527. $total = Category::count();
  2528. $pageSize = 2000;
  2529. $pages = (int) ceil($total / $pageSize);
  2530. $results = [];
  2531. $concurrency = 5; // 最大并发数
  2532. $running = 0;
  2533. $chan = new \Swoole\Coroutine\Channel($pages);
  2534. for ($i = 0; $i < $pages; $i++) {
  2535. Coroutine::create(function () use ($i, $pageSize, $chan) {
  2536. $offset = $i * $pageSize;
  2537. $data = Category::useIndex('idx_covering')
  2538. ->orderBy('id', 'asc')
  2539. ->select('id', 'name', 'pid')
  2540. ->offset($offset)
  2541. ->limit($pageSize)
  2542. ->get()
  2543. ->toArray();
  2544. $chan->push($data);
  2545. });
  2546. }
  2547. for ($i = 0; $i < $pages; $i++) {
  2548. $res = $chan->pop();
  2549. if (is_array($res)) {
  2550. $results = array_merge($results, $res);
  2551. }
  2552. }
  2553. return Result::success($results);
  2554. }
  2555. /**
  2556. * 修改网站栏目排序
  2557. * @param array $data
  2558. * @return array
  2559. */
  2560. public function upWebsiteCategorySort(array $data): array
  2561. {
  2562. $where = [
  2563. 'website_id' => $data['website_id'],
  2564. 'id' => $data['id'],
  2565. ];
  2566. $result = WebsiteCategory::where($where)->update($data);
  2567. if ($result) {
  2568. return Result::success($result);
  2569. } else {
  2570. return Result::error("更新失败", 0);
  2571. }
  2572. }
  2573. //获取底部导航内容详情
  2574. public function getFooterContentInfo(array $data): array
  2575. {
  2576. $where = [
  2577. "id" => $data['content_id']
  2578. ];
  2579. $result = FooterContent::where($where)->first();
  2580. if ($result) {
  2581. return Result::success($result);
  2582. } else {
  2583. return Result::error("没有数据");
  2584. }
  2585. }
  2586. //获取底部导航内容列表
  2587. public function getFooterContentList(array $data): array
  2588. {
  2589. $where = [
  2590. "fcat_id" => $data['fcat_id'],
  2591. ];
  2592. switch (intval($data['type'])) {
  2593. case 0:
  2594. $result = FooterContent::where($where)->first();
  2595. break;
  2596. case 1:
  2597. $result = FooterContent::where($where)->get();
  2598. break;
  2599. }
  2600. if ($result) {
  2601. return Result::success($result);
  2602. } else {
  2603. return Result::error("没有数据");
  2604. }
  2605. }
  2606. /**
  2607. * 获取底部导航列表
  2608. * @param array $data
  2609. * @return array
  2610. */
  2611. public function getFooterCategoryList(array $data): array
  2612. {
  2613. $where = [
  2614. "website_id" => $data['website_id']
  2615. ];
  2616. $result = FooterCategory::where($where)->get();
  2617. if ($result) {
  2618. return Result::success($result);
  2619. } else {
  2620. return Result::error("没有数据");
  2621. }
  2622. }
  2623. // --自助建站-----------20250522fr----------------------start
  2624. /**
  2625. * 获取网站模板下的板块信息
  2626. * @param array $data
  2627. * @return array
  2628. */
  2629. public function getStaticResourceList(array $data): array
  2630. {
  2631. // return Result::success($data);
  2632. $where = [];
  2633. if (isset($data['img_alias']) && !empty($data['img_alias'])) {
  2634. array_push($where, ['website_img.img_alias', 'like', '%' . $data['img_alias'] . '%']);
  2635. }
  2636. if (isset($data['img_type']) && !empty($data['img_type'])) {
  2637. array_push($where, ['website_img.img_type', '=', $data['img_type']]);
  2638. }
  2639. if (isset($data['website_name']) && !empty($data['website_name'])) {
  2640. $website = Website::where('website_name', 'like', '%' . $data['website_name'] . '%')->first();
  2641. if (empty($website)) {
  2642. return Result::error("没有查找到相关数据", 0);
  2643. } else {
  2644. array_push($where, ['website_img.website_id', '=', $website['id']]);
  2645. }
  2646. }
  2647. // return Result::success($where);
  2648. $query = WebsiteImg::when(!empty($where), function ($query) use ($where) {
  2649. $query->where($where);
  2650. })
  2651. ->orderBy('updated_at', 'desc');
  2652. $count = $query->count();
  2653. $row = $query->leftJoin('website', 'website.id', '=', 'website_img.website_id')
  2654. ->select('website_img.*', 'website.website_name')
  2655. ->limit($data['pageSize'])
  2656. ->offset(($data['page'] - 1) * $data['pageSize'])
  2657. ->get();
  2658. if (empty($row)) {
  2659. return Result::error("没有查找到相关数据", 0);
  2660. } else {
  2661. $result = [
  2662. 'row' => $row,
  2663. 'count' => $count,
  2664. ];
  2665. }
  2666. return Result::success($result);
  2667. }
  2668. /**
  2669. * 添加网站模板下的板块信息
  2670. * @param array $data
  2671. */
  2672. public function addStaticResource(array $data): array
  2673. {
  2674. // $file = $data['img_url']->file('image');
  2675. // $size = $file->getSize();
  2676. $img_data = [
  2677. 'website_id' => $data['website_id'] ?? 0,
  2678. 'img_alias' => $data['img_alias'] ?? '',
  2679. 'img_url' => $data['img_url'],
  2680. 'img_size' => $data['img_size'],
  2681. ];
  2682. $img = WebsiteImg::insertGetId($img_data);
  2683. if (empty($img)) {
  2684. return Result::error("添加失败", 0);
  2685. }
  2686. $img_id['id'] = $img;
  2687. $url = WebsiteImg::where($img_id)->value('img_url');
  2688. // 1. 分割路径部分(以 / 为分隔符)
  2689. $pathSegments = explode('/', parse_url($url, PHP_URL_PATH));
  2690. // 2. 取最后一个元素作为文件名
  2691. $fileName = end($pathSegments); // 1743041040714597.jpg
  2692. // 3. 分割文件名获取扩展名
  2693. $fileParts = explode('.', $fileName);
  2694. $fileType = end($fileParts); // jpg
  2695. $img_datas = [
  2696. 'img_type' => $fileType,
  2697. 'name' => $fileName
  2698. ];
  2699. $up_img = WebsiteImg::where($img_id)->update($img_datas);
  2700. if (empty($up_img)) {
  2701. return Result::error("修改失败", 0);
  2702. }
  2703. return Result::success($img);
  2704. // 将字节转换为更友好的单位
  2705. // $friendlySize = $this->formatFileSize($size);
  2706. // $data['img_size'] = $friendlySize;
  2707. }
  2708. /**
  2709. * 修改网站模板下的板块信息
  2710. * @param array $data
  2711. */
  2712. public function delStaticResource(array $data): array
  2713. {
  2714. $where = [
  2715. 'id' => $data['id'],
  2716. ];
  2717. $result = WebsiteImg::where($where)->delete();
  2718. if (empty($result)) {
  2719. return Result::error("修改失败", 0);
  2720. }
  2721. return Result::success($result);
  2722. }
  2723. /**
  2724. * 获取尺寸列表
  2725. * @param array $data
  2726. */
  2727. public function getSizeList(array $data): array
  2728. {
  2729. $where = [];
  2730. if (isset($data['width']) && !empty($data['width'])) {
  2731. array_push($where, ['width', 'like', '%' . $data['width'] . '%']);
  2732. }
  2733. if (isset($data['height']) && !empty($data['height'])) {
  2734. array_push($where, ['height', 'like', '%' . $data['height'] . '%']);
  2735. }
  2736. $query = Size::when($where, function ($query) use ($where) {
  2737. $query->where($where);
  2738. })
  2739. ->orderBy('updated_at', 'desc');
  2740. $count = $query->count();
  2741. $rep = $query
  2742. ->offset(($data['page'] - 1) * $data['pageSize'])
  2743. ->limit($data['pageSize'])
  2744. ->get();
  2745. $result = [
  2746. 'row' => $rep,
  2747. 'count' => $count,
  2748. ];
  2749. if (empty($result)) {
  2750. return Result::error("获取失败", 0);
  2751. } else {
  2752. return Result::success($result);
  2753. }
  2754. }
  2755. /**
  2756. * 添加尺寸
  2757. * @param array $data
  2758. */
  2759. public function addSize(array $data): array
  2760. {
  2761. $size = Size::where('width', $data['width'])->where('height', $data['height'])->first();
  2762. if (!empty($size)) {
  2763. return Result::error("尺寸已存在", 0);
  2764. }
  2765. $result = Size::insertGetId($data);
  2766. if (empty($result)) {
  2767. return Result::error("添加失败", 0);
  2768. }
  2769. return Result::success($result);
  2770. }
  2771. /**
  2772. * 删除尺寸
  2773. * @param array $data
  2774. */
  2775. public function delSize(array $data): array
  2776. {
  2777. $where = [
  2778. 'id' => $data['id'],
  2779. ];
  2780. $result = Size::where($where)->delete();
  2781. if (empty($result)) {
  2782. return Result::error("删除失败", 0);
  2783. }
  2784. return Result::success($result);
  2785. }
  2786. /**
  2787. * 修改尺寸
  2788. * @param array $data
  2789. */
  2790. public function upSize(array $data): array
  2791. {
  2792. $where = [
  2793. 'id' => $data['id'],
  2794. ];
  2795. $size = Size::where('id', '!=', $data['id'])->where('width', $data['width'])->where('height', $data['height'])->first();
  2796. if (!empty($size)) {
  2797. return Result::error("尺寸已存在", 0);
  2798. }
  2799. $result = Size::where($where)->update($data);
  2800. if (empty($result)) {
  2801. return Result::error("修改失败", 0);
  2802. }
  2803. return Result::success($result);
  2804. }
  2805. /**
  2806. * 获取尺寸详情
  2807. * @param array $data
  2808. */
  2809. public function getSizeInfo(array $data): array
  2810. {
  2811. $where = [
  2812. 'id' => $data['id'],
  2813. ];
  2814. $result = Size::where($where)->first();
  2815. if (empty($result)) {
  2816. return Result::error("获取失败", 0);
  2817. } else {
  2818. return Result::success($result);
  2819. }
  2820. }
  2821. /**
  2822. * 获取网站名称缩写
  2823. * @param array $data
  2824. */
  2825. public function getWebsiteAdkey(array $data): array
  2826. {
  2827. $result = PinyinHelper::getFirstLetter($data['website_name']);
  2828. if (empty($result)) {
  2829. return Result::error("没有数据", 0);
  2830. } else {
  2831. return Result::success($result);
  2832. }
  2833. }
  2834. /**
  2835. * 静态资源管理-修改图片别名
  2836. * @param array $data
  2837. */
  2838. public function upStaticResource(array $data): array
  2839. {
  2840. $id = $data['id'];
  2841. unset($data['id']);
  2842. if(isset($data['img_url']) && !empty($data['img_url'])){
  2843. $url = $data['img_url'];
  2844. // 1. 分割路径部分(以 / 为分隔符)
  2845. $pathSegments = explode('/', parse_url($url, PHP_URL_PATH));
  2846. // 2. 取最后一个元素作为文件名
  2847. $fileName = end($pathSegments); // 1743041040714597.jpg
  2848. // 3. 分割文件名获取扩展名
  2849. $fileParts = explode('.', $fileName);
  2850. $fileType = end($fileParts); // jpg
  2851. $data['img_type'] = $fileType;
  2852. $data['name'] = $fileName;
  2853. }
  2854. $result = WebsiteImg::where('id', $id)->update($data);
  2855. if (empty($result)) {
  2856. return Result::error("修改失败", 0);
  2857. }
  2858. return Result::success($result);
  2859. }
  2860. /**
  2861. * 自助建站-修改网站应用状态
  2862. * @param array $data
  2863. */
  2864. public function upWebsiteStatus(array $data): array
  2865. {
  2866. $where = [
  2867. 'website_id' => $data['website_id'],
  2868. ];
  2869. $website_template = WebsiteTemplate::where($where)->first();
  2870. unset($data['website_id']);
  2871. // if($data['status'] == 2){
  2872. // $template_status = 6;
  2873. // }else{
  2874. // $template_status = 1;
  2875. // }
  2876. if (empty($website_template)) {
  2877. return Result::error("网站预制模板获取失败", 0);
  2878. } else {
  2879. // Db::beginTransaction();
  2880. // try {
  2881. // $result['website_template'] = WebsiteTemplate::where($where)->update(['status'=>$template_status]);
  2882. // if (empty($result['website_template'])) {
  2883. // return Result::error("修改网站模板状态失败", 0);
  2884. // }
  2885. $result['website_template_info'] = WebsiteTemplateInfo::where($where)->update(['status' => $data['status']]);
  2886. if (empty($result['website_template_info'])) {
  2887. return Result::error("修改网站基础信息状态失败", 0);
  2888. }
  2889. // Db::commit();
  2890. return Result::success($result);
  2891. // } catch (\Exception $e) {
  2892. // Db::rollBack();
  2893. // return Result::error($e->getMessage(), 0);
  2894. // }
  2895. }
  2896. }
  2897. // --自助建站-----------20250522fr----------------------end
  2898. /**
  2899. * 获取网站白名单路由地址
  2900. * @param array $data
  2901. * @return array
  2902. */
  2903. public function getWhiteRouterList(array $data): array
  2904. {
  2905. // 构建基础查询
  2906. $baseQuery = WhiteRouter::query();
  2907. // 功能名称模糊查询
  2908. if (!empty($data['function_name'])) {
  2909. $baseQuery->where('function_name', 'like', '%' . $data['function_name'] . '%');
  2910. }
  2911. // 网站ID查询 - 使用 JSON_CONTAINS 检查数组中是否包含指定的 website_id
  2912. if (!empty($data['website_id'])) {
  2913. $baseQuery->whereRaw('JSON_CONTAINS(website_id, ?)', [json_encode((int)$data['website_id'])]);
  2914. }
  2915. // 获取总数
  2916. $count = $baseQuery->count();
  2917. // 分页查询
  2918. $result = $baseQuery->orderBy('updated_at', 'desc')
  2919. ->limit($data['pageSize'])
  2920. ->offset(($data['page'] - 1) * $data['pageSize'])
  2921. ->get();
  2922. if (empty($result)) {
  2923. return Result::error("暂无数据", 0);
  2924. }
  2925. // 处理结果,将 website_id 转换为数组并获取对应的网站名称
  2926. $result->transform(function ($item) {
  2927. $websiteIds = json_decode($item->website_id, true);
  2928. $websiteNames = Website::whereIn('id', $websiteIds)
  2929. ->pluck('website_name')
  2930. ->toArray();
  2931. $item->website_names = $websiteNames;
  2932. $item->website_id = $websiteIds; // 将 website_id 转换为数组
  2933. return $item;
  2934. });
  2935. return Result::success([
  2936. 'rows' => $result->toArray(),
  2937. 'count' => $count
  2938. ]);
  2939. }
  2940. /**
  2941. * 添加网站白名单路由地址
  2942. * @param array $data
  2943. * @return array
  2944. */
  2945. public function addWhiteRouter(array $data): array
  2946. {
  2947. // 确保 website_id 是数组
  2948. $websiteIds = is_array($data['website_id']) ? $data['website_id'] : [$data['website_id']];
  2949. // 过滤空值并去重
  2950. $websiteIds = array_filter($websiteIds);
  2951. $websiteIds = array_unique($websiteIds);
  2952. // 将数组中的值转换为整数
  2953. $websiteIds = array_map(function ($value) {
  2954. return (int)$value;
  2955. }, $websiteIds);
  2956. // 转换为 JSON 字符串存储
  2957. $data['website_id'] = json_encode($websiteIds);
  2958. $result = WhiteRouter::insertGetId($data);
  2959. if (empty($result)) {
  2960. return Result::error("添加失败", 0);
  2961. }
  2962. return Result::success($result);
  2963. }
  2964. /**
  2965. * 修改网站白名单路由地址
  2966. * @param array $data
  2967. * @return array
  2968. */
  2969. public function upWhiteRouter(array $data): array
  2970. {
  2971. $where = [
  2972. 'id' => $data['id'],
  2973. ];
  2974. // 确保 website_id 是数组
  2975. $websiteIds = is_array($data['website_id']) ? $data['website_id'] : [$data['website_id']];
  2976. // 过滤空值并去重
  2977. $websiteIds = array_filter($websiteIds);
  2978. $websiteIds = array_unique($websiteIds);
  2979. // 将数组中的值转换为整数
  2980. $websiteIds = array_map(function ($value) {
  2981. return (int)$value;
  2982. }, $websiteIds);
  2983. // 转换为 JSON 字符串存储
  2984. $data['website_id'] = json_encode($websiteIds);
  2985. $result = WhiteRouter::where($where)->update($data);
  2986. if (empty($result)) {
  2987. return Result::error("修改失败", 0);
  2988. }
  2989. return Result::success($result);
  2990. }
  2991. /**
  2992. * 删除网站白名单路由地址
  2993. * @param array $data
  2994. * @return array
  2995. */
  2996. public function delWhiteRouter(array $data): array
  2997. {
  2998. $where = [
  2999. 'id' => $data['id'],
  3000. ];
  3001. $result = WhiteRouter::where($where)->delete();
  3002. if (empty($result)) {
  3003. return Result::error("删除失败", 0);
  3004. }
  3005. return Result::success($result);
  3006. }
  3007. /**
  3008. * 获取网站白名单路由地址详情
  3009. * @param array $data
  3010. * @return array
  3011. */
  3012. public function getWhiteRouterInfo(array $data): array
  3013. {
  3014. $where = [
  3015. 'id' => $data['id'],
  3016. ];
  3017. $result = WhiteRouter::where($where)->first();
  3018. if (empty($result)) {
  3019. return Result::error("没有查找到相关数据", 0);
  3020. }
  3021. // 将 website_id 从 JSON 字符串转换为数组
  3022. $result->website_id = json_decode($result->website_id, true);
  3023. return Result::success($result);
  3024. }
  3025. /**
  3026. * 克隆网站
  3027. * @param array $data
  3028. * @return array
  3029. */
  3030. public function cloneWebsite(array $data): array
  3031. {
  3032. DB::beginTransaction();
  3033. try {
  3034. // 获取原始网站信息
  3035. $originalWebsite = Website::find($data['website_id']);
  3036. if (!$originalWebsite) {
  3037. return Result::error("找不到该网站", 0);
  3038. }
  3039. // 提取基础名称(去除已有 _copy 或 _copy_xxx)
  3040. $baseName = preg_replace('/_copy(\d+)?$/', '', $originalWebsite->website_name);
  3041. // 查询当前系统中已存在的克隆名称数量
  3042. $count = Website::where('website_name', 'like', $baseName . '_copy%')
  3043. ->orWhere('website_name', $baseName)
  3044. ->count();
  3045. // 构造新名称:第一次是 _copy,之后是 _copy_1, _copy_2 ...
  3046. $newName = $baseName . ($count === 0 ? '_copy' : '_copy_' . $count);
  3047. // 创建克隆网站实例
  3048. $clone_website = $originalWebsite->replicate();
  3049. $clone_website->website_name = $newName;
  3050. $clone_website->save();
  3051. $clone_website->website_url = "[]";
  3052. $clone_website->save();
  3053. // var_dump("返回值:",$clone_website->id);
  3054. //克隆网站基础信息 website_template_info website_category
  3055. $resultWebsiteTemplateInfo = WebsiteTemplateInfo::where(['website_id' => $data['website_id']])->first();
  3056. $clone_website_template_info = $resultWebsiteTemplateInfo->replicate();
  3057. $clone_website_template_info->status = 0;
  3058. $clone_website_template_info->action_id = 0;
  3059. $clone_website_template_info->website_id = $clone_website->id;
  3060. $clone_website_template_info->save();
  3061. //克隆网站导航 获取原始 website_id 对应的所有 WebsiteCategory 记录
  3062. $originalCategories = WebsiteCategory::where('website_id', $data['website_id'])->get();
  3063. // 克隆网站后的新 ID(假设 $clone_website->id 已存在)
  3064. $newWebsiteId = $clone_website->id;
  3065. if ($originalCategories && count($originalCategories) > 0) {
  3066. // 遍历每条记录并克隆
  3067. foreach ($originalCategories as $category) {
  3068. // 使用 replicate() 方法创建模型副本(不包含主键)
  3069. $clonedCategory = $category->replicate();
  3070. // 修改外键字段指向新网站 ID
  3071. $clonedCategory->website_id = $newWebsiteId;
  3072. // 保存克隆后的记录到数据库
  3073. $clonedCategory->save();
  3074. }
  3075. }
  3076. //克隆友情链接 Link 对应的是多个
  3077. $originalLinks = Link::where('website_id', $data['website_id'])->get();
  3078. if ($originalLinks && count($originalLinks) > 0) {
  3079. foreach ($originalLinks as $link) {
  3080. // 使用 replicate() 方法创建模型副本(不包含主键)
  3081. $clonedLink = $link->replicate();
  3082. // 修改外键字段指向新网站 ID
  3083. $clonedLink->website_id = $newWebsiteId;
  3084. // 保存克隆后的记录到数据库
  3085. $clonedLink->save();
  3086. }
  3087. }
  3088. //克隆网站底部信息 footer_category 表 和footer_content 表 footer_category.id = footer_content.fcat_id 都是一对多关系
  3089. $originalFooterCategories = FooterCategory::where('website_id', $data['website_id'])->get();
  3090. if ($originalFooterCategories && count($originalFooterCategories) > 0) {
  3091. foreach ($originalFooterCategories as $footerCategory) {
  3092. $clonedFooterCategory = $footerCategory->replicate();
  3093. $clonedFooterCategory->website_id = $newWebsiteId;
  3094. $clonedFooterCategory->save();
  3095. $originalFooterContents = FooterContent::where('fcat_id', $footerCategory->id)->get();
  3096. if ($originalFooterContents && count($originalFooterContents) > 0) {
  3097. foreach ($originalFooterContents as $footerContent) {
  3098. $clonedFooterContent = $footerContent->replicate();
  3099. $clonedFooterContent->fcat_id = $clonedFooterCategory->id;
  3100. $clonedFooterContent->save();
  3101. }
  3102. }
  3103. }
  3104. }
  3105. Db::commit();
  3106. return Result::success([]);
  3107. } catch (\Exception $e) {
  3108. Db::rollBack();
  3109. return Result::error($e->getMessage(), 0);
  3110. }
  3111. }
  3112. /**
  3113. * 更新网站状态
  3114. * @param array $data
  3115. * @return array
  3116. */
  3117. public function updateWebsiteStatus(array $data): array
  3118. {
  3119. try {
  3120. Website::where(["id" => $data['id']])->update(["status" => intval($data['status'])]);
  3121. return Result::success([]);
  3122. } catch (\Exception $e) {
  3123. return Result::error($e->getMessage(), 0);
  3124. }
  3125. }
  3126. /**
  3127. * 删除网站url
  3128. * @param array $data
  3129. * @return array
  3130. */
  3131. public function delWebsiteUrl(array $data): array
  3132. {
  3133. try {
  3134. $wensiteInfo = Website::where(["id" => $data['website_id']])->first();
  3135. if (empty($wensiteInfo)) {
  3136. return Result::error("找不到该网站", 0);
  3137. }
  3138. $websiteUrlArray = [];
  3139. if (!empty($wensiteInfo->website_url)) {
  3140. $decoded = json_decode((string) $wensiteInfo->website_url, true);
  3141. $websiteUrlArray = is_array($decoded) ? $decoded : [];
  3142. }
  3143. // 从数组中按值删除对应的 URL
  3144. $index = array_search($data['website_url'] ?? null, $websiteUrlArray, true);
  3145. if ($index !== false) {
  3146. unset($websiteUrlArray[$index]);
  3147. // 重新索引,保持为连续的 JSON 数组
  3148. $websiteUrlArray = array_values($websiteUrlArray);
  3149. }
  3150. $newWebsiteUrlJson = json_encode($websiteUrlArray, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
  3151. Website::where(["id" => $data['website_id']])->update(["website_url" => $newWebsiteUrlJson]);
  3152. return Result::success([]);
  3153. } catch (\Exception $e) {
  3154. return Result::error($e->getMessage(), 0);
  3155. }
  3156. }
  3157. public function checkPath(array $data): array
  3158. {
  3159. var_dump("检查路径");
  3160. // return Result::success([]);
  3161. // website_category查找相同path的数据,返回那些数据重复了
  3162. // 查找所有具有相同path的重复记录
  3163. $duplicatePaths = WebsiteCategory::select('path', DB::raw('COUNT(*) as count'))
  3164. ->where('website_id', $data['website_id'])
  3165. ->groupBy('path')
  3166. ->havingRaw('COUNT(*) > 1')
  3167. ->get();
  3168. if ($duplicatePaths->isEmpty()) {
  3169. return Result::success([]);
  3170. }
  3171. // 获取所有重复记录的详细信息
  3172. $duplicateRecords = [];
  3173. foreach ($duplicatePaths as $duplicatePath) {
  3174. $records = WebsiteCategory::where(['path' => $duplicatePath->path])
  3175. ->where('website_id', $data['website_id'])
  3176. ->orderBy('id')
  3177. ->get();
  3178. $duplicateRecords[] = [
  3179. 'path' => $duplicatePath->path,
  3180. 'count' => $duplicatePath->count,
  3181. 'records' => $records
  3182. ];
  3183. }
  3184. return Result::success($duplicateRecords);
  3185. }
  3186. /**
  3187. * 获取栏目
  3188. * @param array $data
  3189. * @return array
  3190. */
  3191. public function getWebsiteModelCategory(array $data): array
  3192. {
  3193. // return Result::success($data);
  3194. $website_id = [
  3195. 'website_id' => $data['website_id'],
  3196. ];
  3197. $website_column_arr = Website::where('id', $data['website_id'])->value('website_column_arr_id');
  3198. if (empty($website_column_arr)) {
  3199. return Result::error("未查询到此网站所属网系!", 0);
  3200. }
  3201. $website_column_arr = json_decode($website_column_arr, true);
  3202. // return Result::success(!in_array(3,$website_column_arr) && $data['pid'] == 0);
  3203. // 初始化 $pid 数组
  3204. // $pid = [];
  3205. // 以下注释掉的代码是之前的逻辑,用于获取非顶级分类的 pid
  3206. $pidQuery = WebsiteCategory::where($website_id)
  3207. ->where('pid', '!=', 0)
  3208. ->orderBy('sort')
  3209. ->select('pid', 'category_id', 'alias', 'aLIas_pinyin');
  3210. $pid = $pidQuery->pluck('pid');
  3211. $pid = array_values(array_unique($pid->toArray()));
  3212. // 构建查询语句
  3213. $query = WebsiteCategory::where($website_id)
  3214. ->when(!in_array(3, $website_column_arr) && $data['pid'] == 0, function ($query) use ($website_column_arr) {
  3215. $query->where('is_show', 1);
  3216. })
  3217. ->when(in_array(3, $website_column_arr) || $data['pid'] != 0, function ($query) use ($data) {
  3218. $query->where('pid', $data['pid']);
  3219. })
  3220. ->offset($data['placeid'])
  3221. ->limit($data['num'])
  3222. ->orderBy('sort')
  3223. ->orderBy('updated_at', 'desc');
  3224. // 如果 $pid 数组不为空,添加 CASE WHEN 条件
  3225. if (!empty($pid)) {
  3226. $placeholders = implode(',', array_fill(0, count($pid), '?'));
  3227. $query->selectRaw("website_category.*, CASE WHEN website_category.category_id IN ($placeholders) THEN 1 ELSE 0 END AS children_count", $pid);
  3228. } else {
  3229. // 如果 $pid 数组为空,不添加 CASE WHEN 条件,添加字段 children_count 并赋值为 0
  3230. $query->select('website_category.*', DB::raw('0 as children_count'));
  3231. }
  3232. // 执行查询
  3233. $placeid = $data['placeid'] - 1;
  3234. $result = $query->offset($placeid)->limit($data['num'])->get();
  3235. if (!empty($result)) {
  3236. $pidResults = $pidQuery->get();
  3237. if (isset($data['type']) && $data['type'] == 1) {
  3238. $result = $result->map(function ($item) use ($pidResults) {
  3239. $children = $pidResults->where('pid', $item->category_id)->map(function ($child) {
  3240. if (!empty($child)) {
  3241. return $child;
  3242. }
  3243. });
  3244. // 重置索引,使 key 值从 0 开始
  3245. $item->children = $children->values();
  3246. return $item;
  3247. });
  3248. } else {
  3249. $pidMap = $pidResults->keyBy('pid');
  3250. $result->each(function ($record) use ($pidMap, $data) {
  3251. if ($data['pid'] == 0) {
  3252. $record->aLIas_pinyin = $record->path;
  3253. }
  3254. // $record->aLIas_pinyin = $record->path;
  3255. if ($pidMap->has($record->category_id)) {
  3256. $pidResult = $pidMap->get($record->category_id);
  3257. $record->chilid_id = $pidResult->category_id;
  3258. $record->chilid_alias = $pidResult->alias;
  3259. // $record->aLIas_pinyin = $pidResult->aLIas_pinyin;
  3260. }
  3261. });
  3262. }
  3263. return Result::success($result);
  3264. } else {
  3265. return Result::error("本网站暂无栏目", 0);
  3266. }
  3267. }
  3268. /**
  3269. * 获取网站栏目信息
  3270. * @param array $data
  3271. */
  3272. public function getWebsiteFootAll(array $data): array
  3273. {
  3274. if(!isset($data['is_diyweb']) || empty($data['is_diyweb'])){
  3275. $website = Website::where('id',$data['website_id'])->where('status',1)->first();
  3276. }else{
  3277. $website = Website::where('id',$data['website_id'])->first();
  3278. }
  3279. if (empty($website)) {
  3280. return Result::error("暂无该网站", 0);
  3281. }
  3282. // 1:图片 2:文字 3:底部
  3283. $result['foot_cate'] = FooterCategory::where('website_id', $data['website_id'])->get()->all();
  3284. $result['link_img'] = Link::where('website_id', $data['website_id'])->where('type', 1)->where('status', 1)->limit($data['link_imgnum'])->orderBy('sort')->get()->all();
  3285. $result['link_text'] = Link::where('website_id', $data['website_id'])->where('type', 2)->where('status', 1)->limit($data['link_textnum'])->orderBy('sort')->get()->all();
  3286. $result['link_foot'] = Link::where('website_id', $data['website_id'])->where('type', 3)->where('status', 1)->limit($data['link_footnum'])->orderBy('sort')->get()->all();
  3287. $result['foot_info'] = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  3288. if (empty($result)) {
  3289. return Result::error("暂无此网站信息", 0);
  3290. }
  3291. return Result::success($result);
  3292. }
  3293. }