Attachment.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. $result = array("total" => $total, "rows" => $list);
  36. return json($result);
  37. }
  38. return $this->view->fetch();
  39. }
  40. /**
  41. * 添加
  42. */
  43. public function add()
  44. {
  45. if ($this->request->isPost())
  46. {
  47. $this->code = -1;
  48. $params = $this->request->post("row/a");
  49. if ($params)
  50. {
  51. if ($this->request->has('field'))
  52. {
  53. //JSON字段
  54. $fieldarr = $valuearr = [];
  55. $field = $this->request->post('field/a');
  56. $value = $this->request->post('value/a');
  57. foreach ($field as $k => $v)
  58. {
  59. if ($v != '')
  60. {
  61. $fieldarr[] = $field[$k];
  62. $valuearr[] = $value[$k];
  63. }
  64. }
  65. $params['content'] = array_combine($fieldarr, $valuearr);
  66. }
  67. $this->model->save($params);
  68. $this->code = 1;
  69. }
  70. return;
  71. }
  72. return $this->view->fetch();
  73. }
  74. /**
  75. * 编辑
  76. */
  77. public function edit($ids = NULL)
  78. {
  79. $row = $this->model->get(['id' => $ids]);
  80. if (!$row)
  81. $this->error(__('No Results were found'));
  82. if ($this->request->isPost())
  83. {
  84. $this->code = -1;
  85. $params = $this->request->post("row/a");
  86. if ($params)
  87. {
  88. $row->save($params);
  89. $this->code = 1;
  90. }
  91. return;
  92. }
  93. $this->view->assign("row", $row);
  94. return $this->view->fetch();
  95. }
  96. /**
  97. * 删除
  98. */
  99. public function del($ids = "")
  100. {
  101. $this->code = -1;
  102. if ($ids)
  103. {
  104. $count = $this->model->where('id', 'in', $ids)->delete();
  105. if ($count)
  106. {
  107. $this->code = 1;
  108. }
  109. }
  110. return;
  111. }
  112. /**
  113. * 批量更新
  114. */
  115. public function multi($ids = "")
  116. {
  117. $this->code = -1;
  118. $ids = $ids ? $ids : $this->request->param("ids");
  119. if ($ids)
  120. {
  121. if ($this->request->has('params'))
  122. {
  123. parse_str($this->request->post("params"), $values);
  124. $values = array_intersect_key($values, array_flip(array('status')));
  125. if ($values)
  126. {
  127. $count = $this->model->where('id', 'in', $ids)->update($values);
  128. if ($count)
  129. {
  130. $this->code = 1;
  131. }
  132. }
  133. }
  134. else
  135. {
  136. $this->code = 1;
  137. }
  138. }
  139. return;
  140. }
  141. }