db->beginTransaction(); try { // 根据流水号获取提现记录 $withdrawLog = MchWithdrawLog::find()->where(['id' => $data['withdrawal_source_id'], 'status' => 1])->one(); if (!$withdrawLog) { throw new \Exception("提现记录不存在"); } $withdrawLog->withdraw_status = 2; if (!$withdrawLog->save()) { throw new \Exception("提现状态修改失败"); } $mch = Mch::find()->where([ 'id' => $withdrawLog->mch_id, 'mall_id' => $withdrawLog->mall_id, 'user_id' => $withdrawLog->user_id, 'status' => 1 ])->one(); if ($mch) { $mch->balance += $withdrawLog->num; if (!$mch->save()) { throw new \Exception("商户余额修改失败"); } \Yii::$app->custom->logs("商户提现回退:" . $withdrawLog->user_id, '回退金额:' . $withdrawLog->num); } $trans->commit(); return true; } catch (\Exception $e) { $trans->rollBack(); \Yii::$app->custom->logs("退款失败", $e->getMessage()); return false; } } }