DecorateTabbarLogic.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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\adminapi\logic\decorate;
  15. use app\common\logic\BaseLogic;
  16. use app\common\model\decorate\DecorateTabbar;
  17. use app\common\service\ConfigService;
  18. use app\common\service\FileService;
  19. /**
  20. * 装修配置-底部导航
  21. * Class DecorateTabbarLogic
  22. * @package app\adminapi\logic\decorate
  23. */
  24. class DecorateTabbarLogic extends BaseLogic
  25. {
  26. /**
  27. * @notes 获取底部导航详情
  28. * @return array
  29. * @throws \think\db\exception\DataNotFoundException
  30. * @throws \think\db\exception\DbException
  31. * @throws \think\db\exception\ModelNotFoundException
  32. * @author 段誉
  33. * @date 2022/9/7 16:58
  34. */
  35. public static function detail(): array
  36. {
  37. $list = DecorateTabbar::getTabbarLists();
  38. $style = ConfigService::get('tabbar', 'style', config('project.decorate.tabbar_style'));
  39. return ['style' => $style, 'list' => $list];
  40. }
  41. /**
  42. * @notes 底部导航保存
  43. * @param $params
  44. * @return bool
  45. * @throws \Exception
  46. * @author 段誉
  47. * @date 2022/9/7 17:19
  48. */
  49. public static function save($params): bool
  50. {
  51. $model = new DecorateTabbar();
  52. // 删除旧配置数据
  53. $model->where('id', '>', 0)->delete();
  54. // 保存数据
  55. $tabbars = $params['list'] ?? [];
  56. $data = [];
  57. foreach ($tabbars as $item) {
  58. $data[] = [
  59. 'name' => $item['name'],
  60. 'selected' => FileService::setFileUrl($item['selected']),
  61. 'unselected' => FileService::setFileUrl($item['unselected']),
  62. 'link' => $item['link'],
  63. 'is_show' => $item['is_show'] ?? 0,
  64. ];
  65. }
  66. $model->saveAll($data);
  67. if (!empty($params['style'])) {
  68. ConfigService::set('tabbar', 'style', $params['style']);
  69. }
  70. return true;
  71. }
  72. }