WebsiteService.php 78 KB

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