News.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. /**
  3. +-----------------------------------------------------------------------------------------------
  4. * GouGuOPEN [ 左手研发,右手开源,未来可期!]
  5. +-----------------------------------------------------------------------------------------------
  6. * @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
  7. +-----------------------------------------------------------------------------------------------
  8. * @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
  9. +-----------------------------------------------------------------------------------------------
  10. * @Author 勾股工作室 <hdm58@qq.com>
  11. +-----------------------------------------------------------------------------------------------
  12. */
  13. declare (strict_types = 1);
  14. namespace app\adm\controller;
  15. use app\base\BaseController;
  16. use app\adm\model\News as NewsModel;
  17. use app\adm\validate\NewsValidate;
  18. use think\exception\ValidateException;
  19. use think\facade\Db;
  20. use think\facade\View;
  21. class News extends BaseController
  22. {
  23. /**
  24. * 构造函数
  25. */
  26. protected $model;
  27. public function __construct()
  28. {
  29. parent::__construct(); // 调用父类构造函数
  30. $this->model = new NewsModel();
  31. }
  32. /**
  33. * 数据列表
  34. */
  35. public function datalist()
  36. {
  37. $param = get_params();
  38. if (request()->isAjax()) {
  39. $where=[];
  40. $where[]=['delete_time','=',0];
  41. if (!empty($param['keywords'])) {
  42. $where[] = ['id|title', 'like', '%' . $param['keywords'] . '%'];
  43. }
  44. $list = $this->model->datalist($where, $param);
  45. return table_assign(0, '', $list);
  46. }
  47. else{
  48. return view();
  49. }
  50. }
  51. /**
  52. * 添加/编辑
  53. */
  54. public function add()
  55. {
  56. $param = get_params();
  57. if (request()->isAjax()) {
  58. if (!empty($param['id']) && $param['id'] > 0) {
  59. try {
  60. validate(NewsValidate::class)->scene('edit')->check($param);
  61. } catch (ValidateException $e) {
  62. // 验证失败 输出错误信息
  63. return to_assign(1, $e->getError());
  64. }
  65. $this->model->edit($param);
  66. } else {
  67. try {
  68. validate(NewsValidate::class)->scene('add')->check($param);
  69. } catch (ValidateException $e) {
  70. // 验证失败 输出错误信息
  71. return to_assign(1, $e->getError());
  72. }
  73. $param['admin_id']=$this->uid;
  74. $this->model->add($param);
  75. }
  76. }else{
  77. $id = isset($param['id']) ? $param['id'] : 0;
  78. if ($id>0) {
  79. $detail = $this->model->getById($id);
  80. if($detail['file_ids'] !=''){
  81. $file_array = Db::name('File')->where('id','in',$detail['file_ids'])->select();
  82. $detail['file_array'] = $file_array;
  83. }
  84. View::assign('detail', $detail);
  85. }
  86. View::assign('id', $id);
  87. return view();
  88. }
  89. }
  90. /**
  91. * 查看
  92. */
  93. public function view($id)
  94. {
  95. $detail = $this->model->getById($id);
  96. if (!empty($detail)) {
  97. $detail['cate'] = Db::name('NoteCate')->where(['id' => $detail['cate_id']])->value('title');
  98. $detail['admin_name'] = Db::name('Admin')->where(['id' => $detail['admin_id']])->value('name');
  99. if($detail['file_ids'] !=''){
  100. $file_array = Db::name('File')->where('id','in',$detail['file_ids'])->select();
  101. $detail['file_array'] = $file_array;
  102. }
  103. View::assign('detail', $detail);
  104. if(is_mobile()){
  105. return view('qiye@/index/view_news');
  106. }
  107. return view();
  108. }
  109. else{
  110. return view(EEEOR_REPORTING,['code'=>404,'warning'=>'找不到页面']);
  111. }
  112. }
  113. /**
  114. * 删除
  115. */
  116. public function del()
  117. {
  118. $param = get_params();
  119. $id = isset($param['id']) ? $param['id'] : 0;
  120. if (request()->isDelete()) {
  121. $this->model->delById($id);
  122. } else {
  123. return to_assign(1, "错误的请求");
  124. }
  125. }
  126. }