BookService.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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')
  81. ->table('books')
  82. ->join('book_configs','books.id','=','book_configs.bid')
  83. ->select(
  84. 'books.id','books.author','books.author','books.intro','books.category_name','books.keyword',
  85. 'books.status','books.chapter_count','books.size','books.last_chapter','book_configs.book_name as name',
  86. 'book_configs.cover','book_configs.force_subscribe_chapter_seq','book_configs.charge_type','book_configs.roles'
  87. )
  88. ->where('books.id',$bid)
  89. ->first();
  90. if(!$new_yunqi_book){
  91. return -2;
  92. }
  93. $book = Book::create(
  94. [
  95. 'ly_bid'=>0,'name'=>$new_yunqi_book->name,'author'=>$new_yunqi_book->author,'intro'=>$new_yunqi_book->intro,'cover'=>$new_yunqi_book->cover,
  96. 'category_name'=>$new_yunqi_book->category_name,'keyword'=>$new_yunqi_book->keyword,'category_id'=>0,'status'=>$new_yunqi_book->status,
  97. '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,
  98. 'sequence'=>0,'yq_bid'=>$bid
  99. ]
  100. );
  101. DB::table('book_yunqi')->insert([
  102. 'bid'=>$book->id,
  103. 'yq_bid'=>$bid,
  104. 'type'=>'NEW_YUNQI',
  105. 'created_at'=>date('Y-m-d H:i:s'),
  106. 'updated_at'=>date('Y-m-d H:i:s')
  107. ]);
  108. for ($i = 1;$i<=$new_yunqi_book->chapter_count;$i++){
  109. $temp = DB::connection('new_yunqi')->table('chapters')->where('bid',$bid)->where('sequence',$i)->select('name','content','is_vip','size')->first();
  110. if($temp){
  111. Chapter::create([
  112. 'bid'=>$book->id,
  113. 'name'=>$temp->name,
  114. 'sequence'=>$i,
  115. 'is_vip'=>$temp->is_vip,
  116. 'size'=>$temp->size,
  117. 'prev_cid'=>0,
  118. 'next_cid'=>0,
  119. 'recent_update_at'=>date('Y-m-d H:i:s'),
  120. 'content'=>$temp->content,
  121. 'ly_chapter_id'=>0
  122. ]);
  123. }
  124. }
  125. \Artisan::call('book:afs',['bid'=>[$book->id]]);
  126. DB::table('book_configs')->where('bid',$book->id)->update([
  127. 'force_subscribe_chapter_seq'=>$new_yunqi_book->force_subscribe_chapter_seq,
  128. 'roles'=>$new_yunqi_book->roles,
  129. 'charge_type'=>$new_yunqi_book->charge_type,
  130. 'cp_source'=>'new_yunqi'
  131. ]);
  132. return 0;
  133. }
  134. }