chengkun
2025-05-23 a6f7b382623096b6a00924f418447cf5204e825e
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
<?php
 
 
 
class gongzhao_model extends model
{
    /**
     * @desc   获取公告列表
     * @param  $whereData :查询条件
     * @param  $data :自定义处理数组
     */
    public function getList($whereData, $data = array())
    {
        $Listgongzhao = array();
        $select       = $data['field'] ? $data['field'] : '*';
        $List         = $this->select_all('gongzhao', $whereData, $select);
 
        if (!empty($List)) {
            if ($data['utype'] == 'wxapp') {
                foreach ($List as $key => $va) {
                    $List[$key]['title']      = mb_substr($va['title'], 0, 40, 'utf-8');
                    $List[$key]['datetime_n'] = date('Y-m-d', $va['startime']);
                    $List[$key]['pic_n']      = checkpic($va['pic'],$this->config['sy_gongzhaologo']);
                }
            }
            $Listgongzhao ['list'] = $List;
        }
 
        return $Listgongzhao;
    }
 
    /**
     *获取公告数量
     * */
    function getNum()
    {
        return $this->select_num('gongzhao');
    }
 
    /**
     * @desc   获取公告详情
     */
    function getInfo($where = array(), $data = array())
    {
        $select = $data['field'] ? $data['field'] : '*';
        $Info   = $this->select_once('gongzhao', $where, $select);
        if (!empty($Info)) {
 
            if($Info['pic']){
                $Info['pic_n'] = checkpic($Info['pic']);
            }
 
            $Info['content'] = str_replace(array("&nbsp;", "&"), array(" ", "&amp;"), $Info['content']);
            preg_match_all('/<img(.*?)src=("|\'|\s)?(.*?)(?="|\'|\s)/', $Info['content'], $res);
            if (!empty($res[3])) {
                foreach ($res[3] as $v) {
                    if (strpos($v, 'http:') === false && strpos($v, 'https:') === false) {
                        $Info['content'] = str_replace($v, $this->config['sy_ossurl'] . $v, $Info['content']);
                    }
                }
            }
            $Info['startime_n'] = date('Y-m-d', $Info['startime']);
        }
        return $Info;
    }
 
    /**
     * @desc    添加数据
     */
    public function addInfo($data = array())
    {
        if (!empty($data['content'])) {
            $content = str_replace(array('"', '\''), array('', ''), $data['content']);
            preg_match_all('/<img[^>]+src=(.*?)\s[^>]+>/im', $content, $match);
            if (!empty($match[1])) {
                $mbstr = substr(strrchr($match[1][0], "\\"), 1);
                $str   = str_replace($mbstr, '', $match[1][0]);
                $str   = str_replace("\\", '', $str);
            }
 
            $contentRep = array('&amp;', "background-color:#ffffff", "background-color:#fff", "white-space:nowrap;");
            $contentStr = str_replace($contentRep, array('&', '', '', ''), $data['content']);
        }
        $time    = time();
        $AddData = array(
            'did'         => $data['did'] == '' ? 0 : $data['did'],
            'title'       => $data['title'],
            'startime'    => !empty($data['startime']) ? strtotime($data['startime']) : $time, //开始时间
            'endtime'     => strtotime($data['endtime']),
            'keyword'     => $data['keyword'],
            'description' => $data['description'],
            'pic'         => !empty($data['pic'])?$data['pic']:'',
            'content'     => $contentStr,
            'datetime'    => $time
        );
        $nid     = $this->insert_into('gongzhao', $AddData);
 
        return $nid;
    }
 
    /**
     * @desc    更新数据
     */
    public function upInfo($whereData, $data = array())
    {
        if (!empty($whereData)) {
            if (!empty($data['content'])) {
                $content = str_replace(array('"', '\''), array('', ''), $data['content']);
                preg_match_all('/<img[^>]+src=(.*?)\s[^>]+>/im', $content, $match);
                if (!empty($match[1])) {
                    $mbstr = substr(strrchr($match[1][0], "\\"), 1);
                    $str   = str_replace($mbstr, '', $match[1][0]);
                    $str   = str_replace("\\", '', $str);
                }
 
                $contentRep = array('&amp;', "background-color:#ffffff", "background-color:#fff", "white-space:nowrap;");
                $contentStr = str_replace($contentRep, array('&', '', '', ''), $data['content']);
                
                
                $PostData = array(
                    'did'         => $data['did'] == '' ? 0 : $data['did'],
                    'title'       => $data['title'],
                    'startime'    => strtotime($data['startime']), //开始时间
                    'endtime'     => strtotime($data['endtime']),
                    'keyword'     => $data['keyword'],
                    'description' => $data['description'],
                    'content'     => $contentStr
                );
                if(!empty($data['pic'])){
                    $PostData['pic'] = $data['pic'];
                }
                
                $nid = $this->update_once('gongzhao', $PostData, array('id' => $whereData['id']));
            }elseif (isset($data['rec'])){
                
                $nid = $this->update_once('gongzhao', $data, array('id' => $whereData['id']));
            }
 
            return $nid;
        }
    }
 
    /**
     * @desc    删除数据
     */
    public function delgongzhao($delId)
    {
        if (empty($delId)) {
            return array(
                'errcode' => 8,
                'msg'     => '请选择要删除的数据!',
            );
        } else {
            if (is_array($delId)) {
                $delId               = pylode(',', $delId);
                $return['layertype'] = 1;
            } else {
                $return['layertype'] = 0;
            }
 
            $nid = $this->delete_all('gongzhao', array('id' => array('in', $delId)), '');
            if ($nid) {
                $return['msg']     = '公告';
                $return['errcode'] = $nid ? '9' : '8';
                $return['msg']     = $nid ? $return['msg'] . '删除成功!' : $return['msg'] . '删除失败!';
            }
        }
 
        return $return;
    }
}
 
?>