From feb07bb0b9c38f64f10cc42c8f552ffe28d8abab Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Mon, 25 Sep 2023 11:33:05 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BD=AC=E7=A7=BB=E5=8F=AF=E6=8F=90=E4=BD=99?= =?UTF-8?q?=E9=A2=9D=20=E5=88=B0=20=E4=BD=99=E9=A2=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/User.php | 18 ++++++++++++++++++ app/model/User.php | 21 +++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/app/controller/User.php b/app/controller/User.php index 9d5128b..e108618 100644 --- a/app/controller/User.php +++ b/app/controller/User.php @@ -228,6 +228,24 @@ class User extends BaseController return $this->renderSuccess('数据返回成功', ['list' => $list]); } + /** + * + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function transferBalance() + { + $userData = $this->request->userInfo; + + $result = UserModel::transferBalance($userData['id']); + + if (!$result['status']) return $this->renderError($result['msg']); + + return $this->renderSuccess('成功'); + } + /** * 退出登陆 */ diff --git a/app/model/User.php b/app/model/User.php index 916c6db..990a4ff 100644 --- a/app/model/User.php +++ b/app/model/User.php @@ -268,6 +268,27 @@ class User extends Model return ['status' => 1]; } + /** + * 可提余额 转移到 余额 + * @param $user_id + * @return array|int[] + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public static function transferBalance($user_id) + { + + $User = self::find($user_id); + if ($User->withdrawal_balance <= 0) return ['status' => 0,'msg' => '可提余额不足,无法转移']; + + $User->balance = bcadd($User->balance + $User->withdrawal_balance,2); + $User->withdrawal_balance = 0; + + $User->save(); + return ['status' => 1]; + } + /** * 生成盐值 * @return string