chengkun
2025-04-18 1bb985f32f2efe0f9dd69f3cf29a1c809b1cf96d
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
<?php
/*
* $Author :PHPYUN开发团队
*
* 官网: http://www.phpyun.com
*
* 版权所有 2009-2021 宿迁鑫潮信息技术有限公司,并保留所有权利。
*
* 软件声明:未经授权前提下,不得用于商业运营、二次开发以及任何形式的再次发布。
 */
class upload_controller extends common{
    
    private $tokenSalt = 'phpyun';//加密的salt
 
    //生成二维码传图的密钥(放到二维码中)
    private function generateToken($type, $uid){
        //考虑到二维码承载的信息长度有限,tokenSalt和password都限定字符串长度,以得到较短的token
        $userinfoM    =    $this->MODEL('userinfo');
        $row         =     $userinfoM->getInfo(array('uid'=> $uid),array('field'=>'`password`'));
        $password     = isset($row['password']) ? $row['password'] : '';
        $password     = substr($password, 0, 8);
        
        $this->tokenSalt    = $this->config['sy_safekey'];
        return yunEncrypt("{$type}|{$uid}|{$password}", $this->tokenSalt);
    }
 
    //验证二维码传图的密钥(提交图片之前进行验证)
    private function checkToken($token){
        $token        =     urldecode($token);
        
        $this->tokenSalt = $this->config['sy_safekey'];
        $str         =     yunDecrypt($token, $this->tokenSalt);
        $arr         =     explode('|', $str);
        if(count($arr) != 3 || $arr[1] == ''){
            return false;
        }
        //根据uid查询password,对比password
        $uid = $arr[1];
        $userinfoM    =    $this->MODEL('userinfo');
        $row         =     $userinfoM->getInfo(array('uid'=> $uid),array('field'=>'`password`'));
        
        $password     =     isset($row['password']) ? $row['password'] : '';
        $password     =     substr($password, 0, 8);
        if($password != $arr[2]){
            return false;
        }
        return array('uid' => $uid, 'type' => $arr[0]);
    }
 
    //生成二维码(扫码上传入口)
    public function qrcode_action(){
        if(!$this->uid){
            exit('请先登录登录');
        }
        //传入上传类型 type , save_action中根据类型选择不同的保存路径
        $type     = isset($_GET['type']) ? $_GET['type'] : '';
        if($type == ''){
            exit('扫码上传图片可选类型type:1企业营业执照上传,2个人身份证上传,3个人头像,4企业logo');
        }
        $token     = $this->generateToken($type, $this->uid);
        $token     = urlencode($token);
        $url     = Url('wap',array('c'=> 'upload', 'a' => 'p', 't' => $token) );
 
        include_once LIB_PATH."yunqrcode.class.php";
        YunQrcode::generatePng2($url, 4);
    }
 
