WebsiteService.php 56 KB

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