<?php

namespace app\model;

use DateTimeInterface;
use support\Model;

class MemberBenefit extends Model
{
    protected $table = 'member_benefit';

    protected $primaryKey = 'member_benefit_id';

    public $keyType = 'string';


    protected $dateFormat = 'U';

    const CREATED_AT = 'member_benefit_addtimes';

    const UPDATED_AT = null;

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

    public function member()
    {
        return $this->hasOne(Member::class, 'member_id', 'join_benefit_member_id')
            ->select('member_id', 'member_mobile');
    }

    public function cert()
    {
        return $this->hasOne(MemberCert::class, 'join_cert_member_id', 'member');
    }

    public function goods()
    {
        return $this->hasOne(Goods::class, 'goods_id', 'join_benefit_goods_id')
            ->select('goods_id', 'goods_cover', 'goods_name');
    }

    public function package()
    {
        return $this->hasOne(Goods::class, 'goods_id', 'join_benefit_package_id')
            ->select('goods_id', 'goods_cover', 'goods_name');
    }

    public function order()
    {
        return $this->hasOne(Order::class, 'order_id', 'join_benefit_order_id')
            ->select('order_id', 'order_name');
    }

}