游戏-用户管理-优化样式增强验证
This commit is contained in:
@@ -61,6 +61,72 @@ class User extends Backend
|
|||||||
return null;
|
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 生成)
|
* 添加(重写:password 使用 Admin 同款加密;uuid 由 username+channel_id 生成)
|
||||||
* @throws Throwable
|
* @throws Throwable
|
||||||
@@ -75,6 +141,7 @@ class User extends Backend
|
|||||||
|
|
||||||
$data = $this->applyInputFilter($data);
|
$data = $this->applyInputFilter($data);
|
||||||
$data = $this->excludeFields($data);
|
$data = $this->excludeFields($data);
|
||||||
|
$this->normalizeEmptyTicketCount($data);
|
||||||
|
|
||||||
$password = $data['password'] ?? null;
|
$password = $data['password'] ?? null;
|
||||||
if (!is_string($password) || trim($password) === '') {
|
if (!is_string($password) || trim($password) === '') {
|
||||||
@@ -168,6 +235,7 @@ class User extends Backend
|
|||||||
|
|
||||||
$data = $this->applyInputFilter($data);
|
$data = $this->applyInputFilter($data);
|
||||||
$data = $this->excludeFields($data);
|
$data = $this->excludeFields($data);
|
||||||
|
$this->normalizeEmptyTicketCount($data);
|
||||||
|
|
||||||
if (array_key_exists('password', $data)) {
|
if (array_key_exists('password', $data)) {
|
||||||
$password = $data['password'];
|
$password = $data['password'];
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -175,7 +175,7 @@ const baTable = new baTableClass(
|
|||||||
status: '1',
|
status: '1',
|
||||||
tier_weight: jsonStringFromFixedKeys(TIER_WEIGHT_KEYS, {}),
|
tier_weight: jsonStringFromFixedKeys(TIER_WEIGHT_KEYS, {}),
|
||||||
bigwin_weight: jsonStringFromFixedKeys(BIGWIN_WEIGHT_KEYS, {}),
|
bigwin_weight: jsonStringFromFixedKeys(BIGWIN_WEIGHT_KEYS, {}),
|
||||||
ticket_count: '[]',
|
ticket_count: null,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -355,6 +355,9 @@ function ticketRowsToJsonString(rows: TicketRow[]): string {
|
|||||||
const nc = Number(c)
|
const nc = Number(c)
|
||||||
body.push({ ante: na, count: nc })
|
body.push({ ante: na, count: nc })
|
||||||
}
|
}
|
||||||
|
if (body.length === 0) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
return JSON.stringify(body)
|
return JSON.stringify(body)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -364,10 +367,11 @@ function syncTicketToForm() {
|
|||||||
const a = ticketRows.value[0]?.ante?.trim() ?? ''
|
const a = ticketRows.value[0]?.ante?.trim() ?? ''
|
||||||
const c = ticketRows.value[0]?.count?.trim() ?? ''
|
const c = ticketRows.value[0]?.count?.trim() ?? ''
|
||||||
if (a === '' || c === '') {
|
if (a === '' || c === '') {
|
||||||
items.ticket_count = ''
|
items.ticket_count = null
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
items.ticket_count = ticketRowsToJsonString(ticketRows.value)
|
const json = ticketRowsToJsonString(ticketRows.value)
|
||||||
|
items.ticket_count = json === '' ? null : json
|
||||||
}
|
}
|
||||||
|
|
||||||
function applyTierBigwinFromJson(tierJson: string, bigwinJson: string) {
|
function applyTierBigwinFromJson(tierJson: string, bigwinJson: string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user