WebsiteService.php 114 KB

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