AttachmentRepository.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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\common\repositories\system\attachment;
  12. //附件
  13. use app\common\dao\BaseDao;
  14. use app\common\dao\system\attachment\AttachmentDao;
  15. use app\common\repositories\BaseRepository;
  16. use FormBuilder\Factory\Elm;
  17. use think\db\exception\DataNotFoundException;
  18. use think\db\exception\DbException;
  19. use think\db\exception\ModelNotFoundException;
  20. use think\facade\Route;
  21. use think\Model;
  22. /**
  23. * Class BaseRepository
  24. * @package common\repositories
  25. * @mixin AttachmentDao
  26. */
  27. class AttachmentRepository extends BaseRepository
  28. {
  29. /**
  30. * @var AttachmentCategoryRepository
  31. */
  32. private $attachmentCategoryRepository;
  33. /**
  34. * AttachmentRepository constructor.
  35. * @param AttachmentDao $dao
  36. * @param AttachmentCategoryRepository $attachmentCategoryRepository
  37. */
  38. public function __construct(AttachmentDao $dao, AttachmentCategoryRepository $attachmentCategoryRepository)
  39. {
  40. /**
  41. * @var AttachmentDao
  42. */
  43. $this->dao = $dao;
  44. $this->attachmentCategoryRepository = $attachmentCategoryRepository;
  45. }
  46. /**
  47. * @param array $where
  48. * @param int $page
  49. * @param int $limit
  50. * @return array
  51. * @throws DataNotFoundException
  52. * @throws DbException
  53. * @throws ModelNotFoundException
  54. * @author xaboy
  55. * @day 2020-04-15
  56. */
  57. public function getList(array $where, int $page, int $limit)
  58. {
  59. $query = $this->search($where);
  60. $count = $query->count($this->dao->getPk());
  61. $list = $query->page($page, $limit)->hidden(['upload_type', 'user_type', 'user_id'])
  62. ->select();
  63. return compact('count', 'list');
  64. }
  65. /**
  66. * @param int $uploadType
  67. * @param int $userType
  68. * @param int $userId
  69. * @param array $data
  70. * @return BaseDao|Model
  71. * @author xaboy
  72. * @day 2020-04-15
  73. */
  74. public function create(int $uploadType, int $userType, int $userId, array $data)
  75. {
  76. $data['upload_type'] = $uploadType;
  77. $data['user_type'] = $userType;
  78. $data['user_id'] = $userId;
  79. return $this->dao->create($data);
  80. }
  81. /**
  82. * @param array $ids
  83. * @param int $categoryId
  84. * @param int $merId
  85. * @return int
  86. * @throws DbException
  87. * @author xaboy
  88. * @day 2020-04-16
  89. */
  90. public function batchChangeCategory(array $ids, int $categoryId, $merId = 0)
  91. {
  92. return $this->dao->batchChange($ids, ['attachment_category_id' => $categoryId], $merId);
  93. }
  94. public function form(int $id,int $merId)
  95. {
  96. if ($merId) {
  97. $action = 'merchantAttachmentUpdate';
  98. } else {
  99. $action = 'systemAttachmentUpdate';
  100. }
  101. $formData = $this->dao->get($id)->toArray();
  102. $form = Elm::createForm(Route::buildUrl($action, is_null($id) ? [] : ['id' => $id])->build());
  103. $form->setRule([
  104. Elm::input('attachment_name', '名称')->required(),
  105. ]);
  106. return $form->setTitle('编辑配置')->formData($formData);
  107. }
  108. }