123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- package models
- import (
- "github.com/beego/beego/v2/client/orm"
- "hongze/hongze_cygx/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:"创建时间"`
- }
- // ActivityVoiceReq 音频数据
- type CygxActivityVoiceReq struct {
- ActivityId int ` description:"活动ID"`
- Url string `description:"音频资源url地址"`
- Name string `description:"音频名称"`
- PlaySeconds int `description:"音频时长"`
- }
- // 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 a.activity_time > ? AND v.activity_id IN (` + utils.GetOrmInReplace(lenactivityIds) + `) `
- o := orm.NewOrm()
- _, err = o.Raw(sql, endTime, 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
- }
|