| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- <?php
- namespace App\Module\Point\AdminControllers\Helper;
- use App\Module\Point\Enums\LOG_TYPE;
- use App\Module\Point\Enums\POINT_TYPE;
- /**
- * 表单辅助特性
- *
- * 提供积分模块后台控制器的表单构建功能的具体实现
- */
- trait FormHelperTrait
- {
- /**
- * 添加积分类型选择字段
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @param bool $required 是否必填
- * @return void
- */
- public function selectPointId(string $field = 'point_id', string $label = '积分类型', bool $required = true): void
- {
- $select = $this->form->select($field, $label)->options([
- 1 => '经验积分',
- 2 => '成就积分',
- 3 => '活动积分',
- 4 => '签到积分',
- 5 => '推荐积分',
- ]);
-
- if ($required) {
- $select->required();
- }
- }
- /**
- * 添加操作类型选择字段
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @param bool $required 是否必填
- * @return void
- */
- public function selectOperateType(string $field = 'operate_type', string $label = '操作类型', bool $required = true): void
- {
- $select = $this->form->select($field, $label)->options(LOG_TYPE::getAllTypes());
-
- if ($required) {
- $select->required();
- }
- }
- /**
- * 添加积分数量输入字段
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @param bool $required 是否必填
- * @param int $min 最小值
- * @return void
- */
- public function numberAmount(string $field = 'amount', string $label = '积分数量', bool $required = true, int $min = 0): void
- {
- $number = $this->form->number($field, $label)->min($min);
-
- if ($required) {
- $number->required();
- }
- }
- /**
- * 添加积分余额输入字段
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @param bool $required 是否必填
- * @param int $min 最小值
- * @return void
- */
- public function numberBalance(string $field = 'balance', string $label = '积分余额', bool $required = true, int $min = 0): void
- {
- $number = $this->form->number($field, $label)->min($min);
-
- if ($required) {
- $number->required();
- }
- }
- /**
- * 添加用户ID输入字段
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @param bool $required 是否必填
- * @return void
- */
- public function numberUserId(string $field = 'user_id', string $label = '用户ID', bool $required = true): void
- {
- $number = $this->form->number($field, $label)->min(1);
-
- if ($required) {
- $number->required();
- }
- }
- /**
- * 添加状态选择字段
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @param bool $required 是否必填
- * @return void
- */
- public function selectStatus(string $field = 'status', string $label = '状态', bool $required = true): void
- {
- $select = $this->form->select($field, $label)->options([
- 0 => '待处理',
- 1 => '已完成',
- 2 => '已失败',
- ]);
-
- if ($required) {
- $select->required();
- }
- }
- /**
- * 添加订单类型选择字段
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @param bool $required 是否必填
- * @return void
- */
- public function selectOrderType(string $field = 'order_type', string $label = '订单类型', bool $required = true): void
- {
- $select = $this->form->select($field, $label)->options([
- 'exchange' => '积分兑换',
- 'consume' => '积分消费',
- 'reward' => '积分奖励',
- 'refund' => '积分退款',
- ]);
-
- if ($required) {
- $select->required();
- }
- }
- /**
- * 添加备注文本域字段
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @param bool $required 是否必填
- * @param int $rows 行数
- * @return void
- */
- public function textareaRemark(string $field = 'remark', string $label = '备注', bool $required = false, int $rows = 3): void
- {
- $textarea = $this->form->textarea($field, $label)->rows($rows);
-
- if ($required) {
- $textarea->required();
- }
- }
- /**
- * 添加操作ID输入字段
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @param bool $required 是否必填
- * @return void
- */
- public function textOperateId(string $field = 'operate_id', string $label = '操作ID', bool $required = true): void
- {
- $text = $this->form->text($field, $label);
-
- if ($required) {
- $text->required();
- }
- }
- /**
- * 添加订单号输入字段
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @param bool $required 是否必填
- * @return void
- */
- public function textOrderNo(string $field = 'order_no', string $label = '订单号', bool $required = true): void
- {
- $text = $this->form->text($field, $label);
-
- if ($required) {
- $text->required();
- }
- }
- /**
- * 添加标题输入字段
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @param bool $required 是否必填
- * @return void
- */
- public function textTitle(string $field = 'title', string $label = '标题', bool $required = true): void
- {
- $text = $this->form->text($field, $label);
-
- if ($required) {
- $text->required();
- }
- }
- /**
- * 添加描述文本域字段
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @param bool $required 是否必填
- * @param int $rows 行数
- * @return void
- */
- public function textareaDescription(string $field = 'description', string $label = '描述', bool $required = false, int $rows = 4): void
- {
- $textarea = $this->form->textarea($field, $label)->rows($rows);
-
- if ($required) {
- $textarea->required();
- }
- }
- /**
- * 添加JSON数据文本域字段
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @param bool $required 是否必填
- * @param int $rows 行数
- * @return void
- */
- public function textareaJson(string $field, string $label, bool $required = false, int $rows = 5): void
- {
- $textarea = $this->form->textarea($field, $label)->rows($rows);
-
- if ($required) {
- $textarea->required();
- }
- }
- /**
- * 添加时间戳隐藏字段处理
- *
- * @return void
- */
- public function hiddenTimestamps(): void
- {
- $this->form->hidden('create_time');
- $this->form->hidden('update_time');
- }
- }
|