From 2d4bf9bb2d755b0c6447cceaee70f232ccc20409 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Thu, 28 Sep 2023 18:36:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=8B=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/User.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/app/controller/User.php b/app/controller/User.php index 5812ab9..9f3dd12 100644 --- a/app/controller/User.php +++ b/app/controller/User.php @@ -239,11 +239,22 @@ class User extends BaseController { $userData = $this->request->userInfo; - $result = UserModel::transferBalance($userData['id']); + $connection = Db::connect(); - if (!$result['status']) return $this->renderError($result['msg']); + try { + + # 开启事务 + $connection->startTrans(); - return $this->renderSuccess('成功'); + $result = UserModel::transferBalance($userData['id']); + if (!$result['status']) return $this->renderError($result['msg']); + + $connection->commit(); + return $this->renderSuccess('成功'); + } catch (\Exception $e) { + $connection->rollback(); + return $this->renderError('操作失败'); + } } /**