BookService.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. namespace App\Modules\Book\Services;
  3. use App\Modules\Book\Models\Book;
  4. use App\Modules\Book\Models\Chapter;
  5. use GuzzleHttp\Client;
  6. use Redis;
  7. use App\Modules\Statistic\Services\WapVisitStatService;
  8. use DB;
  9. class BookService
  10. {
  11. /**
  12. * 获取book中存在的分类信息id
  13. * @return array
  14. */
  15. public static function getCategoryId(){
  16. return Book::getCategoryId();
  17. }
  18. /**
  19. * 修改图书描述
  20. * @param $bid
  21. * @param $intro
  22. * @return mixed
  23. *
  24. */
  25. public static function updateIntro($bid,$intro){
  26. return Book::where('id',$bid)->update(['intro'=>$intro]);
  27. }
  28. /**
  29. * 设置章节价格
  30. * @param int $channel_id
  31. * @param int $price
  32. */
  33. public static function setChapterPrice(int $channel_id,float $price):void{
  34. try{
  35. Redis::hset('book_chapter_price',$channel_id,$price);
  36. }catch (\Exception $e){
  37. }
  38. }
  39. /**
  40. * 获取渠道设置的价格
  41. * @param int $channel_id
  42. * @return int
  43. */
  44. public static function getChapterPrice(int $channel_id){
  45. try{
  46. $fee = Redis::hget('book_chapter_price',$channel_id);
  47. if($fee)
  48. return (float)$fee;
  49. else
  50. return 0;
  51. }catch (\Exception $e){
  52. }
  53. return 0;
  54. }
  55. public static function getBookStatistics($smart_push_books){
  56. // 获取书籍统计数据
  57. if(!empty($smart_push_books)){
  58. foreach($smart_push_books as $key=>$smart_push_book){
  59. $book_statistics = WapVisitStatService::smartPushTestBookStats($smart_push_book->bid);
  60. $smart_push_books[$key]->uv = $book_statistics['uv'];
  61. $smart_push_books[$key]->pv = $book_statistics['pv'];
  62. $smart_push_books[$key]->charge_amount = $book_statistics['charge_amount'];
  63. $smart_push_books[$key]->charge_user_num = $book_statistics['charge_user_num'];
  64. $smart_push_books[$key]->book_amount = $book_statistics['book_amount'];
  65. $smart_push_books[$key]->book_user_num = $book_statistics['book_user_num'];
  66. $smart_push_books[$key]->real_push_user_num = $book_statistics['real_push_user_num'];
  67. $smart_push_books[$key]->second_chapter_uv = $book_statistics['second_chapter_uv'];
  68. }
  69. }
  70. return $smart_push_books;
  71. }
  72. public static function getBookById($bid){
  73. return Book::find($bid);
  74. }
  75. public static function newYunQiBook($bid){
  76. $old = DB::table('book_yunqi')->where('yq_bid',$bid)->where('type','NEW_YUNQI')->first();
  77. if($old){
  78. return -1;
  79. }
  80. $new_yunqi_book = DB::connection('new_yunqi')->table('books')->where('id',$bid)->fist();
  81. if(!$new_yunqi_book){
  82. return -2;
  83. }
  84. $book = Book::create(
  85. [
  86. 'ly_bid'=>0,'name'=>$new_yunqi_book->name,'author'=>$new_yunqi_book->author,'intro'=>$new_yunqi_book->intro,'cover'=>$new_yunqi_book->cover,
  87. 'category_name'=>$new_yunqi_book->category_name,'keyword'=>$new_yunqi_book->keyword,'category_id'=>0,'status'=>$new_yunqi_book->status,
  88. 'chapter_count'=>$new_yunqi_book->chapter_count,'first_cid'=>0,'last_cid'=>0,'size'=>$new_yunqi_book->size,'last_chapter'=>$new_yunqi_book->last_chapter,
  89. 'sequence'=>0,'yq_bid'=>$bid
  90. ]
  91. );
  92. DB::table('book_yunqi')->insert([
  93. 'bid'=>$book->id,
  94. 'yq_bid'=>$bid,
  95. 'type'=>'NEW_YUNQI',
  96. 'created_at'=>date('Y-m-d H:i:s'),
  97. 'updated_at'=>date('Y-m-d H:i:s')
  98. ]);
  99. for ($i = 1;$i<=$new_yunqi_book->chapter_count;$i++){
  100. $temp = DB::connection('new_yunqi')->table('chapters')->where('bid',$bid)->where('sequence',$i)->select('name','content','is_vip','size')->first();
  101. if($new_yunqi_book){
  102. Chapter::create([
  103. 'bid'=>$book->id,
  104. 'name'=>$temp->name,
  105. 'sequence'=>$i,
  106. 'is_vip'=>$temp->is_vip,
  107. 'size'=>$temp->size,
  108. 'prev_cid'=>0,
  109. 'next_cid'=>0,
  110. 'recent_update_at'=>date('Y-m-d H:i:s'),
  111. 'content'=>$temp->content,
  112. 'ly_chapter_id'=>0
  113. ]);
  114. }
  115. }
  116. \Artisan::callSilent('book:afs',['bid'=>[$book->id]]);
  117. return 0;
  118. }
  119. }