!91 导出优化

Merge pull request !91 from develop
This commit is contained in:
赵世界 2022-09-02 09:06:19 +00:00 committed by Gitee
commit f1b7fb7feb
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -40,7 +40,7 @@ class GoodsSkusExport implements FromCollection, ShouldAutoSize
];
$map = [
'cost' => ['成本', '更新前成本', '更新后成本'],
'inventory' => ['库存', '盘点'],
'inventory' => ['库存', '盘点', '更新前盘点'],
];
$headTitle = array_merge($headTitle, $map[$this->type]);
$day = DateTimeUtils::getToday();
@ -53,7 +53,7 @@ class GoodsSkusExport implements FromCollection, ShouldAutoSize
->orderBy('id', 'asc')
->get();
foreach ($logs as $log) {
if ($log['before_update'] != $log['after_update']) {
if ($log['before_update'] != $log['after_update'] || (int)$log['after_update']) {
if (!isset($update[$log['target_id']])) {
$update[$log['target_id']]['before_update'] = $log['before_update'];
}
@ -72,7 +72,6 @@ class GoodsSkusExport implements FromCollection, ShouldAutoSize
$query->with(['type:id,name', 'brand:id,name']);
}]);
if ('inventory' === $this->type) {
$model->where('stock', '<>', 0);
$model->with(['daily' => function ($query) use ($day) {
$query->where('day', $day);
}]);
@ -90,13 +89,14 @@ class GoodsSkusExport implements FromCollection, ShouldAutoSize
$arr[4] = $item['sku_code'];
$arr[5] = $item['title'];
if ('cost' === $this->type) {
$arr[6] = $item['cost'];
$arr[7] = $update[$item['id']]['before_update'];
$arr[8] = $update[$item['id']]['after_update'];
$arr[6] = (string)$item['cost'];
$arr[7] = (string)$update[$item['id']]['before_update'];
$arr[8] = (string)$update[$item['id']]['after_update'];
}
if ('inventory' === $this->type) {
$arr[6] = $item['stock'];
$arr[7] = $item['daily']['inventory'];
$arr[6] = (string)$item['stock'];
$arr[7] = (string)$item['daily']['inventory'];
$arr[8] = (string)$update[$item['id']]['before_update'];
}
$bodyData[] = $arr;
}