GroupController.php
6.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
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
<?php
/**
* Created by PhpStorm.
* auther: sgj
* Date: 2019/1/5
* Time: 9:34
*/
namespace app\admin\controller;
use app\admin\model\UserModel;
use app\portal\model\GroupModel;
use cmf\controller\AdminBaseController;
/**
* Class GroupController
* @package app\admin\controller
* @adminMenuRoot(
* 'name' => '圈子管理',
* 'action' => 'default',
* 'parent' => '',
* 'display'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => ''
* )
*/
class GroupController extends AdminBaseController
{
protected $GroupModel;
protected $OfficeModel;
public function __construct(GroupModel $GroupModel)
{
parent::__construct();
$this->GroupModel = $GroupModel;
}
/**
*圈子列表
* @adminMenu(
* 'name' => '圈子列表',
* 'parent' => 'default',
* 'display'=> true,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '密码修改',
* 'param' => ''
* )
*/
public function index(){
$group=$this->GroupModel->getAllGroup()->toArray();
//dump($group);
$this->assign('group',$group);
return $this->fetch();
}
/**
*添加圈子
* @adminMenu(
* 'name' => '添加圈子',
* 'parent' => 'default',
* 'display'=> false,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '',
* 'param' => ''
* )
*/
public function groupAdd(){
return $this->fetch();
}
public function groupDel(){
$map['id']=input('id');
$update['delete_time']=time();
$result=$this->GroupModel->where($map)->Update($update);
if ($result){
$this->success('删除成功!');
}else{
$this->error('操作失败!');
}
}
public function groupEdit(){
$id=input('id');
if (empty($id)){
$this->error('缺少相应参数!');
}
$group=$this->GroupModel->getGroup($id);
$User=new \app\user\model\UserModel();
if(!empty($group['owner'])){
$user=$User->getUserBase($group['owner'])->toArray();
$group['owner_name']=$user['user_login'];
}
$this->assign('group',$group);
return $this->fetch();
}
public function groupArticle(){
$group_id=input('id');
$article=$this->GroupModel->getArticleList($group_id);
$this->assign('article',$article);
$this->assign('group_id',$group_id);
return $this->fetch();
}
/**
* 编辑群信息
* @throws \think\Exception
* @throws \think\exception\PDOException
*/
public function editGroupPost(){
$update=input();
unset($update['id']);
$map['id']=input('id');
$result=db('group')->where($map)->update($update);
if ($result){
$this->success('编辑成功');
}
$this->error('编辑失败');
}
/**
* 添加群信息
*/
public function addGroupPost(){
$data=input();
$data['addtime']=time();
if (empty($data['name'])){
$this->error('名称不能为空');
}
$result=db('group')->insert($data);
if ($result){
$this->success('添加成功');
}
$this->error('添加失败');
}
/**
*群内人员信息
*/
public function groupPeople(){
$Group=$this->GroupModel;
$group=$Group->getGroup(input('id'));
$map['g.delete_time']=null;
$map['g.group_id']=input('id');
$list=db('group_user')
->alias('g')
->field('g.id as gid,u.*')
->where($map)
->join('user u','g.user_id=u.id')
->paginate('20');
$page = $list->render();
$this->assign('group', $group);
$this->assign('list', $list);
$this->assign('page', $page);
return $this->fetch();
}
/**
* 拉黑用户
*/
public function banUser(){
$map['id']=input('id');
$result=db('group_user')->where($map)->delete();
if ($result==1){
$this->success('删除用户!');
}else{
$this->error('删除失败!');
}
}
public function groupPeopleAdd(){
$user_id=explode(',',input('user_id'));
foreach ($user_id as $k=>$v){
$insert[$k]['user_id']=$v;
$insert[$k]['group_id']=input('group_id');
$insert[$k]['addtime']=time();
}
db('group_user')->insertAll($insert);
$this->success();
}
public function groupArticleDelete(){
$map['post_id']=input('id');
$map['group_id']=input('group_id');
$result=db('portal_group_post')->where($map)->delete();
if ($result==1){
$this->success('操作成功!');
}else{
$this->error('操作失败!');
}
}
/**
* @return mixed
*/
public function groupInfo(){
$map['g.group_id']=input('id');
$map['g.delete_time']=null;
$list=db('group_text')
->field('g.*,u.user_login,u.avatar')
->alias('g')
->join('user u','g.user_id=u.id')
->where($map)
->paginate('20');
$info=$list->items();
foreach ($info as $k=>$v){
$info[$k]['more']=json_decode($v['more'],true);
}
$page = $list->render();
$this->assign('list', $info);
$this->assign('page', $page);
return $this->fetch();
}
public function commentinfo(){
$map['g.id']=input('id');
$list=db('friend_comment')
->field('g.*,u.user_login,u.avatar')
->alias('g')
->join('user u','g.user_id=u.id')
->where($map)
->paginate('20');
$info=$list->items();
$page = $list->render();
$this->assign('list', $info);
$this->assign('page', $page);
return $this->fetch();
}
public function commentDelete(){
$map['id']=input('');
$result=db('friend_comment')->where($map)->delete();
if ($result==1){
$this->success('删除成功!');
}else{
$this->error('删除失败!');
}
}
}