创建模型验证器,验证数据正确性
This commit is contained in:
@@ -31,6 +31,8 @@ class Channel extends Backend
|
||||
|
||||
protected string|array $quickSearchField = ['id', 'code', 'name'];
|
||||
|
||||
protected bool $modelSceneValidate = true;
|
||||
|
||||
private array $currentChannelIds = [];
|
||||
|
||||
protected function initController(WebmanRequest $request): ?Response
|
||||
|
||||
@@ -23,7 +23,9 @@ class CommissionRecord extends Backend
|
||||
|
||||
protected array $withJoinTable = ['settlementPeriod', 'channel', 'admin'];
|
||||
|
||||
protected bool $modelValidate = false;
|
||||
protected bool $modelValidate = true;
|
||||
|
||||
protected bool $modelSceneValidate = true;
|
||||
|
||||
protected function initController(WebmanRequest $request): ?Response
|
||||
{
|
||||
|
||||
@@ -21,7 +21,9 @@ class SettlementPeriod extends Backend
|
||||
|
||||
protected string|array $orderGuarantee = ['id' => 'desc'];
|
||||
|
||||
protected bool $modelValidate = false;
|
||||
protected bool $modelValidate = true;
|
||||
|
||||
protected bool $modelSceneValidate = true;
|
||||
|
||||
protected function initController(WebmanRequest $request): ?Response
|
||||
{
|
||||
|
||||
@@ -22,7 +22,9 @@ class GameConfig extends Backend
|
||||
|
||||
protected string|array $orderGuarantee = ['id' => 'asc'];
|
||||
|
||||
protected bool $modelValidate = false;
|
||||
protected bool $modelValidate = true;
|
||||
|
||||
protected bool $modelSceneValidate = true;
|
||||
|
||||
protected function initController(WebmanRequest $request): ?Response
|
||||
{
|
||||
|
||||
@@ -22,7 +22,9 @@ class Config extends Backend
|
||||
|
||||
protected string|array $orderGuarantee = ['id' => 'asc'];
|
||||
|
||||
protected bool $modelValidate = false;
|
||||
protected bool $modelValidate = true;
|
||||
|
||||
protected bool $modelSceneValidate = true;
|
||||
|
||||
protected function initController(WebmanRequest $request): ?Response
|
||||
{
|
||||
|
||||
@@ -23,7 +23,9 @@ class Period extends Backend
|
||||
|
||||
protected string|array $orderGuarantee = ['id' => 'desc'];
|
||||
|
||||
protected bool $modelValidate = false;
|
||||
protected bool $modelValidate = true;
|
||||
|
||||
protected bool $modelSceneValidate = true;
|
||||
|
||||
protected function initController(WebmanRequest $request): ?Response
|
||||
{
|
||||
|
||||
@@ -21,7 +21,9 @@ class OperationNotice extends Backend
|
||||
|
||||
protected string|array $orderGuarantee = ['id' => 'desc'];
|
||||
|
||||
protected bool $modelValidate = false;
|
||||
protected bool $modelValidate = true;
|
||||
|
||||
protected bool $modelSceneValidate = true;
|
||||
|
||||
protected function initController(WebmanRequest $request): ?Response
|
||||
{
|
||||
|
||||
@@ -23,7 +23,9 @@ class UserNoticeRead extends Backend
|
||||
|
||||
protected array $withJoinTable = ['user', 'operationNotice'];
|
||||
|
||||
protected bool $modelValidate = false;
|
||||
protected bool $modelValidate = true;
|
||||
|
||||
protected bool $modelSceneValidate = true;
|
||||
|
||||
protected function initController(WebmanRequest $request): ?Response
|
||||
{
|
||||
|
||||
@@ -14,7 +14,9 @@ class DepositOrder extends Backend
|
||||
{
|
||||
protected ?object $model = null;
|
||||
|
||||
protected bool $modelValidate = false;
|
||||
protected bool $modelValidate = true;
|
||||
|
||||
protected bool $modelSceneValidate = true;
|
||||
|
||||
protected string|array $quickSearchField = ['id', 'order_no', 'pay_channel', 'remark'];
|
||||
|
||||
|
||||
@@ -14,7 +14,9 @@ class WithdrawOrder extends Backend
|
||||
{
|
||||
protected ?object $model = null;
|
||||
|
||||
protected bool $modelValidate = false;
|
||||
protected bool $modelValidate = true;
|
||||
|
||||
protected bool $modelSceneValidate = true;
|
||||
|
||||
protected string|array $quickSearchField = ['id', 'order_no', 'remark'];
|
||||
|
||||
|
||||
@@ -26,6 +26,8 @@ class User extends Backend
|
||||
|
||||
protected string|array $quickSearchField = ['id', 'username', 'phone'];
|
||||
|
||||
protected bool $modelSceneValidate = true;
|
||||
|
||||
protected function initController(WebmanRequest $request): ?Response
|
||||
{
|
||||
$this->model = new \app\common\model\User();
|
||||
|
||||
@@ -17,4 +17,24 @@ class OperationNotice extends Model
|
||||
'notice_type' => 'integer',
|
||||
'status' => 'integer',
|
||||
];
|
||||
|
||||
public function setPublishAtAttr($value)
|
||||
{
|
||||
if ($value === null || $value === '') {
|
||||
return 0;
|
||||
}
|
||||
if (is_int($value)) {
|
||||
return $value;
|
||||
}
|
||||
if (is_string($value)) {
|
||||
if (ctype_digit($value)) {
|
||||
return (int) $value;
|
||||
}
|
||||
$ts = strtotime($value);
|
||||
if ($ts !== false) {
|
||||
return $ts;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
28
app/common/validate/AgentCommissionRecord.php
Normal file
28
app/common/validate/AgentCommissionRecord.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\common\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class AgentCommissionRecord extends Validate
|
||||
{
|
||||
protected $failException = true;
|
||||
|
||||
protected $rule = [
|
||||
'settlement_period_id' => 'require|integer|gt:0',
|
||||
'channel_id' => 'require|integer|gt:0',
|
||||
'admin_id' => 'require|integer|gt:0',
|
||||
'commission_rate' => 'require|float|egt:0',
|
||||
'calc_base_amount' => 'require|float',
|
||||
'commission_amount' => 'require|float',
|
||||
'status' => 'in:0,1,2',
|
||||
'remark' => 'max:255',
|
||||
];
|
||||
|
||||
protected $scene = [
|
||||
'add' => ['settlement_period_id', 'channel_id', 'admin_id', 'commission_rate', 'calc_base_amount', 'commission_amount', 'status', 'remark'],
|
||||
'edit' => ['commission_rate', 'calc_base_amount', 'commission_amount', 'status', 'remark'],
|
||||
];
|
||||
}
|
||||
25
app/common/validate/AgentSettlementPeriod.php
Normal file
25
app/common/validate/AgentSettlementPeriod.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\common\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class AgentSettlementPeriod extends Validate
|
||||
{
|
||||
protected $failException = true;
|
||||
|
||||
protected $rule = [
|
||||
'settlement_no' => 'require|max:64|unique:agent_settlement_period',
|
||||
'period_start_at' => 'require|integer|egt:0',
|
||||
'period_end_at' => 'require|integer|egt:0',
|
||||
'status' => 'in:0,1,2',
|
||||
'remark' => 'max:255',
|
||||
];
|
||||
|
||||
protected $scene = [
|
||||
'add' => ['settlement_no', 'period_start_at', 'period_end_at', 'status', 'remark'],
|
||||
'edit' => ['period_start_at', 'period_end_at', 'status', 'remark'],
|
||||
];
|
||||
}
|
||||
26
app/common/validate/Channel.php
Normal file
26
app/common/validate/Channel.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\common\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class Channel extends Validate
|
||||
{
|
||||
protected $failException = true;
|
||||
|
||||
protected $rule = [
|
||||
'code' => 'require|max:255|unique:channel',
|
||||
'name' => 'require|max:255',
|
||||
'agent_mode' => 'require|in:turnover,affiliate',
|
||||
'status' => 'in:0,1',
|
||||
'admin_id' => 'require|integer|gt:0',
|
||||
'remark' => 'max:255',
|
||||
];
|
||||
|
||||
protected $scene = [
|
||||
'add' => ['code', 'name', 'agent_mode', 'status', 'admin_id', 'remark'],
|
||||
'edit' => ['name', 'agent_mode', 'status', 'admin_id', 'remark'],
|
||||
];
|
||||
}
|
||||
23
app/common/validate/DepositOrder.php
Normal file
23
app/common/validate/DepositOrder.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\common\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class DepositOrder extends Validate
|
||||
{
|
||||
protected $failException = true;
|
||||
|
||||
protected $rule = [
|
||||
'order_no' => 'require|max:64|unique:deposit_order',
|
||||
'user_id' => 'require|integer|gt:0',
|
||||
'status' => 'require|in:0,1,2,3',
|
||||
];
|
||||
|
||||
protected $scene = [
|
||||
'add' => ['order_no', 'user_id', 'status'],
|
||||
'edit' => ['status'],
|
||||
];
|
||||
}
|
||||
23
app/common/validate/GameConfig.php
Normal file
23
app/common/validate/GameConfig.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\common\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class GameConfig extends Validate
|
||||
{
|
||||
protected $failException = true;
|
||||
|
||||
protected $rule = [
|
||||
'config_key' => 'require|max:64|unique:game_config',
|
||||
'value_type' => 'require|in:string,int,decimal,json',
|
||||
'remark' => 'max:255',
|
||||
];
|
||||
|
||||
protected $scene = [
|
||||
'add' => ['config_key', 'value_type', 'remark'],
|
||||
'edit' => ['value_type', 'remark'],
|
||||
];
|
||||
}
|
||||
26
app/common/validate/GamePeriod.php
Normal file
26
app/common/validate/GamePeriod.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\common\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class GamePeriod extends Validate
|
||||
{
|
||||
protected $failException = true;
|
||||
|
||||
protected $rule = [
|
||||
'period_no' => 'require|max:64|unique:game_period',
|
||||
'period_start_at' => 'integer',
|
||||
'status' => 'require|in:0,1,2,3,4,5',
|
||||
'draw_mode' => 'in:0,1',
|
||||
'preset_number' => 'between:1,36',
|
||||
'result_number' => 'between:1,36',
|
||||
];
|
||||
|
||||
protected $scene = [
|
||||
'add' => ['period_no', 'period_start_at', 'status', 'draw_mode', 'preset_number', 'result_number'],
|
||||
'edit' => ['period_start_at', 'status', 'draw_mode', 'preset_number', 'result_number'],
|
||||
];
|
||||
}
|
||||
41
app/common/validate/OperationNotice.php
Normal file
41
app/common/validate/OperationNotice.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\common\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class OperationNotice extends Validate
|
||||
{
|
||||
protected $failException = true;
|
||||
|
||||
protected $rule = [
|
||||
'title' => 'require|max:255',
|
||||
'notice_type' => 'require|in:0,1',
|
||||
'status' => 'require|in:0,1',
|
||||
'publish_at' => 'require|checkPublishAt',
|
||||
];
|
||||
|
||||
protected $scene = [
|
||||
'add' => ['title', 'notice_type', 'status', 'publish_at'],
|
||||
'edit' => ['title', 'notice_type', 'status', 'publish_at'],
|
||||
];
|
||||
|
||||
protected function checkPublishAt($value): bool
|
||||
{
|
||||
if (is_int($value)) {
|
||||
return $value >= 0;
|
||||
}
|
||||
if (is_string($value)) {
|
||||
if ($value === '') {
|
||||
return false;
|
||||
}
|
||||
if (ctype_digit($value)) {
|
||||
return true;
|
||||
}
|
||||
return strtotime($value) !== false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
32
app/common/validate/User.php
Normal file
32
app/common/validate/User.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\common\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class User extends Validate
|
||||
{
|
||||
protected $failException = true;
|
||||
|
||||
protected $rule = [
|
||||
'username' => 'require|max:255',
|
||||
'password' => 'require|min:6|max:255',
|
||||
'phone' => 'max:32',
|
||||
'email' => 'email',
|
||||
'channel_id' => 'require|integer|gt:0',
|
||||
'status' => 'in:0,1',
|
||||
];
|
||||
|
||||
protected $scene = [
|
||||
'add' => ['username', 'password', 'phone', 'email', 'channel_id', 'status'],
|
||||
'edit' => ['username', 'password', 'phone', 'email', 'channel_id', 'status'],
|
||||
];
|
||||
|
||||
public function sceneEdit(): static
|
||||
{
|
||||
return $this->only(['username', 'password', 'phone', 'email', 'channel_id', 'status'])
|
||||
->remove('password', 'require');
|
||||
}
|
||||
}
|
||||
24
app/common/validate/UserNoticeRead.php
Normal file
24
app/common/validate/UserNoticeRead.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\common\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class UserNoticeRead extends Validate
|
||||
{
|
||||
protected $failException = true;
|
||||
|
||||
protected $rule = [
|
||||
'user_id' => 'require|integer|gt:0',
|
||||
'notice_id' => 'require|integer|gt:0',
|
||||
'confirmed' => 'in:0,1',
|
||||
'read_at' => 'integer',
|
||||
];
|
||||
|
||||
protected $scene = [
|
||||
'add' => ['user_id', 'notice_id', 'confirmed', 'read_at'],
|
||||
'edit' => ['user_id', 'notice_id', 'confirmed', 'read_at'],
|
||||
];
|
||||
}
|
||||
25
app/common/validate/WithdrawOrder.php
Normal file
25
app/common/validate/WithdrawOrder.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\common\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class WithdrawOrder extends Validate
|
||||
{
|
||||
protected $failException = true;
|
||||
|
||||
protected $rule = [
|
||||
'order_no' => 'require|max:64|unique:withdraw_order',
|
||||
'user_id' => 'require|integer|gt:0',
|
||||
'amount' => 'float|egt:0',
|
||||
'status' => 'require|in:0,1,2,3',
|
||||
'remark' => 'max:255',
|
||||
];
|
||||
|
||||
protected $scene = [
|
||||
'add' => ['order_no', 'user_id', 'amount', 'status', 'remark'],
|
||||
'edit' => ['amount', 'status', 'remark'],
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user