Beispiel #1
0
 function show()
 {
     $report = array();
     //搜索过期广告 排除下架广告
     $expired_con = ' AND end_time<unix_timestamp() AND end_time!="" AND status!=6 AND status!=2';
     $sql = 'SELECT id FROM ' . DB_PREFIX . 'advcontent WHERE 1 ' . $expired_con;
     $q = $this->db->query($sql);
     $ads = array();
     while ($row = $this->db->fetch_array($q)) {
         $ads[] = $row['id'];
     }
     //过期广告
     if ($ads) {
         //查询过期广告的其余时间段
         $sql = 'SELECT * FROM ' . DB_PREFIX . 'adtime WHERE adid IN(' . implode(',', $ads) . ') AND end_time!="" ORDER BY start_time ASC';
         $q = $this->db->query($sql);
         $adtimes = array();
         while ($row = $this->db->fetch_array($q)) {
             $adtimes[$row['adid']]['start_time'][] = $row['start_time'];
             $adtimes[$row['adid']]['end_time'][] = $row['end_time'];
         }
         foreach ($adtimes as $adid => $array_time) {
             $start_time = $end_time = '';
             $publishTime = get_ad_publishTime($array_time['start_time'], $array_time['end_time']);
             $start_time = $publishTime['start_time'] ? $publishTime['start_time'] : '';
             $end_time = $publishTime['end_time'] ? $publishTime['end_time'] : '';
             $status = get_ad_status($start_time, $end_time);
             $sql = 'UPDATE ' . DB_PREFIX . 'advcontent SET start_time = "' . $start_time . '", end_time = "' . $end_time . '", status = "' . $status . '" WHERE id = ' . intval($adid);
             $this->db->query($sql);
             $report['下架'][] = $adid;
         }
     }
     //广告上架
     $ads2 = array();
     $sql2 = 'SELECT id FROM ' . DB_PREFIX . 'advcontent WHERE start_time <= unix_timestamp() AND status != 6 AND end_time>=unix_timestamp() AND end_time !=""';
     $q2 = $this->db->query($sql2);
     while ($row = $this->db->fetch_array($q2)) {
         $ads2[] = $row['id'];
     }
     //存在过期广告
     if ($ads2) {
         $sql = 'UPDATE ' . DB_PREFIX . 'advcontent SET status = 1 WHERE id IN (' . implode(',', $ads2) . ')';
         $this->db->query($sql);
     }
     $this->addItem($report);
     $this->output();
 }
Beispiel #2
0
 function get_ad_status_by_id($ids = array())
 {
     if (!$ids) {
         return;
     }
     $return = array();
     $ids = is_array($ids) && $ids ? implode(',', $ids) : $ids;
     $sql = 'SELECT * FROM ' . DB_PREFIX . 'adtime WHERE adid IN(' . $ids . ') ORDER BY start_time ASC';
     $q = $this->db->query($sql);
     $adtimes = array();
     while ($row = $this->db->fetch_array($q)) {
         $adtimes[$row['adid']]['start_time'][] = $row['start_time'];
         $adtimes[$row['adid']]['end_time'][] = $row['end_time'];
     }
     foreach ($adtimes as $adid => $array_time) {
         $start_time = $end_time = '';
         //默认状态为过期
         $publishTime = get_ad_publishTime($array_time['start_time'], $array_time['end_time']);
         $start_time = $publishTime['start_time'] ? $publishTime['start_time'] : '';
         $end_time = $publishTime['end_time'] ? $publishTime['end_time'] : '';
         $return[$adid] = intval(get_ad_status($start_time, $end_time));
     }
     return $return;
 }
Beispiel #3
0
 function update_content()
 {
     $sql = 'SELECT * FROM ' . DB_PREFIX . 'advcontent WHERE id = ' . intval($this->input['ad_id']);
     $ad = $this->db->query_first($sql);
     if (!$ad) {
         $this->errorOutput(NOID);
     }
     $data = array('id' => intval($this->input['ad_id']), 'title' => trim($this->input['title']), 'link' => in_array(strtolower($this->input['link']), array('http://', 'https://')) ? '' : trim($this->input['link']), 'brief' => trim($this->input['brief']), 'source' => trim($this->input['source']), 'org_id' => $this->user['org_id'], 'priority' => intval(trim($this->input['priority'])), 'ip' => hg_getip(), 'weight' => '', 'end_time' => '', 'start_time' => '');
     if (!$this->input['mtype']) {
         $this->errorOutput('无效的广告素材');
     }
     if ($data['link']) {
         if (!preg_match('/^(http:\\/\\/|https:\\/\\/){1}/i', $data['link']) && !preg_match('/(.*?)#(.*?)/i', $data['link'])) {
             $this->errorOutput(AD_LINK_ERROR);
         }
     }
     if ($this->input['isvalidweight']) {
         $data['weight'] = intval(trim($this->input['weight']));
     }
     $update_material_sql = '';
     if ($this->input['material'] || $this->input['js_code'] || $this->input['ad_text']) {
         //如果更新素材信息
         $data['mtype'] = $this->input['mtype'];
         $data['material'] = $this->get_material_info($this->input['material']);
         $update_material_sql = 'material = \'' . $data['material'] . '\',' . 'mtype = "' . $data['mtype'] . '",';
     }
     //表单提交名称为start开始时间和end结束时间
     $publishTime = get_ad_publishTime($this->input['start'], $this->input['end'], false);
     if ($publishTime === false) {
         $this->errorOutput(AD_TIME_ERROR);
     }
     //下架广告状态不更新
     $sql = 'SELECT status,id,org_id,user_id FROM ' . DB_PREFIX . 'advcontent WHERE id = ' . $data['id'];
     $record = $this->db->query_first($sql);
     #####
     $this->verify_content_prms(array('_action' => 'manage', 'id' => $record['id'], 'org_id' => $record['org_id'], 'user_id' => $record['user_id']));
     #####
     if ($record['status'] == 6) {
         $data['status'] = 6;
     } else {
         $data['status'] = get_ad_status($publishTime['start_time'], $publishTime['end_time']);
     }
     //更新广告主要内容
     $sql = 'UPDATE ' . DB_PREFIX . 'advcontent SET title = "' . $data['title'] . '",' . 'link = "' . $data['link'] . '",' . 'brief = "' . $data['brief'] . '",' . 'source = "' . $data['source'] . '",' . 'priority = "' . $data['priority'] . '",' . $update_material_sql . 'weight = "' . $data['weight'] . '",' . 'start_time = "' . $publishTime['start_time'] . '",' . 'end_time = "' . $publishTime['end_time'] . '",' . 'status = "' . $data['status'] . '",' . 'ip = "' . $data['ip'] . '" WHERE id = ' . $data['id'];
     $this->db->query($sql);
     if ($this->db->affected_rows()) {
         $this->db->query("UPDATE " . DB_PREFIX . 'advcontent set update_user_id=' . $this->user['user_id'] . ', update_user_name="' . $this->user['user_name'] . '" WHERE id = ' . $data['id']);
     }
     //重新计算广告时间
     $sql = 'DELETE FROM ' . DB_PREFIX . 'adtime WHERE adid = ' . $data['id'];
     $q = $this->db->query($sql);
     $adtime = $this->adfunc->insert_ad_time($this->input['start'], $this->input['end'], $data['id']);
     if (!$adtime) {
         $this->errorOutput(ADTIME_ERROR);
     }
     $this->addLogs('更新广告内容', $ad, $data, $ad['title']);
     $this->addItem('success');
     $this->output();
 }