    //wap站扫码上传页面
    public function p_action(){
 
        $userinfoM    =    $this->MODEL('userinfo');
 
        $token     = isset($_GET['t']) ? $_GET['t'] : '';
        $arr     = $this->checkToken($token);
        if($arr == false || !isset($arr['type']) || !isset($arr['uid']) ){
            exit('抱歉,功能维护中');
        }
        $this->yunset('token', $token);
        $this->yunset('type', $arr['type']);
        
        if($arr['type'] == 3 || $arr['type'] == 4 || $arr['type'] == 5 || $arr['type'] == 6){//上传头像
            $pic    =    $icon    =    '';
            if ($arr['type']==3){
                
                $photo         =     $userinfoM->getUserInfo(array('uid'=>$arr['uid']),array('usertype'=>1,'field'=>'`photo`,`sex`'));
 
                if(!$photo['photo']){
                    if ($photo['sex']==1){
                        $icon    =    $this->config['sy_member_icon'];
                    }else{
                        $icon    =    $this->config['sy_member_iconv'];
                    }
                }else{
                    $pic        =    $photo['photo'];
                }
            }elseif ($arr['type']==4){
 
                $photo         =     $userinfoM->getUserInfo(array('uid'=>$arr['uid']),array('usertype'=>2,'field'=>'logo`'));
 
                if(!$photo['logo']){
                    $icon    =    $this->config['sy_unit_icon'];
                }else{
                    $pic    =    $photo['logo'];
                }
            }elseif ($arr['type']==5){
 
                $photo         =     $userinfoM->getUserInfo(array('uid'=>$arr['uid']),array('usertype'=>3,'field'=>'photo`'));
                if(!$photo['photo']){
                    $icon    =    $this->config['sy_lt_icon'];
                }else{
                    $pic    =    $photo['photo'];
                }
            }elseif ($arr['type']==6){
 
                $photo         =     $userinfoM->getUserInfo(array('uid'=>$arr['uid']),array('usertype'=>4,'field'=>'logo`'));
 
                if(!$photo['logo']){
                    $icon    =    $this->config['sy_px_icon'];
                }else{
                    $pic    =    $photo['logo'];
                }
            }
            $photo['photo']    =    checkpic($pic,$icon);
            $this->yunset('photo',$photo['photo']);
 
            $this->seo("wap_upload");
            $this->yuntpl(array('wap/uploadimg_userlogo'));
        }else{
            $this->yuntpl(array('wap/uploadimg'));
        }
    }
 
    //保存上传
    public function uploadimg_save_action(){
        $token = isset($_POST['token']) ? $_POST['token'] : '';
        if($token == ''){
            echo json_encode(array('status' => -1, 'msg' => '二维码传图出错,请联系网站管理员'));
            exit;
        }
        $arr = $this->checkToken($token);
        if($arr == false || !isset($arr['type']) || !isset($arr['uid']) ){
            echo json_encode(array('status' => -1, 'msg' => '操作超时,请刷新pc端网页二维码重试' . $token));
            exit;
        }
 
        $path = $this->uploadimg_save_path($arr['type'], $arr['uid']);
        
        echo json_encode($path);exit;
 
        if($path != ''){
            echo json_encode(array('status' => 1, 'path' => $path));
            exit;
        }else{
            echo json_encode(array('status' => -1, 'msg' => '上传失败,请重试'));
            exit;
        }
    }
 
    //根据上传图片的不同环境,保存图片路径到对应的地方,及执行其他逻辑
    private function uploadimg_save_path($type, $uid){
        
        $companyM     =     $this->MODEL('company');
        $resumeM     =     $this->MODEL('resume');
        $UserinfoM    =    $this->MODEL('userinfo');
 
        $uid         =     addslashes($uid);
 
        switch($type){
            case 1://上传企业营业执照        
                // $pic         =     $this->upload();
                // $path         =     $pic;
                
                $cert         =   $companyM -> getCertInfo(array('uid' => $uid, 'type' => '3'));
 
                $postData   =   array(
                    'status'    =>     $this -> config['com_cert_status'] == '1' ? 0 : 1,
                    'ctime'        =>     time()
                );
                if (!empty($_POST['preview'])) {
                    $postData['check']   =  $_POST['preview'];
                }
                if (!empty($_POST['owner_cert'])) {
                    $postData['owner_cert']   =  $_POST['owner_cert'];
                }
                if (!empty($_POST['wt_cert'])) {
                    $postData['wt_cert']   =  $_POST['wt_cert'];
                }
                if (!empty($_POST['other_cert'])) {
                    $postData['other_cert']   =  $_POST['other_cert'];
                }
                
                if (!empty($cert) && is_array($cert) && $cert['ctime']) {
                    
                    $return   =   $companyM -> upCertInfo(array('id'=>intval($cert['id']), 'uid' => $uid), $postData, array('yyzz' => '1', 'usertype' => 2, 'com_name'=>trim($_POST['com_name'])));
                }else{
                    $postData['uid']        =    $uid;
                    $postData['type']        =    '3';
                    $postData['step']        =    '1';
                    $postData['did']        =    $this ->config['did'];
                    $postData['usertype']    =    2;
                    $postData['com_name']    =    trim($_POST['com_name']);
                    
                    $return    =    $companyM -> addCertInfo($postData);
                }
                return $return;
 
                break;
            case 2://个人上传身份证
            
                $pic     = $this->upload();
                $path     = $pic;
 
                $data    =    array(
                    'usertype'        =>    1,
                    'name'            =>    $_POST['name'],
                    'idcard'        =>    $_POST['idcard'],
                    'idcard_pic'    =>    $path,
                );
                $return    =    $UserinfoM -> upidcardInfo(array('uid'=>$uid,'wap'=>'1'),$data);
                if($return['errcode']==9){
                    $_COOKIE['uid']         =     $uid;
                    $_COOKIE['usertype']    =     1;
                }
                return $return;
            break;
            case 3://个人上传头像
                $return   =  $resumeM -> upPhoto(array('uid'=>$uid),array('utype'=>'user','base'=>$_POST['uimage']));
                return $return;
            break;
            case 4://企业上传logo
 
                $return   =  $companyM -> upLogo(array('uid'=>$uid),array('utype'=>'user','base'=>$_POST['uimage']));
                return $return;
            break;
        }
        return '';
    }
 
