ChapterComments.php 900 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. namespace App\Modules\Book\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. use DB;
  5. class ChapterComments extends Model
  6. {
  7. protected $table = 'chapter_comments';
  8. protected $fillable = ['id','bid','tags','chapter','uid'];
  9. public static function addComments($param){
  10. $sign = ['uid'=>$param['uid'],'chapter'=>$param['chapter']];
  11. $update = ['tags'=>$param['tags'],'bid'=>$param['bid']];
  12. return self::updateOrCreate($sign,$update);
  13. }
  14. public static function getChapterComment($cid,$uid){
  15. return self::where([
  16. ['chapter','=',$cid],['uid','=',$uid]
  17. ])->first();
  18. }
  19. public static function getBookStats(){
  20. self::select(DB::raw('sum(uv) as UV,count('))
  21. ->leftjoin('book_configs','book_configs.bid','=','chapter_comments.bid')
  22. ->groupBy('chapter_comments.bid')
  23. ->get();
  24. }
  25. }