BoxRecordController.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Admin\Repositories\BoxRecord;
  4. use Dcat\Admin\Form;
  5. use Dcat\Admin\Grid;
  6. use Dcat\Admin\Show;
  7. use Dcat\Admin\Http\Controllers\AdminController;
  8. class BoxRecordController extends AdminController
  9. {
  10. /**
  11. * Make a grid builder.
  12. *
  13. * @return Grid
  14. */
  15. protected function grid()
  16. {
  17. return Grid::make(new BoxRecord(['account']), function (Grid $grid) {
  18. $grid->column('id')->sortable();
  19. $grid->column('account.uid','用户UID');
  20. $grid->column('account.avatar','用户头像')->image(config("filesystems.disks.cosv5.url"), 60, 60);
  21. $grid->column('account.username','用户名称')->display(function($v) {
  22. return "<a href='/admin/accounts?id={$this->account_id}' target='_blank'>{$v}</a>";
  23. });
  24. $grid->column('num');
  25. $grid->column('box_ids')->display(function($v) {
  26. return "点击查看(".($v? count(explode(",", $v)): 0).")";
  27. })->expand(function () {
  28. if($this->box_ids) {
  29. return \App\Admin\Renderable\BoxRecordAttiresTable::make(["ids"=>$this->box_ids]);
  30. }
  31. return "";
  32. });
  33. // $grid->column('attire_ids');
  34. $grid->column('retrieve_pasters');
  35. // $grid->column('retrieve_attire_ids');
  36. $grid->column('retrieve_box_ids')->display(function($v) {
  37. return "点击查看(".($v? count(explode(",", $v)):0).")";
  38. })->expand(function () {
  39. if($this->retrieve_box_ids) {
  40. return \App\Admin\Renderable\BoxRecordRetrieveAttiresTable::make(["ids"=>$this->retrieve_box_ids]);
  41. }
  42. return "";
  43. });
  44. $grid->column('cost_coupons');
  45. $grid->column('created_at');
  46. // $grid->column('updated_at')->sortable();
  47. $grid->model()->orderByDesc("id");
  48. $grid->disableActions();
  49. $grid->disableBatchDelete();
  50. $grid->disableRefreshButton();
  51. $grid->disableCreateButton();
  52. $grid->disableRowSelector();
  53. // $grid->simplePaginate();
  54. $grid->paginate(15);
  55. $grid->addTableClass(['table-text-center']);
  56. // $grid->disableToolbar();
  57. $grid->filter(function ($filter) {
  58. // 展开过滤器
  59. $filter->panel();
  60. $filter->expand();
  61. $filter->where('aid', function ($query) {
  62. $query->whereHas('account', function ($query) {
  63. $query->where('uid', $this->input);
  64. });
  65. }, '用户UID')->width(2);
  66. // $filter->equal('attire.cate', '类别')->select($this->cates)->width(2); // 设置编辑数据显示
  67. $filter->equal('account_id','用户名')->select(\App\Models\Account::pluck('username','id'))->width(2);
  68. });
  69. //
  70. $grid->export()->rows(function ($rows) {
  71. // dump($rows);
  72. foreach ($rows as &$row) {
  73. $tmp = $row->toArray();
  74. // dd($tmp);
  75. //
  76. $boxIds = explode(",", $tmp['box_ids']);
  77. if(count($boxIds)>0) {
  78. $tmp3 = \App\Models\GiftBox::withTrashed()
  79. ->whereIn('id', $boxIds)
  80. ->with(['attire'])
  81. ->get()
  82. ->toArray();
  83. }
  84. //
  85. $boxNames = [];
  86. foreach($tmp3 as $v) {
  87. $boxNames[] = $v['attire']['name'];
  88. }
  89. //
  90. $tmp['retrieve_box_ids'] = $tmp['retrieve_box_ids'] ?? "";
  91. $retrieveBoxIds = explode(",", $tmp['retrieve_box_ids']);
  92. if(count($retrieveBoxIds)>0) {
  93. $tmp2 = \App\Models\GiftBox::withTrashed()
  94. ->whereIn('id', $retrieveBoxIds)
  95. ->with(['attire'])
  96. ->get()
  97. ->toArray();
  98. }
  99. $retrieveNames = [];
  100. foreach($tmp2 as $v) {
  101. $retrieveNames[] = $v['attire']['name'];
  102. }
  103. //
  104. $tmp = array_column($tmp, null, 'id');
  105. //
  106. $row['account.username'] = $tmp['account']['username']?? '';
  107. $row['box_ids'] = implode("\r\n", $boxNames);
  108. $row['retrieve_box_ids'] = implode("\r\n", $retrieveNames);
  109. }
  110. //
  111. return $rows;
  112. });
  113. });
  114. }
  115. /**
  116. * Make a show builder.
  117. *
  118. * @param mixed $id
  119. *
  120. * @return Show
  121. */
  122. protected function detail($id)
  123. {
  124. return Show::make($id, new BoxRecord(), function (Show $show) {
  125. $show->field('id');
  126. $show->field('account_id');
  127. $show->field('num');
  128. $show->field('attire_ids');
  129. $show->field('retrieve_pasters');
  130. $show->field('retrieve_attire_ids');
  131. $show->field('cost_coupons');
  132. $show->field('created_at');
  133. $show->field('updated_at');
  134. });
  135. }
  136. /**
  137. * Make a form builder.
  138. *
  139. * @return Form
  140. */
  141. protected function form()
  142. {
  143. return Form::make(new BoxRecord(), function (Form $form) {
  144. $form->display('id');
  145. $form->text('account_id');
  146. $form->text('num');
  147. $form->text('attire_ids');
  148. $form->text('retrieve_pasters');
  149. $form->text('retrieve_attire_ids');
  150. $form->text('cost_coupons');
  151. $form->display('created_at');
  152. $form->display('updated_at');
  153. });
  154. }
  155. }