Then, you should create a page with a form asking for the affiliate id, with a joomla form extension or directly yourself, then redirect to some page of your website with the parameter &partner_id=ID
where the ID would be the id entered by the user.
Then he would be automatically affected to that partner.
For the restriction of the purchase, you could edit the file "step" of the view "checkout" via the menu Display>Views and add a check there by loading the information of the user from the hikashop_user table like that:
$user = hikashop_loadUser(true);