chengkun
2025-04-27 ecc546d7df6ad021bfbc531674b10c2ffd224637
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
<?php
 
 
class ad_model extends model{
 
    // 查询广告类别
    function getAdClassList($whereData = array(), $data = array())
    {
        $ListNew = array();
        $data['field'] = empty($data['field']) ? '*' : $data['field'];
        $List = $this->select_all('ad_class', $whereData, $data['field']);
        
        if (! empty($List)) {
            
            if ($data['href']) {
                foreach ($List as $k => $v) {
                    
                    $List[$k]['hrefn'] = checkpic($v['href']);
                }
            }
            
            $ListNew['list'] = $List;
        }
        
        return $ListNew;
    }
 
    // 查询单个广告类
    function getAdClassInfo($whereData = array(), $data = array())
    {
        if ($whereData) {
            $data['field'] = empty($data['field']) ? '*' : $data['field'];
            
            $acInfo = $this->select_once('ad_class', $whereData, $data['field']);
        }
        
        return $acInfo;
    }
 
    // 更新广告类
    function upAdClass($whereData = array(), $data = array())
    {
        if (! empty($whereData)) {
            
            $nid = $this->update_once('ad_class', $data, $whereData);
        }
        return $nid;
    }
 
    // 添加广告类
    function addAdClass($setData = array())
    {
        if (! empty($setData)) {
            
            $nid = $this->insert_into('ad_class', $setData);
        }
        
        return $nid;
    }
 
    // 删除广告
    function delAdClass($whereData, $data)
    {
        if ($data['type'] == 'one') { // 单个删除
            
            $limit = 'limit 1';
        }
        
        if ($data['type'] == 'all') { // 多个删除
            
            $limit = '';
        }
        
        $result = $this->delete_all('ad_class', $whereData, $limit);
        
        return $result;
    }
 
    // 查询广告
    function getList($whereData = array(), $data = array())
    {
        $ListNew = array();
        $data['field']      =   empty($data['field']) ? '*' : $data['field'];
        
        if($this->config['did']){
            $whereData['did']   =   $this->config['did'];
        }
        $List = $this->select_all('ad', $whereData, $data['field']);
        
        if (! empty($List)) {
            
            $ListNew['list'] = $List;
        }
        
        return $ListNew;
    }
 
    // 添加广告
    function addAd($setData = array())
    {
        if (! empty($setData)) {
            
            $nid = $this->insert_into('ad', $setData);
        }
        
        return $nid;
    }
 
    // 查询广告
    function getInfo($whereData = array(), $data = array())
    {
        if ($whereData) {
            $data['field'] = empty($data['field']) ? '*' : $data['field'];
            
            $info = $this->select_once('ad', $whereData, $data['field']);
            if ($info['pic_url']) {
                $info['pic_url_n'] = checkpic($info['pic_url']);
            }
        }
        
        return $info;
    }
 
    // 更新广告
    function upInfo($whereData = array(), $data = array())
    {
        if (! empty($whereData)) {
            
            $nid = $this->update_once('ad', $data, $whereData);
        }
        return $nid;
    }
 
    // 删除广告
    function delAd($whereData, $data)
    {
        if ($data['type'] == 'one') { // 单个删除
            
            $limit = 'limit 1';
        }
        
        if ($data['type'] == 'all') { // 多个删除
            
            $limit = '';
        }
         
        $result = $this->delete_all('ad', $whereData, $limit);
        
        return $result;
    }
 
    // 查询广告订单
    function getAdOrderInfo($whereData = array(), $data = array())
    {
        if ($whereData) {
            $data['field'] = empty($data['field']) ? '*' : $data['field'];
            
            $adOrder = $this->select_once('ad_order', $whereData, $data['field']);
            
            if($adOrder['pic_url']){
                $adOrder['pic_url_n'] = checkpic($adOrder['pic_url']);
            }
        }
        
        return $adOrder;
    }
 
