|
|
@ -95,9 +95,18 @@ class AuthApiController extends BaseAuthApiController |
|
|
|
// } |
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
$checkUserAgent = AgentUser::where('code', '=', $request->agents_code)->first(); |
|
|
|
$checkUserAgent = AgentUser::where('code', '=', $request->agents_code)->first(); |
|
|
|
|
|
|
|
|
|
|
|
if (empty($checkUserAgent)) { |
|
|
|
if (empty($checkUserAgent)) { |
|
|
|
return response()->json(['status' => false, 'msg' => 'Đăng ký thất bại, Không tìm thấy đại lý.']); |
|
|
|
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 = "A99"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$agentCodeNew = $this->generateNewCode($lastCode); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$dataInsert = $this->transformRegisterData($request->all()); |
|
|
|
$dataInsert = $this->transformRegisterData($request->all()); |
|
|
|
|
|
|
|
|
|
|
@ -117,7 +126,7 @@ class AuthApiController extends BaseAuthApiController |
|
|
|
'user_id' => $userId, |
|
|
|
'user_id' => $userId, |
|
|
|
'agent_id' => $agentInsertId, |
|
|
|
'agent_id' => $agentInsertId, |
|
|
|
'status' => 1, |
|
|
|
'status' => 1, |
|
|
|
'code' => $dataInsert['phone'], |
|
|
|
'code' => $agentCodeNew??'', |
|
|
|
'agent_root_id' => $checkUserAgent->agent_root_id |
|
|
|
'agent_root_id' => $checkUserAgent->agent_root_id |
|
|
|
]); |
|
|
|
]); |
|
|
|
} |
|
|
|
} |
|
|
@ -128,6 +137,15 @@ class AuthApiController extends BaseAuthApiController |
|
|
|
|
|
|
|
|
|
|
|
return response()->json(['status' => false, 'msg' => $this->getMessageReponse(2)]); |
|
|
|
return response()->json(['status' => false, 'msg' => $this->getMessageReponse(2)]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public function generateNewCode($code){ |
|
|
|
|
|
|
|
$newCode = ''; |
|
|
|
|
|
|
|
if(!empty($code)){ |
|
|
|
|
|
|
|
$latestCodeNumber = (int) substr($code, 1); |
|
|
|
|
|
|
|
$newCodeNumber = $latestCodeNumber + 1; |
|
|
|
|
|
|
|
$newCode = 'A' . str_pad($newCodeNumber, 3, '0', STR_PAD_LEFT); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return $newCode; |
|
|
|
|
|
|
|
} |
|
|
|
public function logout(Request $request) |
|
|
|
public function logout(Request $request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$token = $request->user()->token(); |
|
|
|
$token = $request->user()->token(); |
|
|
|