WebsiteService.php 56 KB

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