mod_bonus = Model('user_bonus'); $this->member_id = $member_id; $this->usable_amount = 0.00; $items = $this->mod_bonus->getUsableBonus($this->member_id); $this->all_bonus = []; foreach ($items as $item) { $bonus = user_bonus::create_by_param($item); $this->all_bonus[] = $bonus; $this->usable_amount += $bonus->remain_amount(); } $this->usable_amount = ($this->usable_amount * 100 + 0.5) / 100; $this->mUsedType = $used_type; } public function usable_amount() { return $this->usable_amount; } public function withold_bonus($rate,$bonus_sn,$money) { foreach ($this->all_bonus as $bonus) { if($bonus_sn == $bonus->bonus_sn()) { $left = intval($bonus->remain_amount() * 100 + 0.5); $money = intval($money * 100 + 0.5); $left = $left - $money; $left = $left >= 0 ? $left / 100 : 0.00; $rate = $bonus->bonus_rate(); $param = $bonus->get_param(); $param['remain_amount'] = $left; if($this->mUsedType == bonus_helper::send_bonus_withold) { $send = intval($bonus->send_amount() * 100 + 0.5); $send = $send + $money; $send = $send / 100; $param['send_amount'] = $send; } elseif($this->mUsedType == bonus_helper::pay_order_withold) { $paied = intval($bonus->pay_amount() * 100 + 0.5); $paied = $paied + $money; $paied = $paied / 100; $param['pay_amount'] = $paied; } else { } QueueClient::push("onUseBonus",['time' => time(),'use_type' => $this->mUsedType,'rate' => $rate,'amount' => $money / 100,'member_id' => $this->member_id]); $this->mod_bonus->replace($param); return true; } } return false; } public function withold($rate,$money) { $left_cent = intval($this->usable_amount * 100 + 0.5); $money_cent = intval($money * 100 + 0.5); if($money_cent <= 0 || $left_cent <= 0 || $left_cent <= $money_cent) { return false; } $left = $money_cent; $datas = []; foreach ($this->all_bonus as $bonus) { if($left <= 0) break; if($this->mUsedType == bonus_helper::send_bonus_withold && $bonus->can_share() == false) { continue; } $rate = $bonus->bonus_rate(); $param = $bonus->get_param(); $remain = $bonus->remain_amount(); $remain = intval($remain * 100 + 0.5); if($left >= $remain) { $left -= $remain; $param['remain_amount'] = 0.00; $used = $remain; } else { $remain -= $left; $param['remain_amount'] = $remain / 100; $used = $left; $left = 0; } if($this->mUsedType == bonus_helper::send_bonus_withold) { $send = intval($bonus->send_amount() * 100 + 0.5); $send = $send + $used; $send = $send / 100; $param['send_amount'] = $send; } elseif($this->mUsedType == bonus_helper::pay_order_withold) { $paied = intval($bonus->pay_amount() * 100 + 0.5); $paied = $paied + $used; $paied = $paied / 100; $param['pay_amount'] = $paied; } else { } QueueClient::push("onUseBonus",['time' => time(),'use_type' => $this->mUsedType,'rate' => $rate,'amount' => $used / 100,'member_id' => $this->member_id]); array_push($datas,$param); } if(!empty($datas)) { $this->mod_bonus->replaceAll($datas); } return true; } }