WebsiteService.php 79 KB

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