<?php


namespace app\model;

use DateTimeInterface;
use support\Model;

class Appointment extends Model
{
    protected $table = 'appointment';

    protected $primaryKey = 'appointment_id';

    protected $keyType = 'string';

    protected $dateFormat = 'U';

    const CREATED_AT = 'appointment_addtimes';

    const UPDATED_AT = null;

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

    /**
     * @Desc 关联用户
     * @Author Gorden
     * @Date 2024/3/29 10:59
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function member()
    {
        return $this->hasOne(Member::class, 'member_id', 'join_appointment_member_id');
    }

    public function memberInfo()
    {
        return $this->hasOne(MemberInfo::class, 'join_info_member_id', 'join_appointment_member_id')
            ->select('join_info_member_id', 'member_info_nickname');
    }

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

    /**
     * @Desc 关联商品
     * @Author Gorden
     * @Date 2024/3/29 10:58
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function goods()
    {
        return $this->hasOne(Goods::class, 'goods_id', 'join_appointment_goods_id');
    }

    /**
     * @Desc 关联订单
     * @Author Gorden
     * @Date 2024/3/29 10:58
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function order()
    {
        return $this->hasOne(Order::class, 'order_id', 'join_appointment_order_id');
    }

    public function running()
    {
        return $this->hasOne(GoodsRunning::class, 'join_running_goods_id', 'join_appointment_goods_id')
            ->select('join_running_goods_id', 'goods_running_storage', 'goods_running_sale');
    }

    /**
     * @Desc 关联权益
     * @Author Gorden
     * @Date 2024/3/29 10:58
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function benefit()
    {
        return $this->hasOne(MemberBenefit::class, 'member_benefit_id', 'join_appointment_member_benefit_id');
    }

    public function sku(){
        return $this->hasMany(GoodsSku::class,'join_sku_goods_id','join_appointment_goods_id')
            ->select('goods_sku_id','goods_sku_specs_json','goods_sku_sales_price');
    }
}