    // 查询广告订单列表
    function getAdOrderList($whereData = array(), $data = array())
    {
        $ListNew = array();
        $data['field'] = empty($data['field']) ? '*' : $data['field'];
        $List = $this->select_all('ad_order', $whereData, $data['field']);
        
        if (! empty($List)) {
            
            foreach ($List as $k => $v) {
                    
                $List[$k]['pic_url_n'] = checkpic($v['pic_url']);
            }
            
            if ($data['utype'] == 'admin') {
                $List = $this->getDataList($List);
            }
            // 联合company_order表查询
            if ($data['utype'] == 'order') {
                $orderids = array();
                foreach ($List as $k => $v) {
                    if ($v['order_id']) {
                        $orderids[] = $v['order_id'];
                    }
                }
                $owhere = array(
                    'uid'      => $data['uid'],
                    'order_id' => array('in',pylode(',', $orderids)));
                
                $order = $this->select_all('company_order', $owhere, 'id,order_id,order_type');
                
                foreach ($List as $k => $val) {
                    
                    foreach ($order as $v) {
                        if ($val['order_id'] == $v['order_id']) {
                            $List[$k]['orderid']    = $v['id'];
                            $List[$k]['order_type'] = $v['order_type'];
                        }
                    }
                }
            }
            $ListNew['list'] = $List;
        }
        return $ListNew;
    }
 
    // 添加广告订单
    function addOrderAd($setData = array())
    {
        if (! empty($setData)) {
            
            $nid = $this->insert_into('ad_order', $setData);
        }
        
        return $nid;
    }
 
    // 更新广告订单
    function upOrderAd($whereData = array(), $data = array())
    {
        if (! empty($whereData)) {
            
            $nid = $this->update_once('ad_order', $data, $whereData);
        }
        return $nid;
    }
 
    // 删除广告订单
    function delAdOrder($whereData, $data)
    {
        if ($data['type'] == 'one') { // 单个删除
            
            $limit = 'limit 1';
        }
        
        if ($data['type'] == 'all') { // 多个删除
            
            $limit = '';
        }
 
        $result = $this->delete_all('ad_order', $whereData, $limit);
        
        return $result;
    }
 
    // 查询广告列表
    function getAdList($whereData = array(), $data = array())
    {
        $ListNew = array();
        $List = $this->getList($whereData, $data['field']);
        
        // 提取广告类
        $class = $this->getAdClassList(array('orderby' => 'orders,desc'));
        $ListNew['class'] = $class['list'];
        
        if (is_array($class['list']) && $class) {
            foreach ($class['list'] as $val) {
                $nclass[$val['id']] = $val['class_name'];
            }
        }
        $ListNew['nclass'] = $nclass;
        
        if (! empty($List['list'])) {
            
            // 提取分站
            require_once ('cache.model.php');
            $cacheM   = new cache_model($this->db, $this->def);
            $domain   = $cacheM->GetCache('domain');
            
            $linkrows = $List['list'];
            if (is_array($linkrows)) {
                foreach ($linkrows as $key => $value) {
                    
                    $start = @strtotime($value['time_start']);
                    $end   = @strtotime($value['time_end'] . " 23:59:59");
                    $time  = time();
                    
                    $linkrows[$key]['class_name']  = $nclass[$value['class_id']];
                    if ($value['did']>0) {
                        $linkrows[$key]['d_title'] = $domain['Dname'][$value['did']];
                    } elseif($value['did']==-1) {
                        $linkrows[$key]['d_title'] = '全站';    
                    } else {
                        $linkrows[$key]['d_title'] = '主站';
                    }
                    if ($value['is_check'] == "1") {
                        $linkrows[$key]['check'] = "<font color='green'>已审核</font>";
                    } else {
                        $linkrows[$key]['check'] = "<font color='red'>未审核</font>";
                    }
                    $value['pic_url'] = checkpic($value['pic_url']);
                    
                    switch ($value['ad_type']) {
                        case "word":
                            $linkrows[$key]['ad_typename'] = "文字广告";
                            break;
                        
                        case "pic":
                            $linkrows[$key]['ad_typename'] = '<a href="javascript:void(0)" class="preview admin_n_img" url="' . $value['pic_url'] . '"></a>';
                            break;
                        
                        case "flash":
                            $linkrows[$key]['ad_typename'] = "FLASH广告";
                            break;
                        
                        case "lianmeng":
                            $linkrows[$key]['ad_typename'] = "联盟广告";
                            break;
                    }
                    
                    if ($value['time_start'] != "" && $start != "" && ($value['time_end'] == "" || $end != "")) {
                        
                        if ($value['time_end'] == "" || $end > $time) {
                            
                            if ($value['is_open'] == '1' && $start < $time) {
                                
                                $linkrows[$key]['type'] = "<font color='green'>使用中..</font>";
                                
                            } else if ($start < $time && $value['is_open'] == '0') {
                                
                                $linkrows[$key]['type'] = "<font color='red'>已停用</font>";
                                
                            } elseif ($start > $time && ($end > $time || $value['time'] == "")) {
                                
                                $linkrows[$key]['type'] = "<font color='#ff6600'>广告暂未开始</font>";
                            }
                        } else {
                            
                            $linkrows[$key]['type'] = "<font color='red'>过期广告</font>";
                            $linkrows[$key]['is_end'] = '1';
                        }
                    } else {
                        $linkrows[$key]['type'] = "<font color='red'>无效广告</font>";
                    }
                }
            }
            $ListNew['list'] = $linkrows;
        }
        
        return $ListNew;
    }
 
