3 changed files with 152 additions and 2 deletions
-
39app/Admin/Actions/Grid/v3/GoodsActivityCopy.php
-
5app/Admin/Controllers/v3/GoodsActivityController.php
-
110app/Admin/Forms/v3/GoodsActivityCopyForm.php
@ -0,0 +1,39 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Actions\Grid\v3; |
||||
|
|
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use Dcat\Admin\Widgets\Modal; |
||||
|
use App\Admin\Forms\v3\GoodsActivityCopyForm; |
||||
|
use Dcat\Admin\Widgets\Lazy; |
||||
|
|
||||
|
class GoodsActivityCopy extends RowAction |
||||
|
{ |
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '复制'; |
||||
|
|
||||
|
public function render() |
||||
|
{ |
||||
|
$id = $this->getKey(); |
||||
|
$form = GoodsActivityCopyForm::make(['id'=>$this->row->id,'name'=>$this->row->name])->setKey($id); |
||||
|
|
||||
|
$modal = Modal::make() |
||||
|
->xl() |
||||
|
->title($this->title) |
||||
|
->body($form) |
||||
|
->button($this->title); |
||||
|
|
||||
|
return $modal; |
||||
|
} |
||||
|
|
||||
|
public function parameters() |
||||
|
{ |
||||
|
|
||||
|
return [ |
||||
|
'id' => $this->row->id, |
||||
|
'name' => $this->row->name |
||||
|
]; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,110 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Forms\v3; |
||||
|
|
||||
|
use Dcat\Admin\Models\Administrator; |
||||
|
use Dcat\Admin\Traits\LazyWidget; |
||||
|
use Dcat\Admin\Widgets\Form; |
||||
|
use Dcat\Admin\Contracts\LazyRenderable; |
||||
|
use Symfony\Component\HttpFoundation\Response; |
||||
|
use App\Models\v3\Store as StoreModel; |
||||
|
use App\Models\v3\Goods as GoodsModel; |
||||
|
use App\Models\v3\GoodsBanners as GoodsBannerModel; |
||||
|
|
||||
|
class GoodsActivityCopyForm extends Form implements LazyRenderable |
||||
|
{ |
||||
|
use LazyWidget; |
||||
|
|
||||
|
/** |
||||
|
* Handle the form request. |
||||
|
* |
||||
|
* @param array $input |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(array $input) |
||||
|
{ |
||||
|
// 获取外部传递参数
|
||||
|
$goodsId = $input['goods_id']; |
||||
|
$storeIds= $input['store_ids']; |
||||
|
|
||||
|
$goods = GoodsModel::find($goodsId); |
||||
|
$goodsBanners = GoodsBannerModel::where('goods_id',$goodsId)->get(); |
||||
|
$markets = StoreModel::whereIn('id',$storeIds)->pluck('market_id','id'); |
||||
|
foreach($storeIds as $key =>$value){ |
||||
|
$storeId = $value; |
||||
|
$model = new GoodsModel(); |
||||
|
|
||||
|
$model->store_id = $storeId; |
||||
|
$model->market_id = $markets[$storeId]; |
||||
|
$model->category_id = $goods->category_id; |
||||
|
|
||||
|
$model->name = $goods->name; |
||||
|
$model->cover_img = $goods->cover_img; |
||||
|
$model->goods_unit = $goods->goods_unit; |
||||
|
|
||||
|
$model->tags = $goods->tags; |
||||
|
$model->spec = $goods->spec; |
||||
|
$model->details_imgs = $goods->details_imgs; |
||||
|
$model->content = $goods->content; |
||||
|
$model->details = $goods->details; |
||||
|
|
||||
|
$model->price = $goods->price; |
||||
|
$model->original_price = $goods->original_price; |
||||
|
$model->vip_price = $goods->vip_price; |
||||
|
|
||||
|
$model->start_num = $goods->start_num; |
||||
|
$model->restrict_num = $goods->restrict_num; |
||||
|
$model->is_infinite = $goods->is_infinite; |
||||
|
$model->inventory = $goods->inventory; |
||||
|
|
||||
|
$model->on_sale = $goods->on_sale; |
||||
|
$model->sort = $goods->sort; |
||||
|
$model->remark = $goods->remark; |
||||
|
|
||||
|
if($model->save() && !empty($goodsBanners)){ |
||||
|
$goodsId = $model->getKey(); |
||||
|
$banners = []; |
||||
|
foreach($goodsBanners as $kb => $vb){ |
||||
|
$banners[] = [ |
||||
|
'goods_id' => $goodsId, |
||||
|
'type' => $vb->type, |
||||
|
'path' => $vb->path, |
||||
|
'sort' => $vb->sort, |
||||
|
'created_at' => time(), |
||||
|
'updated_at' => time(), |
||||
|
]; |
||||
|
GoodsBannerModel::insert($banners); |
||||
|
} |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
return $this->success('修改成功', '/goods'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Build a form here. |
||||
|
*/ |
||||
|
public function form() |
||||
|
{ |
||||
|
$id = $this->getKey(); |
||||
|
$name = $this->name ?? ''; |
||||
|
dd($name); |
||||
|
$this->hidden('id')->value($id); |
||||
|
|
||||
|
$this->display('name')->value($name); |
||||
|
$stores = StoreModel::getStoreArray(); |
||||
|
$this->multipleSelect('store_ids','选择店铺')->required()->options($stores)->help('选择店铺,将当前商品复制到所选店铺。注意选择重复店铺问题!!!'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* The data of the form. |
||||
|
* |
||||
|
* @return array |
||||
|
*/ |
||||
|
public function default() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
|
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue