WebsiteService.php 56 KB

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