fix:사업자 정보 미입력 시 불필요한 SalesPartner 레코드 생성 방지
- 기존 레코드가 있거나 실제 값이 입력된 경우에만 저장 - SoftDelete 스코프 충돌 방지를 위해 where 쿼리로 변경 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -110,16 +110,19 @@ public function updateSalesPartner(User $user, array $data, array $documents = [
|
||||
}
|
||||
|
||||
// 2-1. 사업자 정보 업데이트
|
||||
if (array_key_exists('company_name', $data) || array_key_exists('biz_no', $data) || array_key_exists('address', $data)) {
|
||||
$sp = SalesPartner::firstOrNew(['user_id' => $user->id]);
|
||||
$hasBizInfo = !empty($data['company_name']) || !empty($data['biz_no']) || !empty($data['address']);
|
||||
$existingSp = SalesPartner::where('user_id', $user->id)->first();
|
||||
|
||||
if ($hasBizInfo || $existingSp) {
|
||||
$sp = $existingSp ?? new SalesPartner(['user_id' => $user->id]);
|
||||
if (!$sp->exists) {
|
||||
$sp->partner_code = SalesPartner::generatePartnerCode();
|
||||
$sp->partner_type = 'individual';
|
||||
$sp->status = 'active';
|
||||
}
|
||||
$sp->company_name = $data['company_name'] ?? $sp->company_name;
|
||||
$sp->biz_no = $data['biz_no'] ?? $sp->biz_no;
|
||||
$sp->address = $data['address'] ?? $sp->address;
|
||||
$sp->company_name = $data['company_name'] ?? null;
|
||||
$sp->biz_no = $data['biz_no'] ?? null;
|
||||
$sp->address = $data['address'] ?? null;
|
||||
$sp->save();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user