WebsiteService.php 55 KB

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