IndexLogic.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\api\logic;
  15. use app\common\logic\BaseLogic;
  16. use app\common\model\article\Article;
  17. use app\common\model\decorate\DecoratePage;
  18. use app\common\model\decorate\DecorateTabbar;
  19. use app\common\service\ConfigService;
  20. use app\common\service\FileService;
  21. /**
  22. * index
  23. * Class IndexLogic
  24. * @package app\api\logic
  25. */
  26. class IndexLogic extends BaseLogic
  27. {
  28. /**
  29. * @notes 首页数据
  30. * @return array
  31. * @throws \think\db\exception\DataNotFoundException
  32. * @throws \think\db\exception\DbException
  33. * @throws \think\db\exception\ModelNotFoundException
  34. * @author 段誉
  35. * @date 2022/9/21 19:15
  36. */
  37. public static function getIndexData()
  38. {
  39. // 装修配置
  40. $decoratePage = DecoratePage::findOrEmpty(1);
  41. // 首页文章
  42. $field = [
  43. 'id', 'title', 'desc', 'abstract', 'image',
  44. 'author', 'click_actual', 'click_virtual', 'create_time'
  45. ];
  46. $article = Article::field($field)
  47. ->where(['is_show' => 1])
  48. ->order(['id' => 'desc'])
  49. ->limit(20)->append(['click'])
  50. ->hidden(['click_actual', 'click_virtual'])
  51. ->select()->toArray();
  52. return [
  53. 'page' => $decoratePage,
  54. 'article' => $article
  55. ];
  56. }
  57. /**
  58. * @notes 获取政策协议
  59. * @param string $type
  60. * @return array
  61. * @author 段誉
  62. * @date 2022/9/20 20:00
  63. */
  64. public static function getPolicyByType(string $type)
  65. {
  66. return [
  67. 'title' => ConfigService::get('agreement', $type . '_title', ''),
  68. 'content' => ConfigService::get('agreement', $type . '_content', ''),
  69. ];
  70. }
  71. /**
  72. * @notes 装修信息
  73. * @param $id
  74. * @return array
  75. * @author 段誉
  76. * @date 2022/9/21 18:37
  77. */
  78. public static function getDecorate($id)
  79. {
  80. return DecoratePage::field(['type', 'name', 'data', 'meta'])
  81. ->findOrEmpty($id)->toArray();
  82. }
  83. /**
  84. * @notes 获取配置
  85. * @return array
  86. * @throws \think\db\exception\DataNotFoundException
  87. * @throws \think\db\exception\DbException
  88. * @throws \think\db\exception\ModelNotFoundException
  89. * @author 段誉
  90. * @date 2022/9/21 19:38
  91. */
  92. public static function getConfigData()
  93. {
  94. // 底部导航
  95. $tabbar = DecorateTabbar::getTabbarLists();
  96. // 导航颜色
  97. $style = ConfigService::get('tabbar', 'style', config('project.decorate.tabbar_style'));
  98. // 登录配置
  99. $loginConfig = [
  100. // 登录方式
  101. 'login_way' => ConfigService::get('login', 'login_way', config('project.login.login_way')),
  102. // 注册强制绑定手机
  103. 'coerce_mobile' => ConfigService::get('login', 'coerce_mobile', config('project.login.coerce_mobile')),
  104. // 政策协议
  105. 'login_agreement' => ConfigService::get('login', 'login_agreement', config('project.login.login_agreement')),
  106. // 第三方登录 开关
  107. 'third_auth' => ConfigService::get('login', 'third_auth', config('project.login.third_auth')),
  108. // 微信授权登录
  109. 'wechat_auth' => ConfigService::get('login', 'wechat_auth', config('project.login.wechat_auth')),
  110. // qq授权登录
  111. 'qq_auth' => ConfigService::get('login', 'qq_auth', config('project.login.qq_auth')),
  112. ];
  113. // 网址信息
  114. $website = [
  115. 'h5_favicon' => FileService::getFileUrl(ConfigService::get('website', 'h5_favicon')),
  116. 'shop_name' => ConfigService::get('website', 'shop_name'),
  117. 'shop_logo' => FileService::getFileUrl(ConfigService::get('website', 'shop_logo')),
  118. ];
  119. // H5配置
  120. $webPage = [
  121. // 渠道状态 0-关闭 1-开启
  122. 'status' => ConfigService::get('web_page', 'status', 1),
  123. // 关闭后渠道后访问页面 0-空页面 1-自定义链接
  124. 'page_status' => ConfigService::get('web_page', 'page_status', 0),
  125. // 自定义链接
  126. 'page_url' => ConfigService::get('web_page', 'page_url', ''),
  127. 'url' => request()->domain() . '/mobile'
  128. ];
  129. // 备案信息
  130. $copyright = ConfigService::get('copyright', 'config', []);
  131. return [
  132. 'domain' => FileService::getFileUrl(),
  133. 'style' => $style,
  134. 'tabbar' => $tabbar,
  135. 'login' => $loginConfig,
  136. 'website' => $website,
  137. 'webPage' => $webPage,
  138. 'version'=> config('project.version'),
  139. 'copyright' => $copyright,
  140. ];
  141. }
  142. }