4 changed files with 128 additions and 5 deletions
-
36app/Admin/Actions/Grid/v3/GoodsImage.php
-
20app/Admin/Controllers/v3/GoodsController.php
-
73app/Admin/Forms/v3/GoodsImageForm.php
-
4app/Admin/routes.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\GoodsImageForm; |
|||
|
|||
class GoodsImage extends RowAction |
|||
{ |
|||
/** |
|||
* @return string |
|||
*/ |
|||
protected $title = '上传图片'; |
|||
|
|||
public function render() |
|||
{ |
|||
$id = $this->getKey(); |
|||
|
|||
$modal = Modal::make() |
|||
->xl() |
|||
->title($this->title) |
|||
->body(GoodsImageForm::make()->setKey($id)) |
|||
->button($this->title); |
|||
|
|||
return $modal; |
|||
} |
|||
|
|||
public function parameters() |
|||
{ |
|||
|
|||
return [ |
|||
|
|||
]; |
|||
} |
|||
} |
|||
@ -0,0 +1,73 @@ |
|||
<?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 []; |
|||
} |
|||
|
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue