Attachment.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  54. $total = $this->model
  55. ->where($where)
  56. ->order($sort, $order)
  57. ->count();
  58. $list = $this->model
  59. ->where($where)
  60. ->order($sort, $order)
  61. ->limit($offset, $limit)
  62. ->select();
  63. $result = array("total" => $total, "rows" => $list);
  64. return json($result);
  65. }
  66. return $this->view->fetch();
  67. }
  68. /**
  69. * 添加
  70. */
  71. public function add()
  72. {
  73. if ($this->request->isPost())
  74. {
  75. $this->code = -1;
  76. $params = $this->request->post("row/a");
  77. if ($params)
  78. {
  79. if ($this->request->has('field'))
  80. {
  81. //JSON字段
  82. $fieldarr = $valuearr = [];
  83. $field = $this->request->post('field/a');
  84. $value = $this->request->post('value/a');
  85. foreach ($field as $k => $v)
  86. {
  87. if ($v != '')
  88. {
  89. $fieldarr[] = $field[$k];
  90. $valuearr[] = $value[$k];
  91. }
  92. }
  93. $params['content'] = array_combine($fieldarr, $valuearr);
  94. }
  95. $this->model->save($params);
  96. $this->code = 1;
  97. }
  98. return;
  99. }
  100. return $this->view->fetch();
  101. }
  102. /**
  103. * 编辑
  104. */
  105. public function edit($ids = NULL)
  106. {
  107. $row = $this->model->get(['id' => $ids]);
  108. if (!$row)
  109. $this->error(__('No Results were found'));
  110. if ($this->request->isPost())
  111. {
  112. $this->code = -1;
  113. $params = $this->request->post("row/a");
  114. if ($params)
  115. {
  116. $row->save($params);
  117. $this->code = 1;
  118. }
  119. return;
  120. }
  121. $this->view->assign("row", $row);
  122. return $this->view->fetch();
  123. }
  124. /**
  125. * 删除
  126. */
  127. public function del($ids = "")
  128. {
  129. $this->code = -1;
  130. if ($ids)
  131. {
  132. $count = $this->model->where('id', 'in', $ids)->delete();
  133. if ($count)
  134. {
  135. $this->code = 1;
  136. }
  137. }
  138. return;
  139. }
  140. /**
  141. * 批量更新
  142. */
  143. public function multi($ids = "")
  144. {
  145. $this->code = -1;
  146. $ids = $ids ? $ids : $this->request->param("ids");
  147. if ($ids)
  148. {
  149. if ($this->request->has('params'))
  150. {
  151. parse_str($this->request->post("params"), $values);
  152. $values = array_intersect_key($values, array_flip(array('status')));
  153. if ($values)
  154. {
  155. $count = $this->model->where('id', 'in', $ids)->update($values);
  156. if ($count)
  157. {
  158. $this->code = 1;
  159. }
  160. }
  161. }
  162. else
  163. {
  164. $this->code = 1;
  165. }
  166. }
  167. return;
  168. }
  169. }