|
<?php
namespace app\admin\controller;
use think\Request;
use app\admin\model\Carousel as CarouselModel;
/**
* 轮播图管理
* @author huwhis@163.com
* @version 0.0.1
*/
class Carousel extends Base
{
protected $model;
public function __construct(Request $request = null)
{
parent::__construct($request);
$this->model = new CarouselModel();
}
public function index()
{
$data = $this->model->paginate();
$this->assign('data', $data);
return $this->fetch();
}
public function save(Request $request = null, $id = 0)
{
if ($request->isPost()) {
$param = $request->param();
if ($param['picture'] == '') {
$this->error("图片地址不能为空");
}
try {
if ($param['id'] != 0) {
$this->model->save([
'picture' => $param['picture'],
'url' => $param['url'],
'title' => $param['title'],
'summary' => $param['summary'],
'thumb' => $param['thumb']
], ['id' => $param['id']]);
} else {
$this->model->save([
'picture' => $param['picture'],
'title' => $param['title'],
'summary' => $param['summary'],
'thumb' => $param['thumb'],
'url' => $param['url']
]);
}
} catch (\Exception $e) {
$msg = $e->getMessage();
$this->error("错误提示:" . $msg);
}
$this->success('操作成功', 'admin/carousel/index');
} else {
if ($id) {
$data = $this->model->find($id);
} else {
$data = [
'id' => 0,
'picture' => '',
'url' => '',
'title' => '',
'summary' => '',
'thumb' => ''
];
}
$this->assign('data', $data);
return $this->fetch();
}
}
public function uploadimg()
{
return $this->fetch();
}
public function delete($id = null)
{
if (Request::instance()->isAjax()) {
if ($this->model->destroy($id)) {
return ['code' => 2, 'msg' => "删除成功"];
} else {
return ['code' => 0, 'msg' => "删除失败"];
}
}
}
}
|