id)->pluck('product_sku_id'); $query = ModelsProductSku::online(); // 过滤掉已有的商品 $query->whereNotIn('id', $skuIds); // 选择某一分类 if ($categotyId) { $query->where('category_id', $categotyId); } $skus = $query->get(); foreach($skus as $sku) { ProductSku::create([ 'store_id' => $store->id, 'product_sku_id' => $sku->id, 'status' => 1, 'amount' => $amount, ]); } DB::commit(); return $this->response()->success('导入 '.$skus->count().' 个商品')->refresh(); } catch (\Exception $e) { DB::rollBack(); report($e); return $this->response()->error($e->getMessage()); } } public function form() { $storeId = $this->model()->store_id; $this->hidden('store_id')->default($storeId); $this->select('category_id', '分类')->options(admin_route('api.product_categories', ['level' => 2])); $this->number('amount', '默认库存')->min(0)->default(1000); // $this->display('product', '已选商品数量')->value(1000); $this->display('store_product', '店铺已有商品')->value(ProductSku::where('store_id', $storeId)->count())->help('导入商品会忽略已存在的商品'); // $this->display('export_product', '即将导入商品')->value(1000); } }