UploadGroup.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace app\common\model\file;
  3. use app\common\model\BaseModel;
  4. use app\shop\model\file\UploadFile;
  5. /**
  6. * 文件库分组模型
  7. */
  8. class UploadGroup extends BaseModel
  9. {
  10. protected $name = 'upload_group';
  11. protected $pk = 'group_id';
  12. /**
  13. * 分组详情
  14. */
  15. public static function detail($group_id, $shop_supplier_id = 0) {
  16. return (new static())->where('shop_supplier_id', '=', $shop_supplier_id)->find($group_id);
  17. }
  18. /**
  19. * 获取列表记录
  20. */
  21. public function getList($groupType = '', $shop_supplier_id = 0)
  22. {
  23. $model = $this;
  24. !empty($groupType) && $model = $model->where('group_type', '=', trim($groupType));
  25. return $model->where('shop_supplier_id', '=', $shop_supplier_id)
  26. ->where('is_delete', '=', 0)
  27. ->order(['sort' => 'asc', 'create_time' => 'desc'])
  28. ->select();
  29. }
  30. /**
  31. * 添加新记录
  32. */
  33. public function add($data)
  34. {
  35. return $this->save(array_merge([
  36. 'app_id' => self::$app_id,
  37. 'sort' => 100
  38. ], $data));
  39. }
  40. /**
  41. * 更新记录
  42. */
  43. public function edit($data)
  44. {
  45. return $this->save($data) !== false;
  46. }
  47. /**
  48. * 删除记录
  49. */
  50. public function remove()
  51. {
  52. // 更新该分组下的所有文件
  53. (new UploadFile())->where('group_id', '=', $this['group_id'])
  54. ->update(['group_id' => 0]);
  55. // 删除分组
  56. return $this->save(['is_delete' => 1]);
  57. }
  58. }