266 lines
7.0 KiB
PHP
266 lines
7.0 KiB
PHP
![]() |
<?php
|
||
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
||
|
|
||
|
class Ad extends MY_Controller {
|
||
|
|
||
|
public function __construct()
|
||
|
{
|
||
|
parent::__construct();
|
||
|
$this->Func_model->check_session(true);
|
||
|
$this->load->model('admin/Ad_model');
|
||
|
$this->load->model('admin/City_model');
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
获取广告牌列表
|
||
|
*/
|
||
|
public function lst()
|
||
|
{
|
||
|
$pagecurrent = isset($_POST['pagecurrent'])?stripslashes($_POST['pagecurrent']):"";
|
||
|
$communityid = isset($_POST['communityid'])?$_POST['communityid']:"";
|
||
|
$initcity = isset($_POST['initcity'])?$_POST['initcity']:"";
|
||
|
|
||
|
if ($pagecurrent == "")
|
||
|
{
|
||
|
return false;
|
||
|
}else
|
||
|
{
|
||
|
$data = array();
|
||
|
$num = $this->Config_model->getPageNum();
|
||
|
if ($communityid != "")
|
||
|
{
|
||
|
$like = array();
|
||
|
$where = array("communityid" => $communityid);
|
||
|
$data = $this->Db_model->getPage("advertisement",$where,$like,$pagecurrent);
|
||
|
$msg = $this->Db_model->getSearchData("advertisement",$where,$like,"id","DESC",((int)$pagecurrent-1)*$num,$num);
|
||
|
$len = count($data);
|
||
|
}else
|
||
|
{
|
||
|
//$cityid = isset($_POST['cityid'])?$_POST['cityid']:"";
|
||
|
$areaid = isset($_POST['areaid'])?$_POST['areaid']:"";
|
||
|
$communityid = isset($_POST['communityid'])?$_POST['communityid']:"";
|
||
|
|
||
|
|
||
|
$like = array();
|
||
|
if ($areaid != "" && $communityid == "")
|
||
|
{
|
||
|
$where = array("areaid" => $areaid);
|
||
|
}else if ($areaid != "" && $communityid != "")
|
||
|
{
|
||
|
$where = array("areaid" => $areaid, "communityid" => $communityid);
|
||
|
}else
|
||
|
{
|
||
|
$where = array();
|
||
|
}
|
||
|
|
||
|
$data = $this->Db_model->getPage("advertisement",$where,$like,$pagecurrent);
|
||
|
$msg = $this->Db_model->getSearchData("advertisement",$where,$like,"id","DESC",((int)$pagecurrent-1)*$num,$num);
|
||
|
$len = count($data);
|
||
|
}
|
||
|
|
||
|
foreach ($msg as $row)
|
||
|
{
|
||
|
$data[$len][] = $this->Ad_model->setAdMsg($row);
|
||
|
}
|
||
|
if ($initcity == "true")
|
||
|
$data['arealist'] = $this->City_model->getArea("");
|
||
|
$this->Func_model->toJsFunc("adList",$this->Func_model->decodeUnicode($data));
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
增加广告牌
|
||
|
*/
|
||
|
public function addAd()
|
||
|
{
|
||
|
$data = $this->Ad_model->receiveAdMsg();
|
||
|
|
||
|
$where = array('number' => $data['number']);
|
||
|
$infor = $this->Db_model->getSpecificData("advertisement",$where);
|
||
|
if (count($infor) > 0)
|
||
|
{
|
||
|
$this->Func_model->setTip("number_tip",$this->Config_model->msg[7]);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
$count=count($_FILES["file"]["name"]);
|
||
|
for($i=0;$i<$count;$i++)
|
||
|
{
|
||
|
if ($_FILES["file"]['name'][$i] != "")
|
||
|
{
|
||
|
$field_name = 'file_' . $i;
|
||
|
$_FILES[$field_name] = array('name' => $_FILES["file"]['name'][$i],
|
||
|
'size' => $_FILES["file"]['size'][$i],
|
||
|
'citydess' => $_FILES["file"]['citydess'][$i],
|
||
|
'type' => $_FILES["file"]['type'][$i],
|
||
|
'tmp_name' => $_FILES["file"]['tmp_name'][$i],
|
||
|
'error' => $_FILES["file"]['error'][$i]
|
||
|
);
|
||
|
$msg = $this->Func_model->do_upload($field_name, $this->Config_model->fileMsg);
|
||
|
|
||
|
if ($msg)
|
||
|
{
|
||
|
if ($i == 0)
|
||
|
{
|
||
|
$data['photo'] = $msg['file_name'];
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
$data['img'] = $msg['file_name'];
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$this->Db_model->insertData("advertisement",$data);
|
||
|
$this->Func_model->toJsFunc("disAd","");
|
||
|
$this->Func_model->setAlert($this->Config_model->msg[0]);
|
||
|
}
|
||
|
|
||
|
|
||
|
/*
|
||
|
删除广告
|
||
|
*/
|
||
|
public function delAd()
|
||
|
{
|
||
|
$id = isset($_POST['id'])?$_POST['id']:"";
|
||
|
|
||
|
if ($id == "")
|
||
|
return ;
|
||
|
|
||
|
$where = array('id' => $id);
|
||
|
$this->Db_model->delData("advertisement",$where);
|
||
|
$this->Func_model->toJsFunc("disAd","");
|
||
|
$this->Func_model->setAlert($this->Config_model->msg[0]);
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
广告信息
|
||
|
*/
|
||
|
public function adInfor()
|
||
|
{
|
||
|
$id = isset($_POST['adid'])?$_POST['adid']:"";
|
||
|
|
||
|
if ($id == "")
|
||
|
return ;
|
||
|
|
||
|
$where = array('id' => $id);
|
||
|
$infor = $this->Db_model->getSpecificData("advertisement",$where);
|
||
|
|
||
|
$data = $this->Ad_model->setAdMsg($infor[0]);
|
||
|
$data['citylist'] = $this->City_model->getCity();
|
||
|
$this->Func_model->toJsFunc("adInfor",$this->Func_model->decodeUnicode($data));
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
编辑广告信息
|
||
|
*/
|
||
|
public function editAd()
|
||
|
{
|
||
|
$id = isset($_POST['adid'])?$_POST['adid']:"";
|
||
|
$data['cityid'] = isset($_POST['cityid'])?$_POST['cityid']:"";
|
||
|
$data['areaid'] = isset($_POST['areaid'])?$_POST['areaid']:"";
|
||
|
$data['communityid'] = isset($_POST['communityid'])?$_POST['communityid']:"";
|
||
|
$data['number'] = isset($_POST['number'])?$_POST['number']:"";
|
||
|
$data['citydess'] = isset($_POST['cityd'])?$_POST['cityd']:"";
|
||
|
$data['free'] = isset($_POST['vacancy'])?$_POST['vacancy']:"";
|
||
|
$data['size'] = isset($_POST['size'])?$_POST['size']:"";
|
||
|
|
||
|
$where = array('number' => $data['number']);
|
||
|
$infor = $this->Db_model->getSpecificData("advertisement",$where);
|
||
|
if (count($infor) > 0)
|
||
|
{
|
||
|
if ((int)$infor[0]->id != (int)$id)
|
||
|
{
|
||
|
$this->Func_model->setTip("number_tip",$this->Config_model->msg[7]);
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if ($_FILES['file']['name'] != "")
|
||
|
{
|
||
|
$msg = $this->Func_model->do_upload("file", $this->Config_model->fileMsg);
|
||
|
$data['img'] = $msg['file_name'];
|
||
|
}
|
||
|
|
||
|
$where = array('id' => $id);
|
||
|
$this->Db_model->updateData("advertisement",$data,$where);
|
||
|
|
||
|
$this->Func_model->toJsFunc("editAd","");
|
||
|
$this->Func_model->setAlert($this->Config_model->msg[0]);
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
所有广告牌信息
|
||
|
*/
|
||
|
public function getAd()
|
||
|
{
|
||
|
$data = $this->Ad_model->getAd();
|
||
|
$this->Func_model->toJsFunc("setAd",$this->Func_model->decodeUnicode($data));
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
删除图片
|
||
|
*/
|
||
|
public function delPhoto()
|
||
|
{
|
||
|
$id = isset($_POST['id'])?$_POST['id']:"";
|
||
|
$photo = isset($_POST['photo'])?$_POST['photo']:"";
|
||
|
|
||
|
$where = array('id' => $id);
|
||
|
$infor = $this->Db_model->getSpecificData("advertisement",$where);
|
||
|
|
||
|
$imgarr = explode('|', $infor[0]->photo);
|
||
|
foreach($imgarr as $k=>$v){
|
||
|
if ($v == $photo)
|
||
|
{
|
||
|
array_splice($imgarr,$k,1);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$data['photo'] = implode('|', $imgarr);
|
||
|
$this->Db_model->updateData("advertisement",$data,$where);
|
||
|
$this->Func_model->toJsFunc("editAd","");
|
||
|
$this->Func_model->setAlert($this->Config_model->msg[0]);
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
编辑封面
|
||
|
*/
|
||
|
public function editPhoto()
|
||
|
{
|
||
|
$id = isset($_POST['id'])?$_POST['id']:"";
|
||
|
|
||
|
$msg = $this->Func_model->do_upload("photo", $this->Config_model->fileMsg);
|
||
|
$img = $msg['file_name'];
|
||
|
|
||
|
$where = array('id' => $id);
|
||
|
$infor = $this->Db_model->getSpecificData("advertisement",$where);
|
||
|
if ($infor[0]->photo == "")
|
||
|
{
|
||
|
$data['photo'] = $img;
|
||
|
}else
|
||
|
{
|
||
|
$data['photo'] = $infor[0]->photo . "|" . $img;
|
||
|
}
|
||
|
|
||
|
$this->Db_model->updateData("advertisement",$data,$where);
|
||
|
$this->Func_model->toJsFunc("editAd","");
|
||
|
$this->Func_model->setAlert($this->Config_model->msg[0]);
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
更新广告牌的空余广告位
|
||
|
*/
|
||
|
public function updateFree(){
|
||
|
$id=$_POST['id'];
|
||
|
$infors = $this->Db_model->getSpecificData("vacancy",array("signid"=>$id,"state"=>0));
|
||
|
$frees=count($infors);
|
||
|
$this->Db_model->updateData("advertisement",array("free"=>$frees),array("id"=>$id));
|
||
|
$this->Func_model->toJsFunc("updateAd",$frees.",".$id);
|
||
|
$this->Func_model->setAlert($this->Config_model->msg[0]);
|
||
|
}
|
||
|
}
|