WebsiteService.php 83 KB

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