chengkun
2025-05-23 a6f7b382623096b6a00924f418447cf5204e825e
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
<?php
 
class subscribe_model extends model{
 
    //以下为phpyun5.0新增
    /**
     * @desc   引用log类,添加用户日志   
     */
    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=''); 
    }
    /**
     *  @desc   获取缓存数据
     */
    private function getClass($options){
        
        if (!empty($options)){
            
            include_once ('cache.model.php');
            
            $cacheM     =   new cache_model($this->db, $this->def);
            
            $cache      =   $cacheM -> GetCache($options);
            
            return $cache;
        }
    }
    /**
     * 获取订阅列表
     * $whereData     查询条件
     * $data         自定义处理数组
     */
     
    public function getList($whereData,$data=array()){
        $ListNew    =    array();
        $List        =    $this -> select_all('subscribe',$whereData);
        
        if(!empty( $List )){
            $cache   =   $this -> getClass(array('job','city','user'));
            foreach($List as $k=>$v){
                $jobname    =    $cityname    =    array();
                $jobname[]    =    $cache['job_name'][$v['job1']];
                $jobname[]    =    $cache['job_name'][$v['job1_son']];
                if($cache['job_name'][$v['job_post']]){
                    
                    $jobname[]            =    $cache['job_name'][$v['job_post']];
                }
                
                $cityname[]                =    $cache['city_name'][$v['provinceid']];
                
                if($cache['city_name'][$v['cityid']]){
                    $cityname[]            =    $cache['city_name'][$v['cityid']];
                }
                if($cache['city_name'][$v['three_cityid']]){
                    $cityname[]            =    $cache['city_name'][$v['three_cityid']];
                } 
                
                $List[$k]['jobname']    =    @implode(',',$jobname);
                $List[$k]['city_name']    =    @implode('-',$cityname);
                if($v['minsalary'] && $v['maxsalary']){
                    if($this ->config['resume_salarytype']==1){
                        $List[$k]['salary']  =  $v['minsalary'].'-'.$v['maxsalary'];
                    }else{
                        if($v['maxsalary']<1000){
                            if($this->config['resume_salarytype']==2){
                                $List[$k]['salary']  =  '1千以下';
                            }elseif($this->config['resume_salarytype']==3){
                                $List[$k]['salary']  =  '1K以下';
                            }elseif($this->config['resume_salarytype']==4){
                                $List[$k]['salary']  =  '1k以下';
                            }
                        }else{
                            $List[$k]['salary']  =  changeSalary($v['minsalary']).'-'.changeSalary($v['maxsalary']);
                        }
                    }
                }elseif ($v['minsalary']){
                    if($this ->config['resume_salarytype']==1){
                        $List[$k]['salary']  =  $v['minsalary'];
                    }else{
                        $List[$k]['salary']  =  changeSalary($v['minsalary']);
                    }
                }elseif ($v['maxsalary']){
                    if($this ->config['resume_salarytype']==1){
                        $List[$k]['salary']  =  $v['maxsalary'];
                    }else{
                        $List[$k]['salary']  =  changeSalary($v['maxsalary']);
                    }
                }else{
                    
                    $List[$k]['salary']  =  '面议';
                }
            }
        }
 
        return    $List;
    }
    public function getInfo($where=array(), $data = array()) {
        
        $select     =   $data['field'] ? $data['field'] : '*';
        $Info        =   $this -> select_once('subscribe', $where, $select);
        return $Info;
    }
    function upInfo($data=array(),$Where=array()){
        
        return $this->update_once('subscribe',$data,$Where);
    }
    function addInfo($data=array()){
        
        return $this->insert_into('subscribe',$data);
    }
    /**
     * 获取订阅记录列表subscriberecord
     * $whereData     查询条件
     * $data         自定义处理数组
     */
     
    public function getRecordList($whereData,$data=array()){
        $ListNew    =    array();
        $List        =    $this -> select_all('subscriberecord',$whereData);
 
        return    $List;
    }
    
    /**
     * 删除下载简历
     * $whereData     查询条件
     * $data         自定义处理数组
     */
    public function del($id,$data){
        
        $limit                =  'limit 1';
        $return['layertype']  =     0;
        
        if (!empty($id)){
            
            if(is_array($id)){
                
                $id  =  pylode(',', $id);
                $return['layertype']  =  1;
                $limit                =  '';
            }
            if($data['uid']){
                $delWhere    =    array('uid'=>$data['uid'],'id'=>array('in',$id));
            }else{
                $delWhere    =    array('id'=>array('in',$id));
            }
 
            $nid      =  $this -> delete_all('subscribe',$delWhere,$limit);
            
            if ($nid){
                
                $this -> delete_all('subscriberecord',array('sid'=>array('in',$id)),$limit);
                $this -> addMemberLog($data['uid'],$data['usertype'],"删除订阅(ID:".$id.")",5,3);
                $return['msg']      =  '删除成功';
                $return['errcode']  =  '9';
            }else{
                $return['msg']      =  '删除失败';
                $return['errcode']  =  '8';
            }
        }else{
            $return['msg']      =  '请选择您要删除的记录';
            $return['errcode']  =  '8';
        }
        return $return;
    }
 
    /**
     * 应用中增加订阅
     * 判断了是增加或是修改
     * 2019-07-12
     */
    public function createSubscribe($data = array()){
 
        $res    =    array(
            'errcode'    =>    8,
            'msg'        =>    ''
        );
 
        if(empty($data['uid'])){
            $res['msg']    =    '您还未登录!';
            return $res;
        }
 
        //个人 企业用户才可订阅
        if(empty($data['usertype']) || !in_array($data['usertype'], array(1, 2))){
            $res['msg']    =    '只有个人和企业用户才可订阅!';
            return $res;
        }
 
        $sid            =    intval($data['sid']);
        $data['type']    =    intval($data['type']);
 
        //判断订阅类型
        if($data['usertype'] != $data['type']){
            $res['msg']    =    '订阅类型错误!';
            return $res;
        }
 
        //用户绑定的微信信息
        $userField    =    '`email`,`wxid`, `wxopenid`';
        $userInfo    =    $this -> select_once('member' , array('uid' => $data['uid']), $userField);
        if(empty($userInfo)){
            $res['msg']    =    '用户信息错误!';
            return $res;
        }
 
        //未传入订阅的id时,通过uid type判断是否已订阅
        if(empty($sid)){
            $oldField    =    array('field' => '`id`');
            $oldSub        =    $this -> getInfo(array('uid' => $data['uid'], 'type' => $data['type']), $oldField);
            if(!empty($oldSub)){
                $sid    =    $oldSub['id'];
            }
        }
 
        if(empty($userInfo['wxid']) && empty($userInfo['wxopenid'])){
            require_once ('weixin.model.php');
            $wxM        =    new weixin_model($this->db, $this->def);
            $qrcode        =    $wxM -> applyWxQrcode($_POST['wxloginid'], '', $data['uid']);
            if(empty($qrcode)){
                $res['msg']    =    '暂未绑定微信公众号,无法订阅!';
            }else{
                $res['msg']    =    '马上绑定微信, 接收订阅信息!';
            }
            return $res;
        }
 
        //处理参数
        $data['email']        =    $userInfo['email'];
        $data['ctime']        =    time(); 
        if(empty($sid)){
            $data['uid']    =    $data['uid'];
            $sid            =    $this -> addInfo($data);
        }else{
            unset($data['sid']);
 
            $this -> upInfo($data, array('id' => $sid));
        }
 
        $res['errcode']        =    9;
        $res['msg']            =    '订阅成功!';
        return $res;
 
    }
 
    /**
     * 发送订阅
     * type 1-订阅职位,2-订阅人才
     * limit 发送订阅信息的数量默认为5
     * 2019-07-12
     */
    public function sendSubscribe($data = array()){
 
        $res    =    array(
            'errcode'    =>    8,
            'msg'        =>    ''
        );
        if(empty($data['type']) || !in_array($data['type'], array(1, 2))){
            $res['msg']    =    '缺少订阅类型参数!';
            return $res;
        }
 
        //设置默认订阅数量
        $data['limit']    =    empty($data['limit']) ? 5 : intval($data['limit']);
 
        //获取需要发送的订阅
        $subscribe        =    $this -> select_all('subscribe', array(
            'type'    =>    $data['type'],
            'time'    =>    array('>', 0)));
        if(empty($subscribe)){
            $res['msg']    =    '暂无订阅数据!';
            return $res;
        }
 
        $currentTime    =    time();
        foreach ($subscribe as $sv) {
            //距离当前的天数
            $ytime        =    $currentTime - $sv['ctime'];
            $endDays    =    ceil(bcdiv($ytime, 86400, 2));
 
            //发送周期的整数则发送订阅信息
            if(bccomp(bcmod($endDays, $sv['time']), 0, 2) != 0){
                continue;
            }
        
            $whereData    =    array();
 
            //增加更新时间条件
            if(!empty($sv['cycle_time']) && $sv['cycle_time'] > 0){
                $beginTime                    =    $sv['cycle_time']*86400;
                $whereData['lastupdate']    =    array('>=', $currentTime - $beginTime);
            }
 
            //增加薪水条件
            if(!empty($sv['minsalary'])){
                $whereData['minsalary']        =    array('>=', $sv['minsalary']);
            }
            if(!empty($sv['maxsalary'])){
                $whereData['maxsalary']        =    array('<=', $sv['maxsalary']);
            }
 
            
 
            $whereData['limit']                =    $data['limit'];
            $whereData['orderby']            =    'lastupdate';
            //1-订阅职位,2-订阅人才
            if($sv['type'] == 2){
                //省份城市条件
                if(!empty($sv['three_cityid'])){
                    $whereData['city_classid']    =    array('findin', $sv['three_cityid']);
                }elseif (!empty($sv['cityid'])) {
                    $whereData['city_classid']    =    array('findin', $sv['cityid']);
                }elseif (!empty($sv['provinceid'])) {
                    $whereData['city_classid']    =    array('findin', $sv['provinceid']);
                }
                if(!empty($sv['job_post'])){
                    $whereData['job_classid']    =    array('findin', $sv['job_post']);
                }elseif (!empty($sv['job1_son'])) {
                    $whereData['job_classid']    =    array('findin', $sv['job1_son']);
                }elseif (!empty($sv['job1'])) {
                    $whereData['job_classid']    =    array('findin', $sv['job1']);
                }
                $whereData['status']            =    1;
                $whereData['r_status']            =    1;
 
                $subList    =    $this -> select_all('resume_expect', $whereData, '`name`');
            }elseif ($sv['type'] == 1) {
                //省份城市条件
                if(!empty($sv['three_cityid'])){
                    $whereData['three_cityid']    =    $sv['three_cityid'];
                }elseif (!empty($sv['cityid'])) {
                    $whereData['cityid']        =    $sv['cityid'];
                }elseif (!empty($sv['provinceid'])) {
                    $whereData['provinceid']    =    $sv['provinceid'];
                }
                if(!empty($sv['job_post'])){
                    $whereData['job_post']        =    $sv['job_post'];
                }elseif (!empty($sv['job1_son'])) {
                    $whereData['job1_son']        =    $sv['job1_son'];
                }elseif (!empty($sv['job1'])) {
                    $whereData['job1']            =    $sv['job1'];
                }
                $whereData['state']                =    1;
                $subList    =    $this -> select_all('company_job', $whereData, '`name`');                
            }
            //没查询到数据直接pass
            if(empty($subList)){
                continue;
            }
 
            //订阅的职位 简历名称
            $nameArr        =    array();
            foreach($subList as $val){
                $nameArr[]    =    $val['name'];
            }
            $contentStr        =    @implode(',', $nameArr);
 
            //发送微信通知信息
            require_once ('weixin.model.php');
            $wxM            =    new weixin_model($this->db, $this->def);
            $FirstType         =    $sv['type']==1 ? '职位' : '人才';
            $wxRes            =    $wxM -> sendSubscribe(array(
                'uid'        =>    $sv['uid'],
                'First'        =>    '您订阅的'.$FirstType.'有了新的信息!',
                'content'    =>    $contentStr
            ));
            if($wxRes['errcode']==8){
                continue;
            }
 
            //保存相关订阅记录
            $recordArr        =    array(
                'sid'        =>    $sv['id'],
                'uid'        =>    $sv['uid'],
                'type'        =>    $sv['type'],
                'content'    =>    $contentStr,
                'time'        =>    $currentTime
            );
 
            $this -> insert_into('subscriberecord', $recordArr);
        }
 
        $res['errcode']    =    9;
        return $res;
    }
    
}
?>