CooperationController.php
10.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
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
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;
use app\admin\model\ThemeModel;
use app\portal\model\CooperationModel;
use app\portal\model\PortalPostModel;
use cmf\controller\AdminBaseController;
use app\portal\model\PortalTagModel;
use app\portal\service\PostService;
use think\Db;
use think\Request;
use think\Loader;
class CooperationController extends AdminBaseController
{
/**
* 列表
* @adminMenu(
* 'name' => '文章管理',
* 'parent' => 'portal/AdminIndex/default',
* 'display'=> true,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '文章列表',
* 'param' => ''
* )
*/
public function index(Request $request)
{
$where_coo['status'] = 1;
$arr = array();
if($request->param()){
$search = $request->param();
$startTime = empty($search['start_time']) ? 0 : strtotime($search['start_time']);
$endTime = empty($search['end_time']) ? 0 : strtotime($search['end_time']);
if ($startTime && $endTime) {
$arr['start_time'] = $search['start_time'];
$arr['end_time'] = $search['end_time'];
$where_coo['create_time'] = array('between',"$startTime,$endTime");
$this->assign('start_time', $search['start_time']);
$this->assign('end_time', $search['end_time']);
}else{
if($startTime){
$arr['start_time'] = $search['start_time'];
$where_coo['create_time'] = array('egt',$startTime);
$this->assign('start_time', $search['start_time']);
}
if($endTime){
$arr['end_time'] = $search['end_time'];
$where_coo['create_time'] = array('elt',$endTime);
$this->assign('end_time', $search['end_time']);
}
}
if(!empty($search['keyword'])){
$arr['keyword'] = $search['keyword'];
$where_coo['name'] = array('like',"%".$search['keyword']."%");
$this->assign('keyword',$search['keyword']);
}
}
$coo_list = Db::name('Cooperation')->where($where_coo)->order('score desc , create_time desc')
->paginate(10,false,['query'=>$arr]);
$page = $coo_list->render();
// ->select()->toArray();
$this->assign('list',$coo_list);
$this->assign('page',$page);
return $this->fetch();
}
/**
* 添加、修改
* @adminMenu(
* 'name' => '添加文章',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '添加文章',
* 'param' => ''
* )
*/
public function add(Request $request)
{
if($request->post()){
// 添加数据
$data = $request->post();
if($request->Post('id')){
// 修改
$change_add['title'] = $data['title'];
$change_add['pic'] = $data['pic'];
$change_add['score'] = $data['score'];
$change_add['jump'] = $data['jump'];
$change_add['type'] = $data['type'];
$validate = Loader::validate('Cooperation');
if(!$validate->scene('edit')->check($change_add)){
$mes = $validate->getError();
$this->error("$mes");
}
$change_add['id'] = $request->Post('id');
$model = new CooperationModel();
$final = $model->isUpdate(true)->allowField(true)->save($change_add);
}else{
// 添加
$add['title'] = $data['title'];
$add['pic'] = $data['pic'];
$add['score'] = $data['score'];
$add['jump'] = $data['jump'];
$add['type'] = $data['type'];
$validate = Loader::validate('Cooperation');
if(!$validate->scene('add')->check($add)){
$mes = $validate->getError();
$this->error("$mes");
}
$model = new CooperationModel();
$final = $model->save($add);
}
if($final){
$this->success('成功',url('index'));
}else{
$this->error('失败');
}
}else{
$where_find['id'] = $request->param('id');
$list = Db::name('Cooperation')->where($where_find)->find();
$this->assign('list',$list);
return $this->fetch('add');
}
}
// 删除
public function del(Request $request){
$ids = $this->request->post();
$id = $request->param('id');
if($ids){
$add_del['id'] = array('in',$ids['ids']);
}else if($id){
$add_del['id'] = $request->param('id');
}else{
$this->error('删除失败');
}
$add_del['status'] = 9;
$model = new CooperationModel();
$del = $model->isUpdate(true)->allowField(true)->save($add_del);
if($del){
$this->success('删除成功',url('index'));
}else{
$this->error('删除失败');
}
}
// 两分钟视频
public function video(){
if ($this->request->isPost()) {
$data = $this->request->param();
if (!empty($data['file_names']) && !empty($data['file_urls'])) {
$data['post']['more']['files'] = [];
foreach ($data['file_urls'] as $key => $url) {
$fileUrl = cmf_asset_relative_url($url);
$first = str_split($fileUrl,4);
if($first[0] == 'http'){
$add['path'] = $fileUrl;
}else{
$add['path'] = cmf_get_asset_url($fileUrl);
}
$add['update_time'] = time();
$where_change['id'] = 1;
$res = Db::name('Video')->where($where_change)->update($add);
if($res){
$this->success('修改成功',url('Cooperation/video'));
}else{
$this->error('添加失败');
}
}
}else{
$this->error('视频不能为空');
}
}else{
$where_status['status'] = 1;
$video = Db::name('Video')->where($where_status)->find();
$this->assign('video',$video);
return $this->fetch();
}
}
// 网站配置
public function conf(){
$data = $this->request->param();
if($this->request->post()){
if(empty($data['id'])){
$add = $data;
$add['qrshare'] = $this->createQRcode($add['share']);
$add['create_time'] = time();
$add['update_time'] = time();
$res = Db::name('Conf')->insertGetId($add);
}else{
$add = $data;
if(!empty($add['share'])){
$add['qrshare'] = $this->createQRcode($add['share']);
}
$add['update_time'] = time();
$where_save['id'] = $data['id'];
$res = Db::name('Conf')->where($where_save)->update($add);
}
if($res){
$this->success('成功');
}else{
$this->error('失败');
}
}
$where_conf['id'] = 1;
$find_one = Db::name('Conf')->where($where_conf)->find();
$this->assign('list',$find_one);
return $this->fetch();
}
/**
* 生成二维码
* $param url 地址
*/
public function createQRcode($url) {
require VENDOR_PATH.'WxpayAPI/example/phpqrcode/phpqrcode.php';
$QRcode = new \QRcode();
$errorCorrectionLevel = 'L'; //容错级别
$matrixPointSize = 5; //生成图片大小
//生成二维码图片
$data = './upload/';
$flodername = 'qrcode/' . date("Ymd", time());
$png = uniqid() . '.png';
$filename = $data.$flodername . '/' . $png;
if (!file_exists($data.$flodername)) {
mkdir($data.$flodername, 0777, true);
}
$QRcode->png($url, $filename, $errorCorrectionLevel, $matrixPointSize);
return $flodername . '/' . $png;
}
// 推广内容
public function push(){
$data = $this->request->param();
if($this->request->post()){
$add['title'] = $data['title'];
$add['content'] = $data['content'];
$add['update_time'] = time();
if(empty($data['id'])){
$add['create_time'] = time();
$res = Db::name('Push')->insertGetId($add);
}else{
$where_id['id'] = $data['id'];
$res = Db::name('Push')->where($where_id)->update($add);
}
if($res){
$this->success('修改成功');
}else{
$this->error('修改失败');
}
}else{
$where_push['status'] = 1;
$list = Db::name('Push')->where($where_push)->find();
}
$this->assign('list',$list);
return $this->fetch();
}
}