| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- <?php
- namespace App\Admin\Controllers;
- use App\Admin\Repositories\BoxRecord;
- use Dcat\Admin\Form;
- use Dcat\Admin\Grid;
- use Dcat\Admin\Show;
- use Dcat\Admin\Http\Controllers\AdminController;
- class BoxRecordController extends AdminController
- {
- /**
- * Make a grid builder.
- *
- * @return Grid
- */
- protected function grid()
- {
- return Grid::make(new BoxRecord(['account']), function (Grid $grid) {
- $grid->column('id')->sortable();
- $grid->column('account.uid','用户UID');
- $grid->column('account.avatar','用户头像')->image(config("filesystems.disks.cosv5.url"), 60, 60);
- $grid->column('account.username','用户名称')->display(function($v) {
- return "<a href='/admin/accounts?id={$this->account_id}' target='_blank'>{$v}</a>";
- });
- $grid->column('num');
- $grid->column('box_ids')->display(function($v) {
- return "点击查看(".($v? count(explode(",", $v)): 0).")";
- })->expand(function () {
- if($this->box_ids) {
- return \App\Admin\Renderable\BoxRecordAttiresTable::make(["ids"=>$this->box_ids]);
- }
- return "";
- });
- // $grid->column('attire_ids');
- $grid->column('retrieve_pasters');
- // $grid->column('retrieve_attire_ids');
- $grid->column('retrieve_box_ids')->display(function($v) {
- return "点击查看(".($v? count(explode(",", $v)):0).")";
- })->expand(function () {
- if($this->retrieve_box_ids) {
- return \App\Admin\Renderable\BoxRecordRetrieveAttiresTable::make(["ids"=>$this->retrieve_box_ids]);
- }
- return "";
- });
- $grid->column('cost_coupons');
- $grid->column('created_at');
- // $grid->column('updated_at')->sortable();
-
- $grid->model()->orderByDesc("id");
- $grid->disableActions();
- $grid->disableBatchDelete();
- $grid->disableRefreshButton();
- $grid->disableCreateButton();
- $grid->disableRowSelector();
- // $grid->simplePaginate();
- $grid->paginate(15);
- $grid->addTableClass(['table-text-center']);
- // $grid->disableToolbar();
- $grid->filter(function ($filter) {
- // 展开过滤器
- $filter->panel();
- $filter->expand();
- $filter->where('aid', function ($query) {
- $query->whereHas('account', function ($query) {
- $query->where('uid', $this->input);
- });
- }, '用户UID')->width(2);
- // $filter->equal('attire.cate', '类别')->select($this->cates)->width(2); // 设置编辑数据显示
- $filter->equal('account_id','用户名')->select(\App\Models\Account::pluck('username','id'))->width(2);
- });
- //
- $grid->export()->rows(function ($rows) {
- // dump($rows);
- foreach ($rows as &$row) {
- $tmp = $row->toArray();
- // dd($tmp);
- //
- $boxIds = explode(",", $tmp['box_ids']);
- if(count($boxIds)>0) {
- $tmp3 = \App\Models\GiftBox::withTrashed()
- ->whereIn('id', $boxIds)
- ->with(['attire'])
- ->get()
- ->toArray();
- }
- //
- $boxNames = [];
- foreach($tmp3 as $v) {
- $boxNames[] = $v['attire']['name'];
- }
- //
- $tmp['retrieve_box_ids'] = $tmp['retrieve_box_ids'] ?? "";
- $retrieveBoxIds = explode(",", $tmp['retrieve_box_ids']);
- if(count($retrieveBoxIds)>0) {
- $tmp2 = \App\Models\GiftBox::withTrashed()
- ->whereIn('id', $retrieveBoxIds)
- ->with(['attire'])
- ->get()
- ->toArray();
- }
- $retrieveNames = [];
- foreach($tmp2 as $v) {
- $retrieveNames[] = $v['attire']['name'];
- }
- //
- $tmp = array_column($tmp, null, 'id');
- //
- $row['account.username'] = $tmp['account']['username']?? '';
- $row['box_ids'] = implode("\r\n", $boxNames);
- $row['retrieve_box_ids'] = implode("\r\n", $retrieveNames);
- }
- //
- return $rows;
- });
- });
- }
- /**
- * Make a show builder.
- *
- * @param mixed $id
- *
- * @return Show
- */
- protected function detail($id)
- {
- return Show::make($id, new BoxRecord(), function (Show $show) {
- $show->field('id');
- $show->field('account_id');
- $show->field('num');
- $show->field('attire_ids');
- $show->field('retrieve_pasters');
- $show->field('retrieve_attire_ids');
- $show->field('cost_coupons');
- $show->field('created_at');
- $show->field('updated_at');
- });
- }
- /**
- * Make a form builder.
- *
- * @return Form
- */
- protected function form()
- {
- return Form::make(new BoxRecord(), function (Form $form) {
- $form->display('id');
- $form->text('account_id');
- $form->text('num');
- $form->text('attire_ids');
- $form->text('retrieve_pasters');
- $form->text('retrieve_attire_ids');
- $form->text('cost_coupons');
-
- $form->display('created_at');
- $form->display('updated_at');
- });
- }
- }
|