diff --git a/app/admin/apis/migumanage/migu_admin.go b/app/admin/apis/migumanage/migu_admin.go index 0e5b9d0..3e1596a 100644 --- a/app/admin/apis/migumanage/migu_admin.go +++ b/app/admin/apis/migumanage/migu_admin.go @@ -11,7 +11,6 @@ import ( "net/http" "sort" "strconv" - "strings" "sync" "time" ) @@ -1852,37 +1851,8 @@ func (e MiGuDeployService) SysChannelList(c *gin.Context) { } var channels []models.ChannelData - - // 1. 查询mg_product表的ChannelCode - var productChannelCodes []string - var mgOrders []models.MgProduct - err = e.Orm.Model(&models.MgProduct{}). - Select("channel_api_id"). - Find(&mgOrders).Error - - if err != nil { - e.Logger.Error("查询产品渠道编码失败:", err) - response.Error(c, http.StatusInternalServerError, err, "查询失败") - return - } - - // 2. 拆分逗号分隔的ChannelCode,并去除空白 - for _, order := range mgOrders { - channelCodes := strings.Split(order.ChannelApiID, ",") - for _, code := range channelCodes { - code = strings.TrimSpace(code) // 去掉前后空白 - if code != "" { - productChannelCodes = append(productChannelCodes, code) - } - } - } - - // 3. 查询mg_channel表的MainChannelCode和SubChannelCode var mgChannels []models.MgChannel - err = e.Orm.Model(&models.MgChannel{}). - Select("main_channel_code, sub_channel_code"). - Find(&mgChannels).Error - + err = e.Orm.Model(&models.MgChannel{}).Where("status = 1").Find(&mgChannels).Error if err != nil { e.Logger.Error("查询渠道列表失败:", err) response.Error(c, http.StatusInternalServerError, err, "查询失败") @@ -1892,14 +1862,8 @@ func (e MiGuDeployService) SysChannelList(c *gin.Context) { // 4. 构建所有组合,并剔除重复的渠道编码 channelSet := make(map[string]struct{}) - // 添加产品表中的渠道编码 - for _, code := range productChannelCodes { - channelSet[code] = struct{}{} - } - // 添加渠道表中的主渠道和子渠道编码 for _, channel := range mgChannels { - channelSet[channel.MainChannelCode] = struct{}{} channelSet[channel.SubChannelCode] = struct{}{} } @@ -1930,6 +1894,113 @@ func (e MiGuDeployService) SysChannelList(c *gin.Context) { e.OK(resp, "") } +//func (e MiGuDeployService) SysChannelList(c *gin.Context) { +// err := e.MakeContext(c).MakeOrm().Errors +// if err != nil { +// e.Logger.Error(err) +// response.Error(c, http.StatusInternalServerError, err, "数据库连接失败") +// return +// } +// +// req := &models.SysChannelListReq{} +// if c.ShouldBindJSON(req) != nil { +// e.Logger.Error("参数解析失败") +// response.Error(c, http.StatusBadRequest, errors.New("参数错误"), "参数错误") +// return +// } +// +// resp := models.SysChannelListResp{ +// PageNum: req.PageNum, +// PageSize: req.PageSize, +// } +// +// pageNum := req.PageNum - 1 +// if pageNum < 0 { +// pageNum = 0 +// } +// if req.PageSize == 0 { +// req.PageSize = 10 +// } +// +// var channels []models.ChannelData +// +// // 1. 查询mg_product表的ChannelCode +// var productChannelCodes []string +// var mgOrders []models.MgProduct +// err = e.Orm.Model(&models.MgProduct{}). +// Select("channel_api_id"). +// Find(&mgOrders).Error +// +// if err != nil { +// e.Logger.Error("查询产品渠道编码失败:", err) +// response.Error(c, http.StatusInternalServerError, err, "查询失败") +// return +// } +// +// // 2. 拆分逗号分隔的ChannelCode,并去除空白 +// for _, order := range mgOrders { +// channelCodes := strings.Split(order.ChannelApiID, ",") +// for _, code := range channelCodes { +// code = strings.TrimSpace(code) // 去掉前后空白 +// if code != "" { +// productChannelCodes = append(productChannelCodes, code) +// } +// } +// } +// +// // 3. 查询mg_channel表的MainChannelCode和SubChannelCode +// var mgChannels []models.MgChannel +// err = e.Orm.Model(&models.MgChannel{}). +// Select("main_channel_code, sub_channel_code"). +// Find(&mgChannels).Error +// +// if err != nil { +// e.Logger.Error("查询渠道列表失败:", err) +// response.Error(c, http.StatusInternalServerError, err, "查询失败") +// return +// } +// +// // 4. 构建所有组合,并剔除重复的渠道编码 +// channelSet := make(map[string]struct{}) +// +// // 添加产品表中的渠道编码 +// for _, code := range productChannelCodes { +// channelSet[code] = struct{}{} +// } +// +// // 添加渠道表中的主渠道和子渠道编码 +// for _, channel := range mgChannels { +// channelSet[channel.MainChannelCode] = struct{}{} +// channelSet[channel.SubChannelCode] = struct{}{} +// } +// +// // 5. 转换为ChannelData结构体并分页 +// for code := range channelSet { +// if code != "" { // 跳过空的channel_code +// channels = append(channels, models.ChannelData{ +// ChannelCode: code, +// }) +// } +// } +// +// // 总数 +// resp.Count = len(channels) +// +// // 分页 +// startIndex := pageNum * req.PageSize +// endIndex := startIndex + req.PageSize +// if startIndex > len(channels) { +// startIndex = len(channels) +// } +// if endIndex > len(channels) { +// endIndex = len(channels) +// } +// +// resp.List = channels[startIndex:endIndex] +// +// e.OK(resp, "") +//} + // HomepageDataSummary 查询首页汇总数据 // @Summary 查询首页汇总数据 // @Tags 2024-咪咕-管理后台