quanwei
2025-12-10 898043fc97d2ab8b793fd317a049b874ed207c6d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
 
namespace app\api\model\plus\vip;
 
use app\common\model\plus\vip\Cash as CashModel;
use app\common\exception\BaseException;
 
 
/**
 * VIP专区提现API模型
 */
class Cash extends CashModel
{
    /**
     * 隐藏属性
     * @var array
     */
    protected $hidden = [
        'app_id',
        'update_time'
    ];
 
    /**
     * 提交提现申请
     * @param $vipUser
     * @param $data
     * @return bool
     * @throws BaseException
     */
    public function submit($vipUser, $data)
    {
        // 设置验证
        $setting = \app\common\model\plus\vip\Setting::getItem('settlement', $vipUser['app_id']);
 
        // 验证最低提现金额
        if ($data['money'] <= 0) {
            $this->error = '提现金额必须大于0';
            return false;
        }
        
        if ($data['money'] < $setting['min_money']) {
            $this->error = '最低提现金额为' . $setting['min_money'] . '元';
            return false;
        }
        
        if ($data['money'] > $vipUser['money']) {
            $this->error = '提现金额不能超过可提现佣金';
            return false;
        }
        // 生成提现单号
        $data['cash_no'] = 'V' . date('YmdHis') . mt_rand(1000, 9999);
        $data['user_id'] = $vipUser['user_id'];
        $data['apply_status'] = 10;
        $data['app_id'] = $vipUser['app_id'];
        
        // 计算手续费
        $fee_rate = $setting['fee_rate'] ?? 0;
        $data['fee_rate'] = $fee_rate;
        $data['fee_money'] = $data['money'] * ($fee_rate * 0.01);
        $data['real_money'] = $data['money'] - $data['fee_money'];
        
        // 开启事务
        $this->startTrans();
        try {
            // 保存提现申请
            $this->save($data);
            
            // 冻结VIP用户资金
            User::freezeMoney($vipUser['user_id'], $data['money']);
 
            $this->commit();
            return true;
        } catch (\Exception $e) {
            $this->rollback();
            $this->error = $e->getMessage();
            return false;
        }
    }
 
    /**
     * 获取提现明细列表
     * @param $user_id
     * @param int $status
     * @param array $query
     * @return \think\Paginator
     * @throws \think\exception\DbException
     */
    public function getList($user_id, $status = -1, $query = [])
    {
        $model = $this->where('user_id', '=', $user_id);
 
        if ($status > -1) {
            $model = $model->where('apply_status', '=', $status);
        }
 
        return $model->with(['user'])
            ->order(['create_time' => 'desc'])
            ->paginate($query, false, [
                'query' => \request()->request()
            ]);
    }
}