Merge pull request !170 from 赵世界/develop
This commit is contained in:
赵世界 2023-04-28 02:43:23 +00:00 committed by Gitee
commit 6371835479
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 9 additions and 27 deletions

View File

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

View File

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

View File

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