= $vip_start? 1:0; $size += mb_strlen($content); $cid = self::createOrUpdateContent($bid,$i,$last_name,$content,$is_vip); if($i == $start_sequence){ $first_cid = $cid; } $i++;$content = ''; $last_name = $name; } }else{ $content .= $temp."\r\n"; } } //当前是最后一张 $is_vip = $i >= $vip_start? 1:0; $last_cid = self::createOrUpdateContent($bid,$i,$last_name,$content,$is_vip); $last_chapter = $last_name; $size += mb_strlen($content); fclose($handle); return ['size'=>$size,'chapter_count'=>$i,'first_cid'=>$first_cid,'last_cid'=>$last_cid,'last_chapter'=>$last_chapter]; } /** * 保存章节,支持覆盖 * * @param [type] $bid * @param [type] $sequence * @param [type] $name * @param [type] $content * @param [type] $is_vip * @return void */ private static function createOrUpdateContent($bid,$sequence,$name,$content,$is_vip){ $name = mb_convert_encoding($name,'UTF-8'); $content = mb_convert_encoding($content,'UTF-8'); $chapter_info = BookChapters::where('bid',$bid)->where('sequence',$sequence)->first(); if($chapter_info){ $content_info = BookChapterContents::where('id',$chapter_info->chapter_content_id)->first(); if($content_info){ $content_info->chapter_name = $name; $content_info->content = $content; $content_info->save(); }else{ $content_info = BookChapterContents::create(['bid'=>$bid,'chapter_name'=>$name,'content'=>$content]); } $chapter_info->name = $name; $chapter_info->size = mb_strlen($content); $chapter_info->chapter_content_id = $content_info->id; $chapter_info->save(); }else{ $content_info = BookChapterContents::create(['bid'=>$bid,'chapter_name'=>$name,'content'=>$content]); $chapter_info = BookChapters::create([ 'bid'=>$bid,'name'=>$name,'sequence'=>$sequence,'size'=>mb_strlen($content), 'is_vip'=>$is_vip,'prev_cid'=>0,'next_cid'=>0,'chapter_content_id'=>$content_info->id ]); } return $chapter_info->id; } /** * 解析章节标题 * * @param [type] $content * @return void */ private static function parseName($content){ if(stripos($content,'###') !== false){ return str_replace('###','',$content); } /* $status = preg_match('/^第.*?章/',$content); if($status){ return $content; }*/ return ''; } }