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.
|
|
<?php
namespace App\Admin\Forms;
use Dcat\Admin\Widgets\Form;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{
/** * 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(); $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)->help('选择店铺,将当前商品复制到所选店铺。注意选择重复店铺问题!!!'); }
/** * The data of the form. * * @return array */ public function default() { return []; }
}
|