chengkun
2025-05-20 4c1f0f659384d71ce28be1fc0343e56e75568fe1
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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
<?php
 
 
 
class set_controller extends com_controller
{
    
    function getCert_action()
    {
 
        $comM        =   $this -> MODEL('company');
        $comCert    =   $comM -> getCertInfo(array('uid' => $this->member['uid'], 'type' => '3'));
        
        $data['comname']    =   $this->comInfo['name'];
        $data['statusbody'] =   $comCert['statusbody'];
        if($comCert){
 
          $data['status']   =   $comCert['status'];
        }else{
 
           $data['status']  =   -1;
        }
 
        $data['com_social_credit']    =   $this->config['com_social_credit'];
        $data['com_cert_owner']        =   $this->config['com_cert_owner'];
        $data['com_cert_wt']        =   $this->config['com_cert_wt'];
        $data['com_cert_other']        =   $this->config['com_cert_other'];
        // 小程序里面因安全域名限制,在开启oss的情况下,委托书/承诺函范本上传时服务器也传了一份,这里直接用服务器上的
        $data['exa_cert_wt']        =   $this->config['exa_cert_wt'] ? $this->config['sy_weburl'].$this->config['exa_cert_wt']:'';
        $data['pic_type']           =   $this->config['pic_type'];
        $data['file_maxsize']       =   $this->config['file_maxsize'];
        
        if($comCert['check'] || $comCert['owner_cert'] || $comCert['wt_cert'] || $comCert['other_cert']){
            
            $data['social_credit']  =   $comCert['social_credit'];
            $data['url']            =   $comCert['old_check'];
            $data['ocurl']          =   $comCert['old_owner_cert'];
            $data['wturl']          =   $comCert['old_wt_cert'];
            $data['otherurl']       =   $comCert['old_other_cert'];
            $this->render_json(1,'ok',$data);
        }else{
            
            $this->render_json(2,'',$data);
        }
 
    }
 
