<?php

namespace app\model;

use support\Model;

class CouponDetail extends Model
{
    protected $table = 'coupon_detail';

    protected $primaryKey = 'coupon_id';

    protected $dateFormat = 'U';

    const CREATED_AT = 'coupon_detail_addtimes';

    const UPDATED_AT = null;

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

    public function detail()
    {
        return $this->hasMany(CouponDetail::class,'join_detail_coupon_id','join_detail_coupon_id');
    }

    /**
     * @Desc 关联会员
     * @Author Gorden
     * @Date 2024/3/30 13:08
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function member()
    {
        return $this->hasOne(Member::class, 'member_id', 'join_coupon_detail_member_id');
    }

    /**
     * @Desc 关联实名
     * @Author Gorden
     * @Date 2024/8/21 13:50
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function cert()
    {
        return $this->hasOne(MemberCert::class, 'join_cert_member_id', 'join_coupon_detail_member_id');
    }

    /**
     * @Desc 关联详情
     * @Author Gorden
     * @Date 2024/8/21 13:51
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function info()
    {
        return $this->hasOne(MemberInfo::class, 'join_info_member_id', 'join_coupon_detail_member_id');
    }

    /**
     * @Desc 关联优惠券
     * @Author Gorden
     * @Date 2024/3/30 13:08
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function coupon()
    {
        return $this->hasOne(Coupon::class, 'coupon_id', 'join_detail_coupon_id');
    }
}