Attachment.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace app\admin\controller\general;
  3. use app\common\controller\Backend;
  4. /**
  5. * 附件管理
  6. *
  7. * @icon fa fa-circle-o
  8. * @remark 主要用于管理上传到又拍云的数据或上传至本服务的上传数据
  9. */
  10. class Attachment extends Backend
  11. {
  12. protected $model = null;
  13. public function _initialize()
  14. {
  15. parent::_initialize();
  16. $this->model = model('Attachment');
  17. }
  18. /**
  19. * 查看
  20. */
  21. public function index()
  22. {
  23. //设置过滤方法
  24. $this->request->filter(['strip_tags']);
  25. if ($this->request->isAjax())
  26. {
  27. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  28. $total = $this->model
  29. ->where($where)
  30. ->order($sort, $order)
  31. ->count();
  32. $list = $this->model
  33. ->where($where)
  34. ->order($sort, $order)
  35. ->limit($offset, $limit)
  36. ->select();
  37. $cdnurl = preg_replace("/\/(\w+)\.php$/i", '', $this->request->root());
  38. foreach ($list as $k => &$v)
  39. {
  40. $v['fullurl'] = ($v['storage'] == 'local' ? $cdnurl : $this->view->config['upload']['cdnurl']) . $v['url'];
  41. }
  42. unset($v);
  43. $result = array("total" => $total, "rows" => $list);
  44. return json($result);
  45. }
  46. return $this->view->fetch();
  47. }
  48. /**
  49. * 选择附件
  50. */
  51. public function select()
  52. {
  53. if ($this->request->isAjax())
  54. {
  55. return $this->index();
  56. }
  57. return $this->view->fetch();
  58. }
  59. /**
  60. * 添加
  61. */
  62. public function add()
  63. {
  64. if ($this->request->isAjax())
  65. {
  66. $this->error();
  67. }
  68. return $this->view->fetch();
  69. }
  70. public function del($ids = "")
  71. {
  72. if ($ids)
  73. {
  74. $count = $this->model->destroy($ids);
  75. if ($count)
  76. {
  77. \think\Hook::listen("upload_after", $this);
  78. $this->success();
  79. }
  80. }
  81. $this->error(__('Parameter %s can not be empty', 'ids'));
  82. }
  83. }