WebsiteService.php 105 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771
  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::whereNotIn('status', ['404'])->count();
  717. $res['category']['count'] = Category::where([])->count();
  718. $res['good']['count'] = Good::where([])->count();
  719. $res['book']['count'] = Book::where([])->count();
  720. $res['jobHunting']['count'] = JobHunting::where([])->count();
  721. $res['jobRecruiting']['count'] = JobRecruiting::where([])->count();
  722. $res['complaint']['count'] = Complaint::where([])->count();
  723. $res['notice']['count'] = Notice::where([])->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 article.created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(article.created_at),`user`.type_id ORDER BY date ASC');
  726. $res['monthGood'] = Db::select(' SELECT DATE(good.created_at) AS date,COUNT(*) AS count ,user.type_id FROM good left JOIN user on good.user_id = user.id WHERE good.created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(good.created_at),`user`.type_id ORDER BY date ASC');
  727. $res['monthBook'] = Db::select(' SELECT DATE(book.created_at) AS date,COUNT(*) AS count ,user.type_id FROM book left JOIN user on book.user_id = user.id WHERE book.created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(book.created_at),`user`.type_id ORDER BY date ASC');
  728. $res['monthJobHunting'] = Db::select(' SELECT DATE(job_hunting.created_at) AS date,COUNT(*) AS count ,user.type_id FROM job_hunting left JOIN user on job_hunting.user_id = user.id WHERE job_hunting.created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(job_hunting.created_at),`user`.type_id ORDER BY date ASC');
  729. $res['monthJobRecruiting'] = Db::select(' SELECT DATE(job_recruiting.created_at) AS date,COUNT(*) AS count ,user.type_id FROM job_recruiting left JOIN user on job_recruiting.user_id = user.id WHERE job_recruiting.created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(job_recruiting.created_at),`user`.type_id ORDER BY date ASC');
  730. $res['userType'] = User::where([])->selectRaw("count(*) as counts,type_id")->groupBy('type_id')->get();
  731. //待审核数据
  732. $res['apply']['article'] = Article::where(['status' => 0])->count(); //
  733. $res['apply']['good'] = Good::where(['status' => 1])->count();
  734. $res['apply']['book'] = Book::where(['status' => 1])->count();
  735. $res['apply']['jobHunting'] = JobHunting::where(['status' => 1])->count();
  736. $res['apply']['jobRecruiting'] = JobRecruiting::where(['status' => 0])->count();
  737. $res['apply']['complaint'] = Complaint::where(['status' => 1])->count();
  738. $res['apply']['notice'] = Notice::where(['status' => 1])->count(); //订单状态:1:通过;2:驳回;3:撤回;4:修改;5:过期;6:待审核;7:结束',
  739. $res['apply']['order'] = Order::where(['status' => 6])->count();
  740. return Result::success($res);
  741. case 1:
  742. case 2:
  743. case 3:
  744. $res = [];
  745. //查询已审核文章
  746. $user_id = $data['user_id'];
  747. $article = Article::where('status', 1)
  748. ->where('admin_user_id', $user_id)
  749. ->orderBy('updated_at', 'desc')
  750. ->limit(10)
  751. ->get();
  752. $res['article'] = $article;
  753. $res['article']['count'] = Article::whereNotIn('status', ['404'])->where('admin_user_id', $user_id)->count();
  754. $res['good']['count'] = Good::where([])->where('user_id', $user_id)->count();
  755. $res['book']['count'] = Book::where([])->where('user_id', $user_id)->count();
  756. $res['jobHunting']['count'] = JobHunting::where([])->where('user_id', $user_id)->count();
  757. $res['jobRecruiting']['count'] = JobRecruiting::where([])->where('user_id', $user_id)->count();
  758. $res['complaint']['count'] = Complaint::where([])->where('user_id', $user_id)->count();
  759. $res['notice']['count'] = Notice::where([])->where('user_id', $user_id)->count();
  760. //待审核数据
  761. $res['apply']['article'] = Article::where(['status' => 0])->where('admin_user_id', $user_id)->count(); //
  762. $res['apply']['good'] = Good::where(['status' => 1])->where('user_id', $user_id)->count();
  763. $res['apply']['book'] = Book::where(['status' => 1])->where('user_id', $user_id)->count();
  764. $res['apply']['jobHunting'] = JobHunting::where(['status' => 1])->where('user_id', $user_id)->count();
  765. $res['apply']['jobRecruiting'] = JobRecruiting::where(['status' => 0])->where('user_id', $user_id)->count();
  766. $res['apply']['complaint'] = Complaint::where(['status' => 1])->where('user_id', $user_id)->count();
  767. $res['apply']['notice'] = Notice::where(['status' => 1])->where('user_id', $user_id)->count();
  768. return Result::success($res);
  769. }
  770. return [];
  771. }
  772. /**
  773. * 获取风格
  774. * @return void
  775. */
  776. public function getTemplateClass(array $data): array
  777. {
  778. $where = [];
  779. if (isset($data['name']) && $data['name']) {
  780. array_push($where, ['template_class.name', 'like', '%' . $data['name'] . '%']);
  781. }
  782. $template = TemplateClass::when($where, function ($query) use ($where) {
  783. $query->where($where);
  784. })
  785. ->leftJoin('template', 'template_class.id', '=', 'template.template_class_id')
  786. ->select('template_class.*', DB::raw('COUNT(template.id) as template_count'))
  787. ->groupBy('template_class.id')
  788. ->orderBy('template_class.updated_at', 'desc');
  789. $countQuery = clone $template;
  790. $count = $countQuery->count();
  791. $row = $template
  792. ->offset(($data['page'] - 1) * $data['pageSize'])
  793. ->limit($data['pageSize'])
  794. ->get();
  795. $result = [
  796. 'rows' => $row,
  797. 'count' => $count,
  798. ];
  799. if ($row->isEmpty()) {
  800. return Result::error("暂无风格", 0);
  801. } else {
  802. return Result::success($result);
  803. }
  804. }
  805. /**
  806. * 添加风格
  807. * @param
  808. * @return void
  809. */
  810. public function addTemplateClass(array $data): array
  811. {
  812. $data['keyword'] = json_encode($data['keyword']);
  813. $template = TemplateClass::where(['name' => $data['name']])->first();
  814. if ($template) {
  815. return Result::error("风格名称已存在", 0);
  816. }
  817. $result = TemplateClass::insertGetId($data);
  818. if (empty($result)) {
  819. return Result::error("创建风格失败", 0);
  820. } else {
  821. return Result::success(["id" => $result]);
  822. }
  823. }
  824. /**
  825. * 更新风格
  826. * @param array $data
  827. * @return array
  828. */
  829. public function upTemplateClass(array $data): array
  830. {
  831. $where = [
  832. 'id' => $data['id'],
  833. ];
  834. $template = TemplateClass::where($where)->first();
  835. if (empty($template)) {
  836. return Result::error("未查询到风格", 0);
  837. }
  838. if($template->type == 1){
  839. return Result::error("默认风格不能修改", 0);
  840. }
  841. $template = TemplateClass::where('id','!=',$data['id'])->where(['name' => $data['name']])->first();
  842. if ($template) {
  843. return Result::error("风格名称已存在", 0);
  844. }
  845. $updateData = [
  846. 'name' => $data['name'],
  847. 'keyword' => json_encode($data['keyword']),
  848. ];
  849. $result = TemplateClass::where($where)->update($updateData);
  850. if (empty($result)) {
  851. return Result::error("更新失败", 0);
  852. } else {
  853. return Result::success($result);
  854. }
  855. }
  856. /**
  857. * 删除风格
  858. * @param array $data
  859. * @return array
  860. */
  861. public function delTemplateClass(array $data): array
  862. {
  863. $where = [
  864. 'id' => $data['id'],
  865. ];
  866. $template = TemplateClass::where($where)->first();
  867. if (empty($template)) {
  868. return Result::error("未查询到风格", 0);
  869. }
  870. if($template->type == 1){
  871. return Result::error("默认风格不能删除", 0);
  872. }
  873. $result = TemplateClass::where($where)->delete();
  874. if (empty($result)) {
  875. return Result::error("删除失败", 0);
  876. } else {
  877. return Result::success($result);
  878. }
  879. }
  880. /**
  881. * 获取分类下的模板
  882. * @param array $data
  883. * @return array
  884. */
  885. public function getTemplate(array $data): array
  886. {
  887. $page = $data['page'];
  888. $pageSize = $data['pageSize'];
  889. $where = [];
  890. if (isset($data['template_class_id']) && $data['template_class_id']) {
  891. array_push($where, ['template_class_id', '=', $data['template_class_id']]);
  892. }
  893. $result = Template::where($where)
  894. ->limit($pageSize)->offset(($page - 1) * $pageSize)->get();
  895. $count = Template::where($where)->count();
  896. if (empty($result)) {
  897. return Result::error("没有数据", 0);
  898. }
  899. $data = [
  900. 'rows' => $result->toArray(),
  901. 'count' => $count,
  902. ];
  903. return Result::success($data);
  904. }
  905. /**
  906. * 创建模板
  907. * @param
  908. * @return void
  909. */
  910. public function addTemplate(array $data): array
  911. {
  912. $insertData = [
  913. 'template_name' => $data['template_name'],
  914. 'template_img' => json_encode($data['template_img']),
  915. 'template_class_id' => $data['template_class_id'],
  916. ];
  917. $result = Template::insertGetId($insertData);
  918. if (empty($result)) {
  919. return Result::error("创建模板失败", 0);
  920. } else {
  921. return Result::success(["id" => $result]);
  922. }
  923. }
  924. /**
  925. * 更新模板
  926. * @param array $data
  927. * @return array
  928. */
  929. public function upTemplate(array $data): array
  930. {
  931. $where = [
  932. 'id' => $data['id'],
  933. ];
  934. $insertData = [
  935. 'template_name' => $data['template_name'],
  936. 'template_img' => json_encode($data['template_img']),
  937. 'template_class_id' => $data['template_class_id'],
  938. ];
  939. $result = Template::where($where)->update($insertData);
  940. if (empty($result)) {
  941. return Result::error("更新模板失败", 0);
  942. } else {
  943. return Result::success();
  944. }
  945. }
  946. /**
  947. * 删除模板
  948. * @param array $data
  949. * @return array
  950. */
  951. public function delTemplate(array $data): array
  952. {
  953. $where = [
  954. 'id' => $data['id'],
  955. ];
  956. $result = Template::where($where)->delete();
  957. if (empty($result)) {
  958. return Result::error("删除模板失败", 0);
  959. } else {
  960. return Result::success();
  961. }
  962. }
  963. /**
  964. * 搜索网站
  965. * @param array $data
  966. * @return array
  967. */
  968. public function websiteList(array $data): array
  969. {
  970. $where = [];
  971. if (isset($data['keyword']) && !empty($data['keyword'])) {
  972. array_push($where, ['website.website_name', 'like', '%' . $data['keyword'] . '%']);
  973. }
  974. $result = Website::where($where)->get();
  975. if ($result) {
  976. return Result::success($result);
  977. } else {
  978. return Result::error("没有网站", 0);
  979. }
  980. }
  981. public function addWebsiteCategory(array $data): array
  982. {
  983. $website_id = $data['website_id'];
  984. $category_arr_id = $data['category_arr_id'];
  985. $categoryList = Category::whereIn('id', $category_arr_id)->get();
  986. $categoryListIds = [];
  987. if ($categoryList) {
  988. foreach ($categoryList->toArray() as $val) {
  989. array_push($categoryListIds, $val['id']);
  990. }
  991. }
  992. $arr = [];
  993. if ($categoryListIds) {
  994. foreach ($categoryListIds as $v) {
  995. $ids = $this->getUnderlingUIds(intval($v));
  996. $ids_arr = explode(",", $ids);
  997. array_push($arr, $ids_arr);
  998. }
  999. }
  1000. $mergedArray = [];
  1001. foreach ($arr as $subarray) {
  1002. $mergedArray = array_merge($mergedArray, $subarray);
  1003. }
  1004. var_dump("所有:", $arr, $mergedArray);
  1005. //查询出所有的分类进行分割插入 组装数据
  1006. $categoryListData = Category::whereIn('id', $mergedArray)->get();
  1007. $categoryListData = $categoryListData->toArray();
  1008. $insertData = [];
  1009. if ($categoryListData) {
  1010. foreach ($categoryListData as $key => $value) {
  1011. $insertData[$key]['website_id'] = $website_id;
  1012. $insertData[$key]['name'] = $value['name'];
  1013. $insertData[$key]['sort'] = $value['sort'];
  1014. $insertData[$key]['pid'] = $value['pid'];
  1015. $insertData[$key]['pid_arr'] = $value['pid_arr'];
  1016. $insertData[$key]['seo_title'] = $value['seo_title'];
  1017. $insertData[$key]['seo_keywords'] = $value['seo_keywords'];
  1018. $insertData[$key]['seo_description'] = $value['seo_description'];
  1019. $insertData[$key]['alias'] = $value['name'];
  1020. $insertData[$key]['category_id'] = $value['id'];
  1021. }
  1022. }
  1023. $result = WebsiteCategory::insert($insertData);
  1024. var_dump("插入数据状态:", $result);
  1025. if ($result) {
  1026. return Result::success($result);
  1027. } else {
  1028. return Result::error("创建失败", 0);
  1029. }
  1030. }
  1031. /**
  1032. * 删除网站导航
  1033. * @param array $data
  1034. * @return array
  1035. */
  1036. public function delWebsiteCategory(array $data): array
  1037. {
  1038. $website_id = $data['website_id'] ?? 0;
  1039. $category_id = $data['category_id'] ?? 0;
  1040. $ids = $this->getUnderlingUIds(intval($category_id));
  1041. $ids_arr = explode(",", $ids);
  1042. $result = WebsiteCategory::where(['website_id' => $website_id])->whereIn("category_id", $ids_arr)->delete();
  1043. if ($result) {
  1044. return Result::success($result);
  1045. } else {
  1046. return Result::error("删除失败", 0);
  1047. }
  1048. }
  1049. /**
  1050. * 获取网站导航
  1051. * @param array $data
  1052. * @return array
  1053. */
  1054. public function getAdminWebsiteCategory(array $data): array
  1055. {
  1056. $where = [
  1057. 'website_id' => $data['website_id'],
  1058. ];
  1059. $result = WebsiteCategory::where($where)->orderBy('sort', 'asc')->get();
  1060. $list = [];
  1061. if ($result) {
  1062. foreach ($result->toArray() as $val) {
  1063. array_push($list, json_decode($val['category_arr_id']));
  1064. }
  1065. }
  1066. if ($result) {
  1067. return Result::success($list);
  1068. } else {
  1069. return Result::error("查询失败", 0);
  1070. }
  1071. }
  1072. /**
  1073. * 更新网站导航
  1074. * @param array $data
  1075. * @return array
  1076. */
  1077. public function upWebsiteCategory(array $data): array
  1078. {
  1079. $pinyin = new Pinyin();
  1080. Db::beginTransaction();
  1081. try {
  1082. if (!empty($data['category_arr_id'])) {
  1083. $websiteId = $data['website_id'];
  1084. // 1. 获取旧的 category_id 列表
  1085. $oldCategoryListIds = WebsiteCategory::where('website_id', $websiteId)->pluck('category_id')->toArray();
  1086. // 2. 获取新的 category_id 列表(去重)
  1087. $newCategoryListIds = [];
  1088. foreach ($data['category_arr_id'] as $arr) {
  1089. $lastId = end($arr);
  1090. $newCategoryListIds[] = $lastId;
  1091. }
  1092. $newCategoryListIds = array_unique($newCategoryListIds);
  1093. // 3. 需要删除的 category_id
  1094. $toDelete = array_diff($oldCategoryListIds, $newCategoryListIds);
  1095. if (!empty($toDelete)) {
  1096. WebsiteCategory::where('website_id', $websiteId)
  1097. ->whereIn('category_id', $toDelete)
  1098. ->delete();
  1099. }
  1100. // 4. 批量查出所有需要的 category 信息
  1101. $categories = Category::whereIn('id', $newCategoryListIds)->get()->keyBy('id');
  1102. // 5. 组装 upsertData,确保 category_id 不重复
  1103. $upsertData = [];
  1104. $handledCategoryIds = [];
  1105. foreach ($data['category_arr_id'] as $arr) {
  1106. $categoryId = end($arr);
  1107. if (!isset($categories[$categoryId]) || in_array($categoryId, $handledCategoryIds)) continue;
  1108. $info = $categories[$categoryId];
  1109. $aLIas_pinyin = $pinyin->permalink($info->name, '');
  1110. $upsertData[] = [
  1111. 'website_id' => $websiteId,
  1112. 'category_id' => $categoryId,
  1113. 'name' => $info->name ?? '',
  1114. 'alias' => $info->name ?? '',
  1115. 'aLIas_pinyin' => $aLIas_pinyin ?? '',
  1116. 'sort' => $info->sort ?? 0,
  1117. 'pid' => $info->pid ?? 0,
  1118. 'pid_arr' => $info->pid_arr ?? json_encode([]),
  1119. 'seo_title' => $info->seo_title ?? "",
  1120. 'seo_keywords' => $info->seo_keywords ?? "",
  1121. 'seo_description' => $info->seo_description ?? "",
  1122. 'is_url' => $info->is_url ?? 0,
  1123. 'web_url' => $info->web_url ?? '',
  1124. 'type' => $info->type ?? 1,
  1125. 'category_arr_id' => json_encode($arr)
  1126. ];
  1127. $handledCategoryIds[] = $categoryId;
  1128. }
  1129. // 6. upsert
  1130. if (!empty($upsertData)) {
  1131. WebsiteCategory::upsert(
  1132. $upsertData,
  1133. ['website_id', 'category_id'],
  1134. [
  1135. 'aLIas_pinyin',
  1136. 'pid',
  1137. 'pid_arr',
  1138. 'is_url',
  1139. 'web_url',
  1140. 'category_arr_id'
  1141. ]
  1142. );
  1143. }
  1144. }
  1145. Db::commit();
  1146. return Result::success();
  1147. } catch (\Throwable $ex) {
  1148. Db::rollBack();
  1149. return Result::error("修改失败" . $ex->getMessage(), 0);
  1150. }
  1151. }
  1152. /**
  1153. * 获取网站列表
  1154. * @param array $data
  1155. * @return array
  1156. */
  1157. public function getWebsiteCategoryList(array $data): array
  1158. {
  1159. $where = [];
  1160. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1161. array_push($where, ['website.website_name', 'like', '%' . $data['keyword'] . '%']);
  1162. }
  1163. if (isset($data['website_column_id']) && !empty($data['website_column_id'])) {
  1164. array_push($where, ['website.website_column_id', '=', $data['website_column_id']]);
  1165. }
  1166. $result = Website::where($where)
  1167. ->with(["websiteCategory" => function ($query) {
  1168. $query->where(['pid' => 0])->select('website_id', 'name', 'alias', 'category_id');
  1169. }])
  1170. ->limit($data['pageSize'])->orderBy("updated_at", "desc")->offset(($data['page'] - 1) * $data['pageSize'])
  1171. ->get();
  1172. $count = Website::where($where)->count();
  1173. if (empty($result)) {
  1174. return Result::error("没有数据", 0);
  1175. }
  1176. $data = [
  1177. 'rows' => $result->toArray(),
  1178. 'count' => $count,
  1179. ];
  1180. if ($result) {
  1181. return Result::success($data);
  1182. } else {
  1183. return Result::error("查询失败", 0);
  1184. }
  1185. }
  1186. /**
  1187. * 删除网站下的所有导航
  1188. * @param array $data
  1189. * @return array
  1190. */
  1191. public function delWebsiteAllCategory(array $data): array
  1192. {
  1193. $website_id = $data['website_id'];
  1194. $result = WebsiteCategory::where(['website_id' => $website_id])->delete();
  1195. if ($result) {
  1196. return Result::success($result);
  1197. } else {
  1198. return Result::error("删除失败", 0);
  1199. }
  1200. }
  1201. /**
  1202. * 获取网站下的某一个导航
  1203. * @param array $data
  1204. * @return array
  1205. */
  1206. public function getWebsiteCategoryOnes(array $data): array
  1207. {
  1208. $website_id = $data['website_id'];
  1209. $category_id = $data['category_id'];
  1210. $result = WebsiteCategory::where(['website_category.website_id' => $website_id, 'website_category.category_id' => $category_id])
  1211. ->first();
  1212. if ($result) {
  1213. return Result::success($result);
  1214. } else {
  1215. return Result::error("查询失败", 0);
  1216. }
  1217. }
  1218. /**
  1219. * 更新网闸下的某一个导航
  1220. * @param array $data
  1221. * @return array
  1222. */
  1223. public function upWebsiteCategoryones(array $data): array
  1224. {
  1225. //处理所有数据
  1226. //获取所有数据
  1227. if (isset($data['all']) && $data['all'] == 'all') {
  1228. $result = WebsiteCategory::get();
  1229. $result = $result->toArray();
  1230. var_dump($result, '------------');
  1231. $pinyin = new Pinyin();
  1232. $letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  1233. for ($i = 0; $i < count($result); $i++) {
  1234. // $randss = substr(str_shuffle($letters), 0, 4);
  1235. $result[$i]['aLIas_pinyin'] = $pinyin->permalink($result[$i]['alias'], '');
  1236. WebsiteCategory::where(['id' => $result[$i]['id']])->update(['aLIas_pinyin' => $result[$i]['aLIas_pinyin']]);
  1237. }
  1238. var_dump($result, '--------222----');
  1239. if ($result) {
  1240. return Result::success($result);
  1241. } else {
  1242. return Result::error("更新失败", 0);
  1243. }
  1244. }
  1245. //处理所有数据
  1246. $where = [
  1247. 'website_id' => $data['website_id'],
  1248. 'category_id' => $data['category_id'],
  1249. ];
  1250. $alias = $data['alias'];
  1251. $pinyin = new Pinyin();
  1252. $aLIas_pinyin = $pinyin->permalink($alias, '');
  1253. //从WebsiteCategory取出alis ,并转成拼音存放到aLIas_pinyin
  1254. $result = WebsiteCategory::where($where)->first();
  1255. $result = $result->toArray();
  1256. //+四位随机字母
  1257. $letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  1258. // 打乱字符串顺序并截取前四位
  1259. // $randss = substr(str_shuffle($letters), 0, 4);
  1260. if ($data['alias_pinyin'] == '') {
  1261. $data['aLIas_pinyin'] = $aLIas_pinyin;
  1262. }
  1263. $result = WebsiteCategory::where($where)->update($data);
  1264. if ($result) {
  1265. return Result::success($result);
  1266. } else {
  1267. return Result::error("更新失败", 0);
  1268. }
  1269. }
  1270. /**
  1271. * 获取网站下的所有导航(包含子导航)
  1272. * @param array $data
  1273. * @return array
  1274. */
  1275. public function getWebsiteAllCategory(array $data): array
  1276. {
  1277. $where = [];
  1278. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1279. array_push($where, ['website_category.website_id', '=', $data['website_id']]);
  1280. }
  1281. // if (isset($data['name']) && !empty($data['name'])) {
  1282. // array_push($where, ['website_category.name', 'like', '%' . $data['name'] . '%']);
  1283. // }
  1284. // if (isset($data['alias']) && !empty($data['alias'])) {
  1285. // array_push($where, ['website_category.alias', 'like', '%' . $data['alias'] . '%']);
  1286. // }
  1287. // if (isset($data['department_id']) && !empty($data['department_id'])) {
  1288. // array_push($where, ['category.department_id', '=', $data['department_id']]);
  1289. // }
  1290. // if (isset($data['city_id']) && !empty($data['city_id'])) {
  1291. // array_push($where, ['category.city_id', '=', $data['city_id']]);
  1292. // }
  1293. $result = WebsiteCategory::where($where)
  1294. ->leftJoin("category", 'website_category.category_id', 'category.id')
  1295. ->select("website_category.*", "category.name as name")
  1296. // ->leftJoin("category", 'website_category.category_id', 'category.id')
  1297. // ->leftJoin("department", 'category.department_id', 'department.id')
  1298. // ->leftJoin("district", 'category.city_id', 'district.id')
  1299. // ->select("website_category.*", "department.name as department_name", "district.name as city_name")
  1300. // ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])
  1301. ->orderBy("sort", "asc")
  1302. ->get();
  1303. // $count = WebsiteCategory::where($where)
  1304. // ->leftJoin("category", 'website_category.category_id', 'category.id')
  1305. // ->leftJoin("department", 'category.department_id', 'department.id')
  1306. // ->leftJoin("district", 'category.city_id', 'district.id')
  1307. // ->count();
  1308. if (empty($result)) {
  1309. return Result::error("没有数据", 0);
  1310. }
  1311. // $data = [
  1312. // 'rows' => $result->toArray(),
  1313. // 'count' => $count,
  1314. // ];
  1315. if ($result) {
  1316. return Result::success($result->toArray());
  1317. } else {
  1318. return Result::error("查询失败", 0);
  1319. }
  1320. }
  1321. /**
  1322. * 递归查询数据
  1323. * @param $id
  1324. * @param $ids
  1325. * @return string
  1326. */
  1327. public function getUnderlingUIds($id, $ids = '')
  1328. {
  1329. $back = Category::where(['pid' => $id])->get();
  1330. $back = $back->toArray();
  1331. if (!empty($back) && is_array($back)) {
  1332. foreach ($back as $v) {
  1333. //防止当前人的ID重复去查询,形成恶性循环
  1334. if ($v['id'] == $id) {
  1335. continue;
  1336. }
  1337. $back2 = Category::where(['pid' => $id])->count('id');
  1338. if ($back2 > 0) {
  1339. $ids = $this->getUnderlingUIds($v['id'], $ids);
  1340. } else {
  1341. $ids .= ',' . $v['id'];
  1342. }
  1343. }
  1344. }
  1345. $ids = $id . ',' . $ids . ',';
  1346. $ids = str_replace(',,', ",", $ids);
  1347. $ids = trim($ids, ',');
  1348. return $ids;
  1349. }
  1350. /**
  1351. * 检测网站名称是否重复
  1352. * @param array $data
  1353. * @return array
  1354. */
  1355. public function checkWebsiteName(array $data): array
  1356. {
  1357. if (isset($data['id'])) {
  1358. $data[] = ['id', "!=", $data['id']];
  1359. unset($data['id']);
  1360. }
  1361. $websiteInfo = Website::query()->where($data)->first();
  1362. if (empty($websiteInfo)) {
  1363. return Result::error("找不到网站", 0);
  1364. }
  1365. return Result::success($websiteInfo->toArray());
  1366. }
  1367. /**
  1368. * 检测网站url是否重复
  1369. * @param array $data
  1370. * @return array
  1371. */
  1372. public function checkWebsiteUrl(array $data): array
  1373. {
  1374. $whereData = [];
  1375. if (isset($data['id'])) {
  1376. $whereData = [['id', "!=", $data['id']]];
  1377. unset($data['id']);
  1378. }
  1379. $websiteInfo = Website::query()->where($whereData)->whereJsonContains('website_url', $data['website_url'])->first();
  1380. if (empty($websiteInfo)) {
  1381. return Result::error("找不到URL", 0);
  1382. }
  1383. return Result::success($websiteInfo->toArray());
  1384. }
  1385. /**
  1386. * 获取网站底部基础信息
  1387. * @param array $data
  1388. * @return array
  1389. */
  1390. public function getWebsiteFootInfo(array $data): array
  1391. {
  1392. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1393. $website_head = Website::where('id', $data['website_id'])
  1394. ->where('status', 1)
  1395. ->select('id', 'website_name', 'logo', 'title', 'keywords', 'description', 'suffix', 'website_url')
  1396. ->first();
  1397. if (empty($website_head)) {
  1398. return Result::error("找不到网站", 0);
  1399. }
  1400. } else {
  1401. return Result::error("参数错误", 0);
  1402. }
  1403. $website_head = Website::where('id', $data['website_id'])
  1404. ->select('id', 'website_name', 'logo', 'title', 'keywords', 'description', 'suffix', 'website_url')->first();
  1405. $website_foot = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1406. if (empty($website_foot)) {
  1407. return Result::error("暂无底部基础信息", 0);
  1408. }
  1409. $website_head['website_url'] = $website_head['website_url'] ? json_decode($website_head['website_url']) : [];
  1410. $result = [
  1411. 'website_foot' => $website_foot,
  1412. 'website_head' => $website_head,
  1413. ];
  1414. return Result::success($result);
  1415. }
  1416. /**
  1417. * 获取网站底部导航
  1418. * @param array $data
  1419. * @return array
  1420. */
  1421. public function getWebsiteFooterCategory(array $data): array
  1422. {
  1423. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1424. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1425. if (empty($website)) {
  1426. return Result::error("找不到网站", 0);
  1427. }
  1428. } else {
  1429. return Result::error("参数错误", 0);
  1430. }
  1431. $result = FooterCategory::where('website_id', $data['website_id'])->get();
  1432. if (empty($result)) {
  1433. return Result::error("暂无底部导航", 0);
  1434. }
  1435. return Result::success($result->toArray());
  1436. }
  1437. /**
  1438. * 获取网站底部导航列表
  1439. * @param array $data
  1440. * @return array
  1441. */
  1442. public function getWebsiteFooterCategoryList(array $data): array
  1443. {
  1444. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1445. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1446. if (empty($website)) {
  1447. return Result::error("找不到网站", 0);
  1448. }
  1449. } else {
  1450. return Result::error("参数错误", 0);
  1451. }
  1452. $footercategory = FooterCategory::where('website_id', $data['website_id'])->where('id', $data['fcat_id'])->first();
  1453. // '底部导航类型 0:内容型;1:列表型;',
  1454. if (!isset($footercategory['type']) || $footercategory['type'] == 0) {
  1455. return Result::error("底部导航id错误", 0);
  1456. } else {
  1457. $query = FooterContent::where('fcat_id', $data['fcat_id']);
  1458. if ($query->count() == 0) {
  1459. return Result::error("暂无底部导航列表", 0);
  1460. } elseif ($query->count() == 1) {
  1461. $result = $query->first();
  1462. } else {
  1463. $result = $query->get();
  1464. }
  1465. }
  1466. return Result::success($result);
  1467. }
  1468. /**
  1469. * 获取网站底部导航
  1470. * @param array $data
  1471. * @return array
  1472. */
  1473. public function getWebsiteFooterCategoryInfo(array $data): array
  1474. {
  1475. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1476. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1477. if (empty($website)) {
  1478. return Result::error("找不到网站", 0);
  1479. }
  1480. } else {
  1481. return Result::error("参数错误", 0);
  1482. }
  1483. if (isset($data['type']) && $data['type'] == 0) {
  1484. $fcatid = FooterCategory::where('website_id', $data['website_id'])->where('id', $data['fcat_id'])->first();
  1485. if (empty($fcatid)) {
  1486. return Result::error("底部导航id错误", 0);
  1487. }
  1488. $result = FooterContent::where('fcat_id', $data['fcat_id'])->first();
  1489. } else {
  1490. $result = FooterContent::where('id', $data['fcat_id'])->first();
  1491. }
  1492. if (empty($result)) {
  1493. return Result::error("暂无底部导航内容", 0);
  1494. }
  1495. return Result::success($result);
  1496. }
  1497. /*
  1498. * 搜索网站二级导航
  1499. * @param array $data
  1500. * @return array
  1501. * */
  1502. public function selectWebsiteCategory(array $data): array
  1503. {
  1504. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1505. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1506. if (empty($website)) {
  1507. return Result::error("暂无该网站", 0);
  1508. }
  1509. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id')->all();
  1510. // return Result::success($category);
  1511. if (empty($category)) {
  1512. return Result::error("暂无此导航", 0);
  1513. }
  1514. $query = Category::whereIn('id', $category);
  1515. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1516. $cityid = District::where('id', $data['cityid'])->first();
  1517. if (empty($cityid)) {
  1518. return Result::error("暂无此城市", 0);
  1519. } else {
  1520. $city_category = $query->whereRaw('JSON_CONTAINS(city_arr_id,?)', [$data['cityid']])->pluck('id');
  1521. // $where[] = ['JSON_CONTAINS(city_arr_id, ?)', $data['cityid']];
  1522. if (empty($city_category)) {
  1523. return Result::error("暂无此城市下的导航", 0);
  1524. }
  1525. $result['catid'] = $city_category;
  1526. $city = 1;
  1527. // var_dump("城市====================",$result);
  1528. }
  1529. }
  1530. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1531. $departmentid = Department::where('id', $data['department_id'])->first();
  1532. if (empty($departmentid)) {
  1533. return Result::error("暂无此部门", 0);
  1534. } else {
  1535. $depart_category = $query->whereRaw('JSON_CONTAINS(department_arr_id,?)', [$data['department_id']])->pluck('id');
  1536. if (empty($depart_category)) {
  1537. return Result::error("暂无此部门下的导航", 0);
  1538. }
  1539. $result['catid'] = $depart_category;
  1540. // var_dump("职能部门*******************",$result);
  1541. $department = 1;
  1542. }
  1543. }
  1544. if (!empty($city) && !empty($department)) {
  1545. // var_dump("城市和职能部门----------------------",$result);
  1546. $sel_category = $query->whereRaw('JSON_CONTAINS(city_arr_id,?)', [$data['cityid']])->whereRaw('JSON_CONTAINS(department_arr_id,?)', [$data['department_id']])->pluck('id');
  1547. if (empty($sel_category)) {
  1548. return Result::error("暂无此城市和职能部门下的导航", 0);
  1549. }
  1550. $result['catid'] = $sel_category;
  1551. }
  1552. if (empty($result)) {
  1553. return Result::error("暂无导航", 0);
  1554. }
  1555. // department_id
  1556. } else {
  1557. return Result::error("参数错误", 0);
  1558. }
  1559. return Result::success($result);
  1560. }
  1561. /**
  1562. * 获取网站栏目seo
  1563. * @param array $data
  1564. * @return array
  1565. */
  1566. public function getWebsiteCategoryHead(array $data): array
  1567. {
  1568. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1569. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1570. if (empty($website)) {
  1571. return Result::error("找不到网站", 0);
  1572. }
  1573. } else {
  1574. return Result::error("参数错误", 0);
  1575. }
  1576. if (isset($data['catid']) && !empty($data['catid'])) {
  1577. $result = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->first();
  1578. }
  1579. if (empty($result)) {
  1580. return Result::error("暂无导航", 0);
  1581. }
  1582. $result['website_name'] = $website['website_name'] ?? '';
  1583. $result['suffix'] = $website['suffix'] ?? '';
  1584. return Result::success($result);
  1585. }
  1586. /*
  1587. * 获取某个栏目
  1588. * @param array $data
  1589. * @return array
  1590. * */
  1591. public function getOneWebsiteCategory(array $data): array
  1592. {
  1593. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1594. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1595. if (empty($website)) {
  1596. return Result::error("暂无该网站", 0);
  1597. }
  1598. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['category_id'])->first();
  1599. if (empty($category)) {
  1600. return Result::error("暂无此导航", 0);
  1601. }
  1602. $category['children_count'] = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['category_id'])->count();
  1603. $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();
  1604. $category['parent_id'] = $parent['parent_id'] ?? '';
  1605. $category['parent_pinyin'] = $parent['aLIas_pinyin'] ?? '';
  1606. $category['parent_name'] = $parent['parent_name'] ?? '';
  1607. return Result::success($category);
  1608. } else {
  1609. return Result::error("参数错误", 0);
  1610. }
  1611. }
  1612. // 自助建站--fr-------------------
  1613. /**
  1614. * 获取并搜索 网站模板信息
  1615. * @param array $data
  1616. * @return array
  1617. */
  1618. public function getWebsiteintel(array $data): array
  1619. {
  1620. //查询所有网站模板信息
  1621. $query = Website::where('website.status', 1)
  1622. ->leftJoin("website_template_info", "website_template_info.website_id", "website.id")
  1623. ->leftJoin("template", "template.id", "website_template_info.template_id")
  1624. ->leftJoin("template_class", "template_class.id", "template.template_class_id")
  1625. ->select(
  1626. "website_template_info.id",
  1627. "template_class.name",
  1628. "website.id as website_id",
  1629. "website.website_name",
  1630. "website.website_url",
  1631. "website_template_info.action_id",
  1632. "website_template_info.created_at",
  1633. "website_template_info.updated_at",
  1634. "website_template_info.page_type",
  1635. DB::raw("COALESCE(website_template_info.status, 0) as template_status"),
  1636. "template.template_name"
  1637. );
  1638. //若存在条件;则在$query的基础上进行筛选
  1639. if (isset($data['website_name']) && !empty($data['website_name'])) {
  1640. $query->where('website.website_name', 'like', '%' . $data['website_name'] . '%');
  1641. }
  1642. if (isset($data['status']) && !empty($data['status'])) {
  1643. $query->where('website_template_info.status', $data['status']);
  1644. }
  1645. $count = $query->count();
  1646. $query->limit($data['pageSize'])
  1647. ->offset(($data['page'] - 1) * $data['pageSize'])
  1648. ->orderBy("website_template_info.updated_at", "desc");
  1649. $rep = $query->get();
  1650. if ($rep->count() == 0) {
  1651. return Result::error("没有查找到相关数据", 0);
  1652. } else {
  1653. $rep->each(function ($item) {
  1654. if (!empty($item->page_type)) {
  1655. $pageTypeArray = json_decode($item->page_type, true);
  1656. if (is_array($pageTypeArray)) {
  1657. $item->page_type = $pageTypeArray;
  1658. }
  1659. }
  1660. });
  1661. $result = [
  1662. "rows" => $rep->toArray(),
  1663. "count" => $count,
  1664. ];
  1665. return Result::success($result);
  1666. }
  1667. // return Result::success($result);
  1668. }
  1669. /**
  1670. * 添加网站基础信息
  1671. * @param array $data
  1672. * @return array
  1673. */
  1674. public function addWebsiteTemplateintel(array $data): array
  1675. {
  1676. $website = Website::where('website.id', $data['website_id'])->first();
  1677. if (empty($website)) {
  1678. return Result::error("请输入正确的网站id!", 0);
  1679. }
  1680. if (empty($website['website_column_id'])) {
  1681. return Result::error("请先关联导航池!", 0);
  1682. }
  1683. // 获取此网站的底部导航 类型 type: 0:内容型底部导航(只有一条详情内容);1:列表型底部导航(可以有多条详情内容)
  1684. $foot_type = FooterCategory::where('website_id', $data['website_id'])->pluck('type')->toArray();
  1685. if (empty($foot_type)) {
  1686. return Result::error("请先关联底部导航池!", 0);
  1687. } elseif (in_array(1, $foot_type)) {
  1688. $foot_type = 1;
  1689. } else {
  1690. $foot_type = 0;
  1691. }
  1692. $result['foot_type'] = $foot_type;
  1693. // 友情链接类型'1:图片 2:文字 3:底部';
  1694. $types = Link::where('website_id', $data['website_id'])->pluck('type')->toArray();
  1695. $missingTypes = [];
  1696. if (!in_array(1, $types)) {
  1697. $missingTypes[] = "文字链接";
  1698. }
  1699. if (!in_array(2, $types)) {
  1700. $missingTypes[] = "图片链接";
  1701. }
  1702. if (!in_array(3, $types)) {
  1703. $missingTypes[] = "底部链接";
  1704. }
  1705. if (!empty($missingTypes)) {
  1706. $errorMessage = "请先添加 " . implode(" 和 ", $missingTypes) . "!";
  1707. return Result::error($errorMessage, 0);
  1708. }
  1709. if (isset($data['page_type'])) {
  1710. // 删除重复元素并重新索引数组
  1711. $data['page_type'] = array_unique($data['page_type']);
  1712. $data['page_type'] = array_values($data['page_type']);
  1713. if (in_array(1, $data['page_type']) && in_array(7, $data['page_type'])) {
  1714. // 数组中同时包含值为 1(首页) 和值为 7 (底部导航详情页)的元素
  1715. $info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1716. if (empty($info)) {
  1717. // 将数组转换为 JSON 字符串
  1718. $data['page_type'] = json_encode($data['page_type']) ?? '';
  1719. // 操作状态:1:填写完成基础信息;2:选择完成模板;0:未构建
  1720. $data['action_id'] = 1;
  1721. try {
  1722. $result = WebsiteTemplateInfo::insertGetId($data);
  1723. } catch (\Exception $e) {
  1724. if ($e->getCode() == 22001) {
  1725. $errorMessage = $e->getMessage();
  1726. return Result::error("请检查表单,某个字段超出了长度限制!");
  1727. } else {
  1728. // 处理其他类型的数据库错误
  1729. return Result::error("插入操作失败: " . $e->getMessage());
  1730. }
  1731. return Result::error("添加失败!", 0);
  1732. }
  1733. } else {
  1734. return Result::error("该网站已经构建过了!", 0);
  1735. }
  1736. } else {
  1737. return Result::error("请先选择首页和底部导航详情页!", 0);
  1738. }
  1739. }
  1740. if (empty($result)) {
  1741. return Result::error("添加失败!", 0);
  1742. } else {
  1743. return Result::success($result);
  1744. }
  1745. }
  1746. /**
  1747. * 获取网站基础信息
  1748. *
  1749. * @return array
  1750. */
  1751. public function getWebsiteTemplateintel(array $data): array
  1752. {
  1753. $result = WebsiteTemplateInfo::where('website_template_info.website_id', $data['website_id'])
  1754. ->leftJoin('footer_category', 'footer_category.website_id', 'website_template_info.website_id')
  1755. ->leftJoin('website', 'website.id', 'website_template_info.website_id')
  1756. ->select(
  1757. "website_template_info.*",
  1758. "footer_category.type",
  1759. "website.website_name",
  1760. "website.id as website_id"
  1761. )
  1762. ->first();
  1763. if (empty($result['website_name'])) {
  1764. return Result::error("请输入正确的网站id!", 0);
  1765. }
  1766. if ($result) {
  1767. $result['page_type'] = json_decode($result['page_type'], true);
  1768. return Result::success($result);
  1769. } else {
  1770. return Result::error("请先添加网站基础信息!", 0);
  1771. }
  1772. }
  1773. /**
  1774. * 修改网站基础信息
  1775. *
  1776. * @return array
  1777. */
  1778. public function upWebsiteTemplateintel(array $data): array
  1779. {
  1780. $web = Website::where('website.id', $data['website_id'])->first();
  1781. if (empty($web)) {
  1782. return Result::error("请输入正确的网站id!", 0);
  1783. }
  1784. $where = ['website_id' => $data['website_id']];
  1785. $result = WebsiteTemplateInfo::where($where)->first();
  1786. if (empty($result)) {
  1787. return Result::error("请先添加网站基础信息!", 0);
  1788. } else {
  1789. unset($data['website_id']);
  1790. // 删除重复元素
  1791. $data['page_type'] = array_unique($data['page_type']);
  1792. // 重新索引数组
  1793. $data['page_type'] = array_values($data['page_type']);
  1794. // 数组中同时包含值为 1(首页) 和值为 7 (底部导航详情页)的元素
  1795. if (in_array(1, $data['page_type']) && in_array(7, $data['page_type'])) {
  1796. // 将数组转换为 JSON 字符串
  1797. $data['page_type'] = json_encode($data['page_type']) ?? '';
  1798. try {
  1799. $result = WebsiteTemplateInfo::where($where)->update($data);
  1800. } catch (\Exception $e) {
  1801. if ($e->getCode() == 22001) {
  1802. $errorMessage = $e->getMessage();
  1803. return Result::error("请检查表单,某个字段超出了长度限制!");
  1804. } else {
  1805. // 处理其他类型的数据库错误
  1806. return Result::error("修改操作失败: " . $e->getMessage());
  1807. }
  1808. return Result::error("修改失败!", 0);
  1809. }
  1810. } else {
  1811. return Result::error("请先选择首页和底部导航详情页!", 0);
  1812. }
  1813. }
  1814. if (empty($result)) {
  1815. return Result::error("修改失败!", 0);
  1816. } else {
  1817. return Result::success($result);
  1818. }
  1819. }
  1820. /**
  1821. * 获取所有网站风格信息
  1822. *
  1823. * @return array
  1824. */
  1825. public function getAllTemplateClass(array $data): array
  1826. {
  1827. $result = TemplateClass::all();
  1828. if (empty($result)) {
  1829. return Result::error("没有查找到相关数据!", 0);
  1830. } else {
  1831. return Result::success($result);
  1832. }
  1833. }
  1834. /**
  1835. * 搜索并获取网站模板信息
  1836. * @param array $data
  1837. * @return array
  1838. */
  1839. public function getWebsiteTemplateList(array $data): array
  1840. {
  1841. $website = Website::where('website.id', $data['website_id'])->first();
  1842. if (empty($website)) {
  1843. return Result::error("请输入正确的网站id!", 0);
  1844. } else {
  1845. $page_type = WebsiteTemplateInfo::where('website_id', $data['website_id'])->select('page_type')->first();
  1846. if (empty($page_type)) {
  1847. return Result::error("此网站还未添加基础信息!", 0);
  1848. } else {
  1849. $where = json_decode($page_type['page_type'], true);
  1850. // $where = $data["page_type"];
  1851. if (isset($data['template_class_id']) && !empty($data['template_class_id'])) {
  1852. $template_class = TemplateClass::where('id', $data['template_class_id'])->first();
  1853. if (empty($template_class)) {
  1854. return Result::error("请输入正确的模板风格id!", 0);
  1855. } else {
  1856. // 获取指定风格下的模板
  1857. $rep = Template::where('template_class_id', $data['template_class_id'])
  1858. ->where(function ($query) use ($where) {
  1859. foreach ($where as $value) {
  1860. $query->whereJsonContains('template_img', ['value' => $value]);
  1861. }
  1862. })
  1863. ->limit($data['pageSize'])
  1864. ->offset(($data['page'] - 1) * $data['pageSize'])
  1865. ->orderBy("template.updated_at", "desc")
  1866. ->get();
  1867. $count = Template::where('template_class_id', $data['template_class_id'])
  1868. ->where(function ($query) use ($where) {
  1869. foreach ($where as $value) {
  1870. $query->whereJsonContains('template_img', ['value' => $value]);
  1871. }
  1872. })->count();
  1873. }
  1874. } else {
  1875. //获取所有模板
  1876. $rep = Template::where(function ($query) use ($where) {
  1877. foreach ($where as $value) {
  1878. $query->whereJsonContains('template_img', ['value' => $value]);
  1879. }
  1880. })
  1881. ->limit($data['pageSize'])
  1882. ->offset(($data['page'] - 1) * $data['pageSize'])
  1883. ->orderBy("template.updated_at", "desc")
  1884. ->get();
  1885. $count = Template::where(function ($query) use ($where) {
  1886. foreach ($where as $value) {
  1887. $query->whereJsonContains('template_img', ['value' => $value]);
  1888. }
  1889. })->count();
  1890. }
  1891. if (empty($rep) || $rep->count() == 0) {
  1892. return Result::error("没有查找到相关数据!", 0);
  1893. } else {
  1894. // 过滤 template_img 字段 只获取 基础信息中 包含的模板图片
  1895. // $rep->each(function ($item) use ($where) {
  1896. // $template_img = json_decode($item->template_img, true);
  1897. // if(is_array($template_img)){
  1898. // $filtered_img = array_filter($template_img, function ($img) use ($where) {
  1899. // return isset($img['value']) && in_array($img['value'], $where);
  1900. // });
  1901. // }
  1902. // $item->template_img = $filtered_img;
  1903. // });
  1904. // $result = [
  1905. // "rows" => $rep->toArray(),
  1906. // "count" => $count
  1907. // ];
  1908. $rep->each(function ($item) use ($where) {
  1909. $template_img = json_decode($item->template_img, true);
  1910. if (is_array($template_img)) {
  1911. $filtered_img = array_filter($template_img, function ($img) use ($where) {
  1912. return isset($img['value']) && in_array($img['value'], $where);
  1913. });
  1914. // 对过滤后的数组进行重新排序
  1915. $sorted_img = array_values($filtered_img);
  1916. $item->template_img = $sorted_img;
  1917. } else {
  1918. $item->template_img = []; // 如果无法解码为数组,则设置为空数组
  1919. }
  1920. });
  1921. $result = [
  1922. "rows" => $rep->toArray(),
  1923. "count" => $count,
  1924. ];
  1925. }
  1926. }
  1927. }
  1928. return Result::success($result);
  1929. }
  1930. /**
  1931. * 添加网站模板
  1932. * @param array $data
  1933. */
  1934. public function addWebsiteTemplateclassintel(array $data): array
  1935. {
  1936. $template = Template::where('id', $data['template_id'])->first();
  1937. $web = Website::where('id', $data['website_id'])->first();
  1938. if (empty($template)) {
  1939. return Result::error("请输入正确的模板id", 0);
  1940. }
  1941. if (empty($web)) {
  1942. return Result::error("请输入正确的网站id", 0);
  1943. }
  1944. $result = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['template_id' => $data['template_id'], 'action_id' => 2]);
  1945. if (empty($result)) {
  1946. return Result::error("添加失败", 0);
  1947. } else {
  1948. return Result::success($result);
  1949. }
  1950. }
  1951. /**
  1952. * 获取网站模板信息
  1953. * @param array $data
  1954. */
  1955. public function getWebsiteTemplateclassintel(array $data): array
  1956. {
  1957. // return Result::success($data);
  1958. $template = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1959. if (empty($template)) {
  1960. return Result::error("请输入正确的搭建网站id", 0);
  1961. }
  1962. $page_type = json_decode($template['page_type'], true);
  1963. // 获取指定网站下的基础信息和模板及风格信息
  1964. $result = WebsiteTemplateInfo::where([
  1965. ['website_template_info.website_id', $data['website_id']],
  1966. ['template_id', '!=', null],
  1967. ])
  1968. ->leftJoin('template', 'template.id', 'website_template_info.template_id')
  1969. ->leftJoin('template_class', 'template_class.id', 'template.template_class_id')
  1970. ->where(function ($query) use ($page_type) {
  1971. // 假设 $data['page_type'] 是一个数组,包含需要匹配的 page_type 值
  1972. foreach ($page_type as $pageType) {
  1973. $query->orWhereJsonContains('template.template_img', ['value' => $pageType]);
  1974. }
  1975. })
  1976. ->select(
  1977. 'template.template_name',
  1978. 'template.template_img',
  1979. 'template.id as tid',
  1980. 'template_class.name',
  1981. 'template_class.id as class_id',
  1982. 'website_template_info.page_type',
  1983. 'website_template_info.website_id'
  1984. )
  1985. ->first();
  1986. if (empty($result)) {
  1987. return Result::error("没有查找到相关数据", 0);
  1988. }
  1989. // return Result::success($result);
  1990. // 过滤 template_img 字段 只获取 基础信息中 包含的模板图片
  1991. $template_img = $result['template_img'] !== null ? json_decode($result['template_img'], true) : [];
  1992. $page_type = $result['page_type'] !== null ? json_decode($result['page_type'], true) : [];
  1993. foreach ($template_img as $key => $value) {
  1994. if (!in_array($value['value'], $page_type)) {
  1995. unset($template_img[$key]);
  1996. }
  1997. }
  1998. // return Result::success($result);
  1999. $result['template_img'] = array_values($template_img);
  2000. $result['page_type'] = $page_type;
  2001. // $templateList = $this->getWebsiteTemplateList($data);
  2002. // $count = $templateList['data']['count']??'';
  2003. // $pages = $count / $data['pageSize'];
  2004. // $found = false;
  2005. // while ($pages && !$found) {
  2006. // $templates = $this->getWebsiteTemplateList($pages,$data['pageSize']);
  2007. // $index = array_search($template['template_id'], array_column($templates['rows'], 'id'));
  2008. // if ($index !== false) {
  2009. // $found = true;
  2010. // $result['page'] = $pages;
  2011. // $pages = 0;
  2012. // // echo "查询到的 template 在第 $page 页";
  2013. // }
  2014. // $pages--;
  2015. // }
  2016. return Result::success($result);
  2017. }
  2018. /**
  2019. * 获取网站模板下的板块信息
  2020. * @param array $data
  2021. */
  2022. public function getWebsiteSectorList(array $data): array
  2023. {
  2024. $website = Website::where('id', $data['website_id'])->first();
  2025. if (empty($website)) {
  2026. return Result::error("请输入正确的网站id", 0);
  2027. }
  2028. $template = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  2029. if (empty($template['template_id'])) {
  2030. return Result::error("请先添加网站模板", 0);
  2031. }
  2032. $query = Sector::where('template_id', $template['template_id']);
  2033. if ($query->count() == 0) {
  2034. return Result::error("没有查找到相关板块数据", 0);
  2035. } elseif ($query->count() == 1) {
  2036. $sector = $query->first();
  2037. } else {
  2038. $sector = $query->get();
  2039. }
  2040. $result['page_type'] = $template['page_type'];
  2041. $result['tid'] = $template['template_id'];
  2042. $result = [
  2043. "tid" => $template['template_id'],
  2044. "page_type" => $template['page_type'],
  2045. "sector" => $sector,
  2046. ];
  2047. return Result::success($result);
  2048. }
  2049. // 自助建站---------------fr---------------
  2050. // 网站底基础信息--fr-------------------
  2051. /**
  2052. * 添加网站底基础信息
  2053. * @param array $data
  2054. */
  2055. public function addWebFootInfo(array $data): array
  2056. {
  2057. $website = Website::where('id', $data['website_id'])->first();
  2058. if (empty($website)) {
  2059. return Result::error("请输入正确的网站id!", 0);
  2060. }
  2061. $info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  2062. if (!empty($info)) {
  2063. return Result::error("该网站已经添加过了!", 0);
  2064. }
  2065. $result = WebsiteTemplateInfo::where('website_id', $data['website_id'])->insertGetId($data);
  2066. if (empty($result)) {
  2067. return Result::error("请先添加网站基础信息!", 0);
  2068. } else {
  2069. return Result::success($result);
  2070. }
  2071. }
  2072. /**
  2073. * 获取网站底基础信息
  2074. * @param array $data
  2075. */
  2076. public function getWebFootInfo(array $data): array
  2077. {
  2078. $website = Website::where('id', $data['website_id'])->first();
  2079. if (empty($website)) {
  2080. return Result::error("请输入正确的网站id!", 0);
  2081. }
  2082. $result = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  2083. if (empty($result)) {
  2084. return Result::error("请先添加网站基础信息!", 0);
  2085. }
  2086. return Result::success($result);
  2087. }
  2088. /**
  2089. * 修改网站底基础信息
  2090. * @param array $data
  2091. */
  2092. public function upWebFootInfo(array $data): array
  2093. {
  2094. // return Result::success($data);
  2095. $website = Website::where('id', $data['website_id'])->first();
  2096. if (empty($website)) {
  2097. return Result::error("请输入正确的网站id!", 0);
  2098. }
  2099. $web = $data['website_id'];
  2100. unset($data['website_id']);
  2101. $where = ['website_id' => $web];
  2102. // return Result::success($data);
  2103. $result = WebsiteTemplateInfo::where($where)->first();
  2104. if (empty($result)) {
  2105. $data['website_id'] = $web;
  2106. $result = WebsiteTemplateInfo::insertGetId($data);
  2107. // return Result::error("请先添加网站基础信息!",0);
  2108. } else {
  2109. $result = WebsiteTemplateInfo::where($where)->update($data);
  2110. }
  2111. // $where = ['website_id'=>$data['website_id']];
  2112. // unset($data['website_id']);
  2113. // $result = WebsiteTemplateInfo::updateOrInsert($where, $data);
  2114. if (empty($result)) {
  2115. return Result::error("修改失败!", 0);
  2116. }
  2117. return Result::success($result);
  2118. }
  2119. /*
  2120. * 获取父级/子级栏目------路由
  2121. * @param array $data
  2122. * @return array
  2123. * */
  2124. public function getWebsiteParentCategory(array $data): array
  2125. {
  2126. // return Result::success($data);
  2127. if (isset($data['website_id']) && !empty($data['website_id'])) {
  2128. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  2129. }
  2130. if (empty($website)) {
  2131. return Result::error("暂无该网站", 0);
  2132. }
  2133. // 在 Hyperf 中,查询构建器(Builder)没有 `map` 方法,`map` 方法是集合(Collection)的方法。
  2134. // 因此,需要先调用 `get()` 方法获取查询结果集合,再使用 `map` 方法进行处理。
  2135. $category['parent'] = WebsiteCategory::where('website_id', $data['website_id'])
  2136. ->where('pid', 0)
  2137. ->selectRaw("category_id as cid, alias as name, CONCAT('/', '', aLIas_pinyin, '/') as path")
  2138. ->get() // 添加 get() 方法获取结果集合
  2139. ->all();
  2140. // 提前查询所有父级栏目,避免在 map 中多次查询
  2141. // 提前查询所有父级栏目信息并以 category_id 作为键存储
  2142. $parentCategories = WebsiteCategory::where('website_id', $data['website_id'])
  2143. ->where('pid', 0)
  2144. ->select('category_id', 'aLIas_pinyin')
  2145. ->get()
  2146. ->keyBy('category_id');
  2147. // 直接查询子栏目信息
  2148. $child = WebsiteCategory::where('website_id', $data['website_id'])
  2149. ->where('pid', '!=', 0)
  2150. ->select('alias', 'category_id', 'aLIas_pinyin', 'pid')
  2151. ->get();
  2152. // 使用集合的 map 方法处理子栏目信息
  2153. $category['child'] = $child->map(function ($item) use ($parentCategories) {
  2154. $alias = $item->alias;
  2155. $category_id = $item->category_id;
  2156. $aLIas_pinyin = $item->aLIas_pinyin;
  2157. $parent = $parentCategories->get($item->pid);
  2158. $parentAlias = $parent ? $parent->aLIas_pinyin : '';
  2159. $result = [
  2160. 'name' => $alias,
  2161. 'cid' => $category_id
  2162. ];
  2163. if (!empty($aLIas_pinyin) && !empty($parentAlias)) {
  2164. $result['path'] = "/{$parentAlias}/{$aLIas_pinyin}/";
  2165. }
  2166. return $result;
  2167. })->values()->all();
  2168. if (empty($category)) {
  2169. return Result::error("暂无此导航", 0);
  2170. }
  2171. return Result::success($category);
  2172. }
  2173. /**
  2174. * 获取网站栏目信息
  2175. * @param array $data
  2176. */
  2177. public function getWebsiteFootAll(array $data): array
  2178. {
  2179. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  2180. if (empty($website)) {
  2181. return Result::error("暂无该网站", 0);
  2182. }
  2183. // 1:图片 2:文字 3:底部
  2184. $result['foot_cate'] = FooterCategory::where('website_id', $data['website_id'])->get()->all();
  2185. $result['link_img'] = Link::where('website_id', $data['website_id'])->where('type', 1)->where('status', 1)->limit($data['link_imgnum'])->orderBy('sort')->get()->all();
  2186. $result['link_text'] = Link::where('website_id', $data['website_id'])->where('type', 2)->where('status', 1)->limit($data['link_textnum'])->orderBy('sort')->get()->all();
  2187. $result['link_foot'] = Link::where('website_id', $data['website_id'])->where('type', 3)->where('status', 1)->limit($data['link_footnum'])->orderBy('sort')->get()->all();
  2188. $result['foot_info'] = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  2189. if (empty($result)) {
  2190. return Result::error("暂无此网站信息", 0);
  2191. }
  2192. return Result::success($result);
  2193. }
  2194. /**
  2195. * 获取网站顶部信息
  2196. * @param array $data
  2197. */
  2198. public function getWebsiteHead(array $data): array
  2199. {
  2200. $result = Website::where('id', $data['website_id'])->where('status', 1)->select('website_name', 'logo')->first();
  2201. if (empty($result)) {
  2202. return Result::error("暂无该网站", 0);
  2203. }
  2204. return Result::success($result);
  2205. }
  2206. /**
  2207. * 路由匹配
  2208. * @param array $data
  2209. */
  2210. public function getWebsiteRoute(array $data): array
  2211. {
  2212. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  2213. if (empty($website)) {
  2214. return Result::error("暂无该网站", 0);
  2215. }
  2216. if (isset($data['pinyin']) &&!empty($data['pinyin'])) {
  2217. $result = WebsiteCategory::where('website_category.website_id', $data['website_id'])
  2218. ->where('website_category.aLIas_pinyin', $data['pinyin'])
  2219. ->leftJoin('website_category as pc', function ($join) use ($data) {
  2220. $join->on('pc.pid', '=', 'website_category.category_id')
  2221. ->where('pc.website_id', '=', $data['website_id']);
  2222. })
  2223. ->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'))
  2224. ->first();
  2225. }
  2226. if(isset($data['foot_pinyin']) &&!empty($data['foot_pinyin'])){
  2227. $result = FooterCategory::where('website_id',$data['website_id'])->where('name_pinyin',$data['foot_pinyin'])->first(['id']);
  2228. }
  2229. if (!isset($result) || empty($result)) {
  2230. return Result::error("暂无该导航", 0);
  2231. }
  2232. return Result::success($result);
  2233. }
  2234. //20250212 网站标识
  2235. public function addWebsiteGroup(array $data): array
  2236. {
  2237. //判斷name是不是重复
  2238. $websiteGroupInfo = WebsiteGroup::query()->where('name', $data['name'])->first();
  2239. if (!empty($websiteGroupInfo)) {
  2240. return Result::error("网站标识重复", 0);
  2241. }
  2242. //添加信息
  2243. $result = WebsiteGroup::insertGetId($data);
  2244. var_dump($result);
  2245. if (empty($result)) {
  2246. return Result::error("创建失败", 0);
  2247. } else {
  2248. return Result::success($result);
  2249. }
  2250. }
  2251. public function getWebsiteGroupList(array $data): array
  2252. {
  2253. $where = [];
  2254. if (isset($data['name']) && !empty($data['name'])) {
  2255. array_push($where, ['website_group.name', 'like', '%' . $data['name'] . '%']);
  2256. }
  2257. $result = WebsiteGroup::where($where)
  2258. ->limit($data['pageSize'])->orderBy("id", "desc")->offset(($data['page'] - 1) * $data['pageSize'])
  2259. ->get();
  2260. foreach ($result as $websiteGroup) {
  2261. $webIds = json_decode($websiteGroup->web_ids, true);
  2262. $websites = Website::whereIn('id', $webIds)->get();
  2263. $websiteNames = $websites->pluck('website_name', 'id')->toArray();
  2264. $websiteGroup->website_names = $websiteNames;
  2265. $websiteGroup->website_names1 = implode(',', array_values($websiteNames));
  2266. }
  2267. $count = WebsiteGroup::where($where)->count();
  2268. if (empty($result)) {
  2269. return Result::error("没有数据", 0);
  2270. }
  2271. return Result::success(['list' => $result->toArray(), 'count' => $count]);
  2272. }
  2273. public function getWebsiteGroupInfo(array $data): array
  2274. {
  2275. $websiteInfo = WebsiteGroup::query()->where('id', $data['id'])->first();
  2276. $webIds = json_decode($websiteInfo->web_ids, true);
  2277. $websites = Website::whereIn('id', $webIds)->get();
  2278. $websiteNames = $websites->pluck('website_name', 'id')->toArray();
  2279. $websiteInfo->website_names = $websiteNames;
  2280. $websiteInfo->website_names1 = implode(',', array_values($websiteNames));
  2281. if (empty($websiteInfo)) {
  2282. return Result::error("找不到URL", 0);
  2283. }
  2284. return Result::success($websiteInfo->toArray());
  2285. }
  2286. public function updateWebsiteGroup(array $data): array
  2287. {
  2288. $where = [
  2289. 'id' => $data['id'],
  2290. ];
  2291. $insertData = [
  2292. 'name' => $data['name'],
  2293. 'web_ids' => $data['web_ids'],
  2294. ];
  2295. //判斷name是不是重复
  2296. $websiteGroupInfo = WebsiteGroup::query()->where('name', $data['name'])->first();
  2297. if (!empty($websiteGroupInfo) && $websiteGroupInfo->id != $data['id']) {
  2298. return Result::error("网站标识重复", 0);
  2299. }
  2300. $result = WebsiteGroup::where($where)->update($insertData);
  2301. var_dump($result, '------更新');
  2302. if (empty($result)) {
  2303. return Result::error("更新失败", 0);
  2304. } else {
  2305. return Result::success();
  2306. }
  2307. }
  2308. public function deleteWebsiteGroup(array $data): array
  2309. {
  2310. $where = [
  2311. 'id' => $data['id'],
  2312. ];
  2313. //看看user表是不是有这个id
  2314. $userGroup = User::query()->where('sszq', $data['id'])->first();
  2315. if (!empty($userGroup)) {
  2316. return Result::error("有用户在使用该网站标识,不能删除", 0);
  2317. }
  2318. $result = WebsiteGroup::where($where)->delete();
  2319. if (empty($result)) {
  2320. return Result::error("删除失败", 0);
  2321. } else {
  2322. return Result::success();
  2323. }
  2324. }
  2325. public function getWebsiteNavList(array $data): array
  2326. {
  2327. $data['type'] = isset($data['type']) ? $data['type'] : 1;
  2328. $where = [];
  2329. if (isset($data['website_id']) && !empty($data['website_id'])) {
  2330. array_push($where, ['website_id', '=', $data['website_id']]);
  2331. }
  2332. if (isset($data['pid'])) {
  2333. array_push($where, ['pid', '=', $data['pid']]);
  2334. }
  2335. if (isset($data['type']) && !empty($data['type'])) {
  2336. array_push($where, ['type', '=', $data['type']]);
  2337. }
  2338. // 根据站点和type获取websiteCategory 中的id
  2339. $websiteCategoryids = WebsiteCategory::query()
  2340. ->where('website_id', '=', $data['website_id'])
  2341. ->where('type', '=', $data['type'])
  2342. ->pluck('category_arr_id')->toArray();
  2343. var_dump($websiteCategoryids, '------获取websiteCategory 中的id');
  2344. //合并去重
  2345. $category_ids = [];
  2346. foreach ($websiteCategoryids as $key => $value) {
  2347. $v = json_decode($value, true);
  2348. $category_ids = array_unique(array_merge($category_ids, $v));
  2349. }
  2350. // var_dump($category_ids, '------获取websiteCategory 中的id');
  2351. //根据pid取出所有的websiteCategory 中的id
  2352. $list = WebsiteCategory::query()
  2353. ->where('website_id', '=', $data['website_id'])
  2354. ->where('pid', '=', $data['pid'])
  2355. ->whereIn('category_id', $category_ids)
  2356. ->get();
  2357. if (empty($list)) {
  2358. return Result::error("获取失败", 0);
  2359. } else {
  2360. return Result::success($list);
  2361. }
  2362. }
  2363. // 20250307 根据网站标识获和导航获取站点
  2364. public function getWebsiteNavPoolSite(array $data): array
  2365. {
  2366. $where = [];
  2367. if (isset($data['category_id']) && !empty($data['category_id'])) {
  2368. array_push($where, ['category_id', '=', $data['category_id']]);
  2369. }
  2370. $list = WebsiteCategory::query()->where($where)
  2371. ->leftJoin('website', 'website.id', '=', 'website_category.website_id')
  2372. ->select('website_category.*', 'website.website_name')
  2373. ->distinct()
  2374. ->get();
  2375. if (empty($list)) {
  2376. return Result::error("获取失败", 0);
  2377. } else {
  2378. return Result::success($list);
  2379. }
  2380. }
  2381. public function getWebsiteNavPool(array $data): array
  2382. {
  2383. // 初始化查询条件数组
  2384. $query = WebsiteCategory::query();
  2385. // 如果传入了 websiteids,则添加到查询条件中
  2386. if (isset($data['websiteids']) && !empty($data['websiteids'])) {
  2387. $query->whereIn('website_id', $data['websiteids']);
  2388. }
  2389. // 如果传入了 pid,则添加到查询条件中
  2390. if (isset($data['pid'])) {
  2391. $query->where('pid', '=', $data['pid']);
  2392. }
  2393. // 执行查询 唯一性 id
  2394. $list = $query->distinct()->get();
  2395. // 根据查询结果返回相应的结果
  2396. if ($list->isEmpty()) {
  2397. return Result::error("获取失败", 0);
  2398. } else {
  2399. return Result::success($list->toArray());
  2400. }
  2401. }
  2402. /**
  2403. *
  2404. * @param array $data
  2405. * @return array
  2406. */
  2407. public function getAllCategory(array $data): array
  2408. {
  2409. $result = Category::when($data, function ($query) use ($data) {
  2410. if (isset($data['name']) && !empty($data['name'])) {
  2411. $query->where('category.name', 'like', '%' . trim($data['name']) . '%');
  2412. }
  2413. })->get();
  2414. if (empty($result)) {
  2415. return Result::error("获取失败", 0);
  2416. } else {
  2417. return Result::success($result);
  2418. }
  2419. }
  2420. /**
  2421. * 修改网站栏目排序
  2422. * @param array $data
  2423. * @return array
  2424. */
  2425. public function upWebsiteCategorySort(array $data): array
  2426. {
  2427. $where = [
  2428. 'website_id' => $data['website_id'],
  2429. 'id' => $data['id'],
  2430. ];
  2431. $result = WebsiteCategory::where($where)->update($data);
  2432. if ($result) {
  2433. return Result::success($result);
  2434. } else {
  2435. return Result::error("更新失败", 0);
  2436. }
  2437. }
  2438. // --自助建站-----------20250522fr----------------------start
  2439. /**
  2440. * 获取网站模板下的板块信息
  2441. * @param array $data
  2442. * @return array
  2443. */
  2444. public function getStaticResourceList(array $data): array
  2445. {
  2446. // return Result::success($data);
  2447. $where = [];
  2448. if(isset($data['img_alias']) &&!empty($data['img_alias'])){
  2449. array_push($where, ['website_img.img_alias', 'like', '%'. $data['img_alias']. '%']);
  2450. }
  2451. if(isset($data['img_type']) &&!empty($data['img_type'])){
  2452. array_push($where, ['website_img.img_type', '=', $data['img_type']]);
  2453. }
  2454. if(isset($data['website_name']) &&!empty($data['website_name'])){
  2455. $website = Website::where('website_name','like','%'.$data['website_name'].'%')->first();
  2456. if(empty($website)){
  2457. return Result::error("没有查找到相关数据", 0);
  2458. }else{
  2459. array_push($where, ['website_img.website_id', '=', $website['id']]);
  2460. }
  2461. }
  2462. // return Result::success($where);
  2463. $query = WebsiteImg::when(!empty($where), function ($query) use ($where) {
  2464. $query->where($where);
  2465. })
  2466. ->orderBy('updated_at', 'desc');
  2467. $count = $query->count();
  2468. $row = $query->leftJoin('website', 'website.id', '=', 'website_img.website_id')
  2469. ->select('website_img.*', 'website.website_name')
  2470. ->limit($data['pageSize'])
  2471. ->offset(($data['page'] - 1) * $data['pageSize'])
  2472. ->get();
  2473. if (empty($row)) {
  2474. return Result::error("没有查找到相关数据", 0);
  2475. } else {
  2476. $result = [
  2477. 'row' => $row,
  2478. 'count' => $count,
  2479. ];}
  2480. return Result::success($result);
  2481. }
  2482. /**
  2483. * 添加网站模板下的板块信息
  2484. * @param array $data
  2485. */
  2486. public function addStaticResource(array $data): array
  2487. {
  2488. // $file = $data['img_url']->file('image');
  2489. // $size = $file->getSize();
  2490. $img_data = [
  2491. 'website_id' => $data['website_id'] ?? 0,
  2492. 'img_alias' => $data['img_alias'] ?? '',
  2493. 'img_url' => $data['img_url'],
  2494. 'img_size' => $data['img_size'],
  2495. ];
  2496. $img = WebsiteImg::insertGetId($img_data);
  2497. if (empty($img)) {
  2498. return Result::error("添加失败", 0);
  2499. }
  2500. $img_id['id'] = $img;
  2501. $url = WebsiteImg::where($img_id)->value('img_url');
  2502. // 1. 分割路径部分(以 / 为分隔符)
  2503. $pathSegments = explode('/', parse_url($url, PHP_URL_PATH));
  2504. // 2. 取最后一个元素作为文件名
  2505. $fileName = end($pathSegments); // 1743041040714597.jpg
  2506. // 3. 分割文件名获取扩展名
  2507. $fileParts = explode('.', $fileName);
  2508. $fileType = end($fileParts); // jpg
  2509. $img_datas = [
  2510. 'img_type' => $fileType,
  2511. 'name' => $fileName
  2512. ];
  2513. $up_img = WebsiteImg::where($img_id)->update($img_datas);
  2514. if (empty($up_img)) {
  2515. return Result::error("修改失败", 0);
  2516. }
  2517. return Result::success($up_img);
  2518. // 将字节转换为更友好的单位
  2519. // $friendlySize = $this->formatFileSize($size);
  2520. // $data['img_size'] = $friendlySize;
  2521. }
  2522. /**
  2523. * 修改网站模板下的板块信息
  2524. * @param array $data
  2525. */
  2526. public function delStaticResource(array $data): array
  2527. {
  2528. $where = [
  2529. 'id' => $data['id'],
  2530. ];
  2531. $result = WebsiteImg::where($where)->delete();
  2532. if (empty($result)) {
  2533. return Result::error("修改失败", 0);
  2534. }
  2535. return Result::success($result);
  2536. }
  2537. /**
  2538. * 获取尺寸列表
  2539. * @param array $data
  2540. */
  2541. public function getSizeList(array $data): array
  2542. {
  2543. $where = [];
  2544. if(isset($data['width']) &&!empty($data['width'])){
  2545. array_push($where, ['width','like','%'.$data['width'].'%']);
  2546. }
  2547. if(isset($data['height']) &&!empty($data['height'])){
  2548. array_push($where, ['height','like','%'.$data['height'].'%']);
  2549. }
  2550. $query = Size::when($where, function ($query) use ($where) {
  2551. $query->where($where);
  2552. })
  2553. ->orderBy('updated_at', 'desc');
  2554. $count = $query->count();
  2555. $rep = $query
  2556. ->offset(($data['page'] - 1) * $data['pageSize'])
  2557. ->limit($data['pageSize'])
  2558. ->get();
  2559. $result = [
  2560. 'row' => $rep,
  2561. 'count' => $count,
  2562. ];
  2563. if (empty($result)) {
  2564. return Result::error("获取失败", 0);
  2565. } else {
  2566. return Result::success($result);
  2567. }
  2568. }
  2569. /**
  2570. * 添加尺寸
  2571. * @param array $data
  2572. */
  2573. public function addSize(array $data): array
  2574. {
  2575. $size = Size::where('width', $data['width'])->where('height', $data['height'])->first();
  2576. if (!empty($size)) {
  2577. return Result::error("尺寸已存在", 0);
  2578. }
  2579. $result = Size::insertGetId($data);
  2580. if (empty($result)) {
  2581. return Result::error("添加失败", 0);
  2582. }
  2583. return Result::success($result);
  2584. }
  2585. /**
  2586. * 删除尺寸
  2587. * @param array $data
  2588. */
  2589. public function delSize(array $data): array
  2590. {
  2591. $where = [
  2592. 'id' => $data['id'],
  2593. ];
  2594. $result = Size::where($where)->delete();
  2595. if (empty($result)) {
  2596. return Result::error("删除失败", 0);
  2597. }
  2598. return Result::success($result);
  2599. }
  2600. /**
  2601. * 修改尺寸
  2602. * @param array $data
  2603. */
  2604. public function upSize(array $data): array
  2605. {
  2606. $where = [
  2607. 'id' => $data['id'],
  2608. ];
  2609. $size = Size::where('id','!=', $data['id'])->where('width',$data['width'])->where('height',$data['height'])->first();
  2610. if (!empty($size)) {
  2611. return Result::error("尺寸已存在", 0);
  2612. }
  2613. $result = Size::where($where)->update($data);
  2614. if (empty($result)) {
  2615. return Result::error("修改失败", 0);
  2616. }
  2617. return Result::success($result);
  2618. }
  2619. /**
  2620. * 获取尺寸详情
  2621. * @param array $data
  2622. */
  2623. public function getSizeInfo(array $data): array
  2624. {
  2625. $where = [
  2626. 'id' => $data['id'],
  2627. ];
  2628. $result = Size::where($where)->first();
  2629. if (empty($result)) {
  2630. return Result::error("获取失败", 0);
  2631. } else {
  2632. return Result::success($result);
  2633. }
  2634. }
  2635. // --自助建站-----------20250522fr----------------------end
  2636. }