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
<?php
 
 
 
class crm_org_kh_controller extends adminCommon
{
 
    function set_search()
    {
 
        $cacheM     =   $this->MODEL('cache');
        $crmCache   =   $cacheM->GetCache(array('crm'));
        $this->yunset(array('cache' => $crmCache, 'crmClassName' => $crmCache['crmclass_name'], 'crmStatus' => $crmCache['crmdata']['client_status'], 'crmType' => $crmCache['crmdata']['client_type']));
 
        $yyzz       =   array('1' => '已认证', '2' => '待审核', '3' => '未通过', '4' => '待认证');
 
        $ratingM    =   $this->MODEL('rating');
        $ratingArr  =   $ratingM->getList(array('category' => '1', 'orderby' => 'sort'), array('field' => '`id`,`name`'));
        $vipEtime   =   array('1' => '三天内', '2' => '七天内', '3' => '一月内', '4' => '已到期');
        $orders     =   array('1' => '客户ID', '2' => '登录日期', '3' => 'VIP到期时间', '4' => '跟进时间');
        $lastFtime  =   array('1' => '从未跟进', '2' => '今天', '3' => '三天未跟进', '4' => '七天未跟进', '5' => '一月未跟进', '6' => '一百天未跟进');
        $nextFtime  =   array('1' => '今天', '2' => '明天', '3' => '三天内', '4' => '七天内', '5' => '一月内');
        $this->yunset(array('yyzzStatus' => $yyzz, 'ratingArr' => $ratingArr, 'vipEtime' => $vipEtime, 'orders' => $orders, 'lastFtime' => $lastFtime, 'nextFtime' => $nextFtime));
 
        $this->yunset('todayStart', strtotime('today'));
    }
 
