05AB1E, 9 bytes
7%É31αsΘ-
Same formula as @Adám's APL (Dyalog Unicode) answer, which I've also partially used in this earlier answer of mine.
Explanation:
7% # Take the (implicit) input-integer modulo-7
É # Check whether it is odd (short for modulo-2)
31α # Take the absolute difference with 31
s # Swap to take the (implicit) input-integer again
Θ # 05AB1E truthify; 1 if n==1; 0 otherwise
- # And subtract this from the earlier number
# (after which the result is output implicitly)