mirror of
https://gitee.com/hzchunfen/erp.git
synced 2025-12-01 06:30:49 +00:00
feat: #10000 盘点导入优化
This commit is contained in:
parent
6ba0ceb47d
commit
1c4e9cc040
@ -32,46 +32,64 @@ class InventoryImport implements ToCollection, SkipsEmptyRows
|
|||||||
}
|
}
|
||||||
unset($row);
|
unset($row);
|
||||||
$hasGoods = Goods::query()->whereIn('goods_code', $goodsCodes)->get(['id', 'goods_code'])->toArray();
|
$hasGoods = Goods::query()->whereIn('goods_code', $goodsCodes)->get(['id', 'goods_code'])->toArray();
|
||||||
|
$hasGoodsIds = array_column($hasGoods, 'id');
|
||||||
$hasGoods = ArrayUtils::index($hasGoods, 'goods_code');
|
$hasGoods = ArrayUtils::index($hasGoods, 'goods_code');
|
||||||
$updateIds = [];
|
$updateIds = [];
|
||||||
$day = DateTimeUtils::getToday();
|
$day = DateTimeUtils::getToday();
|
||||||
$dateTime = date('Y-m-d H:i:s');
|
$dateTime = date('Y-m-d H:i:s');
|
||||||
|
$hasGoodsSkus = GoodsSku::query()
|
||||||
|
->whereIn('goods_id', $hasGoodsIds)
|
||||||
|
->get(['id', 'status', 'stock', 'cost', 'sku_code', 'goods_id'])
|
||||||
|
->toArray();
|
||||||
foreach ($collection as $row) {
|
foreach ($collection as $row) {
|
||||||
if (!isset($hasGoods[$row[0]])) {
|
if (!isset($hasGoods[$row[0]])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$goodsSku = GoodsSku::query()
|
$goodsId = $hasGoods[$row[0]]['id'];
|
||||||
->select(['id', 'status', 'stock', 'cost'])
|
$goodsSku = [];
|
||||||
->where('goods_id', $hasGoods[$row[0]]['id'])
|
foreach ($hasGoodsSkus as $item) {
|
||||||
->where('sku_code', $row[4])
|
if ($item['sku_code'] === $row[4] && $item['goods_id'] === $goodsId) {
|
||||||
->first();
|
$goodsSku = $item;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (empty($goodsSku)) {
|
if (empty($goodsSku)) {
|
||||||
Log::warning(json_encode($row, 256) . '=====库存导入未找到');
|
Log::warning(json_encode($row, 256) . '=====库存导入未找到');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$goodsSku->stock = $row[6] + $row[7];
|
if ('下架' === $goodsSku['status']) {
|
||||||
if ('下架' === $goodsSku->status) {
|
GoodsSku::query()->where('id', $goodsSku['id'])->update([
|
||||||
$goodsSku->status = 1;
|
'stock' => $row[6] + $row[7],
|
||||||
|
'cost' => $row[8],
|
||||||
|
'status' => 1,
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
GoodsSku::query()->where('id', $goodsSku['id'])->update([
|
||||||
|
'stock' => $row[6] + $row[7],
|
||||||
|
'cost' => $row[8],
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
$goodsSku->cost = $row[8];
|
$updateIds[] = $goodsSku['id'];
|
||||||
$goodsSku->save();
|
DailyStockRecord::query()->where('sku_id', $goodsSku['id'])->where('day', $day)->update([
|
||||||
$updateIds[] = $goodsSku->id;
|
|
||||||
DailyStockRecord::query()->where('sku_id', $goodsSku->id)->where('day', $day)->update([
|
|
||||||
'arrived_today_num' => $row[7],
|
'arrived_today_num' => $row[7],
|
||||||
'inventory' => $row[6],
|
'inventory' => $row[6],
|
||||||
'inventory_time' => $dateTime
|
'inventory_time' => $dateTime
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
sleep(2);
|
||||||
$onSkuIds = GoodsSku::query()
|
$onSkuIds = GoodsSku::query()
|
||||||
->where('status', '>', 0)
|
->where('status', '>', 0)
|
||||||
->pluck('id')
|
->pluck('id')
|
||||||
->toArray();
|
->toArray();
|
||||||
$downSkuIds = array_diff($onSkuIds, $updateIds);
|
$downSkuIds = array_diff($onSkuIds, $updateIds);
|
||||||
foreach ($downSkuIds as $downSkuId) {
|
$goodsSkus = GoodsSku::query()->whereIn('id', $downSkuIds)
|
||||||
$goodsSku = GoodsSku::query()->select(['id', 'yesterday_num', 'stock'])->find($downSkuId);
|
->get(['id', 'yesterday_num', 'stock'])
|
||||||
$goodsSku->yesterday_num -= $goodsSku->stock;
|
->toArray();
|
||||||
$goodsSku->stock = 0;
|
foreach ($goodsSkus as $goodsSku) {
|
||||||
$goodsSku->save();
|
GoodsSku::query()->where('id', $goodsSku['id'])->update([
|
||||||
|
'yesterday_num' => $goodsSku['yesterday_num'] - $goodsSku['stock'],
|
||||||
|
'stock' => 0,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
sleep(2);
|
sleep(2);
|
||||||
event(new StockUpdateEvent($onSkuIds, 1));
|
event(new StockUpdateEvent($onSkuIds, 1));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user