diff --git a/app/admin/controller/Channel.php b/app/admin/controller/Channel.php index 83a7249..849664f 100644 --- a/app/admin/controller/Channel.php +++ b/app/admin/controller/Channel.php @@ -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 diff --git a/app/admin/controller/agent/CommissionRecord.php b/app/admin/controller/agent/CommissionRecord.php index 3944a73..017db51 100644 --- a/app/admin/controller/agent/CommissionRecord.php +++ b/app/admin/controller/agent/CommissionRecord.php @@ -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 { diff --git a/app/admin/controller/agent/SettlementPeriod.php b/app/admin/controller/agent/SettlementPeriod.php index 0409859..458055d 100644 --- a/app/admin/controller/agent/SettlementPeriod.php +++ b/app/admin/controller/agent/SettlementPeriod.php @@ -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 { diff --git a/app/admin/controller/config/GameConfig.php b/app/admin/controller/config/GameConfig.php index 8d34425..136452c 100644 --- a/app/admin/controller/config/GameConfig.php +++ b/app/admin/controller/config/GameConfig.php @@ -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 { diff --git a/app/admin/controller/game/Config.php b/app/admin/controller/game/Config.php index 357c1d7..ab94ba0 100644 --- a/app/admin/controller/game/Config.php +++ b/app/admin/controller/game/Config.php @@ -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 { diff --git a/app/admin/controller/game/Period.php b/app/admin/controller/game/Period.php index 1acef84..9dfca04 100644 --- a/app/admin/controller/game/Period.php +++ b/app/admin/controller/game/Period.php @@ -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 { diff --git a/app/admin/controller/operation/OperationNotice.php b/app/admin/controller/operation/OperationNotice.php index 9b61544..d041e6c 100644 --- a/app/admin/controller/operation/OperationNotice.php +++ b/app/admin/controller/operation/OperationNotice.php @@ -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 { diff --git a/app/admin/controller/operation/UserNoticeRead.php b/app/admin/controller/operation/UserNoticeRead.php index 97442a8..ef0e6a3 100644 --- a/app/admin/controller/operation/UserNoticeRead.php +++ b/app/admin/controller/operation/UserNoticeRead.php @@ -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 { diff --git a/app/admin/controller/order/DepositOrder.php b/app/admin/controller/order/DepositOrder.php index 4b6d6a5..b02b172 100644 --- a/app/admin/controller/order/DepositOrder.php +++ b/app/admin/controller/order/DepositOrder.php @@ -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']; diff --git a/app/admin/controller/order/WithdrawOrder.php b/app/admin/controller/order/WithdrawOrder.php index dae7b2c..4c64f96 100644 --- a/app/admin/controller/order/WithdrawOrder.php +++ b/app/admin/controller/order/WithdrawOrder.php @@ -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']; diff --git a/app/admin/controller/user/User.php b/app/admin/controller/user/User.php index f43e79c..b3d4177 100644 --- a/app/admin/controller/user/User.php +++ b/app/admin/controller/user/User.php @@ -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(); diff --git a/app/common/model/OperationNotice.php b/app/common/model/OperationNotice.php index 7995188..f674183 100644 --- a/app/common/model/OperationNotice.php +++ b/app/common/model/OperationNotice.php @@ -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; + } } diff --git a/app/common/validate/AgentCommissionRecord.php b/app/common/validate/AgentCommissionRecord.php new file mode 100644 index 0000000..0cda244 --- /dev/null +++ b/app/common/validate/AgentCommissionRecord.php @@ -0,0 +1,28 @@ + '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'], + ]; +} diff --git a/app/common/validate/AgentSettlementPeriod.php b/app/common/validate/AgentSettlementPeriod.php new file mode 100644 index 0000000..3bb0ec7 --- /dev/null +++ b/app/common/validate/AgentSettlementPeriod.php @@ -0,0 +1,25 @@ + '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'], + ]; +} diff --git a/app/common/validate/Channel.php b/app/common/validate/Channel.php new file mode 100644 index 0000000..7a5517b --- /dev/null +++ b/app/common/validate/Channel.php @@ -0,0 +1,26 @@ + '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'], + ]; +} diff --git a/app/common/validate/DepositOrder.php b/app/common/validate/DepositOrder.php new file mode 100644 index 0000000..b5c4007 --- /dev/null +++ b/app/common/validate/DepositOrder.php @@ -0,0 +1,23 @@ + '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'], + ]; +} diff --git a/app/common/validate/GameConfig.php b/app/common/validate/GameConfig.php new file mode 100644 index 0000000..fa00858 --- /dev/null +++ b/app/common/validate/GameConfig.php @@ -0,0 +1,23 @@ + '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'], + ]; +} diff --git a/app/common/validate/GamePeriod.php b/app/common/validate/GamePeriod.php new file mode 100644 index 0000000..2847eb5 --- /dev/null +++ b/app/common/validate/GamePeriod.php @@ -0,0 +1,26 @@ + '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'], + ]; +} diff --git a/app/common/validate/OperationNotice.php b/app/common/validate/OperationNotice.php new file mode 100644 index 0000000..8c74b6a --- /dev/null +++ b/app/common/validate/OperationNotice.php @@ -0,0 +1,41 @@ + '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; + } +} diff --git a/app/common/validate/User.php b/app/common/validate/User.php new file mode 100644 index 0000000..957df39 --- /dev/null +++ b/app/common/validate/User.php @@ -0,0 +1,32 @@ + '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'); + } +} diff --git a/app/common/validate/UserNoticeRead.php b/app/common/validate/UserNoticeRead.php new file mode 100644 index 0000000..084d4f5 --- /dev/null +++ b/app/common/validate/UserNoticeRead.php @@ -0,0 +1,24 @@ + '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'], + ]; +} diff --git a/app/common/validate/WithdrawOrder.php b/app/common/validate/WithdrawOrder.php new file mode 100644 index 0000000..5a3c01f --- /dev/null +++ b/app/common/validate/WithdrawOrder.php @@ -0,0 +1,25 @@ + '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'], + ]; +}