WebsiteService.php 79 KB

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