WebsiteService.php 112 KB

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