$stffs = Pid_xstj('采购类', 20220609, 20220609);
$msg['count'] = count($stffs);
$msg['zt'] = 5;
$msg['msg'] = "查询成功";
$msg['erro'] = $stffs;
echo json_encode($msg, JSON_UNESCAPED_UNICODE);
function Pid_xstj($lb = '', $qtime = '', $ztime = '')
{ //通过Pid类别获取指定类别的总销售量 销售量为空的则忽略
if ($lb == '' || $qtime == '' || $ztime == '') { //如果 类别 或查询时间为空就直接返回失败
echo "没有接收到参数";
return null;
} else {
require "connet.php"; //引用连接文件
$stffs = lb_Pid($lb, 'ParentId'); //取出符合类别的所有Pid
$arr = [];
foreach ($stffs as $key => $value) { //遍历循环所有的Pid
$sql = "SELECT sum(if(gy is null,quan,gy)),sum(if(zzje is null,xsje,zzje)) FROM `jl` WHERE `pid`=:pid and `time`>={$qtime} and `time`<={$ztime}";
$stmt = $pdo->prepare($sql);
$stmt->execute(['pid' => $value['ParentId']]);
//die($stmt->debugDumpParams());
$stff = $stmt->fetch(pdo::FETCH_ASSOC);
if (intval($stff['sum(if(gy is null,quan,gy))']) > 0) {
$stff = ['name' => Pid_name($value['ParentId']), 'quan' => $stff['sum(if(gy is null,quan,gy))'], 'xsje' => round($stff['sum(if(zzje is null,xsje,zzje))'], 2), 'pid' => $value['ParentId']];
array_push($arr, $stff);
}
};
return $arr;
}
}
调试输出 (编码_Utf8到Ansi (网页_访问_对象 (“http://open.wfsever.cn:8081/bdxt/111.php”, , , , , , , , , , , 90)))