chengkun
2025-05-22 1a8aea45ebb1582c9f65d9e8dcd520002f83ae12
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
<?php
 
 
class crm_deal_controller extends adminCommon
{
 
    function index_action()
    {
                
        $adminM =   $this->MODEL('admin');
        
        $orderM =   $this->MODEL('companyorder');
        
        $power  =  $adminM -> getPower(array('uid'=>$_SESSION['auid']));
        
        $this ->  yunset('power', $power['power']);
        
        $where  =   $urlarr =   array();
 
        $where['order_state']   =   2;
        
        $auid   =   intval($_SESSION['auid']);
        
        $auser  =   $adminM -> getAdminUser(array('uid' => $auid));
   
        if ($_GET['depart'] == '1') {
            
            if($auser['org'] > 0){
                
                $crmM    =    $this->MODEL('crm');
                $orgInfo    =    $crmM -> getOrgInfo(array('id' => $auser['org']));
            
                $oIds    =    $orgIds    =    $orgIdss    =    $orgIdsss    =    array();
                 
                if ($auser['power'] == '1'){    // 同级部门权限
                    $oList                =    $crmM -> getOrgList(array('level' => $orgInfo['level']));
                    
                    foreach ($oList as $k => $v) {
                        $orgIds[]        =    $v['id'];
                    }    
                }
                
                if ($auser['power'] == '1'){    // 子部门权限
                    if ($orgInfo['level'] == '1'){
                         
                        $orgList            =    $crmM -> getOrgList(array('fid' => $auser['org']));
                        
                        foreach ($orgList as $ok => $ov) {
                            $orgIdss[]        =    $ov['id'];    
                        }
                        
                        $orgLists            =    $crmM -> getOrgList(array('fid' => array('in', pylode(',', $orgIdss))));
                        
                        foreach ($orgLists as $ook => $oov) {
                            $orgIdsss[]        =    $oov['id'];
                        }
                        
                    }elseif ($orgInfo['level'] == '2'){
                         
                        $orgList            =    $crmM -> getOrgList(array('fid' => $auser['org']));
                        foreach ($orgList as $ok => $ov) {
                            $orgIdss[]        =    $ov['id'];    
                        }
                        
                    } 
                }
                $oIds    =    array_merge($orgIds, $orgIdss, $orgIdsss);
                
                $ausers    =    $adminM -> getList(array('uid'=>array('<>',$_SESSION['auid']),'org'=>array('in', pylode(',', $oIds))),array('field'=>'`uid`,`name`,`username`'));
                
                foreach ($ausers as $av) {
                    $auids[]    =    $av['uid'];
                }
            }
            
            if ($_GET['auid']) {
            
                $where['crm_uid']   =   $_GET['auid'];
                $urlarr['auid']     =   $_GET['auid'];
            }else{
                
                $where['PHPYUNBTWSTART_A']  =   '';
                $where['crm_uid'][]            =    array('<>',0,'AND');
                $where['crm_uid'][]            =    array('in',pylode(',',$auids),'AND');
                $where['PHPYUNBTWEND_A']    =   '';
            }
            
            $this->yunset(array('depart' => 1, 'ausers' => $ausers));
        }else{
            
            $where['crm_uid']   =   $auid;
        }
        
        if ($_GET['orDay']) {
            
            $orDay  =   intval($_GET['orDay']);
            
            if ($orDay == 1) {
                
                $where['order_time']        =   array('>', strtotime(date('Y-m-d')));
            }else if($orDay == 2){
                
                $where['PHPYUNBTWSTART_A']  =   '';
                $where['order_time'][]      =   array('>=', strtotime(date('Y-m-d')) - 86400, 'AND');
                $where['order_time'][]      =   array('<=', strtotime(date('Y-m-d')), 'AND');
                $where['PHPYUNBTWEND_A']    =   '';
            }
            
            $urlarr['orDay']    =   $orDay;
        }
        
        if ($_GET['rating']) {
            
            $rating =   intval($_GET['rating']);
            
            $where['rating']    =   $rating;
            $urlarr['rating']   =   $rating;
        }
        
        if ($_GET['keyword']) {
            
            $TypeStr    =   intval($_GET['or_type']);
            $KeywordStr =   trim($_GET['keyword']);
            
            if ($TypeStr == 1) {
                
                $cWhere['name']     =   array('like', $KeywordStr);
            }elseif ($TypeStr == 2){
                
                $cWhere['linkman']  =   array('like', $KeywordStr);
            }
            
            $comM       =   $this -> MODEL('company');
            
            $comList    =   $comM -> getList($cWhere, array('field' => '`uid`'));
 
            foreach ($comList['list'] as $cv) {
                $uids[] =   $cv['uid'];
            }
            
            $where['uid']   =   array('in', pylode(',', $uids));
            
            
            $urlarr['keyword']  =   $KeywordStr;
            $urlarr['or_type']  =   $TypeStr;
        }
        
        $urlarr                =   $_GET;
        $urlarr['page']     =   '{{page}}';
        $pageurl            =   Url($_GET['m'], $urlarr, 'admin');
        
         
        $pageM              =   $this -> MODEL('page');
        $pages              =   $pageM -> pageList('company_order', $where, $pageurl, $_GET['page']);
        
        if ($pages['total'] > 0) {
            
            
            if ($_GET['order'] && $_GET['t']) {
 
                $where['orderby']   =   $_GET['t'].','.$_GET['order'];
                $urlarr['order']    =   $_GET['order'];
                $urlarr['t']        =   $_GET['t'];
            } else {
 
                $where['orderby']   =   'id, DESC';
            }
 
            $where['limit']         =   $pages['limit'];
            
            $orders                 =   $orderM -> getList($where, array('utype' => 'crmdeal'));
         
        }
        
        $ratingM    =    $this -> MODEL('rating');
        $ratinglist    =    $ratingM -> getList(array('category' => '1', 'service_price' => array('>', '0')), array('field'=>'`id`,`name`'));
        
        $this->yunset(array('orders' => $orders, 'auser' => $auser, 'ausers' => $ausers, 'ratinglist' => $ratinglist));
        $this->yuntpl(array('admin/crm_deal_list'));
    }
     
}
?>