Browse Source

检索优化

dev
nizongfeng 3 years ago
parent
commit
2103e15ceb
4 changed files with 47 additions and 3 deletions
  1. +21
    -2
      application/admin/dao/PaymentOrderDao.php
  2. +14
    -1
      application/admin/dao/ReceiptOrderDao.php
  3. +6
    -0
      application/admin/view/payment_order/index.html
  4. +6
    -0
      application/admin/view/receipt_order/index.html

+ 21
- 2
application/admin/dao/PaymentOrderDao.php View File

@@ -123,20 +123,39 @@ class PaymentOrderDao
if ($param['status']."" != 'all') { if ($param['status']."" != 'all') {
$where["a.status"] = $param['status']; $where["a.status"] = $param['status'];
} }
$having = [];
if(!empty($param['startCost']) && !empty($param['endCost'])) {
$having[] = " (itemMoney >= {$param['startCost']} and itemMoney <= {$param['endCost']} ) or (hotelMoney >= {$param['startCost']} and hotelMoney <= {$param['endCost']} ) ";
}
if(!empty($param['startCost']) && empty($param['endCost'])) {
$having[] = " (itemMoney >= {$param['startCost']} ) or (hotelMoney >= {$param['startCost']} ) ";
}
if(empty($param['startCost']) && !empty($param['endCost'])) {
$having[] = " (itemMoney <= {$param['endCost']} ) or (hotelMoney <= {$param['endCost']} ) ";
}
$offset = ($param['pageNum'] - 1) * $param['pageSize']; $offset = ($param['pageNum'] - 1) * $param['pageSize'];
$receiptOrder = new PaymentOrder(); $receiptOrder = new PaymentOrder();
$total = $receiptOrder $total = $receiptOrder
->alias("a") ->alias("a")
->field("a.*,
(SELECT ifnull( sum( total_cost ), 0 ) from hbp_order_item where payment_order_id = a.id) 'itemMoney',
(SELECT ifnull( sum( total_cost ), 0 ) from hbp_order_hotel where payment_order_id = a.id) 'hotelMoney'
")
->group("a.id") ->group("a.id")
->where($where)->count();
->where($where)
->having(join("and", $having))
->count();
$list = $receiptOrder $list = $receiptOrder
->alias("a") ->alias("a")
->field("a.*, ->field("a.*,
(SELECT concat('订单:',ifnull( GROUP_CONCAT( id ORDER BY id DESC ), '-' ), '</br>成本:',ifnull( sum( total_cost ), '-' )) from hbp_order_item where payment_order_id = a.id) 'item', (SELECT concat('订单:',ifnull( GROUP_CONCAT( id ORDER BY id DESC ), '-' ), '</br>成本:',ifnull( sum( total_cost ), '-' )) from hbp_order_item where payment_order_id = a.id) 'item',
(SELECT concat('订单:',ifnull( GROUP_CONCAT( id ORDER BY id DESC ), '-' ), '</br>成本:',ifnull( sum( total_cost ), '-' )) from hbp_order_hotel where payment_order_id = a.id) 'hotel'
(SELECT concat('订单:',ifnull( GROUP_CONCAT( id ORDER BY id DESC ), '-' ), '</br>成本:',ifnull( sum( total_cost ), '-' )) from hbp_order_hotel where payment_order_id = a.id) 'hotel',
(SELECT ifnull( sum( total_cost ), 0 ) from hbp_order_item where payment_order_id = a.id) 'itemMoney',
(SELECT ifnull( sum( total_cost ), 0 ) from hbp_order_hotel where payment_order_id = a.id) 'hotelMoney'
") ")
->group("a.id") ->group("a.id")
->where($where) ->where($where)
->having(join("and", $having))
->limit($offset, $param['pageSize']) ->limit($offset, $param['pageSize'])
->order("a.id","DESC")->select(); ->order("a.id","DESC")->select();




+ 14
- 1
application/admin/dao/ReceiptOrderDao.php View File

@@ -124,6 +124,16 @@ class ReceiptOrderDao
if ($param['status']."" != 'all') { if ($param['status']."" != 'all') {
$where["a.status"] = $param['status']; $where["a.status"] = $param['status'];
} }
$having = "";
if(!empty($param['startMoney']) && !empty($param['endMoney'])) {
$having = " total_amount >= {$param['startMoney']} and total_amount <= {$param['endMoney']} ";
}
if(!empty($param['startMoney']) && empty($param['endMoney'])) {
$having = " total_amount >= {$param['startMoney']} ";
}
if(empty($param['startMoney']) && !empty($param['endMoney'])) {
$having = " total_amount <= {$param['endMoney']} ";
}
$offset = ($param['pageNum'] - 1) * $param['pageSize']; $offset = ($param['pageNum'] - 1) * $param['pageSize'];
$receiptOrder = new ReceiptOrder(); $receiptOrder = new ReceiptOrder();
$total = $receiptOrder $total = $receiptOrder
@@ -131,7 +141,9 @@ class ReceiptOrderDao
->join('hbp_order_main b', 'a.id = b.receipt_order_id', 'left') ->join('hbp_order_main b', 'a.id = b.receipt_order_id', 'left')
->field("a.*,GROUP_CONCAT(b.id) order_ids,sum(b.total_amount) total_amount") ->field("a.*,GROUP_CONCAT(b.id) order_ids,sum(b.total_amount) total_amount")
->group("a.id") ->group("a.id")
->where($where)->count();
->where($where)
->having($having)
->count();


$list = $receiptOrder $list = $receiptOrder
->alias("a") ->alias("a")
@@ -139,6 +151,7 @@ class ReceiptOrderDao
->field("a.*,GROUP_CONCAT(b.id ORDER BY b.id DESC) order_ids,sum(b.total_amount) total_amount") ->field("a.*,GROUP_CONCAT(b.id ORDER BY b.id DESC) order_ids,sum(b.total_amount) total_amount")
->group("a.id") ->group("a.id")
->where($where) ->where($where)
->having($having)
->limit($offset, $param['pageSize']) ->limit($offset, $param['pageSize'])
->order("id","DESC")->select(); ->order("id","DESC")->select();
$data = ["total" => $total, "list" => $list->toArray()]; $data = ["total" => $total, "list" => $list->toArray()];


+ 6
- 0
application/admin/view/payment_order/index.html View File

@@ -20,6 +20,10 @@
:value="item.id"> :value="item.id">
</el-option> </el-option>
</el-select> </el-select>
<span>成本</span>
<el-input-number v-model="search.startCost" style="width: 170px;" placeholder="请输入内容" clearable></el-input-number>
~
<el-input-number v-model="search.endCost" style="width: 170px;" placeholder="请输入内容" clearable></el-input-number>
<el-button type="primary" icon="el-icon-search" @click="getData(1)">搜索</el-button> <el-button type="primary" icon="el-icon-search" @click="getData(1)">搜索</el-button>
<el-button type="primary" icon="el-icon-plus" @click="edit(null)">新增付款单</el-button> <el-button type="primary" icon="el-icon-plus" @click="edit(null)">新增付款单</el-button>
</div> </div>
@@ -285,6 +289,8 @@
search: { search: {
name: "", name: "",
status: "all", status: "all",
startCost:"",
endCost:"",
pageSize: 10, pageSize: 10,
pageNum: 1 pageNum: 1
}, },


+ 6
- 0
application/admin/view/receipt_order/index.html View File

@@ -20,6 +20,10 @@
:value="item.id"> :value="item.id">
</el-option> </el-option>
</el-select> </el-select>
<span>成本</span>
<el-input-number v-model="search.startMoney" style="width: 170px;" placeholder="请输入内容" clearable></el-input-number>
~
<el-input-number v-model="search.endMoney" style="width: 170px;" placeholder="请输入内容" clearable></el-input-number>
<el-button type="primary" icon="el-icon-search" @click="getData(1)">搜索</el-button> <el-button type="primary" icon="el-icon-search" @click="getData(1)">搜索</el-button>
<el-button type="primary" icon="el-icon-plus" @click="edit(null)">新增收款单</el-button> <el-button type="primary" icon="el-icon-plus" @click="edit(null)">新增收款单</el-button>
</div> </div>
@@ -252,6 +256,8 @@
search: { search: {
name: "", name: "",
status: "all", status: "all",
startMoney:0,
endMoney:0,
pageSize: 10, pageSize: 10,
pageNum: 1 pageNum: 1
}, },


Loading…
Cancel
Save