WebsiteService.php 102 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680
  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. if ($result) {
  1027. return Result::success($result);
  1028. } else {
  1029. return Result::error("查询失败", 0);
  1030. }
  1031. }
  1032. /**
  1033. * 更新网站导航
  1034. * @param array $data
  1035. * @return array
  1036. */
  1037. public function upWebsiteCategory(array $data): array
  1038. {
  1039. $pinyin = new Pinyin();
  1040. Db::beginTransaction();
  1041. try {
  1042. if (!empty($data['category_arr_id'])) {
  1043. $websiteId = $data['website_id'];
  1044. // 1. 获取旧的 category_id 列表
  1045. $oldCategoryListIds = WebsiteCategory::where('website_id', $websiteId)->pluck('category_id')->toArray();
  1046. // 2. 获取新的 category_id 列表(去重)
  1047. $newCategoryListIds = [];
  1048. foreach ($data['category_arr_id'] as $arr) {
  1049. $lastId = end($arr);
  1050. $newCategoryListIds[] = $lastId;
  1051. }
  1052. $newCategoryListIds = array_unique($newCategoryListIds);
  1053. // 3. 需要删除的 category_id
  1054. $toDelete = array_diff($oldCategoryListIds, $newCategoryListIds);
  1055. if (!empty($toDelete)) {
  1056. WebsiteCategory::where('website_id', $websiteId)
  1057. ->whereIn('category_id', $toDelete)
  1058. ->delete();
  1059. }
  1060. // 4. 批量查出所有需要的 category 信息
  1061. $categories = Category::whereIn('id', $newCategoryListIds)->get()->keyBy('id');
  1062. // 5. 组装 upsertData,确保 category_id 不重复
  1063. $upsertData = [];
  1064. $handledCategoryIds = [];
  1065. foreach ($data['category_arr_id'] as $arr) {
  1066. $categoryId = end($arr);
  1067. if (!isset($categories[$categoryId]) || in_array($categoryId, $handledCategoryIds)) continue;
  1068. $info = $categories[$categoryId];
  1069. $aLIas_pinyin = $pinyin->permalink($info->name, '');
  1070. $upsertData[] = [
  1071. 'website_id' => $websiteId,
  1072. 'category_id' => $categoryId,
  1073. 'name' => $info->name ?? '',
  1074. 'alias' => $info->name ?? '',
  1075. 'aLIas_pinyin' => $aLIas_pinyin ?? '',
  1076. 'sort' => $info->sort ?? 0,
  1077. 'pid' => $info->pid ?? 0,
  1078. 'pid_arr' => $info->pid_arr ?? json_encode([]),
  1079. 'seo_title' => $info->seo_title ?? "",
  1080. 'seo_keywords' => $info->seo_keywords ?? "",
  1081. 'seo_description' => $info->seo_description ?? "",
  1082. 'is_url' => $info->is_url ?? 0,
  1083. 'web_url' => $info->web_url ?? '',
  1084. 'type' => $info->type ?? 1,
  1085. 'category_arr_id' => json_encode($arr)
  1086. ];
  1087. $handledCategoryIds[] = $categoryId;
  1088. }
  1089. // 6. upsert
  1090. if (!empty($upsertData)) {
  1091. WebsiteCategory::upsert(
  1092. $upsertData,
  1093. ['website_id', 'category_id'],
  1094. [
  1095. 'aLIas_pinyin',
  1096. 'pid',
  1097. 'pid_arr',
  1098. 'is_url',
  1099. 'web_url',
  1100. 'category_arr_id'
  1101. ]
  1102. );
  1103. }
  1104. }
  1105. Db::commit();
  1106. return Result::success();
  1107. } catch (\Throwable $ex) {
  1108. Db::rollBack();
  1109. return Result::error("修改失败" . $ex->getMessage(), 0);
  1110. }
  1111. }
  1112. /**
  1113. * 获取网站列表
  1114. * @param array $data
  1115. * @return array
  1116. */
  1117. public function getWebsiteCategoryList(array $data): array
  1118. {
  1119. $where = [];
  1120. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1121. array_push($where, ['website.website_name', 'like', '%' . $data['keyword'] . '%']);
  1122. }
  1123. if (isset($data['website_column_id']) && !empty($data['website_column_id'])) {
  1124. array_push($where, ['website.website_column_id', '=', $data['website_column_id']]);
  1125. }
  1126. $result = Website::where($where)
  1127. ->with(["websiteCategory" => function ($query) {
  1128. $query->where(['pid' => 0])->select('website_id', 'name', 'alias', 'category_id');
  1129. }])
  1130. ->limit($data['pageSize'])->orderBy("updated_at", "desc")->offset(($data['page'] - 1) * $data['pageSize'])
  1131. ->get();
  1132. $count = Website::where($where)->count();
  1133. if (empty($result)) {
  1134. return Result::error("没有数据", 0);
  1135. }
  1136. $data = [
  1137. 'rows' => $result->toArray(),
  1138. 'count' => $count,
  1139. ];
  1140. if ($result) {
  1141. return Result::success($data);
  1142. } else {
  1143. return Result::error("查询失败", 0);
  1144. }
  1145. }
  1146. /**
  1147. * 删除网站下的所有导航
  1148. * @param array $data
  1149. * @return array
  1150. */
  1151. public function delWebsiteAllCategory(array $data): array
  1152. {
  1153. $website_id = $data['website_id'];
  1154. $result = WebsiteCategory::where(['website_id' => $website_id])->delete();
  1155. if ($result) {
  1156. return Result::success($result);
  1157. } else {
  1158. return Result::error("删除失败", 0);
  1159. }
  1160. }
  1161. /**
  1162. * 获取网站下的某一个导航
  1163. * @param array $data
  1164. * @return array
  1165. */
  1166. public function getWebsiteCategoryOnes(array $data): array
  1167. {
  1168. $website_id = $data['website_id'];
  1169. $category_id = $data['category_id'];
  1170. $result = WebsiteCategory::where(['website_category.website_id' => $website_id, 'website_category.category_id' => $category_id])
  1171. ->first();
  1172. if ($result) {
  1173. return Result::success($result);
  1174. } else {
  1175. return Result::error("查询失败", 0);
  1176. }
  1177. }
  1178. /**
  1179. * 更新网闸下的某一个导航
  1180. * @param array $data
  1181. * @return array
  1182. */
  1183. public function upWebsiteCategoryones(array $data): array
  1184. {
  1185. //处理所有数据
  1186. //获取所有数据
  1187. if (isset($data['all']) && $data['all'] == 'all') {
  1188. $result = WebsiteCategory::get();
  1189. $result = $result->toArray();
  1190. var_dump($result, '------------');
  1191. $pinyin = new Pinyin();
  1192. $letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  1193. for ($i = 0; $i < count($result); $i++) {
  1194. // $randss = substr(str_shuffle($letters), 0, 4);
  1195. $result[$i]['aLIas_pinyin'] = $pinyin->permalink($result[$i]['alias'], '');
  1196. WebsiteCategory::where(['id' => $result[$i]['id']])->update(['aLIas_pinyin' => $result[$i]['aLIas_pinyin']]);
  1197. }
  1198. var_dump($result, '--------222----');
  1199. if ($result) {
  1200. return Result::success($result);
  1201. } else {
  1202. return Result::error("更新失败", 0);
  1203. }
  1204. }
  1205. //处理所有数据
  1206. $where = [
  1207. 'website_id' => $data['website_id'],
  1208. 'category_id' => $data['category_id'],
  1209. ];
  1210. $alias = $data['alias'];
  1211. $pinyin = new Pinyin();
  1212. $aLIas_pinyin = $pinyin->permalink($alias, '');
  1213. //从WebsiteCategory取出alis ,并转成拼音存放到aLIas_pinyin
  1214. $result = WebsiteCategory::where($where)->first();
  1215. $result = $result->toArray();
  1216. //+四位随机字母
  1217. $letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  1218. // 打乱字符串顺序并截取前四位
  1219. // $randss = substr(str_shuffle($letters), 0, 4);
  1220. if ($data['alias_pinyin'] == '') {
  1221. $data['aLIas_pinyin'] = $aLIas_pinyin;
  1222. }
  1223. $result = WebsiteCategory::where($where)->update($data);
  1224. if ($result) {
  1225. return Result::success($result);
  1226. } else {
  1227. return Result::error("更新失败", 0);
  1228. }
  1229. }
  1230. /**
  1231. * 获取网站下的所有导航(包含子导航)
  1232. * @param array $data
  1233. * @return array
  1234. */
  1235. public function getWebsiteAllCategory(array $data): array
  1236. {
  1237. $where = [];
  1238. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1239. array_push($where, ['website_category.website_id', '=', $data['website_id']]);
  1240. }
  1241. // if (isset($data['name']) && !empty($data['name'])) {
  1242. // array_push($where, ['website_category.name', 'like', '%' . $data['name'] . '%']);
  1243. // }
  1244. // if (isset($data['alias']) && !empty($data['alias'])) {
  1245. // array_push($where, ['website_category.alias', 'like', '%' . $data['alias'] . '%']);
  1246. // }
  1247. // if (isset($data['department_id']) && !empty($data['department_id'])) {
  1248. // array_push($where, ['category.department_id', '=', $data['department_id']]);
  1249. // }
  1250. // if (isset($data['city_id']) && !empty($data['city_id'])) {
  1251. // array_push($where, ['category.city_id', '=', $data['city_id']]);
  1252. // }
  1253. $result = WebsiteCategory::where($where)
  1254. ->leftJoin("category", 'website_category.category_id', 'category.id')
  1255. ->select("website_category.*", "category.name as name")
  1256. // ->leftJoin("category", 'website_category.category_id', 'category.id')
  1257. // ->leftJoin("department", 'category.department_id', 'department.id')
  1258. // ->leftJoin("district", 'category.city_id', 'district.id')
  1259. // ->select("website_category.*", "department.name as department_name", "district.name as city_name")
  1260. // ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])
  1261. ->orderBy("sort", "asc")
  1262. ->get();
  1263. // $count = WebsiteCategory::where($where)
  1264. // ->leftJoin("category", 'website_category.category_id', 'category.id')
  1265. // ->leftJoin("department", 'category.department_id', 'department.id')
  1266. // ->leftJoin("district", 'category.city_id', 'district.id')
  1267. // ->count();
  1268. if (empty($result)) {
  1269. return Result::error("没有数据", 0);
  1270. }
  1271. // $data = [
  1272. // 'rows' => $result->toArray(),
  1273. // 'count' => $count,
  1274. // ];
  1275. if ($result) {
  1276. return Result::success($result->toArray());
  1277. } else {
  1278. return Result::error("查询失败", 0);
  1279. }
  1280. }
  1281. /**
  1282. * 递归查询数据
  1283. * @param $id
  1284. * @param $ids
  1285. * @return string
  1286. */
  1287. public function getUnderlingUIds($id, $ids = '')
  1288. {
  1289. $back = Category::where(['pid' => $id])->get();
  1290. $back = $back->toArray();
  1291. if (!empty($back) && is_array($back)) {
  1292. foreach ($back as $v) {
  1293. //防止当前人的ID重复去查询,形成恶性循环
  1294. if ($v['id'] == $id) {
  1295. continue;
  1296. }
  1297. $back2 = Category::where(['pid' => $id])->count('id');
  1298. if ($back2 > 0) {
  1299. $ids = $this->getUnderlingUIds($v['id'], $ids);
  1300. } else {
  1301. $ids .= ',' . $v['id'];
  1302. }
  1303. }
  1304. }
  1305. $ids = $id . ',' . $ids . ',';
  1306. $ids = str_replace(',,', ",", $ids);
  1307. $ids = trim($ids, ',');
  1308. return $ids;
  1309. }
  1310. /**
  1311. * 检测网站名称是否重复
  1312. * @param array $data
  1313. * @return array
  1314. */
  1315. public function checkWebsiteName(array $data): array
  1316. {
  1317. if (isset($data['id'])) {
  1318. $data[] = ['id', "!=", $data['id']];
  1319. unset($data['id']);
  1320. }
  1321. $websiteInfo = Website::query()->where($data)->first();
  1322. if (empty($websiteInfo)) {
  1323. return Result::error("找不到网站", 0);
  1324. }
  1325. return Result::success($websiteInfo->toArray());
  1326. }
  1327. /**
  1328. * 检测网站url是否重复
  1329. * @param array $data
  1330. * @return array
  1331. */
  1332. public function checkWebsiteUrl(array $data): array
  1333. {
  1334. $whereData = [];
  1335. if (isset($data['id'])) {
  1336. $whereData = [['id', "!=", $data['id']]];
  1337. unset($data['id']);
  1338. }
  1339. $websiteInfo = Website::query()->where($whereData)->whereJsonContains('website_url', $data['website_url'])->first();
  1340. if (empty($websiteInfo)) {
  1341. return Result::error("找不到URL", 0);
  1342. }
  1343. return Result::success($websiteInfo->toArray());
  1344. }
  1345. /**
  1346. * 获取网站底部基础信息
  1347. * @param array $data
  1348. * @return array
  1349. */
  1350. public function getWebsiteFootInfo(array $data): array
  1351. {
  1352. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1353. $website_head = Website::where('id', $data['website_id'])
  1354. ->where('status', 1)
  1355. ->select('id', 'website_name', 'logo', 'title', 'keywords', 'description', 'suffix', 'website_url')
  1356. ->first();
  1357. if (empty($website_head)) {
  1358. return Result::error("找不到网站", 0);
  1359. }
  1360. } else {
  1361. return Result::error("参数错误", 0);
  1362. }
  1363. $website_head = Website::where('id', $data['website_id'])
  1364. ->select('id', 'website_name', 'logo', 'title', 'keywords', 'description', 'suffix', 'website_url')->first();
  1365. $website_foot = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1366. if (empty($website_foot)) {
  1367. return Result::error("暂无底部基础信息", 0);
  1368. }
  1369. $website_head['website_url'] = $website_head['website_url'] ? json_decode($website_head['website_url']) : [];
  1370. $result = [
  1371. 'website_foot' => $website_foot,
  1372. 'website_head' => $website_head,
  1373. ];
  1374. return Result::success($result);
  1375. }
  1376. /**
  1377. * 获取网站底部导航
  1378. * @param array $data
  1379. * @return array
  1380. */
  1381. public function getWebsiteFooterCategory(array $data): array
  1382. {
  1383. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1384. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1385. if (empty($website)) {
  1386. return Result::error("找不到网站", 0);
  1387. }
  1388. } else {
  1389. return Result::error("参数错误", 0);
  1390. }
  1391. $result = FooterCategory::where('website_id', $data['website_id'])->get();
  1392. if (empty($result)) {
  1393. return Result::error("暂无底部导航", 0);
  1394. }
  1395. return Result::success($result->toArray());
  1396. }
  1397. /**
  1398. * 获取网站底部导航列表
  1399. * @param array $data
  1400. * @return array
  1401. */
  1402. public function getWebsiteFooterCategoryList(array $data): array
  1403. {
  1404. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1405. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1406. if (empty($website)) {
  1407. return Result::error("找不到网站", 0);
  1408. }
  1409. } else {
  1410. return Result::error("参数错误", 0);
  1411. }
  1412. $footercategory = FooterCategory::where('website_id', $data['website_id'])->where('id', $data['fcat_id'])->first();
  1413. // '底部导航类型 0:内容型;1:列表型;',
  1414. if (!isset($footercategory['type']) || $footercategory['type'] == 0) {
  1415. return Result::error("底部导航id错误", 0);
  1416. } else {
  1417. $query = FooterContent::where('fcat_id', $data['fcat_id']);
  1418. if ($query->count() == 0) {
  1419. return Result::error("暂无底部导航列表", 0);
  1420. } elseif ($query->count() == 1) {
  1421. $result = $query->first();
  1422. } else {
  1423. $result = $query->get();
  1424. }
  1425. }
  1426. return Result::success($result);
  1427. }
  1428. /**
  1429. * 获取网站底部导航
  1430. * @param array $data
  1431. * @return array
  1432. */
  1433. public function getWebsiteFooterCategoryInfo(array $data): array
  1434. {
  1435. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1436. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1437. if (empty($website)) {
  1438. return Result::error("找不到网站", 0);
  1439. }
  1440. } else {
  1441. return Result::error("参数错误", 0);
  1442. }
  1443. if (isset($data['type']) && $data['type'] == 0) {
  1444. $fcatid = FooterCategory::where('website_id', $data['website_id'])->where('id', $data['fcat_id'])->first();
  1445. if (empty($fcatid)) {
  1446. return Result::error("底部导航id错误", 0);
  1447. }
  1448. $result = FooterContent::where('fcat_id', $data['fcat_id'])->first();
  1449. } else {
  1450. $result = FooterContent::where('id', $data['fcat_id'])->first();
  1451. }
  1452. if (empty($result)) {
  1453. return Result::error("暂无底部导航内容", 0);
  1454. }
  1455. return Result::success($result);
  1456. }
  1457. /*
  1458. * 搜索网站二级导航
  1459. * @param array $data
  1460. * @return array
  1461. * */
  1462. public function selectWebsiteCategory(array $data): array
  1463. {
  1464. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1465. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1466. if (empty($website)) {
  1467. return Result::error("暂无该网站", 0);
  1468. }
  1469. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id')->all();
  1470. // return Result::success($category);
  1471. if (empty($category)) {
  1472. return Result::error("暂无此导航", 0);
  1473. }
  1474. $query = Category::whereIn('id', $category);
  1475. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1476. $cityid = District::where('id', $data['cityid'])->first();
  1477. if (empty($cityid)) {
  1478. return Result::error("暂无此城市", 0);
  1479. } else {
  1480. $city_category = $query->whereRaw('JSON_CONTAINS(city_arr_id,?)', [$data['cityid']])->pluck('id');
  1481. // $where[] = ['JSON_CONTAINS(city_arr_id, ?)', $data['cityid']];
  1482. if (empty($city_category)) {
  1483. return Result::error("暂无此城市下的导航", 0);
  1484. }
  1485. $result['catid'] = $city_category;
  1486. $city = 1;
  1487. // var_dump("城市====================",$result);
  1488. }
  1489. }
  1490. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1491. $departmentid = Department::where('id', $data['department_id'])->first();
  1492. if (empty($departmentid)) {
  1493. return Result::error("暂无此部门", 0);
  1494. } else {
  1495. $depart_category = $query->whereRaw('JSON_CONTAINS(department_arr_id,?)', [$data['department_id']])->pluck('id');
  1496. if (empty($depart_category)) {
  1497. return Result::error("暂无此部门下的导航", 0);
  1498. }
  1499. $result['catid'] = $depart_category;
  1500. // var_dump("职能部门*******************",$result);
  1501. $department = 1;
  1502. }
  1503. }
  1504. if (!empty($city) && !empty($department)) {
  1505. // var_dump("城市和职能部门----------------------",$result);
  1506. $sel_category = $query->whereRaw('JSON_CONTAINS(city_arr_id,?)', [$data['cityid']])->whereRaw('JSON_CONTAINS(department_arr_id,?)', [$data['department_id']])->pluck('id');
  1507. if (empty($sel_category)) {
  1508. return Result::error("暂无此城市和职能部门下的导航", 0);
  1509. }
  1510. $result['catid'] = $sel_category;
  1511. }
  1512. if (empty($result)) {
  1513. return Result::error("暂无导航", 0);
  1514. }
  1515. // department_id
  1516. } else {
  1517. return Result::error("参数错误", 0);
  1518. }
  1519. return Result::success($result);
  1520. }
  1521. /**
  1522. * 获取网站栏目seo
  1523. * @param array $data
  1524. * @return array
  1525. */
  1526. public function getWebsiteCategoryHead(array $data): array
  1527. {
  1528. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1529. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1530. if (empty($website)) {
  1531. return Result::error("找不到网站", 0);
  1532. }
  1533. } else {
  1534. return Result::error("参数错误", 0);
  1535. }
  1536. if (isset($data['catid']) && !empty($data['catid'])) {
  1537. $result = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->first();
  1538. }
  1539. if (empty($result)) {
  1540. return Result::error("暂无导航", 0);
  1541. }
  1542. $result['website_name'] = $website['website_name'] ?? '';
  1543. $result['suffix'] = $website['suffix'] ?? '';
  1544. return Result::success($result);
  1545. }
  1546. /*
  1547. * 获取某个栏目
  1548. * @param array $data
  1549. * @return array
  1550. * */
  1551. public function getOneWebsiteCategory(array $data): array
  1552. {
  1553. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1554. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1555. if (empty($website)) {
  1556. return Result::error("暂无该网站", 0);
  1557. }
  1558. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['category_id'])->first();
  1559. if (empty($category)) {
  1560. return Result::error("暂无此导航", 0);
  1561. }
  1562. $category['children_count'] = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['category_id'])->count();
  1563. $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();
  1564. $category['parent_id'] = $parent['parent_id'] ?? '';
  1565. $category['parent_pinyin'] = $parent['aLIas_pinyin'] ?? '';
  1566. $category['parent_name'] = $parent['parent_name'] ?? '';
  1567. return Result::success($category);
  1568. } else {
  1569. return Result::error("参数错误", 0);
  1570. }
  1571. }
  1572. // 自助建站--fr-------------------
  1573. /**
  1574. * 获取并搜索 网站模板信息
  1575. * @param array $data
  1576. * @return array
  1577. */
  1578. public function getWebsiteintel(array $data): array
  1579. {
  1580. //查询所有网站模板信息
  1581. $query = Website::where('website.status', 1)
  1582. ->leftJoin("website_template_info", "website_template_info.website_id", "website.id")
  1583. ->leftJoin("template", "template.id", "website_template_info.template_id")
  1584. ->leftJoin("template_class", "template_class.id", "template.template_class_id")
  1585. ->select(
  1586. "website_template_info.id",
  1587. "template_class.name",
  1588. "website.id as website_id",
  1589. "website.website_name",
  1590. "website.website_url",
  1591. "website_template_info.action_id",
  1592. "website_template_info.created_at",
  1593. "website_template_info.updated_at",
  1594. "website_template_info.page_type",
  1595. DB::raw("COALESCE(website_template_info.status, 0) as template_status"),
  1596. "template.template_name"
  1597. );
  1598. //若存在条件;则在$query的基础上进行筛选
  1599. if (isset($data['website_name']) && !empty($data['website_name'])) {
  1600. $query->where('website.website_name', 'like', '%' . $data['website_name'] . '%');
  1601. }
  1602. if (isset($data['status']) && !empty($data['status'])) {
  1603. $query->where('website_template_info.status', $data['status']);
  1604. }
  1605. $count = $query->count();
  1606. $query->limit($data['pageSize'])
  1607. ->offset(($data['page'] - 1) * $data['pageSize'])
  1608. ->orderBy("website_template_info.updated_at", "desc");
  1609. $rep = $query->get();
  1610. if ($rep->count() == 0) {
  1611. return Result::error("没有查找到相关数据", 0);
  1612. } else {
  1613. $rep->each(function ($item) {
  1614. if (!empty($item->page_type)) {
  1615. $pageTypeArray = json_decode($item->page_type, true);
  1616. if (is_array($pageTypeArray)) {
  1617. $item->page_type = $pageTypeArray;
  1618. }
  1619. }
  1620. });
  1621. $result = [
  1622. "rows" => $rep->toArray(),
  1623. "count" => $count,
  1624. ];
  1625. return Result::success($result);
  1626. }
  1627. // return Result::success($result);
  1628. }
  1629. /**
  1630. * 添加网站基础信息
  1631. * @param array $data
  1632. * @return array
  1633. */
  1634. public function addWebsiteTemplateintel(array $data): array
  1635. {
  1636. $website = Website::where('website.id', $data['website_id'])->first();
  1637. if (empty($website)) {
  1638. return Result::error("请输入正确的网站id!", 0);
  1639. }
  1640. if (empty($website['website_column_id'])) {
  1641. return Result::error("请先关联导航池!", 0);
  1642. }
  1643. // 获取此网站的底部导航 类型 type: 0:内容型底部导航(只有一条详情内容);1:列表型底部导航(可以有多条详情内容)
  1644. $foot_type = FooterCategory::where('website_id', $data['website_id'])->pluck('type')->toArray();
  1645. if (empty($foot_type)) {
  1646. return Result::error("请先关联底部导航池!", 0);
  1647. } elseif (in_array(1, $foot_type)) {
  1648. $foot_type = 1;
  1649. } else {
  1650. $foot_type = 0;
  1651. }
  1652. $result['foot_type'] = $foot_type;
  1653. // 友情链接类型'1:图片 2:文字 3:底部';
  1654. $types = Link::where('website_id', $data['website_id'])->pluck('type')->toArray();
  1655. $missingTypes = [];
  1656. if (!in_array(1, $types)) {
  1657. $missingTypes[] = "文字链接";
  1658. }
  1659. if (!in_array(2, $types)) {
  1660. $missingTypes[] = "图片链接";
  1661. }
  1662. if (!in_array(3, $types)) {
  1663. $missingTypes[] = "底部链接";
  1664. }
  1665. if (!empty($missingTypes)) {
  1666. $errorMessage = "请先添加 " . implode(" 和 ", $missingTypes) . "!";
  1667. return Result::error($errorMessage, 0);
  1668. }
  1669. if (isset($data['page_type'])) {
  1670. // 删除重复元素并重新索引数组
  1671. $data['page_type'] = array_unique($data['page_type']);
  1672. $data['page_type'] = array_values($data['page_type']);
  1673. if (in_array(1, $data['page_type']) && in_array(7, $data['page_type'])) {
  1674. // 数组中同时包含值为 1(首页) 和值为 7 (底部导航详情页)的元素
  1675. $info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1676. if (empty($info)) {
  1677. // 将数组转换为 JSON 字符串
  1678. $data['page_type'] = json_encode($data['page_type']) ?? '';
  1679. // 操作状态:1:填写完成基础信息;2:选择完成模板;0:未构建
  1680. $data['action_id'] = 1;
  1681. try {
  1682. $result = WebsiteTemplateInfo::insertGetId($data);
  1683. } catch (\Exception $e) {
  1684. if ($e->getCode() == 22001) {
  1685. $errorMessage = $e->getMessage();
  1686. return Result::error("请检查表单,某个字段超出了长度限制!");
  1687. } else {
  1688. // 处理其他类型的数据库错误
  1689. return Result::error("插入操作失败: " . $e->getMessage());
  1690. }
  1691. return Result::error("添加失败!", 0);
  1692. }
  1693. } else {
  1694. return Result::error("该网站已经构建过了!", 0);
  1695. }
  1696. } else {
  1697. return Result::error("请先选择首页和底部导航详情页!", 0);
  1698. }
  1699. }
  1700. if (empty($result)) {
  1701. return Result::error("添加失败!", 0);
  1702. } else {
  1703. return Result::success($result);
  1704. }
  1705. }
  1706. /**
  1707. * 获取网站基础信息
  1708. *
  1709. * @return array
  1710. */
  1711. public function getWebsiteTemplateintel(array $data): array
  1712. {
  1713. $result = WebsiteTemplateInfo::where('website_template_info.website_id', $data['website_id'])
  1714. ->leftJoin('footer_category', 'footer_category.website_id', 'website_template_info.website_id')
  1715. ->leftJoin('website', 'website.id', 'website_template_info.website_id')
  1716. ->select(
  1717. "website_template_info.*",
  1718. "footer_category.type",
  1719. "website.website_name",
  1720. "website.id as website_id"
  1721. )
  1722. ->first();
  1723. if (empty($result['website_name'])) {
  1724. return Result::error("请输入正确的网站id!", 0);
  1725. }
  1726. if ($result) {
  1727. $result['page_type'] = json_decode($result['page_type'], true);
  1728. return Result::success($result);
  1729. } else {
  1730. return Result::error("请先添加网站基础信息!", 0);
  1731. }
  1732. }
  1733. /**
  1734. * 修改网站基础信息
  1735. *
  1736. * @return array
  1737. */
  1738. public function upWebsiteTemplateintel(array $data): array
  1739. {
  1740. $web = Website::where('website.id', $data['website_id'])->first();
  1741. if (empty($web)) {
  1742. return Result::error("请输入正确的网站id!", 0);
  1743. }
  1744. $where = ['website_id' => $data['website_id']];
  1745. $result = WebsiteTemplateInfo::where($where)->first();
  1746. if (empty($result)) {
  1747. return Result::error("请先添加网站基础信息!", 0);
  1748. } else {
  1749. unset($data['website_id']);
  1750. // 删除重复元素
  1751. $data['page_type'] = array_unique($data['page_type']);
  1752. // 重新索引数组
  1753. $data['page_type'] = array_values($data['page_type']);
  1754. // 数组中同时包含值为 1(首页) 和值为 7 (底部导航详情页)的元素
  1755. if (in_array(1, $data['page_type']) && in_array(7, $data['page_type'])) {
  1756. // 将数组转换为 JSON 字符串
  1757. $data['page_type'] = json_encode($data['page_type']) ?? '';
  1758. try {
  1759. $result = WebsiteTemplateInfo::where($where)->update($data);
  1760. } catch (\Exception $e) {
  1761. if ($e->getCode() == 22001) {
  1762. $errorMessage = $e->getMessage();
  1763. return Result::error("请检查表单,某个字段超出了长度限制!");
  1764. } else {
  1765. // 处理其他类型的数据库错误
  1766. return Result::error("修改操作失败: " . $e->getMessage());
  1767. }
  1768. return Result::error("修改失败!", 0);
  1769. }
  1770. } else {
  1771. return Result::error("请先选择首页和底部导航详情页!", 0);
  1772. }
  1773. }
  1774. if (empty($result)) {
  1775. return Result::error("修改失败!", 0);
  1776. } else {
  1777. return Result::success($result);
  1778. }
  1779. }
  1780. /**
  1781. * 获取所有网站风格信息
  1782. *
  1783. * @return array
  1784. */
  1785. public function getAllTemplateClass(array $data): array
  1786. {
  1787. $result = TemplateClass::all();
  1788. if (empty($result)) {
  1789. return Result::error("没有查找到相关数据!", 0);
  1790. } else {
  1791. return Result::success($result);
  1792. }
  1793. }
  1794. /**
  1795. * 搜索并获取网站模板信息
  1796. * @param array $data
  1797. * @return array
  1798. */
  1799. public function getWebsiteTemplateList(array $data): array
  1800. {
  1801. $website = Website::where('website.id', $data['website_id'])->first();
  1802. if (empty($website)) {
  1803. return Result::error("请输入正确的网站id!", 0);
  1804. } else {
  1805. $page_type = WebsiteTemplateInfo::where('website_id', $data['website_id'])->select('page_type')->first();
  1806. if (empty($page_type)) {
  1807. return Result::error("此网站还未添加基础信息!", 0);
  1808. } else {
  1809. $where = json_decode($page_type['page_type'], true);
  1810. // $where = $data["page_type"];
  1811. if (isset($data['template_class_id']) && !empty($data['template_class_id'])) {
  1812. $template_class = TemplateClass::where('id', $data['template_class_id'])->first();
  1813. if (empty($template_class)) {
  1814. return Result::error("请输入正确的模板风格id!", 0);
  1815. } else {
  1816. // 获取指定风格下的模板
  1817. $rep = Template::where('template_class_id', $data['template_class_id'])
  1818. ->where(function ($query) use ($where) {
  1819. foreach ($where as $value) {
  1820. $query->whereJsonContains('template_img', ['value' => $value]);
  1821. }
  1822. })
  1823. ->limit($data['pageSize'])
  1824. ->offset(($data['page'] - 1) * $data['pageSize'])
  1825. ->orderBy("template.updated_at", "desc")
  1826. ->get();
  1827. $count = Template::where('template_class_id', $data['template_class_id'])
  1828. ->where(function ($query) use ($where) {
  1829. foreach ($where as $value) {
  1830. $query->whereJsonContains('template_img', ['value' => $value]);
  1831. }
  1832. })->count();
  1833. }
  1834. } else {
  1835. //获取所有模板
  1836. $rep = Template::where(function ($query) use ($where) {
  1837. foreach ($where as $value) {
  1838. $query->whereJsonContains('template_img', ['value' => $value]);
  1839. }
  1840. })
  1841. ->limit($data['pageSize'])
  1842. ->offset(($data['page'] - 1) * $data['pageSize'])
  1843. ->orderBy("template.updated_at", "desc")
  1844. ->get();
  1845. $count = Template::where(function ($query) use ($where) {
  1846. foreach ($where as $value) {
  1847. $query->whereJsonContains('template_img', ['value' => $value]);
  1848. }
  1849. })->count();
  1850. }
  1851. if (empty($rep) || $rep->count() == 0) {
  1852. return Result::error("没有查找到相关数据!", 0);
  1853. } else {
  1854. // 过滤 template_img 字段 只获取 基础信息中 包含的模板图片
  1855. // $rep->each(function ($item) use ($where) {
  1856. // $template_img = json_decode($item->template_img, true);
  1857. // if(is_array($template_img)){
  1858. // $filtered_img = array_filter($template_img, function ($img) use ($where) {
  1859. // return isset($img['value']) && in_array($img['value'], $where);
  1860. // });
  1861. // }
  1862. // $item->template_img = $filtered_img;
  1863. // });
  1864. // $result = [
  1865. // "rows" => $rep->toArray(),
  1866. // "count" => $count
  1867. // ];
  1868. $rep->each(function ($item) use ($where) {
  1869. $template_img = json_decode($item->template_img, true);
  1870. if (is_array($template_img)) {
  1871. $filtered_img = array_filter($template_img, function ($img) use ($where) {
  1872. return isset($img['value']) && in_array($img['value'], $where);
  1873. });
  1874. // 对过滤后的数组进行重新排序
  1875. $sorted_img = array_values($filtered_img);
  1876. $item->template_img = $sorted_img;
  1877. } else {
  1878. $item->template_img = []; // 如果无法解码为数组,则设置为空数组
  1879. }
  1880. });
  1881. $result = [
  1882. "rows" => $rep->toArray(),
  1883. "count" => $count,
  1884. ];
  1885. }
  1886. }
  1887. }
  1888. return Result::success($result);
  1889. }
  1890. /**
  1891. * 添加网站模板
  1892. * @param array $data
  1893. */
  1894. public function addWebsiteTemplateclassintel(array $data): array
  1895. {
  1896. $template = Template::where('id', $data['template_id'])->first();
  1897. $web = Website::where('id', $data['website_id'])->first();
  1898. if (empty($template)) {
  1899. return Result::error("请输入正确的模板id", 0);
  1900. }
  1901. if (empty($web)) {
  1902. return Result::error("请输入正确的网站id", 0);
  1903. }
  1904. $result = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['template_id' => $data['template_id'], 'action_id' => 2]);
  1905. if (empty($result)) {
  1906. return Result::error("添加失败", 0);
  1907. } else {
  1908. return Result::success($result);
  1909. }
  1910. }
  1911. /**
  1912. * 获取网站模板信息
  1913. * @param array $data
  1914. */
  1915. public function getWebsiteTemplateclassintel(array $data): array
  1916. {
  1917. // return Result::success($data);
  1918. $template = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1919. if (empty($template)) {
  1920. return Result::error("请输入正确的搭建网站id", 0);
  1921. }
  1922. $page_type = json_decode($template['page_type'], true);
  1923. // 获取指定网站下的基础信息和模板及风格信息
  1924. $result = WebsiteTemplateInfo::where([
  1925. ['website_template_info.website_id', $data['website_id']],
  1926. ['template_id', '!=', null],
  1927. ])
  1928. ->leftJoin('template', 'template.id', 'website_template_info.template_id')
  1929. ->leftJoin('template_class', 'template_class.id', 'template.template_class_id')
  1930. ->where(function ($query) use ($page_type) {
  1931. // 假设 $data['page_type'] 是一个数组,包含需要匹配的 page_type 值
  1932. foreach ($page_type as $pageType) {
  1933. $query->orWhereJsonContains('template.template_img', ['value' => $pageType]);
  1934. }
  1935. })
  1936. ->select(
  1937. 'template.template_name',
  1938. 'template.template_img',
  1939. 'template.id as tid',
  1940. 'template_class.name',
  1941. 'template_class.id as class_id',
  1942. 'website_template_info.page_type',
  1943. 'website_template_info.website_id'
  1944. )
  1945. ->first();
  1946. if (empty($result)) {
  1947. return Result::error("没有查找到相关数据", 0);
  1948. }
  1949. // return Result::success($result);
  1950. // 过滤 template_img 字段 只获取 基础信息中 包含的模板图片
  1951. $template_img = $result['template_img'] !== null ? json_decode($result['template_img'], true) : [];
  1952. $page_type = $result['page_type'] !== null ? json_decode($result['page_type'], true) : [];
  1953. foreach ($template_img as $key => $value) {
  1954. if (!in_array($value['value'], $page_type)) {
  1955. unset($template_img[$key]);
  1956. }
  1957. }
  1958. // return Result::success($result);
  1959. $result['template_img'] = array_values($template_img);
  1960. $result['page_type'] = $page_type;
  1961. // $templateList = $this->getWebsiteTemplateList($data);
  1962. // $count = $templateList['data']['count']??'';
  1963. // $pages = $count / $data['pageSize'];
  1964. // $found = false;
  1965. // while ($pages && !$found) {
  1966. // $templates = $this->getWebsiteTemplateList($pages,$data['pageSize']);
  1967. // $index = array_search($template['template_id'], array_column($templates['rows'], 'id'));
  1968. // if ($index !== false) {
  1969. // $found = true;
  1970. // $result['page'] = $pages;
  1971. // $pages = 0;
  1972. // // echo "查询到的 template 在第 $page 页";
  1973. // }
  1974. // $pages--;
  1975. // }
  1976. return Result::success($result);
  1977. }
  1978. /**
  1979. * 获取网站模板下的板块信息
  1980. * @param array $data
  1981. */
  1982. public function getWebsiteSectorList(array $data): array
  1983. {
  1984. $website = Website::where('id', $data['website_id'])->first();
  1985. if (empty($website)) {
  1986. return Result::error("请输入正确的网站id", 0);
  1987. }
  1988. $template = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1989. if (empty($template['template_id'])) {
  1990. return Result::error("请先添加网站模板", 0);
  1991. }
  1992. $query = Sector::where('template_id', $template['template_id']);
  1993. if ($query->count() == 0) {
  1994. return Result::error("没有查找到相关板块数据", 0);
  1995. } elseif ($query->count() == 1) {
  1996. $sector = $query->first();
  1997. } else {
  1998. $sector = $query->get();
  1999. }
  2000. $result['page_type'] = $template['page_type'];
  2001. $result['tid'] = $template['template_id'];
  2002. $result = [
  2003. "tid" => $template['template_id'],
  2004. "page_type" => $template['page_type'],
  2005. "sector" => $sector,
  2006. ];
  2007. return Result::success($result);
  2008. }
  2009. // 自助建站---------------fr---------------
  2010. // 网站底基础信息--fr-------------------
  2011. /**
  2012. * 添加网站底基础信息
  2013. * @param array $data
  2014. */
  2015. public function addWebFootInfo(array $data): array
  2016. {
  2017. $website = Website::where('id', $data['website_id'])->first();
  2018. if (empty($website)) {
  2019. return Result::error("请输入正确的网站id!", 0);
  2020. }
  2021. $info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  2022. if (!empty($info)) {
  2023. return Result::error("该网站已经添加过了!", 0);
  2024. }
  2025. $result = WebsiteTemplateInfo::where('website_id', $data['website_id'])->insertGetId($data);
  2026. if (empty($result)) {
  2027. return Result::error("请先添加网站基础信息!", 0);
  2028. } else {
  2029. return Result::success($result);
  2030. }
  2031. }
  2032. /**
  2033. * 获取网站底基础信息
  2034. * @param array $data
  2035. */
  2036. public function getWebFootInfo(array $data): array
  2037. {
  2038. $website = Website::where('id', $data['website_id'])->first();
  2039. if (empty($website)) {
  2040. return Result::error("请输入正确的网站id!", 0);
  2041. }
  2042. $result = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  2043. if (empty($result)) {
  2044. return Result::error("请先添加网站基础信息!", 0);
  2045. }
  2046. return Result::success($result);
  2047. }
  2048. /**
  2049. * 修改网站底基础信息
  2050. * @param array $data
  2051. */
  2052. public function upWebFootInfo(array $data): array
  2053. {
  2054. // return Result::success($data);
  2055. $website = Website::where('id', $data['website_id'])->first();
  2056. if (empty($website)) {
  2057. return Result::error("请输入正确的网站id!", 0);
  2058. }
  2059. $web = $data['website_id'];
  2060. unset($data['website_id']);
  2061. $where = ['website_id' => $web];
  2062. // return Result::success($data);
  2063. $result = WebsiteTemplateInfo::where($where)->first();
  2064. if (empty($result)) {
  2065. $data['website_id'] = $web;
  2066. $result = WebsiteTemplateInfo::insertGetId($data);
  2067. // return Result::error("请先添加网站基础信息!",0);
  2068. } else {
  2069. $result = WebsiteTemplateInfo::where($where)->update($data);
  2070. }
  2071. // $where = ['website_id'=>$data['website_id']];
  2072. // unset($data['website_id']);
  2073. // $result = WebsiteTemplateInfo::updateOrInsert($where, $data);
  2074. if (empty($result)) {
  2075. return Result::error("修改失败!", 0);
  2076. }
  2077. return Result::success($result);
  2078. }
  2079. /*
  2080. * 获取父级/子级栏目------路由
  2081. * @param array $data
  2082. * @return array
  2083. * */
  2084. public function getWebsiteParentCategory(array $data): array
  2085. {
  2086. // return Result::success($data);
  2087. if (isset($data['website_id']) && !empty($data['website_id'])) {
  2088. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  2089. }
  2090. if (empty($website)) {
  2091. return Result::error("暂无该网站", 0);
  2092. }
  2093. // 在 Hyperf 中,查询构建器(Builder)没有 `map` 方法,`map` 方法是集合(Collection)的方法。
  2094. // 因此,需要先调用 `get()` 方法获取查询结果集合,再使用 `map` 方法进行处理。
  2095. $category['parent'] = WebsiteCategory::where('website_id', $data['website_id'])
  2096. ->where('pid', 0)
  2097. ->selectRaw("category_id as cid, alias as name, CONCAT('/', '', aLIas_pinyin, '/') as path")
  2098. ->get() // 添加 get() 方法获取结果集合
  2099. ->all();
  2100. // 提前查询所有父级栏目,避免在 map 中多次查询
  2101. // 提前查询所有父级栏目信息并以 category_id 作为键存储
  2102. $parentCategories = WebsiteCategory::where('website_id', $data['website_id'])
  2103. ->where('pid', 0)
  2104. ->select('category_id', 'aLIas_pinyin')
  2105. ->get()
  2106. ->keyBy('category_id');
  2107. // 直接查询子栏目信息
  2108. $child = WebsiteCategory::where('website_id', $data['website_id'])
  2109. ->where('pid', '!=', 0)
  2110. ->select('alias', 'category_id', 'aLIas_pinyin', 'pid')
  2111. ->get();
  2112. // 使用集合的 map 方法处理子栏目信息
  2113. $category['child'] = $child->map(function ($item) use ($parentCategories) {
  2114. $alias = $item->alias;
  2115. $category_id = $item->category_id;
  2116. $aLIas_pinyin = $item->aLIas_pinyin;
  2117. $parent = $parentCategories->get($item->pid);
  2118. $parentAlias = $parent ? $parent->aLIas_pinyin : '';
  2119. $result = [
  2120. 'name' => $alias,
  2121. 'cid' => $category_id
  2122. ];
  2123. if (!empty($aLIas_pinyin) && !empty($parentAlias)) {
  2124. $result['path'] = "/{$parentAlias}/{$aLIas_pinyin}/";
  2125. }
  2126. return $result;
  2127. })->values()->all();
  2128. if (empty($category)) {
  2129. return Result::error("暂无此导航", 0);
  2130. }
  2131. return Result::success($category);
  2132. }
  2133. /**
  2134. * 获取网站栏目信息
  2135. * @param array $data
  2136. */
  2137. public function getWebsiteFootAll(array $data): array
  2138. {
  2139. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  2140. if (empty($website)) {
  2141. return Result::error("暂无该网站", 0);
  2142. }
  2143. // 1:图片 2:文字 3:底部
  2144. $result['foot_cate'] = FooterCategory::where('website_id', $data['website_id'])->get()->all();
  2145. $result['link_img'] = Link::where('website_id', $data['website_id'])->where('type', 1)->where('status', 1)->limit($data['link_imgnum'])->orderBy('sort')->get()->all();
  2146. $result['link_text'] = Link::where('website_id', $data['website_id'])->where('type', 2)->where('status', 1)->limit($data['link_textnum'])->orderBy('sort')->get()->all();
  2147. $result['link_foot'] = Link::where('website_id', $data['website_id'])->where('type', 3)->where('status', 1)->limit($data['link_footnum'])->orderBy('sort')->get()->all();
  2148. $result['foot_info'] = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  2149. if (empty($result)) {
  2150. return Result::error("暂无此网站信息", 0);
  2151. }
  2152. return Result::success($result);
  2153. }
  2154. /**
  2155. * 获取网站顶部信息
  2156. * @param array $data
  2157. */
  2158. public function getWebsiteHead(array $data): array
  2159. {
  2160. $result = Website::where('id', $data['website_id'])->where('status', 1)->select('website_name', 'logo')->first();
  2161. if (empty($result)) {
  2162. return Result::error("暂无该网站", 0);
  2163. }
  2164. return Result::success($result);
  2165. }
  2166. /**
  2167. * 路由匹配
  2168. * @param array $data
  2169. */
  2170. public function getWebsiteRoute(array $data): array
  2171. {
  2172. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  2173. if (empty($website)) {
  2174. return Result::error("暂无该网站", 0);
  2175. }
  2176. if (isset($data['pinyin']) &&!empty($data['pinyin'])) {
  2177. $result = WebsiteCategory::where('website_category.website_id', $data['website_id'])
  2178. ->where('website_category.aLIas_pinyin', $data['pinyin'])
  2179. ->leftJoin('website_category as pc', function ($join) use ($data) {
  2180. $join->on('pc.pid', '=', 'website_category.category_id')
  2181. ->where('pc.website_id', '=', $data['website_id']);
  2182. })
  2183. ->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'))
  2184. ->first();
  2185. }
  2186. if(isset($data['foot_pinyin']) &&!empty($data['foot_pinyin'])){
  2187. $result = FooterCategory::where('website_id',$data['website_id'])->where('name_pinyin',$data['foot_pinyin'])->first(['id']);
  2188. }
  2189. if (!isset($result) || empty($result)) {
  2190. return Result::error("暂无该导航", 0);
  2191. }
  2192. return Result::success($result);
  2193. }
  2194. //20250212 网站标识
  2195. public function addWebsiteGroup(array $data): array
  2196. {
  2197. //判斷name是不是重复
  2198. $websiteGroupInfo = WebsiteGroup::query()->where('name', $data['name'])->first();
  2199. if (!empty($websiteGroupInfo)) {
  2200. return Result::error("网站标识重复", 0);
  2201. }
  2202. //添加信息
  2203. $result = WebsiteGroup::insertGetId($data);
  2204. var_dump($result);
  2205. if (empty($result)) {
  2206. return Result::error("创建失败", 0);
  2207. } else {
  2208. return Result::success($result);
  2209. }
  2210. }
  2211. public function getWebsiteGroupList(array $data): array
  2212. {
  2213. $where = [];
  2214. if (isset($data['name']) && !empty($data['name'])) {
  2215. array_push($where, ['website_group.name', 'like', '%' . $data['name'] . '%']);
  2216. }
  2217. $result = WebsiteGroup::where($where)
  2218. ->limit($data['pageSize'])->orderBy("id", "desc")->offset(($data['page'] - 1) * $data['pageSize'])
  2219. ->get();
  2220. foreach ($result as $websiteGroup) {
  2221. $webIds = json_decode($websiteGroup->web_ids, true);
  2222. $websites = Website::whereIn('id', $webIds)->get();
  2223. $websiteNames = $websites->pluck('website_name', 'id')->toArray();
  2224. $websiteGroup->website_names = $websiteNames;
  2225. $websiteGroup->website_names1 = implode(',', array_values($websiteNames));
  2226. }
  2227. $count = WebsiteGroup::where($where)->count();
  2228. if (empty($result)) {
  2229. return Result::error("没有数据", 0);
  2230. }
  2231. return Result::success(['list' => $result->toArray(), 'count' => $count]);
  2232. }
  2233. public function getWebsiteGroupInfo(array $data): array
  2234. {
  2235. $websiteInfo = WebsiteGroup::query()->where('id', $data['id'])->first();
  2236. $webIds = json_decode($websiteInfo->web_ids, true);
  2237. $websites = Website::whereIn('id', $webIds)->get();
  2238. $websiteNames = $websites->pluck('website_name', 'id')->toArray();
  2239. $websiteInfo->website_names = $websiteNames;
  2240. $websiteInfo->website_names1 = implode(',', array_values($websiteNames));
  2241. if (empty($websiteInfo)) {
  2242. return Result::error("找不到URL", 0);
  2243. }
  2244. return Result::success($websiteInfo->toArray());
  2245. }
  2246. public function updateWebsiteGroup(array $data): array
  2247. {
  2248. $where = [
  2249. 'id' => $data['id'],
  2250. ];
  2251. $insertData = [
  2252. 'name' => $data['name'],
  2253. 'web_ids' => $data['web_ids'],
  2254. ];
  2255. //判斷name是不是重复
  2256. $websiteGroupInfo = WebsiteGroup::query()->where('name', $data['name'])->first();
  2257. if (!empty($websiteGroupInfo) && $websiteGroupInfo->id != $data['id']) {
  2258. return Result::error("网站标识重复", 0);
  2259. }
  2260. $result = WebsiteGroup::where($where)->update($insertData);
  2261. var_dump($result, '------更新');
  2262. if (empty($result)) {
  2263. return Result::error("更新失败", 0);
  2264. } else {
  2265. return Result::success();
  2266. }
  2267. }
  2268. public function deleteWebsiteGroup(array $data): array
  2269. {
  2270. $where = [
  2271. 'id' => $data['id'],
  2272. ];
  2273. //看看user表是不是有这个id
  2274. $userGroup = User::query()->where('sszq', $data['id'])->first();
  2275. if (!empty($userGroup)) {
  2276. return Result::error("有用户在使用该网站标识,不能删除", 0);
  2277. }
  2278. $result = WebsiteGroup::where($where)->delete();
  2279. if (empty($result)) {
  2280. return Result::error("删除失败", 0);
  2281. } else {
  2282. return Result::success();
  2283. }
  2284. }
  2285. public function getWebsiteNavList(array $data): array
  2286. {
  2287. $data['type'] = isset($data['type']) ? $data['type'] : 1;
  2288. $where = [];
  2289. if (isset($data['website_id']) && !empty($data['website_id'])) {
  2290. array_push($where, ['website_id', '=', $data['website_id']]);
  2291. }
  2292. if (isset($data['pid'])) {
  2293. array_push($where, ['pid', '=', $data['pid']]);
  2294. }
  2295. if (isset($data['type']) && !empty($data['type'])) {
  2296. array_push($where, ['type', '=', $data['type']]);
  2297. }
  2298. // 根据站点和type获取websiteCategory 中的id
  2299. $websiteCategoryids = WebsiteCategory::query()
  2300. ->where('website_id', '=', $data['website_id'])
  2301. ->where('type', '=', $data['type'])
  2302. ->pluck('category_arr_id')->toArray();
  2303. var_dump($websiteCategoryids, '------获取websiteCategory 中的id');
  2304. //合并去重
  2305. $category_ids = [];
  2306. foreach ($websiteCategoryids as $key => $value) {
  2307. $v = json_decode($value, true);
  2308. $category_ids = array_unique(array_merge($category_ids, $v));
  2309. }
  2310. // var_dump($category_ids, '------获取websiteCategory 中的id');
  2311. //根据pid取出所有的websiteCategory 中的id
  2312. $list = WebsiteCategory::query()
  2313. ->where('website_id', '=', $data['website_id'])
  2314. ->where('pid', '=', $data['pid'])
  2315. ->whereIn('category_id', $category_ids)
  2316. ->get();
  2317. if (empty($list)) {
  2318. return Result::error("获取失败", 0);
  2319. } else {
  2320. return Result::success($list);
  2321. }
  2322. }
  2323. // 20250307 根据网站标识获和导航获取站点
  2324. public function getWebsiteNavPoolSite(array $data): array
  2325. {
  2326. $where = [];
  2327. if (isset($data['category_id']) && !empty($data['category_id'])) {
  2328. array_push($where, ['category_id', '=', $data['category_id']]);
  2329. }
  2330. $list = WebsiteCategory::query()->where($where)
  2331. ->leftJoin('website', 'website.id', '=', 'website_category.website_id')
  2332. ->select('website_category.*', 'website.website_name')
  2333. ->distinct()
  2334. ->get();
  2335. if (empty($list)) {
  2336. return Result::error("获取失败", 0);
  2337. } else {
  2338. return Result::success($list);
  2339. }
  2340. }
  2341. public function getWebsiteNavPool(array $data): array
  2342. {
  2343. // 初始化查询条件数组
  2344. $query = WebsiteCategory::query();
  2345. // 如果传入了 websiteids,则添加到查询条件中
  2346. if (isset($data['websiteids']) && !empty($data['websiteids'])) {
  2347. $query->whereIn('website_id', $data['websiteids']);
  2348. }
  2349. // 如果传入了 pid,则添加到查询条件中
  2350. if (isset($data['pid'])) {
  2351. $query->where('pid', '=', $data['pid']);
  2352. }
  2353. // 执行查询 唯一性 id
  2354. $list = $query->distinct()->get();
  2355. // 根据查询结果返回相应的结果
  2356. if ($list->isEmpty()) {
  2357. return Result::error("获取失败", 0);
  2358. } else {
  2359. return Result::success($list->toArray());
  2360. }
  2361. }
  2362. /**
  2363. *
  2364. * @param array $data
  2365. * @return array
  2366. */
  2367. public function getAllCategory(array $data): array
  2368. {
  2369. $result = Category::when($data, function ($query) use ($data) {
  2370. if (isset($data['name']) && !empty($data['name'])) {
  2371. $query->where('category.name', 'like', '%' . trim($data['name']) . '%');
  2372. }
  2373. })->get();
  2374. if (empty($result)) {
  2375. return Result::error("获取失败", 0);
  2376. } else {
  2377. return Result::success($result);
  2378. }
  2379. }
  2380. /**
  2381. * 修改网站栏目排序
  2382. * @param array $data
  2383. * @return array
  2384. */
  2385. public function upWebsiteCategorySort(array $data): array
  2386. {
  2387. $where = [
  2388. 'website_id' => $data['website_id'],
  2389. 'id' => $data['id'],
  2390. ];
  2391. $result = WebsiteCategory::where($where)->update($data);
  2392. if ($result) {
  2393. return Result::success($result);
  2394. } else {
  2395. return Result::error("更新失败", 0);
  2396. }
  2397. }
  2398. //获取底部导航内容详情
  2399. public function getFooterContentInfo(array $data): array
  2400. {
  2401. $where = [
  2402. "id" => $data['content_id']
  2403. ];
  2404. $result = FooterContent::where($where)->first();
  2405. if ($result) {
  2406. return Result::success($result);
  2407. } else {
  2408. return Result::error("没有数据");
  2409. }
  2410. }
  2411. //获取底部导航内容列表
  2412. public function getFooterContentList(array $data): array
  2413. {
  2414. $where = [
  2415. "fcat_id" => $data['fcat_id'],
  2416. ];
  2417. switch (intval($data['type'])) {
  2418. case 0:
  2419. $result = FooterContent::where($where)->first();
  2420. break;
  2421. case 1:
  2422. $result = FooterContent::where($where)->get();
  2423. break;
  2424. }
  2425. if ($result) {
  2426. return Result::success($result);
  2427. } else {
  2428. return Result::error("没有数据");
  2429. }
  2430. }
  2431. /**
  2432. * 获取底部导航列表
  2433. * @param array $data
  2434. * @return array
  2435. */
  2436. public function getFooterCategoryList(array $data): array
  2437. {
  2438. $where = [
  2439. "website_id" => $data['website_id']
  2440. ];
  2441. $result = FooterCategory::where($where)->get();
  2442. if ($result) {
  2443. return Result::success($result);
  2444. } else {
  2445. return Result::error("没有数据");
  2446. }
  2447. }
  2448. // --自助建站-----------20250522fr----------------------start
  2449. /**
  2450. * 获取网站模板下的板块信息
  2451. * @param array $data
  2452. * @return array
  2453. */
  2454. public function getStaticResourceList(array $data): array
  2455. {
  2456. // return Result::success($data);
  2457. $where = [];
  2458. if(isset($data['img_alias']) &&!empty($data['img_alias'])){
  2459. array_push($where, ['img_alias', 'like', '%'. $data['img_alias']. '%']);
  2460. }
  2461. if(isset($data['img_type']) &&!empty($data['img_type'])){
  2462. array_push($where, ['img_type', '=', $data['img_type']]);
  2463. }
  2464. if(isset($data['website_name']) &&!empty($data['website_name'])){
  2465. $website = Website::where('website_name','like','%'.$data['website_name'].'%')->first();
  2466. if(empty($website)){
  2467. return Result::error("没有查找到相关数据", 0);
  2468. }else{
  2469. array_push($where, ['website_id', '=', $website['id']]);
  2470. }
  2471. }
  2472. // return Result::success($where);
  2473. $query = WebsiteImg::when(!empty($where), function ($query) use ($where) {
  2474. $query->where($where);
  2475. })
  2476. ->orderBy('updated_at', 'desc');
  2477. $count = $query->count();
  2478. $row = $query->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->get();
  2479. if (empty($row)) {
  2480. return Result::error("没有查找到相关数据", 0);
  2481. } else {
  2482. $result = [
  2483. 'row' => $row,
  2484. 'count' => $count,
  2485. ];}
  2486. return Result::success($result);
  2487. }
  2488. /**
  2489. * 添加网站模板下的板块信息
  2490. * @param array $data
  2491. */
  2492. public function addStaticResource(array $data): array
  2493. {
  2494. // $file = $data['img_url']->file('image');
  2495. // $size = $file->getSize();
  2496. $img_data = [
  2497. 'website_id' => $data['website_id'] ?? 0,
  2498. 'img_alias' => $data['img_alias'] ?? '',
  2499. 'img_url' => $data['img_url'],
  2500. 'img_size' => $data['img_size'],
  2501. ];
  2502. $img = WebsiteImg::insertGetId($img_data);
  2503. if (empty($img)) {
  2504. return Result::error("添加失败", 0);
  2505. }
  2506. $img_id['id'] = $img;
  2507. $url = WebsiteImg::where($img_id)->value('img_url');
  2508. // 1. 分割路径部分(以 / 为分隔符)
  2509. $pathSegments = explode('/', parse_url($url, PHP_URL_PATH));
  2510. // 2. 取最后一个元素作为文件名
  2511. $fileName = end($pathSegments); // 1743041040714597.jpg
  2512. // 3. 分割文件名获取扩展名
  2513. $fileParts = explode('.', $fileName);
  2514. $fileType = end($fileParts); // jpg
  2515. $img_datas = [
  2516. 'img_type' => $fileType,
  2517. 'name' => $fileName
  2518. ];
  2519. $up_img = WebsiteImg::where($img_id)->update($img_datas);
  2520. if (empty($up_img)) {
  2521. return Result::error("修改失败", 0);
  2522. }
  2523. return Result::success($up_img);
  2524. // 将字节转换为更友好的单位
  2525. // $friendlySize = $this->formatFileSize($size);
  2526. // $data['img_size'] = $friendlySize;
  2527. }
  2528. /**
  2529. * 修改网站模板下的板块信息
  2530. * @param array $data
  2531. */
  2532. public function delStaticResource(array $data): array
  2533. {
  2534. $where = [
  2535. 'id' => $data['id'],
  2536. ];
  2537. $result = WebsiteImg::where($where)->delete();
  2538. if (empty($result)) {
  2539. return Result::error("修改失败", 0);
  2540. }
  2541. return Result::success($result);
  2542. }
  2543. // --自助建站-----------20250522fr----------------------end
  2544. }