func AppOperateRecharge(a *decorator.ApiBase) error { logger.AccessLogger.Info("AppOperateRecharge...") resp := adminStruct.BusinessOrderRecharge{} err := a.Ts.Table("business_base as a"). Select('a.bid, a.bname, a.acct_bal, a.buy_Sum_Amt,sum(CASE WHEN b.stmt_status = 1 THEN a.stmt_amt ELSE 0 END) as unpaid_amt, sum(CASE WHEN b.stmt_status = 0 THEN a.stmt_amt ELSE 0 END) as stmt_amt, a.admin_uid, a.user_name, a.status'). 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.uid=a.bid"). Where("a.bid=?", a.Token.LinkId). Group("a.bid"). Scan(resp) if err != nil { return err } return a.ReturnSuccessCustomResponse(resp) }
时间: 2024-04-15 22:31:16 浏览: 113
在给出的代码中,你想要查询待结算商家的待结算货款和已结算货款,并将结果存储到结构体`BusinessOrderRecharge`中。为了实现这个目标,你需要对代码进行以下修改:
```go
func AppOperateRecharge(a *decorator.ApiBase) error {
logger.AccessLogger.Info("AppOperateRecharge...")
resp := adminStruct.BusinessOrderRecharge{}
err := a.Ts.Table("business_base as a").
Select("a.bid, a.bname, a.acct_bal, a.buy_Sum_Amt, sum(CASE WHEN b.stmt_status = 1 THEN a.stmt_amt ELSE 0 END) as unpaid_amt, sum(CASE WHEN b.stmt_status = 0 THEN a.stmt_amt ELSE 0 END) as stmt_amt, a.admin_uid, a.user_name, a.status").
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.uid=a.bid").
Where("a.bid=?", a.Token.LinkId).
Group("a.bid").
Scan(&resp)
if err != nil {
return err
}
return a.ReturnSuccessCustomResponse(resp)
}
```
在修改后的代码中,我更正了`Select`函数的参数,将单引号改为双引号,以正确表示字符串。同时,我还在`Scan`函数的参数中添加了取地址符`&`,以便将查询结果存储到结构体`resp`中。
请注意,这只是一个修改的示例,具体根据你的业务逻辑和数据结构来进行调整。
阅读全文