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.
73 lines
1.9 KiB
73 lines
1.9 KiB
<?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 Illuminate\Support\Facades\DB;
|
|
|
|
class GoodsImageForm extends Form
|
|
{
|
|
|
|
/**
|
|
* Handle the form request.
|
|
*
|
|
* @param array $input
|
|
*
|
|
* @return Response
|
|
*/
|
|
public function handle(array $input)
|
|
{
|
|
// 获取外部传递参数
|
|
$goodsId = $input['goods_id'];
|
|
$coverImg= $input['cover_img'];
|
|
$bannerImg= $input['img_banner'];
|
|
|
|
if($goodsId > 0 && !empty($coverImg)){
|
|
$data = ['cover_img' => $coverImg];
|
|
GoodsModel::where('id',$goodsId)->update($data);
|
|
}
|
|
if($goodsId > 0 && !empty($bannerImg)){
|
|
$banner = GoodsBannerModel::where('goods_id',$goodsId)->first();
|
|
if(empty($banner)){
|
|
$banner = new GoodsBanners();
|
|
$banner->goods_id = $goodsId;
|
|
$banner->type = 1;
|
|
$banner->created_at = time();
|
|
}
|
|
$banner->path = $bannerImg;
|
|
$banner->updated_at = time();
|
|
$banner->save();
|
|
}
|
|
|
|
return $this->error('修改成功');
|
|
}
|
|
|
|
/**
|
|
* Build a form here.
|
|
*/
|
|
public function form()
|
|
{
|
|
$id = $this->getKey();
|
|
$goods = GoodsModel::select('name')->find($id);
|
|
$goodName = empty($goods->name)?'':$goods->name;
|
|
$this->hidden('goods_id')->value($id);
|
|
$this->display('name','商品名称')->value($goodName);
|
|
$this->image('cover_img','封面图')->autoUpload();
|
|
$this->image('img_banner','轮播图')->autoUpload();
|
|
}
|
|
|
|
/**
|
|
* The data of the form.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function default()
|
|
{
|
|
return [];
|
|
}
|
|
|
|
}
|