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-21 13:24:25 浏览: 42
这段代码是一个名为 `AppOperateRecharge` 的函数,它接收两个参数:`a` 和 `data`。该函数的目的是查询并返回业务订单充值信息。
函数首先创建了一个名为 `resp` 的结构体变量,用于存储返回的数据。然后,打印了一条日志记录。
接下来,查询语句 `resQuerya` 被创建。它是一个复杂的查询,涉及多个表之间的连接和条件过滤。查询的目标是从数据库中检索业务订单的充值信息。
在创建查询语句时,根据 `data` 中的条件对查询进行了一系列的过滤。例如,根据业务名称进行模糊匹配过滤。
然后,通过执行 `Count` 方法获取满足条件的总记录数,并将其存储在 `resp.Count` 变量中。
如果存在满足条件的记录,继续执行查询业务订单充值信息的代码。该查询会获取与业务订单相关的充值信息,并将其存储在 `resp.Data` 中。
最后,通过调用 `a.ReturnSuccessCustomResponse(resp)` 方法,将查询结果作为成功的自定义响应返回。
需要注意的是,代码中使用了一些表之间的连接和聚合函数,并且在查询语句中使用了一些条件过滤和计算逻辑。
相关问题
修改这段代码里的错误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) }
修改后的代码如下:
```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` 字段中。这样,代码就能正常运行。
func AppOperateRecharge(a *decorator.ApiBase, data *adminStruct.BusinessOrderRecharge) 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 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 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 data.BusinessName > 0 { resQuerya = resQuerya.Where(" a.bname=?", data.BusinessName) } Count(&resp.Count). Offset(a.Offset). Limit(a.Size). Find(&resp.Data) return a.ReturnSuccessCustomResponse(resp) }
在函数`AppOperateRecharge`中增加商家名称搜索的功能,您可以按照以下修改:
```go
func AppOperateRecharge(a *decorator.ApiBase, data *adminStruct.BusinessOrderRecharge) 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 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 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.BusinessName) > 0 {
resQuerya = resQuerya.Where("a.bname LIKE ?", "%"+data.BusinessName+"%")
}
resQuerya.Count(&resp.Count).
Offset(a.Offset).
Limit(a.Size).
Find(&resp.Data)
return a.ReturnSuccessCustomResponse(resp)
}
```
在上述代码中,我们将函数的参数`data`改为`*adminStruct.BusinessOrderRecharge`类型,并在查询语句中添加了一个条件,根据商家名称进行模糊匹配。使用`LIKE`关键字和通配符`%`来实现模糊搜索。
这样,当调用`AppOperateRecharge`函数时,可以传递`BusinessName`字段作为参数进行商家名称的搜索,例如:
```go
data := &adminStruct.BusinessOrderRecharge{
// ...
BusinessName: "商家名称",
// ...
}
err := AppOperateRecharge(a, data)
```
请注意,这只是一个示例修改,具体的实现可能因为代码结构和需求的不同而有所调整。
阅读全文