form->select($field, $label) ->options(AccountService::getFundsDesc()) ->required(); } /** * 添加操作类型选择 * * 复用价值:高 - 统一处理操作类型的选择,使用枚举类型 * * @param string $field 字段名 * @param string $label 标签名 * @return Field\Select */ public function selectOperateType(string $field = 'operate_type', string $label = '操作类型'): Field\Select { return $this->form->select($field, $label) ->options(LOG_TYPE::getValueDescription()) ->required(); } /** * 添加资金类型选择 * * 复用价值:高 - 统一处理资金类型的选择,使用枚举类型 * * @param string $field 字段名 * @param string $label 标签名 * @return Field\Select */ public function selectFundType(string $field = 'fund_type', string $label = '资金类型'): Field\Select { return $this->form->select($field, $label) ->options(FUND_TYPE::getValueDescription()) ->required(); } /** * 添加金额输入(元转毫) * * 复用价值:高 - 统一处理金额的输入,包括单位转换和验证 * * @param string $field 字段名 * @param string $label 标签名 * @param bool $required 是否必填 * @return Field\Text */ public function textAmount(string $field = 'amount', string $label = '金额', bool $required = true): Field\Text { $field = $this->form->text($field, $label) ->help('金额,单位为元,系统会自动转换为毫') ->saving(function ($value) { return $value * 1000; }); if ($required) { $field->required(); } return $field; } /** * 添加转账表单组 * * 复用价值:高 - 提供完整的转账表单组,包括来源账户、目标账户、金额等 * * @return void */ public function addTransferFields(): void { $this->form->divider('转账信息'); $this->form->number('user_id', '来源用户ID') ->required() ->min(1) ->help('来源用户ID,必须是有效的用户'); $this->selectFundId('fund_id', '来源资金账户'); $this->form->number('to_user_id', '目标用户ID') ->required() ->min(1) ->help('目标用户ID,必须是有效的用户'); $this->selectFundId('to_fund_id', '目标资金账户'); $this->textAmount('amount', '转账金额'); $this->form->textarea('remark', '备注') ->rows(3); } /** * 添加资金操作表单组 * * 复用价值:高 - 提供完整的资金操作表单组,包括用户、账户、金额、操作类型等 * * @param bool $isDeduct 是否为扣除操作 * @return void */ public function addFundOperationFields(bool $isDeduct = false): void { $this->form->divider('资金操作信息'); $this->form->number('user_id', '用户ID') ->required() ->min(1) ->help('用户ID,必须是有效的用户'); $this->selectFundId('fund_id', '资金账户'); $amountLabel = $isDeduct ? '扣除金额' : '增加金额'; $this->textAmount('amount', $amountLabel) ->saving(function ($value) use ($isDeduct) { return $isDeduct ? -abs($value * 1000) : abs($value * 1000); }); $this->selectOperateType('operate_type', '操作类型'); $this->form->textarea('remark', '备注') ->rows(3); } }