| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- <?php
- namespace App\Module\Point\AdminControllers\Helper;
- use App\Module\Point\Enums\LOG_TYPE;
- use App\Module\Point\Enums\POINT_TYPE;
- /**
- * 详情页辅助特性
- *
- * 提供积分模块后台控制器的详情页构建功能的具体实现
- */
- trait ShowHelperTrait
- {
- /**
- * 添加积分类型字段
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @return void
- */
- public function fieldPointId(string $field = 'point_id', string $label = '积分类型'): void
- {
- $this->show->field($field, $label)->using([
- 1 => '经验积分',
- 2 => '成就积分',
- 3 => '活动积分',
- 4 => '签到积分',
- 5 => '推荐积分',
- ]);
- }
- /**
- * 添加操作类型字段
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @return void
- */
- public function fieldOperateType(string $field = 'operate_type', string $label = '操作类型'): void
- {
- $this->show->field($field, $label)->using(LOG_TYPE::getAllTypes());
- }
- /**
- * 添加积分余额字段
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @return void
- */
- public function fieldBalance(string $field = 'balance', string $label = '积分余额'): void
- {
- $this->show->field($field, $label)->as(function ($value) {
- return number_format($value);
- });
- }
- /**
- * 添加积分数量字段
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @return void
- */
- public function fieldAmount(string $field = 'amount', string $label = '积分数量'): void
- {
- $this->show->field($field, $label)->as(function ($value) {
- $formattedValue = number_format(abs($value));
-
- if ($value > 0) {
- return "+{$formattedValue}";
- } elseif ($value < 0) {
- return "-{$formattedValue}";
- } else {
- return $formattedValue;
- }
- });
- }
- /**
- * 添加时间戳字段
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @param string $format 日期格式
- * @return void
- */
- public function fieldTimestamp(string $field, string $label, string $format = 'Y-m-d H:i:s'): void
- {
- $this->show->field($field, $label)->as(function ($value) use ($format) {
- return $value ? date($format, $value) : '';
- });
- }
- /**
- * 添加状态字段
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @return void
- */
- public function fieldStatus(string $field = 'status', string $label = '状态'): void
- {
- $this->show->field($field, $label)->using([
- 0 => '待处理',
- 1 => '已完成',
- 2 => '已失败',
- ]);
- }
- /**
- * 添加订单类型字段
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @return void
- */
- public function fieldOrderType(string $field = 'order_type', string $label = '订单类型'): void
- {
- $this->show->field($field, $label)->using([
- 'exchange' => '积分兑换',
- 'consume' => '积分消费',
- 'reward' => '积分奖励',
- 'refund' => '积分退款',
- ]);
- }
- /**
- * 添加JSON数据字段
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @return void
- */
- public function fieldJson(string $field, string $label): void
- {
- $this->show->field($field, $label)->as(function ($value) {
- if (is_array($value)) {
- return '<pre>' . json_encode($value, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . '</pre>';
- }
- return $value;
- });
- }
- /**
- * 添加积分流转信息字段
- *
- * @param string $label 标签名
- * @return void
- */
- public function fieldCirculationInfo(string $label = '流转信息'): void
- {
- $this->show->field('user_id', $label)->as(function ($userId) {
- $fromPointId = $this->from_point_id;
- $toPointId = $this->to_point_id;
-
- $pointTypes = [
- 1 => '经验积分',
- 2 => '成就积分',
- 3 => '活动积分',
- 4 => '签到积分',
- 5 => '推荐积分',
- ];
-
- if (is_object($fromPointId)) {
- $fromPointId = $fromPointId->value;
- }
- if (is_object($toPointId)) {
- $toPointId = $toPointId->value;
- }
-
- $fromPointName = $pointTypes[$fromPointId] ?? "积分{$fromPointId}";
- $toPointName = $pointTypes[$toPointId] ?? "积分{$toPointId}";
-
- return "用户: {$userId}<br>从: {$fromPointName}<br>到: {$toPointName}";
- });
- }
- /**
- * 添加积分转账信息字段
- *
- * @param string $label 标签名
- * @return void
- */
- public function fieldTransferInfo(string $label = '转账信息'): void
- {
- $this->show->field('from_user_id', $label)->as(function ($fromUserId) {
- $toUserId = $this->to_user_id;
- $pointId = $this->point_id;
-
- $pointTypes = [
- 1 => '经验积分',
- 2 => '成就积分',
- 3 => '活动积分',
- 4 => '签到积分',
- 5 => '推荐积分',
- ];
-
- if (is_object($pointId)) {
- $pointId = $pointId->value;
- }
-
- $pointName = $pointTypes[$pointId] ?? "积分{$pointId}";
-
- return "从: 用户{$fromUserId}<br>到: 用户{$toUserId}<br>类型: {$pointName}";
- });
- }
- /**
- * 添加积分数量格式化字段
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @return void
- */
- public function fieldPoints(string $field, string $label): void
- {
- $this->show->field($field, $label)->as(function ($value) {
- return number_format($value);
- });
- }
- }
|