RulesPointsService.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace common\services;
  3. use common\components\AjaxException;
  4. use common\models\RulesPoints;
  5. use yii\db\ActiveQuery;
  6. class RulesPointsService
  7. {
  8. /**
  9. * @param $id
  10. * @return RulesPoints
  11. * @throws AjaxException
  12. */
  13. public static function getRulesPointsById($id): RulesPoints
  14. {
  15. /** @var RulesPoints $RulesPoints */
  16. $RulesPoints = RulesPoints::find()->where(["delete_time" => 0, "id" => $id])->one();
  17. if (!$RulesPoints) {
  18. throw new AjaxException("该规章不存在!");
  19. }
  20. return $RulesPoints;
  21. }
  22. /**
  23. * @return ActiveQuery
  24. */
  25. public static function getRulesPointsQuery(): ActiveQuery
  26. {
  27. return RulesPoints::find()->where(["delete_time" => 0]);
  28. }
  29. /**
  30. * 通过规章ID删除规章点
  31. * @param $rule_id
  32. */
  33. public static function deleteByRulesId($rule_id): void
  34. {
  35. RulesPoints::updateAll(["delete_time" => time()], ["rule_id" => $rule_id]);
  36. }
  37. public static function getAllList($query)
  38. {
  39. return $query->select("id,point,name,content,dic")->orderBy("point asc")->all();
  40. }
  41. }