PHP开发之订单列表统计当页金额总和
PHP开发之订单列表统计当页金额总和:
html:
<form onsubmit="return searchSubmit()" method="GET" class="form-inline" id="searchToolbar">
<div class="form-group">
<select class="form-control" name="type">
<option value="1">系统订单号</option>
<option value="2">商户订单号</option>
<option value="3">商品名称</option>
<option value="4">商品金额</option>
<option value="5">实付金额</option>
<option value="6">网站域名</option>
</select>
</div>
<div class="form-group" id="searchword">
<input type="text" class="form-control" name="kw" placeholder="搜索内容" style="min-width: 300px;">
</div>
<div class="input-group input-daterange">
<input type="text" id="starttime" name="starttime" class="form-control dates" placeholder="开始日期" autocomplete="off" title="留空则不限时间范围">
<span class="input-group-addon" onclick="$('#starttime').val('');$('#endtime').val('');" title="清除"><i class="fa fa-chevron-right"></i></span>
<input type="text" id="endtime" name="endtime" class="form-control dates" placeholder="结束日期" autocomplete="off" title="留空则不限时间范围">
</div>
<div class="form-group">
<select name="paytype" class="form-control"><?php echo $type_select?></select>
</div>
<div class="form-group">
<select name="dstatus" class="form-control"><option value="-1">全部状态</option><option value="0">状态未支付</option><option value="1">状态已支付</option><option value="2">状态已退款</option><option value="3">状态已冻结</option></select>
</div>
<button class="btn btn-primary" type="submit" ><i class="fa fa-search"></i> 搜索</button>
<a href="javascript:searchClear();total_money();" class="btn btn-default"><i class="fa fa-refresh"></i> 重置</a>
<a id="total_money"></a>
</form>
<table id="listTable">
</table>
jq部分:
$('form').submit(function(){
updateToolbar();
const defaultPageSize = 20;
const pageNumber = typeof window.$_GET['pageNumber'] != 'undefined' ? parseInt(window.$_GET['pageNumber']) : 1;
const pageSize = typeof window.$_GET['pageSize'] != 'undefined' ? parseInt(window.$_GET['pageSize']) : defaultPageSize;
var data = $('form').serialize();
$.ajax({
type : 'POST',
url : 'ajax2.php?act=total_money',
pageNumber: pageNumber,
pageSize: pageSize,
data : data,
dataType : 'json',
success : function(data) {
if(data.total_money){
$("#total_money").html('金额:'+data.total_money);
}else{
layer.alert('金额:');
}
},
error:function(data){
layer.msg('服务器错误');
}
});
})
function total_money(){
updateToolbar();
const defaultPageSize = 20;
const pageNumber = typeof window.$_GET['pageNumber'] != 'undefined' ? parseInt(window.$_GET['pageNumber']) : 1;
const pageSize = typeof window.$_GET['pageSize'] != 'undefined' ? parseInt(window.$_GET['pageSize']) : defaultPageSize;
var data = '';
$.ajax({
type : 'POST',
url : 'ajax2.php?act=total_money',
pageNumber: pageNumber,
pageSize: pageSize,
data : data,
dataType : 'json',
success : function(data) {
if(data.total_money){
$("#total_money").html('金额:'+data.total_money);
}else{
layer.alert('金额:');
}
},
error:function(data){
layer.msg('服务器错误');
}
});
}
后端接口部分:
case 'total_money':
$sql=" uid=$uid";
if(isset($_POST['paytype']) && !empty($_POST['paytype'])) {
$type = intval($_POST['paytype']);
$sql.=" AND A.`type`='$type'";
}elseif(isset($_POST['channel']) && !empty($_POST['channel'])) {
$channel = intval($_POST['channel']);
$sql.=" AND A.`channel`='$channel'";
}elseif(isset($_POST['subchannel']) && !empty($_POST['subchannel'])) {
$subchannel = intval($_POST['subchannel']);
$sql.=" AND A.`subchannel`='$subchannel'";
}
if(isset($_POST['dstatus']) && $_POST['dstatus']>-1) {
$dstatus = intval($_POST['dstatus']);
$sql.=" AND A.status='{$dstatus}'";
}
if(!empty($_POST['starttime']) || !empty($_POST['endtime'])){
if(!empty($_POST['starttime'])){
$starttime = daddslashes($_POST['starttime']);
$sql.=" AND A.addtime>='{$starttime} 00:00:00'";
}
if(!empty($_POST['endtime'])){
$endtime = daddslashes($_POST['endtime']);
$sql.=" AND A.addtime<='{$endtime} 23:59:59'";
}
}
if(isset($_POST['kw']) && !empty($_POST['kw'])) {
$kw=daddslashes($_POST['kw']);
if($_POST['type']==1){
$sql.=" AND A.`trade_no`='{$kw}'";
}elseif($_POST['type']==2){
$sql.=" AND A.`out_trade_no`='{$kw}'";
}elseif($_POST['type']==3){
$sql.=" AND A.`name` like '%{$kw}%'";
}elseif($_POST['type']==4){
$sql.=" AND A.`money`='{$kw}'";
}elseif($_POST['type']==5){
$sql.=" AND A.`realmoney`='{$kw}'";
}elseif($_POST['type']==6){
$sql.=" AND A.`domain`='{$kw}'";
}
}
$offset = intval($_POST['offset']);
$limit = intval($_POST['limit']);
$total_money = $DB->getColumn("SELECT sum(money) from pre_order A WHERE{$sql}");
exit(json_encode(['total_money'=>$total_money]));
break;
最后实现效果:
订单列表实现了当页的金额合计和筛选搜索的功能。