You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
information-system/application/third_party/advertise/controllers/index.php

172 lines
6.1 KiB
PHTML

<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Index extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->permission->is_admin();
$this->load->model('InfoStructures_model');
$this->load->model('advertise_model');
}
//广告列表
public function index($expire='news')
{
$data=array();
$data['structure_list']=$this->advertise_model->get_structure_list();
if (empty($data['structure_list'])) {
$this->add(0,false);
redirect(site_url("thirdparty/advertise"));
}
$data['ad_is_id'] = $data['structure_list'][0]->id;
$ad_sitecode=$this->config->item('site_code');
$ad_expire=$ad_expire_end=false;
if ($expire!='news') {
$ad_expire=time();
$ad_expire_end=$expire=='expired'?false:(time()+5*24*60*60);
}
$data['sub_nav']=$expire;
$data['list']=$this->advertise_model->get_ad_list($ad_sitecode,$ad_expire,$ad_expire_end);
$this->load->view('bootstrap3/header', $data);
$this->load->view('ad_list');
$this->load->view('bootstrap3/footer');
}
//广告管理编辑页面
public function detail($ad_is_id=''){
$data=array();
$data['sub_nav']='';
$data['structure_list']=$this->advertise_model->get_structure_list();
if (empty($data['structure_list'])) {
$this->add(0,false);
redirect(site_url("thirdparty/advertise"));
}
if (empty($ad_is_id)) {
$ad_is_id = $data['structure_list'][0]->id;
}
$data['ad_is_id']=$ad_is_id;
$data['advertise']=$this->advertise_model->get_advertise_treeid($data['ad_is_id']);
$data['webpage_list']=$this->advertise_model->get_advertise_page($data['ad_is_id']);
$data['click_rate']=$this->advertise_model->get_click_rate($data['advertise']->ad_id);
$data['advertise']->ad_content = str_replace("url=//","url=https://",$data['advertise']->ad_content);
$this->load->view('bootstrap3/header', $data);
$this->load->view('advertise');
$this->load->view('bootstrap3/footer');
}
public function ad_edit()
{
$ad_title=$this->input->post('ad_title');
$ad_content=$this->input->post('ad_content');
$ad_type='';
$ad_expire=strtotime($this->input->post('ad_expire'));
$ad_place=$this->input->post('ad_place');
$ad_status=$this->input->post('ad_status');
$ad_id=$this->input->post('ad_id');
$result=$this->advertise_model->update($ad_title,$ad_content,$ad_type,$ad_expire,$ad_place,$ad_status,$ad_id);
if ($result) {
$data[] = array('name' => 'ok', 'value' => $this->lang->line('form_info_success'));
}else{
$data[] = array('name' => 'no', 'value' => '保存失败,请联系管理员');
}
echo json_encode($data);
}
public function page_edit()
{
$adp_ic_url=$this->input->post('adp_ic_url');
if (trim($adp_ic_url)=='') {
$data[] = array('name' => 'no', 'value' => '关联的页面链接不能为空,吼吼!');
echo json_encode($data);
return;
}
$adp_ic_url=str_replace($this->config->item('site_url'),'',$adp_ic_url);
$adp_forself=$this->input->post('adp_forself');
$adp_status=1;
$adp_id=$this->input->post('adp_id');
$adp_ad_id=$this->input->post('adp_ad_id');
if (empty($adp_id)) {
$result=$this->advertise_model->add_page($adp_ad_id,$adp_ic_url,$adp_forself,$this->config->item('site_code'));
}else{
$result=$this->advertise_model->update_page($adp_ic_url,$adp_forself,$adp_status,$adp_id,$adp_ad_id);
}
if (!$result) {
$data[] = array('name' => 'no', 'value' => '关联失败,请联系管理员!');
echo json_encode($data);
}
}
//添加新广告节点
public function add($is_parent_id,$is_ajax=true)
{
$insert_id = $this->InfoStructures_model->Add($is_parent_id);
if ($insert_id && $ad_id=$this->advertise_model->add_advertise($insert_id,'New tree',$this->config->item('site_code'),time())){
$data[] = array('name' => 'ok', 'value' => $insert_id);
}else{
$data[] = array('name' => 'no', 'value' => $this->lang->line('form_info_error'));
}
if ($is_ajax) {
echo json_encode($data);
return TRUE;
}
return $insert_id;
}
//移动排序广告
public function tree_move()
{
//网站会提交一个同级节点id列表字符串按照这个去排序
$parent_id = $this->input->post('pid');
$idsStr = $this->input->post('ids');
$idsArray = explode(',', $idsStr);
foreach ($idsArray as $key => $value)
{
if ($value)
{
//设置排序
$this->InfoStructures_model->set_sort($value, $key);
//设置path
$this->InfoStructures_model->set_path($parent_id, $value);
}
}
$data[] = array('name' => 'ok', 'value' => $this->lang->line('structures_success_move'));
echo json_encode($data);
return TRUE;
}
//删除广告
public function delete()
{
$isdelete=$this->advertise_model->delete($this->input->post('ad_id'));
if ($isdelete) {
$this->advertise_model->delete_page($this->input->post('ad_id'));
$this->InfoStructures_model->Delete($this->input->post('ad_is_id'));
$data[] = array('name' => 'ok', 'value' => site_url('thirdparty/advertise'));
echo json_encode($data);
}else{
$data[] = array('name' => 'no', 'value' => $this->lang->line('form_keyworlds_error'));
echo json_encode($data);
}
}
public function delete_page($adp_id)
{
$result=0;
if ($this->advertise_model->delete_page_by_adpid($adp_id)) {
$result=1;
}
echo $result;
}
}