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