    private function upload($path=''){
        
        if($_POST['preview']){
            $upArr   =  array(
                'dir'      =>  'cert',
                'base'     =>  $_POST['preview'],
            );
            
            $result  =  $this -> newupload($upArr);
            
            if (!empty($result['msg'])){
                
                $return['msg']      =  $result['msg'];
                
                echo json_encode(array('msg' => $result['msg']));exit;
                
            }elseif (!empty($result['picurl'])){
                
                return   $result['picurl'];
            }
            
        }else{
            echo json_encode(array('status' => -1, 'msg' => '请上传图片'));exit;
        }
    }
    /**
      * @desc 处理单个图片上传
      * @param file/需上传文件; dir/上传目录; type/上传图片类型; base/需上传base64; preview/pc预览即上传
     */
    private function newupload($data = array('file'=>null,'dir'=>null,'type'=>null,'base'=>null,'preview'=>null)){
          
        $UploadM =    $this->MODEL('upload');
          
        $upArr   =  array(
            'file'     =>  $data['file'],
            'dir'      =>  $data['dir'],
            'type'     =>  $data['type'],
            'base'     =>  $data['base'],
            'preview'  =>  $data['preview']
        );
        $return  =  $UploadM -> newUpload($upArr);
        return $return;
    }
    /**
    1.统计已经上传图片地方、上传文件地方, (搜索Upload_pic)
    有哪些操作,验证了什么,保存了什么信息(文件路径),
 
    前台:企业上传logo、上传企业执照照片、,个人上传简历照片,
 
    2.把共用的验证逻辑写到上传类中,
    
    4.写一个手机端拍照/相册上传的页面
 
    5.写一个生产二维码扫码上传的接口
 
    6.pc端需要上传的地方,添加扫码上传的二维码展示
 
    7. to do : 手机端上传成功,让pc端页面触发刷新(参考微信二维码付款,订单页面触发刷新)
    
    */
    function upCertPic_action(){
        $UploadM        =    $this    ->    MODEL('upload');
 
        $picurl            =    '';
        $msg            =    '';
        $error            =    '';
 
        if(isset($_POST['preview'])){
                    // pc端上传
            $upArr        =  array(
                'base'  =>  $_POST['preview'],
                'dir'   =>  'cert'
            );
            $uploadM      =    $this->MODEL('upload');
            $pic          =    $uploadM->newUpload($upArr);
 
            if (!empty($pic['msg'])){
 
                $error    =    2;
                $msg     =     $pic['msg'];
 
            }elseif (!empty($pic['picurl'])){
                $error    =    1;
                $picurl =  $pic['picurl'];
            }
        }else{
            $error    =    2;
            $msg     =     '请选择图片';
        }
 
        $return['error']     = $error;
        $return['msg']         = $msg;
        $return['picurl']     = $picurl;
 
        echo json_encode($return);die;
    }
}
?>