quanwei
2025-11-21 1db9a4130699636cabe7e0c9f7f15d004aadada0
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
<?php
 
namespace app\api\model\plus\vip;
 
use app\api\model\plus\vip\User as VipUserModel;
use app\common\model\plus\vip\Apply as ApplyModel;
use app\common\exception\BaseException;
 
 
/**
 * VIP专区申请模型
 */
class Apply extends ApplyModel
{
    /**
     * 隐藏属性
     * @var array
     */
    protected $hidden = [
        'app_id',
        'update_time'
    ];
 
    /**
     * 提交申请
     * @param $user
     * @param $data
     * @return bool|false
     * @throws BaseException
     */
    public function submit($user, $data)
    {
        // 是否已提交申请
        if ($this->checkExist($user['user_id'])) {
            throw new BaseException(['msg' => '该用户已提交过申请,请勿重复提交']);
        }
 
        // 表单数据
        $data['user_id'] = $user['user_id'];
        $data['apply_status'] = 10;
        $data['app_id'] = $user['app_id'];
        
        // 开启事务
        $this->startTrans();
        try {
            // 保存申请信息
            $this->save($data);
            
            // 新增VIP专区用户
            VipUserModel::add($user['user_id'], [
                'real_name' => $data['real_name'],
                'mobile' => $data['mobile'],
                'referee_id' => $user['referee_id'] ?? 0,
            ]);
 
            $this->commit();
            return true;
        } catch (\Exception $e) {
            $this->rollback();
            throw new BaseException(['msg' => $e->getMessage()]);
        }
    }
 
    /**
     * 检查是否已提交申请
     * @param $user_id
     * @return bool
     */
    private function checkExist($user_id)
    {
        return (new self)->where('user_id', '=', $user_id)
            ->where('apply_status', '<>', 30)
            ->count() > 0;
    }
 
    /**
     * 获取申请列表
     * @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()
            ]);
    }
}