WebsiteService.php 88 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438
  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Model\AdSize;
  4. use App\Model\Article;
  5. use App\Model\Ad;
  6. use App\Model\Category;
  7. use App\Model\AdPlace;
  8. use App\Model\Department;
  9. use App\Model\District;
  10. use App\Model\FooterCategory;
  11. use App\Model\FooterContent;
  12. use App\Model\LetterOfComplaint;
  13. use App\Model\Link;
  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\Sector;
  23. use Hyperf\DbConnection\Db;
  24. use Hyperf\RpcServer\Annotation\RpcService;
  25. use App\Tools\Result;
  26. use Carbon\Carbon;
  27. use App\Model\WebsiteCategory;
  28. use App\Model\WebsiteTemplate;
  29. use App\Model\WebsiteTemplateInfo;
  30. use Hamcrest\Arrays\IsArray;
  31. use PhpParser\Node\Stmt\Return_;
  32. use App\Model\WebsiteGroup;
  33. use function PHPUnit\Framework\isNull;
  34. use App\Model\Component;
  35. // use Illuminate\Support\Facades\DB;
  36. #[RpcService(name: "WebsiteService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  37. class WebsiteService implements WebsiteServiceInterface
  38. {
  39. /**
  40. * @param string $keyword
  41. * @param int $page
  42. * @param int $pageSize
  43. * @return array
  44. */
  45. public function getWebsitetList(array $data): array
  46. {
  47. // 构建查询
  48. $query = Website::when($data, function ($query) use ($data) {
  49. if (isset($data['keyword']) && !empty($data['keyword'])) {
  50. $query->where('website.website_name', 'like', '%' . trim($data['keyword']) . '%');
  51. }
  52. if (isset($data['website_column_id']) && !empty($data['website_column_id'])) {
  53. $query->whereJsonContains("website.website_column_arr_id", intval($data['website_column_id']));
  54. }
  55. if (isset($data['city_id']) && !empty($data['city_id'])) {
  56. $query->whereJsonContains("website.city_arr_id", intval($data['city_id']));
  57. }
  58. });
  59. // 执行查询并获取总数和结果
  60. $queryWithJoins = $query->leftJoin("website_column", "website.website_column_id", "website_column.id")
  61. ->leftJoin("district", "district.id", "website.city_id");
  62. $count = $queryWithJoins->count();
  63. $result = $queryWithJoins->select("website.*", "website_column.column_name", "district.name as city_name")
  64. ->limit($data['pageSize'])
  65. ->offset(($data['page'] - 1) * $data['pageSize'])
  66. ->orderBy("website.updated_at", "desc")
  67. ->get();
  68. if (empty($result)) {
  69. return Result::error("没有数据", 0);
  70. }
  71. $data = [
  72. 'rows' => $result->toArray(),
  73. 'count' => $count,
  74. ];
  75. return Result::success($data);
  76. }
  77. /**
  78. * @param array $data
  79. * @return array
  80. */
  81. public function createWebsite(array $data): array
  82. {
  83. var_dump("网站数据:", $data);
  84. $insertData = [
  85. 'website_name' => $data['website_name'],
  86. 'logo' => $data['logo'] ?? '',
  87. 'website_url' => $data['website_url'] ?? '',
  88. // 'city_id'=>$data['city_id']??0,
  89. 'website_column_id' => $data['website_column_id'],
  90. 'title' => $data['title'] ?? '',
  91. 'keywords' => $data['keywords'] ?? '',
  92. 'description' => $data['description'] ?? '',
  93. 'status' => $data['status'] ?? 1,
  94. 'website_column_arr_id' => $data['website_column_arr_id'],
  95. // 'city_arr_id'=>$data['city_arr_id']??[0],
  96. 'template_id' => $data['template_id'] ?? 0,
  97. 'suffix' => $data['suffix'] ??"",
  98. ];
  99. $result = Website::insertGetId($insertData);
  100. if (empty($result)) {
  101. return Result::error("创建失败", 0);
  102. } else {
  103. return Result::success(["id" => $result]);
  104. }
  105. }
  106. /**
  107. * @param int $id
  108. * @param array $data
  109. * @return array
  110. */
  111. public function updateWebsite(int $id, array $data): array
  112. {
  113. $insertData = [
  114. 'website_name' => $data['website_name'],
  115. 'logo' => $data['logo'] ?? '',
  116. 'website_url' => $data['website_url'] ?? '',
  117. // 'city_id'=>$data['city_id']??0,
  118. 'website_column_id' => $data['website_column_id'],
  119. 'title' => $data['title'] ?? '',
  120. 'keywords' => $data['keywords'] ?? '',
  121. 'description' => $data['description'] ?? '',
  122. // 'status' => $data['status'] ?? 0,
  123. 'website_column_arr_id' => $data['website_column_arr_id'],
  124. // 'city_arr_id'=>$data['city_arr_id']??[0],
  125. 'template_id' => $data['template_id'] ?? 0,
  126. 'suffix' => $data['suffix'] ??"",
  127. ];
  128. var_dump("=========:",$insertData);
  129. $result = Website::where('id', $id)->update($insertData);
  130. var_dump("更新站点", $result);
  131. if (empty($result)) {
  132. return Result::error("更新失败", 0);
  133. } else {
  134. return Result::success();
  135. }
  136. }
  137. /**
  138. * @param int $id
  139. * @return array
  140. */
  141. public function delWebsite(int $id): array
  142. {
  143. $result = Website::where('id', $id)->delete();
  144. if (empty($result)) {
  145. return Result::error("删除失败", 0);
  146. } else {
  147. return Result::success();
  148. }
  149. }
  150. /**
  151. * @param int $id
  152. * @return array
  153. */
  154. public function getWebsiteInfo(int $id): array
  155. {
  156. $where = [
  157. ['website.id', '=', $id],
  158. ];
  159. $result = Website::where($where)
  160. ->leftJoin("template", "template.id", "website.template_id")
  161. ->select("website.*", "template.template_name", "template.template_img")
  162. ->first();
  163. if (empty($result)) {
  164. return Result::error("数据不存在", 0);
  165. } else {
  166. return Result::success($result->toArray());
  167. }
  168. }
  169. /**
  170. * 查询所有的站点栏目
  171. * @return array
  172. */
  173. public function getWebsiteColumn(array $data): array
  174. {
  175. $result = WebsiteColumn::where($data)->get();
  176. if (empty($result)) {
  177. return Result::error("数据不存在", 0);
  178. } else {
  179. return Result::success($result->toArray());
  180. }
  181. }
  182. /**
  183. * @param string $keyword
  184. * @param int $page
  185. * @param int $pageSize
  186. * @return array
  187. */
  188. public function getWebsiteColumnList(array $data): array
  189. {
  190. $where = [];
  191. if (isset($data['keyword']) && $data['keyword']) {
  192. array_push($where, ['website_column.column_name', 'like', '%' . $data['keyword'] . '%']);
  193. }
  194. $result = WebsiteColumn::where($where)
  195. ->leftJoin("website_column as wc", "website_column.pid", "wc.id")
  196. ->select("website_column.*", "wc.column_name as parent_column_name")
  197. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->get();
  198. $count = WebsiteColumn::where($where)->count();
  199. if (empty($result)) {
  200. return Result::error("没有数据", 0);
  201. }
  202. $data = [
  203. 'rows' => $result->toArray(),
  204. 'count' => $count,
  205. ];
  206. return Result::success($data);
  207. }
  208. /**
  209. * @param array $data
  210. * @return array
  211. */
  212. public function createWebsiteColumn(array $data): array
  213. {
  214. $insertData = [
  215. 'column_name' => $data['column_name'],
  216. 'pid' => $data['pid'] ?? '',
  217. 'column_arr_id' => $data['column_arr_id'] ?? [0],
  218. 'sort' => $data['sort'] ?? 0,
  219. 'remark' => $data['remark'] ?? '',
  220. ];
  221. $result = WebsiteColumn::insertGetId($insertData);
  222. if (empty($result)) {
  223. return Result::error("创建失败", 0);
  224. } else {
  225. return Result::success(["id" => $result]);
  226. }
  227. }
  228. /**
  229. * @param int $id
  230. * @param array $data
  231. * @return array
  232. */
  233. public function updateWebsiteColumn(int $id, array $data): array
  234. {
  235. $insertData = [
  236. 'column_name' => $data['column_name'],
  237. 'pid' => $data['pid'] ?? '',
  238. 'column_arr_id' => $data['column_arr_id'] ?? [0],
  239. 'sort' => $data['sort'] ?? 0,
  240. 'remark' => $data['remark'] ?? '',
  241. ];
  242. $result = WebsiteColumn::where('id', $id)->update($insertData);
  243. if (empty($result)) {
  244. return Result::error("更新失败", 0);
  245. } else {
  246. return Result::success();
  247. }
  248. }
  249. /**
  250. * @param int $id
  251. * @return array
  252. */
  253. public function delWebsiteColumn(int $id): array
  254. {
  255. $list = WebsiteColumn::where(['pid' => $id])->get();
  256. if ($list) {
  257. return Result::error("存在子网系,不能删除,请先删除子网系", 0);
  258. }
  259. $result = WebsiteColumn::where('id', $id)->delete();
  260. if (empty($result)) {
  261. return Result::error("删除失败", 0);
  262. } else {
  263. return Result::success();
  264. }
  265. }
  266. /**
  267. * @param string $keyword
  268. * @param int $page
  269. * @param int $pageSize
  270. * @return array
  271. */
  272. public function getWebsiteRoleList(string $keyword, int $page, int $pageSize, int $websiteId): array
  273. {
  274. $where = [
  275. ['role.role_name', 'like', '%' . $keyword . '%'],
  276. ['website_role.website_id', '=', $websiteId],
  277. ];
  278. $result = WebsiteRole::where($where)
  279. ->leftJoin("role", "role.id", "website_role.role_id")
  280. ->select("role.*", "website_role.type", "website_role.role_id", "website_role.id as website_role_id", "website_role.website_id")
  281. ->limit($pageSize)->offset(($page - 1) * $pageSize)->get();
  282. $count = WebsiteRole::where($where)->leftJoin("role", "role.id", "website_role.role_id")->count();
  283. if (empty($result)) {
  284. return Result::error("没有数据", 0);
  285. }
  286. $data = [
  287. 'rows' => $result->toArray(),
  288. 'count' => $count,
  289. ];
  290. return Result::success($data);
  291. }
  292. /**
  293. * @param array $data
  294. * @return array
  295. */
  296. public function createWebsiteRole(array $data): array
  297. {
  298. $insertData = [
  299. 'website_id' => $data['website_id'],
  300. 'role_id' => $data['role_id'] ?? '',
  301. ];
  302. $info = WebsiteRole::where($insertData)->first();
  303. if ($info) {
  304. return Result::error("不能重复添加角色", 0);
  305. }
  306. $insertData['admin_user_id'] = $data['admin_user_id'] ?? '';
  307. $insertData['type'] = $data['type'] ?? '';
  308. $result = WebsiteRole::insertGetId($insertData);
  309. if (empty($result)) {
  310. return Result::error("创建失败", 0);
  311. } else {
  312. return Result::success(["id" => $result]);
  313. }
  314. }
  315. /**
  316. * 暂时用不上
  317. * @param int $id
  318. * @param array $data
  319. * @return array
  320. */
  321. public function updateWebsiteRole(int $id, array $data): array
  322. {
  323. $insertData = [
  324. 'website_id' => $data['website_id'],
  325. 'type' => $data['type'] ?? '',
  326. ];
  327. $result = WebsiteRole::where('id', $id)->update($insertData);
  328. if (empty($result)) {
  329. return Result::error("更新失败", 0);
  330. } else {
  331. return Result::success();
  332. }
  333. }
  334. /**
  335. * @param int $id
  336. * @return array
  337. */
  338. public function delWebsiteRole(int $id): array
  339. {
  340. $result = WebsiteRole::where('id', $id)->delete();
  341. if (empty($result)) {
  342. return Result::error("删除失败", 0);
  343. } else {
  344. return Result::success();
  345. }
  346. }
  347. /**
  348. * @param string $keyword
  349. * @param int $page
  350. * @param int $pageSize
  351. * @return array
  352. */
  353. public function getWebsiteRoleUserList(string $keyword, int $page, int $pageSize, int $websiteId, int $roleId): array
  354. {
  355. $where = [
  356. ['website_role_user.website_id', '=', $websiteId],
  357. ['website_role_user.role_id', '=', $roleId],
  358. ];
  359. $count = WebsiteRoleUser::where($where)->count();
  360. $where[] = ['u.user_name', 'like', '%' . $keyword . '%'];
  361. $result = WebsiteRoleUser::where($where)
  362. ->leftJoin("user as u", "website_role_user.user_id", "u.id")
  363. ->leftJoin("website as w", "website_role_user.website_id", "u.id")
  364. ->leftJoin("role as r", "website_role_user.role_id", "r.id")
  365. ->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')
  366. ->limit($pageSize)->offset(($page - 1) * $pageSize)->get();
  367. if (empty($result)) {
  368. return Result::error("没有数据", 0);
  369. }
  370. $data = [
  371. 'rows' => $result->toArray(),
  372. 'count' => $count,
  373. ];
  374. return Result::success($data);
  375. }
  376. /**
  377. * @param array $data
  378. * @return array
  379. */
  380. public function createWebsiteRoleUser(array $data): array
  381. {
  382. $insertData = [
  383. 'website_id' => $data['website_id'],
  384. 'user_id' => $data['user_id'] ?? '',
  385. ];
  386. $info = WebsiteRoleUser::where($insertData)->first();
  387. if ($info) {
  388. return Result::error("不能重复添加角色用户", 0);
  389. }
  390. $insertData['role_id'] = $data['role_id'] ?? '';
  391. $insertData['admin_user_id'] = $data['admin_user_id'] ?? '';
  392. $insertData['type'] = $data['type'] ?? '';
  393. $result = WebsiteRoleUser::insertGetId($insertData);
  394. if (empty($result)) {
  395. return Result::error("创建失败", 0);
  396. } else {
  397. return Result::success(["id" => $result]);
  398. }
  399. }
  400. /**
  401. * @param int $id
  402. * @param array $data
  403. * @return array
  404. */
  405. public function updateWebsiteRoleUser(int $id, array $data): array
  406. {
  407. $insertData = [
  408. 'website_id' => $data['website_id'],
  409. 'type' => $data['type'] ?? '',
  410. 'type_id' => $data['type_id'] ?? '',
  411. 'role_id' => $data['role_id'] ?? '',
  412. ];
  413. $result = WebsiteRoleUser::where('id', $id)->update($insertData);
  414. if (empty($result)) {
  415. return Result::error("更新失败", 0);
  416. } else {
  417. return Result::success();
  418. }
  419. }
  420. /**
  421. * @param int $id
  422. * @return array
  423. */
  424. public function delWebsiteRoleUser(int $id): array
  425. {
  426. $result = WebsiteRoleUser::where('id', $id)->delete();
  427. if (empty($result)) {
  428. return Result::error("删除失败", 0);
  429. } else {
  430. return Result::success();
  431. }
  432. }
  433. /**
  434. * 根据域名获取网站 站点id
  435. * @param array $data
  436. * @return array
  437. */
  438. public function getWebsiteId(array $data): array
  439. {
  440. $result = Website::whereJsonContains('website_url', $data['website_url'])->first();
  441. if (empty($result)) {
  442. return Result::error("查询站点失败", 0);
  443. } else {
  444. return Result::success($result);
  445. }
  446. }
  447. /**
  448. * 查询网站下面的导航
  449. * @param array $data
  450. * @return array
  451. */
  452. public function getWebsiteCategory(array $data): array
  453. {
  454. $where = [
  455. 'website_id' => $data['website_id'],
  456. ];
  457. // 使用递归查询构建树状结构
  458. $category = WebsiteCategory::where($where)
  459. ->with([
  460. 'children' => function ($query) {
  461. $query->orderBy('sort', 'asc');
  462. },
  463. ])
  464. ->orderBy('sort', 'asc')
  465. ->where('pid', 0) // 仅查询顶级节点
  466. ->get()->all();
  467. if (empty($category)) {
  468. return Result::error("查询站点栏目失败", 0);
  469. } else {
  470. $count = WebsiteCategory::where($where)->count();
  471. $result = [
  472. 'rep' => $category,
  473. 'count' => $count,
  474. ];
  475. return Result::success($result);
  476. }
  477. }
  478. /**
  479. * 查询网站的广告
  480. * @param array $data
  481. * @return array
  482. */
  483. public function getWebsiteAdvertisement(array $data): array
  484. {
  485. $where = [
  486. 'website_id' => $data['website_id'],
  487. 'ad_place.status' => 1,
  488. // 'ad.status' => 1,
  489. ];
  490. if (isset($data['ad_tag']) && !empty($data['ad_tag'])) {
  491. $now = Carbon::now()->format('Y-m-d H:i:s'); // 获取当前时间
  492. $where[] = ['ad_place.ad_tag', 'like', '%' . $data['ad_tag'] . '%'];
  493. $result = AdPlace::where($where)
  494. ->leftJoin("ad", function ($join) use ($now) {
  495. $join->on("ad.pid", "=", "ad_place.id")
  496. ->where('ad.status', 1)
  497. ->where('ad.fromtime', '<=', $now)
  498. ->where('ad.totime', '>=', $now);
  499. })
  500. ->select("ad_place.*", 'ad.*', "ad_place.id as ad_place_id", "ad.name as ad_name")
  501. ->get()->all();
  502. if (empty($result)) {
  503. return Result::error("此广告位不存在!", 0);
  504. }
  505. } else {
  506. return Result::error("请选择广告位!", 0);
  507. }
  508. return Result::success($result);
  509. }
  510. /**
  511. *
  512. * @param array $data
  513. * @return array
  514. */
  515. /**网站行政职能搜索 */
  516. public function selectWebsiteDepartment(array $data): array
  517. {
  518. $depart = Department::where('pid',0)->orderBy('id','asc')->get();
  519. if(isset($data['keyword']) && !empty($data['keyword'])){
  520. $departments= Department::where('name', 'like', '%' . $data['keyword'] . '%')->get();
  521. if(empty($departments)){
  522. $result['message']="未查询到与此相关职能部门";
  523. }else{
  524. $count = Department::where('name','like',"%{$data['keyword']}%")->count();
  525. $m = [
  526. 'department'=>$depart,
  527. 'type'=>$departments,
  528. 'count'=>$count
  529. ];
  530. }
  531. $result['sele'] = $m;
  532. return Result::success($result['sele']);
  533. }
  534. $result=$depart;
  535. return Result::success($result);
  536. }
  537. /**
  538. * 搜索地区
  539. * @param array $data
  540. * @return array
  541. */
  542. public function selectWebsiteArea(array $data): array
  543. {
  544. // return Result::success($data);
  545. $pid = $data['pid'] ?? 0;
  546. $result = District::where('pid',$pid)->where('status',1)->orderBy('code')->get();
  547. if(empty($result)){
  548. return Result::error("未查询到此地区",0);
  549. }else{
  550. return Result::success($result);
  551. }
  552. }
  553. /**
  554. * 获取栏目
  555. * @param array $data
  556. * @return array
  557. */
  558. public function getWebsiteModelCategory(array $data): array
  559. {
  560. $website_id = [
  561. 'website_category.website_id' => $data['website_id'],
  562. ];
  563. $placeid = $data['placeid'] - 1;
  564. $pid = [
  565. 'website_category.pid' => $data['pid'],
  566. ];
  567. var_dump("=======", $pid);
  568. $num = $data['num'];
  569. // return Result::success($data);
  570. $result = WebsiteCategory::where($website_id)
  571. ->leftJoin("category", 'website_category.category_id', 'category.id')
  572. ->select('website_category.*', 'category.is_url', 'category.web_url')
  573. ->where($pid)
  574. // ->with(['children' => function ($query) use ($data) {
  575. // $query->where('website_category.website_id', $data['website_id']);
  576. // }])
  577. ->orderBy('website_category.sort')
  578. ->offset($placeid)
  579. ->limit($num)
  580. ->get();
  581. foreach ($result as $k => $v) {
  582. $child[$k]['children_countent'] = WebsiteCategory::where($website_id)
  583. ->where('website_category.pid', $v['category_id'])
  584. ->count();
  585. if (!empty($child[$k]['children_countent'])) {
  586. $result[$k]['children_count'] = $child[$k]['children_countent'];
  587. } else {
  588. $result[$k]['children_count'] = 0;
  589. }
  590. }
  591. // return Result::success($result);
  592. if(!empty($result)){
  593. return Result::success($result);
  594. }else{
  595. return Result::error("本网站暂无栏目",0);
  596. }
  597. }
  598. /**
  599. * 获取友情链接
  600. * @param array $data
  601. * @return array
  602. */
  603. public function selectWebsiteLinks(array $data): array
  604. {
  605. $where = [
  606. 'website_id' => $data['website_id'],
  607. 'status' => 1,
  608. 'type' => $data['type'],
  609. ];
  610. $num = $data['num'];
  611. $result = Link::where($where)->orderBy('sort')->limit($num)->get();
  612. if (!empty($result)) {
  613. return Result::success($result);
  614. } else {
  615. return Result::error("本网站暂无此类型友情链接", 0);
  616. }
  617. }
  618. /**
  619. * 网站首页数据统计, 管理员
  620. * @return void
  621. */
  622. public function getAdminIndex(array $data): array
  623. {
  624. var_dump("用户类型:", $data['type_id']);
  625. switch ($data['type_id']) {
  626. case 4:
  627. $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;');
  628. return Result::success($result);
  629. break;
  630. case 10000:
  631. $res = [];
  632. //网站
  633. $res['website']['count'] = 0;
  634. $res['website']['growth_rate'] = 0;
  635. //资讯
  636. $res['article']['count'] = 0;
  637. $res['article']['growth_rate'] = 0;
  638. //导航池
  639. $res['category']['count'] = 0;
  640. $res['category']['growth_rate'] = 0;
  641. //近一月数据
  642. $res['monthArticle'] = [];
  643. //用户类型
  644. $res['userType'] = [];
  645. $res['website']['count'] = Website::where([])->count();
  646. $res['article']['count'] = Article::whereNotIn('status', ['404'])->count();
  647. $res['category']['count'] = Category::where([])->count();
  648. $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;');
  649. $res['userType'] = User::where([])->selectRaw("count(*) as counts,type_id")->groupBy('type_id')->get();
  650. return Result::success($res);
  651. }
  652. return [];
  653. }
  654. /**
  655. * 获取模板类型
  656. * @return void
  657. */
  658. public function getTemplateClass(array $data): array
  659. {
  660. $where = [];
  661. if (isset($data['name']) && $data['name']) {
  662. array_push($where, ['name', 'like', '%' . $data['name'] . '%']);
  663. }
  664. $result = TemplateClass::where($where)->orderBy('sort', 'asc')->get();
  665. if (empty($result)) {
  666. return Result::error("没有模板类型", 0);
  667. } else {
  668. return Result::success($result);
  669. }
  670. }
  671. /**
  672. * 添加模板类型
  673. * @param
  674. * @return void
  675. */
  676. public function addTemplateClass(array $data): array
  677. {
  678. $insertData = [
  679. 'name' => $data['name'],
  680. ];
  681. $result = TemplateClass::insertGetId($insertData);
  682. if (empty($result)) {
  683. return Result::error("创建失败", 0);
  684. } else {
  685. return Result::success(["id" => $result]);
  686. }
  687. }
  688. /**
  689. * 更新模板
  690. * @param array $data
  691. * @return array
  692. */
  693. public function upTemplateClass(array $data): array
  694. {
  695. $where = [
  696. 'id' => $data['id'],
  697. ];
  698. $insertData = [
  699. 'name' => $data['name'],
  700. ];
  701. $result = TemplateClass::where($where)->update($insertData);
  702. if (empty($result)) {
  703. return Result::error("更新失败", 0);
  704. } else {
  705. return Result::success();
  706. }
  707. }
  708. /**
  709. * 删除模板
  710. * @param array $data
  711. * @return array
  712. */
  713. public function delTemplateClass(array $data): array
  714. {
  715. $where = [
  716. 'id' => $data['id'],
  717. ];
  718. $result = TemplateClass::where($where)->delete();
  719. if (empty($result)) {
  720. return Result::error("删除失败", 0);
  721. } else {
  722. return Result::success();
  723. }
  724. }
  725. /**
  726. * 获取分类下的模板
  727. * @param array $data
  728. * @return array
  729. */
  730. public function getTemplate(array $data): array
  731. {
  732. $page = $data['page'];
  733. $pageSize = $data['pageSize'];
  734. $where = [];
  735. if (isset($data['template_class_id']) && $data['template_class_id']) {
  736. array_push($where, ['template_class_id', '=', $data['template_class_id']]);
  737. }
  738. $result = Template::where($where)
  739. ->limit($pageSize)->offset(($page - 1) * $pageSize)->get();
  740. $count = Template::where($where)->count();
  741. if (empty($result)) {
  742. return Result::error("没有数据", 0);
  743. }
  744. $data = [
  745. 'rows' => $result->toArray(),
  746. 'count' => $count,
  747. ];
  748. return Result::success($data);
  749. }
  750. /**
  751. * 创建模板
  752. * @param
  753. * @return void
  754. */
  755. public function addTemplate(array $data): array
  756. {
  757. $insertData = [
  758. 'template_name' => $data['template_name'],
  759. 'template_img' => json_encode($data['template_img']),
  760. 'template_class_id' => $data['template_class_id'],
  761. ];
  762. $result = Template::insertGetId($insertData);
  763. if (empty($result)) {
  764. return Result::error("创建模板失败", 0);
  765. } else {
  766. return Result::success(["id" => $result]);
  767. }
  768. }
  769. /**
  770. * 更新模板
  771. * @param array $data
  772. * @return array
  773. */
  774. public function upTemplate(array $data): array
  775. {
  776. $where = [
  777. 'id' => $data['id'],
  778. ];
  779. $insertData = [
  780. 'template_name' => $data['template_name'],
  781. 'template_img' => json_encode($data['template_img']),
  782. 'template_class_id' => $data['template_class_id'],
  783. ];
  784. $result = Template::where($where)->update($insertData);
  785. if (empty($result)) {
  786. return Result::error("更新模板失败", 0);
  787. } else {
  788. return Result::success();
  789. }
  790. }
  791. /**
  792. * 删除模板
  793. * @param array $data
  794. * @return array
  795. */
  796. public function delTemplate(array $data): array
  797. {
  798. $where = [
  799. 'id' => $data['id'],
  800. ];
  801. $result = Template::where($where)->delete();
  802. if (empty($result)) {
  803. return Result::error("删除模板失败", 0);
  804. } else {
  805. return Result::success();
  806. }
  807. }
  808. /**
  809. * 搜索网站
  810. * @param array $data
  811. * @return array
  812. */
  813. public function websiteList(array $data): array
  814. {
  815. $where = [];
  816. if (isset($data['keyword']) && !empty($data['keyword'])) {
  817. array_push($where, ['website.website_name', 'like', '%' . $data['keyword'] . '%']);
  818. }
  819. $result = Website::where($where)->get();
  820. if ($result) {
  821. return Result::success($result);
  822. } else {
  823. return Result::error("没有网站", 0);
  824. }
  825. }
  826. public function addWebsiteCategory(array $data): array
  827. {
  828. $website_id = $data['website_id'];
  829. $category_arr_id = $data['category_arr_id'];
  830. $categoryList = Category::whereIn('id', $category_arr_id)->get();
  831. $categoryListIds = [];
  832. if ($categoryList) {
  833. foreach ($categoryList->toArray() as $val) {
  834. array_push($categoryListIds, $val['id']);
  835. }
  836. }
  837. $arr = [];
  838. if ($categoryListIds) {
  839. foreach ($categoryListIds as $v) {
  840. $ids = $this->getUnderlingUIds(intval($v));
  841. $ids_arr = explode(",", $ids);
  842. array_push($arr, $ids_arr);
  843. }
  844. }
  845. $mergedArray = [];
  846. foreach ($arr as $subarray) {
  847. $mergedArray = array_merge($mergedArray, $subarray);
  848. }
  849. var_dump("所有:", $arr, $mergedArray);
  850. //查询出所有的分类进行分割插入 组装数据
  851. $categoryListData = Category::whereIn('id', $mergedArray)->get();
  852. $categoryListData = $categoryListData->toArray();
  853. $insertData = [];
  854. if ($categoryListData) {
  855. foreach ($categoryListData as $key => $value) {
  856. $insertData[$key]['website_id'] = $website_id;
  857. $insertData[$key]['name'] = $value['name'];
  858. $insertData[$key]['sort'] = $value['sort'];
  859. $insertData[$key]['pid'] = $value['pid'];
  860. $insertData[$key]['pid_arr'] = $value['pid_arr'];
  861. $insertData[$key]['seo_title'] = $value['seo_title'];
  862. $insertData[$key]['seo_keywords'] = $value['seo_keywords'];
  863. $insertData[$key]['seo_description'] = $value['seo_description'];
  864. $insertData[$key]['alias'] = $value['name'];
  865. $insertData[$key]['category_id'] = $value['id'];
  866. }
  867. }
  868. $result = WebsiteCategory::insert($insertData);
  869. var_dump("插入数据状态:", $result);
  870. if ($result) {
  871. return Result::success($result);
  872. } else {
  873. return Result::error("创建失败", 0);
  874. }
  875. }
  876. /**
  877. * 删除网站导航
  878. * @param array $data
  879. * @return array
  880. */
  881. public function delWebsiteCategory(array $data): array
  882. {
  883. $website_id = $data['website_id'] ?? 0;
  884. $category_id = $data['category_id'] ?? 0;
  885. $ids = $this->getUnderlingUIds(intval($category_id));
  886. $ids_arr = explode(",", $ids);
  887. $result = WebsiteCategory::where(['website_id' => $website_id])->whereIn("category_id", $ids_arr)->delete();
  888. if ($result) {
  889. return Result::success($result);
  890. } else {
  891. return Result::error("删除失败", 0);
  892. }
  893. }
  894. /**
  895. * 获取网站导航
  896. * @param array $data
  897. * @return array
  898. */
  899. public function getAdminWebsiteCategory(array $data): array
  900. {
  901. $where = [
  902. 'website_id' => $data['website_id'],
  903. ];
  904. $result = WebsiteCategory::where($where)->orderBy('sort', 'asc')->get();
  905. $list = [];
  906. if($result){
  907. foreach ($result->toArray() as $val) {
  908. array_push($list, json_decode($val['category_arr_id']));
  909. }
  910. }
  911. if ($result) {
  912. return Result::success($list);
  913. } else {
  914. return Result::error("查询失败", 0);
  915. }
  916. }
  917. /**
  918. * 更新网站导航
  919. * @param array $data
  920. * @return array
  921. */
  922. public function upWebsiteCategory(array $data): array
  923. {
  924. Db::beginTransaction();
  925. try {
  926. if($data['category_arr_id']){
  927. $oldCategoryList = WebsiteCategory::where(['website_id' => $data['website_id']])->get();
  928. if($oldCategoryList){
  929. $oldCategoryList = $oldCategoryList->toArray();
  930. $oldCategoryListIds = [];
  931. foreach ($oldCategoryList as $val) {
  932. array_push($oldCategoryListIds, $val['category_id']);
  933. }
  934. $newCategoryListIds = [];
  935. foreach ($data['category_arr_id'] as $v){
  936. array_push($newCategoryListIds, end($v));
  937. }
  938. $differenceIDS = array_merge(array_diff($oldCategoryListIds, $newCategoryListIds), array_diff($newCategoryListIds, $oldCategoryListIds));
  939. if($differenceIDS){
  940. foreach ($differenceIDS as $v){
  941. WebsiteCategory::where(['website_id' => $data['website_id'], 'category_id' => $v])->delete();
  942. }
  943. }
  944. foreach ($data['category_arr_id'] as $key => $value){
  945. $info = Category::where(['id' => end($value)])->first();
  946. $info = $info->toArray();
  947. // 假设 $data、$value 和 $info 是已经定义好的变量
  948. $attributes = [
  949. 'website_id' => $data['website_id'],
  950. 'category_id' => end($value)
  951. ];
  952. // 先复制一份要更新或创建的数据
  953. $values = [
  954. 'website_id' => $data['website_id'],
  955. 'name' => $info['name']?? '',
  956. 'alias' => $info['name']?? '',
  957. 'sort' => $info['sort']?? 0,
  958. 'pid' => $info['pid']?? 0,
  959. 'pid_arr' => $info['pid_arr']?? json_encode([]),
  960. 'seo_title' => $info['seo_title']?? "",
  961. 'seo_keywords' => $info['seo_keywords']?? "",
  962. 'seo_description' => $info['seo_description']?? "",
  963. 'is_url' => $info['is_url']?? 0,
  964. 'web_url' => $info['web_url']?? '',
  965. 'category_id' => end($value),
  966. 'category_arr_id' => $value? json_encode($value) : json_encode([])
  967. ];
  968. // 检查数据库中是否已有该记录
  969. $existingRecord = WebsiteCategory::where($attributes)->first();
  970. if ($existingRecord && $existingRecord->name) {
  971. unset($values['name']);
  972. }
  973. if ($existingRecord && $existingRecord->sort>=0) {
  974. unset($values['sort']);
  975. }
  976. if ($existingRecord && $existingRecord->seo_title) {
  977. unset($values['seo_title']);
  978. }
  979. if ($existingRecord && $existingRecord->seo_keywords) {
  980. unset($values['seo_keywords']);
  981. }
  982. if ($existingRecord && $existingRecord->seo_description) {
  983. unset($values['seo_description']);
  984. }
  985. if ($existingRecord && $existingRecord->alias) {
  986. unset($values['alias']);
  987. }
  988. // 执行 updateOrCreate 操作
  989. WebsiteCategory::updateOrCreate($attributes, $values);
  990. }
  991. }
  992. }
  993. Db::commit();
  994. return Result::success();
  995. } catch (\Throwable $ex) {
  996. Db::rollBack();
  997. // var_dump($ex->getMessage());
  998. return Result::error("修改失败".$ex->getMessage(), 0);
  999. }
  1000. }
  1001. /**
  1002. * 获取网站列表
  1003. * @param array $data
  1004. * @return array
  1005. */
  1006. public function getWebsiteCategoryList(array $data): array
  1007. {
  1008. $where = [];
  1009. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1010. array_push($where, ['website.website_name', 'like', '%' . $data['keyword'] . '%']);
  1011. }
  1012. if (isset($data['website_column_id']) && !empty($data['website_column_id'])) {
  1013. array_push($where, ['website.website_column_id', '=', $data['website_column_id']]);
  1014. }
  1015. $result = Website::where($where)
  1016. ->with(["websiteCategory" => function ($query) {
  1017. $query->where(['pid' => 0])->select('website_id', 'name', 'alias', 'category_id');
  1018. }])
  1019. ->limit($data['pageSize'])->orderBy("updated_at", "desc")->offset(($data['page'] - 1) * $data['pageSize'])
  1020. ->get();
  1021. $count = Website::where($where)->count();
  1022. if (empty($result)) {
  1023. return Result::error("没有数据", 0);
  1024. }
  1025. $data = [
  1026. 'rows' => $result->toArray(),
  1027. 'count' => $count,
  1028. ];
  1029. if ($result) {
  1030. return Result::success($data);
  1031. } else {
  1032. return Result::error("查询失败", 0);
  1033. }
  1034. }
  1035. /**
  1036. * 删除网站下的所有导航
  1037. * @param array $data
  1038. * @return array
  1039. */
  1040. public function delWebsiteAllCategory(array $data): array
  1041. {
  1042. $website_id = $data['website_id'];
  1043. $result = WebsiteCategory::where(['website_id' => $website_id])->delete();
  1044. if ($result) {
  1045. return Result::success($result);
  1046. } else {
  1047. return Result::error("删除失败", 0);
  1048. }
  1049. }
  1050. /**
  1051. * 获取网站下的某一个导航
  1052. * @param array $data
  1053. * @return array
  1054. */
  1055. public function getWebsiteCategoryOnes(array $data): array
  1056. {
  1057. $website_id = $data['website_id'];
  1058. $category_id = $data['category_id'];
  1059. $result = WebsiteCategory::where(['website_category.website_id' => $website_id, 'website_category.category_id' => $category_id])
  1060. ->first();
  1061. if ($result) {
  1062. return Result::success($result);
  1063. } else {
  1064. return Result::error("查询失败", 0);
  1065. }
  1066. }
  1067. /**
  1068. * 更新网闸下的某一个导航
  1069. * @param array $data
  1070. * @return array
  1071. */
  1072. public function upWebsiteCategoryones(array $data): array
  1073. {
  1074. $where = [
  1075. 'website_id' => $data['website_id'],
  1076. 'category_id' => $data['category_id'],
  1077. ];
  1078. $data['sort'] = $data['sort'] ?? 0;
  1079. $result = WebsiteCategory::where($where)->update($data);
  1080. if ($result) {
  1081. return Result::success($result);
  1082. } else {
  1083. return Result::error("更新失败", 0);
  1084. }
  1085. }
  1086. /**
  1087. * 获取网站下的所有导航(包含子导航)
  1088. * @param array $data
  1089. * @return array
  1090. */
  1091. public function getWebsiteAllCategory(array $data): array
  1092. {
  1093. $where = [];
  1094. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1095. array_push($where, ['website_category.website_id', '=', $data['website_id']]);
  1096. }
  1097. // if (isset($data['name']) && !empty($data['name'])) {
  1098. // array_push($where, ['website_category.name', 'like', '%' . $data['name'] . '%']);
  1099. // }
  1100. // if (isset($data['alias']) && !empty($data['alias'])) {
  1101. // array_push($where, ['website_category.alias', 'like', '%' . $data['alias'] . '%']);
  1102. // }
  1103. // if (isset($data['department_id']) && !empty($data['department_id'])) {
  1104. // array_push($where, ['category.department_id', '=', $data['department_id']]);
  1105. // }
  1106. // if (isset($data['city_id']) && !empty($data['city_id'])) {
  1107. // array_push($where, ['category.city_id', '=', $data['city_id']]);
  1108. // }
  1109. $result = WebsiteCategory::where($where)
  1110. // ->leftJoin("category", 'website_category.category_id', 'category.id')
  1111. // ->leftJoin("department", 'category.department_id', 'department.id')
  1112. // ->leftJoin("district", 'category.city_id', 'district.id')
  1113. // ->select("website_category.*", "department.name as department_name", "district.name as city_name")
  1114. // ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])
  1115. ->orderBy("sort","asc")
  1116. ->get();
  1117. // $count = WebsiteCategory::where($where)
  1118. // ->leftJoin("category", 'website_category.category_id', 'category.id')
  1119. // ->leftJoin("department", 'category.department_id', 'department.id')
  1120. // ->leftJoin("district", 'category.city_id', 'district.id')
  1121. // ->count();
  1122. if (empty($result)) {
  1123. return Result::error("没有数据", 0);
  1124. }
  1125. // $data = [
  1126. // 'rows' => $result->toArray(),
  1127. // 'count' => $count,
  1128. // ];
  1129. if ($result) {
  1130. return Result::success( $result->toArray());
  1131. } else {
  1132. return Result::error("查询失败", 0);
  1133. }
  1134. }
  1135. /**
  1136. * 递归查询数据
  1137. * @param $id
  1138. * @param $ids
  1139. * @return string
  1140. */
  1141. public function getUnderlingUIds($id, $ids = '')
  1142. {
  1143. $back = Category::where(['pid' => $id])->get();
  1144. $back = $back->toArray();
  1145. if (!empty($back) && is_array($back)) {
  1146. foreach ($back as $v) {
  1147. //防止当前人的ID重复去查询,形成恶性循环
  1148. if ($v['id'] == $id) {
  1149. continue;
  1150. }
  1151. $back2 = Category::where(['pid' => $id])->count('id');
  1152. if ($back2 > 0) {
  1153. $ids = $this->getUnderlingUIds($v['id'], $ids);
  1154. } else {
  1155. $ids .= ',' . $v['id'];
  1156. }
  1157. }
  1158. }
  1159. $ids = $id . ',' . $ids . ',';
  1160. $ids = str_replace(',,', ",", $ids);
  1161. $ids = trim($ids, ',');
  1162. return $ids;
  1163. }
  1164. /**
  1165. * 检测网站名称是否重复
  1166. * @param array $data
  1167. * @return array
  1168. */
  1169. public function checkWebsiteName(array $data): array
  1170. {
  1171. if (isset($data['id'])) {
  1172. $data[] = ['id', "!=", $data['id']];
  1173. unset($data['id']);
  1174. }
  1175. $websiteInfo = Website::query()->where($data)->first();
  1176. if (empty($websiteInfo)) {
  1177. return Result::error("找不到网站", 0);
  1178. }
  1179. return Result::success($websiteInfo->toArray());
  1180. }
  1181. /**
  1182. * 检测网站url是否重复
  1183. * @param array $data
  1184. * @return array
  1185. */
  1186. public function checkWebsiteUrl(array $data): array
  1187. {
  1188. $whereData = [];
  1189. if (isset($data['id'])) {
  1190. $whereData = [['id', "!=", $data['id']]];
  1191. unset($data['id']);
  1192. }
  1193. $websiteInfo = Website::query()->where($whereData)->whereJsonContains('website_url', $data['website_url'])->first();
  1194. if (empty($websiteInfo)) {
  1195. return Result::error("找不到URL", 0);
  1196. }
  1197. return Result::success($websiteInfo->toArray());
  1198. }
  1199. /**
  1200. * 获取网站底部基础信息
  1201. * @param array $data
  1202. * @return array
  1203. */
  1204. public function getWebsiteFootInfo(array $data): array
  1205. {
  1206. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1207. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1208. if (empty($website)) {
  1209. return Result::error("找不到网站", 0);
  1210. }
  1211. } else {
  1212. return Result::error("参数错误", 0);
  1213. }
  1214. $website_foot = WebsiteTemplateInfo::where('website_id', $data['website_id'])->where('status', 2)->first();
  1215. $website_head = Website::where('id', $data['website_id'])
  1216. ->select('id', 'website_name', 'logo', 'title', 'keywords', 'description','suffix','website_url')->first();
  1217. if (empty($website_foot)) {
  1218. return Result::error("暂无底部基础信息", 0);
  1219. }
  1220. if (empty($website_head)) {
  1221. return Result::error("暂无头部基础信息", 0);
  1222. }
  1223. $website_head['website_url'] = $website_head['website_url']?json_decode($website_head['website_url']):[];
  1224. $result = [
  1225. 'website_foot' => $website_foot,
  1226. 'website_head' => $website_head,
  1227. ];
  1228. return Result::success($result);
  1229. }
  1230. /**
  1231. * 获取网站底部导航
  1232. * @param array $data
  1233. * @return array
  1234. */
  1235. public function getWebsiteFooterCategory(array $data): array
  1236. {
  1237. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1238. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1239. if (empty($website)) {
  1240. return Result::error("找不到网站", 0);
  1241. }
  1242. } else {
  1243. return Result::error("参数错误", 0);
  1244. }
  1245. $result = FooterCategory::where('website_id', $data['website_id'])->get();
  1246. if (empty($result)) {
  1247. return Result::error("暂无底部导航", 0);
  1248. }
  1249. return Result::success($result->toArray());
  1250. }
  1251. /**
  1252. * 获取网站底部导航列表
  1253. * @param array $data
  1254. * @return array
  1255. */
  1256. public function getWebsiteFooterCategoryList(array $data): array
  1257. {
  1258. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1259. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1260. if (empty($website)) {
  1261. return Result::error("找不到网站", 0);
  1262. }
  1263. } else {
  1264. return Result::error("参数错误", 0);
  1265. }
  1266. $footercategory = FooterCategory::where('website_id', $data['website_id'])->where('id', $data['fcat_id'])->first();
  1267. // '底部导航类型 0:内容型;1:列表型;',
  1268. if (!isset($footercategory['type']) || $footercategory['type'] == 0) {
  1269. return Result::error("底部导航id错误", 0);
  1270. } else {
  1271. $query = FooterContent::where('fcat_id', $data['fcat_id']);
  1272. if ($query->count() == 0) {
  1273. return Result::error("暂无底部导航列表", 0);
  1274. } elseif ($query->count() == 1) {
  1275. $result = $query->first();
  1276. } else {
  1277. $result = $query->get();
  1278. }
  1279. }
  1280. return Result::success($result);
  1281. }
  1282. /**
  1283. * 获取网站底部导航
  1284. * @param array $data
  1285. * @return array
  1286. */
  1287. public function getWebsiteFooterCategoryInfo(array $data): array
  1288. {
  1289. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1290. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1291. if (empty($website)) {
  1292. return Result::error("找不到网站", 0);
  1293. }
  1294. } else {
  1295. return Result::error("参数错误", 0);
  1296. }
  1297. if (isset($data['type']) && $data['type'] == 0) {
  1298. $fcatid = FooterCategory::where('website_id', $data['website_id'])->where('id', $data['fcat_id'])->first();
  1299. if (empty($fcatid)) {
  1300. return Result::error("底部导航id错误", 0);
  1301. }
  1302. $result = FooterContent::where('fcat_id', $data['fcat_id'])->first();
  1303. } else {
  1304. $result = FooterContent::where('id', $data['fcat_id'])->first();
  1305. }
  1306. if (empty($result)) {
  1307. return Result::error("暂无底部导航内容", 0);
  1308. }
  1309. return Result::success($result);
  1310. }
  1311. /*
  1312. * 搜索网站二级导航
  1313. * @param array $data
  1314. * @return array
  1315. * */
  1316. public function selectWebsiteCategory(array $data): array
  1317. {
  1318. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1319. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1320. if (empty($website)) {
  1321. return Result::error("暂无该网站", 0);
  1322. }
  1323. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id')->all();
  1324. // return Result::success($category);
  1325. if (empty($category)) {
  1326. return Result::error("暂无此导航", 0);
  1327. }
  1328. $query = Category::whereIn('id', $category);
  1329. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1330. $cityid = District::where('id', $data['cityid'])->first();
  1331. if (empty($cityid)) {
  1332. return Result::error("暂无此城市", 0);
  1333. } else {
  1334. $city_category = $query->whereRaw('JSON_CONTAINS(city_arr_id,?)', [$data['cityid']])->pluck('id');
  1335. // $where[] = ['JSON_CONTAINS(city_arr_id, ?)', $data['cityid']];
  1336. if (empty($city_category)) {
  1337. return Result::error("暂无此城市下的导航", 0);
  1338. }
  1339. $result['catid'] = $city_category;
  1340. $city = 1;
  1341. // var_dump("城市====================",$result);
  1342. }
  1343. }
  1344. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1345. $departmentid = Department::where('id', $data['department_id'])->first();
  1346. if (empty($departmentid)) {
  1347. return Result::error("暂无此部门", 0);
  1348. } else {
  1349. $depart_category = $query->whereRaw('JSON_CONTAINS(department_arr_id,?)', [$data['department_id']])->pluck('id');
  1350. if (empty($depart_category)) {
  1351. return Result::error("暂无此部门下的导航", 0);
  1352. }
  1353. $result['catid'] = $depart_category;
  1354. // var_dump("职能部门*******************",$result);
  1355. $department = 1;
  1356. }
  1357. }
  1358. if (!empty($city) && !empty($department)) {
  1359. // var_dump("城市和职能部门----------------------",$result);
  1360. $sel_category = $query->whereRaw('JSON_CONTAINS(city_arr_id,?)', [$data['cityid']])->whereRaw('JSON_CONTAINS(department_arr_id,?)', [$data['department_id']])->pluck('id');
  1361. if (empty($sel_category)) {
  1362. return Result::error("暂无此城市和职能部门下的导航", 0);
  1363. }
  1364. $result['catid'] = $sel_category;
  1365. }
  1366. if (empty($result)) {
  1367. return Result::error("暂无导航", 0);
  1368. }
  1369. // department_id
  1370. } else {
  1371. return Result::error("参数错误", 0);
  1372. }
  1373. return Result::success($result);
  1374. }
  1375. /**
  1376. * 获取网站栏目seo
  1377. * @param array $data
  1378. * @return array
  1379. */
  1380. public function getWebsiteCategoryHead(array $data): array
  1381. {
  1382. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1383. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1384. if (empty($website)) {
  1385. return Result::error("找不到网站", 0);
  1386. }
  1387. } else {
  1388. return Result::error("参数错误", 0);
  1389. }
  1390. if (isset($data['catid']) && !empty($data['catid'])) {
  1391. $fcatid = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->first();
  1392. if (empty($fcatid)) {
  1393. return Result::error("导航id错误", 0);
  1394. }
  1395. $result = Category::where('id', $data['catid'])->first();
  1396. $result['website_name'] = $website['website_name']??'';
  1397. $result['suffix'] = $website['suffix']??'';
  1398. }
  1399. if (empty($result)) {
  1400. return Result::error("暂无导航", 0);
  1401. }
  1402. return Result::success($result);
  1403. }
  1404. /*
  1405. * 获取某个栏目
  1406. * @param array $data
  1407. * @return array
  1408. * */
  1409. public function getOneWebsiteCategory(array $data): array
  1410. {
  1411. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1412. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1413. if (empty($website)) {
  1414. return Result::error("暂无该网站", 0);
  1415. }
  1416. $result = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['category_id'])->select('category_id', 'alias')->first();
  1417. // return Result::success($category);
  1418. if (empty($result)) {
  1419. return Result::error("暂无此导航", 0);
  1420. }
  1421. // department_id
  1422. } else {
  1423. return Result::error("参数错误", 0);
  1424. }
  1425. return Result::success($result);
  1426. }
  1427. //20250212 网站标识
  1428. public function addWebsiteGroup(array $data): array
  1429. {
  1430. //判斷name是不是重复
  1431. $websiteGroupInfo = WebsiteGroup::query()->where('name', $data['name'])->first();
  1432. if (!empty($websiteGroupInfo)) {
  1433. return Result::error("网站标识重复", 0);
  1434. }
  1435. //添加信息
  1436. $result = WebsiteGroup::insertGetId($data);
  1437. var_dump($result);
  1438. if (empty($result)) {
  1439. return Result::error("创建失败", 0);
  1440. } else {
  1441. return Result::success($result);
  1442. }
  1443. }
  1444. public function getWebsiteGroupList(array $data): array
  1445. {
  1446. $where = [];
  1447. if (isset($data['name']) && !empty($data['name'])) {
  1448. array_push($where, ['website_group.name', 'like', '%' . $data['name'] . '%']);
  1449. }
  1450. $result = WebsiteGroup::where($where)
  1451. ->limit($data['pageSize'])->orderBy("id", "desc")->offset(($data['page'] - 1) * $data['pageSize'])
  1452. ->get();
  1453. foreach ($result as $websiteGroup) {
  1454. $webIds = json_decode($websiteGroup->web_ids, true);
  1455. $websites = Website::whereIn('id', $webIds)->get();
  1456. $websiteNames = $websites->pluck('website_name', 'id')->toArray();
  1457. $websiteGroup->website_names = $websiteNames;
  1458. $websiteGroup->website_names1 = implode(',', array_values($websiteNames));
  1459. }
  1460. $count = WebsiteGroup::where($where)->count();
  1461. if (empty($result)) {
  1462. return Result::error("没有数据", 0);
  1463. }
  1464. return Result::success(['list' => $result->toArray(), 'count' => $count]);
  1465. }
  1466. public function getWebsiteGroupInfo(array $data): array
  1467. {
  1468. $websiteInfo = WebsiteGroup::query()->where('id', $data['id'])->first();
  1469. $webIds = json_decode($websiteInfo->web_ids, true);
  1470. $websites = Website::whereIn('id', $webIds)->get();
  1471. $websiteNames = $websites->pluck('website_name', 'id')->toArray();
  1472. $websiteInfo->website_names = $websiteNames;
  1473. $websiteInfo->website_names1 = implode(',', array_values($websiteNames));
  1474. if (empty($websiteInfo)) {
  1475. return Result::error("找不到URL", 0);
  1476. }
  1477. return Result::success($websiteInfo->toArray());
  1478. }
  1479. public function updateWebsiteGroup(array $data): array
  1480. {
  1481. $where = [
  1482. 'id' => $data['id'],
  1483. ];
  1484. $insertData = [
  1485. 'name' => $data['name'],
  1486. 'web_ids' => $data['web_ids'],
  1487. ];
  1488. //判斷name是不是重复
  1489. $websiteGroupInfo = WebsiteGroup::query()->where('name', $data['name'])->first();
  1490. if (!empty($websiteGroupInfo)) {
  1491. return Result::error("网站标识重复", 0);
  1492. }
  1493. $result = WebsiteGroup::where($where)->update($insertData);
  1494. var_dump($result, '------更新');
  1495. if (empty($result)) {
  1496. return Result::error("更新失败", 0);
  1497. } else {
  1498. return Result::success();
  1499. }
  1500. }
  1501. public function deleteWebsiteGroup(array $data): array
  1502. {
  1503. $where = [
  1504. 'id' => $data['id'],
  1505. ];
  1506. //看看user表是不是有这个id
  1507. $userGroup = User::query()->where('sszq', $data['id'])->first();
  1508. if (!empty($userGroup)) {
  1509. return Result::error("有用户在使用该网站标识,不能删除", 0);
  1510. }
  1511. $result = WebsiteGroup::where($where)->delete();
  1512. if (empty($result)) {
  1513. return Result::error("删除失败", 0);
  1514. } else {
  1515. return Result::success();
  1516. }
  1517. }
  1518. public function getWebsiteNavList(array $data): array
  1519. {
  1520. $where = [];
  1521. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1522. array_push($where, ['website_id', '=', $data['website_id']]);
  1523. }
  1524. if (isset($data['pid'])) {
  1525. array_push($where, ['pid', '=', $data['pid']]);
  1526. }
  1527. $list = WebsiteCategory::query()->where($where)->get();
  1528. if (empty($list)) {
  1529. return Result::error("获取失败", 0);
  1530. } else {
  1531. return Result::success($list);
  1532. }
  1533. }
  1534. //20250212 网站标识
  1535. // 自助建站--fr-------------------
  1536. /**
  1537. * 获取并搜索 网站模板信息
  1538. * @param array $data
  1539. * @return array
  1540. */
  1541. public function getWebsiteintel(array $data): array
  1542. {
  1543. //查询所有网站模板信息
  1544. $query = Website::where('website.status', 1)
  1545. ->leftJoin("website_template_info", "website_template_info.website_id", "website.id")
  1546. ->leftJoin("template", "template.id", "website_template_info.template_id")
  1547. ->leftJoin("template_class", "template_class.id", "template.template_class_id")
  1548. ->select(
  1549. "website_template_info.id",
  1550. "template_class.name",
  1551. "website.id as website_id",
  1552. "website.website_name",
  1553. "website.website_url",
  1554. "website_template_info.action_id",
  1555. "website_template_info.created_at",
  1556. "website_template_info.updated_at",
  1557. "website_template_info.page_type",
  1558. DB::raw("COALESCE(website_template_info.status, 0) as template_status"),
  1559. "template.template_name"
  1560. );
  1561. //若存在条件;则在$query的基础上进行筛选
  1562. if (isset($data['website_name']) && !empty($data['website_name'])) {
  1563. $query->where('website.website_name', 'like', '%' . $data['website_name'] . '%');
  1564. }
  1565. if (isset($data['status']) && !empty($data['status'])) {
  1566. $query->where('website_template_info.status', $data['status']);
  1567. }
  1568. $count = $query->count();
  1569. $query->limit($data['pageSize'])
  1570. ->offset(($data['page'] - 1) * $data['pageSize'])
  1571. ->orderBy("website_template_info.updated_at", "desc");
  1572. $rep = $query->get();
  1573. if ($rep->count() == 0) {
  1574. return Result::error("没有查找到相关数据", 0);
  1575. } else {
  1576. $rep->each(function ($item) {
  1577. if (!empty($item->page_type)) {
  1578. $pageTypeArray = json_decode($item->page_type, true);
  1579. if (is_array($pageTypeArray)) {
  1580. $item->page_type = $pageTypeArray;
  1581. }
  1582. }
  1583. });
  1584. $result = [
  1585. "rows" => $rep->toArray(),
  1586. "count" => $count,
  1587. ];
  1588. return Result::success($result);
  1589. }
  1590. // return Result::success($result);
  1591. }
  1592. /**
  1593. * 添加网站基础信息
  1594. * @param array $data
  1595. * @return array
  1596. */
  1597. public function addWebsiteTemplateintel(array $data): array
  1598. {
  1599. // var_dump("接收参数:",$data['webSiteData']['base']);
  1600. Db::beginTransaction();
  1601. try {
  1602. $websiteTemplateInfo = WebsiteTemplate::where(['website_id' => $data['webSiteData']['base']['websiteId']])->first();
  1603. // var_dump($websiteTemplateInfo);
  1604. //原始数据
  1605. $templateList = $data['webSiteData']['template'];
  1606. if ($websiteTemplateInfo) {
  1607. //模板存在-更新广告
  1608. } else {
  1609. //创建广告
  1610. $adList = $this->getAdlist($templateList);
  1611. if (!empty($adList)) {
  1612. AdPlace::insert($adList);
  1613. }
  1614. }
  1615. // $result = WebsiteTemplate::updateOrInsert(['website_id'=>$data['webSiteData']['base']['websiteId']],['template_data'=>json_encode($data['webSiteData']),'updated_at'=>date("Y-m-d H:i:s",time())]);
  1616. Db::commit();
  1617. } catch (\Throwable $ex) {
  1618. Db::rollBack();
  1619. var_dump($ex->getMessage());
  1620. return Result::error("创建失败", 0);
  1621. $website = Website::where('website.id', $data['website_id'])->first();
  1622. if (empty($website)) {
  1623. return Result::error("请输入正确的网站id!", 0);
  1624. }
  1625. if (empty($website['website_column_id'])) {
  1626. return Result::error("请先关联导航池!", 0);
  1627. }
  1628. // 获取此网站的底部导航 类型 type: 0:内容型底部导航(只有一条详情内容);1:列表型底部导航(可以有多条详情内容)
  1629. $foot_type = FooterCategory::where('website_id', $data['website_id'])->pluck('type')->toArray();
  1630. if (empty($foot_type)) {
  1631. return Result::error("请先关联底部导航池!", 0);
  1632. } elseif (in_array(1, $foot_type)) {
  1633. $foot_type = 1;
  1634. } else {
  1635. $foot_type = 0;
  1636. }
  1637. $result['foot_type'] = $foot_type;
  1638. // 友情链接类型'1:图片 2:文字 3:底部';
  1639. $types = Link::where('website_id', $data['website_id'])->pluck('type')->toArray();
  1640. $missingTypes = [];
  1641. if (!in_array(1, $types)) {
  1642. $missingTypes[] = "文字链接";
  1643. }
  1644. if (!in_array(2, $types)) {
  1645. $missingTypes[] = "图片链接";
  1646. }
  1647. if (!in_array(3, $types)) {
  1648. $missingTypes[] = "底部链接";
  1649. }
  1650. if (!empty($missingTypes)) {
  1651. $errorMessage = "请先添加 " . implode(" 和 ", $missingTypes) . "!";
  1652. return Result::error($errorMessage, 0);
  1653. }
  1654. if (isset($data['page_type'])) {
  1655. // 删除重复元素并重新索引数组
  1656. $data['page_type'] = array_unique($data['page_type']);
  1657. $data['page_type'] = array_values($data['page_type']);
  1658. if (in_array(1, $data['page_type']) && in_array(7, $data['page_type'])) {
  1659. // 数组中同时包含值为 1(首页) 和值为 7 (底部导航详情页)的元素
  1660. $info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1661. if (empty($info)) {
  1662. // 将数组转换为 JSON 字符串
  1663. $data['page_type'] = json_encode($data['page_type']) ?? '';
  1664. // 操作状态:1:填写完成基础信息;2:选择完成模板;0:未构建
  1665. $data['action_id'] = 1;
  1666. try {
  1667. $result = WebsiteTemplateInfo::insertGetId($data);
  1668. } catch (\Exception $e) {
  1669. if ($e->getCode() == 22001) {
  1670. $errorMessage = $e->getMessage();
  1671. return Result::error("请检查表单,某个字段超出了长度限制!");
  1672. } else {
  1673. // 处理其他类型的数据库错误
  1674. return Result::error("插入操作失败: " . $e->getMessage());
  1675. }
  1676. return Result::error("添加失败!", 0);
  1677. }
  1678. } else {
  1679. return Result::error("该网站已经构建过了!", 0);
  1680. }
  1681. } else {
  1682. return Result::error("请先选择首页和底部导航详情页!", 0);
  1683. }
  1684. }
  1685. }
  1686. if (empty($result)) {
  1687. return Result::error("添加失败!", 0);
  1688. } else {
  1689. return Result::success($result);
  1690. }
  1691. return Result::success();
  1692. }
  1693. //获取传过来的广告列表
  1694. public function getAdlist($templateList)
  1695. {
  1696. if ($templateList) {
  1697. $adList = [];
  1698. foreach ($templateList as $val) {
  1699. if ($val) {
  1700. foreach ($val as $v) {
  1701. if ($v['componentList']) {
  1702. foreach ($v['componentList'] as $p) {
  1703. if ($p['component_type'] == 3) {
  1704. // var_dump("ppppppppppppp:",$p);
  1705. $adSizeInfo = AdSize::where(['width' => $p['componentData']['width'], 'height' => $p['componentData']['height']])->first();
  1706. $adSizeInfo = $adSizeInfo->toArray();
  1707. $adData = [
  1708. 'website_id' => $data['webSiteData']['base']['websiteId'],
  1709. 'status' => 1,
  1710. 'name' => $p['componentData']['text'],
  1711. 'ad_id' => $p['componentData']['ad_id'],
  1712. 'ad_size_id' => $adSizeInfo['id'],
  1713. ];
  1714. array_push($adList, $adData);
  1715. }
  1716. }
  1717. }
  1718. }
  1719. }
  1720. }
  1721. if (count($adList) > 0) {
  1722. return $adList;
  1723. }
  1724. }
  1725. }
  1726. /**
  1727. * 获取网站基础信息
  1728. *
  1729. * @return array
  1730. */
  1731. public function getWebsiteTemplateintel(array $data): array
  1732. {
  1733. $result = WebsiteTemplateInfo::where('website_template_info.website_id', $data['website_id'])
  1734. ->leftJoin('footer_category', 'footer_category.website_id', 'website_template_info.website_id')
  1735. ->leftJoin('website', 'website.id', 'website_template_info.website_id')
  1736. ->select(
  1737. "website_template_info.*",
  1738. "footer_category.type",
  1739. "website.website_name",
  1740. "website.id as website_id"
  1741. )
  1742. ->first();
  1743. if (empty($result['website_name'])) {
  1744. return Result::error("请输入正确的网站id!", 0);
  1745. }
  1746. if ($result) {
  1747. $result['page_type'] = json_decode($result['page_type'], true);
  1748. return Result::success($result);
  1749. } else {
  1750. return Result::error("请先添加网站基础信息!", 0);
  1751. }
  1752. }
  1753. /**
  1754. * 修改网站基础信息
  1755. *
  1756. * @return array
  1757. */
  1758. public function upWebsiteTemplateintel(array $data): array
  1759. {
  1760. $web = Website::where('website.id', $data['website_id'])->first();
  1761. if (empty($web)) {
  1762. return Result::error("请输入正确的网站id!", 0);
  1763. }
  1764. $where = ['website_id' => $data['website_id']];
  1765. $result = WebsiteTemplateInfo::where($where)->first();
  1766. if (empty($result)) {
  1767. return Result::error("请先添加网站基础信息!", 0);
  1768. } else {
  1769. unset($data['website_id']);
  1770. // 删除重复元素
  1771. $data['page_type'] = array_unique($data['page_type']);
  1772. // 重新索引数组
  1773. $data['page_type'] = array_values($data['page_type']);
  1774. // 数组中同时包含值为 1(首页) 和值为 7 (底部导航详情页)的元素
  1775. if (in_array(1, $data['page_type']) && in_array(7, $data['page_type'])) {
  1776. // 将数组转换为 JSON 字符串
  1777. $data['page_type'] = json_encode($data['page_type']) ?? '';
  1778. try {
  1779. $result = WebsiteTemplateInfo::where($where)->update($data);
  1780. } catch (\Exception $e) {
  1781. if ($e->getCode() == 22001) {
  1782. $errorMessage = $e->getMessage();
  1783. return Result::error("请检查表单,某个字段超出了长度限制!");
  1784. } else {
  1785. // 处理其他类型的数据库错误
  1786. return Result::error("修改操作失败: " . $e->getMessage());
  1787. }
  1788. return Result::error("修改失败!", 0);
  1789. }
  1790. } else {
  1791. return Result::error("请先选择首页和底部导航详情页!", 0);
  1792. }
  1793. }
  1794. if (empty($result)) {
  1795. return Result::error("修改失败!", 0);
  1796. } else {
  1797. return Result::success($result);
  1798. }
  1799. }
  1800. /**
  1801. * 获取所有网站风格信息
  1802. *
  1803. * @return array
  1804. */
  1805. public function getAllTemplateClass(array $data): array
  1806. {
  1807. $result = TemplateClass::all();
  1808. if (empty($result)) {
  1809. return Result::error("没有查找到相关数据!", 0);
  1810. } else {
  1811. return Result::success($result);
  1812. }
  1813. }
  1814. /**
  1815. * 搜索并获取网站模板信息
  1816. * @param array $data
  1817. * @return array
  1818. */
  1819. public function getWebsiteTemplateList(array $data): array
  1820. {
  1821. $website = Website::where('website.id', $data['website_id'])->first();
  1822. if (empty($website)) {
  1823. return Result::error("请输入正确的网站id!", 0);
  1824. } else {
  1825. $page_type = WebsiteTemplateInfo::where('website_id', $data['website_id'])->select('page_type')->first();
  1826. if (empty($page_type)) {
  1827. return Result::error("此网站还未添加基础信息!", 0);
  1828. } else {
  1829. $where = json_decode($page_type['page_type'], true);
  1830. // $where = $data["page_type"];
  1831. if (isset($data['template_class_id']) && !empty($data['template_class_id'])) {
  1832. $template_class = TemplateClass::where('id', $data['template_class_id'])->first();
  1833. if (empty($template_class)) {
  1834. return Result::error("请输入正确的模板风格id!", 0);
  1835. } else {
  1836. // 获取指定风格下的模板
  1837. $rep = Template::where('template_class_id', $data['template_class_id'])
  1838. ->where(function ($query) use ($where) {
  1839. foreach ($where as $value) {
  1840. $query->whereJsonContains('template_img', ['value' => $value]);
  1841. }
  1842. })
  1843. ->limit($data['pageSize'])
  1844. ->offset(($data['page'] - 1) * $data['pageSize'])
  1845. ->orderBy("template.updated_at", "desc")
  1846. ->get();
  1847. $count = Template::where('template_class_id', $data['template_class_id'])
  1848. ->where(function ($query) use ($where) {
  1849. foreach ($where as $value) {
  1850. $query->whereJsonContains('template_img', ['value' => $value]);
  1851. }
  1852. })->count();
  1853. }
  1854. } else {
  1855. //获取所有模板
  1856. $rep = Template::where(function ($query) use ($where) {
  1857. foreach ($where as $value) {
  1858. $query->whereJsonContains('template_img', ['value' => $value]);
  1859. }
  1860. })
  1861. ->limit($data['pageSize'])
  1862. ->offset(($data['page'] - 1) * $data['pageSize'])
  1863. ->orderBy("template.updated_at", "desc")
  1864. ->get();
  1865. $count = Template::where(function ($query) use ($where) {
  1866. foreach ($where as $value) {
  1867. $query->whereJsonContains('template_img', ['value' => $value]);
  1868. }
  1869. })->count();
  1870. }
  1871. if (empty($rep) || $rep->count() == 0) {
  1872. return Result::error("没有查找到相关数据!", 0);
  1873. } else {
  1874. // 过滤 template_img 字段 只获取 基础信息中 包含的模板图片
  1875. // $rep->each(function ($item) use ($where) {
  1876. // $template_img = json_decode($item->template_img, true);
  1877. // if(is_array($template_img)){
  1878. // $filtered_img = array_filter($template_img, function ($img) use ($where) {
  1879. // return isset($img['value']) && in_array($img['value'], $where);
  1880. // });
  1881. // }
  1882. // $item->template_img = $filtered_img;
  1883. // });
  1884. // $result = [
  1885. // "rows" => $rep->toArray(),
  1886. // "count" => $count
  1887. // ];
  1888. $rep->each(function ($item) use ($where) {
  1889. $template_img = json_decode($item->template_img, true);
  1890. if (is_array($template_img)) {
  1891. $filtered_img = array_filter($template_img, function ($img) use ($where) {
  1892. return isset($img['value']) && in_array($img['value'], $where);
  1893. });
  1894. // 对过滤后的数组进行重新排序
  1895. $sorted_img = array_values($filtered_img);
  1896. $item->template_img = $sorted_img;
  1897. } else {
  1898. $item->template_img = []; // 如果无法解码为数组,则设置为空数组
  1899. }
  1900. });
  1901. $result = [
  1902. "rows" => $rep->toArray(),
  1903. "count" => $count,
  1904. ];
  1905. }
  1906. }
  1907. }
  1908. return Result::success($result);
  1909. }
  1910. /**
  1911. * 添加网站模板
  1912. * @param array $data
  1913. */
  1914. public function addWebsiteTemplateclassintel(array $data): array
  1915. {
  1916. $template = Template::where('id', $data['template_id'])->first();
  1917. $web = Website::where('id', $data['website_id'])->first();
  1918. if (empty($template)) {
  1919. return Result::error("请输入正确的模板id", 0);
  1920. }
  1921. if (empty($web)) {
  1922. return Result::error("请输入正确的网站id", 0);
  1923. }
  1924. $result = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['template_id' => $data['template_id'], 'action_id' => 2]);
  1925. if (empty($result)) {
  1926. return Result::error("添加失败", 0);
  1927. } else {
  1928. return Result::success($result);
  1929. }
  1930. }
  1931. /**
  1932. * 获取网站模板信息
  1933. * @param array $data
  1934. */
  1935. public function getWebsiteTemplateclassintel(array $data): array
  1936. {
  1937. // return Result::success($data);
  1938. $template = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1939. if (empty($template)) {
  1940. return Result::error("请输入正确的搭建网站id", 0);
  1941. }
  1942. $page_type = json_decode($template['page_type'], true);
  1943. // 获取指定网站下的基础信息和模板及风格信息
  1944. $result = WebsiteTemplateInfo::where([
  1945. ['website_template_info.website_id', $data['website_id']],
  1946. ['template_id', '!=', null],
  1947. ])
  1948. ->leftJoin('template', 'template.id', 'website_template_info.template_id')
  1949. ->leftJoin('template_class', 'template_class.id', 'template.template_class_id')
  1950. ->where(function ($query) use ($page_type) {
  1951. // 假设 $data['page_type'] 是一个数组,包含需要匹配的 page_type 值
  1952. foreach ($page_type as $pageType) {
  1953. $query->orWhereJsonContains('template.template_img', ['value' => $pageType]);
  1954. }
  1955. })
  1956. ->select(
  1957. 'template.template_name',
  1958. 'template.template_img',
  1959. 'template.id as tid',
  1960. 'template_class.name',
  1961. 'template_class.id as class_id',
  1962. 'website_template_info.page_type',
  1963. 'website_template_info.website_id')
  1964. ->first();
  1965. if (empty($result)) {
  1966. return Result::error("没有查找到相关数据", 0);
  1967. }
  1968. // return Result::success($result);
  1969. // 过滤 template_img 字段 只获取 基础信息中 包含的模板图片
  1970. $template_img = $result['template_img'] !== null ? json_decode($result['template_img'], true) : [];
  1971. $page_type = $result['page_type'] !== null ? json_decode($result['page_type'], true) : [];
  1972. foreach ($template_img as $key => $value) {
  1973. if (!in_array($value['value'], $page_type)) {
  1974. unset($template_img[$key]);
  1975. }
  1976. }
  1977. // return Result::success($result);
  1978. $result['template_img'] = array_values($template_img);
  1979. $result['page_type'] = $page_type;
  1980. // $templateList = $this->getWebsiteTemplateList($data);
  1981. // $count = $templateList['data']['count']??'';
  1982. // $pages = $count / $data['pageSize'];
  1983. // $found = false;
  1984. // while ($pages && !$found) {
  1985. // $templates = $this->getWebsiteTemplateList($pages,$data['pageSize']);
  1986. // $index = array_search($template['template_id'], array_column($templates['rows'], 'id'));
  1987. // if ($index !== false) {
  1988. // $found = true;
  1989. // $result['page'] = $pages;
  1990. // $pages = 0;
  1991. // // echo "查询到的 template 在第 $page 页";
  1992. // }
  1993. // $pages--;
  1994. // }
  1995. return Result::success($result);
  1996. }
  1997. /**
  1998. * 获取网站模板下的板块信息
  1999. * @param array $data
  2000. */
  2001. public function getWebsiteSectorList(array $data): array
  2002. {
  2003. $website = Website::where('id', $data['website_id'])->first();
  2004. if (empty($website)) {
  2005. return Result::error("请输入正确的网站id", 0);
  2006. }
  2007. $template = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  2008. if (empty($template['template_id'])) {
  2009. return Result::error("请先添加网站模板", 0);
  2010. }
  2011. $query = Sector::where('template_id', $template['template_id']);
  2012. if ($query->count() == 0) {
  2013. return Result::error("没有查找到相关板块数据", 0);
  2014. } elseif ($query->count() == 1) {
  2015. $sector = $query->first();
  2016. } else {
  2017. $sector = $query->get();
  2018. }
  2019. $result['page_type'] = $template['page_type'];
  2020. $result['tid'] = $template['template_id'];
  2021. $result = [
  2022. "tid" => $template['template_id'],
  2023. "page_type" => $template['page_type'],
  2024. "sector" => $sector,
  2025. ];
  2026. return Result::success($result);
  2027. }
  2028. // 自助建站---------------fr---------------
  2029. // 自助建站------liu-------------
  2030. /**
  2031. * 风格下的板块
  2032. * @return void
  2033. */
  2034. public function templateSectorList(array $data): array
  2035. {
  2036. $where = [
  2037. 'template_id' => $data['template_id'],
  2038. ];
  2039. $result = Sector::where($where)->whereJsonContains("page_type", $data['page_type'])
  2040. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])
  2041. ->get();
  2042. $count = Sector::where($where)->count();
  2043. if (empty($result)) {
  2044. return Result::error("没有数据", 0);
  2045. }
  2046. $data = [
  2047. 'rows' => $result->toArray(),
  2048. 'count' => $count,
  2049. ];
  2050. if (empty($result)) {
  2051. return Result::error("没有数据", 0);
  2052. }
  2053. return Result::success($data);
  2054. }
  2055. /**
  2056. * 板块下的组件
  2057. * @param array $data
  2058. * @return array
  2059. */
  2060. public function sectorComponentList(array $data): array
  2061. {
  2062. $where = [
  2063. 'template_id' => $data['template_id'],
  2064. 'sector_id' => $data['sector_id'],
  2065. ];
  2066. $result = Component::where($where)
  2067. ->select("*")
  2068. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])
  2069. ->get();
  2070. $count = Component::where($where)->count();
  2071. if (empty($result)) {
  2072. return Result::error("没有数据", 0);
  2073. }
  2074. $data = [
  2075. 'rows' => $result->toArray(),
  2076. 'count' => $count,
  2077. ];
  2078. if (empty($result)) {
  2079. return Result::error("没有数据", 0);
  2080. }
  2081. return Result::success($data);
  2082. }
  2083. /**
  2084. * 获取模板内容
  2085. * @return void
  2086. */
  2087. public function getWebsiteTemplateInfo(array $data): array//丢了
  2088. {
  2089. $wehre = [
  2090. "website_id" => $data['website_id'],
  2091. ];
  2092. $result = WebsiteTemplate::where($wehre)->first();
  2093. if ($result) {
  2094. return Result::success($result);
  2095. } else {
  2096. return Result::error("没有数据", 0);
  2097. }
  2098. }
  2099. /**
  2100. * 保存网站模板
  2101. * @param array $data
  2102. * @return array
  2103. */
  2104. public function addWebsiteTemplate(array $data): array
  2105. {
  2106. // var_dump("接收参数:",$data['webSiteData']['base']);
  2107. Db::beginTransaction();
  2108. try {
  2109. $websiteTemplateInfo = WebsiteTemplate::where(['website_id' => $data['webSiteData']['base']['websiteId']])->first();
  2110. // var_dump($websiteTemplateInfo);
  2111. //原始数据
  2112. $templateList = $data['webSiteData']['template'];
  2113. if ($websiteTemplateInfo) {
  2114. //模板存在-更新广告
  2115. } else {
  2116. //创建广告
  2117. $adList = $this->getAdlist($templateList);
  2118. if (!empty($adList)) {
  2119. AdPlace::insert($adList);
  2120. }
  2121. }
  2122. // $result = WebsiteTemplate::updateOrInsert(['website_id'=>$data['webSiteData']['base']['websiteId']],['template_data'=>json_encode($data['webSiteData']),'updated_at'=>date("Y-m-d H:i:s",time())]);
  2123. Db::commit();
  2124. } catch (\Throwable $ex) {
  2125. Db::rollBack();
  2126. var_dump($ex->getMessage());
  2127. return Result::error("创建失败", 0);
  2128. }
  2129. return Result::success();
  2130. }
  2131. /**
  2132. * 预览网站首页模板数据
  2133. * @param array $data
  2134. * @return array
  2135. */
  2136. public function getWebsiteTemplateData(array $data): array
  2137. {
  2138. $wehre = [
  2139. "website_id" => $data['website_id'],
  2140. ];
  2141. $result = WebsiteTemplate::where($wehre)->first();
  2142. if ($result) {
  2143. $templateData = json_decode($result['template_data'], true);
  2144. // var_dump("数据:",$templateData[1]);
  2145. $templateData[1] = $this->getNewsList($templateData[1]);
  2146. return Result::success($templateData);
  2147. } else {
  2148. return Result::error("没有数据", 0);
  2149. }
  2150. }
  2151. /**
  2152. * 获取列表数据
  2153. * @return void
  2154. */
  2155. public function getNewsList(array $data): array
  2156. {
  2157. if ($data) {
  2158. foreach ($data as $key => $val) {
  2159. if ($val) {
  2160. foreach ($val['data'] as $k => $item) {
  2161. if ($item['isReturn'] && intval($item['isReturn']) == 1) {
  2162. $imgList = [];
  2163. if ($item['data']['imgNum'] && intval($item['data']['imgNum']) > 0) {
  2164. $imgList = Article::where('imgurl', "!=", "")
  2165. ->where('catid', $item['data']['category_id'])
  2166. ->select($item['data']['selectField'])
  2167. ->orderBy("created_at", "desc")
  2168. ->offset(0)
  2169. ->limit(intval($item['data']['imgNum']))
  2170. ->get();
  2171. $imgList = $imgList->toArray();
  2172. $listIds = [];
  2173. if ($imgList) {
  2174. $listIds = array_column($imgList, 'id');
  2175. }
  2176. $dataList = Article::whereNotIn('id', $listIds)
  2177. ->where('catid', $item['data']['category_id'])
  2178. ->select($item['data']['selectField'])
  2179. ->orderBy("created_at", "desc")
  2180. ->offset(0)
  2181. ->limit(intval($item['data']['pageSize']) - intval($item['data']['imgNum']))
  2182. ->get();
  2183. $dataList = $dataList->toArray();
  2184. var_dump("图片列表:", $imgList, "数据列表:", $dataList);
  2185. $datas = array_merge($imgList, $dataList);
  2186. // return $datas;
  2187. var_dump("合并列表:", $datas);
  2188. $data[$key]['data'][$k]['dataList'] = $datas;
  2189. } else {
  2190. $dataList = Article::where('catid', $item['data']['category_id'])
  2191. ->select($item['data']['selectField'])
  2192. ->orderBy("created_at", "desc")
  2193. ->offset(0)
  2194. ->limit(intval($item['data']['pageSize']))
  2195. ->get();
  2196. $dataList = $dataList->toArray();
  2197. var_dump("数据列表:", $dataList);
  2198. }
  2199. }
  2200. }
  2201. }
  2202. }
  2203. }
  2204. return $data;
  2205. }
  2206. /**
  2207. * 获取底部导航列表
  2208. * @param array $data
  2209. * @return array
  2210. */
  2211. public function getFooterCategoryList(array $data): array
  2212. {
  2213. $where = [
  2214. "website_id" => $data['website_id'],
  2215. ];
  2216. $result = FooterCategory::where($where)->get();
  2217. if ($result) {
  2218. return Result::success($result);
  2219. } else {
  2220. return Result::error("没有数据");
  2221. }
  2222. }
  2223. //获取底部导航内容列表
  2224. public function getFooterContentList(array $data): array
  2225. {
  2226. $where = [
  2227. "fcat_id" => $data['fcat_id'],
  2228. ];
  2229. switch (intval($data['type'])) {
  2230. case 0:
  2231. $result = FooterContent::where($where)->first();
  2232. break;
  2233. case 1:
  2234. $result = FooterContent::where($where)->get();
  2235. break;
  2236. }
  2237. if ($result) {
  2238. return Result::success($result);
  2239. } else {
  2240. return Result::error("没有数据");
  2241. }
  2242. }
  2243. //获取底部导航内容详情
  2244. public function getFooterContentInfo(array $data): array
  2245. {
  2246. $where = [
  2247. "id" => $data['content_id'],
  2248. ];
  2249. $result = FooterContent::where($where)->first();
  2250. if ($result) {
  2251. return Result::success($result);
  2252. } else {
  2253. return Result::error("没有数据");
  2254. }
  2255. }
  2256. // 自传建站---------------liu------------
  2257. // 20250307 根据网站标识获和导航获取站点
  2258. public function getWebsiteNavPoolSite(array $data): array
  2259. {
  2260. $where = [];
  2261. if (isset($data['category_id']) && !empty($data['category_id'])) {
  2262. array_push($where, ['category_id', '=', $data['category_id']]);
  2263. }
  2264. $list = WebsiteCategory::query()->where($where)
  2265. ->leftJoin('website', 'website.id', '=', 'website_category.website_id')
  2266. ->select('website_category.*', 'website.website_name')
  2267. ->distinct()
  2268. ->get();
  2269. if (empty($list)) {
  2270. return Result::error("获取失败", 0);
  2271. } else {
  2272. return Result::success($list);
  2273. }
  2274. }
  2275. public function getWebsiteNavPool(array $data): array
  2276. {
  2277. // 初始化查询条件数组
  2278. $query = WebsiteCategory::query();
  2279. // 如果传入了 websiteids,则添加到查询条件中
  2280. if (isset($data['websiteids']) && !empty($data['websiteids'])) {
  2281. $query->whereIn('website_id', $data['websiteids']);
  2282. }
  2283. // 如果传入了 pid,则添加到查询条件中
  2284. if (isset($data['pid'])) {
  2285. $query->where('pid', '=', $data['pid']);
  2286. }
  2287. // 执行查询 唯一性 id
  2288. $list = $query->distinct()->get();
  2289. // 根据查询结果返回相应的结果
  2290. if ($list->isEmpty()) {
  2291. return Result::error("获取失败", 0);
  2292. } else {
  2293. return Result::success($list->toArray());
  2294. }
  2295. }
  2296. // 20250307 根据网站标识获和导航获取站点
  2297. /**
  2298. *
  2299. * @param array $data
  2300. * @return array
  2301. */
  2302. public function getAllCategory(array $data): array
  2303. {
  2304. $result = Category::when($data, function ($query) use ($data) {
  2305. if (isset($data['name']) && !empty($data['name'])) {
  2306. $query->where('category.name', 'like', '%' . trim($data['name']) . '%');
  2307. }
  2308. })->get();
  2309. if (empty($result)) {
  2310. return Result::error("获取失败", 0);
  2311. } else {
  2312. return Result::success($result);
  2313. }
  2314. }
  2315. }