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

136 lines
4.2 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Admin\Repositories\Goods;
  4. use App\Models\Store;
  5. use Dcat\Admin\Form;
  6. use Dcat\Admin\Grid;
  7. use Dcat\Admin\Show;
  8. use Dcat\Admin\Controllers\AdminController;
  9. use App\Models\GoodsType as GoodsTypeModel;
  10. use App\Models\Store as StoreModel;
  11. use Dcat\Admin\Form\NestedForm;
  12. class GoodsController extends AdminController
  13. {
  14. /**
  15. * Make a grid builder.
  16. *
  17. * @return Grid
  18. */
  19. protected function grid()
  20. {
  21. return Grid::make(new Goods(), function (Grid $grid) {
  22. $grid->id->sortable();
  23. $grid->cover_img_url->image('',50);
  24. $grid->name;
  25. $grid->goods_type_id->display(function ($goodsTypeId){
  26. $goodsType = GoodsTypeModel::getGoodsInfo($goodsTypeId,'type_name');
  27. return empty($goodsType) ? '' : $goodsType->type_name;
  28. });
  29. $grid->store_id->display(function ($storeId){
  30. $store = StoreModel::getStoreInfo($storeId,'name');
  31. return empty($store) ? '' : $store->name;
  32. });
  33. $grid->price;
  34. $grid->sort->sortable();
  35. $grid->on_sale->switch();
  36. $grid->filter(function (Grid\Filter $filter) {
  37. $filter->equal('id');
  38. });
  39. // 每页10条
  40. $grid->paginate(10);
  41. });
  42. }
  43. /**
  44. * Make a show builder.
  45. *
  46. * @param mixed $id
  47. *
  48. * @return Show
  49. */
  50. protected function detail($id)
  51. {
  52. return Show::make($id, new Goods(), function (Show $show) {
  53. $show->id;
  54. $show->name;
  55. $show->type_id;
  56. $show->store_id;
  57. $show->cover_img;
  58. $show->price;
  59. $show->original_price;
  60. $show->vip_price;
  61. $show->on_sale;
  62. $show->inventory;
  63. $show->content;
  64. $show->sort;
  65. $show->restrict_num;
  66. $show->start_num;
  67. $show->is_infinite;
  68. $show->good_unit;
  69. $show->tags;
  70. $show->details_imgs;
  71. $show->spec;
  72. $show->created_at;
  73. $show->updated_at;
  74. });
  75. }
  76. /**
  77. * Make a form builder.
  78. *
  79. * @return Form
  80. */
  81. protected function form()
  82. {
  83. return Form::make(new Goods(), function (Form $form) {
  84. $form->hidden('id');
  85. // 二级分类(商品分类)
  86. $goodsTypeList = GoodsTypeModel::getGoodsTypeArray();
  87. // 店铺
  88. $store = StoreModel::getStoreArray();
  89. $form->select('goods_type_id')->width(4)->required()->options($goodsTypeList);
  90. $form->select('store_id')->width(4)->required()->options($store);
  91. $form->text('name')->width(4)->required()->maxLength(20);
  92. $form->image('cover_img')->width(2)->required();
  93. $form->currency('price')->width(4)->required()->floatTwo()->symbol('¥');
  94. $form->currency('original_price')->width(4)->required()->floatTwo()->symbol('¥');
  95. $form->currency('vip_price')->width(4)->required()->floatTwo()->symbol('¥');
  96. $form->text('good_unit')->width(4)->help('如:斤,个,盒,500克,1000克,1500克等')->saveAsJson();
  97. $form->switch('is_infinite');
  98. $form->number('inventory')->width(2)->required()->attribute('min', 1)->default(1);
  99. $form->number('restrict_num')->width(2)->attribute('min', 0)->default(0)->help('0表示不限购');
  100. $form->number('start_num')->width(2)->attribute('min', 1)->default(1);
  101. $form->multipleImage('details_imgs');
  102. $form->textarea('content');
  103. $form->number('sort')->width(2);
  104. $form->tags('tags')->options(['新品','热销','新鲜'])->saveAsJson();
  105. $form->table('spec', function (NestedForm $table) {
  106. $table->text('规格名称')->help('如:净含量:500克,包装:12个/盒,保质期:120天等');
  107. $table->text('值');
  108. });
  109. $form->saving(function (Form $form){
  110. $tage = $form->input('tags');
  111. var_dump($tage);
  112. $data = $form->input('spec');
  113. dd($data);
  114. });
  115. });
  116. }
  117. }