WebsiteService.php 105 KB

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