WebsiteService.php 72 KB

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