quanwei
2025-12-13 30563323a53b0d0260c97d08a9e8bd4cc8227a95
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
<?php
 
namespace app\shop\model\plus\vip;
 
use app\common\model\plus\vip\Capital;
use app\common\model\plus\vip\Cash as CashModel;
use app\common\service\message\MessageService;
 
/**
 * VIP专区提现明细模型
 */
class Cash extends CashModel
{
    /**
     * 获取列表
     */
    public function getList($search)
    {
        $model = $this->with(['user'])
            ->order(['create_time' => 'desc']);
            
        if (!empty($search['nick_name'])) {
            $model = $model->where('user.nickName', 'like', '%' . $search['nick_name'] . '%');
        }
 
        if (isset($search['apply_status']) && $search['apply_status'] > -1) {
            $model = $model->where('apply_status', '=', $search['apply_status']);
        }
 
        return $model->paginate($search);
    }
    /**
     * 提现审核
     */
    public function submit($param)
    {
        $data = ['apply_status' => $param['apply_status']];
        if ($param['apply_status'] == 30) {
            $data['reject_reason'] = $param['reject_reason'];
        }
        // 更新申请记录
        $data['audit_time'] = time();
        self::update($data, ['id' => $param['id']]);
        // 提现驳回:解冻分销商资金
        if ($param['apply_status'] == 30) {
            User::backFreezeMoney($param['user_id'], $param['money']);
        }
 
        // 发送模板消息
        (new MessageService)->cash($this);
        return true;
    }
     /**
      * 确认已打款
      */
    public function money()
    {
        $this->startTrans();
        try {
            // 更新申请状态
            $data = ['apply_status' => 40, 'audit_time' => time()];
            self::update($data, ['id' => $this['id']]);
 
            // 更新分销商累积提现佣金
            User::totalMoney($this['user_id'], $this['money']);
 
            // 记录分销商资金明细
            Capital::add([
                'user_id' => $this['user_id'],
                'flow_type' => 20,
                'money' => -$this['money'],
                'describe' => '申请提现',
            ]);
            // 发送模板消息
           //(new Message)->withdraw($this);
            // 事务提交
            $this->commit();
            return true;
        } catch (\Exception $e) {
            $this->error = $e->getMessage();
            $this->rollback();
            return false;
        }
    }
}