WxShopClassifysController.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. namespace App\Admin\Controllers\Shop;
  3. use App\Admin\Actions\Extensions\ShopClassifyConfigButton;
  4. use App\Admin\Repositories\Shop\WxShopClassify;
  5. use App\Models\Shop\WxShopClassify as ShopClassify;
  6. use Dcat\Admin\Form;
  7. use Dcat\Admin\Grid;
  8. use Dcat\Admin\Layout\Content;
  9. use Dcat\Admin\Show;
  10. use Dcat\Admin\Http\Controllers\AdminController;
  11. use Dcat\Admin\Layout\Row;
  12. use Dcat\Admin\Tree;
  13. class WxShopClassifysController extends AdminController
  14. {
  15. private $options = [0=>'不显示', 1=>'总是显示', 2=>'审核时不显示'];
  16. public function index(Content $content)
  17. {
  18. return $content->header('商品分类3层结构')->description('这里主要调整类别结构')
  19. ->body(function (Row $row) {
  20. $tree = new Tree(new WxShopClassify);
  21. $row->column(12, $tree);
  22. $tree->maxDepth(3);
  23. $tree->branch(function ($branch) {
  24. if(_empty_($branch['pic'])){
  25. $logo = '<div style="width:25px;height:25px;margin-left:10px;display: inline-block;"></div>';
  26. }else{
  27. $logo = "<img src='" . $branch['pic'] ."' style='width:25px;height:25px;margin-left:10px;' class='img'/>";
  28. }
  29. if(_empty_($branch['bg_img'])){
  30. $bg = '<div style="width: 50px;margin-left: 10px;display: inline-block;"></div>';
  31. }else{
  32. $bg = "<img src='" . $branch['bg_img'] ."' style='width:50px;height:20px;margin-left:10px;opacity: 0.5;' class='img'/>";
  33. }
  34. $depth = $branch['depth'];
  35. $tip = '';
  36. $margin_left = 160;
  37. if($depth == 2){
  38. $margin_left = 130;
  39. }else if($depth == 3){
  40. $margin_left = 100;
  41. }
  42. if($branch['in_mp'] == 2){
  43. $tip .= '<span style="width: 100px;margin-left: '.(_empty_($tip) ? $margin_left : 100).'px;">小程序端:审核时不显示</span>';
  44. }else if($branch['in_mp'] === 0){
  45. $tip .= '<span style="width: 100px;margin-left: '.(_empty_($tip) ? $margin_left : 100).'px;">小程序端:不显示</span>';
  46. }else{
  47. $tip .= '<span style="width: 100px;margin-left: '.(_empty_($tip) ? $margin_left : 100).'px;"></span>';
  48. }
  49. if($branch['in_app'] == 2){
  50. $tip .= '<span style="width: 100px;margin-left: '.(_empty_($tip) ? $margin_left : 100).'px;">App端:审核时不显示</span>';
  51. }else if($branch['in_app'] === 0){
  52. $tip .= '<span style="width: 100px;margin-left: '.(_empty_($tip) ? $margin_left : 100).'px;">App端:不显示</span>';
  53. }else{
  54. $tip .= '<span style="width: 100px;margin-left: '.(_empty_($tip) ? $margin_left : 100).'px;"></span>';
  55. }
  56. if($branch['in_h5'] == 2){
  57. $tip .= '<span style="width: 100px;margin-left: '.(_empty_($tip) ? $margin_left : 100).'px;">H5端:审核时不显示</span>';
  58. }else if($branch['in_h5'] === 0){
  59. $tip .= '<span style="width: 100px;margin-left: '.(_empty_($tip) ? $margin_left : 100).'px;">H5端:不显示</span>';
  60. }else{
  61. $tip .= '<span style="width: 100px;margin-left: '.(_empty_($tip) ? $margin_left : 100).'px;"></span>';
  62. }
  63. return "{$branch['id']} - {$branch['name']} $logo $bg $tip";
  64. });
  65. });
  66. }
  67. /**
  68. * Make a grid builder.
  69. *
  70. * @return Grid
  71. */
  72. protected function grid()
  73. {
  74. return Grid::make(new WxShopClassify(), function (Grid $grid) {
  75. $grid->simplePaginate();
  76. $grid->model()->where('depth', 3)->orderBy('id', 'desc');
  77. $grid->quickSearch(['id', 'name','intro'])->placeholder('搜索分类ID,名字,介绍...');
  78. $grid->column('id')->sortable();
  79. $grid->column('pic')->image('', 60);
  80. $grid->column('bg_img')->image('', 60);
  81. $grid->column('intro');
  82. $grid->column('parent_id')->select(ShopClassify::pluck('name', 'id'));
  83. $grid->column('sort')->editable();
  84. // $grid->column('is_highlight', '高亮')->switch();
  85. // $grid->column('is_hot', '热榜')->switch();
  86. $grid->column('state')->switch();
  87. $grid->column('in_h5')->select($this->options);
  88. $grid->column('in_app')->select($this->options);
  89. $grid->column('in_mp')->select($this->options);
  90. // $grid->column('created_at');
  91. // $grid->fixColumns(1);
  92. $grid->model()->orderBy('id', 'asc');
  93. $grid->filter(function (Grid\Filter $filter) {
  94. $filter->equal('id');
  95. });
  96. $grid->tools([
  97. new ShopClassifyConfigButton()
  98. ]);
  99. });
  100. }
  101. /**
  102. * Make a show builder.
  103. *
  104. * @param mixed $id
  105. *
  106. * @return Show
  107. */
  108. protected function detail($id)
  109. {
  110. return Show::make($id, new WxShopClassify(), function (Show $show) {
  111. $show->field('id');
  112. $show->field('name');
  113. $show->field('intro');
  114. $show->field('pic');
  115. $show->field('bg_img');
  116. $show->field('parent_id');
  117. $show->field('sort');
  118. $show->field('state');
  119. $show->field('in_h5');
  120. $show->field('in_app');
  121. $show->field('in_mp');
  122. $show->field('created_at');
  123. $show->field('updated_at');
  124. });
  125. }
  126. /**
  127. * Make a form builder.
  128. *
  129. * @return Form
  130. */
  131. protected function form()
  132. {
  133. return Form::make(new WxShopClassify(), function (Form $form) {
  134. $form->display('id');
  135. $options = ShopClassify::where('depth', '<>', 3)->pluck('name', 'id')->toArray();
  136. $options[0] = '顶级分类';
  137. $form->select('parent_id', '父级分类')->help('第一层级的请选择“顶级分类”')->options($options)->default(0);
  138. $form->text('name', '名字');
  139. $form->text('intro', '介绍');
  140. $form->image('pic', '图标')->help('建议尺寸:750*750')
  141. ->url('files/uploads')->uniqueName()->autoUpload();
  142. $form->image('bg_img', '背景')->help('现在用在类目榜单的位置,宽高比:2.7')
  143. ->url('files/uploads')->uniqueName()->autoUpload();
  144. $form->number('sort', '排序');
  145. $form->switch('state', '状态')->default(1);
  146. // $form->switch('is_highlight', '高亮');
  147. // $form->switch('is_hot', '热榜');
  148. $form->radio('in_h5', 'H5端')->options($this->options)->default(1);
  149. $form->radio('in_app', 'App端')->options($this->options)->default(1);
  150. $form->radio('in_mp', '小程序端')->options($this->options)->default(1);
  151. $form->deleting(function (Form $form){
  152. global $__MINI_GLOBAL_TENANT_ID__;
  153. if($__MINI_GLOBAL_TENANT_ID__ > 0){
  154. return $form->response()->error('权限不足,不可以删除其他分站对象');
  155. }
  156. });
  157. });
  158. }
  159. }