Note.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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\Note as NoteModel;
  17. use app\adm\validate\NoteValidate;
  18. use think\exception\ValidateException;
  19. use think\facade\Db;
  20. use think\facade\View;
  21. class Note extends BaseController
  22. {
  23. /**
  24. * 构造函数
  25. */
  26. protected $model;
  27. public function __construct()
  28. {
  29. parent::__construct(); // 调用父类构造函数
  30. $this->model = new NoteModel();
  31. }
  32. /**
  33. * 数据列表
  34. */
  35. public function datalist()
  36. {
  37. $param = get_params();
  38. if (request()->isAjax()) {
  39. $where=[];
  40. $where[]=['a.delete_time','=',0];
  41. if (!empty($param['keywords'])) {
  42. $where[] = ['a.id|a.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. $param['start_time'] = isset($param['start_time']) ? strtotime(urldecode($param['start_time'])) : 0;
  59. $param['end_time'] = isset($param['end_time']) ? strtotime(urldecode($param['end_time'])) : 0;
  60. if (!empty($param['id']) && $param['id'] > 0) {
  61. try {
  62. validate(NoteValidate::class)->scene('edit')->check($param);
  63. } catch (ValidateException $e) {
  64. // 验证失败 输出错误信息
  65. return to_assign(1, $e->getError());
  66. }
  67. $this->model->edit($param);
  68. } else {
  69. try {
  70. validate(NoteValidate::class)->scene('add')->check($param);
  71. } catch (ValidateException $e) {
  72. // 验证失败 输出错误信息
  73. return to_assign(1, $e->getError());
  74. }
  75. $param['admin_id']=$this->uid;
  76. $this->model->add($param);
  77. }
  78. }else{
  79. $id = isset($param['id']) ? $param['id'] : 0;
  80. if ($id>0) {
  81. $detail = $this->model->getById($id);
  82. if($detail['file_ids'] !=''){
  83. $file_array = Db::name('File')->where('id','in',$detail['file_ids'])->select();
  84. $detail['file_array'] = $file_array;
  85. }
  86. View::assign('detail', $detail);
  87. }
  88. View::assign('id', $id);
  89. if(is_mobile()){
  90. return view('qiye@/index/note_add');
  91. }
  92. return view();
  93. }
  94. }
  95. /**
  96. * 查看
  97. */
  98. public function view($id)
  99. {
  100. $detail = $this->model->getById($id);
  101. if (!empty($detail)) {
  102. $detail['cate'] = Db::name('NoteCate')->where(['id' => $detail['cate_id']])->value('title');
  103. $detail['admin_name'] = Db::name('Admin')->where(['id' => $detail['admin_id']])->value('name');
  104. if($detail['file_ids'] !=''){
  105. $file_array = Db::name('File')->where('id','in',$detail['file_ids'])->select();
  106. $detail['file_array'] = $file_array;
  107. }
  108. View::assign('detail', $detail);
  109. if(is_mobile()){
  110. return view('qiye@/index/note_view');
  111. }
  112. return view();
  113. }
  114. else{
  115. return view(EEEOR_REPORTING,['code'=>404,'warning'=>'找不到页面']);
  116. }
  117. }
  118. /**
  119. * 删除
  120. */
  121. public function del()
  122. {
  123. $param = get_params();
  124. $id = isset($param['id']) ? $param['id'] : 0;
  125. if (request()->isDelete()) {
  126. $this->model->delById($id);
  127. } else {
  128. return to_assign(1, "错误的请求");
  129. }
  130. }
  131. }