Template.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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\home\controller;
  15. use app\base\BaseController;
  16. use app\home\model\Template as TemplateModel;
  17. use app\home\validate\TemplateValidate;
  18. use think\exception\ValidateException;
  19. use think\facade\Db;
  20. use think\facade\View;
  21. class Template extends BaseController
  22. {
  23. /**
  24. * 构造函数
  25. */
  26. protected $model;
  27. public function __construct()
  28. {
  29. parent::__construct(); // 调用父类构造函数
  30. $this->model = new TemplateModel();
  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(TemplateValidate::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(TemplateValidate::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. $copyid = isset($param['copyid']) ? $param['copyid'] : 0;
  79. if ($id>0) {
  80. $detail = $this->model->getById($id);
  81. View::assign('detail', $detail);
  82. }
  83. if ($copyid>0) {
  84. $detail = $this->model->getById($copyid);
  85. View::assign('detail', $detail);
  86. }
  87. View::assign('copyid', $copyid);
  88. return view();
  89. }
  90. }
  91. /**
  92. * 查看
  93. */
  94. public function view($id)
  95. {
  96. $detail = $this->model->getById($id);
  97. if (!empty($detail)) {
  98. View::assign('detail', $detail);
  99. return view();
  100. }
  101. else{
  102. return view(EEEOR_REPORTING,['code'=>404,'warning'=>'找不到页面']);
  103. }
  104. }
  105. /**
  106. * 删除
  107. */
  108. public function del()
  109. {
  110. $param = get_params();
  111. $id = isset($param['id']) ? $param['id'] : 0;
  112. if (request()->isDelete()) {
  113. $this->model->delById($id);
  114. } else {
  115. return to_assign(1, "错误的请求");
  116. }
  117. }
  118. //设置
  119. public function set()
  120. {
  121. $param = get_params();
  122. $res = $this->model::field('id,status')->update($param);
  123. if ($res) {
  124. if($param['status'] == 0){
  125. add_log('disable', $param['id'], $param);
  126. }
  127. else if($param['status'] == 1){
  128. add_log('recovery', $param['id'], $param);
  129. }
  130. return to_assign();
  131. }
  132. else{
  133. return to_assign(0, '操作失败');
  134. }
  135. }
  136. }