Menu.php 3.9 KB

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