Category.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\common\library\Ip;
  5. use app\common\service\WaterBookService;
  6. use app\main\service\AdminService;
  7. use app\main\service\UserService;
  8. use think\Cookie;
  9. class Category extends Api
  10. {
  11. public function _initialize()
  12. {
  13. parent::_initialize();
  14. }
  15. /**
  16. * 男女频道下的分类信息数据
  17. * @param int $sex 频道
  18. * @return json
  19. */
  20. public function channelcategoriesapi()
  21. {
  22. $sex = input('sex');
  23. $data = model('BookCategory')::channelCategories($sex);
  24. return json($data);
  25. }
  26. /**
  27. * 查询类目下的书籍列表数据
  28. * @param int $book_category_id 书籍分类id
  29. * @param int $type 书籍分类id
  30. * @return json
  31. */
  32. public function booklistapi()
  33. {
  34. $book_category_id = input('book_category_id', 8);
  35. $type = input('type', 'all');
  36. $page = input('page', 1);
  37. $user_id = Cookie::get('user_id');
  38. //清水
  39. if ($user_id) {
  40. $userInfo = UserService::instance()->getUserModel()->getUserInfo($user_id);
  41. $channel_id = $userInfo['channel_id'] ?? 0;
  42. if (empty($channel_id)) {
  43. $is_water = false;
  44. } else {
  45. $channel_id = AdminService::instance()->getAdminExtendModel()->getChannelId($channel_id);
  46. $is_water = WaterBookService::instance()->showBook($channel_id, $user_id, Ip::ip());
  47. }
  48. } else {
  49. $is_water = false;
  50. }
  51. $books = model('BookCategory')::booklist($book_category_id, $type, $page, $is_water);
  52. return json($books);
  53. }
  54. }