Treaty.php 4.01 KB
<?php

namespace App\Models\Legal;

use App\Models\BaseModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * Class Treaty
 * @package App\Models\Legal
 */
class Treaty extends BaseModel
{
    use HasFactory,SoftDeletes;

    /**
     * @var string
     */
    protected $table = 'treaty';

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function file()
    {
        return $this->hasMany(TreatyFile::class, 'treaty_id');
    }

    /**
     * @var string[]
     */
    public static $cost_model = [
        1=>'一次性费用',
        2=>'分成',
        3=>'分成+预付',
        5=>'分成+一次性费用',
        6=>'抵扣成本后再分成',
        7=>'分成+预付+一次性费用',
        8=>'抵扣成本+分成+预付',
        9=>'一次性费用+抵扣成本后分成',
    ];

    /**
     * @var string[]
     */
    public static $service_type = [
        1=>'唱片业务',
        2=>'线下演艺活动',
        3=>'短视频业务',
        4=>'互联网直播业务',
        5=>'影视剧业务',
        6=>'广告代言',
        7=>'媒体推广合作',
        8=>'其他',
    ];

    /**
     * 模式
     * @return string
     */
    public function getChargeModelAttribute()
    {
        switch ($this->cost_model) {
            case 1:
                return "一次性费用" . $this->formatCost();
                break;
            case 2:
                return "分成" . $this->formatDivide();
                break;
            case 3:
                return '分成' . $this->formatDivide() .'+预付'. $this->formatPrepaid();
                break;
            case 5:
                return '分成' . $this->formatDivide() .'+一次性费用'. $this->formatCost();
                break;
            case 6:
                return '抵扣成本后再分成' . $this->formatDivide();
                break;
            case 7:
                return '分成' . $this->formatDivide() . '+预付' .$this->formatPrepaid(). '+一次性费用' . $this->formatCost();
                break;
            case 8:
                return '抵扣成本后分成' .$this->formatDivide(). '+预付' . $this->formatPrepaid();
                break;
            case 9:
                return '一次性费用' . $this->formatCost() .'+抵扣成本后分成' . $this->formatDivide();
                break;
        }
    }

    /**
     * 合约类型
     * @param $value
     * @return string
     */
    public function getTreatyTypeAttribute($value)
    {
        switch ($value) {
            case 1:
                return '唱片约艺人';
                break;
            case 2:
                return '全约艺人';
                break;
            case 3:
                return 'mcn达人';
                break;
        }
    }

    /**
     * 合作业务类型
     * @param $value
     * @return array
     */
    public function getServiceTypeAttribute($value)
    {
        $res = [];
        $service_type = explode(',', $value);
        foreach ($service_type as $item) {
            isset(self::$service_type[$item]) && $res[] = self::$service_type[$item];
        }

        return $res;
    }


    /**
     * 拼接预付模式
     * @return string
     */
    public function formatPrepaid()
    {
        $str = '('.$this->prepaid.')';
        return $str;
    }

    /**
     * 拼接分成模式
     * @return string
     */
    public function formatCost()
    {
        $str = '('.$this->cost.')';
        return $str;
    }

    /**
     * 拼接分成模式
     * @return string
     */
    public function formatDivide()
    {
        $str = '(';
        !empty($this->s_rate) && $str .= "演唱/"  . $this->s_rate * 100 .'%';
        !empty($this->l_rate) && $str .= ",作词/" . $this->l_rate * 100 .'%';
        !empty($this->c_rate) && $str .= ",作曲/" . $this->c_rate * 100 .'%';
        !empty($this->p_rate) && $str .= ",制作/" . $this->p_rate * 100 .'%';
        $str .= ')';

        return $str;
    }
}