AdminImageController.php
3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 小夏 < 449134904@qq.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;
use cmf\controller\AdminBaseController;
use app\portal\model\ImageModel;
use think\Db;
//封面图片管理
class AdminImageController extends AdminBaseController
{
//首页
public function index(){
$type = $this->request->param('type');
$imageModel = new ImageModel();
if(!empty($type) && isset($type)){
$image = $imageModel->where('type',$type)->order('weigh desc')->select();
}else{
$image = $imageModel->order('weigh desc')->select();
}
$this->assign('image', $image);
//封面图分类
$list = $this->getImgCategory();
$this->assign('list',$list);
$this->assign('type',$type);
return $this->fetch();
}
//添加页面
public function add(){
//封面图分类
$list = $this->getImgCategory();
$this->assign('list',$list);
return $this->fetch();
}
//自定义封面图分类
private function getImgCategory(){
$imgCategory = [
['id'=>1,'name'=>'首页'],
['id'=>2,'name'=>'星球画廊'],
['id'=>3,'name'=>'星享体验'],
['id'=>4,'name'=>'星探推荐'],
['id'=>5,'name'=>'星际活动']
];
return $imgCategory;
}
//提交保存
public function addPost(){
$data = $this->request->param();
$imageModel = new ImageModel();
$result = $this->validate($data, 'AdminImage');
if ($result !== true) {
$this->error($result);
}
$imageModel->allowField(true)->save($data);
$this->success("添加成功!", url("AdminImage/index"));
}
//编辑页面
public function edit(){
$id = $this->request->param('id', 0, 'intval');
$imageModel = new ImageModel();
$image = $imageModel->get($id);
//封面图分类
$list = $this->getImgCategory();
$this->assign('list',$list);
$this->assign('image', $image);
return $this->fetch();
}
//编辑保存页面
public function editPost()
{
$data = $this->request->param();
$imageModel = new ImageModel();
$result = $this->validate($data, 'AdminImage');
if ($result !== true) {
$this->error($result);
}
$imageModel->allowField(true)->isUpdate(true)->save($data);
$this->success("保存成功!", url("AdminImage/index"));
}
//删除
public function delete(){
$id = $this->request->param('id', 0, 'intval');
$imageModel = new ImageModel();
$imageModel->where('id',$id)->delete();
$this->success("删除成功!", url("AdminImage/index"));
}
}