WebsiteService.php 56 KB

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