WebsiteService.php 102 KB

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