Types.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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\mobile\controller;
  15. use app\base\BaseController;
  16. use app\mobile\model\MobileTypes as MobileTypesModel;
  17. use app\mobile\validate\TypesValidate;
  18. use think\exception\ValidateException;
  19. use think\facade\Db;
  20. use think\facade\View;
  21. class Types extends BaseController
  22. {
  23. /**
  24. * 构造函数
  25. */
  26. protected $model;
  27. public function __construct()
  28. {
  29. parent::__construct(); // 调用父类构造函数
  30. $this->model = new MobileTypesModel();
  31. }
  32. /**
  33. * 数据列表
  34. */
  35. public function datalist()
  36. {
  37. if (request()->isAjax()) {
  38. $list = $this->model->order('sort asc')->select();
  39. return to_assign(0, '', $list);
  40. }
  41. else{
  42. return view();
  43. }
  44. }
  45. /**
  46. * 添加/编辑
  47. */
  48. public function add()
  49. {
  50. $param = get_params();
  51. if (request()->isAjax()) {
  52. if (!empty($param['id']) && $param['id'] > 0) {
  53. try {
  54. validate(TypesValidate::class)->scene('edit')->check($param);
  55. } catch (ValidateException $e) {
  56. // 验证失败 输出错误信息
  57. return to_assign(1, $e->getError());
  58. }
  59. $this->model->edit($param);
  60. } else {
  61. try {
  62. validate(TypesValidate::class)->scene('add')->check($param);
  63. } catch (ValidateException $e) {
  64. // 验证失败 输出错误信息
  65. return to_assign(1, $e->getError());
  66. }
  67. $this->model->add($param);
  68. }
  69. }else{
  70. $id = isset($param['id']) ? $param['id'] : 0;
  71. if ($id>0) {
  72. $detail = $this->model->getById($id);
  73. View::assign('detail', $detail);
  74. }
  75. return view();
  76. }
  77. }
  78. /**
  79. * 查看
  80. */
  81. public function view($id)
  82. {
  83. $detail = $this->model->getById($id);
  84. if (!empty($detail)) {
  85. View::assign('detail', $detail);
  86. return view();
  87. }
  88. else{
  89. return view(EEEOR_REPORTING,['code'=>404,'warning'=>'找不到页面']);
  90. }
  91. }
  92. /**
  93. * 删除
  94. */
  95. public function del()
  96. {
  97. if (request()->isDelete()) {
  98. $param = get_params();
  99. $id = isset($param['id']) ? $param['id'] : 0;
  100. $type = isset($param['type']) ? $param['type'] : 0;
  101. $this->model->delById($id,$type);
  102. } else {
  103. return to_assign(1, "错误的请求");
  104. }
  105. }
  106. /**
  107. * 设置
  108. */
  109. public function set()
  110. {
  111. if (request()->isAjax()) {
  112. $param = get_params();
  113. $res = $this->model->strict(false)->field('id,status')->update($param);
  114. if ($res) {
  115. if($param['status'] == 0){
  116. add_log('disable', $param['id'], $param);
  117. }
  118. else if($param['status'] == 1){
  119. add_log('recovery', $param['id'], $param);
  120. }
  121. return to_assign();
  122. }
  123. else{
  124. return to_assign(0, '操作失败');
  125. }
  126. } else {
  127. return to_assign(1, "错误的请求");
  128. }
  129. }
  130. }