PublicController.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\api\controller\pc;
  12. use app\Request;
  13. use app\services\article\ArticleCategoryServices;
  14. use app\services\article\ArticleServices;
  15. use app\services\pc\PublicServices;
  16. use crmeb\services\CacheService;
  17. class PublicController
  18. {
  19. protected $services;
  20. public function __construct(PublicServices $services)
  21. {
  22. $this->services = $services;
  23. }
  24. /**
  25. * 获取城市数据
  26. * @param Request $request
  27. * @return mixed
  28. */
  29. public function getCity(Request $request)
  30. {
  31. list($pid) = $request->getMore([
  32. [['pid', 'd'], 0],
  33. ], true);
  34. return app('json')->success($this->services->getCity($pid));
  35. }
  36. /**
  37. * 获取公司信息
  38. * @return mixed
  39. */
  40. public function getCompanyInfo()
  41. {
  42. $data['contact_number'] = sys_config('contact_number');
  43. $data['company_address'] = sys_config('company_address');
  44. $data['copyright'] = sys_config('nncnL_crmeb_copyright', '');
  45. $data['record_No'] = sys_config('record_No');
  46. $data['site_name'] = sys_config('site_name');
  47. $data['site_keywords'] = sys_config('site_keywords');
  48. $data['site_description'] = sys_config('site_description');
  49. $data['network_security'] = sys_config('network_security');
  50. $data['network_security_url'] = sys_config('network_security_url');
  51. $data['icp_url'] = sys_config('icp_url');
  52. $data['pc_home_menus'] = sys_data('pc_home_menus');
  53. $data['pc_home_links'] = sys_data('pc_home_links');
  54. $logoUrl = sys_config('pc_logo');
  55. if (strstr($logoUrl, 'http') === false && $logoUrl) {
  56. $logoUrl = sys_config('site_url') . $logoUrl;
  57. }
  58. $logoUrl = str_replace('\\', '/', $logoUrl);
  59. $data['logoUrl'] = $logoUrl;
  60. return app('json')->success($data);
  61. }
  62. /**
  63. * 获取关注微信二维码
  64. * @return mixed
  65. */
  66. public function getWechatQrcode()
  67. {
  68. $data['wechat_qrcode'] = sys_config('wechat_qrcode');
  69. return app('json')->success($data);
  70. }
  71. /**
  72. * 文章分类
  73. * @param ArticleCategoryServices $services
  74. * @return \think\Response
  75. * @author wuhaotian
  76. * @email 442384644@qq.com
  77. * @date 2024/5/6
  78. */
  79. public function getNewsCategory(ArticleCategoryServices $services)
  80. {
  81. $cateInfo = CacheService::remember('ARTICLE_CATEGORY_PC', function () use ($services) {
  82. return $services->getArticleCategory();
  83. });
  84. return app('json')->success($cateInfo);
  85. }
  86. /**
  87. * pc文章列表
  88. * @param Request $request
  89. * @param ArticleServices $services
  90. * @return \think\Response
  91. * @throws \ReflectionException
  92. * @throws \think\db\exception\DataNotFoundException
  93. * @throws \think\db\exception\DbException
  94. * @throws \think\db\exception\ModelNotFoundException
  95. * @author wuhaotian
  96. * @email 442384644@qq.com
  97. * @date 2024/5/6
  98. */
  99. public function getNewsList(Request $request, ArticleServices $services)
  100. {
  101. list($cid, $page, $limit) = $request->getMore([
  102. [['cid', 'd'], 0],
  103. [['page', 'd'], 0],
  104. [['limit', 'd'], 0],
  105. ], true);
  106. if ($cid == 0) {
  107. $where = ['is_hot' => 1];
  108. } else {
  109. $where = ['cid' => $cid];
  110. }
  111. $data = $services->getList($where, $page, $limit);
  112. foreach ($data['list'] as &$item) {
  113. $item['add_time'] = date('Y-m-d H:i', $item['add_time']);
  114. }
  115. return app('json')->success($data);
  116. }
  117. /**
  118. * 文章详情
  119. * @param ArticleServices $services
  120. * @param $id
  121. * @return \think\Response
  122. * @throws \ReflectionException
  123. * @throws \think\db\exception\DataNotFoundException
  124. * @throws \think\db\exception\DbException
  125. * @throws \think\db\exception\ModelNotFoundException
  126. * @author wuhaotian
  127. * @email 442384644@qq.com
  128. * @date 2024/5/6
  129. */
  130. public function getNewsDetail(ArticleServices $services, $id)
  131. {
  132. $info = $services->getInfo($id);
  133. return app('json')->success($info);
  134. }
  135. }