<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\NoticeModel
 *
 * @property int $id 主键
 * @property int $uid 用户id
 * @property string $title 标题
 * @property string|null $content 通知内容
 * @property int $type 通知类型
 * 1:要联系方式;
 * 2:投诉操作;
 * 3:投诉结果;
 * 4:被索要联系方式;
 * 5:系统通知;
 * 6:被表白;
 * 7:接收表白;
 * 8:拒绝表白
 * 9:审核不通过
 * 10:发送表白
 * 11:赠送小fa;
 * 12:被赠送小fa
 * @property int $type_id 通知连接对象
 * 1:卡片id;
 * 2:无;
 * 3:投诉记录id;
 * 4:索要联系方式用户的id;
 * 6:表白记录id;
 * 7:卡片id;
 * 8:表白记录id;
 * 9:卡片id;
 * 10:卡片id
 * @property \Illuminate\Support\Carbon $create_at 创建时间
 * @property string $cdate 创建时间
 * @property int $is_read 是否查看
 * @property \Illuminate\Support\Carbon $update_at 修改时间
 * @property string $tab_content 按钮文字
 * @property string $tab_url 按钮地址
 * @property string $tab_action 动作
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\NoticeModel newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\NoticeModel newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\NoticeModel query()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\NoticeModel whereCdate($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\NoticeModel whereContent($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\NoticeModel whereCreateAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\NoticeModel whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\NoticeModel whereIsRead($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\NoticeModel whereTabAction($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\NoticeModel whereTabContent($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\NoticeModel whereTabUrl($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\NoticeModel whereTitle($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\NoticeModel whereType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\NoticeModel whereTypeId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\NoticeModel whereUid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\NoticeModel whereUpdateAt($value)
 * @mixin \Eloquent
 */
class NoticeModel extends Model
{
    protected $connection = "mysql_fenpeiduixiang";

    protected $table = "kdgx_partner_charge_notive";

    protected $dateFormat = 'U';

    public const CREATED_AT = 'create_at';

    public const UPDATED_AT = 'update_at';

    public $fillable = [
        'uid',
        'title',
        'content',
        'type',
        'cdate',
        'type_id',
        'is_read',
        'tab_content',
        'tab_url',
        'tab_action'
    ];

    /**
     * 加入系统通知
     * @param $uid 通知用户
     * @param $type 通知类型
     * @param $title 通知标题
     * @param $content 通知内容
     * @param $type_data 附加数据
     */
    public function joinSysNotice($uid, $type, $title, $content, $type_data)
    {
        $this->fill([
            'uid' => $uid,
            'type' => $type,
            'title' => $title,
            'content' => $content,
            'type_id' => $type_data,
        ]);
        $this->save();
    }

    public static function boot()
    {
        parent::boot();

        self::saving(function ($model) {
            $model->cdate = date('Y-m-d');
        });
    }
}
