controller.tpl 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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\<module>\controller;
  15. use app\base\BaseController;
  16. use app\<module>\model\<Bmodel> as <Bmodel>Model;
  17. use app\<module>\validate\<Bcontroller>Validate;
  18. use think\exception\ValidateException;
  19. use think\facade\Db;
  20. use think\facade\View;
  21. class <Bcontroller> extends BaseController
  22. {
  23. /**
  24. * 构造函数
  25. */
  26. protected $model;
  27. public function __construct()
  28. {
  29. parent::__construct(); // 调用父类构造函数
  30. $this->model = new <Bmodel>Model();
  31. }
  32. /**
  33. * 数据列表
  34. */
  35. public function datalist()
  36. {
  37. $param = get_params();
  38. if (request()->isAjax()) {
  39. $where=[];
  40. $whereOr=[];
  41. $where[]=['delete_time','=',0];
  42. if (!empty($param['keywords'])) {
  43. $where[] = ['id|title', 'like', '%' . $param['keywords'] . '%'];
  44. }
  45. $list = $this->model->datalist($param,$where,$whereOr);
  46. return table_assign(0, '', $list);
  47. }
  48. else{
  49. return view();
  50. }
  51. }
  52. /**
  53. * 添加/编辑
  54. */
  55. public function add()
  56. {
  57. $param = get_params();
  58. if (request()->isAjax()) {
  59. if (!empty($param['id']) && $param['id'] > 0) {
  60. try {
  61. validate(<Bcontroller>Validate::class)->scene('edit')->check($param);
  62. } catch (ValidateException $e) {
  63. // 验证失败 输出错误信息
  64. return to_assign(1, $e->getError());
  65. }
  66. $this->model->edit($param);
  67. } else {
  68. try {
  69. validate(<Bcontroller>Validate::class)->scene('add')->check($param);
  70. } catch (ValidateException $e) {
  71. // 验证失败 输出错误信息
  72. return to_assign(1, $e->getError());
  73. }
  74. $param['admin_id'] = $this->uid;
  75. $this->model->add($param);
  76. }
  77. }else{
  78. $id = isset($param['id']) ? $param['id'] : 0;
  79. if ($id>0) {
  80. $detail = $this->model->getById($id);
  81. View::assign('detail', $detail);
  82. }
  83. return view();
  84. }
  85. }
  86. /**
  87. * 查看
  88. */
  89. public function view($id)
  90. {
  91. $detail = $this->model->getById($id);
  92. if (!empty($detail)) {
  93. View::assign('detail', $detail);
  94. return view();
  95. }
  96. else{
  97. return view(EEEOR_REPORTING,['code'=>404,'warning'=>'找不到页面']);
  98. }
  99. }
  100. /**
  101. * 删除
  102. */
  103. public function del()
  104. {
  105. if (request()->isDelete()) {
  106. $param = get_params();
  107. $id = isset($param['id']) ? $param['id'] : 0;
  108. $this->model->delById($id);
  109. } else {
  110. return to_assign(1, "错误的请求");
  111. }
  112. }
  113. }