ComController.php
10.4 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
<?php
namespace App\Http\Controllers\Bside;
use App\Enums\Common\Code;
use App\Helper\Common;
use App\Helper\FormGlobalsoApi;
use App\Helper\Translate;
use App\Http\Logic\Bside\User\UserLogic;
use App\Http\Logic\Bside\User\UserLoginLogic;
use App\Models\Manage\EntryPosition;
use App\Models\Manage\JobLevel;
use App\Models\Manage\Manage;
use App\Models\Manage\ManageHr;
use App\Models\Project\Project;
use App\Models\Project\Project as ProjectModel;
use App\Models\Service\Service;
use App\Models\SmsLog;
use App\Models\User\ProjectMenu as ProjectMenuModel;
use App\Models\User\ProjectRole as ProjectRoleModel;
use App\Models\User\User;
use App\Models\User\User as UserModel;
use App\Utils\EncryptUtils;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Route;
use Mrgoon\AliSms\AliSms;
/***
* 当前为公共类 所有方法均不需要验证登录token
*/
class ComController extends BaseController
{
/**
* @name :管理员登录
* @author :liyuhang
* @method
*/
public function login(){
$this->request->validate([
'mobile'=>['required', 'regex:/^1[3-9]\d{9}$/'],
'password'=>['required'],
],[
'mobile.required'=>'电话号码必须填写',
'password.required'=>'内容必须填写',
'mobile.regex' => '请输入正确的手机号码',
]);
$userLogic = new UserLoginLogic();
$res = $userLogic->login();
$this->response('请求成功',Code::SUCCESS,$res);
}
/**
* 根据CODE自动登录
* @author zbj
* @date 2023/7/25
*/
public function autologin(UserLoginLogic $logic, EncryptUtils $encrypt)
{
$serviceSettingModel = new Service();
$info = $serviceSettingModel->read(['type'=>4]);
if($info === false){
$this->response('当前访问地址不存在',Code::USER_ERROR);
}
$data = $encrypt->unlock_url($this->param['code'], $info['values']);
$data = json_decode($data, true);
if(!isset($data['project_id']) && !isset($data['user_id'])){
$this->response('无效Code',Code::USER_ERROR);
}
$res = $logic->autologin($data);
$this->response('请求成功',Code::SUCCESS, $res);
}
/**
* @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'],',');
$lists = $projectMenuModel->where(['status'=>0,'is_role'=>0])->whereIn('id',explode(',',$info['role_menu']))->get();
}else{
$lists = $projectMenuModel->where(['is_role'=>0])->get();
}
$lists = $lists->toArray();
$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(ProjectModel $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->param);
$this->response('编辑成功');
}
/**
* @name :退出登录
* @return void
* @author :liyuhang
* @method :post
*/
public function logout(){
$rs = Cache::pull($this->token);
if($rs === false){
$this->response('error',Code::USER_ERROR);
}
$this->response('success');
}
/**
* 发送登录短信
* @param Request $request
* @return \Illuminate\Http\JsonResponse
*/
public function sendLoginSms()
{
$this->request->validate([
'mobile'=>['required', 'regex:/^1[3-9]\d{9}$/'],
],[
'mobile.required' => '手机号码不能为空',
'mobile.regex' => '请输入正确的手机号码',
]);
$mobile = $this->param['mobile'];
$user = UserModel::where(['mobile' => $mobile])->first();
if (empty($user)) {
$this->response('请输入正确的手机号码!', Code::USER_LOGIN_ERROE);
}
$last_sms = SmsLog::getLastLog($mobile, SmsLog::TYPE_LOGIN);
if ($last_sms && $last_sms->use = SmsLog::USE_USABLE && time() - strtotime($last_sms->created_at) < 60) {
$this->response('请不要重复发送短信!', Code::USER_LOGIN_ERROE);
}
$template = config('aliyunsms.login_sms_temp');
$code['code'] = rand(100000,999999);
$ali_sms = new AliSms();
$send = $ali_sms->sendSms(strval($mobile), $template, $code);
if (empty($send->Code) && $send->Code != 'OK') {
$this->response('发送失败, 请稍后重试!', Code::USER_LOGIN_ERROE);
}
SmsLog::createLog($mobile, $code['code']);
$this->response('success');
}
/**
* @remark :根据关键字生成链接
* @name :pubLink
* @author :lyh
* @method :post
* @time :2023/6/28 16:13
*/
public function stringTranslation(){
$str = Translate::tran($this->param['str'], 'en');
$this->response('success',Code::SUCCESS,$str);
}
public function ceshi(){
$model = new Service();
$info = $model->read(['type'=>5]);
$values = json_decode($info['values']);
$values = array_reverse($values);
foreach ($values as $k => $v){
$v = (array)$v;
$data = [
'name'=>$v['name'],
'mobile'=>$v['mobile'],
'password'=>'$2y$10$ZNHxlIddWiQzQbIIzFgYJOsPlQ4n0cwWl8Sea53qvQvDXtu3WeYMC',
'created_at'=>date('Y-m-d H:i:s'),
'updated_at'=>date('Y-m-d H:i:s'),
];
$manager_id = DB::table('gl_manage')->insertGetId($data);
if($v['sex'] == '女'){
$v['sex'] = 2;
}else{
$v['sex'] = 1;
}
$education = [
'专科' => 1,
'大专' => 1,
'中专' => 0,
'本科' => 2,
'自考本科'=>0,
'全日制本科'=>2,
'本科在读'=>2,
'大学本科'=>2,
'硕士研究生' => 3,
'硕士'=>3,
'其他' => 0,
];
$belong_group = [
'-' => 0,
'KA组' => 1,
'A组' => 2,
'B组' => 3,
'C组'=>4,
'D组'=>5,
'E组'=>6,
'F组'=>7,
'G组' => 8,
'H组'=>9,
'GA组' => 10,
'GB组' => 11,
'GC组' => 12,
'前端组' => 13,
'后端组' => 10,
'黑格组' => 10,
'售后组' => 10,
'其他' => 0,
];
//获取入职岗位
$entryPositionModel = new EntryPosition();
$entry_position = $entryPositionModel->read(['name'=>$v['entry_position']]);
if($entry_position !== false){
$entry_position = $entry_position['id'];
}else{
$entry_position = '';
}
//获取级别
$jobLevelModel = new JobLevel();
$p_level = $jobLevelModel->read(['name'=>$v['p_level']]);
if($entry_position !== false){
$p_level = $p_level['id'];
}else{
$p_level = '';
}
$manager_data = [
'manage_id'=>$manager_id ?? '',
'name'=>$v['name'],
'id_card'=>$v['id_card'],
'mobile'=>$v['mobile'],
'birthday'=>$v['birthday'],
'address'=>$v['address'],
'sex'=>$v['sex'],
'nationality'=>$v['nationality'],
'belong_group'=>$belong_group[$v['belong_group']],
'education'=>isset($education[$v['education']]) ? $education[$v['education']] : 0,
'major'=>$v['major'],
'graduate_school'=>$v['graduate_school'],
'english_level'=>$v['english_level'],
'entry_position'=>$entry_position,
'p_level'=>$p_level,
'residential_address'=>$v['residential_address'],
'emergency_contact'=>$v['emergency_contact'],
'career_history'=>json_encode((array)$v['career_history']),
'learning_history'=>json_encode((array)$v['learning_history']),
'bank_card'=>$v['bank_card'],
'photo_gallery'=>json_encode((array)$v['photo_gallery']),
'id_card_gallery'=>json_encode((array)$v['id_card_gallery']),
'certificate_gallery'=>json_encode((array)$v['certificate_gallery']),
'dangyuan'=>$v['dangyuan'],
'dangzhibu'=>$v['dangzhibu'],
'dang_address'=>$v['dang_address'],
'join_date'=>$v['join_date'],
'status'=>($v['status'] == '在职') ? 1 : 2,
'computer_account'=>$v['computer_account'],
'qq_account'=>$v['qq_account']
];
$hrModel = new ManageHr();
$hrModel->add($manager_data);
}
return 1;
}
}