Evaluate.php 1.7 KB
<?php

namespace app\admin\model\workorder;

use think\Model;


class Evaluate extends Model
{


    // 表名
    protected $name = 'workorder_evaluate';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'stars_text',
        'solved_text'
    ];


    public function getStarsList()
    {
        return [
            '1' => __('Stars 1'),
            '2' => __('Stars 2'),
            '3' => __('Stars 3'),
            '4' => __('Stars 4'),
            '5' => __('Stars 5')
        ];
    }

    public function getSolvedList()
    {
        return ['0' => __('Solved 0'), '1' => __('Solved 1')];
    }


    public function getStarsTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['stars']) ? $data['stars'] : '');
        $list  = $this->getStarsList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getSolvedTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['solved']) ? $data['solved'] : '');
        $list  = $this->getSolvedList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function orders()
    {
        return $this->belongsTo('Orders', 'order_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function user()
    {
        return $this->belongsTo('app\admin\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function category()
    {
        return $this->belongsTo('Category', 'category_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}