WebsiteService.php 97 KB

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