SystemStorageDao.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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\dao\system\config;
  12. use app\dao\BaseDao;
  13. use app\model\system\config\SystemStorage;
  14. /**
  15. * Class SystemStorageDao
  16. * @package app\dao\system\config
  17. */
  18. class SystemStorageDao extends BaseDao
  19. {
  20. /**
  21. * @return string
  22. */
  23. protected function setModel(): string
  24. {
  25. return SystemStorage::class;
  26. }
  27. /**
  28. * 获取列表
  29. * @param array $where
  30. * @param array|string[] $field
  31. * @param int $page
  32. * @param int $limit
  33. * @param null $sort
  34. * @param array $with
  35. * @return array
  36. * @throws \think\db\exception\DataNotFoundException
  37. * @throws \think\db\exception\DbException
  38. * @throws \think\db\exception\ModelNotFoundException
  39. */
  40. public function getList(array $where = [], array $field = ['*'], int $page = 0, int $limit = 0, $sort = null, array $with = [])
  41. {
  42. return $this->search($where)->field($field)->when($page && $limit, function ($query) use ($page, $limit) {
  43. $query->page($page, $limit);
  44. })->when($sort, function ($query) use ($sort) {
  45. if (is_array($sort)) {
  46. foreach ($sort as $v => $k) {
  47. if (is_numeric($v)) {
  48. $query->order($k, 'desc');
  49. } else {
  50. $query->order($v, $k);
  51. }
  52. }
  53. } else {
  54. $query->order($sort, 'desc');
  55. }
  56. })->with($with)->select()->toArray();
  57. }
  58. /**
  59. * @param array $where
  60. * @param bool $search
  61. * @return \crmeb\basic\BaseModel|mixed|\think\Model
  62. * @throws \ReflectionException
  63. */
  64. public function search(array $where = [], bool $search = false)
  65. {
  66. return parent::search($where, $search)->when(isset($where['type']), function ($query) use ($where) {
  67. $query->where('type', $where['type']);
  68. })->where('is_delete', 0)->when(isset($where['access_key']), function ($query) use ($where) {
  69. $query->where('access_key', $where['access_key']);
  70. })->when(!empty($where['id']), function ($query) use ($where) {
  71. $query->where('id', $where['id']);
  72. });
  73. }
  74. }