liufumingren e8605149c0 初始化
2026-08-06 17:04:35 +08:00

67 lines
2.6 KiB
PHP

<?php
namespace app\index\library\qimen;
use Exception;
use think\Db;
use think\db\exception\BindParamException;
use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException;
use think\exception\DbException;
use think\exception\PDOException;
use think\exception\ValidateException;
class Inventory extends Main
{
protected $StockModel;
protected $StockBarcodesModel;
public function __construct(){
parent::_initialize();
}
public function query($data)
{
$criteriaList = $data['criteriaList']['criteria'];
$items = [];
$itemIds = array_column($criteriaList, 'itemId');
// 直接使用id字段查询
$stockList = $this->StockQimenModel
->alias("qimen_stock")
->field("qimen_stock.warehouse_code as warehouseCode,
qimen_stock.id as itemId,
qimen_stock.goods_code as itemCode,
SUM(CASE WHEN storage.stock_status = 'NORMAL' THEN storage.quantity ELSE 0 END) as quantity,
SUM(CASE WHEN storage.stock_status = 'FROZEN' THEN storage.locked_quantity ELSE 0 END) as lockQuantity,
storage.inventory_type as inventoryType,
'' as batchCode,
'' as productDate,
'' as expireDate,
'' as produceCode")
->join("wms_storage storage", "storage.stock_id = qimen_stock.stock_id and storage.warehouse_id = qimen_stock.warehouse_id and storage.store_id=qimen_stock.store_id", "left")
->where('qimen_stock.id', 'in', $itemIds)
->group("qimen_stock.id, storage.inventory_type") // 保持按库存类型分组
->select();
foreach ($stockList as $stock) {
$items[] = [
'warehouseCode' => $stock['warehouseCode'],
'itemCode' => $stock['itemCode'],
'itemId' => $stock['itemId'],
'inventoryType' => $stock['inventoryType'] ?? 'ZP',
'quantity' => (int)$stock['quantity'],
'lockQuantity' => (int)$stock['lockQuantity'],
'batchCode' => $stock['batchCode'],
'productDate' => $stock['productDate'],
'expireDate' => $stock['expireDate'],
'produceCode' => $stock['produceCode'],
'extendProps' => []
];
}
return [
'flag' => 'success',
'code' => '1',
'message' => count($items) > 0 ? '匹配商品成功' : json_encode($itemIds),
'items' => $items
];
}
}