WebsiteService.php 46 KB

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