AuditRecord.php 3.4 KB
<?php
/**
+-----------------------------------------------------------------------------------------------------------------------
 * 模型层:系统 审核记录 模型类
+-----------------------------------------------------------------------------------------------------------------------
 *
 * PHP version 7
 *
 * @category  App\Models\System
 * @package   App\Models\System
 * @author    Richer <yangzi1028@163.com>
 * @date      2020年12月29日16:42:11
 * @copyright 2020-2022 Richer (http://www.Richer.com/)
 * @license   http://www.Richer.com/ License
 * @link      http://www.Richer.com/
 */
namespace App\Models\System;

use App\Models\Traits\MorphMapTrait;
use App\Models\User\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Support\Arr;

/**
 * Class AuditRecord
 *
 * @category  App\Models\System
 * @package   App\Models\System
 * @author    Richer <yangzi1028@163.com>
 * @date      2020年12月29日16:42:11
 * @copyright 2020-2022 Richer (http://www.Richer.com/)
 * @license   http://www.Richer.com/ License
 * @link      http://www.Richer.com/
 */
class AuditRecord extends Model
{
    use MorphMapTrait;

    // 指定数据库表
    const TABLE = 'system_audit_records';
    protected $table = self::TABLE ;

    // 指定对象显示名称:方便系统统一查询和做其他处理
    const OBJ_NAME      = 'audit-record';
    const OBJ_NAME_ZH   = '审核记录';

    const SUBMITTED = 1;// 已提交
    const AUDIT_PASSED =  2;// 审核通过
    const AUDIT_NOT_PASSED = 99;// 审核不通过
    const AUDIT_STATUS_OPTIONS = [
        self::SUBMITTED => 'submitted',
        self::AUDIT_PASSED => 'audit_passed',
        self::AUDIT_NOT_PASSED => 'audit_not_passed',
    ];
    const AUDIT_COLOR_STATUS_OPTIONS = [
        self::SUBMITTED         => 'warning',
        self::AUDIT_PASSED      => 'success',
        self::AUDIT_NOT_PASSED  => 'danger',
    ];
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'user_id', 'user_type', 'auditable_id', 'auditable_type', 'audited_by', 'audited_status','audited_opinion',
        'audited_at', 'remark', 'created_at'
    ];

    /**
     * 访问器被附加到模型数组的形式。
     *
     * @var array
     */
    protected $appends = ['audited_status_show', 'audited_status_show_color'];

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

    /**
     * @return MorphTo
     */
    public function user(): MorphTo
    {
        return $this->morphTo();
    }

    /**
     * @return MorphTo
     */
    public function auditable(): MorphTo
    {
        return $this->morphTo();
    }

    /**
     * 获取状态的中文显示
     *
     * @return mixed
     */
    public function getAuditedStatusShowAttribute()
    {
        return __(Arr::get(self::AUDIT_STATUS_OPTIONS, $this->audited_status ? : config('constants.AUDIT_PASSED')));
    }

    /**
     * 获取状态的中文显示
     *
     * @return mixed
     */
    public function getAuditedStatusShowColorAttribute()
    {
        $color = Arr::get(self::AUDIT_COLOR_STATUS_OPTIONS, $this->audited_status);
        return '<span class="text text-'.$color.'" style="white-space:nowrap;">'.$this->audited_status_show.'</span>';
    }
}