3 changed files with 125 additions and 1 deletions
-
36app/Admin/Actions/Grid/v3/GoodsSpec.php
-
3app/Admin/Controllers/v3/GoodsController.php
-
87app/Admin/Forms/v3/GoodsSpecForm.php
@ -0,0 +1,36 @@ |
|||
<?php |
|||
|
|||
namespace App\Admin\Actions\Grid\v3; |
|||
|
|||
use Dcat\Admin\Grid\RowAction; |
|||
use Dcat\Admin\Widgets\Modal; |
|||
use App\Admin\Forms\v3\GoodsSpecForm; |
|||
|
|||
class GoodsSpec extends RowAction |
|||
{ |
|||
/** |
|||
* @return string |
|||
*/ |
|||
protected $title = '管理规格'; |
|||
|
|||
public function render() |
|||
{ |
|||
$id = $this->getKey(); |
|||
|
|||
$modal = Modal::make() |
|||
->xl() |
|||
->title($this->title) |
|||
->body(GoodsSpecForm::make()->setKey($id)) |
|||
->button($this->title); |
|||
|
|||
return $modal; |
|||
} |
|||
|
|||
public function parameters() |
|||
{ |
|||
|
|||
return [ |
|||
|
|||
]; |
|||
} |
|||
} |
|||
@ -0,0 +1,87 @@ |
|||
<?php |
|||
|
|||
namespace App\Admin\Forms\v3; |
|||
|
|||
use App\Models\v3\GoodsBanners; |
|||
use Dcat\Admin\Widgets\Form; |
|||
use Symfony\Component\HttpFoundation\Response; |
|||
use App\Models\v3\Goods as GoodsModel; |
|||
use App\Models\v3\GoodsBanners as GoodsBannerModel; |
|||
use Dcat\Admin\Form\NestedForm; |
|||
|
|||
class GoodsSpecForm extends Form |
|||
{ |
|||
|
|||
/** |
|||
* Handle the form request. |
|||
* |
|||
* @param array $input |
|||
* |
|||
* @return Response |
|||
*/ |
|||
public function handle(array $input) |
|||
{ |
|||
// 获取外部传递参数
|
|||
$goodsId = $input['goods_id']; |
|||
// $tags= isset($input['tags'])?$input['tags']:[];
|
|||
$spec= isset($input['spec'])?$input['spec']:[]; |
|||
|
|||
$edit = false; |
|||
$goods = GoodsModel::find($goodsId); |
|||
if(empty($goods)){ |
|||
$this->error('商品不存在!'); |
|||
} |
|||
// if(!empty($tags)){
|
|||
// $tagsArr = [];
|
|||
// if(!empty($tags)){
|
|||
// foreach($tags as $kt => $tag){
|
|||
// if(empty($tag)){
|
|||
// unset($tags[$kt]);
|
|||
// continue;
|
|||
// }
|
|||
// $tagsArr[] = $tag;
|
|||
// }
|
|||
// };
|
|||
// $goods->tags = json_encode($tagsArr);
|
|||
// }
|
|||
if(!empty($spec)){ |
|||
$goods->spec = $spec; |
|||
$edit = true; |
|||
} |
|||
if($edit && $goods->save()){ |
|||
return $this->error('修改成功!'); |
|||
} |
|||
|
|||
return $this->error('未做任何修改或者修改失败!'); |
|||
} |
|||
|
|||
/** |
|||
* Build a form here. |
|||
*/ |
|||
public function form() |
|||
{ |
|||
$id = $this->getKey(); |
|||
$goods = GoodsModel::select('name','tags','spec')->find($id); |
|||
$goodName = empty($goods->name)?'':$goods->name; |
|||
// $tags = empty($goods->tags)?[]:$goods->tags;
|
|||
$spec = empty($goods->spec)?[]:$goods->spec; |
|||
$this->hidden('goods_id')->value($id); |
|||
$this->display('name','商品名称')->value($goodName); |
|||
// $this->tags('tags','标签')->options(['新品','热销','新鲜'])->value($tags);
|
|||
$this->table('spec', function (NestedForm $table) { |
|||
$table->text('spec_key')->required()->help('如:净含量:500克,保质期:120天,包装:12个/盒等'); |
|||
$table->text('spec_value')->required(); |
|||
})->value($spec); |
|||
} |
|||
|
|||
/** |
|||
* The data of the form. |
|||
* |
|||
* @return array |
|||
*/ |
|||
public function default() |
|||
{ |
|||
return []; |
|||
} |
|||
|
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue