Project.php 3.42 KB
<?php

namespace App\Models;

use App\Models\Pivots\UserProjectPivot;
use App\Support\Model;
use Awobaz\Compoships\Database\Eloquent\Relations\BelongsTo;
use Awobaz\Compoships\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\SoftDeletes;

class Project extends Model
{
    use SoftDeletes;

    protected $table = 'projects';

    protected $guarded = [];

    protected $hidden = ['deleted_at'];

    protected $casts = [
        'is_public'         => 'int',
        'is_can_apply'      => 'int',
        'is_can_manage'     => 'int',
        'is_can_demo_apply' => 'int',
        'is_demo_audit'     => 'int',
    ];

    public array $columnMap = [
        'cover'             => '封面',
        'name'              => '名称',
        'intro'             => '简介',
        'master_id'         => '主理人',
        'is_promote'        => '是否确认分享人',
        'is_public'         => '是否仅显示自己创建的试唱活动',
        'is_can_apply'      => '是否允许提交上架申请',
        'is_can_manage'     => '是否允许自行添加外部成员',
        'is_can_demo_apply' => '是否允许提交Demo上架',
        'is_demo_audit'     => 'Demo上架是否需要审核',
        'weight'            => '权重值'
    ];

    /**
     * @param $value
     * @return string
     */
    public function getCoverAttribute($value): string
    {
        return empty($value) ? 'https://hi-sing-cdn.hikoon.com/image/20230925/b2f5im19hc1695620904296trgzs37vx.png' : $value;
    }

    /**
     * @return \Awobaz\Compoships\Database\Eloquent\Relations\BelongsTo
     */
    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class)->withTrashed();
    }

    /**
     * @return \Awobaz\Compoships\Database\Eloquent\Relations\BelongsTo
     */
    public function master(): BelongsTo
    {
        return $this->belongsTo(User::class)->withTrashed();
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function managers(): BelongsToMany
    {
        return $this->belongsToMany(User::class, UserProjectPivot::class);
    }

    /**
     * @return \Awobaz\Compoships\Database\Eloquent\Relations\HasMany
     */
    public function members(): HasMany
    {
        return $this->hasMany(ProjectHasMember::class);
    }

    /**
     * @return \Awobaz\Compoships\Database\Eloquent\Relations\HasMany
     */
    public function activities(): HasMany
    {
        return $this->hasMany(Activity::class)->where('activitys.audit_status', 1);
    }

    /**
     * @return \Awobaz\Compoships\Database\Eloquent\Relations\HasMany
     */
    public function totalSong(): HasMany
    {
        return $this->hasMany(Activity::class)->where('audit_status', 1)->whereNotIn('status', [0, 2, 4]);
    }

    /**
     * @return \Awobaz\Compoships\Database\Eloquent\Relations\HasMany
     */
    public function onlineSong(): HasMany
    {
        return $this->hasMany(Activity::class)->where(['status' => 1, 'audit_status' => 1]);
    }

    /**
     * @return \Awobaz\Compoships\Database\Eloquent\Relations\HasOne|\Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function comfirmTime()
    {
        return $this->hasOne(ProjectConfirmationTime::class, 'project_id', 'id');
    }

    public function visitor()
    {
        return $this->hasMany(ProjectVisitor::class, 'project_id', 'id');
    }
}