rechargeModel = $rechargeModel; } public function tryRecharge() { DB::transaction(function () { $this->_tryRecharge(); }); return true; } /** * @throws ShopException */ private function _tryRecharge() { $result = $this->updateMemberPoint(); if (!$result) { throw new ShopException('充值失败:更新数据失败'); } $result = $this->updateRechargeStatus(); if (!$result) { throw new ShopException('充值失败:修改充值状态失败'); } } /** * @return PointService|bool * @throws ShopException */ private function updateMemberPoint() { return (new PointService($this->getChangeData()))->changePoint(); } /** * @return bool */ private function updateRechargeStatus() { $this->rechargeModel->status = RechargeModel::STATUS_SUCCESS; return $this->rechargeModel->save(); } /** * @return array */ private function getChangeData() { return [ 'point_mode' => PointService::POINT_MODE_ADMIN, 'member_id' => $this->rechargeModel->member_id, 'point' => $this->rechargeModel->money, 'remark' => $this->rechargeRemark(), 'point_income_type' => $this->pointIncomeType() ]; } /** * @return string */ private function rechargeRemark() { return "充值变动['{$this->rechargeModel->money}']积分,充值记录ID【{$this->rechargeModel->id}】"; } /** * @return int */ private function pointIncomeType() { return $this->rechargeModel->money < 0 ? PointService::POINT_INCOME_LOSE : PointService::POINT_INCOME_GET; } }