BookConfig.php 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace App\Models\Book;
  3. use DB;
  4. use Hashids;
  5. use Illuminate\Database\Eloquent\Model;
  6. use Log;
  7. use Redis;
  8. class BookConfig extends Model
  9. {
  10. protected $table = 'book_configs';
  11. protected $fillable = ['bid', 'force_subscribe_chapter_seq', 'price', 'cover', 'book_name',
  12. 'copyright', 'charge_type', 'hot', 'is_on_shelf', 'source_domain', 'recommend_index', 'roles', 'test_status', 'plan_push_user_num', 'test_update_time',
  13. 'is_show_index_content', 'click_count', 'promotion_domain', 'copyright_limit_data', 'recommend_cid', 'is_high_quality', 'vip_seq','editor_recommend','is_current_week_promotion','unit_price'];
  14. /**
  15. * 根据id数组获取图书信息
  16. * @param array $bid_arr
  17. * @param array $order
  18. * @return mixed
  19. */
  20. public static function getBooksByIds(array $bid_arr, array $order = [], $is_on_shelf = '')
  21. {
  22. if(empty($is_on_shelf)) $is_on_shelf = 2;
  23. $res = self::join('books', 'book_configs.bid', '=', 'books.id')
  24. ->leftjoin('book_categories', 'books.category_id', 'book_categories.id')
  25. ->select('book_configs.bid', 'book_configs.force_subscribe_chapter_seq', 'book_configs.vip_seq', 'book_configs.price',
  26. 'book_configs.cover', 'book_configs.book_name', 'book_configs.copyright', 'book_configs.charge_type', 'book_configs.is_on_shelf',
  27. 'books.author', 'books.intro', 'book_categories.category_name', 'category_id', 'status', 'chapter_count', 'book_configs.click_count',
  28. 'first_cid', 'last_cid', 'size', 'last_chapter', 'books.keyword', 'book_configs.recommend_index', 'book_configs.is_show_index_content',
  29. 'book_configs.product_id', 'book_categories.channel_name', 'books.last_cid', 'books.last_chapter', 'book_configs.product_id', 'books.updated_at as last_update_time',
  30. 'book_configs.copyright_limit_data', 'book_configs.promotion_domain', 'books.name as old_name', 'book_configs.recommend_cid'
  31. )
  32. ->whereIn('book_configs.bid', $bid_arr);
  33. if($is_on_shelf !='all' && !empty($is_on_shelf)) {
  34. $res->where('is_on_shelf',$is_on_shelf);
  35. }
  36. if ($order) {
  37. $res->orderBy($order[0], $order[1]);
  38. } else {
  39. $str = implode(',', $bid_arr);
  40. $field = 'bid,' . $str;
  41. $res->orderBy(DB::raw('field(' . $field . ')'));
  42. }
  43. return $res->limit(50)->get();
  44. }
  45. /**
  46. * 根据bid获取图书信息
  47. * @param $bid
  48. * @return mixed
  49. */
  50. public static function getBookById($bid)
  51. {
  52. if (empty($bid)) return null;
  53. return self::join('books', 'book_configs.bid', '=', 'books.id')
  54. ->leftjoin('book_categories', 'books.category_id', 'book_categories.id')
  55. ->select('book_configs.bid', 'book_configs.is_on_shelf', 'book_configs.force_subscribe_chapter_seq', 'book_configs.vip_seq', 'book_configs.cp_source', 'book_configs.price', 'book_configs.cover', 'book_configs.book_name',
  56. 'book_configs.copyright', 'book_configs.created_at', 'book_configs.charge_type', 'book_configs.is_on_shelf', 'books.author', 'books.intro', 'book_categories.category_name',
  57. 'category_id', 'status', 'chapter_count', 'first_cid', 'last_cid', 'size', 'last_chapter', 'books.keyword', 'book_configs.recommend_index','book_configs.test_status','book_configs.unit_price','book_configs.calculate_price_type',
  58. 'book_configs.is_show_index_content', 'book_configs.click_count', 'book_configs.product_id', 'book_categories.channel_name', 'books.last_cid', 'books.updated_at as last_update_time',
  59. 'books.last_chapter', 'book_configs.product_id', 'book_configs.copyright_limit_data', 'book_configs.promotion_domain', 'books.name as old_name', 'book_configs.recommend_cid', 'book_configs.is_high_quality'
  60. , 'book_configs.copyright_from'
  61. )->where('book_configs.bid', $bid)->first();
  62. }
  63. /**
  64. * 通过书名模糊搜索bid
  65. * @param $book_name
  66. * @return mixed
  67. */
  68. static function getIdByName($book_name)
  69. {
  70. return self::select('bid')->where('book_name', 'like', '%' . $book_name . '%')->get();
  71. }
  72. }