UserConsumeRecordController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace App\Admin\Controllers\Order;
  3. use App\Models\UserConsumeRecord;
  4. use Dcat\Admin\Form;
  5. use Dcat\Admin\Grid;
  6. use Dcat\Admin\Show;
  7. use Dcat\Admin\Http\Controllers\AdminController;
  8. class UserConsumeRecordController extends AdminController
  9. {
  10. /**
  11. * Make a grid builder.
  12. *
  13. * @return Grid
  14. */
  15. protected function grid()
  16. {
  17. return Grid::make(UserConsumeRecord::with(['user.info']), function (Grid $grid) {
  18. $grid->model()->orderByDesc('created_at');
  19. $grid->column('id')->sortable();
  20. $grid->column('user_id', '用户')->display(function () {
  21. $str = '';
  22. $str .= "<div style='margin-right:10px;display: flex;align-items: center'>";
  23. $str .= '<img data-action="preview-img" src="' . $this->user->avatar . '" onerror="this.src=\'https://fourtiao.oss-cn-beijing.aliyuncs.com/zhangsiye/images/6b40343b27263be34cf3212bf44f74c3.png\'" style="height:50px;width:50px;cursor:pointer;margin-right:10px;" class="img img-thumbnail">';
  24. $str .= '<div>';
  25. $str .= '<p style="margin-bottom: 5px">' . $this->user->nickname . '</p>';
  26. $str .= '<p style="margin-bottom: 0px">' . $this->user->mobile . '</p>';
  27. $str .= '</div>';
  28. $str .= '</div>';
  29. return $str;
  30. });
  31. $grid->column('user.info.platform', '所属平台')
  32. ->using(config('global.platform'))
  33. ->label([1 => 'primary', 2 => 'success', 3 => 'info']);
  34. $grid->column('type')
  35. ->using(config('global.consume_type'))
  36. ->label(['success', 'info', 'primary']);
  37. $grid->column('before')->label('info');
  38. $grid->column('change')->display(function () {
  39. return $this->change > 0 ? '+' . $this->change : $this->change;
  40. })->label('danger');
  41. $grid->column('current')->label('success');
  42. $grid->column('remark');
  43. $grid->column('created_at');
  44. $grid->filter(function (Grid\Filter $filter) {
  45. $filter->panel();
  46. $filter->like('user.nickname', '昵称')->width(3);
  47. $filter->equal('user.info.platform', '所属平台')->select(config('global.platform'))->width(3);
  48. $filter->equal('type', '类型')->select(config('global.consume_type'))->width(3);
  49. $filter->between('created_at', '创建时间')->datetime()->width(3);
  50. });
  51. $grid->disableCreateButton();
  52. $grid->disableRowSelector();
  53. $grid->disableActions();
  54. });
  55. }
  56. /**
  57. * Make a show builder.
  58. *
  59. * @return Show
  60. */
  61. protected function detail($id)
  62. {
  63. return Show::make($id, new UserConsumeRecord(), function (Show $show) {
  64. $show->field('id');
  65. $show->field('user_id');
  66. $show->field('type');
  67. $show->field('before');
  68. $show->field('change');
  69. $show->field('current');
  70. $show->field('remark');
  71. $show->field('order_id');
  72. $show->field('created_at');
  73. $show->field('updated_at');
  74. });
  75. }
  76. /**
  77. * Make a form builder.
  78. *
  79. * @return Form
  80. */
  81. protected function form()
  82. {
  83. return Form::make(new UserConsumeRecord(), function (Form $form) {
  84. $form->display('id');
  85. $form->text('user_id');
  86. $form->text('type');
  87. $form->text('before');
  88. $form->text('change');
  89. $form->text('current');
  90. $form->text('remark');
  91. $form->text('order_id');
  92. $form->display('created_at');
  93. $form->display('updated_at');
  94. });
  95. }
  96. }