123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- <?php
- namespace App\Modules\Book\Services;
- use App\Modules\Book\Models\Book;
- use App\Modules\Book\Models\Chapter;
- use GuzzleHttp\Client;
- use Redis;
- use App\Modules\Statistic\Services\WapVisitStatService;
- use DB;
- class BookService
- {
- /**
- * 获取book中存在的分类信息id
- * @return array
- */
- public static function getCategoryId(){
- return Book::getCategoryId();
- }
- /**
- * 修改图书描述
- * @param $bid
- * @param $intro
- * @return mixed
- *
- */
- public static function updateIntro($bid,$intro){
- return Book::where('id',$bid)->update(['intro'=>$intro]);
- }
- /**
- * 设置章节价格
- * @param int $channel_id
- * @param int $price
- */
- public static function setChapterPrice(int $channel_id,float $price):void{
- try{
- Redis::hset('book_chapter_price',$channel_id,$price);
- }catch (\Exception $e){
- }
- }
- /**
- * 获取渠道设置的价格
- * @param int $channel_id
- * @return int
- */
- public static function getChapterPrice(int $channel_id){
- try{
- $fee = Redis::hget('book_chapter_price',$channel_id);
- if($fee)
- return (float)$fee;
- else
- return 0;
- }catch (\Exception $e){
- }
- return 0;
- }
-
- public static function getBookStatistics($smart_push_books){
- // 获取书籍统计数据
- if(!empty($smart_push_books)){
- foreach($smart_push_books as $key=>$smart_push_book){
- $book_statistics = WapVisitStatService::smartPushTestBookStats($smart_push_book->bid);
- $smart_push_books[$key]->uv = $book_statistics['uv'];
- $smart_push_books[$key]->pv = $book_statistics['pv'];
- $smart_push_books[$key]->charge_amount = $book_statistics['charge_amount'];
- $smart_push_books[$key]->charge_user_num = $book_statistics['charge_user_num'];
- $smart_push_books[$key]->book_amount = $book_statistics['book_amount'];
- $smart_push_books[$key]->book_user_num = $book_statistics['book_user_num'];
- $smart_push_books[$key]->real_push_user_num = $book_statistics['real_push_user_num'];
- $smart_push_books[$key]->second_chapter_uv = $book_statistics['second_chapter_uv'];
- }
- }
- return $smart_push_books;
- }
- public static function getBookById($bid){
- return Book::find($bid);
- }
- public static function newYunQiBook($bid){
- $old = DB::table('book_yunqi')->where('yq_bid',$bid)->where('type','NEW_YUNQI')->first();
- if($old){
- return -1;
- }
- $new_yunqi_book = DB::connection('new_yunqi')->table('books')->where('id',$bid)->fist();
- if(!$new_yunqi_book){
- return -2;
- }
- $book = Book::create(
- [
- 'ly_bid'=>0,'name'=>$new_yunqi_book->name,'author'=>$new_yunqi_book->author,'intro'=>$new_yunqi_book->intro,'cover'=>$new_yunqi_book->cover,
- 'category_name'=>$new_yunqi_book->category_name,'keyword'=>$new_yunqi_book->keyword,'category_id'=>0,'status'=>$new_yunqi_book->status,
- '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,
- 'sequence'=>0,'yq_bid'=>$bid
- ]
- );
- DB::table('book_yunqi')->insert([
- 'bid'=>$book->id,
- 'yq_bid'=>$bid,
- 'type'=>'NEW_YUNQI',
- 'created_at'=>date('Y-m-d H:i:s'),
- 'updated_at'=>date('Y-m-d H:i:s')
- ]);
- for ($i = 1;$i<=$new_yunqi_book->chapter_count;$i++){
- $temp = DB::connection('new_yunqi')->table('chapters')->where('bid',$bid)->where('sequence',$i)->select('name','content','is_vip','size')->first();
- if($new_yunqi_book){
- Chapter::create([
- 'bid'=>$book->id,
- 'name'=>$temp->name,
- 'sequence'=>$i,
- 'is_vip'=>$temp->is_vip,
- 'size'=>$temp->size,
- 'prev_cid'=>0,
- 'next_cid'=>0,
- 'recent_update_at'=>date('Y-m-d H:i:s'),
- 'content'=>$temp->content,
- 'ly_chapter_id'=>0
- ]);
- }
- }
- \Artisan::callSilent('book:afs',['bid'=>[$book->id]]);
- return 0;
- }
- }
|