SystemAttachmentDao.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. declare (strict_types=1);
  12. namespace app\dao\system\attachment;
  13. use app\dao\BaseDao;
  14. use app\model\system\attachment\SystemAttachment;
  15. /**
  16. *
  17. * Class SystemAttachmentDao
  18. * @package app\dao\attachment
  19. */
  20. class SystemAttachmentDao extends BaseDao
  21. {
  22. /**
  23. * 设置模型
  24. * @return string
  25. */
  26. protected function setModel(): string
  27. {
  28. return SystemAttachment::class;
  29. }
  30. /**
  31. * 搜索附件分类search
  32. * @param array $where
  33. * @return \crmeb\basic\BaseModel|mixed|\think\Model
  34. */
  35. public function search(array $where = [])
  36. {
  37. return parent::search($where)->when(isset($where['name']) && $where['name']!='', function ($query) use ($where) {
  38. $query->where('att_id|real_name|name', 'LIKE', '%' . trim($where['name']) . '%');
  39. });
  40. }
  41. /**
  42. * 获取图片列表
  43. * @param array $where
  44. * @param int $page
  45. * @param int $limit
  46. * @return array
  47. * @throws \think\db\exception\DataNotFoundException
  48. * @throws \think\db\exception\DbException
  49. * @throws \think\db\exception\ModelNotFoundException
  50. */
  51. public function getList(array $where, int $page, int $limit)
  52. {
  53. return $this->search($where)->where('module_type', 1)->page($page, $limit)->order('att_id DESC')->select()->toArray();
  54. }
  55. /**
  56. * 移动图片
  57. * @param array $data
  58. * @return \crmeb\basic\BaseModel
  59. */
  60. public function move(array $data)
  61. {
  62. return $this->getModel()->whereIn('att_id', $data['images'])->update(['pid' => $data['pid']]);
  63. }
  64. /**
  65. * 获取名称
  66. * @param array $where
  67. * @param int $page
  68. * @param int $limit
  69. * @return array
  70. * @throws \think\db\exception\DataNotFoundException
  71. * @throws \think\db\exception\DbException
  72. * @throws \think\db\exception\ModelNotFoundException
  73. */
  74. public function getLikeNameList(array $where, int $page, int $limit)
  75. {
  76. return $this->search($where)->page($page, $limit)->order('att_id desc')->select()->toArray();
  77. }
  78. /**
  79. * 获取昨日系统生成
  80. * @param int $type
  81. * @param int $relationId
  82. * @return \think\Collection
  83. * @throws \think\db\exception\DataNotFoundException
  84. * @throws \think\db\exception\DbException
  85. * @throws \think\db\exception\ModelNotFoundException
  86. */
  87. public function getYesterday(int $type = 1, $relationId = 0)
  88. {
  89. return $this->getModel()->where('type', $type)->when($relationId, function ($query) use ($relationId) {
  90. $query->where('relation_id', $relationId);
  91. })->whereTime('time', 'yesterday')->where('module_type', 2)->field(['name', 'att_dir', 'att_id', 'image_type'])->select();
  92. }
  93. /**
  94. * 删除昨日生成海报
  95. * @throws \Exception
  96. */
  97. public function delYesterday()
  98. {
  99. $this->getModel()->whereTime('time', 'yesterday')->where('module_type', 2)->delete();
  100. }
  101. /**
  102. * 获取扫码上传的图片数据
  103. * @param $scan_token
  104. * @return array
  105. * @throws \think\db\exception\DataNotFoundException
  106. * @throws \think\db\exception\DbException
  107. * @throws \think\db\exception\ModelNotFoundException
  108. */
  109. public function scanUploadImage($scan_token)
  110. {
  111. return $this->getModel()->where('scan_token', $scan_token)->field('att_dir,att_id')->select()->toArray();
  112. }
  113. }