WebsiteService.php 78 KB

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