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

85 lines
2.4 KiB

<?php
namespace App\Admin\Forms\v3;
use Dcat\Admin\Widgets\Form;
use Symfony\Component\HttpFoundation\Response;
use App\Models\v3\Goods as GoodsModel;
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 [];
}
}