<?php


namespace common\services;


use common\components\AjaxException;
use common\models\RulesPoints;
use yii\db\ActiveQuery;

class RulesPointsService
{
    /**
     * @param $id
     * @return RulesPoints
     * @throws AjaxException
     */
    public static function getRulesPointsById($id): RulesPoints
    {
        /** @var RulesPoints $RulesPoints */
        $RulesPoints = RulesPoints::find()->where(["delete_time" => 0, "id" => $id])->one();
        if (!$RulesPoints) {
            throw new AjaxException("该规章不存在！");
        }
        return $RulesPoints;
    }

    /**
     * @return ActiveQuery
     */
    public static function getRulesPointsQuery(): ActiveQuery
    {
        return RulesPoints::find()->where(["delete_time" => 0]);
    }

    /**
     * 通过规章ID删除规章点
     * @param $rule_id
     */
    public static function deleteByRulesId($rule_id): void
    {
        RulesPoints::updateAll(["delete_time" => time()], ["rule_id" => $rule_id]);
    }

    public static function getAllList($query)
    {
        return $query->select("id,point,name,content,dic")->orderBy("point asc")->all();
    }

}