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. // 1:首页 2:分类页 3:列表页 4:详情页 5:搜索页 6:特殊列表 7:特殊详情页
  1606. if (in_array(1, $data['page_type']) && in_array(7, $data['page_type'])) {
  1607. // 数组中同时包含值为 1(首页) 和值为 7 (底部导航详情页)的元素
  1608. $info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1609. if (empty($info)) {
  1610. // 将数组转换为 JSON 字符串
  1611. $data['page_type'] = json_encode($data['page_type']) ?? '';
  1612. // 操作状态:1:填写完成基础信息;2:选择完成模板;0:未构建
  1613. $data['action_id'] = 1;
  1614. try {
  1615. $result = WebsiteTemplateInfo::insertGetId($data);
  1616. } catch (\Exception $e) {
  1617. if ($e->getCode() == 22001) {
  1618. $errorMessage = $e->getMessage();
  1619. return Result::error("请检查表单,某个字段超出了长度限制!");
  1620. } else {
  1621. // 处理其他类型的数据库错误
  1622. return Result::error("插入操作失败: " . $e->getMessage());
  1623. }
  1624. return Result::error("添加失败!", 0);
  1625. }
  1626. } else {
  1627. return Result::error("该网站已经构建过了!", 0);
  1628. }
  1629. } else {
  1630. return Result::error("请先选择首页和底部导航详情页!", 0);
  1631. }
  1632. }
  1633. if (empty($result)) {
  1634. return Result::error("添加失败!", 0);
  1635. } else {
  1636. return Result::success($result);
  1637. }
  1638. }
  1639. /**
  1640. * 获取网站基础信息
  1641. * @return array
  1642. *
  1643. */
  1644. public function getWebsiteTemplateintel(array $data): array
  1645. {
  1646. $result = WebsiteTemplateInfo::where('website_template_info.website_id', $data['website_id'])
  1647. ->leftJoin('footer_category', 'footer_category.website_id', 'website_template_info.website_id')
  1648. ->leftJoin('website', 'website.id', 'website_template_info.website_id')
  1649. ->select(
  1650. "website_template_info.*",
  1651. "footer_category.type",
  1652. "website.website_name",
  1653. "website.id as website_id"
  1654. )
  1655. ->first();
  1656. if (empty($result['website_name'])) {
  1657. return Result::error("请输入正确的网站id!", 0);
  1658. }
  1659. if ($result) {
  1660. $result['page_type'] = json_decode($result['page_type'], true);
  1661. return Result::success($result);
  1662. } else {
  1663. return Result::error("请先添加网站基础信息!", 0);
  1664. }
  1665. }
  1666. /**
  1667. * 修改网站基础信息
  1668. *
  1669. * @return array
  1670. */
  1671. public function upWebsiteTemplateintel(array $data): array
  1672. {
  1673. $web = Website::where('website.id', $data['website_id'])->first();
  1674. if (empty($web)) {
  1675. return Result::error("请输入正确的网站id!", 0);
  1676. }
  1677. $where = ['website_id' => $data['website_id']];
  1678. $result = WebsiteTemplateInfo::where($where)->first();
  1679. if (empty($result)) {
  1680. return Result::error("请先添加网站基础信息!", 0);
  1681. } else {
  1682. unset($data['website_id']);
  1683. // 删除重复元素
  1684. $data['page_type'] = array_unique($data['page_type']);
  1685. // 重新索引数组
  1686. $data['page_type'] = array_values($data['page_type']);
  1687. // 数组中同时包含值为 1(首页) 和值为 7 (底部导航详情页)的元素
  1688. if (in_array(1, $data['page_type']) && in_array(7, $data['page_type'])) {
  1689. // 将数组转换为 JSON 字符串
  1690. $data['page_type'] = json_encode($data['page_type']) ?? '';
  1691. try {
  1692. $result = WebsiteTemplateInfo::where($where)->update($data);
  1693. } catch (\Exception $e) {
  1694. if ($e->getCode() == 22001) {
  1695. $errorMessage = $e->getMessage();
  1696. return Result::error("请检查表单,某个字段超出了长度限制!");
  1697. } else {
  1698. // 处理其他类型的数据库错误
  1699. return Result::error("修改操作失败: " . $e->getMessage());
  1700. }
  1701. return Result::error("修改失败!", 0);
  1702. }
  1703. } else {
  1704. return Result::error("请先选择首页和底部导航详情页!", 0);
  1705. }
  1706. }
  1707. if (empty($result)) {
  1708. return Result::error("修改失败!", 0);
  1709. } else {
  1710. return Result::success($result);
  1711. }
  1712. }
  1713. /**
  1714. * 获取所有网站风格信息
  1715. *
  1716. * @return array
  1717. */
  1718. public function getAllTemplateClass(array $data): array
  1719. {
  1720. $result = TemplateClass::all();
  1721. if (empty($result)) {
  1722. return Result::error("没有查找到相关数据!", 0);
  1723. } else {
  1724. return Result::success($result);
  1725. }
  1726. }
  1727. /**
  1728. * 搜索并获取网站模板信息
  1729. * @param array $data
  1730. * @return array
  1731. */
  1732. public function getWebsiteTemplateList(array $data): array
  1733. {
  1734. $website = Website::where('website.id', $data['website_id'])->first();
  1735. if (empty($website)) {
  1736. return Result::error("请输入正确的网站id!", 0);
  1737. } else {
  1738. $page_type = WebsiteTemplateInfo::where('website_id', $data['website_id'])->select('page_type')->first();
  1739. if (empty($page_type)) {
  1740. return Result::error("此网站还未添加基础信息!", 0);
  1741. } else {
  1742. $where = json_decode($page_type['page_type'], true);
  1743. // $where = $data["page_type"];
  1744. if (isset($data['template_class_id']) && !empty($data['template_class_id'])) {
  1745. $template_class = TemplateClass::where('id', $data['template_class_id'])->first();
  1746. if (empty($template_class)) {
  1747. return Result::error("请输入正确的模板风格id!", 0);
  1748. } else {
  1749. // 获取指定风格下的模板
  1750. $rep = Template::where('template_class_id', $data['template_class_id'])
  1751. ->where(function ($query) use ($where) {
  1752. foreach ($where as $value) {
  1753. $query->whereJsonContains('template_img', ['value' => $value]);
  1754. }
  1755. })
  1756. ->limit($data['pageSize'])
  1757. ->offset(($data['page'] - 1) * $data['pageSize'])
  1758. ->orderBy("template.updated_at", "desc")
  1759. ->get();
  1760. $count = Template::where('template_class_id', $data['template_class_id'])
  1761. ->where(function ($query) use ($where) {
  1762. foreach ($where as $value) {
  1763. $query->whereJsonContains('template_img', ['value' => $value]);
  1764. }
  1765. })->count();
  1766. }
  1767. } else {
  1768. //获取所有模板
  1769. $rep = Template::where(function ($query) use ($where) {
  1770. foreach ($where as $value) {
  1771. $query->whereJsonContains('template_img', ['value' => $value]);
  1772. }
  1773. })
  1774. ->limit($data['pageSize'])
  1775. ->offset(($data['page'] - 1) * $data['pageSize'])
  1776. ->orderBy("template.updated_at", "desc")
  1777. ->get();
  1778. $count = Template::where(function ($query) use ($where) {
  1779. foreach ($where as $value) {
  1780. $query->whereJsonContains('template_img', ['value' => $value]);
  1781. }
  1782. })->count();
  1783. }
  1784. if (empty($rep) || $rep->count() == 0) {
  1785. return Result::error("没有查找到相关数据!", 0);
  1786. } else {
  1787. // 过滤 template_img 字段 只获取 基础信息中 包含的模板图片
  1788. // $rep->each(function ($item) use ($where) {
  1789. // $template_img = json_decode($item->template_img, true);
  1790. // if(is_array($template_img)){
  1791. // $filtered_img = array_filter($template_img, function ($img) use ($where) {
  1792. // return isset($img['value']) && in_array($img['value'], $where);
  1793. // });
  1794. // }
  1795. // $item->template_img = $filtered_img;
  1796. // });
  1797. // $result = [
  1798. // "rows" => $rep->toArray(),
  1799. // "count" => $count
  1800. // ];
  1801. $rep->each(function ($item) use ($where) {
  1802. $template_img = json_decode($item->template_img, true);
  1803. if (is_array($template_img)) {
  1804. $filtered_img = array_filter($template_img, function ($img) use ($where) {
  1805. return isset($img['value']) && in_array($img['value'], $where);
  1806. });
  1807. // 对过滤后的数组进行重新排序
  1808. $sorted_img = array_values($filtered_img);
  1809. $item->template_img = $sorted_img;
  1810. } else {
  1811. $item->template_img = []; // 如果无法解码为数组,则设置为空数组
  1812. }
  1813. });
  1814. $result = [
  1815. "rows" => $rep->toArray(),
  1816. "count" => $count,
  1817. ];
  1818. }
  1819. }
  1820. }
  1821. return Result::success($result);
  1822. }
  1823. /**
  1824. * 添加网站模板
  1825. * @param array $data
  1826. */
  1827. public function addWebsiteTemplateclassintel(array $data): array
  1828. {
  1829. $template = Template::where('id', $data['template_id'])->first();
  1830. $web = Website::where('id', $data['website_id'])->first();
  1831. if (empty($template)) {
  1832. return Result::error("请输入正确的模板id", 0);
  1833. }
  1834. if (empty($web)) {
  1835. return Result::error("请输入正确的网站id", 0);
  1836. }
  1837. $result = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['template_id' => $data['template_id'], 'action_id' => 2]);
  1838. if (empty($result)) {
  1839. return Result::error("添加失败", 0);
  1840. } else {
  1841. return Result::success($result);
  1842. }
  1843. }
  1844. /**
  1845. * 获取网站模板信息
  1846. * @param array $data
  1847. */
  1848. public function getWebsiteTemplateclassintel(array $data): array
  1849. {
  1850. // return Result::success($data);
  1851. $template = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1852. if (empty($template)) {
  1853. return Result::error("请输入正确的搭建网站id", 0);
  1854. }
  1855. $page_type = json_decode($template['page_type'], true);
  1856. // 获取指定网站下的基础信息和模板及风格信息
  1857. $result = WebsiteTemplateInfo::where([
  1858. ['website_template_info.website_id', $data['website_id']],
  1859. ['website_template_info.template_id', '!=', null],
  1860. ])
  1861. ->leftJoin('template', 'template.id', 'website_template_info.template_id')
  1862. ->leftJoin('template_class', 'template_class.id', 'template.template_class_id')
  1863. ->where(function ($query) use ($page_type) {
  1864. // 假设 $data['page_type'] 是一个数组,包含需要匹配的 page_type 值
  1865. foreach ($page_type as $pageType) {
  1866. $query->orWhereJsonContains('template.template_img', ['value' => $pageType]);
  1867. }
  1868. })
  1869. ->select(
  1870. 'template.template_name',
  1871. 'template.template_img',
  1872. 'template.id as tid',
  1873. 'template_class.name',
  1874. 'template_class.id as class_id',
  1875. 'website_template_info.page_type',
  1876. 'website_template_info.website_id'
  1877. )
  1878. ->first();
  1879. if (empty($result)) {
  1880. return Result::error("没有查找到相关数据", 0);
  1881. }
  1882. // return Result::success($result);
  1883. // 过滤 template_img 字段 只获取 基础信息中 包含的模板图片
  1884. $template_img = $result['template_img'] !== null ? json_decode($result['template_img'], true) : [];
  1885. $page_type = $result['page_type'] !== null ? json_decode($result['page_type'], true) : [];
  1886. foreach ($template_img as $key => $value) {
  1887. if (!in_array($value['value'], $page_type)) {
  1888. unset($template_img[$key]);
  1889. }
  1890. }
  1891. // return Result::success($result);
  1892. $result['template_img'] = array_values($template_img);
  1893. $result['page_type'] = $page_type;
  1894. // $templateList = $this->getWebsiteTemplateList($data);
  1895. // $count = $templateList['data']['count']??'';
  1896. // $pages = $count / $data['pageSize'];
  1897. // $found = false;
  1898. // while ($pages && !$found) {
  1899. // $templates = $this->getWebsiteTemplateList($pages,$data['pageSize']);
  1900. // $index = array_search($template['template_id'], array_column($templates['rows'], 'id'));
  1901. // if ($index !== false) {
  1902. // $found = true;
  1903. // $result['page'] = $pages;
  1904. // $pages = 0;
  1905. // // echo "查询到的 template 在第 $page 页";
  1906. // }
  1907. // $pages--;
  1908. // }
  1909. return Result::success($result);
  1910. }
  1911. /**
  1912. * 获取网站模板下的板块信息
  1913. * @param array $data
  1914. */
  1915. public function getWebsiteSectorList(array $data): array
  1916. {
  1917. $website = Website::where('id', $data['website_id'])->first();
  1918. if (empty($website)) {
  1919. return Result::error("请输入正确的网站id", 0);
  1920. }
  1921. $template = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1922. if (empty($template['template_id'])) {
  1923. return Result::error("请先添加网站模板", 0);
  1924. }
  1925. $query = Sector::where('template_id', $template['template_id']);
  1926. if ($query->count() == 0) {
  1927. return Result::error("没有查找到相关板块数据", 0);
  1928. } elseif ($query->count() == 1) {
  1929. $sector = $query->first();
  1930. } else {
  1931. $sector = $query->get();
  1932. }
  1933. $result['page_type'] = $template['page_type'];
  1934. $result['tid'] = $template['template_id'];
  1935. $result = [
  1936. "tid" => $template['template_id'],
  1937. "page_type" => $template['page_type'],
  1938. "sector" => $sector,
  1939. ];
  1940. return Result::success($result);
  1941. }
  1942. // 自助建站---------------fr---------------
  1943. // 网站底基础信息--fr-------------------
  1944. /**
  1945. * 添加网站底基础信息
  1946. * @param array $data
  1947. */
  1948. public function addWebFootInfo(array $data): array
  1949. {
  1950. $website = Website::where('id', $data['website_id'])->first();
  1951. if (empty($website)) {
  1952. return Result::error("请输入正确的网站id!", 0);
  1953. }
  1954. $info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1955. if (!empty($info)) {
  1956. return Result::error("该网站已经添加过了!", 0);
  1957. }
  1958. $result = WebsiteTemplateInfo::where('website_id', $data['website_id'])->insertGetId($data);
  1959. if (empty($result)) {
  1960. return Result::error("请先添加网站基础信息!", 0);
  1961. } else {
  1962. return Result::success($result);
  1963. }
  1964. }
  1965. /**
  1966. * 获取网站底基础信息
  1967. * @param array $data
  1968. */
  1969. public function getWebFootInfo(array $data): array
  1970. {
  1971. $website = Website::where('id', $data['website_id'])->first();
  1972. if (empty($website)) {
  1973. return Result::error("请输入正确的网站id!", 0);
  1974. }
  1975. $result = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1976. if (empty($result)) {
  1977. return Result::error("请先添加网站基础信息!", 0);
  1978. }
  1979. return Result::success($result);
  1980. }
  1981. /**
  1982. * 修改网站底基础信息
  1983. * @param array $data
  1984. */
  1985. public function upWebFootInfo(array $data): array
  1986. {
  1987. // return Result::success($data);
  1988. $website = Website::where('id', $data['website_id'])->first();
  1989. if (empty($website)) {
  1990. return Result::error("请输入正确的网站id!", 0);
  1991. }
  1992. $web = $data['website_id'];
  1993. unset($data['website_id']);
  1994. $where = ['website_id' => $web];
  1995. // return Result::success($data);
  1996. $result = WebsiteTemplateInfo::where($where)->first();
  1997. if (empty($result)) {
  1998. $data['website_id'] = $web;
  1999. $result = WebsiteTemplateInfo::insertGetId($data);
  2000. // return Result::error("请先添加网站基础信息!",0);
  2001. } else {
  2002. $result = WebsiteTemplateInfo::where($where)->update($data);
  2003. }
  2004. // $where = ['website_id'=>$data['website_id']];
  2005. // unset($data['website_id']);
  2006. // $result = WebsiteTemplateInfo::updateOrInsert($where, $data);
  2007. if (empty($result)) {
  2008. return Result::error("修改失败!", 0);
  2009. }
  2010. return Result::success($result);
  2011. }
  2012. /*
  2013. * 获取父级/子级栏目------路由
  2014. * @param array $data
  2015. * @return array
  2016. * */
  2017. public function getWebsiteParentCategory(array $data): array
  2018. {
  2019. // return Result::success($data);
  2020. if (isset($data['website_id']) && !empty($data['website_id'])) {
  2021. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  2022. }
  2023. if (empty($website)) {
  2024. return Result::error("暂无该网站", 0);
  2025. }
  2026. // 在 Hyperf 中,查询构建器(Builder)没有 `map` 方法,`map` 方法是集合(Collection)的方法。
  2027. // 因此,需要先调用 `get()` 方法获取查询结果集合,再使用 `map` 方法进行处理。
  2028. $category['parent'] = WebsiteCategory::where('website_id', $data['website_id'])
  2029. ->where('pid', 0)
  2030. ->selectRaw("category_id as cid, alias as name, CONCAT('/', '', aLIas_pinyin, '/') as path")
  2031. ->get() // 添加 get() 方法获取结果集合
  2032. ->all();
  2033. // 提前查询所有父级栏目,避免在 map 中多次查询
  2034. // 提前查询所有父级栏目信息并以 category_id 作为键存储
  2035. $parentCategories = WebsiteCategory::where('website_id', $data['website_id'])
  2036. ->where('pid', 0)
  2037. ->select('category_id', 'aLIas_pinyin')
  2038. ->get()
  2039. ->keyBy('category_id');
  2040. // 直接查询子栏目信息
  2041. $child = WebsiteCategory::where('website_id', $data['website_id'])
  2042. ->where('pid', '!=', 0)
  2043. ->select('alias', 'category_id', 'aLIas_pinyin', 'pid')
  2044. ->get();
  2045. // 使用集合的 map 方法处理子栏目信息
  2046. $category['child'] = $child->map(function ($item) use ($parentCategories) {
  2047. $alias = $item->alias;
  2048. $category_id = $item->category_id;
  2049. $aLIas_pinyin = $item->aLIas_pinyin;
  2050. $parent = $parentCategories->get($item->pid);
  2051. $parentAlias = $parent ? $parent->aLIas_pinyin : '';
  2052. $result = [
  2053. 'name' => $alias,
  2054. 'cid' => $category_id
  2055. ];
  2056. if (!empty($aLIas_pinyin) && !empty($parentAlias)) {
  2057. $result['path'] = "/{$parentAlias}/{$aLIas_pinyin}/";
  2058. }
  2059. return $result;
  2060. })->values()->all();
  2061. if (empty($category)) {
  2062. return Result::error("暂无此导航", 0);
  2063. }
  2064. return Result::success($category);
  2065. }
  2066. /**
  2067. * 获取网站栏目信息
  2068. * @param array $data
  2069. */
  2070. public function getWebsiteFootAll(array $data): array
  2071. {
  2072. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  2073. if (empty($website)) {
  2074. return Result::error("暂无该网站", 0);
  2075. }
  2076. // 1:图片 2:文字 3:底部
  2077. $result['foot_cate'] = FooterCategory::where('website_id', $data['website_id'])->get()->all();
  2078. $result['link_img'] = Link::where('website_id', $data['website_id'])->where('type', 1)->where('status', 1)->limit($data['link_imgnum'])->orderBy('sort')->get()->all();
  2079. $result['link_text'] = Link::where('website_id', $data['website_id'])->where('type', 2)->where('status', 1)->limit($data['link_textnum'])->orderBy('sort')->get()->all();
  2080. $result['link_foot'] = Link::where('website_id', $data['website_id'])->where('type', 3)->where('status', 1)->limit($data['link_footnum'])->orderBy('sort')->get()->all();
  2081. $result['foot_info'] = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  2082. if (empty($result)) {
  2083. return Result::error("暂无此网站信息", 0);
  2084. }
  2085. return Result::success($result);
  2086. }
  2087. /**
  2088. * 获取网站顶部信息
  2089. * @param array $data
  2090. */
  2091. public function getWebsiteHead(array $data): array
  2092. {
  2093. $result = Website::where('id', $data['website_id'])->where('status', 1)->select('website_name', 'logo')->first();
  2094. if (empty($result)) {
  2095. return Result::error("暂无该网站", 0);
  2096. }
  2097. return Result::success($result);
  2098. }
  2099. /**
  2100. * 路由匹配
  2101. * @param array $data
  2102. */
  2103. public function getWebsiteRoute(array $data): array
  2104. {
  2105. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  2106. if (empty($website)) {
  2107. return Result::error("暂无该网站", 0);
  2108. }
  2109. if (isset($data['pinyin']) &&!empty($data['pinyin'])) {
  2110. $result = WebsiteCategory::where('website_category.website_id', $data['website_id'])
  2111. ->where('website_category.aLIas_pinyin', $data['pinyin'])
  2112. ->leftJoin('website_category as pc', function ($join) use ($data) {
  2113. $join->on('pc.pid', '=', 'website_category.category_id')
  2114. ->where('pc.website_id', '=', $data['website_id']);
  2115. })
  2116. ->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'))
  2117. ->first();
  2118. }
  2119. if(isset($data['foot_pinyin']) &&!empty($data['foot_pinyin'])){
  2120. $result = FooterCategory::where('website_id',$data['website_id'])->where('name_pinyin',$data['foot_pinyin'])->first(['id']);
  2121. }
  2122. if (!isset($result) || empty($result)) {
  2123. return Result::error("暂无该导航", 0);
  2124. }
  2125. return Result::success($result);
  2126. }
  2127. //20250212 网站标识
  2128. public function addWebsiteGroup(array $data): array
  2129. {
  2130. //判斷name是不是重复
  2131. $websiteGroupInfo = WebsiteGroup::query()->where('name', $data['name'])->first();
  2132. if (!empty($websiteGroupInfo)) {
  2133. return Result::error("网站标识重复", 0);
  2134. }
  2135. //添加信息
  2136. $result = WebsiteGroup::insertGetId($data);
  2137. var_dump($result);
  2138. if (empty($result)) {
  2139. return Result::error("创建失败", 0);
  2140. } else {
  2141. return Result::success($result);
  2142. }
  2143. }
  2144. public function getWebsiteGroupList(array $data): array
  2145. {
  2146. $where = [];
  2147. if (isset($data['name']) && !empty($data['name'])) {
  2148. array_push($where, ['website_group.name', 'like', '%' . $data['name'] . '%']);
  2149. }
  2150. $result = WebsiteGroup::where($where)
  2151. ->limit($data['pageSize'])->orderBy("id", "desc")->offset(($data['page'] - 1) * $data['pageSize'])
  2152. ->get();
  2153. foreach ($result as $websiteGroup) {
  2154. $webIds = json_decode($websiteGroup->web_ids, true);
  2155. $websites = Website::whereIn('id', $webIds)->get();
  2156. $websiteNames = $websites->pluck('website_name', 'id')->toArray();
  2157. $websiteGroup->website_names = $websiteNames;
  2158. $websiteGroup->website_names1 = implode(',', array_values($websiteNames));
  2159. }
  2160. $count = WebsiteGroup::where($where)->count();
  2161. if (empty($result)) {
  2162. return Result::error("没有数据", 0);
  2163. }
  2164. return Result::success(['list' => $result->toArray(), 'count' => $count]);
  2165. }
  2166. public function getWebsiteGroupInfo(array $data): array
  2167. {
  2168. $websiteInfo = WebsiteGroup::query()->where('id', $data['id'])->first();
  2169. $webIds = json_decode($websiteInfo->web_ids, true);
  2170. $websites = Website::whereIn('id', $webIds)->get();
  2171. $websiteNames = $websites->pluck('website_name', 'id')->toArray();
  2172. $websiteInfo->website_names = $websiteNames;
  2173. $websiteInfo->website_names1 = implode(',', array_values($websiteNames));
  2174. if (empty($websiteInfo)) {
  2175. return Result::error("找不到URL", 0);
  2176. }
  2177. return Result::success($websiteInfo->toArray());
  2178. }
  2179. public function updateWebsiteGroup(array $data): array
  2180. {
  2181. $where = [
  2182. 'id' => $data['id'],
  2183. ];
  2184. $insertData = [
  2185. 'name' => $data['name'],
  2186. 'web_ids' => $data['web_ids'],
  2187. ];
  2188. //判斷name是不是重复
  2189. $websiteGroupInfo = WebsiteGroup::query()->where('name', $data['name'])->first();
  2190. if (!empty($websiteGroupInfo) && $websiteGroupInfo->id != $data['id']) {
  2191. return Result::error("网站标识重复", 0);
  2192. }
  2193. $result = WebsiteGroup::where($where)->update($insertData);
  2194. var_dump($result, '------更新');
  2195. if (empty($result)) {
  2196. return Result::error("更新失败", 0);
  2197. } else {
  2198. return Result::success();
  2199. }
  2200. }
  2201. public function deleteWebsiteGroup(array $data): array
  2202. {
  2203. $where = [
  2204. 'id' => $data['id'],
  2205. ];
  2206. //看看user表是不是有这个id
  2207. $userGroup = User::query()->where('sszq', $data['id'])->first();
  2208. if (!empty($userGroup)) {
  2209. return Result::error("有用户在使用该网站标识,不能删除", 0);
  2210. }
  2211. $result = WebsiteGroup::where($where)->delete();
  2212. if (empty($result)) {
  2213. return Result::error("删除失败", 0);
  2214. } else {
  2215. return Result::success();
  2216. }
  2217. }
  2218. public function getWebsiteNavList(array $data): array
  2219. {
  2220. $data['type'] = isset($data['type']) ? $data['type'] : 1;
  2221. $where = [];
  2222. if (isset($data['website_id']) && !empty($data['website_id'])) {
  2223. array_push($where, ['website_id', '=', $data['website_id']]);
  2224. }
  2225. if (isset($data['pid'])) {
  2226. array_push($where, ['pid', '=', $data['pid']]);
  2227. }
  2228. if (isset($data['type']) && !empty($data['type'])) {
  2229. array_push($where, ['type', '=', $data['type']]);
  2230. }
  2231. // 根据站点和type获取websiteCategory 中的id
  2232. $websiteCategoryids = WebsiteCategory::query()
  2233. ->where('website_id', '=', $data['website_id'])
  2234. ->where('type', '=', $data['type'])
  2235. ->pluck('category_arr_id')->toArray();
  2236. var_dump($websiteCategoryids, '------获取websiteCategory 中的id');
  2237. //合并去重
  2238. $category_ids = [];
  2239. foreach ($websiteCategoryids as $key => $value) {
  2240. $v = json_decode($value, true);
  2241. $category_ids = array_unique(array_merge($category_ids, $v));
  2242. }
  2243. // var_dump($category_ids, '------获取websiteCategory 中的id');
  2244. //根据pid取出所有的websiteCategory 中的id
  2245. $list = WebsiteCategory::query()
  2246. ->where('website_id', '=', $data['website_id'])
  2247. ->where('pid', '=', $data['pid'])
  2248. ->whereIn('category_id', $category_ids)
  2249. ->get();
  2250. if (empty($list)) {
  2251. return Result::error("获取失败", 0);
  2252. } else {
  2253. return Result::success($list);
  2254. }
  2255. }
  2256. // 20250307 根据网站标识获和导航获取站点
  2257. public function getWebsiteNavPoolSite(array $data): array
  2258. {
  2259. $where = [];
  2260. if (isset($data['category_id']) && !empty($data['category_id'])) {
  2261. array_push($where, ['category_id', '=', $data['category_id']]);
  2262. }
  2263. $list = WebsiteCategory::query()->where($where)
  2264. ->leftJoin('website', 'website.id', '=', 'website_category.website_id')
  2265. ->select('website_category.*', 'website.website_name')
  2266. ->distinct()
  2267. ->get();
  2268. if (empty($list)) {
  2269. return Result::error("获取失败", 0);
  2270. } else {
  2271. return Result::success($list);
  2272. }
  2273. }
  2274. public function getWebsiteNavPool(array $data): array
  2275. {
  2276. // 初始化查询条件数组
  2277. $query = WebsiteCategory::query();
  2278. // 如果传入了 websiteids,则添加到查询条件中
  2279. if (isset($data['websiteids']) && !empty($data['websiteids'])) {
  2280. $query->whereIn('website_id', $data['websiteids']);
  2281. }
  2282. // 如果传入了 pid,则添加到查询条件中
  2283. if (isset($data['pid'])) {
  2284. $query->where('pid', '=', $data['pid']);
  2285. }
  2286. // 执行查询 唯一性 id
  2287. $list = $query->distinct()->get();
  2288. // 根据查询结果返回相应的结果
  2289. if ($list->isEmpty()) {
  2290. return Result::error("获取失败", 0);
  2291. } else {
  2292. return Result::success($list->toArray());
  2293. }
  2294. }
  2295. /**
  2296. *
  2297. * @param array $data
  2298. * @return array
  2299. */
  2300. public function getAllCategory(array $data): array
  2301. {
  2302. $result = Category::when($data, function ($query) use ($data) {
  2303. if (isset($data['name']) && !empty($data['name'])) {
  2304. $query->where('category.name', 'like', '%' . trim($data['name']) . '%');
  2305. }
  2306. })->get();
  2307. if (empty($result)) {
  2308. return Result::error("获取失败", 0);
  2309. } else {
  2310. return Result::success($result);
  2311. }
  2312. }
  2313. /**
  2314. * 修改网站栏目排序
  2315. * @param array $data
  2316. * @return array
  2317. */
  2318. public function upWebsiteCategorySort(array $data): array
  2319. {
  2320. $where = [
  2321. 'website_id' => $data['website_id'],
  2322. 'id' => $data['id'],
  2323. ];
  2324. $result = WebsiteCategory::where($where)->update($data);
  2325. if ($result) {
  2326. return Result::success($result);
  2327. } else {
  2328. return Result::error("更新失败", 0);
  2329. }
  2330. }
  2331. // --自助建站-----------20250522fr----------------------start
  2332. /**
  2333. * 获取网站模板下的板块信息
  2334. * @param array $data
  2335. * @return array
  2336. */
  2337. public function getStaticResourceList(array $data): array
  2338. {
  2339. // return Result::success($data);
  2340. $where = [];
  2341. if(isset($data['img_alias']) &&!empty($data['img_alias'])){
  2342. array_push($where, ['website_img.img_alias', 'like', '%'. $data['img_alias']. '%']);
  2343. }
  2344. if(isset($data['img_type']) &&!empty($data['img_type'])){
  2345. array_push($where, ['website_img.img_type', '=', $data['img_type']]);
  2346. }
  2347. if(isset($data['website_name']) &&!empty($data['website_name'])){
  2348. $website = Website::where('website_name','like','%'.$data['website_name'].'%')->first();
  2349. if(empty($website)){
  2350. return Result::error("没有查找到相关数据", 0);
  2351. }else{
  2352. array_push($where, ['website_img.website_id', '=', $website['id']]);
  2353. }
  2354. }
  2355. // return Result::success($where);
  2356. $query = WebsiteImg::when(!empty($where), function ($query) use ($where) {
  2357. $query->where($where);
  2358. })
  2359. ->orderBy('updated_at', 'desc');
  2360. $count = $query->count();
  2361. $row = $query->leftJoin('website', 'website.id', '=', 'website_img.website_id')
  2362. ->select('website_img.*', 'website.website_name')
  2363. ->limit($data['pageSize'])
  2364. ->offset(($data['page'] - 1) * $data['pageSize'])
  2365. ->get();
  2366. if (empty($row)) {
  2367. return Result::error("没有查找到相关数据", 0);
  2368. } else {
  2369. $result = [
  2370. 'row' => $row,
  2371. 'count' => $count,
  2372. ];}
  2373. return Result::success($result);
  2374. }
  2375. /**
  2376. * 添加网站模板下的板块信息
  2377. * @param array $data
  2378. */
  2379. public function addStaticResource(array $data): array
  2380. {
  2381. // $file = $data['img_url']->file('image');
  2382. // $size = $file->getSize();
  2383. $img_data = [
  2384. 'website_id' => $data['website_id'] ?? 0,
  2385. 'img_alias' => $data['img_alias'] ?? '',
  2386. 'img_url' => $data['img_url'],
  2387. 'img_size' => $data['img_size'],
  2388. ];
  2389. $img = WebsiteImg::insertGetId($img_data);
  2390. if (empty($img)) {
  2391. return Result::error("添加失败", 0);
  2392. }
  2393. $img_id['id'] = $img;
  2394. $url = WebsiteImg::where($img_id)->value('img_url');
  2395. // 1. 分割路径部分(以 / 为分隔符)
  2396. $pathSegments = explode('/', parse_url($url, PHP_URL_PATH));
  2397. // 2. 取最后一个元素作为文件名
  2398. $fileName = end($pathSegments); // 1743041040714597.jpg
  2399. // 3. 分割文件名获取扩展名
  2400. $fileParts = explode('.', $fileName);
  2401. $fileType = end($fileParts); // jpg
  2402. $img_datas = [
  2403. 'img_type' => $fileType,
  2404. 'name' => $fileName
  2405. ];
  2406. $up_img = WebsiteImg::where($img_id)->update($img_datas);
  2407. if (empty($up_img)) {
  2408. return Result::error("修改失败", 0);
  2409. }
  2410. return Result::success($up_img);
  2411. // 将字节转换为更友好的单位
  2412. // $friendlySize = $this->formatFileSize($size);
  2413. // $data['img_size'] = $friendlySize;
  2414. }
  2415. /**
  2416. * 修改网站模板下的板块信息
  2417. * @param array $data
  2418. */
  2419. public function delStaticResource(array $data): array
  2420. {
  2421. $where = [
  2422. 'id' => $data['id'],
  2423. ];
  2424. $result = WebsiteImg::where($where)->delete();
  2425. if (empty($result)) {
  2426. return Result::error("修改失败", 0);
  2427. }
  2428. return Result::success($result);
  2429. }
  2430. /**
  2431. * 获取尺寸列表
  2432. * @param array $data
  2433. */
  2434. public function getSizeList(array $data): array
  2435. {
  2436. $where = [];
  2437. if(isset($data['width']) &&!empty($data['width'])){
  2438. array_push($where, ['width','like','%'.$data['width'].'%']);
  2439. }
  2440. if(isset($data['height']) &&!empty($data['height'])){
  2441. array_push($where, ['height','like','%'.$data['height'].'%']);
  2442. }
  2443. $query = Size::when($where, function ($query) use ($where) {
  2444. $query->where($where);
  2445. })
  2446. ->orderBy('updated_at', 'desc');
  2447. $count = $query->count();
  2448. $rep = $query
  2449. ->offset(($data['page'] - 1) * $data['pageSize'])
  2450. ->limit($data['pageSize'])
  2451. ->get();
  2452. $result = [
  2453. 'row' => $rep,
  2454. 'count' => $count,
  2455. ];
  2456. if (empty($result)) {
  2457. return Result::error("获取失败", 0);
  2458. } else {
  2459. return Result::success($result);
  2460. }
  2461. }
  2462. /**
  2463. * 添加尺寸
  2464. * @param array $data
  2465. */
  2466. public function addSize(array $data): array
  2467. {
  2468. $size = Size::where('width', $data['width'])->where('height', $data['height'])->first();
  2469. if (!empty($size)) {
  2470. return Result::error("尺寸已存在", 0);
  2471. }
  2472. $result = Size::insertGetId($data);
  2473. if (empty($result)) {
  2474. return Result::error("添加失败", 0);
  2475. }
  2476. return Result::success($result);
  2477. }
  2478. /**
  2479. * 删除尺寸
  2480. * @param array $data
  2481. */
  2482. public function delSize(array $data): array
  2483. {
  2484. $where = [
  2485. 'id' => $data['id'],
  2486. ];
  2487. $result = Size::where($where)->delete();
  2488. if (empty($result)) {
  2489. return Result::error("删除失败", 0);
  2490. }
  2491. return Result::success($result);
  2492. }
  2493. /**
  2494. * 修改尺寸
  2495. * @param array $data
  2496. */
  2497. public function upSize(array $data): array
  2498. {
  2499. $where = [
  2500. 'id' => $data['id'],
  2501. ];
  2502. $size = Size::where('id','!=', $data['id'])->where('width',$data['width'])->where('height',$data['height'])->first();
  2503. if (!empty($size)) {
  2504. return Result::error("尺寸已存在", 0);
  2505. }
  2506. $result = Size::where($where)->update($data);
  2507. if (empty($result)) {
  2508. return Result::error("修改失败", 0);
  2509. }
  2510. return Result::success($result);
  2511. }
  2512. /**
  2513. * 获取尺寸详情
  2514. * @param array $data
  2515. */
  2516. public function getSizeInfo(array $data): array
  2517. {
  2518. $where = [
  2519. 'id' => $data['id'],
  2520. ];
  2521. $result = Size::where($where)->first();
  2522. if (empty($result)) {
  2523. return Result::error("获取失败", 0);
  2524. } else {
  2525. return Result::success($result);
  2526. }
  2527. }
  2528. // --自助建站-----------20250522fr----------------------end
  2529. }