error('活动结束时间必须大于当前时间!'); } $goods = GoodsModel::find($goodsId); $goodsBanners = GoodsBannerModel::where('goods_id',$goodsId)->get(); $markets = StoreModel::whereIn('id',$storeIds)->pluck('market_id','id'); foreach($storeIds as $key =>$storeId){ $marketId = $markets[$storeId]??0; $model = new GoodsModel(); $model->expire_time = $expireTime; $model->time_limit_days = $timeLimitDays; $model->time_limit_num = $timeLimitNum; $model->can_use_coupon = $canUseCoupon; $model->type = $type; $model->inventory = $inventory; $model->goods_id = 0; $model->store_id = $storeId; $model->market_id = $marketId; $model->market_ids = ["$marketId"]; $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->on_sale = 0; $model->sort = $goods->sort; $model->remark = $goods->remark; if($model->save() && !empty($goodsBanners)){ $goodsId = $model->getKey(); 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_activity'); } /** * Build a form here. */ public function form() { $id = $this->payload['id'] ?? 0; $name = $this->payload['name'] ?? ''; $this->hidden('id')->value($id); $this->display('name')->value($name)->help('复制的活动商品默认下架状态,请核对信息后手动上架!'); $stores = StoreModel::getStoreArray(); $this->multipleSelect('store_ids','选择店铺')->required()->options($stores)->help('选择店铺,将当前商品复制到所选店铺。注意选择重复店铺问题!!!'); $this->number('inventory','库存')->required()->attribute('min', 1)->default(1); $this->datetime('expire_time','活动结束时间')->required()->format('YYYY-MM-DD HH:mm:ss')->rules('after:now',['after'=>'活动结束时间必须大于当前时间!']); $this->number('time_limit_days','限制的天数')->default(1)->help('A时间段内限购'); $this->number('time_limit_num','限制购买数量')->default(1)->help('A时间段内限购的数量'); $this->switch('can_use_coupon','可同时使用优惠券')->default(0); $this->select('type','活动类型')->options(GoodsModel::$_TYPE)->default('flash_sale'); $this->disableResetButton(); } /** * The data of the form. * * @return array */ public function default() { return []; } }