Просмотр исходного кода

fix: 修复代理可空字段写库失败

doge 10 часов назад
Родитель
Сommit
541a824253
2 измененных файлов с 15 добавлено и 3 удалено
  1. 10 1
      app/Http/Controllers/agent/WalletController.php
  2. 5 2
      app/Services/Agent/AgentService.php

+ 10 - 1
app/Http/Controllers/agent/WalletController.php

@@ -43,8 +43,17 @@ class WalletController extends AgentApiController
                 'bank_name' => ['nullable', 'string', 'max:128'], 'network' => ['nullable', 'string', 'max:32'],
                 'bank_name' => ['nullable', 'string', 'max:128'], 'network' => ['nullable', 'string', 'max:32'],
                 'details' => ['nullable', 'array'], 'status' => ['nullable', 'integer', 'in:0,1'],
                 'details' => ['nullable', 'array'], 'status' => ['nullable', 'integer', 'in:0,1'],
             ]);
             ]);
+            $isNew = empty($data['id']);
+            foreach (['name', 'bank_name', 'network'] as $field) {
+                if ($isNew || array_key_exists($field, $data)) {
+                    $data[$field] = trim((string) ($data[$field] ?? ''));
+                }
+            }
+            if ($isNew || array_key_exists('status', $data)) {
+                $data['status'] = $data['status'] ?? 1;
+            }
             $agent = $this->currentAgent();
             $agent = $this->currentAgent();
-            $account = empty($data['id']) ? new AgentWithdrawAccount() : AgentWithdrawAccount::query()->where('agent_id', $agent->id)->findOrFail($data['id']);
+            $account = $isNew ? new AgentWithdrawAccount() : AgentWithdrawAccount::query()->where('agent_id', $agent->id)->findOrFail($data['id']);
             $account->fill($data);
             $account->fill($data);
             $account->agent_id = $agent->id;
             $account->agent_id = $agent->id;
             $account->save();
             $account->save();

+ 5 - 2
app/Services/Agent/AgentService.php

@@ -69,8 +69,11 @@ class AgentService
             } elseif (array_key_exists('parent_id', $data)) {
             } elseif (array_key_exists('parent_id', $data)) {
                 $this->move($agent, $data['parent_id'] === null ? null : (int) $data['parent_id']);
                 $this->move($agent, $data['parent_id'] === null ? null : (int) $data['parent_id']);
             }
             }
-            foreach (['username', 'real_name', 'status', 'deposit_fee_rate', 'withdraw_fee_rate', 'flow_commission_rate', 'profit_commission_rate'] as $field) {
-                if (array_key_exists($field, $data)) {
+            if (array_key_exists('real_name', $data)) {
+                $agent->real_name = trim((string) ($data['real_name'] ?? ''));
+            }
+            foreach (['username', 'status', 'deposit_fee_rate', 'withdraw_fee_rate', 'flow_commission_rate', 'profit_commission_rate'] as $field) {
+                if (array_key_exists($field, $data) && $data[$field] !== null) {
                     $agent->{$field} = $data[$field];
                     $agent->{$field} = $data[$field];
                 }
                 }
             }
             }