WebsiteService.php 114 KB

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