WebsiteService.php 56 KB

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