WebsiteService.php 88 KB

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