WebsiteService.php 114 KB

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