2020-01-01 13:17:19 +08:00
|
|
|
<?php
|
|
|
|
namespace app\admin\controller;
|
|
|
|
|
|
|
|
use app\common\controller\AdminController;
|
|
|
|
use think\facade\View;
|
|
|
|
use think\facade\Db;
|
|
|
|
use think\facade\Request;
|
2021-07-22 10:43:48 +08:00
|
|
|
use app\common\model\Slider as SliderModel;
|
2020-01-01 13:17:19 +08:00
|
|
|
|
|
|
|
class Slider extends AdminController
|
|
|
|
{
|
|
|
|
/**
|
2021-07-15 19:10:33 +08:00
|
|
|
* @return string
|
|
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
|
|
* @throws \think\db\exception\DbException
|
|
|
|
* @throws \think\db\exception\ModelNotFoundException
|
2020-01-01 13:17:19 +08:00
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
2022-08-02 20:39:46 +08:00
|
|
|
return View::fetch();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 链接列表
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function list()
|
|
|
|
{
|
|
|
|
$list = [];
|
|
|
|
$type = input('slid_type');
|
|
|
|
$limit = input('limit');
|
|
|
|
$page = input('page');
|
|
|
|
if($type) {
|
|
|
|
$datas = SliderModel::where('slid_type',$type)->where('')->paginate([
|
|
|
|
'list_rows'=> $limit,
|
|
|
|
'page'=>$page
|
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
$datas = SliderModel::paginate([
|
|
|
|
'list_rows'=> $limit,
|
|
|
|
'page'=>$page
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(count($datas)) {
|
|
|
|
$list = ['code'=>0,'msg'=>'获取数据成功'];
|
|
|
|
foreach($datas as $k=>$v) {
|
|
|
|
$list['data'][] = [
|
|
|
|
'id'=>$v['id'],
|
|
|
|
'slid_name'=>$v['slid_name'],
|
|
|
|
'slid_img' =>$v['slid_img'],
|
|
|
|
'slid_type'=>$v['slid_type'],
|
|
|
|
'slid_href'=>$v['slid_href'],
|
|
|
|
'slid_color'=>$v['slid_color'],
|
|
|
|
'slid_start'=> time() < $v['slid_start'] ? '<span style="color:#1c97f5;">未开始</span>' : date('Y-m-d H:i',$v['slid_start']),
|
|
|
|
'slid_over'=> time() > $v['slid_over'] ? '<span style="color:#F00;">已结束</span>' : date('Y-m-d H:i',$v['slid_over']),
|
|
|
|
'slid_status'=> $v['slid_status'] ? '正常' : '禁止'
|
|
|
|
];
|
|
|
|
}
|
|
|
|
return json($list);
|
|
|
|
} else {
|
|
|
|
return json(['code'=>-1,'msg'=>'还没有数据']);
|
|
|
|
}
|
2020-01-01 13:17:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 显示创建资源表单页.
|
|
|
|
*
|
|
|
|
* @return \think\Response
|
|
|
|
*/
|
|
|
|
public function add()
|
|
|
|
{
|
|
|
|
//添加幻灯
|
|
|
|
if(Request::isAjax()){
|
|
|
|
$data = Request::param();
|
|
|
|
$data['slid_start'] = strtotime($data['slid_start']);
|
|
|
|
$data['slid_over'] = strtotime($data['slid_over']);
|
2022-08-02 20:39:46 +08:00
|
|
|
$slid = new SliderModel();
|
|
|
|
$result = $slid->add($data);
|
|
|
|
if($result == 1){
|
2021-06-10 13:39:51 +08:00
|
|
|
$res = ['code'=>0,'msg'=>'添加成功'];
|
2020-01-01 13:17:19 +08:00
|
|
|
}else{
|
2021-06-10 13:39:51 +08:00
|
|
|
$res = ['code'=>-1,'msg'=>'添加失败'];
|
2020-01-01 13:17:19 +08:00
|
|
|
}
|
2022-08-02 20:39:46 +08:00
|
|
|
return json($res);
|
2020-01-01 13:17:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return View::fetch();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-07-15 19:10:33 +08:00
|
|
|
* @param $id
|
|
|
|
* @return string|\think\response\Json
|
|
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
|
|
* @throws \think\db\exception\DbException
|
|
|
|
* @throws \think\db\exception\ModelNotFoundException
|
2020-01-01 13:17:19 +08:00
|
|
|
*/
|
2022-08-02 20:39:46 +08:00
|
|
|
public function edit()
|
2020-01-01 13:17:19 +08:00
|
|
|
{
|
2022-08-02 20:39:46 +08:00
|
|
|
$id = (int)input('id');
|
|
|
|
$slider = Db::name('slider')->find($id);
|
2020-01-01 13:17:19 +08:00
|
|
|
|
2022-08-02 20:39:46 +08:00
|
|
|
if(Request::isAjax()){
|
|
|
|
$data = Request::param();
|
|
|
|
$data['slid_start'] = strtotime($data['slid_start']);
|
|
|
|
$data['slid_over'] = strtotime($data['slid_over']);
|
|
|
|
$slid = new SliderModel();
|
|
|
|
$result = $slid->edit($data);
|
|
|
|
if($result == 1){
|
|
|
|
$res = ['code'=>0,'msg'=>'编辑成功'];
|
|
|
|
}else{
|
|
|
|
$res = ['code'=>-1,'msg'=>'编辑失败'];
|
|
|
|
}
|
|
|
|
return json($res);
|
2020-01-01 13:17:19 +08:00
|
|
|
}
|
|
|
|
View::assign('slider',$slider);
|
|
|
|
|
|
|
|
return View::fetch();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-07-15 19:10:33 +08:00
|
|
|
* @return \think\response\Json
|
2020-01-01 13:17:19 +08:00
|
|
|
*/
|
|
|
|
public function uploadImg()
|
|
|
|
{
|
2022-08-02 20:39:46 +08:00
|
|
|
$uploads = new \app\common\lib\Uploads();
|
|
|
|
$upRes = $uploads->put('file','slider',1024,'image');
|
|
|
|
$slires = $upRes->getData();
|
2021-07-15 19:10:33 +08:00
|
|
|
|
2022-08-02 20:39:46 +08:00
|
|
|
if($slires['status'] == 0){
|
2021-07-15 19:10:33 +08:00
|
|
|
$name_path = $slires['url'];
|
2020-01-01 13:17:19 +08:00
|
|
|
$res = ['code'=>0,'msg'=>'上传flash成功','src'=>$name_path];
|
|
|
|
} else {
|
|
|
|
$res = ['code'=>1,'msg'=>'上传错误'];
|
|
|
|
}
|
|
|
|
return json($res);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-07-15 19:10:33 +08:00
|
|
|
* @param $id
|
|
|
|
* @return \think\response\Json
|
|
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
|
|
* @throws \think\db\exception\DbException
|
|
|
|
* @throws \think\db\exception\ModelNotFoundException
|
2020-01-01 13:17:19 +08:00
|
|
|
*/
|
|
|
|
public function delete($id)
|
|
|
|
{
|
2022-08-02 20:39:46 +08:00
|
|
|
$slider = SliderModel::find($id);
|
|
|
|
$res = $slider->delete();
|
|
|
|
if($res){
|
|
|
|
return json(['code'=>0,'msg'=>'删除成功']);
|
|
|
|
} else {
|
|
|
|
return json(['code'=>-1,'msg'=>'删除失败']);
|
|
|
|
}
|
2020-01-01 13:17:19 +08:00
|
|
|
}
|
|
|
|
}
|