Attachment.php 4.6 KB

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