Manage.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php namespace Upload\Api;
  2. use Dever;
  3. use Manage\Lib\Auth;
  4. class Manage extends Auth
  5. {
  6. # 获取图片组件信息
  7. public function getImage($value = false)
  8. {
  9. Dever::project('image');
  10. $result = array();
  11. $option = array();
  12. if ($value == 1) {
  13. $option = Dever::db('thumb', 'image')->select([]);
  14. } elseif ($value == 2) {
  15. $option = Dever::db('crop', 'image')->select([]);
  16. } elseif ($value == 3) {
  17. $option = Dever::db('water_pic', 'image')->select([]);
  18. } elseif ($value == 4) {
  19. $option = Dever::db('water_txt', 'image')->select([]);
  20. }
  21. $result['type_id']['type'] = 'select';
  22. $result['type_id']['option'] = $option;
  23. $result['type_id']['value'] = $option[0]['id'] ?? '';
  24. return $result;
  25. }
  26. # 删除文件
  27. public function upFileStatus()
  28. {
  29. $rule_id = Dever::input('id');
  30. $id = Dever::input('file_id');
  31. $status = Dever::input('status', 'is_numeric', '状态', 2);
  32. $user_id = Dever::load('util', 'upload')->getUser();
  33. return Dever::db('file', 'upload')->update(array('id' => $id, 'user_id' => $user_id), array('status' => $status));
  34. }
  35. # 彻底删除文件
  36. public function delFile()
  37. {
  38. $rule_id = Dever::input('id');
  39. $id = Dever::input('file_id');
  40. $user_id = Dever::load('util', 'upload')->getUser();
  41. $state = Dever::db('file', 'upload')->delete(array('id' => $id, 'status' => 2, 'user_id' => $user_id));
  42. if ($state) {
  43. # 同时删除文件
  44. }
  45. return 'ok';
  46. }
  47. # 添加文件
  48. public function addFile($id, $url, $file, $source, $name, $size)
  49. {
  50. $data = Dever::load('save', 'upload')->init($id)->addFile($url, $source, $name, $file, $size);
  51. return $data;
  52. }
  53. # 获取文件库文件列表
  54. public function getFileList()
  55. {
  56. $type = Dever::input('type', 'is_numeric', '类型', 0);
  57. $id = Dever::input('id', 'is_numeric', '上传规则错误', 1);
  58. $cate_id = Dever::input('cate_id', 'is_numeric', '上传分类', 1);
  59. $group_id = Dever::load('util', 'upload')->getGroup();
  60. $user_id = Dever::load('util', 'upload')->getUser();
  61. $file = Dever::input('file');
  62. $data = Dever::input();
  63. $set = array();
  64. $set['num'] = 10;
  65. $where['rule_id'] = $id;
  66. $where['status'] = 1;
  67. #$where['cate_id'] = $cate_id;
  68. if ($type == 1) {
  69. $where['group_id'] = $group_id;
  70. } elseif ($type == 2) {
  71. $where['user_id'] = $user_id;
  72. } elseif ($type == 4) {
  73. $where['status'] = 2;
  74. }
  75. $result['file'] = Dever::db('file', 'upload')->select($where, $set);
  76. if ($result['file']) {
  77. foreach ($result['file'] as &$v) {
  78. if ($v['source_name']) {
  79. $v['name'] = $v['source_name'];
  80. }
  81. $v['url'] = Dever::load('view', 'upload')->getUrl($v);
  82. $v['class'] = '';
  83. $v['del'] = 2;
  84. if ($user_id == $v['user_id']) {
  85. $v['del'] = 1;
  86. }
  87. if ($file) {
  88. foreach ($file as $v1) {
  89. if ($v1 && $v1['url'] == $v['url']) {
  90. $v['class'] = 'show-image-active';
  91. }
  92. }
  93. }
  94. }
  95. }
  96. $result['total'] = Dever::page('total');
  97. return $result;
  98. }
  99. }