package models import ( "github.com/beego/beego/v2/client/orm" "hongze/hongze_clpt/utils" "time" ) // ActivityVoice 活动语音表结构体 type CygxActivityVoice struct { ActivityVoiceId int `orm:"column(activity_voice_id);pk" description:"活动音频ID"` ActivityId int ` description:"活动ID"` VoiceUrl string `description:"音频地址"` VoiceName string `description:"音频名称"` VoicePlaySeconds string `description:"音频时长"` VoiceCounts int `description:"播放量"` ModifyTime string `description:"更新时间"` CreateTime time.Time `description:"创建时间"` } // ActivityVoice 活动语音表结构体 type CygxActivityVoiceResp struct { ActivityVoiceId int `orm:"column(activity_voice_id);pk" description:"活动音频ID"` ActivityId int ` description:"活动ID"` VoiceUrl string `description:"音频地址"` VoiceName string `description:"音频名称"` VoicePlaySeconds string `description:"音频时长"` VoiceCounts int `description:"播放量"` ModifyTime string `description:"更新时间"` CreateTime string `description:"创建时间"` ChartPermissionId int `description:"权限id"` ChartPermissionName string `description:"行业名称"` } // ActivityVoiceReq 音频数据 type CygxActivityVoiceReq struct { ActivityId int ` description:"活动ID"` Url string `description:"音频资源url地址"` Name string `description:"音频名称"` PlaySeconds int `description:"音频时长"` Type int `description:"类型: 1-音频; 2-活动视频; 3-产业视频 、 4-系列问答视频"` } // GetCygxActivityVoiceReqList 获取活动ID的音频 func GetCygxActivityVoiceReqList(activityIds []int) (items []*CygxActivityVoiceReq, err error) { lenactivityIds := len(activityIds) if lenactivityIds == 0 { return } //活动音频,设置有效时间为30天,失效后该活动就不再支持音频回放。有效期起始时间为活动的开始时间 //endTime := time.Now().AddDate(0, 0, -30).Format("2006-01-02 15:04:05") sql := `SELECT v.activity_id, v.voice_url AS url, v.voice_name AS name, v.voice_play_seconds AS play_seconds FROM cygx_activity_voice AS v INNER JOIN cygx_activity AS a ON a.activity_id = v.activity_id WHERE 1 = 1 AND v.is_hide = 0 AND v.activity_id IN (` + utils.GetOrmInReplace(lenactivityIds) + `) ` o := orm.NewOrm() _, err = o.Raw(sql, activityIds).QueryRows(&items) return } func UpdateCygxActivityVoiceCounts(activityId int) (err error) { sql := `UPDATE cygx_activity_voice SET voice_counts = voice_counts+1 WHERE activity_id = ? ` o := orm.NewOrm() _, err = o.Raw(sql, activityId).Exec() return } // GetCygxActivityVoiceById 主键获取活动音频 func GetCygxActivityVoiceById(videoId int) (item *CygxActivityVoice, err error) { sql := `SELECT * FROM cygx_activity_voice WHERE activity_voice_id = ? LIMIT 1` err = orm.NewOrm().Raw(sql, videoId).QueryRow(&item) return } // 列表 func GetActivityVoiceListAll(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxActivityVideoListResp, err error) { o := orm.NewOrm() sql := `SELECT art.* FROM cygx_activity as art INNER JOIN cygx_activity_voice AS v ON v.activity_id = art.activity_id WHERE 1= 1 ` if condition != "" { sql += condition } sql += ` LIMIT ?,?` _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items) return } // 列表 func GetActivityVoiceList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxActivityVoiceResp, err error) { o := orm.NewOrm() sql := `SELECT v.*,art.chart_permission_id,art.chart_permission_name FROM cygx_activity_voice AS v INNER JOIN cygx_activity as art ON art.activity_id = v.activity_id WHERE 1= 1 ` if condition != "" { sql += condition } sql += ` LIMIT ?,?` _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items) return } // GetCygxActivityVoiceByActivityId 主键获取活动音频 func GetCygxActivityVoiceByActivityId(activityId int) (item *CygxActivityVoice, err error) { sql := `SELECT * FROM cygx_activity_voice WHERE activity_id = ? LIMIT 1` err = orm.NewOrm().Raw(sql, activityId).QueryRow(&item) return } // 获取所有活动音频ID func GetActivityVoiceActivityIds() (activityIds string, err error) { sql := `SELECT GROUP_CONCAT( DISTINCT a.activity_id SEPARATOR ',' ) AS activityids FROM cygx_activity_voice AS a WHERE is_hide = 0 ` o := orm.NewOrm() err = o.Raw(sql).QueryRow(&activityIds) return } func UpdateActivityVoiceCommentNum(activityId int) (err error) { sql := `UPDATE cygx_activity_voice SET comment_num = comment_num+1 WHERE activity_id = ? ` o := orm.NewOrm() _, err = o.Raw(sql, activityId).Exec() return }