WebsiteService.php 108 KB

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