WebsiteService.php 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155
  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.name as ad_name',
  490. 'ad.image_src',
  491. 'ad.image_url',
  492. 'ad.image_alt')
  493. ->get()->all();
  494. if(empty($result)){
  495. return Result::error("此广告位不存在!",0);
  496. }
  497. }else{
  498. return Result::error("请选择广告位!",0);
  499. }
  500. return Result::success($result);
  501. }
  502. /**
  503. *
  504. * @param array $data
  505. * @return array
  506. */
  507. /**网站行政职能搜索 */
  508. public function selectWebsiteDepartment(array $data): array
  509. {
  510. $depart = Department::where('pid',0)->orderBy('id','asc')->get();
  511. if(isset($data['keyword']) && !empty($data['keyword'])){
  512. $departments= Department::where('name', 'like', '%' . $data['keyword'] . '%')->get();
  513. if(empty($departments)){
  514. $result['message']="未查询到与此相关职能部门";
  515. }else{
  516. $count = Department::where('name','like',"%{$data['keyword']}%")->count();
  517. $m = [
  518. 'department'=>$depart,
  519. 'type'=>$departments,
  520. 'count'=>$count
  521. ];
  522. }
  523. $result['sele'] = $m;
  524. return Result::success($result['sele']);
  525. }
  526. $result=$depart;
  527. return Result::success($result);
  528. }
  529. /**
  530. * 搜索地区
  531. * @param array $data
  532. * @return array
  533. */
  534. public function selectWebsiteArea(array $data): array
  535. {
  536. // return Result::success($data);
  537. $pid = $data['pid'] ?? 0;
  538. $result = District::where('pid',$pid)->where('status',1)->orderBy('code')->get();
  539. if(empty($result)){
  540. return Result::error("未查询到此地区",0);
  541. }else{
  542. return Result::success($result);
  543. }
  544. }
  545. /**
  546. * 获取栏目
  547. * @param array $data
  548. * @return array
  549. */
  550. public function getWebsiteModelCategory(array $data): array
  551. {
  552. // return Result::success($data);
  553. $website_id=[
  554. 'website_id' => $data['website_id']
  555. ];
  556. // 初始化 $pid 数组
  557. // $pid = [];
  558. // 以下注释掉的代码是之前的逻辑,用于获取非顶级分类的 pid
  559. $pidQuery = WebsiteCategory::where($website_id)
  560. ->where('pid', '!=', 0)
  561. ->orderBy('sort')
  562. ->select('pid','category_id','alias');
  563. $pid = $pidQuery->pluck('pid');
  564. $pid = array_values(array_unique($pid->toArray()));
  565. // 构建查询语句
  566. $query = WebsiteCategory::where($website_id)
  567. ->where('pid', $data['pid'])
  568. ->offset($data['placeid'])
  569. ->limit($data['num'])
  570. ->orderBy('sort');
  571. // 如果 $pid 数组不为空,添加 CASE WHEN 条件
  572. if (!empty($pid)) {
  573. $placeholders = implode(',', array_fill(0, count($pid), '?'));
  574. $query->selectRaw("website_category.*, CASE WHEN website_category.category_id IN ($placeholders) THEN 1 ELSE 0 END AS children_count", $pid);
  575. } else {
  576. // 如果 $pid 数组为空,不添加 CASE WHEN 条件,添加字段 children_count 并赋值为 0
  577. $query->select('website_category.*', DB::raw('0 as children_count'));
  578. }
  579. // 执行查询
  580. $placeid = $data['placeid']-1;
  581. $result = $query->offset($placeid)->limit($data['num'])->get();
  582. if (!empty($result)) {
  583. $pidResults = $pidQuery->get();
  584. $pidMap = $pidResults->keyBy('pid');
  585. $result->each(function ($record) use ($pidMap) {
  586. if ($pidMap->has($record->category_id)) {
  587. $pidResult = $pidMap->get($record->category_id);
  588. $record->chilid_id = $pidResult->category_id;
  589. $record->chilid_alias = $pidResult->alias;
  590. }
  591. });
  592. return Result::success($result);
  593. } else {
  594. return Result::error("本网站暂无栏目", 0);
  595. }
  596. }
  597. /**
  598. * 获取友情链接
  599. * @param array $data
  600. * @return array
  601. */
  602. public function selectWebsiteLinks(array $data): array
  603. {
  604. $where = [
  605. 'website_id' => $data['website_id'],
  606. 'status' => 1,
  607. 'type' => $data['type']
  608. ];
  609. $num=$data['num'];
  610. $result=Link::where($where)->orderBy('sort')->limit($num)->get();
  611. if(!empty($result)){
  612. return Result::success($result);
  613. }else{
  614. return Result::error("本网站暂无此类型友情链接",0);
  615. }
  616. }
  617. /**
  618. * 网站首页数据统计, 管理员
  619. * @return void
  620. */
  621. public function getAdminIndex(array $data): array
  622. {
  623. var_dump("用户类型:",$data['type_id']);
  624. switch ($data['type_id']){
  625. case 4:
  626. $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;');
  627. return Result::success($result);
  628. break;
  629. case 10000:
  630. $res = [];
  631. //网站
  632. $res['website']['count'] = 0;
  633. $res['website']['growth_rate'] = 0;
  634. //资讯
  635. $res['article']['count'] = 0;
  636. $res['article']['growth_rate'] = 0;
  637. //导航池
  638. $res['category']['count'] = 0;
  639. $res['category']['growth_rate'] = 0;
  640. //近一月数据
  641. $res['monthArticle']= [];
  642. //用户类型
  643. $res['userType'] = [];
  644. $res['website']['count'] = Website::where([])->count();
  645. $res['article']['count'] = Article::whereNotIn('status',['404'])->count();
  646. $res['category']['count'] = Category::where([])->count();
  647. $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;');
  648. $res['userType'] = User::where([])->selectRaw("count(*) as counts,type_id")->groupBy('type_id')->get();
  649. return Result::success($res);
  650. }
  651. return [];
  652. }
  653. /**
  654. * 获取模板类型
  655. * @return void
  656. */
  657. public function getTemplateClass(array $data): array
  658. {
  659. $where = [];
  660. if(isset($data['name']) && $data['name']){
  661. array_push($where,['name','like','%'.$data['name'].'%']);
  662. }
  663. $result = TemplateClass::where($where)->orderBy('sort','asc')->get();
  664. if(empty($result)){
  665. return Result::error("没有模板类型",0);
  666. }else{
  667. return Result::success($result);
  668. }
  669. }
  670. /**
  671. * 添加模板类型
  672. * @param
  673. * @return void
  674. */
  675. public function addTemplateClass(array $data): array
  676. {
  677. $insertData = [
  678. 'name'=>$data['name']
  679. ];
  680. $result = TemplateClass::insertGetId($insertData);
  681. if(empty($result)){
  682. return Result::error("创建失败",0);
  683. }else{
  684. return Result::success(["id"=>$result]);
  685. }
  686. }
  687. /**
  688. * 更新模板
  689. * @param array $data
  690. * @return array
  691. */
  692. public function upTemplateClass(array $data): array
  693. {
  694. $where = [
  695. 'id'=>$data['id']
  696. ];
  697. $insertData = [
  698. 'name'=>$data['name']
  699. ];
  700. $result = TemplateClass::where($where)->update($insertData);
  701. if(empty($result)){
  702. return Result::error("更新失败",0);
  703. }else{
  704. return Result::success();
  705. }
  706. }
  707. /**
  708. * 删除模板
  709. * @param array $data
  710. * @return array
  711. */
  712. public function delTemplateClass(array $data): array
  713. {
  714. $where = [
  715. 'id'=>$data['id']
  716. ];
  717. $result = TemplateClass::where($where)->delete();
  718. if(empty($result)){
  719. return Result::error("删除失败",0);
  720. }else{
  721. return Result::success();
  722. }
  723. }
  724. /**
  725. * 获取分类下的模板
  726. * @param array $data
  727. * @return array
  728. */
  729. public function getTemplate(array $data): array
  730. {
  731. $page = $data['page'];
  732. $pageSize = $data['pageSize'];
  733. $where = [];
  734. if(isset($data['template_class_id']) && $data['template_class_id']){
  735. array_push($where,['template_class_id','=',$data['template_class_id']]);
  736. }
  737. $result = Template::where($where)
  738. ->limit($pageSize)->offset(($page-1)*$pageSize)->get();
  739. $count = Template::where($where)->count();
  740. if (empty($result)) {
  741. return Result::error("没有数据",0);
  742. }
  743. $data = [
  744. 'rows'=>$result->toArray(),
  745. 'count'=>$count
  746. ];
  747. return Result::success($data);
  748. }
  749. /**
  750. * 创建模板
  751. * @param
  752. * @return void
  753. */
  754. public function addTemplate(array $data): array
  755. {
  756. $insertData = [
  757. 'template_name'=>$data['template_name'],
  758. 'template_img'=>json_encode($data['template_img']),
  759. 'template_class_id'=>$data['template_class_id'],
  760. ];
  761. $result = Template::insertGetId($insertData);
  762. if(empty($result)){
  763. return Result::error("创建模板失败",0);
  764. }else{
  765. return Result::success(["id"=>$result]);
  766. }
  767. }
  768. /**
  769. * 更新模板
  770. * @param array $data
  771. * @return array
  772. */
  773. public function upTemplate(array $data): array
  774. {
  775. $where = [
  776. 'id'=>$data['id']
  777. ];
  778. $insertData = [
  779. 'template_name'=>$data['template_name'],
  780. 'template_img'=>json_encode($data['template_img']),
  781. 'template_class_id'=>$data['template_class_id'],
  782. ];
  783. $result = Template::where($where)->update($insertData);
  784. if(empty($result)){
  785. return Result::error("更新模板失败",0);
  786. }else{
  787. return Result::success();
  788. }
  789. }
  790. /**
  791. * 删除模板
  792. * @param array $data
  793. * @return array
  794. */
  795. public function delTemplate(array $data): array
  796. {
  797. $where = [
  798. 'id'=>$data['id']
  799. ];
  800. $result = Template::where($where)->delete();
  801. if(empty($result)){
  802. return Result::error("删除模板失败",0);
  803. }else{
  804. return Result::success();
  805. }
  806. }
  807. /**
  808. * 搜索网站
  809. * @param array $data
  810. * @return array
  811. */
  812. public function websiteList(array $data): array
  813. {
  814. $where = [];
  815. if(isset($data['keyword']) && !empty($data['keyword'])){
  816. array_push($where,['website.website_name','like','%'.$data['keyword'].'%']);
  817. }
  818. $result = Website::where($where)->get();
  819. if($result){
  820. return Result::success($result);
  821. }else{
  822. return Result::error("没有网站",0);
  823. }
  824. }
  825. public function addWebsiteCategory(array $data): array
  826. {
  827. $website_id = $data['website_id'];
  828. $category_arr_id = $data['category_arr_id'];
  829. $categoryList = Category::whereIn('id',$category_arr_id)->get();
  830. $categoryListIds = [];
  831. if($categoryList){
  832. foreach ($categoryList->toArray() as $val){
  833. array_push($categoryListIds,$val['id']);
  834. }
  835. }
  836. $arr = [];
  837. if($categoryListIds){
  838. foreach ($categoryListIds as $v){
  839. $ids = $this->getUnderlingUIds(intval($v));
  840. $ids_arr = explode(",", $ids);
  841. array_push($arr,$ids_arr);
  842. }
  843. }
  844. $mergedArray = [];
  845. foreach ($arr as $subarray) {
  846. $mergedArray = array_merge($mergedArray, $subarray);
  847. }
  848. var_dump("所有:",$arr,$mergedArray);
  849. //查询出所有的分类进行分割插入 组装数据
  850. $categoryListData = Category::whereIn('id',$mergedArray)->get();
  851. $categoryListData = $categoryListData->toArray();
  852. $insertData = [];
  853. if($categoryListData){
  854. foreach ($categoryListData as $key=>$value){
  855. $insertData[$key]['website_id'] = $website_id;
  856. $insertData[$key]['name'] = $value['name'];
  857. $insertData[$key]['sort'] = $value['sort'];
  858. $insertData[$key]['pid'] = $value['pid'];
  859. $insertData[$key]['pid_arr'] = $value['pid_arr'];
  860. $insertData[$key]['seo_title'] = $value['seo_title'];
  861. $insertData[$key]['seo_keywords'] = $value['seo_keywords'];
  862. $insertData[$key]['seo_description'] = $value['seo_description'];
  863. $insertData[$key]['alias'] = $value['name'];
  864. $insertData[$key]['category_id'] = $value['id'];
  865. }
  866. }
  867. $result = WebsiteCategory::insert($insertData);
  868. var_dump("插入数据状态:",$result);
  869. if($result){
  870. return Result::success($result);
  871. }else{
  872. return Result::error("创建失败",0);
  873. }
  874. }
  875. /**
  876. * 删除网站导航
  877. * @param array $data
  878. * @return array
  879. */
  880. public function delWebsiteCategory(array $data): array
  881. {
  882. $website_id = $data['website_id']??0;
  883. $category_id = $data['category_id']??0;
  884. $ids = $this->getUnderlingUIds(intval($category_id));
  885. $ids_arr = explode(",", $ids);
  886. $result = WebsiteCategory::where(['website_id'=>$website_id])->whereIn("category_id",$ids_arr)->delete();
  887. if($result){
  888. return Result::success($result);
  889. }else{
  890. return Result::error("删除失败",0);
  891. }
  892. }
  893. /**
  894. * 获取网站导航
  895. * @param array $data
  896. * @return array
  897. */
  898. public function getAdminWebsiteCategory(array $data): array
  899. {
  900. $where = [
  901. 'website_id'=>$data['website_id'],
  902. 'pid'=>0
  903. ];
  904. $result = WebsiteCategory::where($where)->get();
  905. if($result){
  906. return Result::success($result);
  907. }else{
  908. return Result::error("查询失败",0);
  909. }
  910. }
  911. /**
  912. * 更新网站导航
  913. * @param array $data
  914. * @return array
  915. */
  916. public function upWebsiteCategory(array $data): array
  917. {
  918. Db::beginTransaction();
  919. try{
  920. //合并栏目id
  921. $reqIds = array_merge($data['old_category_arr_id'],$data['new_category_arr_id']);
  922. //对比old 数组差异化,把差异化的删除
  923. $result = WebsiteCategory::where(['website_id'=>$data['website_id'],'pid'=>0])->get();
  924. $result = $result->toArray();
  925. $categoryIds = [];
  926. if($result){
  927. foreach ($result as $val){
  928. array_push($categoryIds,$val['category_id']);
  929. }
  930. }
  931. //和原始数据对比取交际
  932. $reqidsIntersect = array_intersect($reqIds,$categoryIds);
  933. //再取差集 进行对比
  934. $differenceIDS = array_merge(array_diff($reqidsIntersect, $categoryIds),array_diff($categoryIds,$reqidsIntersect));
  935. var_dump("差集:",$differenceIDS);
  936. $arr_ids = [];
  937. if(count($differenceIDS)>0){
  938. foreach ($differenceIDS as $vv){
  939. $idV = $this->getUnderlingUIds(intval($vv));
  940. $ids_arrV = explode(",", $idV);
  941. array_push($arr_ids,$ids_arrV);
  942. }
  943. }
  944. $del_ids = array_reduce($arr_ids, 'array_merge', array());
  945. //有差异 删除
  946. if(count($del_ids)>0){
  947. WebsiteCategory::where(['website_id'=>$data['website_id']])->whereIn("category_id",$del_ids)->delete();
  948. }
  949. //传过来的值 和 交际 对比,选出要添加的值 进行插入
  950. $insertIDS = array_merge(array_diff($reqIds, $reqidsIntersect),array_diff($reqidsIntersect,$reqIds));
  951. var_dump("要存储的:",$insertIDS);
  952. //新的数组重新创建
  953. if(count($insertIDS)>0){
  954. $arr = [];
  955. $categoryListIds = $insertIDS;
  956. if($categoryListIds){
  957. foreach ($categoryListIds as $v){
  958. $ids = $this->getUnderlingUIds(intval($v));
  959. $ids_arr = explode(",", $ids);
  960. array_push($arr,$ids_arr);
  961. }
  962. }
  963. $mergedArray = [];
  964. foreach ($arr as $subarray) {
  965. $mergedArray = array_merge($mergedArray, $subarray);
  966. }
  967. var_dump("要插入的ID:",$mergedArray);
  968. //查询出所有的分类进行分割插入 组装数据
  969. $categoryListData = Category::whereIn('id',$mergedArray)->get();
  970. $categoryListData = $categoryListData->toArray();
  971. $insertData = [];
  972. if($categoryListData){
  973. foreach ($categoryListData as $key=>$value){
  974. $insertData[$key]['website_id'] = $data['website_id'];
  975. $insertData[$key]['name'] = $value['name'];
  976. $insertData[$key]['sort'] = $value['sort'];
  977. $insertData[$key]['pid'] = $value['pid'];
  978. $insertData[$key]['pid_arr'] = $value['pid_arr'];
  979. $insertData[$key]['seo_title'] = $value['seo_title'];
  980. $insertData[$key]['seo_keywords'] = $value['seo_keywords'];
  981. $insertData[$key]['seo_description'] = $value['seo_description'];
  982. $insertData[$key]['alias'] = $value['name'];
  983. $insertData[$key]['category_id'] = $value['id'];
  984. }
  985. }
  986. WebsiteCategory::insert($insertData);
  987. }
  988. Db::commit();
  989. } catch(\Throwable $ex){
  990. Db::rollBack();
  991. var_dump($ex->getMessage());
  992. return Result::error("修改失败",0);
  993. }
  994. return Result::success();
  995. }
  996. /**
  997. * 获取网站列表
  998. * @param array $data
  999. * @return array
  1000. */
  1001. public function getWebsiteCategoryList(array $data): array
  1002. {
  1003. $where = [];
  1004. if(isset($data['keyword']) && !empty($data['keyword'])){
  1005. array_push($where,['website.website_name','like','%'.$data['keyword'].'%']);
  1006. }
  1007. if(isset($data['website_column_id']) && !empty($data['website_column_id'])){
  1008. array_push($where,['website.website_column_id','=',$data['website_column_id']]);
  1009. }
  1010. $result = Website::where($where)
  1011. ->with(["websiteCategory"=>function ($query) {
  1012. $query->where(['pid'=>0])->select('website_id','name','alias','category_id');
  1013. }])
  1014. ->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])
  1015. ->get();
  1016. $count = Website::where($where)->count();
  1017. if (empty($result)) {
  1018. return Result::error("没有数据",0);
  1019. }
  1020. $data = [
  1021. 'rows'=>$result->toArray(),
  1022. 'count'=>$count
  1023. ];
  1024. if($result){
  1025. return Result::success($data);
  1026. }else{
  1027. return Result::error("查询失败",0);
  1028. }
  1029. }
  1030. /**
  1031. * 删除网站下的所有导航
  1032. * @param array $data
  1033. * @return array
  1034. */
  1035. public function delWebsiteAllCategory(array $data): array
  1036. {
  1037. $website_id = $data['website_id'];
  1038. $result = WebsiteCategory::where(['website_id'=>$website_id])->delete();
  1039. if($result){
  1040. return Result::success($result);
  1041. }else{
  1042. return Result::error("删除失败",0);
  1043. }
  1044. }
  1045. /**
  1046. * 获取网站下的某一个导航
  1047. * @param array $data
  1048. * @return array
  1049. */
  1050. public function getWebsiteCategoryOnes(array $data): array
  1051. {
  1052. $website_id = $data['website_id'];
  1053. $category_id = $data['category_id'];
  1054. $result = WebsiteCategory::where(['website_category.website_id'=>$website_id,'website_category.category_id'=>$category_id])
  1055. ->first();
  1056. if($result){
  1057. return Result::success($result);
  1058. }else{
  1059. return Result::error("查询失败",0);
  1060. }
  1061. }
  1062. /**
  1063. * 更新网闸下的某一个导航
  1064. * @param array $data
  1065. * @return array
  1066. */
  1067. public function upWebsiteCategoryones(array $data): array
  1068. {
  1069. $where = [
  1070. 'website_id'=>$data['website_id'],
  1071. 'category_id'=>$data['category_id'],
  1072. ];
  1073. $result = WebsiteCategory::where($where)->update($data);
  1074. if($result){
  1075. return Result::success($result);
  1076. }else{
  1077. return Result::error("更新失败",0);
  1078. }
  1079. }
  1080. /**
  1081. * 获取网站下的所有导航(包含子导航)
  1082. * @param array $data
  1083. * @return array
  1084. */
  1085. public function getWebsiteAllCategory(array $data): array
  1086. {
  1087. $where = [];
  1088. if(isset($data['website_id']) && !empty($data['website_id'])){
  1089. array_push($where,['website_category.website_id','=',$data['website_id']]);
  1090. }
  1091. if(isset($data['name']) && !empty($data['name'])){
  1092. array_push($where,['website_category.name','like','%'.$data['name'].'%']);
  1093. }
  1094. if(isset($data['alias']) && !empty($data['alias'])){
  1095. array_push($where,['website_category.alias','like','%'.$data['alias'].'%']);
  1096. }
  1097. if(isset($data['department_id']) && !empty($data['department_id'])){
  1098. array_push($where,['category.department_id','=',$data['department_id']]);
  1099. }
  1100. if(isset($data['city_id']) && !empty($data['city_id'])){
  1101. array_push($where,['category.city_id','=',$data['city_id']]);
  1102. }
  1103. $result = WebsiteCategory::where($where)
  1104. ->leftJoin("category",'website_category.category_id','category.id')
  1105. ->leftJoin("department",'category.department_id','department.id')
  1106. ->leftJoin("district",'category.city_id','district.id')
  1107. ->select("website_category.*","department.name as department_name","district.name as city_name")
  1108. ->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])
  1109. ->get();
  1110. $count = WebsiteCategory::where($where)
  1111. ->leftJoin("category",'website_category.category_id','category.id')
  1112. ->leftJoin("department",'category.department_id','department.id')
  1113. ->leftJoin("district",'category.city_id','district.id')
  1114. ->count();
  1115. if (empty($result)) {
  1116. return Result::error("没有数据",0);
  1117. }
  1118. $data = [
  1119. 'rows'=>$result->toArray(),
  1120. 'count'=>$count
  1121. ];
  1122. if($result){
  1123. return Result::success($data);
  1124. }else{
  1125. return Result::error("查询失败",0);
  1126. }
  1127. if($result){
  1128. return Result::success($result);
  1129. }else{
  1130. return Result::error("查询失败",0);
  1131. }
  1132. }
  1133. /**
  1134. * 递归查询数据
  1135. * @param $id
  1136. * @param $ids
  1137. * @return string
  1138. */
  1139. public function getUnderlingUIds($id, $ids='')
  1140. {
  1141. $back = Category::where(['pid'=>$id])->get();
  1142. $back = $back->toArray();
  1143. if (!empty($back) && is_array($back)) {
  1144. foreach ($back as $v) {
  1145. //防止当前人的ID重复去查询,形成恶性循环
  1146. if ($v['id'] == $id) {
  1147. continue;
  1148. }
  1149. $back2 = Category::where(['pid'=>$id])->count('id');
  1150. if ($back2 > 0) {
  1151. $ids = $this->getUnderlingUIds($v['id'],$ids);
  1152. } else {
  1153. $ids .= ','.$v['id'];
  1154. }
  1155. }
  1156. }
  1157. $ids = $id.','.$ids.',';
  1158. $ids = str_replace(',,', ",", $ids);
  1159. $ids = trim($ids, ',');
  1160. return $ids;
  1161. }
  1162. /**
  1163. * 检测网站名称是否重复
  1164. * @param array $data
  1165. * @return array
  1166. */
  1167. public function checkWebsiteName(array $data): array
  1168. {
  1169. if(isset($data['id'])){
  1170. $data[] = ['id',"!=",$data['id']];
  1171. unset($data['id']);
  1172. }
  1173. $websiteInfo = Website::query()->where($data)->first();
  1174. if (empty($websiteInfo)) {
  1175. return Result::error("找不到网站",0);
  1176. }
  1177. return Result::success($websiteInfo->toArray());
  1178. }
  1179. /**
  1180. * 检测网站url是否重复
  1181. * @param array $data
  1182. * @return array
  1183. */
  1184. public function checkWebsiteUrl(array $data): array
  1185. {
  1186. $whereData = [];
  1187. if(isset($data['id'])){
  1188. $whereData = [['id',"!=",$data['id']]];
  1189. unset($data['id']);
  1190. }
  1191. $websiteInfo = Website::query()->where($whereData)->whereJsonContains('website_url', $data['website_url'])->first();
  1192. if (empty($websiteInfo)) {
  1193. return Result::error("找不到URL",0);
  1194. }
  1195. return Result::success($websiteInfo->toArray());
  1196. }
  1197. /**
  1198. * 获取网站底部基础信息
  1199. * @param array $data
  1200. * @return array
  1201. */
  1202. public function getWebsiteFootInfo(array $data): array
  1203. {
  1204. if(isset($data['website_id']) && !empty($data['website_id'])){
  1205. $website_head = Website::where('id',$data['website_id'])
  1206. ->where('status',1)
  1207. ->select('id', 'website_name', 'logo', 'title', 'keywords', 'description', 'suffix', 'website_url')
  1208. ->first();
  1209. if (empty($website_head)) {
  1210. return Result::error("找不到网站",0);
  1211. }
  1212. }else{
  1213. return Result::error("参数错误",0);
  1214. }
  1215. $website_foot = WebsiteTemplateInfo::where('website_id',$data['website_id'])->where('status',2)->first();
  1216. if (empty($website_foot)) {
  1217. return Result::error("暂无底部基础信息",0);
  1218. }
  1219. $website_head['website_url'] = $website_head['website_url'] ? json_decode($website_head['website_url']) : [];
  1220. $result = [
  1221. 'website_foot'=>$website_foot,
  1222. 'website_head'=>$website_head
  1223. ];
  1224. return Result::success($result);
  1225. }
  1226. /**
  1227. * 获取网站底部导航
  1228. * @param array $data
  1229. * @return array
  1230. */
  1231. public function getWebsiteFooterCategory(array $data): array
  1232. {
  1233. if(isset($data['website_id']) && !empty($data['website_id'])){
  1234. $website = Website::where('id',$data['website_id'])->where('status',1)->first();
  1235. if (empty($website)) {
  1236. return Result::error("找不到网站",0);
  1237. }
  1238. }else{
  1239. return Result::error("参数错误",0);
  1240. }
  1241. $result = FooterCategory::where('website_id',$data['website_id'])->get();
  1242. if (empty($result)) {
  1243. return Result::error("暂无底部导航",0);
  1244. }
  1245. return Result::success($result->toArray());
  1246. }
  1247. /**
  1248. * 获取网站底部导航列表
  1249. * @param array $data
  1250. * @return array
  1251. */
  1252. public function getWebsiteFooterCategoryList(array $data): array
  1253. {
  1254. if(isset($data['website_id']) && !empty($data['website_id'])){
  1255. $website = Website::where('id',$data['website_id'])->where('status',1)->first();
  1256. if (empty($website)) {
  1257. return Result::error("找不到网站",0);
  1258. }
  1259. }else{
  1260. return Result::error("参数错误",0);
  1261. }
  1262. $footercategory = FooterCategory::where('website_id',$data['website_id'])->where('id',$data['fcat_id'])->first();
  1263. // '底部导航类型 0:内容型;1:列表型;',
  1264. if (!isset($footercategory['type']) || $footercategory['type'] == 0) {
  1265. return Result::error("底部导航id错误",0);
  1266. }else{
  1267. $query = FooterContent::where('fcat_id',$data['fcat_id']);
  1268. if($query->count() == 0){
  1269. return Result::error("暂无底部导航列表",0);
  1270. }elseif($query->count() == 1){
  1271. $result = $query->first();
  1272. }else{
  1273. $result = $query->get();
  1274. }
  1275. }
  1276. return Result::success($result);
  1277. }
  1278. /**
  1279. * 获取网站底部导航
  1280. * @param array $data
  1281. * @return array
  1282. */
  1283. public function getWebsiteFooterCategoryInfo(array $data): array
  1284. {
  1285. if(isset($data['website_id']) && !empty($data['website_id'])){
  1286. $website = Website::where('id',$data['website_id'])->where('status',1)->first();
  1287. if (empty($website)) {
  1288. return Result::error("找不到网站",0);
  1289. }
  1290. }else{
  1291. return Result::error("参数错误",0);
  1292. }
  1293. if (isset($data['type']) && $data['type'] == 0) {
  1294. $fcatid = FooterCategory::where('website_id',$data['website_id'])->where('id',$data['fcat_id'])->first();
  1295. if (empty($fcatid)) {
  1296. return Result::error("底部导航id错误",0);
  1297. }
  1298. $result = FooterContent::where('fcat_id',$data['fcat_id'])->first();
  1299. }else{
  1300. $result = FooterContent::where('id',$data['fcat_id'])->first();
  1301. }
  1302. if (empty($result)) {
  1303. return Result::error("暂无底部导航内容",0);
  1304. }
  1305. return Result::success($result);
  1306. }
  1307. /*
  1308. * 搜索网站二级导航
  1309. * @param array $data
  1310. * @return array
  1311. * */
  1312. public function selectWebsiteCategory(array $data): array
  1313. {
  1314. if(isset($data['website_id']) &&!empty($data['website_id'])){
  1315. $website = Website::where('id',$data['website_id'])->where('status',1)->first();
  1316. if (empty($website)) {
  1317. return Result::error("暂无该网站",0);
  1318. }
  1319. $category = WebsiteCategory::where('website_id',$data['website_id'])->pluck('category_id')->all();
  1320. // return Result::success($category);
  1321. if (empty($category)) {
  1322. return Result::error("暂无此导航",0);
  1323. }
  1324. $query = Category::whereIn('id', $category);
  1325. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1326. $cityid = District::where('id', $data['cityid'])->first();
  1327. if (empty($cityid)) {
  1328. return Result::error("暂无此城市", 0);
  1329. } else {
  1330. $city_category = $query->whereRaw('JSON_CONTAINS(city_arr_id,?)', [$data['cityid']])->pluck('id');
  1331. // $where[] = ['JSON_CONTAINS(city_arr_id, ?)', $data['cityid']];
  1332. if (empty($city_category)) {
  1333. return Result::error("暂无此城市下的导航", 0);
  1334. }
  1335. $result['catid'] = $city_category;
  1336. $city = 1;
  1337. // var_dump("城市====================",$result);
  1338. }
  1339. }
  1340. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1341. $departmentid = Department::where('id', $data['department_id'])->first();
  1342. if (empty($departmentid)) {
  1343. return Result::error("暂无此部门", 0);
  1344. } else {
  1345. $depart_category = $query->whereRaw('JSON_CONTAINS(department_arr_id,?)', [$data['department_id']])->pluck('id');
  1346. if (empty($depart_category)) {
  1347. return Result::error("暂无此部门下的导航", 0);
  1348. }
  1349. $result['catid'] = $depart_category;
  1350. // var_dump("职能部门*******************",$result);
  1351. $department = 1;
  1352. }
  1353. }
  1354. if(!empty($city) && !empty($department)){
  1355. // var_dump("城市和职能部门----------------------",$result);
  1356. $sel_category = $query->whereRaw('JSON_CONTAINS(city_arr_id,?)', [$data['cityid']])->whereRaw('JSON_CONTAINS(department_arr_id,?)', [$data['department_id']])->pluck('id');
  1357. if (empty($sel_category)) {
  1358. return Result::error("暂无此城市和职能部门下的导航", 0);
  1359. }
  1360. $result['catid'] = $sel_category;
  1361. }
  1362. if (empty($result)) {
  1363. return Result::error("暂无导航",0);
  1364. }
  1365. // department_id
  1366. }else{
  1367. return Result::error("参数错误",0);
  1368. }
  1369. return Result::success($result);
  1370. }
  1371. /**
  1372. * 获取网站栏目seo
  1373. * @param array $data
  1374. * @return array
  1375. */
  1376. public function getWebsiteCategoryHead(array $data): array
  1377. {
  1378. if(isset($data['website_id']) && !empty($data['website_id'])){
  1379. $website = Website::where('id',$data['website_id'])->where('status',1)->first();
  1380. if (empty($website)) {
  1381. return Result::error("找不到网站",0);
  1382. }
  1383. }else{
  1384. return Result::error("参数错误",0);
  1385. }
  1386. if (isset($data['catid']) && !empty($data['catid'])) {
  1387. $fcatid = WebsiteCategory::where('website_id',$data['website_id'])->where('category_id',$data['catid'])->first();
  1388. if (empty($fcatid)) {
  1389. return Result::error("导航id错误",0);
  1390. }
  1391. $result = Category::where('id',$data['catid'])->first();
  1392. }
  1393. if (empty($result)) {
  1394. return Result::error("暂无导航",0);
  1395. }
  1396. return Result::success($result);
  1397. }
  1398. /*
  1399. * 获取某个栏目
  1400. * @param array $data
  1401. * @return array
  1402. * */
  1403. public function getOneWebsiteCategory(array $data): array
  1404. {
  1405. if(isset($data['website_id']) &&!empty($data['website_id'])){
  1406. $website = Website::where('id',$data['website_id'])->where('status',1)->first();
  1407. if (empty($website)) {
  1408. return Result::error("暂无该网站",0);
  1409. }
  1410. $category = WebsiteCategory::where('website_id',$data['website_id'])->where('category_id',$data['category_id'])->first();
  1411. if (empty($category)) {
  1412. return Result::error("暂无此导航",0);
  1413. }
  1414. $category['children_count'] = WebsiteCategory::where('website_id',$data['website_id'])->where('pid',$data['category_id'])->count();
  1415. $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();
  1416. $category['parent_id'] = $parent['parent_id']?? '';
  1417. $category['parent_pinyin'] = $parent['aLIas_pinyin']?? '';
  1418. $category['parent_name'] = $parent['parent_name']?? '';
  1419. return Result::success($category);
  1420. }else{
  1421. return Result::error("参数错误",0);
  1422. }
  1423. }
  1424. // 自助建站--fr-------------------
  1425. /**
  1426. * 获取并搜索 网站模板信息
  1427. * @param array $data
  1428. * @return array
  1429. */
  1430. public function getWebsiteintel(array $data): array
  1431. {
  1432. //查询所有网站模板信息
  1433. $query = Website::where('website.status', 1)
  1434. ->leftJoin("website_template_info", "website_template_info.website_id", "website.id")
  1435. ->leftJoin("template", "template.id", "website_template_info.template_id")
  1436. ->leftJoin("template_class", "template_class.id", "template.template_class_id")
  1437. ->select(
  1438. "website_template_info.id",
  1439. "template_class.name",
  1440. "website.id as website_id",
  1441. "website.website_name",
  1442. "website.website_url",
  1443. "website_template_info.action_id",
  1444. "website_template_info.created_at",
  1445. "website_template_info.updated_at",
  1446. "website_template_info.page_type",
  1447. DB::raw("COALESCE(website_template_info.status, 0) as template_status"),
  1448. "template.template_name"
  1449. );
  1450. //若存在条件;则在$query的基础上进行筛选
  1451. if(isset($data['website_name']) && !empty($data['website_name'])){
  1452. $query->where('website.website_name', 'like', '%' . $data['website_name'] . '%');
  1453. }
  1454. if(isset($data['status']) && !empty($data['status'])){
  1455. $query->where('website_template_info.status', $data['status']);
  1456. }
  1457. $count = $query->count();
  1458. $query->limit($data['pageSize'])
  1459. ->offset(($data['page'] - 1) * $data['pageSize'])
  1460. ->orderBy("website_template_info.updated_at", "desc");
  1461. $rep = $query->get();
  1462. if($rep->count()==0){
  1463. return Result::error("没有查找到相关数据",0);
  1464. } else {
  1465. $rep->each(function ($item) {
  1466. if (!empty($item->page_type)) {
  1467. $pageTypeArray = json_decode($item->page_type, true);
  1468. if (is_array($pageTypeArray)) {
  1469. $item->page_type = $pageTypeArray;
  1470. }
  1471. }
  1472. });
  1473. $result = [
  1474. "rows" => $rep->toArray(),
  1475. "count" => $count
  1476. ];
  1477. return Result::success($result);
  1478. }
  1479. // return Result::success($result);
  1480. }
  1481. /**
  1482. * 添加网站基础信息
  1483. * @param array $data
  1484. * @return array
  1485. */
  1486. public function addWebsiteTemplateintel(array $data): array
  1487. {
  1488. $website = Website::where('website.id',$data['website_id'])->first();
  1489. if(empty($website)){
  1490. return Result::error("请输入正确的网站id!", 0);
  1491. }
  1492. if(empty($website['website_column_id'])){
  1493. return Result::error("请先关联导航池!", 0);
  1494. }
  1495. // 获取此网站的底部导航 类型 type: 0:内容型底部导航(只有一条详情内容);1:列表型底部导航(可以有多条详情内容)
  1496. $foot_type = FooterCategory::where('website_id',$data['website_id'])->pluck('type')->toArray();
  1497. if (empty($foot_type)) {
  1498. return Result::error("请先关联底部导航池!", 0);
  1499. } elseif (in_array(1, $foot_type)) {
  1500. $foot_type = 1;
  1501. } else {
  1502. $foot_type = 0;
  1503. }
  1504. $result['foot_type'] = $foot_type;
  1505. // 友情链接类型'1:图片 2:文字 3:底部';
  1506. $types = Link::where('website_id', $data['website_id'])->pluck('type')->toArray();
  1507. $missingTypes = [];
  1508. if (!in_array(1, $types)) {
  1509. $missingTypes[] = "文字链接";
  1510. }
  1511. if (!in_array(2, $types)) {
  1512. $missingTypes[] = "图片链接";
  1513. }
  1514. if (!in_array(3, $types)) {
  1515. $missingTypes[] = "底部链接";
  1516. }
  1517. if (!empty($missingTypes)) {
  1518. $errorMessage = "请先添加 " . implode(" 和 ", $missingTypes) . "!";
  1519. return Result::error($errorMessage, 0);
  1520. }
  1521. if(isset($data['page_type'])){
  1522. // 删除重复元素并重新索引数组
  1523. $data['page_type'] = array_unique($data['page_type']);
  1524. $data['page_type'] = array_values($data['page_type']);
  1525. if (in_array(1, $data['page_type']) && in_array(7, $data['page_type'])) {
  1526. // 数组中同时包含值为 1(首页) 和值为 7 (底部导航详情页)的元素
  1527. $info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1528. if (empty($info)) {
  1529. // 将数组转换为 JSON 字符串
  1530. $data['page_type'] = json_encode($data['page_type'])??'';
  1531. // 操作状态:1:填写完成基础信息;2:选择完成模板;0:未构建
  1532. $data['action_id'] = 1;
  1533. try {
  1534. $result = WebsiteTemplateInfo::insertGetId($data);
  1535. } catch (\Exception $e) {
  1536. if ($e->getCode() == 22001) {
  1537. $errorMessage = $e->getMessage();
  1538. return Result::error("请检查表单,某个字段超出了长度限制!");
  1539. } else {
  1540. // 处理其他类型的数据库错误
  1541. return Result::error("插入操作失败: " . $e->getMessage());
  1542. }
  1543. return Result::error("添加失败!", 0);
  1544. }
  1545. } else {
  1546. return Result::error("该网站已经构建过了!", 0);
  1547. }
  1548. } else {
  1549. return Result::error("请先选择首页和底部导航详情页!", 0);
  1550. }
  1551. }
  1552. if(empty($result)){
  1553. return Result::error("添加失败!",0);
  1554. }else{
  1555. return Result::success($result);
  1556. }
  1557. }
  1558. /**
  1559. * 获取网站基础信息
  1560. *
  1561. * @return array
  1562. */
  1563. public function getWebsiteTemplateintel(array $data): array
  1564. {
  1565. $result = WebsiteTemplateInfo::where('website_template_info.website_id',$data['website_id'])
  1566. ->leftJoin('footer_category','footer_category.website_id','website_template_info.website_id')
  1567. ->leftJoin('website','website.id','website_template_info.website_id')
  1568. ->select(
  1569. "website_template_info.*",
  1570. "footer_category.type",
  1571. "website.website_name",
  1572. "website.id as website_id"
  1573. )
  1574. ->first();
  1575. if(empty($result['website_name'])){
  1576. return Result::error("请输入正确的网站id!", 0);
  1577. }
  1578. if($result){
  1579. $result['page_type'] = json_decode($result['page_type'],true);
  1580. return Result::success($result);
  1581. }else{
  1582. return Result::error("请先添加网站基础信息!",0);
  1583. }
  1584. }
  1585. /**
  1586. * 修改网站基础信息
  1587. *
  1588. * @return array
  1589. */
  1590. public function upWebsiteTemplateintel(array $data): array
  1591. {
  1592. $web = Website::where('website.id',$data['website_id'])->first();
  1593. if(empty($web)){
  1594. return Result::error("请输入正确的网站id!", 0);
  1595. }
  1596. $where = ['website_id'=>$data['website_id']];
  1597. $result = WebsiteTemplateInfo::where($where)->first();
  1598. if(empty($result)){
  1599. return Result::error("请先添加网站基础信息!",0);
  1600. }else{
  1601. unset($data['website_id']);
  1602. // 删除重复元素
  1603. $data['page_type'] = array_unique($data['page_type']);
  1604. // 重新索引数组
  1605. $data['page_type'] = array_values($data['page_type']);
  1606. // 数组中同时包含值为 1(首页) 和值为 7 (底部导航详情页)的元素
  1607. if (in_array(1, $data['page_type']) && in_array(7, $data['page_type'])) {
  1608. // 将数组转换为 JSON 字符串
  1609. $data['page_type'] = json_encode($data['page_type'])??'';
  1610. try {
  1611. $result = WebsiteTemplateInfo::where($where)->update($data);
  1612. } catch (\Exception $e) {
  1613. if ($e->getCode() == 22001) {
  1614. $errorMessage = $e->getMessage();
  1615. return Result::error("请检查表单,某个字段超出了长度限制!");
  1616. } else {
  1617. // 处理其他类型的数据库错误
  1618. return Result::error("修改操作失败: " . $e->getMessage());
  1619. }
  1620. return Result::error("修改失败!", 0);
  1621. }
  1622. }else{
  1623. return Result::error("请先选择首页和底部导航详情页!",0);
  1624. }
  1625. }
  1626. if(empty($result)){
  1627. return Result::error("修改失败!",0);
  1628. }else{
  1629. return Result::success($result);
  1630. }
  1631. }
  1632. /**
  1633. * 获取所有网站风格信息
  1634. *
  1635. * @return array
  1636. */
  1637. public function getAllTemplateClass(array $data): array
  1638. {
  1639. $result = TemplateClass::all();
  1640. if(empty($result)){
  1641. return Result::error("没有查找到相关数据!",0);
  1642. }else{
  1643. return Result::success($result);
  1644. }
  1645. }
  1646. /**
  1647. * 搜索并获取网站模板信息
  1648. * @param array $data
  1649. * @return array
  1650. */
  1651. public function getWebsiteTemplateList(array $data): array
  1652. {
  1653. $website = Website::where('website.id',$data['website_id'])->first();
  1654. if(empty($website)){
  1655. return Result::error("请输入正确的网站id!",0);
  1656. }else{
  1657. $page_type = WebsiteTemplateInfo::where('website_id',$data['website_id'])->select('page_type')->first();
  1658. if(empty($page_type)){
  1659. return Result::error("此网站还未添加基础信息!",0);
  1660. } else{
  1661. $where = json_decode($page_type['page_type'], true);
  1662. // $where = $data["page_type"];
  1663. if(isset($data['template_class_id']) && !empty($data['template_class_id'])){
  1664. $template_class = TemplateClass::where('id',$data['template_class_id'])->first();
  1665. if(empty($template_class)){
  1666. return Result::error("请输入正确的模板风格id!",0);
  1667. }else{
  1668. // 获取指定风格下的模板
  1669. $rep = Template::where('template_class_id', $data['template_class_id'])
  1670. ->where(function ($query) use ($where) {
  1671. foreach ($where as $value) {
  1672. $query->whereJsonContains('template_img', ['value' => $value]);
  1673. }
  1674. })
  1675. ->limit($data['pageSize'])
  1676. ->offset(($data['page'] - 1) * $data['pageSize'])
  1677. ->orderBy("template.updated_at", "desc")
  1678. ->get();
  1679. $count = Template::where('template_class_id', $data['template_class_id'])
  1680. ->where(function ($query) use ($where) {
  1681. foreach ($where as $value) {
  1682. $query->whereJsonContains('template_img', ['value' => $value]);
  1683. }
  1684. })->count();
  1685. }
  1686. }else{
  1687. //获取所有模板
  1688. $rep = Template::where(function ($query) use ($where) {
  1689. foreach ($where as $value) {
  1690. $query->whereJsonContains('template_img', ['value' => $value]);
  1691. }
  1692. })
  1693. ->limit($data['pageSize'])
  1694. ->offset(($data['page'] - 1) * $data['pageSize'])
  1695. ->orderBy("template.updated_at", "desc")
  1696. ->get();
  1697. $count = Template::where(function ($query) use ($where) {
  1698. foreach ($where as $value) {
  1699. $query->whereJsonContains('template_img', ['value' => $value]);
  1700. }
  1701. })->count();
  1702. }
  1703. if(empty($rep) || $rep->count()==0){
  1704. return Result::error("没有查找到相关数据!",0);
  1705. }else{
  1706. // 过滤 template_img 字段 只获取 基础信息中 包含的模板图片
  1707. // $rep->each(function ($item) use ($where) {
  1708. // $template_img = json_decode($item->template_img, true);
  1709. // if(is_array($template_img)){
  1710. // $filtered_img = array_filter($template_img, function ($img) use ($where) {
  1711. // return isset($img['value']) && in_array($img['value'], $where);
  1712. // });
  1713. // }
  1714. // $item->template_img = $filtered_img;
  1715. // });
  1716. // $result = [
  1717. // "rows" => $rep->toArray(),
  1718. // "count" => $count
  1719. // ];
  1720. $rep->each(function ($item) use ($where) {
  1721. $template_img = json_decode($item->template_img, true);
  1722. if (is_array($template_img)) {
  1723. $filtered_img = array_filter($template_img, function ($img) use ($where) {
  1724. return isset($img['value']) && in_array($img['value'], $where);
  1725. });
  1726. // 对过滤后的数组进行重新排序
  1727. $sorted_img = array_values($filtered_img);
  1728. $item->template_img = $sorted_img;
  1729. } else {
  1730. $item->template_img = []; // 如果无法解码为数组,则设置为空数组
  1731. }
  1732. });
  1733. $result = [
  1734. "rows" => $rep->toArray(),
  1735. "count" => $count
  1736. ];
  1737. }
  1738. }
  1739. }
  1740. return Result::success($result);
  1741. }
  1742. /**
  1743. * 添加网站模板
  1744. * @param array $data
  1745. */
  1746. public function addWebsiteTemplateclassintel(array $data): array
  1747. {
  1748. $template = Template::where('id',$data['template_id'])->first();
  1749. $web = Website::where('id',$data['website_id'])->first();
  1750. if(empty($template)){
  1751. return Result::error("请输入正确的模板id",0);
  1752. }
  1753. if(empty($web)){
  1754. return Result::error("请输入正确的网站id",0);
  1755. }
  1756. $result = WebsiteTemplateInfo::where('website_id',$data['website_id'])->update(['template_id'=>$data['template_id'],'action_id'=>2]);
  1757. if(empty($result)){
  1758. return Result::error("添加失败",0);
  1759. }else{
  1760. return Result::success($result);
  1761. }
  1762. }
  1763. /**
  1764. * 获取网站模板信息
  1765. * @param array $data
  1766. */
  1767. public function getWebsiteTemplateclassintel(array $data): array
  1768. {
  1769. // return Result::success($data);
  1770. $template = WebsiteTemplateInfo::where('website_id',$data['website_id'])->first();
  1771. if(empty($template)){
  1772. return Result::error("请输入正确的搭建网站id",0);
  1773. }
  1774. $page_type = json_decode($template['page_type'], true);
  1775. // 获取指定网站下的基础信息和模板及风格信息
  1776. $result = WebsiteTemplateInfo::where([
  1777. ['website_template_info.website_id',$data['website_id']],
  1778. ['template_id','!=',null]
  1779. ])
  1780. ->leftJoin('template','template.id','website_template_info.template_id')
  1781. ->leftJoin('template_class','template_class.id','template.template_class_id')
  1782. ->where(function ($query) use ($page_type) {
  1783. // 假设 $data['page_type'] 是一个数组,包含需要匹配的 page_type 值
  1784. foreach ($page_type as $pageType) {
  1785. $query->orWhereJsonContains('template.template_img', ['value' => $pageType]);
  1786. }
  1787. })
  1788. ->select(
  1789. 'template.template_name',
  1790. 'template.template_img',
  1791. 'template.id as tid',
  1792. 'template_class.name',
  1793. 'template_class.id as class_id',
  1794. 'website_template_info.page_type',
  1795. 'website_template_info.website_id')
  1796. ->first();
  1797. if(empty($result)){
  1798. return Result::error("没有查找到相关数据",0);
  1799. }
  1800. // return Result::success($result);
  1801. // 过滤 template_img 字段 只获取 基础信息中 包含的模板图片
  1802. $template_img = $result['template_img'] !== null ? json_decode($result['template_img'], true) : [];
  1803. $page_type = $result['page_type'] !== null ? json_decode($result['page_type'], true) : [];
  1804. foreach ($template_img as $key => $value) {
  1805. if (!in_array($value['value'], $page_type)) {
  1806. unset($template_img[$key]);
  1807. }
  1808. }
  1809. // return Result::success($result);
  1810. $result['template_img'] = array_values($template_img);
  1811. $result['page_type'] = $page_type;
  1812. // $templateList = $this->getWebsiteTemplateList($data);
  1813. // $count = $templateList['data']['count']??'';
  1814. // $pages = $count / $data['pageSize'];
  1815. // $found = false;
  1816. // while ($pages && !$found) {
  1817. // $templates = $this->getWebsiteTemplateList($pages,$data['pageSize']);
  1818. // $index = array_search($template['template_id'], array_column($templates['rows'], 'id'));
  1819. // if ($index !== false) {
  1820. // $found = true;
  1821. // $result['page'] = $pages;
  1822. // $pages = 0;
  1823. // // echo "查询到的 template 在第 $page 页";
  1824. // }
  1825. // $pages--;
  1826. // }
  1827. return Result::success($result);
  1828. }
  1829. /**
  1830. * 获取网站模板下的板块信息
  1831. * @param array $data
  1832. */
  1833. public function getWebsiteSectorList(array $data): array
  1834. {
  1835. $website = Website::where('id',$data['website_id'])->first();
  1836. if(empty($website)){
  1837. return Result::error("请输入正确的网站id",0);
  1838. }
  1839. $template = WebsiteTemplateInfo::where('website_id',$data['website_id'])->first();
  1840. if(empty($template['template_id'])){
  1841. return Result::error("请先添加网站模板",0);
  1842. }
  1843. $query = Sector::where('template_id',$template['template_id']);
  1844. if($query->count() == 0){
  1845. return Result::error("没有查找到相关板块数据",0);
  1846. }elseif($query->count() == 1){
  1847. $sector = $query->first();
  1848. }else{
  1849. $sector = $query->get();
  1850. }
  1851. $result['page_type'] = $template['page_type'];
  1852. $result['tid'] = $template['template_id'];
  1853. $result = [
  1854. "tid" => $template['template_id'],
  1855. "page_type" => $template['page_type'],
  1856. "sector" => $sector
  1857. ];
  1858. return Result::success($result);
  1859. }
  1860. // 自助建站---------------fr---------------
  1861. // 网站底基础信息--fr-------------------
  1862. /**
  1863. * 添加网站底基础信息
  1864. * @param array $data
  1865. */
  1866. public function addWebFootInfo(array $data): array
  1867. {
  1868. $website = Website::where('id',$data['website_id'])->first();
  1869. if(empty($website)){
  1870. return Result::error("请输入正确的网站id!", 0);
  1871. }
  1872. $info = WebsiteTemplateInfo::where('website_id',$data['website_id'])->first();
  1873. if(!empty($info)){
  1874. return Result::error("该网站已经添加过了!", 0);
  1875. }
  1876. $result = WebsiteTemplateInfo::where('website_id',$data['website_id'])->insertGetId($data);
  1877. if(empty($result)){
  1878. return Result::error("请先添加网站基础信息!",0);
  1879. }else{
  1880. return Result::success($result);
  1881. }
  1882. }
  1883. /**
  1884. * 获取网站底基础信息
  1885. * @param array $data
  1886. */
  1887. public function getWebFootInfo(array $data): array
  1888. {
  1889. $website = Website::where('id',$data['website_id'])->first();
  1890. if(empty($website)){
  1891. return Result::error("请输入正确的网站id!", 0);
  1892. }
  1893. $result = WebsiteTemplateInfo::where('website_id',$data['website_id'])->first();
  1894. if(empty($result)){
  1895. return Result::error("请先添加网站基础信息!",0);
  1896. }
  1897. return Result::success($result);
  1898. }
  1899. /**
  1900. * 修改网站底基础信息
  1901. * @param array $data
  1902. */
  1903. public function upWebFootInfo(array $data): array
  1904. {
  1905. // return Result::success($data);
  1906. $website = Website::where('id',$data['website_id'])->first();
  1907. if(empty($website)){
  1908. return Result::error("请输入正确的网站id!", 0);
  1909. }
  1910. $web = $data['website_id'];
  1911. unset($data['website_id']);
  1912. $where = ['website_id'=>$web];
  1913. // return Result::success($data);
  1914. $result = WebsiteTemplateInfo::where($where)->first();
  1915. if(empty($result)){
  1916. $data['website_id'] = $web;
  1917. $result = WebsiteTemplateInfo::insertGetId($data);
  1918. // return Result::error("请先添加网站基础信息!",0);
  1919. } else{
  1920. $result = WebsiteTemplateInfo::where($where)->update($data);
  1921. }
  1922. // $where = ['website_id'=>$data['website_id']];
  1923. // unset($data['website_id']);
  1924. // $result = WebsiteTemplateInfo::updateOrInsert($where, $data);
  1925. if(empty($result)){
  1926. return Result::error("修改失败!",0);
  1927. }
  1928. return Result::success($result);
  1929. }
  1930. /*
  1931. * 获取父级/子级栏目------路由
  1932. * @param array $data
  1933. * @return array
  1934. * */
  1935. public function getWebsiteParentCategory(array $data): array
  1936. {
  1937. // return Result::success($data);
  1938. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1939. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1940. }
  1941. if (empty($website)) {
  1942. return Result::error("暂无该网站", 0);
  1943. }
  1944. // 在 Hyperf 中,查询构建器(Builder)没有 `map` 方法,`map` 方法是集合(Collection)的方法。
  1945. // 因此,需要先调用 `get()` 方法获取查询结果集合,再使用 `map` 方法进行处理。
  1946. $category['parent'] = WebsiteCategory::where('website_id', $data['website_id'])
  1947. ->where('pid', 0)
  1948. ->selectRaw("category_id as cid, alias as name, CONCAT('/', '', aLIas_pinyin, '/') as path")
  1949. ->get() // 添加 get() 方法获取结果集合
  1950. ->all();
  1951. // 提前查询所有父级栏目,避免在 map 中多次查询
  1952. // 提前查询所有父级栏目信息并以 category_id 作为键存储
  1953. $parentCategories = WebsiteCategory::where('website_id', $data['website_id'])
  1954. ->where('pid', 0)
  1955. ->select('category_id', 'aLIas_pinyin')
  1956. ->get()
  1957. ->keyBy('category_id');
  1958. // 直接查询子栏目信息
  1959. $child = WebsiteCategory::where('website_id', $data['website_id'])
  1960. ->where('pid', '!=', 0)
  1961. ->select('alias', 'category_id', 'aLIas_pinyin', 'pid')
  1962. ->get();
  1963. // 使用集合的 map 方法处理子栏目信息
  1964. $category['child'] = $child->map(function ($item) use ($parentCategories) {
  1965. $alias = $item->alias;
  1966. $category_id = $item->category_id;
  1967. $alias_pinyin = $item->aLIas_pinyin;
  1968. $parent = $parentCategories->get($item->pid);
  1969. $parentAlias = $parent ? $parent->aLIas_pinyin : '';
  1970. $result = [
  1971. 'name' => $alias,
  1972. 'cid' => $category_id
  1973. ];
  1974. if (!empty($alias_pinyin) && !empty($parentAlias)) {
  1975. $result['path'] = "/{$parentAlias}/{$alias_pinyin}/";
  1976. }
  1977. return $result;
  1978. })->values()->all();
  1979. if (empty($category)) {
  1980. return Result::error("暂无此导航", 0);
  1981. }
  1982. return Result::success($category);
  1983. }
  1984. /**
  1985. * 获取网站栏目信息
  1986. * @param array $data
  1987. */
  1988. public function getWebsiteFootAll(array $data): array
  1989. {
  1990. $website = Website::where('id',$data['website_id'])->where('status',1)->first();
  1991. if (empty($website)) {
  1992. return Result::error("暂无该网站",0);
  1993. }
  1994. // 1:图片 2:文字 3:底部
  1995. $result['foot_cate'] = FooterCategory::where('website_id',$data['website_id'])->get()->all();
  1996. $result['link_img'] = Link::where('website_id',$data['website_id'])->where('type',1)->where('status',1)->limit($data['link_imgnum'])->orderBy('sort')->get()->all();
  1997. $result['link_text'] = Link::where('website_id',$data['website_id'])->where('type',2)->where('status',1)->limit($data['link_textnum'])->orderBy('sort')->get()->all();
  1998. $result['link_foot'] = Link::where('website_id',$data['website_id'])->where('type',3)->where('status',1)->limit($data['link_footnum'])->orderBy('sort')->get()->all();
  1999. $result['foot_info'] = WebsiteTemplateInfo::where('website_id',$data['website_id'])->where('status',2)->first();
  2000. if(empty($result)){
  2001. return Result::error("暂无此网站信息",0);
  2002. }
  2003. return Result::success($result);
  2004. }
  2005. /**
  2006. * 获取网站顶部信息
  2007. * @param array $data
  2008. */
  2009. public function getWebsiteHead(array $data): array
  2010. {
  2011. $result = Website::where('id',$data['website_id'])->where('status',1)->select('website_name','logo')->first();
  2012. if (empty($result)) {
  2013. return Result::error("暂无该网站",0);
  2014. }
  2015. return Result::success($result);
  2016. }
  2017. /**
  2018. * 获取网站底部信息
  2019. * @param array $data
  2020. */
  2021. public function getWebsiteRoute(array $data): array
  2022. {
  2023. $website = Website::where('id',$data['website_id'])->where('status',1)->first();
  2024. if (empty($website)) {
  2025. return Result::error("暂无该网站",0);
  2026. }
  2027. // return Result::success($data);
  2028. $result = WebsiteCategory::where('website_id',$data['website_id'])->where('aLIas_pinyin',$data['pinyin'])->first(['category_id']);
  2029. if (empty($result)) {
  2030. return Result::error("暂无此导航",0);
  2031. }
  2032. return Result::success($result['category_id']);
  2033. }
  2034. }