327 lines
13 KiB
PHP
Executable File
327 lines
13 KiB
PHP
Executable File
<?php
|
|
|
|
namespace app\admin\controller;
|
|
|
|
use think\Lang;
|
|
use think\Loader;
|
|
use think\Config;
|
|
|
|
class Banner extends BaseController {
|
|
|
|
public function index() {
|
|
$this->redirect('/admin/banner/lists');
|
|
}
|
|
|
|
public function lists() {
|
|
$skeyword = $this->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('banner')->getBannerLists($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('banner_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);
|
|
}
|
|
$data['sort'] = intval($data['sort']);
|
|
$data['alt'] = $data['alt'];
|
|
$data['videourl'] = empty($data['videourl']) ? '' : $data['videourl'];
|
|
$data['descolor'] = empty($data['descolor']) ? $data['alt'] : $data['descolor'];
|
|
$data['btncolor'] = empty($data['btncolor']) ? $data['alt'] : $data['btncolor'];
|
|
$data['style'] = empty($data['style']) ? 1 : $data['style'];
|
|
$data['siteid'] = $this->siteid;
|
|
$data['country_code'] = $this->country_code;
|
|
$model = model('banner')->insertRow($data);
|
|
if ($model && $model->getData('id')) {
|
|
return $this->redirect(url('/admin/banner/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) {
|
|
$banner = model('banner')->getRow($id);
|
|
if (empty($banner)) {
|
|
return $this->error(Lang::get('incorrect operation'));
|
|
}
|
|
$value['banner'] = $banner;
|
|
} else {
|
|
return $this->error(Lang::get('incorrect operation'));
|
|
}
|
|
$typeid = isset($banner['typeid']) ? $banner['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');
|
|
// tiaoshi($banner);die;
|
|
$typeOption = model('banner_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 = ['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);
|
|
}
|
|
$data['videourl'] = empty($data['videourl']) ? '' : $data['videourl'];
|
|
$data['sort'] = intval($data['sort']);
|
|
$data['descolor'] = empty($data['descolor']) ? $data['alt'] : $data['descolor'];
|
|
$data['btncolor'] = empty($data['btncolor']) ? $data['alt'] : $data['btncolor'];
|
|
$data['style'] = empty($data['style']) ? 1 : $data['style'];
|
|
$model = model('banner')->updateRow($data);
|
|
if ($model && $model->getData('id')) {
|
|
return $this->redirect(url('/admin/banner/lists'));
|
|
} else {
|
|
return $this->error(Lang::get('operation failed'));
|
|
}
|
|
}
|
|
return $this->error(Lang::get('incorrect operation'));
|
|
}
|
|
|
|
public function togglerecommend() {
|
|
$id = $this->request->get('id', 0);
|
|
$flag = $this->request->get('flag', 0);
|
|
$id = intval($id);
|
|
if ($this->request->isGet() && $id) {
|
|
$model = model('banner')->updateRow(['id' => $id, 'recommend' => $flag]);
|
|
if ($model && $model->getData('id')) {
|
|
return $this->success(Lang::get('operation successed'), url('/admin/banner/lists'));
|
|
} else {
|
|
return $this->error(Lang::get('operation failed'));
|
|
}
|
|
}
|
|
return $this->error(Lang::get('incorrect operation'));
|
|
}
|
|
|
|
public function updatesort() {
|
|
$id = $this->request->param('id', 0);
|
|
$sort = $this->request->param('sort', 0);
|
|
$sort = intval($sort);
|
|
$id = intval($id);
|
|
if ($this->request->isAjax() && $id) {
|
|
$model = model('banner')->updateRow(['id' => $id, 'sort' => $sort]);
|
|
if ($model && $model->getData('id')) {
|
|
return $this->success(Lang::get('operation successed'), url('/admin/banner/lists'));
|
|
} else {
|
|
return $this->error(Lang::get('operation failed'));
|
|
}
|
|
}
|
|
return $this->error(Lang::get('incorrect operation'));
|
|
}
|
|
|
|
public function delete($id = 0) {
|
|
$id = intval($id);
|
|
if ($id > 0) {
|
|
$model = model('banner')->deleteRow($id);
|
|
if ($model && $model->getData('id')) {
|
|
return $this->success(Lang::get('operation successed'), url('/admin/banner/lists'));
|
|
} else {
|
|
return $this->error(Lang::get('operation failed'));
|
|
}
|
|
}
|
|
return $this->error(Lang::get('incorrect operation'));
|
|
}
|
|
|
|
public function deletes() {
|
|
if ($this->request->isPost()) {
|
|
$ids = $this->request->post('ids');
|
|
$in_ids = explode(',', trim($ids, ','));
|
|
|
|
$result = model('banner')->deleteRows($in_ids);
|
|
if ($result) {
|
|
return $this->success(Lang::get('operation successed'), url('/admin/banner/lists'));
|
|
} else {
|
|
return $this->error(Lang::get('operation failed'));
|
|
}
|
|
}
|
|
return $this->error(Lang::get('incorrect operation'));
|
|
}
|
|
|
|
public function recommends() {
|
|
$ids = $this->request->post('ids');
|
|
$in_ids = explode(',', trim($ids, ','));
|
|
if ($this->request->isPost() && $in_ids) {
|
|
$result = model('banner')->updateRow(['recommend' => 1], ['id' => ['in', $in_ids]]);
|
|
if ($result) {
|
|
return $this->success(Lang::get('operation successed'), url('/admin/banner/lists'));
|
|
} else {
|
|
return $this->error(Lang::get('operation failed'));
|
|
}
|
|
}
|
|
return $this->error(Lang::get('incorrect operation'));
|
|
}
|
|
|
|
//类别
|
|
public function typelists() {
|
|
$skeyword = $this->request->get('skeyword', '', 'urldecode');
|
|
$arg_where = array('pid' => 0, 'stat' => 0, 'siteid' => $this->siteid, 'country_code' => $this->country_code);
|
|
$arg_order = array('id' => 'desc');
|
|
$arg_field = array('id', 'name', 'description', 'createtime');
|
|
if (!empty($skeyword)) {
|
|
$skeyword = trim($skeyword);
|
|
$arg_where['name'] = ['like', '%' . $skeyword . '%'];
|
|
$search['skeyword'] = $skeyword;
|
|
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
|
|
} else {
|
|
$search['skeyword'] = '';
|
|
}
|
|
$dataObject = model('banner_type')->getPageList($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 typeedit($id = 0) {
|
|
$id = intval($id);
|
|
if ($id > 0) {
|
|
$bannertype = model('banner_type')->getRow($id);
|
|
if (empty($bannertype)) {
|
|
return $this->error(Lang::get('incorrect operation'));
|
|
}
|
|
$value['bannertype'] = $bannertype;
|
|
} else {
|
|
return $this->error(Lang::get('incorrect operation'));
|
|
}
|
|
$this->assign($value);
|
|
return $this->fetch();
|
|
}
|
|
|
|
public function typeupdate() {
|
|
if ($this->request->isPost()) {
|
|
$data = $this->request->post();
|
|
if (empty($data) || !is_array($data)) {
|
|
return $this->error(Lang::get('incorrect operation'));
|
|
}
|
|
$validaterule = ['name' => 'require'];
|
|
$validatemsg = ['name.require' => '名称不能为空'];
|
|
$valid_result = $this->validate($data, $validaterule, $validatemsg);
|
|
if (true !== $valid_result) {
|
|
// 验证失败 输出错误信息
|
|
return $this->error($valid_result);
|
|
}
|
|
$model = model('banner_type')->updateRow($data);
|
|
if ($model && $model->getData('id')) {
|
|
return $this->redirect(url('/admin/banner/typelists'));
|
|
} else {
|
|
return $this->error(Lang::get('operation failed'));
|
|
}
|
|
}
|
|
return $this->error(Lang::get('incorrect operation'));
|
|
}
|
|
|
|
public function typeadd() {
|
|
return $this->fetch();
|
|
}
|
|
|
|
public function typecreate() {
|
|
if ($this->request->isPost()) {
|
|
$data = $this->request->post();
|
|
if (empty($data) || !is_array($data)) {
|
|
return $this->error(Lang::get('incorrect operation'));
|
|
}
|
|
$validaterule = ['name' => 'require'];
|
|
$validatemsg = ['name.require' => '名称不能为空'];
|
|
$valid_result = $this->validate($data, $validaterule, $validatemsg);
|
|
if (true !== $valid_result) {
|
|
// 验证失败 输出错误信息
|
|
return $this->error($valid_result);
|
|
}
|
|
$data['siteid'] = $this->siteid;
|
|
$data['country_code'] = $this->country_code;
|
|
$model = model('banner_type')->insertRow($data);
|
|
if ($model && $model->getData('id')) {
|
|
return $this->redirect(url('/admin/banner/typelists'));
|
|
} else {
|
|
return $this->error(Lang::get('operation failed'));
|
|
}
|
|
}
|
|
return $this->error(Lang::get('incorrect operation'));
|
|
}
|
|
|
|
public function typedelete($id = 0) {
|
|
$id = intval($id);
|
|
if ($id > 0) {
|
|
$result = model('banner_type')->deleteRow($id);
|
|
if ($result) {
|
|
return $this->success(Lang::get('operation successed'), url('/admin/banner/typelists'));
|
|
} else {
|
|
return $this->error(Lang::get('operation failed'));
|
|
}
|
|
}
|
|
return $this->error(Lang::get('incorrect operation'));
|
|
}
|
|
|
|
public function typedeletes() {
|
|
$ids = $this->request->post('ids');
|
|
if ($this->request->isPost() && $ids) {
|
|
$result = model('banner_type')->deleteRows($ids);
|
|
|
|
if ($result) {
|
|
return $this->success(Lang::get('operation successed'), url('/admin/banner/typelists'));
|
|
} else {
|
|
return $this->error(Lang::get('operation failed'));
|
|
}
|
|
}
|
|
return $this->error(Lang::get('incorrect operation'));
|
|
}
|
|
|
|
}
|