WebsiteService.php 97 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525
  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Model\Article;
  4. use App\Model\Ad;
  5. use App\Model\Category;
  6. use App\Model\AdPlace;
  7. use App\Model\Department;
  8. use App\Model\District;
  9. use App\Model\FooterCategory;
  10. use App\Model\FooterContent;
  11. use App\Model\WebsiteTemplateInfo;
  12. use App\Model\Link;
  13. use App\Model\LetterOfComplaint;
  14. use App\Model\TemplateClass;
  15. use App\Model\Template;
  16. use App\Model\User;
  17. use App\Model\UserInfo;
  18. use App\Model\WebsiteRole;
  19. use App\Model\WebsiteRoleUser;
  20. use App\Model\Website;
  21. use App\Model\WebsiteColumn;
  22. use App\Model\Good;
  23. use App\Model\Book;
  24. use App\Model\JobRecruiting;
  25. use App\Model\JobHunting;
  26. use App\Model\Notice;
  27. use App\Model\Complaint;
  28. use App\Model\Order;
  29. use Hyperf\DbConnection\Db;
  30. use Hyperf\RpcServer\Annotation\RpcService;
  31. use App\Tools\Result;
  32. use Carbon\Carbon;
  33. use App\Model\WebsiteCategory;
  34. use App\Model\WebsiteGroup;
  35. use App\Model\WebsiteTemplate;
  36. use App\Model\Sector;
  37. use PhpParser\Node\Stmt\Return_;
  38. use function PHPUnit\Framework\isNull;
  39. use Overtrue\Pinyin\Pinyin;
  40. use App\Tools\buildTree;
  41. #[RpcService(name: "WebsiteService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  42. class WebsiteService implements WebsiteServiceInterface
  43. {
  44. /**
  45. * 获取网站列表
  46. * @param string $keyword
  47. * @param int $page
  48. * @param int $pageSize
  49. * @return array
  50. */
  51. public function getWebsitetList(array $data): array
  52. {
  53. // 构建查询
  54. $query = Website::when($data, function ($query) use ($data) {
  55. if (isset($data['keyword']) && !empty($data['keyword'])) {
  56. $query->where('website.website_name', 'like', '%' . trim($data['keyword']) . '%');
  57. }
  58. if (isset($data['website_column_id']) && !empty($data['website_column_id'])) {
  59. $query->whereJsonContains("website.website_column_arr_id", intval($data['website_column_id']));
  60. }
  61. if (isset($data['city_id']) && !empty($data['city_id'])) {
  62. $query->whereJsonContains("website.city_arr_id", intval($data['city_id']));
  63. }
  64. });
  65. // 执行查询并获取总数和结果
  66. $queryWithJoins = $query->leftJoin("website_column", "website.website_column_id", "website_column.id")
  67. ->leftJoin("district", "district.id", "website.city_id");
  68. $count = $queryWithJoins->count();
  69. $result = $queryWithJoins->select("website.*", "website_column.column_name", "district.name as city_name")
  70. ->limit($data['pageSize'])
  71. ->offset(($data['page'] - 1) * $data['pageSize'])
  72. ->orderBy("website.updated_at", "desc")
  73. ->get();
  74. if (empty($result)) {
  75. return Result::error("没有数据", 0);
  76. }
  77. $data = [
  78. 'rows' => $result->toArray(),
  79. 'count' => $count,
  80. ];
  81. return Result::success($data);
  82. }
  83. /**
  84. * @param array $data
  85. * @return array
  86. */
  87. public function createWebsite(array $data): array
  88. {
  89. var_dump("网站数据:", $data);
  90. $insertData = [
  91. 'website_name' => $data['website_name'],
  92. 'logo' => $data['logo'] ?? '',
  93. 'website_url' => $data['website_url'] ?? '',
  94. // 'city_id'=>$data['city_id']??0,
  95. 'website_column_id' => $data['website_column_id'],
  96. 'title' => $data['title'] ?? '',
  97. 'keywords' => $data['keywords'] ?? '',
  98. 'description' => $data['description'] ?? '',
  99. 'status' => $data['status'] ?? 1,
  100. 'website_column_arr_id' => $data['website_column_arr_id'],
  101. // 'city_arr_id'=>$data['city_arr_id']??[0],
  102. 'template_id' => $data['template_id'] ?? 0,
  103. 'suffix' => $data['suffix'] ?? "",
  104. ];
  105. $result = Website::insertGetId($insertData);
  106. if (empty($result)) {
  107. return Result::error("创建失败", 0);
  108. } else {
  109. return Result::success(["id" => $result]);
  110. }
  111. }
  112. /**
  113. * @param int $id
  114. * @param array $data
  115. * @return array
  116. */
  117. public function updateWebsite(int $id, array $data): array
  118. {
  119. $insertData = [
  120. 'website_name' => $data['website_name'],
  121. 'logo' => $data['logo'] ?? '',
  122. 'website_url' => $data['website_url'] ?? '',
  123. // 'city_id'=>$data['city_id']??0,
  124. 'website_column_id' => $data['website_column_id'],
  125. 'title' => $data['title'] ?? '',
  126. 'keywords' => $data['keywords'] ?? '',
  127. 'description' => $data['description'] ?? '',
  128. // 'status' => $data['status'] ?? 0,
  129. 'website_column_arr_id' => $data['website_column_arr_id'],
  130. // 'city_arr_id'=>$data['city_arr_id']??[0],
  131. 'template_id' => $data['template_id'] ?? 0,
  132. 'suffix' => $data['suffix'] ?? "",
  133. ];
  134. var_dump("=========:", $insertData);
  135. $result = Website::where('id', $id)->update($insertData);
  136. var_dump("更新站点", $result);
  137. if (empty($result)) {
  138. return Result::error("更新失败", 0);
  139. } else {
  140. return Result::success();
  141. }
  142. }
  143. /**
  144. * @param int $id
  145. * @return array
  146. */
  147. public function delWebsite(int $id): array
  148. {
  149. $result = Website::where('id', $id)->delete();
  150. if (empty($result)) {
  151. return Result::error("删除失败", 0);
  152. } else {
  153. return Result::success();
  154. }
  155. }
  156. /**
  157. * @param int $id
  158. * @return array
  159. */
  160. public function getWebsiteInfo(int $id): array
  161. {
  162. $where = [
  163. ['website.id', '=', $id],
  164. ];
  165. $result = Website::where($where)
  166. ->leftJoin("template", "template.id", "website.template_id")
  167. ->select("website.*", "template.template_name", "template.template_img")
  168. ->first();
  169. if (empty($result)) {
  170. return Result::error("数据不存在", 0);
  171. } else {
  172. return Result::success($result->toArray());
  173. }
  174. }
  175. /**
  176. * 查询所有的站点栏目
  177. * @return array
  178. */
  179. public function getWebsiteColumn(array $data): array
  180. {
  181. $result = WebsiteColumn::where($data)->get();
  182. if (empty($result)) {
  183. return Result::error("数据不存在", 0);
  184. } else {
  185. return Result::success($result->toArray());
  186. }
  187. }
  188. /**
  189. * @param string $keyword
  190. * @param int $page
  191. * @param int $pageSize
  192. * @return array
  193. */
  194. public function getWebsiteColumnList(array $data): array
  195. {
  196. $where = [];
  197. if (isset($data['keyword']) && $data['keyword']) {
  198. array_push($where, ['website_column.column_name', 'like', '%' . $data['keyword'] . '%']);
  199. }
  200. $result = WebsiteColumn::where($where)
  201. ->leftJoin("website_column as wc", "website_column.pid", "wc.id")
  202. ->select("website_column.*", "wc.column_name as parent_column_name")
  203. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->get();
  204. $count = WebsiteColumn::where($where)->count();
  205. if (empty($result)) {
  206. return Result::error("没有数据", 0);
  207. }
  208. $data = [
  209. 'rows' => $result->toArray(),
  210. 'count' => $count,
  211. ];
  212. return Result::success($data);
  213. }
  214. /**
  215. * @param array $data
  216. * @return array
  217. */
  218. public function createWebsiteColumn(array $data): array
  219. {
  220. $insertData = [
  221. 'column_name' => $data['column_name'],
  222. 'pid' => $data['pid'] ?? '',
  223. 'column_arr_id' => $data['column_arr_id'] ?? [0],
  224. 'sort' => $data['sort'] ?? 0,
  225. 'remark' => $data['remark'] ?? '',
  226. ];
  227. $result = WebsiteColumn::insertGetId($insertData);
  228. if (empty($result)) {
  229. return Result::error("创建失败", 0);
  230. } else {
  231. return Result::success(["id" => $result]);
  232. }
  233. }
  234. /**
  235. * @param int $id
  236. * @param array $data
  237. * @return array
  238. */
  239. public function updateWebsiteColumn(int $id, array $data): array
  240. {
  241. $insertData = [
  242. 'column_name' => $data['column_name'],
  243. 'pid' => $data['pid'] ?? '',
  244. 'column_arr_id' => $data['column_arr_id'] ?? [0],
  245. 'sort' => $data['sort'] ?? 0,
  246. 'remark' => $data['remark'] ?? '',
  247. ];
  248. $result = WebsiteColumn::where('id', $id)->update($insertData);
  249. if (empty($result)) {
  250. return Result::error("更新失败", 0);
  251. } else {
  252. return Result::success();
  253. }
  254. }
  255. /**
  256. * @param int $id
  257. * @return array
  258. */
  259. public function delWebsiteColumn(int $id): array
  260. {
  261. $list = WebsiteColumn::where(['pid' => $id])->get();
  262. if ($list) {
  263. return Result::error("存在子网系,不能删除,请先删除子网系", 0);
  264. }
  265. $result = WebsiteColumn::where('id', $id)->delete();
  266. if (empty($result)) {
  267. return Result::error("删除失败", 0);
  268. } else {
  269. return Result::success();
  270. }
  271. }
  272. /**
  273. * @param string $keyword
  274. * @param int $page
  275. * @param int $pageSize
  276. * @return array
  277. */
  278. public function getWebsiteRoleList(string $keyword, int $page, int $pageSize, int $websiteId): array
  279. {
  280. $where = [
  281. ['role.role_name', 'like', '%' . $keyword . '%'],
  282. ['website_role.website_id', '=', $websiteId],
  283. ];
  284. $result = WebsiteRole::where($where)
  285. ->leftJoin("role", "role.id", "website_role.role_id")
  286. ->select("role.*", "website_role.type", "website_role.role_id", "website_role.id as website_role_id", "website_role.website_id")
  287. ->limit($pageSize)->offset(($page - 1) * $pageSize)->get();
  288. $count = WebsiteRole::where($where)->leftJoin("role", "role.id", "website_role.role_id")->count();
  289. if (empty($result)) {
  290. return Result::error("没有数据", 0);
  291. }
  292. $data = [
  293. 'rows' => $result->toArray(),
  294. 'count' => $count,
  295. ];
  296. return Result::success($data);
  297. }
  298. /**
  299. * @param array $data
  300. * @return array
  301. */
  302. public function createWebsiteRole(array $data): array
  303. {
  304. $insertData = [
  305. 'website_id' => $data['website_id'],
  306. 'role_id' => $data['role_id'] ?? '',
  307. ];
  308. $info = WebsiteRole::where($insertData)->first();
  309. if ($info) {
  310. return Result::error("不能重复添加角色", 0);
  311. }
  312. $insertData['admin_user_id'] = $data['admin_user_id'] ?? '';
  313. $insertData['type'] = $data['type'] ?? '';
  314. $result = WebsiteRole::insertGetId($insertData);
  315. if (empty($result)) {
  316. return Result::error("创建失败", 0);
  317. } else {
  318. return Result::success(["id" => $result]);
  319. }
  320. }
  321. /**
  322. * 暂时用不上
  323. * @param int $id
  324. * @param array $data
  325. * @return array
  326. */
  327. public function updateWebsiteRole(int $id, array $data): array
  328. {
  329. $insertData = [
  330. 'website_id' => $data['website_id'],
  331. 'type' => $data['type'] ?? '',
  332. ];
  333. $result = WebsiteRole::where('id', $id)->update($insertData);
  334. if (empty($result)) {
  335. return Result::error("更新失败", 0);
  336. } else {
  337. return Result::success();
  338. }
  339. }
  340. /**
  341. * @param int $id
  342. * @return array
  343. */
  344. public function delWebsiteRole(int $id): array
  345. {
  346. $result = WebsiteRole::where('id', $id)->delete();
  347. if (empty($result)) {
  348. return Result::error("删除失败", 0);
  349. } else {
  350. return Result::success();
  351. }
  352. }
  353. /**
  354. * @param string $keyword
  355. * @param int $page
  356. * @param int $pageSize
  357. * @return array
  358. */
  359. public function getWebsiteRoleUserList(string $keyword, int $page, int $pageSize, int $websiteId, int $roleId): array
  360. {
  361. $where = [
  362. ['website_role_user.website_id', '=', $websiteId],
  363. ['website_role_user.role_id', '=', $roleId],
  364. ];
  365. $count = WebsiteRoleUser::where($where)->count();
  366. $where[] = ['u.user_name', 'like', '%' . $keyword . '%'];
  367. $result = WebsiteRoleUser::where($where)
  368. ->leftJoin("user as u", "website_role_user.user_id", "u.id")
  369. ->leftJoin("website as w", "website_role_user.website_id", "u.id")
  370. ->leftJoin("role as r", "website_role_user.role_id", "r.id")
  371. ->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')
  372. ->limit($pageSize)->offset(($page - 1) * $pageSize)->get();
  373. if (empty($result)) {
  374. return Result::error("没有数据", 0);
  375. }
  376. $data = [
  377. 'rows' => $result->toArray(),
  378. 'count' => $count,
  379. ];
  380. return Result::success($data);
  381. }
  382. /**
  383. * @param array $data
  384. * @return array
  385. */
  386. public function createWebsiteRoleUser(array $data): array
  387. {
  388. $insertData = [
  389. 'website_id' => $data['website_id'],
  390. 'user_id' => $data['user_id'] ?? '',
  391. ];
  392. $info = WebsiteRoleUser::where($insertData)->first();
  393. if ($info) {
  394. return Result::error("不能重复添加角色用户", 0);
  395. }
  396. $insertData['role_id'] = $data['role_id'] ?? '';
  397. $insertData['admin_user_id'] = $data['admin_user_id'] ?? '';
  398. $insertData['type'] = $data['type'] ?? '';
  399. $result = WebsiteRoleUser::insertGetId($insertData);
  400. if (empty($result)) {
  401. return Result::error("创建失败", 0);
  402. } else {
  403. return Result::success(["id" => $result]);
  404. }
  405. }
  406. /**
  407. * @param int $id
  408. * @param array $data
  409. * @return array
  410. */
  411. public function updateWebsiteRoleUser(int $id, array $data): array
  412. {
  413. $insertData = [
  414. 'website_id' => $data['website_id'],
  415. 'type' => $data['type'] ?? '',
  416. 'type_id' => $data['type_id'] ?? '',
  417. 'role_id' => $data['role_id'] ?? '',
  418. ];
  419. $result = WebsiteRoleUser::where('id', $id)->update($insertData);
  420. if (empty($result)) {
  421. return Result::error("更新失败", 0);
  422. } else {
  423. return Result::success();
  424. }
  425. }
  426. /**
  427. * @param int $id
  428. * @return array
  429. */
  430. public function delWebsiteRoleUser(int $id): array
  431. {
  432. $result = WebsiteRoleUser::where('id', $id)->delete();
  433. if (empty($result)) {
  434. return Result::error("删除失败", 0);
  435. } else {
  436. return Result::success();
  437. }
  438. }
  439. /**
  440. * 根据域名获取网站 站点id
  441. * @param array $data
  442. * @return array
  443. */
  444. public function getWebsiteId(array $data): array
  445. {
  446. $result = Website::whereJsonContains('website_url', $data['website_url'])->first();
  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 getWebsiteCategory(array $data): array
  459. {
  460. $where = [
  461. 'website_id' => $data['website_id'],
  462. ];
  463. // 使用递归查询构建树状结构
  464. $category = WebsiteCategory::where($where)
  465. ->with([
  466. 'children' => function ($query) {
  467. $query->orderBy('sort', 'asc');
  468. },
  469. ])
  470. ->orderBy('sort', 'asc')
  471. ->where('pid', 0) // 仅查询顶级节点
  472. ->get()->all();
  473. if (empty($category)) {
  474. return Result::error("查询站点栏目失败", 0);
  475. } else {
  476. $count = WebsiteCategory::where($where)->count();
  477. $result = [
  478. 'rep' => $category,
  479. 'count' => $count,
  480. ];
  481. return Result::success($result);
  482. }
  483. }
  484. /**
  485. * 查询网站的广告
  486. * @param array $data
  487. * @return array
  488. */
  489. public function getWebsiteAdvertisement(array $data): array
  490. {
  491. $where = [
  492. 'ad_place.status' => 1,
  493. ];
  494. if (isset($data['ad_tag']) && !empty($data['ad_tag'])) {
  495. $now = Carbon::now()->format('Y-m-d H:i:s'); // 获取当前时间
  496. $where[] = ['ad_place.ad_tag', 'like', '%' . $data['ad_tag'] . '%'];
  497. // return Result::success($where);
  498. $result = AdPlace::where($where)
  499. ->leftJoin("ad", function ($join) use ($now) {
  500. $join->on("ad.pid", "=", "ad_place.id")
  501. ->where('ad.status', 1)
  502. ->where('ad.fromtime', '<=', $now)
  503. ->where('ad.totime', '>=', $now);
  504. })
  505. ->select(
  506. 'ad_place.name as place_name',
  507. 'ad_place.thumb',
  508. 'ad_place.ad_tag',
  509. 'ad_place.introduce',
  510. 'ad.name as ad_name',
  511. 'ad.image_src',
  512. 'ad.image_url',
  513. 'ad.image_alt'
  514. )
  515. ->get()->all();
  516. if (empty($result)) {
  517. return Result::error("此广告位不存在!", 0);
  518. }
  519. } else {
  520. return Result::error("请选择广告位!", 0);
  521. }
  522. return Result::success($result);
  523. }
  524. /**
  525. *
  526. * @param array $data
  527. * @return array
  528. */
  529. /**网站行政职能搜索 */
  530. public function selectWebsiteDepartment(array $data): array
  531. {
  532. $depart = Department::where('pid', 0)->orderBy('id', 'asc')->get();
  533. if (isset($data['keyword']) && !empty($data['keyword'])) {
  534. $departments = Department::where('name', 'like', '%' . $data['keyword'] . '%')->get();
  535. if (empty($departments)) {
  536. $result['message'] = "未查询到与此相关职能部门";
  537. } else {
  538. $count = Department::where('name', 'like', "%{$data['keyword']}%")->count();
  539. $m = [
  540. 'department' => $depart,
  541. 'type' => $departments,
  542. 'count' => $count,
  543. ];
  544. }
  545. $result['sele'] = $m;
  546. return Result::success($result['sele']);
  547. }
  548. $result = $depart;
  549. return Result::success($result);
  550. }
  551. /**
  552. * 搜索地区
  553. * @param array $data
  554. * @return array
  555. */
  556. public function selectWebsiteArea(array $data): array
  557. {
  558. // return Result::success($data);
  559. $pid = $data['pid'] ?? 0;
  560. $result = District::leftJoin('district as district2', 'district.pid', '=', 'district2.id')
  561. ->where('district.pid', $pid)
  562. ->where('district.status', 1)
  563. ->select('district.*', 'district2.name as pid_name')
  564. ->orderBy('district.code')->get();
  565. if (empty($result)) {
  566. return Result::error("未查询到此地区", 0);
  567. } else {
  568. return Result::success($result);
  569. }
  570. }
  571. /**
  572. * 获取栏目
  573. * @param array $data
  574. * @return array
  575. */
  576. public function getWebsiteModelCategory(array $data): array
  577. {
  578. // return Result::success($data);
  579. $website_id = [
  580. 'website_id' => $data['website_id'],
  581. ];
  582. // 初始化 $pid 数组
  583. // $pid = [];
  584. // 以下注释掉的代码是之前的逻辑,用于获取非顶级分类的 pid
  585. $pidQuery = WebsiteCategory::where($website_id)
  586. ->where('pid', '!=', 0)
  587. ->orderBy('sort')
  588. ->select('pid', 'category_id', 'alias');
  589. $pid = $pidQuery->pluck('pid');
  590. $pid = array_values(array_unique($pid->toArray()));
  591. // 构建查询语句
  592. $query = WebsiteCategory::where($website_id)
  593. ->where('pid', $data['pid'])
  594. ->offset($data['placeid'])
  595. ->limit($data['num'])
  596. ->orderBy('sort');
  597. // 如果 $pid 数组不为空,添加 CASE WHEN 条件
  598. if (!empty($pid)) {
  599. $placeholders = implode(',', array_fill(0, count($pid), '?'));
  600. $query->selectRaw("website_category.*, CASE WHEN website_category.category_id IN ($placeholders) THEN 1 ELSE 0 END AS children_count", $pid);
  601. } else {
  602. // 如果 $pid 数组为空,不添加 CASE WHEN 条件,添加字段 children_count 并赋值为 0
  603. $query->select('website_category.*', DB::raw('0 as children_count'));
  604. }
  605. // 执行查询
  606. $placeid = $data['placeid'] - 1;
  607. $result = $query->offset($placeid)->limit($data['num'])->get();
  608. if (!empty($result)) {
  609. $pidResults = $pidQuery->get();
  610. if(isset($data['type']) && $data['type'] == 1){
  611. $result = $result->map(function ($item) use ($pidResults) {
  612. $children = $pidResults->where('pid', $item->category_id)->map(function ($child) {
  613. if(!empty($child)){
  614. return $child;
  615. }
  616. });
  617. // 重置索引,使 key 值从 0 开始
  618. $item->children = $children->values();
  619. return $item;
  620. });
  621. }else{
  622. $pidMap = $pidResults->keyBy('pid');
  623. $result->each(function ($record) use ($pidMap) {
  624. if ($pidMap->has($record->category_id)) {
  625. $pidResult = $pidMap->get($record->category_id);
  626. $record->chilid_id = $pidResult->category_id;
  627. $record->chilid_alias = $pidResult->alias;
  628. }
  629. });
  630. }
  631. return Result::success($result);
  632. } else {
  633. return Result::error("本网站暂无栏目", 0);
  634. }
  635. }
  636. /**
  637. * 获取友情链接
  638. * @param array $data
  639. * @return array
  640. */
  641. public function selectWebsiteLinks(array $data): array
  642. {
  643. $where = [
  644. 'website_id' => $data['website_id'],
  645. 'status' => 1,
  646. 'type' => $data['type'],
  647. ];
  648. $num = $data['num'];
  649. $result = Link::where($where)->orderBy('sort')->limit($num)->get();
  650. if (!empty($result)) {
  651. return Result::success($result);
  652. } else {
  653. return Result::error("本网站暂无此类型友情链接", 0);
  654. }
  655. }
  656. /**
  657. * 网站首页数据统计, 管理员
  658. * @return void
  659. */
  660. public function getAdminIndex(array $data): array
  661. {
  662. var_dump("用户类型:", $data['type_id']);
  663. switch ($data['type_id']) {
  664. case 4:
  665. $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;');
  666. $res = [];
  667. //查询已审核文章
  668. $user_id = $data['user_id'];
  669. $article = Article::where('status', 1)
  670. ->where('admin_user_id', $user_id)
  671. ->orderBy('updated_at', 'desc')
  672. ->limit(10)
  673. ->get();
  674. $res['letterOfComplaintList'] = $result;
  675. $res['article'] = $article;
  676. $res['article']['count'] = Article::whereNotIn('status', ['404'])->where('admin_user_id', $user_id)->count();
  677. $res['good']['count'] = Good::where([])->where('user_id', $user_id)->count();
  678. $res['book']['count'] = Book::where([])->where('user_id', $user_id)->count();
  679. $res['jobHunting']['count'] = JobHunting::where([])->where('user_id', $user_id)->count();
  680. $res['jobRecruiting']['count'] = JobRecruiting::where([])->where('user_id', $user_id)->count();
  681. $res['complaint']['count'] = Complaint::where([])->where('user_id', $user_id)->count();
  682. $res['notice']['count'] = Notice::where([])->where('user_id', $user_id)->count();
  683. //待审核数据
  684. $res['apply']['article'] = Article::where(['status' => 0])->where('admin_user_id', $user_id)->count(); //
  685. $res['apply']['good'] = Good::where(['status' => 1])->where('user_id', $user_id)->count();
  686. $res['apply']['book'] = Book::where(['status' => 1])->where('user_id', $user_id)->count();
  687. $res['apply']['jobHunting'] = JobHunting::where(['status' => 1])->where('user_id', $user_id)->count();
  688. $res['apply']['jobRecruiting'] = JobRecruiting::where(['status' => 0])->where('user_id', $user_id)->count();
  689. $res['apply']['complaint'] = Complaint::where(['status' => 1])->where('user_id', $user_id)->count();
  690. $res['apply']['notice'] = Notice::where(['status' => 1])->where('user_id', $user_id)->count();
  691. return Result::success($res);
  692. case 10000:
  693. $res = [];
  694. //网站
  695. $res['website']['count'] = 0;
  696. $res['website']['growth_rate'] = 0;
  697. //资讯
  698. $res['article']['count'] = 0;
  699. $res['article']['growth_rate'] = 0;
  700. //导航池
  701. $res['category']['count'] = 0;
  702. $res['category']['growth_rate'] = 0;
  703. //商品
  704. $res['good']['count'] = 0;
  705. $res['book']['count'] = 0;
  706. $res['jobHunting']['count'] = 0;
  707. $res['jobRecruiting']['count'] = 0;
  708. //近一月数据
  709. $res['monthArticle'] = [];
  710. //用户类型
  711. $res['userType'] = [];
  712. $res['website']['count'] = Website::where([])->count();
  713. $res['article']['count'] = Article::whereNotIn('status', ['404'])->count();
  714. $res['category']['count'] = Category::where([])->count();
  715. $res['good']['count'] = Good::where([])->count();
  716. $res['book']['count'] = Book::where([])->count();
  717. $res['jobHunting']['count'] = JobHunting::where([])->count();
  718. $res['jobRecruiting']['count'] = JobRecruiting::where([])->count();
  719. $res['complaint']['count'] = Complaint::where([])->count();
  720. $res['notice']['count'] = Notice::where([])->count();
  721. // $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;');
  722. $res['monthArticle'] = Db::select(' SELECT DATE(article.created_at) AS date,COUNT(*) AS count ,user.type_id FROM article left JOIN user on article.admin_user_id = user.id WHERE article.created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(article.created_at),`user`.type_id ORDER BY date ASC');
  723. $res['monthGood'] = Db::select(' SELECT DATE(good.created_at) AS date,COUNT(*) AS count ,user.type_id FROM good left JOIN user on good.user_id = user.id WHERE good.created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(good.created_at),`user`.type_id ORDER BY date ASC');
  724. $res['monthBook'] = Db::select(' SELECT DATE(book.created_at) AS date,COUNT(*) AS count ,user.type_id FROM book left JOIN user on book.user_id = user.id WHERE book.created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(book.created_at),`user`.type_id ORDER BY date ASC');
  725. $res['monthJobHunting'] = Db::select(' SELECT DATE(job_hunting.created_at) AS date,COUNT(*) AS count ,user.type_id FROM job_hunting left JOIN user on job_hunting.user_id = user.id WHERE job_hunting.created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(job_hunting.created_at),`user`.type_id ORDER BY date ASC');
  726. $res['monthJobRecruiting'] = Db::select(' SELECT DATE(job_recruiting.created_at) AS date,COUNT(*) AS count ,user.type_id FROM job_recruiting left JOIN user on job_recruiting.user_id = user.id WHERE job_recruiting.created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(job_recruiting.created_at),`user`.type_id ORDER BY date ASC');
  727. $res['userType'] = User::where([])->selectRaw("count(*) as counts,type_id")->groupBy('type_id')->get();
  728. //待审核数据
  729. $res['apply']['article'] = Article::where(['status' => 0])->count(); //
  730. $res['apply']['good'] = Good::where(['status' => 1])->count();
  731. $res['apply']['book'] = Book::where(['status' => 1])->count();
  732. $res['apply']['jobHunting'] = JobHunting::where(['status' => 1])->count();
  733. $res['apply']['jobRecruiting'] = JobRecruiting::where(['status' => 0])->count();
  734. $res['apply']['complaint'] = Complaint::where(['status' => 1])->count();
  735. $res['apply']['notice'] = Notice::where(['status' => 1])->count(); //订单状态:1:通过;2:驳回;3:撤回;4:修改;5:过期;6:待审核;7:结束',
  736. $res['apply']['order'] = Order::where(['status' => 6])->count();
  737. return Result::success($res);
  738. case 1:
  739. case 2:
  740. case 3:
  741. $res = [];
  742. //查询已审核文章
  743. $user_id = $data['user_id'];
  744. $article = Article::where('status', 1)
  745. ->where('admin_user_id', $user_id)
  746. ->orderBy('updated_at', 'desc')
  747. ->limit(10)
  748. ->get();
  749. $res['article'] = $article;
  750. $res['article']['count'] = Article::whereNotIn('status', ['404'])->where('admin_user_id', $user_id)->count();
  751. $res['good']['count'] = Good::where([])->where('user_id', $user_id)->count();
  752. $res['book']['count'] = Book::where([])->where('user_id', $user_id)->count();
  753. $res['jobHunting']['count'] = JobHunting::where([])->where('user_id', $user_id)->count();
  754. $res['jobRecruiting']['count'] = JobRecruiting::where([])->where('user_id', $user_id)->count();
  755. $res['complaint']['count'] = Complaint::where([])->where('user_id', $user_id)->count();
  756. $res['notice']['count'] = Notice::where([])->where('user_id', $user_id)->count();
  757. //待审核数据
  758. $res['apply']['article'] = Article::where(['status' => 0])->where('admin_user_id', $user_id)->count(); //
  759. $res['apply']['good'] = Good::where(['status' => 1])->where('user_id', $user_id)->count();
  760. $res['apply']['book'] = Book::where(['status' => 1])->where('user_id', $user_id)->count();
  761. $res['apply']['jobHunting'] = JobHunting::where(['status' => 1])->where('user_id', $user_id)->count();
  762. $res['apply']['jobRecruiting'] = JobRecruiting::where(['status' => 0])->where('user_id', $user_id)->count();
  763. $res['apply']['complaint'] = Complaint::where(['status' => 1])->where('user_id', $user_id)->count();
  764. $res['apply']['notice'] = Notice::where(['status' => 1])->where('user_id', $user_id)->count();
  765. return Result::success($res);
  766. }
  767. return [];
  768. }
  769. /**
  770. * 获取模板类型
  771. * @return void
  772. */
  773. public function getTemplateClass(array $data): array
  774. {
  775. $where = [];
  776. if (isset($data['name']) && $data['name']) {
  777. array_push($where, ['name', 'like', '%' . $data['name'] . '%']);
  778. }
  779. $result = TemplateClass::where($where)->orderBy('sort', 'asc')->get();
  780. if (empty($result)) {
  781. return Result::error("没有模板类型", 0);
  782. } else {
  783. return Result::success($result);
  784. }
  785. }
  786. /**
  787. * 添加模板类型
  788. * @param
  789. * @return void
  790. */
  791. public function addTemplateClass(array $data): array
  792. {
  793. $insertData = [
  794. 'name' => $data['name'],
  795. ];
  796. $result = TemplateClass::insertGetId($insertData);
  797. if (empty($result)) {
  798. return Result::error("创建失败", 0);
  799. } else {
  800. return Result::success(["id" => $result]);
  801. }
  802. }
  803. /**
  804. * 更新模板
  805. * @param array $data
  806. * @return array
  807. */
  808. public function upTemplateClass(array $data): array
  809. {
  810. $where = [
  811. 'id' => $data['id'],
  812. ];
  813. $insertData = [
  814. 'name' => $data['name'],
  815. ];
  816. $result = TemplateClass::where($where)->update($insertData);
  817. if (empty($result)) {
  818. return Result::error("更新失败", 0);
  819. } else {
  820. return Result::success();
  821. }
  822. }
  823. /**
  824. * 删除模板
  825. * @param array $data
  826. * @return array
  827. */
  828. public function delTemplateClass(array $data): array
  829. {
  830. $where = [
  831. 'id' => $data['id'],
  832. ];
  833. $result = TemplateClass::where($where)->delete();
  834. if (empty($result)) {
  835. return Result::error("删除失败", 0);
  836. } else {
  837. return Result::success();
  838. }
  839. }
  840. /**
  841. * 获取分类下的模板
  842. * @param array $data
  843. * @return array
  844. */
  845. public function getTemplate(array $data): array
  846. {
  847. $page = $data['page'];
  848. $pageSize = $data['pageSize'];
  849. $where = [];
  850. if (isset($data['template_class_id']) && $data['template_class_id']) {
  851. array_push($where, ['template_class_id', '=', $data['template_class_id']]);
  852. }
  853. $result = Template::where($where)
  854. ->limit($pageSize)->offset(($page - 1) * $pageSize)->get();
  855. $count = Template::where($where)->count();
  856. if (empty($result)) {
  857. return Result::error("没有数据", 0);
  858. }
  859. $data = [
  860. 'rows' => $result->toArray(),
  861. 'count' => $count,
  862. ];
  863. return Result::success($data);
  864. }
  865. /**
  866. * 创建模板
  867. * @param
  868. * @return void
  869. */
  870. public function addTemplate(array $data): array
  871. {
  872. $insertData = [
  873. 'template_name' => $data['template_name'],
  874. 'template_img' => json_encode($data['template_img']),
  875. 'template_class_id' => $data['template_class_id'],
  876. ];
  877. $result = Template::insertGetId($insertData);
  878. if (empty($result)) {
  879. return Result::error("创建模板失败", 0);
  880. } else {
  881. return Result::success(["id" => $result]);
  882. }
  883. }
  884. /**
  885. * 更新模板
  886. * @param array $data
  887. * @return array
  888. */
  889. public function upTemplate(array $data): array
  890. {
  891. $where = [
  892. 'id' => $data['id'],
  893. ];
  894. $insertData = [
  895. 'template_name' => $data['template_name'],
  896. 'template_img' => json_encode($data['template_img']),
  897. 'template_class_id' => $data['template_class_id'],
  898. ];
  899. $result = Template::where($where)->update($insertData);
  900. if (empty($result)) {
  901. return Result::error("更新模板失败", 0);
  902. } else {
  903. return Result::success();
  904. }
  905. }
  906. /**
  907. * 删除模板
  908. * @param array $data
  909. * @return array
  910. */
  911. public function delTemplate(array $data): array
  912. {
  913. $where = [
  914. 'id' => $data['id'],
  915. ];
  916. $result = Template::where($where)->delete();
  917. if (empty($result)) {
  918. return Result::error("删除模板失败", 0);
  919. } else {
  920. return Result::success();
  921. }
  922. }
  923. /**
  924. * 搜索网站
  925. * @param array $data
  926. * @return array
  927. */
  928. public function websiteList(array $data): array
  929. {
  930. $where = [];
  931. if (isset($data['keyword']) && !empty($data['keyword'])) {
  932. array_push($where, ['website.website_name', 'like', '%' . $data['keyword'] . '%']);
  933. }
  934. $result = Website::where($where)->get();
  935. if ($result) {
  936. return Result::success($result);
  937. } else {
  938. return Result::error("没有网站", 0);
  939. }
  940. }
  941. public function addWebsiteCategory(array $data): array
  942. {
  943. $website_id = $data['website_id'];
  944. $category_arr_id = $data['category_arr_id'];
  945. $categoryList = Category::whereIn('id', $category_arr_id)->get();
  946. $categoryListIds = [];
  947. if ($categoryList) {
  948. foreach ($categoryList->toArray() as $val) {
  949. array_push($categoryListIds, $val['id']);
  950. }
  951. }
  952. $arr = [];
  953. if ($categoryListIds) {
  954. foreach ($categoryListIds as $v) {
  955. $ids = $this->getUnderlingUIds(intval($v));
  956. $ids_arr = explode(",", $ids);
  957. array_push($arr, $ids_arr);
  958. }
  959. }
  960. $mergedArray = [];
  961. foreach ($arr as $subarray) {
  962. $mergedArray = array_merge($mergedArray, $subarray);
  963. }
  964. var_dump("所有:", $arr, $mergedArray);
  965. //查询出所有的分类进行分割插入 组装数据
  966. $categoryListData = Category::whereIn('id', $mergedArray)->get();
  967. $categoryListData = $categoryListData->toArray();
  968. $insertData = [];
  969. if ($categoryListData) {
  970. foreach ($categoryListData as $key => $value) {
  971. $insertData[$key]['website_id'] = $website_id;
  972. $insertData[$key]['name'] = $value['name'];
  973. $insertData[$key]['sort'] = $value['sort'];
  974. $insertData[$key]['pid'] = $value['pid'];
  975. $insertData[$key]['pid_arr'] = $value['pid_arr'];
  976. $insertData[$key]['seo_title'] = $value['seo_title'];
  977. $insertData[$key]['seo_keywords'] = $value['seo_keywords'];
  978. $insertData[$key]['seo_description'] = $value['seo_description'];
  979. $insertData[$key]['alias'] = $value['name'];
  980. $insertData[$key]['category_id'] = $value['id'];
  981. }
  982. }
  983. $result = WebsiteCategory::insert($insertData);
  984. var_dump("插入数据状态:", $result);
  985. if ($result) {
  986. return Result::success($result);
  987. } else {
  988. return Result::error("创建失败", 0);
  989. }
  990. }
  991. /**
  992. * 删除网站导航
  993. * @param array $data
  994. * @return array
  995. */
  996. public function delWebsiteCategory(array $data): array
  997. {
  998. $website_id = $data['website_id'] ?? 0;
  999. $category_id = $data['category_id'] ?? 0;
  1000. $ids = $this->getUnderlingUIds(intval($category_id));
  1001. $ids_arr = explode(",", $ids);
  1002. $result = WebsiteCategory::where(['website_id' => $website_id])->whereIn("category_id", $ids_arr)->delete();
  1003. if ($result) {
  1004. return Result::success($result);
  1005. } else {
  1006. return Result::error("删除失败", 0);
  1007. }
  1008. }
  1009. /**
  1010. * 获取网站导航
  1011. * @param array $data
  1012. * @return array
  1013. */
  1014. public function getAdminWebsiteCategory(array $data): array
  1015. {
  1016. $where = [
  1017. 'website_id' => $data['website_id'],
  1018. ];
  1019. $result = WebsiteCategory::where($where)->orderBy('sort', 'asc')->get();
  1020. $list = [];
  1021. if ($result) {
  1022. foreach ($result->toArray() as $val) {
  1023. array_push($list, json_decode($val['category_arr_id']));
  1024. }
  1025. }
  1026. if ($result) {
  1027. return Result::success($list);
  1028. } else {
  1029. return Result::error("查询失败", 0);
  1030. }
  1031. }
  1032. /**
  1033. * 更新网站导航
  1034. * @param array $data
  1035. * @return array
  1036. */
  1037. public function upWebsiteCategory(array $data): array
  1038. {
  1039. $pinyin = new Pinyin();
  1040. Db::beginTransaction();
  1041. try {
  1042. if (!empty($data['category_arr_id'])) {
  1043. $websiteId = $data['website_id'];
  1044. // 1. 获取旧的 category_id 列表
  1045. $oldCategoryListIds = WebsiteCategory::where('website_id', $websiteId)->pluck('category_id')->toArray();
  1046. // 2. 获取新的 category_id 列表(去重)
  1047. $newCategoryListIds = [];
  1048. foreach ($data['category_arr_id'] as $arr) {
  1049. $lastId = end($arr);
  1050. $newCategoryListIds[] = $lastId;
  1051. }
  1052. $newCategoryListIds = array_unique($newCategoryListIds);
  1053. // 3. 需要删除的 category_id
  1054. $toDelete = array_diff($oldCategoryListIds, $newCategoryListIds);
  1055. if (!empty($toDelete)) {
  1056. WebsiteCategory::where('website_id', $websiteId)
  1057. ->whereIn('category_id', $toDelete)
  1058. ->delete();
  1059. }
  1060. // 4. 批量查出所有需要的 category 信息
  1061. $categories = Category::whereIn('id', $newCategoryListIds)->get()->keyBy('id');
  1062. // 5. 组装 upsertData,确保 category_id 不重复
  1063. $upsertData = [];
  1064. $handledCategoryIds = [];
  1065. foreach ($data['category_arr_id'] as $arr) {
  1066. $categoryId = end($arr);
  1067. if (!isset($categories[$categoryId]) || in_array($categoryId, $handledCategoryIds)) continue;
  1068. $info = $categories[$categoryId];
  1069. $aLIas_pinyin = $pinyin->permalink($info->name, '');
  1070. $upsertData[] = [
  1071. 'website_id' => $websiteId,
  1072. 'category_id' => $categoryId,
  1073. 'name' => $info->name ?? '',
  1074. 'alias' => $info->name ?? '',
  1075. 'aLIas_pinyin' => $aLIas_pinyin ?? '',
  1076. 'sort' => $info->sort ?? 0,
  1077. 'pid' => $info->pid ?? 0,
  1078. 'pid_arr' => $info->pid_arr ?? json_encode([]),
  1079. 'seo_title' => $info->seo_title ?? "",
  1080. 'seo_keywords' => $info->seo_keywords ?? "",
  1081. 'seo_description' => $info->seo_description ?? "",
  1082. 'is_url' => $info->is_url ?? 0,
  1083. 'web_url' => $info->web_url ?? '',
  1084. 'type' => $info->type ?? 1,
  1085. 'category_arr_id' => json_encode($arr)
  1086. ];
  1087. $handledCategoryIds[] = $categoryId;
  1088. }
  1089. // 6. upsert
  1090. if (!empty($upsertData)) {
  1091. WebsiteCategory::upsert(
  1092. $upsertData,
  1093. ['website_id', 'category_id'],
  1094. [
  1095. 'aLIas_pinyin',
  1096. 'pid',
  1097. 'pid_arr',
  1098. 'is_url',
  1099. 'web_url',
  1100. 'category_arr_id'
  1101. ]
  1102. );
  1103. }
  1104. }
  1105. Db::commit();
  1106. return Result::success();
  1107. } catch (\Throwable $ex) {
  1108. Db::rollBack();
  1109. return Result::error("修改失败" . $ex->getMessage(), 0);
  1110. }
  1111. }
  1112. /**
  1113. * 获取网站列表
  1114. * @param array $data
  1115. * @return array
  1116. */
  1117. public function getWebsiteCategoryList(array $data): array
  1118. {
  1119. $where = [];
  1120. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1121. array_push($where, ['website.website_name', 'like', '%' . $data['keyword'] . '%']);
  1122. }
  1123. if (isset($data['website_column_id']) && !empty($data['website_column_id'])) {
  1124. array_push($where, ['website.website_column_id', '=', $data['website_column_id']]);
  1125. }
  1126. $result = Website::where($where)
  1127. ->with(["websiteCategory" => function ($query) {
  1128. $query->where(['pid' => 0])->select('website_id', 'name', 'alias', 'category_id');
  1129. }])
  1130. ->limit($data['pageSize'])->orderBy("updated_at", "desc")->offset(($data['page'] - 1) * $data['pageSize'])
  1131. ->get();
  1132. $count = Website::where($where)->count();
  1133. if (empty($result)) {
  1134. return Result::error("没有数据", 0);
  1135. }
  1136. $data = [
  1137. 'rows' => $result->toArray(),
  1138. 'count' => $count,
  1139. ];
  1140. if ($result) {
  1141. return Result::success($data);
  1142. } else {
  1143. return Result::error("查询失败", 0);
  1144. }
  1145. }
  1146. /**
  1147. * 删除网站下的所有导航
  1148. * @param array $data
  1149. * @return array
  1150. */
  1151. public function delWebsiteAllCategory(array $data): array
  1152. {
  1153. $website_id = $data['website_id'];
  1154. $result = WebsiteCategory::where(['website_id' => $website_id])->delete();
  1155. if ($result) {
  1156. return Result::success($result);
  1157. } else {
  1158. return Result::error("删除失败", 0);
  1159. }
  1160. }
  1161. /**
  1162. * 获取网站下的某一个导航
  1163. * @param array $data
  1164. * @return array
  1165. */
  1166. public function getWebsiteCategoryOnes(array $data): array
  1167. {
  1168. $website_id = $data['website_id'];
  1169. $category_id = $data['category_id'];
  1170. $result = WebsiteCategory::where(['website_category.website_id' => $website_id, 'website_category.category_id' => $category_id])
  1171. ->first();
  1172. if ($result) {
  1173. return Result::success($result);
  1174. } else {
  1175. return Result::error("查询失败", 0);
  1176. }
  1177. }
  1178. /**
  1179. * 更新网闸下的某一个导航
  1180. * @param array $data
  1181. * @return array
  1182. */
  1183. public function upWebsiteCategoryones(array $data): array
  1184. {
  1185. //处理所有数据
  1186. //获取所有数据
  1187. if (isset($data['all']) && $data['all'] == 'all') {
  1188. $result = WebsiteCategory::get();
  1189. $result = $result->toArray();
  1190. var_dump($result, '------------');
  1191. $pinyin = new Pinyin();
  1192. $letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  1193. for ($i = 0; $i < count($result); $i++) {
  1194. // $randss = substr(str_shuffle($letters), 0, 4);
  1195. $result[$i]['aLIas_pinyin'] = $pinyin->permalink($result[$i]['alias'], '');
  1196. WebsiteCategory::where(['id' => $result[$i]['id']])->update(['aLIas_pinyin' => $result[$i]['aLIas_pinyin']]);
  1197. }
  1198. var_dump($result, '--------222----');
  1199. if ($result) {
  1200. return Result::success($result);
  1201. } else {
  1202. return Result::error("更新失败", 0);
  1203. }
  1204. }
  1205. //处理所有数据
  1206. $where = [
  1207. 'website_id' => $data['website_id'],
  1208. 'category_id' => $data['category_id'],
  1209. ];
  1210. $alias = $data['alias'];
  1211. $pinyin = new Pinyin();
  1212. $aLIas_pinyin = $pinyin->permalink($alias, '');
  1213. //从WebsiteCategory取出alis ,并转成拼音存放到aLIas_pinyin
  1214. $result = WebsiteCategory::where($where)->first();
  1215. $result = $result->toArray();
  1216. //+四位随机字母
  1217. $letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  1218. // 打乱字符串顺序并截取前四位
  1219. // $randss = substr(str_shuffle($letters), 0, 4);
  1220. if ($data['alias_pinyin'] == '') {
  1221. $data['aLIas_pinyin'] = $aLIas_pinyin;
  1222. }
  1223. $result = WebsiteCategory::where($where)->update($data);
  1224. if ($result) {
  1225. return Result::success($result);
  1226. } else {
  1227. return Result::error("更新失败", 0);
  1228. }
  1229. }
  1230. /**
  1231. * 获取网站下的所有导航(包含子导航)
  1232. * @param array $data
  1233. * @return array
  1234. */
  1235. public function getWebsiteAllCategory(array $data): array
  1236. {
  1237. $where = [];
  1238. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1239. array_push($where, ['website_category.website_id', '=', $data['website_id']]);
  1240. }
  1241. // if (isset($data['name']) && !empty($data['name'])) {
  1242. // array_push($where, ['website_category.name', 'like', '%' . $data['name'] . '%']);
  1243. // }
  1244. // if (isset($data['alias']) && !empty($data['alias'])) {
  1245. // array_push($where, ['website_category.alias', 'like', '%' . $data['alias'] . '%']);
  1246. // }
  1247. // if (isset($data['department_id']) && !empty($data['department_id'])) {
  1248. // array_push($where, ['category.department_id', '=', $data['department_id']]);
  1249. // }
  1250. // if (isset($data['city_id']) && !empty($data['city_id'])) {
  1251. // array_push($where, ['category.city_id', '=', $data['city_id']]);
  1252. // }
  1253. $result = WebsiteCategory::where($where)
  1254. ->leftJoin("category", 'website_category.category_id', 'category.id')
  1255. ->select("website_category.*", "category.name as name")
  1256. // ->leftJoin("category", 'website_category.category_id', 'category.id')
  1257. // ->leftJoin("department", 'category.department_id', 'department.id')
  1258. // ->leftJoin("district", 'category.city_id', 'district.id')
  1259. // ->select("website_category.*", "department.name as department_name", "district.name as city_name")
  1260. // ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])
  1261. ->orderBy("sort", "asc")
  1262. ->get();
  1263. // $count = WebsiteCategory::where($where)
  1264. // ->leftJoin("category", 'website_category.category_id', 'category.id')
  1265. // ->leftJoin("department", 'category.department_id', 'department.id')
  1266. // ->leftJoin("district", 'category.city_id', 'district.id')
  1267. // ->count();
  1268. if (empty($result)) {
  1269. return Result::error("没有数据", 0);
  1270. }
  1271. // $data = [
  1272. // 'rows' => $result->toArray(),
  1273. // 'count' => $count,
  1274. // ];
  1275. if ($result) {
  1276. return Result::success($result->toArray());
  1277. } else {
  1278. return Result::error("查询失败", 0);
  1279. }
  1280. }
  1281. /**
  1282. * 递归查询数据
  1283. * @param $id
  1284. * @param $ids
  1285. * @return string
  1286. */
  1287. public function getUnderlingUIds($id, $ids = '')
  1288. {
  1289. $back = Category::where(['pid' => $id])->get();
  1290. $back = $back->toArray();
  1291. if (!empty($back) && is_array($back)) {
  1292. foreach ($back as $v) {
  1293. //防止当前人的ID重复去查询,形成恶性循环
  1294. if ($v['id'] == $id) {
  1295. continue;
  1296. }
  1297. $back2 = Category::where(['pid' => $id])->count('id');
  1298. if ($back2 > 0) {
  1299. $ids = $this->getUnderlingUIds($v['id'], $ids);
  1300. } else {
  1301. $ids .= ',' . $v['id'];
  1302. }
  1303. }
  1304. }
  1305. $ids = $id . ',' . $ids . ',';
  1306. $ids = str_replace(',,', ",", $ids);
  1307. $ids = trim($ids, ',');
  1308. return $ids;
  1309. }
  1310. /**
  1311. * 检测网站名称是否重复
  1312. * @param array $data
  1313. * @return array
  1314. */
  1315. public function checkWebsiteName(array $data): array
  1316. {
  1317. if (isset($data['id'])) {
  1318. $data[] = ['id', "!=", $data['id']];
  1319. unset($data['id']);
  1320. }
  1321. $websiteInfo = Website::query()->where($data)->first();
  1322. if (empty($websiteInfo)) {
  1323. return Result::error("找不到网站", 0);
  1324. }
  1325. return Result::success($websiteInfo->toArray());
  1326. }
  1327. /**
  1328. * 检测网站url是否重复
  1329. * @param array $data
  1330. * @return array
  1331. */
  1332. public function checkWebsiteUrl(array $data): array
  1333. {
  1334. $whereData = [];
  1335. if (isset($data['id'])) {
  1336. $whereData = [['id', "!=", $data['id']]];
  1337. unset($data['id']);
  1338. }
  1339. $websiteInfo = Website::query()->where($whereData)->whereJsonContains('website_url', $data['website_url'])->first();
  1340. if (empty($websiteInfo)) {
  1341. return Result::error("找不到URL", 0);
  1342. }
  1343. return Result::success($websiteInfo->toArray());
  1344. }
  1345. /**
  1346. * 获取网站底部基础信息
  1347. * @param array $data
  1348. * @return array
  1349. */
  1350. public function getWebsiteFootInfo(array $data): array
  1351. {
  1352. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1353. $website_head = Website::where('id', $data['website_id'])
  1354. ->where('status', 1)
  1355. ->select('id', 'website_name', 'logo', 'title', 'keywords', 'description', 'suffix', 'website_url')
  1356. ->first();
  1357. if (empty($website_head)) {
  1358. return Result::error("找不到网站", 0);
  1359. }
  1360. } else {
  1361. return Result::error("参数错误", 0);
  1362. }
  1363. $website_head = Website::where('id', $data['website_id'])
  1364. ->select('id', 'website_name', 'logo', 'title', 'keywords', 'description', 'suffix', 'website_url')->first();
  1365. $website_foot = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1366. if (empty($website_foot)) {
  1367. return Result::error("暂无底部基础信息", 0);
  1368. }
  1369. $website_head['website_url'] = $website_head['website_url'] ? json_decode($website_head['website_url']) : [];
  1370. $result = [
  1371. 'website_foot' => $website_foot,
  1372. 'website_head' => $website_head,
  1373. ];
  1374. return Result::success($result);
  1375. }
  1376. /**
  1377. * 获取网站底部导航
  1378. * @param array $data
  1379. * @return array
  1380. */
  1381. public function getWebsiteFooterCategory(array $data): array
  1382. {
  1383. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1384. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1385. if (empty($website)) {
  1386. return Result::error("找不到网站", 0);
  1387. }
  1388. } else {
  1389. return Result::error("参数错误", 0);
  1390. }
  1391. $result = FooterCategory::where('website_id', $data['website_id'])->get();
  1392. if (empty($result)) {
  1393. return Result::error("暂无底部导航", 0);
  1394. }
  1395. return Result::success($result->toArray());
  1396. }
  1397. /**
  1398. * 获取网站底部导航列表
  1399. * @param array $data
  1400. * @return array
  1401. */
  1402. public function getWebsiteFooterCategoryList(array $data): array
  1403. {
  1404. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1405. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1406. if (empty($website)) {
  1407. return Result::error("找不到网站", 0);
  1408. }
  1409. } else {
  1410. return Result::error("参数错误", 0);
  1411. }
  1412. $footercategory = FooterCategory::where('website_id', $data['website_id'])->where('id', $data['fcat_id'])->first();
  1413. // '底部导航类型 0:内容型;1:列表型;',
  1414. if (!isset($footercategory['type']) || $footercategory['type'] == 0) {
  1415. return Result::error("底部导航id错误", 0);
  1416. } else {
  1417. $query = FooterContent::where('fcat_id', $data['fcat_id']);
  1418. if ($query->count() == 0) {
  1419. return Result::error("暂无底部导航列表", 0);
  1420. } elseif ($query->count() == 1) {
  1421. $result = $query->first();
  1422. } else {
  1423. $result = $query->get();
  1424. }
  1425. }
  1426. return Result::success($result);
  1427. }
  1428. /**
  1429. * 获取网站底部导航
  1430. * @param array $data
  1431. * @return array
  1432. */
  1433. public function getWebsiteFooterCategoryInfo(array $data): array
  1434. {
  1435. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1436. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1437. if (empty($website)) {
  1438. return Result::error("找不到网站", 0);
  1439. }
  1440. } else {
  1441. return Result::error("参数错误", 0);
  1442. }
  1443. if (isset($data['type']) && $data['type'] == 0) {
  1444. $fcatid = FooterCategory::where('website_id', $data['website_id'])->where('id', $data['fcat_id'])->first();
  1445. if (empty($fcatid)) {
  1446. return Result::error("底部导航id错误", 0);
  1447. }
  1448. $result = FooterContent::where('fcat_id', $data['fcat_id'])->first();
  1449. } else {
  1450. $result = FooterContent::where('id', $data['fcat_id'])->first();
  1451. }
  1452. if (empty($result)) {
  1453. return Result::error("暂无底部导航内容", 0);
  1454. }
  1455. return Result::success($result);
  1456. }
  1457. /*
  1458. * 搜索网站二级导航
  1459. * @param array $data
  1460. * @return array
  1461. * */
  1462. public function selectWebsiteCategory(array $data): array
  1463. {
  1464. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1465. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1466. if (empty($website)) {
  1467. return Result::error("暂无该网站", 0);
  1468. }
  1469. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id')->all();
  1470. // return Result::success($category);
  1471. if (empty($category)) {
  1472. return Result::error("暂无此导航", 0);
  1473. }
  1474. $query = Category::whereIn('id', $category);
  1475. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1476. $cityid = District::where('id', $data['cityid'])->first();
  1477. if (empty($cityid)) {
  1478. return Result::error("暂无此城市", 0);
  1479. } else {
  1480. $city_category = $query->whereRaw('JSON_CONTAINS(city_arr_id,?)', [$data['cityid']])->pluck('id');
  1481. // $where[] = ['JSON_CONTAINS(city_arr_id, ?)', $data['cityid']];
  1482. if (empty($city_category)) {
  1483. return Result::error("暂无此城市下的导航", 0);
  1484. }
  1485. $result['catid'] = $city_category;
  1486. $city = 1;
  1487. // var_dump("城市====================",$result);
  1488. }
  1489. }
  1490. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1491. $departmentid = Department::where('id', $data['department_id'])->first();
  1492. if (empty($departmentid)) {
  1493. return Result::error("暂无此部门", 0);
  1494. } else {
  1495. $depart_category = $query->whereRaw('JSON_CONTAINS(department_arr_id,?)', [$data['department_id']])->pluck('id');
  1496. if (empty($depart_category)) {
  1497. return Result::error("暂无此部门下的导航", 0);
  1498. }
  1499. $result['catid'] = $depart_category;
  1500. // var_dump("职能部门*******************",$result);
  1501. $department = 1;
  1502. }
  1503. }
  1504. if (!empty($city) && !empty($department)) {
  1505. // var_dump("城市和职能部门----------------------",$result);
  1506. $sel_category = $query->whereRaw('JSON_CONTAINS(city_arr_id,?)', [$data['cityid']])->whereRaw('JSON_CONTAINS(department_arr_id,?)', [$data['department_id']])->pluck('id');
  1507. if (empty($sel_category)) {
  1508. return Result::error("暂无此城市和职能部门下的导航", 0);
  1509. }
  1510. $result['catid'] = $sel_category;
  1511. }
  1512. if (empty($result)) {
  1513. return Result::error("暂无导航", 0);
  1514. }
  1515. // department_id
  1516. } else {
  1517. return Result::error("参数错误", 0);
  1518. }
  1519. return Result::success($result);
  1520. }
  1521. /**
  1522. * 获取网站栏目seo
  1523. * @param array $data
  1524. * @return array
  1525. */
  1526. public function getWebsiteCategoryHead(array $data): array
  1527. {
  1528. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1529. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1530. if (empty($website)) {
  1531. return Result::error("找不到网站", 0);
  1532. }
  1533. } else {
  1534. return Result::error("参数错误", 0);
  1535. }
  1536. if (isset($data['catid']) && !empty($data['catid'])) {
  1537. $result = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->first();
  1538. }
  1539. if (empty($result)) {
  1540. return Result::error("暂无导航", 0);
  1541. }
  1542. $result['website_name'] = $website['website_name'] ?? '';
  1543. $result['suffix'] = $website['suffix'] ?? '';
  1544. return Result::success($result);
  1545. }
  1546. /*
  1547. * 获取某个栏目
  1548. * @param array $data
  1549. * @return array
  1550. * */
  1551. public function getOneWebsiteCategory(array $data): array
  1552. {
  1553. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1554. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1555. if (empty($website)) {
  1556. return Result::error("暂无该网站", 0);
  1557. }
  1558. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['category_id'])->first();
  1559. if (empty($category)) {
  1560. return Result::error("暂无此导航", 0);
  1561. }
  1562. $category['children_count'] = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['category_id'])->count();
  1563. $parent = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->select('category_id as parent_id', 'alias as parent_name', 'aLIas_pinyin')->first();
  1564. $category['parent_id'] = $parent['parent_id'] ?? '';
  1565. $category['parent_pinyin'] = $parent['aLIas_pinyin'] ?? '';
  1566. $category['parent_name'] = $parent['parent_name'] ?? '';
  1567. return Result::success($category);
  1568. } else {
  1569. return Result::error("参数错误", 0);
  1570. }
  1571. }
  1572. // 自助建站--fr-------------------
  1573. /**
  1574. * 获取并搜索 网站模板信息
  1575. * @param array $data
  1576. * @return array
  1577. */
  1578. public function getWebsiteintel(array $data): array
  1579. {
  1580. //查询所有网站模板信息
  1581. $query = Website::where('website.status', 1)
  1582. ->leftJoin("website_template_info", "website_template_info.website_id", "website.id")
  1583. ->leftJoin("template", "template.id", "website_template_info.template_id")
  1584. ->leftJoin("template_class", "template_class.id", "template.template_class_id")
  1585. ->select(
  1586. "website_template_info.id",
  1587. "template_class.name",
  1588. "website.id as website_id",
  1589. "website.website_name",
  1590. "website.website_url",
  1591. "website_template_info.action_id",
  1592. "website_template_info.created_at",
  1593. "website_template_info.updated_at",
  1594. "website_template_info.page_type",
  1595. DB::raw("COALESCE(website_template_info.status, 0) as template_status"),
  1596. "template.template_name"
  1597. );
  1598. //若存在条件;则在$query的基础上进行筛选
  1599. if (isset($data['website_name']) && !empty($data['website_name'])) {
  1600. $query->where('website.website_name', 'like', '%' . $data['website_name'] . '%');
  1601. }
  1602. if (isset($data['status']) && !empty($data['status'])) {
  1603. $query->where('website_template_info.status', $data['status']);
  1604. }
  1605. $count = $query->count();
  1606. $query->limit($data['pageSize'])
  1607. ->offset(($data['page'] - 1) * $data['pageSize'])
  1608. ->orderBy("website_template_info.updated_at", "desc");
  1609. $rep = $query->get();
  1610. if ($rep->count() == 0) {
  1611. return Result::error("没有查找到相关数据", 0);
  1612. } else {
  1613. $rep->each(function ($item) {
  1614. if (!empty($item->page_type)) {
  1615. $pageTypeArray = json_decode($item->page_type, true);
  1616. if (is_array($pageTypeArray)) {
  1617. $item->page_type = $pageTypeArray;
  1618. }
  1619. }
  1620. });
  1621. $result = [
  1622. "rows" => $rep->toArray(),
  1623. "count" => $count,
  1624. ];
  1625. return Result::success($result);
  1626. }
  1627. // return Result::success($result);
  1628. }
  1629. /**
  1630. * 添加网站基础信息
  1631. * @param array $data
  1632. * @return array
  1633. */
  1634. public function addWebsiteTemplateintel(array $data): array
  1635. {
  1636. $website = Website::where('website.id', $data['website_id'])->first();
  1637. if (empty($website)) {
  1638. return Result::error("请输入正确的网站id!", 0);
  1639. }
  1640. if (empty($website['website_column_id'])) {
  1641. return Result::error("请先关联导航池!", 0);
  1642. }
  1643. // 获取此网站的底部导航 类型 type: 0:内容型底部导航(只有一条详情内容);1:列表型底部导航(可以有多条详情内容)
  1644. $foot_type = FooterCategory::where('website_id', $data['website_id'])->pluck('type')->toArray();
  1645. if (empty($foot_type)) {
  1646. return Result::error("请先关联底部导航池!", 0);
  1647. } elseif (in_array(1, $foot_type)) {
  1648. $foot_type = 1;
  1649. } else {
  1650. $foot_type = 0;
  1651. }
  1652. $result['foot_type'] = $foot_type;
  1653. // 友情链接类型'1:图片 2:文字 3:底部';
  1654. $types = Link::where('website_id', $data['website_id'])->pluck('type')->toArray();
  1655. $missingTypes = [];
  1656. if (!in_array(1, $types)) {
  1657. $missingTypes[] = "文字链接";
  1658. }
  1659. if (!in_array(2, $types)) {
  1660. $missingTypes[] = "图片链接";
  1661. }
  1662. if (!in_array(3, $types)) {
  1663. $missingTypes[] = "底部链接";
  1664. }
  1665. if (!empty($missingTypes)) {
  1666. $errorMessage = "请先添加 " . implode(" 和 ", $missingTypes) . "!";
  1667. return Result::error($errorMessage, 0);
  1668. }
  1669. if (isset($data['page_type'])) {
  1670. // 删除重复元素并重新索引数组
  1671. $data['page_type'] = array_unique($data['page_type']);
  1672. $data['page_type'] = array_values($data['page_type']);
  1673. if (in_array(1, $data['page_type']) && in_array(7, $data['page_type'])) {
  1674. // 数组中同时包含值为 1(首页) 和值为 7 (底部导航详情页)的元素
  1675. $info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1676. if (empty($info)) {
  1677. // 将数组转换为 JSON 字符串
  1678. $data['page_type'] = json_encode($data['page_type']) ?? '';
  1679. // 操作状态:1:填写完成基础信息;2:选择完成模板;0:未构建
  1680. $data['action_id'] = 1;
  1681. try {
  1682. $result = WebsiteTemplateInfo::insertGetId($data);
  1683. } catch (\Exception $e) {
  1684. if ($e->getCode() == 22001) {
  1685. $errorMessage = $e->getMessage();
  1686. return Result::error("请检查表单,某个字段超出了长度限制!");
  1687. } else {
  1688. // 处理其他类型的数据库错误
  1689. return Result::error("插入操作失败: " . $e->getMessage());
  1690. }
  1691. return Result::error("添加失败!", 0);
  1692. }
  1693. } else {
  1694. return Result::error("该网站已经构建过了!", 0);
  1695. }
  1696. } else {
  1697. return Result::error("请先选择首页和底部导航详情页!", 0);
  1698. }
  1699. }
  1700. if (empty($result)) {
  1701. return Result::error("添加失败!", 0);
  1702. } else {
  1703. return Result::success($result);
  1704. }
  1705. }
  1706. /**
  1707. * 获取网站基础信息
  1708. *
  1709. * @return array
  1710. */
  1711. public function getWebsiteTemplateintel(array $data): array
  1712. {
  1713. $result = WebsiteTemplateInfo::where('website_template_info.website_id', $data['website_id'])
  1714. ->leftJoin('footer_category', 'footer_category.website_id', 'website_template_info.website_id')
  1715. ->leftJoin('website', 'website.id', 'website_template_info.website_id')
  1716. ->select(
  1717. "website_template_info.*",
  1718. "footer_category.type",
  1719. "website.website_name",
  1720. "website.id as website_id"
  1721. )
  1722. ->first();
  1723. if (empty($result['website_name'])) {
  1724. return Result::error("请输入正确的网站id!", 0);
  1725. }
  1726. if ($result) {
  1727. $result['page_type'] = json_decode($result['page_type'], true);
  1728. return Result::success($result);
  1729. } else {
  1730. return Result::error("请先添加网站基础信息!", 0);
  1731. }
  1732. }
  1733. /**
  1734. * 修改网站基础信息
  1735. *
  1736. * @return array
  1737. */
  1738. public function upWebsiteTemplateintel(array $data): array
  1739. {
  1740. $web = Website::where('website.id', $data['website_id'])->first();
  1741. if (empty($web)) {
  1742. return Result::error("请输入正确的网站id!", 0);
  1743. }
  1744. $where = ['website_id' => $data['website_id']];
  1745. $result = WebsiteTemplateInfo::where($where)->first();
  1746. if (empty($result)) {
  1747. return Result::error("请先添加网站基础信息!", 0);
  1748. } else {
  1749. unset($data['website_id']);
  1750. // 删除重复元素
  1751. $data['page_type'] = array_unique($data['page_type']);
  1752. // 重新索引数组
  1753. $data['page_type'] = array_values($data['page_type']);
  1754. // 数组中同时包含值为 1(首页) 和值为 7 (底部导航详情页)的元素
  1755. if (in_array(1, $data['page_type']) && in_array(7, $data['page_type'])) {
  1756. // 将数组转换为 JSON 字符串
  1757. $data['page_type'] = json_encode($data['page_type']) ?? '';
  1758. try {
  1759. $result = WebsiteTemplateInfo::where($where)->update($data);
  1760. } catch (\Exception $e) {
  1761. if ($e->getCode() == 22001) {
  1762. $errorMessage = $e->getMessage();
  1763. return Result::error("请检查表单,某个字段超出了长度限制!");
  1764. } else {
  1765. // 处理其他类型的数据库错误
  1766. return Result::error("修改操作失败: " . $e->getMessage());
  1767. }
  1768. return Result::error("修改失败!", 0);
  1769. }
  1770. } else {
  1771. return Result::error("请先选择首页和底部导航详情页!", 0);
  1772. }
  1773. }
  1774. if (empty($result)) {
  1775. return Result::error("修改失败!", 0);
  1776. } else {
  1777. return Result::success($result);
  1778. }
  1779. }
  1780. /**
  1781. * 获取所有网站风格信息
  1782. *
  1783. * @return array
  1784. */
  1785. public function getAllTemplateClass(array $data): array
  1786. {
  1787. $result = TemplateClass::all();
  1788. if (empty($result)) {
  1789. return Result::error("没有查找到相关数据!", 0);
  1790. } else {
  1791. return Result::success($result);
  1792. }
  1793. }
  1794. /**
  1795. * 搜索并获取网站模板信息
  1796. * @param array $data
  1797. * @return array
  1798. */
  1799. public function getWebsiteTemplateList(array $data): array
  1800. {
  1801. $website = Website::where('website.id', $data['website_id'])->first();
  1802. if (empty($website)) {
  1803. return Result::error("请输入正确的网站id!", 0);
  1804. } else {
  1805. $page_type = WebsiteTemplateInfo::where('website_id', $data['website_id'])->select('page_type')->first();
  1806. if (empty($page_type)) {
  1807. return Result::error("此网站还未添加基础信息!", 0);
  1808. } else {
  1809. $where = json_decode($page_type['page_type'], true);
  1810. // $where = $data["page_type"];
  1811. if (isset($data['template_class_id']) && !empty($data['template_class_id'])) {
  1812. $template_class = TemplateClass::where('id', $data['template_class_id'])->first();
  1813. if (empty($template_class)) {
  1814. return Result::error("请输入正确的模板风格id!", 0);
  1815. } else {
  1816. // 获取指定风格下的模板
  1817. $rep = Template::where('template_class_id', $data['template_class_id'])
  1818. ->where(function ($query) use ($where) {
  1819. foreach ($where as $value) {
  1820. $query->whereJsonContains('template_img', ['value' => $value]);
  1821. }
  1822. })
  1823. ->limit($data['pageSize'])
  1824. ->offset(($data['page'] - 1) * $data['pageSize'])
  1825. ->orderBy("template.updated_at", "desc")
  1826. ->get();
  1827. $count = Template::where('template_class_id', $data['template_class_id'])
  1828. ->where(function ($query) use ($where) {
  1829. foreach ($where as $value) {
  1830. $query->whereJsonContains('template_img', ['value' => $value]);
  1831. }
  1832. })->count();
  1833. }
  1834. } else {
  1835. //获取所有模板
  1836. $rep = Template::where(function ($query) use ($where) {
  1837. foreach ($where as $value) {
  1838. $query->whereJsonContains('template_img', ['value' => $value]);
  1839. }
  1840. })
  1841. ->limit($data['pageSize'])
  1842. ->offset(($data['page'] - 1) * $data['pageSize'])
  1843. ->orderBy("template.updated_at", "desc")
  1844. ->get();
  1845. $count = Template::where(function ($query) use ($where) {
  1846. foreach ($where as $value) {
  1847. $query->whereJsonContains('template_img', ['value' => $value]);
  1848. }
  1849. })->count();
  1850. }
  1851. if (empty($rep) || $rep->count() == 0) {
  1852. return Result::error("没有查找到相关数据!", 0);
  1853. } else {
  1854. // 过滤 template_img 字段 只获取 基础信息中 包含的模板图片
  1855. // $rep->each(function ($item) use ($where) {
  1856. // $template_img = json_decode($item->template_img, true);
  1857. // if(is_array($template_img)){
  1858. // $filtered_img = array_filter($template_img, function ($img) use ($where) {
  1859. // return isset($img['value']) && in_array($img['value'], $where);
  1860. // });
  1861. // }
  1862. // $item->template_img = $filtered_img;
  1863. // });
  1864. // $result = [
  1865. // "rows" => $rep->toArray(),
  1866. // "count" => $count
  1867. // ];
  1868. $rep->each(function ($item) use ($where) {
  1869. $template_img = json_decode($item->template_img, true);
  1870. if (is_array($template_img)) {
  1871. $filtered_img = array_filter($template_img, function ($img) use ($where) {
  1872. return isset($img['value']) && in_array($img['value'], $where);
  1873. });
  1874. // 对过滤后的数组进行重新排序
  1875. $sorted_img = array_values($filtered_img);
  1876. $item->template_img = $sorted_img;
  1877. } else {
  1878. $item->template_img = []; // 如果无法解码为数组,则设置为空数组
  1879. }
  1880. });
  1881. $result = [
  1882. "rows" => $rep->toArray(),
  1883. "count" => $count,
  1884. ];
  1885. }
  1886. }
  1887. }
  1888. return Result::success($result);
  1889. }
  1890. /**
  1891. * 添加网站模板
  1892. * @param array $data
  1893. */
  1894. public function addWebsiteTemplateclassintel(array $data): array
  1895. {
  1896. $template = Template::where('id', $data['template_id'])->first();
  1897. $web = Website::where('id', $data['website_id'])->first();
  1898. if (empty($template)) {
  1899. return Result::error("请输入正确的模板id", 0);
  1900. }
  1901. if (empty($web)) {
  1902. return Result::error("请输入正确的网站id", 0);
  1903. }
  1904. $result = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['template_id' => $data['template_id'], 'action_id' => 2]);
  1905. if (empty($result)) {
  1906. return Result::error("添加失败", 0);
  1907. } else {
  1908. return Result::success($result);
  1909. }
  1910. }
  1911. /**
  1912. * 获取网站模板信息
  1913. * @param array $data
  1914. */
  1915. public function getWebsiteTemplateclassintel(array $data): array
  1916. {
  1917. // return Result::success($data);
  1918. $template = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1919. if (empty($template)) {
  1920. return Result::error("请输入正确的搭建网站id", 0);
  1921. }
  1922. $page_type = json_decode($template['page_type'], true);
  1923. // 获取指定网站下的基础信息和模板及风格信息
  1924. $result = WebsiteTemplateInfo::where([
  1925. ['website_template_info.website_id', $data['website_id']],
  1926. ['template_id', '!=', null],
  1927. ])
  1928. ->leftJoin('template', 'template.id', 'website_template_info.template_id')
  1929. ->leftJoin('template_class', 'template_class.id', 'template.template_class_id')
  1930. ->where(function ($query) use ($page_type) {
  1931. // 假设 $data['page_type'] 是一个数组,包含需要匹配的 page_type 值
  1932. foreach ($page_type as $pageType) {
  1933. $query->orWhereJsonContains('template.template_img', ['value' => $pageType]);
  1934. }
  1935. })
  1936. ->select(
  1937. 'template.template_name',
  1938. 'template.template_img',
  1939. 'template.id as tid',
  1940. 'template_class.name',
  1941. 'template_class.id as class_id',
  1942. 'website_template_info.page_type',
  1943. 'website_template_info.website_id'
  1944. )
  1945. ->first();
  1946. if (empty($result)) {
  1947. return Result::error("没有查找到相关数据", 0);
  1948. }
  1949. // return Result::success($result);
  1950. // 过滤 template_img 字段 只获取 基础信息中 包含的模板图片
  1951. $template_img = $result['template_img'] !== null ? json_decode($result['template_img'], true) : [];
  1952. $page_type = $result['page_type'] !== null ? json_decode($result['page_type'], true) : [];
  1953. foreach ($template_img as $key => $value) {
  1954. if (!in_array($value['value'], $page_type)) {
  1955. unset($template_img[$key]);
  1956. }
  1957. }
  1958. // return Result::success($result);
  1959. $result['template_img'] = array_values($template_img);
  1960. $result['page_type'] = $page_type;
  1961. // $templateList = $this->getWebsiteTemplateList($data);
  1962. // $count = $templateList['data']['count']??'';
  1963. // $pages = $count / $data['pageSize'];
  1964. // $found = false;
  1965. // while ($pages && !$found) {
  1966. // $templates = $this->getWebsiteTemplateList($pages,$data['pageSize']);
  1967. // $index = array_search($template['template_id'], array_column($templates['rows'], 'id'));
  1968. // if ($index !== false) {
  1969. // $found = true;
  1970. // $result['page'] = $pages;
  1971. // $pages = 0;
  1972. // // echo "查询到的 template 在第 $page 页";
  1973. // }
  1974. // $pages--;
  1975. // }
  1976. return Result::success($result);
  1977. }
  1978. /**
  1979. * 获取网站模板下的板块信息
  1980. * @param array $data
  1981. */
  1982. public function getWebsiteSectorList(array $data): array
  1983. {
  1984. $website = Website::where('id', $data['website_id'])->first();
  1985. if (empty($website)) {
  1986. return Result::error("请输入正确的网站id", 0);
  1987. }
  1988. $template = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1989. if (empty($template['template_id'])) {
  1990. return Result::error("请先添加网站模板", 0);
  1991. }
  1992. $query = Sector::where('template_id', $template['template_id']);
  1993. if ($query->count() == 0) {
  1994. return Result::error("没有查找到相关板块数据", 0);
  1995. } elseif ($query->count() == 1) {
  1996. $sector = $query->first();
  1997. } else {
  1998. $sector = $query->get();
  1999. }
  2000. $result['page_type'] = $template['page_type'];
  2001. $result['tid'] = $template['template_id'];
  2002. $result = [
  2003. "tid" => $template['template_id'],
  2004. "page_type" => $template['page_type'],
  2005. "sector" => $sector,
  2006. ];
  2007. return Result::success($result);
  2008. }
  2009. // 自助建站---------------fr---------------
  2010. // 网站底基础信息--fr-------------------
  2011. /**
  2012. * 添加网站底基础信息
  2013. * @param array $data
  2014. */
  2015. public function addWebFootInfo(array $data): array
  2016. {
  2017. $website = Website::where('id', $data['website_id'])->first();
  2018. if (empty($website)) {
  2019. return Result::error("请输入正确的网站id!", 0);
  2020. }
  2021. $info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  2022. if (!empty($info)) {
  2023. return Result::error("该网站已经添加过了!", 0);
  2024. }
  2025. $result = WebsiteTemplateInfo::where('website_id', $data['website_id'])->insertGetId($data);
  2026. if (empty($result)) {
  2027. return Result::error("请先添加网站基础信息!", 0);
  2028. } else {
  2029. return Result::success($result);
  2030. }
  2031. }
  2032. /**
  2033. * 获取网站底基础信息
  2034. * @param array $data
  2035. */
  2036. public function getWebFootInfo(array $data): array
  2037. {
  2038. $website = Website::where('id', $data['website_id'])->first();
  2039. if (empty($website)) {
  2040. return Result::error("请输入正确的网站id!", 0);
  2041. }
  2042. $result = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  2043. if (empty($result)) {
  2044. return Result::error("请先添加网站基础信息!", 0);
  2045. }
  2046. return Result::success($result);
  2047. }
  2048. /**
  2049. * 修改网站底基础信息
  2050. * @param array $data
  2051. */
  2052. public function upWebFootInfo(array $data): array
  2053. {
  2054. // return Result::success($data);
  2055. $website = Website::where('id', $data['website_id'])->first();
  2056. if (empty($website)) {
  2057. return Result::error("请输入正确的网站id!", 0);
  2058. }
  2059. $web = $data['website_id'];
  2060. unset($data['website_id']);
  2061. $where = ['website_id' => $web];
  2062. // return Result::success($data);
  2063. $result = WebsiteTemplateInfo::where($where)->first();
  2064. if (empty($result)) {
  2065. $data['website_id'] = $web;
  2066. $result = WebsiteTemplateInfo::insertGetId($data);
  2067. // return Result::error("请先添加网站基础信息!",0);
  2068. } else {
  2069. $result = WebsiteTemplateInfo::where($where)->update($data);
  2070. }
  2071. // $where = ['website_id'=>$data['website_id']];
  2072. // unset($data['website_id']);
  2073. // $result = WebsiteTemplateInfo::updateOrInsert($where, $data);
  2074. if (empty($result)) {
  2075. return Result::error("修改失败!", 0);
  2076. }
  2077. return Result::success($result);
  2078. }
  2079. /*
  2080. * 获取父级/子级栏目------路由
  2081. * @param array $data
  2082. * @return array
  2083. * */
  2084. public function getWebsiteParentCategory(array $data): array
  2085. {
  2086. // return Result::success($data);
  2087. if (isset($data['website_id']) && !empty($data['website_id'])) {
  2088. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  2089. }
  2090. if (empty($website)) {
  2091. return Result::error("暂无该网站", 0);
  2092. }
  2093. // 在 Hyperf 中,查询构建器(Builder)没有 `map` 方法,`map` 方法是集合(Collection)的方法。
  2094. // 因此,需要先调用 `get()` 方法获取查询结果集合,再使用 `map` 方法进行处理。
  2095. $category['parent'] = WebsiteCategory::where('website_id', $data['website_id'])
  2096. ->where('pid', 0)
  2097. ->selectRaw("category_id as cid, alias as name, CONCAT('/', '', aLIas_pinyin, '/') as path")
  2098. ->get() // 添加 get() 方法获取结果集合
  2099. ->all();
  2100. // 提前查询所有父级栏目,避免在 map 中多次查询
  2101. // 提前查询所有父级栏目信息并以 category_id 作为键存储
  2102. $parentCategories = WebsiteCategory::where('website_id', $data['website_id'])
  2103. ->where('pid', 0)
  2104. ->select('category_id', 'aLIas_pinyin')
  2105. ->get()
  2106. ->keyBy('category_id');
  2107. // 直接查询子栏目信息
  2108. $child = WebsiteCategory::where('website_id', $data['website_id'])
  2109. ->where('pid', '!=', 0)
  2110. ->select('alias', 'category_id', 'aLIas_pinyin', 'pid')
  2111. ->get();
  2112. // 使用集合的 map 方法处理子栏目信息
  2113. $category['child'] = $child->map(function ($item) use ($parentCategories) {
  2114. $alias = $item->alias;
  2115. $category_id = $item->category_id;
  2116. $aLIas_pinyin = $item->aLIas_pinyin;
  2117. $parent = $parentCategories->get($item->pid);
  2118. $parentAlias = $parent ? $parent->aLIas_pinyin : '';
  2119. $result = [
  2120. 'name' => $alias,
  2121. 'cid' => $category_id
  2122. ];
  2123. if (!empty($aLIas_pinyin) && !empty($parentAlias)) {
  2124. $result['path'] = "/{$parentAlias}/{$aLIas_pinyin}/";
  2125. }
  2126. return $result;
  2127. })->values()->all();
  2128. if (empty($category)) {
  2129. return Result::error("暂无此导航", 0);
  2130. }
  2131. return Result::success($category);
  2132. }
  2133. /**
  2134. * 获取网站栏目信息
  2135. * @param array $data
  2136. */
  2137. public function getWebsiteFootAll(array $data): array
  2138. {
  2139. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  2140. if (empty($website)) {
  2141. return Result::error("暂无该网站", 0);
  2142. }
  2143. // 1:图片 2:文字 3:底部
  2144. $result['foot_cate'] = FooterCategory::where('website_id', $data['website_id'])->get()->all();
  2145. $result['link_img'] = Link::where('website_id', $data['website_id'])->where('type', 1)->where('status', 1)->limit($data['link_imgnum'])->orderBy('sort')->get()->all();
  2146. $result['link_text'] = Link::where('website_id', $data['website_id'])->where('type', 2)->where('status', 1)->limit($data['link_textnum'])->orderBy('sort')->get()->all();
  2147. $result['link_foot'] = Link::where('website_id', $data['website_id'])->where('type', 3)->where('status', 1)->limit($data['link_footnum'])->orderBy('sort')->get()->all();
  2148. $result['foot_info'] = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  2149. if (empty($result)) {
  2150. return Result::error("暂无此网站信息", 0);
  2151. }
  2152. return Result::success($result);
  2153. }
  2154. /**
  2155. * 获取网站顶部信息
  2156. * @param array $data
  2157. */
  2158. public function getWebsiteHead(array $data): array
  2159. {
  2160. $result = Website::where('id', $data['website_id'])->where('status', 1)->select('website_name', 'logo')->first();
  2161. if (empty($result)) {
  2162. return Result::error("暂无该网站", 0);
  2163. }
  2164. return Result::success($result);
  2165. }
  2166. /**
  2167. * 路由匹配
  2168. * @param array $data
  2169. */
  2170. public function getWebsiteRoute(array $data): array
  2171. {
  2172. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  2173. if (empty($website)) {
  2174. return Result::error("暂无该网站", 0);
  2175. }
  2176. if (isset($data['pinyin']) &&!empty($data['pinyin'])) {
  2177. $result = WebsiteCategory::where('website_category.website_id', $data['website_id'])
  2178. ->where('website_category.aLIas_pinyin', $data['pinyin'])
  2179. ->leftJoin('website_category as pc', function ($join) use ($data) {
  2180. $join->on('pc.pid', '=', 'website_category.category_id')
  2181. ->where('pc.website_id', '=', $data['website_id']);
  2182. })
  2183. ->select('website_category.category_id', 'website_category.aLIas_pinyin', DB::raw('CASE WHEN pc.category_id IS NOT NULL THEN 1 ELSE 0 END as children_count'))
  2184. ->first();
  2185. }
  2186. if(isset($data['foot_pinyin']) &&!empty($data['foot_pinyin'])){
  2187. $result = FooterCategory::where('website_id',$data['website_id'])->where('name_pinyin',$data['foot_pinyin'])->first(['id']);
  2188. }
  2189. if (!isset($result) || empty($result)) {
  2190. return Result::error("暂无该导航", 0);
  2191. }
  2192. return Result::success($result);
  2193. }
  2194. //20250212 网站标识
  2195. public function addWebsiteGroup(array $data): array
  2196. {
  2197. //判斷name是不是重复
  2198. $websiteGroupInfo = WebsiteGroup::query()->where('name', $data['name'])->first();
  2199. if (!empty($websiteGroupInfo)) {
  2200. return Result::error("网站标识重复", 0);
  2201. }
  2202. //添加信息
  2203. $result = WebsiteGroup::insertGetId($data);
  2204. var_dump($result);
  2205. if (empty($result)) {
  2206. return Result::error("创建失败", 0);
  2207. } else {
  2208. return Result::success($result);
  2209. }
  2210. }
  2211. public function getWebsiteGroupList(array $data): array
  2212. {
  2213. $where = [];
  2214. if (isset($data['name']) && !empty($data['name'])) {
  2215. array_push($where, ['website_group.name', 'like', '%' . $data['name'] . '%']);
  2216. }
  2217. $result = WebsiteGroup::where($where)
  2218. ->limit($data['pageSize'])->orderBy("id", "desc")->offset(($data['page'] - 1) * $data['pageSize'])
  2219. ->get();
  2220. foreach ($result as $websiteGroup) {
  2221. $webIds = json_decode($websiteGroup->web_ids, true);
  2222. $websites = Website::whereIn('id', $webIds)->get();
  2223. $websiteNames = $websites->pluck('website_name', 'id')->toArray();
  2224. $websiteGroup->website_names = $websiteNames;
  2225. $websiteGroup->website_names1 = implode(',', array_values($websiteNames));
  2226. }
  2227. $count = WebsiteGroup::where($where)->count();
  2228. if (empty($result)) {
  2229. return Result::error("没有数据", 0);
  2230. }
  2231. return Result::success(['list' => $result->toArray(), 'count' => $count]);
  2232. }
  2233. public function getWebsiteGroupInfo(array $data): array
  2234. {
  2235. $websiteInfo = WebsiteGroup::query()->where('id', $data['id'])->first();
  2236. $webIds = json_decode($websiteInfo->web_ids, true);
  2237. $websites = Website::whereIn('id', $webIds)->get();
  2238. $websiteNames = $websites->pluck('website_name', 'id')->toArray();
  2239. $websiteInfo->website_names = $websiteNames;
  2240. $websiteInfo->website_names1 = implode(',', array_values($websiteNames));
  2241. if (empty($websiteInfo)) {
  2242. return Result::error("找不到URL", 0);
  2243. }
  2244. return Result::success($websiteInfo->toArray());
  2245. }
  2246. public function updateWebsiteGroup(array $data): array
  2247. {
  2248. $where = [
  2249. 'id' => $data['id'],
  2250. ];
  2251. $insertData = [
  2252. 'name' => $data['name'],
  2253. 'web_ids' => $data['web_ids'],
  2254. ];
  2255. //判斷name是不是重复
  2256. $websiteGroupInfo = WebsiteGroup::query()->where('name', $data['name'])->first();
  2257. if (!empty($websiteGroupInfo) && $websiteGroupInfo->id != $data['id']) {
  2258. return Result::error("网站标识重复", 0);
  2259. }
  2260. $result = WebsiteGroup::where($where)->update($insertData);
  2261. var_dump($result, '------更新');
  2262. if (empty($result)) {
  2263. return Result::error("更新失败", 0);
  2264. } else {
  2265. return Result::success();
  2266. }
  2267. }
  2268. public function deleteWebsiteGroup(array $data): array
  2269. {
  2270. $where = [
  2271. 'id' => $data['id'],
  2272. ];
  2273. //看看user表是不是有这个id
  2274. $userGroup = User::query()->where('sszq', $data['id'])->first();
  2275. if (!empty($userGroup)) {
  2276. return Result::error("有用户在使用该网站标识,不能删除", 0);
  2277. }
  2278. $result = WebsiteGroup::where($where)->delete();
  2279. if (empty($result)) {
  2280. return Result::error("删除失败", 0);
  2281. } else {
  2282. return Result::success();
  2283. }
  2284. }
  2285. public function getWebsiteNavList(array $data): array
  2286. {
  2287. $data['type'] = isset($data['type']) ? $data['type'] : 1;
  2288. $where = [];
  2289. if (isset($data['website_id']) && !empty($data['website_id'])) {
  2290. array_push($where, ['website_id', '=', $data['website_id']]);
  2291. }
  2292. if (isset($data['pid'])) {
  2293. array_push($where, ['pid', '=', $data['pid']]);
  2294. }
  2295. if (isset($data['type']) && !empty($data['type'])) {
  2296. array_push($where, ['type', '=', $data['type']]);
  2297. }
  2298. // 根据站点和type获取websiteCategory 中的id
  2299. $websiteCategoryids = WebsiteCategory::query()
  2300. ->where('website_id', '=', $data['website_id'])
  2301. ->where('type', '=', $data['type'])
  2302. ->pluck('category_arr_id')->toArray();
  2303. var_dump($websiteCategoryids, '------获取websiteCategory 中的id');
  2304. //合并去重
  2305. $category_ids = [];
  2306. foreach ($websiteCategoryids as $key => $value) {
  2307. $v = json_decode($value, true);
  2308. $category_ids = array_unique(array_merge($category_ids, $v));
  2309. }
  2310. // var_dump($category_ids, '------获取websiteCategory 中的id');
  2311. //根据pid取出所有的websiteCategory 中的id
  2312. $list = WebsiteCategory::query()
  2313. ->where('website_id', '=', $data['website_id'])
  2314. ->where('pid', '=', $data['pid'])
  2315. ->whereIn('category_id', $category_ids)
  2316. ->get();
  2317. if (empty($list)) {
  2318. return Result::error("获取失败", 0);
  2319. } else {
  2320. return Result::success($list);
  2321. }
  2322. }
  2323. // 20250307 根据网站标识获和导航获取站点
  2324. public function getWebsiteNavPoolSite(array $data): array
  2325. {
  2326. $where = [];
  2327. if (isset($data['category_id']) && !empty($data['category_id'])) {
  2328. array_push($where, ['category_id', '=', $data['category_id']]);
  2329. }
  2330. $list = WebsiteCategory::query()->where($where)
  2331. ->leftJoin('website', 'website.id', '=', 'website_category.website_id')
  2332. ->select('website_category.*', 'website.website_name')
  2333. ->distinct()
  2334. ->get();
  2335. if (empty($list)) {
  2336. return Result::error("获取失败", 0);
  2337. } else {
  2338. return Result::success($list);
  2339. }
  2340. }
  2341. public function getWebsiteNavPool(array $data): array
  2342. {
  2343. // 初始化查询条件数组
  2344. $query = WebsiteCategory::query();
  2345. // 如果传入了 websiteids,则添加到查询条件中
  2346. if (isset($data['websiteids']) && !empty($data['websiteids'])) {
  2347. $query->whereIn('website_id', $data['websiteids']);
  2348. }
  2349. // 如果传入了 pid,则添加到查询条件中
  2350. if (isset($data['pid'])) {
  2351. $query->where('pid', '=', $data['pid']);
  2352. }
  2353. // 执行查询 唯一性 id
  2354. $list = $query->distinct()->get();
  2355. // 根据查询结果返回相应的结果
  2356. if ($list->isEmpty()) {
  2357. return Result::error("获取失败", 0);
  2358. } else {
  2359. return Result::success($list->toArray());
  2360. }
  2361. }
  2362. /**
  2363. *
  2364. * @param array $data
  2365. * @return array
  2366. */
  2367. public function getAllCategory(array $data): array
  2368. {
  2369. $result = Category::when($data, function ($query) use ($data) {
  2370. if (isset($data['name']) && !empty($data['name'])) {
  2371. $query->where('category.name', 'like', '%' . trim($data['name']) . '%');
  2372. }
  2373. })->get();
  2374. if (empty($result)) {
  2375. return Result::error("获取失败", 0);
  2376. } else {
  2377. return Result::success($result);
  2378. }
  2379. }
  2380. /**
  2381. * 修改网站栏目排序
  2382. * @param array $data
  2383. * @return array
  2384. */
  2385. public function upWebsiteCategorySort(array $data): array
  2386. {
  2387. $where = [
  2388. 'website_id' => $data['website_id'],
  2389. 'id' => $data['id'],
  2390. ];
  2391. $result = WebsiteCategory::where($where)->update($data);
  2392. if ($result) {
  2393. return Result::success($result);
  2394. } else {
  2395. return Result::error("更新失败", 0);
  2396. }
  2397. }
  2398. }