WebsiteService.php 84 KB

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