WebsiteService.php 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161
  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\WebsiteRole;
  18. use App\Model\WebsiteRoleUser;
  19. use App\Model\Website;
  20. use App\Model\WebsiteColumn;
  21. use Hyperf\DbConnection\Db;
  22. use Hyperf\RpcServer\Annotation\RpcService;
  23. use App\Tools\Result;
  24. use Carbon\Carbon;
  25. use App\Model\WebsiteCategory;
  26. use App\Model\WebsiteTemplate;
  27. use App\Model\Sector;
  28. use PhpParser\Node\Stmt\Return_;
  29. use function PHPUnit\Framework\isNull;
  30. #[RpcService(name: "WebsiteService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  31. class WebsiteService implements WebsiteServiceInterface
  32. {
  33. /**
  34. * @param string $keyword
  35. * @param int $page
  36. * @param int $pageSize
  37. * @return array
  38. */
  39. public function getWebsitetList(array $data): array
  40. {
  41. $where = [];
  42. if(isset($data['keyword']) && !empty($data['keyword'])){
  43. array_push($where,['website.website_name','like','%'.$data['keyword'].'%']);
  44. }
  45. if(isset($data['website_column_id']) && !empty($data['website_column_id'])){
  46. array_push($where,['website.website_column_id','=',$data['website_column_id']]);
  47. }
  48. if(isset($data['city_id']) && !empty($data['city_id'])){
  49. array_push($where,['website.city_id','=',$data['city_id']]);
  50. }
  51. $result = Website::where($where)
  52. ->leftJoin("website_column","website.website_column_id","website_column.id")
  53. ->leftJoin("district","district.id","website.city_id")
  54. ->select("website.*","website_column.column_name","district.name as city_name")
  55. ->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])->orderBy("website.id","desc")->get();
  56. $count = Website::where($where)->count();
  57. if (empty($result)) {
  58. return Result::error("没有数据",0);
  59. }
  60. $data = [
  61. 'rows'=>$result->toArray(),
  62. 'count'=>$count
  63. ];
  64. return Result::success($data);
  65. }
  66. /**
  67. * @param array $data
  68. * @return array
  69. */
  70. public function createWebsite(array $data): array
  71. {
  72. var_dump("网站数据:",$data);
  73. $insertData = [
  74. 'website_name'=>$data['website_name'],
  75. 'logo'=>$data['logo']??'',
  76. 'website_url'=>$data['website_url']??'',
  77. 'city_id'=>$data['city_id']??0,
  78. 'website_column_id'=>$data['website_column_id'],
  79. 'title'=>$data['title']??'',
  80. 'keywords'=>$data['keywords']??'',
  81. 'description'=>$data['description']??'',
  82. 'status'=>$data['status']??0,
  83. 'website_column_arr_id'=>$data['website_column_arr_id'],
  84. 'city_arr_id'=>$data['city_arr_id']??[0],
  85. 'template_id' =>$data['template_id']??0,
  86. ];
  87. $result = Website::insertGetId($insertData);
  88. if(empty($result)){
  89. return Result::error("创建失败",0);
  90. }else{
  91. return Result::success(["id"=>$result]);
  92. }
  93. }
  94. /**
  95. * @param int $id
  96. * @param array $data
  97. * @return array
  98. */
  99. public function updateWebsite(int $id,array $data): array
  100. {
  101. $insertData = [
  102. 'website_name'=>$data['website_name'],
  103. 'logo'=>$data['logo']??'',
  104. 'website_url'=>$data['website_url']??'',
  105. 'city_id'=>$data['city_id']??0,
  106. 'website_column_id'=>$data['website_column_id'],
  107. 'title'=>$data['title']??'',
  108. 'keywords'=>$data['keywords']??'',
  109. 'description'=>$data['description']??'',
  110. 'status'=>$data['status']??0,
  111. 'website_column_arr_id'=>$data['website_column_arr_id'],
  112. 'city_arr_id'=>$data['city_arr_id']??[0],
  113. 'template_id' =>$data['template_id']??0,
  114. ];
  115. $result = Website::where('id',$id)->update($insertData);
  116. var_dump("更新站点",$result);
  117. if(empty($result)){
  118. return Result::error("更新失败",0);
  119. }else{
  120. return Result::success();
  121. }
  122. }
  123. /**
  124. * @param int $id
  125. * @return array
  126. */
  127. public function delWebsite(int $id): array
  128. {
  129. $result = Website::where('id',$id )->delete();
  130. if(empty($result)){
  131. return Result::error("删除失败",0);
  132. }else{
  133. return Result::success();
  134. }
  135. }
  136. /**
  137. * @param int $id
  138. * @return array
  139. */
  140. public function getWebsiteInfo(int $id): array
  141. {
  142. $where = [
  143. ['website.id','=',$id]
  144. ];
  145. $result = Website::where($where )
  146. ->leftJoin("template","template.id","website.template_id")
  147. ->select("website.*","template.template_name","template.template_img")
  148. ->first();
  149. if(empty($result)){
  150. return Result::error("数据不存在",0);
  151. }else{
  152. return Result::success($result->toArray());
  153. }
  154. }
  155. /**
  156. * 查询所有的站点栏目
  157. * @return array
  158. */
  159. public function getWebsiteColumn(array $data): array
  160. {
  161. $result = WebsiteColumn::where($data)->get();
  162. if(empty($result)){
  163. return Result::error("数据不存在",0);
  164. }else{
  165. return Result::success($result->toArray());
  166. }
  167. }
  168. /**
  169. * @param string $keyword
  170. * @param int $page
  171. * @param int $pageSize
  172. * @return array
  173. */
  174. public function getWebsiteColumnList(array $data):array
  175. {
  176. $where = [];
  177. if(isset($data['keyword']) && $data['keyword']){
  178. array_push($where,['website_column.column_name','like','%'.$data['keyword'].'%']);
  179. }
  180. $result = WebsiteColumn::where($where)
  181. ->leftJoin("website_column as wc","website_column.pid","wc.id")
  182. ->select("website_column.*","wc.column_name as parent_column_name")
  183. ->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])->get();
  184. $count = WebsiteColumn::where($where)->count();
  185. if (empty($result)) {
  186. return Result::error("没有数据",0);
  187. }
  188. $data = [
  189. 'rows'=>$result->toArray(),
  190. 'count'=>$count
  191. ];
  192. return Result::success($data);
  193. }
  194. /**
  195. * @param array $data
  196. * @return array
  197. */
  198. public function createWebsiteColumn(array $data): array
  199. {
  200. $insertData = [
  201. 'column_name'=>$data['column_name'],
  202. 'pid'=>$data['pid']??'',
  203. 'column_arr_id'=>$data['column_arr_id']??[0],
  204. 'sort'=>$data['sort']??0,
  205. 'remark'=>$data['remark']??'',
  206. ];
  207. $result = WebsiteColumn::insertGetId($insertData);
  208. if(empty($result)){
  209. return Result::error("创建失败",0);
  210. }else{
  211. return Result::success(["id"=>$result]);
  212. }
  213. }
  214. /**
  215. * @param int $id
  216. * @param array $data
  217. * @return array
  218. */
  219. public function updateWebsiteColumn(int $id,array $data): array
  220. {
  221. $insertData = [
  222. 'column_name'=>$data['column_name'],
  223. 'pid'=>$data['pid']??'',
  224. 'column_arr_id'=>$data['column_arr_id']??[0],
  225. 'sort'=>$data['sort']??0,
  226. 'remark'=>$data['remark']??'',
  227. ];
  228. $result = WebsiteColumn::where('id',$id)->update($insertData);
  229. if(empty($result)){
  230. return Result::error("更新失败",0);
  231. }else{
  232. return Result::success();
  233. }
  234. }
  235. /**
  236. * @param int $id
  237. * @return array
  238. */
  239. public function delWebsiteColumn(int $id): array
  240. {
  241. $list = WebsiteColumn::where(['pid'=>$id])->get();
  242. if($list){
  243. return Result::error("存在子网系,不能删除,请先删除子网系",0);
  244. }
  245. $result = WebsiteColumn::where('id',$id )->delete();
  246. if(empty($result)){
  247. return Result::error("删除失败",0);
  248. }else{
  249. return Result::success();
  250. }
  251. }
  252. /**
  253. * @param string $keyword
  254. * @param int $page
  255. * @param int $pageSize
  256. * @return array
  257. */
  258. public function getWebsiteRoleList(string $keyword,int $page,int $pageSize,int $websiteId):array
  259. {
  260. $where = [
  261. ['role.role_name','like','%'.$keyword.'%'],
  262. ['website_role.website_id','=',$websiteId],
  263. ];
  264. $result = WebsiteRole::where($where)
  265. ->leftJoin("role","role.id","website_role.role_id")
  266. ->select("role.*","website_role.type","website_role.role_id","website_role.id as website_role_id","website_role.website_id")
  267. ->limit($pageSize)->offset(($page-1)*$pageSize)->get();
  268. $count = WebsiteRole::where($where) ->leftJoin("role","role.id","website_role.role_id")->count();
  269. if (empty($result)) {
  270. return Result::error("没有数据",0);
  271. }
  272. $data = [
  273. 'rows'=>$result->toArray(),
  274. 'count'=>$count
  275. ];
  276. return Result::success($data);
  277. }
  278. /**
  279. * @param array $data
  280. * @return array
  281. */
  282. public function createWebsiteRole(array $data): array
  283. {
  284. $insertData = [
  285. 'website_id'=>$data['website_id'],
  286. 'role_id'=>$data['role_id']??''
  287. ];
  288. $info = WebsiteRole::where($insertData)->first();
  289. if($info){
  290. return Result::error("不能重复添加角色",0);
  291. }
  292. $insertData['admin_user_id'] = $data['admin_user_id']??'';
  293. $insertData['type'] = $data['type']??'';
  294. $result = WebsiteRole::insertGetId($insertData);
  295. if(empty($result)){
  296. return Result::error("创建失败",0);
  297. }else{
  298. return Result::success(["id"=>$result]);
  299. }
  300. }
  301. /**
  302. * 暂时用不上
  303. * @param int $id
  304. * @param array $data
  305. * @return array
  306. */
  307. public function updateWebsiteRole(int $id,array $data): array
  308. {
  309. $insertData = [
  310. 'website_id'=>$data['website_id'],
  311. 'type'=>$data['type']??'',
  312. ];
  313. $result = WebsiteRole::where('id',$id)->update($insertData);
  314. if(empty($result)){
  315. return Result::error("更新失败",0);
  316. }else{
  317. return Result::success();
  318. }
  319. }
  320. /**
  321. * @param int $id
  322. * @return array
  323. */
  324. public function delWebsiteRole(int $id): array
  325. {
  326. $result = WebsiteRole::where('id',$id )->delete();
  327. if(empty($result)){
  328. return Result::error("删除失败",0);
  329. }else{
  330. return Result::success();
  331. }
  332. }
  333. /**
  334. * @param string $keyword
  335. * @param int $page
  336. * @param int $pageSize
  337. * @return array
  338. */
  339. public function getWebsiteRoleUserList(string $keyword,int $page,int $pageSize,int $websiteId,int $roleId):array
  340. {
  341. $where = [
  342. ['website_role_user.website_id','=',$websiteId],
  343. ['website_role_user.role_id','=',$roleId],
  344. ];
  345. $count = WebsiteRoleUser::where($where)->count();
  346. $where[] = ['u.user_name','like','%'.$keyword.'%'];
  347. $result = WebsiteRoleUser::where($where)
  348. ->leftJoin("user as u","website_role_user.user_id","u.id")
  349. ->leftJoin("website as w","website_role_user.website_id","u.id")
  350. ->leftJoin("role as r","website_role_user.role_id","r.id")
  351. ->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')
  352. ->limit($pageSize)->offset(($page-1)*$pageSize)->get();
  353. if (empty($result)) {
  354. return Result::error("没有数据",0);
  355. }
  356. $data = [
  357. 'rows'=>$result->toArray(),
  358. 'count'=>$count
  359. ];
  360. return Result::success($data);
  361. }
  362. /**
  363. * @param array $data
  364. * @return array
  365. */
  366. public function createWebsiteRoleUser(array $data): array
  367. {
  368. $insertData = [
  369. 'website_id'=>$data['website_id'],
  370. 'user_id'=>$data['user_id']??'',
  371. ];
  372. $info = WebsiteRoleUser::where($insertData)->first();
  373. if($info){
  374. return Result::error("不能重复添加角色用户",0);
  375. }
  376. $insertData['role_id'] = $data['role_id']??'';
  377. $insertData['admin_user_id'] = $data['admin_user_id']??'';
  378. $insertData['type'] = $data['type']??'';
  379. $result = WebsiteRoleUser::insertGetId($insertData);
  380. if(empty($result)){
  381. return Result::error("创建失败",0);
  382. }else{
  383. return Result::success(["id"=>$result]);
  384. }
  385. }
  386. /**
  387. * @param int $id
  388. * @param array $data
  389. * @return array
  390. */
  391. public function updateWebsiteRoleUser(int $id,array $data): array
  392. {
  393. $insertData = [
  394. 'website_id'=>$data['website_id'],
  395. 'type'=>$data['type']??'',
  396. 'type_id'=>$data['type_id']??'',
  397. 'role_id'=>$data['role_id']??'',
  398. ];
  399. $result = WebsiteRoleUser::where('id',$id)->update($insertData);
  400. if(empty($result)){
  401. return Result::error("更新失败",0);
  402. }else{
  403. return Result::success();
  404. }
  405. }
  406. /**
  407. * @param int $id
  408. * @return array
  409. */
  410. public function delWebsiteRoleUser(int $id): array
  411. {
  412. $result = WebsiteRoleUser::where('id',$id )->delete();
  413. if(empty($result)){
  414. return Result::error("删除失败",0);
  415. }else{
  416. return Result::success();
  417. }
  418. }
  419. /**
  420. * 根据域名获取网站 站点id
  421. * @param array $data
  422. * @return array
  423. */
  424. public function getWebsiteId(array $data): array
  425. {
  426. $result = Website::whereJsonContains('website_url',$data['website_url'])->first();
  427. if(empty($result)){
  428. return Result::error("查询站点失败",0);
  429. }else{
  430. return Result::success($result);
  431. }
  432. }
  433. /**
  434. * 查询网站下面的导航
  435. * @param array $data
  436. * @return array
  437. */
  438. public function getWebsiteCategory(array $data): array
  439. {
  440. $where = [
  441. 'website_id'=>$data['website_id']
  442. ];
  443. // 使用递归查询构建树状结构
  444. $category = WebsiteCategory::where($where)
  445. ->with([
  446. 'children' => function ($query) {
  447. $query->orderBy('sort', 'asc');
  448. }
  449. ])
  450. ->orderBy('sort', 'asc')
  451. ->where('pid', 0) // 仅查询顶级节点
  452. ->get()->all();
  453. if(empty($category)){
  454. return Result::error("查询站点栏目失败",0);
  455. }else{
  456. $count = WebsiteCategory::where($where)->count();
  457. $result = [
  458. 'rep' => $category,
  459. 'count' => $count
  460. ];
  461. return Result::success($result);
  462. }
  463. }
  464. /**
  465. * 查询网站的广告
  466. * @param array $data
  467. * @return array
  468. */
  469. public function getWebsiteAdvertisement(array $data): array
  470. {
  471. $where = [
  472. 'ad_place.status' => 1,
  473. ];
  474. if(isset($data['ad_tag']) && !empty($data['ad_tag'])){
  475. $now = Carbon::now()->format('Y-m-d H:i:s'); // 获取当前时间
  476. $where[] = ['ad_place.ad_tag','like','%'.$data['ad_tag'].'%'];
  477. // return Result::success($where);
  478. $result = AdPlace::where($where)
  479. ->leftJoin("ad", function ($join) use ($now) {
  480. $join->on("ad.pid", "=", "ad_place.id")
  481. ->where('ad.status', 1)
  482. ->where('ad.fromtime', '<=', $now)
  483. ->where('ad.totime', '>=', $now);
  484. })
  485. ->select(
  486. 'ad_place.name as place_name',
  487. 'ad_place.thumb',
  488. 'ad_place.ad_tag',
  489. 'ad_place.introduce',
  490. 'ad.name as ad_name',
  491. 'ad.image_src',
  492. 'ad.image_url',
  493. 'ad.image_alt')
  494. ->get()->all();
  495. if(empty($result)){
  496. return Result::error("此广告位不存在!",0);
  497. }
  498. }else{
  499. return Result::error("请选择广告位!",0);
  500. }
  501. return Result::success($result);
  502. }
  503. /**
  504. *
  505. * @param array $data
  506. * @return array
  507. */
  508. /**网站行政职能搜索 */
  509. public function selectWebsiteDepartment(array $data): array
  510. {
  511. $depart = Department::where('pid',0)->orderBy('id','asc')->get();
  512. if(isset($data['keyword']) && !empty($data['keyword'])){
  513. $departments= Department::where('name', 'like', '%' . $data['keyword'] . '%')->get();
  514. if(empty($departments)){
  515. $result['message']="未查询到与此相关职能部门";
  516. }else{
  517. $count = Department::where('name','like',"%{$data['keyword']}%")->count();
  518. $m = [
  519. 'department'=>$depart,
  520. 'type'=>$departments,
  521. 'count'=>$count
  522. ];
  523. }
  524. $result['sele'] = $m;
  525. return Result::success($result['sele']);
  526. }
  527. $result=$depart;
  528. return Result::success($result);
  529. }
  530. /**
  531. * 搜索地区
  532. * @param array $data
  533. * @return array
  534. */
  535. public function selectWebsiteArea(array $data): array
  536. {
  537. // return Result::success($data);
  538. $pid = $data['pid'] ?? 0;
  539. $result = District::where('pid',$pid)->where('status',1)->orderBy('code')->get();
  540. if(empty($result)){
  541. return Result::error("未查询到此地区",0);
  542. }else{
  543. return Result::success($result);
  544. }
  545. }
  546. /**
  547. * 获取栏目
  548. * @param array $data
  549. * @return array
  550. */
  551. public function getWebsiteModelCategory(array $data): array
  552. {
  553. // return Result::success($data);
  554. $website_id=[
  555. 'website_id' => $data['website_id']
  556. ];
  557. // 初始化 $pid 数组
  558. // $pid = [];
  559. // 以下注释掉的代码是之前的逻辑,用于获取非顶级分类的 pid
  560. $pidQuery = WebsiteCategory::where($website_id)
  561. ->where('pid', '!=', 0)
  562. ->orderBy('sort')
  563. ->select('pid','category_id','alias');
  564. $pid = $pidQuery->pluck('pid');
  565. $pid = array_values(array_unique($pid->toArray()));
  566. // 构建查询语句
  567. $query = WebsiteCategory::where($website_id)
  568. ->where('pid', $data['pid'])
  569. ->offset($data['placeid'])
  570. ->limit($data['num'])
  571. ->orderBy('sort');
  572. // 如果 $pid 数组不为空,添加 CASE WHEN 条件
  573. if (!empty($pid)) {
  574. $placeholders = implode(',', array_fill(0, count($pid), '?'));
  575. $query->selectRaw("website_category.*, CASE WHEN website_category.category_id IN ($placeholders) THEN 1 ELSE 0 END AS children_count", $pid);
  576. } else {
  577. // 如果 $pid 数组为空,不添加 CASE WHEN 条件,添加字段 children_count 并赋值为 0
  578. $query->select('website_category.*', DB::raw('0 as children_count'));
  579. }
  580. // 执行查询
  581. $placeid = $data['placeid']-1;
  582. $result = $query->offset($placeid)->limit($data['num'])->get();
  583. if (!empty($result)) {
  584. $pidResults = $pidQuery->get();
  585. $pidMap = $pidResults->keyBy('pid');
  586. $result->each(function ($record) use ($pidMap) {
  587. if ($pidMap->has($record->category_id)) {
  588. $pidResult = $pidMap->get($record->category_id);
  589. $record->chilid_id = $pidResult->category_id;
  590. $record->chilid_alias = $pidResult->alias;
  591. }
  592. });
  593. return Result::success($result);
  594. } else {
  595. return Result::error("本网站暂无栏目", 0);
  596. }
  597. }
  598. /**
  599. * 获取友情链接
  600. * @param array $data
  601. * @return array
  602. */
  603. public function selectWebsiteLinks(array $data): array
  604. {
  605. $where = [
  606. 'website_id' => $data['website_id'],
  607. 'status' => 1,
  608. 'type' => $data['type']
  609. ];
  610. $num=$data['num'];
  611. $result=Link::where($where)->orderBy('sort')->limit($num)->get();
  612. if(!empty($result)){
  613. return Result::success($result);
  614. }else{
  615. return Result::error("本网站暂无此类型友情链接",0);
  616. }
  617. }
  618. /**
  619. * 网站首页数据统计, 管理员
  620. * @return void
  621. */
  622. public function getAdminIndex(array $data): array
  623. {
  624. var_dump("用户类型:",$data['type_id']);
  625. switch ($data['type_id']){
  626. case 4:
  627. $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;');
  628. return Result::success($result);
  629. break;
  630. case 10000:
  631. $res = [];
  632. //网站
  633. $res['website']['count'] = 0;
  634. $res['website']['growth_rate'] = 0;
  635. //资讯
  636. $res['article']['count'] = 0;
  637. $res['article']['growth_rate'] = 0;
  638. //导航池
  639. $res['category']['count'] = 0;
  640. $res['category']['growth_rate'] = 0;
  641. //近一月数据
  642. $res['monthArticle']= [];
  643. //用户类型
  644. $res['userType'] = [];
  645. $res['website']['count'] = Website::where([])->count();
  646. $res['article']['count'] = Article::whereNotIn('status',['404'])->count();
  647. $res['category']['count'] = Category::where([])->count();
  648. $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;');
  649. $res['userType'] = User::where([])->selectRaw("count(*) as counts,type_id")->groupBy('type_id')->get();
  650. return Result::success($res);
  651. }
  652. return [];
  653. }
  654. /**
  655. * 获取模板类型
  656. * @return void
  657. */
  658. public function getTemplateClass(array $data): array
  659. {
  660. $where = [];
  661. if(isset($data['name']) && $data['name']){
  662. array_push($where,['name','like','%'.$data['name'].'%']);
  663. }
  664. $result = TemplateClass::where($where)->orderBy('sort','asc')->get();
  665. if(empty($result)){
  666. return Result::error("没有模板类型",0);
  667. }else{
  668. return Result::success($result);
  669. }
  670. }
  671. /**
  672. * 添加模板类型
  673. * @param
  674. * @return void
  675. */
  676. public function addTemplateClass(array $data): array
  677. {
  678. $insertData = [
  679. 'name'=>$data['name']
  680. ];
  681. $result = TemplateClass::insertGetId($insertData);
  682. if(empty($result)){
  683. return Result::error("创建失败",0);
  684. }else{
  685. return Result::success(["id"=>$result]);
  686. }
  687. }
  688. /**
  689. * 更新模板
  690. * @param array $data
  691. * @return array
  692. */
  693. public function upTemplateClass(array $data): array
  694. {
  695. $where = [
  696. 'id'=>$data['id']
  697. ];
  698. $insertData = [
  699. 'name'=>$data['name']
  700. ];
  701. $result = TemplateClass::where($where)->update($insertData);
  702. if(empty($result)){
  703. return Result::error("更新失败",0);
  704. }else{
  705. return Result::success();
  706. }
  707. }
  708. /**
  709. * 删除模板
  710. * @param array $data
  711. * @return array
  712. */
  713. public function delTemplateClass(array $data): array
  714. {
  715. $where = [
  716. 'id'=>$data['id']
  717. ];
  718. $result = TemplateClass::where($where)->delete();
  719. if(empty($result)){
  720. return Result::error("删除失败",0);
  721. }else{
  722. return Result::success();
  723. }
  724. }
  725. /**
  726. * 获取分类下的模板
  727. * @param array $data
  728. * @return array
  729. */
  730. public function getTemplate(array $data): array
  731. {
  732. $page = $data['page'];
  733. $pageSize = $data['pageSize'];
  734. $where = [];
  735. if(isset($data['template_class_id']) && $data['template_class_id']){
  736. array_push($where,['template_class_id','=',$data['template_class_id']]);
  737. }
  738. $result = Template::where($where)
  739. ->limit($pageSize)->offset(($page-1)*$pageSize)->get();
  740. $count = Template::where($where)->count();
  741. if (empty($result)) {
  742. return Result::error("没有数据",0);
  743. }
  744. $data = [
  745. 'rows'=>$result->toArray(),
  746. 'count'=>$count
  747. ];
  748. return Result::success($data);
  749. }
  750. /**
  751. * 创建模板
  752. * @param
  753. * @return void
  754. */
  755. public function addTemplate(array $data): array
  756. {
  757. $insertData = [
  758. 'template_name'=>$data['template_name'],
  759. 'template_img'=>json_encode($data['template_img']),
  760. 'template_class_id'=>$data['template_class_id'],
  761. ];
  762. $result = Template::insertGetId($insertData);
  763. if(empty($result)){
  764. return Result::error("创建模板失败",0);
  765. }else{
  766. return Result::success(["id"=>$result]);
  767. }
  768. }
  769. /**
  770. * 更新模板
  771. * @param array $data
  772. * @return array
  773. */
  774. public function upTemplate(array $data): array
  775. {
  776. $where = [
  777. 'id'=>$data['id']
  778. ];
  779. $insertData = [
  780. 'template_name'=>$data['template_name'],
  781. 'template_img'=>json_encode($data['template_img']),
  782. 'template_class_id'=>$data['template_class_id'],
  783. ];
  784. $result = Template::where($where)->update($insertData);
  785. if(empty($result)){
  786. return Result::error("更新模板失败",0);
  787. }else{
  788. return Result::success();
  789. }
  790. }
  791. /**
  792. * 删除模板
  793. * @param array $data
  794. * @return array
  795. */
  796. public function delTemplate(array $data): array
  797. {
  798. $where = [
  799. 'id'=>$data['id']
  800. ];
  801. $result = Template::where($where)->delete();
  802. if(empty($result)){
  803. return Result::error("删除模板失败",0);
  804. }else{
  805. return Result::success();
  806. }
  807. }
  808. /**
  809. * 搜索网站
  810. * @param array $data
  811. * @return array
  812. */
  813. public function websiteList(array $data): array
  814. {
  815. $where = [];
  816. if(isset($data['keyword']) && !empty($data['keyword'])){
  817. array_push($where,['website.website_name','like','%'.$data['keyword'].'%']);
  818. }
  819. $result = Website::where($where)->get();
  820. if($result){
  821. return Result::success($result);
  822. }else{
  823. return Result::error("没有网站",0);
  824. }
  825. }
  826. public function addWebsiteCategory(array $data): array
  827. {
  828. $website_id = $data['website_id'];
  829. $category_arr_id = $data['category_arr_id'];
  830. $categoryList = Category::whereIn('id',$category_arr_id)->get();
  831. $categoryListIds = [];
  832. if($categoryList){
  833. foreach ($categoryList->toArray() as $val){
  834. array_push($categoryListIds,$val['id']);
  835. }
  836. }
  837. $arr = [];
  838. if($categoryListIds){
  839. foreach ($categoryListIds as $v){
  840. $ids = $this->getUnderlingUIds(intval($v));
  841. $ids_arr = explode(",", $ids);
  842. array_push($arr,$ids_arr);
  843. }
  844. }
  845. $mergedArray = [];
  846. foreach ($arr as $subarray) {
  847. $mergedArray = array_merge($mergedArray, $subarray);
  848. }
  849. var_dump("所有:",$arr,$mergedArray);
  850. //查询出所有的分类进行分割插入 组装数据
  851. $categoryListData = Category::whereIn('id',$mergedArray)->get();
  852. $categoryListData = $categoryListData->toArray();
  853. $insertData = [];
  854. if($categoryListData){
  855. foreach ($categoryListData as $key=>$value){
  856. $insertData[$key]['website_id'] = $website_id;
  857. $insertData[$key]['name'] = $value['name'];
  858. $insertData[$key]['sort'] = $value['sort'];
  859. $insertData[$key]['pid'] = $value['pid'];
  860. $insertData[$key]['pid_arr'] = $value['pid_arr'];
  861. $insertData[$key]['seo_title'] = $value['seo_title'];
  862. $insertData[$key]['seo_keywords'] = $value['seo_keywords'];
  863. $insertData[$key]['seo_description'] = $value['seo_description'];
  864. $insertData[$key]['alias'] = $value['name'];
  865. $insertData[$key]['category_id'] = $value['id'];
  866. }
  867. }
  868. $result = WebsiteCategory::insert($insertData);
  869. var_dump("插入数据状态:",$result);
  870. if($result){
  871. return Result::success($result);
  872. }else{
  873. return Result::error("创建失败",0);
  874. }
  875. }
  876. /**
  877. * 删除网站导航
  878. * @param array $data
  879. * @return array
  880. */
  881. public function delWebsiteCategory(array $data): array
  882. {
  883. $website_id = $data['website_id']??0;
  884. $category_id = $data['category_id']??0;
  885. $ids = $this->getUnderlingUIds(intval($category_id));
  886. $ids_arr = explode(",", $ids);
  887. $result = WebsiteCategory::where(['website_id'=>$website_id])->whereIn("category_id",$ids_arr)->delete();
  888. if($result){
  889. return Result::success($result);
  890. }else{
  891. return Result::error("删除失败",0);
  892. }
  893. }
  894. /**
  895. * 获取网站导航
  896. * @param array $data
  897. * @return array
  898. */
  899. public function getAdminWebsiteCategory(array $data): array
  900. {
  901. $where = [
  902. 'website_id'=>$data['website_id'],
  903. 'pid'=>0
  904. ];
  905. $result = WebsiteCategory::where($where)->get();
  906. if($result){
  907. return Result::success($result);
  908. }else{
  909. return Result::error("查询失败",0);
  910. }
  911. }
  912. /**
  913. * 更新网站导航
  914. * @param array $data
  915. * @return array
  916. */
  917. public function upWebsiteCategory(array $data): array
  918. {
  919. Db::beginTransaction();
  920. try{
  921. //合并栏目id
  922. $reqIds = array_merge($data['old_category_arr_id'],$data['new_category_arr_id']);
  923. //对比old 数组差异化,把差异化的删除
  924. $result = WebsiteCategory::where(['website_id'=>$data['website_id'],'pid'=>0])->get();
  925. $result = $result->toArray();
  926. $categoryIds = [];
  927. if($result){
  928. foreach ($result as $val){
  929. array_push($categoryIds,$val['category_id']);
  930. }
  931. }
  932. //和原始数据对比取交际
  933. $reqidsIntersect = array_intersect($reqIds,$categoryIds);
  934. //再取差集 进行对比
  935. $differenceIDS = array_merge(array_diff($reqidsIntersect, $categoryIds),array_diff($categoryIds,$reqidsIntersect));
  936. var_dump("差集:",$differenceIDS);
  937. $arr_ids = [];
  938. if(count($differenceIDS)>0){
  939. foreach ($differenceIDS as $vv){
  940. $idV = $this->getUnderlingUIds(intval($vv));
  941. $ids_arrV = explode(",", $idV);
  942. array_push($arr_ids,$ids_arrV);
  943. }
  944. }
  945. $del_ids = array_reduce($arr_ids, 'array_merge', array());
  946. //有差异 删除
  947. if(count($del_ids)>0){
  948. WebsiteCategory::where(['website_id'=>$data['website_id']])->whereIn("category_id",$del_ids)->delete();
  949. }
  950. //传过来的值 和 交际 对比,选出要添加的值 进行插入
  951. $insertIDS = array_merge(array_diff($reqIds, $reqidsIntersect),array_diff($reqidsIntersect,$reqIds));
  952. var_dump("要存储的:",$insertIDS);
  953. //新的数组重新创建
  954. if(count($insertIDS)>0){
  955. $arr = [];
  956. $categoryListIds = $insertIDS;
  957. if($categoryListIds){
  958. foreach ($categoryListIds as $v){
  959. $ids = $this->getUnderlingUIds(intval($v));
  960. $ids_arr = explode(",", $ids);
  961. array_push($arr,$ids_arr);
  962. }
  963. }
  964. $mergedArray = [];
  965. foreach ($arr as $subarray) {
  966. $mergedArray = array_merge($mergedArray, $subarray);
  967. }
  968. var_dump("要插入的ID:",$mergedArray);
  969. //查询出所有的分类进行分割插入 组装数据
  970. $categoryListData = Category::whereIn('id',$mergedArray)->get();
  971. $categoryListData = $categoryListData->toArray();
  972. $insertData = [];
  973. if($categoryListData){
  974. foreach ($categoryListData as $key=>$value){
  975. $insertData[$key]['website_id'] = $data['website_id'];
  976. $insertData[$key]['name'] = $value['name'];
  977. $insertData[$key]['sort'] = $value['sort'];
  978. $insertData[$key]['pid'] = $value['pid'];
  979. $insertData[$key]['pid_arr'] = $value['pid_arr'];
  980. $insertData[$key]['seo_title'] = $value['seo_title'];
  981. $insertData[$key]['seo_keywords'] = $value['seo_keywords'];
  982. $insertData[$key]['seo_description'] = $value['seo_description'];
  983. $insertData[$key]['alias'] = $value['name'];
  984. $insertData[$key]['category_id'] = $value['id'];
  985. }
  986. }
  987. WebsiteCategory::insert($insertData);
  988. }
  989. Db::commit();
  990. } catch(\Throwable $ex){
  991. Db::rollBack();
  992. var_dump($ex->getMessage());
  993. return Result::error("修改失败",0);
  994. }
  995. return Result::success();
  996. }
  997. /**
  998. * 获取网站列表
  999. * @param array $data
  1000. * @return array
  1001. */
  1002. public function getWebsiteCategoryList(array $data): array
  1003. {
  1004. $where = [];
  1005. if(isset($data['keyword']) && !empty($data['keyword'])){
  1006. array_push($where,['website.website_name','like','%'.$data['keyword'].'%']);
  1007. }
  1008. if(isset($data['website_column_id']) && !empty($data['website_column_id'])){
  1009. array_push($where,['website.website_column_id','=',$data['website_column_id']]);
  1010. }
  1011. $result = Website::where($where)
  1012. ->with(["websiteCategory"=>function ($query) {
  1013. $query->where(['pid'=>0])->select('website_id','name','alias','category_id');
  1014. }])
  1015. ->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])
  1016. ->get();
  1017. $count = Website::where($where)->count();
  1018. if (empty($result)) {
  1019. return Result::error("没有数据",0);
  1020. }
  1021. $data = [
  1022. 'rows'=>$result->toArray(),
  1023. 'count'=>$count
  1024. ];
  1025. if($result){
  1026. return Result::success($data);
  1027. }else{
  1028. return Result::error("查询失败",0);
  1029. }
  1030. }
  1031. /**
  1032. * 删除网站下的所有导航
  1033. * @param array $data
  1034. * @return array
  1035. */
  1036. public function delWebsiteAllCategory(array $data): array
  1037. {
  1038. $website_id = $data['website_id'];
  1039. $result = WebsiteCategory::where(['website_id'=>$website_id])->delete();
  1040. if($result){
  1041. return Result::success($result);
  1042. }else{
  1043. return Result::error("删除失败",0);
  1044. }
  1045. }
  1046. /**
  1047. * 获取网站下的某一个导航
  1048. * @param array $data
  1049. * @return array
  1050. */
  1051. public function getWebsiteCategoryOnes(array $data): array
  1052. {
  1053. $website_id = $data['website_id'];
  1054. $category_id = $data['category_id'];
  1055. $result = WebsiteCategory::where(['website_category.website_id'=>$website_id,'website_category.category_id'=>$category_id])
  1056. ->first();
  1057. if($result){
  1058. return Result::success($result);
  1059. }else{
  1060. return Result::error("查询失败",0);
  1061. }
  1062. }
  1063. /**
  1064. * 更新网闸下的某一个导航
  1065. * @param array $data
  1066. * @return array
  1067. */
  1068. public function upWebsiteCategoryones(array $data): array
  1069. {
  1070. $where = [
  1071. 'website_id'=>$data['website_id'],
  1072. 'category_id'=>$data['category_id'],
  1073. ];
  1074. $result = WebsiteCategory::where($where)->update($data);
  1075. if($result){
  1076. return Result::success($result);
  1077. }else{
  1078. return Result::error("更新失败",0);
  1079. }
  1080. }
  1081. /**
  1082. * 获取网站下的所有导航(包含子导航)
  1083. * @param array $data
  1084. * @return array
  1085. */
  1086. public function getWebsiteAllCategory(array $data): array
  1087. {
  1088. $where = [];
  1089. if(isset($data['website_id']) && !empty($data['website_id'])){
  1090. array_push($where,['website_category.website_id','=',$data['website_id']]);
  1091. }
  1092. if(isset($data['name']) && !empty($data['name'])){
  1093. array_push($where,['website_category.name','like','%'.$data['name'].'%']);
  1094. }
  1095. if(isset($data['alias']) && !empty($data['alias'])){
  1096. array_push($where,['website_category.alias','like','%'.$data['alias'].'%']);
  1097. }
  1098. if(isset($data['department_id']) && !empty($data['department_id'])){
  1099. array_push($where,['category.department_id','=',$data['department_id']]);
  1100. }
  1101. if(isset($data['city_id']) && !empty($data['city_id'])){
  1102. array_push($where,['category.city_id','=',$data['city_id']]);
  1103. }
  1104. $result = WebsiteCategory::where($where)
  1105. ->leftJoin("category",'website_category.category_id','category.id')
  1106. ->leftJoin("department",'category.department_id','department.id')
  1107. ->leftJoin("district",'category.city_id','district.id')
  1108. ->select("website_category.*","department.name as department_name","district.name as city_name")
  1109. ->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])
  1110. ->get();
  1111. $count = WebsiteCategory::where($where)
  1112. ->leftJoin("category",'website_category.category_id','category.id')
  1113. ->leftJoin("department",'category.department_id','department.id')
  1114. ->leftJoin("district",'category.city_id','district.id')
  1115. ->count();
  1116. if (empty($result)) {
  1117. return Result::error("没有数据",0);
  1118. }
  1119. $data = [
  1120. 'rows'=>$result->toArray(),
  1121. 'count'=>$count
  1122. ];
  1123. if($result){
  1124. return Result::success($data);
  1125. }else{
  1126. return Result::error("查询失败",0);
  1127. }
  1128. if($result){
  1129. return Result::success($result);
  1130. }else{
  1131. return Result::error("查询失败",0);
  1132. }
  1133. }
  1134. /**
  1135. * 递归查询数据
  1136. * @param $id
  1137. * @param $ids
  1138. * @return string
  1139. */
  1140. public function getUnderlingUIds($id, $ids='')
  1141. {
  1142. $back = Category::where(['pid'=>$id])->get();
  1143. $back = $back->toArray();
  1144. if (!empty($back) && is_array($back)) {
  1145. foreach ($back as $v) {
  1146. //防止当前人的ID重复去查询,形成恶性循环
  1147. if ($v['id'] == $id) {
  1148. continue;
  1149. }
  1150. $back2 = Category::where(['pid'=>$id])->count('id');
  1151. if ($back2 > 0) {
  1152. $ids = $this->getUnderlingUIds($v['id'],$ids);
  1153. } else {
  1154. $ids .= ','.$v['id'];
  1155. }
  1156. }
  1157. }
  1158. $ids = $id.','.$ids.',';
  1159. $ids = str_replace(',,', ",", $ids);
  1160. $ids = trim($ids, ',');
  1161. return $ids;
  1162. }
  1163. /**
  1164. * 检测网站名称是否重复
  1165. * @param array $data
  1166. * @return array
  1167. */
  1168. public function checkWebsiteName(array $data): array
  1169. {
  1170. if(isset($data['id'])){
  1171. $data[] = ['id',"!=",$data['id']];
  1172. unset($data['id']);
  1173. }
  1174. $websiteInfo = Website::query()->where($data)->first();
  1175. if (empty($websiteInfo)) {
  1176. return Result::error("找不到网站",0);
  1177. }
  1178. return Result::success($websiteInfo->toArray());
  1179. }
  1180. /**
  1181. * 检测网站url是否重复
  1182. * @param array $data
  1183. * @return array
  1184. */
  1185. public function checkWebsiteUrl(array $data): array
  1186. {
  1187. $whereData = [];
  1188. if(isset($data['id'])){
  1189. $whereData = [['id',"!=",$data['id']]];
  1190. unset($data['id']);
  1191. }
  1192. $websiteInfo = Website::query()->where($whereData)->whereJsonContains('website_url', $data['website_url'])->first();
  1193. if (empty($websiteInfo)) {
  1194. return Result::error("找不到URL",0);
  1195. }
  1196. return Result::success($websiteInfo->toArray());
  1197. }
  1198. /**
  1199. * 获取网站底部基础信息
  1200. * @param array $data
  1201. * @return array
  1202. */
  1203. public function getWebsiteFootInfo(array $data): array
  1204. {
  1205. if(isset($data['website_id']) && !empty($data['website_id'])){
  1206. $website_head = Website::where('id',$data['website_id'])
  1207. ->where('status',1)
  1208. ->select('id', 'website_name', 'logo', 'title', 'keywords', 'description', 'suffix', 'website_url')
  1209. ->first();
  1210. if (empty($website_head)) {
  1211. return Result::error("找不到网站",0);
  1212. }
  1213. }else{
  1214. return Result::error("参数错误",0);
  1215. }
  1216. $website_foot = WebsiteTemplateInfo::where('website_id',$data['website_id'])->first();
  1217. if (empty($website_foot)) {
  1218. return Result::error("暂无底部基础信息",0);
  1219. }
  1220. $website_head['website_url'] = $website_head['website_url'] ? json_decode($website_head['website_url']) : [];
  1221. $result = [
  1222. 'website_foot'=>$website_foot,
  1223. 'website_head'=>$website_head
  1224. ];
  1225. return Result::success($result);
  1226. }
  1227. /**
  1228. * 获取网站底部导航
  1229. * @param array $data
  1230. * @return array
  1231. */
  1232. public function getWebsiteFooterCategory(array $data): array
  1233. {
  1234. if(isset($data['website_id']) && !empty($data['website_id'])){
  1235. $website = Website::where('id',$data['website_id'])->where('status',1)->first();
  1236. if (empty($website)) {
  1237. return Result::error("找不到网站",0);
  1238. }
  1239. }else{
  1240. return Result::error("参数错误",0);
  1241. }
  1242. $result = FooterCategory::where('website_id',$data['website_id'])->get();
  1243. if (empty($result)) {
  1244. return Result::error("暂无底部导航",0);
  1245. }
  1246. return Result::success($result->toArray());
  1247. }
  1248. /**
  1249. * 获取网站底部导航列表
  1250. * @param array $data
  1251. * @return array
  1252. */
  1253. public function getWebsiteFooterCategoryList(array $data): array
  1254. {
  1255. if(isset($data['website_id']) && !empty($data['website_id'])){
  1256. $website = Website::where('id',$data['website_id'])->where('status',1)->first();
  1257. if (empty($website)) {
  1258. return Result::error("找不到网站",0);
  1259. }
  1260. }else{
  1261. return Result::error("参数错误",0);
  1262. }
  1263. $footercategory = FooterCategory::where('website_id',$data['website_id'])->where('id',$data['fcat_id'])->first();
  1264. // '底部导航类型 0:内容型;1:列表型;',
  1265. if (!isset($footercategory['type']) || $footercategory['type'] == 0) {
  1266. return Result::error("底部导航id错误",0);
  1267. }else{
  1268. $query = FooterContent::where('fcat_id',$data['fcat_id']);
  1269. if($query->count() == 0){
  1270. return Result::error("暂无底部导航列表",0);
  1271. }elseif($query->count() == 1){
  1272. $result = $query->first();
  1273. }else{
  1274. $result = $query->get();
  1275. }
  1276. }
  1277. return Result::success($result);
  1278. }
  1279. /**
  1280. * 获取网站底部导航
  1281. * @param array $data
  1282. * @return array
  1283. */
  1284. public function getWebsiteFooterCategoryInfo(array $data): array
  1285. {
  1286. if(isset($data['website_id']) && !empty($data['website_id'])){
  1287. $website = Website::where('id',$data['website_id'])->where('status',1)->first();
  1288. if (empty($website)) {
  1289. return Result::error("找不到网站",0);
  1290. }
  1291. }else{
  1292. return Result::error("参数错误",0);
  1293. }
  1294. if (isset($data['type']) && $data['type'] == 0) {
  1295. $fcatid = FooterCategory::where('website_id',$data['website_id'])->where('id',$data['fcat_id'])->first();
  1296. if (empty($fcatid)) {
  1297. return Result::error("底部导航id错误",0);
  1298. }
  1299. $result = FooterContent::where('fcat_id',$data['fcat_id'])->first();
  1300. }else{
  1301. $result = FooterContent::where('id',$data['fcat_id'])->first();
  1302. }
  1303. if (empty($result)) {
  1304. return Result::error("暂无底部导航内容",0);
  1305. }
  1306. return Result::success($result);
  1307. }
  1308. /*
  1309. * 搜索网站二级导航
  1310. * @param array $data
  1311. * @return array
  1312. * */
  1313. public function selectWebsiteCategory(array $data): array
  1314. {
  1315. if(isset($data['website_id']) &&!empty($data['website_id'])){
  1316. $website = Website::where('id',$data['website_id'])->where('status',1)->first();
  1317. if (empty($website)) {
  1318. return Result::error("暂无该网站",0);
  1319. }
  1320. $category = WebsiteCategory::where('website_id',$data['website_id'])->pluck('category_id')->all();
  1321. // return Result::success($category);
  1322. if (empty($category)) {
  1323. return Result::error("暂无此导航",0);
  1324. }
  1325. $query = Category::whereIn('id', $category);
  1326. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1327. $cityid = District::where('id', $data['cityid'])->first();
  1328. if (empty($cityid)) {
  1329. return Result::error("暂无此城市", 0);
  1330. } else {
  1331. $city_category = $query->whereRaw('JSON_CONTAINS(city_arr_id,?)', [$data['cityid']])->pluck('id');
  1332. // $where[] = ['JSON_CONTAINS(city_arr_id, ?)', $data['cityid']];
  1333. if (empty($city_category)) {
  1334. return Result::error("暂无此城市下的导航", 0);
  1335. }
  1336. $result['catid'] = $city_category;
  1337. $city = 1;
  1338. // var_dump("城市====================",$result);
  1339. }
  1340. }
  1341. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1342. $departmentid = Department::where('id', $data['department_id'])->first();
  1343. if (empty($departmentid)) {
  1344. return Result::error("暂无此部门", 0);
  1345. } else {
  1346. $depart_category = $query->whereRaw('JSON_CONTAINS(department_arr_id,?)', [$data['department_id']])->pluck('id');
  1347. if (empty($depart_category)) {
  1348. return Result::error("暂无此部门下的导航", 0);
  1349. }
  1350. $result['catid'] = $depart_category;
  1351. // var_dump("职能部门*******************",$result);
  1352. $department = 1;
  1353. }
  1354. }
  1355. if(!empty($city) && !empty($department)){
  1356. // var_dump("城市和职能部门----------------------",$result);
  1357. $sel_category = $query->whereRaw('JSON_CONTAINS(city_arr_id,?)', [$data['cityid']])->whereRaw('JSON_CONTAINS(department_arr_id,?)', [$data['department_id']])->pluck('id');
  1358. if (empty($sel_category)) {
  1359. return Result::error("暂无此城市和职能部门下的导航", 0);
  1360. }
  1361. $result['catid'] = $sel_category;
  1362. }
  1363. if (empty($result)) {
  1364. return Result::error("暂无导航",0);
  1365. }
  1366. // department_id
  1367. }else{
  1368. return Result::error("参数错误",0);
  1369. }
  1370. return Result::success($result);
  1371. }
  1372. /**
  1373. * 获取网站栏目seo
  1374. * @param array $data
  1375. * @return array
  1376. */
  1377. public function getWebsiteCategoryHead(array $data): array
  1378. {
  1379. if(isset($data['website_id']) && !empty($data['website_id'])){
  1380. $website = Website::where('id',$data['website_id'])->where('status',1)->first();
  1381. if (empty($website)) {
  1382. return Result::error("找不到网站",0);
  1383. }
  1384. }else{
  1385. return Result::error("参数错误",0);
  1386. }
  1387. if (isset($data['catid']) && !empty($data['catid'])) {
  1388. $result = WebsiteCategory::where('website_id',$data['website_id'])->where('category_id',$data['catid'])->first();
  1389. }
  1390. if (empty($result)) {
  1391. return Result::error("暂无导航",0);
  1392. }
  1393. $result['website_name'] = $website['website_name'] ?? '';
  1394. $result['suffix'] = $website['suffix'] ?? '';
  1395. return Result::success($result);
  1396. }
  1397. /*
  1398. * 获取某个栏目
  1399. * @param array $data
  1400. * @return array
  1401. * */
  1402. public function getOneWebsiteCategory(array $data): array
  1403. {
  1404. if(isset($data['website_id']) &&!empty($data['website_id'])){
  1405. $website = Website::where('id',$data['website_id'])->where('status',1)->first();
  1406. if (empty($website)) {
  1407. return Result::error("暂无该网站",0);
  1408. }
  1409. $category = WebsiteCategory::where('website_id',$data['website_id'])->where('category_id',$data['category_id'])->first();
  1410. if (empty($category)) {
  1411. return Result::error("暂无此导航",0);
  1412. }
  1413. $category['children_count'] = WebsiteCategory::where('website_id',$data['website_id'])->where('pid',$data['category_id'])->count();
  1414. $parent = WebsiteCategory::where('website_id',$data['website_id'])->where('category_id',$category['pid'])->select('category_id as parent_id','alias as parent_name','aLIas_pinyin')->first();
  1415. $category['parent_id'] = $parent['parent_id']?? '';
  1416. $category['parent_pinyin'] = $parent['aLIas_pinyin']?? '';
  1417. $category['parent_name'] = $parent['parent_name']?? '';
  1418. return Result::success($category);
  1419. }else{
  1420. return Result::error("参数错误",0);
  1421. }
  1422. }
  1423. // 自助建站--fr-------------------
  1424. /**
  1425. * 获取并搜索 网站模板信息
  1426. * @param array $data
  1427. * @return array
  1428. */
  1429. public function getWebsiteintel(array $data): array
  1430. {
  1431. //查询所有网站模板信息
  1432. $query = Website::where('website.status', 1)
  1433. ->leftJoin("website_template_info", "website_template_info.website_id", "website.id")
  1434. ->leftJoin("template", "template.id", "website_template_info.template_id")
  1435. ->leftJoin("template_class", "template_class.id", "template.template_class_id")
  1436. ->select(
  1437. "website_template_info.id",
  1438. "template_class.name",
  1439. "website.id as website_id",
  1440. "website.website_name",
  1441. "website.website_url",
  1442. "website_template_info.action_id",
  1443. "website_template_info.created_at",
  1444. "website_template_info.updated_at",
  1445. "website_template_info.page_type",
  1446. DB::raw("COALESCE(website_template_info.status, 0) as template_status"),
  1447. "template.template_name"
  1448. );
  1449. //若存在条件;则在$query的基础上进行筛选
  1450. if(isset($data['website_name']) && !empty($data['website_name'])){
  1451. $query->where('website.website_name', 'like', '%' . $data['website_name'] . '%');
  1452. }
  1453. if(isset($data['status']) && !empty($data['status'])){
  1454. $query->where('website_template_info.status', $data['status']);
  1455. }
  1456. $count = $query->count();
  1457. $query->limit($data['pageSize'])
  1458. ->offset(($data['page'] - 1) * $data['pageSize'])
  1459. ->orderBy("website_template_info.updated_at", "desc");
  1460. $rep = $query->get();
  1461. if($rep->count()==0){
  1462. return Result::error("没有查找到相关数据",0);
  1463. } else {
  1464. $rep->each(function ($item) {
  1465. if (!empty($item->page_type)) {
  1466. $pageTypeArray = json_decode($item->page_type, true);
  1467. if (is_array($pageTypeArray)) {
  1468. $item->page_type = $pageTypeArray;
  1469. }
  1470. }
  1471. });
  1472. $result = [
  1473. "rows" => $rep->toArray(),
  1474. "count" => $count
  1475. ];
  1476. return Result::success($result);
  1477. }
  1478. // return Result::success($result);
  1479. }
  1480. /**
  1481. * 添加网站基础信息
  1482. * @param array $data
  1483. * @return array
  1484. */
  1485. public function addWebsiteTemplateintel(array $data): array
  1486. {
  1487. $website = Website::where('website.id',$data['website_id'])->first();
  1488. if(empty($website)){
  1489. return Result::error("请输入正确的网站id!", 0);
  1490. }
  1491. if(empty($website['website_column_id'])){
  1492. return Result::error("请先关联导航池!", 0);
  1493. }
  1494. // 获取此网站的底部导航 类型 type: 0:内容型底部导航(只有一条详情内容);1:列表型底部导航(可以有多条详情内容)
  1495. $foot_type = FooterCategory::where('website_id',$data['website_id'])->pluck('type')->toArray();
  1496. if (empty($foot_type)) {
  1497. return Result::error("请先关联底部导航池!", 0);
  1498. } elseif (in_array(1, $foot_type)) {
  1499. $foot_type = 1;
  1500. } else {
  1501. $foot_type = 0;
  1502. }
  1503. $result['foot_type'] = $foot_type;
  1504. // 友情链接类型'1:图片 2:文字 3:底部';
  1505. $types = Link::where('website_id', $data['website_id'])->pluck('type')->toArray();
  1506. $missingTypes = [];
  1507. if (!in_array(1, $types)) {
  1508. $missingTypes[] = "文字链接";
  1509. }
  1510. if (!in_array(2, $types)) {
  1511. $missingTypes[] = "图片链接";
  1512. }
  1513. if (!in_array(3, $types)) {
  1514. $missingTypes[] = "底部链接";
  1515. }
  1516. if (!empty($missingTypes)) {
  1517. $errorMessage = "请先添加 " . implode(" 和 ", $missingTypes) . "!";
  1518. return Result::error($errorMessage, 0);
  1519. }
  1520. if(isset($data['page_type'])){
  1521. // 删除重复元素并重新索引数组
  1522. $data['page_type'] = array_unique($data['page_type']);
  1523. $data['page_type'] = array_values($data['page_type']);
  1524. if (in_array(1, $data['page_type']) && in_array(7, $data['page_type'])) {
  1525. // 数组中同时包含值为 1(首页) 和值为 7 (底部导航详情页)的元素
  1526. $info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1527. if (empty($info)) {
  1528. // 将数组转换为 JSON 字符串
  1529. $data['page_type'] = json_encode($data['page_type'])??'';
  1530. // 操作状态:1:填写完成基础信息;2:选择完成模板;0:未构建
  1531. $data['action_id'] = 1;
  1532. try {
  1533. $result = WebsiteTemplateInfo::insertGetId($data);
  1534. } catch (\Exception $e) {
  1535. if ($e->getCode() == 22001) {
  1536. $errorMessage = $e->getMessage();
  1537. return Result::error("请检查表单,某个字段超出了长度限制!");
  1538. } else {
  1539. // 处理其他类型的数据库错误
  1540. return Result::error("插入操作失败: " . $e->getMessage());
  1541. }
  1542. return Result::error("添加失败!", 0);
  1543. }
  1544. } else {
  1545. return Result::error("该网站已经构建过了!", 0);
  1546. }
  1547. } else {
  1548. return Result::error("请先选择首页和底部导航详情页!", 0);
  1549. }
  1550. }
  1551. if(empty($result)){
  1552. return Result::error("添加失败!",0);
  1553. }else{
  1554. return Result::success($result);
  1555. }
  1556. }
  1557. /**
  1558. * 获取网站基础信息
  1559. *
  1560. * @return array
  1561. */
  1562. public function getWebsiteTemplateintel(array $data): array
  1563. {
  1564. $result = WebsiteTemplateInfo::where('website_template_info.website_id',$data['website_id'])
  1565. ->leftJoin('footer_category','footer_category.website_id','website_template_info.website_id')
  1566. ->leftJoin('website','website.id','website_template_info.website_id')
  1567. ->select(
  1568. "website_template_info.*",
  1569. "footer_category.type",
  1570. "website.website_name",
  1571. "website.id as website_id"
  1572. )
  1573. ->first();
  1574. if(empty($result['website_name'])){
  1575. return Result::error("请输入正确的网站id!", 0);
  1576. }
  1577. if($result){
  1578. $result['page_type'] = json_decode($result['page_type'],true);
  1579. return Result::success($result);
  1580. }else{
  1581. return Result::error("请先添加网站基础信息!",0);
  1582. }
  1583. }
  1584. /**
  1585. * 修改网站基础信息
  1586. *
  1587. * @return array
  1588. */
  1589. public function upWebsiteTemplateintel(array $data): array
  1590. {
  1591. $web = Website::where('website.id',$data['website_id'])->first();
  1592. if(empty($web)){
  1593. return Result::error("请输入正确的网站id!", 0);
  1594. }
  1595. $where = ['website_id'=>$data['website_id']];
  1596. $result = WebsiteTemplateInfo::where($where)->first();
  1597. if(empty($result)){
  1598. return Result::error("请先添加网站基础信息!",0);
  1599. }else{
  1600. unset($data['website_id']);
  1601. // 删除重复元素
  1602. $data['page_type'] = array_unique($data['page_type']);
  1603. // 重新索引数组
  1604. $data['page_type'] = array_values($data['page_type']);
  1605. // 数组中同时包含值为 1(首页) 和值为 7 (底部导航详情页)的元素
  1606. if (in_array(1, $data['page_type']) && in_array(7, $data['page_type'])) {
  1607. // 将数组转换为 JSON 字符串
  1608. $data['page_type'] = json_encode($data['page_type'])??'';
  1609. try {
  1610. $result = WebsiteTemplateInfo::where($where)->update($data);
  1611. } catch (\Exception $e) {
  1612. if ($e->getCode() == 22001) {
  1613. $errorMessage = $e->getMessage();
  1614. return Result::error("请检查表单,某个字段超出了长度限制!");
  1615. } else {
  1616. // 处理其他类型的数据库错误
  1617. return Result::error("修改操作失败: " . $e->getMessage());
  1618. }
  1619. return Result::error("修改失败!", 0);
  1620. }
  1621. }else{
  1622. return Result::error("请先选择首页和底部导航详情页!",0);
  1623. }
  1624. }
  1625. if(empty($result)){
  1626. return Result::error("修改失败!",0);
  1627. }else{
  1628. return Result::success($result);
  1629. }
  1630. }
  1631. /**
  1632. * 获取所有网站风格信息
  1633. *
  1634. * @return array
  1635. */
  1636. public function getAllTemplateClass(array $data): array
  1637. {
  1638. $result = TemplateClass::all();
  1639. if(empty($result)){
  1640. return Result::error("没有查找到相关数据!",0);
  1641. }else{
  1642. return Result::success($result);
  1643. }
  1644. }
  1645. /**
  1646. * 搜索并获取网站模板信息
  1647. * @param array $data
  1648. * @return array
  1649. */
  1650. public function getWebsiteTemplateList(array $data): array
  1651. {
  1652. $website = Website::where('website.id',$data['website_id'])->first();
  1653. if(empty($website)){
  1654. return Result::error("请输入正确的网站id!",0);
  1655. }else{
  1656. $page_type = WebsiteTemplateInfo::where('website_id',$data['website_id'])->select('page_type')->first();
  1657. if(empty($page_type)){
  1658. return Result::error("此网站还未添加基础信息!",0);
  1659. } else{
  1660. $where = json_decode($page_type['page_type'], true);
  1661. // $where = $data["page_type"];
  1662. if(isset($data['template_class_id']) && !empty($data['template_class_id'])){
  1663. $template_class = TemplateClass::where('id',$data['template_class_id'])->first();
  1664. if(empty($template_class)){
  1665. return Result::error("请输入正确的模板风格id!",0);
  1666. }else{
  1667. // 获取指定风格下的模板
  1668. $rep = Template::where('template_class_id', $data['template_class_id'])
  1669. ->where(function ($query) use ($where) {
  1670. foreach ($where as $value) {
  1671. $query->whereJsonContains('template_img', ['value' => $value]);
  1672. }
  1673. })
  1674. ->limit($data['pageSize'])
  1675. ->offset(($data['page'] - 1) * $data['pageSize'])
  1676. ->orderBy("template.updated_at", "desc")
  1677. ->get();
  1678. $count = Template::where('template_class_id', $data['template_class_id'])
  1679. ->where(function ($query) use ($where) {
  1680. foreach ($where as $value) {
  1681. $query->whereJsonContains('template_img', ['value' => $value]);
  1682. }
  1683. })->count();
  1684. }
  1685. }else{
  1686. //获取所有模板
  1687. $rep = Template::where(function ($query) use ($where) {
  1688. foreach ($where as $value) {
  1689. $query->whereJsonContains('template_img', ['value' => $value]);
  1690. }
  1691. })
  1692. ->limit($data['pageSize'])
  1693. ->offset(($data['page'] - 1) * $data['pageSize'])
  1694. ->orderBy("template.updated_at", "desc")
  1695. ->get();
  1696. $count = Template::where(function ($query) use ($where) {
  1697. foreach ($where as $value) {
  1698. $query->whereJsonContains('template_img', ['value' => $value]);
  1699. }
  1700. })->count();
  1701. }
  1702. if(empty($rep) || $rep->count()==0){
  1703. return Result::error("没有查找到相关数据!",0);
  1704. }else{
  1705. // 过滤 template_img 字段 只获取 基础信息中 包含的模板图片
  1706. // $rep->each(function ($item) use ($where) {
  1707. // $template_img = json_decode($item->template_img, true);
  1708. // if(is_array($template_img)){
  1709. // $filtered_img = array_filter($template_img, function ($img) use ($where) {
  1710. // return isset($img['value']) && in_array($img['value'], $where);
  1711. // });
  1712. // }
  1713. // $item->template_img = $filtered_img;
  1714. // });
  1715. // $result = [
  1716. // "rows" => $rep->toArray(),
  1717. // "count" => $count
  1718. // ];
  1719. $rep->each(function ($item) use ($where) {
  1720. $template_img = json_decode($item->template_img, true);
  1721. if (is_array($template_img)) {
  1722. $filtered_img = array_filter($template_img, function ($img) use ($where) {
  1723. return isset($img['value']) && in_array($img['value'], $where);
  1724. });
  1725. // 对过滤后的数组进行重新排序
  1726. $sorted_img = array_values($filtered_img);
  1727. $item->template_img = $sorted_img;
  1728. } else {
  1729. $item->template_img = []; // 如果无法解码为数组,则设置为空数组
  1730. }
  1731. });
  1732. $result = [
  1733. "rows" => $rep->toArray(),
  1734. "count" => $count
  1735. ];
  1736. }
  1737. }
  1738. }
  1739. return Result::success($result);
  1740. }
  1741. /**
  1742. * 添加网站模板
  1743. * @param array $data
  1744. */
  1745. public function addWebsiteTemplateclassintel(array $data): array
  1746. {
  1747. $template = Template::where('id',$data['template_id'])->first();
  1748. $web = Website::where('id',$data['website_id'])->first();
  1749. if(empty($template)){
  1750. return Result::error("请输入正确的模板id",0);
  1751. }
  1752. if(empty($web)){
  1753. return Result::error("请输入正确的网站id",0);
  1754. }
  1755. $result = WebsiteTemplateInfo::where('website_id',$data['website_id'])->update(['template_id'=>$data['template_id'],'action_id'=>2]);
  1756. if(empty($result)){
  1757. return Result::error("添加失败",0);
  1758. }else{
  1759. return Result::success($result);
  1760. }
  1761. }
  1762. /**
  1763. * 获取网站模板信息
  1764. * @param array $data
  1765. */
  1766. public function getWebsiteTemplateclassintel(array $data): array
  1767. {
  1768. // return Result::success($data);
  1769. $template = WebsiteTemplateInfo::where('website_id',$data['website_id'])->first();
  1770. if(empty($template)){
  1771. return Result::error("请输入正确的搭建网站id",0);
  1772. }
  1773. $page_type = json_decode($template['page_type'], true);
  1774. // 获取指定网站下的基础信息和模板及风格信息
  1775. $result = WebsiteTemplateInfo::where([
  1776. ['website_template_info.website_id',$data['website_id']],
  1777. ['template_id','!=',null]
  1778. ])
  1779. ->leftJoin('template','template.id','website_template_info.template_id')
  1780. ->leftJoin('template_class','template_class.id','template.template_class_id')
  1781. ->where(function ($query) use ($page_type) {
  1782. // 假设 $data['page_type'] 是一个数组,包含需要匹配的 page_type 值
  1783. foreach ($page_type as $pageType) {
  1784. $query->orWhereJsonContains('template.template_img', ['value' => $pageType]);
  1785. }
  1786. })
  1787. ->select(
  1788. 'template.template_name',
  1789. 'template.template_img',
  1790. 'template.id as tid',
  1791. 'template_class.name',
  1792. 'template_class.id as class_id',
  1793. 'website_template_info.page_type',
  1794. 'website_template_info.website_id')
  1795. ->first();
  1796. if(empty($result)){
  1797. return Result::error("没有查找到相关数据",0);
  1798. }
  1799. // return Result::success($result);
  1800. // 过滤 template_img 字段 只获取 基础信息中 包含的模板图片
  1801. $template_img = $result['template_img'] !== null ? json_decode($result['template_img'], true) : [];
  1802. $page_type = $result['page_type'] !== null ? json_decode($result['page_type'], true) : [];
  1803. foreach ($template_img as $key => $value) {
  1804. if (!in_array($value['value'], $page_type)) {
  1805. unset($template_img[$key]);
  1806. }
  1807. }
  1808. // return Result::success($result);
  1809. $result['template_img'] = array_values($template_img);
  1810. $result['page_type'] = $page_type;
  1811. // $templateList = $this->getWebsiteTemplateList($data);
  1812. // $count = $templateList['data']['count']??'';
  1813. // $pages = $count / $data['pageSize'];
  1814. // $found = false;
  1815. // while ($pages && !$found) {
  1816. // $templates = $this->getWebsiteTemplateList($pages,$data['pageSize']);
  1817. // $index = array_search($template['template_id'], array_column($templates['rows'], 'id'));
  1818. // if ($index !== false) {
  1819. // $found = true;
  1820. // $result['page'] = $pages;
  1821. // $pages = 0;
  1822. // // echo "查询到的 template 在第 $page 页";
  1823. // }
  1824. // $pages--;
  1825. // }
  1826. return Result::success($result);
  1827. }
  1828. /**
  1829. * 获取网站模板下的板块信息
  1830. * @param array $data
  1831. */
  1832. public function getWebsiteSectorList(array $data): array
  1833. {
  1834. $website = Website::where('id',$data['website_id'])->first();
  1835. if(empty($website)){
  1836. return Result::error("请输入正确的网站id",0);
  1837. }
  1838. $template = WebsiteTemplateInfo::where('website_id',$data['website_id'])->first();
  1839. if(empty($template['template_id'])){
  1840. return Result::error("请先添加网站模板",0);
  1841. }
  1842. $query = Sector::where('template_id',$template['template_id']);
  1843. if($query->count() == 0){
  1844. return Result::error("没有查找到相关板块数据",0);
  1845. }elseif($query->count() == 1){
  1846. $sector = $query->first();
  1847. }else{
  1848. $sector = $query->get();
  1849. }
  1850. $result['page_type'] = $template['page_type'];
  1851. $result['tid'] = $template['template_id'];
  1852. $result = [
  1853. "tid" => $template['template_id'],
  1854. "page_type" => $template['page_type'],
  1855. "sector" => $sector
  1856. ];
  1857. return Result::success($result);
  1858. }
  1859. // 自助建站---------------fr---------------
  1860. // 网站底基础信息--fr-------------------
  1861. /**
  1862. * 添加网站底基础信息
  1863. * @param array $data
  1864. */
  1865. public function addWebFootInfo(array $data): array
  1866. {
  1867. $website = Website::where('id',$data['website_id'])->first();
  1868. if(empty($website)){
  1869. return Result::error("请输入正确的网站id!", 0);
  1870. }
  1871. $info = WebsiteTemplateInfo::where('website_id',$data['website_id'])->first();
  1872. if(!empty($info)){
  1873. return Result::error("该网站已经添加过了!", 0);
  1874. }
  1875. $result = WebsiteTemplateInfo::where('website_id',$data['website_id'])->insertGetId($data);
  1876. if(empty($result)){
  1877. return Result::error("请先添加网站基础信息!",0);
  1878. }else{
  1879. return Result::success($result);
  1880. }
  1881. }
  1882. /**
  1883. * 获取网站底基础信息
  1884. * @param array $data
  1885. */
  1886. public function getWebFootInfo(array $data): array
  1887. {
  1888. $website = Website::where('id',$data['website_id'])->first();
  1889. if(empty($website)){
  1890. return Result::error("请输入正确的网站id!", 0);
  1891. }
  1892. $result = WebsiteTemplateInfo::where('website_id',$data['website_id'])->first();
  1893. if(empty($result)){
  1894. return Result::error("请先添加网站基础信息!",0);
  1895. }
  1896. return Result::success($result);
  1897. }
  1898. /**
  1899. * 修改网站底基础信息
  1900. * @param array $data
  1901. */
  1902. public function upWebFootInfo(array $data): array
  1903. {
  1904. // return Result::success($data);
  1905. $website = Website::where('id',$data['website_id'])->first();
  1906. if(empty($website)){
  1907. return Result::error("请输入正确的网站id!", 0);
  1908. }
  1909. $web = $data['website_id'];
  1910. unset($data['website_id']);
  1911. $where = ['website_id'=>$web];
  1912. // return Result::success($data);
  1913. $result = WebsiteTemplateInfo::where($where)->first();
  1914. if(empty($result)){
  1915. $data['website_id'] = $web;
  1916. $result = WebsiteTemplateInfo::insertGetId($data);
  1917. // return Result::error("请先添加网站基础信息!",0);
  1918. } else{
  1919. $result = WebsiteTemplateInfo::where($where)->update($data);
  1920. }
  1921. // $where = ['website_id'=>$data['website_id']];
  1922. // unset($data['website_id']);
  1923. // $result = WebsiteTemplateInfo::updateOrInsert($where, $data);
  1924. if(empty($result)){
  1925. return Result::error("修改失败!",0);
  1926. }
  1927. return Result::success($result);
  1928. }
  1929. /*
  1930. * 获取父级/子级栏目------路由
  1931. * @param array $data
  1932. * @return array
  1933. * */
  1934. public function getWebsiteParentCategory(array $data): array
  1935. {
  1936. // return Result::success($data);
  1937. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1938. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1939. }
  1940. if (empty($website)) {
  1941. return Result::error("暂无该网站", 0);
  1942. }
  1943. // 在 Hyperf 中,查询构建器(Builder)没有 `map` 方法,`map` 方法是集合(Collection)的方法。
  1944. // 因此,需要先调用 `get()` 方法获取查询结果集合,再使用 `map` 方法进行处理。
  1945. $category['parent'] = WebsiteCategory::where('website_id', $data['website_id'])
  1946. ->where('pid', 0)
  1947. ->selectRaw("category_id as cid, alias as name, CONCAT('/', '', aLIas_pinyin, '/') as path")
  1948. ->get() // 添加 get() 方法获取结果集合
  1949. ->all();
  1950. // 提前查询所有父级栏目,避免在 map 中多次查询
  1951. // 提前查询所有父级栏目信息并以 category_id 作为键存储
  1952. $parentCategories = WebsiteCategory::where('website_id', $data['website_id'])
  1953. ->where('pid', 0)
  1954. ->select('category_id', 'aLIas_pinyin')
  1955. ->get()
  1956. ->keyBy('category_id');
  1957. // 直接查询子栏目信息
  1958. $child = WebsiteCategory::where('website_id', $data['website_id'])
  1959. ->where('pid', '!=', 0)
  1960. ->select('alias', 'category_id', 'aLIas_pinyin', 'pid')
  1961. ->get();
  1962. // 使用集合的 map 方法处理子栏目信息
  1963. $category['child'] = $child->map(function ($item) use ($parentCategories) {
  1964. $alias = $item->alias;
  1965. $category_id = $item->category_id;
  1966. $alias_pinyin = $item->aLIas_pinyin;
  1967. $parent = $parentCategories->get($item->pid);
  1968. $parentAlias = $parent ? $parent->aLIas_pinyin : '';
  1969. $result = [
  1970. 'name' => $alias,
  1971. 'cid' => $category_id
  1972. ];
  1973. if (!empty($alias_pinyin) && !empty($parentAlias)) {
  1974. $result['path'] = "/{$parentAlias}/{$alias_pinyin}/";
  1975. }
  1976. return $result;
  1977. })->values()->all();
  1978. if (empty($category)) {
  1979. return Result::error("暂无此导航", 0);
  1980. }
  1981. return Result::success($category);
  1982. }
  1983. /**
  1984. * 获取网站栏目信息
  1985. * @param array $data
  1986. */
  1987. public function getWebsiteFootAll(array $data): array
  1988. {
  1989. $website = Website::where('id',$data['website_id'])->where('status',1)->first();
  1990. if (empty($website)) {
  1991. return Result::error("暂无该网站",0);
  1992. }
  1993. // 1:图片 2:文字 3:底部
  1994. $result['foot_cate'] = FooterCategory::where('website_id',$data['website_id'])->get()->all();
  1995. $result['link_img'] = Link::where('website_id',$data['website_id'])->where('type',1)->where('status',1)->limit($data['link_imgnum'])->orderBy('sort')->get()->all();
  1996. $result['link_text'] = Link::where('website_id',$data['website_id'])->where('type',2)->where('status',1)->limit($data['link_textnum'])->orderBy('sort')->get()->all();
  1997. $result['link_foot'] = Link::where('website_id',$data['website_id'])->where('type',3)->where('status',1)->limit($data['link_footnum'])->orderBy('sort')->get()->all();
  1998. $result['foot_info'] = WebsiteTemplateInfo::where('website_id',$data['website_id'])->first();
  1999. if(empty($result)){
  2000. return Result::error("暂无此网站信息",0);
  2001. }
  2002. return Result::success($result);
  2003. }
  2004. /**
  2005. * 获取网站顶部信息
  2006. * @param array $data
  2007. */
  2008. public function getWebsiteHead(array $data): array
  2009. {
  2010. $result = Website::where('id',$data['website_id'])->where('status',1)->select('website_name','logo')->first();
  2011. if (empty($result)) {
  2012. return Result::error("暂无该网站",0);
  2013. }
  2014. return Result::success($result);
  2015. }
  2016. /**
  2017. * 路由匹配
  2018. * @param array $data
  2019. */
  2020. public function getWebsiteRoute(array $data): array
  2021. {
  2022. $website = Website::where('id',$data['website_id'])->where('status',1)->first();
  2023. if (empty($website)) {
  2024. return Result::error("暂无该网站",0);
  2025. }
  2026. // return Result::success($data);
  2027. if (isset($data['pinyin']) &&!empty($data['pinyin'])) {
  2028. $result = WebsiteCategory::where('website_id',$data['website_id'])->where('aLIas_pinyin',$data['pinyin'])->first(['category_id']);
  2029. }
  2030. if(isset($data['foot_pinyin']) &&!empty($data['foot_pinyin'])){
  2031. $result = FooterCategory::where('website_id',$data['website_id'])->where('name_pinyin',$data['foot_pinyin'])->first(['id']);
  2032. }
  2033. if (!isset($result) || empty($result)) {
  2034. return Result::error("暂无该导航",0);
  2035. }
  2036. return Result::success($result);
  2037. }
  2038. }