Attachment.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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->code = -1;
  65. }
  66. return $this->view->fetch();
  67. }
  68. }