123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Model;
- use Prettus\Repository\Contracts\Transformable;
- use Prettus\Repository\Traits\TransformableTrait;
- /**
- * Class Notice.
- *
- * @package namespace App\Models;
- * @method static \Illuminate\Database\Eloquent\Builder|Notice newModelQuery()
- * @method static \Illuminate\Database\Eloquent\Builder|Notice newQuery()
- * @method static \Illuminate\Database\Eloquent\Builder|Notice query()
- * @mixin \Eloquent
- * @property int $id
- * @property string|null $title 标题
- * @property string|null $content 内容
- * @property int $sort 排序
- * @property int $show 是否显示 0:不显示;1:显示
- * @property int $new 是否显示 0:默认;1:最新
- * @property \Illuminate\Support\Carbon|null $created_at
- * @property \Illuminate\Support\Carbon|null $updated_at
- * @method static \Illuminate\Database\Eloquent\Builder|Notice whereContent($value)
- * @method static \Illuminate\Database\Eloquent\Builder|Notice whereCreatedAt($value)
- * @method static \Illuminate\Database\Eloquent\Builder|Notice whereId($value)
- * @method static \Illuminate\Database\Eloquent\Builder|Notice whereNew($value)
- * @method static \Illuminate\Database\Eloquent\Builder|Notice whereShow($value)
- * @method static \Illuminate\Database\Eloquent\Builder|Notice whereSort($value)
- * @method static \Illuminate\Database\Eloquent\Builder|Notice whereTitle($value)
- * @method static \Illuminate\Database\Eloquent\Builder|Notice whereUpdatedAt($value)
- * @property string|null $title_en 标题
- * @property string|null $content_en 内容(英文)
- * @method static \Illuminate\Database\Eloquent\Builder|Notice whereContentEn($value)
- * @method static \Illuminate\Database\Eloquent\Builder|Notice whereTitleEn($value)
- */
- class Notice extends Model implements Transformable
- {
- use TransformableTrait;
- /**
- * The attributes that are mass assignable.
- *
- * @var array
- */
- protected $guarded = ['id', 'updated_at', 'created_at'];
- /**
- * 验证是否阅读
- * @param $m_id
- * @return int
- */
- function getIsRead($m_id)
- {
- if (empty($this->{'id'})) return false;
- $read_num = NoticeRead::where('n_id', $this->{'id'})->where('member_id', $m_id)->count();
- return $read_num>0?1:0;
- }
- /**
- * 添加阅读信息
- * @param $m_id
- * @return int|mixed
- */
- function setRead($m_id)
- {
- if (empty($this->{'id'})) return 0;
- $read_num = NoticeRead::where('n_id', $this->{'id'})->where('member_id', $m_id)->count();
- if ($read_num > 0) {
- return 0;
- }
- $read = NoticeRead::create(['member_id' => $m_id, 'n_id' => $this->{'id'}]);
- return $read->{'id'};
- }
- }
|