商品预售
parent
122f9538bf
commit
2030ffdee4
|
|
@ -52,6 +52,7 @@ class ProductSpuController extends AdminController
|
||||||
});
|
});
|
||||||
$grid->column('weight');
|
$grid->column('weight');
|
||||||
$grid->column('sales_value');
|
$grid->column('sales_value');
|
||||||
|
$grid->column('is_pre_sale')->switch();
|
||||||
$grid->column('created_at')->sortable();
|
$grid->column('created_at')->sortable();
|
||||||
|
|
||||||
//排序
|
//排序
|
||||||
|
|
@ -213,6 +214,8 @@ class ProductSpuController extends AdminController
|
||||||
$form->ignore(['one_category', 'two_category', 'attr_group']);
|
$form->ignore(['one_category', 'two_category', 'attr_group']);
|
||||||
$form->display('created_at');
|
$form->display('created_at');
|
||||||
$form->display('updated_at');
|
$form->display('updated_at');
|
||||||
|
|
||||||
|
$form->hidden('is_pre_sale');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,7 @@ class OrderPreController extends Controller
|
||||||
|
|
||||||
$scene = http_build_query([
|
$scene = http_build_query([
|
||||||
'order_pre' => $order_pre->id,
|
'order_pre' => $order_pre->id,
|
||||||
|
'invite_code' => $user->userInfo->code,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$response = $app->app_code->getUnlimit($scene, [
|
$response = $app->app_code->getUnlimit($scene, [
|
||||||
|
|
|
||||||
|
|
@ -118,6 +118,7 @@ class ProductSkuController extends Controller
|
||||||
'sku' => ProduckSkuResource::make($sku),
|
'sku' => ProduckSkuResource::make($sku),
|
||||||
'is_collected' => $isCollected,
|
'is_collected' => $isCollected,
|
||||||
'features' => ProductFeatureResource::collection($spu->features),
|
'features' => ProductFeatureResource::collection($spu->features),
|
||||||
|
'is_pre_sale' => !!$spu->is_pre_sale
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -159,13 +159,11 @@ class ProductSku extends Model
|
||||||
*/
|
*/
|
||||||
public function getSaleableStockAttribute(): int
|
public function getSaleableStockAttribute(): int
|
||||||
{
|
{
|
||||||
// 因预售商品功能, 所以这里直接返回
|
if ($this->isOnline()) {
|
||||||
return 1000000;
|
return $this->attributes['stock'];
|
||||||
// if ($this->isOnline()) {
|
}
|
||||||
// return $this->attributes['stock'];
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,8 @@ class ProductSpu extends Model
|
||||||
'release_at',
|
'release_at',
|
||||||
'sales_value',
|
'sales_value',
|
||||||
'cover',
|
'cover',
|
||||||
'description'
|
'description',
|
||||||
|
'is_pre_sale',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function modelFilter()
|
public function modelFilter()
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,8 @@ class OrderService
|
||||||
foreach ($products as $product) {
|
foreach ($products as $product) {
|
||||||
$sku = $product['sku'];
|
$sku = $product['sku'];
|
||||||
|
|
||||||
if ($product['quantity'] > $sku->saleable_stock) {
|
// 商品是否预售
|
||||||
|
if (!$sku->spu->is_pre_sale && $product['quantity'] > $sku->saleable_stock) {
|
||||||
throw new BizException('商品库存不足');
|
throw new BizException('商品库存不足');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -385,11 +386,16 @@ class OrderService
|
||||||
protected function deductProduct(ProductSku $sku, int $qty)
|
protected function deductProduct(ProductSku $sku, int $qty)
|
||||||
{
|
{
|
||||||
$sku->update([
|
$sku->update([
|
||||||
'sales' => DB::Raw("sales + {$qty}"),
|
'sales' => DB::Raw("sales + {$qty}")
|
||||||
// 扣商品库存
|
|
||||||
// 'stock' => DB::raw("stock - {$qty}"),
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// 未开启预售, 扣除商品库存
|
||||||
|
if ($sku->spu && !$sku->spu->is_pre_sale) {
|
||||||
|
$sku->update([
|
||||||
|
'stock' => DB::raw("stock - {$qty}")
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
$sku->spu?->increment('sales', $qty);
|
$sku->spu?->increment('sales', $qty);
|
||||||
|
|
||||||
// // 如果是因为赠品库存不足引起的异常,则需重试
|
// // 如果是因为赠品库存不足引起的异常,则需重试
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class AddIsPreSaleToProductSpus extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('product_spus', function (Blueprint $table) {
|
||||||
|
$table->unsignedTinyInteger('is_pre_sale')->default(1)->comment('是否预售');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('product_spus', function (Blueprint $table) {
|
||||||
|
$table->dropColumn(['is_pre_sale']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -39,6 +39,7 @@ return [
|
||||||
'category'=>[
|
'category'=>[
|
||||||
'name'=>'商品分类',
|
'name'=>'商品分类',
|
||||||
],
|
],
|
||||||
|
'is_pre_sale' => '预售',
|
||||||
],
|
],
|
||||||
'options' => [
|
'options' => [
|
||||||
'deny' => '删除失败',
|
'deny' => '删除失败',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue