WebsiteService.php 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080
  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\LetterOfComplaint;
  12. use App\Model\Link;
  13. use App\Model\TemplateClass;
  14. use App\Model\Template;
  15. use App\Model\User;
  16. use App\Model\UserInfo;
  17. use App\Model\WebsiteRole;
  18. use App\Model\WebsiteRoleUser;
  19. use App\Model\Website;
  20. use App\Model\WebsiteColumn;
  21. use App\Model\Sector;
  22. use Hyperf\DbConnection\Db;
  23. use Hyperf\RpcServer\Annotation\RpcService;
  24. use App\Tools\Result;
  25. use Carbon\Carbon;
  26. use App\Model\WebsiteCategory;
  27. use App\Model\WebsiteTemplate;
  28. use App\Model\WebsiteTemplateInfo;
  29. use Hamcrest\Arrays\IsArray;
  30. use PhpParser\Node\Stmt\Return_;
  31. use App\Model\WebsiteGroup;
  32. use function PHPUnit\Framework\isNull;
  33. // use Illuminate\Support\Facades\DB;
  34. #[RpcService(name: "WebsiteService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  35. class WebsiteService implements WebsiteServiceInterface
  36. {
  37. /**
  38. * @param string $keyword
  39. * @param int $page
  40. * @param int $pageSize
  41. * @return array
  42. */
  43. public function getWebsitetList(array $data): array
  44. {
  45. $resultWwhere = Website::when($data, function ($query) use ($data) {
  46. if (isset($data['keyword']) && !empty($data['keyword'])) {
  47. $query->where('website.website_name', 'like', '%' . $data['keyword'] . '%');
  48. }
  49. if (isset($data['website_column_id']) && !empty($data['website_column_id'])) {
  50. $query->whereJsonContains("website.website_column_arr_id", intval($data['website_column_id']));
  51. }
  52. if (isset($data['city_id']) && !empty($data['city_id'])) {
  53. $query->whereJsonContains("website.city_arr_id", intval($data['city_id']));
  54. }
  55. });
  56. $count = $resultWwhere->leftJoin("website_column", "website.website_column_id", "website_column.id")
  57. ->leftJoin("district", "district.id", "website.city_id")->count();
  58. $result = $resultWwhere->select("website.*", "website_column.column_name", "district.name as city_name")
  59. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("website.id", "desc")->get();
  60. if (empty($result)) {
  61. return Result::error("没有数据", 0);
  62. }
  63. $data = [
  64. 'rows' => $result->toArray(),
  65. 'count' => $count,
  66. ];
  67. return Result::success($data);
  68. }
  69. /**
  70. * @param array $data
  71. * @return array
  72. */
  73. public function createWebsite(array $data): array
  74. {
  75. var_dump("网站数据:", $data);
  76. $insertData = [
  77. 'website_name' => $data['website_name'],
  78. 'logo' => $data['logo'] ?? '',
  79. 'website_url' => $data['website_url'] ?? '',
  80. // 'city_id'=>$data['city_id']??0,
  81. 'website_column_id' => $data['website_column_id'],
  82. 'title' => $data['title'] ?? '',
  83. 'keywords' => $data['keywords'] ?? '',
  84. 'description' => $data['description'] ?? '',
  85. 'status' => $data['status'] ?? 0,
  86. 'website_column_arr_id' => $data['website_column_arr_id'],
  87. // 'city_arr_id'=>$data['city_arr_id']??[0],
  88. 'template_id' => $data['template_id'] ?? 0,
  89. ];
  90. $result = Website::insertGetId($insertData);
  91. if (empty($result)) {
  92. return Result::error("创建失败", 0);
  93. } else {
  94. return Result::success(["id" => $result]);
  95. }
  96. }
  97. /**
  98. * @param int $id
  99. * @param array $data
  100. * @return array
  101. */
  102. public function updateWebsite(int $id, array $data): array
  103. {
  104. $insertData = [
  105. 'website_name' => $data['website_name'],
  106. 'logo' => $data['logo'] ?? '',
  107. 'website_url' => $data['website_url'] ?? '',
  108. // 'city_id'=>$data['city_id']??0,
  109. 'website_column_id' => $data['website_column_id'],
  110. 'title' => $data['title'] ?? '',
  111. 'keywords' => $data['keywords'] ?? '',
  112. 'description' => $data['description'] ?? '',
  113. 'status' => $data['status'] ?? 0,
  114. 'website_column_arr_id' => $data['website_column_arr_id'],
  115. // 'city_arr_id'=>$data['city_arr_id']??[0],
  116. 'template_id' => $data['template_id'] ?? 0,
  117. ];
  118. $result = Website::where('id', $id)->update($insertData);
  119. var_dump("更新站点", $result);
  120. if (empty($result)) {
  121. return Result::error("更新失败", 0);
  122. } else {
  123. return Result::success();
  124. }
  125. }
  126. /**
  127. * @param int $id
  128. * @return array
  129. */
  130. public function delWebsite(int $id): array
  131. {
  132. $result = Website::where('id', $id)->delete();
  133. if (empty($result)) {
  134. return Result::error("删除失败", 0);
  135. } else {
  136. return Result::success();
  137. }
  138. }
  139. /**
  140. * @param int $id
  141. * @return array
  142. */
  143. public function getWebsiteInfo(int $id): array
  144. {
  145. $where = [
  146. ['website.id', '=', $id],
  147. ];
  148. $result = Website::where($where)
  149. ->leftJoin("template", "template.id", "website.template_id")
  150. ->select("website.*", "template.template_name", "template.template_img")
  151. ->first();
  152. if (empty($result)) {
  153. return Result::error("数据不存在", 0);
  154. } else {
  155. return Result::success($result->toArray());
  156. }
  157. }
  158. /**
  159. * 查询所有的站点栏目
  160. * @return array
  161. */
  162. public function getWebsiteColumn(array $data): array
  163. {
  164. $result = WebsiteColumn::where($data)->get();
  165. if (empty($result)) {
  166. return Result::error("数据不存在", 0);
  167. } else {
  168. return Result::success($result->toArray());
  169. }
  170. }
  171. /**
  172. * @param string $keyword
  173. * @param int $page
  174. * @param int $pageSize
  175. * @return array
  176. */
  177. public function getWebsiteColumnList(array $data): array
  178. {
  179. $where = [];
  180. if (isset($data['keyword']) && $data['keyword']) {
  181. array_push($where, ['website_column.column_name', 'like', '%' . $data['keyword'] . '%']);
  182. }
  183. $result = WebsiteColumn::where($where)
  184. ->leftJoin("website_column as wc", "website_column.pid", "wc.id")
  185. ->select("website_column.*", "wc.column_name as parent_column_name")
  186. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->get();
  187. $count = WebsiteColumn::where($where)->count();
  188. if (empty($result)) {
  189. return Result::error("没有数据", 0);
  190. }
  191. $data = [
  192. 'rows' => $result->toArray(),
  193. 'count' => $count,
  194. ];
  195. return Result::success($data);
  196. }
  197. /**
  198. * @param array $data
  199. * @return array
  200. */
  201. public function createWebsiteColumn(array $data): array
  202. {
  203. $insertData = [
  204. 'column_name' => $data['column_name'],
  205. 'pid' => $data['pid'] ?? '',
  206. 'column_arr_id' => $data['column_arr_id'] ?? [0],
  207. 'sort' => $data['sort'] ?? 0,
  208. 'remark' => $data['remark'] ?? '',
  209. ];
  210. $result = WebsiteColumn::insertGetId($insertData);
  211. if (empty($result)) {
  212. return Result::error("创建失败", 0);
  213. } else {
  214. return Result::success(["id" => $result]);
  215. }
  216. }
  217. /**
  218. * @param int $id
  219. * @param array $data
  220. * @return array
  221. */
  222. public function updateWebsiteColumn(int $id, 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::where('id', $id)->update($insertData);
  232. if (empty($result)) {
  233. return Result::error("更新失败", 0);
  234. } else {
  235. return Result::success();
  236. }
  237. }
  238. /**
  239. * @param int $id
  240. * @return array
  241. */
  242. public function delWebsiteColumn(int $id): array
  243. {
  244. $list = WebsiteColumn::where(['pid' => $id])->get();
  245. if ($list) {
  246. return Result::error("存在子网系,不能删除,请先删除子网系", 0);
  247. }
  248. $result = WebsiteColumn::where('id', $id)->delete();
  249. if (empty($result)) {
  250. return Result::error("删除失败", 0);
  251. } else {
  252. return Result::success();
  253. }
  254. }
  255. /**
  256. * @param string $keyword
  257. * @param int $page
  258. * @param int $pageSize
  259. * @return array
  260. */
  261. public function getWebsiteRoleList(string $keyword, int $page, int $pageSize, int $websiteId): array
  262. {
  263. $where = [
  264. ['role.role_name', 'like', '%' . $keyword . '%'],
  265. ['website_role.website_id', '=', $websiteId],
  266. ];
  267. $result = WebsiteRole::where($where)
  268. ->leftJoin("role", "role.id", "website_role.role_id")
  269. ->select("role.*", "website_role.type", "website_role.role_id", "website_role.id as website_role_id", "website_role.website_id")
  270. ->limit($pageSize)->offset(($page - 1) * $pageSize)->get();
  271. $count = WebsiteRole::where($where)->leftJoin("role", "role.id", "website_role.role_id")->count();
  272. if (empty($result)) {
  273. return Result::error("没有数据", 0);
  274. }
  275. $data = [
  276. 'rows' => $result->toArray(),
  277. 'count' => $count,
  278. ];
  279. return Result::success($data);
  280. }
  281. /**
  282. * @param array $data
  283. * @return array
  284. */
  285. public function createWebsiteRole(array $data): array
  286. {
  287. $insertData = [
  288. 'website_id' => $data['website_id'],
  289. 'role_id' => $data['role_id'] ?? '',
  290. ];
  291. $info = WebsiteRole::where($insertData)->first();
  292. if ($info) {
  293. return Result::error("不能重复添加角色", 0);
  294. }
  295. $insertData['admin_user_id'] = $data['admin_user_id'] ?? '';
  296. $insertData['type'] = $data['type'] ?? '';
  297. $result = WebsiteRole::insertGetId($insertData);
  298. if (empty($result)) {
  299. return Result::error("创建失败", 0);
  300. } else {
  301. return Result::success(["id" => $result]);
  302. }
  303. }
  304. /**
  305. * 暂时用不上
  306. * @param int $id
  307. * @param array $data
  308. * @return array
  309. */
  310. public function updateWebsiteRole(int $id, array $data): array
  311. {
  312. $insertData = [
  313. 'website_id' => $data['website_id'],
  314. 'type' => $data['type'] ?? '',
  315. ];
  316. $result = WebsiteRole::where('id', $id)->update($insertData);
  317. if (empty($result)) {
  318. return Result::error("更新失败", 0);
  319. } else {
  320. return Result::success();
  321. }
  322. }
  323. /**
  324. * @param int $id
  325. * @return array
  326. */
  327. public function delWebsiteRole(int $id): array
  328. {
  329. $result = WebsiteRole::where('id', $id)->delete();
  330. if (empty($result)) {
  331. return Result::error("删除失败", 0);
  332. } else {
  333. return Result::success();
  334. }
  335. }
  336. /**
  337. * @param string $keyword
  338. * @param int $page
  339. * @param int $pageSize
  340. * @return array
  341. */
  342. public function getWebsiteRoleUserList(string $keyword, int $page, int $pageSize, int $websiteId, int $roleId): array
  343. {
  344. $where = [
  345. ['website_role_user.website_id', '=', $websiteId],
  346. ['website_role_user.role_id', '=', $roleId],
  347. ];
  348. $count = WebsiteRoleUser::where($where)->count();
  349. $where[] = ['u.user_name', 'like', '%' . $keyword . '%'];
  350. $result = WebsiteRoleUser::where($where)
  351. ->leftJoin("user as u", "website_role_user.user_id", "u.id")
  352. ->leftJoin("website as w", "website_role_user.website_id", "u.id")
  353. ->leftJoin("role as r", "website_role_user.role_id", "r.id")
  354. ->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')
  355. ->limit($pageSize)->offset(($page - 1) * $pageSize)->get();
  356. if (empty($result)) {
  357. return Result::error("没有数据", 0);
  358. }
  359. $data = [
  360. 'rows' => $result->toArray(),
  361. 'count' => $count,
  362. ];
  363. return Result::success($data);
  364. }
  365. /**
  366. * @param array $data
  367. * @return array
  368. */
  369. public function createWebsiteRoleUser(array $data): array
  370. {
  371. $insertData = [
  372. 'website_id' => $data['website_id'],
  373. 'user_id' => $data['user_id'] ?? '',
  374. ];
  375. $info = WebsiteRoleUser::where($insertData)->first();
  376. if ($info) {
  377. return Result::error("不能重复添加角色用户", 0);
  378. }
  379. $insertData['role_id'] = $data['role_id'] ?? '';
  380. $insertData['admin_user_id'] = $data['admin_user_id'] ?? '';
  381. $insertData['type'] = $data['type'] ?? '';
  382. $result = WebsiteRoleUser::insertGetId($insertData);
  383. if (empty($result)) {
  384. return Result::error("创建失败", 0);
  385. } else {
  386. return Result::success(["id" => $result]);
  387. }
  388. }
  389. /**
  390. * @param int $id
  391. * @param array $data
  392. * @return array
  393. */
  394. public function updateWebsiteRoleUser(int $id, array $data): array
  395. {
  396. $insertData = [
  397. 'website_id' => $data['website_id'],
  398. 'type' => $data['type'] ?? '',
  399. 'type_id' => $data['type_id'] ?? '',
  400. 'role_id' => $data['role_id'] ?? '',
  401. ];
  402. $result = WebsiteRoleUser::where('id', $id)->update($insertData);
  403. if (empty($result)) {
  404. return Result::error("更新失败", 0);
  405. } else {
  406. return Result::success();
  407. }
  408. }
  409. /**
  410. * @param int $id
  411. * @return array
  412. */
  413. public function delWebsiteRoleUser(int $id): array
  414. {
  415. $result = WebsiteRoleUser::where('id', $id)->delete();
  416. if (empty($result)) {
  417. return Result::error("删除失败", 0);
  418. } else {
  419. return Result::success();
  420. }
  421. }
  422. /**
  423. * 根据域名获取网站 站点id
  424. * @param array $data
  425. * @return array
  426. */
  427. public function getWebsiteId(array $data): array
  428. {
  429. $result = Website::whereJsonContains('website_url', $data['website_url'])->first();
  430. if (empty($result)) {
  431. return Result::error("查询站点失败", 0);
  432. } else {
  433. return Result::success($result);
  434. }
  435. }
  436. /**
  437. * 查询网站下面的导航
  438. * @param array $data
  439. * @return array
  440. */
  441. public function getWebsiteCategory(array $data): array
  442. {
  443. $where = [
  444. 'website_id' => $data['website_id'],
  445. 'pid' => 0,
  446. ];
  447. $result = WebsiteCategory::where($where)->orderBy('sort', 'asc')->get();
  448. if (empty($result)) {
  449. return Result::error("查询站点栏目失败", 0);
  450. } else {
  451. return Result::success($result);
  452. }
  453. }
  454. /**
  455. * 查询网站的广告
  456. * @param array $data
  457. * @return array
  458. */
  459. public function getWebsiteAdvertisement(array $data): array
  460. {
  461. $where = [
  462. 'website_id' => $data['website_id'],
  463. 'ad_place.status' => 1,
  464. // 'ad.status' => 1,
  465. ];
  466. if(isset($data['ad_tag']) && !empty($data['ad_tag'])){
  467. $now = Carbon::now()->format('Y-m-d H:i:s'); // 获取当前时间
  468. $where[] = ['ad_place.ad_tag','like','%'.$data['ad_tag'].'%'];
  469. $result = AdPlace::where($where)
  470. ->leftJoin("ad", function ($join) use ($now) {
  471. $join->on("ad.pid", "=", "ad_place.id")
  472. ->where('ad.status', 1)
  473. ->where('ad.fromtime', '<=', $now)
  474. ->where('ad.totime', '>=', $now);
  475. })
  476. ->select("ad_place.*",'ad.*',"ad_place.id as ad_place_id","ad.name as ad_name")
  477. ->get()->all();
  478. if(empty($result)){
  479. return Result::error("此广告位不存在!",0);
  480. }
  481. }else{
  482. return Result::error("请选择广告位!",0);
  483. }
  484. return Result::success($result);
  485. }
  486. /**
  487. *
  488. * @param array $data
  489. * @return array
  490. */
  491. /**网站行政职能搜索 */
  492. public function selectWebsiteDepartment(array $data): array
  493. {
  494. $depart = Department::where('pid', 0)->orderBy('id', 'asc')->limit(10)->get();
  495. if (isset($data['keyword']) && !empty($data['keyword'])) {
  496. $departments = Department::where('name', 'like', '%' . $data['keyword'] . '%')->get();
  497. if (empty($departments)) {
  498. $result['message'] = "未查询到与此相关职能部门";
  499. } else {
  500. $count = Department::where('name', 'like', "%{$data['keyword']}%")->count();
  501. $m = [
  502. 'department' => $depart,
  503. 'type' => $departments,
  504. 'count' => $count,
  505. ];
  506. }
  507. $result['sele'] = $m;
  508. return Result::success($result['sele']);
  509. }
  510. $result = $depart;
  511. return Result::success($result);
  512. }
  513. /**
  514. * 搜索地区
  515. * @param array $data
  516. * @return array
  517. */
  518. public function selectWebsiteArea(array $data): array
  519. {
  520. $provinces = District::where('pid', 0)->where('status', 1)->get();
  521. if (isset($data['province'])) {
  522. $province = District::where('pid', 0)->where('status', 1)->where('id', $data['province'])->orderBy('id')->get();
  523. $province = $province->toArray();
  524. if (!empty($province)) {
  525. $citys = District::where('pid', $data['province'])->where('status', 1)->orderBy('id')->get();
  526. if (!empty($citys) && isset($data['city']) && !empty($data['city'])) {
  527. // $province = $province->toArray();
  528. $province_id = [];
  529. foreach ($province as $val) {
  530. array_push($province_id, $val['id']);
  531. }
  532. // var_dump($province_id);
  533. $city = District::whereIn('pid', $province_id)->where('status', 1)->where('id', $data['city'])->orderBy('id')->get();
  534. if (!empty($city)) {
  535. $city_id = [];
  536. foreach ($city as $val) {
  537. array_push($city_id, $val['id']);
  538. }
  539. $regions = District::whereIn('pid', $city_id)->where('status', 1)->orderBy('id')->get();
  540. $result = [
  541. 'province' => $province,
  542. 'city' => $city,
  543. 'region' => $regions,
  544. ];
  545. } else {
  546. return Result::error("未查询到此城市", 0);
  547. }
  548. } else {
  549. $result = [
  550. 'province' => $province,
  551. 'city' => $citys,
  552. 'region' => null,
  553. ];
  554. }
  555. } else {
  556. return Result::error("未查询到此省份", 0);
  557. }
  558. } else {
  559. // $keys = array('data');
  560. $result = $provinces;
  561. }
  562. return Result::success($result);
  563. }
  564. /**
  565. * 获取栏目
  566. * @param array $data
  567. * @return array
  568. */
  569. public function getWebsiteModelCategory(array $data): array
  570. {
  571. $website_id=[
  572. 'website_category.website_id' => $data['website_id']
  573. ];
  574. $placeid=$data['placeid']-1;
  575. $pid=[
  576. 'website_category.pid' => $data['pid'],
  577. ];
  578. var_dump( "=======",$pid);
  579. $num = $data['num'];
  580. // return Result::success($data);
  581. $result=WebsiteCategory::where($website_id)
  582. ->leftJoin("category",'website_category.category_id','category.id')
  583. ->select('website_category.*','category.is_url','category.web_url')
  584. ->where($pid)
  585. // ->with(['children' => function ($query) use ($data) {
  586. // $query->where('website_category.website_id', $data['website_id']);
  587. // }])
  588. ->orderBy('website_category.sort')
  589. ->offset($placeid)
  590. ->limit($num)
  591. ->get();
  592. foreach($result as $k=>$v){
  593. $child[$k]['children_countent']=WebsiteCategory::where($website_id)
  594. ->where('website_category.pid',$v['category_id'])
  595. ->count();
  596. if(!empty($child[$k]['children_countent'])){
  597. $result[$k]['children_count']=$child[$k]['children_countent'];
  598. }else{
  599. $result[$k]['children_count']=0;
  600. }
  601. }
  602. return Result::success($result);
  603. if(!empty($result)){
  604. return Result::success($result);
  605. }else{
  606. return Result::error("本网站暂无栏目",0);
  607. }
  608. }
  609. /**
  610. * 获取友情链接
  611. * @param array $data
  612. * @return array
  613. */
  614. public function selectWebsiteLinks(array $data): array
  615. {
  616. $where = [
  617. 'website_id' => $data['website_id'],
  618. 'status' => 1,
  619. 'type' => $data['type']
  620. ];
  621. $num=$data['num'];
  622. $result=Link::where($where)->orderBy('sort')->limit($num)->get();
  623. if(!empty($result)){
  624. return Result::success($result);
  625. }else{
  626. return Result::error("本网站暂无此类型友情链接",0);
  627. }
  628. }
  629. /**
  630. * 网站首页数据统计, 管理员
  631. * @return void
  632. */
  633. public function getAdminIndex(array $data): array
  634. {
  635. var_dump("用户类型:", $data['type_id']);
  636. switch ($data['type_id']) {
  637. case 4:
  638. $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;');
  639. return Result::success($result);
  640. break;
  641. case 10000:
  642. $res = [];
  643. //网站
  644. $res['website']['count'] = 0;
  645. $res['website']['growth_rate'] = 0;
  646. //资讯
  647. $res['article']['count'] = 0;
  648. $res['article']['growth_rate'] = 0;
  649. //导航池
  650. $res['category']['count'] = 0;
  651. $res['category']['growth_rate'] = 0;
  652. //近一月数据
  653. $res['monthArticle'] = [];
  654. //用户类型
  655. $res['userType'] = [];
  656. $res['website']['count'] = Website::where([])->count();
  657. $res['article']['count'] = Article::whereNotIn('status', ['404'])->count();
  658. $res['category']['count'] = Category::where([])->count();
  659. $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;');
  660. $res['userType'] = User::where([])->selectRaw("count(*) as counts,type_id")->groupBy('type_id')->get();
  661. return Result::success($res);
  662. }
  663. return [];
  664. }
  665. /**
  666. * 获取模板类型
  667. * @return void
  668. */
  669. public function getTemplateClass(array $data): array
  670. {
  671. $where = [];
  672. if (isset($data['name']) && $data['name']) {
  673. array_push($where, ['name', 'like', '%' . $data['name'] . '%']);
  674. }
  675. $result = TemplateClass::where($where)->orderBy('sort', 'asc')->get();
  676. if (empty($result)) {
  677. return Result::error("没有模板类型", 0);
  678. } else {
  679. return Result::success($result);
  680. }
  681. }
  682. /**
  683. * 添加模板类型
  684. * @param
  685. * @return void
  686. */
  687. public function addTemplateClass(array $data): array
  688. {
  689. $insertData = [
  690. 'name' => $data['name'],
  691. ];
  692. $result = TemplateClass::insertGetId($insertData);
  693. if (empty($result)) {
  694. return Result::error("创建失败", 0);
  695. } else {
  696. return Result::success(["id" => $result]);
  697. }
  698. }
  699. /**
  700. * 更新模板
  701. * @param array $data
  702. * @return array
  703. */
  704. public function upTemplateClass(array $data): array
  705. {
  706. $where = [
  707. 'id' => $data['id'],
  708. ];
  709. $insertData = [
  710. 'name' => $data['name'],
  711. ];
  712. $result = TemplateClass::where($where)->update($insertData);
  713. if (empty($result)) {
  714. return Result::error("更新失败", 0);
  715. } else {
  716. return Result::success();
  717. }
  718. }
  719. /**
  720. * 删除模板
  721. * @param array $data
  722. * @return array
  723. */
  724. public function delTemplateClass(array $data): array
  725. {
  726. $where = [
  727. 'id' => $data['id'],
  728. ];
  729. $result = TemplateClass::where($where)->delete();
  730. if (empty($result)) {
  731. return Result::error("删除失败", 0);
  732. } else {
  733. return Result::success();
  734. }
  735. }
  736. /**
  737. * 获取分类下的模板
  738. * @param array $data
  739. * @return array
  740. */
  741. public function getTemplate(array $data): array
  742. {
  743. $page = $data['page'];
  744. $pageSize = $data['pageSize'];
  745. $where = [];
  746. if (isset($data['template_class_id']) && $data['template_class_id']) {
  747. array_push($where, ['template_class_id', '=', $data['template_class_id']]);
  748. }
  749. $result = Template::where($where)
  750. ->limit($pageSize)->offset(($page - 1) * $pageSize)->get();
  751. $count = Template::where($where)->count();
  752. if (empty($result)) {
  753. return Result::error("没有数据", 0);
  754. }
  755. $data = [
  756. 'rows' => $result->toArray(),
  757. 'count' => $count,
  758. ];
  759. return Result::success($data);
  760. }
  761. /**
  762. * 创建模板
  763. * @param
  764. * @return void
  765. */
  766. public function addTemplate(array $data): array
  767. {
  768. $insertData = [
  769. 'template_name' => $data['template_name'],
  770. 'template_img' => json_encode($data['template_img']),
  771. 'template_class_id' => $data['template_class_id'],
  772. ];
  773. $result = Template::insertGetId($insertData);
  774. if (empty($result)) {
  775. return Result::error("创建模板失败", 0);
  776. } else {
  777. return Result::success(["id" => $result]);
  778. }
  779. }
  780. /**
  781. * 更新模板
  782. * @param array $data
  783. * @return array
  784. */
  785. public function upTemplate(array $data): array
  786. {
  787. $where = [
  788. 'id' => $data['id'],
  789. ];
  790. $insertData = [
  791. 'template_name' => $data['template_name'],
  792. 'template_img' => json_encode($data['template_img']),
  793. 'template_class_id' => $data['template_class_id'],
  794. ];
  795. $result = Template::where($where)->update($insertData);
  796. if (empty($result)) {
  797. return Result::error("更新模板失败", 0);
  798. } else {
  799. return Result::success();
  800. }
  801. }
  802. /**
  803. * 删除模板
  804. * @param array $data
  805. * @return array
  806. */
  807. public function delTemplate(array $data): array
  808. {
  809. $where = [
  810. 'id' => $data['id'],
  811. ];
  812. $result = Template::where($where)->delete();
  813. if (empty($result)) {
  814. return Result::error("删除模板失败", 0);
  815. } else {
  816. return Result::success();
  817. }
  818. }
  819. /**
  820. * 搜索网站
  821. * @param array $data
  822. * @return array
  823. */
  824. public function websiteList(array $data): array
  825. {
  826. $where = [];
  827. if (isset($data['keyword']) && !empty($data['keyword'])) {
  828. array_push($where, ['website.website_name', 'like', '%' . $data['keyword'] . '%']);
  829. }
  830. $result = Website::where($where)->get();
  831. if ($result) {
  832. return Result::success($result);
  833. } else {
  834. return Result::error("没有网站", 0);
  835. }
  836. }
  837. public function addWebsiteCategory(array $data): array
  838. {
  839. $website_id = $data['website_id'];
  840. $category_arr_id = $data['category_arr_id'];
  841. $categoryList = Category::whereIn('id', $category_arr_id)->get();
  842. $categoryListIds = [];
  843. if ($categoryList) {
  844. foreach ($categoryList->toArray() as $val) {
  845. array_push($categoryListIds, $val['id']);
  846. }
  847. }
  848. $arr = [];
  849. if ($categoryListIds) {
  850. foreach ($categoryListIds as $v) {
  851. $ids = $this->getUnderlingUIds(intval($v));
  852. $ids_arr = explode(",", $ids);
  853. array_push($arr, $ids_arr);
  854. }
  855. }
  856. $mergedArray = [];
  857. foreach ($arr as $subarray) {
  858. $mergedArray = array_merge($mergedArray, $subarray);
  859. }
  860. var_dump("所有:", $arr, $mergedArray);
  861. //查询出所有的分类进行分割插入 组装数据
  862. $categoryListData = Category::whereIn('id', $mergedArray)->get();
  863. $categoryListData = $categoryListData->toArray();
  864. $insertData = [];
  865. if ($categoryListData) {
  866. foreach ($categoryListData as $key => $value) {
  867. $insertData[$key]['website_id'] = $website_id;
  868. $insertData[$key]['name'] = $value['name'];
  869. $insertData[$key]['sort'] = $value['sort'];
  870. $insertData[$key]['pid'] = $value['pid'];
  871. $insertData[$key]['pid_arr'] = $value['pid_arr'];
  872. $insertData[$key]['seo_title'] = $value['seo_title'];
  873. $insertData[$key]['seo_keywords'] = $value['seo_keywords'];
  874. $insertData[$key]['seo_description'] = $value['seo_description'];
  875. $insertData[$key]['alias'] = $value['name'];
  876. $insertData[$key]['category_id'] = $value['id'];
  877. }
  878. }
  879. $result = WebsiteCategory::insert($insertData);
  880. var_dump("插入数据状态:", $result);
  881. if ($result) {
  882. return Result::success($result);
  883. } else {
  884. return Result::error("创建失败", 0);
  885. }
  886. }
  887. /**
  888. * 删除网站导航
  889. * @param array $data
  890. * @return array
  891. */
  892. public function delWebsiteCategory(array $data): array
  893. {
  894. $website_id = $data['website_id'] ?? 0;
  895. $category_id = $data['category_id'] ?? 0;
  896. $ids = $this->getUnderlingUIds(intval($category_id));
  897. $ids_arr = explode(",", $ids);
  898. $result = WebsiteCategory::where(['website_id' => $website_id])->whereIn("category_id", $ids_arr)->delete();
  899. if ($result) {
  900. return Result::success($result);
  901. } else {
  902. return Result::error("删除失败", 0);
  903. }
  904. }
  905. /**
  906. * 获取网站导航
  907. * @param array $data
  908. * @return array
  909. */
  910. public function getAdminWebsiteCategory(array $data): array
  911. {
  912. $where = [
  913. 'website_id' => $data['website_id'],
  914. 'pid' => 0,
  915. ];
  916. $result = WebsiteCategory::where($where)->get();
  917. if ($result) {
  918. return Result::success($result);
  919. } else {
  920. return Result::error("查询失败", 0);
  921. }
  922. }
  923. /**
  924. * 更新网站导航
  925. * @param array $data
  926. * @return array
  927. */
  928. public function upWebsiteCategory(array $data): array
  929. {
  930. Db::beginTransaction();
  931. try {
  932. //合并栏目id
  933. $reqIds = array_merge($data['old_category_arr_id'], $data['new_category_arr_id']);
  934. //对比old 数组差异化,把差异化的删除
  935. $result = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])->get();
  936. $result = $result->toArray();
  937. $categoryIds = [];
  938. if ($result) {
  939. foreach ($result as $val) {
  940. array_push($categoryIds, $val['category_id']);
  941. }
  942. }
  943. //和原始数据对比取交际
  944. $reqidsIntersect = array_intersect($reqIds, $categoryIds);
  945. //再取差集 进行对比
  946. $differenceIDS = array_merge(array_diff($reqidsIntersect, $categoryIds), array_diff($categoryIds, $reqidsIntersect));
  947. var_dump("差集:", $differenceIDS);
  948. $arr_ids = [];
  949. if (count($differenceIDS) > 0) {
  950. foreach ($differenceIDS as $vv) {
  951. $idV = $this->getUnderlingUIds(intval($vv));
  952. $ids_arrV = explode(",", $idV);
  953. array_push($arr_ids, $ids_arrV);
  954. }
  955. }
  956. $del_ids = array_reduce($arr_ids, 'array_merge', array());
  957. //有差异 删除
  958. if (count($del_ids) > 0) {
  959. WebsiteCategory::where(['website_id' => $data['website_id']])->whereIn("category_id", $del_ids)->delete();
  960. }
  961. //传过来的值 和 交际 对比,选出要添加的值 进行插入
  962. $insertIDS = array_merge(array_diff($reqIds, $reqidsIntersect), array_diff($reqidsIntersect, $reqIds));
  963. var_dump("要存储的:", $insertIDS);
  964. //新的数组重新创建
  965. if (count($insertIDS) > 0) {
  966. $arr = [];
  967. $categoryListIds = $insertIDS;
  968. if ($categoryListIds) {
  969. foreach ($categoryListIds as $v) {
  970. $ids = $this->getUnderlingUIds(intval($v));
  971. $ids_arr = explode(",", $ids);
  972. array_push($arr, $ids_arr);
  973. }
  974. }
  975. $mergedArray = [];
  976. foreach ($arr as $subarray) {
  977. $mergedArray = array_merge($mergedArray, $subarray);
  978. }
  979. var_dump("要插入的ID:", $mergedArray);
  980. //查询出所有的分类进行分割插入 组装数据
  981. $categoryListData = Category::whereIn('id', $mergedArray)->get();
  982. $categoryListData = $categoryListData->toArray();
  983. $insertData = [];
  984. if ($categoryListData) {
  985. foreach ($categoryListData as $key => $value) {
  986. $insertData[$key]['website_id'] = $data['website_id'];
  987. $insertData[$key]['name'] = $value['name'];
  988. $insertData[$key]['sort'] = $value['sort'];
  989. $insertData[$key]['pid'] = $value['pid'];
  990. $insertData[$key]['pid_arr'] = $value['pid_arr'];
  991. $insertData[$key]['seo_title'] = $value['seo_title'];
  992. $insertData[$key]['seo_keywords'] = $value['seo_keywords'];
  993. $insertData[$key]['seo_description'] = $value['seo_description'];
  994. $insertData[$key]['alias'] = $value['name'];
  995. $insertData[$key]['category_id'] = $value['id'];
  996. }
  997. }
  998. WebsiteCategory::insert($insertData);
  999. }
  1000. Db::commit();
  1001. } catch (\Throwable $ex) {
  1002. Db::rollBack();
  1003. var_dump($ex->getMessage());
  1004. return Result::error("修改失败", 0);
  1005. }
  1006. return Result::success();
  1007. }
  1008. /**
  1009. * 获取网站列表
  1010. * @param array $data
  1011. * @return array
  1012. */
  1013. public function getWebsiteCategoryList(array $data): array
  1014. {
  1015. $where = [];
  1016. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1017. array_push($where, ['website.website_name', 'like', '%' . $data['keyword'] . '%']);
  1018. }
  1019. if (isset($data['website_column_id']) && !empty($data['website_column_id'])) {
  1020. array_push($where, ['website.website_column_id', '=', $data['website_column_id']]);
  1021. }
  1022. $result = Website::where($where)
  1023. ->with(["websiteCategory" => function ($query) {
  1024. $query->where(['pid' => 0])->select('website_id', 'name', 'alias', 'category_id');
  1025. }])
  1026. ->limit($data['pageSize'])->orderBy("updated_at", "desc")->offset(($data['page'] - 1) * $data['pageSize'])
  1027. ->get();
  1028. $count = Website::where($where)->count();
  1029. if (empty($result)) {
  1030. return Result::error("没有数据", 0);
  1031. }
  1032. $data = [
  1033. 'rows' => $result->toArray(),
  1034. 'count' => $count,
  1035. ];
  1036. if ($result) {
  1037. return Result::success($data);
  1038. } else {
  1039. return Result::error("查询失败", 0);
  1040. }
  1041. }
  1042. /**
  1043. * 删除网站下的所有导航
  1044. * @param array $data
  1045. * @return array
  1046. */
  1047. public function delWebsiteAllCategory(array $data): array
  1048. {
  1049. $website_id = $data['website_id'];
  1050. $result = WebsiteCategory::where(['website_id' => $website_id])->delete();
  1051. if ($result) {
  1052. return Result::success($result);
  1053. } else {
  1054. return Result::error("删除失败", 0);
  1055. }
  1056. }
  1057. /**
  1058. * 获取网站下的某一个导航
  1059. * @param array $data
  1060. * @return array
  1061. */
  1062. public function getWebsiteCategoryOnes(array $data): array
  1063. {
  1064. $website_id = $data['website_id'];
  1065. $category_id = $data['category_id'];
  1066. $result = WebsiteCategory::where(['website_category.website_id' => $website_id, 'website_category.category_id' => $category_id])
  1067. ->first();
  1068. if ($result) {
  1069. return Result::success($result);
  1070. } else {
  1071. return Result::error("查询失败", 0);
  1072. }
  1073. }
  1074. /**
  1075. * 更新网闸下的某一个导航
  1076. * @param array $data
  1077. * @return array
  1078. */
  1079. public function upWebsiteCategoryones(array $data): array
  1080. {
  1081. $where = [
  1082. 'website_id' => $data['website_id'],
  1083. 'category_id' => $data['category_id'],
  1084. ];
  1085. $data['sort'] = $data['sort']??0;
  1086. $result = WebsiteCategory::where($where)->update($data);
  1087. if ($result) {
  1088. return Result::success($result);
  1089. } else {
  1090. return Result::error("更新失败", 0);
  1091. }
  1092. }
  1093. /**
  1094. * 获取网站下的所有导航(包含子导航)
  1095. * @param array $data
  1096. * @return array
  1097. */
  1098. public function getWebsiteAllCategory(array $data): array
  1099. {
  1100. $where = [];
  1101. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1102. array_push($where, ['website_category.website_id', '=', $data['website_id']]);
  1103. }
  1104. if (isset($data['name']) && !empty($data['name'])) {
  1105. array_push($where, ['website_category.name', 'like', '%' . $data['name'] . '%']);
  1106. }
  1107. if (isset($data['alias']) && !empty($data['alias'])) {
  1108. array_push($where, ['website_category.alias', 'like', '%' . $data['alias'] . '%']);
  1109. }
  1110. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1111. array_push($where, ['category.department_id', '=', $data['department_id']]);
  1112. }
  1113. if (isset($data['city_id']) && !empty($data['city_id'])) {
  1114. array_push($where, ['category.city_id', '=', $data['city_id']]);
  1115. }
  1116. $result = WebsiteCategory::where($where)
  1117. ->leftJoin("category", 'website_category.category_id', 'category.id')
  1118. ->leftJoin("department", 'category.department_id', 'department.id')
  1119. ->leftJoin("district", 'category.city_id', 'district.id')
  1120. ->select("website_category.*", "department.name as department_name", "district.name as city_name")
  1121. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])
  1122. ->get();
  1123. $count = WebsiteCategory::where($where)
  1124. ->leftJoin("category", 'website_category.category_id', 'category.id')
  1125. ->leftJoin("department", 'category.department_id', 'department.id')
  1126. ->leftJoin("district", 'category.city_id', 'district.id')
  1127. ->count();
  1128. if (empty($result)) {
  1129. return Result::error("没有数据", 0);
  1130. }
  1131. $data = [
  1132. 'rows' => $result->toArray(),
  1133. 'count' => $count,
  1134. ];
  1135. if ($result) {
  1136. return Result::success($data);
  1137. } else {
  1138. return Result::error("查询失败", 0);
  1139. }
  1140. if ($result) {
  1141. return Result::success($result);
  1142. } else {
  1143. return Result::error("查询失败", 0);
  1144. }
  1145. }
  1146. /**
  1147. * 递归查询数据
  1148. * @param $id
  1149. * @param $ids
  1150. * @return string
  1151. */
  1152. public function getUnderlingUIds($id, $ids = '')
  1153. {
  1154. $back = Category::where(['pid' => $id])->get();
  1155. $back = $back->toArray();
  1156. if (!empty($back) && is_array($back)) {
  1157. foreach ($back as $v) {
  1158. //防止当前人的ID重复去查询,形成恶性循环
  1159. if ($v['id'] == $id) {
  1160. continue;
  1161. }
  1162. $back2 = Category::where(['pid' => $id])->count('id');
  1163. if ($back2 > 0) {
  1164. $ids = $this->getUnderlingUIds($v['id'], $ids);
  1165. } else {
  1166. $ids .= ',' . $v['id'];
  1167. }
  1168. }
  1169. }
  1170. $ids = $id . ',' . $ids . ',';
  1171. $ids = str_replace(',,', ",", $ids);
  1172. $ids = trim($ids, ',');
  1173. return $ids;
  1174. }
  1175. /**
  1176. * 检测网站名称是否重复
  1177. * @param array $data
  1178. * @return array
  1179. */
  1180. public function checkWebsiteName(array $data): array
  1181. {
  1182. if (isset($data['id'])) {
  1183. $data[] = ['id', "!=", $data['id']];
  1184. unset($data['id']);
  1185. }
  1186. $websiteInfo = Website::query()->where($data)->first();
  1187. if (empty($websiteInfo)) {
  1188. return Result::error("找不到网站", 0);
  1189. }
  1190. return Result::success($websiteInfo->toArray());
  1191. }
  1192. /**
  1193. * 检测网站url是否重复
  1194. * @param array $data
  1195. * @return array
  1196. */
  1197. public function checkWebsiteUrl(array $data): array
  1198. {
  1199. $whereData = [];
  1200. if (isset($data['id'])) {
  1201. $whereData = [['id', "!=", $data['id']]];
  1202. unset($data['id']);
  1203. }
  1204. $websiteInfo = Website::query()->where($whereData)->whereJsonContains('website_url', $data['website_url'])->first();
  1205. if (empty($websiteInfo)) {
  1206. return Result::error("找不到URL", 0);
  1207. }
  1208. return Result::success($websiteInfo->toArray());
  1209. }
  1210. // 自助建站--fr-------------------
  1211. /**
  1212. * 获取网站底部基础信息
  1213. * @param array $data
  1214. * @return array
  1215. */
  1216. public function getWebsiteFootInfo(array $data): array
  1217. {
  1218. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1219. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1220. if (empty($website)) {
  1221. return Result::error("找不到网站", 0);
  1222. }
  1223. } else {
  1224. return Result::error("参数错误", 0);
  1225. }
  1226. $website_foot = WebsiteTemplateInfo::where('website_id', $data['website_id'])->where('status', 2)->first();
  1227. $website_head = Website::where('id', $data['website_id'])
  1228. ->select('id', 'website_name', 'logo', 'title', 'keywords', 'description')->first();
  1229. if (empty($website_foot)) {
  1230. return Result::error("暂无底部基础信息", 0);
  1231. }
  1232. if (empty($website_head)) {
  1233. return Result::error("暂无头部基础信息", 0);
  1234. }
  1235. $result = [
  1236. 'website_foot' => $website_foot,
  1237. 'website_head' => $website_head,
  1238. ];
  1239. return Result::success($result);
  1240. }
  1241. /**
  1242. * 获取网站底部导航
  1243. * @param array $data
  1244. * @return array
  1245. */
  1246. public function getWebsiteFooterCategory(array $data): array
  1247. {
  1248. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1249. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1250. if (empty($website)) {
  1251. return Result::error("找不到网站", 0);
  1252. }
  1253. } else {
  1254. return Result::error("参数错误", 0);
  1255. }
  1256. $result = FooterCategory::where('website_id', $data['website_id'])->get();
  1257. if (empty($result)) {
  1258. return Result::error("暂无底部导航", 0);
  1259. }
  1260. return Result::success($result->toArray());
  1261. }
  1262. /**
  1263. * 获取网站底部导航列表
  1264. * @param array $data
  1265. * @return array
  1266. */
  1267. public function getWebsiteFooterCategoryList(array $data): array
  1268. {
  1269. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1270. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1271. if (empty($website)) {
  1272. return Result::error("找不到网站", 0);
  1273. }
  1274. } else {
  1275. return Result::error("参数错误", 0);
  1276. }
  1277. $footercategory = FooterCategory::where('website_id', $data['website_id'])->where('id', $data['fcat_id'])->first();
  1278. // '底部导航类型 0:内容型;1:列表型;',
  1279. if (!isset($footercategory['type']) || $footercategory['type'] == 0) {
  1280. return Result::error("底部导航id错误", 0);
  1281. } else {
  1282. $query = FooterContent::where('fcat_id', $data['fcat_id']);
  1283. if ($query->count() == 0) {
  1284. return Result::error("暂无底部导航列表", 0);
  1285. } elseif ($query->count() == 1) {
  1286. $result = $query->first();
  1287. } else {
  1288. $result = $query->get();
  1289. }
  1290. }
  1291. return Result::success($result);
  1292. }
  1293. /**
  1294. * 获取网站底部导航
  1295. * @param array $data
  1296. * @return array
  1297. */
  1298. public function getWebsiteFooterCategoryInfo(array $data): array
  1299. {
  1300. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1301. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1302. if (empty($website)) {
  1303. return Result::error("找不到网站", 0);
  1304. }
  1305. } else {
  1306. return Result::error("参数错误", 0);
  1307. }
  1308. if (isset($data['type']) && $data['type'] == 0) {
  1309. $fcatid = FooterCategory::where('website_id', $data['website_id'])->where('id', $data['fcat_id'])->first();
  1310. if (empty($fcatid)) {
  1311. return Result::error("底部导航id错误", 0);
  1312. }
  1313. $result = FooterContent::where('fcat_id', $data['fcat_id'])->first();
  1314. } else {
  1315. $result = FooterContent::where('id', $data['fcat_id'])->first();
  1316. }
  1317. if (empty($result)) {
  1318. return Result::error("暂无底部导航内容", 0);
  1319. }
  1320. return Result::success($result);
  1321. }
  1322. /*
  1323. * 搜索网站二级导航
  1324. * @param array $data
  1325. * @return array
  1326. * */
  1327. public function selectWebsiteCategory(array $data): array
  1328. {
  1329. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1330. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1331. if (empty($website)) {
  1332. return Result::error("暂无该网站", 0);
  1333. }
  1334. $category = WebsiteCategory::where('website_id',$data['website_id'])->pluck('category_id')->all();
  1335. // return Result::success($category);
  1336. if (empty($category)) {
  1337. return Result::error("暂无此导航",0);
  1338. }
  1339. $query = Category::whereIn('id', $category);
  1340. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1341. $cityid = District::where('id', $data['cityid'])->first();
  1342. if (empty($cityid)) {
  1343. return Result::error("暂无此城市", 0);
  1344. } else {
  1345. $city_category = $query->whereRaw('JSON_CONTAINS(city_arr_id,?)', [$data['cityid']])->pluck('id');
  1346. // $where[] = ['JSON_CONTAINS(city_arr_id, ?)', $data['cityid']];
  1347. if (empty($city_category)) {
  1348. return Result::error("暂无此城市下的导航", 0);
  1349. }
  1350. $result['catid'] = $city_category;
  1351. $city = 1;
  1352. // var_dump("城市====================",$result);
  1353. }
  1354. }
  1355. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1356. $departmentid = Department::where('id', $data['department_id'])->first();
  1357. if (empty($departmentid)) {
  1358. return Result::error("暂无此部门", 0);
  1359. } else {
  1360. $depart_category = $query->whereRaw('JSON_CONTAINS(department_arr_id,?)', [$data['department_id']])->pluck('id');
  1361. if (empty($depart_category)) {
  1362. return Result::error("暂无此部门下的导航", 0);
  1363. }
  1364. $result['catid'] = $depart_category;
  1365. // var_dump("职能部门*******************",$result);
  1366. $department = 1;
  1367. }
  1368. }
  1369. if(!empty($city) && !empty($department)){
  1370. // var_dump("城市和职能部门----------------------",$result);
  1371. $sel_category = $query->whereRaw('JSON_CONTAINS(city_arr_id,?)', [$data['cityid']])->whereRaw('JSON_CONTAINS(department_arr_id,?)', [$data['department_id']])->pluck('id');
  1372. if (empty($sel_category)) {
  1373. return Result::error("暂无此城市和职能部门下的导航", 0);
  1374. }
  1375. $result['catid'] = $sel_category;
  1376. }
  1377. if (empty($result)) {
  1378. return Result::error("暂无导航",0);
  1379. }
  1380. // department_id
  1381. } else {
  1382. return Result::error("参数错误", 0);
  1383. }
  1384. return Result::success($result);
  1385. }
  1386. /**
  1387. * 获取网站栏目seo
  1388. * @param array $data
  1389. * @return array
  1390. */
  1391. public function getWebsiteCategoryHead(array $data): array
  1392. {
  1393. $where = [];
  1394. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1395. array_push($where, ['website_id', '=', $data['website_id']]);
  1396. }
  1397. if (isset($data['catid']) && !empty($data['catid'])) {
  1398. $fcatid = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->first();
  1399. if (empty($fcatid)) {
  1400. return Result::error("导航id错误", 0);
  1401. }
  1402. $result = Category::where('id', $data['catid'])->first();
  1403. }
  1404. if (empty($result)) {
  1405. return Result::error("暂无导航", 0);
  1406. }
  1407. return Result::success($result);
  1408. }
  1409. /*
  1410. * 获取某个栏目
  1411. * @param array $data
  1412. * @return array
  1413. * */
  1414. public function getOneWebsiteCategory(array $data): array
  1415. {
  1416. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1417. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1418. if (empty($website)) {
  1419. return Result::error("暂无该网站", 0);
  1420. }
  1421. $result = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['category_id'])->select('category_id', 'name')->first();
  1422. // return Result::success($category);
  1423. if (empty($result)) {
  1424. return Result::error("暂无此导航", 0);
  1425. }
  1426. // department_id
  1427. } else {
  1428. return Result::error("参数错误", 0);
  1429. }
  1430. return Result::success($result);
  1431. }
  1432. //20250212 网站标识
  1433. public function addWebsiteGroup(array $data): array
  1434. {
  1435. //判斷name是不是重复
  1436. $websiteGroupInfo = WebsiteGroup::query()->where('name', $data['name'])->first();
  1437. if (!empty($websiteGroupInfo)) {
  1438. return Result::error("网站标识重复", 0);
  1439. }
  1440. //添加信息
  1441. $result = WebsiteGroup::insertGetId($data);
  1442. var_dump($result);
  1443. if (empty($result)) {
  1444. return Result::error("创建失败", 0);
  1445. } else {
  1446. return Result::success($result);
  1447. }
  1448. }
  1449. public function getWebsiteGroupList(array $data): array
  1450. {
  1451. $where = [];
  1452. if (isset($data['name']) && !empty($data['name'])) {
  1453. array_push($where, ['website_group.name', 'like', '%' . $data['name'] . '%']);
  1454. }
  1455. $result = WebsiteGroup::where($where)
  1456. ->limit($data['pageSize'])->orderBy("id", "desc")->offset(($data['page'] - 1) * $data['pageSize'])
  1457. ->get();
  1458. foreach ($result as $websiteGroup) {
  1459. $webIds = json_decode($websiteGroup->web_ids, true);
  1460. $websites = Website::whereIn('id', $webIds)->get();
  1461. $websiteNames = $websites->pluck('website_name', 'id')->toArray();
  1462. $websiteGroup->website_names = $websiteNames;
  1463. $websiteGroup->website_names1 = implode(',', array_values($websiteNames));
  1464. }
  1465. $count = WebsiteGroup::where($where)->count();
  1466. if (empty($result)) {
  1467. return Result::error("没有数据", 0);
  1468. }
  1469. return Result::success(['list' => $result->toArray(), 'count' => $count]);
  1470. }
  1471. public function getWebsiteGroupInfo(array $data): array
  1472. {
  1473. $websiteInfo = WebsiteGroup::query()->where('id', $data['id'])->first();
  1474. $webIds = json_decode($websiteInfo->web_ids, true);
  1475. $websites = Website::whereIn('id', $webIds)->get();
  1476. $websiteNames = $websites->pluck('website_name', 'id')->toArray();
  1477. $websiteInfo->website_names = $websiteNames;
  1478. $websiteInfo->website_names1 = implode(',', array_values($websiteNames));
  1479. if (empty($websiteInfo)) {
  1480. return Result::error("找不到URL", 0);
  1481. }
  1482. return Result::success($websiteInfo->toArray());
  1483. }
  1484. public function updateWebsiteGroup(array $data): array
  1485. {
  1486. $where = [
  1487. 'id' => $data['id'],
  1488. ];
  1489. $insertData = [
  1490. 'name' => $data['name'],
  1491. 'web_ids' => $data['web_ids'],
  1492. ];
  1493. //判斷name是不是重复
  1494. $websiteGroupInfo = WebsiteGroup::query()->where('name', $data['name'])->first();
  1495. if (!empty($websiteGroupInfo)) {
  1496. return Result::error("网站标识重复", 0);
  1497. }
  1498. $result = WebsiteGroup::where($where)->update($insertData);
  1499. var_dump($result, '------更新');
  1500. if (empty($result)) {
  1501. return Result::error("更新失败", 0);
  1502. } else {
  1503. return Result::success();
  1504. }
  1505. }
  1506. public function deleteWebsiteGroup(array $data): array
  1507. {
  1508. $where = [
  1509. 'id' => $data['id'],
  1510. ];
  1511. //看看user表是不是有这个id
  1512. $userGroup = User::query()->where('sszq', $data['id'])->first();
  1513. if (!empty($userGroup)) {
  1514. return Result::error("有用户在使用该网站标识,不能删除", 0);
  1515. }
  1516. $result = WebsiteGroup::where($where)->delete();
  1517. if (empty($result)) {
  1518. return Result::error("删除失败", 0);
  1519. } else {
  1520. return Result::success();
  1521. }
  1522. }
  1523. public function getWebsiteNavList(array $data): array
  1524. {
  1525. $where = [];
  1526. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1527. array_push($where, ['website_id', '=', $data['website_id']]);
  1528. }
  1529. if (isset($data['pid'])) {
  1530. array_push($where, ['pid', '=', $data['pid']]);
  1531. }
  1532. $list = WebsiteCategory::query()->where($where)->get();
  1533. if (empty($list)) {
  1534. return Result::error("获取失败", 0);
  1535. } else {
  1536. return Result::success($list);
  1537. }
  1538. }
  1539. //20250212 网站标识
  1540. // 自助建站--fr-------------------
  1541. /**
  1542. * 获取并搜索 网站模板信息
  1543. * @param array $data
  1544. * @return array
  1545. */
  1546. public function getWebsiteintel(array $data): array
  1547. {
  1548. //查询所有网站模板信息
  1549. $query = Website::where('website.status', 1)
  1550. ->leftJoin("website_template_info", "website_template_info.website_id", "website.id")
  1551. ->leftJoin("template", "template.id", "website_template_info.template_id")
  1552. ->leftJoin("template_class", "template_class.id", "template.template_class_id")
  1553. ->select(
  1554. "website_template_info.id",
  1555. "template_class.name",
  1556. "website.id as website_id",
  1557. "website.website_name",
  1558. "website.website_url",
  1559. "website_template_info.action_id",
  1560. "website_template_info.created_at",
  1561. "website_template_info.updated_at",
  1562. "website_template_info.page_type",
  1563. DB::raw("COALESCE(website_template_info.status, 0) as template_status"),
  1564. "template.template_name"
  1565. );
  1566. //若存在条件;则在$query的基础上进行筛选
  1567. if(isset($data['website_name']) && !empty($data['website_name'])){
  1568. $query->where('website.website_name', 'like', '%' . $data['website_name'] . '%');
  1569. }
  1570. if(isset($data['status']) && !empty($data['status'])){
  1571. $query->where('website_template_info.status', $data['status']);
  1572. }
  1573. $count = $query->count();
  1574. $query->limit($data['pageSize'])
  1575. ->offset(($data['page'] - 1) * $data['pageSize'])
  1576. ->orderBy("website_template_info.updated_at", "desc");
  1577. $rep = $query->get();
  1578. if($rep->count()==0){
  1579. return Result::error("没有查找到相关数据",0);
  1580. } else {
  1581. $rep->each(function ($item) {
  1582. if (!empty($item->page_type)) {
  1583. $pageTypeArray = json_decode($item->page_type, true);
  1584. if (is_array($pageTypeArray)) {
  1585. $item->page_type = $pageTypeArray;
  1586. }
  1587. }
  1588. });
  1589. $result = [
  1590. "rows" => $rep->toArray(),
  1591. "count" => $count
  1592. ];
  1593. return Result::success($result);
  1594. }
  1595. // return Result::success($result);
  1596. }
  1597. /**
  1598. * 添加网站基础信息
  1599. * @param array $data
  1600. * @return array
  1601. */
  1602. public function addWebsiteTemplateintel(array $data): array
  1603. {
  1604. $website = Website::where('website.id',$data['website_id'])->first();
  1605. if(empty($website)){
  1606. return Result::error("请输入正确的网站id!", 0);
  1607. }
  1608. if(empty($website['website_column_id'])){
  1609. return Result::error("请先关联导航池!", 0);
  1610. }
  1611. // 获取此网站的底部导航 类型 type: 0:内容型底部导航(只有一条详情内容);1:列表型底部导航(可以有多条详情内容)
  1612. $foot_type = FooterCategory::where('website_id',$data['website_id'])->pluck('type')->toArray();
  1613. if (empty($foot_type)) {
  1614. return Result::error("请先关联底部导航池!", 0);
  1615. } elseif (in_array(1, $foot_type)) {
  1616. $foot_type = 1;
  1617. } else {
  1618. $foot_type = 0;
  1619. }
  1620. $result['foot_type'] = $foot_type;
  1621. // 友情链接类型'1:图片 2:文字 3:底部';
  1622. $types = Link::where('website_id', $data['website_id'])->pluck('type')->toArray();
  1623. $missingTypes = [];
  1624. if (!in_array(1, $types)) {
  1625. $missingTypes[] = "文字链接";
  1626. }
  1627. if (!in_array(2, $types)) {
  1628. $missingTypes[] = "图片链接";
  1629. }
  1630. if (!in_array(3, $types)) {
  1631. $missingTypes[] = "底部链接";
  1632. }
  1633. if (!empty($missingTypes)) {
  1634. $errorMessage = "请先添加 " . implode(" 和 ", $missingTypes) . "!";
  1635. return Result::error($errorMessage, 0);
  1636. }
  1637. if(isset($data['page_type'])){
  1638. // 删除重复元素并重新索引数组
  1639. $data['page_type'] = array_unique($data['page_type']);
  1640. $data['page_type'] = array_values($data['page_type']);
  1641. if (in_array(1, $data['page_type']) && in_array(7, $data['page_type'])) {
  1642. // 数组中同时包含值为 1(首页) 和值为 7 (底部导航详情页)的元素
  1643. $info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1644. if (empty($info)) {
  1645. // 将数组转换为 JSON 字符串
  1646. $data['page_type'] = json_encode($data['page_type'])??'';
  1647. // 操作状态:1:填写完成基础信息;2:选择完成模板;0:未构建
  1648. $data['action_id'] = 1;
  1649. try {
  1650. $result = WebsiteTemplateInfo::insertGetId($data);
  1651. } catch (\Exception $e) {
  1652. if ($e->getCode() == 22001) {
  1653. $errorMessage = $e->getMessage();
  1654. return Result::error("请检查表单,某个字段超出了长度限制!");
  1655. } else {
  1656. // 处理其他类型的数据库错误
  1657. return Result::error("插入操作失败: " . $e->getMessage());
  1658. }
  1659. return Result::error("添加失败!", 0);
  1660. }
  1661. } else {
  1662. return Result::error("该网站已经构建过了!", 0);
  1663. }
  1664. } else {
  1665. return Result::error("请先选择首页和底部导航详情页!", 0);
  1666. }
  1667. }
  1668. if(empty($result)){
  1669. return Result::error("添加失败!",0);
  1670. }else{
  1671. return Result::success($result);
  1672. }
  1673. }
  1674. /**
  1675. * 获取网站基础信息
  1676. *
  1677. * @return array
  1678. */
  1679. public function getWebsiteTemplateintel(array $data): array
  1680. {
  1681. $result = WebsiteTemplateInfo::where('website_template_info.website_id',$data['website_id'])
  1682. ->leftJoin('footer_category','footer_category.website_id','website_template_info.website_id')
  1683. ->leftJoin('website','website.id','website_template_info.website_id')
  1684. ->select(
  1685. "website_template_info.*",
  1686. "footer_category.type",
  1687. "website.website_name",
  1688. "website.id as website_id"
  1689. )
  1690. ->first();
  1691. if(empty($result['website_name'])){
  1692. return Result::error("请输入正确的网站id!", 0);
  1693. }
  1694. if($result){
  1695. $result['page_type'] = json_decode($result['page_type'],true);
  1696. return Result::success($result);
  1697. }else{
  1698. return Result::error("请先添加网站基础信息!",0);
  1699. }
  1700. }
  1701. /**
  1702. * 修改网站基础信息
  1703. *
  1704. * @return array
  1705. */
  1706. public function upWebsiteTemplateintel(array $data): array
  1707. {
  1708. $web = Website::where('website.id',$data['website_id'])->first();
  1709. if(empty($web)){
  1710. return Result::error("请输入正确的网站id!", 0);
  1711. }
  1712. $where = ['website_id'=>$data['website_id']];
  1713. $result = WebsiteTemplateInfo::where($where)->first();
  1714. if(empty($result)){
  1715. return Result::error("请先添加网站基础信息!",0);
  1716. }else{
  1717. unset($data['website_id']);
  1718. // 删除重复元素
  1719. $data['page_type'] = array_unique($data['page_type']);
  1720. // 重新索引数组
  1721. $data['page_type'] = array_values($data['page_type']);
  1722. // 数组中同时包含值为 1(首页) 和值为 7 (底部导航详情页)的元素
  1723. if (in_array(1, $data['page_type']) && in_array(7, $data['page_type'])) {
  1724. // 将数组转换为 JSON 字符串
  1725. $data['page_type'] = json_encode($data['page_type'])??'';
  1726. try {
  1727. $result = WebsiteTemplateInfo::where($where)->update($data);
  1728. } catch (\Exception $e) {
  1729. if ($e->getCode() == 22001) {
  1730. $errorMessage = $e->getMessage();
  1731. return Result::error("请检查表单,某个字段超出了长度限制!");
  1732. } else {
  1733. // 处理其他类型的数据库错误
  1734. return Result::error("修改操作失败: " . $e->getMessage());
  1735. }
  1736. return Result::error("修改失败!", 0);
  1737. }
  1738. }else{
  1739. return Result::error("请先选择首页和底部导航详情页!",0);
  1740. }
  1741. }
  1742. if(empty($result)){
  1743. return Result::error("修改失败!",0);
  1744. }else{
  1745. return Result::success($result);
  1746. }
  1747. }
  1748. /**
  1749. * 获取所有网站风格信息
  1750. *
  1751. * @return array
  1752. */
  1753. public function getAllTemplateClass(array $data): array
  1754. {
  1755. $result = TemplateClass::all();
  1756. if(empty($result)){
  1757. return Result::error("没有查找到相关数据!",0);
  1758. }else{
  1759. return Result::success($result);
  1760. }
  1761. }
  1762. /**
  1763. * 搜索并获取网站模板信息
  1764. * @param array $data
  1765. * @return array
  1766. */
  1767. public function getWebsiteTemplateList(array $data): array
  1768. {
  1769. $website = Website::where('website.id',$data['website_id'])->first();
  1770. if(empty($website)){
  1771. return Result::error("请输入正确的网站id!",0);
  1772. }else{
  1773. $page_type = WebsiteTemplateInfo::where('website_id',$data['website_id'])->select('page_type')->first();
  1774. if(empty($page_type)){
  1775. return Result::error("此网站还未添加基础信息!",0);
  1776. } else{
  1777. $where = json_decode($page_type['page_type'], true);
  1778. // $where = $data["page_type"];
  1779. if(isset($data['template_class_id']) && !empty($data['template_class_id'])){
  1780. $template_class = TemplateClass::where('id',$data['template_class_id'])->first();
  1781. if(empty($template_class)){
  1782. return Result::error("请输入正确的模板风格id!",0);
  1783. }else{
  1784. // 获取指定风格下的模板
  1785. $rep = Template::where('template_class_id', $data['template_class_id'])
  1786. ->where(function ($query) use ($where) {
  1787. foreach ($where as $value) {
  1788. $query->whereJsonContains('template_img', ['value' => $value]);
  1789. }
  1790. })
  1791. ->limit($data['pageSize'])
  1792. ->offset(($data['page'] - 1) * $data['pageSize'])
  1793. ->orderBy("template.updated_at", "desc")
  1794. ->get();
  1795. $count = Template::where('template_class_id', $data['template_class_id'])
  1796. ->where(function ($query) use ($where) {
  1797. foreach ($where as $value) {
  1798. $query->whereJsonContains('template_img', ['value' => $value]);
  1799. }
  1800. })->count();
  1801. }
  1802. }else{
  1803. //获取所有模板
  1804. $rep = Template::where(function ($query) use ($where) {
  1805. foreach ($where as $value) {
  1806. $query->whereJsonContains('template_img', ['value' => $value]);
  1807. }
  1808. })
  1809. ->limit($data['pageSize'])
  1810. ->offset(($data['page'] - 1) * $data['pageSize'])
  1811. ->orderBy("template.updated_at", "desc")
  1812. ->get();
  1813. $count = Template::where(function ($query) use ($where) {
  1814. foreach ($where as $value) {
  1815. $query->whereJsonContains('template_img', ['value' => $value]);
  1816. }
  1817. })->count();
  1818. }
  1819. if(empty($rep) || $rep->count()==0){
  1820. return Result::error("没有查找到相关数据!",0);
  1821. }else{
  1822. // 过滤 template_img 字段 只获取 基础信息中 包含的模板图片
  1823. // $rep->each(function ($item) use ($where) {
  1824. // $template_img = json_decode($item->template_img, true);
  1825. // if(is_array($template_img)){
  1826. // $filtered_img = array_filter($template_img, function ($img) use ($where) {
  1827. // return isset($img['value']) && in_array($img['value'], $where);
  1828. // });
  1829. // }
  1830. // $item->template_img = $filtered_img;
  1831. // });
  1832. // $result = [
  1833. // "rows" => $rep->toArray(),
  1834. // "count" => $count
  1835. // ];
  1836. $rep->each(function ($item) use ($where) {
  1837. $template_img = json_decode($item->template_img, true);
  1838. if (is_array($template_img)) {
  1839. $filtered_img = array_filter($template_img, function ($img) use ($where) {
  1840. return isset($img['value']) && in_array($img['value'], $where);
  1841. });
  1842. // 对过滤后的数组进行重新排序
  1843. $sorted_img = array_values($filtered_img);
  1844. $item->template_img = $sorted_img;
  1845. } else {
  1846. $item->template_img = []; // 如果无法解码为数组,则设置为空数组
  1847. }
  1848. });
  1849. $result = [
  1850. "rows" => $rep->toArray(),
  1851. "count" => $count
  1852. ];
  1853. }
  1854. }
  1855. }
  1856. return Result::success($result);
  1857. }
  1858. /**
  1859. * 添加网站模板
  1860. * @param array $data
  1861. */
  1862. public function addWebsiteTemplateclassintel(array $data): array
  1863. {
  1864. $template = Template::where('id',$data['template_id'])->first();
  1865. $web = Website::where('id',$data['website_id'])->first();
  1866. if(empty($template)){
  1867. return Result::error("请输入正确的模板id",0);
  1868. }
  1869. if(empty($web)){
  1870. return Result::error("请输入正确的网站id",0);
  1871. }
  1872. $result = WebsiteTemplateInfo::where('website_id',$data['website_id'])->update(['template_id'=>$data['template_id'],'action_id'=>2]);
  1873. if(empty($result)){
  1874. return Result::error("添加失败",0);
  1875. }else{
  1876. return Result::success($result);
  1877. }
  1878. }
  1879. /**
  1880. * 获取网站模板信息
  1881. * @param array $data
  1882. */
  1883. public function getWebsiteTemplateclassintel(array $data): array
  1884. {
  1885. // return Result::success($data);
  1886. $template = WebsiteTemplateInfo::where('website_id',$data['website_id'])->first();
  1887. if(empty($template)){
  1888. return Result::error("请输入正确的搭建网站id",0);
  1889. }
  1890. $page_type = json_decode($template['page_type'], true);
  1891. // 获取指定网站下的基础信息和模板及风格信息
  1892. $result = WebsiteTemplateInfo::where([
  1893. ['website_template_info.website_id',$data['website_id']],
  1894. ['template_id','!=',null]
  1895. ])
  1896. ->leftJoin('template','template.id','website_template_info.template_id')
  1897. ->leftJoin('template_class','template_class.id','template.template_class_id')
  1898. ->where(function ($query) use ($page_type) {
  1899. // 假设 $data['page_type'] 是一个数组,包含需要匹配的 page_type 值
  1900. foreach ($page_type as $pageType) {
  1901. $query->orWhereJsonContains('template.template_img', ['value' => $pageType]);
  1902. }
  1903. })
  1904. ->select(
  1905. 'template.template_name',
  1906. 'template.template_img',
  1907. 'template.id as tid',
  1908. 'template_class.name',
  1909. 'template_class.id as class_id',
  1910. 'website_template_info.page_type',
  1911. 'website_template_info.website_id')
  1912. ->first();
  1913. if(empty($result)){
  1914. return Result::error("没有查找到相关数据",0);
  1915. }
  1916. // return Result::success($result);
  1917. // 过滤 template_img 字段 只获取 基础信息中 包含的模板图片
  1918. $template_img = $result['template_img'] !== null ? json_decode($result['template_img'], true) : [];
  1919. $page_type = $result['page_type'] !== null ? json_decode($result['page_type'], true) : [];
  1920. foreach ($template_img as $key => $value) {
  1921. if (!in_array($value['value'], $page_type)) {
  1922. unset($template_img[$key]);
  1923. }
  1924. }
  1925. // return Result::success($result);
  1926. $result['template_img'] = array_values($template_img);
  1927. $result['page_type'] = $page_type;
  1928. // $templateList = $this->getWebsiteTemplateList($data);
  1929. // $count = $templateList['data']['count']??'';
  1930. // $pages = $count / $data['pageSize'];
  1931. // $found = false;
  1932. // while ($pages && !$found) {
  1933. // $templates = $this->getWebsiteTemplateList($pages,$data['pageSize']);
  1934. // $index = array_search($template['template_id'], array_column($templates['rows'], 'id'));
  1935. // if ($index !== false) {
  1936. // $found = true;
  1937. // $result['page'] = $pages;
  1938. // $pages = 0;
  1939. // // echo "查询到的 template 在第 $page 页";
  1940. // }
  1941. // $pages--;
  1942. // }
  1943. return Result::success($result);
  1944. }
  1945. /**
  1946. * 获取网站模板下的板块信息
  1947. * @param array $data
  1948. */
  1949. public function getWebsiteSectorList(array $data): array
  1950. {
  1951. $website = Website::where('id',$data['website_id'])->first();
  1952. if(empty($website)){
  1953. return Result::error("请输入正确的网站id",0);
  1954. }
  1955. $template = WebsiteTemplateInfo::where('website_id',$data['website_id'])->first();
  1956. if(empty($template['template_id'])){
  1957. return Result::error("请先添加网站模板",0);
  1958. }
  1959. $query = Sector::where('template_id',$template['template_id']);
  1960. if($query->count() == 0){
  1961. return Result::error("没有查找到相关板块数据",0);
  1962. }elseif($query->count() == 1){
  1963. $sector = $query->first();
  1964. }else{
  1965. $sector = $query->get();
  1966. }
  1967. $result['page_type'] = $template['page_type'];
  1968. $result['tid'] = $template['template_id'];
  1969. $result = [
  1970. "tid" => $template['template_id'],
  1971. "page_type" => $template['page_type'],
  1972. "sector" => $sector
  1973. ];
  1974. return Result::success($result);
  1975. }
  1976. // 自助建站---------------fr---------------
  1977. }