UploadGroup.php 1.5 KB

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