Browse Source

语音播报列表、新增编辑发布

hsun 2 years ago
parent
commit
507dd3bbde

+ 10 - 161
controller/voice_broadcast/voice_broadcast.go

@@ -8,7 +8,6 @@ import (
 	"hongze/hongze_yb/models/tables/voice_broadcast"
 	"hongze/hongze_yb/models/tables/voice_section"
 	"hongze/hongze_yb/services"
-	"hongze/hongze_yb/services/company"
 	"hongze/hongze_yb/services/user"
 	"hongze/hongze_yb/utils"
 	"strconv"
@@ -17,10 +16,12 @@ import (
 
 // BroadcastList
 // @Description 语音播报列表
-// @Param page_index			query int false "页码"
-// @Param page_size				query int false "每页数量"
-// @Param broadcast_id			query int false "语音播报id"
-// @Param section_id			query int false "板块id"
+// @Param page_index	query int false "页码"
+// @Param page_size		query int false "每页数量"
+// @Param broadcast_id	query int false "语音播报ID(分享进来的时候筛选用)"
+// @Param section_id	query int false "板块ID"
+// @Param author_id		query int false "作者ID(我的语音播报列表)"
+// @Param mine_status	query int false "语音播报状态:0-未发布 1-已发布 2-全部(我的语音播报列表)"
 // @Success 200 {object} []voiceResp.BroadcastListResp
 // @failure 400 {string} string "获取失败"
 // @Router /list [Post]
@@ -38,20 +39,8 @@ func BroadcastList(c *gin.Context) {
 	}
 
 	userinfo := user.GetInfoByClaims(c)
-	ok, checkInfo, _, err := company.CheckBaseFiccPermission(userinfo.CompanyID, int(userinfo.UserID))
+	list, err := services.GetVoiceBroadcastList(req.PageIndex, req.PageSize, req.SectionId, req.BroadcastId, req.AuthorId, req.MineStatus, userinfo)
 	if err != nil {
-		response.FailMsg("用户权限验证失败", "CheckBaseAuth-用户权限验证失败"+err.Error(), c)
-		c.Abort()
-		return
-	}
-	if !ok {
-		response.AuthError(checkInfo, "暂无权限", c)
-		c.Abort()
-		return
-	}
-	list, err := services.GetVoiceBroadcastList(req.PageIndex, req.PageSize, req.SectionId, req.BroadcastId, userinfo)
-	if err != nil {
-
 		response.FailMsg("获取语音播报列表失败,"+err.Error(), "QuestionList ErrMsg:"+err.Error(), c)
 		return
 	}
@@ -67,124 +56,6 @@ func BroadcastList(c *gin.Context) {
 	response.OkData("获取成功", resp, c)
 }
 
-// AddBroadcast
-// @Description 新建语音播报
-// @Param file  query  string  true  "音频文件"
-// @Success 200 {string} string "发布成功"
-// @failure 400 {string} string "发布失败"
-// @Router /add [post]
-//func AddBroadcast(c *gin.Context) {
-//	broadcastName := c.PostForm("broadcast_name")
-//	nsectionId := c.PostForm("section_id")
-//	sectionId, _ := strconv.Atoi(nsectionId)
-//	sectionName := c.PostForm("section_name")
-//	nvarietyId := c.PostForm("variety_id")
-//	varietyId, _ := strconv.Atoi(nvarietyId)
-//	varietyName := c.PostForm("variety_name")
-//	nauthorId := c.PostForm("author_id")
-//	authorId, _ := strconv.Atoi(nauthorId)
-//	author := c.PostForm("author")
-//	imgUrl := c.PostForm("img_url")
-//	file, err := c.FormFile("file")
-//	if err != nil {
-//		response.FailMsg("获取资源失败", "获取资源失败, Err:"+err.Error(), c)
-//		return
-//	}
-//	if imgUrl == "" {
-//		response.Fail("图片不能为空", c)
-//		return
-//	}
-//	// 生成动态分享图
-//	createTimeStr := time.Now().Local().Format(utils.FormatDate)
-//	pars := services.VoiceBroadcastShareImgPars{
-//		BackgroundImg: imgUrl,
-//		Title:         sectionName,
-//		CreateTime:    createTimeStr,
-//	}
-//	parsByte, e := json.Marshal(pars)
-//	if e != nil {
-//		response.Fail("分享图参数有误", c)
-//		return
-//	}
-//	shareImg, e := services.GetDynamicShareImg(services.VoiceBroadcastShareImgSource, string(parsByte))
-//	if e != nil {
-//		response.Fail("生成分享图失败", c)
-//		return
-//	}
-//
-//	ext := path.Ext(file.Filename)
-//	if ext != ".mp3" {
-//		response.Fail("暂仅支持mp3格式", c)
-//		return
-//	}
-//	dateDir := time.Now().Format("20060102")
-//	localDir := global.CONFIG.Serve.StaticDir + "hongze/" + dateDir
-//	if err := os.MkdirAll(localDir, 0766); err != nil {
-//		response.FailMsg("存储目录创建失败", "QuestionUploadAudio 存储目录创建失败, Err:"+err.Error(), c)
-//		return
-//	}
-//	randStr := utils.GetRandStringNoSpecialChar(28)
-//	filtName := randStr + ext
-//	fpath := localDir + "/" + filtName
-//	defer func() {
-//		_ = os.Remove(fpath)
-//	}()
-//	// 生成文件至指定目录
-//	if err := c.SaveUploadedFile(file, fpath); err != nil {
-//		response.FailMsg("文件生成失败", "QuestionUploadAudio 文件生成失败, Err:"+err.Error(), c)
-//		return
-//	}
-//	// 获取音频文件时长
-//	fByte, err := ioutil.ReadFile(fpath)
-//	if err != nil {
-//		response.FailMsg("读取本地文件失败", "QuestionUploadAudio 读取本地文件失败", c)
-//		return
-//	}
-//	if len(fByte) <= 0 {
-//		response.FailMsg("文件大小有误", "QuestionUploadAudio 文件大小有误", c)
-//		return
-//	}
-//	seconds, err := services.GetMP3PlayDuration(fByte)
-//	if err != nil {
-//		response.FailMsg("读取文件时长失败", "QuestionUploadAudio 读取文件时长失败", c)
-//		return
-//	}
-//	// 音频大小MB
-//	fi, err := os.Stat(fpath)
-//	if err != nil {
-//		response.FailMsg("读取文件大小失败", "QuestionUploadAudio 读取文件大小失败", c)
-//		return
-//	}
-//	mb := utils.Bit2MB(fi.Size(), 2)
-//	// 上传文件至阿里云
-//	ossDir := "yb_wx/voice_broadcast/"
-//	resourceUrl, err := services.UploadAliyunToDir(filtName, fpath, ossDir)
-//	if err != nil {
-//		response.FailMsg("文件上传失败", "QuestionUploadAudio 文件上传失败, Err:"+err.Error(), c)
-//		return
-//	}
-//
-//	voiceBroadcast := voice_broadcast.VoiceBroadcast{
-//		BroadcastName:    broadcastName,
-//		SectionId:        sectionId,
-//		SectionName:      sectionName,
-//		VarietyId:        varietyId,
-//		VarietyName:      varietyName,
-//		AuthorId:         authorId,
-//		Author:           author,
-//		ImgUrl:           shareImg,
-//		VoiceUrl:         resourceUrl,
-//		VoicePlaySeconds: fmt.Sprint(seconds),
-//		VoiceSize:        fmt.Sprint(mb),
-//		CreateTime:       time.Now().Format(utils.FormatDateTime),
-//	}
-//	err = voiceBroadcast.AddVoiceBroadcast()
-//	if err != nil {
-//		fmt.Println("AddUserViewHistory err", err.Error())
-//	}
-//	response.OkData("发布成功", voiceBroadcast.BroadcastId, c)
-//}
-
 // PublishBroadcast
 // @Description 发布语音播报
 // @Param broadcast_id		query  int  	false  	"语音播报ID"
@@ -396,8 +267,8 @@ func AddStatistics(c *gin.Context) {
 // BroadcastDetail 获取语音播报详情
 // @Tags 语音播报模块
 // @Description 获取语音播报详情
-// @Param variety_tag_id  query  int  true  "标签ID"
-// @Success 200 {object} response.PriceDrivenItem
+// @Param broadcast_id  query  int  true  "语音播报ID"
+// @Success 200 {object} voiceResp.Broadcast
 // @failure 400 {string} string "获取失败"
 // @Router /detail [get]
 func BroadcastDetail(c *gin.Context) {
@@ -411,33 +282,11 @@ func BroadcastDetail(c *gin.Context) {
 		return
 	}
 	userInfo := user.GetInfoByClaims(c)
-	item, e := voice_broadcast.GetBroadcastById(req.BroadcastId)
+	resp, e := services.GetVoiceBroadcastDetail(req.BroadcastId, int(userInfo.UserID))
 	if e != nil {
 		response.FailMsg("获取失败", "BroadcastDetail ErrMsg:"+e.Error(), c)
 		return
 	}
-	resp := &voiceResp.Broadcast{
-		BroadcastId:      item.BroadcastId,
-		BroadcastName:    item.BroadcastName,
-		SectionId:        item.SectionId,
-		SectionName:      item.SectionName,
-		VarietyId:        item.VarietyId,
-		VarietyName:      item.VarietyName,
-		AuthorId:         item.AuthorId,
-		Author:           item.Author,
-		ImgUrl:           item.ImgUrl,
-		VoiceUrl:         item.VoiceUrl,
-		VoicePlaySeconds: item.VoicePlaySeconds,
-		VoiceSize:        item.VoiceSize,
-		CreateTime:       item.CreateTime,
-	}
-	// 是否为作者、是否可以推送消息
-	if int(userInfo.UserID) == item.AuthorId {
-		resp.IsAuthor = true
-		if item.MsgState == 0 {
-			resp.CouldSendMsg = true
-		}
-	}
 	response.OkData("获取成功", resp, c)
 }
 

+ 56 - 25
logic/user/user.go

@@ -9,6 +9,7 @@ import (
 	"hongze/hongze_yb/models/tables/company_product"
 	"hongze/hongze_yb/models/tables/rddp/msg_code"
 	"hongze/hongze_yb/models/tables/research_variety_tag_relation"
+	"hongze/hongze_yb/models/tables/sys_role_admin"
 	"hongze/hongze_yb/models/tables/wx_user"
 	"hongze/hongze_yb/models/tables/yb_apply_record"
 	"hongze/hongze_yb/models/tables/yb_index_tab"
@@ -112,6 +113,7 @@ type Detail struct {
 	PermissionList []CompanyPermission `json:"permission_list" description:"权限列表"`
 	IsInner        int                 `json:"is_inner" description:"是否为内部员工"`
 	IsResearcher   int                 `json:"is_researcher" description:"是否为研究员"`
+	IsVoiceAdmin   int                 `json:"is_voice_admin" description:"是否为语音管理员"`
 	AdminInfo      *admin2.Admin       `json:"admin_info" description:"系统管理员信息"`
 	UnRead         int64               `json:"un_read" description:"消息未读数"`
 	NickName       string              `json:"nick_name" description:"用户昵称"`
@@ -201,17 +203,6 @@ func GetUserInfo(userInfo user.UserInfo) (userDetail Detail, err error, errMsg s
 		}
 
 	}
-	// 是否为内部员工
-	isInner := 0
-	ok, adminInfo, err := user.GetAdminByUserInfo(userInfo)
-	if err != nil {
-		err = errors.New("获取用户系统管理员信息失败")
-		errMsg = "系统异常4002"
-		return
-	}
-	if ok {
-		isInner = 1
-	}
 
 	// 查询消息未读数
 	unRead, err := yb_message.GetUnreadByUserId(userInfo.UserID)
@@ -223,18 +214,11 @@ func GetUserInfo(userInfo user.UserInfo) (userDetail Detail, err error, errMsg s
 	if headimgurl == "" {
 		headimgurl = utils.DEFAULT_HONGZE_USER_LOGO
 	}
-	// 查询是否为研究员
-	isResearcher := 0
-	if isInner == 1 {
-		researchGroupList, e := research_variety_tag_relation.GetResearchVarietyTagRelationByAdminId(int(adminInfo.AdminID))
-		if e != nil {
-			errMsg = "查询是否为研究员失败"
-			err = errors.New("用户身份信息有误")
-			return
-		}
-		if len(researchGroupList) > 0 {
-			isResearcher = 1
-		}
+
+	// 查询是否为内部员工、研究员、语音管理员
+	isInner, isResearcher, isVoiceAdmin, adminInfo, e := GetUserIdentity(int(userInfo.CompanyID), userInfo.Mobile, userInfo.Email)
+	if e != nil {
+		return
 	}
 
 	userDetail = Detail{
@@ -249,6 +233,7 @@ func GetUserInfo(userInfo user.UserInfo) (userDetail Detail, err error, errMsg s
 		PermissionList: list,         //权限列表
 		IsInner:        isInner,      // 是否为内部员工
 		IsResearcher:   isResearcher, // 是否为研究员
+		IsVoiceAdmin:   isVoiceAdmin, // 语音管理员
 		AdminInfo:      adminInfo,    // 系统管理员信息
 		UnRead:         unRead,
 		NickName:       userInfo.NickName,
@@ -536,11 +521,57 @@ func GetTopTab(userInfo user.UserInfo, version string) (list []*TopTab, err erro
 			continue
 		}
 		list = append(list, &TopTab{
-			Tab: v.Tab,
+			Tab:  v.Tab,
 			Mark: v.Mark,
 			Icon: v.DefaultIcon,
 			Sort: v.Sort,
 		})
 	}
 	return
-}
+}
+
+// GetUserIdentity 获取用户身份(内部员工、研究员、语音管理员)
+func GetUserIdentity(companyId int, mobile, email string) (isInner, isResearcher, isVoiceAdmin int, adminInfo *admin2.Admin, err error) {
+	if companyId != utils.HzCompanyId {
+		return
+	}
+	if mobile == "" && email == "" {
+		return
+	}
+	var e error
+	// 通过手机号/邮箱获取管理员信息
+	if mobile != "" {
+		adminInfo, e = admin2.GetAdminByMobile(mobile)
+		if e != nil && e != utils.ErrNoRow {
+			return
+		}
+	} else {
+		adminInfo, e = admin2.GetAdminByEmail(email)
+		if e != nil && e != utils.ErrNoRow {
+			return
+		}
+	}
+	// 仅内部员工才判断研究员、语音管理员身份
+	if adminInfo != nil && adminInfo.AdminID > 0 && adminInfo.Enabled == 1 {
+		isInner = 1
+		// 研究员
+		researchGroupList, e := research_variety_tag_relation.GetResearchVarietyTagRelationByAdminId(int(adminInfo.AdminID))
+		if e != nil {
+			err = errors.New("用户研究员信息有误")
+			return
+		}
+		if len(researchGroupList) > 0 {
+			isResearcher = 1
+		}
+		// 语音管理员
+		voiceAdmin, e := sys_role_admin.GetVoiceAdmin(int(adminInfo.AdminID))
+		if e != nil && e != utils.ErrNoRow {
+			err = errors.New("用户语音管理员信息有误")
+			return
+		}
+		if voiceAdmin != nil && voiceAdmin.Id > 0 {
+			isVoiceAdmin = 1
+		}
+	}
+	return
+}

+ 15 - 13
models/request/voice_broadcast.go

@@ -9,6 +9,8 @@ type BroadcastListReq struct {
 	PageSize    int `json:"page_size" form:"page_size"`
 	BroadcastId int `json:"broadcast_id" form:"broadcast_id"`
 	SectionId   int `json:"section_id" form:"section_id"`
+	AuthorId    int `json:"author_id" form:"author_id" description:"我的语音播报作者ID"`
+	MineStatus  int `json:"mine_status" form:"mine_status" description:"我的语音播报状态:0-未发布 1-已发布 2-全部"`
 }
 
 type AddBroadcastStatisticsReq struct {
@@ -25,17 +27,17 @@ type BroadcastMsgSendReq struct {
 }
 
 type SaveBroadcastReq struct {
-	BroadcastId      int                   `form:"broadcast_id" description:"语音播报ID"`
-	BroadcastName    string                `form:"broadcast_name" description:"语音标题"`
-	SectionId        int                   `form:"section_id" description:"板块ID"`
-	SectionName      string                `form:"section_name" description:"板块名称"`
-	VarietyId        int                   `form:"variety_id" description:"品种ID"`
-	VarietyName      string                `form:"variety_name" description:"品种名称"`
-	AuthorId         int                   `form:"author_id" description:"作者ID"`
-	Author           string                `form:"author" description:"作者名称"`
-	ImgUrl           string                `form:"img_url" description:"分享图背景"`
-	File             *multipart.FileHeader `form:"file" description:"语音文件"`
-	Imgs             string                `form:"imgs" description:"图片,英文逗号拼接"`
-	PublishType      int                   `form:"publish_type" description:"发布类型: 0-仅发布 1-发布并推送 2-定时发布"`
-	PrePublishTime   string                `form:"pre_publish_time" description:"预发布时间"`
+	BroadcastId    int                   `form:"broadcast_id" description:"语音播报ID"`
+	BroadcastName  string                `form:"broadcast_name" description:"语音标题"`
+	SectionId      int                   `form:"section_id" description:"板块ID"`
+	SectionName    string                `form:"section_name" description:"板块名称"`
+	VarietyId      int                   `form:"variety_id" description:"品种ID"`
+	VarietyName    string                `form:"variety_name" description:"品种名称"`
+	AuthorId       int                   `form:"author_id" description:"作者ID"`
+	Author         string                `form:"author" description:"作者名称"`
+	ImgUrl         string                `form:"img_url" description:"分享图背景"`
+	File           *multipart.FileHeader `form:"file" description:"语音文件"`
+	Imgs           string                `form:"imgs" description:"图片,英文逗号拼接"`
+	PublishType    int                   `form:"publish_type" description:"发布类型: 0-仅发布 1-发布并推送 2-定时发布"`
+	PrePublishTime string                `form:"pre_publish_time" description:"预发布时间"`
 }

+ 19 - 18
models/response/voice_broadcast.go

@@ -7,31 +7,32 @@ type BroadcastListResp struct {
 }
 
 type Broadcast struct {
-	BroadcastId      int    `description:"语音ID"`
-	BroadcastName    string `description:"语音名称"`
-	SectionId        int    `description:"语音分类ID"`
-	SectionName      string `description:"语音分类名称"`
-	VarietyId        int    `description:"品种id"`
-	VarietyName      string `description:"品种名称"`
-	AuthorId         int    `description:"作者id"`
-	Author           string `description:"作者"`
-	ImgUrl           string `description:"背景图url"`
-	VoiceUrl         string `description:"音频url"`
-	VoicePlaySeconds string `description:"音频时长"`
-	VoiceSize        string `description:"音频大小"`
-	CreateTime       string `description:"创建时间"`
-	IsAuthor         bool   `description:"是否为作者"`
-	CouldSendMsg     bool   `description:"是否可推送消息"`
+	BroadcastId      int      `description:"语音ID"`
+	BroadcastName    string   `description:"语音名称"`
+	SectionId        int      `description:"语音分类ID"`
+	SectionName      string   `description:"语音分类名称"`
+	VarietyId        int      `description:"品种id"`
+	VarietyName      string   `description:"品种名称"`
+	AuthorId         int      `description:"作者id"`
+	Author           string   `description:"作者"`
+	ImgUrl           string   `description:"背景图url"`
+	VoiceUrl         string   `description:"音频url"`
+	VoicePlaySeconds string   `description:"音频时长"`
+	VoiceSize        string   `description:"音频大小"`
+	CreateTime       string   `description:"创建时间"`
+	IsAuthor         bool     `description:"是否为作者"`
+	CouldSendMsg     bool     `description:"是否可推送消息"`
+	PublishState     int      `description:"发布状态:0-未发布 1-已发布"`
+	PrePublishTime   string   `description:"定时发布时间"`
+	Imgs             []string `description:"图片"`
 }
 
-//type SectionListResp struct {
-//	List []VarietyList
-//}
 type VarietyList struct {
 	VarietyId   int
 	VarietyName string
 	Children    []SectionList
 }
+
 type SectionList struct {
 	ImgUrl      string
 	SectionId   int

+ 1 - 1
models/tables/admin/admin.go

@@ -4,7 +4,7 @@ import "time"
 
 // Admin [...]
 type Admin struct {
-	AdminID                 int64     `gorm:"primaryKey;column:admin_id;type:bigint(20);not null" json:"-"`
+	AdminID                 int64     `gorm:"primaryKey;column:admin_id;type:bigint(20);not null" json:"adminId"`
 	AdminName               string    `gorm:"uniqueIndex:un;index:name;index:admin_pass;column:admin_name;type:varchar(60);not null" json:"adminName"`
 	AdminAvatar             string    `gorm:"column:admin_avatar;type:varchar(255)" json:"adminAvatar"`
 	RealName                string    `gorm:"column:real_name;type:varchar(60)" json:"realName"`

+ 11 - 1
models/tables/voice_broadcast/query.go

@@ -28,4 +28,14 @@ func GetBroadcastById(broadcastId int) (item *VoiceBroadcast, err error) {
 func GetBroadcastList() (list []*VoiceBroadcast, err error) {
 	err = global.DEFAULT_MYSQL.Model(VoiceBroadcast{}).Scan(&list).Error
 	return
-}
+}
+
+func GetPageListByCondition(condition string, pars []interface{}, pageIndex, pageSize int) (list []*VoiceBroadcast, err error) {
+	offset := (pageIndex - 1) * pageSize
+	err = global.DEFAULT_MYSQL.Model(VoiceBroadcast{}).
+		Where(condition, pars...).
+		Offset(offset).Limit(pageSize).
+		Order("create_time DESC").
+		Scan(&list).Error
+	return
+}

+ 26 - 0
models/tables/voice_broadcast_img/model.go

@@ -1 +1,27 @@
 package voice_broadcast_img
+
+import "hongze/hongze_yb/global"
+
+// GetVoiceImgListByVoiceIds 通过语音播报IDs获取图片列表
+func GetVoiceImgListByVoiceIds(idArr []int) (list []*YbVoiceBroadcastImg, err error) {
+	if len(idArr) == 0 {
+		return
+	}
+	err = global.DEFAULT_MYSQL.
+		Model(YbVoiceBroadcastImg{}).
+		Select("broadcast_id, img_url").
+		Where("broadcast_id IN ?", idArr).
+		Order("broadcast_id ASC, create_time ASC").
+		Scan(&list).Error
+	return
+}
+
+// GetVoiceImgListByVoiceId 通过语音播报ID获取图片列表
+func GetVoiceImgListByVoiceId(voiceId int) (list []*YbVoiceBroadcastImg, err error) {
+	err = global.DEFAULT_MYSQL.
+		Model(YbVoiceBroadcastImg{}).
+		Select("broadcast_id, img_url").
+		Where("broadcast_id = ?", voiceId).
+		Scan(&list).Error
+	return
+}

+ 1 - 1
routers/voice_broadcast.go

@@ -8,13 +8,13 @@ import (
 
 func InitVoiceBroadcast(r *gin.Engine)  {
 	rGroup := r.Group("api/voice/broadcast").Use(middleware.Token())
-	rGroup.POST("/list", voice_broadcast.BroadcastList)
 	rGroup.POST("/add", voice_broadcast.PublishBroadcast)
 	rGroup.GET("/section/list", voice_broadcast.SectionList)
 	rGroup.GET("/delete", voice_broadcast.DelBroadcast)
 	rGroup.POST("/statistics/add", voice_broadcast.AddStatistics)
 	// 权限校验
 	rGroup2 := r.Group("api/voice/broadcast").Use(middleware.Token(), middleware.CheckBaseAuth())
+	rGroup2.POST("/list", voice_broadcast.BroadcastList)
 	rGroup2.GET("/detail", voice_broadcast.BroadcastDetail)
 	rGroup2.POST("/msg_send", voice_broadcast.MsgSend)
 }

+ 110 - 171
services/voice_broadcast.go

@@ -12,7 +12,6 @@ import (
 	"hongze/hongze_yb/models/tables/voice_broadcast"
 	"hongze/hongze_yb/models/tables/voice_broadcast_img"
 	"hongze/hongze_yb/models/tables/voice_broadcast_statistics"
-	"hongze/hongze_yb/models/tables/voice_section"
 	"hongze/hongze_yb/services/user"
 	"hongze/hongze_yb/services/wechat"
 	"hongze/hongze_yb/utils"
@@ -24,110 +23,62 @@ import (
 	"time"
 )
 
-func GetVoiceBroadcastList(pageindex, pagesize, sectionId, broadcastId int, userInfo user.UserInfo) (list []response.Broadcast, err error) {
-	if broadcastId == 0 {
-		if sectionId == 0 {
-			broadList, e := voice_broadcast.GetBroadcast(pageindex, pagesize)
-			if e != nil {
-				e = errors.New("获取语音播报列表失败 Err:" + e.Error())
-			}
-			for _, item := range broadList {
-				var respItem response.Broadcast
-				respItem = response.Broadcast{
-					BroadcastId:      item.BroadcastId,
-					BroadcastName:    item.BroadcastName,
-					SectionId:        item.SectionId,
-					SectionName:      item.SectionName,
-					VarietyId:        item.VarietyId,
-					VarietyName:      item.VarietyName,
-					AuthorId:         item.AuthorId,
-					Author:           item.Author,
-					ImgUrl:           item.ImgUrl,
-					VoiceUrl:         item.VoiceUrl,
-					VoicePlaySeconds: item.VoicePlaySeconds,
-					VoiceSize:        item.VoiceSize,
-					CreateTime:       item.CreateTime,
-					IsAuthor:         false,
-				}
-				if int(userInfo.UserID) == item.AuthorId {
-					respItem.IsAuthor = true
-					// 是否可以推送消息
-					if item.MsgState == 0 {
-						respItem.CouldSendMsg = true
-					}
-				}
-				list = append(list, respItem)
-
-			}
-			err = e
-			return
-		}
-		broadList, e := voice_broadcast.GetBroadcastByCondition(pageindex, pagesize, sectionId)
-		if e != nil {
-			e = errors.New("获取语音播报列表失败 Err:" + e.Error())
-		}
-		for _, item := range broadList {
-			var respItem response.Broadcast
-			respItem = response.Broadcast{
-				BroadcastId:      item.BroadcastId,
-				BroadcastName:    item.BroadcastName,
-				SectionId:        item.SectionId,
-				SectionName:      item.SectionName,
-				VarietyId:        item.VarietyId,
-				VarietyName:      item.VarietyName,
-				AuthorId:         item.AuthorId,
-				Author:           item.Author,
-				ImgUrl:           item.ImgUrl,
-				VoiceUrl:         item.VoiceUrl,
-				VoicePlaySeconds: item.VoicePlaySeconds,
-				VoiceSize:        item.VoiceSize,
-				CreateTime:       item.CreateTime,
-				IsAuthor:         false,
-			}
-			if int(userInfo.UserID) == item.AuthorId {
-				respItem.IsAuthor = true
-				// 是否可以推送消息
-				if item.MsgState == 0 {
-					respItem.CouldSendMsg = true
-				}
-			}
-			list = append(list, respItem)
-
-		}
-		err = e
-		return
+// GetVoiceBroadcastList 获取语音播报列表
+func GetVoiceBroadcastList(pageIndex, pageSize, sectionId, broadcastId, authorId, mineStatus int, userInfo user.UserInfo) (resp []response.Broadcast, err error) {
+	condition := ` 1=1`
+	var pars []interface{}
+	// 分享进来的指定语音播报
+	if broadcastId > 0 {
+		condition += ` AND broadcast_id = ?`
+		pars = append(pars, broadcastId)
 	} else {
-		broadList, e := voice_broadcast.GetBroadcastByIdAndPage(pageindex, pagesize, broadcastId)
-		if e != nil {
-			e = errors.New("获取语音播报列表失败 Err:" + e.Error())
+		// 板块
+		if sectionId > 0 {
+			condition += ` AND section_id = ?`
+			pars = append(pars, sectionId)
 		}
-		for _, item := range broadList {
-			var respItem response.Broadcast
-			respItem = response.Broadcast{
-				BroadcastId:      item.BroadcastId,
-				BroadcastName:    item.BroadcastName,
-				SectionId:        item.SectionId,
-				SectionName:      item.SectionName,
-				VarietyId:        item.VarietyId,
-				VarietyName:      item.VarietyName,
-				AuthorId:         item.AuthorId,
-				Author:           item.Author,
-				ImgUrl:           item.ImgUrl,
-				VoiceUrl:         item.VoiceUrl,
-				VoicePlaySeconds: item.VoicePlaySeconds,
-				VoiceSize:        item.VoiceSize,
-				CreateTime:       item.CreateTime,
-				IsAuthor:         false,
+		// 我的
+		if authorId > 0 {
+			condition += ` AND author_id = ?`
+			pars = append(pars, authorId)
+			// 我的语音播报状态: 0-未发布 1-已发布 2-全部
+			if mineStatus != 2 {
+				condition += ` AND publish_state = ?`
+				pars = append(pars, mineStatus)
 			}
-			if int(userInfo.UserID) == item.AuthorId {
-				respItem.IsAuthor = true
-			}
-			list = append(list, respItem)
-
 		}
-		err = e
+	}
+	voiceList, e := voice_broadcast.GetPageListByCondition(condition, pars, pageIndex, pageSize)
+	if e != nil {
+		err = errors.New("获取语音播报列表失败, Err: " + e.Error())
 		return
 	}
+	listLen := len(voiceList)
+	if listLen == 0 {
+		return
+	}
+	// 图片
+	voiceIds := make([]int, 0)
+	for i := 0; i < listLen; i++ {
+		voiceIds = append(voiceIds, voiceList[i].BroadcastId)
+	}
+	imgList, e := voice_broadcast_img.GetVoiceImgListByVoiceIds(voiceIds)
+	if e != nil {
+		err = errors.New("获取语音播报列表图片失败, Err: " + e.Error())
+		return
+	}
+	imgMap := make(map[int][]*voice_broadcast_img.YbVoiceBroadcastImg, 0)
+	imgListLen := len(imgList)
+	for i := 0; i < imgListLen; i++ {
+		imgMap[imgList[i].BroadcastId] = append(imgMap[imgList[i].BroadcastId], imgList[i])
+	}
+	// 响应数据
+	userId := int(userInfo.UserID)
+	for i := 0; i < listLen; i++ {
+		r := handleBroadcastItem(userId, voiceList[i], imgMap[voiceList[i].BroadcastId])
+		resp = append(resp, r)
+	}
+	return
 }
 
 // GetVoiceAdminByUserInfo 判断当前用户是否为语音管理员
@@ -262,78 +213,6 @@ func SendBroadcastMsg(broadcastId, userId int) (errMsg string, err error) {
 	return
 }
 
-// VoiceBroadcastShareImgPars 语音播报分享图参数
-type VoiceBroadcastShareImgPars struct {
-	BackgroundImg string `json:"background_img"`
-	Title         string `json:"title"`
-	CreateTime    string `json:"create_time"`
-}
-
-// UpdateVoiceBroadcastImgUrl 更新历史语音播报分享图
-func UpdateVoiceBroadcastImgUrl() (err error) {
-	defer func() {
-		if err != nil {
-			fmt.Println(err.Error())
-		}
-	}()
-	// 获取语音播报列表
-	list, e := voice_broadcast.GetBroadcastList()
-	if e != nil {
-		err = errors.New("获取语音播报列表失败")
-		return
-	}
-	// 获取语音播报板块分享图
-	sectionList, e := voice_section.GetVoiceSection()
-	if e != nil {
-		err = errors.New("获取语音播报列表失败")
-		return
-	}
-	sectionMap := make(map[int]string, 0)
-	sectionNameMap := make(map[int]string, 0)
-	for _, s := range sectionList {
-		sectionMap[s.SectionId] = s.ImgUrl
-		sectionNameMap[s.SectionId] = s.SectionName
-	}
-	// 生成语音分享图并更新
-	listLen := len(list)
-	fmt.Println("待更新数:", listLen)
-	updateCols := []string{"ImgUrl"}
-	for i := 0; i < listLen; i++ {
-		item := list[i]
-		fmt.Println("正在更新-Id:", item.BroadcastId)
-		imgUrl := sectionMap[item.SectionId]
-		if imgUrl == "" {
-			fmt.Println("背景图为空-Id:", item.BroadcastId)
-			continue
-		}
-		sectionName := sectionNameMap[item.SectionId]
-		timeDate := item.CreateTime[0:10]
-		pars := VoiceBroadcastShareImgPars{
-			BackgroundImg: imgUrl,
-			Title:         sectionName,
-			CreateTime:    timeDate,
-		}
-		parsByte, e := json.Marshal(pars)
-		if e != nil {
-			err = errors.New("分享图参数有误")
-			return
-		}
-		shareImg, e := GetDynamicShareImg(VoiceBroadcastShareImgSource, string(parsByte))
-		//fmt.Println(shareImg)
-		if e != nil {
-			err = errors.New("生成分享图失败")
-			return
-		}
-		item.ImgUrl = shareImg
-		if e = item.Update(updateCols); e != nil {
-			err = errors.New("更新语音播报失败")
-			return
-		}
-		fmt.Println("更新成功-Id:", item.BroadcastId)
-	}
-	return
-}
-
 // PublishVoiceBroadcast 发布语音播报
 func PublishVoiceBroadcast(broadcastId, sectionId, varietyId, authorId, publishType int, broadcastName, sectionName, varietyName, author,
 	imgUrl, prePublishTime, imgs string, voiceFile *multipart.FileHeader) (errMsg string, err error) {
@@ -453,6 +332,13 @@ func PublishVoiceBroadcast(broadcastId, sectionId, varietyId, authorId, publishT
 	return
 }
 
+// VoiceBroadcastShareImgPars 语音播报分享图参数
+type VoiceBroadcastShareImgPars struct {
+	BackgroundImg string `json:"background_img"`
+	Title         string `json:"title"`
+	CreateTime    string `json:"create_time"`
+}
+
 // createVoiceBroadcastShareImg 生成动态分享图
 func createVoiceBroadcastShareImg(baseImg, sectionName, createTime string) (shareImg string, err error) {
 	pars := VoiceBroadcastShareImgPars{
@@ -528,3 +414,56 @@ func handleVoiceBroadcastFile(voiceFile *multipart.FileHeader) (fileSeconds int,
 	}
 	return
 }
+
+// GetVoiceBroadcastDetail 获取语音播报详情
+func GetVoiceBroadcastDetail(broadcastId, userId int) (detail response.Broadcast, err error) {
+	item, e := voice_broadcast.GetBroadcastById(broadcastId)
+	if e != nil {
+		err = errors.New("获取语音播报详情失败, Err: " + e.Error())
+		return
+	}
+	// 语音播报图片
+	imgList, e := voice_broadcast_img.GetVoiceImgListByVoiceId(broadcastId)
+	if e != nil {
+		err = errors.New("获取语音播报图片失败, Err: " + e.Error())
+		return
+	}
+	detail = handleBroadcastItem(userId, item, imgList)
+	return
+}
+
+// handleBroadcastItem 语音播报响应数据处理
+func handleBroadcastItem(userId int, item *voice_broadcast.VoiceBroadcast, imgs []*voice_broadcast_img.YbVoiceBroadcastImg) (resp response.Broadcast) {
+	if item == nil {
+		return
+	}
+	resp.BroadcastId = item.BroadcastId
+	resp.BroadcastName = item.BroadcastName
+	resp.SectionId = item.SectionId
+	resp.SectionName = item.SectionName
+	resp.VarietyId = item.VarietyId
+	resp.VarietyName = item.VarietyName
+	resp.AuthorId = item.AuthorId
+	resp.Author = item.Author
+	resp.ImgUrl = item.ImgUrl
+	resp.VoiceUrl = item.VoiceUrl
+	resp.VoicePlaySeconds = item.VoicePlaySeconds
+	resp.VoiceSize = item.VoiceSize
+	resp.CreateTime = item.CreateTime
+	resp.PublishState = item.PublishState
+	resp.PrePublishTime = item.PrePublishTime
+	// 是否为作者、是否可推送消息
+	if userId == item.AuthorId {
+		resp.IsAuthor = true
+		if item.MsgState == 0 {
+			resp.CouldSendMsg = true
+		}
+	}
+	imgLen := len(imgs)
+	imgArr := make([]string, 0)
+	for i := 0; i < imgLen; i++ {
+		imgArr = append(imgArr, imgs[i].ImgUrl)
+	}
+	resp.Imgs = imgArr
+	return
+}

+ 4 - 3
utils/constants.go

@@ -136,7 +136,7 @@ const (
 	TEMPLATE_MSG_ACTIVITY_APPOINTMENT            //活动预约/报名时间通知
 	_
 	TEMPLATE_MSG_YB_COMMUNITY_QUESTION // 研报小程序-问答社区通知
-	TEMPLATE_MSG_YB_VOICE_BROADCAST // 研报小程序-语音播报
+	TEMPLATE_MSG_YB_VOICE_BROADCAST    // 研报小程序-语音播报
 )
 
 // 微信用户user_record注册平台
@@ -155,6 +155,7 @@ const (
 )
 
 const (
-	AdminId  = 11      //系统操作的用户id
-	RealName = "超级管理员" //系统操作的用户名称
+	AdminId     = 11      //系统操作的用户id
+	RealName    = "超级管理员" //系统操作的用户名称
+	HzCompanyId = 16      // 弘则研究公司ID
 )