Document.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <?php
  2. /**
  3. * 会员协议管理
  4. */
  5. namespace app\admin\controller;
  6. use think\facade\View;
  7. use think\facade\Lang;
  8. /**
  9. *
  10. *
  11. * ----------------------------------------------------------------------------
  12. *
  13. * 控制器
  14. */
  15. class Document extends AdminControl
  16. {
  17. public function initialize()
  18. {
  19. parent::initialize(); // TODO: Change the autogenerated stub
  20. Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/document.lang.php');
  21. }
  22. /**
  23. * 系统文章管理首页
  24. */
  25. public function index()
  26. {
  27. $document_model = model('document');
  28. $doc_list = $document_model->getDocumentList();
  29. View::assign('doc_list', $doc_list);
  30. $this->setAdminCurItem('index');
  31. return View::fetch();
  32. }
  33. /**
  34. * 系统文章编辑
  35. */
  36. public function edit()
  37. {
  38. if (request()->isPost()) {
  39. /**
  40. * 验证
  41. */
  42. $data = [
  43. 'document_title' => input('post.document_title'),
  44. 'document_content' => input('post.document_content'),
  45. ];
  46. $document_validate = ds_validate('document');
  47. if (!$document_validate->scene('edit')->check($data)) {
  48. $this->error($document_validate->getError());
  49. } else {
  50. $param = array();
  51. $param['document_id'] = intval(input('document_id'));
  52. $param['document_title'] = trim(input('document_title'));
  53. $param['document_content'] = trim(input('document_content'));
  54. $param['document_time'] = TIMESTAMP;
  55. $document_model = model('document');
  56. $result = $document_model->editDocument($param);
  57. if ($result) {
  58. /**
  59. * 更新图片信息ID
  60. */
  61. $upload_model = model('upload');
  62. $file_id_array = input('post.file_id/a');
  63. if (is_array($file_id_array) && !empty($file_id_array)) {
  64. foreach ($file_id_array as $k => $v) {
  65. $v = intval($v);
  66. $update_array = array();
  67. $update_array['item_id'] = intval(input('document_id'));
  68. $upload_model->editUpload($update_array, array(array('upload_id', '=', intval($v))));
  69. unset($update_array);
  70. }
  71. }
  72. $this->log(lang('ds_edit') . lang('document_index_document') . '[ID:' . input('document_id') . ']', 1);
  73. $this->success(lang('ds_common_save_succ'), 'document/index');
  74. } else {
  75. $this->error(lang('ds_common_save_fail'));
  76. }
  77. }
  78. } else {
  79. if (empty(input('param.document_id'))) {
  80. $this->error(lang('miss_argument'));
  81. }
  82. $document_model = model('document');
  83. $doc = $document_model->getOneDocumentById(intval(input('param.document_id')));
  84. /**
  85. * 模型实例化
  86. */
  87. $upload_model = model('upload');
  88. $condition = array();
  89. $condition[] = array('upload_type', '=', '4');
  90. $condition[] = array('item_id', '=', $doc['document_id']);
  91. $file_upload = $upload_model->getUploadList($condition);
  92. if (is_array($file_upload)) {
  93. foreach ($file_upload as $k => $v) {
  94. $file_upload[$k]['upload_path'] = $file_upload[$k]['file_name'];
  95. }
  96. }
  97. View::assign('PHPSESSID', session_id());
  98. View::assign('file_upload', $file_upload);
  99. View::assign('doc', $doc);
  100. $this->setAdminCurItem('edit');
  101. return View::fetch();
  102. }
  103. }
  104. /**
  105. * 系统文章图片上传
  106. */
  107. public function document_pic_upload()
  108. {
  109. /**
  110. * 上传图片
  111. */
  112. $file_name = '';
  113. $file_object = request()->file('fileupload');
  114. if ($file_object) {
  115. $res = ds_upload_pic(ATTACH_ARTICLE, 'fileupload');
  116. if ($res['code']) {
  117. $file_name = $res['data']['file_name'];
  118. } else {
  119. echo $res['msg'];
  120. exit;
  121. }
  122. } else {
  123. echo 'error';
  124. exit;
  125. }
  126. /**
  127. * 模型实例化
  128. */
  129. $upload_model = model('upload');
  130. /**
  131. * 图片数据入库
  132. */
  133. $insert_array = array();
  134. $insert_array['file_name'] = $file_name;
  135. $insert_array['upload_type'] = '4';
  136. $insert_array['file_size'] = $_FILES['fileupload']['size'];
  137. $insert_array['item_id'] = intval(input('param.item_id'));
  138. $insert_array['upload_time'] = TIMESTAMP;
  139. $result = $upload_model->addUpload($insert_array);
  140. if ($result) {
  141. $data = array();
  142. $data['file_id'] = $result;
  143. $data['file_name'] = $file_name;
  144. $data['file_path'] = ds_get_pic(ATTACH_ARTICLE, $file_name);
  145. /**
  146. * 整理为json格式
  147. */
  148. $output = json_encode($data);
  149. echo $output;
  150. }
  151. }
  152. /**
  153. * ajax操作
  154. */
  155. public function ajax()
  156. {
  157. switch (input('param.branch')) {
  158. /**
  159. * 删除文章图片
  160. */
  161. case 'del_file_upload':
  162. if (intval(input('param.file_id')) > 0) {
  163. $upload_model = model('upload');
  164. /**
  165. * 删除图片
  166. */
  167. $file_array = $upload_model->getOneUpload(intval(input('param.file_id')));
  168. @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_ARTICLE . DIRECTORY_SEPARATOR . $file_array['file_name']);
  169. /**
  170. * 删除信息
  171. */
  172. $condition = array();
  173. $condition[] = array('upload_id', '=', intval(input('param.file_id')));
  174. $upload_model->delUpload($condition);
  175. echo 'true';
  176. exit;
  177. } else {
  178. echo 'false';
  179. exit;
  180. }
  181. break;
  182. }
  183. }
  184. /**
  185. * 获取卖家栏目列表,针对控制器下的栏目
  186. */
  187. protected function getAdminItemList()
  188. {
  189. $menu_array = array(
  190. array(
  191. 'name' => 'index', 'text' => lang('ds_manage'), 'url' => (string) url('Document/index')
  192. ),
  193. );
  194. if (request()->action() == 'edit') {
  195. $menu_array[] = array(
  196. 'name' => 'edit', 'text' => lang('ds_edit'), 'url' => 'javascript:void(0)'
  197. );
  198. }
  199. return $menu_array;
  200. }
  201. }