WebsiteService.php 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633
  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. $resultWwhere = Website::when($data, function ($query) use ($data) {
  42. if (isset($data['keyword']) && !empty($data['keyword'])) {
  43. $query->where('website.website_name', 'like', '%' . $data['keyword'] . '%');
  44. }
  45. if (isset($data['website_column_id']) && !empty($data['website_column_id'])) {
  46. $query->whereJsonContains("website.website_column_arr_id", intval($data['website_column_id']));
  47. }
  48. if (isset($data['city_id']) && !empty($data['city_id'])) {
  49. $query->whereJsonContains("website.city_arr_id", intval($data['city_id']));
  50. }
  51. });
  52. $count = $resultWwhere->leftJoin("website_column", "website.website_column_id", "website_column.id")
  53. ->leftJoin("district", "district.id", "website.city_id")->count();
  54. $result = $resultWwhere->leftJoin("website_column", "website.website_column_id", "website_column.id")
  55. ->leftJoin("district", "district.id", "website.city_id")
  56. ->select("website.*", "website_column.column_name", "district.name as city_name")
  57. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("website.updated_at", "desc")->get();
  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. 'website_id' => $data['website_id'],
  474. 'ad_place.status' => 1,
  475. // 'ad.status' => 1,
  476. ];
  477. if (isset($data['ad_tag']) && !empty($data['ad_tag'])) {
  478. $now = Carbon::now()->format('Y-m-d H:i:s'); // 获取当前时间
  479. $where[] = ['ad_place.ad_tag','like','%'.$data['ad_tag'].'%'];
  480. $result = AdPlace::where($where)
  481. ->leftJoin("ad", function ($join) use ($now) {
  482. $join->on("ad.pid", "=", "ad_place.id")
  483. ->where('ad.status', 1)
  484. ->where('ad.fromtime', '<=', $now)
  485. ->where('ad.totime', '>=', $now);
  486. })
  487. ->select("ad_place.*",'ad.*',"ad_place.id as ad_place_id","ad.name as ad_name")
  488. ->get()->all();
  489. if(empty($result)){
  490. return Result::error("此广告位不存在!",0);
  491. }
  492. }else{
  493. return Result::error("请选择广告位!",0);
  494. }
  495. return Result::success($result);
  496. }
  497. /**
  498. *
  499. * @param array $data
  500. * @return array
  501. */
  502. /**网站行政职能搜索 */
  503. public function selectWebsiteDepartment(array $data): array
  504. {
  505. $depart = Department::where('pid', 0)->orderBy('id', 'asc')->limit(10)->get();
  506. if (isset($data['keyword']) && !empty($data['keyword'])) {
  507. $departments = Department::where('name', 'like', '%' . $data['keyword'] . '%')->get();
  508. if (empty($departments)) {
  509. $result['message'] = "未查询到与此相关职能部门";
  510. } else {
  511. $count = Department::where('name', 'like', "%{$data['keyword']}%")->count();
  512. $m = [
  513. 'department' => $depart,
  514. 'type' => $departments,
  515. 'count' => $count,
  516. ];
  517. }
  518. $result['sele'] = $m;
  519. return Result::success($result['sele']);
  520. }
  521. $result = $depart;
  522. return Result::success($result);
  523. }
  524. /**
  525. * 搜索地区
  526. * @param array $data
  527. * @return array
  528. */
  529. public function selectWebsiteArea(array $data): array
  530. {
  531. $provinces = District::where('pid', 0)->where('status', 1)->get();
  532. if (isset($data['province'])) {
  533. $province = District::where('pid', 0)->where('status', 1)->where('id', $data['province'])->orderBy('id')->get();
  534. $province = $province->toArray();
  535. if (!empty($province)) {
  536. $citys = District::where('pid', $data['province'])->where('status', 1)->orderBy('id')->get();
  537. if (!empty($citys) && isset($data['city']) && !empty($data['city'])) {
  538. // $province = $province->toArray();
  539. $province_id = [];
  540. foreach ($province as $val) {
  541. array_push($province_id, $val['id']);
  542. }
  543. // var_dump($province_id);
  544. $city = District::whereIn('pid', $province_id)->where('status', 1)->where('id', $data['city'])->orderBy('id')->get();
  545. if (!empty($city)) {
  546. $city_id = [];
  547. foreach ($city as $val) {
  548. array_push($city_id, $val['id']);
  549. }
  550. $regions = District::whereIn('pid', $city_id)->where('status', 1)->orderBy('id')->get();
  551. $result = [
  552. 'province' => $province,
  553. 'city' => $city,
  554. 'region' => $regions,
  555. ];
  556. } else {
  557. return Result::error("未查询到此城市", 0);
  558. }
  559. } else {
  560. $result = [
  561. 'province' => $province,
  562. 'city' => $citys,
  563. 'region' => null,
  564. ];
  565. }
  566. } else {
  567. return Result::error("未查询到此省份", 0);
  568. }
  569. } else {
  570. // $keys = array('data');
  571. $result = $provinces;
  572. }
  573. return Result::success($result);
  574. }
  575. /**
  576. * 获取栏目
  577. * @param array $data
  578. * @return array
  579. */
  580. public function getWebsiteModelCategory(array $data): array
  581. {
  582. $website_id = [
  583. 'website_category.website_id' => $data['website_id'],
  584. ];
  585. $placeid = $data['placeid'] - 1;
  586. $pid = [
  587. 'website_category.pid' => $data['pid'],
  588. ];
  589. var_dump("=======", $pid);
  590. $num = $data['num'];
  591. // return Result::success($data);
  592. $result = WebsiteCategory::where($website_id)
  593. ->leftJoin("category", 'website_category.category_id', 'category.id')
  594. ->select('website_category.*', 'category.is_url', 'category.web_url')
  595. ->where($pid)
  596. // ->with(['children' => function ($query) use ($data) {
  597. // $query->where('website_category.website_id', $data['website_id']);
  598. // }])
  599. ->orderBy('website_category.sort')
  600. ->offset($placeid)
  601. ->limit($num)
  602. ->get();
  603. foreach ($result as $k => $v) {
  604. $child[$k]['children_countent'] = WebsiteCategory::where($website_id)
  605. ->where('website_category.pid', $v['category_id'])
  606. ->count();
  607. if (!empty($child[$k]['children_countent'])) {
  608. $result[$k]['children_count'] = $child[$k]['children_countent'];
  609. } else {
  610. $result[$k]['children_count'] = 0;
  611. }
  612. }
  613. return Result::success($result);
  614. if (!empty($result)) {
  615. return Result::success($result);
  616. } else {
  617. return Result::error("本网站暂无栏目", 0);
  618. }
  619. }
  620. /**
  621. * 获取友情链接
  622. * @param array $data
  623. * @return array
  624. */
  625. public function selectWebsiteLinks(array $data): array
  626. {
  627. $where = [
  628. 'website_id' => $data['website_id'],
  629. 'status' => 1,
  630. 'type' => $data['type']
  631. ];
  632. $num=$data['num'];
  633. $result=Link::where($where)->orderBy('sort')->limit($num)->get();
  634. if(!empty($result)){
  635. return Result::success($result);
  636. }else{
  637. return Result::error("本网站暂无此类型友情链接",0);
  638. }
  639. }
  640. /**
  641. * 网站首页数据统计, 管理员
  642. * @return void
  643. */
  644. public function getAdminIndex(array $data): array
  645. {
  646. var_dump("用户类型:", $data['type_id']);
  647. switch ($data['type_id']) {
  648. case 4:
  649. $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;');
  650. return Result::success($result);
  651. break;
  652. case 10000:
  653. $res = [];
  654. //网站
  655. $res['website']['count'] = 0;
  656. $res['website']['growth_rate'] = 0;
  657. //资讯
  658. $res['article']['count'] = 0;
  659. $res['article']['growth_rate'] = 0;
  660. //导航池
  661. $res['category']['count'] = 0;
  662. $res['category']['growth_rate'] = 0;
  663. //近一月数据
  664. $res['monthArticle'] = [];
  665. //用户类型
  666. $res['userType'] = [];
  667. $res['website']['count'] = Website::where([])->count();
  668. $res['article']['count'] = Article::whereNotIn('status', ['404'])->count();
  669. $res['category']['count'] = Category::where([])->count();
  670. $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;');
  671. $res['userType'] = User::where([])->selectRaw("count(*) as counts,type_id")->groupBy('type_id')->get();
  672. return Result::success($res);
  673. }
  674. return [];
  675. }
  676. /**
  677. * 获取模板类型
  678. * @return void
  679. */
  680. public function getTemplateClass(array $data): array
  681. {
  682. $where = [];
  683. if (isset($data['name']) && $data['name']) {
  684. array_push($where, ['name', 'like', '%' . $data['name'] . '%']);
  685. }
  686. $result = TemplateClass::where($where)->orderBy('sort', 'asc')->get();
  687. if (empty($result)) {
  688. return Result::error("没有模板类型", 0);
  689. } else {
  690. return Result::success($result);
  691. }
  692. }
  693. /**
  694. * 添加模板类型
  695. * @param
  696. * @return void
  697. */
  698. public function addTemplateClass(array $data): array
  699. {
  700. $insertData = [
  701. 'name' => $data['name'],
  702. ];
  703. $result = TemplateClass::insertGetId($insertData);
  704. if (empty($result)) {
  705. return Result::error("创建失败", 0);
  706. } else {
  707. return Result::success(["id" => $result]);
  708. }
  709. }
  710. /**
  711. * 更新模板
  712. * @param array $data
  713. * @return array
  714. */
  715. public function upTemplateClass(array $data): array
  716. {
  717. $where = [
  718. 'id' => $data['id'],
  719. ];
  720. $insertData = [
  721. 'name' => $data['name'],
  722. ];
  723. $result = TemplateClass::where($where)->update($insertData);
  724. if (empty($result)) {
  725. return Result::error("更新失败", 0);
  726. } else {
  727. return Result::success();
  728. }
  729. }
  730. /**
  731. * 删除模板
  732. * @param array $data
  733. * @return array
  734. */
  735. public function delTemplateClass(array $data): array
  736. {
  737. $where = [
  738. 'id' => $data['id'],
  739. ];
  740. $result = TemplateClass::where($where)->delete();
  741. if (empty($result)) {
  742. return Result::error("删除失败", 0);
  743. } else {
  744. return Result::success();
  745. }
  746. }
  747. /**
  748. * 获取分类下的模板
  749. * @param array $data
  750. * @return array
  751. */
  752. public function getTemplate(array $data): array
  753. {
  754. $page = $data['page'];
  755. $pageSize = $data['pageSize'];
  756. $where = [];
  757. if (isset($data['template_class_id']) && $data['template_class_id']) {
  758. array_push($where, ['template_class_id', '=', $data['template_class_id']]);
  759. }
  760. $result = Template::where($where)
  761. ->limit($pageSize)->offset(($page - 1) * $pageSize)->get();
  762. $count = Template::where($where)->count();
  763. if (empty($result)) {
  764. return Result::error("没有数据", 0);
  765. }
  766. $data = [
  767. 'rows' => $result->toArray(),
  768. 'count' => $count,
  769. ];
  770. return Result::success($data);
  771. }
  772. /**
  773. * 创建模板
  774. * @param
  775. * @return void
  776. */
  777. public function addTemplate(array $data): array
  778. {
  779. $insertData = [
  780. 'template_name' => $data['template_name'],
  781. 'template_img' => json_encode($data['template_img']),
  782. 'template_class_id' => $data['template_class_id'],
  783. ];
  784. $result = Template::insertGetId($insertData);
  785. if (empty($result)) {
  786. return Result::error("创建模板失败", 0);
  787. } else {
  788. return Result::success(["id" => $result]);
  789. }
  790. }
  791. /**
  792. * 更新模板
  793. * @param array $data
  794. * @return array
  795. */
  796. public function upTemplate(array $data): array
  797. {
  798. $where = [
  799. 'id' => $data['id'],
  800. ];
  801. $insertData = [
  802. 'template_name' => $data['template_name'],
  803. 'template_img' => json_encode($data['template_img']),
  804. 'template_class_id' => $data['template_class_id'],
  805. ];
  806. $result = Template::where($where)->update($insertData);
  807. if (empty($result)) {
  808. return Result::error("更新模板失败", 0);
  809. } else {
  810. return Result::success();
  811. }
  812. }
  813. /**
  814. * 删除模板
  815. * @param array $data
  816. * @return array
  817. */
  818. public function delTemplate(array $data): array
  819. {
  820. $where = [
  821. 'id' => $data['id'],
  822. ];
  823. $result = Template::where($where)->delete();
  824. if (empty($result)) {
  825. return Result::error("删除模板失败", 0);
  826. } else {
  827. return Result::success();
  828. }
  829. }
  830. /**
  831. * 搜索网站
  832. * @param array $data
  833. * @return array
  834. */
  835. public function websiteList(array $data): array
  836. {
  837. $where = [];
  838. if (isset($data['keyword']) && !empty($data['keyword'])) {
  839. array_push($where, ['website.website_name', 'like', '%' . $data['keyword'] . '%']);
  840. }
  841. $result = Website::where($where)->get();
  842. if ($result) {
  843. return Result::success($result);
  844. } else {
  845. return Result::error("没有网站", 0);
  846. }
  847. }
  848. public function addWebsiteCategory(array $data): array
  849. {
  850. $website_id = $data['website_id'];
  851. $category_arr_id = $data['category_arr_id'];
  852. $categoryList = Category::whereIn('id', $category_arr_id)->get();
  853. $categoryListIds = [];
  854. if ($categoryList) {
  855. foreach ($categoryList->toArray() as $val) {
  856. array_push($categoryListIds, $val['id']);
  857. }
  858. }
  859. $arr = [];
  860. if ($categoryListIds) {
  861. foreach ($categoryListIds as $v) {
  862. $ids = $this->getUnderlingUIds(intval($v));
  863. $ids_arr = explode(",", $ids);
  864. array_push($arr, $ids_arr);
  865. }
  866. }
  867. $mergedArray = [];
  868. foreach ($arr as $subarray) {
  869. $mergedArray = array_merge($mergedArray, $subarray);
  870. }
  871. var_dump("所有:", $arr, $mergedArray);
  872. //查询出所有的分类进行分割插入 组装数据
  873. $categoryListData = Category::whereIn('id', $mergedArray)->get();
  874. $categoryListData = $categoryListData->toArray();
  875. $insertData = [];
  876. if ($categoryListData) {
  877. foreach ($categoryListData as $key => $value) {
  878. $insertData[$key]['website_id'] = $website_id;
  879. $insertData[$key]['name'] = $value['name'];
  880. $insertData[$key]['sort'] = $value['sort'];
  881. $insertData[$key]['pid'] = $value['pid'];
  882. $insertData[$key]['pid_arr'] = $value['pid_arr'];
  883. $insertData[$key]['seo_title'] = $value['seo_title'];
  884. $insertData[$key]['seo_keywords'] = $value['seo_keywords'];
  885. $insertData[$key]['seo_description'] = $value['seo_description'];
  886. $insertData[$key]['alias'] = $value['name'];
  887. $insertData[$key]['category_id'] = $value['id'];
  888. }
  889. }
  890. $result = WebsiteCategory::insert($insertData);
  891. var_dump("插入数据状态:", $result);
  892. if ($result) {
  893. return Result::success($result);
  894. } else {
  895. return Result::error("创建失败", 0);
  896. }
  897. }
  898. /**
  899. * 删除网站导航
  900. * @param array $data
  901. * @return array
  902. */
  903. public function delWebsiteCategory(array $data): array
  904. {
  905. $website_id = $data['website_id'] ?? 0;
  906. $category_id = $data['category_id'] ?? 0;
  907. $ids = $this->getUnderlingUIds(intval($category_id));
  908. $ids_arr = explode(",", $ids);
  909. $result = WebsiteCategory::where(['website_id' => $website_id])->whereIn("category_id", $ids_arr)->delete();
  910. if ($result) {
  911. return Result::success($result);
  912. } else {
  913. return Result::error("删除失败", 0);
  914. }
  915. }
  916. /**
  917. * 获取网站导航
  918. * @param array $data
  919. * @return array
  920. */
  921. public function getAdminWebsiteCategory(array $data): array
  922. {
  923. $where = [
  924. 'website_id' => $data['website_id'],
  925. 'pid' => 0,
  926. ];
  927. $result = WebsiteCategory::where($where)->get();
  928. if ($result) {
  929. return Result::success($result);
  930. } else {
  931. return Result::error("查询失败", 0);
  932. }
  933. }
  934. /**
  935. * 更新网站导航
  936. * @param array $data
  937. * @return array
  938. */
  939. public function upWebsiteCategory(array $data): array
  940. {
  941. Db::beginTransaction();
  942. try {
  943. //合并栏目id
  944. $reqIds = array_merge($data['old_category_arr_id'], $data['new_category_arr_id']);
  945. //对比old 数组差异化,把差异化的删除
  946. $result = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])->get();
  947. $result = $result->toArray();
  948. $categoryIds = [];
  949. if ($result) {
  950. foreach ($result as $val) {
  951. array_push($categoryIds, $val['category_id']);
  952. }
  953. }
  954. //和原始数据对比取交际
  955. $reqidsIntersect = array_intersect($reqIds, $categoryIds);
  956. //再取差集 进行对比
  957. $differenceIDS = array_merge(array_diff($reqidsIntersect, $categoryIds), array_diff($categoryIds, $reqidsIntersect));
  958. var_dump("差集:", $differenceIDS);
  959. $arr_ids = [];
  960. if (count($differenceIDS) > 0) {
  961. foreach ($differenceIDS as $vv) {
  962. $idV = $this->getUnderlingUIds(intval($vv));
  963. $ids_arrV = explode(",", $idV);
  964. array_push($arr_ids, $ids_arrV);
  965. }
  966. }
  967. $del_ids = array_reduce($arr_ids, 'array_merge', array());
  968. //有差异 删除
  969. if (count($del_ids) > 0) {
  970. WebsiteCategory::where(['website_id' => $data['website_id']])->whereIn("category_id", $del_ids)->delete();
  971. }
  972. //传过来的值 和 交际 对比,选出要添加的值 进行插入
  973. $insertIDS = array_merge(array_diff($reqIds, $reqidsIntersect), array_diff($reqidsIntersect, $reqIds));
  974. var_dump("要存储的:", $insertIDS);
  975. //新的数组重新创建
  976. if (count($insertIDS) > 0) {
  977. $arr = [];
  978. $categoryListIds = $insertIDS;
  979. if ($categoryListIds) {
  980. foreach ($categoryListIds as $v) {
  981. $ids = $this->getUnderlingUIds(intval($v));
  982. $ids_arr = explode(",", $ids);
  983. array_push($arr, $ids_arr);
  984. }
  985. }
  986. $mergedArray = [];
  987. foreach ($arr as $subarray) {
  988. $mergedArray = array_merge($mergedArray, $subarray);
  989. }
  990. var_dump("要插入的ID:", $mergedArray);
  991. //查询出所有的分类进行分割插入 组装数据
  992. $categoryListData = Category::whereIn('id', $mergedArray)->get();
  993. $categoryListData = $categoryListData->toArray();
  994. $insertData = [];
  995. if ($categoryListData) {
  996. foreach ($categoryListData as $key => $value) {
  997. $insertData[$key]['website_id'] = $data['website_id'];
  998. $insertData[$key]['name'] = $value['name'];
  999. $insertData[$key]['sort'] = $value['sort'];
  1000. $insertData[$key]['pid'] = $value['pid'];
  1001. $insertData[$key]['pid_arr'] = $value['pid_arr'];
  1002. $insertData[$key]['seo_title'] = $value['seo_title'];
  1003. $insertData[$key]['seo_keywords'] = $value['seo_keywords'];
  1004. $insertData[$key]['seo_description'] = $value['seo_description'];
  1005. $insertData[$key]['alias'] = $value['name'];
  1006. $insertData[$key]['category_id'] = $value['id'];
  1007. }
  1008. }
  1009. WebsiteCategory::insert($insertData);
  1010. }
  1011. Db::commit();
  1012. } catch (\Throwable $ex) {
  1013. Db::rollBack();
  1014. var_dump($ex->getMessage());
  1015. return Result::error("修改失败", 0);
  1016. }
  1017. return Result::success();
  1018. }
  1019. /**
  1020. * 获取网站列表
  1021. * @param array $data
  1022. * @return array
  1023. */
  1024. public function getWebsiteCategoryList(array $data): array
  1025. {
  1026. $where = [];
  1027. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1028. array_push($where, ['website.website_name', 'like', '%' . $data['keyword'] . '%']);
  1029. }
  1030. if (isset($data['website_column_id']) && !empty($data['website_column_id'])) {
  1031. array_push($where, ['website.website_column_id', '=', $data['website_column_id']]);
  1032. }
  1033. $result = Website::where($where)
  1034. ->with(["websiteCategory" => function ($query) {
  1035. $query->where(['pid' => 0])->select('website_id', 'name', 'alias', 'category_id');
  1036. }])
  1037. ->limit($data['pageSize'])->orderBy("updated_at", "desc")->offset(($data['page'] - 1) * $data['pageSize'])
  1038. ->get();
  1039. $count = Website::where($where)->count();
  1040. if (empty($result)) {
  1041. return Result::error("没有数据", 0);
  1042. }
  1043. $data = [
  1044. 'rows' => $result->toArray(),
  1045. 'count' => $count,
  1046. ];
  1047. if ($result) {
  1048. return Result::success($data);
  1049. } else {
  1050. return Result::error("查询失败", 0);
  1051. }
  1052. }
  1053. /**
  1054. * 删除网站下的所有导航
  1055. * @param array $data
  1056. * @return array
  1057. */
  1058. public function delWebsiteAllCategory(array $data): array
  1059. {
  1060. $website_id = $data['website_id'];
  1061. $result = WebsiteCategory::where(['website_id' => $website_id])->delete();
  1062. if ($result) {
  1063. return Result::success($result);
  1064. } else {
  1065. return Result::error("删除失败", 0);
  1066. }
  1067. }
  1068. /**
  1069. * 获取网站下的某一个导航
  1070. * @param array $data
  1071. * @return array
  1072. */
  1073. public function getWebsiteCategoryOnes(array $data): array
  1074. {
  1075. $website_id = $data['website_id'];
  1076. $category_id = $data['category_id'];
  1077. $result = WebsiteCategory::where(['website_category.website_id' => $website_id, 'website_category.category_id' => $category_id])
  1078. ->first();
  1079. if ($result) {
  1080. return Result::success($result);
  1081. } else {
  1082. return Result::error("查询失败", 0);
  1083. }
  1084. }
  1085. /**
  1086. * 更新网闸下的某一个导航
  1087. * @param array $data
  1088. * @return array
  1089. */
  1090. public function upWebsiteCategoryones(array $data): array
  1091. {
  1092. $where = [
  1093. 'website_id' => $data['website_id'],
  1094. 'category_id' => $data['category_id'],
  1095. ];
  1096. $result = WebsiteCategory::where($where)->update($data);
  1097. if ($result) {
  1098. return Result::success($result);
  1099. } else {
  1100. return Result::error("更新失败", 0);
  1101. }
  1102. }
  1103. /**
  1104. * 获取网站下的所有导航(包含子导航)
  1105. * @param array $data
  1106. * @return array
  1107. */
  1108. public function getWebsiteAllCategory(array $data): array
  1109. {
  1110. $where = [];
  1111. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1112. array_push($where, ['website_category.website_id', '=', $data['website_id']]);
  1113. }
  1114. if (isset($data['name']) && !empty($data['name'])) {
  1115. array_push($where, ['website_category.name', 'like', '%' . $data['name'] . '%']);
  1116. }
  1117. if (isset($data['alias']) && !empty($data['alias'])) {
  1118. array_push($where, ['website_category.alias', 'like', '%' . $data['alias'] . '%']);
  1119. }
  1120. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1121. array_push($where, ['category.department_id', '=', $data['department_id']]);
  1122. }
  1123. if (isset($data['city_id']) && !empty($data['city_id'])) {
  1124. array_push($where, ['category.city_id', '=', $data['city_id']]);
  1125. }
  1126. $result = WebsiteCategory::where($where)
  1127. ->leftJoin("category", 'website_category.category_id', 'category.id')
  1128. ->leftJoin("department", 'category.department_id', 'department.id')
  1129. ->leftJoin("district", 'category.city_id', 'district.id')
  1130. ->select("website_category.*", "department.name as department_name", "district.name as city_name")
  1131. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])
  1132. ->get();
  1133. $count = WebsiteCategory::where($where)
  1134. ->leftJoin("category", 'website_category.category_id', 'category.id')
  1135. ->leftJoin("department", 'category.department_id', 'department.id')
  1136. ->leftJoin("district", 'category.city_id', 'district.id')
  1137. ->count();
  1138. if (empty($result)) {
  1139. return Result::error("没有数据", 0);
  1140. }
  1141. $data = [
  1142. 'rows' => $result->toArray(),
  1143. 'count' => $count,
  1144. ];
  1145. if ($result) {
  1146. return Result::success($data);
  1147. } else {
  1148. return Result::error("查询失败", 0);
  1149. }
  1150. if ($result) {
  1151. return Result::success($result);
  1152. } else {
  1153. return Result::error("查询失败", 0);
  1154. }
  1155. }
  1156. /**
  1157. * 递归查询数据
  1158. * @param $id
  1159. * @param $ids
  1160. * @return string
  1161. */
  1162. public function getUnderlingUIds($id, $ids = '')
  1163. {
  1164. $back = Category::where(['pid' => $id])->get();
  1165. $back = $back->toArray();
  1166. if (!empty($back) && is_array($back)) {
  1167. foreach ($back as $v) {
  1168. //防止当前人的ID重复去查询,形成恶性循环
  1169. if ($v['id'] == $id) {
  1170. continue;
  1171. }
  1172. $back2 = Category::where(['pid' => $id])->count('id');
  1173. if ($back2 > 0) {
  1174. $ids = $this->getUnderlingUIds($v['id'], $ids);
  1175. } else {
  1176. $ids .= ',' . $v['id'];
  1177. }
  1178. }
  1179. }
  1180. $ids = $id . ',' . $ids . ',';
  1181. $ids = str_replace(',,', ",", $ids);
  1182. $ids = trim($ids, ',');
  1183. return $ids;
  1184. }
  1185. /**
  1186. * 检测网站名称是否重复
  1187. * @param array $data
  1188. * @return array
  1189. */
  1190. public function checkWebsiteName(array $data): array
  1191. {
  1192. if (isset($data['id'])) {
  1193. $data[] = ['id', "!=", $data['id']];
  1194. unset($data['id']);
  1195. }
  1196. $websiteInfo = Website::query()->where($data)->first();
  1197. if (empty($websiteInfo)) {
  1198. return Result::error("找不到网站", 0);
  1199. }
  1200. return Result::success($websiteInfo->toArray());
  1201. }
  1202. /**
  1203. * 检测网站url是否重复
  1204. * @param array $data
  1205. * @return array
  1206. */
  1207. public function checkWebsiteUrl(array $data): array
  1208. {
  1209. $whereData = [];
  1210. if (isset($data['id'])) {
  1211. $whereData = [['id', "!=", $data['id']]];
  1212. unset($data['id']);
  1213. }
  1214. $websiteInfo = Website::query()->where($whereData)->whereJsonContains('website_url', $data['website_url'])->first();
  1215. if (empty($websiteInfo)) {
  1216. return Result::error("找不到URL", 0);
  1217. }
  1218. return Result::success($websiteInfo->toArray());
  1219. }
  1220. /**
  1221. * 获取网站底部基础信息
  1222. * @param array $data
  1223. * @return array
  1224. */
  1225. public function getWebsiteFootInfo(array $data): array
  1226. {
  1227. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1228. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1229. if (empty($website)) {
  1230. return Result::error("找不到网站", 0);
  1231. }
  1232. } else {
  1233. return Result::error("参数错误", 0);
  1234. }
  1235. $website_foot = WebsiteTemplateInfo::where('website_id', $data['website_id'])->where('status', 2)->first();
  1236. $website_head = Website::where('id', $data['website_id'])
  1237. ->select('id', 'website_name', 'logo', 'title', 'keywords', 'description')->first();
  1238. if (empty($website_foot)) {
  1239. return Result::error("暂无底部基础信息", 0);
  1240. }
  1241. if (empty($website_head)) {
  1242. return Result::error("暂无头部基础信息", 0);
  1243. }
  1244. $result = [
  1245. 'website_foot' => $website_foot,
  1246. 'website_head' => $website_head,
  1247. ];
  1248. return Result::success($result);
  1249. }
  1250. /**
  1251. * 获取网站底部导航
  1252. * @param array $data
  1253. * @return array
  1254. */
  1255. public function getWebsiteFooterCategory(array $data): array
  1256. {
  1257. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1258. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1259. if (empty($website)) {
  1260. return Result::error("找不到网站", 0);
  1261. }
  1262. } else {
  1263. return Result::error("参数错误", 0);
  1264. }
  1265. $result = FooterCategory::where('website_id', $data['website_id'])->get();
  1266. if (empty($result)) {
  1267. return Result::error("暂无底部导航", 0);
  1268. }
  1269. return Result::success($result->toArray());
  1270. }
  1271. /**
  1272. * 获取网站底部导航列表
  1273. * @param array $data
  1274. * @return array
  1275. */
  1276. public function getWebsiteFooterCategoryList(array $data): array
  1277. {
  1278. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1279. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1280. if (empty($website)) {
  1281. return Result::error("找不到网站", 0);
  1282. }
  1283. } else {
  1284. return Result::error("参数错误", 0);
  1285. }
  1286. $footercategory = FooterCategory::where('website_id', $data['website_id'])->where('id', $data['fcat_id'])->first();
  1287. // '底部导航类型 0:内容型;1:列表型;',
  1288. if (!isset($footercategory['type']) || $footercategory['type'] == 0) {
  1289. return Result::error("底部导航id错误", 0);
  1290. } else {
  1291. $query = FooterContent::where('fcat_id', $data['fcat_id']);
  1292. if ($query->count() == 0) {
  1293. return Result::error("暂无底部导航列表", 0);
  1294. } elseif ($query->count() == 1) {
  1295. $result = $query->first();
  1296. } else {
  1297. $result = $query->get();
  1298. }
  1299. }
  1300. return Result::success($result);
  1301. }
  1302. /**
  1303. * 获取网站底部导航
  1304. * @param array $data
  1305. * @return array
  1306. */
  1307. public function getWebsiteFooterCategoryInfo(array $data): array
  1308. {
  1309. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1310. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1311. if (empty($website)) {
  1312. return Result::error("找不到网站", 0);
  1313. }
  1314. } else {
  1315. return Result::error("参数错误", 0);
  1316. }
  1317. if (isset($data['type']) && $data['type'] == 0) {
  1318. $fcatid = FooterCategory::where('website_id', $data['website_id'])->where('id', $data['fcat_id'])->first();
  1319. if (empty($fcatid)) {
  1320. return Result::error("底部导航id错误", 0);
  1321. }
  1322. $result = FooterContent::where('fcat_id', $data['fcat_id'])->first();
  1323. } else {
  1324. $result = FooterContent::where('id', $data['fcat_id'])->first();
  1325. }
  1326. if (empty($result)) {
  1327. return Result::error("暂无底部导航内容", 0);
  1328. }
  1329. return Result::success($result);
  1330. }
  1331. /*
  1332. * 搜索网站二级导航
  1333. * @param array $data
  1334. * @return array
  1335. * */
  1336. public function selectWebsiteCategory(array $data): array
  1337. {
  1338. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1339. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1340. if (empty($website)) {
  1341. return Result::error("暂无该网站", 0);
  1342. }
  1343. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id')->all();
  1344. // return Result::success($category);
  1345. if (empty($category)) {
  1346. return Result::error("暂无此导航", 0);
  1347. }
  1348. $query = Category::whereIn('id', $category);
  1349. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1350. $cityid = District::where('id', $data['cityid'])->first();
  1351. if (empty($cityid)) {
  1352. return Result::error("暂无此城市", 0);
  1353. } else {
  1354. $city_category = $query->whereRaw('JSON_CONTAINS(city_arr_id,?)', [$data['cityid']])->pluck('id');
  1355. // $where[] = ['JSON_CONTAINS(city_arr_id, ?)', $data['cityid']];
  1356. if (empty($city_category)) {
  1357. return Result::error("暂无此城市下的导航", 0);
  1358. }
  1359. $result['catid'] = $city_category;
  1360. $city = 1;
  1361. // var_dump("城市====================",$result);
  1362. }
  1363. }
  1364. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1365. $departmentid = Department::where('id', $data['department_id'])->first();
  1366. if (empty($departmentid)) {
  1367. return Result::error("暂无此部门", 0);
  1368. } else {
  1369. $depart_category = $query->whereRaw('JSON_CONTAINS(department_arr_id,?)', [$data['department_id']])->pluck('id');
  1370. if (empty($depart_category)) {
  1371. return Result::error("暂无此部门下的导航", 0);
  1372. }
  1373. $result['catid'] = $depart_category;
  1374. // var_dump("职能部门*******************",$result);
  1375. $department = 1;
  1376. }
  1377. }
  1378. if (!empty($city) && !empty($department)) {
  1379. // var_dump("城市和职能部门----------------------",$result);
  1380. $sel_category = $query->whereRaw('JSON_CONTAINS(city_arr_id,?)', [$data['cityid']])->whereRaw('JSON_CONTAINS(department_arr_id,?)', [$data['department_id']])->pluck('id');
  1381. if (empty($sel_category)) {
  1382. return Result::error("暂无此城市和职能部门下的导航", 0);
  1383. }
  1384. $result['catid'] = $sel_category;
  1385. }
  1386. if (empty($result)) {
  1387. return Result::error("暂无导航", 0);
  1388. }
  1389. // department_id
  1390. } else {
  1391. return Result::error("参数错误", 0);
  1392. }
  1393. return Result::success($result);
  1394. }
  1395. /**
  1396. * 获取网站栏目seo
  1397. * @param array $data
  1398. * @return array
  1399. */
  1400. public function getWebsiteCategoryHead(array $data): array
  1401. {
  1402. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1403. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1404. if (empty($website)) {
  1405. return Result::error("找不到网站", 0);
  1406. }
  1407. } else {
  1408. return Result::error("参数错误", 0);
  1409. }
  1410. if (isset($data['catid']) && !empty($data['catid'])) {
  1411. $fcatid = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->first();
  1412. if (empty($fcatid)) {
  1413. return Result::error("导航id错误", 0);
  1414. }
  1415. $result = Category::where('id', $data['catid'])->first();
  1416. }
  1417. if (empty($result)) {
  1418. return Result::error("暂无导航", 0);
  1419. }
  1420. return Result::success($result);
  1421. }
  1422. /*
  1423. * 获取某个栏目
  1424. * @param array $data
  1425. * @return array
  1426. * */
  1427. public function getOneWebsiteCategory(array $data): array
  1428. {
  1429. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1430. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1431. if (empty($website)) {
  1432. return Result::error("暂无该网站", 0);
  1433. }
  1434. $result = WebsiteCategory::where('website_id',$data['website_id'])->where('category_id',$data['category_id'])->select('category_id','alias')->first();
  1435. // return Result::success($category);
  1436. if (empty($result)) {
  1437. return Result::error("暂无此导航", 0);
  1438. }
  1439. // department_id
  1440. } else {
  1441. return Result::error("参数错误", 0);
  1442. }
  1443. return Result::success($result);
  1444. }
  1445. //20250212 网站标识
  1446. public function addWebsiteGroup(array $data): array
  1447. {
  1448. //判斷name是不是重复
  1449. $websiteGroupInfo = WebsiteGroup::query()->where('name', $data['name'])->first();
  1450. if (!empty($websiteGroupInfo)) {
  1451. return Result::error("网站标识重复", 0);
  1452. }
  1453. //添加信息
  1454. $result = WebsiteGroup::insertGetId($data);
  1455. var_dump($result);
  1456. if (empty($result)) {
  1457. return Result::error("创建失败", 0);
  1458. } else {
  1459. return Result::success($result);
  1460. }
  1461. }
  1462. public function getWebsiteGroupList(array $data): array
  1463. {
  1464. $where = [];
  1465. if (isset($data['name']) && !empty($data['name'])) {
  1466. array_push($where, ['website_group.name', 'like', '%' . $data['name'] . '%']);
  1467. }
  1468. $result = WebsiteGroup::where($where)
  1469. ->limit($data['pageSize'])->orderBy("id", "desc")->offset(($data['page'] - 1) * $data['pageSize'])
  1470. ->get();
  1471. foreach ($result as $websiteGroup) {
  1472. $webIds = json_decode($websiteGroup->web_ids, true);
  1473. $websites = Website::whereIn('id', $webIds)->get();
  1474. $websiteNames = $websites->pluck('website_name', 'id')->toArray();
  1475. $websiteGroup->website_names = $websiteNames;
  1476. $websiteGroup->website_names1 = implode(',', array_values($websiteNames));
  1477. }
  1478. $count = WebsiteGroup::where($where)->count();
  1479. if (empty($result)) {
  1480. return Result::error("没有数据", 0);
  1481. }
  1482. return Result::success(['list' => $result->toArray(), 'count' => $count]);
  1483. }
  1484. public function getWebsiteGroupInfo(array $data): array
  1485. {
  1486. $websiteInfo = WebsiteGroup::query()->where('id', $data['id'])->first();
  1487. $webIds = json_decode($websiteInfo->web_ids, true);
  1488. $websites = Website::whereIn('id', $webIds)->get();
  1489. $websiteNames = $websites->pluck('website_name', 'id')->toArray();
  1490. $websiteInfo->website_names = $websiteNames;
  1491. $websiteInfo->website_names1 = implode(',', array_values($websiteNames));
  1492. if (empty($websiteInfo)) {
  1493. return Result::error("找不到URL", 0);
  1494. }
  1495. return Result::success($websiteInfo->toArray());
  1496. }
  1497. public function updateWebsiteGroup(array $data): array
  1498. {
  1499. $where = [
  1500. 'id' => $data['id'],
  1501. ];
  1502. $insertData = [
  1503. 'name' => $data['name'],
  1504. 'web_ids' => $data['web_ids'],
  1505. ];
  1506. //判斷name是不是重复
  1507. $websiteGroupInfo = WebsiteGroup::query()->where('name', $data['name'])->first();
  1508. if (!empty($websiteGroupInfo)) {
  1509. return Result::error("网站标识重复", 0);
  1510. }
  1511. $result = WebsiteGroup::where($where)->update($insertData);
  1512. var_dump($result, '------更新');
  1513. if (empty($result)) {
  1514. return Result::error("更新失败", 0);
  1515. } else {
  1516. return Result::success();
  1517. }
  1518. }
  1519. public function deleteWebsiteGroup(array $data): array
  1520. {
  1521. $where = [
  1522. 'id' => $data['id'],
  1523. ];
  1524. //看看user表是不是有这个id
  1525. $userGroup = User::query()->where('sszq', $data['id'])->first();
  1526. if (!empty($userGroup)) {
  1527. return Result::error("有用户在使用该网站标识,不能删除", 0);
  1528. }
  1529. $result = WebsiteGroup::where($where)->delete();
  1530. if (empty($result)) {
  1531. return Result::error("删除失败", 0);
  1532. } else {
  1533. return Result::success();
  1534. }
  1535. }
  1536. public function getWebsiteNavList(array $data): array
  1537. {
  1538. $where = [];
  1539. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1540. array_push($where, ['website_id', '=', $data['website_id']]);
  1541. }
  1542. if (isset($data['pid'])) {
  1543. array_push($where, ['pid', '=', $data['pid']]);
  1544. }
  1545. $list = WebsiteCategory::query()->where($where)->get();
  1546. if (empty($list)) {
  1547. return Result::error("获取失败", 0);
  1548. } else {
  1549. return Result::success($list);
  1550. }
  1551. }
  1552. }