Browse Source

转移可提余额 到 余额

master
wanghongjun 3 years ago
parent
commit
feb07bb0b9
  1. 18
      app/controller/User.php
  2. 21
      app/model/User.php

18
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('成功');
}
/**
* 退出登陆
*/

21
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

Loading…
Cancel
Save