|
|
|
@ -112,14 +112,16 @@ class AuthApiController extends BaseAuthApiController |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$dataInsert = $this->transformRegisterData($request->all()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!empty($dataInsert)) { |
|
|
|
|
if (!empty($checkUserAgent->agent_id)) { |
|
|
|
|
$agentParent = Agent::find($checkUserAgent->agent_id); |
|
|
|
|
$grantParent = $agentParent->grant; |
|
|
|
|
$parentPath = $agentParent->parent_path??null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$userId = \App\Models\User::insertGetId($dataInsert); |
|
|
|
|
|
|
|
|
|
if ($userId) { |
|
|
|
|
$dataAgentInsert = [ |
|
|
|
|
'name' => $dataInsert['name'] ?? '', |
|
|
|
@ -130,7 +132,12 @@ class AuthApiController extends BaseAuthApiController |
|
|
|
|
'address' => $dataInsert['address'] ?? '', |
|
|
|
|
]; |
|
|
|
|
$agentInsertId = Agent::insertGetId($dataAgentInsert); |
|
|
|
|
|
|
|
|
|
if ($agentInsertId) { |
|
|
|
|
if(!empty($parentPath)){ |
|
|
|
|
$myParentPath = $this->addParentPath($parentPath, $agentInsertId); |
|
|
|
|
Agent::where('id', $agentInsertId)->update(['parent_path' => $myParentPath]); |
|
|
|
|
} |
|
|
|
|
AgentUser::insert([ |
|
|
|
|
'user_id' => $userId, |
|
|
|
|
'agent_id' => $agentInsertId, |
|
|
|
@ -146,6 +153,9 @@ class AuthApiController extends BaseAuthApiController |
|
|
|
|
|
|
|
|
|
return response()->json(['status' => false, 'msg' => $this->getMessageReponse(2)]); |
|
|
|
|
} |
|
|
|
|
public function addParentPath($parentPath, $userIdAdd){ |
|
|
|
|
return rtrim($parentPath, '-') . '-' . $userIdAdd . '-'; |
|
|
|
|
} |
|
|
|
|
public function generateNewCode($code) |
|
|
|
|
{ |
|
|
|
|
$newCode = ''; |
|
|
|
|