GoodController.php
3.0 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
/**
* Created by PhpStorm.
* auther: sgj
* Date: 2020/10/14
* Time: 9:30
*/
namespace app\admin\controller;
use cmf\controller\AdminBaseController;
use think\Controller;
class GoodController extends AdminBaseController
{
/**
* 商品首页
* @return mixed
*/
public function index(){
$param=$this->request->param();
$map=[];
$map['delete_time']=null;
$data= db('goods')->where($map)->order('id desc')->paginate();
$data->appends($param);
$list=$data->items();
$this->assign([
'data'=>$list,
'page'=>$data->render(),
]);
return $this->fetch();
}
/**
* 编辑商品
*/
public function edit(){
$id=input('id');
$data=db('goods')->where('id',$id)->find();
$data['banner']=json_decode($data['banner']);
$data['banner_name']=json_decode($data['banner_name']);
$this->assign('data',$data);
return $this->fetch();
}
/**
* 编辑商品
*/
public function editPost(){
$id=input('id');
$data=input();
$banner=input('banner/a');
$banner_name=input('banner_name/a');
if (empty($banner)){
}else{
unset($data['banner']);
unset($data['banner_name']);
$data['banner']=json_encode($banner,true);
$data['banner_name']=json_encode($banner_name,true);
}
$info=db('goods')->where('id',$id)->update($data);
if (!empty($info)){
$this->success('编辑成功!');
}else{
$this->error('编辑失败!');
}
}
/**
* 添加页面
*/
public function add(){
return $this->fetch();
}
/**
* 添加提交
*/
public function addPost(){
$data=input();
$banner=input('banner/a');
$banner_name=input('banner_name/a');
if (empty($banner)){
}else{
unset($data['banner']);
unset($data['banner_name']);
$data['banner']=json_encode($banner,true);
$data['banner_name']=json_encode($banner_name,true);
}
$info=db('goods')->insert($data);
if (!empty($info)){
$this->success('编辑成功!');
}else{
$this->error('编辑失败!');
}
}
/**
* 删除
* @throws \think\Exception
* @throws \think\exception\PDOException
*/
public function delete(){
$id=input('id');
$update['delete_time']=time();
$result=db('goods')->where('id',$id)->update($update);
if ($result){
$this->success('操作成功!');
}else{
$this->error('操作失败!');
}
}
public function online(){
$id=input('id');
$update['is_online']=input('status');
$result=db('goods')->where('id',$id)->update($update);
if ($result){
$this->success('操作成功!');
}else{
$this->error('操作失败!');
}
}
}