GroupController.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?php
  2. namespace app\system\controller;
  3. use app\BaseController;
  4. use app\model\api\GroupModel;
  5. use think\facade\Request;
  6. use think\model;
  7. class GroupController extends BaseController
  8. {
  9. /**
  10. * 分组列表
  11. *
  12. * @return mixed
  13. */
  14. public function index()
  15. {
  16. $title = Request::param('title');
  17. $page = Request::param('page', 1, 'intval');
  18. $pagesize = Request::param('pagesize', 10, 'intval');
  19. $groupModel = new GroupModel();
  20. $query = $groupModel->order('gr_id ASC');
  21. if (!empty($title)) {
  22. $query->whereLike('title', '%' . $title . '%');
  23. }
  24. $list = $query->paginate([
  25. 'page' => $page,
  26. 'list_rows' => $pagesize,
  27. ]);
  28. $data = [
  29. 'list' => $list->items(),
  30. 'total' => $list->total(),
  31. 'page' => $list->currentPage(),
  32. 'pagesize' => $list->listRows(),
  33. ];
  34. return app('json')->success($data);
  35. }
  36. /**
  37. * 添加分组信息
  38. * @param Request $request
  39. * @return mixed
  40. */
  41. public function add(Request $request)
  42. {
  43. $uname = Request::param('uname');
  44. $type1 = Request::param('type1');
  45. $type2 = Request::param('type2');
  46. $title = Request::param('title');
  47. $ins = Request::param('ins');
  48. $indeximg = Request::param('indeximg');
  49. $data = [
  50. 'uname' => $uname,
  51. 'type1' => $type1,
  52. 'type2' => $type2,
  53. 'title' => $title,
  54. 'ins' => $ins,
  55. 'indeximg' => $indeximg,
  56. ];
  57. $groupModel = new GroupModel();
  58. $result = $groupModel->addGroups($data);
  59. if ($result !== false) {
  60. return json(['code' => 0, 'msg' => '添加成功']);
  61. }
  62. return json(['code' => 1, 'msg' => '添加失败']);
  63. }
  64. /**
  65. * 编辑分组信息
  66. * @param Request $request
  67. * @return mixed
  68. */
  69. public function edit(Request $request)
  70. {
  71. $grId = Request::param('gr_id');
  72. $uname = Request::param('uname');
  73. $type1 = Request::param('type1');
  74. $type2 = Request::param('type2');
  75. $title = Request::param('title');
  76. $ins = Request::param('ins');
  77. $indeximg = Request::param('indeximg');
  78. $data = [
  79. 'gr_id' => $grId,
  80. 'uname' => $uname,
  81. 'type1' => $type1,
  82. 'type2' => $type2,
  83. 'title' => $title,
  84. 'ins' => $ins,
  85. 'indeximg' => $indeximg,
  86. ];
  87. $groupModel = new GroupModel();
  88. $result = $groupModel->updateGroups($grId, $data);
  89. if ($result !== false) {
  90. return json(['code' => 0, 'msg' => '保存成功']);
  91. }
  92. return json(['code' => 1, 'msg' => '保存失败']);
  93. }
  94. /**
  95. * 修改审核状态
  96. * @return mixed
  97. */
  98. public function changeStatus()
  99. {
  100. $gr_id = Request::param('gr_id');
  101. $audit = Request::param('audit');
  102. $courseModel = new GroupModel();
  103. $result = $courseModel->updateAuditStatus($gr_id, ['audit' => $audit]);
  104. if ($result !== false) {
  105. return app('json')->success();
  106. } else {
  107. return app('json')->fail();
  108. }
  109. }
  110. /**
  111. * 修改是否轮播状态Recommend
  112. *
  113. * @return mixed|\think\response\Json
  114. */
  115. public function changeRecommend()
  116. {
  117. $gr_id = Request::param('gr_id');
  118. $recommend = Request::param('recommend');
  119. $courseModel = new GroupModel();
  120. $result = $courseModel->updateAuditStatus($gr_id, ['recommend' => $recommend]);
  121. if ($result !== false) {
  122. return app('json')->success();
  123. } else {
  124. return app('json')->fail();
  125. }
  126. }
  127. /**
  128. * 删除分组
  129. *
  130. * @param Request $request
  131. * @return mixed|\think\response\Json
  132. */
  133. public function delete(Request $request)
  134. {
  135. $id = $request->param('id/d', 0);
  136. if (!$id) {
  137. return json(['code' => -1, 'msg' => '参数错误']);
  138. }
  139. $groupModel = new GroupModel();
  140. $result = $groupModel->where('gr_id', $id)->delete();
  141. if ($result) {
  142. return json(['code' => 0, 'msg' => '删除成功']);
  143. } else {
  144. return json(['code' => -1, 'msg' => '删除失败']);
  145. }
  146. }
  147. }