You're looking at a cashback style set-up, though you don't have to pay in cash.
What you need to do is give each visitor a unique ID, easy enough if your site has membership anyway, and when you present the affiliate link to the visitor you attach the unique ID to the link as an optional note (almost all networks support this in some way).
Now when an order is completed the note is recorded by the affiliate network and put in their report. You can load that report back into your site and it will know who to give rewards to.
This is the very simplest description of how a cashback site can work, and there are other methods and complications depending on the network, target market and reward type.
There are scripts you can buy which would achieve this -
FSRevolution could do it using the points based option, but to be honest the only cashback / reward sites which do well are bespoke / heavily customised, and you won't get anywhere by being the same as everyone else. Even the heavily automated systems require a lot of babysitting and maintainence, so don't expect to have a site made and then be able to forget about it.