    /**
     * 查询ad_order表内没有的数据,引用相关类,查询关联表,提取列表数据所需信息
     * 
     * @param array $List            
     */
    private function getDataList($List)
    {
        include (CONFIG_PATH."db.data.php");
        
        foreach ($List as $k => $v) {
            $List[$k]['order_state_n'] = $arr_data['paystate'][$v['order_state']];
            $comid[] = $v['comid'];
        }
        
        // 查询member
        $mWhere['uid']  = array('in',pylode(',', $comid));
        $mList = $this->select_all('member', $mWhere, '`uid`,`username`');
        
        // 查询company
        $comWhere['uid']  = array('in', pylode(',', $comid));
        $comList = $this->select_all('company', $comWhere, '`uid`,`name`');
        
        foreach ($List as $k => $v) {
            
            // 提取member查询数据
            if (! empty($mList)) {
                
                foreach ($mList as $mv) {
                    
                    if ($v['comid'] == $mv['uid']) {
                        
                        $List[$k]['username'] = $mv['username'];
                    }
                }
            }
            
            // 提取company查询数据
            if (! empty($comList)) {
                
                foreach ($comList as $comv) {
                    
                    if ($v['comid'] == $comv['uid']) {
                        
                        $List[$k]['comname'] = $comv['name'];
                    }
                }
            }
        }
        
        return $List;
    }
 
    // 查询广告点击次数
    function getAdClickNum($Where)
    {
        return $this->select_num('adclick', $Where);
    }
 
    /**
     * 引用userinfo类,查询member列表信息
     */
    // 插入广告点击记录
    function addAdClick($data = array())
    {
        
        return $this->insert_into('adclick', $data);
    }
 
