WebsiteService.php 55 KB

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