quanwei
2025-12-05 feda780069d64479c0c20493603717e100655da9
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
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
 
namespace app\api\model\branch;
 
use app\common\model\branch\Member as MemberModel;
// use app\common\model\branch\Branch as BranchModel;
// use app\common\model\user\User as UserModel;
 
/**
 * 连盟成员模型
 * Class Member
 * @package app\api\model\branch
 */
class Member extends MemberModel
{
    /**
     * 获取连盟成员列表
     */
    public function getList($params = [])
    {
        // 构建查询规则
        $model = $this->alias('A')
            ->field(['A.*, user.nickName, user.avatarUrl, user.real_name, user.mobile, branch_position.weight, branch_position.name as position_name'])
            ->with(['branch', 'supplier'])
            ->join('user', 'user.user_id = A.user_id', 'left')
            ->join('branch_position', 'branch_position.position_id = A.position_id', 'left')
            ->where('A.is_delete', '=', 0)
            ->where('A.position_id', '<>', 0)
            ->where('A.position_id', '<>', 3)
            ->order(['branch_position.weight' => 'desc', 'A.create_time' => 'desc']);
        // 查询条件
        if (!empty($params['branch_id'])) {
           $model = $model->where('A.branch_id', '=', $params['branch_id']);
        }
        if (!empty($params['keywords'])) {
            if ($params['keywords'] == 'user_id') {
                $model = $model->where('user.user_id', '=', (int)$params['keywords']);
            } else {
                $model = $model->where('user.nickName|user.real_name|user.mobile', 'like', '%' . $params['keywords'] . '%');
            }
        }
        return $model->paginate($params);
    }
 
    /**
     * 新增记录
     */
    // public function add($data)
    // {
    //     $data['app_id'] = self::$app_id;
    //     $this->save($data);
    //     // 更新分会人数
    //     BranchModel::incTotal($data['branch_id']);
    //     // 检查真实姓名和电话有没有更改
    //     $user = UserModel::detail($data['user_id']);
    //     $userData = [];
    //     if ($user['real_name'] != $data['real_name']) {
    //         $userData['real_name'] = $data['real_name'];
    //     }
    //     if ($user['mobile'] != $data['mobile']) {
    //         $userData['mobile'] = $data['mobile'];
    //     }
    //     if ($userData) {
    //         $user->save($userData);
    //     }
    //     return true;
    // }
 
    /**
     * 编辑连盟成员
     * @param $data
     * @return bool
     */
    // public function edit($data)
    // {
    //     return $this->save($data) !== false;
    // }
 
    /**
     * 删除连盟成员
     * @return mixed
     */
    public function setDelete()
    {
        return $this->transaction(function () {
            return $this->delete();
        });
    }
    
    /**
     * 提现打款成功:累积提现佣金
     */
    public static function totalMoney($user_id, $money)
    {
        $model = self::detail($user_id);
        return $model->save([
            'freeze_money' => $model['freeze_money'] - $money,
            'total_money' => $model['total_money'] + $money,
        ]);
    }
 
    /**
     * 提现驳回:解冻股东资金
     */
    public static function backFreezeMoney($user_id, $money)
    {
        $model = self::detail($user_id);
        return $model->save([
            'money' => $model['money'] + $money,
            'freeze_money' => $model['freeze_money'] - $money,
        ]);
    }
 
 
}