chengkun
2025-05-23 0d8e263c22903234efea68fd13a27d8b7b59aac1
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<?php
 
class companyaccount_model extends model{
 
    
    // 获取套餐数据信息
    private function getStatisInfo($uid, $data = array())
    {
        require_once ('statis.model.php');
 
        $StatisM    =   new statis_model($this->db, $this->def);
 
        return $StatisM -> getInfo($uid, $data);
    }
    
    // 添加会员日志
    private function addMemberLog($uid, $usertype, $content, $opera = '', $type = '')
    {
        require_once ('log.model.php');
 
        $LogM       =   new log_model($this->db, $this->def);
 
        return $LogM -> addMemberLog($uid, $usertype, $content, $opera, $type);
    }
    
    /**
     * @data    添加company_account 子账号数据
     */
    public function addInfo($data = array()) {
        
        $nid    =    $this -> insert_into('company_account', $data);
        return $nid;
    }
 
    /**
     * @data    修改company_account 子账号数据
     */
    public function updInfo($where = array(), $data = array()) {
        
        $nid    =    $this -> update_once('company_account', $data, $where);
        return $nid;
        
    }
 
    /**
     * @data    company_account 子账号数据列表
     */
    public function getList($where = array(), $data = array()) {
 
        $select =   $data['field'] ? $data['field'] : '*';
        $List    =   $this -> select_all('company_account', $where, $select);
        return $List;
        
    }
 
    /**
     * @data    company_account 子账号数据信息
     */
    public function getInfo($where = array(), $data = array()) {
 
        $select =   $data['field'] ? $data['field'] : '*';
        $Info    =   $this -> select_once('company_account', $where, $select);
        return $Info;
        
    }
 
    /**
     * @data    company_account 子账号数量
     */
    public function getNum($where = array()) {
 
        return $this -> select_num('company_account', $where);
        
    }
 
    /**
     * @data    添加company_account 子账号数据
     * 创建完子账号,增加 company_statis信息
     */
    public function createAccount($data = array()){
        $res    =   array(
            'errcode'   =>  8,
            'msg'       =>  ''
        );
        if(empty($data['comid'])){
            $res['msg'] =   '缺少主账号信息!';
            return $res;
        }
 
        //增加company_statis信息
        require_once ('statis.model.php');
        $statisM        =    new statis_model($this->db, $this->def);
        $fatherData     =   $statisM -> getInfo($data['comid'], array('usertype' => 2));
        if(empty($fatherData)){
            $res['msg'] =   '主账号套餐信息错误!';
            return $res;
        }
 
        //创建子账号
        $accountId      =   $this -> addInfo($data);
        if(empty($accountId)){
            $res['msg'] =   '子账号创建失败!';
            return $res;
        }
 
        //补充主账号的信息
        $sonStatisData  =   array();
        $sonStatisData['rating']      =   $fatherData['rating'];
        $sonStatisData['rating_name'] =   $fatherData['rating_name'];
        $sonStatisData['rating_type'] =   $fatherData['rating_type'];
        $sonStatisData['vip_stime']   =   $fatherData['vip_stime'];
        $sonStatisData['vip_etime']   =   $fatherData['vip_etime'];
        $sonStatisData['uid']         =   $accountId;
 
        $statisId       =   $statisM -> addInfo($sonStatisData, array('usertype' => 2));
 
        $res['errcode'] =   9;
        return $res;
    }
 
    /**
     * @desc   删除子账户
      *                        子账号套餐归还主账号
      *                        删除相关数据表信息:member、company_statis、company_account
     *                        
     * @param  int $data['pid'] 主账号
     * @param  int $data['uid'] 子账号
     * 
     */
    public function delChild($data = array()){
        
        if(empty($data['uid']) || empty($data['pid'])){
            $res            =    array(
                'ecode'        =>    8,
                'msg'        =>    '参数UID错误'
            );
            return $res;
        }else{
            
            $pid            =   intval($data['pid']);
            $uid            =   intval($data['uid']);
        }
        
        $field              =   '`job_num`, `breakjob_num`, `down_resume`, `invite_resume`, `top_num`, `rec_num`, `urgent_num`, `zph_num`';
        $statisChild        =   $this -> getStatisInfo($uid, array('usertype' => 2, 'field' => $field));
        
        $res['id']          =   $this -> delete_all('member', array('uid' => $uid), '');
        
        if ($res['id']) {
 
            /* 子账号套餐添加单主账号 */
            if (!empty($statisChild) && is_array($statisChild)) {
                
                $upStatisData   =   array(
                    
                    'job_num'       =>  array('+', intval($statisChild['job_num'])),
                    'breakjob_num'  =>  array('+', intval($statisChild['breakjob_num'])),
                    'down_resume'   =>  array('+', intval($statisChild['down_resume'])),
                    'invite_resume' =>  array('+', intval($statisChild['invite_resume'])),
                    'top_num'       =>  array('+', intval($statisChild['top_num'])),
                    'rec_num'       =>  array('+', intval($statisChild['rec_num'])),
                    'urgent_num'    =>  array('+', intval($statisChild['urgent_num'])),
                    'zph_num'       =>  array('+', intval($statisChild['zph_num']))
                );
                
                $this -> update_once('company_statis', $upStatisData, array('uid' => $pid));
            }
            
            $this -> delete_all('company_statis', array('uid' => $uid), '');
            $this -> delete_all('company_account', array('uid' => $uid), '');
            $this -> addMemberLog($pid, 2, '删除子账号(UID:'.$uid.')', 27, 3);
            
            $res    =   array('ecode' => 9, 'msg' => '子账号删除成功!');
            
        }else{
            
            $res    =   array('ecode' => 8, 'msg' => '子账号删除失败!');
        }
        return $res;
    }
 
    /**
     * @desc    company_account 子账号数据列表;应用中的列表
     */
    public function getWorkList($where = array(), $data = array()) {
        
        $List   =   array();
        $List   =   $this -> getList($where, $data);
        
        if(empty($List)){
            return $List;
        }
 
        //获取登录名称
        $uid    =   array();
        
        foreach ($List as $v) {
            $uid[]  =   $v['uid'];
        }
        require_once ('userinfo.model.php');        
        $memberM    =   new userinfo_model($this->db, $this->def);
        $memField   =   array('field' => '`uid`, `username`,`status`');
        $tmpList    =   $memberM -> getList(array('uid' => array('in', pylode(',', $uid))), $memField);
        
        $memberList =   array();
        $statusList =   array();
        foreach ($tmpList as $tv) {
            $memberList[$tv['uid']]     =   $tv['username'];
            $statusList[$tv['uid']]     =   $tv['status'];
        }
 
        //给子账号补充登录名称
        foreach ($List as $lk => $lv) {
            
            $List[$lk]['ctime_n']  =   date('Y-m-d',$lv['ctime']);
            
            if(array_key_exists($lv['uid'], $memberList)){
                $List[$lk]['username']  =   $memberList[$lv['uid']];
            }
            if(array_key_exists($lv['uid'], $statusList)){
                $List[$lk]['status']    =   $statusList[$lv['uid']];
            }
        }
 
        return $List;
    }
}
?>