<?php
namespace app\common\model\orders;
use app\common\model\BaseModel;
use app\common\model\goods\Goods;
use app\common\model\user\User;
use app\common\model\works\ServiceWork;

/**
 * @author 林海涛
 * @date 2024/7/17 下午5:23
 */
class OrderEffectiveLog extends BaseModel
{
    protected $name = 'order_effective_log';
    protected $type = [
        'effective_images' => 'array',
    ];
    public function goods()
    {
        return $this->hasOne(Goods::class, 'id', 'goods_id');
    }

    public function originalServiceWork()
    {
        return $this->hasOne(ServiceWork::class, 'id', 'work_id');
    }
    public function userInfo()
    {
        return $this->hasOne(User::class, 'id', 'user_id');
    }
    public function serviceWork()
    {
        return $this->hasOne(ServiceWork::class, 'order_effective_id', 'id');
    }

    public function getEndEffectiveTimeAttr($value,$data)
    {
        return !empty($data['end_effective_time'])?date('Y-m-d H:i:s',$data['end_effective_time']):'';
    }

    public static function getEffectiveUnitTextAttr($value,$data)
    {
       $type = [1 => '天',2=> '小时'];
       return $type[$data['effective_unit']];
    }
}