    //上传企业认证图片处理返回url
    function upCertPic_action(){
 
        $UploadM        =    $this    ->    MODEL('upload');
 
        $picurl            =    '';
        $msg            =    '';
        $error            =    '';
 
        if(isset($_FILES['file'])){
                    // pc端上传
            $upArr        =  array(
                'file'  =>  $_FILES['file'],
                '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     =     '请选择图片';
        }
 
        $this->render_json($error,$msg,$picurl);
    }
 
    //上传企业资质
    function saveCert_action()
    {
        
        $comM        =   $this -> MODEL('company');
 
        if($this->comInfo['r_status']==0){
            
            $status    =    $this->comInfo['r_status'];
        }else{
 
            $status    =    $this -> config['com_cert_status'] == '1' ? 0 : 1;
        }
 
        $upData     =   array(
            'ctime'     =>  time(),
            'status'    =>  $status
        );
        if($_POST['social_credit']){
            $upData['social_credit']    =   $_POST['social_credit'];
        }
        if($_POST['check']){
 
            $upData['check']            =   $_POST['check'];
        }else if($_POST['base']){
 
            $upData['base']             =   $_POST['base'];
        }
        if($_POST['owner_cert']){
 
            $upData['owner_cert']       =   $_POST['owner_cert'];
        }else if($_POST['base_owner_cert']){
 
            $upData['base_owner_cert']  =   $_POST['base_owner_cert'];
        }
        if($_POST['wt_cert']){
 
            $upData['wt_cert']          =   $_POST['wt_cert'];
        }else if($_POST['base_wt_cert']){
 
            $upData['base_wt_cert']     =   $_POST['base_wt_cert'];
        }
        if($_POST['other_cert']){
 
            $upData['other_cert']       =   $_POST['other_cert'];
        }else if($_POST['base_other_cert']){
 
            $upData['base_other_cert']  =   $_POST['base_other_cert'];
        }
 
        $cert       =   $comM -> getCertInfo(array('uid' =>$this->member['uid'], 'type' => '3'));
        
        //判断是否上传必要资质
        $errcode    =   0;
        $msg        =   '必须上传';
        $douhao     =   false;
 
 
        if($this->config['com_cert_owner']==1 && !$_POST['owner_cert'] && !$cert['owner_cert'] && !$_POST['base_owner_cert']){
            if($douhao){
                $msg    .=  ',';
            }
            $douhao     =   true;
            $msg        .=  '经办人身份证';
            $errcode    =   8;
        }
        if($this->config['com_cert_wt']==1 && !$_POST['wt_cert'] && !$_POST['base_wt_cert'] && !$cert['wt_cert']){
            if($douhao){
                $msg    .=  ',';
            }
            $douhao     =   true;
            $msg        .=  '委托函';
            $errcode    =   8;
        }
        
        if($errcode==8){
            $this->render_json(2,$msg);
        }
        //判断是否上传必要资质end
 
        if (!empty($cert) && $cert['ctime']) {
             
            $err        =   $comM -> upCertInfo(array('id'=>$cert['id'], 'uid' => $this->member['uid']), $upData, array('yyzz' => '1', 'usertype' => 2, 'com_name'=>trim($_POST['name'])));
            
        }else{
            $postData   =   array(
                'uid'       =>  $this->member['uid'],
                'type'      =>  '3',
                'step'      =>  '1',
                'did'       =>  $this ->config['did'],
                'usertype'  =>  2,
                'com_name'  =>  trim($_POST['name'])
            );
            $postData    =   array_merge($postData, $upData);
            $err        =   $comM -> addCertInfo($postData);
        }
 
        if($err){
            $error        =    $err['errcode']==9 ? 1 : 2;
            if($error==1){
                $msg    =   '更新成功!';
            }else{
                $msg    =   !empty($err['msg']) ? $err['msg'] : '更新失败!';
            }
        }
        $this->render_json($error,$msg);
    }
 
 
    //手机认证,发送短信;
    function mobliecert_action()
    {
        //判断手机号码是否存在
        $UserinfoM         =   $this->MODEL('userinfo');
        $where['uid']      =   array('<>',$this->member['uid']);
        $where['moblie']   =   $_POST['moblie'];
        $Info              =  $UserinfoM->getInfo($where);
        
        if($Info){
            $this->render_json(10,'手机号码已存在,请重新填写新号码');
        }
        $com     =    array(
            'uid'      => $this->member['uid'],
            'usertype' => '2'
        );
        $moblie        =    trim($_POST['moblie']);
        $noticeM    =    $this->MODEL('notice');
 
        $port        =    $this->plat == 'mini' ? '3' : '4';    // 短信发送端口$port : 3-小程序  4-APP
        $result        =    $noticeM->sendCode($moblie, 'cert', $port, $com);
 
        if ($result['error'] == 1){
            
            $logM  =  $this->MODEL('log');
            $logM->addMemberLog($com['uid'], $com['usertype'], '手机认证验证码,认证手机号:'.$moblie, 13, 2);
            $this->render_json(0,'ok');
        }else{
            $this->render_json($result['error'],$result['msg']);
        }
    }
 
    function bindingbox_action()
    {
        $comM                =       $this -> MODEL('company');
 
        $UserinfoM           =       $this->MODEL('userinfo');
 
        $uid                  =       $this->member['uid'];
        if($_POST['id']=='tel'){
 
            $moblie              =        $_POST['moblie'];
        
              $where['uid']          =       array('<>',$uid);
            
            $where['moblie']       =       $moblie;
        
            $Info                  =          $UserinfoM->getInfo($where);
            if($Info){
                $this    ->    render_json(2,'手机号码已存在,请重新填写新号码','');
            }else{
                $data     =   array(
                    'uid'         =>    $this ->member['uid'],
                    'usertype'    =>    $this ->member['usertype'],
                    'moblie'      =>    $_POST['moblie'],
                );
                $return  =  array();
                $user    =  $UserinfoM->getInfo(array('uid'=>$uid),array('field'=>'username,moblie,password,salt'));
                if (isset($_POST['provider']) && $user['username'] == $user['moblie']){
                    // 用户名和手机号重复,修改手机号会修改用户名,需要重新生成token;
                    $token  =  md5($data['moblie'].$user['password'].$user['salt'].$user['usertype']);
                    $return['user']  =  array('uid'=>$uid,'usertype'=>$user['usertype'],'token'=>$token);
                }
                $result  =   $comM -> upCertInfo(array('uid'=>$this ->member['uid'], 'check2'=>$_POST['code']), array('status'=>'0'), $data);
                
                if($result==1){
                    $this    ->    render_json(0,'手机绑定成功',$return);    
                }if($result==4){
                    
                   $this    ->    render_json(4,'短信验证码已过期,请重新发送!');
                    
                }else  if($result==3){
                    $this    ->    render_json(3,'短信验证码不正确!');
                }else if($result==2){
                    $this    ->    render_json(2,'请先获取短信验证码!');
                }else{
                    $this    ->    render_json(2,'手机绑定失败!');
                }
 
            }
 
        }elseif ($_POST['id']=='email'){
            if(!empty($_POST['source']) && $_POST['source'] == 'wap'){
                session_start();
                $code       =   $_POST['authcode'];
                if (md5(strtolower($code)) != $_SESSION['authcode'] || empty($_SESSION['authcode'])) {
                    $error    =    4;
                    $data['errmsg']    =    '验证码不正确';
                    $this    ->    render_json($error,$data['errmsg']);
                }
            }
 
            $email              =        $_POST['email'];
 
            $where['uid']          =       array('<>',$uid);
              
              $where['email']       =       $email;
          
            $Info                  =          $UserinfoM->getInfo($where);
 
            if($Info){
                $error    =    2;
                $data['errmsg']    =    '邮箱已存在,请重新填写邮箱';
                $this    ->    render_json($error,$data['errmsg']);
            }else{
                $data      =   array(
                    'usertype' =>  $this ->member['usertype'],
                    'email'    =>  $_POST['email']
                );
                
                $return   =   $comM -> sendCertEmail(array('uid'=>$this->member['uid'], 'type'=>'1'), $data);
                if($return=='1'){
                    $error    =    0;
                    $data['errmsg']    =    '邮箱绑定成功';
                    $this    ->    render_json($error,$data['errmsg']);
                }elseif($return  == 3){
                    $data['errmsg']            =        '邮件没有配置,请联系管理员!';
                    $this    ->    render_json($return,$data['errmsg']);
                }elseif($return ==2){
                    $data['errmsg']            =        '邮件通知已关闭,请联系管理员';
                    $this    ->    render_json($return,$data['errmsg']);
                }else{
                    $data['errmsg']    =    '操作错误';
                    $this    ->    render_json($return,$data['errmsg']);
                }
                
            }
 
        }
 
    }
 
    function pwd_action()
    {
        if($_POST['newpwd']){
            $UserinfoM  =   $this->MODEL('userinfo');
            $data       =   array(
                'uid'           =>  $this->member['uid'],
                'usertype'      =>  $this->member['usertype'],
                'oldpassword'   =>  $_POST['oldpwd'],
                'password'      =>  $_POST['newpwd'],
                'repassword'    =>  $_POST['confirmpwd']
            );
            $return    =   $UserinfoM -> savePassword($data);
            
        }
        $data['error']    =    $return['errcode']==9 ? 0 : 2;
        
        $this -> render_json($data['error'], $return['msg']);
 
    }
    
    function setname_action(){
        $UserinfoM    =    $this->MODEL('userinfo');
        $data    =    array(
            'username'    =>  trim($_POST['username']),
            'password'    =>  trim($_POST['password']),
            'uid'        =>  $this->member['uid'],
            'usertype'    =>  2,
            'restname'    =>  '1'
        );
        if (!empty($data['username'])) {
            $return =    $UserinfoM->saveUserName($data);
            if($return['errcode'] == '1'){
                $error    =    1;
            }else{
                $error    =    2;
                $msg    =    $return['msg'];
            }
        }else{
            $error    =    2;
            $msg    =    '修改失败';
        }
        $this -> render_json($error, $msg,$return);
    }
    /**
     * 子账号列表
     */
    function child_action(){
 
        $comaM      =   $this -> MODEL('companyaccount');
 
        $rows       =   array();
 
        $page                =    $_POST['page'];
 
        $where['comid']     =   $this ->member['uid'];
        $total = $comaM->getNum($where);
        $where['orderby']    =    'uid';        
 
        $limit                =    $_POST['limit'] ? $_POST['limit'] : 10;
 
        if($page){//分页
            $pagenav        =    ($page-1)*$limit;
            $where['limit']    =    array($pagenav,$limit);
        }else{
            $where['limit']    =    $limit;
        }
 
        $rows    =    $comaM -> getWorkList($where);        
        
        $list    =    count($rows) ? $rows : array();
        $this    -> render_json(0,'',$list,$total);
    }
    /**
     * 创建子账号之前检测数量
     */
    function childCheck_action()
    {
        $statisM    =   $this -> MODEL('statis');
        $res        =   $statisM -> getItemUseCondition(array(
            'uid'   =>  $this -> member['uid'],
            'item'  =>  'sons_num'
        ));
        
        if($res['ecode'] == 55){
            $msg    =  $res['msg'];
            $error    =  3;
        }else{
            $msg    =  'ok';
            $error  =  0;
        }
        $data['iosfk']        =    $this->config['sy_iospay'] ;
        $this->render_json($error,$msg,$data);
    }
    /**
     * 创建子账号
     */
    function childedit_action(){
 
        $cuid        =    intval($_POST['cuid']);
 
        $sonInfo    =    array();
        $error        =    1;
        //检查是否可以套餐足够
        if(empty($cuid)){
            $statisM    =   $this -> MODEL('statis');
            $res        =   $statisM -> getItemUseCondition(array(
                'uid'   =>  $this -> member['uid'],
                'item'  =>  'sons_num'
            ));
    
            if($res['ecode'] == 55){
                $msg    =    $res['msg'];    
                $error    =    3;
            }
        }else{
            $comaM      =   $this -> MODEL('companyaccount');
            $info        =    $comaM -> getWorkList(array('uid' => $cuid));
            if(empty($info)){
                $msg    =    '子账号不存在';
                $error    =    2;
            }
            $sonInfo    =    $info[0];
        }
 
        $this->render_json($error,$msg,$sonInfo);
        
        
    }
    /**
     * 添加 修改子账号
     */
    function childeditsave_action(){
        
        $_POST      =   $this -> post_trim($_POST);
        
 
        $cuid       =   intval($_POST['cuid']);
 
        $memberM    =   $this -> MODEL('userinfo');
        unset($_POST['cuid']);
        unset($_POST['uid']);
        if(empty($cuid)){
            $res    =   $memberM -> addChildInfo(array(
                'uid'       =>  $this -> member['uid'],
                'cdata'     =>  $_POST,
                'paytype'   =>  'vip'
              ));
 
        }else{
            $res    =   $memberM -> updChildInfo(array('uid' => $cuid), $_POST);
        }
        $error        =    $res['ecode'] == 9 ? 1:2;
        $msg        =    $res['msg'];
 
        $this->render_json($error,$msg);
 
    }
    /**
     * 删除子账号
     */
    public function del_action()
    {
        $_POST  =   $this -> post_trim($_POST);
 
        $comaM  =   $this -> MODEL('companyaccount');
 
        $res    =   $comaM -> delChild(array('pid' => $this->member['uid'], 'uid' => $_POST['suid']));
        $error    =    $res['ecode']==9 ? 1 : 2;
        $msg    =    $res['msg'];
        $this    ->    render_json($error,$msg);
    }
    /**
     * 分配子账号
     */
    public function childassign_action(){
 
        if($_POST['submit']){//保存分配
            unset($_POST['submit']);
            $_POST      =   $this -> post_trim($_POST);
            //参数判断
            $cuid       =   intval($_POST['cuid']);
            if(empty($cuid)){
                $msg    =    '非法操作!';
                $error    =    2;
            }else{
                $statisM        =   $this -> MODEL('statis');
                unset($_POST['cuid']);
                $_POST['uid']   =   $this -> member['uid'];
                $_POST['spid']  =   $cuid;
 
                
                $res        =   $statisM -> assignChildStatis($_POST);
                $error        =    $res['ecode']==9 ? 1 : 2; 
                $msg        =    $res['msg'];
            }
            
            $this->render_json($error,$msg,null);
        }
        
        $cuid        =    intval($_POST['cuid']);
 
        $inids      =   $this -> member['uid'].','.$cuid;
 
        $statisM    =   $this -> MODEL('statis');
        
        $statisList =   $statisM -> getList(array('uid' => array('in', $inids)));
 
        if(empty($statisList)){
            $msg    =    '主账号套餐不存在';
            $error    =    2;
        }else{
            $fatherS    =   $sonS   =   array();
        
            foreach ($statisList as $sv) {
 
                if($sv['uid'] == $this -> member['uid']){
                
                    $fatherS        =   $sv;
                }elseif ($sv['uid'] == $cuid) {
                    
                    $sonS            =   $sv;
                }
            }
 
            $data        =   array(
                'fathers'   =>  $fatherS,
                'sons'      =>  $sonS,
                'chat_name'    =>  isset($this->config['sy_chat_name']) ? $this->config['sy_chat_name'] : '',
                'chat_open' =>  isset($this->config['sy_chat_open']) ? $this->config['sy_chat_open'] : 2
            );
            $error    =    1;
            $msg    =    '';
        }
 
        $this->render_json($error,$msg,$data);
    }
    function upMap_action(){
        $companyM    =    $this->MODEL('company');
        if($_POST){
            $coordinates  =  $this->Convert_GCJ02_To_BD09($_POST['x'], $_POST['y']);
            $data    =    array(
                'xvalue'    =>    $coordinates['lng'],
                'yvalue'    =>    $coordinates['lat']
            );
            $return    =    $companyM->setMap($this->member['uid'],$data);
            if($return['cod']  == '9'){
                $error    =    1;
            }else{
                $error    =    2;
            }
            $this->render_json($error, $return['msg']);
        }
    }
    function getBind_action(){
        
        $userInfoM  =  $this->MODEL('userinfo');
        $member     =  $userInfoM->getInfo(array('uid'=>$this->member['uid']),array('field'=>'`qqid`,`bdopenid`,`qqunionid`,`wxid`,`wxopenid`,`unionid`,`app_wxid`,`sinaid`,`maguid`,`qfyuid`'));
        
        $return  =  array(
            'qqbind'    =>  0,
            'wxbind'    =>  0,
            'sinabind'  =>  0,
            'magbind'   =>  0,
            'qfybind'   =>  0,
            'bdbind'    =>  0,
        );
        if (isset($this->config['sy_qqdt']) && $this->config['sy_qqdt'] == 1 && !empty($member['qqunionid'])){
            $return['qqbind']  =  1;
        }elseif (!empty($member['qqid'])){
            $return['qqbind']  =  1;
        }
        if ($_POST['provider'] == 'app'){
            if (!empty($member['app_wxid']) || !empty($member['unionid'])){
                $return['wxbind']  =  1;
            }else{
                if (!empty($member['wxid'])){
                    $return['wxbind']  =  2;
                }
            }
        }elseif ($_POST['provider'] == 'h5'){
            if (!empty($member['wxid']) || !empty($member['unionid'])){
                $return['wxbind']  =  1;
            }else{
                if (!empty($member['wxopenid']) || !empty($member['app_wxid'])){
                    $return['wxbind']  =  2;
                }
            }
        }else{
            if (!empty($member['wxopenid']) || !empty($member['unionid'])){
                $return['wxbind']  =  1;
            }else{
                if (!empty($member['wxid']) || !empty($member['app_wxid'])){
                    $return['wxbind']  =  2;
                }
            }
        }
        if (!empty($member['sinaid'])){
            $return['sinabind']  =  1;
        }
        if (!empty($member['maguid'])){
            $return['magbind']  =  1;
        }
        if (!empty($member['qfyuid'])){
            $return['qfybind']  =  1;
        }
        if (!empty($member['bdopenid'])){
            $return['bdbind'] = 1;
        }
        $this->render_json(0, 'ok', $return);
    }
    
    function binding_action()
    {
        $userInfoM  =  $this->MODEL('userinfo');
        
        if ($_POST['isbind'] == 1){
            
            $uni = 'wxapp';
            if (isset($_POST['provider'])){
                if ($_POST['provider'] == 'weixin'){
                    $uni = '微信小程序';
                }
                if ($_POST['provider'] == 'app'){
                    $uni = 'APP/微信';
                }
            }
            if ($_POST['type'] == 'weixin'){
                
                $up  =  array('wxid'=>'','wxopenid'=>'','app_wxid'=>'','unionid'=>'');
                
            }elseif ($_POST['type'] == 'qq'){
                
                $up  =  array('qqid'=>'','qqunionid'=>'');
                $uni =  'APP/QQ';
                
            }elseif ($_POST['type'] == 'sinaweibo'){
                
                $up  =  array('sinaid'=>'');
                $uni =  'APP/weibo';
            }elseif ($_POST['type'] == 'baidu'){
                $up = array('bdopenid'=>'');
                $uni = '百度小程序';
            }
            
            $userInfoM->upInfo(array('uid'=>$this->member['uid']), $up);
            
            $logM  =  $this->Model('log');
            $logM->addMemberLog($this->member['uid'],$this->member['usertype'], $uni.'解除绑定');
            
            $this->render_json(0, 'ok');
            
        }else{
            
            $bdData['uid']     =  $this->member['uid'];
            $bdData['type']    =  $_POST['type'];
            $bdData['openid']  =  $_POST['openid'];
            $bdData['provider']=  $_POST['provider'];
            if (!empty($_POST['unionid'])){
                
                $bdData['unionid']    = $_POST['unionid'];
            }
            
            if ($_POST['type'] == 'weixin' && !empty($_POST['code'])){
                
                $getdata  =  $this->getOpenid($_POST['code']);
                if (isset($getdata['errcode'])){
                    $this->MODEL('errlog')->addErrorLog($this->member['uid'], 10, '微信小程序绑定获取openid错误。code:'.$_POST['code'].'。'.$getdata['errcode'].','.$getdata['errmsg']);
                    $this->render_json($getdata['errcode'],$getdata['errmsg']);
                }
                $bdData['openid']  =  $getdata['openid'];
                if (!empty($getdata['unionid'])){
                    
                    $bdData['unionid']    =    $getdata['unionid'];
                }
            }elseif ($_POST['type']=='baidu' && !empty($_POST['code'])){
                $getdata  =  $this->getBdOpenid($_POST['code']);
                if (isset($getdata['errno'])){
                    $this->MODEL('errlog')->addErrorLog('', 10, '百度小程序登录获取openid错误。code:'.$_POST['code'].'。'.$getdata['error'].','.$getdata['error']);
                    $this->render_json($getdata['errno'],$getdata['error']);
                }
                $bdData['openid']  =  $getdata['openid'];
            }
            $return  =  $userInfoM->loginBind($bdData);
            $this->render_json($return['error'],$return['msg']);
        }
    }
    // 查询申请记录
    function getLogout_action()
    {
        $logoutM  =  $this->MODEL('logout');
        $row      =  $logoutM->getInfo(array('uid'=>$this->member['uid']));
        
        if (!empty($row)){
            
            $this->render_json(1,'您已申请了注销账号');
        }else{
            
            $this->render_json(0,'ok');
        }
    }
    //注销账号申请
    public function logoutApply_action()
    {
        $_POST  =   $this->post_trim($_POST);
        $p      =   array(
            'password' => $_POST['password']
        );
 
        $logoutM=   $this->MODEL('logout');
        $return =   $logoutM->apply(array('uid' => $this->member['uid']), $p);
 
        if ($return['errcode'] == 9) {
 
            $this->render_json(0, 'ok');
        } else {
 
            $this->render_json($return['errcode'], $return['msg']);
        }
    }
    /**
     * 邀请模板列表
     */
    function yqmb_action(){
        
        
        $yqmbM              =   $this -> MODEL('yqmb');
 
        $page                =    $_POST['page'];
 
        $where['uid']         =   $this ->member['uid'];
                
        $where['orderby']    =    'id,desc';        
 
        $limit                =    $_POST['limit'] ? $_POST['limit'] : 10;
 
        if($page){//分页
            $pagenav        =    ($page-1)*$limit;
            $where['limit']    =    array($pagenav,$limit);
        }else{
            $where['limit']    =    $limit;
        }
 
        $rows    =    $yqmbM -> getList($where);
 
        $mbnum    =    $yqmbM -> getNum(array('uid' => $this->member['uid']));
        
        $list    =    count($rows) ? $rows : array();
 
        $data['list']     = $list;
 
        $data['mbnum']     = $mbnum ? $mbnum : 0;
 
        $data['maxnum'] = $this->config['com_yqmb_num'] ? $this->config['com_yqmb_num'] : 0;
 
        $this->render_json(0,'',$data);
    }
    
    /**
     * 删除模板
     */
    public function delYqmb_action()
    {
        $_POST  =   $this -> post_trim($_POST);
 
        $yqmbM  =   $this -> MODEL('yqmb');
 
        $res    =   $yqmbM->delYqmb($_POST['id'],array('uid'=>$this->member['uid']));
        $error    =    $res['errcode']==9 ? 1 : 2;
        $msg    =    $res['msg'];
        $this    ->    render_json($error,$msg);
    }
    
    function yqmbedit_action(){
 
        $yid        =    intval($_POST['yid']);
        $yqmbM      =   $this -> MODEL('yqmb');
        $error        =    1;
        
        if(empty($yid)){
            $mbnum    =    $yqmbM->getNum(array('uid'=>$this->member['uid']));
            
            $info   =  array(
                'name'     =>  '',
                'linkman'  =>  '',
                'linktel'  =>  '',
                'address'  =>  '',
                'content'  =>  ''
            );
            if($mbnum>=$this->config['com_yqmb_num']){
                $msg    =    '最多可以创建'.$this->config['com_yqmb_num'].'个模板';    
                $error    =    3;
            }
        }else{
            $info        =    $yqmbM -> getInfo(array('id' => $yid));
            if(empty($info)){
                $msg    =    '模板不存在';
                $error    =    2;
            }
        }
 
        $this->render_json($error,$msg,$info);
        
        
    }
    function yqmbeditsave_action(){
        $_POST      =   $this -> post_trim($_POST);
        
        $yqmbM         =     $this->MODEL('yqmb');
        $yid           =   intval($_POST['yid']);
 
        $where      =   array();
        if($yid){
            
            $where['id']=   $yid;
            
        }
        
        $data = array(
            'uid'       =>  $this->member['uid']
        );
        $setdata = array(
            'name'      => $_POST['name'],
            'linkman'   => $_POST['linkman'],
            'linktel'   => $_POST['linktel'],
            'content'   => $_POST['content'],
            'intertime' => $_POST['intertime'],
            'address'   => $_POST['address'],
        );
        $return         =   $yqmbM->addInfo($setdata,$data,$where);
 
        $error        =    $return['errcode'] == 9 ? 1:2;
        $msg        =    $return['msg'];
 
        $this->render_json($error,$msg);
    }
    // 开启、关闭app推送
    function pushSet_action(){
        
        $UserinfoM = $this->MODEL('userinfo');
        $UserinfoM->upInfo(array('uid'=>$this->member['uid']), array('app_push'=>$_POST['app_push']));
        $this->render_json(0,'ok');
    }
 
    /**
     * 使用充值卡
     */
    function useCard_action()
    {
 
        $_POST  = $this->post_trim($_POST);
        $vData  =   array(
            'card'  =>  $_POST['card'],
            'password'  =>  $_POST['password']
        );
 
        $data['userdid'] = $this->userdid;
 
        $couponM=   $this->MODEL('coupon');
        $return =   $couponM->usePreCard($vData, array('uid' => $this->member['uid'], 'username' => $this->member['username'], 'usertype' => 2));
 
        $error  =    $return['errcode'] == 9 ? 1 : 2;
        $msg    =   $return['msg'];
 
        $this->render_json($error,$msg);
 
 
    }
}
?>