HotSearchLogic.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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\setting;
  15. use app\common\logic\BaseLogic;
  16. use app\common\model\HotSearch;
  17. use app\common\service\ConfigService;
  18. use app\common\service\FileService;
  19. /**
  20. * 热门搜素逻辑
  21. * Class HotSearchLogic
  22. * @package app\adminapi\logic\setting
  23. */
  24. class HotSearchLogic extends BaseLogic
  25. {
  26. /**
  27. * @notes 获取配置
  28. * @return array
  29. * @author 段誉
  30. * @date 2022/9/5 18:48
  31. */
  32. public static function getConfig()
  33. {
  34. return [
  35. // 功能状态 0-关闭 1-开启
  36. 'status' => ConfigService::get('hot_search', 'status', 0),
  37. // 热门搜索数据
  38. 'data' => HotSearch::field(['name', 'sort'])->order(['sort' => 'desc', 'id' =>'desc'])->select()->toArray(),
  39. ];
  40. }
  41. /**
  42. * @notes 设置热门搜搜
  43. * @param $params
  44. * @return bool
  45. * @author 段誉
  46. * @date 2022/9/5 18:58
  47. */
  48. public static function setConfig($params)
  49. {
  50. try {
  51. if (!empty($params['data'])) {
  52. $model = (new HotSearch());
  53. $model->where('id', '>', 0)->delete();
  54. $model->saveAll($params['data']);
  55. }
  56. $status = empty($params['status']) ? 0 : $params['status'];
  57. ConfigService::set('hot_search', 'status', $status);
  58. return true;
  59. } catch (\Exception $e) {
  60. self::$error = $e->getMessage();
  61. return false;
  62. }
  63. }
  64. }