游戏-用户管理-优化样式增强验证
This commit is contained in:
@@ -61,6 +61,72 @@ class User extends Backend
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 抽奖券 ticket_count:空串、[]、[""]、无有效 {ante,count} 时写入 NULL,避免库里出现无意义 JSON
|
||||
*
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
private function normalizeEmptyTicketCount(array &$data): void
|
||||
{
|
||||
if (!array_key_exists('ticket_count', $data)) {
|
||||
return;
|
||||
}
|
||||
$v = $data['ticket_count'];
|
||||
if ($v === null) {
|
||||
$data['ticket_count'] = null;
|
||||
|
||||
return;
|
||||
}
|
||||
if ($v === '') {
|
||||
$data['ticket_count'] = null;
|
||||
|
||||
return;
|
||||
}
|
||||
if (!is_string($v)) {
|
||||
return;
|
||||
}
|
||||
$s = trim($v);
|
||||
if ($s === '' || $s === '[]' || strtolower($s) === 'null') {
|
||||
$data['ticket_count'] = null;
|
||||
|
||||
return;
|
||||
}
|
||||
$decoded = json_decode($s, true);
|
||||
if ($decoded === null && json_last_error() !== JSON_ERROR_NONE) {
|
||||
return;
|
||||
}
|
||||
if (!is_array($decoded)) {
|
||||
return;
|
||||
}
|
||||
if ($decoded === []) {
|
||||
$data['ticket_count'] = null;
|
||||
|
||||
return;
|
||||
}
|
||||
$valid = false;
|
||||
foreach ($decoded as $item) {
|
||||
if (!is_array($item)) {
|
||||
continue;
|
||||
}
|
||||
if (!array_key_exists('ante', $item) || !array_key_exists('count', $item)) {
|
||||
continue;
|
||||
}
|
||||
$ante = $item['ante'];
|
||||
$count = $item['count'];
|
||||
if ($ante === '' || $ante === null || $count === '' || $count === null) {
|
||||
continue;
|
||||
}
|
||||
if (!is_numeric($ante) || !is_numeric($count)) {
|
||||
continue;
|
||||
}
|
||||
$valid = true;
|
||||
break;
|
||||
}
|
||||
if (!$valid) {
|
||||
$data['ticket_count'] = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加(重写:password 使用 Admin 同款加密;uuid 由 username+channel_id 生成)
|
||||
* @throws Throwable
|
||||
@@ -75,6 +141,7 @@ class User extends Backend
|
||||
|
||||
$data = $this->applyInputFilter($data);
|
||||
$data = $this->excludeFields($data);
|
||||
$this->normalizeEmptyTicketCount($data);
|
||||
|
||||
$password = $data['password'] ?? null;
|
||||
if (!is_string($password) || trim($password) === '') {
|
||||
@@ -168,6 +235,7 @@ class User extends Backend
|
||||
|
||||
$data = $this->applyInputFilter($data);
|
||||
$data = $this->excludeFields($data);
|
||||
$this->normalizeEmptyTicketCount($data);
|
||||
|
||||
if (array_key_exists('password', $data)) {
|
||||
$password = $data['password'];
|
||||
|
||||
Reference in New Issue
Block a user