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'] = "已审核"; } else { $linkrows[$key]['check'] = "未审核"; } $value['pic_url'] = checkpic($value['pic_url']); switch ($value['ad_type']) { case "word": $linkrows[$key]['ad_typename'] = "文字广告"; break; case "pic": $linkrows[$key]['ad_typename'] = ''; 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'] = "使用中.."; } else if ($start < $time && $value['is_open'] == '0') { $linkrows[$key]['type'] = "已停用"; } elseif ($start > $time && ($end > $time || $value['time'] == "")) { $linkrows[$key]['type'] = "广告暂未开始"; } } else { $linkrows[$key]['type'] = "过期广告"; $linkrows[$key]['is_end'] = '1'; } } else { $linkrows[$key]['type'] = "无效广告"; } } } $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 = "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']=\"$value[word_info]\";\r\n"; }else{ $show .= "\$ad_label['$value[class_id]']['ad_$value[id]']['html']=\"$value[word_info]\";\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']=\"\";\r\n"; $show .= "\$ad_label['$value[class_id]']['ad_$value[id]']['lay_html']=\"\";\r\n"; } else { $show .= "\$ad_label['$value[class_id]']['ad_$value[id]']['html']=\"\";\r\n"; $show .= "\$ad_label['$value[class_id]']['ad_$value[id]']['lay_html']=\"\";\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']=\"\";\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('&','&',$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; } */ } ?>