<?php

namespace app\model;

use DateTimeInterface;
use support\Model;

class Member extends Model
{
    protected $table = 'member';

    protected $primaryKey = 'member_id';

    protected $keyType = 'string';

    protected $dateFormat = 'U';

    const CREATED_AT = 'member_addtimes';

    const UPDATED_AT = null;

    public function serializeDate(DateTimeInterface $date)
    {
        return $date->format('Y-m-d H:i:s');
    }

    /**
     * @Desc 关联member cert
     * @Author Gorden
     * @Date 2024/3/25 13:57
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function cert()
    {
        return $this->hasOne(MemberCert::class, 'join_cert_member_id', 'member_id');
    }

    /**
     * @Desc 关联member info
     * @Author Gorden
     * @Date 2024/3/25 13:56
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function info()
    {
        return $this->hasOne(MemberInfo::class, 'join_info_member_id', 'member_id');
    }

    public function account()
    {
        return $this->hasMany(MemberAccount::class, 'join_account_member_id', 'member_id');
    }

    public function accountOne()
    {
        return $this->hasOne(MemberAccount::class, 'join_account_member_id', 'member_id');
    }

    public function role(){
        return $this->hasOne(MemberRole::class,'member_role_id','join_member_role_id');
    }
}