浏览代码

Merge branch 'mfyx_3.6' of http://8.136.199.33:3000/hongze/hongze_cygx into debug

xingzai 7 月之前
父节点
当前提交
cbc6f3bc28
共有 2 个文件被更改,包括 109 次插入0 次删除
  1. 32 0
      models/activity_vivo_points_set.go
  2. 77 0
      services/activity_points.go

+ 32 - 0
models/activity_vivo_points_set.go

@@ -0,0 +1,32 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxActivityVivoPointsSet struct {
+	PointSetId   int       `orm:"column(point_set_id);pk";comment:"主键id"`
+	ActivityId   int       `comment:"活动ID"`
+	PointsObject string    `comment:"扣点设置方式 1:同报名参会时的扣点数、2:输入其余点数"`
+	PointsNum    float64   `comment:"扣点数量"`
+	GoodsMoney   float64   `comment:"商品总价"`
+	Source       string    `comment:"来源 activityvideo 活动视频、activityvoice 活动音频"`
+	CreateTime   time.Time `comment:"创建时间"`
+	ModifyTime   time.Time `comment:"更新时间"`
+}
+
+// 根据活动ID判断音视频是否设置了扣点
+func GetCygxActivityVivoPointsSetCountByActivityId(activityId int) (count int, err error) {
+	o := orm.NewOrm()
+	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_activity_vivo_points_set  WHERE activity_id =?  `
+	err = o.Raw(sqlCount, activityId).QueryRow(&count)
+	return
+}
+
+func GetCygxActivityVivoPointsSetByActivityId(activityId int) (item *CygxActivityVivoPointsSet, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_activity_vivo_points_set WHERE activity_id = ?  `
+	err = o.Raw(sql, activityId).QueryRow(&item)
+	return
+}

+ 77 - 0
services/activity_points.go

@@ -174,6 +174,10 @@ func YanXuanActivityPointsBillReduce() (err error) {
 				go YanXuanCompanyCompanyTryOutReduce(log)
 				fmt.Println("7:正式专试用定时任务更新研选扣点。")
 				break
+			case 8:
+				go YanXuanActivityVivoPointsBillSignupReduce(log)
+				fmt.Println("8:播放研选扣点音视频。")
+				break
 			default:
 				fmt.Println(string(b))
 				go utils.SendAlarmMsg("处理研选活动扣点处理Redis队列消息失败:"+string(b), 2)
@@ -1092,3 +1096,76 @@ func YanXuanCompanyCompanyTryOutReduce(log models.YanXuanActivityPointsRedis) (e
 
 	return
 }
+
+// 8:用户观看音视频研选扣点处理
+func YanXuanActivityVivoPointsBillSignupReduce(log models.YanXuanActivityPointsRedis) (err error) {
+	//func YanXuanActivityPointsBillSubmitMeetingReduce(activityId int) (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendAlarmMsg("用户观看音视频研选扣点处理,处理Redis队列消息失败:"+err.Error()+fmt.Sprint("ActivityId", log.ActivityId, "UserId", log.UserId), 2)
+		}
+	}()
+
+	activityId := log.ActivityId
+	userId := log.UserId
+	//获取活动是否扣点以及扣点规则明细
+	vivoPointsSetDetail, e := models.GetCygxActivityVivoPointsSetByActivityId(activityId)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("GetCygxActivityVivoPointsSetByActivityId" + e.Error())
+		return
+	}
+	if vivoPointsSetDetail == nil {
+		return
+	}
+
+	activityInfo, e := models.GetAddActivityInfoByActivityId(activityId)
+	if e != nil {
+		err = errors.New("GetAddActivityInfoByActivityId" + e.Error())
+		return
+	}
+
+	user, e := models.GetWxUserItemByUserId(userId)
+	if e != nil {
+		err = errors.New("GetWxUserItemByUserId" + e.Error())
+		return
+	}
+
+	// 获取用户所在公司剩余的点
+	companyPointsNum, e := models.GetCompanyPoints(user.CompanyId)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("GetCompanyPoints, Err: " + e.Error())
+		return
+	}
+
+	//获取需要添加的流水信息
+	var items []*models.CygxActivityPointsBill
+	item := new(models.CygxActivityPointsBill)
+	item.UserId = user.UserId
+	item.ActivityId = activityId
+	item.CreateTime = time.Now()
+	item.Mobile = user.Mobile
+	item.Email = user.Email
+	item.CompanyId = user.CompanyId
+	item.CompanyName = user.CompanyName
+	item.RealName = user.RealName
+	item.BillDetailed = -vivoPointsSetDetail.PointsNum
+	item.RegisterPlatform = log.RegisterPlatform
+	item.AdminId = log.AdminId
+	item.Source = log.Source
+	item.ChartPermissionId = activityInfo.ChartPermissionId
+	item.DoType = 1
+	item.Content = "查看活动回放"
+	item.Points = companyPointsNum - vivoPointsSetDetail.PointsNum
+	items = append(items, item)
+
+	//更新对应机构的剩余点数
+	var itemCompanys []*models.CygxActivityPointsCompany
+	itemCompany := new(models.CygxActivityPointsCompany)
+	itemCompany.CompanyId = user.CompanyId
+	itemCompany.Points = item.Points
+	itemCompany.ModifyTime = time.Now()
+	itemCompanys = append(itemCompanys, itemCompany)
+	err = models.AddCygxActivityPointsBillMulti(items, itemCompanys)
+	return
+}