12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- 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"`
- ActivityVoiceId 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.activity_voice_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.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
- }
- // 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
- }
|