point <= $maxPoint) { throw new \Exception("积分必须大于当前最大积分({$maxPoint})"); } } public static function onBeforeUpdate($row) { $prevPoint = self::where('id', '<', $row->id) ->order('point', 'desc') ->value('point'); if ($prevPoint && $row->point <= $prevPoint) { throw new \Exception("积分必须大于上一个等级积分({$prevPoint})"); } $nextPoint = self::where('id', '>', $row->id) ->order('point', 'asc') ->value('point'); if ($nextPoint && $row->point >= $nextPoint) { throw new \Exception("积分必须小于下一个等级积分({$nextPoint})"); } } public static function onbeforeDelete($row) { if ($row['issystem']) { throw new \Exception('系统用户组[' . $row['name'] . ']不能删除!'); } } public function user() { return $this->belongsTo('User', 'id', 'group_id'); } }