ComController.php
3.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
<?php
namespace App\Http\Controllers\Bside\BCom;
use App\Enums\Common\Code;
use App\Helper\Common;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\User\UserLogic;
use App\Models\Project\Project;
use App\Models\User\ProjectMenu as ProjectMenuModel;
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){
$projectRoleModel = new ProjectRoleModel();
$info = $projectRoleModel->read(['id'=>$this->user['role_id']]);
$info['role_menu'] = trim($info['role_menu'],',');
$this->map = [
'status'=>0,
'is_role'=>0,
'id'=>['in',explode(',',$info['role_menu'])]
];
}else{
$this->map = [
'status'=>0,
];
}
$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);
}
/**
* @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);
}
/**
* @name :登录用户编辑资料/修改密码
* @author :liyuhang
* @method
*/
public function edit_info(){
$this->request->validate([
'password'=>['required'],
'name'=>['required'],
],[
'password.required'=>'密码必须填写',
'name.required'=>'名称必须填写',
]);
$userLogic = new UserLogic();
$this->param['id'] = $this->uid;
$userLogic->edits();
$this->response('编辑成功');
}
/**
* @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');
}
/**
* @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秒 超过时间视为无效授权
];
$common = new Common();
$str = $common->encrypt($data);
$this->response('success',Code::SUCCESS,['str'=>$str]);
}
}