Notice.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Prettus\Repository\Contracts\Transformable;
  5. use Prettus\Repository\Traits\TransformableTrait;
  6. /**
  7. * Class Notice.
  8. *
  9. * @package namespace App\Models;
  10. * @method static \Illuminate\Database\Eloquent\Builder|Notice newModelQuery()
  11. * @method static \Illuminate\Database\Eloquent\Builder|Notice newQuery()
  12. * @method static \Illuminate\Database\Eloquent\Builder|Notice query()
  13. * @mixin \Eloquent
  14. * @property int $id
  15. * @property string|null $title 标题
  16. * @property string|null $content 内容
  17. * @property int $sort 排序
  18. * @property int $show 是否显示 0:不显示;1:显示
  19. * @property int $new 是否显示 0:默认;1:最新
  20. * @property \Illuminate\Support\Carbon|null $created_at
  21. * @property \Illuminate\Support\Carbon|null $updated_at
  22. * @method static \Illuminate\Database\Eloquent\Builder|Notice whereContent($value)
  23. * @method static \Illuminate\Database\Eloquent\Builder|Notice whereCreatedAt($value)
  24. * @method static \Illuminate\Database\Eloquent\Builder|Notice whereId($value)
  25. * @method static \Illuminate\Database\Eloquent\Builder|Notice whereNew($value)
  26. * @method static \Illuminate\Database\Eloquent\Builder|Notice whereShow($value)
  27. * @method static \Illuminate\Database\Eloquent\Builder|Notice whereSort($value)
  28. * @method static \Illuminate\Database\Eloquent\Builder|Notice whereTitle($value)
  29. * @method static \Illuminate\Database\Eloquent\Builder|Notice whereUpdatedAt($value)
  30. * @property string|null $title_en 标题
  31. * @property string|null $content_en 内容(英文)
  32. * @method static \Illuminate\Database\Eloquent\Builder|Notice whereContentEn($value)
  33. * @method static \Illuminate\Database\Eloquent\Builder|Notice whereTitleEn($value)
  34. */
  35. class Notice extends Model implements Transformable
  36. {
  37. use TransformableTrait;
  38. /**
  39. * The attributes that are mass assignable.
  40. *
  41. * @var array
  42. */
  43. protected $guarded = ['id', 'updated_at', 'created_at'];
  44. /**
  45. * 验证是否阅读
  46. * @param $m_id
  47. * @return int
  48. */
  49. function getIsRead($m_id)
  50. {
  51. if (empty($this->{'id'})) return false;
  52. $read_num = NoticeRead::where('n_id', $this->{'id'})->where('member_id', $m_id)->count();
  53. return $read_num>0?1:0;
  54. }
  55. /**
  56. * 添加阅读信息
  57. * @param $m_id
  58. * @return int|mixed
  59. */
  60. function setRead($m_id)
  61. {
  62. if (empty($this->{'id'})) return 0;
  63. $read_num = NoticeRead::where('n_id', $this->{'id'})->where('member_id', $m_id)->count();
  64. if ($read_num > 0) {
  65. return 0;
  66. }
  67. $read = NoticeRead::create(['member_id' => $m_id, 'n_id' => $this->{'id'}]);
  68. return $read->{'id'};
  69. }
  70. }