WebsiteService.php 56 KB

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