mirror of
https://gitee.com/hzchunfen/erp.git
synced 2025-12-01 14:40:44 +00:00
feat: #10000 更新
This commit is contained in:
parent
4cb1b405f1
commit
0dbcf176c8
@ -63,28 +63,22 @@ class CombinationGoodsStockUpdateListener
|
|||||||
}
|
}
|
||||||
// 计算主商品库存
|
// 计算主商品库存
|
||||||
if ($combinationGoodsItemIds) {
|
if ($combinationGoodsItemIds) {
|
||||||
$itemIds = array_keys($combinationGoodsItemIds);
|
$combinationGoodsItems = CombinationGood::query()
|
||||||
$goodsSkuIds = CombinationGood::query()
|
->whereIn('item_id', array_keys($combinationGoodsItemIds))
|
||||||
->whereIn('item_id', $itemIds)
|
->get();
|
||||||
->pluck('goods_sku_id')
|
if ($combinationGoodsItems->isEmpty()){
|
||||||
->toArray();
|
|
||||||
if (empty($goodsSkuIds)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
$goodsSkuIds = array_column($combinationGoodsItems->toArray(), 'goods_sku_id');
|
||||||
$goodsSkus = GoodsSku::query()
|
$goodsSkus = GoodsSku::query()
|
||||||
->whereIn('id', $goodsSkuIds)
|
->whereIn('id', $goodsSkuIds)
|
||||||
->pluck('stock', 'id')
|
->pluck('stock', 'id')
|
||||||
->toArray();
|
->toArray();
|
||||||
foreach ($combinationGoodsItemIds as $itemId => $stock) {
|
foreach ($combinationGoodsItems as $item){
|
||||||
$combinationGoods = CombinationGood::query()
|
$stock = $combinationGoodsItemIds[$item['item_id']] / $item['item_num'];
|
||||||
->where('item_id', $itemId)
|
if ($stock < $goodsSkus[$item['goods_sku_id']]) {
|
||||||
->get();
|
GoodsSku::query()->where('id', $item['goods_sku_id'])->update(['stock' => $stock]);
|
||||||
foreach ($combinationGoods as $goods) {
|
$updateIds[] = $item['goods_sku_id'];
|
||||||
$stock = $combinationGoodsItemIds[$goods['item_id']] / $goods['item_num'];
|
|
||||||
if ($stock < $goodsSkus[$goods['goods_sku_id']]) {
|
|
||||||
GoodsSku::query()->where('id', $goods['goods_sku_id'])->update(['stock' => $stock]);
|
|
||||||
$updateIds[] = $goods['goods_sku_id'];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user