SystemStorageDao.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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. use crmeb\traits\SearchDaoTrait;
  15. /**
  16. * Class SystemStorageDao
  17. * @package app\dao\system\config
  18. */
  19. class SystemStorageDao extends BaseDao
  20. {
  21. use SearchDaoTrait;
  22. /**
  23. * @return string
  24. */
  25. protected function setModel(): string
  26. {
  27. return SystemStorage::class;
  28. }
  29. /**
  30. * 获取分页列表
  31. * @param array $where
  32. * @param array $field
  33. * @param int $page
  34. * @param int $limit
  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 getStorageList(array $where, array $field = ['*'], int $page = 0, int $limit = 0)
  41. {
  42. return $this->search($where)->field($field)->when($page && $limit, function ($query) use ($page, $limit) {
  43. $query->page($page, $limit);
  44. })->order('add_time desc')->select()->toArray();
  45. }
  46. /**
  47. * @param array $where
  48. * @return int
  49. */
  50. public function getCount(array $where)
  51. {
  52. return $this->search($where)->count();
  53. }
  54. /**
  55. * @param array $where
  56. * @return \crmeb\basic\BaseModel|mixed|\think\Model
  57. */
  58. public function search(array $where = [])
  59. {
  60. return parent::search($where)->when(isset($where['type']), function ($query) use ($where) {
  61. $query->where('type', $where['type']);
  62. })->where('is_delete', 0)->when(isset($where['access_key']), function ($query) use ($where) {
  63. $query->where('access_key', $where['access_key']);
  64. });
  65. }
  66. }