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