WebsiteService.php 60 KB

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