修改这段代码里的错误func AppOperateRecharge(a *decorator.ApiBase, data *adminStruct.BusinessOrderRechargeName) error { logger.AccessLogger.Info("AppOperateRecharge...") resp := adminStruct.BusinessOrderRechargeResponse{} resp.ResponseCommon = a.NewSuccessResponseCommon() resQuerya := a.Ts.Table("business_base as a"). Select(`s.bid, a.bname, s.acct_bal, s.buy_sum_amt, + ifnull(sum(CASE WHEN b.stmt_status = 1 THEN b.stmt_amt ELSE 0 END), 0) as unpaid_amt, + ifnull(sum(i.order_amt) i.epay_status=0 and i.contract_no='' ),0)as buyunpaid, + ifnull(sum(CASE WHEN b.stmt_status = 0 THEN b.stmt_amt ELSE 0 END), 0 )as stmt_amt, + a.admin_uid, u.user_name, a.status`). Joins("left join source_pay_info as i on i.link_id=a.bid"). Joins("left join business_bal as s on s.bid=a.bid"). Joins("left join user_base as u on u.uid=a.admin_uid"). Joins("left join business_settlement as b on b.bid=a.bid"). Group("a.bid") if len(data.Bname) > 0 { resQuerya = resQuerya.Where("a.bname like ?", data.Bname) } utils.Error(resQuerya.Limit(a.Size). Offset(a.Offset).Count(&resp.Count). Find(&resp.Data).Error) return a.ReturnSuccessCustomResponse(resp) }
时间: 2024-04-17 18:24:57 浏览: 129
go-testing-interface:Go(golang)库将* testing.T公开为接口
修改后的代码如下:
```go
func AppOperateRecharge(a *decorator.ApiBase, data *adminStruct.BusinessOrderRechargeName) error {
logger.AccessLogger.Info("AppOperateRecharge...")
resp := adminStruct.BusinessOrderRechargeResponse{}
resp.ResponseCommon = a.NewSuccessResponseCommon()
resQuerya := a.Ts.Table("business_base as a").
Select(`s.bid, a.bname, s.acct_bal, s.buy_sum_amt,
ifnull(sum(CASE WHEN b.stmt_status = 1 THEN b.stmt_amt ELSE 0 END), 0) as unpaid_amt,
ifnull(sum(CASE WHEN i.epay_status=0 and i.contract_no='' and i.link_id = a.bid THEN i.order_amt ELSE 0 END), 0) as buyunpaid,
ifnull(sum(CASE WHEN b.stmt_status = 0 THEN b.stmt_amt ELSE 0 END), 0) as stmt_amt,
a.admin_uid, u.user_name, a.status`).
Joins("left join source_pay_info as i on i.link_id=a.bid").
Joins("left join business_bal as s on s.bid=a.bid").
Joins("left join user_base as u on u.uid=a.admin_uid").
Joins("left join business_settlement as b on b.bid=a.bid").
Group("a.bid")
if len(data.Bname) > 0 {
resQuerya = resQuerya.Where("a.bname like ?", data.Bname)
}
utils.Error(resQuerya.Limit(a.Size).
Offset(a.Offset).Count(&resp.Count).
Find(&resp.Data).Error)
return a.ReturnSuccessCustomResponse(resp)
}
```
修改的地方在以下部分:
```go
ifnull(sum(i.order_amt) i.epay_status=0 and i.contract_no='' ),0)as buyunpaid,
```
修改为:
```go
ifnull(sum(CASE WHEN i.epay_status=0 and i.contract_no='' and i.link_id = a.bid THEN i.order_amt ELSE 0 END), 0) as buyunpaid,
```
修改后的代码将修复原来存在的错误。现在,`ifnull` 函数将正确计算满足条件的订单金额总和,并将结果存储在 `buyunpaid` 字段中。这样,代码就能正常运行。
阅读全文