Attachment.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. if ($this->request->isAjax())
  24. {
  25. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  26. $total = $this->model
  27. ->where($where)
  28. ->order($sort, $order)
  29. ->count();
  30. $list = $this->model
  31. ->where($where)
  32. ->order($sort, $order)
  33. ->limit($offset, $limit)
  34. ->select();
  35. $cdnurl = preg_replace("/\/(\w+)\.php$/i", '', $this->request->root());
  36. foreach ($list as $k => &$v)
  37. {
  38. $v['fullurl'] = ($v['storage'] == 'local' ? $cdnurl : $this->view->config['upload']['cdnurl']) . $v['url'];
  39. }
  40. unset($v);
  41. $result = array("total" => $total, "rows" => $list);
  42. return json($result);
  43. }
  44. return $this->view->fetch();
  45. }
  46. /**
  47. * 选择附件
  48. */
  49. public function select()
  50. {
  51. if ($this->request->isAjax())
  52. {
  53. return $this->index();
  54. }
  55. return $this->view->fetch();
  56. }
  57. /**
  58. * 添加
  59. */
  60. public function add()
  61. {
  62. if ($this->request->isAjax())
  63. {
  64. $this->error();
  65. }
  66. return $this->view->fetch();
  67. }
  68. public function del($ids = "")
  69. {
  70. if ($ids)
  71. {
  72. $count = $this->model->destroy($ids);
  73. if ($count)
  74. {
  75. \think\Hook::listen("upload_after", $this);
  76. $this->success();
  77. }
  78. }
  79. $this->error(__('Parameter %s can not be empty', 'ids'));
  80. }
  81. }