HelpController.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. namespace App\Http\Controllers\Manage\Help;
  3. use App\Http\Controllers\Manage\Help\Transformers\HelpTransformer;
  4. use App\Modules\Help\Services\HelpService;
  5. use Illuminate\Http\Request;
  6. use App\Http\Controllers\Controller;
  7. class HelpController extends Controller
  8. {
  9. /**
  10. * @apiDefine Help 帮助
  11. */
  12. /**
  13. * @apiVersion 1.0.0
  14. * @apiDescription 获取帮助
  15. * @api {get} help/getAllHelpList 获取帮助
  16. * @apiGroup Help
  17. * @apiName getAllHelpList
  18. * @apiParam {string} status状态(enbale,disable)
  19. * @apiSuccess {int} code 状态码
  20. * @apiSuccess {String} msg 信息
  21. * @apiSuccess {object} data 结果集
  22. * @apiSuccess {object} data.id id
  23. * @apiSuccess {object} data.title 标题
  24. * @apiSuccess {object} data.content 内容
  25. * @apiSuccess {object} data.created_at 创建时间
  26. * @apiSuccess {object} data.updated_at 更新时间
  27. * @apiSuccess {object} data.is_enabled 是否启用(0不启用,1启用)
  28. * @apiSuccessExample {json} Success-Response:
  29. * HTTP/1.1 200 OK
  30. * {
  31. * code: 0,
  32. * msg: "",
  33. * data: {}
  34. * }
  35. */
  36. public function getAllHelpList(Request $request){
  37. $status = $request->get('is_enabled');
  38. $status_array = ['enbale'=>1,'disable'=>0];
  39. $where = [];
  40. if($status && isset($status_array[$status])){
  41. $where[] = ['is_enabled'=>$status_array[$status]];
  42. }
  43. $res = HelpService::getAllHelpList($where);
  44. return response()->pagination(new HelpTransformer(),$res);
  45. }
  46. /**
  47. * @apiVersion 1.0.0
  48. * @apiDescription 获取帮助
  49. * @api {get} help/getHelp/{id} 获取帮助
  50. * @apiGroup Help
  51. * @apiName getHelp
  52. * @apiSuccess {int} code 状态码
  53. * @apiSuccess {String} msg 信息
  54. * @apiSuccess {object} data 结果集
  55. * @apiSuccess {object} data.id id
  56. * @apiSuccess {object} data.title 标题
  57. * @apiSuccess {object} data.content 内容
  58. * @apiSuccess {object} data.created_at 创建时间
  59. * @apiSuccess {object} data.updated_at 更新时间
  60. * @apiSuccess {object} data.is_enabled 是否启用(0不启用,1启用)
  61. * @apiSuccessExample {json} Success-Response:
  62. * HTTP/1.1 200 OK
  63. * {
  64. * code: 0,
  65. * msg: "",
  66. * data: {}
  67. * }
  68. */
  69. public function getHelp($id){
  70. return response()->item(new HelpTransformer(),HelpService::getById($id));
  71. }
  72. /**
  73. * @apiVersion 1.0.0
  74. * @apiDescription 添加帮助
  75. * @api {post} help/createHelp 添加帮助
  76. * @apiGroup Help
  77. * @apiName createHelp
  78. * @apiSuccess {int} code 状态码
  79. * @apiSuccess {String} msg 信息
  80. * @apiSuccess {object} data 结果集
  81. * @apiParam {string} content内容
  82. * @apiParam {string} title标题
  83. * @apiSuccessExample {json} Success-Response:
  84. * HTTP/1.1 200 OK
  85. * {
  86. * code: 0,
  87. * msg: "",
  88. * data: {}
  89. * }
  90. */
  91. public function createHelp(Request $request){
  92. $content = $request->post('content');
  93. $title = $request->post('title');
  94. if(empty($content) || empty($title)){
  95. return response()->error('PARAM_EMPTY');
  96. }
  97. $data = compact('title','content');
  98. if(HelpService::create($data)){
  99. return response()->success();
  100. }else{
  101. return response()->error('UNKNOWN_ERROR');
  102. }
  103. }
  104. /**
  105. * @apiVersion 1.0.0
  106. * @apiDescription 编辑帮助
  107. * @api {post} help/editHelp 编辑帮助
  108. * @apiGroup Help
  109. * @apiName editHelp
  110. * @apiParam {string} content 内容
  111. * @apiParam {string} title 标题
  112. * @apiParam {int} id id
  113. * @apiSuccess {int} code 状态码
  114. * @apiSuccess {String} msg 信息
  115. * @apiSuccess {object} data 结果集
  116. * @apiSuccessExample {json} Success-Response:
  117. * HTTP/1.1 200 OK
  118. * {
  119. * code: 0,
  120. * msg: "",
  121. * data: {}
  122. * }
  123. */
  124. public function editHelp(Request $request){
  125. $content = $request->post('content');
  126. $title = $request->post('title');
  127. $id = $request->post('id');
  128. if(empty($content) || empty($title) || empty($id)){
  129. return response()->error('PARAM_EMPTY');
  130. }
  131. HelpService::updateHelp($id,compact('content','title'));
  132. return response()->success();
  133. }
  134. /**
  135. * @apiVersion 1.0.0
  136. * @apiDescription 编辑帮助状态
  137. * @api {post} help/editStatus 编辑帮助状态
  138. * @apiGroup Help
  139. * @apiName editStatus
  140. * @apiSuccess {int} code 状态码
  141. * @apiSuccess {String} msg 信息
  142. * @apiSuccess {object} data 结果集
  143. * @apiParam {string} status状态(enbale,disable)
  144. * @apiParam {int} id
  145. * @apiSuccessExample {json} Success-Response:
  146. * HTTP/1.1 200 OK
  147. * {
  148. * code: 0,
  149. * msg: "",
  150. * data: {}
  151. * }
  152. */
  153. public function editStatus(Request $request){
  154. $status = $request->post('status');
  155. $id = $request->post('id');
  156. $status_array = ['enbale'=>1,'disable'=>0];
  157. if(empty($status) || empty($id) || !isset($status_array[$status])) {
  158. return response()->error('PARAM_EMPTY');
  159. }
  160. HelpService::enableHelpStatus($id,$status_array[$status]);
  161. return response()->success();
  162. }
  163. }