func AppOperateRecharge(a *decorator.ApiBase) error { logger.AccessLogger.Info("AppOperateRecharge...") resp := adminStruct.BusinessOrderRecharge{} a.Ts.Table("business_base as a"). Select("s.bid, a.bname, s.acct_bal,s.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, 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"). Where("a.bid=?", a.Token.LinkId). Group("a.bid"). Scan(resp) return a.ReturnSuccessCustomResponse(resp) }商家状态为状态0入驻成功1信息待完善2信息审核中3信息审核通过4信息审核不通过5综合评级中6入驻拒绝9删除返回结构体Statustype BusinessOrderRecharge struct { Bid int64 `json:"bid"` // 商家ID Bname string `json:"bname"` // 商家名称 Acct_Bal int64 `json:"acct_bal" ` //账面余额 Buy_sum_amt int64 `json:"buy_sum_amt" ` //采购货款 Unpaid_amt int64 `json:"unpaid_amt"` //待结算货款 Stmt_amt int64 `json:"stmt_amt"` //已结算金额 Admin_uid int64 `json:"admin_Uid"` //管理员 Admin_name string `json:"admin_name"` //管理员姓名 Status string `json:"status"` //商家状态 }
时间: 2024-04-18 17:27:41 浏览: 99
这段代码是一个名为`AppOperateRecharge`的函数,它接受一个名为`a`的指向`decorator.ApiBase`类型的指针作为参数,并返回一个`error`类型的值。
函数首先记录一条日志信息,然后创建一个名为`resp`的`adminStruct.BusinessOrderRecharge`类型的变量。
接下来,函数使用`a.Ts.Table`方法查询数据库中的数据,并将查询结果存储到`resp`变量中。查询语句使用了多个`Joins`方法进行表连接操作,并使用了`Where`方法添加了一个条件。
最后,函数调用`a.ReturnSuccessCustomResponse`方法,并将`resp`作为参数传递给该方法,并返回其返回值。
在返回结构体`BusinessOrderRecharge`中,包含了商家的各种信息,例如商家ID(`Bid`)、商家名称(`Bname`)、账面余额(`Acct_Bal`)、采购货款(`Buy_sum_amt`)等等。
相关问题
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) }
在给出的代码中,你想要查询待结算商家的待结算货款和已结算货款,并将结果存储到结构体`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`中。
请注意,这只是一个修改的示例,具体根据你的业务逻辑和数据结构来进行调整。
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)
```
请注意,这只是一个示例修改,具体的实现可能因为代码结构和需求的不同而有所调整。
阅读全文