Bladeren bron

no message

xingzai 1 jaar geleden
bovenliggende
commit
b28817ec96
5 gewijzigde bestanden met toevoegingen van 197 en 47 verwijderingen
  1. 23 17
      controllers/cygx/activity.go
  2. 30 30
      models/cygx/activity.go
  3. 26 0
      models/cygx/activity_video.go
  4. 35 0
      models/cygx/activity_voice.go
  5. 83 0
      services/cygx/acitvity.go

+ 23 - 17
controllers/cygx/activity.go

@@ -650,7 +650,7 @@ func (this *ActivityCoAntroller) PreserveAndPublish() {
 					item.AdminName = activityInfo.AdminName
 					item.PublishDate = utils.StrTimeToTime(activityInfo.PublishDate)
 				}
-				//音频
+				//音频 目前只有一个
 				itemVoice := new(cygx.CygxActivityVoice)
 				//var itemVoiceList []*cygx.CygxActivityVoice
 				if len(voiceList) > 0 {
@@ -674,17 +674,23 @@ func (this *ActivityCoAntroller) PreserveAndPublish() {
 				}
 				//删除原有的视频数据
 				//if itemVideo.VideoUrl != "" {
-				videoDetail, err := cygx.GetCygxActivityVideoReqDetail(activityId)
+				//videoDetail, err := cygx.GetCygxActivityVideoReqDetail(activityId)
+				//if err != nil && err.Error() != utils.ErrNoRow() {
+				//	br.Msg = "获取信息失败"
+				//	br.ErrMsg = "GetCygxActivityVideoReqDetail,Err:" + err.Error() + "activityId:" + strconv.Itoa(activityId)
+				//	return
+				//}
+				//if videoDetail != nil {
+				//	go cygxService.UpdateResourceData(videoDetail.VideoId, "activityvideo", "delete", time.Now().Format(utils.FormatDateTime))
+				//}
+				//}
+				//处理音视频上传
+				err := cygxService.UpdateActivityVideoAndVoice(activityInfo, itemVoice, itemVideo)
 				if err != nil && err.Error() != utils.ErrNoRow() {
 					br.Msg = "获取信息失败"
-					br.ErrMsg = "GetCygxActivityVideoReqDetail,Err:" + err.Error() + "activityId:" + strconv.Itoa(activityId)
+					br.ErrMsg = "UpdateActivityVideoAndVoice,Err:" + err.Error() + "activityId:" + strconv.Itoa(activityId)
 					return
 				}
-				if videoDetail != nil {
-					go cygxService.UpdateResourceData(videoDetail.VideoId, "activityvideo", "delete", time.Now().Format(utils.FormatDateTime))
-				}
-				//}
-
 				//if itemVoice.VoiceUrl != "" {
 				voiceReqList, err := cygx.GetCygxActivityVoiceReqList(activityId)
 				if err != nil && err.Error() != utils.ErrNoRow() {
@@ -699,20 +705,20 @@ func (this *ActivityCoAntroller) PreserveAndPublish() {
 				}
 				//}
 				//如果活动信息有如下变更则做消息推送
-				voiceIdNew, videoIdNew, err := cygx.EditActivity(item, activityInfo.PublishStatus, industrialActivityItemsList, subjectActivityItemsList, itemVoice, itemVideo, itemPointsSet)
+				err = cygx.EditActivity(item, activityInfo.PublishStatus, industrialActivityItemsList, subjectActivityItemsList, itemPointsSet)
 				if err != nil {
 					br.Msg = "操作失败"
 					br.ErrMsg = "操作失败,Err:" + err.Error()
 					return
 				}
-				//更新活动音频
-				if int(voiceIdNew) > 0 {
-					go cygxService.UpdateResourceData(int(voiceIdNew), "activityvoice", "add", activityInfo.ActivityTime)
-				}
-				//更新活动视频
-				if int(videoIdNew) > 0 {
-					go cygxService.UpdateResourceData(int(videoIdNew), "activityvideo", "add", activityInfo.ActivityTime)
-				}
+				////更新活动音频
+				//if int(voiceIdNew) > 0 {
+				//	go cygxService.UpdateResourceData(int(voiceIdNew), "activityvoice", "add", activityInfo.ActivityTime)
+				//}
+				////更新活动视频
+				//if int(videoIdNew) > 0 {
+				//	go cygxService.UpdateResourceData(int(videoIdNew), "activityvideo", "add", activityInfo.ActivityTime)
+				//}
 
 				errAct = err
 				if activityInfo.PublishStatus == 1 && activityInfo.ActivityTimeText != item.ActivityTimeText {

+ 30 - 30
models/cygx/activity.go

@@ -331,7 +331,7 @@ func GetAddActivityInfoById(ActivityId int) (item *ActivityDetail, err error) {
 }
 
 // 修改
-func EditActivity(item *CygxActivity, oldPublishStatus int, industrialActivityItems [][]*CygxIndustrialActivityGroupManagement, subjectActivityItems [][]*CygxIndustrialActivityGroupSubject, itemVoice *CygxActivityVoice, itemVideo *CygxActivityVideo, itemPointsSet *CygxActivityPointsSet) (voiceId, videoId int64, err error) {
+func EditActivity(item *CygxActivity, oldPublishStatus int, industrialActivityItems [][]*CygxIndustrialActivityGroupManagement, subjectActivityItems [][]*CygxIndustrialActivityGroupSubject, itemPointsSet *CygxActivityPointsSet) (err error) {
 	o := orm.NewOrm()
 	to, err := o.Begin()
 	if err != nil {
@@ -460,37 +460,37 @@ func EditActivity(item *CygxActivity, oldPublishStatus int, industrialActivityIt
 
 	//音频处理
 	//删除旧的音频
-	sql = "DELETE FROM cygx_activity_voice WHERE activity_id=?"
-	_, err = to.Raw(sql, activityId).Exec()
-	//插入新的音频
-	//if len(itemVoiceList) > 0 {
-	//	voiceId, err := to.InsertMulti(len(itemVoiceList), itemVoiceList)
-	//	if err != nil {
-	//		return
+	//sql = "DELETE FROM cygx_activity_voice WHERE activity_id=?"
+	//_, err = to.Raw(sql, activityId).Exec()
+	////插入新的音频
+	////if len(itemVoiceList) > 0 {
+	////	voiceId, err := to.InsertMulti(len(itemVoiceList), itemVoiceList)
+	////	if err != nil {
+	////		return
+	////	}
+	////}
+	//if itemVoice != nil {
+	//	if itemVoice.VoiceUrl != "" {
+	//		voiceId, err = to.Insert(itemVoice)
+	//		if err != nil {
+	//			return
+	//		}
+	//	}
+	//}
+	//
+	////视频处理
+	////删除旧的视频
+	//sql = "DELETE FROM cygx_activity_video WHERE activity_id=?"
+	//_, err = to.Raw(sql, activityId).Exec()
+	////插入新的音频
+	//if itemVideo != nil {
+	//	if itemVideo.VideoUrl != "" {
+	//		videoId, err = to.Insert(itemVideo)
+	//		if err != nil {
+	//			return
+	//		}
 	//	}
 	//}
-	if itemVoice != nil {
-		if itemVoice.VoiceUrl != "" {
-			voiceId, err = to.Insert(itemVoice)
-			if err != nil {
-				return
-			}
-		}
-	}
-
-	//视频处理
-	//删除旧的视频
-	sql = "DELETE FROM cygx_activity_video WHERE activity_id=?"
-	_, err = to.Raw(sql, activityId).Exec()
-	//插入新的音频
-	if itemVideo != nil {
-		if itemVideo.VideoUrl != "" {
-			videoId, err = to.Insert(itemVideo)
-			if err != nil {
-				return
-			}
-		}
-	}
 
 	{
 		//处理研选扣点子表

+ 26 - 0
models/cygx/activity_video.go

@@ -3,6 +3,7 @@ package cygx
 import (
 	"github.com/beego/beego/v2/client/orm"
 	"github.com/rdlucklib/rdluck_tools/paging"
+	"time"
 )
 
 type CygxActivityVideo struct {
@@ -46,6 +47,31 @@ type CygxActivityVideoListRep struct {
 	List   []*CygxActivityVideoListResp
 }
 
+// 添加
+func AddCygxActivityVideo(item *CygxActivityVideo) (newId int64, err error) {
+	o := orm.NewOrm()
+	newId, err = o.Insert(item)
+	return
+}
+
+// 修改
+func UpdateCygxActivityVideo(item *CygxActivityVideo) (err error) {
+	to := orm.NewOrm()
+	updateParams := make(map[string]interface{})
+	updateParams["VideoName"] = item.VideoName
+	updateParams["VideoDuration"] = item.VideoDuration
+	updateParams["VideoUrl"] = item.VideoUrl
+	updateParams["ModifyDate"] = time.Now()
+	ptrStructOrTableName := "cygx_activity_video"
+	whereParam := map[string]interface{}{"activity_id": item.ActivityId}
+	qs := to.QueryTable(ptrStructOrTableName)
+	for expr, exprV := range whereParam {
+		qs = qs.Filter(expr, exprV)
+	}
+	_, err = qs.Update(updateParams)
+	return
+}
+
 // 获取数量
 func GetActivityVideoCount(condition string, pars []interface{}) (count int, err error) {
 	sqlCount := ` SELECT

+ 35 - 0
models/cygx/activity_voice.go

@@ -23,6 +23,41 @@ type CygxActivityVoiceReq struct {
 	ActivityVoiceId int    `description:"活动音频ID"`
 }
 
+// 添加
+func AddCygxActivityVoice(item *CygxActivityVoice) (newId int64, err error) {
+	o := orm.NewOrm()
+	newId, err = o.Insert(item)
+	return
+}
+
+// 修改
+func UpdateCygxActivityVoice(item *CygxActivityVoice) (err error) {
+	to := orm.NewOrm()
+	updateParams := make(map[string]interface{})
+	updateParams["VoiceName"] = item.VoiceName
+	updateParams["VideoDuration"] = item.VoicePlaySeconds
+	updateParams["VoiceUrl"] = item.VoiceUrl
+	ptrStructOrTableName := "cygx_activity_voice"
+	whereParam := map[string]interface{}{"activity_id": item.ActivityId}
+	qs := to.QueryTable(ptrStructOrTableName)
+	for expr, exprV := range whereParam {
+		qs = qs.Filter(expr, exprV)
+	}
+	_, err = qs.Update(updateParams)
+	return
+}
+
+// 获取数量
+func GetCygxActivityVoiceCount(condition string, pars []interface{}) (count int, err error) {
+	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_activity_voice  WHERE 1= 1  `
+	if condition != "" {
+		sqlCount += condition
+	}
+	o := orm.NewOrm()
+	err = o.Raw(sqlCount, pars).QueryRow(&count)
+	return
+}
+
 // 列表
 func GetCygxActivityVoiceReqList(activityId int) (items []*CygxActivityVoiceReq, err error) {
 	o := orm.NewOrm()

+ 83 - 0
services/cygx/acitvity.go

@@ -1474,3 +1474,86 @@ func CheckActivityUpdatePower(adminId int, activityInfo *cygx.ActivityDetail) (h
 	havePower = true
 	return
 }
+
+func UpdateActivityVideoAndVoice(activityInfo *cygx.ActivityDetail, itemVoice *cygx.CygxActivityVoice, itemVideo *cygx.CygxActivityVideo) (err error) {
+	if activityInfo.ActiveState != 3 {
+		return // 没有结束的活动不会上传音视频
+	}
+	activityId := activityInfo.ActivityId
+	var condition string
+	var pars []interface{}
+	//处理音频
+	if itemVoice != nil {
+		condition = " AND activity_id = ? "
+		pars = append(pars, activityId)
+		total, e := cygx.GetCygxActivityVoiceCount(condition, pars)
+		if e != nil {
+			err = errors.New("GetCygxActivityVoiceCount" + e.Error())
+			return
+		}
+		//如果大于0就新增,反之就修改
+		if total > 0 {
+			newId, e := cygx.AddCygxActivityVoice(itemVoice)
+			if e != nil {
+				err = errors.New("GetCygxActivityVoiceCount" + e.Error())
+				return
+			}
+			go UpdateResourceData(int(newId), utils.CYGX_OBJ_ACTIVITYVOICE, "add", activityInfo.ActivityTime) // 把活动音频的数据添加到 cygx_resource_data 表
+		} else {
+			e = cygx.UpdateCygxActivityVoice(itemVoice)
+			if e != nil {
+				err = errors.New("UpdateCygxActivityVoice" + e.Error())
+				return
+			}
+		}
+	}
+
+	//处理视频
+	if itemVideo != nil {
+		condition = " AND art.activity_id = ? "
+		pars = append(pars, activityId)
+		total, e := cygx.GetActivityVideoCount(condition, pars)
+		if e != nil {
+			err = errors.New("GetActivityVideoCount" + e.Error())
+			return
+		}
+		//如果大于0就新增,反之就修改
+		if total > 0 {
+			newId, e := cygx.AddCygxActivityVideo(itemVideo)
+			if e != nil {
+				err = errors.New("AddCygxActivityVideo" + e.Error())
+				return
+			}
+			go UpdateResourceData(int(newId), utils.CYGX_OBJ_ACTIVITYVIDEO, "add", activityInfo.ActivityTime) // 把活动音频的数据添加到 cygx_resource_data 表
+		} else {
+			e = cygx.UpdateCygxActivityVideo(itemVideo)
+			if e != nil {
+				err = errors.New("UpdateCygxActivityVideo" + e.Error())
+				return
+			}
+		}
+	}
+
+	//如果两个都为空,就判断之前是否上传过
+	if itemVoice == nil && itemVideo == nil {
+		voiceDetail, e := cygx.GetCygxActivityVoiceReqDetail(activityId)
+		if e != nil && e.Error() != utils.ErrNoRow() {
+			err = errors.New("GetCygxActivityVoiceReqDetail" + e.Error())
+			return
+		}
+		if voiceDetail != nil {
+			go UpdateResourceData(voiceDetail.ActivityVoiceId, utils.CYGX_OBJ_ACTIVITYVOICE, "delete", time.Now().Format(utils.FormatDateTime)) // 把活动音频在 cygx_resource_data 表中删除
+		}
+
+		//删除原有的视频数据
+		videoDetail, e := cygx.GetCygxActivityVideoReqDetail(activityId)
+		if e != nil && e.Error() != utils.ErrNoRow() {
+			err = errors.New("GetCygxActivityVideoReqDetail" + e.Error())
+			return
+		}
+		if videoDetail != nil {
+			go UpdateResourceData(videoDetail.VideoId, utils.CYGX_OBJ_ACTIVITYVIDEO, "delete", time.Now().Format(utils.FormatDateTime)) // 把活动视频在 cygx_resource_data 表中删除
+		}
+	}
+	return
+}