WebsiteService.php 104 KB

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