WebsiteService.php 96 KB

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