6
0
Fork 0

sku 预售

release
panliang 2022-06-09 10:08:13 +08:00
parent 2030ffdee4
commit 3df12d381c
6 changed files with 22 additions and 5 deletions

View File

@ -145,6 +145,8 @@ class ProductSkuController extends AdminController
$form->ignore(['attr_group']);
$form->display('created_at');
$form->display('updated_at');
$form->hidden('is_pre_sale');
});
}

View File

@ -76,6 +76,7 @@ class ProductSkuTable extends Grid
2 => 'danger',
]);
$grid->column('release_at');
$grid->column('is_pre_sale', '预售')->switch();
$grid->model()->orderBy('created_at', 'desc');
$grid->model()->orderBy('release_at', 'desc');
$grid->actions(function (Grid\Displayers\Actions $actions) {

View File

@ -66,6 +66,7 @@ class ProductSku extends Model
'sales_value',
'buynote_id',
'verify_state',
'is_pre_sale',
];
/**

View File

@ -114,8 +114,8 @@ class OrderService
foreach ($products as $product) {
$sku = $product['sku'];
// 商品是否预售
if (!$sku->spu->is_pre_sale && $product['quantity'] > $sku->saleable_stock) {
// 商品开启预售, 则不验证库存
if (!$sku->spu->is_pre_sale && !$sku->is_pre_sale && $product['quantity'] > $sku->saleable_stock) {
throw new BizException('商品库存不足');
}
}
@ -390,7 +390,7 @@ class OrderService
]);
// 未开启预售, 扣除商品库存
if ($sku->spu && !$sku->spu->is_pre_sale) {
if (!$sku->spu->is_pre_sale && !$sku->is_pre_sale) {
$sku->update([
'stock' => DB::raw("stock - {$qty}")
]);
@ -1205,9 +1205,14 @@ class OrderService
if (! $product->isGift()) {
$product->spu?->increment('sales', -$product->quantity);
$product->sku?->update([
'stock' => DB::Raw("stock + {$product->quantity}"),
'sales' => DB::Raw("sales - {$product->quantity}"),
]);
// 商品未开启预售,返还库存
if (!$product->spu->is_pre_sale && !$product->sku->is_pre_sale) {
$product->sku?->update([
'stock' => DB::Raw("stock + {$product->quantity}"),
]);
}
continue;
}

View File

@ -14,7 +14,11 @@ class AddIsPreSaleToProductSpus extends Migration
public function up()
{
Schema::table('product_spus', function (Blueprint $table) {
$table->unsignedTinyInteger('is_pre_sale')->default(1)->comment('是否预售');
$table->unsignedTinyInteger('is_pre_sale')->default(0)->comment('是否预售');
});
Schema::table('product_skus', function (Blueprint $table) {
$table->unsignedTinyInteger('is_pre_sale')->default(0)->comment('是否预售');
});
}
@ -28,5 +32,8 @@ class AddIsPreSaleToProductSpus extends Migration
Schema::table('product_spus', function (Blueprint $table) {
$table->dropColumn(['is_pre_sale']);
});
// Schema::table('product_skus', function (Blueprint $table) {
// $table->dropColumn(['is_pre_sale']);
// });
}
}

View File

@ -40,6 +40,7 @@ return [
'limit'=>'限量',
'growth_value'=>'成长值',
'sales_value'=>'销售值',
'is_pre_sale' => '预售',
],
'options' => [
'deny' => '删除失败',