Browse Source

复制商品功能

master
liangyuyan 5 years ago
parent
commit
39b2890c56
  1. 7
      app/Admin/Actions/Grid/GoodsCopy.php
  2. 18
      app/Admin/Controllers/v3/GoodsController.php
  3. 56
      app/Admin/Forms/GoodsCopyForm.php

7
app/Admin/Actions/Grid/GoodsCopy.php

@ -29,4 +29,11 @@ class GoodsCopy extends RowAction
return $modal;
}
public function parameters()
{
return [
];
}
}

18
app/Admin/Controllers/v3/GoodsController.php

@ -206,24 +206,8 @@ class GoodsController extends AdminController
// 商品所属市场,根据店铺查询市场
$info = StoreModel::getStoreInfo($storeId,'market_id');
$form->market_id = $info->market_id;
$storeIds = $form->input('store_ids');
$form->deleteFiles('store_ids');
dd($storeIds);
});
$form->saved(function (Form $form){
if($form->isCreating()) {
// 添加到多店铺
// $storeIds = $form->input('store_ids');
// $form->deleteFiles('store_ids');
$goodsModel = new GoodsModel();
// 获取最终保存的数组
// $updates = $form->updates();
// dd($updates);
}
});
});
}

56
app/Admin/Forms/GoodsCopyForm.php

@ -7,6 +7,7 @@ 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;
use Illuminate\Support\Facades\DB;
class GoodsCopyForm extends Form
{
@ -23,15 +24,56 @@ class GoodsCopyForm extends Form
// 获取外部传递参数
$goodsId = $input['goods_id'];
$storeIds= $input['store_ids'];
// dd($storeIds);
$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 = $goods;
dd($model->toArray());
$model->store_id = $value;
$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');
@ -43,9 +85,11 @@ class GoodsCopyForm extends Form
public function form()
{
$id = $this->getKey();
$this->text('goods_id')->value($id);
$goods = GoodsModel::select('name')->find($id);
$this->hidden('goods_id')->value($id);
$this->display('name')->value($goods->name);
$stores = StoreModel::getStoreArray();
$this->multipleSelect('store_ids','选择店铺')->required()->options($stores);
$this->multipleSelect('store_ids','选择店铺')->required()->options($stores)->help('选择店铺,将当前商品复制到所选店铺。注意选择重复店铺问题!!!');
}
/**

Loading…
Cancel
Save