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