WebsiteService.php 55 KB

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