    function model_ad_arr()
    {
        $show = "<?php\r\n\$ad_label=array();\r\n";
        
        $ad_list = $this->select_all("ad", array('is_open' => 1,'orderby' => array('sort,desc','id,desc')));
        
        if (is_array($ad_list)) {
            
            $time = time();
            
            foreach ($ad_list as $key => $value) {
                
                $start = strtotime($value['time_start'] . " 00:00:00");
                
                $end   = strtotime($value['time_end'] . " 23:59:59");
                
                if (! empty($value['time_end'])) {
                    
                    if ($end > $time) {
                        
                        $end_type = 1;
                    } else {
                        
                        $end_type = 2;
                    }
                } else {
                    
                    $end_type = 1;
                }
                if ($start && $start < $time && $end_type == 1 && $value['is_check'] == "1") {
                    
                    if ($value['ad_type'] == "word") {
                        if ($value['target'] == 2) {
                            $show .= "\$ad_label['$value[class_id]']['ad_$value[id]']['html']=\"<a href='$value[word_url]' target='_blank'>$value[word_info]</a>\";\r\n";
                        }else{
                            $show .= "\$ad_label['$value[class_id]']['ad_$value[id]']['html']=\"<a href='$value[word_url]'>$value[word_info]</a>\";\r\n";
                        }
                    } elseif ($value['ad_type'] == "pic") {
                        
                        if (@! stripos("ttp://", $value['pic_url'])) {
                            
                            $pic_url = checkpic($value['pic_url']);
                        }
                        
                        $height = $width = $alt = "";
                        
                        if ($value['pic_height']) {
                            
                            $height = "height='$value[pic_height]'";
                        }
                        if ($value['pic_width']) {
                            
                            $width  = "width='$value[pic_width]'";
                        }
                        if ($value['pic_content']) {
                            
                            $alt    = "alt='".str_replace('"','\"',$value['pic_content'])."'";
                        }
                        if ($this->config['sy_seo_rewrite'] == '1') {
                            $pic_src = $this->config['sy_weburl'] . "/c_clickhits-id_" . $value['id'] . ".html";
                        } else {
                            
                            $pic_src = $this->config['sy_weburl'] . "/index.php?c=clickhits&id=" . $value['id'];
                        }
                        
                        if ($value['target'] == 2) {
                            
                            $show .= "\$ad_label['$value[class_id]']['ad_$value[id]']['html']=\"<a href='$pic_src' target='_blank' rel='nofollow'><img src='$pic_url'  " . $height . " " . $width . " " . $alt . "></a>\";\r\n";
 
                            $show .= "\$ad_label['$value[class_id]']['ad_$value[id]']['lay_html']=\"<a href='$pic_src' target='_blank' rel='nofollow'><img lay-src='$pic_url'  " . $height . " " . $width . " " . $alt . "></a>\";\r\n";
 
 
                        } else {
                            
                            $show .= "\$ad_label['$value[class_id]']['ad_$value[id]']['html']=\"<a href='$pic_src' rel='nofollow'><img src='$pic_url' " . $height . " " . $width . " " . $alt . " ></a>\";\r\n";
 
                            $show .= "\$ad_label['$value[class_id]']['ad_$value[id]']['lay_html']=\"<a href='$pic_src' rel='nofollow'><img lay-src='$pic_url' " . $height . " " . $width . " " . $alt . " ></a>\";\r\n";
                        }
                        
                        $show .= "\$ad_label['$value[class_id]']['ad_$value[id]']['pic']=\"$pic_url\";\r\n";
                        
                        $show .= "\$ad_label['$value[class_id]']['ad_$value[id]']['src']=\"$pic_src\";\r\n";
                    } elseif ($value['ad_type'] == "flash") {
                        
                        if (! stripos("ttp://", $value['flash_url'])) {
                            
                            $flash_url = checkpic($value['flash_url']);
                        }
                        
                        $show .= "\$ad_label['$value[class_id]']['ad_$value[id]']['html']=\"<object type='application/x-shockwave-flash' data='$flash_url' width='$value[flash_width]' height='$value[flash_height]'><param name='movie' value='$flash_url' /><param value='transparent' name='wmode'></object>\";\r\n";
                    } elseif ($value['ad_type'] == "lianmeng") {
                        
                        $show .= "\$ad_label['$value[class_id]']['ad_$value[id]']['html']=\"" . str_replace('"', '\\"', $value['lianmeng_url']) . "\";\r\n";
                    }
                    $show .= "\$ad_label['$value[class_id]']['ad_$value[id]']['start']=\"" . strtotime(date('Y-m-d H:i:s', $start)) . "\";\r\n";
                    $show .= "\$ad_label['$value[class_id]']['ad_$value[id]']['end']=\"" . strtotime(date('Y-m-d H:i:s', $end)) . "\";\r\n";
                    $show .= "\$ad_label['$value[class_id]']['ad_$value[id]']['type']=\"" . $value['ad_type'] . "\";\r\n";
                    $show .= "\$ad_label['$value[class_id]']['ad_$value[id]']['name']=\"" . $value['ad_name'] . "\";\r\n";
                    $show .= "\$ad_label['$value[class_id]']['ad_$value[id]']['did']=\"" . $value['did'] . "\";\r\n";
                    $show .= "\$ad_label['$value[class_id]']['ad_$value[id]']['id']=\"" . $value['id'] . "\";\r\n";
                    $show .= "\$ad_label['$value[class_id]']['ad_$value[id]']['class_id']=\"" . $value['class_id'] . "\";\r\n";
                    if($value['appurl']){
                        $show .= "\$ad_label['$value[class_id]']['ad_$value[id]']['appurl']=\"" . $value['appurl'] . "\";\r\n";
                    }
                }
            }
        }
        $show .= "?>";
        $path = PLUS_PATH . "pimg_cache.php";
        $fp = @fopen($path, "w");
        $fw = @fwrite($fp, $show);
        @fclose($fp);
        @chmod($path, 0777);
        return $fw;
    }
 
