WebsiteService.php 105 KB

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