ShowHelperTrait.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. namespace App\Module\Activity\AdminControllers\Helper;
  3. use App\Module\Activity\Enums\ACTIVITY_STATUS;
  4. use App\Module\Activity\Enums\ACTIVITY_TYPE;
  5. use App\Module\Activity\Enums\CONDITION_TYPE;
  6. use App\Module\Activity\Enums\PARTICIPATION_STATUS;
  7. use App\Module\Activity\Enums\REWARD_STATUS;
  8. use App\Module\Game\Enums\REWARD_TYPE;
  9. use App\Module\Game\Enums\REWARD_SOURCE_TYPE;
  10. use Dcat\Admin\Show;
  11. /**
  12. * 详情页辅助特性
  13. *
  14. * 提供活动模块后台控制器的详情页构建功能的具体实现
  15. */
  16. trait ShowHelperTrait
  17. {
  18. /**
  19. * 显示活动状态
  20. *
  21. * @param string $field 字段名
  22. * @param string $label 标签名
  23. * @return Show\Field
  24. */
  25. public function fieldActivityStatus(string $field = 'status', string $label = '活动状态'): Show\Field
  26. {
  27. return $this->show->field($field, $label)->using(ACTIVITY_STATUS::getAll());
  28. }
  29. /**
  30. * 显示活动类型
  31. *
  32. * @param string $field 字段名
  33. * @param string $label 标签名
  34. * @return Show\Field
  35. */
  36. public function fieldActivityType(string $field = 'type', string $label = '活动类型'): Show\Field
  37. {
  38. return $this->show->field($field, $label)->using(ACTIVITY_TYPE::getAll());
  39. }
  40. /**
  41. * 显示条件类型
  42. *
  43. * @param string $field 字段名
  44. * @param string $label 标签名
  45. * @return Show\Field
  46. */
  47. public function fieldConditionType(string $field = 'condition_type', string $label = '条件类型'): Show\Field
  48. {
  49. return $this->show->field($field, $label)->using(CONDITION_TYPE::getAll());
  50. }
  51. /**
  52. * 显示参与状态
  53. *
  54. * @param string $field 字段名
  55. * @param string $label 标签名
  56. * @return Show\Field
  57. */
  58. public function fieldParticipationStatus(string $field = 'completion_status', string $label = '参与状态'): Show\Field
  59. {
  60. return $this->show->field($field, $label)->using(PARTICIPATION_STATUS::getAll());
  61. }
  62. /**
  63. * 显示奖励状态
  64. *
  65. * @param string $field 字段名
  66. * @param string $label 标签名
  67. * @return Show\Field
  68. */
  69. public function fieldRewardStatus(string $field = 'reward_status', string $label = '奖励状态'): Show\Field
  70. {
  71. return $this->show->field($field, $label)->using(REWARD_STATUS::getAll());
  72. }
  73. /**
  74. * 显示奖励类型
  75. *
  76. * @param string $field 字段名
  77. * @param string $label 标签名
  78. * @return Show\Field
  79. */
  80. public function fieldRewardType(string $field = 'reward_type', string $label = '奖励类型'): Show\Field
  81. {
  82. return $this->show->field($field, $label)->using(REWARD_TYPE::getAll());
  83. }
  84. /**
  85. * 显示奖励来源类型
  86. *
  87. * @param string $field 字段名
  88. * @param string $label 标签名
  89. * @return Show\Field
  90. */
  91. public function fieldRewardSourceType(string $field = 'source_type', string $label = '奖励来源'): Show\Field
  92. {
  93. return $this->show->field($field, $label)->using(REWARD_SOURCE_TYPE::getValueDescription());
  94. }
  95. /**
  96. * 显示活动时间范围
  97. *
  98. * @param string $startField 开始时间字段
  99. * @param string $endField 结束时间字段
  100. * @param string $label 标签名
  101. * @return Show\Field
  102. */
  103. public function fieldActivityTimeRange(string $startField = 'start_time', string $endField = 'end_time', string $label = '活动时间'): Show\Field
  104. {
  105. return $this->show->field($startField, $label)->as(function ($startTime) use ($endField) {
  106. $endTime = $this->{$endField};
  107. return date('Y-m-d H:i:s', strtotime($startTime)) . ' 至 ' . date('Y-m-d H:i:s', strtotime($endTime));
  108. });
  109. }
  110. /**
  111. * 显示活动配置
  112. *
  113. * @param string $field 字段名
  114. * @param string $label 标签名
  115. * @return Show\Field
  116. */
  117. public function fieldActivityConfig(string $field = 'config', string $label = '活动配置'): Show\Field
  118. {
  119. return $this->show->field($field, $label)->json();
  120. }
  121. /**
  122. * 显示活动条件
  123. *
  124. * @param string $field 字段名
  125. * @param string $label 标签名
  126. * @return Show\Field
  127. */
  128. public function fieldActivityConditions(string $field = 'conditions', string $label = '活动条件'): Show\Field
  129. {
  130. return $this->show->field($field, $label)->json();
  131. }
  132. /**
  133. * 显示活动奖励
  134. *
  135. * @param string $field 字段名
  136. * @param string $label 标签名
  137. * @return Show\Field
  138. */
  139. public function fieldActivityRewards(string $field = 'rewards', string $label = '活动奖励'): Show\Field
  140. {
  141. return $this->show->field($field, $label)->json();
  142. }
  143. }