Attachment.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. if (filter_var($v['url'], FILTER_VALIDATE_URL)) { //验证路径是否为完整URL格式
  41. $v['fullurl'] = $v['url'];
  42. } else {
  43. $v['fullurl'] = ($v['storage'] == 'local' ? $cdnurl : $this->view->config['upload']['cdnurl']) . $v['url'];
  44. }
  45. }
  46. unset($v);
  47. $result = array("total" => $total, "rows" => $list);
  48. return json($result);
  49. }
  50. return $this->view->fetch();
  51. }
  52. /**
  53. * 选择附件
  54. */
  55. public function select()
  56. {
  57. if ($this->request->isAjax())
  58. {
  59. return $this->index();
  60. }
  61. return $this->view->fetch();
  62. }
  63. /**
  64. * 添加
  65. */
  66. public function add()
  67. {
  68. if ($this->request->isAjax())
  69. {
  70. $this->error();
  71. }
  72. return $this->view->fetch();
  73. }
  74. public function del($ids = "")
  75. {
  76. if ($ids)
  77. {
  78. $count = $this->model->destroy($ids);
  79. if ($count)
  80. {
  81. \think\Hook::listen("upload_after", $this);
  82. $this->success();
  83. }
  84. }
  85. $this->error(__('Parameter %s can not be empty', 'ids'));
  86. }
  87. }