<?php

namespace app\model;

use DateTimeInterface;
use support\Model;

class Coupon extends Model
{
    protected $table = 'coupon';

    protected $primaryKey = 'coupon_id';

    protected $keyType = 'string';

    protected $dateFormat = 'U';

    const CREATED_AT = 'coupon_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','coupon_id');
    }

    public function category(){
        return $this->hasOne(SysCategory::class,'category_id','join_coupon_category_id')->select('category_id','category_name');
    }

    public function user(){
        return $this->hasOne(SysUser::class,'user_id','coupon_creator_user_id')->select('user_id','user_name');
    }
}