ComController.php
10.2 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
<?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\Http\Logic\Bside\User\UserLogic;
use App\Jobs\PurchaserJob;
use App\Models\Com\Purchaser;
use App\Models\CustomModule\CustomModule;
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\ProjectRole as ProjectRoleModel;
use App\Models\User\User;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Hash;
/***
* 当前为公共类
*/
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 $k => $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'].','),',');
}
$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;
}
if(!empty($data)){
$this->map['id'] = ['not in',$data];
}
return $this->map;
}
/**
* @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;
}
/**
* @name :登录用户编辑资料/修改密码
* @author :liyuhang
* @method
*/
public function edit_info(){
$this->request->validate([
// 'oldPassword'=>'required',
'password' => 'required',
'confirm'=>'required',
], [
// 'oldPassword.required' => '请输入原密码',
'password.required' => '请输入新密码',
'confirm.required' => '请再次输入新密码',
]);
//查询员密码是否正确
$userModel = new User();
$info = $userModel->read(['id'=>$this->user['id']]);
// if($info['password'] != base64_encode(md5($this->param['oldPassword']))){
// $this->response('原密码错误',Code::USER_ERROR);
// }
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();
$list = $userModel->list(['mobile'=>$this->user['mobile'],'project_id'=>['!=',$this->user['project_id']]],'id',['id','project_id']);
if(!empty($list)){
$projectModel = new Project();
foreach ($list as $k => $v){
$projectInfo = $projectModel->read(['id'=>$v['project_id']],['id','company']);
//获取当前项目详情
$data[] = ['project_id'=>$projectInfo['id'],'company'=>$projectInfo['company']];
}
}
//登录选择项目的有效时间
Cache::add('login-project-'.$this->user['mobile'],1,300);
$this->response('success',Code::SUCCESS,$data);
}
}