    function model_saveadd($post, $pic = NULL)
    {
        if (empty($post['did'])) {
            
            $did = 0;
        }
        $value = array(
            
            'ad_name'    => $post['ad_name'],
            'target'     => $post['target'],
            'time_start' => $post['ad_time_start'],
            'time_end'   => $post['ad_time_end'],
            'ad_type'    => $post['ad_type'],
            'class_id'   => $post['class_id'],
            'is_check'   => $post['is_check'],
            'did'        => $post['did'],
            'is_open'    => $post['is_open'],
            'sort'       => $post['sort'],
            'remark'     => $post['remark'],
            'appurl'     => $post['appurl']
        );
        
        if ($post['ad_type']) {
            
            if ($post['ad_type'] == "word") {
                
                $value['word_info']    =    $post['word_info'];
                $value['word_url']    =    $post['word_url'];
            } elseif ($post['ad_type'] == "pic") {
                
                if ($pic != "") {
                    if (strpos($pic,$this->config['sy_weburl']) !== false){
                        $pic  =  str_replace($this->config['sy_weburl'].'/data','./data',$pic);
                    }
                    if (strpos($pic,$this->config['sy_ossurl']) !== false){
                        $pic  =  str_replace($this->config['sy_ossurl'].'/data','./data',$pic);
                    }
                    $value['pic_url']    =    $pic;
                }
                $pic_src = str_replace("amp;", "", $post['pic_src']);
                
                $value['pic_src']        =    $pic_src;
                $value['pic_content']    =    $post['pic_content'];
                $value['pic_width']        =    $post['pic_width'];
                $value['pic_height']    =    $post['pic_height'];
                
            } elseif ($post['ad_type'] == "flash") {
                if ($pic != "") {
                    $value['flash_url']    =    $pic;
                }
                $value['flash_width']    =    $post['flash_width'];
                $value['flash_height']    =    $post['flash_height'];
                
            } elseif ($post['ad_type'] == "lianmeng") {
                
                $value['lianmeng_url']    =    $post['lianmeng_url'];
            }
            if($post['id']){
                $nid     =     $this->update_once("ad", $value, array('id' => $post['id']));
                $msg    =    '广告更新';
                $url    =   str_replace('&amp;','&',$post['lasturl']);
            }else{
                $nid     =     $this->insert_into("ad", $value);
                $msg    =    '广告添加';
                $url    =   'index.php?m=advertise';
            }
            $this->model_ad_arr();
            
            if ($nid) {
                $return['msg']        =     $msg."成功!";
                $return['url']        =     $url;
                $return['errcode']    =    9;
            } else {
                
                $return['msg']        =    $msg."失败!";
                $return['url']        =    $_SERVER['HTTP_REFERER'];
                $return['errcode']    =    8;
            }
        } else {
            
            $return['msg']         =     "您还未选择广告类型!";
            $return['url']         =     'index.php?m=advertise&c=ad_add';
            $return['errcode']     =     8;
        }
        return $return;
    }
 
    /**
     * 未发现使用:   -----  【 sy  2020年6月12日 11:42:30】
     * 暂时不做删除
     */
    /**
    function model_del_ad($id)
    {
        
        if ($id) {
 
            $result =   $this->delete_all('ad', array('id' => $id));
 
            $return['msg']      =   $result ? '删除成功!' : '删除失败!';
            $return['url']      =   'index.php?m=advertise';
            $return['errcode']  =   $result ? 9 : 8;
 
            $this->model_ad_arr();
        }
 
        return $return;
    }
    */
}
?>