| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- <?php
- namespace App\Module\Game\AdminControllers\Helper;
- use App\Module\Game\AdminControllers\LazyRenderable\GameConsumeGroupLazyRenderable;
- use App\Module\Game\AdminControllers\LazyRenderable\GameConditionGroupLazyRenderable;
- use App\Module\Game\AdminControllers\LazyRenderable\RewardGroupLazyRenderable;
- use App\Module\Game\Enums\REWARD_SOURCE_TYPE;
- use App\Module\Game\Enums\REWARD_TYPE;
- use App\Module\Game\Models\GameRewardGroup;
- use Dcat\Admin\Form;
- use Dcat\Admin\Form\Field;
- /**
- * 表单辅助特性
- *
- * 提供游戏模块后台控制器的表单构建功能的具体实现
- */
- trait FormHelperTrait
- {
- /**
- * 添加奖励类型选择
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @return Field\Select
- */
- public function selectRewardType(string $field = 'reward_type', string $label = '奖励类型'): Field\Select
- {
- return $this->form->select($field, $label)->options(REWARD_TYPE::getAll())->required();
- }
- /**
- * 添加奖励来源类型选择
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @return Field\Select
- */
- public function selectRewardSourceType(string $field = 'source_type', string $label = '奖励来源'): Field\Select
- {
- return $this->form->select($field, $label)->options(REWARD_SOURCE_TYPE::getValueDescription())->required();
- }
- /**
- * 添加奖励组选择
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @return Field\SelectTable
- */
- public function selectRewardGroup(string $field = 'group_id', string $label = '奖励组'): Field\SelectTable
- {
- $table = RewardGroupLazyRenderable::make();
- return $this->form->selectTable($field, $label)->from($table)
- ->title($label)
- ->model($table->getModel(), $table->getModelSelectId(), $table->getModelViewName());
- }
- /**
- * 添加消耗组选择
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @return Field\SelectTable
- */
- public function selectConsumeGroup(string $field = 'materials_group_id', string $label = '消耗组'): Field\SelectTable
- {
- $table = GameConsumeGroupLazyRenderable::make();
- return $this->form->selectTable($field, $label)->from($table)
- ->title($label)
- ->model($table->getModel(), $table->getModelSelectId(), $table->getModelViewName());
- }
- /**
- * 添加条件组选择
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @return Field\SelectTable
- */
- public function selectConditionGroup(string $field = 'conditions_group_id', string $label = '条件组'): Field\SelectTable
- {
- $table = GameConditionGroupLazyRenderable::make();
- return $this->form->selectTable($field, $label)->from($table)
- ->title($label)
- ->model($table->getModel(), $table->getModelSelectId(), $table->getModelViewName());
- }
- /**
- * 添加是否随机发放开关
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @return Field\Switch
- */
- public function switchIsRandom(string $field = 'is_random', string $label = '随机发放'): Field\Switch
- {
- return $this->form->switch($field, $label)->default(0);
- }
- /**
- * 添加随机数量输入
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @return Field\Number
- */
- public function numberRandomCount(string $field = 'random_count', string $label = '随机数量'): Field\Number
- {
- return $this->form->number($field, $label)->default(1)->min(1)->help('随机发放时的奖励数量,仅当随机发放开启时有效');
- }
- /**
- * 添加是否必中开关
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @return Field\Switch
- */
- public function switchIsGuaranteed(string $field = 'is_guaranteed', string $label = '必中'): Field\Switch
- {
- return $this->form->switch($field, $label)->default(0);
- }
- /**
- * 添加权重输入
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @return Field\Number
- */
- public function numberWeight(string $field = 'weight', string $label = '权重'): Field\Number
- {
- return $this->form->number($field, $label)->default(100)->min(1)->help('权重越高,被选中的概率越大');
- }
- /**
- * 添加目标ID输入
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @return Field\Text
- */
- public function textTargetId(string $field = 'target_id', string $label = '目标ID'): Field\Text
- {
- return $this->form->text($field, $label)->required()->help('根据奖励类型,填写对应的物品ID、货币ID等');
- }
- /**
- * 添加参数1输入
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @return Field\Text
- */
- public function textParam1(string $field = 'param1', string $label = '参数1'): Field\Text
- {
- return $this->form->text($field, $label)->default(0)->help('可选参数,根据奖励类型使用');
- }
- /**
- * 添加参数2输入
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @return Field\Text
- */
- public function textParam2(string $field = 'param2', string $label = '参数2'): Field\Text
- {
- return $this->form->text($field, $label)->default(0)->help('可选参数,根据奖励类型使用');
- }
- /**
- * 添加数量输入
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @return Field\Number
- */
- public function numberQuantity(string $field = 'quantity', string $label = '数量'): Field\Number
- {
- return $this->form->number($field, $label)->default(1)->min(1)->required();
- }
- /**
- * 添加奖励项表格
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @return Field\Table
- */
- public function tableRewardItems(string $field = 'items', string $label = '奖励项'): Field\Table
- {
- return $this->form->table($field, $label, function (Form\NestedForm $table) {
- $table->select('reward_type', '奖励类型')->options(REWARD_TYPE::getAll())->required();
- $table->text('target_id', '目标ID')->required()->help('根据奖励类型,填写对应的物品ID、货币ID等');
- $table->text('param1', '参数1')->default(0)->help('可选参数,根据奖励类型使用');
- $table->text('param2', '参数2')->default(0)->help('可选参数,根据奖励类型使用');
- $table->number('quantity', '数量')->default(1)->min(1)->required();
- $table->number('weight', '权重')->default(100)->min(1);
- $table->switch('is_guaranteed', '必中')->default(0);
- });
- }
- }
|