链街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.

100 lines
3.7 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. $model = $model::where('user_type', Type::USER_TYPE_STORE)->where('user_id',$userId);
  25. return Grid::make($model, function (Grid $grid) {
  26. $grid->column('id','ID');
  27. $grid->column('user_type','账户类型')->display(function($userType){
  28. $item = Type::USER_TYPE_LIST[$userType] ?? '';
  29. return $item;
  30. });
  31. $grid->column('money_type','流水类型')->display(function($moneyType){
  32. $item = Type::MONEY_TYPE_LIST[$moneyType] ?? '';
  33. return $item;
  34. });
  35. $grid->column('money','金额');
  36. $grid->column('current_balance','入账前余额');
  37. $grid->column('comment','描述')->width('16%');
  38. $grid->column('status','状态')
  39. ->using(
  40. FinancialRecord::$status
  41. )
  42. ->label(
  43. config('label.status_label')
  44. );
  45. $grid->column('created_at')->display(function($createdAt){
  46. return date('Y-m-d H:i:s',$createdAt);
  47. });
  48. // 搜索
  49. $grid->filter(function (Grid\Filter $filter){
  50. $userTypeList = Type::USER_TYPE_LIST;
  51. $moneyTypeList = Type::MONEY_TYPE_LIST;
  52. $sourceTYpeList = Type::SOURCE_TYPE_LIST;
  53. unset($userTypeList[0],$moneyTypeList[0]);
  54. $filter->equal('id','流水表ID')->width(3);
  55. $filter->equal('user_id','账户ID')->width(3);
  56. $filter->equal('current_balance','账户余额')->width(3);
  57. $filter->equal('money','流水金额')->width(3);
  58. $filter->equal('source_id','关联流水ID')->width(3);
  59. $filter->equal('money_type','流水类型')->select($moneyTypeList)->width(4);
  60. // $filter->equal('user_type','账户类型')->select($userTypeList)->width(4);
  61. $filter->equal('source_type','关联类型')->select($sourceTYpeList)->width(4);
  62. $filter->whereBetween('created_at',function($q){
  63. $start = $this->input['start'] ?? null;
  64. $end = $this->input['end'] ?? null;
  65. if($start !== null){
  66. $q->where('created_at','>=',strtotime($start));
  67. }
  68. if($end !== null){
  69. $q->where('created_at','<=',strtotime($end));
  70. }
  71. })->datetime()->width(7);
  72. });
  73. $grid->model()->orderBy('id','desc');
  74. // 每页10条
  75. $grid->paginate(10);
  76. $grid->disableActions();
  77. $grid->disableRowSelector();
  78. });
  79. }
  80. public function default()
  81. {
  82. // 获取外部传递的参数
  83. $userId = $this->payload['user_id'] ?? 0;
  84. return [
  85. 'user_id' => $userId,
  86. ];
  87. }
  88. }