ComController.php
14.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
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
<?php
namespace App\Http\Controllers\Bside\BCom;
use App\Enums\Common\Code;
use App\Helper\Arr;
use App\Helper\Common;
use App\Http\Controllers\Bside\BaseController;
use App\Jobs\PurchaserJob;
use App\Models\CustomModule\CustomModule;
use App\Models\OaNotice\OaNotice;
use App\Models\Project\DeployBuild;
use App\Models\Project\Project;
use App\Models\RouteMap\RouteMap;
use App\Models\User\ProjectMenu as ProjectMenuModel;
use App\Models\User\ProjectMenuSeo;
use App\Models\User\ProjectRole as ProjectRoleModel;
use App\Models\User\User;
use Illuminate\Support\Facades\Cache;
/***
* 当前为公共类
*/
class ComController extends BaseController
{
/**
* @name :获取当前用户权限菜单列表
* @author :liyuhang
* @method
*/
public function get_menu(){
//根据当前登录用户角色返回用户菜单列表
$projectMenuModel = new ProjectMenuModel();
if($this->user['role_id'] != 0){
$this->map = $this->getNoAdminMenuCondition();
}else{
$this->map = $this->getAdminMenuCondition();
}
$lists = $projectMenuModel->list($this->map,'sort');
$menu = array();
foreach ($lists as $v){
$v = (array)$v;
if ($v['pid'] == 0) {
$v['sub'] = _get_child($v['id'], $lists);
$menu[] = $v;
}
}
$this->response('当前用户菜单列表',Code::SUCCESS,$menu);
}
/**
* @remark :白帽seo获取菜单
* @name :seo_get_menu
* @author :lyh
* @method :post
* @time :2025/3/4 14:48
*/
public function seo_get_menu(){
$seoMenuModel = new ProjectMenuSeo();
$this->map['status'] = 0;
if($this->user['login_source'] == User::LOGIN_PASSWORD_SOURCE){
$this->map['id'] = ['not in',[19]];
}
$lists = $seoMenuModel->list($this->map,'sort');
$menu = array();
foreach ($lists as $v){
$v = (array)$v;
if ($v['pid'] == 0) {
$v['sub'] = _get_child($v['id'], $lists);
$menu[] = $v;
}
}
$this->response('当前用户菜单列表',Code::SUCCESS,$menu);
}
/**
* @remark :获取当前菜单的自定义模块
* @name :getProjectCustomMenu
* @author :lyh
* @method :post
* @time :2023/12/13 16:48
*/
public function getCustomMenu(){
$customModel = new CustomModule();
$list = $customModel->list(['status'=>0],['topping_time','sort','id']);
if(!empty($list)){
foreach ($list as $k=>$v){
$v['sub'] = [$v['name'].'管理',$v['name'].'分类'];
$list[$k] = $v;
}
}
$this->response('success',Code::SUCCESS,$list);
}
/**
* @name :获取当前项目详情
* @author :liyuhang
* @method
*/
public function get_project(Project $projectModel){
$info = $projectModel->read(['id'=>$this->user['project_id']]);
if(empty($info)){
$this->response('error',Code::USER_ERROR);
}
$this->response('success',Code::SUCCESS,$info);
}
/**
* @remark :非超级管理员菜单列表
* @name :getRoleMenuLis
* @author :lyh
* @method :post
* @time :2023/9/6 11:47
*/
public function getNoAdminMenuCondition(){
$projectRoleModel = new ProjectRoleModel();
$info = $projectRoleModel->read(['id'=>$this->user['role_id']]);
if($info === false){
$this->fail('当前登录角色不存在');
}else{
$code = $this->getIsHome();
if($code != 1){
$info['role_menu'] = trim(str_replace(',11,',',',','.$info['role_menu'].','),',');
}
$blogCode = $this->getIsBlog();
if($blogCode != 1){
$info['role_menu'] = trim(str_replace(',16,',',',','.$info['role_menu'].','),',');
$info['role_menu'] = trim(str_replace(',17,',',',','.$info['role_menu'].','),',');
}
$uploadCode = $this->getIsUpload();
if($uploadCode != 1){
$info['role_menu'] = trim(str_replace(',41,',',',','.$info['role_menu'].','),',');
}
$projectCode = $this->getProjectWatermark();
if($projectCode != 1){
$info['role_menu'] = trim(str_replace(',50,',',',','.$info['role_menu'].','),',');
}
$is_subscribe = $this->getIsSubscribe();
if(!$is_subscribe){
$info['role_menu'] = trim(str_replace(',52,',',',','.$info['role_menu'].','),',');
}
$is_comment = $this->getIsComment();
if($is_comment != 1){
$info['role_menu'] = trim(str_replace(',55,',',',','.$info['role_menu'].','),',');
}
$is_blogs = $this->getIsAiBlog();
if($is_blogs != 1){
$info['role_menu'] = trim(str_replace(',57,',',',','.$info['role_menu'].','),',');
}
$is_video = $this->getIsAiVideo();
if($is_video != 1){
$info['role_menu'] = trim(str_replace(',74,',',',','.$info['role_menu'].','),',');
}
$this->map = [
'status'=>0,
'is_role'=>0,
'id'=>['in',explode(',',$info['role_menu'])]
];
}
return $this->map;
}
/**
* @remark :超级管理员菜单列表
* @name :getAdminMenuCondition
* @author :lyh
* @method :post
* @time :2023/9/6 13:53
*/
public function getAdminMenuCondition(){
$data = [];
$this->map['status'] = 0;
$code = $this->getIsHome();//是否开启首页
if($code != 1){
$data[] = 11;
}
$blogCode = $this->getIsBlog();//是否开启blog
if($blogCode != 1){
$data[] = 16;
$data[] = 17;
}
$uploadCode = $this->getIsUpload();//是否开启上传
if($uploadCode != 1){
$data[] = 41;
}
$projectCode = $this->getProjectWatermark();
if($projectCode != 1){
$data[] = 50;
}
$is_subscribe = $this->getIsSubscribe();
if(!$is_subscribe){
$data[] = 52;
}
$is_comment = $this->getIsComment();
if($is_comment != 1){
$data[] = 55;
}
$is_ai_blog = $this->getIsAiBlog();
if($is_ai_blog != 1){
$data[] = 57;
}
$is_ai_video = $this->getIsAiVideo();
if($is_ai_video != 1){
$data[] = 74;
}
if(!empty($data)){
$this->map['id'] = ['not in',$data];
}
return $this->map;
}
/**
* @remark :是否开启水印功能
* @name :getProjectWatermark
* @author :lyh
* @method :post
* @time :2024/8/28 14:47
*/
public function getProjectWatermark(){
$projectModel = new Project();
$info = $projectModel->read(['id'=>$this->user['project_id']],['id','is_watermark']);
return $info['is_watermark'] ?? 0;
}
/**
* @remark :查看是否显示网站装饰
* @name :getIsHome
* @author :lyh
* @method :post
* @time :2023/9/6 11:30
*/
public function getIsHome(){
if(isset($this->user['manager_id'])){
return 1;
}
$deployBuild = new DeployBuild();
$info = $deployBuild->read(['project_id'=>$this->user['project_id']]);
if(!empty($info['configuration'])){
$configuration = Arr::s2a($info['configuration']);
if(isset($configuration['is_home']) && ((int)$configuration['is_home'] != 0)){
return 1;
}
}
return 0;
}
/**
* @remark :是否开启上传配置
* @name :getIsUpload
* @author :lyh
* @method :post
* @time :2023/12/19 17:22
*/
public function getIsUpload(){
if($this->user['is_upload_manage'] != 0){
return 1;
}
return 0;
}
/**
* @remark :是否显示博客
* @name :getIsBlog
* @author :lyh
* @method :post
* @time :2023/12/19 16:44
*/
public function getIsBlog(){
if($this->user['is_show_blog'] != 0){
return 1;//不显示
}
return 0;
}
public function getIsSubscribe(){
return $this->project['is_subscribe'] ?? 0;
}
/**
* @remark :是否开启评论
* @name :getIsComment
* @author :lyh
* @method :post
* @time :2024/9/14 13:32
*/
public function getIsComment(){
return $this->user['is_comment'] ?? 0;
}
/**
* @remark :是否开启了ai——blog
* @name :getIsAiBlog
* @author :lyh
* @method :post
* @time :2025/2/19 9:39
*/
public function getIsAiBlog(){
return $this->user['is_ai_blog'] ?? 0;
}
/**
* @remark :ai视频
* @name :getIsAiVideo
* @author :lyh
* @method :post
* @time :2025/5/6 14:33
*/
public function getIsAiVideo(){
return $this->user['is_ai_video'] ?? 0;
}
/**
* @name :登录用户编辑资料/修改密码
* @author :liyuhang
* @method
*/
public function edit_info(){
$this->request->validate([
'password' => 'required',
'confirm'=>'required',
], [
'password.required' => '请输入新密码',
'confirm.required' => '请再次输入新密码',
]);
//查询员密码是否正确
$userModel = new User();
$info = $userModel->read(['id'=>$this->user['id']]);
if($this->param['password'] != $this->param['confirm']){
$this->response('两次密码不一致');
}
$rs = $userModel->edit(['password'=>base64_encode(md5($this->param['password']))],['id'=>$this->user['id']]);
if($rs === false){
$this->response('系统错误',Code::SYSTEM_ERROR);
}
Cache::pull($info['token']);
$this->response('success');
}
/**
* @remark :退出登录
* @name :logout
* @author :lyh
* @method :post
* @time :2023/8/19 9:14
*/
public function logout(){
$rs = Cache::pull($this->token);
if($rs === false){
$this->response('error',Code::USER_ERROR);
}
$this->response('success');
}
/**
* @remark :微信解绑
* @name :unbindWechat
* @author :lyh
* @method :post
* @time :2023/9/1 16:47
*/
public function unbindWechat(){
$userModel = new User();
$rs = $userModel->edit(['wechat'=>''],['id'=>$this->user['id']]);
if($rs === false){
$this->response('error',Code::USER_ERROR);
}
$this->response('success',Code::SUCCESS,['status'=>0]);
}
/**
* @remark :生成token
* @name :generateToken
* @author :lyh
* @method :post
* @time :2023/8/24 17:27
*/
public function generateToken(){
$data = [
'phone' => $this->user['mobile'],
'from_order_id' => $this->user['from_order_id'] ?? '5a179274si3j8z', // 提单系统 同步到个项目的唯一凭证(数字或者字符串)
'timestamp' => time(), // 接收到字符串解密出来以后需要 验证时间不超过30秒 超过时间视为无效授权
'nickname' => $this->user['name'], // 名称
];
$common = new Common();
$str = $common->encrypt($data);
$this->response('success',Code::SUCCESS,['str'=>$str]);
}
/**
* @remark :获取访问链接
* @name :getLink
* @author :lyh
* @method :post
* @time :2023/11/10 15:18
*/
public function getLink(){
$this->request->validate([
'type' => 'required',
], [
'type.required' => '类型不能为空',
]);
switch ($this->param['type']){
case 'news':
$url_link = $this->user['domain'].RouteMap::SOURCE_NEWS.'/';
break;
case 'blog':
$url_link = $this->user['domain'].RouteMap::SOURCE_BLOG.'/';
break;
default:
$url_link = $this->user['domain'];
}
$this->response('success',Code::SUCCESS,['url'=>$url_link]);
}
/**
* @remark :根据手机号码,获取当前号码拥有的所有项目
* @name :getMobileProject
* @author :lyh
* @method :post
* @time :2024/2/22 9:32
*/
public function getMobileProject(){
$data = [];
$userModel = new User();
$project_id = $userModel->formatQuery(['mobile'=>$this->user['mobile'],'project_id'=>['!=',$this->user['project_id']]])->pluck('project_id')->toArray();
if(!empty($project_id)){
$projectModel = new Project();
$list = $projectModel->list(['id'=>['in',$project_id],'delete_status'=>0],'id',['id','company']);
foreach ($list as $v){
//获取当前项目详情
$data[] = ['project_id'=>$v['id'],'company'=>$v['company']];
}
}
$this->response('success',Code::SUCCESS,$data);
}
/**
* @remark :获取通知信息
* @name :getNoticeInfo
* @author :lyh
* @method :post
* @time :2024/6/20 16:49
*/
public function getNoticeInfo(){
$oaNoticeModel = new OaNotice();
$this->map['start_time'] = ['<=',date('Y-m-d H:i:s')];
$this->map['end_time'] = ['>=',date('Y-m-d H:i:s')];
$this->map['status'] = 0;
$this->map['project_str'] = ['like','%,'.$this->user['project_id'].',%'];
$lists = $oaNoticeModel->formatQuery($this->map)->orWhere('project_str', 'all')->select(['*'])->orderBy($this->order,'desc')->paginate($this->row, ['*'], 'page', $this->page);
$this->response('success',Code::SUCCESS,$lists);
}
/**
* @remark :
* @name :month_count
* @author :lyh
* @method :post
* @time :2024/10/28 11:51
*/
public function month_counts(){
shell_exec('php artisan month_project '.$this->user['project_id']);
$this->response('重新刷新中,请稍后刷新查询');
}
}