func PostFeedBackList(a *decorator.ApiBase, data *adminStruct.FeedBackList) error { logger.AccessLogger.Info("PostFeedBackList...") res := adminStruct.AfterSaleResp{} f := []adminStruct.AFeedBackList{} query := a.Ts.Table("feedback a"). Select("a.fid,a.gid,m.star,u.user_name,a.appraise_time,boi.order_no,m.shop_id"). Joins("left join reply_temp m on a.mid=m.mid"). Joins("left join business_order_info boi on boi.uid=a.uid"). Joins("left join user_base u on u.uid=a.uid ") if len(data.ShopId) > 0 { query = query.Where("m.shop_id like ?", data.ShopId) } if data.Gid > 0 { query = query.Where("a.gid like ?", data.Gid) } if len(data.OrderNo) > 0 { query = query.Where("boi.order_no like ?", data.OrderNo) } if len(data.UserName) > 0 { query = query.Where("u.user_name like ?", data.UserName) } if data.Star > 0 { query = query.Where("m.star like ?", data.Star) } if data.AppraiseTime > 0 { query = query.Where("a.appraise_time like ? ", data.AppraiseTime) } utils.Error(query.Find(&res.Data).Error) var fids []int64 for _, i := range res.Data { fids = append(fids, i.Fid) } utils.Error(a.Ts.Table("feedback a"). Select("g.image,g.gname,boi.order_no,u.user_name,m.star,a.appraise_time,a.appraise_text,m.country,m.shop_id"). Joins("left join goods_base g on a.gid=g.gid"). Joins("left join reply_temp m on a.mid=m.mid"). Joins("left join business_order_info boi on boi.uid=a.uid"). Joins("left join user_base u on u.uid=a.uid "). Where("a.fid like ?", fids). Find(&f). Error) return a.ReturnSuccessCustomResponse(res) }
时间: 2024-04-18 12:26:31 浏览: 20
为了在`PostFeedBackList`函数中添加商家名称的搜索显示功能,可以按照以下步骤进行修改:
1. 在`data`结构体中添加一个名为`BusinessName`的字符串字段,用于接收商家名称作为搜索条件。
```go
type FeedBackList struct {
// ...
BusinessName string `json:"businessName"`
// ...
}
```
2. 在查询语句中添加一个条件,根据商家名称进行模糊匹配。可以使用`LIKE`关键字和`%`通配符来实现模糊搜索。
```go
query := a.Ts.Table("feedback a").
Select("a.fid, a.gid, m.star, u.user_name, a.appraise_time, boi.order_no, m.shop_id").
Joins("left join reply_temp m on a.mid = m.mid").
Joins("left join business_order_info boi on boi.uid = a.uid").
Joins("left join user_base u on u.uid = a.uid")
if len(data.BusinessName) > 0 {
query = query.Where("m.shop_id LIKE ?", "%"+data.BusinessName+"%")
}
```
在上述代码中,我们使用`Where`方法添加了一个条件,使用`LIKE`和通配符进行模糊匹配,并将商家名称作为参数传递给了`Where`方法。
这样,当调用`PostFeedBackList`函数时,可以通过传递`BusinessName`字段作为参数来进行商家名称的搜索,例如:
```go
data := &adminStruct.FeedBackList{
// ...
BusinessName: "商家名称",
// ...
}
err := PostFeedBackList(a, data)
```
请注意,这只是一个示例修改,具体的实现可能因为代码结构和需求的不同而有所调整。