field('id, role_name, privileges, create_time, update_time') ->order('id', 'desc') ->select(); } /** * 获取角色详情 * @param int $id 角色ID * @param int $merchantId 商户ID * @return array|\think\Model|null */ public static function getRoleById(int $id, int $merchantId) { return self::where('id', $id) ->where('merchant_id', $merchantId) ->find(); } /** * 创建角色 * @param array $data 角色数据 * @return \think\Model */ public static function createRole(array $data) { return self::create($data); } /** * 更新角色 * @param int $id 角色ID * @param int $merchantId 商户ID * @param array $data 更新数据 * @return */ public static function updateRole(int $id, int $merchantId, array $data) { return self::where('id', $id) ->where('merchant_id', $merchantId) ->update($data); } /** * 删除角色 * @param int $id 角色ID * @param int $merchantId 商户ID * @return bool */ public static function deleteRole(int $id, int $merchantId) { return self::where('id', $id) ->where('merchant_id', $merchantId) ->delete(); } /** * 检查角色是否存在 * @param string $roleName 角色名称 * @param int $merchantId 商户ID * @param int|null $excludeId 排除的ID * @return bool */ public static function checkRoleExists(string $roleName, int $merchantId, ?int $excludeId = null): bool { $query = self::where('role_name', $roleName) ->where('merchant_id', $merchantId); if ($excludeId) { $query->where('id', '<>', $excludeId); } return $query->count() > 0; } }