ShowHelper.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <?php
  2. namespace App\Module\Transfer\AdminControllers\Helper;
  3. use Dcat\Admin\Show;
  4. /**
  5. * 详情辅助类
  6. */
  7. class ShowHelper
  8. {
  9. /**
  10. * 配置订单详情显示
  11. *
  12. * @param Show $show
  13. * @return void
  14. */
  15. public static function orderShow(Show $show): void
  16. {
  17. // 基本信息面板
  18. $show->panel('基本信息', function (Show $show) {
  19. $show->field('id', '订单ID');
  20. $show->field('out_order_id', '外部订单ID');
  21. $show->field('transfer_app_id', '划转应用ID');
  22. $show->field('transferApp.title', '划转应用名称');
  23. $show->field('transferApp.keyname', '应用标识');
  24. });
  25. // 用户信息面板
  26. $show->panel('用户信息', function (Show $show) {
  27. $show->field('user_id', '内部用户ID');
  28. $show->field('out_user_id', '外部用户ID');
  29. $show->field('out_id', '外部应用ID');
  30. });
  31. // 订单信息面板
  32. $show->panel('订单信息', function (Show $show) {
  33. $show->field('type', '订单类型')->using([
  34. 1 => '转入',
  35. 2 => '转出'
  36. ])->label([
  37. 1 => 'success',
  38. 2 => 'warning'
  39. ]);
  40. $show->field('status', '订单状态')->using([
  41. 1 => '已创建',
  42. 20 => '处理中',
  43. 30 => '已回调',
  44. 100 => '已完成',
  45. -1 => '失败'
  46. ])->label([
  47. 1 => 'info',
  48. 20 => 'warning',
  49. 30 => 'primary',
  50. 100 => 'success',
  51. -1 => 'danger'
  52. ]);
  53. });
  54. // 金额信息面板
  55. $show->panel('金额信息', function (Show $show) {
  56. $show->field('amount', '内部金额')->as(function ($value) {
  57. return number_format($value, 10);
  58. });
  59. $show->field('out_amount', '外部金额')->as(function ($value) {
  60. return number_format($value, 10);
  61. });
  62. $show->field('exchange_rate', '汇率')->as(function ($value) {
  63. return number_format($value, 4);
  64. });
  65. $show->field('currency_id', '货币类型ID');
  66. $show->field('fund_id', '资金账户类型ID');
  67. });
  68. // 时间信息面板
  69. $show->panel('时间信息', function (Show $show) {
  70. $show->field('created_at', '创建时间');
  71. $show->field('processed_at', '处理时间');
  72. $show->field('callback_at', '回调时间');
  73. $show->field('completed_at', '完成时间');
  74. $show->field('updated_at', '更新时间');
  75. });
  76. // 附加信息面板
  77. $show->panel('附加信息', function (Show $show) {
  78. $show->field('remark', '备注');
  79. $show->field('error_message', '错误信息')->unescape();
  80. $show->field('callback_data', '回调数据')->json();
  81. });
  82. }
  83. /**
  84. * 配置应用详情显示
  85. *
  86. * @param Show $show
  87. * @return void
  88. */
  89. public static function appShow(Show $show): void
  90. {
  91. // 基本信息面板
  92. $show->panel('基本信息', function (Show $show) {
  93. $show->field('id', '应用ID');
  94. $show->field('keyname', '应用标识');
  95. $show->field('title', '应用名称');
  96. $show->field('description', '描述')->unescape();
  97. });
  98. // 外部应用信息面板
  99. $show->panel('外部应用信息', function (Show $show) {
  100. $show->field('out_id', '外部应用ID');
  101. $show->field('out_id2', '外部应用ID2');
  102. $show->field('out_id3', '外部应用ID3');
  103. });
  104. // 配置信息面板
  105. $show->panel('配置信息', function (Show $show) {
  106. $show->field('currency_id', '货币类型ID');
  107. $show->field('fund_id', '资金账户类型ID');
  108. $show->field('fund_to_uid', '转入目标账户UID');
  109. $show->field('fund_in_uid', '转入来源账户UID');
  110. $show->field('exchange_rate', '汇率')->as(function ($value) {
  111. return number_format($value, 4);
  112. });
  113. });
  114. // 状态信息面板
  115. $show->panel('状态信息', function (Show $show) {
  116. $show->field('is_enabled', '启用状态')->using([
  117. 1 => '启用',
  118. 0 => '禁用'
  119. ])->label([
  120. 1 => 'success',
  121. 0 => 'danger'
  122. ]);
  123. });
  124. // API配置面板
  125. $show->panel('API配置', function (Show $show) {
  126. $show->field('order_callback_url', '回调通知URL');
  127. $show->field('order_in_info_url', '转入查询URL');
  128. $show->field('order_out_create_url', '转出创建URL');
  129. $show->field('order_out_info_url', '转出查询URL');
  130. });
  131. // 时间信息面板
  132. $show->panel('时间信息', function (Show $show) {
  133. $show->field('created_at', '创建时间');
  134. $show->field('updated_at', '更新时间');
  135. $show->field('deleted_at', '删除时间');
  136. });
  137. // 统计信息面板
  138. $show->panel('统计信息', function (Show $show) {
  139. $show->field('orders_count', '总订单数')->as(function () {
  140. return $this->orders()->count();
  141. });
  142. $show->field('completed_orders_count', '已完成订单数')->as(function () {
  143. return $this->orders()->where('status', 100)->count();
  144. });
  145. $show->field('failed_orders_count', '失败订单数')->as(function () {
  146. return $this->orders()->where('status', -1)->count();
  147. });
  148. $show->field('total_amount', '总金额')->as(function () {
  149. return number_format($this->orders()->sum('amount'), 2);
  150. });
  151. });
  152. }
  153. /**
  154. * 配置详情页工具栏
  155. *
  156. * @param Show $show
  157. * @return void
  158. */
  159. public static function configureTools(Show $show): void
  160. {
  161. $show->tools(function (Show\Tools $tools) {
  162. // 添加自定义按钮
  163. $tools->append('<a class="btn btn-sm btn-outline-primary" href="javascript:history.back()">
  164. <i class="fa fa-arrow-left"></i> 返回
  165. </a>');
  166. });
  167. }
  168. /**
  169. * 配置关联数据显示
  170. *
  171. * @param Show $show
  172. * @param string $relation
  173. * @param string $title
  174. * @param callable $callback
  175. * @return void
  176. */
  177. public static function configureRelation(Show $show, string $relation, string $title, callable $callback): void
  178. {
  179. $show->relation($relation, $title, $callback);
  180. }
  181. /**
  182. * 添加自定义字段显示
  183. *
  184. * @param Show $show
  185. * @param string $field
  186. * @param string $label
  187. * @param callable|null $callback
  188. * @return void
  189. */
  190. public static function addCustomField(Show $show, string $field, string $label, ?callable $callback = null): void
  191. {
  192. $fieldObj = $show->field($field, $label);
  193. if ($callback) {
  194. $fieldObj->as($callback);
  195. }
  196. }
  197. }