登录注册
This commit is contained in:
@@ -29,17 +29,29 @@ class UserController
|
||||
public function login(Request $request)
|
||||
{
|
||||
$email = Util::getParam($request, 'email');
|
||||
$corpAbbr = Util::getParam($request, 'abbr');
|
||||
$language = Util::getParam($request, 'language');
|
||||
if (Util::isEmpty($email)) {
|
||||
return Util::fail([], trans('required_not_null'));
|
||||
}
|
||||
if (Util::isEmpty($corpAbbr)) {
|
||||
return Util::fail([], 'abbr'.trans('not_null'));
|
||||
}
|
||||
$password = Util::getParam($request, 'password');
|
||||
if (Util::isEmpty($password)) {
|
||||
return Util::fail([], trans('required_not_null'));
|
||||
}
|
||||
|
||||
// 获取企业ID
|
||||
$corpInfo = Corp::where('abbr', $corpAbbr)->first();
|
||||
if (!$corpInfo) {
|
||||
return Util::fail([], '公司不存在');
|
||||
}
|
||||
$corpId = $corpInfo->id;
|
||||
|
||||
$user = User::where('status', 0)
|
||||
// ->where('email', $request->post('email'))
|
||||
->where('corp_id', $corpId)
|
||||
->OrWhere(['email' => $request->post('email'),'phone' => $request->post('email')])
|
||||
->first();
|
||||
// $builder = User::where('status', 0)
|
||||
@@ -139,12 +151,13 @@ class UserController
|
||||
*/
|
||||
public function register(Request $request)
|
||||
{
|
||||
$email = Util::getParam($request, 'email', 'asdf');
|
||||
$email = Util::getParam($request, 'email', '');
|
||||
$code = Util::getParam($request, 'code');
|
||||
$sex = Util::getParam($request, 'sex', 0);
|
||||
$name = Util::getParam($request, 'name', '');
|
||||
$password = Util::getParam($request, 'password');
|
||||
$mobile = Util::getParam($request, 'mobile');
|
||||
$corpAbbr = Util::getParam($request, 'abbr');
|
||||
$id = Util::getParam($request, 'id');
|
||||
$language = Util::getParam($request, 'language');
|
||||
|
||||
@@ -185,26 +198,24 @@ class UserController
|
||||
'avatar' => ''
|
||||
];
|
||||
|
||||
|
||||
if (Util::isEmpty($id)) {
|
||||
$option = ['email' => $email];
|
||||
$userService = new UserService;
|
||||
$res = $userService->createOrquery($option);
|
||||
Log::info('register_rpc',$res);
|
||||
// return Util::fail($res, trans('register_fail'));
|
||||
if ($res['code'] != 200 && $res['data']['code'] != 0){
|
||||
return Util::fail($res, trans('register_fail'));
|
||||
}
|
||||
$data['sn'] = $res['data']['data']['sn'];
|
||||
$data['id'] = $res['data']['data']['uid'];
|
||||
$res = User::firstOrCreate(['sn' => $data['sn']],$data);
|
||||
$res['id'] = $data['id'];
|
||||
} else {
|
||||
$res = User::where('id', $id)
|
||||
->update($data);
|
||||
// Log::info('update', ['res' => $res]);
|
||||
(!$res) ?: $res = User::find($id)->toArray();
|
||||
// 获取可用用户编号
|
||||
$userSnModel = new UserSn();
|
||||
$sn = $userSnModel->where('user_id', '=', 0)->inRandomOrder()->first();
|
||||
if (!$sn) {
|
||||
Log::error('用户注册时未找到适用编号');
|
||||
return Util::fail([], '未找到适用编号');
|
||||
}
|
||||
$data['sn'] = $sn->user_sn;
|
||||
|
||||
|
||||
// 获取企业ID
|
||||
$corpInfo = Corp::where('abbr', $corpAbbr)->first();
|
||||
if (!$corpInfo) {
|
||||
return Util::fail([], '公司不存在');
|
||||
}
|
||||
$data['corp_id'] = $corpInfo->id;
|
||||
|
||||
$res = User::create($data);
|
||||
|
||||
unset($res['password']);
|
||||
locale($language);
|
||||
|
||||
Reference in New Issue
Block a user