chengkun
2025-05-12 c49b17b9588306c14ad4b30e6a2c4b8644f3233b
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
<?php
 
class admin_chat_log_controller extends adminCommon{  
    function index_action(){
        $chatM = $this->MODEL('chat');
        $where = array();
        $noUsername = true;
        if($_GET['keyword']){
            
            $keyword    =    trim($_GET['keyword']);
            
            $type        =    intval($_GET['type']);
            
            if ($type==1 || $type==2){
                
                $userInfoM  =  $this->MODEL('userinfo');
                $member  =  $userInfoM->getList(array('username'=>array('like',$keyword)),array('field'=>'`uid`'));
                if (!empty($member)){
                    
                    $muids  =  array();
                    foreach ($member as $v){
                        
                        $muids[] = $v['uid'];
                    }
                    if ($type == 1){
                        
                        $where['from']  =  array('in',pylode(',', $muids));
                        
                    }elseif ($type == 2){
                        
                        $where['to']  =  array('in',pylode(',', $muids));
                    }
                }else{
                    $noUsername = false;
                }
            }elseif($type=='3'){
                
                $where['content']    =    array('like',$keyword);
            }
            $urlarr['type']            =    "".$type."";
            
            $urlarr['keyword']        =    "".$keyword."";
        }
        if(($_GET['date'])){
            
            $times=@explode('~',$_GET['date']);
            
            $where['PHPYUNBTWSTART']=   '';
            $where['sendTime'][]    =    array('>=',strtotime($times[0]." 00:00:00")*1000);
            $where['sendTime'][]    =    array('<',strtotime($times[1]." 23:59:59")*1000);
            $where['PHPYUNBTWEND']  =   '';
            
            $urlarr['date']        =    $_GET['date'];
        }
        // 用户名没搜到的,不查询
        if ($noUsername){
            $urlarr            =   $_GET;
            $urlarr['page']    =    "{{page}}";
            
            $pageurl        =    Url($_GET['m'],$urlarr,'admin');
            
            $pageM            =    $this  -> MODEL('page');
            
            $pages            =    $pageM -> pageList('chat_log',$where,$pageurl,$_GET['page']);
            
            //分页数大于0的情况下 执行列表查询
            if($pages['total'] > 0){
                
                if($_GET['order'])
                {
                    $where['orderby']    =    $_GET['t'].','.$_GET['order'];
                    
                    $urlarr['order']    =    $_GET['order'];
                    
                    $urlarr['t']        =    $_GET['t'];
                }else{
                    
                    $where['orderby']    =    'id';
                }
                
                $where['limit']    =    $pages['limit'];
                
                $chatList        =    $chatM -> getChatLogList($where,array('admin'=>1));
                
                if ($chatList && is_array($chatList)){
                    
                    foreach ($chatList as $k=>$v){
                        
                        $chatList[$k]['sendTime'] = ceil($v['sendTime']/1000);
                        
                    }
                }
            }
            
            $this->yunset('rows',$chatList);
        }
        
        $this->yuntpl(array('admin/admin_chat_log'));
    }
    function del_action(){
        
        $chatM    =    $this -> Model('chat');
        
        if(is_array($_POST['del'])){
            
            $delid        =    @implode(',',$_POST['del']);
            
            $layer_type    =    1;
        }else{
            $this -> check_token();
            
            $delid        =    (int)$_GET['id'];
            
            $layer_type    =    0;
        }
        
        $where['id']    =    array('in',$delid);
        
        $del    =    $chatM -> delChatLog(array('where'=>$where));
        
        $del?$this -> layer_msg('聊天记录(ID:'.$delid.')删除成功!',9,$layer_type,$_SERVER['HTTP_REFERER']):$this -> layer_msg('删除失败!',8,$layer_type,$_SERVER['HTTP_REFERER']);
        
    }
    function clean_action(){
        $month    =    intval($_POST['month']);
        
        $chatM    =    $this -> MODEL('chat');
        
        $where['sendTime']    =    array('<',strtotime("-".$month." month")*1000);
        
        $del    =    $chatM -> delChatLog(array('where'=>$where));
        
        $del?$this -> layer_msg('聊天记录清理成功!',9):$this -> layer_msg('清理失败!',8);
    }
    /**
     * 按聊天记录id,查询双方聊天记录
     */
    function userchat_action(){
        
        $chatM    =    $this -> MODEL('chat');
        $log = $chatM->getChatLog(array('id'=>(intval($_POST['id']))));
        
        $arr    =  array(
            'toid'       =>  $log['to'],
            'tusertype'  =>  $log['tusertype'],
            'fromid'     =>  $log['from'],
            'fusertype'  =>  $log['fusertype'],
            'page'       =>  $_POST['page'],
            'lastid'     =>  ''
        );
        $return  =  $chatM -> getChatPage($arr);
 
        $pArr   =  array(
            'uid'       =>  intval($log['from']),
            'usertype'  =>  intval($log['fusertype']),
            'toid'      =>  intval($log['to']),
            'totype'    =>  intval($log['tusertype'])
        );
 
        $list   =  $chatM -> getPrepare($pArr);
 
        $return['joblist'] =  !empty($list['joblist'])?$list['joblist']:array(); 
        $return['expect'] =  !empty($list['expect'])?$list['expect']:array(); 
 
 
        $canwx  =   $chatM->getFriendCan(array('type'=>'wx','uid'=>$this->uid,'usertype'=>$this->usertype,'fid'=>$uid,'fusertype'=>$_GET['type']));
        $cantel =   $chatM->getFriendCan(array('type'=>'tel','uid'=>$this->uid,'usertype'=>$this->usertype,'fid'=>$uid,'fusertype'=>$_GET['type']));
 
        $return['cantel'] =  $cantel; 
        $return['canwx'] =  $canwx;   
        
        echo  json_encode($return);die;
    }
}
 
?>