Document.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <?php
  2. /**
  3. * 会员协议管理
  4. */
  5. namespace app\admin\controller;
  6. use think\facade\View;
  7. use think\facade\Lang;
  8. /**
  9. * ============================================================================
  10. * DSMall多用户商城
  11. * ============================================================================
  12. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  13. * 网站地址: http://www.csdeshang.com
  14. * ----------------------------------------------------------------------------
  15. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  16. * 不允许对程序代码以任何形式任何目的的再发布。
  17. * ============================================================================
  18. * 控制器
  19. */
  20. class Document extends AdminControl {
  21. public function initialize() {
  22. parent::initialize(); // TODO: Change the autogenerated stub
  23. Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/document.lang.php');
  24. }
  25. /**
  26. * 系统文章管理首页
  27. */
  28. public function index() {
  29. $document_model = model('document');
  30. $doc_list = $document_model->getDocumentList();
  31. View::assign('doc_list', $doc_list);
  32. $this->setAdminCurItem('index');
  33. return View::fetch();
  34. }
  35. /**
  36. * 系统文章编辑
  37. */
  38. public function edit() {
  39. if (request()->isPost()) {
  40. /**
  41. * 验证
  42. */
  43. $data = [
  44. 'document_title' => input('post.document_title'),
  45. 'document_content' => input('post.document_content'),
  46. ];
  47. $document_validate = ds_validate('document');
  48. if (!$document_validate->scene('edit')->check($data)) {
  49. $this->error($document_validate->getError());
  50. } else {
  51. $param = array();
  52. $param['document_id'] = intval(input('document_id'));
  53. $param['document_title'] = trim(input('document_title'));
  54. $param['document_content'] = trim(input('document_content'));
  55. $param['document_time'] = TIMESTAMP;
  56. $document_model = model('document');
  57. $result = $document_model->editDocument($param);
  58. if ($result) {
  59. /**
  60. * 更新图片信息ID
  61. */
  62. $upload_model = model('upload');
  63. $file_id_array = input('post.file_id/a');
  64. if (is_array($file_id_array) && !empty($file_id_array)) {
  65. foreach ($file_id_array as $k => $v) {
  66. $v = intval($v);
  67. $update_array = array();
  68. $update_array['item_id'] = intval(input('document_id'));
  69. $upload_model->editUpload($update_array,array(array('upload_id','=',intval($v))));
  70. unset($update_array);
  71. }
  72. }
  73. $this->log(lang('ds_edit') . lang('document_index_document') . '[ID:' . input('document_id') . ']', 1);
  74. $this->success(lang('ds_common_save_succ'), 'document/index');
  75. } else {
  76. $this->error(lang('ds_common_save_fail'));
  77. }
  78. }
  79. } else {
  80. if (empty(input('param.document_id'))) {
  81. $this->error(lang('miss_argument'));
  82. }
  83. $document_model = model('document');
  84. $doc = $document_model->getOneDocumentById(intval(input('param.document_id')));
  85. /**
  86. * 模型实例化
  87. */
  88. $upload_model = model('upload');
  89. $condition = array();
  90. $condition[] = array('upload_type', '=', '4');
  91. $condition[] = array('item_id', '=', $doc['document_id']);
  92. $file_upload = $upload_model->getUploadList($condition);
  93. if (is_array($file_upload)) {
  94. foreach ($file_upload as $k => $v) {
  95. $file_upload[$k]['upload_path'] = $file_upload[$k]['file_name'];
  96. }
  97. }
  98. View::assign('PHPSESSID', session_id());
  99. View::assign('file_upload', $file_upload);
  100. View::assign('doc', $doc);
  101. $this->setAdminCurItem('edit');
  102. return View::fetch();
  103. }
  104. }
  105. /**
  106. * 系统文章图片上传
  107. */
  108. public function document_pic_upload() {
  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. switch (input('param.branch')) {
  157. /**
  158. * 删除文章图片
  159. */
  160. case 'del_file_upload':
  161. if (intval(input('param.file_id')) > 0) {
  162. $upload_model = model('upload');
  163. /**
  164. * 删除图片
  165. */
  166. $file_array = $upload_model->getOneUpload(intval(input('param.file_id')));
  167. @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_ARTICLE . DIRECTORY_SEPARATOR . $file_array['file_name']);
  168. /**
  169. * 删除信息
  170. */
  171. $condition = array();
  172. $condition[] = array('upload_id', '=', intval(input('param.file_id')));
  173. $upload_model->delUpload($condition);
  174. echo 'true';
  175. exit;
  176. } else {
  177. echo 'false';
  178. exit;
  179. }
  180. break;
  181. }
  182. }
  183. /**
  184. * 获取卖家栏目列表,针对控制器下的栏目
  185. */
  186. protected function getAdminItemList() {
  187. $menu_array = array(
  188. array(
  189. 'name' => 'index', 'text' => lang('ds_manage'), 'url' => (string) url('Document/index')
  190. ),
  191. );
  192. if (request()->action() == 'edit') {
  193. $menu_array[] = array(
  194. 'name' => 'edit', 'text' => lang('ds_edit'), 'url' => 'javascript:void(0)'
  195. );
  196. }
  197. return $menu_array;
  198. }
  199. }