mDirty = false; $this->mAmount = 0.00; $amount = 0.0; foreach ($rates as $key => $val) { $amount += $val; } $this->mAmount = intval(100 * $amount + 0.5) / 100; } public function add_bonuses($items) { foreach ($items as $item) { $bonus = bonus\user_bonus::create_by_param($item); $amount = intval($bonus->remain_amount() * 100 + 0.5) / 100; if ($amount <= 0) continue; $this->mAmount += intval(100 * $amount + 0.5) / 100; $this->mDirty = true; } } public function is_enough(&$rate, $amount) { $rate = defaultBonusRate(); $amount = intval($amount * 100 + 0.5); $tmp = intval($this->mAmount * 100 + 0.5); return $tmp >= $amount; } public function with_hold($rate, $amount) { $this->mAmount -= ($amount * 100 + 0.5) / 100; $this->mDirty = true; } public function find_rate($amount) { if ($this->is_enough($rate, $amount)) { return ['rate' => defaultBonusRate(), 'amount' => intval($amount * 100 + 0.5) / 100]; } else { $amount = intval($amount * 100 + 0.5); return ['rate' => $rate, 'amount' => $amount / 100]; } } public function format() { return [defaultBonusRate() => intval($this->mAmount * 100 + 0.5) / 100]; } public function total() { return $this->mAmount; } public function dirty() { return $this->mDirty; } public function clean() { $this->mDirty = false; } public function calc_rates($amount) { throw new UnImplementsException(__METHOD__); } public function calc_money($price, &$rates) { throw new UnImplementsException(__METHOD__); } public function calc_price($price, &$rates) { throw new UnImplementsException(__METHOD__); } static function scale() { return (100 - self::PRED_RATE) / 100; } }