BusinessController.php
8.9 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
<?php
namespace api\portal\controller;
use think\Controller;
use think\Db;
/**
* @title 后台业务
* @description 业务相关接口
*/
class BusinessController extends Controller
{
/**
* @title 新媒体业务
* @description
* @author panhaowen
* @url /portal/business/category
* @method POST
*/
public function category()
{
$data=Db::name('category')->where(['delete_time'=>null,'name'=>['neq','营销发布']])->select()->each(function ($item) {
$item['image'] = cmf_get_image_preview_url($item['image']);
return $item;
});
// unset($data[1]);
$this->success('获取信息成功',$data);
}
/**
* @title 添加新媒体业务
* @description
* @author panhaowen
* @url /portal/business/categoryAdd
* @method POST
* @param name:name type:varchar require:1 desc:业务名称
* @param name:image type:varchar require:1 desc:业务图片
*/
public function categoryAdd()
{
$param=$this->request->param();
$param['create_time']=time();
$re=Db::name('category')->insert($param);
if ($re){
$this->success('操作成功');
}else{
$this->error('操作失败');
}
}
/**
* @title 编辑新媒体业务
* @description
* @author panhaowen
* @url /portal/business/categoryEdit
* @method POST
* @param name:id type:int require:1 desc:业务id
*/
public function categoryEdit()
{
$param=$this->request->param();
$data=Db::name('category')->where('id',$param['id'])->find();
$data['image'] = cmf_get_image_preview_url($data['image']);
$this->success('获取信息成功',$data);
}
/**
* @title 编辑新媒体业务提交
* @description
* @author panhaowen
* @url /portal/business/categoryEditPost
* @method POST
* @param name:id type:int require:1 desc:业务id
* @param name:name type:varchar require:1 desc:业务名称
* @param name:image type:varchar require:1 desc:业务图片
*/
public function categoryEditPost()
{
$param=$this->request->param();
$re=Db::name('category')->where('id',$param['id'])->update($param);
if ($re){
$this->success('操作成功');
}else{
$this->error('操作失败');
}
}
/**
* @title 删除新媒体业务
* @description
* @author panhaowen
* @url /portal/business/categoryDelete
* @method POST
* @param name:id type:int require:1 desc:业务id
*/
public function categoryDelete()
{
$param=$this->request->param();
$re=Db::name('category')->where('id',$param['id'])->update(['delete_time'=>time()]);
if ($re){
$this->success('操作成功');
}else{
$this->error('操作失败');
}
}
/**
* @title 具体业务
* @description
* @author panhaowen
* @url /portal/business/business
* @method POST
* @param name:category_id type:int require:1 desc:父级分类id
*/
public function business()
{
$param=$this->request->param();
$data=Db::name('business')->where('category_id',$param['category_id'])->select()->each(function ($item) {
switch ($item['type'])
{
case 1:$item['type']='阅读类';break;
case 2:$item['type']='评论留言类';break;
case 3:$item['type']='内容直发类';break;
}
return $item;
});
$this->success('获取信息成功',$data);
}
/**
* @title 添加具体业务
* @description
* @author panhaowen
* @url /portal/business/businessAdd
* @method POST
* @param name:name type:varchar require:1 desc:业务名称
* @param name:category_id type:int require:1 desc:父级分类id
* @param name:type type:int require:1 desc:业务类型。1:阅读类,2:评论留言类,3:内容直发类
* @param name:price type:int require:1 desc:普通价
* @param name:vip_price type:int require:1 desc:vip价格
* @param name:max type:int require:1 desc:最大购买数
* @param name:min type:int require:1 desc:最小购买数
* @param name:content type:varchar require:1 desc:下单说明
*/
public function businessAdd()
{
$param=$this->request->param();
$param['create_time']=time();
$re=Db::name('business')->insert($param);
if ($re){
$this->success('操作成功');
}else{
$this->error('操作失败');
}
}
/**
* @title 编辑具体业务
* @description
* @author panhaowen
* @url /portal/business/businessEdit
* @method POST
* @param name:id type:int require:1 desc:具体业务id
*/
public function businessEdit()
{
$param=$this->request->param();
$data=Db::name('business')->where('id',$param['id'])->find();
switch ($data['type'])
{
case 1:$data['type']='阅读类';break;
case 2:$data['type']='评论留言类';break;
case 3:$data['type']='内容直发类';break;
}
$this->success('获取信息成功',$data);
}
/**
* @title 编辑具体业务提交
* @description
* @author panhaowen
* @url /portal/business/businessEditPost
* @method POST
* @param name:id type:int require:1 desc:业务id
* @param name:name type:varchar require:1 desc:业务名称
* @param name:type type:int require:1 desc:业务类型。1:阅读类,2:评论留言类,3:内容直发类
* @param name:price type:int require:1 desc:普通价
* @param name:vip_price type:int require:1 desc:vip价格
* @param name:max type:int require:1 desc:最大购买数
* @param name:min type:int require:1 desc:最小购买数
* @param name:content type:varchar require:1 desc:下单说明
*/
public function businessEditPost()
{
$param=$this->request->param();
$re=Db::name('business')->where('id',$param['id'])->update($param);
if ($re){
$this->success('操作成功');
}else{
$this->error('操作失败');
}
}
/**
* @title 删除新媒体业务
* @description
* @author panhaowen
* @url /portal/business/businessDelete
* @method POST
* @param name:id type:int require:1 desc:具体业务id
*/
public function businessDelete()
{
$param=$this->request->param();
$re=Db::name('business')->where('id',$param['id'])->delete();
if ($re){
$this->success('操作成功');
}else{
$this->error('操作失败');
}
}
/**
* @title 图片上传接口
* @description
* @author panhaowen
* @url /portal/business/postImage
* @method POST
* @param name:file type:string require:1 desc:图片资源文件
*/
public function postImage()
{
$file = $this->request->file('file');
// 移动到框架应用根目录/public/upload/ 目录下
$info = $file->validate([
/*'size' => 15678,*/
'ext' => 'jpg,png,gif,jpeg'
]);
$fileMd5 = $info->md5();
$fileSha1 = $info->sha1();
$findFile = Db::name("asset")->where('file_md5', $fileMd5)->where('file_sha1', $fileSha1)->find();
if (!empty($findFile)) {
$this->success("上传成功!", ['url' => cmf_get_asset_url($findFile['file_path']), 'filename' => $findFile['filename']]);
}
$info = $info->move(ROOT_PATH . 'public' . DS . 'upload');
if ($info) {
$saveName = $info->getSaveName();
$originalName = $info->getInfo('name');//name,type,size
$fileSize = $info->getInfo('size');
$suffix = $info->getExtension();
$fileKey = $fileMd5 . md5($fileSha1);
$userId = $this->getUser()['user_id'];
Db::name('asset')->insert([
'user_id' => $userId,
'file_key' => $fileKey,
'filename' => $originalName,
'file_size' => $fileSize,
'file_path' => cmf_get_asset_url($saveName),
'file_md5' => $fileMd5,
'file_sha1' => $fileSha1,
'create_time' => time(),
'suffix' => $suffix
]);
// $storage = cmf_get_option('storage');
// if (isset($storage['type'])&&$storage['type']=='Qiniu') {
// $this->uploadToQiniu($saveName);
// }
$this->success("上传成功!", ['url' => cmf_get_asset_url($saveName), 'filename' => $originalName]);
} else {
// 上传失败获取错误信息
$this->error($file->getError());
}
}
}