    function index_action()
    {
 
        $this->set_search();
 
        $AdminM         =   $this->MODEL('admin');
        $adminUserInfo  =   $AdminM->getAdminUser(array('uid' => $_SESSION['auid']), array('field' => 'org,power,spower'));
 
        $Company        =   $this->MODEL('company');
        $userInfoM      =   $this->MODEL('userinfo');
        $crmM           =   $this->MODEL('crm');
 
        if (isset($adminUserInfo) && $adminUserInfo['org'] > 0) {
 
            $orgInfo    =   $crmM->getOrgInfo(array('id' => $adminUserInfo['org']));
 
            $oIds = $orgIds = $orgIdss = $orgIdsss = array();
 
            if ($adminUserInfo['power'] == '1') {    // 同级部门权限
 
                $oList  =   $crmM->getOrgList(array('level' => $orgInfo['level']));
                foreach ($oList as $k => $v) {
                    $orgIds[]   =   $v['id'];
                }
            }
 
            if ($adminUserInfo['power'] == '1') {    // 子部门权限
                if ($orgInfo['level'] == '1') {
 
                    $orgList    =   $crmM->getOrgList(array('fid' => $adminUserInfo['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' => $adminUserInfo['org']));
                    foreach ($orgList as $ok => $ov) {
 
                        $orgIdss[]  =   $ov['id'];
                    }
                }
            }
 
            $oIds   =   array_merge($orgIds, $orgIdss, $orgIdsss);
 
            $adminUserList  =   $AdminM->getList(array('uid' => array('<>', $_SESSION['auid']), 'org' => array('in', pylode(',', $oIds))), array('field' => '`uid`,`name`,`username`'));
            foreach ($adminUserList as $v) {
                $uids[]     =   $v['uid'];
            }
            $this->yunset('adminUserList', $adminUserList);
        }
 
        if (isset($_GET['kh'])){
 
            if ($_GET['kh'] == 1){
 
                $where['isfollow']          =   1;
 
            } elseif ($_GET['kh'] == 2){
 
                $where['isfollow']          =   1;
                $where['f_time']            =   array('>=', strtotime(date('Y-m-d')));
            } elseif ($_GET['kh'] == 3){
 
                $where['PHPYUNBTWSTART_A']  =   '';
                $where['f_time'][]          =   array('>', 0);
                $where['f_time'][]          =   array('<', strtotime('-30 days'));
                $where['PHPYUNBTWEND_A']    =   '';
            } elseif ($_GET['kh'] == 4){
 
                $where['PHPYUNBTWSTART_A']  =   '';
                $where['isfollow']          =   array('=', '0', 'OR');
                $where['f_time']            =   array('=', '', 'OR');
                $where['PHPYUNBTWEND_A']    =   '';
            } elseif ($_GET['kh'] == 5){
 
                $where['PHPYUNBTWSTART_A']  =   '';
                $where['vipetime'][]        =   array('>', time(), 'AND');
                $where['vipetime'][]        =   array('<', strtotime('+15 days'), 'AND');
                $where['PHPYUNBTWEND_A']    =   '';
            } elseif ($_GET['kh'] == 6){
 
                $where['login_date']        =   array('>=', strtotime(date('Y-m-d')));
                $_GET['loginStart']         =   date('Y-m-d');
            }
 
            $urlarr['kh']                   =   $_GET['kh'];
        }
 
        if (!empty($_GET['crmType'])) {
 
            $crmType                =   intval($_GET['crmType']);
            $where['crm_type']      =   $crmType;
            $urlarr['crmType']      =   $crmType;
        }
 
        if (!empty($_GET['crm_status'])) {
 
            $crm_status             =   intval($_GET['crm_status']);
            $where['crm_status']    =   $crm_status;
            $urlarr['crm_status']   =   $crm_status;
        }
 
        if (!empty($_GET['yyzz_status'])) {
 
            $yyzz_status    =   intval($_GET['yyzz_status']);
 
            if ($yyzz_status == 1) {
 
                $where['yyzz_status']   =   $yyzz_status;
            } else {
 
                $certWhere      =   array();
 
                if ($yyzz_status == 2) {
 
                    $certWhere  =   array('type' => 3, 'status' => 0);
                } elseif ($yyzz_status == 3) {
 
                    $certWhere  =   array('type' => 3, 'status' => 3);
                }elseif ($yyzz_status == 4) {
 
                    $certWhere  =   array('type' => 3);
                }
 
                $certList       =   $Company->getCertList($certWhere, array('field' => '`uid`'));
                $uidArrA        =   array();
                foreach ($certList as $cv) {
 
                    $uidArrA[]  =   $cv['uid'];
                }
 
                if ($yyzz_status == 4){
 
                    $where['uid']   =   array('notin', pylode(',', $uidArrA));
                }else{
 
                    $where['uid']   =   array('in', pylode(',', $uidArrA));
                }
            }
 
            $urlarr['yyzz_status']  =   $yyzz_status;
        }
 
        if (!empty($_GET['rating'])) {
 
            $rating             =   intval($_GET['rating']);
            $where['rating']    =   $rating;
            $urlarr['rating']   =   $rating;
        }
 
        if (!empty($_GET['regStart']) || !empty($_GET['regEnd'])) {
 
            $regStart   =   strtotime($_GET['regStart']);
            $regEnd     =   strtotime($_GET['regEnd']);
 
            $mWhere['PHPYUNBTWSTART_A'] =   '';
            $mWhere['reg_date'][]       =   array('>', $regStart, 'AND');
            $mWhere['reg_date'][]       =   array('<', $regEnd, 'AND');
            $mWhere['PHPYUNBTWEND_A']   =   '';
            $memberList =   $userInfoM->getList($mWhere, array('field' => 'uid'));
 
            $uidArrB = array();
            foreach ($memberList as $mv) {
                $uidArrB[]  =   $mv['uid'];
            }
            $where['uid']   =   array('in', pylode(',', $uidArrB));
 
            $urlarr['regStart'] =   $_GET['regStart'];
            $urlarr['regEnd']   =   $_GET['regEnd'];
        }
 
        if (!empty($_GET['ordertype'])) {
 
            $orderType  =   intval($_GET['ordertype']);
            $order      =   '';
 
            if ($orderType == 1) {
 
                $order  =   'uid';
            } else if ($orderType == 2) {
 
                $order  =   'login_date';
            } else if ($orderType == 3) {
 
                $order  =   'vipetime';
            } else if ($orderType == 4) {
 
                $order  =   'f_time';
            } else if ($orderType == 5) {
 
                $order  =   'crm_time';
            }
 
            $urlarr['ordertype']    =   $orderType;
            $where['orderby']       =   $order.',desc';
        }else{
 
            $where['orderby']       =   'login_date,desc';
        }
 
        if (!empty($_GET['lastFtime'])) {
 
            $lastFtime  =   intval($_GET['lastFtime']);
            if ($lastFtime == 1) {
                $where['PHPYUNBTWSTART_A']  =   '';
                $where['isfollow']  =   array('=', '0', 'OR');
                $where['f_time']    =   array('=', '', 'OR');
                $where['PHPYUNBTWEND_A']  =   '';
            } elseif ($lastFtime == 2) {
 
                $where['f_time'] = array('>', strtotime(date('Y-m-d')));
            } elseif ($lastFtime == 3){
                $where['PHPYUNBTWSTART_A']  =   '';
                $where['f_time'][]    =   array('>', 0);
                $where['f_time'][]    =   array('<', strtotime('-3 days'));
                $where['PHPYUNBTWEND_A']  =   '';
            }elseif ($lastFtime == 4){
                $where['PHPYUNBTWSTART_A']  =   '';
                $where['f_time'][]    =   array('>', 0);
                $where['f_time'][]    =   array('<', strtotime('-7 days'));
                $where['PHPYUNBTWEND_A']  =   '';
            }elseif ($lastFtime == 5){
                $where['PHPYUNBTWSTART_A']  =   '';
                $where['f_time'][]    =   array('>', 0);
                $where['f_time'][]    =   array('<', strtotime('-30 days'));
                $where['PHPYUNBTWEND_A']  =   '';
            }elseif ($lastFtime == 6){
                $where['PHPYUNBTWSTART_A']  =   '';
                $where['f_time'][]    =   array('>', 0);
                $where['f_time'][]    =   array('<', strtotime('-100 days'));
                $where['PHPYUNBTWEND_A']  =   '';
            }else{
                $where['PHPYUNBTWSTART_A']  =   '';
                $where['f_time'][]    =   array('isnull', '', '');
                $where['f_time'][]    =   array('<', strtotime('-'.$_GET['lastFtime'].' days'), 'OR');
                $where['PHPYUNBTWEND_A']  =   '';
            }
 
            $urlarr['lastFtime']    =   $lastFtime;
        }
 
        if (!empty($_GET['nextFtime'])) {
 
            $nextFtime  =   intval($_GET['nextFtime']);
            $taskWhere  =   array();
            if ($nextFtime == 1) {
 
                $taskWhere['PHPYUNBTWSTART_A']  =   '';
                $taskWhere['stime'][]           =   array('>', strtotime(date('Y-m-d')));
                $taskWhere['stime'][]           =   array('<', strtotime(date('Y-m-d 23:59:59')));
                $taskWhere['PHPYUNBTWEND_A']    =   '';
            } elseif ($nextFtime == 2) {
 
                $taskWhere['PHPYUNBTWSTART_A']  =   '';
                $taskWhere['stime'][]           =   array('>', strtotime(date('Y-m-d 23:59:59')));
                $taskWhere['stime'][]           =   array('<', strtotime(date('Y-m-d 23:59:59')) + 86400);
                $taskWhere['PHPYUNBTWEND_A']    =   '';
            } elseif ($nextFtime == 3) {
 
                $taskWhere['PHPYUNBTWSTART_A']  =   '';
                $taskWhere['stime'][]           =   array('>', time());
                $taskWhere['stime'][]           =   array('<', strtotime('+3 day'));
                $taskWhere['PHPYUNBTWEND_A']    =   '';
            } elseif ($nextFtime == 4) {
 
                $taskWhere['PHPYUNBTWSTART_A']  =   '';
                $taskWhere['stime'][]           =   array('>', time());
                $taskWhere['stime'][]           =   array('<', strtotime('+1 week'));
                $taskWhere['PHPYUNBTWEND_A']    =   '';
            } elseif ($nextFtime == 5) {
 
                $taskWhere['PHPYUNBTWSTART_A']  =   '';
                $taskWhere['stime'][]           =   array('>', time());
                $taskWhere['stime'][]           =   array('<', strtotime('+1 month'));
                $taskWhere['PHPYUNBTWEND_A']    =   '';
            }
 
            $taskWhere['uid']   =   $_SESSION['auid'];
            $taskList           =   $crmM->getTaskList($taskWhere, array('field' => '`comid`'));
            $uidArrN            =   array();
            foreach ($taskList as $tv) {
                $uidArrN[]      =   $tv['comid'];
            }
            $where['uid']       =   array('in', pylode(',', $uidArrN));
        }
 
        if (!empty($_GET['vipetime'])) {
 
            $etime  =   intval($_GET['vipetime']);
 
            if ($etime == 4) {
 
                $where['PHPYUNBTWSTART_A']  =   '';
                $where['vipetime'][]        =   array('<', strtotime(date('Y-m-d')), 'AND');
                $where['vipetime'][]        =   array('>', '0', 'AND');
                $where['PHPYUNBTWEND_A']    =   '';
            } else {
 
                if ($etime == 1) {
 
                    $num    =   '+3 day';
                } else if ($etime == 2) {
 
                    $num    =   '+7 day';
                } elseif ($etime == 3) {
 
                    $num    =   '+1 month';
                }
                $where['PHPYUNBTWSTART_A']  =   '';
                $where['vipetime'][]        =   array('>', time(), 'AND');
                $where['vipetime'][]        =   array('<', strtotime($num), 'AND');
                $where['PHPYUNBTWEND_A']    =   '';
            }
            $urlarr['vipetime'] =   $etime;
        }
 
        if (!empty($_GET['loginStart']) || !empty($_GET['loginEnd'])) {
 
            $loginStart =   strtotime($_GET['loginStart']);
            $loginEnd   =   strtotime($_GET['loginEnd']) + 86400;
 
            $where['PHPYUNBTWSTART_A']  =   '';
            $where['login_date'][]      =   array('>', $loginStart, 'AND');
            $where['login_date'][]      =   array('<', $loginEnd, 'AND');
            $where['PHPYUNBTWEND_A']    =   '';
 
            $urlarr['regStart'] =   $_GET['regStart'];
            $urlarr['regEnd']   =   $_GET['regEnd'];
        }
 
        if (isset($_GET['crm_uid']) && $_GET['crm_uid'] > 0){
 
            $where['crm_uid']           =   $_GET['crm_uid'];
            $urlarr['crm_uid']          =   $_GET['crm_uid'];
        }else{
 
            $where['PHPYUNBTWSTART_A']  =   '';
            $where['crm_uid'][]         =   array('<>', 0, 'AND');
            $where['crm_uid'][]         =   array('in', pylode(',', $uids), 'AND');
            $where['PHPYUNBTWEND_A']    =   '';
        }
 
        if ($_GET['keyword']) {
 
            $keywordStr =   trim($_GET['keyword']);
            $typeStr    =   intval($_GET['crm_type']);
 
            if (!empty($keywordStr)) {
                if ($typeStr == 1) {
 
                    $where['name']      =   array('like', $keywordStr);
                } else if ($typeStr == 2) {
 
                    $where['linkman']   =   array('like', $keywordStr);
                } else if ($typeStr == 3) {
 
                    $where['linktel']   =   $keywordStr;
                } else if ($typeStr == 4) {
 
                    $where['uid']       =   $keywordStr;
                }
            }
            $urlarr['crm_type'] =   $typeStr;
            $urlarr['keyword']  =   $keywordStr;
        }
        $urlarr            =   $_GET;
        $urlarr['page'] =   '{{page}}';
        $pageurl        =   Url($_GET['m'], $urlarr, 'admin');
        $pageM          =   $this->MODEL('page');
        $pages          =   $pageM->pageList('company', $where, $pageurl, $_GET['page']);
        if ($pages['total'] > 0) {
            if ($_GET['order']) {
                if ($_GET['t']) {
 
                    $where['orderby']   =   $_GET['t'] . ',' . $_GET['order'];
                    $urlarr['t']        =   $_GET['t'];
                } else {
 
                    $where['orderby']   =   'login_date, desc';
                }
                $urlarr['order']        =   $_GET['order'];
            } else if (isset($order)) {
 
                $where['orderby']       =   $order . ',' . $_GET['order'];
            }
            $where['limit'] =   $pages['limit'];
            $comList        =   $Company->getList($where, array('utype' => 'crm'));
 
            foreach ($comList['list']  as $key => $val){
                $comList['list'][$key]['wxBindmsg'] = $this->wxBindState($val);
            }
 
            $this->yunset('rows', $comList['list']);
        }
        $this->yuntpl(array('admin/crm_org_kh'));
    }
}
 
?>