My question is: How I can limit an user to do an action a limited amount of times every week ?
My case is the following:
I have my products and I am offering an option for every user to ask for a refund if the product is not good. The problem is that many users abuse this action and is time consuming for me to check every product and every user that asks for a refund so I want to limit every user to be able to ask for a refund only 3 times a week but I don't know how.
I have a table named refunds_count that looks like this
ID || userid || product_id || date
----------------------------------
1 || 7 || 9 || 2016-03-9 12:33:22
2 || 7 || 10 || 2016-03-13 14:40:10
3 || 7 || 11 || 2016-03-13 16:42:15
So the user with ID 7 has already two refund requests this week and I don't know how to compare this data to see if the user has made 3 requests already this week
SELECT userid
FROM refunds_count t
WHERE week(now()) = week(t.date)
GROUP BY userid
HAVING COUNT(*) >= 3
This will provide a list of all users that already made 3 refunds this week.
You can last filter those users in your refund system, something like
WHERE userid NOT IN(...the query here...)