链街Dcat后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
3.6 KiB

  1. <?php
  2. namespace App\Admin\Renderable;
  3. use Dcat\Admin\Grid;
  4. use App\Admin\Common\Type;
  5. use App\Admin\Repositories\CommonEmpty;
  6. use Dcat\Admin\Grid\LazyRenderable;
  7. use App\Models\FinancialRecord;
  8. class StoreBalance extends LazyRenderable
  9. {
  10. protected $title = '商户余额明细';
  11. public function grid(): Grid
  12. {
  13. // 获取外部传递的参数
  14. $userId = $this->user_id ?? 0;
  15. $model = FinancialRecord::getFinancialRecordModel($userId);
  16. if(!$model){
  17. return Grid::make(new CommonEmpty(), function (Grid $grid) {
  18. $grid->column('id','商 户 未 绑 定 提 现 用 户 懒 ID !');
  19. $grid->disableRowSelector();
  20. $grid->disableActions();
  21. $grid->disablePagination();
  22. });
  23. }
  24. return Grid::make($model, function (Grid $grid) {
  25. $grid->column('id','ID');
  26. $grid->column('user_type','账户类型')->display(function($userType){
  27. $item = Type::USER_TYPE_LIST[$userType] ?? '';
  28. return $item;
  29. });
  30. $grid->column('money_type','流水类型')->display(function($moneyType){
  31. $item = Type::MONEY_TYPE_LIST[$moneyType] ?? '';
  32. return $item;
  33. });
  34. $grid->column('money','金额');
  35. $grid->column('current_balance','账户余额');
  36. $grid->column('comment','描述');
  37. $grid->column('status','状态')
  38. ->using(
  39. FinancialRecord::$status
  40. )
  41. ->label(
  42. config('label.status_label')
  43. );
  44. $grid->column('created_at')->display(function($createdAt){
  45. return date('Y-m-d H:i:s',$createdAt);
  46. });
  47. // 搜索
  48. $grid->filter(function (Grid\Filter $filter){
  49. $userTypeList = Type::USER_TYPE_LIST;
  50. $moneyTypeList = Type::MONEY_TYPE_LIST;
  51. $sourceTYpeList = Type::SOURCE_TYPE_LIST;
  52. unset($userTypeList[0],$moneyTypeList[0]);
  53. $filter->equal('id','流水表ID')->width(3);
  54. $filter->equal('user_id','账户ID')->width(3);
  55. $filter->equal('current_balance','账户余额')->width(3);
  56. $filter->equal('money','流水金额')->width(3);
  57. $filter->equal('source_id','关联流水ID')->width(3);
  58. $filter->equal('money_type','流水类型')->select($userTypeList)->width(4);
  59. $filter->equal('user_type','账户类型')->select($moneyTypeList)->width(4);
  60. $filter->equal('source_type','关联类型')->select($sourceTYpeList)->width(4);
  61. $filter->whereBetween('created_at',function($q){
  62. $start = $this->input['start'] ?? null;
  63. $end = $this->input['end'] ?? null;
  64. if($start !== null){
  65. $q->where('created_at','>=',strtotime($start));
  66. }
  67. if($end !== null){
  68. $q->where('created_at','<=',strtotime($end));
  69. }
  70. })->datetime()->width(7);
  71. });
  72. $grid->model()->orderBy('id','desc');
  73. // 每页10条
  74. $grid->paginate(10);
  75. $grid->disableActions();
  76. $grid->disableRowSelector();
  77. });
  78. }
  79. public function default()
  80. {
  81. // 获取外部传递的参数
  82. $userId = $this->payload['user_id'] ?? 0;
  83. return [
  84. 'user_id' => $userId,
  85. ];
  86. }
  87. }