BookSubscribleChapter.php 1020 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace App\Modules\Book\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. class BookSubscribleChapter extends Model
  5. {
  6. protected $table = 'book_subscribe_chapter';
  7. protected $fillable = ['book_id', 'subscribe_chapter_id', 'channel_id'];
  8. /**
  9. * 设置强关章节序号
  10. */
  11. public static function setSubcribleChapter($data)
  12. {
  13. $old = self::where('book_id', $data['book_id'])->where('channel_id', $data['channel_id'])->first();
  14. if ($old) {
  15. $old->subscribe_chapter_id = $data['subscribe_chapter_id'];
  16. $old->save();
  17. return $old;
  18. } else {
  19. return self::create($data);
  20. }
  21. }
  22. /**
  23. * 查询渠道设置的书籍的强关章节序号
  24. * $book_id:书本id
  25. * $channelId:渠道id
  26. */
  27. public static function getSubcribleChapter($book_id, $channelId)
  28. {
  29. return self::select('subscribe_chapter_id')->where('book_id', $book_id)->where('channel_id', $channelId)->first();
  30. }
  31. }