WxUsedGoodController.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. namespace App\Admin\Controllers\Used;
  3. use App\Admin\Actions\Grid\UsedGoodsPassAction;
  4. use App\Admin\Repositories\Used\WxUsedGood;
  5. use App\Models\Used\WxUsedClassify;
  6. use App\Wen\Utils\FieldUtils;
  7. use App\Wen\Utils\Settings;
  8. use Dcat\Admin\Form;
  9. use Dcat\Admin\Grid;
  10. use Dcat\Admin\Show;
  11. use Dcat\Admin\Http\Controllers\AdminController;
  12. class WxUsedGoodController extends AdminController
  13. {
  14. /**
  15. * Make a grid builder.
  16. *
  17. * @return Grid
  18. */
  19. protected function grid()
  20. {
  21. return Grid::make(new WxUsedGood(), function (Grid $grid) {
  22. $grid->column('id')->sortable();
  23. $grid->model()->orderBy('id', 'desc');
  24. $grid->quickSearch(['id', 'title', 'detail', 'classify_id','user_id','user.user_name'])->placeholder('搜索ID,标题,简介,用户ID,用户名字,二手分类ID...')->width(50);
  25. $grid->column('owers', '头像')->display(function ($v) {
  26. return '<img src="' . ($this->ower['user_avatar'] ?? Settings::get('img_default', 'https://img.mini.minisns.cn/icons/dafault.png')) . '" style="border-radius:50px;width:30px;" />';
  27. })->width('50px');
  28. $grid->column('ower', '用户名称')->display(function ($v) {
  29. if($v && $v['user_name']){
  30. return '<a target="_blank" href="'.admin_url('users?id='.$v['id']).'">'.$v['user_name'].'</a>' ?? '用户已删除';
  31. }
  32. return '用户已删除';
  33. })->width('100px');
  34. $grid->column('title')->limit(20);
  35. $grid->column('detail')->limit(40);
  36. $grid->column('classify_id')->display(function ($v){
  37. if($v > 0){
  38. return $v;
  39. }
  40. return '';
  41. })->sortable();
  42. $grid->column('price')->sortable();
  43. $grid->column('original_price')->sortable();
  44. $grid->column('is_self_pickup')->using([0 => '', 1 => '是'])->sortable();
  45. $grid->column('is_express_delivery')->using([0 => '', 1 => '是'])->sortable();
  46. $grid->column('express_cost')->sortable();
  47. // $grid->column('image_urls');
  48. // $grid->column('longitude');
  49. // $grid->column('latitude');
  50. // $grid->column('address_name');
  51. // $grid->column('address_detailed');
  52. // $grid->column('ip');
  53. // $grid->column('country');
  54. // $grid->column('province');
  55. // $grid->column('city');
  56. // $grid->column('district');
  57. $grid->column('status')->using(FieldUtils::usedGoodState())->label([
  58. 0 => 'red',
  59. 1 => 'green',
  60. 2 => 'default',
  61. 3 => '#4e9876',
  62. 4 => 'default',
  63. 5 => '#21b978',
  64. 6 => 'default',
  65. 7 => 'default'
  66. ])->sortable();;
  67. $grid->column('created_at')->sortable();
  68. // $grid->column('updated_at')->sortable();
  69. $grid->filter(function (Grid\Filter $filter) {
  70. $filter->equal('id');
  71. });
  72. $grid->batchActions(function ($batch) {
  73. $batch->add(new UsedGoodsPassAction());
  74. });
  75. $grid->disableViewButton();
  76. $grid->filter(function (Grid\Filter $filter) {
  77. $filter->equal('user_id');
  78. $filter->equal('classify_id')->select(WxUsedClassify::where('status', 1)->orderByDesc('order')->orderByDesc('id')->pluck('name', 'id'));
  79. $filter->between('created_at')->date();
  80. });
  81. $grid->disableCreateButton();
  82. // $grid->disableActions();
  83. // 禁用编辑按钮
  84. });
  85. }
  86. /**
  87. * Make a show builder.
  88. *
  89. * @param mixed $id
  90. *
  91. * @return Show
  92. */
  93. protected function detail($id)
  94. {
  95. return Show::make($id, new WxUsedGood(), function (Show $show) {
  96. $show->field('id');
  97. $show->field('user_id');
  98. $show->field('title');
  99. $show->field('detail');
  100. $show->field('classify_id');
  101. $show->field('price');
  102. $show->field('original_price');
  103. $show->field('is_self_pickup');
  104. $show->field('is_express_delivery');
  105. $show->field('express_cost');
  106. $show->field('image_urls');
  107. $show->field('longitude');
  108. $show->field('latitude');
  109. $show->field('address_name');
  110. $show->field('address_detailed');
  111. $show->field('ip');
  112. $show->field('country');
  113. $show->field('province');
  114. $show->field('city');
  115. $show->field('district');
  116. $show->field('status');
  117. $show->field('created_at');
  118. $show->field('updated_at');
  119. });
  120. }
  121. /**
  122. * Make a form builder.
  123. *
  124. * @return Form
  125. */
  126. protected function form()
  127. {
  128. return Form::make(new WxUsedGood(), function (Form $form) {
  129. $form->display('id');
  130. // $form->text('user_id');
  131. $form->text('title');
  132. $form->textarea('detail');
  133. $form->select('classify_id')->options(WxUsedClassify::where('status', 1)->orderByDesc('order')->orderByDesc('id')->pluck('name', 'id'));
  134. $form->text('price');
  135. $form->text('original_price');
  136. // $form->text('is_self_pickup');
  137. // $form->text('is_express_delivery');
  138. $form->text('express_cost');
  139. // $form->text('image_urls');
  140. // $form->text('longitude');
  141. // $form->text('latitude');
  142. // $form->text('address_name');
  143. // $form->text('address_detailed');
  144. // $form->text('ip');
  145. // $form->text('country');
  146. // $form->text('province');
  147. // $form->text('city');
  148. // $form->text('district');
  149. // $form->text('status');
  150. $form->display('created_at');
  151. $form->display('updated_at');
  152. $form->deleting(function (Form $form){
  153. global $__MINI_GLOBAL_TENANT_ID__;
  154. if($__MINI_GLOBAL_TENANT_ID__ > 0){
  155. return $form->response()->error('权限不足,不可以删除其他分站对象');
  156. }
  157. });
  158. });
  159. }
  160. }