mirror of
https://gitee.com/hzchunfen/erp.git
synced 2025-11-30 22:20:45 +00:00
commit
0319b7da17
@ -8,11 +8,11 @@ use App\Models\GoodsSku;
|
||||
use App\Utils\DateTimeUtils;
|
||||
use Exception;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Maatwebsite\Excel\Concerns\SkipsEmptyRows;
|
||||
use Maatwebsite\Excel\Concerns\ToCollection;
|
||||
use App\Utils\ArrayUtils;
|
||||
use App\Events\StockUpdateEvent;
|
||||
|
||||
class InventoryImport implements ToCollection, SkipsEmptyRows
|
||||
{
|
||||
@ -36,34 +36,30 @@ class InventoryImport implements ToCollection, SkipsEmptyRows
|
||||
$updateIds = [];
|
||||
$day = DateTimeUtils::getToday();
|
||||
$dateTime = date('Y-m-d H:i:s');
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
foreach ($collection as $row) {
|
||||
if (!isset($hasGoods[$row[0]])) {
|
||||
continue;
|
||||
}
|
||||
$goodsSku = GoodsSku::query()
|
||||
->where('goods_id', $hasGoods[$row[0]]['id'])
|
||||
->where('sku_code', $row[4])
|
||||
->first();
|
||||
if (empty($goodsSku)) {
|
||||
Log::warning(json_encode($row, 256) . '=====库存导入未找到');
|
||||
continue;
|
||||
}
|
||||
$goodsSku->stock = $row[6] + $row[7];
|
||||
$goodsSku->save();
|
||||
$updateIds[] = $goodsSku->id;
|
||||
DailyStockRecord::query()->where('sku_id', $goodsSku->id)->where('day', $day)->update([
|
||||
'arrived_today_num' => $row[7],
|
||||
'inventory' => $row[6],
|
||||
'inventory_time' => $dateTime
|
||||
]);
|
||||
foreach ($collection as $row) {
|
||||
if (!isset($hasGoods[$row[0]])) {
|
||||
continue;
|
||||
}
|
||||
DB::commit();
|
||||
} catch (Exception $exception) {
|
||||
DB::rollBack();
|
||||
// 返回错误
|
||||
throw $exception;
|
||||
$goodsSku = GoodsSku::query()
|
||||
->where('goods_id', $hasGoods[$row[0]]['id'])
|
||||
->where('sku_code', $row[4])
|
||||
->first();
|
||||
if (empty($goodsSku)) {
|
||||
Log::warning(json_encode($row, 256) . '=====库存导入未找到');
|
||||
continue;
|
||||
}
|
||||
$goodsSku->stock = $row[6] + $row[7];
|
||||
if ('下架' === $goodsSku->status) {
|
||||
$goodsSku->status = 1;
|
||||
}
|
||||
$goodsSku->save();
|
||||
event(new StockUpdateEvent($goodsSku));
|
||||
$updateIds[] = $goodsSku->id;
|
||||
DailyStockRecord::query()->where('sku_id', $goodsSku->id)->where('day', $day)->update([
|
||||
'arrived_today_num' => $row[7],
|
||||
'inventory' => $row[6],
|
||||
'inventory_time' => $dateTime
|
||||
]);
|
||||
}
|
||||
$onSkuIds = GoodsSku::query()
|
||||
->where('status', '<>', 0)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user