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) } type 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" //商家状态 }查看表商家状态字段Status1为返回入驻成功2为待审核并传入结构体Status中
时间: 2024-04-16 13:25:34 浏览: 62
这段代码是一个名为AppOperateRecharge的函数,它接受一个名为a的指向decorator.ApiBase类型的指针作为参数,并返回一个错误。函数内部首先打印日志信息"AppOperateRecharge...",然后定义一个名为resp的adminStruct.BusinessOrderRecharge类型的变量。接下来,它使用a.Ts.Table方法选择表"business_base"并将查询结果存储到resp变量中。查询语句使用了多个左连接(left join)来连接多个表,并通过Where子句指定了条件"a.bid=?",其中a.Token.LinkId表示查询条件的值。最后,通过Group方法对结果进行分组,并使用Scan方法将结果存储到resp变量中。
函数最后使用a.ReturnSuccessCustomResponse方法将resp作为参数返回。
在这段代码中,adminStruct.BusinessOrderRecharge结构体定义了多个字段,包括Bid、Bname、Acct_Bal等,用于存储查询结果的不同列的值。其中Status字段表示商家状态。根据你提供的信息,商家状态字段的值1表示返回入驻成功,值2表示待审核。这些状态值会被传入到BusinessOrderRecharge结构体的Status字段中。
相关问题
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)
```
请注意,这只是一个示例修改,具体的实现可能因为代码结构和需求的不同而有所调整。
阅读全文