1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85:
<?php
class PHPShopBonus {
function __construct($user_id) {
global $PHPShopSystem;
$this->user_id = $user_id;
$this->bonus_plus = intval($PHPShopSystem->getSerilizeParam('admoption.bonus'));
$this->max_order_bonus = intval($PHPShopSystem->getSerilizeParam('admoption.order_bonus'));
$this->PHPShopUser = new PHPShopUser($user_id);
$this->bonus = $this->PHPShopUser->getBonus();
}
function getUserBonus($sum) {
$sum_bonus = $sum * $this->max_order_bonus / 100;
if ($sum_bonus < $this->bonus)
$this->bonus_minus = $sum_bonus;
else
$this->bonus_minus = $this->bonus;
return intval($this->bonus_minus);
}
function setUserBonus($sum) {
return intval($sum * $this->bonus_plus / 100);
}
function updateUserBonus($bonus_minus, $bonus_plus) {
$bonus = $this->bonus - $bonus_minus + $bonus_plus;
if ($bonus < 0)
$bonus = 0;
$PHPShopOrm = new PHPShopOrm($GLOBALS['SysValue']['base']['shopusers']);
$PHPShopOrm->update(array('bonus_new' => $bonus, array('id' => $this->user_id)));
}
function updateBonusLog($order_id,$order_uid, $bonus_minus, $bonus_plus) {
$PHPShopOrm = new PHPShopOrm($GLOBALS['SysValue']['base']['bonus']);
if (!empty($bonus_plus))
$PHPShopOrm->insert(array('date_new' => time(), 'comment_new' => __('') . ' №' . $order_uid, 'user_id_new' => $this->user_id, 'bonus_operation_new' => $bonus_plus,'order_id_new'=>$order_id));
if (!empty($bonus_minus))
$PHPShopOrm->insert(array('date_new' => time(), 'comment_new' => __('') . ' №' . $order_uid, 'user_id_new' => $this->user_id, 'bonus_operation_new' => "-$bonus_minus",'order_id_new'=>$order_id));
}
}
?>