Den spanske rytteren Raúl Fernández vant Valencia Grand Prix, mens Marc Márquez kom på andreplass i sitt siste MotoGP-løp.