修改商品溯源导出
This commit is contained in:
parent
43b34ea55b
commit
7fc4d87249
@ -10,7 +10,7 @@ use app\admin\validate\product_source_link\ProductSourceLinkValidate;
|
||||
use app\common\model\product_source_link\ProductSourceLink;
|
||||
use app\common\model\product_source_link_info\ProductSourceLinkInfo;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use app\common\model\warehouse_order\WarehouseOrder;
|
||||
use app\common\model\warehouse_product\WarehouseProduct;
|
||||
use app\common\service\xlsx\ProductSourceLinkXsl;
|
||||
|
||||
|
||||
@ -105,17 +105,14 @@ class ProductSourceLinkController extends BaseAdminController
|
||||
if (!empty($params['warehouse_id'])) {
|
||||
$query->where('warehouse_id', $params['warehouse_id']);
|
||||
}
|
||||
$list = $query->with(['product', 'warehouse', 'purchase'])
|
||||
->field(['id', 'purchase_uid', 'product_id', 'warehouse_id',])
|
||||
$list = $query->with(['product', 'purchase'])
|
||||
->field(['id', 'purchase_uid', 'product_id'])
|
||||
->order(['id' => 'desc'])
|
||||
->group('purchase_uid,product_id')
|
||||
->select()
|
||||
->each(function ($item) {
|
||||
$item->total_nums = ProductSourceLinkInfo::where('product_id', $item->product_id)->where('oid', $item->id)->where('types', 1)->sum('nums');
|
||||
$item->warehouse_outbound_nums = ProductSourceLinkInfo::where('product_id', $item->product_id)->where('oid', $item->id)->where('types', 2)->sum('nums');
|
||||
})
|
||||
->toArray();
|
||||
$linkInfos = ProductSourceLinkInfo::whereIn('oid', array_column($list, 'id'))->select()->toArray();
|
||||
$orderSnList = WarehouseOrder::field('id,code')->whereIn('id', array_unique(array_column($linkInfos, 'link_id')))->select()->toArray();
|
||||
$orderSnList = WarehouseProduct::field('id,code')->whereIn('id', array_unique(array_column($linkInfos, 'link_id')))->select()->toArray();
|
||||
$orderSnList = reset_index($orderSnList, 'id');
|
||||
foreach ($list as &$item) {
|
||||
$item['in_order_no'] = [];
|
||||
@ -129,17 +126,17 @@ class ProductSourceLinkController extends BaseAdminController
|
||||
if (!empty($orderSnItem)) {
|
||||
$item['in_order_no'][] = $orderSnItem['code'];
|
||||
}
|
||||
$item['in_num'] = bcmul($item['in_num'], $linkInfo['nums'], 2);
|
||||
$item['in_num'] = bcadd($item['in_num'], $linkInfo['nums'], 2);
|
||||
} else {
|
||||
if (!empty($orderSnItem)) {
|
||||
$item['out_order_no'][] = $orderSnItem['code'];
|
||||
}
|
||||
$item['out_num'] = bcmul($item['out_num'], $linkInfo['nums'], 2);
|
||||
$item['out_num'] = bcadd($item['out_num'], $linkInfo['nums'], 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
$item['in_order_no'] = !empty($item['in_order_no']) ? implode(',', $item['in_order_no']) : '';
|
||||
$item['out_order_no'] =!empty($item['out_order_no']) ? implode(',', $item['out_order_no']) : '';
|
||||
$item['in_order_no'] = !empty($item['in_order_no']) ? implode(',', $item['in_order_no']) : '';
|
||||
$item['out_order_no'] =!empty($item['out_order_no']) ? implode(',', $item['out_order_no']) : '';
|
||||
}
|
||||
$file_path = (new ProductSourceLinkXsl())->export($list);
|
||||
return $this->success('导出成功', ['url' => $file_path]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user