TypeController.php
1.8 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
<?php
/**
* Created by PhpStorm.
* User: yhbr
* Date: 2018/8/29
* Time: 9:36
*/
namespace app\admin\controller;
use cmf\controller\AdminBaseController;
use think\Db;
class TypeController extends AdminBaseController {
public function index() {
$res=Db::name('type')->order('listorder')->paginate(20);
return $this->fetch('index', [
'type' => $res,
'page' => $res->render()
]);
}
public function add() {
$request=request();
if($request->isPost()) {
$post=$request->param();
if(!empty($post['type_icon'])) {
$post['type_icon'] = cmf_get_image_url($post['type_icon']);
}
if(Db::name('type')->insert($post)) {
$this->success('添加成功');
}else {
$this->error('添加失败');
}
}else {
return $this->fetch();
}
}
public function edit() {
$request=request();
if($request->isPost()) {
$post=$request->param();
if(!empty($post['type_icon'])) {
$post['type_icon'] = cmf_get_image_url($post['type_icon']);
}
if(Db::name('type')->update($post)) {
$this->success('编辑成功');
}else {
$this->error('您未作出任何修改');
}
}else {
return $this->fetch('edit', [
'info' => Db::name('type')->where(['id'=>$request->param('id')])->find()
]);
}
}
public function del() {
}
public function listOrder() {
$request=request();
if($request->isAjax()) {
Db::name('type')->update($request->param());
}
}
}