WebsiteService.php 97 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523
  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. ->whereRaw('JSON_CONTAINS(category_arr_id,?)', [$data['pid']])
  588. ->orderBy('sort')
  589. ->select('*');
  590. $pid = $pidQuery->pluck('pid');
  591. $pid = array_values(array_unique($pid->toArray()));
  592. // 构建查询语句
  593. $query = WebsiteCategory::where($website_id)
  594. ->where('pid', $data['pid'])
  595. ->offset($data['placeid'])
  596. ->limit($data['num'])
  597. ->orderBy('sort');
  598. // 如果 $pid 数组不为空,添加 CASE WHEN 条件
  599. if (!empty($pid)) {
  600. $placeholders = implode(',', array_fill(0, count($pid), '?'));
  601. $query->selectRaw("website_category.*, CASE WHEN website_category.category_id IN ($placeholders) THEN 1 ELSE 0 END AS children_count", $pid);
  602. } else {
  603. // 如果 $pid 数组为空,不添加 CASE WHEN 条件,添加字段 children_count 并赋值为 0
  604. $query->select('website_category.*', DB::raw('0 as children_count'));
  605. }
  606. // $child = Result::buildMenuTree($child);
  607. $placeid = $data['placeid']-1;
  608. $result = $query->offset($placeid)->limit($data['num'])->get();
  609. if (!empty($result)) {
  610. $pidResults = $pidQuery->get();
  611. if(!isset($data['type']) || empty($data['type'])){
  612. $pidMap = $pidResults->keyBy('pid');
  613. $result->each(function ($record) use ($pidMap) {
  614. if ($pidMap->has($record->category_id)) {
  615. $pidResult = $pidMap->get($record->category_id);
  616. $record->chilid_id = $pidResult->category_id;
  617. $record->chilid_alias = $pidResult->alias;
  618. }
  619. });
  620. }else{
  621. $result = $result->map(function ($item) use ($pidResults) {
  622. $children = $pidResults->where('pid', $item->category_id)->map(function ($child) {
  623. if(!empty($child)){
  624. return $child;
  625. }
  626. });
  627. // 重置索引,使 key 值从 0 开始
  628. $item->children = $children->values();
  629. return $item;
  630. });
  631. }
  632. return Result::success($result);
  633. } else {
  634. return Result::error("本网站暂无栏目", 0);
  635. }
  636. }
  637. /**
  638. * 获取友情链接
  639. * @param array $data
  640. * @return array
  641. */
  642. public function selectWebsiteLinks(array $data): array
  643. {
  644. $where = [
  645. 'website_id' => $data['website_id'],
  646. 'status' => 1,
  647. 'type' => $data['type'],
  648. ];
  649. $num = $data['num'];
  650. $result = Link::where($where)->orderBy('sort')->limit($num)->get();
  651. if (!empty($result)) {
  652. return Result::success($result);
  653. } else {
  654. return Result::error("本网站暂无此类型友情链接", 0);
  655. }
  656. }
  657. /**
  658. * 网站首页数据统计, 管理员
  659. * @return void
  660. */
  661. public function getAdminIndex(array $data): array
  662. {
  663. var_dump("用户类型:", $data['type_id']);
  664. switch ($data['type_id']) {
  665. case 4:
  666. $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;');
  667. $res = [];
  668. //查询已审核文章
  669. $user_id = $data['user_id'];
  670. $article = Article::where('status', 1)
  671. ->where('admin_user_id', $user_id)
  672. ->orderBy('updated_at', 'desc')
  673. ->limit(10)
  674. ->get();
  675. $res['letterOfComplaintList'] = $result;
  676. $res['article'] = $article;
  677. $res['article']['count'] = Article::whereNotIn('status', ['404'])->where('admin_user_id', $user_id)->count();
  678. $res['good']['count'] = Good::where([])->where('user_id', $user_id)->count();
  679. $res['book']['count'] = Book::where([])->where('user_id', $user_id)->count();
  680. $res['jobHunting']['count'] = JobHunting::where([])->where('user_id', $user_id)->count();
  681. $res['jobRecruiting']['count'] = JobRecruiting::where([])->where('user_id', $user_id)->count();
  682. $res['complaint']['count'] = Complaint::where([])->where('user_id', $user_id)->count();
  683. $res['notice']['count'] = Notice::where([])->where('user_id', $user_id)->count();
  684. //待审核数据
  685. $res['apply']['article'] = Article::where(['status' => 0])->where('admin_user_id', $user_id)->count(); //
  686. $res['apply']['good'] = Good::where(['status' => 1])->where('user_id', $user_id)->count();
  687. $res['apply']['book'] = Book::where(['status' => 1])->where('user_id', $user_id)->count();
  688. $res['apply']['jobHunting'] = JobHunting::where(['status' => 1])->where('user_id', $user_id)->count();
  689. $res['apply']['jobRecruiting'] = JobRecruiting::where(['status' => 0])->where('user_id', $user_id)->count();
  690. $res['apply']['complaint'] = Complaint::where(['status' => 1])->where('user_id', $user_id)->count();
  691. $res['apply']['notice'] = Notice::where(['status' => 1])->where('user_id', $user_id)->count();
  692. return Result::success($res);
  693. case 10000:
  694. $res = [];
  695. //网站
  696. $res['website']['count'] = 0;
  697. $res['website']['growth_rate'] = 0;
  698. //资讯
  699. $res['article']['count'] = 0;
  700. $res['article']['growth_rate'] = 0;
  701. //导航池
  702. $res['category']['count'] = 0;
  703. $res['category']['growth_rate'] = 0;
  704. //商品
  705. $res['good']['count'] = 0;
  706. $res['book']['count'] = 0;
  707. $res['jobHunting']['count'] = 0;
  708. $res['jobRecruiting']['count'] = 0;
  709. //近一月数据
  710. $res['monthArticle'] = [];
  711. //用户类型
  712. $res['userType'] = [];
  713. $res['website']['count'] = Website::where([])->count();
  714. $res['article']['count'] = Article::whereNotIn('status', ['404'])->count();
  715. $res['category']['count'] = Category::where([])->count();
  716. $res['good']['count'] = Good::where([])->count();
  717. $res['book']['count'] = Book::where([])->count();
  718. $res['jobHunting']['count'] = JobHunting::where([])->count();
  719. $res['jobRecruiting']['count'] = JobRecruiting::where([])->count();
  720. $res['complaint']['count'] = Complaint::where([])->count();
  721. $res['notice']['count'] = Notice::where([])->count();
  722. // $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;');
  723. $res['monthArticle'] = Db::select(' SELECT DATE(article.created_at) AS date,COUNT(*) AS count ,user.type_id FROM article left JOIN user on article.admin_user_id = user.id WHERE article.created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(article.created_at),`user`.type_id ORDER BY date ASC');
  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 good.created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(good.created_at),`user`.type_id ORDER BY date ASC');
  725. $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.created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(book.created_at),`user`.type_id ORDER BY date ASC');
  726. $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.created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(job_hunting.created_at),`user`.type_id ORDER BY date ASC');
  727. $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.created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(job_recruiting.created_at),`user`.type_id ORDER BY date ASC');
  728. $res['userType'] = User::where([])->selectRaw("count(*) as counts,type_id")->groupBy('type_id')->get();
  729. //待审核数据
  730. $res['apply']['article'] = Article::where(['status' => 0])->count(); //
  731. $res['apply']['good'] = Good::where(['status' => 1])->count();
  732. $res['apply']['book'] = Book::where(['status' => 1])->count();
  733. $res['apply']['jobHunting'] = JobHunting::where(['status' => 1])->count();
  734. $res['apply']['jobRecruiting'] = JobRecruiting::where(['status' => 0])->count();
  735. $res['apply']['complaint'] = Complaint::where(['status' => 1])->count();
  736. $res['apply']['notice'] = Notice::where(['status' => 1])->count(); //订单状态:1:通过;2:驳回;3:撤回;4:修改;5:过期;6:待审核;7:结束',
  737. $res['apply']['order'] = Order::where(['status' => 6])->count();
  738. return Result::success($res);
  739. case 1:
  740. case 2:
  741. case 3:
  742. $res = [];
  743. //查询已审核文章
  744. $user_id = $data['user_id'];
  745. $article = Article::where('status', 1)
  746. ->where('admin_user_id', $user_id)
  747. ->orderBy('updated_at', 'desc')
  748. ->limit(10)
  749. ->get();
  750. $res['article'] = $article;
  751. $res['article']['count'] = Article::whereNotIn('status', ['404'])->where('admin_user_id', $user_id)->count();
  752. $res['good']['count'] = Good::where([])->where('user_id', $user_id)->count();
  753. $res['book']['count'] = Book::where([])->where('user_id', $user_id)->count();
  754. $res['jobHunting']['count'] = JobHunting::where([])->where('user_id', $user_id)->count();
  755. $res['jobRecruiting']['count'] = JobRecruiting::where([])->where('user_id', $user_id)->count();
  756. $res['complaint']['count'] = Complaint::where([])->where('user_id', $user_id)->count();
  757. $res['notice']['count'] = Notice::where([])->where('user_id', $user_id)->count();
  758. //待审核数据
  759. $res['apply']['article'] = Article::where(['status' => 0])->where('admin_user_id', $user_id)->count(); //
  760. $res['apply']['good'] = Good::where(['status' => 1])->where('user_id', $user_id)->count();
  761. $res['apply']['book'] = Book::where(['status' => 1])->where('user_id', $user_id)->count();
  762. $res['apply']['jobHunting'] = JobHunting::where(['status' => 1])->where('user_id', $user_id)->count();
  763. $res['apply']['jobRecruiting'] = JobRecruiting::where(['status' => 0])->where('user_id', $user_id)->count();
  764. $res['apply']['complaint'] = Complaint::where(['status' => 1])->where('user_id', $user_id)->count();
  765. $res['apply']['notice'] = Notice::where(['status' => 1])->where('user_id', $user_id)->count();
  766. return Result::success($res);
  767. }
  768. return [];
  769. }
  770. /**
  771. * 获取模板类型
  772. * @return void
  773. */
  774. public function getTemplateClass(array $data): array
  775. {
  776. $where = [];
  777. if (isset($data['name']) && $data['name']) {
  778. array_push($where, ['name', 'like', '%' . $data['name'] . '%']);
  779. }
  780. $result = TemplateClass::where($where)->orderBy('sort', 'asc')->get();
  781. if (empty($result)) {
  782. return Result::error("没有模板类型", 0);
  783. } else {
  784. return Result::success($result);
  785. }
  786. }
  787. /**
  788. * 添加模板类型
  789. * @param
  790. * @return void
  791. */
  792. public function addTemplateClass(array $data): array
  793. {
  794. $insertData = [
  795. 'name' => $data['name'],
  796. ];
  797. $result = TemplateClass::insertGetId($insertData);
  798. if (empty($result)) {
  799. return Result::error("创建失败", 0);
  800. } else {
  801. return Result::success(["id" => $result]);
  802. }
  803. }
  804. /**
  805. * 更新模板
  806. * @param array $data
  807. * @return array
  808. */
  809. public function upTemplateClass(array $data): array
  810. {
  811. $where = [
  812. 'id' => $data['id'],
  813. ];
  814. $insertData = [
  815. 'name' => $data['name'],
  816. ];
  817. $result = TemplateClass::where($where)->update($insertData);
  818. if (empty($result)) {
  819. return Result::error("更新失败", 0);
  820. } else {
  821. return Result::success();
  822. }
  823. }
  824. /**
  825. * 删除模板
  826. * @param array $data
  827. * @return array
  828. */
  829. public function delTemplateClass(array $data): array
  830. {
  831. $where = [
  832. 'id' => $data['id'],
  833. ];
  834. $result = TemplateClass::where($where)->delete();
  835. if (empty($result)) {
  836. return Result::error("删除失败", 0);
  837. } else {
  838. return Result::success();
  839. }
  840. }
  841. /**
  842. * 获取分类下的模板
  843. * @param array $data
  844. * @return array
  845. */
  846. public function getTemplate(array $data): array
  847. {
  848. $page = $data['page'];
  849. $pageSize = $data['pageSize'];
  850. $where = [];
  851. if (isset($data['template_class_id']) && $data['template_class_id']) {
  852. array_push($where, ['template_class_id', '=', $data['template_class_id']]);
  853. }
  854. $result = Template::where($where)
  855. ->limit($pageSize)->offset(($page - 1) * $pageSize)->get();
  856. $count = Template::where($where)->count();
  857. if (empty($result)) {
  858. return Result::error("没有数据", 0);
  859. }
  860. $data = [
  861. 'rows' => $result->toArray(),
  862. 'count' => $count,
  863. ];
  864. return Result::success($data);
  865. }
  866. /**
  867. * 创建模板
  868. * @param
  869. * @return void
  870. */
  871. public function addTemplate(array $data): array
  872. {
  873. $insertData = [
  874. 'template_name' => $data['template_name'],
  875. 'template_img' => json_encode($data['template_img']),
  876. 'template_class_id' => $data['template_class_id'],
  877. ];
  878. $result = Template::insertGetId($insertData);
  879. if (empty($result)) {
  880. return Result::error("创建模板失败", 0);
  881. } else {
  882. return Result::success(["id" => $result]);
  883. }
  884. }
  885. /**
  886. * 更新模板
  887. * @param array $data
  888. * @return array
  889. */
  890. public function upTemplate(array $data): array
  891. {
  892. $where = [
  893. 'id' => $data['id'],
  894. ];
  895. $insertData = [
  896. 'template_name' => $data['template_name'],
  897. 'template_img' => json_encode($data['template_img']),
  898. 'template_class_id' => $data['template_class_id'],
  899. ];
  900. $result = Template::where($where)->update($insertData);
  901. if (empty($result)) {
  902. return Result::error("更新模板失败", 0);
  903. } else {
  904. return Result::success();
  905. }
  906. }
  907. /**
  908. * 删除模板
  909. * @param array $data
  910. * @return array
  911. */
  912. public function delTemplate(array $data): array
  913. {
  914. $where = [
  915. 'id' => $data['id'],
  916. ];
  917. $result = Template::where($where)->delete();
  918. if (empty($result)) {
  919. return Result::error("删除模板失败", 0);
  920. } else {
  921. return Result::success();
  922. }
  923. }
  924. /**
  925. * 搜索网站
  926. * @param array $data
  927. * @return array
  928. */
  929. public function websiteList(array $data): array
  930. {
  931. $where = [];
  932. if (isset($data['keyword']) && !empty($data['keyword'])) {
  933. array_push($where, ['website.website_name', 'like', '%' . $data['keyword'] . '%']);
  934. }
  935. $result = Website::where($where)->get();
  936. if ($result) {
  937. return Result::success($result);
  938. } else {
  939. return Result::error("没有网站", 0);
  940. }
  941. }
  942. public function addWebsiteCategory(array $data): array
  943. {
  944. $website_id = $data['website_id'];
  945. $category_arr_id = $data['category_arr_id'];
  946. $categoryList = Category::whereIn('id', $category_arr_id)->get();
  947. $categoryListIds = [];
  948. if ($categoryList) {
  949. foreach ($categoryList->toArray() as $val) {
  950. array_push($categoryListIds, $val['id']);
  951. }
  952. }
  953. $arr = [];
  954. if ($categoryListIds) {
  955. foreach ($categoryListIds as $v) {
  956. $ids = $this->getUnderlingUIds(intval($v));
  957. $ids_arr = explode(",", $ids);
  958. array_push($arr, $ids_arr);
  959. }
  960. }
  961. $mergedArray = [];
  962. foreach ($arr as $subarray) {
  963. $mergedArray = array_merge($mergedArray, $subarray);
  964. }
  965. var_dump("所有:", $arr, $mergedArray);
  966. //查询出所有的分类进行分割插入 组装数据
  967. $categoryListData = Category::whereIn('id', $mergedArray)->get();
  968. $categoryListData = $categoryListData->toArray();
  969. $insertData = [];
  970. if ($categoryListData) {
  971. foreach ($categoryListData as $key => $value) {
  972. $insertData[$key]['website_id'] = $website_id;
  973. $insertData[$key]['name'] = $value['name'];
  974. $insertData[$key]['sort'] = $value['sort'];
  975. $insertData[$key]['pid'] = $value['pid'];
  976. $insertData[$key]['pid_arr'] = $value['pid_arr'];
  977. $insertData[$key]['seo_title'] = $value['seo_title'];
  978. $insertData[$key]['seo_keywords'] = $value['seo_keywords'];
  979. $insertData[$key]['seo_description'] = $value['seo_description'];
  980. $insertData[$key]['alias'] = $value['name'];
  981. $insertData[$key]['category_id'] = $value['id'];
  982. }
  983. }
  984. $result = WebsiteCategory::insert($insertData);
  985. var_dump("插入数据状态:", $result);
  986. if ($result) {
  987. return Result::success($result);
  988. } else {
  989. return Result::error("创建失败", 0);
  990. }
  991. }
  992. /**
  993. * 删除网站导航
  994. * @param array $data
  995. * @return array
  996. */
  997. public function delWebsiteCategory(array $data): array
  998. {
  999. $website_id = $data['website_id'] ?? 0;
  1000. $category_id = $data['category_id'] ?? 0;
  1001. $ids = $this->getUnderlingUIds(intval($category_id));
  1002. $ids_arr = explode(",", $ids);
  1003. $result = WebsiteCategory::where(['website_id' => $website_id])->whereIn("category_id", $ids_arr)->delete();
  1004. if ($result) {
  1005. return Result::success($result);
  1006. } else {
  1007. return Result::error("删除失败", 0);
  1008. }
  1009. }
  1010. /**
  1011. * 获取网站导航
  1012. * @param array $data
  1013. * @return array
  1014. */
  1015. public function getAdminWebsiteCategory(array $data): array
  1016. {
  1017. $where = [
  1018. 'website_id' => $data['website_id'],
  1019. ];
  1020. $result = WebsiteCategory::where($where)->orderBy('sort', 'asc')->get();
  1021. $list = [];
  1022. if ($result) {
  1023. foreach ($result->toArray() as $val) {
  1024. array_push($list, json_decode($val['category_arr_id']));
  1025. }
  1026. }
  1027. if ($result) {
  1028. return Result::success($list);
  1029. } else {
  1030. return Result::error("查询失败", 0);
  1031. }
  1032. }
  1033. /**
  1034. * 更新网站导航
  1035. * @param array $data
  1036. * @return array
  1037. */
  1038. public function upWebsiteCategory(array $data): array
  1039. {
  1040. $pinyin = new Pinyin();
  1041. Db::beginTransaction();
  1042. try {
  1043. if (!empty($data['category_arr_id'])) {
  1044. $websiteId = $data['website_id'];
  1045. // 1. 获取旧的 category_id 列表
  1046. $oldCategoryListIds = WebsiteCategory::where('website_id', $websiteId)->pluck('category_id')->toArray();
  1047. // 2. 获取新的 category_id 列表(去重)
  1048. $newCategoryListIds = [];
  1049. foreach ($data['category_arr_id'] as $arr) {
  1050. $lastId = end($arr);
  1051. $newCategoryListIds[] = $lastId;
  1052. }
  1053. $newCategoryListIds = array_unique($newCategoryListIds);
  1054. // 3. 需要删除的 category_id
  1055. $toDelete = array_diff($oldCategoryListIds, $newCategoryListIds);
  1056. if (!empty($toDelete)) {
  1057. WebsiteCategory::where('website_id', $websiteId)
  1058. ->whereIn('category_id', $toDelete)
  1059. ->delete();
  1060. }
  1061. // 4. 批量查出所有需要的 category 信息
  1062. $categories = Category::whereIn('id', $newCategoryListIds)->get()->keyBy('id');
  1063. // 5. 组装 upsertData,确保 category_id 不重复
  1064. $upsertData = [];
  1065. $handledCategoryIds = [];
  1066. foreach ($data['category_arr_id'] as $arr) {
  1067. $categoryId = end($arr);
  1068. if (!isset($categories[$categoryId]) || in_array($categoryId, $handledCategoryIds)) continue;
  1069. $info = $categories[$categoryId];
  1070. $aLIas_pinyin = $pinyin->permalink($info->name, '');
  1071. $upsertData[] = [
  1072. 'website_id' => $websiteId,
  1073. 'category_id' => $categoryId,
  1074. 'name' => $info->name ?? '',
  1075. 'alias' => $info->name ?? '',
  1076. 'aLIas_pinyin' => $aLIas_pinyin ?? '',
  1077. 'sort' => $info->sort ?? 0,
  1078. 'pid' => $info->pid ?? 0,
  1079. 'pid_arr' => $info->pid_arr ?? json_encode([]),
  1080. 'seo_title' => $info->seo_title ?? "",
  1081. 'seo_keywords' => $info->seo_keywords ?? "",
  1082. 'seo_description' => $info->seo_description ?? "",
  1083. 'is_url' => $info->is_url ?? 0,
  1084. 'web_url' => $info->web_url ?? '',
  1085. 'type' => $info->type ?? 1,
  1086. 'category_arr_id' => json_encode($arr)
  1087. ];
  1088. $handledCategoryIds[] = $categoryId;
  1089. }
  1090. // 6. upsert
  1091. if (!empty($upsertData)) {
  1092. WebsiteCategory::upsert(
  1093. $upsertData,
  1094. ['website_id', 'category_id'],
  1095. [
  1096. 'aLIas_pinyin',
  1097. 'pid',
  1098. 'pid_arr',
  1099. 'is_url',
  1100. 'web_url',
  1101. 'category_arr_id'
  1102. ]
  1103. );
  1104. }
  1105. }
  1106. Db::commit();
  1107. return Result::success();
  1108. } catch (\Throwable $ex) {
  1109. Db::rollBack();
  1110. return Result::error("修改失败" . $ex->getMessage(), 0);
  1111. }
  1112. }
  1113. /**
  1114. * 获取网站列表
  1115. * @param array $data
  1116. * @return array
  1117. */
  1118. public function getWebsiteCategoryList(array $data): array
  1119. {
  1120. $where = [];
  1121. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1122. array_push($where, ['website.website_name', 'like', '%' . $data['keyword'] . '%']);
  1123. }
  1124. if (isset($data['website_column_id']) && !empty($data['website_column_id'])) {
  1125. array_push($where, ['website.website_column_id', '=', $data['website_column_id']]);
  1126. }
  1127. $result = Website::where($where)
  1128. ->with(["websiteCategory" => function ($query) {
  1129. $query->where(['pid' => 0])->select('website_id', 'name', 'alias', 'category_id');
  1130. }])
  1131. ->limit($data['pageSize'])->orderBy("updated_at", "desc")->offset(($data['page'] - 1) * $data['pageSize'])
  1132. ->get();
  1133. $count = Website::where($where)->count();
  1134. if (empty($result)) {
  1135. return Result::error("没有数据", 0);
  1136. }
  1137. $data = [
  1138. 'rows' => $result->toArray(),
  1139. 'count' => $count,
  1140. ];
  1141. if ($result) {
  1142. return Result::success($data);
  1143. } else {
  1144. return Result::error("查询失败", 0);
  1145. }
  1146. }
  1147. /**
  1148. * 删除网站下的所有导航
  1149. * @param array $data
  1150. * @return array
  1151. */
  1152. public function delWebsiteAllCategory(array $data): array
  1153. {
  1154. $website_id = $data['website_id'];
  1155. $result = WebsiteCategory::where(['website_id' => $website_id])->delete();
  1156. if ($result) {
  1157. return Result::success($result);
  1158. } else {
  1159. return Result::error("删除失败", 0);
  1160. }
  1161. }
  1162. /**
  1163. * 获取网站下的某一个导航
  1164. * @param array $data
  1165. * @return array
  1166. */
  1167. public function getWebsiteCategoryOnes(array $data): array
  1168. {
  1169. $website_id = $data['website_id'];
  1170. $category_id = $data['category_id'];
  1171. $result = WebsiteCategory::where(['website_category.website_id' => $website_id, 'website_category.category_id' => $category_id])
  1172. ->first();
  1173. if ($result) {
  1174. return Result::success($result);
  1175. } else {
  1176. return Result::error("查询失败", 0);
  1177. }
  1178. }
  1179. /**
  1180. * 更新网闸下的某一个导航
  1181. * @param array $data
  1182. * @return array
  1183. */
  1184. public function upWebsiteCategoryones(array $data): array
  1185. {
  1186. //处理所有数据
  1187. //获取所有数据
  1188. if (isset($data['all']) && $data['all'] == 'all') {
  1189. $result = WebsiteCategory::get();
  1190. $result = $result->toArray();
  1191. var_dump($result, '------------');
  1192. $pinyin = new Pinyin();
  1193. $letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  1194. for ($i = 0; $i < count($result); $i++) {
  1195. // $randss = substr(str_shuffle($letters), 0, 4);
  1196. $result[$i]['aLIas_pinyin'] = $pinyin->permalink($result[$i]['alias'], '');
  1197. WebsiteCategory::where(['id' => $result[$i]['id']])->update(['aLIas_pinyin' => $result[$i]['aLIas_pinyin']]);
  1198. }
  1199. var_dump($result, '--------222----');
  1200. if ($result) {
  1201. return Result::success($result);
  1202. } else {
  1203. return Result::error("更新失败", 0);
  1204. }
  1205. }
  1206. //处理所有数据
  1207. $where = [
  1208. 'website_id' => $data['website_id'],
  1209. 'category_id' => $data['category_id'],
  1210. ];
  1211. $alias = $data['alias'];
  1212. $pinyin = new Pinyin();
  1213. $aLIas_pinyin = $pinyin->permalink($alias, '');
  1214. //从WebsiteCategory取出alis ,并转成拼音存放到aLIas_pinyin
  1215. $result = WebsiteCategory::where($where)->first();
  1216. $result = $result->toArray();
  1217. //+四位随机字母
  1218. $letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  1219. // 打乱字符串顺序并截取前四位
  1220. // $randss = substr(str_shuffle($letters), 0, 4);
  1221. if ($data['alias_pinyin'] == '') {
  1222. $data['aLIas_pinyin'] = $aLIas_pinyin;
  1223. }
  1224. $result = WebsiteCategory::where($where)->update($data);
  1225. if ($result) {
  1226. return Result::success($result);
  1227. } else {
  1228. return Result::error("更新失败", 0);
  1229. }
  1230. }
  1231. /**
  1232. * 获取网站下的所有导航(包含子导航)
  1233. * @param array $data
  1234. * @return array
  1235. */
  1236. public function getWebsiteAllCategory(array $data): array
  1237. {
  1238. $where = [];
  1239. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1240. array_push($where, ['website_category.website_id', '=', $data['website_id']]);
  1241. }
  1242. // if (isset($data['name']) && !empty($data['name'])) {
  1243. // array_push($where, ['website_category.name', 'like', '%' . $data['name'] . '%']);
  1244. // }
  1245. // if (isset($data['alias']) && !empty($data['alias'])) {
  1246. // array_push($where, ['website_category.alias', 'like', '%' . $data['alias'] . '%']);
  1247. // }
  1248. // if (isset($data['department_id']) && !empty($data['department_id'])) {
  1249. // array_push($where, ['category.department_id', '=', $data['department_id']]);
  1250. // }
  1251. // if (isset($data['city_id']) && !empty($data['city_id'])) {
  1252. // array_push($where, ['category.city_id', '=', $data['city_id']]);
  1253. // }
  1254. $result = WebsiteCategory::where($where)
  1255. ->leftJoin("category", 'website_category.category_id', 'category.id')
  1256. ->select("website_category.*", "category.name as name")
  1257. // ->leftJoin("category", 'website_category.category_id', 'category.id')
  1258. // ->leftJoin("department", 'category.department_id', 'department.id')
  1259. // ->leftJoin("district", 'category.city_id', 'district.id')
  1260. // ->select("website_category.*", "department.name as department_name", "district.name as city_name")
  1261. // ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])
  1262. ->orderBy("sort", "asc")
  1263. ->get();
  1264. // $count = WebsiteCategory::where($where)
  1265. // ->leftJoin("category", 'website_category.category_id', 'category.id')
  1266. // ->leftJoin("department", 'category.department_id', 'department.id')
  1267. // ->leftJoin("district", 'category.city_id', 'district.id')
  1268. // ->count();
  1269. if (empty($result)) {
  1270. return Result::error("没有数据", 0);
  1271. }
  1272. // $data = [
  1273. // 'rows' => $result->toArray(),
  1274. // 'count' => $count,
  1275. // ];
  1276. if ($result) {
  1277. return Result::success($result->toArray());
  1278. } else {
  1279. return Result::error("查询失败", 0);
  1280. }
  1281. }
  1282. /**
  1283. * 递归查询数据
  1284. * @param $id
  1285. * @param $ids
  1286. * @return string
  1287. */
  1288. public function getUnderlingUIds($id, $ids = '')
  1289. {
  1290. $back = Category::where(['pid' => $id])->get();
  1291. $back = $back->toArray();
  1292. if (!empty($back) && is_array($back)) {
  1293. foreach ($back as $v) {
  1294. //防止当前人的ID重复去查询,形成恶性循环
  1295. if ($v['id'] == $id) {
  1296. continue;
  1297. }
  1298. $back2 = Category::where(['pid' => $id])->count('id');
  1299. if ($back2 > 0) {
  1300. $ids = $this->getUnderlingUIds($v['id'], $ids);
  1301. } else {
  1302. $ids .= ',' . $v['id'];
  1303. }
  1304. }
  1305. }
  1306. $ids = $id . ',' . $ids . ',';
  1307. $ids = str_replace(',,', ",", $ids);
  1308. $ids = trim($ids, ',');
  1309. return $ids;
  1310. }
  1311. /**
  1312. * 检测网站名称是否重复
  1313. * @param array $data
  1314. * @return array
  1315. */
  1316. public function checkWebsiteName(array $data): array
  1317. {
  1318. if (isset($data['id'])) {
  1319. $data[] = ['id', "!=", $data['id']];
  1320. unset($data['id']);
  1321. }
  1322. $websiteInfo = Website::query()->where($data)->first();
  1323. if (empty($websiteInfo)) {
  1324. return Result::error("找不到网站", 0);
  1325. }
  1326. return Result::success($websiteInfo->toArray());
  1327. }
  1328. /**
  1329. * 检测网站url是否重复
  1330. * @param array $data
  1331. * @return array
  1332. */
  1333. public function checkWebsiteUrl(array $data): array
  1334. {
  1335. $whereData = [];
  1336. if (isset($data['id'])) {
  1337. $whereData = [['id', "!=", $data['id']]];
  1338. unset($data['id']);
  1339. }
  1340. $websiteInfo = Website::query()->where($whereData)->whereJsonContains('website_url', $data['website_url'])->first();
  1341. if (empty($websiteInfo)) {
  1342. return Result::error("找不到URL", 0);
  1343. }
  1344. return Result::success($websiteInfo->toArray());
  1345. }
  1346. /**
  1347. * 获取网站底部基础信息
  1348. * @param array $data
  1349. * @return array
  1350. */
  1351. public function getWebsiteFootInfo(array $data): array
  1352. {
  1353. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1354. $website_head = Website::where('id', $data['website_id'])
  1355. ->where('status', 1)
  1356. ->select('id', 'website_name', 'logo', 'title', 'keywords', 'description', 'suffix', 'website_url')
  1357. ->first();
  1358. if (empty($website_head)) {
  1359. return Result::error("找不到网站", 0);
  1360. }
  1361. } else {
  1362. return Result::error("参数错误", 0);
  1363. }
  1364. $website_head = Website::where('id', $data['website_id'])
  1365. ->select('id', 'website_name', 'logo', 'title', 'keywords', 'description', 'suffix', 'website_url')->first();
  1366. $website_foot = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1367. if (empty($website_foot)) {
  1368. return Result::error("暂无底部基础信息", 0);
  1369. }
  1370. $website_head['website_url'] = $website_head['website_url'] ? json_decode($website_head['website_url']) : [];
  1371. $result = [
  1372. 'website_foot' => $website_foot,
  1373. 'website_head' => $website_head,
  1374. ];
  1375. return Result::success($result);
  1376. }
  1377. /**
  1378. * 获取网站底部导航
  1379. * @param array $data
  1380. * @return array
  1381. */
  1382. public function getWebsiteFooterCategory(array $data): array
  1383. {
  1384. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1385. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1386. if (empty($website)) {
  1387. return Result::error("找不到网站", 0);
  1388. }
  1389. } else {
  1390. return Result::error("参数错误", 0);
  1391. }
  1392. $result = FooterCategory::where('website_id', $data['website_id'])->get();
  1393. if (empty($result)) {
  1394. return Result::error("暂无底部导航", 0);
  1395. }
  1396. return Result::success($result->toArray());
  1397. }
  1398. /**
  1399. * 获取网站底部导航列表
  1400. * @param array $data
  1401. * @return array
  1402. */
  1403. public function getWebsiteFooterCategoryList(array $data): array
  1404. {
  1405. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1406. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1407. if (empty($website)) {
  1408. return Result::error("找不到网站", 0);
  1409. }
  1410. } else {
  1411. return Result::error("参数错误", 0);
  1412. }
  1413. $footercategory = FooterCategory::where('website_id', $data['website_id'])->where('id', $data['fcat_id'])->first();
  1414. // '底部导航类型 0:内容型;1:列表型;',
  1415. if (!isset($footercategory['type']) || $footercategory['type'] == 0) {
  1416. return Result::error("底部导航id错误", 0);
  1417. } else {
  1418. $query = FooterContent::where('fcat_id', $data['fcat_id']);
  1419. if ($query->count() == 0) {
  1420. return Result::error("暂无底部导航列表", 0);
  1421. } elseif ($query->count() == 1) {
  1422. $result = $query->first();
  1423. } else {
  1424. $result = $query->get();
  1425. }
  1426. }
  1427. return Result::success($result);
  1428. }
  1429. /**
  1430. * 获取网站底部导航
  1431. * @param array $data
  1432. * @return array
  1433. */
  1434. public function getWebsiteFooterCategoryInfo(array $data): array
  1435. {
  1436. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1437. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1438. if (empty($website)) {
  1439. return Result::error("找不到网站", 0);
  1440. }
  1441. } else {
  1442. return Result::error("参数错误", 0);
  1443. }
  1444. if (isset($data['type']) && $data['type'] == 0) {
  1445. $fcatid = FooterCategory::where('website_id', $data['website_id'])->where('id', $data['fcat_id'])->first();
  1446. if (empty($fcatid)) {
  1447. return Result::error("底部导航id错误", 0);
  1448. }
  1449. $result = FooterContent::where('fcat_id', $data['fcat_id'])->first();
  1450. } else {
  1451. $result = FooterContent::where('id', $data['fcat_id'])->first();
  1452. }
  1453. if (empty($result)) {
  1454. return Result::error("暂无底部导航内容", 0);
  1455. }
  1456. return Result::success($result);
  1457. }
  1458. /*
  1459. * 搜索网站二级导航
  1460. * @param array $data
  1461. * @return array
  1462. * */
  1463. public function selectWebsiteCategory(array $data): array
  1464. {
  1465. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1466. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1467. if (empty($website)) {
  1468. return Result::error("暂无该网站", 0);
  1469. }
  1470. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id')->all();
  1471. // return Result::success($category);
  1472. if (empty($category)) {
  1473. return Result::error("暂无此导航", 0);
  1474. }
  1475. $query = Category::whereIn('id', $category);
  1476. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1477. $cityid = District::where('id', $data['cityid'])->first();
  1478. if (empty($cityid)) {
  1479. return Result::error("暂无此城市", 0);
  1480. } else {
  1481. $city_category = $query->whereRaw('JSON_CONTAINS(city_arr_id,?)', [$data['cityid']])->pluck('id');
  1482. // $where[] = ['JSON_CONTAINS(city_arr_id, ?)', $data['cityid']];
  1483. if (empty($city_category)) {
  1484. return Result::error("暂无此城市下的导航", 0);
  1485. }
  1486. $result['catid'] = $city_category;
  1487. $city = 1;
  1488. // var_dump("城市====================",$result);
  1489. }
  1490. }
  1491. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1492. $departmentid = Department::where('id', $data['department_id'])->first();
  1493. if (empty($departmentid)) {
  1494. return Result::error("暂无此部门", 0);
  1495. } else {
  1496. $depart_category = $query->whereRaw('JSON_CONTAINS(department_arr_id,?)', [$data['department_id']])->pluck('id');
  1497. if (empty($depart_category)) {
  1498. return Result::error("暂无此部门下的导航", 0);
  1499. }
  1500. $result['catid'] = $depart_category;
  1501. // var_dump("职能部门*******************",$result);
  1502. $department = 1;
  1503. }
  1504. }
  1505. if (!empty($city) && !empty($department)) {
  1506. // var_dump("城市和职能部门----------------------",$result);
  1507. $sel_category = $query->whereRaw('JSON_CONTAINS(city_arr_id,?)', [$data['cityid']])->whereRaw('JSON_CONTAINS(department_arr_id,?)', [$data['department_id']])->pluck('id');
  1508. if (empty($sel_category)) {
  1509. return Result::error("暂无此城市和职能部门下的导航", 0);
  1510. }
  1511. $result['catid'] = $sel_category;
  1512. }
  1513. if (empty($result)) {
  1514. return Result::error("暂无导航", 0);
  1515. }
  1516. // department_id
  1517. } else {
  1518. return Result::error("参数错误", 0);
  1519. }
  1520. return Result::success($result);
  1521. }
  1522. /**
  1523. * 获取网站栏目seo
  1524. * @param array $data
  1525. * @return array
  1526. */
  1527. public function getWebsiteCategoryHead(array $data): array
  1528. {
  1529. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1530. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1531. if (empty($website)) {
  1532. return Result::error("找不到网站", 0);
  1533. }
  1534. } else {
  1535. return Result::error("参数错误", 0);
  1536. }
  1537. if (isset($data['catid']) && !empty($data['catid'])) {
  1538. $result = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->first();
  1539. }
  1540. if (empty($result)) {
  1541. return Result::error("暂无导航", 0);
  1542. }
  1543. $result['website_name'] = $website['website_name'] ?? '';
  1544. $result['suffix'] = $website['suffix'] ?? '';
  1545. return Result::success($result);
  1546. }
  1547. /*
  1548. * 获取某个栏目
  1549. * @param array $data
  1550. * @return array
  1551. * */
  1552. public function getOneWebsiteCategory(array $data): array
  1553. {
  1554. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1555. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1556. if (empty($website)) {
  1557. return Result::error("暂无该网站", 0);
  1558. }
  1559. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['category_id'])->first();
  1560. if (empty($category)) {
  1561. return Result::error("暂无此导航", 0);
  1562. }
  1563. $category['children_count'] = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['category_id'])->count();
  1564. $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();
  1565. $category['parent_id'] = $parent['parent_id'] ?? '';
  1566. $category['parent_pinyin'] = $parent['aLIas_pinyin'] ?? '';
  1567. $category['parent_name'] = $parent['parent_name'] ?? '';
  1568. return Result::success($category);
  1569. } else {
  1570. return Result::error("参数错误", 0);
  1571. }
  1572. }
  1573. // 自助建站--fr-------------------
  1574. /**
  1575. * 获取并搜索 网站模板信息
  1576. * @param array $data
  1577. * @return array
  1578. */
  1579. public function getWebsiteintel(array $data): array
  1580. {
  1581. //查询所有网站模板信息
  1582. $query = Website::where('website.status', 1)
  1583. ->leftJoin("website_template_info", "website_template_info.website_id", "website.id")
  1584. ->leftJoin("template", "template.id", "website_template_info.template_id")
  1585. ->leftJoin("template_class", "template_class.id", "template.template_class_id")
  1586. ->select(
  1587. "website_template_info.id",
  1588. "template_class.name",
  1589. "website.id as website_id",
  1590. "website.website_name",
  1591. "website.website_url",
  1592. "website_template_info.action_id",
  1593. "website_template_info.created_at",
  1594. "website_template_info.updated_at",
  1595. "website_template_info.page_type",
  1596. DB::raw("COALESCE(website_template_info.status, 0) as template_status"),
  1597. "template.template_name"
  1598. );
  1599. //若存在条件;则在$query的基础上进行筛选
  1600. if (isset($data['website_name']) && !empty($data['website_name'])) {
  1601. $query->where('website.website_name', 'like', '%' . $data['website_name'] . '%');
  1602. }
  1603. if (isset($data['status']) && !empty($data['status'])) {
  1604. $query->where('website_template_info.status', $data['status']);
  1605. }
  1606. $count = $query->count();
  1607. $query->limit($data['pageSize'])
  1608. ->offset(($data['page'] - 1) * $data['pageSize'])
  1609. ->orderBy("website_template_info.updated_at", "desc");
  1610. $rep = $query->get();
  1611. if ($rep->count() == 0) {
  1612. return Result::error("没有查找到相关数据", 0);
  1613. } else {
  1614. $rep->each(function ($item) {
  1615. if (!empty($item->page_type)) {
  1616. $pageTypeArray = json_decode($item->page_type, true);
  1617. if (is_array($pageTypeArray)) {
  1618. $item->page_type = $pageTypeArray;
  1619. }
  1620. }
  1621. });
  1622. $result = [
  1623. "rows" => $rep->toArray(),
  1624. "count" => $count,
  1625. ];
  1626. return Result::success($result);
  1627. }
  1628. // return Result::success($result);
  1629. }
  1630. /**
  1631. * 添加网站基础信息
  1632. * @param array $data
  1633. * @return array
  1634. */
  1635. public function addWebsiteTemplateintel(array $data): array
  1636. {
  1637. $website = Website::where('website.id', $data['website_id'])->first();
  1638. if (empty($website)) {
  1639. return Result::error("请输入正确的网站id!", 0);
  1640. }
  1641. if (empty($website['website_column_id'])) {
  1642. return Result::error("请先关联导航池!", 0);
  1643. }
  1644. // 获取此网站的底部导航 类型 type: 0:内容型底部导航(只有一条详情内容);1:列表型底部导航(可以有多条详情内容)
  1645. $foot_type = FooterCategory::where('website_id', $data['website_id'])->pluck('type')->toArray();
  1646. if (empty($foot_type)) {
  1647. return Result::error("请先关联底部导航池!", 0);
  1648. } elseif (in_array(1, $foot_type)) {
  1649. $foot_type = 1;
  1650. } else {
  1651. $foot_type = 0;
  1652. }
  1653. $result['foot_type'] = $foot_type;
  1654. // 友情链接类型'1:图片 2:文字 3:底部';
  1655. $types = Link::where('website_id', $data['website_id'])->pluck('type')->toArray();
  1656. $missingTypes = [];
  1657. if (!in_array(1, $types)) {
  1658. $missingTypes[] = "文字链接";
  1659. }
  1660. if (!in_array(2, $types)) {
  1661. $missingTypes[] = "图片链接";
  1662. }
  1663. if (!in_array(3, $types)) {
  1664. $missingTypes[] = "底部链接";
  1665. }
  1666. if (!empty($missingTypes)) {
  1667. $errorMessage = "请先添加 " . implode(" 和 ", $missingTypes) . "!";
  1668. return Result::error($errorMessage, 0);
  1669. }
  1670. if (isset($data['page_type'])) {
  1671. // 删除重复元素并重新索引数组
  1672. $data['page_type'] = array_unique($data['page_type']);
  1673. $data['page_type'] = array_values($data['page_type']);
  1674. if (in_array(1, $data['page_type']) && in_array(7, $data['page_type'])) {
  1675. // 数组中同时包含值为 1(首页) 和值为 7 (底部导航详情页)的元素
  1676. $info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1677. if (empty($info)) {
  1678. // 将数组转换为 JSON 字符串
  1679. $data['page_type'] = json_encode($data['page_type']) ?? '';
  1680. // 操作状态:1:填写完成基础信息;2:选择完成模板;0:未构建
  1681. $data['action_id'] = 1;
  1682. try {
  1683. $result = WebsiteTemplateInfo::insertGetId($data);
  1684. } catch (\Exception $e) {
  1685. if ($e->getCode() == 22001) {
  1686. $errorMessage = $e->getMessage();
  1687. return Result::error("请检查表单,某个字段超出了长度限制!");
  1688. } else {
  1689. // 处理其他类型的数据库错误
  1690. return Result::error("插入操作失败: " . $e->getMessage());
  1691. }
  1692. return Result::error("添加失败!", 0);
  1693. }
  1694. } else {
  1695. return Result::error("该网站已经构建过了!", 0);
  1696. }
  1697. } else {
  1698. return Result::error("请先选择首页和底部导航详情页!", 0);
  1699. }
  1700. }
  1701. if (empty($result)) {
  1702. return Result::error("添加失败!", 0);
  1703. } else {
  1704. return Result::success($result);
  1705. }
  1706. }
  1707. /**
  1708. * 获取网站基础信息
  1709. *
  1710. * @return array
  1711. */
  1712. public function getWebsiteTemplateintel(array $data): array
  1713. {
  1714. $result = WebsiteTemplateInfo::where('website_template_info.website_id', $data['website_id'])
  1715. ->leftJoin('footer_category', 'footer_category.website_id', 'website_template_info.website_id')
  1716. ->leftJoin('website', 'website.id', 'website_template_info.website_id')
  1717. ->select(
  1718. "website_template_info.*",
  1719. "footer_category.type",
  1720. "website.website_name",
  1721. "website.id as website_id"
  1722. )
  1723. ->first();
  1724. if (empty($result['website_name'])) {
  1725. return Result::error("请输入正确的网站id!", 0);
  1726. }
  1727. if ($result) {
  1728. $result['page_type'] = json_decode($result['page_type'], true);
  1729. return Result::success($result);
  1730. } else {
  1731. return Result::error("请先添加网站基础信息!", 0);
  1732. }
  1733. }
  1734. /**
  1735. * 修改网站基础信息
  1736. *
  1737. * @return array
  1738. */
  1739. public function upWebsiteTemplateintel(array $data): array
  1740. {
  1741. $web = Website::where('website.id', $data['website_id'])->first();
  1742. if (empty($web)) {
  1743. return Result::error("请输入正确的网站id!", 0);
  1744. }
  1745. $where = ['website_id' => $data['website_id']];
  1746. $result = WebsiteTemplateInfo::where($where)->first();
  1747. if (empty($result)) {
  1748. return Result::error("请先添加网站基础信息!", 0);
  1749. } else {
  1750. unset($data['website_id']);
  1751. // 删除重复元素
  1752. $data['page_type'] = array_unique($data['page_type']);
  1753. // 重新索引数组
  1754. $data['page_type'] = array_values($data['page_type']);
  1755. // 数组中同时包含值为 1(首页) 和值为 7 (底部导航详情页)的元素
  1756. if (in_array(1, $data['page_type']) && in_array(7, $data['page_type'])) {
  1757. // 将数组转换为 JSON 字符串
  1758. $data['page_type'] = json_encode($data['page_type']) ?? '';
  1759. try {
  1760. $result = WebsiteTemplateInfo::where($where)->update($data);
  1761. } catch (\Exception $e) {
  1762. if ($e->getCode() == 22001) {
  1763. $errorMessage = $e->getMessage();
  1764. return Result::error("请检查表单,某个字段超出了长度限制!");
  1765. } else {
  1766. // 处理其他类型的数据库错误
  1767. return Result::error("修改操作失败: " . $e->getMessage());
  1768. }
  1769. return Result::error("修改失败!", 0);
  1770. }
  1771. } else {
  1772. return Result::error("请先选择首页和底部导航详情页!", 0);
  1773. }
  1774. }
  1775. if (empty($result)) {
  1776. return Result::error("修改失败!", 0);
  1777. } else {
  1778. return Result::success($result);
  1779. }
  1780. }
  1781. /**
  1782. * 获取所有网站风格信息
  1783. *
  1784. * @return array
  1785. */
  1786. public function getAllTemplateClass(array $data): array
  1787. {
  1788. $result = TemplateClass::all();
  1789. if (empty($result)) {
  1790. return Result::error("没有查找到相关数据!", 0);
  1791. } else {
  1792. return Result::success($result);
  1793. }
  1794. }
  1795. /**
  1796. * 搜索并获取网站模板信息
  1797. * @param array $data
  1798. * @return array
  1799. */
  1800. public function getWebsiteTemplateList(array $data): array
  1801. {
  1802. $website = Website::where('website.id', $data['website_id'])->first();
  1803. if (empty($website)) {
  1804. return Result::error("请输入正确的网站id!", 0);
  1805. } else {
  1806. $page_type = WebsiteTemplateInfo::where('website_id', $data['website_id'])->select('page_type')->first();
  1807. if (empty($page_type)) {
  1808. return Result::error("此网站还未添加基础信息!", 0);
  1809. } else {
  1810. $where = json_decode($page_type['page_type'], true);
  1811. // $where = $data["page_type"];
  1812. if (isset($data['template_class_id']) && !empty($data['template_class_id'])) {
  1813. $template_class = TemplateClass::where('id', $data['template_class_id'])->first();
  1814. if (empty($template_class)) {
  1815. return Result::error("请输入正确的模板风格id!", 0);
  1816. } else {
  1817. // 获取指定风格下的模板
  1818. $rep = Template::where('template_class_id', $data['template_class_id'])
  1819. ->where(function ($query) use ($where) {
  1820. foreach ($where as $value) {
  1821. $query->whereJsonContains('template_img', ['value' => $value]);
  1822. }
  1823. })
  1824. ->limit($data['pageSize'])
  1825. ->offset(($data['page'] - 1) * $data['pageSize'])
  1826. ->orderBy("template.updated_at", "desc")
  1827. ->get();
  1828. $count = Template::where('template_class_id', $data['template_class_id'])
  1829. ->where(function ($query) use ($where) {
  1830. foreach ($where as $value) {
  1831. $query->whereJsonContains('template_img', ['value' => $value]);
  1832. }
  1833. })->count();
  1834. }
  1835. } else {
  1836. //获取所有模板
  1837. $rep = Template::where(function ($query) use ($where) {
  1838. foreach ($where as $value) {
  1839. $query->whereJsonContains('template_img', ['value' => $value]);
  1840. }
  1841. })
  1842. ->limit($data['pageSize'])
  1843. ->offset(($data['page'] - 1) * $data['pageSize'])
  1844. ->orderBy("template.updated_at", "desc")
  1845. ->get();
  1846. $count = Template::where(function ($query) use ($where) {
  1847. foreach ($where as $value) {
  1848. $query->whereJsonContains('template_img', ['value' => $value]);
  1849. }
  1850. })->count();
  1851. }
  1852. if (empty($rep) || $rep->count() == 0) {
  1853. return Result::error("没有查找到相关数据!", 0);
  1854. } else {
  1855. // 过滤 template_img 字段 只获取 基础信息中 包含的模板图片
  1856. // $rep->each(function ($item) use ($where) {
  1857. // $template_img = json_decode($item->template_img, true);
  1858. // if(is_array($template_img)){
  1859. // $filtered_img = array_filter($template_img, function ($img) use ($where) {
  1860. // return isset($img['value']) && in_array($img['value'], $where);
  1861. // });
  1862. // }
  1863. // $item->template_img = $filtered_img;
  1864. // });
  1865. // $result = [
  1866. // "rows" => $rep->toArray(),
  1867. // "count" => $count
  1868. // ];
  1869. $rep->each(function ($item) use ($where) {
  1870. $template_img = json_decode($item->template_img, true);
  1871. if (is_array($template_img)) {
  1872. $filtered_img = array_filter($template_img, function ($img) use ($where) {
  1873. return isset($img['value']) && in_array($img['value'], $where);
  1874. });
  1875. // 对过滤后的数组进行重新排序
  1876. $sorted_img = array_values($filtered_img);
  1877. $item->template_img = $sorted_img;
  1878. } else {
  1879. $item->template_img = []; // 如果无法解码为数组,则设置为空数组
  1880. }
  1881. });
  1882. $result = [
  1883. "rows" => $rep->toArray(),
  1884. "count" => $count,
  1885. ];
  1886. }
  1887. }
  1888. }
  1889. return Result::success($result);
  1890. }
  1891. /**
  1892. * 添加网站模板
  1893. * @param array $data
  1894. */
  1895. public function addWebsiteTemplateclassintel(array $data): array
  1896. {
  1897. $template = Template::where('id', $data['template_id'])->first();
  1898. $web = Website::where('id', $data['website_id'])->first();
  1899. if (empty($template)) {
  1900. return Result::error("请输入正确的模板id", 0);
  1901. }
  1902. if (empty($web)) {
  1903. return Result::error("请输入正确的网站id", 0);
  1904. }
  1905. $result = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['template_id' => $data['template_id'], 'action_id' => 2]);
  1906. if (empty($result)) {
  1907. return Result::error("添加失败", 0);
  1908. } else {
  1909. return Result::success($result);
  1910. }
  1911. }
  1912. /**
  1913. * 获取网站模板信息
  1914. * @param array $data
  1915. */
  1916. public function getWebsiteTemplateclassintel(array $data): array
  1917. {
  1918. // return Result::success($data);
  1919. $template = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1920. if (empty($template)) {
  1921. return Result::error("请输入正确的搭建网站id", 0);
  1922. }
  1923. $page_type = json_decode($template['page_type'], true);
  1924. // 获取指定网站下的基础信息和模板及风格信息
  1925. $result = WebsiteTemplateInfo::where([
  1926. ['website_template_info.website_id', $data['website_id']],
  1927. ['template_id', '!=', null],
  1928. ])
  1929. ->leftJoin('template', 'template.id', 'website_template_info.template_id')
  1930. ->leftJoin('template_class', 'template_class.id', 'template.template_class_id')
  1931. ->where(function ($query) use ($page_type) {
  1932. // 假设 $data['page_type'] 是一个数组,包含需要匹配的 page_type 值
  1933. foreach ($page_type as $pageType) {
  1934. $query->orWhereJsonContains('template.template_img', ['value' => $pageType]);
  1935. }
  1936. })
  1937. ->select(
  1938. 'template.template_name',
  1939. 'template.template_img',
  1940. 'template.id as tid',
  1941. 'template_class.name',
  1942. 'template_class.id as class_id',
  1943. 'website_template_info.page_type',
  1944. 'website_template_info.website_id'
  1945. )
  1946. ->first();
  1947. if (empty($result)) {
  1948. return Result::error("没有查找到相关数据", 0);
  1949. }
  1950. // return Result::success($result);
  1951. // 过滤 template_img 字段 只获取 基础信息中 包含的模板图片
  1952. $template_img = $result['template_img'] !== null ? json_decode($result['template_img'], true) : [];
  1953. $page_type = $result['page_type'] !== null ? json_decode($result['page_type'], true) : [];
  1954. foreach ($template_img as $key => $value) {
  1955. if (!in_array($value['value'], $page_type)) {
  1956. unset($template_img[$key]);
  1957. }
  1958. }
  1959. // return Result::success($result);
  1960. $result['template_img'] = array_values($template_img);
  1961. $result['page_type'] = $page_type;
  1962. // $templateList = $this->getWebsiteTemplateList($data);
  1963. // $count = $templateList['data']['count']??'';
  1964. // $pages = $count / $data['pageSize'];
  1965. // $found = false;
  1966. // while ($pages && !$found) {
  1967. // $templates = $this->getWebsiteTemplateList($pages,$data['pageSize']);
  1968. // $index = array_search($template['template_id'], array_column($templates['rows'], 'id'));
  1969. // if ($index !== false) {
  1970. // $found = true;
  1971. // $result['page'] = $pages;
  1972. // $pages = 0;
  1973. // // echo "查询到的 template 在第 $page 页";
  1974. // }
  1975. // $pages--;
  1976. // }
  1977. return Result::success($result);
  1978. }
  1979. /**
  1980. * 获取网站模板下的板块信息
  1981. * @param array $data
  1982. */
  1983. public function getWebsiteSectorList(array $data): array
  1984. {
  1985. $website = Website::where('id', $data['website_id'])->first();
  1986. if (empty($website)) {
  1987. return Result::error("请输入正确的网站id", 0);
  1988. }
  1989. $template = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1990. if (empty($template['template_id'])) {
  1991. return Result::error("请先添加网站模板", 0);
  1992. }
  1993. $query = Sector::where('template_id', $template['template_id']);
  1994. if ($query->count() == 0) {
  1995. return Result::error("没有查找到相关板块数据", 0);
  1996. } elseif ($query->count() == 1) {
  1997. $sector = $query->first();
  1998. } else {
  1999. $sector = $query->get();
  2000. }
  2001. $result['page_type'] = $template['page_type'];
  2002. $result['tid'] = $template['template_id'];
  2003. $result = [
  2004. "tid" => $template['template_id'],
  2005. "page_type" => $template['page_type'],
  2006. "sector" => $sector,
  2007. ];
  2008. return Result::success($result);
  2009. }
  2010. // 自助建站---------------fr---------------
  2011. // 网站底基础信息--fr-------------------
  2012. /**
  2013. * 添加网站底基础信息
  2014. * @param array $data
  2015. */
  2016. public function addWebFootInfo(array $data): array
  2017. {
  2018. $website = Website::where('id', $data['website_id'])->first();
  2019. if (empty($website)) {
  2020. return Result::error("请输入正确的网站id!", 0);
  2021. }
  2022. $info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  2023. if (!empty($info)) {
  2024. return Result::error("该网站已经添加过了!", 0);
  2025. }
  2026. $result = WebsiteTemplateInfo::where('website_id', $data['website_id'])->insertGetId($data);
  2027. if (empty($result)) {
  2028. return Result::error("请先添加网站基础信息!", 0);
  2029. } else {
  2030. return Result::success($result);
  2031. }
  2032. }
  2033. /**
  2034. * 获取网站底基础信息
  2035. * @param array $data
  2036. */
  2037. public function getWebFootInfo(array $data): array
  2038. {
  2039. $website = Website::where('id', $data['website_id'])->first();
  2040. if (empty($website)) {
  2041. return Result::error("请输入正确的网站id!", 0);
  2042. }
  2043. $result = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  2044. if (empty($result)) {
  2045. return Result::error("请先添加网站基础信息!", 0);
  2046. }
  2047. return Result::success($result);
  2048. }
  2049. /**
  2050. * 修改网站底基础信息
  2051. * @param array $data
  2052. */
  2053. public function upWebFootInfo(array $data): array
  2054. {
  2055. // return Result::success($data);
  2056. $website = Website::where('id', $data['website_id'])->first();
  2057. if (empty($website)) {
  2058. return Result::error("请输入正确的网站id!", 0);
  2059. }
  2060. $web = $data['website_id'];
  2061. unset($data['website_id']);
  2062. $where = ['website_id' => $web];
  2063. // return Result::success($data);
  2064. $result = WebsiteTemplateInfo::where($where)->first();
  2065. if (empty($result)) {
  2066. $data['website_id'] = $web;
  2067. $result = WebsiteTemplateInfo::insertGetId($data);
  2068. // return Result::error("请先添加网站基础信息!",0);
  2069. } else {
  2070. $result = WebsiteTemplateInfo::where($where)->update($data);
  2071. }
  2072. // $where = ['website_id'=>$data['website_id']];
  2073. // unset($data['website_id']);
  2074. // $result = WebsiteTemplateInfo::updateOrInsert($where, $data);
  2075. if (empty($result)) {
  2076. return Result::error("修改失败!", 0);
  2077. }
  2078. return Result::success($result);
  2079. }
  2080. /*
  2081. * 获取父级/子级栏目------路由
  2082. * @param array $data
  2083. * @return array
  2084. * */
  2085. public function getWebsiteParentCategory(array $data): array
  2086. {
  2087. // return Result::success($data);
  2088. if (isset($data['website_id']) && !empty($data['website_id'])) {
  2089. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  2090. }
  2091. if (empty($website)) {
  2092. return Result::error("暂无该网站", 0);
  2093. }
  2094. // 在 Hyperf 中,查询构建器(Builder)没有 `map` 方法,`map` 方法是集合(Collection)的方法。
  2095. // 因此,需要先调用 `get()` 方法获取查询结果集合,再使用 `map` 方法进行处理。
  2096. $category['parent'] = WebsiteCategory::where('website_id', $data['website_id'])
  2097. ->where('pid', 0)
  2098. ->selectRaw("category_id as cid, alias as name, CONCAT('/', '', aLIas_pinyin, '/') as path")
  2099. ->get() // 添加 get() 方法获取结果集合
  2100. ->all();
  2101. // 提前查询所有父级栏目,避免在 map 中多次查询
  2102. // 提前查询所有父级栏目信息并以 category_id 作为键存储
  2103. $parentCategories = WebsiteCategory::where('website_id', $data['website_id'])
  2104. ->where('pid', 0)
  2105. ->select('category_id', 'aLIas_pinyin')
  2106. ->get()
  2107. ->keyBy('category_id');
  2108. // 直接查询子栏目信息
  2109. $child = WebsiteCategory::where('website_id', $data['website_id'])
  2110. ->where('pid', '!=', 0)
  2111. ->select('alias', 'category_id', 'aLIas_pinyin', 'pid')
  2112. ->get();
  2113. // 使用集合的 map 方法处理子栏目信息
  2114. $category['child'] = $child->map(function ($item) use ($parentCategories) {
  2115. $alias = $item->alias;
  2116. $category_id = $item->category_id;
  2117. $aLIas_pinyin = $item->aLIas_pinyin;
  2118. $parent = $parentCategories->get($item->pid);
  2119. $parentAlias = $parent ? $parent->aLIas_pinyin : '';
  2120. $result = [
  2121. 'name' => $alias,
  2122. 'cid' => $category_id
  2123. ];
  2124. if (!empty($aLIas_pinyin) && !empty($parentAlias)) {
  2125. $result['path'] = "/{$parentAlias}/{$aLIas_pinyin}/";
  2126. }
  2127. return $result;
  2128. })->values()->all();
  2129. if (empty($category)) {
  2130. return Result::error("暂无此导航", 0);
  2131. }
  2132. return Result::success($category);
  2133. }
  2134. /**
  2135. * 获取网站栏目信息
  2136. * @param array $data
  2137. */
  2138. public function getWebsiteFootAll(array $data): array
  2139. {
  2140. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  2141. if (empty($website)) {
  2142. return Result::error("暂无该网站", 0);
  2143. }
  2144. // 1:图片 2:文字 3:底部
  2145. $result['foot_cate'] = FooterCategory::where('website_id', $data['website_id'])->get()->all();
  2146. $result['link_img'] = Link::where('website_id', $data['website_id'])->where('type', 1)->where('status', 1)->limit($data['link_imgnum'])->orderBy('sort')->get()->all();
  2147. $result['link_text'] = Link::where('website_id', $data['website_id'])->where('type', 2)->where('status', 1)->limit($data['link_textnum'])->orderBy('sort')->get()->all();
  2148. $result['link_foot'] = Link::where('website_id', $data['website_id'])->where('type', 3)->where('status', 1)->limit($data['link_footnum'])->orderBy('sort')->get()->all();
  2149. $result['foot_info'] = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  2150. if (empty($result)) {
  2151. return Result::error("暂无此网站信息", 0);
  2152. }
  2153. return Result::success($result);
  2154. }
  2155. /**
  2156. * 获取网站顶部信息
  2157. * @param array $data
  2158. */
  2159. public function getWebsiteHead(array $data): array
  2160. {
  2161. $result = Website::where('id', $data['website_id'])->where('status', 1)->select('website_name', 'logo')->first();
  2162. if (empty($result)) {
  2163. return Result::error("暂无该网站", 0);
  2164. }
  2165. return Result::success($result);
  2166. }
  2167. /**
  2168. * 路由匹配
  2169. * @param array $data
  2170. */
  2171. public function getWebsiteRoute(array $data): array
  2172. {
  2173. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  2174. if (empty($website)) {
  2175. return Result::error("暂无该网站", 0);
  2176. }
  2177. // return Result::success($data);
  2178. if (isset($data['pinyin']) &&!empty($data['pinyin'])) {
  2179. $result = WebsiteCategory::where('website_id', $data['website_id'])
  2180. ->where('aLIas_pinyin', $data['pinyin'])
  2181. ->selectRaw('website_category.*,
  2182. CASE
  2183. WHEN EXISTS (SELECT 1 FROM website_category as wc WHERE wc.pid = website_category.category_id)
  2184. THEN 1
  2185. ELSE 0
  2186. END as childrencount')
  2187. ->first(['category_id', 'alias', 'children_count']);
  2188. }
  2189. if(isset($data['foot_pinyin']) &&!empty($data['foot_pinyin'])){
  2190. $result = FooterCategory::where('website_id',$data['website_id'])->where('name_pinyin',$data['foot_pinyin'])->first(['id']);
  2191. }
  2192. if (!isset($result) || empty($result)) {
  2193. return Result::error("暂无该导航", 0);
  2194. }
  2195. return Result::success($result);
  2196. }
  2197. //20250212 网站标识
  2198. public function addWebsiteGroup(array $data): array
  2199. {
  2200. //判斷name是不是重复
  2201. $websiteGroupInfo = WebsiteGroup::query()->where('name', $data['name'])->first();
  2202. if (!empty($websiteGroupInfo)) {
  2203. return Result::error("网站标识重复", 0);
  2204. }
  2205. //添加信息
  2206. $result = WebsiteGroup::insertGetId($data);
  2207. var_dump($result);
  2208. if (empty($result)) {
  2209. return Result::error("创建失败", 0);
  2210. } else {
  2211. return Result::success($result);
  2212. }
  2213. }
  2214. public function getWebsiteGroupList(array $data): array
  2215. {
  2216. $where = [];
  2217. if (isset($data['name']) && !empty($data['name'])) {
  2218. array_push($where, ['website_group.name', 'like', '%' . $data['name'] . '%']);
  2219. }
  2220. $result = WebsiteGroup::where($where)
  2221. ->limit($data['pageSize'])->orderBy("id", "desc")->offset(($data['page'] - 1) * $data['pageSize'])
  2222. ->get();
  2223. foreach ($result as $websiteGroup) {
  2224. $webIds = json_decode($websiteGroup->web_ids, true);
  2225. $websites = Website::whereIn('id', $webIds)->get();
  2226. $websiteNames = $websites->pluck('website_name', 'id')->toArray();
  2227. $websiteGroup->website_names = $websiteNames;
  2228. $websiteGroup->website_names1 = implode(',', array_values($websiteNames));
  2229. }
  2230. $count = WebsiteGroup::where($where)->count();
  2231. if (empty($result)) {
  2232. return Result::error("没有数据", 0);
  2233. }
  2234. return Result::success(['list' => $result->toArray(), 'count' => $count]);
  2235. }
  2236. public function getWebsiteGroupInfo(array $data): array
  2237. {
  2238. $websiteInfo = WebsiteGroup::query()->where('id', $data['id'])->first();
  2239. $webIds = json_decode($websiteInfo->web_ids, true);
  2240. $websites = Website::whereIn('id', $webIds)->get();
  2241. $websiteNames = $websites->pluck('website_name', 'id')->toArray();
  2242. $websiteInfo->website_names = $websiteNames;
  2243. $websiteInfo->website_names1 = implode(',', array_values($websiteNames));
  2244. if (empty($websiteInfo)) {
  2245. return Result::error("找不到URL", 0);
  2246. }
  2247. return Result::success($websiteInfo->toArray());
  2248. }
  2249. public function updateWebsiteGroup(array $data): array
  2250. {
  2251. $where = [
  2252. 'id' => $data['id'],
  2253. ];
  2254. $insertData = [
  2255. 'name' => $data['name'],
  2256. 'web_ids' => $data['web_ids'],
  2257. ];
  2258. //判斷name是不是重复
  2259. $websiteGroupInfo = WebsiteGroup::query()->where('name', $data['name'])->first();
  2260. if (!empty($websiteGroupInfo) && $websiteGroupInfo->id != $data['id']) {
  2261. return Result::error("网站标识重复", 0);
  2262. }
  2263. $result = WebsiteGroup::where($where)->update($insertData);
  2264. var_dump($result, '------更新');
  2265. if (empty($result)) {
  2266. return Result::error("更新失败", 0);
  2267. } else {
  2268. return Result::success();
  2269. }
  2270. }
  2271. public function deleteWebsiteGroup(array $data): array
  2272. {
  2273. $where = [
  2274. 'id' => $data['id'],
  2275. ];
  2276. //看看user表是不是有这个id
  2277. $userGroup = User::query()->where('sszq', $data['id'])->first();
  2278. if (!empty($userGroup)) {
  2279. return Result::error("有用户在使用该网站标识,不能删除", 0);
  2280. }
  2281. $result = WebsiteGroup::where($where)->delete();
  2282. if (empty($result)) {
  2283. return Result::error("删除失败", 0);
  2284. } else {
  2285. return Result::success();
  2286. }
  2287. }
  2288. public function getWebsiteNavList(array $data): array
  2289. {
  2290. $data['type'] = isset($data['type']) ? $data['type'] : 1;
  2291. $where = [];
  2292. if (isset($data['website_id']) && !empty($data['website_id'])) {
  2293. array_push($where, ['website_id', '=', $data['website_id']]);
  2294. }
  2295. if (isset($data['pid'])) {
  2296. array_push($where, ['pid', '=', $data['pid']]);
  2297. }
  2298. if (isset($data['type']) && !empty($data['type'])) {
  2299. array_push($where, ['type', '=', $data['type']]);
  2300. }
  2301. // 根据站点和type获取websiteCategory 中的id
  2302. $websiteCategoryids = WebsiteCategory::query()
  2303. ->where('website_id', '=', $data['website_id'])
  2304. ->where('type', '=', $data['type'])
  2305. ->pluck('category_arr_id')->toArray();
  2306. var_dump($websiteCategoryids, '------获取websiteCategory 中的id');
  2307. //合并去重
  2308. $category_ids = [];
  2309. foreach ($websiteCategoryids as $key => $value) {
  2310. $v = json_decode($value, true);
  2311. $category_ids = array_unique(array_merge($category_ids, $v));
  2312. }
  2313. // var_dump($category_ids, '------获取websiteCategory 中的id');
  2314. //根据pid取出所有的websiteCategory 中的id
  2315. $list = WebsiteCategory::query()
  2316. ->where('website_id', '=', $data['website_id'])
  2317. ->where('pid', '=', $data['pid'])
  2318. ->whereIn('category_id', $category_ids)
  2319. ->get();
  2320. if (empty($list)) {
  2321. return Result::error("获取失败", 0);
  2322. } else {
  2323. return Result::success($list);
  2324. }
  2325. }
  2326. // 20250307 根据网站标识获和导航获取站点
  2327. public function getWebsiteNavPoolSite(array $data): array
  2328. {
  2329. $where = [];
  2330. if (isset($data['category_id']) && !empty($data['category_id'])) {
  2331. array_push($where, ['category_id', '=', $data['category_id']]);
  2332. }
  2333. $list = WebsiteCategory::query()->where($where)
  2334. ->leftJoin('website', 'website.id', '=', 'website_category.website_id')
  2335. ->select('website_category.*', 'website.website_name')
  2336. ->distinct()
  2337. ->get();
  2338. if (empty($list)) {
  2339. return Result::error("获取失败", 0);
  2340. } else {
  2341. return Result::success($list);
  2342. }
  2343. }
  2344. public function getWebsiteNavPool(array $data): array
  2345. {
  2346. // 初始化查询条件数组
  2347. $query = WebsiteCategory::query();
  2348. // 如果传入了 websiteids,则添加到查询条件中
  2349. if (isset($data['websiteids']) && !empty($data['websiteids'])) {
  2350. $query->whereIn('website_id', $data['websiteids']);
  2351. }
  2352. // 如果传入了 pid,则添加到查询条件中
  2353. if (isset($data['pid'])) {
  2354. $query->where('pid', '=', $data['pid']);
  2355. }
  2356. // 执行查询 唯一性 id
  2357. $list = $query->distinct()->get();
  2358. // 根据查询结果返回相应的结果
  2359. if ($list->isEmpty()) {
  2360. return Result::error("获取失败", 0);
  2361. } else {
  2362. return Result::success($list->toArray());
  2363. }
  2364. }
  2365. /**
  2366. *
  2367. * @param array $data
  2368. * @return array
  2369. */
  2370. public function getAllCategory(array $data): array
  2371. {
  2372. $result = Category::when($data, function ($query) use ($data) {
  2373. if (isset($data['name']) && !empty($data['name'])) {
  2374. $query->where('category.name', 'like', '%' . trim($data['name']) . '%');
  2375. }
  2376. })->get();
  2377. if (empty($result)) {
  2378. return Result::error("获取失败", 0);
  2379. } else {
  2380. return Result::success($result);
  2381. }
  2382. }
  2383. /**
  2384. * 修改网站栏目排序
  2385. * @param array $data
  2386. * @return array
  2387. */
  2388. public function upWebsiteCategorySort(array $data): array
  2389. {
  2390. $where = [
  2391. 'website_id' => $data['website_id'],
  2392. 'id' => $data['id'],
  2393. ];
  2394. $result = WebsiteCategory::where($where)->update($data);
  2395. if ($result) {
  2396. return Result::success($result);
  2397. } else {
  2398. return Result::error("更新失败", 0);
  2399. }
  2400. }
  2401. }