WebsiteService.php 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503
  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. $resultWwhere = Website::when($data,function ($query) use ($data){
  36. if(isset($data['keyword']) && !empty($data['keyword'])){
  37. $query->where('website.website_name','like','%'.$data['keyword'].'%');
  38. }
  39. if(isset($data['website_column_id']) && !empty($data['website_column_id'])){
  40. $query->whereJsonContains("website.website_column_arr_id", intval($data['website_column_id']));
  41. }
  42. if(isset($data['city_id']) && !empty($data['city_id'])){
  43. $query->whereJsonContains("website.city_arr_id", intval($data['city_id']));
  44. }
  45. });
  46. $result = $resultWwhere->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 = $resultWwhere->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. }