WebsiteService.php 96 KB

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