WebsiteService.php 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681
  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\UserInfo;
  18. use App\Model\WebsiteRole;
  19. use App\Model\WebsiteRoleUser;
  20. use App\Model\Website;
  21. use App\Model\WebsiteColumn;
  22. use Hyperf\DbConnection\Db;
  23. use Hyperf\RpcServer\Annotation\RpcService;
  24. use App\Tools\Result;
  25. use Carbon\Carbon;
  26. use App\Model\WebsiteCategory;
  27. use App\Model\WebsiteGroup;
  28. use function PHPUnit\Framework\isNull;
  29. #[RpcService(name: "WebsiteService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  30. class WebsiteService implements WebsiteServiceInterface
  31. {
  32. /**
  33. * 获取网站列表
  34. * @param string $keyword
  35. * @param int $page
  36. * @param int $pageSize
  37. * @return array
  38. */
  39. public function getWebsitetList(array $data): array
  40. {
  41. // 构建查询
  42. $query = Website::when($data, function ($query) use ($data) {
  43. if (isset($data['keyword']) && !empty($data['keyword'])) {
  44. $query->where('website.website_name', 'like', '%' . trim($data['keyword']) . '%');
  45. }
  46. if (isset($data['website_column_id']) && !empty($data['website_column_id'])) {
  47. $query->whereJsonContains("website.website_column_arr_id", intval($data['website_column_id']));
  48. }
  49. if (isset($data['city_id']) && !empty($data['city_id'])) {
  50. $query->whereJsonContains("website.city_arr_id", intval($data['city_id']));
  51. }
  52. });
  53. // 执行查询并获取总数和结果
  54. $queryWithJoins = $query->leftJoin("website_column", "website.website_column_id", "website_column.id")
  55. ->leftJoin("district", "district.id", "website.city_id");
  56. $count = $queryWithJoins->count();
  57. $result = $queryWithJoins->select("website.*", "website_column.column_name", "district.name as city_name")
  58. ->limit($data['pageSize'])
  59. ->offset(($data['page'] - 1) * $data['pageSize'])
  60. ->orderBy("website.updated_at", "desc")
  61. ->get();
  62. if (empty($result)) {
  63. return Result::error("没有数据", 0);
  64. }
  65. $data = [
  66. 'rows' => $result->toArray(),
  67. 'count' => $count,
  68. ];
  69. return Result::success($data);
  70. }
  71. /**
  72. * @param array $data
  73. * @return array
  74. */
  75. public function createWebsite(array $data): array
  76. {
  77. var_dump("网站数据:", $data);
  78. $insertData = [
  79. 'website_name' => $data['website_name'],
  80. 'logo' => $data['logo'] ?? '',
  81. 'website_url' => $data['website_url'] ?? '',
  82. // 'city_id'=>$data['city_id']??0,
  83. 'website_column_id' => $data['website_column_id'],
  84. 'title' => $data['title'] ?? '',
  85. 'keywords' => $data['keywords'] ?? '',
  86. 'description' => $data['description'] ?? '',
  87. 'status' => $data['status'] ?? 0,
  88. 'website_column_arr_id' => $data['website_column_arr_id'],
  89. // 'city_arr_id'=>$data['city_arr_id']??[0],
  90. 'template_id' => $data['template_id'] ?? 0,
  91. ];
  92. $result = Website::insertGetId($insertData);
  93. if (empty($result)) {
  94. return Result::error("创建失败", 0);
  95. } else {
  96. return Result::success(["id" => $result]);
  97. }
  98. }
  99. /**
  100. * @param int $id
  101. * @param array $data
  102. * @return array
  103. */
  104. public function updateWebsite(int $id, array $data): array
  105. {
  106. $insertData = [
  107. 'website_name' => $data['website_name'],
  108. 'logo' => $data['logo'] ?? '',
  109. 'website_url' => $data['website_url'] ?? '',
  110. // 'city_id'=>$data['city_id']??0,
  111. 'website_column_id' => $data['website_column_id'],
  112. 'title' => $data['title'] ?? '',
  113. 'keywords' => $data['keywords'] ?? '',
  114. 'description' => $data['description'] ?? '',
  115. 'status' => $data['status'] ?? 0,
  116. 'website_column_arr_id' => $data['website_column_arr_id'],
  117. // 'city_arr_id'=>$data['city_arr_id']??[0],
  118. 'template_id' => $data['template_id'] ?? 0,
  119. ];
  120. $result = Website::where('id', $id)->update($insertData);
  121. var_dump("更新站点", $result);
  122. if (empty($result)) {
  123. return Result::error("更新失败", 0);
  124. } else {
  125. return Result::success();
  126. }
  127. }
  128. /**
  129. * @param int $id
  130. * @return array
  131. */
  132. public function delWebsite(int $id): array
  133. {
  134. $result = Website::where('id', $id)->delete();
  135. if (empty($result)) {
  136. return Result::error("删除失败", 0);
  137. } else {
  138. return Result::success();
  139. }
  140. }
  141. /**
  142. * @param int $id
  143. * @return array
  144. */
  145. public function getWebsiteInfo(int $id): array
  146. {
  147. $where = [
  148. ['website.id', '=', $id],
  149. ];
  150. $result = Website::where($where)
  151. ->leftJoin("template", "template.id", "website.template_id")
  152. ->select("website.*", "template.template_name", "template.template_img")
  153. ->first();
  154. if (empty($result)) {
  155. return Result::error("数据不存在", 0);
  156. } else {
  157. return Result::success($result->toArray());
  158. }
  159. }
  160. /**
  161. * 查询所有的站点栏目
  162. * @return array
  163. */
  164. public function getWebsiteColumn(array $data): array
  165. {
  166. $result = WebsiteColumn::where($data)->get();
  167. if (empty($result)) {
  168. return Result::error("数据不存在", 0);
  169. } else {
  170. return Result::success($result->toArray());
  171. }
  172. }
  173. /**
  174. * @param string $keyword
  175. * @param int $page
  176. * @param int $pageSize
  177. * @return array
  178. */
  179. public function getWebsiteColumnList(array $data): array
  180. {
  181. $where = [];
  182. if (isset($data['keyword']) && $data['keyword']) {
  183. array_push($where, ['website_column.column_name', 'like', '%' . $data['keyword'] . '%']);
  184. }
  185. $result = WebsiteColumn::where($where)
  186. ->leftJoin("website_column as wc", "website_column.pid", "wc.id")
  187. ->select("website_column.*", "wc.column_name as parent_column_name")
  188. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->get();
  189. $count = WebsiteColumn::where($where)->count();
  190. if (empty($result)) {
  191. return Result::error("没有数据", 0);
  192. }
  193. $data = [
  194. 'rows' => $result->toArray(),
  195. 'count' => $count,
  196. ];
  197. return Result::success($data);
  198. }
  199. /**
  200. * @param array $data
  201. * @return array
  202. */
  203. public function createWebsiteColumn(array $data): array
  204. {
  205. $insertData = [
  206. 'column_name' => $data['column_name'],
  207. 'pid' => $data['pid'] ?? '',
  208. 'column_arr_id' => $data['column_arr_id'] ?? [0],
  209. 'sort' => $data['sort'] ?? 0,
  210. 'remark' => $data['remark'] ?? '',
  211. ];
  212. $result = WebsiteColumn::insertGetId($insertData);
  213. if (empty($result)) {
  214. return Result::error("创建失败", 0);
  215. } else {
  216. return Result::success(["id" => $result]);
  217. }
  218. }
  219. /**
  220. * @param int $id
  221. * @param array $data
  222. * @return array
  223. */
  224. public function updateWebsiteColumn(int $id, array $data): array
  225. {
  226. $insertData = [
  227. 'column_name' => $data['column_name'],
  228. 'pid' => $data['pid'] ?? '',
  229. 'column_arr_id' => $data['column_arr_id'] ?? [0],
  230. 'sort' => $data['sort'] ?? 0,
  231. 'remark' => $data['remark'] ?? '',
  232. ];
  233. $result = WebsiteColumn::where('id', $id)->update($insertData);
  234. if (empty($result)) {
  235. return Result::error("更新失败", 0);
  236. } else {
  237. return Result::success();
  238. }
  239. }
  240. /**
  241. * @param int $id
  242. * @return array
  243. */
  244. public function delWebsiteColumn(int $id): array
  245. {
  246. $list = WebsiteColumn::where(['pid' => $id])->get();
  247. if ($list) {
  248. return Result::error("存在子网系,不能删除,请先删除子网系", 0);
  249. }
  250. $result = WebsiteColumn::where('id', $id)->delete();
  251. if (empty($result)) {
  252. return Result::error("删除失败", 0);
  253. } else {
  254. return Result::success();
  255. }
  256. }
  257. /**
  258. * @param string $keyword
  259. * @param int $page
  260. * @param int $pageSize
  261. * @return array
  262. */
  263. public function getWebsiteRoleList(string $keyword, int $page, int $pageSize, int $websiteId): array
  264. {
  265. $where = [
  266. ['role.role_name', 'like', '%' . $keyword . '%'],
  267. ['website_role.website_id', '=', $websiteId],
  268. ];
  269. $result = WebsiteRole::where($where)
  270. ->leftJoin("role", "role.id", "website_role.role_id")
  271. ->select("role.*", "website_role.type", "website_role.role_id", "website_role.id as website_role_id", "website_role.website_id")
  272. ->limit($pageSize)->offset(($page - 1) * $pageSize)->get();
  273. $count = WebsiteRole::where($where)->leftJoin("role", "role.id", "website_role.role_id")->count();
  274. if (empty($result)) {
  275. return Result::error("没有数据", 0);
  276. }
  277. $data = [
  278. 'rows' => $result->toArray(),
  279. 'count' => $count,
  280. ];
  281. return Result::success($data);
  282. }
  283. /**
  284. * @param array $data
  285. * @return array
  286. */
  287. public function createWebsiteRole(array $data): array
  288. {
  289. $insertData = [
  290. 'website_id' => $data['website_id'],
  291. 'role_id' => $data['role_id'] ?? '',
  292. ];
  293. $info = WebsiteRole::where($insertData)->first();
  294. if ($info) {
  295. return Result::error("不能重复添加角色", 0);
  296. }
  297. $insertData['admin_user_id'] = $data['admin_user_id'] ?? '';
  298. $insertData['type'] = $data['type'] ?? '';
  299. $result = WebsiteRole::insertGetId($insertData);
  300. if (empty($result)) {
  301. return Result::error("创建失败", 0);
  302. } else {
  303. return Result::success(["id" => $result]);
  304. }
  305. }
  306. /**
  307. * 暂时用不上
  308. * @param int $id
  309. * @param array $data
  310. * @return array
  311. */
  312. public function updateWebsiteRole(int $id, array $data): array
  313. {
  314. $insertData = [
  315. 'website_id' => $data['website_id'],
  316. 'type' => $data['type'] ?? '',
  317. ];
  318. $result = WebsiteRole::where('id', $id)->update($insertData);
  319. if (empty($result)) {
  320. return Result::error("更新失败", 0);
  321. } else {
  322. return Result::success();
  323. }
  324. }
  325. /**
  326. * @param int $id
  327. * @return array
  328. */
  329. public function delWebsiteRole(int $id): array
  330. {
  331. $result = WebsiteRole::where('id', $id)->delete();
  332. if (empty($result)) {
  333. return Result::error("删除失败", 0);
  334. } else {
  335. return Result::success();
  336. }
  337. }
  338. /**
  339. * @param string $keyword
  340. * @param int $page
  341. * @param int $pageSize
  342. * @return array
  343. */
  344. public function getWebsiteRoleUserList(string $keyword, int $page, int $pageSize, int $websiteId, int $roleId): array
  345. {
  346. $where = [
  347. ['website_role_user.website_id', '=', $websiteId],
  348. ['website_role_user.role_id', '=', $roleId],
  349. ];
  350. $count = WebsiteRoleUser::where($where)->count();
  351. $where[] = ['u.user_name', 'like', '%' . $keyword . '%'];
  352. $result = WebsiteRoleUser::where($where)
  353. ->leftJoin("user as u", "website_role_user.user_id", "u.id")
  354. ->leftJoin("website as w", "website_role_user.website_id", "u.id")
  355. ->leftJoin("role as r", "website_role_user.role_id", "r.id")
  356. ->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')
  357. ->limit($pageSize)->offset(($page - 1) * $pageSize)->get();
  358. if (empty($result)) {
  359. return Result::error("没有数据", 0);
  360. }
  361. $data = [
  362. 'rows' => $result->toArray(),
  363. 'count' => $count,
  364. ];
  365. return Result::success($data);
  366. }
  367. /**
  368. * @param array $data
  369. * @return array
  370. */
  371. public function createWebsiteRoleUser(array $data): array
  372. {
  373. $insertData = [
  374. 'website_id' => $data['website_id'],
  375. 'user_id' => $data['user_id'] ?? '',
  376. ];
  377. $info = WebsiteRoleUser::where($insertData)->first();
  378. if ($info) {
  379. return Result::error("不能重复添加角色用户", 0);
  380. }
  381. $insertData['role_id'] = $data['role_id'] ?? '';
  382. $insertData['admin_user_id'] = $data['admin_user_id'] ?? '';
  383. $insertData['type'] = $data['type'] ?? '';
  384. $result = WebsiteRoleUser::insertGetId($insertData);
  385. if (empty($result)) {
  386. return Result::error("创建失败", 0);
  387. } else {
  388. return Result::success(["id" => $result]);
  389. }
  390. }
  391. /**
  392. * @param int $id
  393. * @param array $data
  394. * @return array
  395. */
  396. public function updateWebsiteRoleUser(int $id, array $data): array
  397. {
  398. $insertData = [
  399. 'website_id' => $data['website_id'],
  400. 'type' => $data['type'] ?? '',
  401. 'type_id' => $data['type_id'] ?? '',
  402. 'role_id' => $data['role_id'] ?? '',
  403. ];
  404. $result = WebsiteRoleUser::where('id', $id)->update($insertData);
  405. if (empty($result)) {
  406. return Result::error("更新失败", 0);
  407. } else {
  408. return Result::success();
  409. }
  410. }
  411. /**
  412. * @param int $id
  413. * @return array
  414. */
  415. public function delWebsiteRoleUser(int $id): array
  416. {
  417. $result = WebsiteRoleUser::where('id', $id)->delete();
  418. if (empty($result)) {
  419. return Result::error("删除失败", 0);
  420. } else {
  421. return Result::success();
  422. }
  423. }
  424. /**
  425. * 根据域名获取网站 站点id
  426. * @param array $data
  427. * @return array
  428. */
  429. public function getWebsiteId(array $data): array
  430. {
  431. $result = Website::whereJsonContains('website_url', $data['website_url'])->first();
  432. if (empty($result)) {
  433. return Result::error("查询站点失败", 0);
  434. } else {
  435. return Result::success($result);
  436. }
  437. }
  438. /**
  439. * 查询网站下面的导航
  440. * @param array $data
  441. * @return array
  442. */
  443. public function getWebsiteCategory(array $data): array
  444. {
  445. $where = [
  446. 'website_id' => $data['website_id'],
  447. ];
  448. // 使用递归查询构建树状结构
  449. $category = WebsiteCategory::where($where)
  450. ->with([
  451. 'children' => function ($query) {
  452. $query->orderBy('sort', 'asc');
  453. },
  454. ])
  455. ->orderBy('sort', 'asc')
  456. ->where('pid', 0) // 仅查询顶级节点
  457. ->get()->all();
  458. if (empty($category)) {
  459. return Result::error("查询站点栏目失败", 0);
  460. } else {
  461. $count = WebsiteCategory::where($where)->count();
  462. $result = [
  463. 'rep' => $category,
  464. 'count' => $count,
  465. ];
  466. return Result::success($result);
  467. }
  468. }
  469. /**
  470. * 查询网站的广告
  471. * @param array $data
  472. * @return array
  473. */
  474. public function getWebsiteAdvertisement(array $data): array
  475. {
  476. $where = [
  477. 'website_id' => $data['website_id'],
  478. 'ad_place.status' => 1,
  479. // 'ad.status' => 1,
  480. ];
  481. if (isset($data['ad_tag']) && !empty($data['ad_tag'])) {
  482. $now = Carbon::now()->format('Y-m-d H:i:s'); // 获取当前时间
  483. $where[] = ['ad_place.ad_tag', 'like', '%' . $data['ad_tag'] . '%'];
  484. $result = AdPlace::where($where)
  485. ->leftJoin("ad", function ($join) use ($now) {
  486. $join->on("ad.pid", "=", "ad_place.id")
  487. ->where('ad.status', 1)
  488. ->where('ad.fromtime', '<=', $now)
  489. ->where('ad.totime', '>=', $now);
  490. })
  491. ->select("ad_place.*", 'ad.*', "ad_place.id as ad_place_id", "ad.name as ad_name")
  492. ->get()->all();
  493. if (empty($result)) {
  494. return Result::error("此广告位不存在!", 0);
  495. }
  496. } else {
  497. return Result::error("请选择广告位!", 0);
  498. }
  499. return Result::success($result);
  500. }
  501. /**
  502. *
  503. * @param array $data
  504. * @return array
  505. */
  506. /**网站行政职能搜索 */
  507. public function selectWebsiteDepartment(array $data): array
  508. {
  509. $depart = Department::where('pid', 0)->orderBy('id', 'asc')->limit(10)->get();
  510. if (isset($data['keyword']) && !empty($data['keyword'])) {
  511. $departments = Department::where('name', 'like', '%' . $data['keyword'] . '%')->get();
  512. if (empty($departments)) {
  513. $result['message'] = "未查询到与此相关职能部门";
  514. } else {
  515. $count = Department::where('name', 'like', "%{$data['keyword']}%")->count();
  516. $m = [
  517. 'department' => $depart,
  518. 'type' => $departments,
  519. 'count' => $count,
  520. ];
  521. }
  522. $result['sele'] = $m;
  523. return Result::success($result['sele']);
  524. }
  525. $result = $depart;
  526. return Result::success($result);
  527. }
  528. /**
  529. * 搜索地区
  530. * @param array $data
  531. * @return array
  532. */
  533. public function selectWebsiteArea(array $data): array
  534. {
  535. $provinces = District::where('pid', 0)->where('status', 1)->get();
  536. if (isset($data['province'])) {
  537. $province = District::where('pid', 0)->where('status', 1)->where('id', $data['province'])->orderBy('id')->get();
  538. $province = $province->toArray();
  539. if (!empty($province)) {
  540. $citys = District::where('pid', $data['province'])->where('status', 1)->orderBy('id')->get();
  541. if (!empty($citys) && isset($data['city']) && !empty($data['city'])) {
  542. // $province = $province->toArray();
  543. $province_id = [];
  544. foreach ($province as $val) {
  545. array_push($province_id, $val['id']);
  546. }
  547. // var_dump($province_id);
  548. $city = District::whereIn('pid', $province_id)->where('status', 1)->where('id', $data['city'])->orderBy('id')->get();
  549. if (!empty($city)) {
  550. $city_id = [];
  551. foreach ($city as $val) {
  552. array_push($city_id, $val['id']);
  553. }
  554. $regions = District::whereIn('pid', $city_id)->where('status', 1)->orderBy('id')->get();
  555. $result = [
  556. 'province' => $province,
  557. 'city' => $city,
  558. 'region' => $regions,
  559. ];
  560. } else {
  561. return Result::error("未查询到此城市", 0);
  562. }
  563. } else {
  564. $result = [
  565. 'province' => $province,
  566. 'city' => $citys,
  567. 'region' => null,
  568. ];
  569. }
  570. } else {
  571. return Result::error("未查询到此省份", 0);
  572. }
  573. } else {
  574. // $keys = array('data');
  575. $result = $provinces;
  576. }
  577. return Result::success($result);
  578. }
  579. /**
  580. * 获取栏目
  581. * @param array $data
  582. * @return array
  583. */
  584. public function getWebsiteModelCategory(array $data): array
  585. {
  586. $website_id = [
  587. 'website_category.website_id' => $data['website_id'],
  588. ];
  589. $placeid = $data['placeid'] - 1;
  590. $pid = [
  591. 'website_category.pid' => $data['pid'],
  592. ];
  593. var_dump("=======", $pid);
  594. $num = $data['num'];
  595. // return Result::success($data);
  596. $result = WebsiteCategory::where($website_id)
  597. ->leftJoin("category", 'website_category.category_id', 'category.id')
  598. ->select('website_category.*', 'category.is_url', 'category.web_url')
  599. ->where($pid)
  600. // ->with(['children' => function ($query) use ($data) {
  601. // $query->where('website_category.website_id', $data['website_id']);
  602. // }])
  603. ->orderBy('website_category.sort')
  604. ->offset($placeid)
  605. ->limit($num)
  606. ->get();
  607. foreach ($result as $k => $v) {
  608. $child[$k]['children_countent'] = WebsiteCategory::where($website_id)
  609. ->where('website_category.pid', $v['category_id'])
  610. ->count();
  611. if (!empty($child[$k]['children_countent'])) {
  612. $result[$k]['children_count'] = $child[$k]['children_countent'];
  613. } else {
  614. $result[$k]['children_count'] = 0;
  615. }
  616. }
  617. return Result::success($result);
  618. if (!empty($result)) {
  619. return Result::success($result);
  620. } else {
  621. return Result::error("本网站暂无栏目", 0);
  622. }
  623. }
  624. /**
  625. * 获取友情链接
  626. * @param array $data
  627. * @return array
  628. */
  629. public function selectWebsiteLinks(array $data): array
  630. {
  631. $where = [
  632. 'website_id' => $data['website_id'],
  633. 'status' => 1,
  634. 'type' => $data['type'],
  635. ];
  636. $num = $data['num'];
  637. $result = Link::where($where)->orderBy('sort')->limit($num)->get();
  638. if (!empty($result)) {
  639. return Result::success($result);
  640. } else {
  641. return Result::error("本网站暂无此类型友情链接", 0);
  642. }
  643. }
  644. /**
  645. * 网站首页数据统计, 管理员
  646. * @return void
  647. */
  648. public function getAdminIndex(array $data): array
  649. {
  650. var_dump("用户类型:", $data['type_id']);
  651. switch ($data['type_id']) {
  652. case 4:
  653. $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;');
  654. return Result::success($result);
  655. break;
  656. case 10000:
  657. $res = [];
  658. //网站
  659. $res['website']['count'] = 0;
  660. $res['website']['growth_rate'] = 0;
  661. //资讯
  662. $res['article']['count'] = 0;
  663. $res['article']['growth_rate'] = 0;
  664. //导航池
  665. $res['category']['count'] = 0;
  666. $res['category']['growth_rate'] = 0;
  667. //近一月数据
  668. $res['monthArticle'] = [];
  669. //用户类型
  670. $res['userType'] = [];
  671. $res['website']['count'] = Website::where([])->count();
  672. $res['article']['count'] = Article::whereNotIn('status', ['404'])->count();
  673. $res['category']['count'] = Category::where([])->count();
  674. $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;');
  675. $res['userType'] = User::where([])->selectRaw("count(*) as counts,type_id")->groupBy('type_id')->get();
  676. return Result::success($res);
  677. }
  678. return [];
  679. }
  680. /**
  681. * 获取模板类型
  682. * @return void
  683. */
  684. public function getTemplateClass(array $data): array
  685. {
  686. $where = [];
  687. if (isset($data['name']) && $data['name']) {
  688. array_push($where, ['name', 'like', '%' . $data['name'] . '%']);
  689. }
  690. $result = TemplateClass::where($where)->orderBy('sort', 'asc')->get();
  691. if (empty($result)) {
  692. return Result::error("没有模板类型", 0);
  693. } else {
  694. return Result::success($result);
  695. }
  696. }
  697. /**
  698. * 添加模板类型
  699. * @param
  700. * @return void
  701. */
  702. public function addTemplateClass(array $data): array
  703. {
  704. $insertData = [
  705. 'name' => $data['name'],
  706. ];
  707. $result = TemplateClass::insertGetId($insertData);
  708. if (empty($result)) {
  709. return Result::error("创建失败", 0);
  710. } else {
  711. return Result::success(["id" => $result]);
  712. }
  713. }
  714. /**
  715. * 更新模板
  716. * @param array $data
  717. * @return array
  718. */
  719. public function upTemplateClass(array $data): array
  720. {
  721. $where = [
  722. 'id' => $data['id'],
  723. ];
  724. $insertData = [
  725. 'name' => $data['name'],
  726. ];
  727. $result = TemplateClass::where($where)->update($insertData);
  728. if (empty($result)) {
  729. return Result::error("更新失败", 0);
  730. } else {
  731. return Result::success();
  732. }
  733. }
  734. /**
  735. * 删除模板
  736. * @param array $data
  737. * @return array
  738. */
  739. public function delTemplateClass(array $data): array
  740. {
  741. $where = [
  742. 'id' => $data['id'],
  743. ];
  744. $result = TemplateClass::where($where)->delete();
  745. if (empty($result)) {
  746. return Result::error("删除失败", 0);
  747. } else {
  748. return Result::success();
  749. }
  750. }
  751. /**
  752. * 获取分类下的模板
  753. * @param array $data
  754. * @return array
  755. */
  756. public function getTemplate(array $data): array
  757. {
  758. $page = $data['page'];
  759. $pageSize = $data['pageSize'];
  760. $where = [];
  761. if (isset($data['template_class_id']) && $data['template_class_id']) {
  762. array_push($where, ['template_class_id', '=', $data['template_class_id']]);
  763. }
  764. $result = Template::where($where)
  765. ->limit($pageSize)->offset(($page - 1) * $pageSize)->get();
  766. $count = Template::where($where)->count();
  767. if (empty($result)) {
  768. return Result::error("没有数据", 0);
  769. }
  770. $data = [
  771. 'rows' => $result->toArray(),
  772. 'count' => $count,
  773. ];
  774. return Result::success($data);
  775. }
  776. /**
  777. * 创建模板
  778. * @param
  779. * @return void
  780. */
  781. public function addTemplate(array $data): array
  782. {
  783. $insertData = [
  784. 'template_name' => $data['template_name'],
  785. 'template_img' => json_encode($data['template_img']),
  786. 'template_class_id' => $data['template_class_id'],
  787. ];
  788. $result = Template::insertGetId($insertData);
  789. if (empty($result)) {
  790. return Result::error("创建模板失败", 0);
  791. } else {
  792. return Result::success(["id" => $result]);
  793. }
  794. }
  795. /**
  796. * 更新模板
  797. * @param array $data
  798. * @return array
  799. */
  800. public function upTemplate(array $data): array
  801. {
  802. $where = [
  803. 'id' => $data['id'],
  804. ];
  805. $insertData = [
  806. 'template_name' => $data['template_name'],
  807. 'template_img' => json_encode($data['template_img']),
  808. 'template_class_id' => $data['template_class_id'],
  809. ];
  810. $result = Template::where($where)->update($insertData);
  811. if (empty($result)) {
  812. return Result::error("更新模板失败", 0);
  813. } else {
  814. return Result::success();
  815. }
  816. }
  817. /**
  818. * 删除模板
  819. * @param array $data
  820. * @return array
  821. */
  822. public function delTemplate(array $data): array
  823. {
  824. $where = [
  825. 'id' => $data['id'],
  826. ];
  827. $result = Template::where($where)->delete();
  828. if (empty($result)) {
  829. return Result::error("删除模板失败", 0);
  830. } else {
  831. return Result::success();
  832. }
  833. }
  834. /**
  835. * 搜索网站
  836. * @param array $data
  837. * @return array
  838. */
  839. public function websiteList(array $data): array
  840. {
  841. $where = [];
  842. if (isset($data['keyword']) && !empty($data['keyword'])) {
  843. array_push($where, ['website.website_name', 'like', '%' . $data['keyword'] . '%']);
  844. }
  845. $result = Website::where($where)->get();
  846. if ($result) {
  847. return Result::success($result);
  848. } else {
  849. return Result::error("没有网站", 0);
  850. }
  851. }
  852. public function addWebsiteCategory(array $data): array
  853. {
  854. $website_id = $data['website_id'];
  855. $category_arr_id = $data['category_arr_id'];
  856. $categoryList = Category::whereIn('id', $category_arr_id)->get();
  857. $categoryListIds = [];
  858. if ($categoryList) {
  859. foreach ($categoryList->toArray() as $val) {
  860. array_push($categoryListIds, $val['id']);
  861. }
  862. }
  863. $arr = [];
  864. if ($categoryListIds) {
  865. foreach ($categoryListIds as $v) {
  866. $ids = $this->getUnderlingUIds(intval($v));
  867. $ids_arr = explode(",", $ids);
  868. array_push($arr, $ids_arr);
  869. }
  870. }
  871. $mergedArray = [];
  872. foreach ($arr as $subarray) {
  873. $mergedArray = array_merge($mergedArray, $subarray);
  874. }
  875. var_dump("所有:", $arr, $mergedArray);
  876. //查询出所有的分类进行分割插入 组装数据
  877. $categoryListData = Category::whereIn('id', $mergedArray)->get();
  878. $categoryListData = $categoryListData->toArray();
  879. $insertData = [];
  880. if ($categoryListData) {
  881. foreach ($categoryListData as $key => $value) {
  882. $insertData[$key]['website_id'] = $website_id;
  883. $insertData[$key]['name'] = $value['name'];
  884. $insertData[$key]['sort'] = $value['sort'];
  885. $insertData[$key]['pid'] = $value['pid'];
  886. $insertData[$key]['pid_arr'] = $value['pid_arr'];
  887. $insertData[$key]['seo_title'] = $value['seo_title'];
  888. $insertData[$key]['seo_keywords'] = $value['seo_keywords'];
  889. $insertData[$key]['seo_description'] = $value['seo_description'];
  890. $insertData[$key]['alias'] = $value['name'];
  891. $insertData[$key]['category_id'] = $value['id'];
  892. }
  893. }
  894. $result = WebsiteCategory::insert($insertData);
  895. var_dump("插入数据状态:", $result);
  896. if ($result) {
  897. return Result::success($result);
  898. } else {
  899. return Result::error("创建失败", 0);
  900. }
  901. }
  902. /**
  903. * 删除网站导航
  904. * @param array $data
  905. * @return array
  906. */
  907. public function delWebsiteCategory(array $data): array
  908. {
  909. $website_id = $data['website_id'] ?? 0;
  910. $category_id = $data['category_id'] ?? 0;
  911. $ids = $this->getUnderlingUIds(intval($category_id));
  912. $ids_arr = explode(",", $ids);
  913. $result = WebsiteCategory::where(['website_id' => $website_id])->whereIn("category_id", $ids_arr)->delete();
  914. if ($result) {
  915. return Result::success($result);
  916. } else {
  917. return Result::error("删除失败", 0);
  918. }
  919. }
  920. /**
  921. * 获取网站导航
  922. * @param array $data
  923. * @return array
  924. */
  925. public function getAdminWebsiteCategory(array $data): array
  926. {
  927. $where = [
  928. 'website_id' => $data['website_id'],
  929. 'pid' => 0,
  930. ];
  931. $result = WebsiteCategory::where($where)->get();
  932. if ($result) {
  933. return Result::success($result);
  934. } else {
  935. return Result::error("查询失败", 0);
  936. }
  937. }
  938. /**
  939. * 更新网站导航
  940. * @param array $data
  941. * @return array
  942. */
  943. public function upWebsiteCategory(array $data): array
  944. {
  945. Db::beginTransaction();
  946. try {
  947. //合并栏目id
  948. $reqIds = array_merge($data['old_category_arr_id'], $data['new_category_arr_id']);
  949. //对比old 数组差异化,把差异化的删除
  950. $result = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])->get();
  951. $result = $result->toArray();
  952. $categoryIds = [];
  953. if ($result) {
  954. foreach ($result as $val) {
  955. array_push($categoryIds, $val['category_id']);
  956. }
  957. }
  958. //和原始数据对比取交际
  959. $reqidsIntersect = array_intersect($reqIds, $categoryIds);
  960. //再取差集 进行对比
  961. $differenceIDS = array_merge(array_diff($reqidsIntersect, $categoryIds), array_diff($categoryIds, $reqidsIntersect));
  962. var_dump("差集:", $differenceIDS);
  963. $arr_ids = [];
  964. if (count($differenceIDS) > 0) {
  965. foreach ($differenceIDS as $vv) {
  966. $idV = $this->getUnderlingUIds(intval($vv));
  967. $ids_arrV = explode(",", $idV);
  968. array_push($arr_ids, $ids_arrV);
  969. }
  970. }
  971. $del_ids = array_reduce($arr_ids, 'array_merge', array());
  972. //有差异 删除
  973. if (count($del_ids) > 0) {
  974. WebsiteCategory::where(['website_id' => $data['website_id']])->whereIn("category_id", $del_ids)->delete();
  975. }
  976. //传过来的值 和 交际 对比,选出要添加的值 进行插入
  977. $insertIDS = array_merge(array_diff($reqIds, $reqidsIntersect), array_diff($reqidsIntersect, $reqIds));
  978. var_dump("要存储的:", $insertIDS);
  979. //新的数组重新创建
  980. if (count($insertIDS) > 0) {
  981. $arr = [];
  982. $categoryListIds = $insertIDS;
  983. if ($categoryListIds) {
  984. foreach ($categoryListIds as $v) {
  985. $ids = $this->getUnderlingUIds(intval($v));
  986. $ids_arr = explode(",", $ids);
  987. array_push($arr, $ids_arr);
  988. }
  989. }
  990. $mergedArray = [];
  991. foreach ($arr as $subarray) {
  992. $mergedArray = array_merge($mergedArray, $subarray);
  993. }
  994. var_dump("要插入的ID:", $mergedArray);
  995. //查询出所有的分类进行分割插入 组装数据
  996. $categoryListData = Category::whereIn('id', $mergedArray)->get();
  997. $categoryListData = $categoryListData->toArray();
  998. $insertData = [];
  999. if ($categoryListData) {
  1000. foreach ($categoryListData as $key => $value) {
  1001. $insertData[$key]['website_id'] = $data['website_id'];
  1002. $insertData[$key]['name'] = $value['name'];
  1003. $insertData[$key]['sort'] = $value['sort'];
  1004. $insertData[$key]['pid'] = $value['pid'];
  1005. $insertData[$key]['pid_arr'] = $value['pid_arr'];
  1006. $insertData[$key]['seo_title'] = $value['seo_title'];
  1007. $insertData[$key]['seo_keywords'] = $value['seo_keywords'];
  1008. $insertData[$key]['seo_description'] = $value['seo_description'];
  1009. $insertData[$key]['alias'] = $value['name'];
  1010. $insertData[$key]['category_id'] = $value['id'];
  1011. }
  1012. }
  1013. WebsiteCategory::insert($insertData);
  1014. }
  1015. Db::commit();
  1016. } catch (\Throwable $ex) {
  1017. Db::rollBack();
  1018. var_dump($ex->getMessage());
  1019. return Result::error("修改失败", 0);
  1020. }
  1021. return Result::success();
  1022. }
  1023. /**
  1024. * 获取网站列表
  1025. * @param array $data
  1026. * @return array
  1027. */
  1028. public function getWebsiteCategoryList(array $data): array
  1029. {
  1030. $where = [];
  1031. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1032. array_push($where, ['website.website_name', 'like', '%' . $data['keyword'] . '%']);
  1033. }
  1034. if (isset($data['website_column_id']) && !empty($data['website_column_id'])) {
  1035. array_push($where, ['website.website_column_id', '=', $data['website_column_id']]);
  1036. }
  1037. $result = Website::where($where)
  1038. ->with(["websiteCategory" => function ($query) {
  1039. $query->where(['pid' => 0])->select('website_id', 'name', 'alias', 'category_id');
  1040. }])
  1041. ->limit($data['pageSize'])->orderBy("updated_at", "desc")->offset(($data['page'] - 1) * $data['pageSize'])
  1042. ->get();
  1043. $count = Website::where($where)->count();
  1044. if (empty($result)) {
  1045. return Result::error("没有数据", 0);
  1046. }
  1047. $data = [
  1048. 'rows' => $result->toArray(),
  1049. 'count' => $count,
  1050. ];
  1051. if ($result) {
  1052. return Result::success($data);
  1053. } else {
  1054. return Result::error("查询失败", 0);
  1055. }
  1056. }
  1057. /**
  1058. * 删除网站下的所有导航
  1059. * @param array $data
  1060. * @return array
  1061. */
  1062. public function delWebsiteAllCategory(array $data): array
  1063. {
  1064. $website_id = $data['website_id'];
  1065. $result = WebsiteCategory::where(['website_id' => $website_id])->delete();
  1066. if ($result) {
  1067. return Result::success($result);
  1068. } else {
  1069. return Result::error("删除失败", 0);
  1070. }
  1071. }
  1072. /**
  1073. * 获取网站下的某一个导航
  1074. * @param array $data
  1075. * @return array
  1076. */
  1077. public function getWebsiteCategoryOnes(array $data): array
  1078. {
  1079. $website_id = $data['website_id'];
  1080. $category_id = $data['category_id'];
  1081. $result = WebsiteCategory::where(['website_category.website_id' => $website_id, 'website_category.category_id' => $category_id])
  1082. ->first();
  1083. if ($result) {
  1084. return Result::success($result);
  1085. } else {
  1086. return Result::error("查询失败", 0);
  1087. }
  1088. }
  1089. /**
  1090. * 更新网闸下的某一个导航
  1091. * @param array $data
  1092. * @return array
  1093. */
  1094. public function upWebsiteCategoryones(array $data): array
  1095. {
  1096. $where = [
  1097. 'website_id' => $data['website_id'],
  1098. 'category_id' => $data['category_id'],
  1099. ];
  1100. $result = WebsiteCategory::where($where)->update($data);
  1101. if ($result) {
  1102. return Result::success($result);
  1103. } else {
  1104. return Result::error("更新失败", 0);
  1105. }
  1106. }
  1107. /**
  1108. * 获取网站下的所有导航(包含子导航)
  1109. * @param array $data
  1110. * @return array
  1111. */
  1112. public function getWebsiteAllCategory(array $data): array
  1113. {
  1114. $where = [];
  1115. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1116. array_push($where, ['website_category.website_id', '=', $data['website_id']]);
  1117. }
  1118. if (isset($data['name']) && !empty($data['name'])) {
  1119. array_push($where, ['website_category.name', 'like', '%' . $data['name'] . '%']);
  1120. }
  1121. if (isset($data['alias']) && !empty($data['alias'])) {
  1122. array_push($where, ['website_category.alias', 'like', '%' . $data['alias'] . '%']);
  1123. }
  1124. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1125. array_push($where, ['category.department_id', '=', $data['department_id']]);
  1126. }
  1127. if (isset($data['city_id']) && !empty($data['city_id'])) {
  1128. array_push($where, ['category.city_id', '=', $data['city_id']]);
  1129. }
  1130. $result = 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. ->select("website_category.*", "department.name as department_name", "district.name as city_name")
  1135. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])
  1136. ->get();
  1137. $count = WebsiteCategory::where($where)
  1138. ->leftJoin("category", 'website_category.category_id', 'category.id')
  1139. ->leftJoin("department", 'category.department_id', 'department.id')
  1140. ->leftJoin("district", 'category.city_id', 'district.id')
  1141. ->count();
  1142. if (empty($result)) {
  1143. return Result::error("没有数据", 0);
  1144. }
  1145. $data = [
  1146. 'rows' => $result->toArray(),
  1147. 'count' => $count,
  1148. ];
  1149. if ($result) {
  1150. return Result::success($data);
  1151. } else {
  1152. return Result::error("查询失败", 0);
  1153. }
  1154. if ($result) {
  1155. return Result::success($result);
  1156. } else {
  1157. return Result::error("查询失败", 0);
  1158. }
  1159. }
  1160. /**
  1161. * 递归查询数据
  1162. * @param $id
  1163. * @param $ids
  1164. * @return string
  1165. */
  1166. public function getUnderlingUIds($id, $ids = '')
  1167. {
  1168. $back = Category::where(['pid' => $id])->get();
  1169. $back = $back->toArray();
  1170. if (!empty($back) && is_array($back)) {
  1171. foreach ($back as $v) {
  1172. //防止当前人的ID重复去查询,形成恶性循环
  1173. if ($v['id'] == $id) {
  1174. continue;
  1175. }
  1176. $back2 = Category::where(['pid' => $id])->count('id');
  1177. if ($back2 > 0) {
  1178. $ids = $this->getUnderlingUIds($v['id'], $ids);
  1179. } else {
  1180. $ids .= ',' . $v['id'];
  1181. }
  1182. }
  1183. }
  1184. $ids = $id . ',' . $ids . ',';
  1185. $ids = str_replace(',,', ",", $ids);
  1186. $ids = trim($ids, ',');
  1187. return $ids;
  1188. }
  1189. /**
  1190. * 检测网站名称是否重复
  1191. * @param array $data
  1192. * @return array
  1193. */
  1194. public function checkWebsiteName(array $data): array
  1195. {
  1196. if (isset($data['id'])) {
  1197. $data[] = ['id', "!=", $data['id']];
  1198. unset($data['id']);
  1199. }
  1200. $websiteInfo = Website::query()->where($data)->first();
  1201. if (empty($websiteInfo)) {
  1202. return Result::error("找不到网站", 0);
  1203. }
  1204. return Result::success($websiteInfo->toArray());
  1205. }
  1206. /**
  1207. * 检测网站url是否重复
  1208. * @param array $data
  1209. * @return array
  1210. */
  1211. public function checkWebsiteUrl(array $data): array
  1212. {
  1213. $whereData = [];
  1214. if (isset($data['id'])) {
  1215. $whereData = [['id', "!=", $data['id']]];
  1216. unset($data['id']);
  1217. }
  1218. $websiteInfo = Website::query()->where($whereData)->whereJsonContains('website_url', $data['website_url'])->first();
  1219. if (empty($websiteInfo)) {
  1220. return Result::error("找不到URL", 0);
  1221. }
  1222. return Result::success($websiteInfo->toArray());
  1223. }
  1224. /**
  1225. * 获取网站底部基础信息
  1226. * @param array $data
  1227. * @return array
  1228. */
  1229. public function getWebsiteFootInfo(array $data): array
  1230. {
  1231. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1232. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1233. if (empty($website)) {
  1234. return Result::error("找不到网站", 0);
  1235. }
  1236. } else {
  1237. return Result::error("参数错误", 0);
  1238. }
  1239. $website_foot = WebsiteTemplateInfo::where('website_id', $data['website_id'])->where('status', 2)->first();
  1240. $website_head = Website::where('id', $data['website_id'])
  1241. ->select('id', 'website_name', 'logo', 'title', 'keywords', 'description')->first();
  1242. if (empty($website_foot)) {
  1243. return Result::error("暂无底部基础信息", 0);
  1244. }
  1245. if (empty($website_head)) {
  1246. return Result::error("暂无头部基础信息", 0);
  1247. }
  1248. $result = [
  1249. 'website_foot' => $website_foot,
  1250. 'website_head' => $website_head,
  1251. ];
  1252. return Result::success($result);
  1253. }
  1254. /**
  1255. * 获取网站底部导航
  1256. * @param array $data
  1257. * @return array
  1258. */
  1259. public function getWebsiteFooterCategory(array $data): array
  1260. {
  1261. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1262. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1263. if (empty($website)) {
  1264. return Result::error("找不到网站", 0);
  1265. }
  1266. } else {
  1267. return Result::error("参数错误", 0);
  1268. }
  1269. $result = FooterCategory::where('website_id', $data['website_id'])->get();
  1270. if (empty($result)) {
  1271. return Result::error("暂无底部导航", 0);
  1272. }
  1273. return Result::success($result->toArray());
  1274. }
  1275. /**
  1276. * 获取网站底部导航列表
  1277. * @param array $data
  1278. * @return array
  1279. */
  1280. public function getWebsiteFooterCategoryList(array $data): array
  1281. {
  1282. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1283. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1284. if (empty($website)) {
  1285. return Result::error("找不到网站", 0);
  1286. }
  1287. } else {
  1288. return Result::error("参数错误", 0);
  1289. }
  1290. $footercategory = FooterCategory::where('website_id', $data['website_id'])->where('id', $data['fcat_id'])->first();
  1291. // '底部导航类型 0:内容型;1:列表型;',
  1292. if (!isset($footercategory['type']) || $footercategory['type'] == 0) {
  1293. return Result::error("底部导航id错误", 0);
  1294. } else {
  1295. $query = FooterContent::where('fcat_id', $data['fcat_id']);
  1296. if ($query->count() == 0) {
  1297. return Result::error("暂无底部导航列表", 0);
  1298. } elseif ($query->count() == 1) {
  1299. $result = $query->first();
  1300. } else {
  1301. $result = $query->get();
  1302. }
  1303. }
  1304. return Result::success($result);
  1305. }
  1306. /**
  1307. * 获取网站底部导航
  1308. * @param array $data
  1309. * @return array
  1310. */
  1311. public function getWebsiteFooterCategoryInfo(array $data): array
  1312. {
  1313. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1314. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1315. if (empty($website)) {
  1316. return Result::error("找不到网站", 0);
  1317. }
  1318. } else {
  1319. return Result::error("参数错误", 0);
  1320. }
  1321. if (isset($data['type']) && $data['type'] == 0) {
  1322. $fcatid = FooterCategory::where('website_id', $data['website_id'])->where('id', $data['fcat_id'])->first();
  1323. if (empty($fcatid)) {
  1324. return Result::error("底部导航id错误", 0);
  1325. }
  1326. $result = FooterContent::where('fcat_id', $data['fcat_id'])->first();
  1327. } else {
  1328. $result = FooterContent::where('id', $data['fcat_id'])->first();
  1329. }
  1330. if (empty($result)) {
  1331. return Result::error("暂无底部导航内容", 0);
  1332. }
  1333. return Result::success($result);
  1334. }
  1335. /*
  1336. * 搜索网站二级导航
  1337. * @param array $data
  1338. * @return array
  1339. * */
  1340. public function selectWebsiteCategory(array $data): array
  1341. {
  1342. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1343. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1344. if (empty($website)) {
  1345. return Result::error("暂无该网站", 0);
  1346. }
  1347. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id')->all();
  1348. // return Result::success($category);
  1349. if (empty($category)) {
  1350. return Result::error("暂无此导航", 0);
  1351. }
  1352. $query = Category::whereIn('id', $category);
  1353. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1354. $cityid = District::where('id', $data['cityid'])->first();
  1355. if (empty($cityid)) {
  1356. return Result::error("暂无此城市", 0);
  1357. } else {
  1358. $city_category = $query->whereRaw('JSON_CONTAINS(city_arr_id,?)', [$data['cityid']])->pluck('id');
  1359. // $where[] = ['JSON_CONTAINS(city_arr_id, ?)', $data['cityid']];
  1360. if (empty($city_category)) {
  1361. return Result::error("暂无此城市下的导航", 0);
  1362. }
  1363. $result['catid'] = $city_category;
  1364. $city = 1;
  1365. // var_dump("城市====================",$result);
  1366. }
  1367. }
  1368. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1369. $departmentid = Department::where('id', $data['department_id'])->first();
  1370. if (empty($departmentid)) {
  1371. return Result::error("暂无此部门", 0);
  1372. } else {
  1373. $depart_category = $query->whereRaw('JSON_CONTAINS(department_arr_id,?)', [$data['department_id']])->pluck('id');
  1374. if (empty($depart_category)) {
  1375. return Result::error("暂无此部门下的导航", 0);
  1376. }
  1377. $result['catid'] = $depart_category;
  1378. // var_dump("职能部门*******************",$result);
  1379. $department = 1;
  1380. }
  1381. }
  1382. if (!empty($city) && !empty($department)) {
  1383. // var_dump("城市和职能部门----------------------",$result);
  1384. $sel_category = $query->whereRaw('JSON_CONTAINS(city_arr_id,?)', [$data['cityid']])->whereRaw('JSON_CONTAINS(department_arr_id,?)', [$data['department_id']])->pluck('id');
  1385. if (empty($sel_category)) {
  1386. return Result::error("暂无此城市和职能部门下的导航", 0);
  1387. }
  1388. $result['catid'] = $sel_category;
  1389. }
  1390. if (empty($result)) {
  1391. return Result::error("暂无导航", 0);
  1392. }
  1393. // department_id
  1394. } else {
  1395. return Result::error("参数错误", 0);
  1396. }
  1397. return Result::success($result);
  1398. }
  1399. /**
  1400. * 获取网站栏目seo
  1401. * @param array $data
  1402. * @return array
  1403. */
  1404. public function getWebsiteCategoryHead(array $data): array
  1405. {
  1406. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1407. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1408. if (empty($website)) {
  1409. return Result::error("找不到网站", 0);
  1410. }
  1411. } else {
  1412. return Result::error("参数错误", 0);
  1413. }
  1414. if (isset($data['catid']) && !empty($data['catid'])) {
  1415. $fcatid = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->first();
  1416. if (empty($fcatid)) {
  1417. return Result::error("导航id错误", 0);
  1418. }
  1419. $result = Category::where('id', $data['catid'])->first();
  1420. }
  1421. if (empty($result)) {
  1422. return Result::error("暂无导航", 0);
  1423. }
  1424. return Result::success($result);
  1425. }
  1426. /*
  1427. * 获取某个栏目
  1428. * @param array $data
  1429. * @return array
  1430. * */
  1431. public function getOneWebsiteCategory(array $data): array
  1432. {
  1433. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1434. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1435. if (empty($website)) {
  1436. return Result::error("暂无该网站", 0);
  1437. }
  1438. $result = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['category_id'])->select('category_id', 'alias')->first();
  1439. // return Result::success($category);
  1440. if (empty($result)) {
  1441. return Result::error("暂无此导航", 0);
  1442. }
  1443. // department_id
  1444. } else {
  1445. return Result::error("参数错误", 0);
  1446. }
  1447. return Result::success($result);
  1448. }
  1449. //20250212 网站标识
  1450. public function addWebsiteGroup(array $data): array
  1451. {
  1452. //判斷name是不是重复
  1453. $websiteGroupInfo = WebsiteGroup::query()->where('name', $data['name'])->first();
  1454. if (!empty($websiteGroupInfo)) {
  1455. return Result::error("网站标识重复", 0);
  1456. }
  1457. //添加信息
  1458. $result = WebsiteGroup::insertGetId($data);
  1459. var_dump($result);
  1460. if (empty($result)) {
  1461. return Result::error("创建失败", 0);
  1462. } else {
  1463. return Result::success($result);
  1464. }
  1465. }
  1466. public function getWebsiteGroupList(array $data): array
  1467. {
  1468. $where = [];
  1469. if (isset($data['name']) && !empty($data['name'])) {
  1470. array_push($where, ['website_group.name', 'like', '%' . $data['name'] . '%']);
  1471. }
  1472. $result = WebsiteGroup::where($where)
  1473. ->limit($data['pageSize'])->orderBy("id", "desc")->offset(($data['page'] - 1) * $data['pageSize'])
  1474. ->get();
  1475. foreach ($result as $websiteGroup) {
  1476. $webIds = json_decode($websiteGroup->web_ids, true);
  1477. $websites = Website::whereIn('id', $webIds)->get();
  1478. $websiteNames = $websites->pluck('website_name', 'id')->toArray();
  1479. $websiteGroup->website_names = $websiteNames;
  1480. $websiteGroup->website_names1 = implode(',', array_values($websiteNames));
  1481. }
  1482. $count = WebsiteGroup::where($where)->count();
  1483. if (empty($result)) {
  1484. return Result::error("没有数据", 0);
  1485. }
  1486. return Result::success(['list' => $result->toArray(), 'count' => $count]);
  1487. }
  1488. public function getWebsiteGroupInfo(array $data): array
  1489. {
  1490. $websiteInfo = WebsiteGroup::query()->where('id', $data['id'])->first();
  1491. $webIds = json_decode($websiteInfo->web_ids, true);
  1492. $websites = Website::whereIn('id', $webIds)->get();
  1493. $websiteNames = $websites->pluck('website_name', 'id')->toArray();
  1494. $websiteInfo->website_names = $websiteNames;
  1495. $websiteInfo->website_names1 = implode(',', array_values($websiteNames));
  1496. if (empty($websiteInfo)) {
  1497. return Result::error("找不到URL", 0);
  1498. }
  1499. return Result::success($websiteInfo->toArray());
  1500. }
  1501. public function updateWebsiteGroup(array $data): array
  1502. {
  1503. $where = [
  1504. 'id' => $data['id'],
  1505. ];
  1506. $insertData = [
  1507. 'name' => $data['name'],
  1508. 'web_ids' => $data['web_ids'],
  1509. ];
  1510. //判斷name是不是重复
  1511. $websiteGroupInfo = WebsiteGroup::query()->where('name', $data['name'])->first();
  1512. if (!empty($websiteGroupInfo)) {
  1513. return Result::error("网站标识重复", 0);
  1514. }
  1515. $result = WebsiteGroup::where($where)->update($insertData);
  1516. var_dump($result, '------更新');
  1517. if (empty($result)) {
  1518. return Result::error("更新失败", 0);
  1519. } else {
  1520. return Result::success();
  1521. }
  1522. }
  1523. public function deleteWebsiteGroup(array $data): array
  1524. {
  1525. $where = [
  1526. 'id' => $data['id'],
  1527. ];
  1528. //看看user表是不是有这个id
  1529. $userGroup = User::query()->where('sszq', $data['id'])->first();
  1530. if (!empty($userGroup)) {
  1531. return Result::error("有用户在使用该网站标识,不能删除", 0);
  1532. }
  1533. $result = WebsiteGroup::where($where)->delete();
  1534. if (empty($result)) {
  1535. return Result::error("删除失败", 0);
  1536. } else {
  1537. return Result::success();
  1538. }
  1539. }
  1540. public function getWebsiteNavList(array $data): array
  1541. {
  1542. $where = [];
  1543. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1544. array_push($where, ['website_id', '=', $data['website_id']]);
  1545. }
  1546. if (isset($data['pid'])) {
  1547. array_push($where, ['pid', '=', $data['pid']]);
  1548. }
  1549. $list = WebsiteCategory::query()->where($where)->get();
  1550. if (empty($list)) {
  1551. return Result::error("获取失败", 0);
  1552. } else {
  1553. return Result::success($list);
  1554. }
  1555. }
  1556. // 20250307 根据网站标识获和导航获取站点
  1557. public function getWebsiteNavPoolSite(array $data): array
  1558. {
  1559. $where = [];
  1560. if (isset($data['category_id']) && !empty($data['category_id'])) {
  1561. array_push($where, ['category_id', '=', $data['category_id']]);
  1562. }
  1563. $list = WebsiteCategory::query()->where($where)
  1564. ->leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1565. ->select('website_category.*', 'website.website_name')
  1566. ->distinct()
  1567. ->get();
  1568. if (empty($list)) {
  1569. return Result::error("获取失败", 0);
  1570. } else {
  1571. return Result::success($list);
  1572. }
  1573. }
  1574. public function getWebsiteNavPool(array $data): array
  1575. {
  1576. // 初始化查询条件数组
  1577. $query = WebsiteCategory::query();
  1578. // 如果传入了 websiteids,则添加到查询条件中
  1579. if (isset($data['websiteids']) && !empty($data['websiteids'])) {
  1580. $query->whereIn('website_id', $data['websiteids']);
  1581. }
  1582. // 如果传入了 pid,则添加到查询条件中
  1583. if (isset($data['pid'])) {
  1584. $query->where('pid', '=', $data['pid']);
  1585. }
  1586. // 执行查询 唯一性 id
  1587. $list = $query->distinct()->get();
  1588. // 根据查询结果返回相应的结果
  1589. if ($list->isEmpty()) {
  1590. return Result::error("获取失败", 0);
  1591. } else {
  1592. return Result::success($list->toArray());
  1593. }
  1594. }
  1595. }