BookChannelScoreController.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace App\Http\Controllers\Channel\Book;
  3. use App\Modules\Book\Services\BookChannelScoreService;
  4. use Illuminate\Http\Request;
  5. use App\Http\Controllers\Channel\BaseController;
  6. use Hashids;
  7. class BookChannelScoreController extends BaseController
  8. {
  9. /**
  10. * @apiDefine Book 图书模块
  11. */
  12. /**
  13. * @apiVersion 1.0.0
  14. * @apiDescription 自主评分
  15. * @api {post} book/score 自主评分
  16. * @apiGroup Book
  17. * @apiParam {String} score 评分(A,B,C,D...)
  18. * @apiParam {Number} bid 图书id
  19. * @apiName score
  20. * @apiSuccess {int} code 状态码
  21. * @apiSuccess {String} msg 信息
  22. * @apiSuccess {object} data 结果集
  23. * @apiSuccessExample {json} Success-Response:
  24. * {
  25. * "code": 0,
  26. * "msg": "",
  27. * "data": {
  28. * }
  29. */
  30. public function score(Request $request)
  31. {
  32. $channel_id = $this->getChannelId();
  33. $score = $request->post('score');
  34. $bid = $request->post('bid');
  35. if (empty($score) || empty($bid)) {
  36. return response()->error("PARAM_EMPTY");
  37. }
  38. if (!is_numeric($bid)) {
  39. $bid = Hashids::decode($bid)[0];
  40. }
  41. if (strlen($score) != 1 || is_numeric($score) || !in_array(strtoupper($score), range('A', 'Z'))) {
  42. //return response()->error("PARAM_EMPTY");
  43. }
  44. BookChannelScoreService::score($channel_id, strtoupper($score), $bid);
  45. return response()->success();
  46. }
  47. }