AttachmentRepository.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author xaboy
  6. * @day 2020-03-24
  7. *
  8. *
  9. */
  10. namespace app\common\repositories\system\attachment;
  11. //附件
  12. use app\common\dao\BaseDao;
  13. use app\common\dao\system\attachment\AttachmentDao;
  14. use app\common\repositories\BaseRepository;
  15. use think\db\exception\DataNotFoundException;
  16. use think\db\exception\DbException;
  17. use think\db\exception\ModelNotFoundException;
  18. use think\Model;
  19. /**
  20. * Class BaseRepository
  21. * @package common\repositories
  22. * @mixin AttachmentDao
  23. */
  24. class AttachmentRepository extends BaseRepository
  25. {
  26. /**
  27. * @var AttachmentCategoryRepository
  28. */
  29. private $attachmentCategoryRepository;
  30. /**
  31. * AttachmentRepository constructor.
  32. * @param AttachmentDao $dao
  33. * @param AttachmentCategoryRepository $attachmentCategoryRepository
  34. */
  35. public function __construct(AttachmentDao $dao, AttachmentCategoryRepository $attachmentCategoryRepository)
  36. {
  37. /**
  38. * @var AttachmentDao
  39. */
  40. $this->dao = $dao;
  41. $this->attachmentCategoryRepository = $attachmentCategoryRepository;
  42. }
  43. /**
  44. * @param array $where
  45. * @param int $page
  46. * @param int $limit
  47. * @return array
  48. * @throws DataNotFoundException
  49. * @throws DbException
  50. * @throws ModelNotFoundException
  51. * @author xaboy
  52. * @day 2020-04-15
  53. */
  54. public function getList(array $where, int $page, int $limit)
  55. {
  56. $query = $this->search($where);
  57. $count = $query->count($this->dao->getPk());
  58. $list = $query->page($page, $limit)->hidden(['upload_type', 'user_type', 'user_id'])->order('create_time DESC')->select();
  59. return compact('count', 'list');
  60. }
  61. /**
  62. * @param int $uploadType
  63. * @param int $userType
  64. * @param int $userId
  65. * @param array $data
  66. * @return BaseDao|Model
  67. * @author xaboy
  68. * @day 2020-04-15
  69. */
  70. public function create(int $uploadType, int $userType, int $userId, array $data)
  71. {
  72. $data['upload_type'] = $uploadType;
  73. $data['user_type'] = $userType;
  74. $data['user_id'] = $userId;
  75. return $this->dao->create($data);
  76. }
  77. /**
  78. * @param array $ids
  79. * @param int $categoryId
  80. * @param int $merId
  81. * @return int
  82. * @throws DbException
  83. * @author xaboy
  84. * @day 2020-04-16
  85. */
  86. public function batchChangeCategory(array $ids, int $categoryId, $merId = 0)
  87. {
  88. return $this->dao->batchChange($ids, ['attachment_category_id' => $categoryId], $merId);
  89. }
  90. }