Parcourir la source

检索优化

dev
nizongfeng il y a 3 ans
Parent
révision
2103e15ceb
4 fichiers modifiés avec 47 ajouts et 3 suppressions
  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 Voir le fichier

@@ -123,20 +123,39 @@ class PaymentOrderDao
if ($param['status']."" != 'all') {
$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'];
$receiptOrder = new PaymentOrder();
$total = $receiptOrder
->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")
->where($where)->count();
->where($where)
->having(join("and", $having))
->count();
$list = $receiptOrder
->alias("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_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")
->where($where)
->having(join("and", $having))
->limit($offset, $param['pageSize'])
->order("a.id","DESC")->select();



+ 14
- 1
application/admin/dao/ReceiptOrderDao.php Voir le fichier

@@ -124,6 +124,16 @@ class ReceiptOrderDao
if ($param['status']."" != 'all') {
$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'];
$receiptOrder = new ReceiptOrder();
$total = $receiptOrder
@@ -131,7 +141,9 @@ class ReceiptOrderDao
->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")
->group("a.id")
->where($where)->count();
->where($where)
->having($having)
->count();

$list = $receiptOrder
->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")
->group("a.id")
->where($where)
->having($having)
->limit($offset, $param['pageSize'])
->order("id","DESC")->select();
$data = ["total" => $total, "list" => $list->toArray()];


+ 6
- 0
application/admin/view/payment_order/index.html Voir le fichier

@@ -20,6 +20,10 @@
:value="item.id">
</el-option>
</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-plus" @click="edit(null)">新增付款单</el-button>
</div>
@@ -285,6 +289,8 @@
search: {
name: "",
status: "all",
startCost:"",
endCost:"",
pageSize: 10,
pageNum: 1
},


+ 6
- 0
application/admin/view/receipt_order/index.html Voir le fichier

@@ -20,6 +20,10 @@
:value="item.id">
</el-option>
</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-plus" @click="edit(null)">新增收款单</el-button>
</div>
@@ -252,6 +256,8 @@
search: {
name: "",
status: "all",
startMoney:0,
endMoney:0,
pageSize: 10,
pageNum: 1
},


Chargement…
Annuler
Enregistrer