WebsiteService.php 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705
  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Model\Article;
  4. use App\Model\Category;
  5. use App\Model\FooterCategory;
  6. use App\Model\FooterContent;
  7. use App\Model\LetterOfComplaint;
  8. use App\Model\Sector;
  9. use App\Model\TemplateClass;
  10. use App\Model\Template;
  11. use App\Model\User;
  12. use App\Model\WebsiteRole;
  13. use App\Model\WebsiteRoleUser;
  14. use App\Model\Website;
  15. use App\Model\WebsiteColumn;
  16. use App\Model\WebsiteTemplate;
  17. use Hyperf\DbConnection\Db;
  18. use Hyperf\RpcServer\Annotation\RpcService;
  19. use App\Tools\Result;
  20. use App\Model\WebsiteCategory;
  21. use App\Model\WebsiteTemplate;
  22. use App\Model\WebsiteTemplateInfo;
  23. use function PHPUnit\Framework\isNull;
  24. use App\Model\Component;
  25. use App\Model\District;
  26. #[RpcService(name: "WebsiteService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  27. class WebsiteService implements WebsiteServiceInterface
  28. {
  29. /**
  30. * @param string $keyword
  31. * @param int $page
  32. * @param int $pageSize
  33. * @return array
  34. */
  35. public function getWebsitetList(array $data): array
  36. {
  37. $resultWwhere = Website::when($data,function ($query) use ($data){
  38. if(isset($data['keyword']) && !empty($data['keyword'])){
  39. $query->where('website.website_name','like','%'.$data['keyword'].'%');
  40. }
  41. if(isset($data['website_column_id']) && !empty($data['website_column_id'])){
  42. $query->whereJsonContains("website.website_column_arr_id", intval($data['website_column_id']));
  43. }
  44. if(isset($data['city_id']) && !empty($data['city_id'])){
  45. $query->whereJsonContains("website.city_arr_id", intval($data['city_id']));
  46. }
  47. });
  48. $result = $resultWwhere->leftJoin("website_column","website.website_column_id","website_column.id")
  49. ->leftJoin("district","district.id","website.city_id")
  50. ->select("website.*","website_column.column_name","district.name as city_name")
  51. ->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])->orderBy("website.id","desc")->get();
  52. $count = $resultWwhere->count();
  53. if (empty($result)) {
  54. return Result::error("没有数据",0);
  55. }
  56. $data = [
  57. 'rows'=>$result->toArray(),
  58. 'count'=>$count
  59. ];
  60. return Result::success($data);
  61. }
  62. /**
  63. * @param array $data
  64. * @return array
  65. */
  66. public function createWebsite(array $data): array
  67. {
  68. var_dump("网站数据:", $data);
  69. $insertData = [
  70. 'website_name' => $data['website_name'],
  71. 'logo' => $data['logo'] ?? '',
  72. 'website_url' => $data['website_url'] ?? '',
  73. 'city_id' => $data['city_id'] ?? 0,
  74. 'website_column_id' => $data['website_column_id'],
  75. 'title' => $data['title'] ?? '',
  76. 'keywords' => $data['keywords'] ?? '',
  77. 'description' => $data['description'] ?? '',
  78. 'status' => $data['status'] ?? 0,
  79. 'website_column_arr_id' => $data['website_column_arr_id'],
  80. 'city_arr_id' => $data['city_arr_id'] ?? [0],
  81. 'template_id' => $data['template_id'] ?? 0,
  82. ];
  83. $result = Website::insertGetId($insertData);
  84. if (empty($result)) {
  85. return Result::error("创建失败", 0);
  86. } else {
  87. return Result::success(["id" => $result]);
  88. }
  89. }
  90. /**
  91. * @param int $id
  92. * @param array $data
  93. * @return array
  94. */
  95. public function updateWebsite(int $id, array $data): array
  96. {
  97. $insertData = [
  98. 'website_name' => $data['website_name'],
  99. 'logo' => $data['logo'] ?? '',
  100. 'website_url' => $data['website_url'] ?? '',
  101. 'city_id' => $data['city_id'] ?? 0,
  102. 'website_column_id' => $data['website_column_id'],
  103. 'title' => $data['title'] ?? '',
  104. 'keywords' => $data['keywords'] ?? '',
  105. 'description' => $data['description'] ?? '',
  106. 'status' => $data['status'] ?? 0,
  107. 'website_column_arr_id' => $data['website_column_arr_id'],
  108. 'city_arr_id' => $data['city_arr_id'] ?? [0],
  109. 'template_id' => $data['template_id'] ?? 0,
  110. ];
  111. $result = Website::where('id', $id)->update($insertData);
  112. var_dump("更新站点", $result);
  113. if (empty($result)) {
  114. return Result::error("更新失败", 0);
  115. } else {
  116. return Result::success();
  117. }
  118. }
  119. /**
  120. * @param int $id
  121. * @return array
  122. */
  123. public function delWebsite(int $id): array
  124. {
  125. $result = Website::where('id', $id)->delete();
  126. if (empty($result)) {
  127. return Result::error("删除失败", 0);
  128. } else {
  129. return Result::success();
  130. }
  131. }
  132. /**
  133. * @param int $id
  134. * @return array
  135. */
  136. public function getWebsiteInfo(int $id): array
  137. {
  138. $where = [
  139. ['website.id', '=', $id]
  140. ];
  141. $result = Website::where($where)
  142. ->leftJoin("website_template_info", "website_template_info.website_id", "website.id")
  143. ->select("website.*",
  144. "website_template_info.template_id",
  145. "website_template_info.page_type",
  146. "website_template_info.statement",
  147. "website_template_info.organizer",
  148. "website_template_info.copyright_information",
  149. "website_template_info.contact_number",
  150. "website_template_info.company_address",
  151. "website_template_info.project_logo",
  152. "website_template_info.project_name",
  153. "website_template_info.project_url",
  154. "website_template_info.company_logo",
  155. "website_template_info.company_name",
  156. "website_template_info.company_url",
  157. "website_template_info.record_number",
  158. "website_template_info.record_number_url",
  159. "website_template_info.icp_number",
  160. "website_template_info.icp_number_url",
  161. "website_template_info.customer_service_qq",
  162. "website_template_info.communications",
  163. "website_template_info.status",
  164. )
  165. ->first();
  166. if (empty($result)) {
  167. return Result::error("数据不存在", 0);
  168. } else {
  169. return Result::success($result->toArray());
  170. }
  171. }
  172. /**
  173. * 查询所有的站点栏目
  174. * @return array
  175. */
  176. public function getWebsiteColumn(array $data): array
  177. {
  178. $result = WebsiteColumn::where($data)->get();
  179. if (empty($result)) {
  180. return Result::error("数据不存在", 0);
  181. } else {
  182. return Result::success($result->toArray());
  183. }
  184. }
  185. /**
  186. * @param string $keyword
  187. * @param int $page
  188. * @param int $pageSize
  189. * @return array
  190. */
  191. public function getWebsiteColumnList(array $data): array
  192. {
  193. $where = [];
  194. if (isset($data['keyword']) && $data['keyword']) {
  195. array_push($where, ['website_column.column_name', 'like', '%' . $data['keyword'] . '%']);
  196. }
  197. $result = WebsiteColumn::where($where)
  198. ->leftJoin("website_column as wc", "website_column.pid", "wc.id")
  199. ->select("website_column.*", "wc.column_name as parent_column_name")
  200. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->get();
  201. $count = WebsiteColumn::where($where)->count();
  202. if (empty($result)) {
  203. return Result::error("没有数据", 0);
  204. }
  205. $data = [
  206. 'rows' => $result->toArray(),
  207. 'count' => $count
  208. ];
  209. return Result::success($data);
  210. }
  211. /**
  212. * @param array $data
  213. * @return array
  214. */
  215. public function createWebsiteColumn(array $data): array
  216. {
  217. $insertData = [
  218. 'column_name' => $data['column_name'],
  219. 'pid' => $data['pid'] ?? '',
  220. 'column_arr_id' => $data['column_arr_id'] ?? [0],
  221. 'sort' => $data['sort'] ?? 0,
  222. 'remark' => $data['remark'] ?? '',
  223. ];
  224. $result = WebsiteColumn::insertGetId($insertData);
  225. if (empty($result)) {
  226. return Result::error("创建失败", 0);
  227. } else {
  228. return Result::success(["id" => $result]);
  229. }
  230. }
  231. /**
  232. * @param int $id
  233. * @param array $data
  234. * @return array
  235. */
  236. public function updateWebsiteColumn(int $id, array $data): array
  237. {
  238. $insertData = [
  239. 'column_name' => $data['column_name'],
  240. 'pid' => $data['pid'] ?? '',
  241. 'column_arr_id' => $data['column_arr_id'] ?? [0],
  242. 'sort' => $data['sort'] ?? 0,
  243. 'remark' => $data['remark'] ?? '',
  244. ];
  245. $result = WebsiteColumn::where('id', $id)->update($insertData);
  246. if (empty($result)) {
  247. return Result::error("更新失败", 0);
  248. } else {
  249. return Result::success();
  250. }
  251. }
  252. /**
  253. * @param int $id
  254. * @return array
  255. */
  256. public function delWebsiteColumn(int $id): array
  257. {
  258. $list = WebsiteColumn::where(['pid' => $id])->get();
  259. if ($list) {
  260. return Result::error("存在子网系,不能删除,请先删除子网系", 0);
  261. }
  262. $result = WebsiteColumn::where('id', $id)->delete();
  263. if (empty($result)) {
  264. return Result::error("删除失败", 0);
  265. } else {
  266. return Result::success();
  267. }
  268. }
  269. /**
  270. * @param string $keyword
  271. * @param int $page
  272. * @param int $pageSize
  273. * @return array
  274. */
  275. public function getWebsiteRoleList(string $keyword, int $page, int $pageSize, int $websiteId): array
  276. {
  277. $where = [
  278. ['role.role_name', 'like', '%' . $keyword . '%'],
  279. ['website_role.website_id', '=', $websiteId],
  280. ];
  281. $result = WebsiteRole::where($where)
  282. ->leftJoin("role", "role.id", "website_role.role_id")
  283. ->select("role.*", "website_role.type", "website_role.role_id", "website_role.id as website_role_id", "website_role.website_id")
  284. ->limit($pageSize)->offset(($page - 1) * $pageSize)->get();
  285. $count = WebsiteRole::where($where)->leftJoin("role", "role.id", "website_role.role_id")->count();
  286. if (empty($result)) {
  287. return Result::error("没有数据", 0);
  288. }
  289. $data = [
  290. 'rows' => $result->toArray(),
  291. 'count' => $count
  292. ];
  293. return Result::success($data);
  294. }
  295. /**
  296. * @param array $data
  297. * @return array
  298. */
  299. public function createWebsiteRole(array $data): array
  300. {
  301. $insertData = [
  302. 'website_id' => $data['website_id'],
  303. 'role_id' => $data['role_id'] ?? ''
  304. ];
  305. $info = WebsiteRole::where($insertData)->first();
  306. if ($info) {
  307. return Result::error("不能重复添加角色", 0);
  308. }
  309. $insertData['admin_user_id'] = $data['admin_user_id'] ?? '';
  310. $insertData['type'] = $data['type'] ?? '';
  311. $result = WebsiteRole::insertGetId($insertData);
  312. if (empty($result)) {
  313. return Result::error("创建失败", 0);
  314. } else {
  315. return Result::success(["id" => $result]);
  316. }
  317. }
  318. /**
  319. * 暂时用不上
  320. * @param int $id
  321. * @param array $data
  322. * @return array
  323. */
  324. public function updateWebsiteRole(int $id, array $data): array
  325. {
  326. $insertData = [
  327. 'website_id' => $data['website_id'],
  328. 'type' => $data['type'] ?? '',
  329. ];
  330. $result = WebsiteRole::where('id', $id)->update($insertData);
  331. if (empty($result)) {
  332. return Result::error("更新失败", 0);
  333. } else {
  334. return Result::success();
  335. }
  336. }
  337. /**
  338. * @param int $id
  339. * @return array
  340. */
  341. public function delWebsiteRole(int $id): array
  342. {
  343. $result = WebsiteRole::where('id', $id)->delete();
  344. if (empty($result)) {
  345. return Result::error("删除失败", 0);
  346. } else {
  347. return Result::success();
  348. }
  349. }
  350. /**
  351. * @param string $keyword
  352. * @param int $page
  353. * @param int $pageSize
  354. * @return array
  355. */
  356. public function getWebsiteRoleUserList(string $keyword, int $page, int $pageSize, int $websiteId, int $roleId): array
  357. {
  358. $where = [
  359. ['website_role_user.website_id', '=', $websiteId],
  360. ['website_role_user.role_id', '=', $roleId],
  361. ];
  362. $count = WebsiteRoleUser::where($where)->count();
  363. $where[] = ['u.user_name', 'like', '%' . $keyword . '%'];
  364. $result = WebsiteRoleUser::where($where)
  365. ->leftJoin("user as u", "website_role_user.user_id", "u.id")
  366. ->leftJoin("website as w", "website_role_user.website_id", "u.id")
  367. ->leftJoin("role as r", "website_role_user.role_id", "r.id")
  368. ->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')
  369. ->limit($pageSize)->offset(($page - 1) * $pageSize)->get();
  370. if (empty($result)) {
  371. return Result::error("没有数据", 0);
  372. }
  373. $data = [
  374. 'rows' => $result->toArray(),
  375. 'count' => $count
  376. ];
  377. return Result::success($data);
  378. }
  379. /**
  380. * @param array $data
  381. * @return array
  382. */
  383. public function createWebsiteRoleUser(array $data): array
  384. {
  385. $insertData = [
  386. 'website_id' => $data['website_id'],
  387. 'user_id' => $data['user_id'] ?? '',
  388. ];
  389. $info = WebsiteRoleUser::where($insertData)->first();
  390. if ($info) {
  391. return Result::error("不能重复添加角色用户", 0);
  392. }
  393. $insertData['role_id'] = $data['role_id'] ?? '';
  394. $insertData['admin_user_id'] = $data['admin_user_id'] ?? '';
  395. $insertData['type'] = $data['type'] ?? '';
  396. $result = WebsiteRoleUser::insertGetId($insertData);
  397. if (empty($result)) {
  398. return Result::error("创建失败", 0);
  399. } else {
  400. return Result::success(["id" => $result]);
  401. }
  402. }
  403. /**
  404. * @param int $id
  405. * @param array $data
  406. * @return array
  407. */
  408. public function updateWebsiteRoleUser(int $id, array $data): array
  409. {
  410. $insertData = [
  411. 'website_id' => $data['website_id'],
  412. 'type' => $data['type'] ?? '',
  413. 'type_id' => $data['type_id'] ?? '',
  414. 'role_id' => $data['role_id'] ?? '',
  415. ];
  416. $result = WebsiteRoleUser::where('id', $id)->update($insertData);
  417. if (empty($result)) {
  418. return Result::error("更新失败", 0);
  419. } else {
  420. return Result::success();
  421. }
  422. }
  423. /**
  424. * @param int $id
  425. * @return array
  426. */
  427. public function delWebsiteRoleUser(int $id): array
  428. {
  429. $result = WebsiteRoleUser::where('id', $id)->delete();
  430. if (empty($result)) {
  431. return Result::error("删除失败", 0);
  432. } else {
  433. return Result::success();
  434. }
  435. }
  436. /**
  437. * 根据域名获取网站 站点id
  438. * @param array $data
  439. * @return array
  440. */
  441. public function getWebsiteId(array $data): array
  442. {
  443. $result = Website::whereJsonContains('website_url', $data['website_url'])->first();
  444. if (empty($result)) {
  445. return Result::error("查询站点失败", 0);
  446. } else {
  447. return Result::success($result);
  448. }
  449. }
  450. /**
  451. * 查询网站下面的导航
  452. * @param array $data
  453. * @return array
  454. */
  455. public function getWebsiteCategory(array $data): array
  456. {
  457. $where = [
  458. 'website_id' => $data['website_id'],
  459. 'pid' => 0
  460. ];
  461. $result = WebsiteCategory::where($where)->orderBy('sort', 'asc')->get();
  462. if (empty($result)) {
  463. return Result::error("查询站点栏目失败", 0);
  464. } else {
  465. return Result::success($result);
  466. }
  467. }
  468. /**
  469. * 查询网站的广告
  470. * @param array $data
  471. * @return array
  472. */
  473. public function getWebsiteAdvertisement(array $data): array
  474. {
  475. $where = [
  476. 'website_id' => $data['website_id'],
  477. 'id' => $data['ad_placeid']
  478. ];
  479. $ad_place = AdPlace::where($where)->orderBy('id', 'asc')->limit(1)->get();
  480. $today = Carbon::now();
  481. if (empty($ad_place)) {
  482. return Result::error("error", 0);
  483. } else {
  484. foreach ($ad_place as $val) {
  485. $adplaceid = $val;
  486. }
  487. $ad = Ad::where('pid', $adplaceid['id'])->where('status', 1)->orderBy('id', 'asc')->get();
  488. if (empty($ad)) {
  489. $result = $adplaceid;
  490. return Result::success($result);
  491. } else {
  492. foreach ($ad as $i) {
  493. $starttime = Carbon::parse($i['fromtime']);
  494. $endtime = Carbon::parse($i['totime']);
  495. $time = $today->between($starttime, $endtime);
  496. if ($time) {
  497. $result = $i;
  498. }
  499. }
  500. if (empty($result)) {
  501. $result = $ad;
  502. return Result::success($result);
  503. } else {
  504. return Result::success($result);
  505. }
  506. }
  507. }
  508. }
  509. /**
  510. * 网站行政职能搜索
  511. * @param array $data
  512. * @return array
  513. */
  514. public function selectWebsiteDepartment(array $data): array
  515. {
  516. $depart = Department::where('pid', 0)->orderBy('id', 'asc')->limit(10)->get();
  517. if (isset($data['keyword']) && !empty($data['keyword'])) {
  518. $departments = Department::where('name', 'like', '%' . $data['keyword'] . '%')->get();
  519. if (empty($departments)) {
  520. $result['message'] = "未查询到与此相关职能部门";
  521. } else {
  522. $count = Department::where('name', 'like', "%{$data['keyword']}%")->count();
  523. $m = [
  524. 'department' => $depart,
  525. 'type' => $departments,
  526. 'count' => $count
  527. ];
  528. }
  529. $result['sele'] = $m;
  530. return Result::success($result['sele']);
  531. }
  532. $result = $depart;
  533. return Result::success($result['data']);
  534. }
  535. /**
  536. * 搜索地区
  537. */
  538. public function selectWebsiteArea(array $data): array
  539. {
  540. $provinces = District::where('pid', 0)->where('status', 1)->get();
  541. if (isset($data['province'])) {
  542. $province = District::where('pid', 0)->where('status', 1)->where('id', $data['province'])->orderBy('id')->get();
  543. $province = $province->toArray();
  544. if (!empty($province)) {
  545. $citys = District::where('pid', $data['province'])->where('status', 1)->orderBy('id')->get();
  546. if (!empty($citys) && isset($data['city']) && !empty($data['city'])) {
  547. // $province = $province->toArray();
  548. $province_id = [];
  549. foreach ($province as $val) {
  550. array_push($province_id, $val['id']);
  551. }
  552. // var_dump($province_id);
  553. $city = District::whereIn('pid', $province_id)->where('status', 1)->where('id', $data['city'])->orderBy('id')->get();
  554. if (!empty($city)) {
  555. $city_id = [];
  556. foreach ($city as $val) {
  557. array_push($city_id, $val['id']);
  558. }
  559. $regions = District::whereIn('pid', $city_id)->where('status', 1)->orderBy('id')->get();
  560. $result = [
  561. 'province' => $province,
  562. 'city' => $city,
  563. 'region' => $regions
  564. ];
  565. } else {
  566. return Result::error("未查询到此城市", 0);
  567. }
  568. } else {
  569. $result = [
  570. 'province' => $province,
  571. 'city' => $citys,
  572. 'region' => null
  573. ];
  574. }
  575. } else {
  576. return Result::error("未查询到此省份", 0);
  577. }
  578. } else {
  579. // $keys = array('data');
  580. $result = $provinces;
  581. }
  582. return Result::success($result);
  583. }
  584. /**
  585. * 获取栏目
  586. * @param array $data
  587. * @return array
  588. */
  589. public function getWebsiteModelCategory(array $data): array
  590. {
  591. $website_id = [
  592. 'website_id' => $data['website_id']
  593. ];
  594. $placeid = $data['placeid'] - 1;
  595. $pid = [
  596. 'pid' => $data['pid'],
  597. ];
  598. $num = $data['num'];
  599. $result = WebsiteCategory::where($website_id)->where($pid)->orderBy('sort')->offset($placeid)->limit($num)->get();
  600. $result = $result->toArray();
  601. if (!empty($result)) {
  602. return Result::success($result);
  603. } else {
  604. return Result::error("本网站暂无栏目", 0);
  605. }
  606. }
  607. /**
  608. *获取友情链接
  609. * @param array $data
  610. * @return array
  611. */
  612. public function selectWebsiteLinks(array $data): array
  613. {
  614. $where = [
  615. 'website_id' => $data['website_id'],
  616. 'status' => 1,
  617. 'type' => $data['type']
  618. ];
  619. $num=$data['num'];
  620. $result=Link::where($where)->orderBy('id')->limit($num)->get();
  621. if(!empty($result)){
  622. return Result::success($result);
  623. }else{
  624. return Result::error("本网站暂无此类型友情链接",0);
  625. }
  626. }
  627. /**
  628. * 网站首页数据统计, 管理员
  629. * @return void
  630. */
  631. public function getAdminIndex(array $data): array
  632. {
  633. var_dump("用户类型:", $data['type_id']);
  634. switch ($data['type_id']) {
  635. case 4:
  636. $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;');
  637. return Result::success($result);
  638. break;
  639. case 10000:
  640. $res = [];
  641. //网站
  642. $res['website']['count'] = 0;
  643. $res['website']['growth_rate'] = 0;
  644. //资讯
  645. $res['article']['count'] = 0;
  646. $res['article']['growth_rate'] = 0;
  647. //导航池
  648. $res['category']['count'] = 0;
  649. $res['category']['growth_rate'] = 0;
  650. //近一月数据
  651. $res['monthArticle'] = [];
  652. //用户类型
  653. $res['userType'] = [];
  654. $res['website']['count'] = Website::where([])->count();
  655. $res['article']['count'] = Article::whereNotIn('status', ['404'])->count();
  656. $res['category']['count'] = Category::where([])->count();
  657. $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;');
  658. $res['userType'] = User::where([])->selectRaw("count(*) as counts,type_id")->groupBy('type_id')->get();
  659. return Result::success($res);
  660. }
  661. return [];
  662. }
  663. /**
  664. * 获取模板类型
  665. * @return void
  666. */
  667. public function getTemplateClass(array $data): array
  668. {
  669. $where = [];
  670. if (isset($data['name']) && $data['name']) {
  671. array_push($where, ['name', 'like', '%' . $data['name'] . '%']);
  672. }
  673. $result = TemplateClass::where($where)->orderBy('sort', 'asc')->get();
  674. if (empty($result)) {
  675. return Result::error("没有模板类型", 0);
  676. } else {
  677. return Result::success($result);
  678. }
  679. }
  680. /**
  681. * 添加模板类型
  682. * @param
  683. * @return void
  684. */
  685. public function addTemplateClass(array $data): array
  686. {
  687. $insertData = [
  688. 'name' => $data['name']
  689. ];
  690. $result = TemplateClass::insertGetId($insertData);
  691. if (empty($result)) {
  692. return Result::error("创建失败", 0);
  693. } else {
  694. return Result::success(["id" => $result]);
  695. }
  696. }
  697. /**
  698. * 更新模板
  699. * @param array $data
  700. * @return array
  701. */
  702. public function upTemplateClass(array $data): array
  703. {
  704. $where = [
  705. 'id' => $data['id']
  706. ];
  707. $insertData = [
  708. 'name' => $data['name']
  709. ];
  710. $result = TemplateClass::where($where)->update($insertData);
  711. if (empty($result)) {
  712. return Result::error("更新失败", 0);
  713. } else {
  714. return Result::success();
  715. }
  716. }
  717. /**
  718. * 删除模板
  719. * @param array $data
  720. * @return array
  721. */
  722. public function delTemplateClass(array $data): array
  723. {
  724. $where = [
  725. 'id' => $data['id']
  726. ];
  727. $result = TemplateClass::where($where)->delete();
  728. if (empty($result)) {
  729. return Result::error("删除失败", 0);
  730. } else {
  731. return Result::success();
  732. }
  733. }
  734. /**
  735. * 获取分类下的模板
  736. * @param array $data
  737. * @return array
  738. */
  739. public function getTemplate(array $data): array
  740. {
  741. $page = $data['page'];
  742. $pageSize = $data['pageSize'];
  743. $where = [];
  744. if (isset($data['template_class_id']) && $data['template_class_id']) {
  745. array_push($where, ['template_class_id', '=', $data['template_class_id']]);
  746. }
  747. $result = Template::where($where)
  748. ->limit($pageSize)->offset(($page - 1) * $pageSize)->get();
  749. $count = Template::where($where)->count();
  750. if (empty($result)) {
  751. return Result::error("没有数据", 0);
  752. }
  753. $data = [
  754. 'rows' => $result->toArray(),
  755. 'count' => $count
  756. ];
  757. return Result::success($data);
  758. }
  759. /**
  760. * 创建模板
  761. * @param
  762. * @return void
  763. */
  764. public function addTemplate(array $data): array
  765. {
  766. $insertData = [
  767. 'template_name' => $data['template_name'],
  768. 'template_img' => json_encode($data['template_img']),
  769. 'template_class_id' => $data['template_class_id'],
  770. ];
  771. $result = Template::insertGetId($insertData);
  772. if (empty($result)) {
  773. return Result::error("创建模板失败", 0);
  774. } else {
  775. return Result::success(["id" => $result]);
  776. }
  777. }
  778. /**
  779. * 更新模板
  780. * @param array $data
  781. * @return array
  782. */
  783. public function upTemplate(array $data): array
  784. {
  785. $where = [
  786. 'id' => $data['id']
  787. ];
  788. $insertData = [
  789. 'template_name' => $data['template_name'],
  790. 'template_img' => json_encode($data['template_img']),
  791. 'template_class_id' => $data['template_class_id'],
  792. ];
  793. $result = Template::where($where)->update($insertData);
  794. if (empty($result)) {
  795. return Result::error("更新模板失败", 0);
  796. } else {
  797. return Result::success();
  798. }
  799. }
  800. /**
  801. * 删除模板
  802. * @param array $data
  803. * @return array
  804. */
  805. public function delTemplate(array $data): array
  806. {
  807. $where = [
  808. 'id' => $data['id']
  809. ];
  810. $result = Template::where($where)->delete();
  811. if (empty($result)) {
  812. return Result::error("删除模板失败", 0);
  813. } else {
  814. return Result::success();
  815. }
  816. }
  817. /**
  818. * 搜索网站
  819. * @param array $data
  820. * @return array
  821. */
  822. public function websiteList(array $data): array
  823. {
  824. $where = [];
  825. if (isset($data['keyword']) && !empty($data['keyword'])) {
  826. array_push($where, ['website.website_name', 'like', '%' . $data['keyword'] . '%']);
  827. }
  828. $result = Website::where($where)->get();
  829. if ($result) {
  830. return Result::success($result);
  831. } else {
  832. return Result::error("没有网站", 0);
  833. }
  834. }
  835. public function addWebsiteCategory(array $data): array
  836. {
  837. $website_id = $data['website_id'];
  838. $category_arr_id = $data['category_arr_id'];
  839. $categoryList = Category::whereIn('id', $category_arr_id)->get();
  840. $categoryListIds = [];
  841. if ($categoryList) {
  842. foreach ($categoryList->toArray() as $val) {
  843. array_push($categoryListIds, $val['id']);
  844. }
  845. }
  846. $arr = [];
  847. if ($categoryListIds) {
  848. foreach ($categoryListIds as $v) {
  849. $ids = $this->getUnderlingUIds(intval($v));
  850. $ids_arr = explode(",", $ids);
  851. array_push($arr, $ids_arr);
  852. }
  853. }
  854. $mergedArray = [];
  855. foreach ($arr as $subarray) {
  856. $mergedArray = array_merge($mergedArray, $subarray);
  857. }
  858. var_dump("所有:", $arr, $mergedArray);
  859. //查询出所有的分类进行分割插入 组装数据
  860. $categoryListData = Category::whereIn('id', $mergedArray)->get();
  861. $categoryListData = $categoryListData->toArray();
  862. $insertData = [];
  863. if ($categoryListData) {
  864. foreach ($categoryListData as $key => $value) {
  865. $insertData[$key]['website_id'] = $website_id;
  866. $insertData[$key]['name'] = $value['name'];
  867. $insertData[$key]['sort'] = $value['sort'];
  868. $insertData[$key]['pid'] = $value['pid'];
  869. $insertData[$key]['pid_arr'] = $value['pid_arr'];
  870. $insertData[$key]['seo_title'] = $value['seo_title'];
  871. $insertData[$key]['seo_keywords'] = $value['seo_keywords'];
  872. $insertData[$key]['seo_description'] = $value['seo_description'];
  873. $insertData[$key]['alias'] = $value['name'];
  874. $insertData[$key]['category_id'] = $value['id'];
  875. }
  876. }
  877. $result = WebsiteCategory::insert($insertData);
  878. var_dump("插入数据状态:", $result);
  879. if ($result) {
  880. return Result::success($result);
  881. } else {
  882. return Result::error("创建失败", 0);
  883. }
  884. }
  885. /**
  886. * 删除网站导航
  887. * @param array $data
  888. * @return array
  889. */
  890. public function delWebsiteCategory(array $data): array
  891. {
  892. $website_id = $data['website_id'] ?? 0;
  893. $category_id = $data['category_id'] ?? 0;
  894. $ids = $this->getUnderlingUIds(intval($category_id));
  895. $ids_arr = explode(",", $ids);
  896. $result = WebsiteCategory::where(['website_id' => $website_id])->whereIn("category_id", $ids_arr)->delete();
  897. if ($result) {
  898. return Result::success($result);
  899. } else {
  900. return Result::error("删除失败", 0);
  901. }
  902. }
  903. /**
  904. * 获取网站导航
  905. * @param array $data
  906. * @return array
  907. */
  908. public function getAdminWebsiteCategory(array $data): array
  909. {
  910. $where = [
  911. 'website_id' => $data['website_id'],
  912. 'pid' => 0
  913. ];
  914. $result = WebsiteCategory::where($where)->get();
  915. if ($result) {
  916. return Result::success($result);
  917. } else {
  918. return Result::error("查询失败", 0);
  919. }
  920. }
  921. /**
  922. * 更新网站导航
  923. * @param array $data
  924. * @return array
  925. */
  926. public function upWebsiteCategory(array $data): array
  927. {
  928. Db::beginTransaction();
  929. try {
  930. //合并栏目id
  931. $reqIds = array_merge($data['old_category_arr_id'], $data['new_category_arr_id']);
  932. //对比old 数组差异化,把差异化的删除
  933. $result = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])->get();
  934. $result = $result->toArray();
  935. $categoryIds = [];
  936. if ($result) {
  937. foreach ($result as $val) {
  938. array_push($categoryIds, $val['category_id']);
  939. }
  940. }
  941. //和原始数据对比取交际
  942. $reqidsIntersect = array_intersect($reqIds, $categoryIds);
  943. //再取差集 进行对比
  944. $differenceIDS = array_merge(array_diff($reqidsIntersect, $categoryIds), array_diff($categoryIds, $reqidsIntersect));
  945. var_dump("差集:", $differenceIDS);
  946. $arr_ids = [];
  947. if (count($differenceIDS) > 0) {
  948. foreach ($differenceIDS as $vv) {
  949. $idV = $this->getUnderlingUIds(intval($vv));
  950. $ids_arrV = explode(",", $idV);
  951. array_push($arr_ids, $ids_arrV);
  952. }
  953. }
  954. $del_ids = array_reduce($arr_ids, 'array_merge', array());
  955. //有差异 删除
  956. if (count($del_ids) > 0) {
  957. WebsiteCategory::where(['website_id' => $data['website_id']])->whereIn("category_id", $del_ids)->delete();
  958. }
  959. //传过来的值 和 交际 对比,选出要添加的值 进行插入
  960. $insertIDS = array_merge(array_diff($reqIds, $reqidsIntersect), array_diff($reqidsIntersect, $reqIds));
  961. var_dump("要存储的:", $insertIDS);
  962. //新的数组重新创建
  963. if (count($insertIDS) > 0) {
  964. $arr = [];
  965. $categoryListIds = $insertIDS;
  966. if ($categoryListIds) {
  967. foreach ($categoryListIds as $v) {
  968. $ids = $this->getUnderlingUIds(intval($v));
  969. $ids_arr = explode(",", $ids);
  970. array_push($arr, $ids_arr);
  971. }
  972. }
  973. $mergedArray = [];
  974. foreach ($arr as $subarray) {
  975. $mergedArray = array_merge($mergedArray, $subarray);
  976. }
  977. var_dump("要插入的ID:", $mergedArray);
  978. //查询出所有的分类进行分割插入 组装数据
  979. $categoryListData = Category::whereIn('id', $mergedArray)->get();
  980. $categoryListData = $categoryListData->toArray();
  981. $insertData = [];
  982. if ($categoryListData) {
  983. foreach ($categoryListData as $key => $value) {
  984. $insertData[$key]['website_id'] = $data['website_id'];
  985. $insertData[$key]['name'] = $value['name'];
  986. $insertData[$key]['sort'] = $value['sort'];
  987. $insertData[$key]['pid'] = $value['pid'];
  988. $insertData[$key]['pid_arr'] = $value['pid_arr'];
  989. $insertData[$key]['seo_title'] = $value['seo_title'];
  990. $insertData[$key]['seo_keywords'] = $value['seo_keywords'];
  991. $insertData[$key]['seo_description'] = $value['seo_description'];
  992. $insertData[$key]['alias'] = $value['name'];
  993. $insertData[$key]['category_id'] = $value['id'];
  994. }
  995. }
  996. WebsiteCategory::insert($insertData);
  997. }
  998. Db::commit();
  999. } catch (\Throwable $ex) {
  1000. Db::rollBack();
  1001. var_dump($ex->getMessage());
  1002. return Result::error("修改失败", 0);
  1003. }
  1004. return Result::success();
  1005. }
  1006. /**
  1007. * 获取网站列表
  1008. * @param array $data
  1009. * @return array
  1010. */
  1011. public function getWebsiteCategoryList(array $data): array
  1012. {
  1013. $where = [];
  1014. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1015. array_push($where, ['website.website_name', 'like', '%' . $data['keyword'] . '%']);
  1016. }
  1017. if (isset($data['website_column_id']) && !empty($data['website_column_id'])) {
  1018. array_push($where, ['website.website_column_id', '=', $data['website_column_id']]);
  1019. }
  1020. $result = Website::where($where)
  1021. ->with(["websiteCategory" => function ($query) {
  1022. $query->where(['pid' => 0])->select('website_id', 'name', 'alias', 'category_id');
  1023. }])
  1024. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])
  1025. ->get();
  1026. $count = Website::where($where)->count();
  1027. if (empty($result)) {
  1028. return Result::error("没有数据", 0);
  1029. }
  1030. $data = [
  1031. 'rows' => $result->toArray(),
  1032. 'count' => $count
  1033. ];
  1034. if ($result) {
  1035. return Result::success($data);
  1036. } else {
  1037. return Result::error("查询失败", 0);
  1038. }
  1039. }
  1040. /**
  1041. * 删除网站下的所有导航
  1042. * @param array $data
  1043. * @return array
  1044. */
  1045. public function delWebsiteAllCategory(array $data): array
  1046. {
  1047. $website_id = $data['website_id'];
  1048. $result = WebsiteCategory::where(['website_id' => $website_id])->delete();
  1049. if ($result) {
  1050. return Result::success($result);
  1051. } else {
  1052. return Result::error("删除失败", 0);
  1053. }
  1054. }
  1055. /**
  1056. * 获取网站下的某一个导航
  1057. * @param array $data
  1058. * @return array
  1059. */
  1060. public function getWebsiteCategoryOnes(array $data): array
  1061. {
  1062. $website_id = $data['website_id'];
  1063. $category_id = $data['category_id'];
  1064. $result = WebsiteCategory::where(['website_category.website_id' => $website_id, 'website_category.category_id' => $category_id])
  1065. ->first();
  1066. if ($result) {
  1067. return Result::success($result);
  1068. } else {
  1069. return Result::error("查询失败", 0);
  1070. }
  1071. }
  1072. /**
  1073. * 更新网闸下的某一个导航
  1074. * @param array $data
  1075. * @return array
  1076. */
  1077. public function upWebsiteCategoryones(array $data): array
  1078. {
  1079. $where = [
  1080. 'website_id' => $data['website_id'],
  1081. 'category_id' => $data['category_id'],
  1082. ];
  1083. $result = WebsiteCategory::where($where)->update($data);
  1084. if ($result) {
  1085. return Result::success($result);
  1086. } else {
  1087. return Result::error("更新失败", 0);
  1088. }
  1089. }
  1090. /**
  1091. * 获取网站下的所有导航(包含子导航)
  1092. * @param array $data
  1093. * @return array
  1094. */
  1095. public function getWebsiteAllCategory(array $data): array
  1096. {
  1097. $where = [];
  1098. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1099. array_push($where, ['website_category.website_id', '=', $data['website_id']]);
  1100. }
  1101. if (isset($data['name']) && !empty($data['name'])) {
  1102. array_push($where, ['website_category.name', 'like', '%' . $data['name'] . '%']);
  1103. }
  1104. if (isset($data['alias']) && !empty($data['alias'])) {
  1105. array_push($where, ['website_category.alias', 'like', '%' . $data['alias'] . '%']);
  1106. }
  1107. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1108. array_push($where, ['category.department_id', '=', $data['department_id']]);
  1109. }
  1110. if (isset($data['city_id']) && !empty($data['city_id'])) {
  1111. array_push($where, ['category.city_id', '=', $data['city_id']]);
  1112. }
  1113. $result = WebsiteCategory::where($where)
  1114. ->leftJoin("category", 'website_category.category_id', 'category.id')
  1115. ->leftJoin("department", 'category.department_id', 'department.id')
  1116. ->leftJoin("district", 'category.city_id', 'district.id')
  1117. ->select("website_category.*", "department.name as department_name", "district.name as city_name")
  1118. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])
  1119. ->get();
  1120. $count = WebsiteCategory::where($where)
  1121. ->leftJoin("category", 'website_category.category_id', 'category.id')
  1122. ->leftJoin("department", 'category.department_id', 'department.id')
  1123. ->leftJoin("district", 'category.city_id', 'district.id')
  1124. ->count();
  1125. if (empty($result)) {
  1126. return Result::error("没有数据", 0);
  1127. }
  1128. $data = [
  1129. 'rows' => $result->toArray(),
  1130. 'count' => $count
  1131. ];
  1132. if ($result) {
  1133. return Result::success($data);
  1134. } else {
  1135. return Result::error("查询失败", 0);
  1136. }
  1137. if ($result) {
  1138. return Result::success($result);
  1139. } else {
  1140. return Result::error("查询失败", 0);
  1141. }
  1142. }
  1143. /**
  1144. * 递归查询数据
  1145. * @param $id
  1146. * @param $ids
  1147. * @return string
  1148. */
  1149. public function getUnderlingUIds($id, $ids = '')
  1150. {
  1151. $back = Category::where(['pid' => $id])->get();
  1152. $back = $back->toArray();
  1153. if (!empty($back) && is_array($back)) {
  1154. foreach ($back as $v) {
  1155. //防止当前人的ID重复去查询,形成恶性循环
  1156. if ($v['id'] == $id) {
  1157. continue;
  1158. }
  1159. $back2 = Category::where(['pid' => $id])->count('id');
  1160. if ($back2 > 0) {
  1161. $ids = $this->getUnderlingUIds($v['id'], $ids);
  1162. } else {
  1163. $ids .= ',' . $v['id'];
  1164. }
  1165. }
  1166. }
  1167. $ids = $id . ',' . $ids . ',';
  1168. $ids = str_replace(',,', ",", $ids);
  1169. $ids = trim($ids, ',');
  1170. return $ids;
  1171. }
  1172. /**
  1173. * 检测网站名称是否重复
  1174. * @param array $data
  1175. * @return array
  1176. */
  1177. public function checkWebsiteName(array $data): array
  1178. {
  1179. if (isset($data['id'])) {
  1180. $data[] = ['id', "!=", $data['id']];
  1181. unset($data['id']);
  1182. }
  1183. $websiteInfo = Website::query()->where($data)->first();
  1184. if (empty($websiteInfo)) {
  1185. return Result::error("找不到网站", 0);
  1186. }
  1187. return Result::success($websiteInfo->toArray());
  1188. }
  1189. /**
  1190. * 检测网站url是否重复
  1191. * @param array $data
  1192. * @return array
  1193. */
  1194. public function checkWebsiteUrl(array $data): array
  1195. {
  1196. $whereData = [];
  1197. if (isset($data['id'])) {
  1198. $whereData = [['id', "!=", $data['id']]];
  1199. unset($data['id']);
  1200. }
  1201. $websiteInfo = Website::query()->where($whereData)->whereJsonContains('website_url', $data['website_url'])->first();
  1202. if (empty($websiteInfo)) {
  1203. return Result::error("找不到URL", 0);
  1204. }
  1205. return Result::success($websiteInfo->toArray());
  1206. }
  1207. /**
  1208. * 获取并搜索 网站模板信息
  1209. * @param array $data
  1210. * @return array
  1211. */
  1212. public function getWebsiteTemplateinfo(array $data): array
  1213. {
  1214. $where = []; // 初始化 $where 数组
  1215. //若存在条件;则在$rep的基础上进行筛选
  1216. if(isset($data['website_name'])){
  1217. array_push($where, ['website.website_name','like','%'.$data['website_name'].'%']);
  1218. }
  1219. if(isset($data['status'])){
  1220. if($data['status'] == 0){
  1221. array_push($where, ['website_template_info.status','=',null]);
  1222. }else{
  1223. array_push($where, ['website_template_info.status','=',$data['status']]);
  1224. }
  1225. }
  1226. //查询所有网站模板信息
  1227. if(empty($where)){
  1228. $rep = Website::where('website.status', 1)
  1229. ->leftJoin("website_template_info", "website_template_info.website_id", "website.id")
  1230. ->leftJoin("template", "template.id", "website_template_info.template_id")
  1231. ->select(
  1232. "website.website_name",
  1233. "website.website_url",
  1234. "website_template_info.id as tid",
  1235. "website_template_info.created_at",
  1236. "website_template_info.updated_at",
  1237. "website_template_info.page_type",
  1238. DB::raw("COALESCE(website_template_info.status, 0) as template_status"),
  1239. "template.template_name"
  1240. )
  1241. ->limit($data['pageSize'])
  1242. ->offset(($data['page'] - 1) * $data['pageSize'])
  1243. ->orderBy("website_template_info.updated_at", "asc")
  1244. ->get();
  1245. }else{
  1246. $rep = Website::where($where)
  1247. ->where('website.status', 1)
  1248. ->leftJoin("website_template_info", "website_template_info.website_id", "website.id")
  1249. ->leftJoin("template", "template.id", "website_template_info.template_id")
  1250. ->select(
  1251. "website.website_name",
  1252. "website.website_url",
  1253. "website_template_info.id as tid",
  1254. "website_template_info.created_at",
  1255. "website_template_info.updated_at",
  1256. "website_template_info.page_type",
  1257. DB::raw("COALESCE(website_template_info.status, 0) as template_status"),
  1258. "template.template_name"
  1259. )
  1260. ->limit($data['pageSize'])
  1261. ->offset(($data['page'] - 1) * $data['pageSize'])
  1262. ->orderBy("website_template_info.updated_at", "asc")
  1263. ->get();
  1264. }
  1265. $result = [
  1266. "rows" => $rep->toArray(),
  1267. "count" => $rep->count()
  1268. ];
  1269. if($rep->count()==0){
  1270. return Result::error("没有查找到相关数据",0);
  1271. } else {
  1272. return Result::success($result); // 返回结果应该是 $result,而不是 $where
  1273. }
  1274. // return Result::success($result);
  1275. }
  1276. /**
  1277. * 添加网站模板信息
  1278. * @param array $data
  1279. * @return array
  1280. */
  1281. public function addWebsiteTemplateinfo(array $data): array
  1282. {
  1283. $website = Website::where('website.id',$data['website_id'])->first();
  1284. if(empty($website)){
  1285. $message = "请输入正确的网站id!";
  1286. }else{
  1287. if(empty($website['website_column_id'])){
  1288. $message = "请先关联导航池!";
  1289. }
  1290. if(isset($data['page_type'])){
  1291. if (in_array(1, $data['page_type']) && in_array(7, $data['page_type'])) {
  1292. // 数组中同时包含值为 1(首页) 和值为 7 (底部导航详情页)的元素
  1293. $result = 'yes';
  1294. $data['page_type'] = json_encode($data['page_type'])??''; // 将数组转换为 JSON 字符串
  1295. $result = WebsiteTemplateInfo::insertGetId($data);
  1296. } else {
  1297. $message = "请先选择首页和底部导航详情页!";
  1298. }
  1299. }else{
  1300. $footer = FooterCategory::where('website_id',$data['website_id'])->select('type')->get();
  1301. if(empty($footer)){
  1302. $types = '2';
  1303. }else{
  1304. $types = 2;
  1305. foreach ($footer as $v) {
  1306. if ($v['type'] == 1) {
  1307. $types = 1;
  1308. } else {
  1309. $types = 0;
  1310. }
  1311. }
  1312. }
  1313. $result['type'] = $types;
  1314. }
  1315. }
  1316. if(empty($result)){
  1317. return Result::error($message,0);
  1318. }else{
  1319. return Result::success($result);
  1320. }
  1321. }
  1322. /**
  1323. * 添加网站模板信息
  1324. * @param array $data
  1325. * @return array
  1326. */
  1327. public function addWebsiteTemplate(array $data): array
  1328. {
  1329. $website = Website::where('website.id',$data['website_id'])->first();
  1330. if(empty($website)){
  1331. $message = "请输入正确的网站id!";
  1332. }else{
  1333. //若存在模板id 则直接添加
  1334. if(isset($data['template_id'])){
  1335. $template = Template::where('id',$data['template_id'])->first();
  1336. if(empty($template)){
  1337. $message = "请输入正确的模板id!";
  1338. }else{
  1339. $result = WebsiteTemplateInfo::where('website_id',$data['website_id'])
  1340. ->update(['template_id'=>$data['template_id']]);
  1341. return Result::success($result);
  1342. }
  1343. }else{
  1344. $where = $data["page_type"];
  1345. if(isset($data['template_class_id'])){
  1346. $template_class = TemplateClass::where('id',$data['template_class_id'])->first();
  1347. if(empty($template_class)){
  1348. $message = "请输入正确的模板风格id!";
  1349. }else{
  1350. // 获取指定风格下的模板
  1351. $rep = Template::where('template_class_id', $data['template_class_id'])
  1352. ->where(function ($query) use ($where) {
  1353. foreach ($where as $value) {
  1354. $query->whereJsonContains('template_img', ['value' => $value]);
  1355. }
  1356. })
  1357. ->leftJoin('template_class','template_class.id','template.template_class_id')
  1358. ->select('template.*','template_class.name')
  1359. ->limit($data['pageSize'])
  1360. ->offset(($data['page'] - 1) * $data['pageSize'])
  1361. ->orderBy("template.updated_at", "desc")
  1362. ->get();
  1363. }
  1364. }else{
  1365. //获取所有模板
  1366. $rep = Template::where(function ($query) use ($where) {
  1367. foreach ($where as $value) {
  1368. $query->whereJsonContains('template_img', ['value' => $value]);
  1369. }
  1370. })
  1371. ->offset(($data['page'] - 1) * $data['pageSize'])
  1372. ->limit($data['pageSize'])
  1373. ->orderBy("template.updated_at", "desc")
  1374. ->get();
  1375. }
  1376. if(empty($rep->toArray())){
  1377. $message = "没有查找到相关数据!";
  1378. }else{
  1379. $result = [
  1380. "rows" => $rep->toArray(),
  1381. "count" => $rep->count()
  1382. ];
  1383. }
  1384. }
  1385. }
  1386. if(empty($rep->toArray())){
  1387. return Result::error($message,0);
  1388. }else{
  1389. return Result::success($result);
  1390. }
  1391. }
  1392. /**
  1393. * 获取所有网站模板信息
  1394. *
  1395. * @return array
  1396. */
  1397. public function getAllTemplateClass(array $data): array
  1398. {
  1399. $result = TemplateClass::all();
  1400. if(empty($result)){
  1401. return Result::error("没有查找到相关数据!",0);
  1402. }else{
  1403. return Result::success($result);
  1404. }
  1405. }
  1406. /**
  1407. * 风格下的板块
  1408. * @return void
  1409. */
  1410. public function templateSectorList(array $data): array
  1411. {
  1412. $where = [
  1413. 'template_id' => $data['template_id']
  1414. ];
  1415. $result = Sector::where($where)->whereJsonContains("page_type", $data['page_type'])
  1416. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])
  1417. ->get();
  1418. $count = Sector::where($where)->count();
  1419. if (empty($result)) {
  1420. return Result::error("没有数据", 0);
  1421. }
  1422. $data = [
  1423. 'rows' => $result->toArray(),
  1424. 'count' => $count
  1425. ];
  1426. if (empty($result)) {
  1427. return Result::error("没有数据", 0);
  1428. }
  1429. return Result::success($data);
  1430. }
  1431. /**
  1432. * 板块下的组件
  1433. * @param array $data
  1434. * @return array
  1435. */
  1436. public function sectorComponentList(array $data): array
  1437. {
  1438. $where = [
  1439. 'template_id' => $data['template_id'],
  1440. 'sector_id' => $data['sector_id'],
  1441. ];
  1442. $result = Component::where($where)
  1443. ->select("*")
  1444. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])
  1445. ->get();
  1446. $count = Component::where($where)->count();
  1447. if (empty($result)) {
  1448. return Result::error("没有数据", 0);
  1449. }
  1450. $data = [
  1451. 'rows' => $result->toArray(),
  1452. 'count' => $count
  1453. ];
  1454. if (empty($result)) {
  1455. return Result::error("没有数据", 0);
  1456. }
  1457. return Result::success($data);
  1458. }
  1459. /**
  1460. * 获取模板内容
  1461. * @return void
  1462. */
  1463. public function getWebsiteTemplateInfo(array $data): array
  1464. {
  1465. $wehre = [
  1466. "website_id" => $data['website_id']
  1467. ];
  1468. $result = WebsiteTemplate::where($wehre)->first();
  1469. if ($result) {
  1470. return Result::success($result);
  1471. } else {
  1472. return Result::error("没有数据", 0);
  1473. }
  1474. }
  1475. /**
  1476. * 保存网站模板
  1477. * @param array $data
  1478. * @return array
  1479. */
  1480. public function addWebsiteTemplate(array $data): array
  1481. {
  1482. var_dump("接收参数:", $data['template_data']);
  1483. $result = WebsiteTemplate::updateOrInsert(['website_id' => $data['website_id']], ['template_data' => json_encode($data['template_data'])]);
  1484. if ($result) {
  1485. return Result::success($result);
  1486. } else {
  1487. return Result::error("创建失败", 0);
  1488. }
  1489. }
  1490. /**
  1491. * 预览网站首页模板数据
  1492. * @param array $data
  1493. * @return array
  1494. */
  1495. public function getWebsiteTemplateData(array $data): array
  1496. {
  1497. $wehre = [
  1498. "website_id" => $data['website_id']
  1499. ];
  1500. $result = WebsiteTemplate::where($wehre)->first();
  1501. if ($result) {
  1502. $templateData = json_decode($result['template_data'], true);
  1503. // var_dump("数据:",$templateData[1]);
  1504. $templateData[1] = $this->getNewsList($templateData[1]);
  1505. return Result::success($templateData);
  1506. } else {
  1507. return Result::error("没有数据", 0);
  1508. }
  1509. }
  1510. /**
  1511. * 获取数据
  1512. * @return void
  1513. */
  1514. public function getNewsList(array $data): array
  1515. {
  1516. if ($data) {
  1517. foreach ($data as $key => $val) {
  1518. if ($val) {
  1519. foreach ($val['data'] as $k => $item) {
  1520. if ($item['isReturn'] && intval($item['isReturn']) == 1) {
  1521. $imgList = [];
  1522. if ($item['data']['imgNum'] && intval($item['data']['imgNum']) > 0) {
  1523. $imgList = Article::where('imgurl', "!=", "")
  1524. ->where('catid', $item['data']['category_id'])
  1525. ->select($item['data']['selectField'])
  1526. ->orderBy("created_at", "desc")
  1527. ->offset(0)
  1528. ->limit(intval($item['data']['imgNum']))
  1529. ->get();
  1530. $imgList = $imgList->toArray();
  1531. $listIds = [];
  1532. if ($imgList) {
  1533. $listIds = array_column($imgList, 'id');
  1534. }
  1535. $dataList = Article::whereNotIn('id', $listIds)
  1536. ->where('catid', $item['data']['category_id'])
  1537. ->select($item['data']['selectField'])
  1538. ->orderBy("created_at", "desc")
  1539. ->offset(0)
  1540. ->limit(intval($item['data']['pageSize']) - intval($item['data']['imgNum']))
  1541. ->get();
  1542. $dataList = $dataList->toArray();
  1543. var_dump("图片列表:", $imgList, "数据列表:", $dataList);
  1544. $datas = array_merge($imgList, $dataList);
  1545. // return $datas;
  1546. var_dump("合并列表:", $datas);
  1547. $data[$key]['data'][$k]['dataList'] = $datas;
  1548. } else {
  1549. $dataList = Article::where('catid', $item['data']['category_id'])
  1550. ->select($item['data']['selectField'])
  1551. ->orderBy("created_at", "desc")
  1552. ->offset(0)
  1553. ->limit(intval($item['data']['pageSize']))
  1554. ->get();
  1555. $dataList = $dataList->toArray();
  1556. var_dump("数据列表:", $dataList);
  1557. }
  1558. }
  1559. }
  1560. }
  1561. }
  1562. }
  1563. return $data;
  1564. }
  1565. /**
  1566. * 获取底部导航列表
  1567. * @param array $data
  1568. * @return array
  1569. */
  1570. public function getFooterCategoryList(array $data): array
  1571. {
  1572. $where = [
  1573. "website_id" => $data['website_id']
  1574. ];
  1575. $result = FooterCategory::where($where)->get();
  1576. if ($result) {
  1577. return Result::success($result);
  1578. } else {
  1579. return Result::error("没有数据");
  1580. }
  1581. }
  1582. //获取底部导航内容列表
  1583. public function getFooterContentList(array $data): array
  1584. {
  1585. $where = [
  1586. "fcat_id" => $data['fcat_id'],
  1587. ];
  1588. switch (intval($data['type'])) {
  1589. case 0:
  1590. $result = FooterContent::where($where)->first();
  1591. break;
  1592. case 1:
  1593. $result = FooterContent::where($where)->get();
  1594. break;
  1595. }
  1596. if ($result) {
  1597. return Result::success($result);
  1598. } else {
  1599. return Result::error("没有数据");
  1600. }
  1601. }
  1602. //获取底部导航内容详情
  1603. public function getFooterContentInfo(array $data): array
  1604. {
  1605. $where = [
  1606. "id" => $data['content_id']
  1607. ];
  1608. $result = FooterContent::where($where)->first();
  1609. if ($result) {
  1610. return Result::success($result);
  1611. } else {
  1612. return Result::error("没有数据");
  1613. }
  1614. }
  1615. }