WebsiteService.php 87 KB

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