UserConsumeRecordController.php 3.8 KB

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