Notice.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. */
  31. class Notice extends Model implements Transformable
  32. {
  33. use TransformableTrait;
  34. /**
  35. * The attributes that are mass assignable.
  36. *
  37. * @var array
  38. */
  39. protected $guarded = ['id', 'updated_at', 'created_at'];
  40. /**
  41. * 验证是否阅读
  42. * @param $m_id
  43. * @return int
  44. */
  45. function getIsRead($m_id)
  46. {
  47. if (empty($this->{'id'})) return false;
  48. $read_num = NoticeRead::where('n_id', $this->{'id'})->where('member_id', $m_id)->count();
  49. return $read_num>0?1:0;
  50. }
  51. /**
  52. * 添加阅读信息
  53. * @param $m_id
  54. * @return int|mixed
  55. */
  56. function setRead($m_id)
  57. {
  58. if (empty($this->{'id'})) return 0;
  59. $read_num = NoticeRead::where('n_id', $this->{'id'})->where('member_id', $m_id)->count();
  60. if ($read_num > 0) {
  61. return 0;
  62. }
  63. $read = NoticeRead::create(['member_id' => $m_id, 'n_id' => $this->{'id'}]);
  64. return $read->{'id'};
  65. }
  66. }