UploadGroup.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. *
  4. * @copyright ©2020 点小铺
  5. * @author hanj
  6. * @link: https://dyuit.com
  7. * Created by VSCode
  8. */
  9. namespace app\store\model;
  10. use app\common\model\UploadGroup as UploadGroupModel;
  11. /**
  12. * 文件库分组模型
  13. * Class UploadGroup
  14. * @package app\store\model
  15. */
  16. class UploadGroup extends UploadGroupModel
  17. {
  18. /**
  19. * 获取列表记录
  20. * @param string $groupType
  21. * @return false|\PDOStatement|string|\think\Collection
  22. * @throws \think\db\exception\DataNotFoundException
  23. * @throws \think\db\exception\ModelNotFoundException
  24. * @throws \think\exception\DbException
  25. */
  26. public function getList($groupType = '')
  27. {
  28. !empty($groupType) && $this->where('group_type', '=', trim($groupType));
  29. return $this->where('is_delete', '=', 0)
  30. ->order(['sort' => 'asc', 'create_time' => 'desc'])
  31. ->select();
  32. }
  33. /**
  34. * 添加新记录
  35. * @param $data
  36. * @return false|int
  37. */
  38. public function add($data)
  39. {
  40. return $this->save(array_merge([
  41. 'wxapp_id' => self::$wxapp_id,
  42. 'sort' => 100
  43. ], $data));
  44. }
  45. /**
  46. * 更新记录
  47. * @param $data
  48. * @return bool|int
  49. */
  50. public function edit($data)
  51. {
  52. return $this->allowField(true)->save($data) !== false;
  53. }
  54. /**
  55. * 删除记录
  56. * @return int
  57. */
  58. public function remove()
  59. {
  60. // 更新该分组下的所有文件
  61. (new UploadFile)->where('group_id', '=', $this['group_id'])
  62. ->update(['group_id' => 0]);
  63. // 删除分组
  64. return $this->save(['is_delete' => 1]);
  65. }
  66. }