Document.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  13. * 网站地址: https://www.valimart.net/
  14. * ----------------------------------------------------------------------------
  15. *
  16. * ============================================================================
  17. * 控制器
  18. */
  19. class Document extends AdminControl {
  20. public function initialize() {
  21. parent::initialize(); // TODO: Change the autogenerated stub
  22. Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/document.lang.php');
  23. }
  24. /**
  25. * 系统文章管理首页
  26. */
  27. public function index() {
  28. $document_model = model('document');
  29. $doc_list = $document_model->getDocumentList();
  30. View::assign('doc_list', $doc_list);
  31. $this->setAdminCurItem('index');
  32. return View::fetch();
  33. }
  34. /**
  35. * 系统文章编辑
  36. */
  37. public function edit() {
  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. $file_name = '';
  112. $file_object = request()->file('fileupload');
  113. if ($file_object) {
  114. $res=ds_upload_pic(ATTACH_ARTICLE,'fileupload');
  115. if($res['code']){
  116. $file_name=$res['data']['file_name'];
  117. }else{
  118. echo $res['msg'];
  119. exit;
  120. }
  121. } else {
  122. echo 'error';
  123. exit;
  124. }
  125. /**
  126. * 模型实例化
  127. */
  128. $upload_model = model('upload');
  129. /**
  130. * 图片数据入库
  131. */
  132. $insert_array = array();
  133. $insert_array['file_name'] = $file_name;
  134. $insert_array['upload_type'] = '4';
  135. $insert_array['file_size'] = $_FILES['fileupload']['size'];
  136. $insert_array['item_id'] = intval(input('param.item_id'));
  137. $insert_array['upload_time'] = TIMESTAMP;
  138. $result = $upload_model->addUpload($insert_array);
  139. if ($result) {
  140. $data = array();
  141. $data['file_id'] = $result;
  142. $data['file_name'] = $file_name;
  143. $data['file_path'] = ds_get_pic(ATTACH_ARTICLE , $file_name);
  144. /**
  145. * 整理为json格式
  146. */
  147. $output = json_encode($data);
  148. echo $output;
  149. }
  150. }
  151. /**
  152. * ajax操作
  153. */
  154. public function ajax() {
  155. switch (input('param.branch')) {
  156. /**
  157. * 删除文章图片
  158. */
  159. case 'del_file_upload':
  160. if (intval(input('param.file_id')) > 0) {
  161. $upload_model = model('upload');
  162. /**
  163. * 删除图片
  164. */
  165. $file_array = $upload_model->getOneUpload(intval(input('param.file_id')));
  166. @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_ARTICLE . DIRECTORY_SEPARATOR . $file_array['file_name']);
  167. /**
  168. * 删除信息
  169. */
  170. $condition = array();
  171. $condition[] = array('upload_id', '=', intval(input('param.file_id')));
  172. $upload_model->delUpload($condition);
  173. echo 'true';
  174. exit;
  175. } else {
  176. echo 'false';
  177. exit;
  178. }
  179. break;
  180. }
  181. }
  182. /**
  183. * 获取卖家栏目列表,针对控制器下的栏目
  184. */
  185. protected function getAdminItemList() {
  186. $menu_array = array(
  187. array(
  188. 'name' => 'index', 'text' => lang('ds_manage'), 'url' => (string) url('Document/index')
  189. ),
  190. );
  191. if (request()->action() == 'edit') {
  192. $menu_array[] = array(
  193. 'name' => 'edit', 'text' => lang('ds_edit'), 'url' => 'javascript:void(0)'
  194. );
  195. }
  196. return $menu_array;
  197. }
  198. }