123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\Db;
- //use app\common\model\wallet;
- /**
- * 用户钱包
- */
- class Takecash extends Api
- {
- protected $noNeedLogin = [];
- protected $noNeedRight = ['*'];
- //提现记录
- public function take_cash_log(){
- $list = Db::name('take_cash')->field('id, number, status, createtime')->where(['user_id'=>$this->auth->id])->autopage()->order('id desc')->select();
- if ($list) {
- foreach ($list as &$v) {
- $v['title'] = '余额提现';
- $v['number'] = '-' . $v['number'];
- $v['createtime'] = date('Y.m.d H:i', $v['createtime']);
- }
- }
- $this->success('success',$list);
- }
- //提现金额配置
- public function withdrawal_config() {
- $show = config('site.withdrawal_show');//提现说明
- $list = Db::name('withdrawal_config')->where('is_show',1)->order('weight asc,id asc')->select();
- if ($list) {
- $arr = [
- 'id' => -1,
- 'money' => 0,
- 'real_money' => 0,
- 'type' => 0,
- 'is_show' => 1,
- 'weight' => 1
- ];
- array_push($list, $arr);
- }
- $return_data['show'] = $show;
- $return_data['withdrawal_rate'] = config('site.withdrawal_rate') > 0 ? config('site.withdrawal_rate') : 10;
- $return_data['min'] = config('site.withdraw_min_money');
- $return_data['list'] = $list;
- $this->success('success',$return_data);
- }
- //提现
- public function withdrawal() {
- $id = input('id', 0, 'intval');
- $type = input('type', 0, 'intval'); //账户类型:1=支付宝,2=银行卡
- $freemoney = input('freemoney', 0, 'intval'); //自定义金额
- if (!$id && !$freemoney) {
- $this->error('请选择或填写提现金额');
- }
- if (!in_array($type, [1, 2])) {
- $this->error('请选择提现账户~');
- }
- if ($this->auth->idcard_status != 1) {
- $this->error('请先完成实名认证~');
- }
- if ($this->auth->gender == 1) {
- $user_wallet = Db::name('user_wallet')->where('user_id',$this->auth->id)->find();
- $is_vip = $this->is_vip($user_wallet['vip_endtime'],$user_wallet['vip_level']);
- if($is_vip != 2){
- $this->error('SVIP才能提现');
- }
- }
- if ($id > 0) {
- $withdrawal_config = Db::name('withdrawal_config')->find($id);
- if (!$withdrawal_config) {
- $this->error('提现金额不存在~');
- }
- if ($withdrawal_config['is_show'] != 1) {
- $this->error('提现金额暂未开放~');
- }
- if ($withdrawal_config['money'] <= 0 || $withdrawal_config['real_money'] <= 0 || $withdrawal_config['money'] < $withdrawal_config['real_money']) {
- $this->error('提现金额异常~');
- }
- //扣除金额
- $money = $withdrawal_config['money'];
- //实际获得金额
- $real_money = $withdrawal_config['real_money'];
- }
- if ($freemoney > 0) {
- //扣除金额
- $money = floatval($freemoney);
- $withdraw_min_money = config('site.withdraw_min_money');
- if($money < $withdraw_min_money){
- $this->error('最低提现'.$withdraw_min_money);
- }
- //平台手续费
- $withdrawal_rate = config('site.withdrawal_rate') >= 0 ? config('site.withdrawal_rate') : 10;
- $plat_money = bcdiv(bcmul($money,$withdrawal_rate,2),100,2);
- //减去手续费,得实得金额
- $real_money = bcsub($money,$plat_money,2);
- }
- if ($money <= 0 || $real_money <= 0) {
- $this->error('提现金额异常');
- }
- $check = Db::name('take_cash')->where(['user_id'=>$this->auth->id,'status'=>0])->find();
- if($check){
- $this->error('您有一笔提现在审核中,待审核通过后再申请提现。');
- }
- $user_money = model('wallet')->getwallet($this->auth->id,'money');
- if($money > $user_money){
- $this->error('可提现余额不足');
- }
- $user_bank_info = Db::name('user_bank')->where(['user_id' => $this->auth->id, 'type' => $type])->find();
- if (!$user_bank_info) {
- $this->error('请先添加提现方式');
- }
- $alipay_account = $user_bank_info['banknumber'];
- $realname = $user_bank_info['realname'];
- $data = [
- 'user_id' => $this->auth->id,
- 'wallet_id' => $freemoney > 0 ? 0 : $id,
- 'number' => $money,
- 'money' => $real_money,
- 'alipay_account' => $alipay_account,
- 'status' => 0,
- 'createtime' => time(),
- 'updatetime' => time(),
- 'type' => $type,
- 'realname' => $realname
- ];
- $msg = '申请成功请等待审核';
- //开启事务
- Db::startTrans();
- $log_id = Db::name('take_cash')->insertGetId($data);
- if (!$log_id) {
- Db::rollback();
- $this->error('您的网络开小差啦~');
- }
- //扣除money
- $rs_wallet = model('Wallet')->lockChangeAccountRemain($this->auth->id,0,'money',-$data['number'],15,'提现(审核中)','take_cash',$log_id);
- if($rs_wallet['status']===false)
- {
- Db::rollback();
- $this->error($rs_wallet['msg']);
- }
- Db::commit();
- $this->success($msg);
- }
- }
|