mirror of
https://gitee.com/hzchunfen/erp.git
synced 2025-11-30 22:20:45 +00:00
commit
6371835479
@ -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);
|
||||||
|
|||||||
@ -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],
|
||||||
|
|||||||
@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user