BookSubScribleChapterController.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace App\Http\Controllers\Channel\Book;
  3. use App\Http\Controllers\Channel\BaseController;
  4. use App\Modules\Book\Services\BookSubscribleChapterService;
  5. use Hashids;
  6. use Illuminate\Http\Request;
  7. class BookSubScribleChapterController extends BaseController
  8. {
  9. /**
  10. * @apiDefine Book 图书模块
  11. */
  12. /**
  13. * @apiVersion 1.0.0
  14. * @apiDescription 设置强关章节
  15. * @api {post} book/setSubScribleChapter 设置强关章节
  16. * @apiGroup Book
  17. * @apiParam {Number} book_id 图书id
  18. * @apiParam {Number} subscribe_chapter_seq 强关章节序号
  19. * @apiName setSubScribleChapterId
  20. * @apiSuccessExample {json} Success-Response:
  21. *
  22. * {
  23. * "code": 0,
  24. * "msg": "",
  25. * "data":[]
  26. * }
  27. */
  28. function setSubScribleChapter(Request $request)
  29. {
  30. $channel_id = $this->getChannelId();
  31. $book_id = $request->has('book_id') ? $request->input('book_id') : '';
  32. $subscribe_chapter_id = $request->has('subscribe_chapter_seq') ? $request->input('subscribe_chapter_seq') : '';
  33. if (empty($book_id) || empty($subscribe_chapter_id)) {
  34. return response()->error("PARAM_EMPTY");
  35. }
  36. $book_id = Hashids::decode($book_id)[0];
  37. if (!is_numeric($book_id) || !is_numeric($subscribe_chapter_id)) {
  38. return response()->error("PARAM_ERROR");
  39. }
  40. $result = BookSubscribleChapterService::setSubcribleChapter(compact('channel_id', 'book_id', 'subscribe_chapter_id'));
  41. if ($result) {
  42. return response()->success();
  43. } else {
  44. return response()->error("HANDLE_FAILED");
  45. }
  46. }
  47. /**
  48. * @apiVersion 1.0.0
  49. * @apiDescription 查询强关章节
  50. * @api {get} book/getSubScribleChapter 查询强关章节
  51. * @apiGroup Book
  52. * @apiParam {Number} book_id 图书id
  53. * @apiName getSubScribleChapter
  54. * @apiSuccessExample {json} Success-Response:
  55. *
  56. * {
  57. * "code": 0,
  58. * "msg": "",
  59. * "data":11,
  60. * }
  61. */
  62. function getSubScribleChapter(Request $request)
  63. {
  64. $book_id = $request->has('book_id') ? $request->input('book_id') : '';
  65. if (empty($book_id)) {
  66. return response()->error("PARAM_EMPTY");
  67. }
  68. $book_id = Hashids::decode($book_id)[0];
  69. if (!is_numeric($book_id)) {
  70. return response()->error("PARAM_ERROR");
  71. }
  72. $distribution_channel_id = $this->getChannelId();
  73. $result = BookSubscribleChapterService::getSubcribleChapter($book_id, $distribution_channel_id);
  74. return response()->success($result);
  75. }
  76. }