WebsiteService.php 101 KB

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