request->get('skeyword', '', 'urldecode');
$arg_where = ['b.siteid' => $this->siteid, 'b.country_code' => $this->country_code];
$arg_order = ['b.id' => 'desc'];
$arg_field = ['b.*', 'bt.id' => 'typeid', 'bt.name' => 'typename'];
if (!empty($skeyword)) {
$skeyword = trim($skeyword);
$arg_where['b.name'] = ['like', '%' . $skeyword . '%'];
$search['skeyword'] = $skeyword;
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
} else {
$search['skeyword'] = '';
}
$dataObject = model('ad')->getAdLists($arg_where, $arg_order, $arg_field);
$value = [
'list' => $dataObject->isEmpty() ? null : $dataObject->items(),
'page' => $dataObject->render(),
'search' => $search,
];
$this->assign($value);
return $this->fetch();
}
public function add($typeid = 0) {
$typeid = is_numeric($typeid) ? intval($typeid) : 0;
$arg_where = array('pid' => 0, 'stat' => 0, 'country_code' => $this->country_code);
$arg_order = array('id' => 'desc');
$arg_field = array('id', 'pid', 'name');
$typeOption = model('ad_type')->getOption($typeid, $arg_where, $arg_order, $arg_field, 100);
$value = ['typeOption' => $typeOption];
$this->assign($value);
return $this->fetch();
}
public function create() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = ['name' => 'require', 'typeid' => 'number|between:0,2147483647',];
$validatemsg = ['name.require' => '名称不能为空', 'typeid.between' => '所属上级值无效',];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$href = isset($data['ad_normbody']['href']) ? addslashes($data['ad_normbody']['href']) : '/';
if ($data['normbody']['style'] == 'htmlcode') {
$data['normbody'] = addslashes($data['normbody']['htmlcode']);
} else if ($data['normbody']['style'] == 'text') {
$style = "style=\"";
if (!empty($data['normbody']['size'])) {
$style .= "font-size:{$data['normbody']['size']};";
}
if (!empty($data['normbody']['color'])) {
$style.= "color:{$data['normbody']['color']};";
}
$style.="\"";
$data['normbody'] = "{$data['normbody']['text']}";
} else if ($data['normbody']['style'] == 'image') {
$style = "style=\"";
if (!empty($data['normbody']['width'])) {
$style .= "width:{$data['normbody']['width']};";
}
if (!empty($data['normbody']['height'])) {
$style.= "height:{$data['normbody']['height']};";
}
$style.="border:0px;\"";
$data['normbody'] = "";
} else {
$data['normbody'] = addslashes($data['normbody']['flash']);
}
if (($timestamp = strtotime($data['starttime'])) === false) {
$data['starttime'] = time();
} else {
$data['starttime'] = $timestamp;
}
if (($timestamp = strtotime($data['endtime'])) === false) {
$data['endtime'] = time();
} else {
$data['endtime'] = $timestamp;
}
$set = array(
'typeid' => $data['typeid'],
'name' => $data['name'],
'sort' => intval($data['sort']),
'tags' => trim($data['tags']),
'timeset' => $data['timeset'],
'starttime' => $data['starttime'],
'endtime' => $data['endtime'],
'normbody' => $data['normbody'],
'expbody' => $data['expbody'],
'siteid' => $this->siteid,
'country_code' => $this->country_code
);
$model = model('ad')->insertRow($set);
if ($model && $model->getData('id')) {
$this->cacheClear('adTag');
return $this->redirect(url('/admin/ad/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function edit($id = 0) {
$id = intval($id);
if ($id > 0) {
$ad = model('ad')->getRow($id);
if (empty($ad)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['ad'] = $ad;
} else {
return $this->error(Lang::get('incorrect operation'));
}
$typeid = isset($ad['typeid']) ? $ad['typeid'] : 0;
$arg_where = array('pid' => 0, 'stat' => 0, 'country_code' => $this->country_code);
$arg_order = array('id' => 'desc');
$arg_field = array('id', 'pid', 'name');
$typeOption = model('ad_type')->getOption($typeid, $arg_where, $arg_order, $arg_field, 100);
$value['typeOption'] = $typeOption;
$value['typeid'] = $typeid;
$this->assign($value);
return $this->fetch();
}
public function update() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = ['id' => 'require', 'name' => 'require', 'typeid' => 'number|between:0,2147483647',];
$validatemsg = ['id.require' => 'ID不能为空', 'name.require' => '名称不能为空', 'typeid.between' => '所属上级值无效',];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
if (($timestamp = strtotime($data['starttime'])) === false) {
$data['starttime'] = time();
} else {
$data['starttime'] = $timestamp;
}
if (($timestamp = strtotime($data['endtime'])) === false) {
$data['endtime'] = time();
} else {
$data['endtime'] = $timestamp;
}
$set = array(
'typeid' => $data['typeid'],
'name' => $data['name'],
'sort' => intval($data['sort']),
'tags' => trim($data['tags']),
'timeset' => $data['timeset'],
'starttime' => $data['starttime'],
'endtime' => $data['endtime'],
'normbody' => $data['normbody'],
'expbody' => $data['expbody'],
'id' => $data['id'],
);
$model = model('ad')->updateRow($set);
if ($model && $id = $model->getData('id')) {
$this->cacheClear('adTag');
return $this->redirect(url('/admin/ad/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function preview() {
$id = $this->request->param('id', 0);
$id = intval($id);
if ($this->request->isAjax() && $id > 0) {
$jscode = '';
$showhtml = "