WebsiteService.php 111 KB

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