Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

coupon code statistics

Tags:

I have a system that allows users to enter coupons (for example like dell or amazon)

I want to know how much a coupon has been used so after 500 times the coupon is no longer valid.

The way I am thinking right now is to insert the coupon into a table and then select count(*) and if it reaches 50 then I don't insert and I return a message saying it's expired.

I think this solution works but I wanted to validate and maybe check if there's a better way to do it.

like image 339
E.G. Avatar asked Nov 22 '11 02:11

E.G.


1 Answers

I assume you have coupons stored in some table with code, description, etc, etc. add num_used column to it and increment it every time the coupon is used. This way you can still insert the coupon into orders if need be but you don't need to do counts. You simply check how many times it was already used when you load your coupon info. I assume you check validity by coupon code anyway so throw another one in for number of times.

like image 126
Alexey Gerasimov Avatar answered Oct 17 '22 00:10

Alexey Gerasimov