Commit c381a567 by liuyingkang

refactor(查询逻辑): 优化合同收款查询的SQL条件和日志记录

- 将HAVING条件改为WHERE条件提高查询效率
- 调整SQL构建顺序,先过滤后分组
- 增强日志记录内容,包含更多调试信息
- 启用合同类型筛选功能
- 调整金额计算字段的显示顺序
parent 2540ec48
......@@ -41,12 +41,15 @@ protected function grid()
$received_at['end'] = $_GET['received_at']['end'] ?? '';
$invoiced_at['start'] = $_GET['invoiced_at']['start'] ?? '';
$invoiced_at['end'] = $_GET['invoiced_at']['end'] ?? '';
//已收款
$receivedMoney = ModelsCovenantReceivePayment::getTotalReceivedAmount($params, $received_at, $invoiced_at);
//开票金额
$invoicedMoney = ModelsCovenantReceivePayment::getTotalInvoicedMoney($params, $received_at, $invoiced_at);
//已收款
$receivedMoney = ModelsCovenantReceivePayment::getTotalReceivedAmount($params, $received_at, $invoiced_at);
//已收款未开票
$receiptNoinvoice = ($receivedMoney - $invoicedMoney) > 0 ? number_format($receivedMoney - $invoicedMoney, 2) : 0;
//已开票未收款
$invoiceNoreceipt = ($invoicedMoney - $receivedMoney) > 0 ? number_format($invoicedMoney - $receivedMoney, 2) : 0;
// 添加一行表头数据
......@@ -105,7 +108,7 @@ protected function grid()
//$filter->like('lnum', '律师编号')->width(3);
$filter->like('lname', '律师名称')->width(3);
$filter->like('cnum', '合同编号')->width(3);
// $filter->equal('ctype', '合同类型')->select(ModelsCovenant::CTYPE)->width(3);
$filter->equal('ctype', '合同类型')->select(ModelsCovenant::CTYPE)->width(3);
// $filter->like('principal', '委托人')->width(3);
$filter->between('received_at', '收款日期')->date()->width(4);
$filter->between('invoiced_at', '开票日期')->date()->width(4);
......
......@@ -157,27 +157,21 @@ public function getList(array $param)
}
}
}
// 添加分组条件
$sql .= " GROUP BY rp.cid, c.cname, c.ctype, c.number, c.principal, c.principal_id, l.number, l.name";
// 添加having条件
if ($lnum) {
$sql .= " HAVING lnum = '$lnum'";
}
if ($lname) {
$sql .= " HAVING lname = '$lname'";
$sql .= " and l.name = '$lname'";
}
if ($cnum) {
$sql .= " HAVING cnum = '$cnum'";
$sql .= " and c.number = '$cnum'";
}
if ($ctype) {
$sql .= " HAVING ctype = '$ctype'";
}
if ($principal) {
$sql .= " HAVING principal = '$principal'";
$sql .= " and c.ctype = '$ctype'";
}
// 添加分组条件
$sql .= " GROUP BY rp.cid, c.cname, c.ctype, c.number, c.principal, c.principal_id, l.number, l.name";
// 添加分页
$sql .= " LIMIT $prePage OFFSET $offset_start";
......
......@@ -639,8 +639,17 @@ public static function getTotalMoney($params, $received_at, $invoiced_at,$rtype)
{
// 获取筛选条件
$lname = $params['lname'] ?? ''; // 律师姓名
Log::add('dubug-params', $params); // 记录SQL日志
//$lnum = $params['lnum'] ?? ''; // 律师编号
$cnum = $params['cnum'] ?? ''; // 合同编号
$ctype = $params['ctype'] ?? ''; // 合同类型
//$principal = $params['principal'] ?? ''; // 委托人
Log::add('dubug-getTotalMoney', [
'params'=>$params,
'received_at'=>$received_at,
'invoiced_at'=>$invoiced_at,
'rtype'=>$rtype,
]); // 记录SQL日志
// 构建基础SQL
$sql = "SELECT rp.cid, c.cname, c.ctype, c.number as cnum, c.principal, c.principal_id,
......@@ -699,13 +708,21 @@ public static function getTotalMoney($params, $received_at, $invoiced_at,$rtype)
}
}
}
// 添加分组和having条件
$sql .= " GROUP BY rp.cid, c.cname, c.ctype, c.number, c.principal, c.principal_id, l.number, l.name";
if ($lname) {
$sql .= " HAVING lname = '$lname'";
$sql .= " and l.name = '$lname'";
}
if ($cnum) {
$sql .= " and c.number = '$cnum'";
}
if ($ctype) {
$sql .= " and c.ctype = '$ctype'";
}
// 添加分组和having条件
$sql .= " GROUP BY rp.cid, c.cname, c.ctype, c.number, c.principal, c.principal_id, l.number, l.name ";
Log::add('dubug-sql', $sql); // 记录SQL日志
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment