mirror of
https://gitee.com/hzchunfen/erp.git
synced 2025-12-01 06:30:49 +00:00
增加锁
This commit is contained in:
parent
495253e791
commit
a9e542f89b
@ -62,12 +62,13 @@ class CombinationGoodsStockUpdateListener implements ShouldQueue
|
|||||||
->with('goodsSku:id,stock')
|
->with('goodsSku:id,stock')
|
||||||
->whereIn('goods_sku_id', $combinationGoodsIds)
|
->whereIn('goods_sku_id', $combinationGoodsIds)
|
||||||
->get();
|
->get();
|
||||||
|
$num = !empty($event->num) ? $event->num : 1;
|
||||||
foreach ($combinationGoods as $item) {
|
foreach ($combinationGoods as $item) {
|
||||||
DB::transaction(function () use ($item, &$updateIds) {
|
DB::transaction(function () use ($item, &$updateIds, $num) {
|
||||||
$goodsSku = GoodsSku::query()->lockForUpdate()->find($item['item_id']);
|
$goodsSku = GoodsSku::query()->lockForUpdate()->find($item['item_id']);
|
||||||
$stock = $goodsSku->stock - $item['item_num'];
|
$stock = $goodsSku->stock - $item['item_num'] * $num;
|
||||||
//新增逻辑 在线库存同步扣减
|
//新增逻辑 在线库存同步扣减
|
||||||
$saleStock = max($goodsSku->sale_stock - $item['item_num'], 0);
|
$saleStock = max($goodsSku->sale_stock - $item['item_num'] * $num, 0);
|
||||||
[$status, $stock] = $this->checkStatusAndStock($goodsSku, $stock, $saleStock);
|
[$status, $stock] = $this->checkStatusAndStock($goodsSku, $stock, $saleStock);
|
||||||
$goodsSku->status = $status;
|
$goodsSku->status = $status;
|
||||||
$goodsSku->stock = $stock;
|
$goodsSku->stock = $stock;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user