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