WebsiteService.php 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613
  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_tag','like','%'.$data['ad_tag'].'%'];
  469. $result = AdPlace::where($where)
  470. ->leftJoin("ad","ad.pid","ad_place.id")
  471. ->select("ad_place.*","ad.*",'ad.name as ad_name','ad.id as ad_id')
  472. ->where('ad.fromtime', '<=', $now)
  473. ->where('ad.totime', '>=', $now)
  474. // ->whereBetween('ad.fromtime', [$now, 'ad.totime'])
  475. ->get()->all();
  476. if(empty($result)){
  477. $result = AdPlace::where($where)->get()->all();
  478. }
  479. if(empty($result)){
  480. return Result::error("此广告位不存在!",0);
  481. }
  482. }else{
  483. return Result::error("请选择广告位!",0);
  484. }
  485. return Result::success($result);
  486. }
  487. /**
  488. *
  489. * @param array $data
  490. * @return array
  491. */
  492. /**网站行政职能搜索 */
  493. public function selectWebsiteDepartment(array $data): array
  494. {
  495. $depart = Department::where('pid', 0)->orderBy('id', 'asc')->limit(10)->get();
  496. if (isset($data['keyword']) && !empty($data['keyword'])) {
  497. $departments = Department::where('name', 'like', '%' . $data['keyword'] . '%')->get();
  498. if (empty($departments)) {
  499. $result['message'] = "未查询到与此相关职能部门";
  500. } else {
  501. $count = Department::where('name', 'like', "%{$data['keyword']}%")->count();
  502. $m = [
  503. 'department' => $depart,
  504. 'type' => $departments,
  505. 'count' => $count,
  506. ];
  507. }
  508. $result['sele'] = $m;
  509. return Result::success($result['sele']);
  510. }
  511. $result = $depart;
  512. return Result::success($result);
  513. }
  514. /**
  515. * 搜索地区
  516. * @param array $data
  517. * @return array
  518. */
  519. public function selectWebsiteArea(array $data): array
  520. {
  521. $provinces = District::where('pid', 0)->where('status', 1)->get();
  522. if (isset($data['province'])) {
  523. $province = District::where('pid', 0)->where('status', 1)->where('id', $data['province'])->orderBy('id')->get();
  524. $province = $province->toArray();
  525. if (!empty($province)) {
  526. $citys = District::where('pid', $data['province'])->where('status', 1)->orderBy('id')->get();
  527. if (!empty($citys) && isset($data['city']) && !empty($data['city'])) {
  528. // $province = $province->toArray();
  529. $province_id = [];
  530. foreach ($province as $val) {
  531. array_push($province_id, $val['id']);
  532. }
  533. // var_dump($province_id);
  534. $city = District::whereIn('pid', $province_id)->where('status', 1)->where('id', $data['city'])->orderBy('id')->get();
  535. if (!empty($city)) {
  536. $city_id = [];
  537. foreach ($city as $val) {
  538. array_push($city_id, $val['id']);
  539. }
  540. $regions = District::whereIn('pid', $city_id)->where('status', 1)->orderBy('id')->get();
  541. $result = [
  542. 'province' => $province,
  543. 'city' => $city,
  544. 'region' => $regions,
  545. ];
  546. } else {
  547. return Result::error("未查询到此城市", 0);
  548. }
  549. } else {
  550. $result = [
  551. 'province' => $province,
  552. 'city' => $citys,
  553. 'region' => null,
  554. ];
  555. }
  556. } else {
  557. return Result::error("未查询到此省份", 0);
  558. }
  559. } else {
  560. // $keys = array('data');
  561. $result = $provinces;
  562. }
  563. return Result::success($result);
  564. }
  565. /**
  566. * 获取栏目
  567. * @param array $data
  568. * @return array
  569. */
  570. public function getWebsiteModelCategory(array $data): array
  571. {
  572. $website_id=[
  573. 'website_category.website_id' => $data['website_id']
  574. ];
  575. $placeid=$data['placeid']-1;
  576. $pid=[
  577. 'website_category.pid' => $data['pid'],
  578. ];
  579. var_dump( "=======",$pid);
  580. $num = $data['num'];
  581. // return Result::success($data);
  582. $result=WebsiteCategory::where($website_id)
  583. ->leftJoin("category",'website_category.category_id','category.id')
  584. ->select('website_category.*','category.is_url','category.web_url')
  585. ->where($pid)
  586. // ->with(['children' => function ($query) use ($data) {
  587. // $query->where('website_category.website_id', $data['website_id']);
  588. // }])
  589. ->orderBy('website_category.sort')
  590. ->offset($placeid)
  591. ->limit($num)
  592. ->get();
  593. foreach($result as $k=>$v){
  594. $child[$k]['children_countent']=WebsiteCategory::where($website_id)
  595. ->where('website_category.pid',$v['category_id'])
  596. ->count();
  597. if(!empty($child[$k]['children_countent'])){
  598. $result[$k]['children_count']=$child[$k]['children_countent'];
  599. }else{
  600. $result[$k]['children_count']=0;
  601. }
  602. }
  603. return Result::success($result);
  604. if(!empty($result)){
  605. return Result::success($result);
  606. }else{
  607. return Result::error("本网站暂无栏目",0);
  608. }
  609. }
  610. /**
  611. * 获取友情链接
  612. * @param array $data
  613. * @return array
  614. */
  615. public function selectWebsiteLinks(array $data): array
  616. {
  617. $where = [
  618. 'website_id' => $data['website_id'],
  619. 'status' => 1,
  620. 'type' => $data['type'],
  621. ];
  622. $num = $data['num'];
  623. $result = Link::where($where)->orderBy('id')->limit($num)->get();
  624. if (!empty($result)) {
  625. return Result::success($result);
  626. } else {
  627. return Result::error("本网站暂无此类型友情链接", 0);
  628. }
  629. }
  630. /**
  631. * 网站首页数据统计, 管理员
  632. * @return void
  633. */
  634. public function getAdminIndex(array $data): array
  635. {
  636. var_dump("用户类型:", $data['type_id']);
  637. switch ($data['type_id']) {
  638. case 4:
  639. $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;');
  640. return Result::success($result);
  641. break;
  642. case 10000:
  643. $res = [];
  644. //网站
  645. $res['website']['count'] = 0;
  646. $res['website']['growth_rate'] = 0;
  647. //资讯
  648. $res['article']['count'] = 0;
  649. $res['article']['growth_rate'] = 0;
  650. //导航池
  651. $res['category']['count'] = 0;
  652. $res['category']['growth_rate'] = 0;
  653. //近一月数据
  654. $res['monthArticle'] = [];
  655. //用户类型
  656. $res['userType'] = [];
  657. $res['website']['count'] = Website::where([])->count();
  658. $res['article']['count'] = Article::whereNotIn('status', ['404'])->count();
  659. $res['category']['count'] = Category::where([])->count();
  660. $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;');
  661. $res['userType'] = User::where([])->selectRaw("count(*) as counts,type_id")->groupBy('type_id')->get();
  662. return Result::success($res);
  663. }
  664. return [];
  665. }
  666. /**
  667. * 获取模板类型
  668. * @return void
  669. */
  670. public function getTemplateClass(array $data): array
  671. {
  672. $where = [];
  673. if (isset($data['name']) && $data['name']) {
  674. array_push($where, ['name', 'like', '%' . $data['name'] . '%']);
  675. }
  676. $result = TemplateClass::where($where)->orderBy('sort', 'asc')->get();
  677. if (empty($result)) {
  678. return Result::error("没有模板类型", 0);
  679. } else {
  680. return Result::success($result);
  681. }
  682. }
  683. /**
  684. * 添加模板类型
  685. * @param
  686. * @return void
  687. */
  688. public function addTemplateClass(array $data): array
  689. {
  690. $insertData = [
  691. 'name' => $data['name'],
  692. ];
  693. $result = TemplateClass::insertGetId($insertData);
  694. if (empty($result)) {
  695. return Result::error("创建失败", 0);
  696. } else {
  697. return Result::success(["id" => $result]);
  698. }
  699. }
  700. /**
  701. * 更新模板
  702. * @param array $data
  703. * @return array
  704. */
  705. public function upTemplateClass(array $data): array
  706. {
  707. $where = [
  708. 'id' => $data['id'],
  709. ];
  710. $insertData = [
  711. 'name' => $data['name'],
  712. ];
  713. $result = TemplateClass::where($where)->update($insertData);
  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 delTemplateClass(array $data): array
  726. {
  727. $where = [
  728. 'id' => $data['id'],
  729. ];
  730. $result = TemplateClass::where($where)->delete();
  731. if (empty($result)) {
  732. return Result::error("删除失败", 0);
  733. } else {
  734. return Result::success();
  735. }
  736. }
  737. /**
  738. * 获取分类下的模板
  739. * @param array $data
  740. * @return array
  741. */
  742. public function getTemplate(array $data): array
  743. {
  744. $page = $data['page'];
  745. $pageSize = $data['pageSize'];
  746. $where = [];
  747. if (isset($data['template_class_id']) && $data['template_class_id']) {
  748. array_push($where, ['template_class_id', '=', $data['template_class_id']]);
  749. }
  750. $result = Template::where($where)
  751. ->limit($pageSize)->offset(($page - 1) * $pageSize)->get();
  752. $count = Template::where($where)->count();
  753. if (empty($result)) {
  754. return Result::error("没有数据", 0);
  755. }
  756. $data = [
  757. 'rows' => $result->toArray(),
  758. 'count' => $count,
  759. ];
  760. return Result::success($data);
  761. }
  762. /**
  763. * 创建模板
  764. * @param
  765. * @return void
  766. */
  767. public function addTemplate(array $data): array
  768. {
  769. $insertData = [
  770. 'template_name' => $data['template_name'],
  771. 'template_img' => json_encode($data['template_img']),
  772. 'template_class_id' => $data['template_class_id'],
  773. ];
  774. $result = Template::insertGetId($insertData);
  775. if (empty($result)) {
  776. return Result::error("创建模板失败", 0);
  777. } else {
  778. return Result::success(["id" => $result]);
  779. }
  780. }
  781. /**
  782. * 更新模板
  783. * @param array $data
  784. * @return array
  785. */
  786. public function upTemplate(array $data): array
  787. {
  788. $where = [
  789. 'id' => $data['id'],
  790. ];
  791. $insertData = [
  792. 'template_name' => $data['template_name'],
  793. 'template_img' => json_encode($data['template_img']),
  794. 'template_class_id' => $data['template_class_id'],
  795. ];
  796. $result = Template::where($where)->update($insertData);
  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 delTemplate(array $data): array
  809. {
  810. $where = [
  811. 'id' => $data['id'],
  812. ];
  813. $result = Template::where($where)->delete();
  814. if (empty($result)) {
  815. return Result::error("删除模板失败", 0);
  816. } else {
  817. return Result::success();
  818. }
  819. }
  820. /**
  821. * 搜索网站
  822. * @param array $data
  823. * @return array
  824. */
  825. public function websiteList(array $data): array
  826. {
  827. $where = [];
  828. if (isset($data['keyword']) && !empty($data['keyword'])) {
  829. array_push($where, ['website.website_name', 'like', '%' . $data['keyword'] . '%']);
  830. }
  831. $result = Website::where($where)->get();
  832. if ($result) {
  833. return Result::success($result);
  834. } else {
  835. return Result::error("没有网站", 0);
  836. }
  837. }
  838. public function addWebsiteCategory(array $data): array
  839. {
  840. $website_id = $data['website_id'];
  841. $category_arr_id = $data['category_arr_id'];
  842. $categoryList = Category::whereIn('id', $category_arr_id)->get();
  843. $categoryListIds = [];
  844. if ($categoryList) {
  845. foreach ($categoryList->toArray() as $val) {
  846. array_push($categoryListIds, $val['id']);
  847. }
  848. }
  849. $arr = [];
  850. if ($categoryListIds) {
  851. foreach ($categoryListIds as $v) {
  852. $ids = $this->getUnderlingUIds(intval($v));
  853. $ids_arr = explode(",", $ids);
  854. array_push($arr, $ids_arr);
  855. }
  856. }
  857. $mergedArray = [];
  858. foreach ($arr as $subarray) {
  859. $mergedArray = array_merge($mergedArray, $subarray);
  860. }
  861. var_dump("所有:", $arr, $mergedArray);
  862. //查询出所有的分类进行分割插入 组装数据
  863. $categoryListData = Category::whereIn('id', $mergedArray)->get();
  864. $categoryListData = $categoryListData->toArray();
  865. $insertData = [];
  866. if ($categoryListData) {
  867. foreach ($categoryListData as $key => $value) {
  868. $insertData[$key]['website_id'] = $website_id;
  869. $insertData[$key]['name'] = $value['name'];
  870. $insertData[$key]['sort'] = $value['sort'];
  871. $insertData[$key]['pid'] = $value['pid'];
  872. $insertData[$key]['pid_arr'] = $value['pid_arr'];
  873. $insertData[$key]['seo_title'] = $value['seo_title'];
  874. $insertData[$key]['seo_keywords'] = $value['seo_keywords'];
  875. $insertData[$key]['seo_description'] = $value['seo_description'];
  876. $insertData[$key]['alias'] = $value['name'];
  877. $insertData[$key]['category_id'] = $value['id'];
  878. }
  879. }
  880. $result = WebsiteCategory::insert($insertData);
  881. var_dump("插入数据状态:", $result);
  882. if ($result) {
  883. return Result::success($result);
  884. } else {
  885. return Result::error("创建失败", 0);
  886. }
  887. }
  888. /**
  889. * 删除网站导航
  890. * @param array $data
  891. * @return array
  892. */
  893. public function delWebsiteCategory(array $data): array
  894. {
  895. $website_id = $data['website_id'] ?? 0;
  896. $category_id = $data['category_id'] ?? 0;
  897. $ids = $this->getUnderlingUIds(intval($category_id));
  898. $ids_arr = explode(",", $ids);
  899. $result = WebsiteCategory::where(['website_id' => $website_id])->whereIn("category_id", $ids_arr)->delete();
  900. if ($result) {
  901. return Result::success($result);
  902. } else {
  903. return Result::error("删除失败", 0);
  904. }
  905. }
  906. /**
  907. * 获取网站导航
  908. * @param array $data
  909. * @return array
  910. */
  911. public function getAdminWebsiteCategory(array $data): array
  912. {
  913. $where = [
  914. 'website_id' => $data['website_id'],
  915. 'pid' => 0,
  916. ];
  917. $result = WebsiteCategory::where($where)->get();
  918. if ($result) {
  919. return Result::success($result);
  920. } else {
  921. return Result::error("查询失败", 0);
  922. }
  923. }
  924. /**
  925. * 更新网站导航
  926. * @param array $data
  927. * @return array
  928. */
  929. public function upWebsiteCategory(array $data): array
  930. {
  931. Db::beginTransaction();
  932. try {
  933. //合并栏目id
  934. $reqIds = array_merge($data['old_category_arr_id'], $data['new_category_arr_id']);
  935. //对比old 数组差异化,把差异化的删除
  936. $result = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])->get();
  937. $result = $result->toArray();
  938. $categoryIds = [];
  939. if ($result) {
  940. foreach ($result as $val) {
  941. array_push($categoryIds, $val['category_id']);
  942. }
  943. }
  944. //和原始数据对比取交际
  945. $reqidsIntersect = array_intersect($reqIds, $categoryIds);
  946. //再取差集 进行对比
  947. $differenceIDS = array_merge(array_diff($reqidsIntersect, $categoryIds), array_diff($categoryIds, $reqidsIntersect));
  948. var_dump("差集:", $differenceIDS);
  949. $arr_ids = [];
  950. if (count($differenceIDS) > 0) {
  951. foreach ($differenceIDS as $vv) {
  952. $idV = $this->getUnderlingUIds(intval($vv));
  953. $ids_arrV = explode(",", $idV);
  954. array_push($arr_ids, $ids_arrV);
  955. }
  956. }
  957. $del_ids = array_reduce($arr_ids, 'array_merge', array());
  958. //有差异 删除
  959. if (count($del_ids) > 0) {
  960. WebsiteCategory::where(['website_id' => $data['website_id']])->whereIn("category_id", $del_ids)->delete();
  961. }
  962. //传过来的值 和 交际 对比,选出要添加的值 进行插入
  963. $insertIDS = array_merge(array_diff($reqIds, $reqidsIntersect), array_diff($reqidsIntersect, $reqIds));
  964. var_dump("要存储的:", $insertIDS);
  965. //新的数组重新创建
  966. if (count($insertIDS) > 0) {
  967. $arr = [];
  968. $categoryListIds = $insertIDS;
  969. if ($categoryListIds) {
  970. foreach ($categoryListIds as $v) {
  971. $ids = $this->getUnderlingUIds(intval($v));
  972. $ids_arr = explode(",", $ids);
  973. array_push($arr, $ids_arr);
  974. }
  975. }
  976. $mergedArray = [];
  977. foreach ($arr as $subarray) {
  978. $mergedArray = array_merge($mergedArray, $subarray);
  979. }
  980. var_dump("要插入的ID:", $mergedArray);
  981. //查询出所有的分类进行分割插入 组装数据
  982. $categoryListData = Category::whereIn('id', $mergedArray)->get();
  983. $categoryListData = $categoryListData->toArray();
  984. $insertData = [];
  985. if ($categoryListData) {
  986. foreach ($categoryListData as $key => $value) {
  987. $insertData[$key]['website_id'] = $data['website_id'];
  988. $insertData[$key]['name'] = $value['name'];
  989. $insertData[$key]['sort'] = $value['sort'];
  990. $insertData[$key]['pid'] = $value['pid'];
  991. $insertData[$key]['pid_arr'] = $value['pid_arr'];
  992. $insertData[$key]['seo_title'] = $value['seo_title'];
  993. $insertData[$key]['seo_keywords'] = $value['seo_keywords'];
  994. $insertData[$key]['seo_description'] = $value['seo_description'];
  995. $insertData[$key]['alias'] = $value['name'];
  996. $insertData[$key]['category_id'] = $value['id'];
  997. }
  998. }
  999. WebsiteCategory::insert($insertData);
  1000. }
  1001. Db::commit();
  1002. } catch (\Throwable $ex) {
  1003. Db::rollBack();
  1004. var_dump($ex->getMessage());
  1005. return Result::error("修改失败", 0);
  1006. }
  1007. return Result::success();
  1008. }
  1009. /**
  1010. * 获取网站列表
  1011. * @param array $data
  1012. * @return array
  1013. */
  1014. public function getWebsiteCategoryList(array $data): array
  1015. {
  1016. $where = [];
  1017. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1018. array_push($where, ['website.website_name', 'like', '%' . $data['keyword'] . '%']);
  1019. }
  1020. if (isset($data['website_column_id']) && !empty($data['website_column_id'])) {
  1021. array_push($where, ['website.website_column_id', '=', $data['website_column_id']]);
  1022. }
  1023. $result = Website::where($where)
  1024. ->with(["websiteCategory" => function ($query) {
  1025. $query->where(['pid' => 0])->select('website_id', 'name', 'alias', 'category_id');
  1026. }])
  1027. ->limit($data['pageSize'])->orderBy("updated_at", "desc")->offset(($data['page'] - 1) * $data['pageSize'])
  1028. ->get();
  1029. $count = Website::where($where)->count();
  1030. if (empty($result)) {
  1031. return Result::error("没有数据", 0);
  1032. }
  1033. $data = [
  1034. 'rows' => $result->toArray(),
  1035. 'count' => $count,
  1036. ];
  1037. if ($result) {
  1038. return Result::success($data);
  1039. } else {
  1040. return Result::error("查询失败", 0);
  1041. }
  1042. }
  1043. /**
  1044. * 删除网站下的所有导航
  1045. * @param array $data
  1046. * @return array
  1047. */
  1048. public function delWebsiteAllCategory(array $data): array
  1049. {
  1050. $website_id = $data['website_id'];
  1051. $result = WebsiteCategory::where(['website_id' => $website_id])->delete();
  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 getWebsiteCategoryOnes(array $data): array
  1064. {
  1065. $website_id = $data['website_id'];
  1066. $category_id = $data['category_id'];
  1067. $result = WebsiteCategory::where(['website_category.website_id' => $website_id, 'website_category.category_id' => $category_id])
  1068. ->first();
  1069. if ($result) {
  1070. return Result::success($result);
  1071. } else {
  1072. return Result::error("查询失败", 0);
  1073. }
  1074. }
  1075. /**
  1076. * 更新网闸下的某一个导航
  1077. * @param array $data
  1078. * @return array
  1079. */
  1080. public function upWebsiteCategoryones(array $data): array
  1081. {
  1082. $where = [
  1083. 'website_id' => $data['website_id'],
  1084. 'category_id' => $data['category_id'],
  1085. ];
  1086. $data['sort'] = $data['sort']??0;
  1087. $result = WebsiteCategory::where($where)->update($data);
  1088. if ($result) {
  1089. return Result::success($result);
  1090. } else {
  1091. return Result::error("更新失败", 0);
  1092. }
  1093. }
  1094. /**
  1095. * 获取网站下的所有导航(包含子导航)
  1096. * @param array $data
  1097. * @return array
  1098. */
  1099. public function getWebsiteAllCategory(array $data): array
  1100. {
  1101. $where = [];
  1102. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1103. array_push($where, ['website_category.website_id', '=', $data['website_id']]);
  1104. }
  1105. if (isset($data['name']) && !empty($data['name'])) {
  1106. array_push($where, ['website_category.name', 'like', '%' . $data['name'] . '%']);
  1107. }
  1108. if (isset($data['alias']) && !empty($data['alias'])) {
  1109. array_push($where, ['website_category.alias', 'like', '%' . $data['alias'] . '%']);
  1110. }
  1111. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1112. array_push($where, ['category.department_id', '=', $data['department_id']]);
  1113. }
  1114. if (isset($data['city_id']) && !empty($data['city_id'])) {
  1115. array_push($where, ['category.city_id', '=', $data['city_id']]);
  1116. }
  1117. $result = WebsiteCategory::where($where)
  1118. ->leftJoin("category", 'website_category.category_id', 'category.id')
  1119. ->leftJoin("department", 'category.department_id', 'department.id')
  1120. ->leftJoin("district", 'category.city_id', 'district.id')
  1121. ->select("website_category.*", "department.name as department_name", "district.name as city_name")
  1122. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])
  1123. ->get();
  1124. $count = WebsiteCategory::where($where)
  1125. ->leftJoin("category", 'website_category.category_id', 'category.id')
  1126. ->leftJoin("department", 'category.department_id', 'department.id')
  1127. ->leftJoin("district", 'category.city_id', 'district.id')
  1128. ->count();
  1129. if (empty($result)) {
  1130. return Result::error("没有数据", 0);
  1131. }
  1132. $data = [
  1133. 'rows' => $result->toArray(),
  1134. 'count' => $count,
  1135. ];
  1136. if ($result) {
  1137. return Result::success($data);
  1138. } else {
  1139. return Result::error("查询失败", 0);
  1140. }
  1141. if ($result) {
  1142. return Result::success($result);
  1143. } else {
  1144. return Result::error("查询失败", 0);
  1145. }
  1146. }
  1147. /**
  1148. * 递归查询数据
  1149. * @param $id
  1150. * @param $ids
  1151. * @return string
  1152. */
  1153. public function getUnderlingUIds($id, $ids = '')
  1154. {
  1155. $back = Category::where(['pid' => $id])->get();
  1156. $back = $back->toArray();
  1157. if (!empty($back) && is_array($back)) {
  1158. foreach ($back as $v) {
  1159. //防止当前人的ID重复去查询,形成恶性循环
  1160. if ($v['id'] == $id) {
  1161. continue;
  1162. }
  1163. $back2 = Category::where(['pid' => $id])->count('id');
  1164. if ($back2 > 0) {
  1165. $ids = $this->getUnderlingUIds($v['id'], $ids);
  1166. } else {
  1167. $ids .= ',' . $v['id'];
  1168. }
  1169. }
  1170. }
  1171. $ids = $id . ',' . $ids . ',';
  1172. $ids = str_replace(',,', ",", $ids);
  1173. $ids = trim($ids, ',');
  1174. return $ids;
  1175. }
  1176. /**
  1177. * 检测网站名称是否重复
  1178. * @param array $data
  1179. * @return array
  1180. */
  1181. public function checkWebsiteName(array $data): array
  1182. {
  1183. if (isset($data['id'])) {
  1184. $data[] = ['id', "!=", $data['id']];
  1185. unset($data['id']);
  1186. }
  1187. $websiteInfo = Website::query()->where($data)->first();
  1188. if (empty($websiteInfo)) {
  1189. return Result::error("找不到网站", 0);
  1190. }
  1191. return Result::success($websiteInfo->toArray());
  1192. }
  1193. /**
  1194. * 检测网站url是否重复
  1195. * @param array $data
  1196. * @return array
  1197. */
  1198. public function checkWebsiteUrl(array $data): array
  1199. {
  1200. $whereData = [];
  1201. if (isset($data['id'])) {
  1202. $whereData = [['id', "!=", $data['id']]];
  1203. unset($data['id']);
  1204. }
  1205. $websiteInfo = Website::query()->where($whereData)->whereJsonContains('website_url', $data['website_url'])->first();
  1206. if (empty($websiteInfo)) {
  1207. return Result::error("找不到URL", 0);
  1208. }
  1209. return Result::success($websiteInfo->toArray());
  1210. }
  1211. /**
  1212. * 获取网站底部基础信息
  1213. * @param array $data
  1214. * @return array
  1215. */
  1216. public function getWebsiteFootInfo(array $data): array
  1217. {
  1218. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1219. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1220. if (empty($website)) {
  1221. return Result::error("找不到网站", 0);
  1222. }
  1223. } else {
  1224. return Result::error("参数错误", 0);
  1225. }
  1226. $website_foot = WebsiteTemplateInfo::where('website_id', $data['website_id'])->where('status', 2)->first();
  1227. $website_head = Website::where('id', $data['website_id'])
  1228. ->select('id', 'website_name', 'logo', 'title', 'keywords', 'description')->first();
  1229. if (empty($website_foot)) {
  1230. return Result::error("暂无底部基础信息", 0);
  1231. }
  1232. if (empty($website_head)) {
  1233. return Result::error("暂无头部基础信息", 0);
  1234. }
  1235. $result = [
  1236. 'website_foot' => $website_foot,
  1237. 'website_head' => $website_head,
  1238. ];
  1239. return Result::success($result);
  1240. }
  1241. /**
  1242. * 获取网站底部导航
  1243. * @param array $data
  1244. * @return array
  1245. */
  1246. public function getWebsiteFooterCategory(array $data): array
  1247. {
  1248. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1249. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1250. if (empty($website)) {
  1251. return Result::error("找不到网站", 0);
  1252. }
  1253. } else {
  1254. return Result::error("参数错误", 0);
  1255. }
  1256. $result = FooterCategory::where('website_id', $data['website_id'])->get();
  1257. if (empty($result)) {
  1258. return Result::error("暂无底部导航", 0);
  1259. }
  1260. return Result::success($result->toArray());
  1261. }
  1262. /**
  1263. * 获取网站底部导航列表
  1264. * @param array $data
  1265. * @return array
  1266. */
  1267. public function getWebsiteFooterCategoryList(array $data): array
  1268. {
  1269. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1270. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1271. if (empty($website)) {
  1272. return Result::error("找不到网站", 0);
  1273. }
  1274. } else {
  1275. return Result::error("参数错误", 0);
  1276. }
  1277. $footercategory = FooterCategory::where('website_id', $data['website_id'])->where('id', $data['fcat_id'])->first();
  1278. // '底部导航类型 0:内容型;1:列表型;',
  1279. if (!isset($footercategory['type']) || $footercategory['type'] == 0) {
  1280. return Result::error("底部导航id错误", 0);
  1281. } else {
  1282. $query = FooterContent::where('fcat_id', $data['fcat_id']);
  1283. if ($query->count() == 0) {
  1284. return Result::error("暂无底部导航列表", 0);
  1285. } elseif ($query->count() == 1) {
  1286. $result = $query->first();
  1287. } else {
  1288. $result = $query->get();
  1289. }
  1290. }
  1291. return Result::success($result);
  1292. }
  1293. /**
  1294. * 获取网站底部导航
  1295. * @param array $data
  1296. * @return array
  1297. */
  1298. public function getWebsiteFooterCategoryInfo(array $data): array
  1299. {
  1300. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1301. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1302. if (empty($website)) {
  1303. return Result::error("找不到网站", 0);
  1304. }
  1305. } else {
  1306. return Result::error("参数错误", 0);
  1307. }
  1308. if (isset($data['type']) && $data['type'] == 0) {
  1309. $fcatid = FooterCategory::where('website_id', $data['website_id'])->where('id', $data['fcat_id'])->first();
  1310. if (empty($fcatid)) {
  1311. return Result::error("底部导航id错误", 0);
  1312. }
  1313. $result = FooterContent::where('fcat_id', $data['fcat_id'])->first();
  1314. } else {
  1315. $result = FooterContent::where('id', $data['fcat_id'])->first();
  1316. }
  1317. if (empty($result)) {
  1318. return Result::error("暂无底部导航内容", 0);
  1319. }
  1320. return Result::success($result);
  1321. }
  1322. /*
  1323. * 搜索网站二级导航
  1324. * @param array $data
  1325. * @return array
  1326. * */
  1327. public function selectWebsiteCategory(array $data): array
  1328. {
  1329. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1330. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1331. if (empty($website)) {
  1332. return Result::error("暂无该网站", 0);
  1333. }
  1334. $category = WebsiteCategory::where('website_id',$data['website_id'])->pluck('category_id')->all();
  1335. // return Result::success($category);
  1336. if (empty($category)) {
  1337. return Result::error("暂无此导航",0);
  1338. }
  1339. $query = Category::whereIn('id', $category);
  1340. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1341. $cityid = District::where('id', $data['cityid'])->first();
  1342. if (empty($cityid)) {
  1343. return Result::error("暂无此城市", 0);
  1344. } else {
  1345. $city_category = $query->whereRaw('JSON_CONTAINS(city_arr_id,?)', [$data['cityid']])->pluck('id');
  1346. // $where[] = ['JSON_CONTAINS(city_arr_id, ?)', $data['cityid']];
  1347. if (empty($city_category)) {
  1348. return Result::error("暂无此城市下的导航", 0);
  1349. }
  1350. $result['catid'] = $city_category;
  1351. $city = 1;
  1352. // var_dump("城市====================",$result);
  1353. }
  1354. }
  1355. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1356. $departmentid = Department::where('id', $data['department_id'])->first();
  1357. if (empty($departmentid)) {
  1358. return Result::error("暂无此部门", 0);
  1359. } else {
  1360. $depart_category = $query->whereRaw('JSON_CONTAINS(department_arr_id,?)', [$data['department_id']])->pluck('id');
  1361. if (empty($depart_category)) {
  1362. return Result::error("暂无此部门下的导航", 0);
  1363. }
  1364. $result['catid'] = $depart_category;
  1365. // var_dump("职能部门*******************",$result);
  1366. $department = 1;
  1367. }
  1368. }
  1369. if(!empty($city) && !empty($department)){
  1370. // var_dump("城市和职能部门----------------------",$result);
  1371. $sel_category = $query->whereRaw('JSON_CONTAINS(city_arr_id,?)', [$data['cityid']])->whereRaw('JSON_CONTAINS(department_arr_id,?)', [$data['department_id']])->pluck('id');
  1372. if (empty($sel_category)) {
  1373. return Result::error("暂无此城市和职能部门下的导航", 0);
  1374. }
  1375. $result['catid'] = $sel_category;
  1376. }
  1377. if (empty($result)) {
  1378. return Result::error("暂无导航",0);
  1379. }
  1380. // department_id
  1381. } else {
  1382. return Result::error("参数错误", 0);
  1383. }
  1384. return Result::success($result);
  1385. }
  1386. /**
  1387. * 获取网站栏目seo
  1388. * @param array $data
  1389. * @return array
  1390. */
  1391. public function getWebsiteCategoryHead(array $data): array
  1392. {
  1393. $where = [];
  1394. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1395. array_push($where, ['website_id', '=', $data['website_id']]);
  1396. }
  1397. if (isset($data['catid']) && !empty($data['catid'])) {
  1398. $fcatid = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->first();
  1399. if (empty($fcatid)) {
  1400. return Result::error("导航id错误", 0);
  1401. }
  1402. $result = Category::where('id', $data['catid'])->first();
  1403. }
  1404. if (empty($result)) {
  1405. return Result::error("暂无导航", 0);
  1406. }
  1407. return Result::success($result);
  1408. }
  1409. /*
  1410. * 获取某个栏目
  1411. * @param array $data
  1412. * @return array
  1413. * */
  1414. public function getOneWebsiteCategory(array $data): array
  1415. {
  1416. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1417. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1418. if (empty($website)) {
  1419. return Result::error("暂无该网站", 0);
  1420. }
  1421. $result = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['category_id'])->select('category_id', 'name')->first();
  1422. // return Result::success($category);
  1423. if (empty($result)) {
  1424. return Result::error("暂无此导航", 0);
  1425. }
  1426. // department_id
  1427. } else {
  1428. return Result::error("参数错误", 0);
  1429. }
  1430. return Result::success($result);
  1431. }
  1432. //20250212 网站标识
  1433. public function addWebsiteGroup(array $data): array
  1434. {
  1435. //添加信息
  1436. $result = WebsiteGroup::insertGetId($data);
  1437. var_dump($result);
  1438. //判斷name是不是重复
  1439. $websiteGroupInfo = WebsiteGroup::query()->where('name', $data['name'])->first();
  1440. if (!empty($websiteGroupInfo)) {
  1441. return Result::error("网站标识重复", 0);
  1442. }
  1443. if (empty($result)) {
  1444. return Result::error("创建失败", 0);
  1445. } else {
  1446. return Result::success($result);
  1447. }
  1448. }
  1449. public function getWebsiteGroupList(array $data): array
  1450. {
  1451. $where = [];
  1452. if (isset($data['name']) && !empty($data['name'])) {
  1453. array_push($where, ['website_group.name', 'like', '%' . $data['name'] . '%']);
  1454. }
  1455. $result = WebsiteGroup::where($where)
  1456. ->limit($data['pageSize'])->orderBy("id", "desc")->offset(($data['page'] - 1) * $data['pageSize'])
  1457. ->get();
  1458. foreach ($result as $websiteGroup) {
  1459. $webIds = json_decode($websiteGroup->web_ids, true);
  1460. $websites = Website::whereIn('id', $webIds)->get();
  1461. $websiteNames = $websites->pluck('website_name', 'id')->toArray();
  1462. $websiteGroup->website_names = $websiteNames;
  1463. $websiteGroup->website_names1 = implode(',', array_values($websiteNames));
  1464. }
  1465. $count = WebsiteGroup::where($where)->count();
  1466. if (empty($result)) {
  1467. return Result::error("没有数据", 0);
  1468. }
  1469. return Result::success(['list' => $result->toArray(), 'count' => $count]);
  1470. }
  1471. public function getWebsiteGroupInfo(array $data): array
  1472. {
  1473. $websiteInfo = WebsiteGroup::query()->where('id', $data['id'])->first();
  1474. $webIds = json_decode($websiteInfo->web_ids, true);
  1475. $websites = Website::whereIn('id', $webIds)->get();
  1476. $websiteNames = $websites->pluck('website_name', 'id')->toArray();
  1477. $websiteInfo->website_names = $websiteNames;
  1478. $websiteInfo->website_names1 = implode(',', array_values($websiteNames));
  1479. if (empty($websiteInfo)) {
  1480. return Result::error("找不到URL", 0);
  1481. }
  1482. return Result::success($websiteInfo->toArray());
  1483. }
  1484. public function updateWebsiteGroup(array $data): array
  1485. {
  1486. $where = [
  1487. 'id' => $data['id'],
  1488. ];
  1489. $insertData = [
  1490. 'name' => $data['name'],
  1491. 'web_ids' => $data['web_ids'],
  1492. ];
  1493. $result = WebsiteGroup::where($where)->update($insertData);
  1494. var_dump($result, '------更新');
  1495. if (empty($result)) {
  1496. return Result::error("更新失败", 0);
  1497. } else {
  1498. return Result::success();
  1499. }
  1500. }
  1501. public function deleteWebsiteGroup(array $data): array
  1502. {
  1503. $where = [
  1504. 'id' => $data['id'],
  1505. ];
  1506. //看看user表是不是有这个id
  1507. $userGroup = User::query()->where('sszq', $data['id'])->first();
  1508. if (!empty($userGroup)) {
  1509. return Result::error("有用户在使用该网站标识,不能删除", 0);
  1510. }
  1511. $result = WebsiteGroup::where($where)->delete();
  1512. if (empty($result)) {
  1513. return Result::error("删除失败", 0);
  1514. } else {
  1515. return Result::success();
  1516. }
  1517. }
  1518. public function getWebsiteNavList(array $data): array
  1519. {
  1520. $where = [];
  1521. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1522. array_push($where, ['website_id', '=', $data['website_id']]);
  1523. }
  1524. if (isset($data['pid']) && !empty($data['pid'])) {
  1525. array_push($where, ['pid', '=', $data['pid']]);
  1526. }
  1527. $list = WebsiteCategory::query()->where($where)->get();
  1528. if (empty($list)) {
  1529. return Result::error("获取失败", 0);
  1530. } else {
  1531. return Result::success($list);
  1532. }
  1533. }
  1534. //20250212 网站标识
  1535. }