WebsiteService.php 51 KB

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