main
nocode 1 year ago
parent f5b15c6e69
commit 44d13d58da
  1. 22
      app/Http/Controllers/Api/AuthApiController.php

@ -29,11 +29,11 @@ class AuthApiController extends BaseAuthApiController
} else {
$user = User::where('phone', $request->username)->first();
}
if(empty($user)){
return response()->json(['status' =>false, 'msg' => 'Email hoặc SĐT chưa được đăng ký.'], parent::HTTP_OK);
if (empty($user)) {
return response()->json(['status' => false, 'msg' => 'Email hoặc SĐT chưa được đăng ký.'], parent::HTTP_OK);
}
if (!Auth::attempt(['id' => $user->id, 'password' => $request->password])) {
return response()->json(['status' =>false, 'msg' =>'Tài khoản hoặc mật khẩu không chính xác. Vui lòng thử lại.'], parent::HTTP_OK);
return response()->json(['status' => false, 'msg' => 'Tài khoản hoặc mật khẩu không chính xác. Vui lòng thử lại.'], parent::HTTP_OK);
}
$user = User::find($user->id);
@ -56,6 +56,9 @@ class AuthApiController extends BaseAuthApiController
if (!empty($agentUser->agent_root_id)) {
// Agent User Root
$agentRootInfo = Agent::find($agentUser->agent_root_id);
$agentUserRoot = AgentUser::where('agent_id', $agentUser->agent_root_id)->where('agent_root_id', $agentUser->agent_root_id)->latest()->first();
}
if (!empty($agentUser->agent_id)) {
// Agent User Current
@ -64,7 +67,7 @@ class AuthApiController extends BaseAuthApiController
$phone = $user->phone ?? null;
$data['general_agents_code'] = $agentUser->code ?? '';
$data['general_agents_code'] = $agentUserRoot->code ?? '';
$data['general_agents_name'] = $agentRootInfo->name ?? '';
$data['downline_register'] = $this->getLinkParam('downline_register', $agentUser->code);
$data['promotional_link'] = $this->getLinkParam('promotional_link', $agentUser->code);
@ -100,8 +103,8 @@ class AuthApiController extends BaseAuthApiController
return response()->json(['status' => false, 'msg' => 'Đăng ký thất bại, Không tìm thấy đại lý.']);
}
$lastIndex = AgentUser::latest()->first();
$lastCode = $lastIndex->code??null;
if(empty($lastCode)){
$lastCode = $lastIndex->code ?? null;
if (empty($lastCode)) {
$lastCode = "A99";
}
@ -126,7 +129,7 @@ class AuthApiController extends BaseAuthApiController
'user_id' => $userId,
'agent_id' => $agentInsertId,
'status' => 1,
'code' => $agentCodeNew??'',
'code' => $agentCodeNew ?? '',
'agent_root_id' => $checkUserAgent->agent_root_id
]);
}
@ -137,9 +140,10 @@ class AuthApiController extends BaseAuthApiController
return response()->json(['status' => false, 'msg' => $this->getMessageReponse(2)]);
}
public function generateNewCode($code){
public function generateNewCode($code)
{
$newCode = '';
if(!empty($code)){
if (!empty($code)) {
$latestCodeNumber = (int) substr($code, 1);
$newCodeNumber = $latestCodeNumber + 1;
$newCode = 'A' . str_pad($newCodeNumber, 3, '0', STR_PAD_LEFT);

Loading…
Cancel
Save