<?php

namespace app\admin\model\score;

use think\Model;


class Team extends Model
{

    

    

    // 表名
    protected $name = 'score_team';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

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

    // 追加属性
    protected $append = [
        "score_employee_ids",
        "people_num",
        "people_names"
    ];


    public function getPeopleNumAttr($value, $data)
    {
        $value = $value ?: ($data['id'] ?? '');
        if(!$value) return 0;
        $score_employee_ids  = Employee::where( "team_id", $value)->count();
        return $score_employee_ids;
    }


    public function getPeopleNamesAttr($value, $data)
    {
        $value = $value ?: ($data['id'] ?? '');
        if(!$value) return "";
        $score_employee_ids  = Employee::where( "team_id", $value)->column( "name");
        return implode(",", $score_employee_ids);
    }



    public function getScoreEmployeeIdsAttr($value, $data)
    {
        $value = $value ?: ($data['id'] ?? '');
        if(!$value) return "";
        $score_employee_ids  = Employee::where( "team_id", $value)->column( "id");
        return implode(",", $score_employee_ids);
    }



    







}
