quanwei
2025-11-11 0d04d60f456b1902c1e27b9586652649df3963d4
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
<?php
 
namespace app\api\model\user;
 
use app\common\exception\BaseException;
use app\common\model\user\Cash as CashModel;
use app\api\model\settings\Setting as SettingModel;
 
/**
 * 余额提现明细模型
 */
class Cash extends CashModel
{
    /**
     * 隐藏字段
     */
    protected $hidden = [
        'update_time',
    ];
 
    /**
     * 获取余额提现明细
     */
    public function getList($user_id, $apply_status = -1, $limit = 15)
    {
        $model = $this;
        $apply_status > -1 && $model = $model->where('apply_status', '=', $apply_status);
        return $model->where('user_id', '=', $user_id)->order(['create_time' => 'desc'])
            ->paginate($limit);
    }
 
    /**
     * 提交申请
     */
    public function submit($user, $data)
    {
        // 数据验证
        $this->validation($user, $data);
        $setting = SettingModel::getItem('balance_cash');
        // 新增申请记录
        $this->save(array_merge($data, [
            'user_id' => $user['user_id'],
            'apply_status' => 10,
            'app_id' => self::$app_id,
            'real_money' => round($data['money'] * $setting['cash_ratio'] / 100, 2),
            'cash_ratio' => $setting['cash_ratio'],
        ]));
        // 冻结用户资金
        $user->freezeMoney($data['money']);
        return true;
    }
 
    /**
     * 数据验证
     */
    private function validation($user, $data)
    {
        // 结算设置
        $settlement = SettingModel::getItem('balance_cash');
        // 最低提现佣金
        if ($data['money'] <= 0) {
            throw new BaseException(['msg' => '提现金额不正确']);
        }
        if ($user['balance'] <= 0) {
            throw new BaseException(['msg' => '当前用户没有可提现余额']);
        }
        if ($data['money'] > $user['balance']) {
            throw new BaseException(['msg' => '提现金额不能大于可提现余额']);
        }
        if ($data['money'] < $settlement['min_money']) {
            throw new BaseException(['msg' => '最低提现金额为' . $settlement['min_money']]);
        }
        if ($data['pay_type'] == '20') {
            if (empty($data['alipay_name']) || empty($data['alipay_account'])) {
                throw new BaseException(['msg' => '请补全提现信息']);
            }
        } elseif ($data['pay_type'] == '30') {
            if (empty($data['bank_name']) || empty($data['bank_account']) || empty($data['bank_card'])) {
                throw new BaseException(['msg' => '请补全提现信息']);
            }
        }
    }
 
}