clear(); if (!$payment->customerCode) { throw new SkipException(sprintf("顧客コード未割当 レコード番号:%d", $payment->getRecordId())); } $this->payment = $payment; $this->getPool(); $this->setPoolDone(); $this->makeHistory(); $this->setPoolAmount(); $this->save(); return $this->pool; } private function getPool() { $access = Pool::getAccess(); $query = Pool::getQuery()->where(Pool::FIELD_CUSTOMER_CODE, $this->payment->customerCode); $list = $access->some($query); if ($list->isNotEmpty()) { if ($list->count() !== 1) { throw new SkipException(sprintf("データ不正 入金プール一意制約違反 顧客コード%d", $this->payment->customerCode)); } $this->pool = $list->first(); return; } $pool = new Pool(); $pool->customerCode = $this->payment->customerCode; $pool->poolAmount = 0; $pool->save(); $this->pool = $pool; } private function makeHistory() { $history = new PoolTransferHistory(); $history->poolRecordNo = $this->pool->getRecordId(); $history->customerCode = $this->payment->customerCode; $history->transferDatetime = DateUtil::now(); $history->transferType = TransgerType::INCOME; $history->transferAmount = $this->payment->paymentAmount; $history->poolAmountBefore = $this->pool->poolAmount; $history->poolAmountAfter = $this->pool->poolAmount + $this->payment->paymentAmount; if ($this->payment instanceof SmbcPayment) { $history->incomeMethod = TransferMethod::CVS; $history->incomeCvsPaymentRecordNo = $this->payment->getRecordId(); } if ($this->payment instanceof SmbcAccountTransferResult) { $history->incomeMethod = TransferMethod::ACCOUNT_TRANSFER; $history->incomeAccountTransferResultRecordNo = $this->payment->getRecordId(); } if ($this->payment instanceof YuchoPaymentResult) { $history->incomeMethod = TransferMethod::YUCHO; $history->incomeYuchoTransferRecordNo = $this->payment->getRecordId(); } if ($this->payment instanceof BankCheckResult) { $history->incomeMethod = TransferMethod::BANK_CHECK; $history->incomeBankCheckPaymentRecordNo = $this->payment->getRecordId(); } if ($this->payment instanceof CreditcardAutoPaymentResult) { $history->incomeMethod = TransferMethod::CREDITCARD; $history->incomeCreditcardPaymentRecordNo = $this->payment->getRecordId(); } $this->history = $history; } private function setPoolDone() { $this->payment->poolDone = ["済"]; } private function setPoolAmount() { $this->pool->poolAmount += $this->payment->paymentAmount; } private function save() { $this->history->save(); $this->pool->save(); $this->payment->save(); } private function clear() { $this->payment = null; $this->pool = null; $this->history = null; } }