<?php

namespace app\admin\model;

use support\Model;

class UserMedicalExaminationReport extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'user_medical_examination_report';

    /**
     * The primary key associated with the table.
     *
     * @var string
     */
    protected $primaryKey = 'report_id';

    /**
     * Indicates if the model should be timestamped.
     *
     * @var bool
     */
    public $timestamps = false;

    /**
     * Notes:检测是否存在
     * @param string $group
     * @return bool
     * User: yym
     * Date: 2022/9/15
     */
    public static function checkStatus(string $group)
    {
        return static::where(['report_group' => $group])->exists();
    }

    /**
     * Notes:插入数据
     * @param array $data
     * @return false|int
     * User: yym
     * Date: 2022/9/15
     */
    public static function insertData(array $data)
    {
        if(empty($data))
        {
            return false;
        }
        return static::insertGetId($data);
    }

    /**
     * Notes:更新数据
     * @param string $group
     * @param array $data
     * @return false|int
     * User: yym
     * Date: 2022/9/15
     */
    public static function updateData(string $group, array $data)
    {
        if(empty($group) || empty($data))
        {
            return false;
        }
        return static::where(['report_group' => $group])->update($data);
    }

    /**
     * Notes:获取会员体检信息
     * @param int $user_id
     * @return array
     * User: yym
     * Date: 2022/9/21
     */
    public static function getList(int $user_id)
    {
        $list = static::where(['report_user_id' => $user_id])
            ->orderBy('report_time', 'desc')
            ->get()
            ->toArray();
        $count = static::where(['report_user_id' => $user_id])->count();
        return [$list, $count];
    }
}
