<?php

namespace app\admin\model;

use support\Model;

/**
 * 系统配置分类表模型
 * Class SystemConfigClassify
 * @package app\api\model
 */
class SystemConfigClassify extends Model
{
    const WAIT   = '0';
    const DONE   = '1';
    const MEMBER_AUTH_STATUS = [
        self::WAIT   => '停用',
        self::DONE   => '启用',
    ];
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'system_config_classify';

    public $timestamps = false;

    /**
     * Notes:子集模型关联
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     * User: yym
     * Date: 2022/10/10
     */
    public function children()
    {
        return $this->hasMany(SystemConfigClassify::class, 'classify_pid', 'classify_id');
    }

    /**
     * Notes:设置分类列表
     * @return array
     * User: yym
     * Date: 2022/10/10
     */
    public static function getClassifyList()
    {
        return static::where(['classify_pid' => 0])
            ->with(['children'])
            ->orderBy('classify_sort', 'desc')
            ->get()
            ->toArray();
    }

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

    /**
     * Notes:根据主键获取单个信息
     * @param int $classify_id
     * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|null
     * User: yym
     * Date: 2022/10/10
     */
    public static function getInfo(int $classify_id)
    {
        return static::where(['classify_id' => $classify_id])->first();
    }

    /**
     * Notes:根据主键更新信息
     * @param int $classify_id
     * @param array $data
     * @return false|int
     * User: yym
     * Date: 2022/10/10
     */
    public static function updateData(int $classify_id, array $data)
    {
        if(empty($classify_id) || empty($data))
        {
            return false;
        }
        return static::where(['classify_id' => $classify_id])->update($data);
    }
}
