NavService.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Niucloud-admin 企业快速开发的多应用管理平台
  4. // +----------------------------------------------------------------------
  5. // | 官方网址:https://www.niucloud.com
  6. // +----------------------------------------------------------------------
  7. // | niucloud团队 版权所有 开源版本可自由商用
  8. // +----------------------------------------------------------------------
  9. // | Author: Niucloud Team
  10. // +----------------------------------------------------------------------
  11. namespace app\service\admin\web;
  12. use app\model\web\Nav;
  13. use core\base\BaseAdminService;
  14. /**
  15. * 首页导航服务层
  16. * Class WebService
  17. * @package app\service\admin\web
  18. */
  19. class NavService extends BaseAdminService
  20. {
  21. public function __construct()
  22. {
  23. parent::__construct();
  24. $this->model = new Nav();
  25. }
  26. /**
  27. * 获取首页导航列表
  28. * @param array $where
  29. * @return array
  30. */
  31. public function getPage(array $where = [])
  32. {
  33. $field = 'id, nav_title, nav_url, sort, is_blank, create_time, update_time, nav_icon, is_show';
  34. $order = 'create_time desc';
  35. $search_model = $this->model->where([ [ 'site_id', '=', $this->site_id ] ])->withSearch([ "nav_title" ], $where)->field($field)->order($order);
  36. $list = $this->pageQuery($search_model);
  37. return $list;
  38. }
  39. /**
  40. * 获取首页导航列表
  41. * @param array $where
  42. * @param string $field
  43. * @return array
  44. */
  45. public function getList(array $where = [], $field = 'id, nav_title, nav_url, sort, is_blank, create_time, update_time, nav_icon, is_show')
  46. {
  47. $order = "create_time desc";
  48. return $this->model->where([ [ 'site_id', '=', $this->site_id ] ])->withSearch([ "nav_title" ], $where)->field($field)->select()->order($order)->toArray();
  49. }
  50. /**
  51. * 获取首页导航信息
  52. * @param int $id
  53. * @return array
  54. */
  55. public function getInfo(int $id)
  56. {
  57. $field = 'id, site_id, nav_title, nav_url, sort, is_blank, create_time, update_time, nav_icon, is_show';
  58. $info = $this->model->field($field)->where([ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ] ])->findOrEmpty()->toArray();
  59. return $info;
  60. }
  61. /**
  62. * 添加首页导航
  63. * @param array $data
  64. * @return mixed
  65. */
  66. public function add(array $data)
  67. {
  68. $data[ 'create_time' ] = time();
  69. $data[ 'site_id' ] = $this->site_id;
  70. $res = $this->model->create($data);
  71. return $res->id;
  72. }
  73. /**
  74. * 首页导航编辑
  75. * @param int $id
  76. * @param array $data
  77. * @return bool
  78. */
  79. public function edit(int $id, array $data)
  80. {
  81. $data[ 'update_time' ] = time();
  82. $this->model->where([ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ] ])->update($data);
  83. return true;
  84. }
  85. /**
  86. * 删除首页导航
  87. * @param int $id
  88. * @return bool
  89. */
  90. public function del(int $id)
  91. {
  92. $model = $this->model->where([ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ] ])->find();
  93. $res = $model->delete();
  94. return $res;
  95. }
  96. }