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

179 lines
6.7 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. <?php
  2. namespace App\Admin\Controllers\v3;
  3. use App\Admin\Repositories\v3\Goods;
  4. use Dcat\Admin\Form;
  5. use Dcat\Admin\Grid;
  6. use Dcat\Admin\Show;
  7. use Dcat\Admin\Controllers\AdminController;
  8. use App\Models\v3\Category as CategoryModel;
  9. use App\Models\v3\Store as StoreModel;
  10. use Dcat\Admin\Form\NestedForm;
  11. use App\Models\v3\Goods as GoodsModel;
  12. use App\Models\v3\Market as MarketModel;
  13. class GoodsController extends AdminController
  14. {
  15. /**
  16. * Make a grid builder.
  17. *
  18. * @return Grid
  19. */
  20. protected function grid()
  21. {
  22. return Grid::make(new Goods(), function (Grid $grid) {
  23. $grid->id->sortable();
  24. $grid->cover_img_url->image('',50);
  25. $grid->name;
  26. $grid->category_id->display(function ($categoryId){
  27. $category = CategoryModel::getCategoryInfo($categoryId,'title');
  28. return empty($category) ? '' : $category->title;
  29. });
  30. $grid->store_id->display(function ($storeId){
  31. $store = StoreModel::getStoreInfo($storeId,'name');
  32. return empty($store) ? '' : $store->name;
  33. });
  34. $grid->price;
  35. $grid->sort->sortable();
  36. $grid->on_sale->switch();
  37. $grid->filter(function (Grid\Filter $filter) {
  38. $filter->equal('id');
  39. });
  40. $grid->model()->orderBy('id', 'desc');
  41. // 每页10条
  42. $grid->paginate(10);
  43. });
  44. }
  45. /**
  46. * Make a show builder.
  47. *
  48. * @param mixed $id
  49. *
  50. * @return Show
  51. */
  52. protected function detail($id)
  53. {
  54. // $g = GoodsModel::find(1572);
  55. // dd($g->toArray());
  56. return Show::make($id, new Goods(), function (Show $show) {
  57. $show->row(function (Show\Row $show) {
  58. $show->width(6)->field('id');
  59. $show->width(6)->field('name');
  60. $show->width(6)->category_id->as(function ($categoryId){
  61. $item = CategoryModel::getCategoryInfo($categoryId,'title');
  62. return empty($item) ? '' : $item->title;
  63. });
  64. $show->width(6)->store_id->as(function ($storeId){
  65. $item = StoreModel::getStoreInfo($storeId,'name');
  66. return empty($item) ? '' : $item->name;
  67. });
  68. $show->width(6)->cover_img->image();
  69. $show->width(6)->price;
  70. $show->width(6)->original_price;
  71. $show->width(6)->vip_price;
  72. $show->width(6)->inventory;
  73. $show->width(6)->good_unit;
  74. });
  75. $show->row(function (Show\Row $show) {
  76. $show->width(6)->on_sale_text;
  77. $show->width(6)->content;
  78. $show->width(6)->sort;
  79. $show->width(6)->restrict_num;
  80. $show->width(6)->start_num;
  81. $show->width(6)->is_infinite_text;
  82. $show->width(6)->tags->as(function ($value){
  83. return $value;
  84. });
  85. // $show->width(6)->spec;
  86. // $show->details_imgs;
  87. // $show->created_at;
  88. // $show->updated_at;
  89. });
  90. });
  91. }
  92. /**
  93. * Make a form builder.
  94. *
  95. * @return Form
  96. */
  97. protected function form()
  98. {
  99. $builder = GoodsModel::with(['ImageBanners','VideoBanners']);
  100. return Form::make($builder, function (Form $form) {
  101. $form->hidden('id');
  102. // 二级分类
  103. $categoryList = CategoryModel::getCategoryArray([['parent_id','>',0]]);
  104. // 店铺
  105. $storeList = StoreModel::getStoreArray();
  106. //市场
  107. $marketList = MarketModel::getMarket();
  108. $form->column(6, function (Form $form) use($marketList,$storeList,$categoryList ){
  109. $form->select('market_id')->required()->options($marketList);
  110. $form->select('category_id')->required()->options($categoryList);
  111. $form->select('store_id')->required()->options($storeList);
  112. $form->text('name')->required()->maxLength(20);
  113. $form->image('cover_img')->required();
  114. $form->number('sort');
  115. });
  116. $form->column(6, function (Form $form) {
  117. $form->currency('price')->required()->floatTwo()->symbol('¥');
  118. $form->currency('original_price')->required()->floatTwo()->symbol('¥');
  119. $form->currency('vip_price')->required()->floatTwo()->symbol('¥');
  120. $form->text('good_unit')->help('如:斤,个,盒,500克,1000克,1500克等');
  121. $form->radio('is_infinite')->options(['关闭','开启'])->default(1);
  122. $form->number('inventory')->required()->attribute('min', 1)->default(1);
  123. $form->number('restrict_num')->attribute('min', 0)->default(0)->help('0表示不限购');
  124. $form->number('start_num')->attribute('min', 1)->default(1);
  125. });
  126. $form->column(12, function (Form $form) {
  127. $form->hasMany('image_banners', function (Form\NestedForm $form) {
  128. $form->image('path')->width(2);
  129. $form->number('sort')->width(2)->default(0);
  130. $form->hidden('type')->value(1)->default(1);
  131. })->required();
  132. $form->divider();
  133. $form->hasMany('video_banners', function (Form\NestedForm $form) {
  134. $form->file('path')->width(2);
  135. $form->number('sort')->width(2)->default(0);
  136. $form->hidden('type')->value(2)->default(2);
  137. });
  138. $form->divider();
  139. $form->multipleImage('details_imgs')->help('按图片顺序上传');
  140. $form->text('content')->maxLength(50);
  141. $form->text('remark')->maxLength(50);
  142. $form->tags('tags','标签')->options(['新品','热销','新鲜']);
  143. $form->table('spec', function (NestedForm $table) {
  144. $table->text('spec_key')->help('如:净含量:500克,保质期:120天,包装:12个/盒等');
  145. $table->text('spec_value');
  146. });
  147. $form->switch('on_sale')
  148. ->customFormat(function ($v) {
  149. return $v == '上架' ? 1 : 0;
  150. })
  151. ->saving(function ($v) {
  152. return $v;
  153. });
  154. $form->disableResetButton();
  155. $form->disableViewCheck();
  156. $form->disableEditingCheck();
  157. $form->disableCreatingCheck();
  158. });
  159. });
  160. }
  161. }