feat: #10000 组合商品计算错误修改

This commit is contained in:
赵世界 2023-04-28 10:42:26 +08:00
parent 45ed0c0463
commit 62f5dd4464
3 changed files with 9 additions and 27 deletions

View File

@ -79,17 +79,11 @@ class GoodsCombinationController extends Controller
->whereIn('id', $itemIds) ->whereIn('id', $itemIds)
->pluck('stock', 'id') ->pluck('stock', 'id')
->toArray(); ->toArray();
$stock = 0; $stock = [];
foreach ($combinationGoods as $item) { foreach ($combinationGoods as $item) {
$num = (int)($skus[$item['item_id']] / $item['item_num']); $stock[] = (int)($skus[$item['item_id']] / $item['item_num']);
if (0 === $stock) {
$stock = $num;
continue;
}
if ($num < $stock) {
$stock = $num;
}
} }
$stock = min($stock);
$status = $stock ? (5 < $stock ? 1 : 2) : 0; $status = $stock ? (5 < $stock ? 1 : 2) : 0;
if ($id = $request->input('id')) { if ($id = $request->input('id')) {
$sku = GoodsSku::query()->findOrFail($id); $sku = GoodsSku::query()->findOrFail($id);

View File

@ -55,17 +55,11 @@ class CombinationGoodsImport implements ToArray, SkipsEmptyRows, WithStartRow
->get(['id', 'external_sku_id', 'stock']) ->get(['id', 'external_sku_id', 'stock'])
->toArray(); ->toArray();
$skus = ArrayUtils::index($skus, 'external_sku_id'); $skus = ArrayUtils::index($skus, 'external_sku_id');
$stock = 0; $stock = [];
foreach ($info['item'] as $item) { foreach ($info['item'] as $item) {
$num = (int)($skus[$item['item_code']]['stock'] / $item['item_num']); $stock[] = (int)($skus[$item['item_code']]['stock'] / $item['item_num']);
if (0 === $stock) {
$stock = $num;
continue;
}
if ($num < $stock) {
$stock = $num;
}
} }
$stock = min($stock);
$status = $stock ? (5 < $stock ? 1 : 2) : 0; $status = $stock ? (5 < $stock ? 1 : 2) : 0;
$sku = GoodsSku::query()->updateOrCreate( $sku = GoodsSku::query()->updateOrCreate(
['external_sku_id' => $info['external_sku_id'], 'is_combination' => 1], ['external_sku_id' => $info['external_sku_id'], 'is_combination' => 1],

View File

@ -75,17 +75,11 @@ class CombinationGoodsStockUpdateListener
->with('goodsSkuItem:id,stock') ->with('goodsSkuItem:id,stock')
->where('goods_sku_id', $goodsSkuId) ->where('goods_sku_id', $goodsSkuId)
->get(); ->get();
$stock = 0; $stock = [];
foreach ($combinationGoods as $goods) { foreach ($combinationGoods as $goods) {
$num = $goods['goodsSkuItem']['stock'] / $goods['item_num']; $stock[] = (int)($goods['goodsSkuItem']['stock'] / $goods['item_num']);
if (0 === $stock) {
$stock = $num;
continue;
}
if ($num < $stock) {
$stock = $num;
}
} }
$stock = min($stock);
GoodsSku::query()->where('id', $goodsSkuId)->update(['stock' => $stock]); GoodsSku::query()->where('id', $goodsSkuId)->update(['stock' => $stock]);
$updateIds[] = $goodsSkuId; $updateIds[] = $goodsSkuId;
} }