public function getStockBatchInfo($stockid = null, $goodsname = null, $batchno = null, $page = 1, $limit = 10)
{
// $params = request()->param();
// $stockid = $params['stockid'] ?? null;
// $goodsname = $params['goodsname'] ?? null;
// $batchno = $params['batchno'] ?? null;
// $page = $params['page'] ?? 1;
// $limit = $params['limit'] ?? 10;
try {
$query = Db::name('glg_stock');
// 只有当条件存在时才添加到查询中
if (!empty($stockid)) {
$query->where('stockid', $stockid);
}
if (!empty($goodsname)) {
$query->where('goodsname', $goodsname); // $query->where('goodsname', 'like', '%' . $goodsname . '%'); // 支持模糊查询
}
if (!empty($batchno)) {
$query->where('batchno', $batchno);
}
// 获取总数
$count = $query->count();
// 获取分页数据
$result = $query->page($page, $limit)->select(); // $result = $query->select();
return json([
'code' => 0, // layui成功的code为0
'msg' => '查询成功',
'count' => $count, // count($result),
'data' => $result
]);
} catch (\Exception $e) {
return json([
'code' => 1, // layui错误的code通常为1或其他非0值
'msg' => $e->getMessage(),
'count' => 0,
'data' => []
]);
}
}
// layui table配置示例
table.render({
elem: '#stockTable',
url: '/your-controller/getStockInfo',
method: 'post',
where: {
stockid: 'your_stockid_value',
goodsname: 'your_goodsname_value',
batchno: 'your_batchno_value'
},
cols: [[
{field: 'stockid', title: '库存ID'},
{field: 'goodsname', title: '商品名称'},
{field: 'batchno', title: '批次号'},
// 其他字段...
]],
page: true
});
版权归属:
Administrator
许可协议:
本文使用《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》协议授权
评论区