WebsiteService.php 90 KB

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