WebsiteService.php 87 KB

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