فهرست منبع

feat:活动信息

wangshan 1 سال پیش
والد
کامیت
a0caa5e64f

+ 3 - 3
src/jfw/modules/publicapply/src/activityday/consts/consts.go

@@ -25,9 +25,9 @@ var (
 	RafflePool                        = make(chan bool, 1)
 	PrizeKey                          = "activity_day_%s_%d_%d_%d" //奖品名称  活动id  奖品id 日期
 	RepeatKey                         = "activity_day_action_%d"
-	LotteryUserMsg_Winner             = "您今天已中奖,明天%d:00再来吧"
+	LotteryUserMsg_Winner             = "您今天已中奖,明天%s再来吧"
 	LotteryUserMsg_WinnerNoMore       = "您今天已中奖,快去查看奖品吧"
-	LotteryUserMsg_NoPreze            = "今天已抢光,明天%d:00再来吧"
+	LotteryUserMsg_NoPreze            = "今天已抢光,明天%s再来吧"
 	LotteryUserMsg_NoMore             = "今天已抢光,活动已结束"
 	TableActivityInfo                 = "jyactivities.activity_info"        // 活动信息表
 	TablePrizeInfo                    = "jyactivities.lottery_prize_info"   // 奖品信息表
@@ -35,7 +35,7 @@ var (
 	TableEquityInfo                   = "jyactivities.equity_info"          // 第三方权权益码表
 	TableOrder                        = "jianyu.dataexport_order"           // 订单表
 	NotStarted                        = "当前活动未开始"
-	Ended                             = "已结束"
+	Ended                             = "当前活动已结束"
 	LotteryNotStarted                 = "当前活动抽奖还未开始"
 	LotteryEnded                      = "当前活动抽奖已结束"
 	WinnerPrizeMsg_VIP                = "您已升级为超级订阅用户"

+ 6 - 7
src/jfw/modules/publicapply/src/activityday/dao/activeInfo.go

@@ -1,7 +1,6 @@
 package dao
 
 import (
-	"app.yhyue.com/moapp/jybase/date"
 	"fmt"
 	"jy/src/jfw/modules/publicapply/src/activityday/consts"
 	"jy/src/jfw/modules/publicapply/src/activityday/entity"
@@ -12,18 +11,18 @@ type Lai entity.LotteryActiveInfo
 
 func (l *Lai) Check() error {
 	now := time.Now()
-	ast, _ := time.ParseInLocation(date.Date_Full_Layout, l.ActiveStartTime, time.Local) //活动开始时间
-	aet, _ := time.ParseInLocation(date.Date_Full_Layout, l.ActiveEndTime, time.Local)   //活动结束时间
-	if ast.Unix() > now.Unix() {
+	//ast, _ := time.ParseInLocation(date.Date_Full_Layout, l.ActiveStartTime, time.Local) //活动开始时间
+	//aet, _ := time.ParseInLocation(date.Date_Full_Layout, l.ActiveEndTime, time.Local)   //活动结束时间
+	if l.ActiveStartTime > now.Unix() {
 		return fmt.Errorf(consts.NotStarted)
 	}
-	if aet.Unix() < now.Unix() {
+	if l.ActiveEndTime < now.Unix() {
 		return fmt.Errorf(consts.Ended)
 	}
-	if l.LotteryStartTime > now.Hour() {
+	if l.LotteryStartTime > now.Unix() {
 		return fmt.Errorf(consts.LotteryNotStarted)
 	}
-	if l.LotteryEndTime < now.Hour() {
+	if l.LotteryEndTime < now.Unix() {
 		return fmt.Errorf(consts.LotteryEnded)
 	}
 	return nil

+ 58 - 37
src/jfw/modules/publicapply/src/activityday/dao/dao.go

@@ -33,14 +33,20 @@ func GetLotteryActiveInfo(activeId int64, sess map[string]interface{}, session *
 	var (
 		err     error
 		prizeRs []map[string]interface{}
+		now     = time.Now()
 	)
+	activeInfo = LotteryActiveInfoRes{
+		Lai:     &Lai{},
+		Prize:   prizeRs,
+		NowUnix: now.Unix(),
+	}
 	r.DLai, _ = r.ActiveInfo()
 	if r.DLai == nil {
 		return
 	}
-	ast, _ := time.ParseInLocation(date.Date_Full_Layout, r.DLai.ActiveStartTime, time.Local) //活动开始时间
-	aet, _ := time.ParseInLocation(date.Date_Full_Layout, r.DLai.ActiveEndTime, time.Local)   //活动结束时间  这里处理是因为前端要求是时间戳
-	now := time.Now()
+	activeInfo.ActiveStartTime = r.DLai.ActiveStartTime   //活动开始时间
+	activeInfo.ActiveEndTime = r.DLai.ActiveEndTime       //活动结束时间
+	activeInfo.LotteryStartUnix = r.DLai.LotteryStartTime //抽奖开始时间
 	platform := GetPlatform(req)
 	if platform != "pc" {
 		platform = "app"
@@ -64,41 +70,52 @@ func GetLotteryActiveInfo(activeId int64, sess map[string]interface{}, session *
 			})
 		}
 	}
+	activeInfo.Lai = &Lai{
+		Name:             r.DLai.Name,
+		LotteryStartTime: r.DLai.LotteryStartTime,
+		LotteryEndTime:   r.DLai.LotteryEndTime,
+		Cost:             r.DLai.Cost,
+		Rule:             r.DLai.Rule,
+		ShareCopy:        r.DLai.ShareCopy,
+		Pic:              pic,
+	}
 	//activeInfo.Prize = prizeRs
-	lotteryStart := time.Date(now.Year(), now.Month(), now.Day(), r.DLai.LotteryStartTime, 0, 0, 0, time.Local)
+	//lotteryStart := time.Date(now.Year(), now.Month(), now.Day(), r.DLai.LotteryStartTime, 0, 0, 0, time.Local)
 	//time.Duration(r.DLai.LotteryStartTime) * time.Hour) // 将当前时间截断到0点并加上小时(去除了最后一纳秒)
-	LotteryStartUnix := lotteryStart.Unix()
-	activeInfo = LotteryActiveInfoRes{
-		Lai: &Lai{
-			Name:             r.DLai.Name,
-			LotteryStartTime: r.DLai.LotteryStartTime,
-			LotteryEndTime:   r.DLai.LotteryEndTime,
-			Cost:             r.DLai.Cost,
-			Rule:             r.DLai.Rule,
-			ShareCopy:        r.DLai.ShareCopy,
-			Pic:              pic,
-		},
-		Prize:            prizeRs,
-		ActiveStartTime:  ast.Unix(),
-		ActiveEndTime:    aet.Unix(),
-		NowUnix:          now.Unix(),
-		LotteryStartUnix: LotteryStartUnix,
-	}
-	if ast.Unix() > now.Unix() || activeInfo.LotteryStartTime > now.Hour() {
-		if ast.Unix() > now.Unix() {
-			activeInfo.LotteryStartUnix = time.Date(ast.Year(), ast.Month(), ast.Day(), r.DLai.LotteryStartTime, 0, 0, 0, time.Local).Unix()
-		}
-		activeInfo.Status = 1
-		activeInfo.Msg = consts.NotStarted
-		return
-	}
-	if ast.Unix() < now.Unix() && aet.Unix() > now.Unix() && activeInfo.LotteryEndTime < now.Hour() {
+	//LotteryStartUnix := lotteryStart.Unix()
+	//activeInfo = LotteryActiveInfoRes{
+	//	Lai: &Lai{
+	//		Name:             r.DLai.Name,
+	//		LotteryStartTime: r.DLai.LotteryStartTime,
+	//		LotteryEndTime:   r.DLai.LotteryEndTime,
+	//		Cost:             r.DLai.Cost,
+	//		Rule:             r.DLai.Rule,
+	//		ShareCopy:        r.DLai.ShareCopy,
+	//		Pic:              pic,
+	//	},
+	//	Prize:            prizeRs,
+	//	ActiveStartTime:  ast.Unix(),
+	//	ActiveEndTime:    aet.Unix(),
+	//	NowUnix:          now.Unix(),
+	//	LotteryStartUnix: r.DLai.LotteryStartTime,
+	//}
+	//活动已结束
+	if activeInfo.ActiveEndTime < now.Unix() {
 		activeInfo.Status = 2
-		activeInfo.Msg = "不在当天抽奖时间内"
-		return
+		activeInfo.Msg = consts.Ended
 	}
-	// 未登录用户 显示抽奖
-	if common.Int64All(sess["positionId"]) == 0 || r.DLai.Mold == 0 { //购买赠送奖品 只需要购买须知信息
+	//活动未开始 或 抽奖未开始
+	if activeInfo.ActiveStartTime > now.Unix() || activeInfo.LotteryStartTime > now.Unix() {
+		activeInfo.Status = 1
+		//活动未开始
+		if activeInfo.ActiveStartTime > now.Unix() {
+			activeInfo.Msg = consts.NotStarted
+			lst := time.Unix(activeInfo.LotteryStartTime, 0).Local()                                                                                  //每天抽奖开始时间
+			ast := time.Unix(activeInfo.ActiveStartTime, 0).Local()                                                                                   //活动开始时间
+			activeInfo.LotteryStartUnix = time.Date(ast.Year(), ast.Month(), ast.Day(), lst.Hour(), lst.Minute(), lst.Second(), 0, time.Local).Unix() //活动当天 抽奖开始时间
+		} else if activeInfo.LotteryStartTime > now.Unix() { //抽奖未开始
+			activeInfo.Msg = consts.LotteryNotStarted
+		}
 		return
 	}
 	activeInfo.Status = 2
@@ -107,17 +124,21 @@ func GetLotteryActiveInfo(activeId int64, sess map[string]interface{}, session *
 		activeInfo.Msg = err.Error()
 		return
 	}
+	// 未登录用户 显示抽奖
+	if common.Int64All(sess["positionId"]) == 0 || r.DLai.Mold == 0 { //购买赠送奖品 只需要购买须知信息
+		return
+	}
 	//用户获奖信息
 	if r.DLua, err = r.UserAccountInfo(); err != nil {
 		log.Println("当前用户暂无中奖记录:", r.UserInfo.Phone)
 	}
 	//是否是活动结束日
-	lastDay := now.Format(date.Date_Short_Layout) == strings.Split(r.DLai.ActiveEndTime, " ")[0]
+	lastDay := now.Format(date.Date_Short_Layout) == time.Unix(r.DLai.ActiveEndTime, 0).Local().Format(date.Date_Short_Layout)
 	if r.DLua != nil {
 		//今天抽奖机会是否已用完
 		if num := r.DLua.CheckTodayLotteryNum(); num >= r.DLai.DailyNum {
 			//今日抽奖机会已用完
-			err = fmt.Errorf(fmt.Sprintf(consts.LotteryUserMsg_Winner, r.DLai.LotteryStartTime)) //明天可抽奖
+			err = fmt.Errorf(fmt.Sprintf(consts.LotteryUserMsg_Winner, date.FormatDateByInt64(&r.DLai.LotteryStartTime, date.Date_Time_Layout))) //明天可抽奖
 			//是否是活动结束当天
 			if lastDay {
 				err = fmt.Errorf(consts.LotteryUserMsg_WinnerNoMore)
@@ -129,7 +150,7 @@ func GetLotteryActiveInfo(activeId int64, sess map[string]interface{}, session *
 	//今日库存 及 有效奖品整理
 	if todayPrizeNum := r.EffectivePrizeInventory(); todayPrizeNum == 0 {
 		//暂无库存
-		err = fmt.Errorf(fmt.Sprintf(consts.LotteryUserMsg_NoPreze, r.DLai.LotteryStartTime))
+		err = fmt.Errorf(fmt.Sprintf(consts.LotteryUserMsg_NoPreze, date.FormatDateByInt64(&r.DLai.LotteryStartTime, date.Date_Time_Layout)))
 		//是否是活动结束当天
 		if lastDay {
 			err = fmt.Errorf(consts.LotteryUserMsg_NoMore)

+ 19 - 13
src/jfw/modules/publicapply/src/activityday/dao/raffle.go

@@ -118,12 +118,12 @@ func (r *RaffleInfo) Raffle() (error, entity.WinnerPrizeInfo) {
 			log.Println("当前用户暂无中奖记录:", r.UserInfo.Phone)
 		}
 		//是否是活动结束日
-		lastDay := now.Format(date.Date_Short_Layout) == strings.Split(r.DLai.ActiveEndTime, " ")[0]
+		lastDay := now.Format(date.Date_Short_Layout) == time.Unix(r.DLai.ActiveEndTime, 0).Local().Format(date.Date_Short_Layout)
 		if r.DLua != nil {
 			//今天抽奖机会是否已用完
 			if num := r.DLua.CheckTodayLotteryNum(); num >= r.DLai.DailyNum {
 				//今日抽奖机会已用完
-				err = fmt.Errorf(fmt.Sprintf(consts.LotteryUserMsg_Winner, r.DLai.LotteryStartTime)) //明天可抽奖
+				err = fmt.Errorf(fmt.Sprintf(consts.LotteryUserMsg_Winner, date.FormatDateByInt64(&r.DLai.LotteryStartTime, date.Date_Time_Layout))) //明天可抽奖
 				//是否是活动结束当天
 				if lastDay {
 					err = fmt.Errorf(consts.LotteryUserMsg_WinnerNoMore)
@@ -138,7 +138,7 @@ func (r *RaffleInfo) Raffle() (error, entity.WinnerPrizeInfo) {
 		//今日库存 及 有效奖品整理
 		if todayPrizeNum := r.EffectivePrizeInventory(); todayPrizeNum == 0 {
 			//暂无库存
-			err = fmt.Errorf(fmt.Sprintf(consts.LotteryUserMsg_NoPreze, r.DLai.LotteryStartTime))
+			err = fmt.Errorf(fmt.Sprintf(consts.LotteryUserMsg_NoPreze, date.FormatDateByInt64(&r.DLai.LotteryStartTime, date.Date_Time_Layout)))
 			//是否是活动结束当天
 			if lastDay {
 				err = fmt.Errorf(consts.LotteryUserMsg_NoMore)
@@ -152,7 +152,7 @@ func (r *RaffleInfo) Raffle() (error, entity.WinnerPrizeInfo) {
 		if r.Prize == nil || r.Prize.Name == "" {
 			log.Println("都到这了,居然没有奖品-.-!,肯定有问题。", r.UserInfo.Phone)
 			//今日抽奖机会已用完
-			err = fmt.Errorf(fmt.Sprintf(consts.LotteryUserMsg_Winner, r.DLai.LotteryStartTime)) //明天可抽奖
+			err = fmt.Errorf(fmt.Sprintf(consts.LotteryUserMsg_Winner, date.FormatDateByInt64(&r.DLai.LotteryStartTime, date.Date_Time_Layout))) //明天可抽奖
 			if lastDay {
 				err = fmt.Errorf(consts.LotteryUserMsg_WinnerNoMore)
 			}
@@ -166,10 +166,12 @@ func (r *RaffleInfo) Raffle() (error, entity.WinnerPrizeInfo) {
 		url, subtitle := r.GetPrizeInfo()
 		r.Prize.Url = url
 		//TODO 消息通知
-		err = r.SendMsgInfo(err)
-		if err != nil {
-			log.Println("消息通知 异常-err:", err.Error())
-		}
+		go func(r *RaffleInfo, err error) {
+			sendErr := r.SendMsgInfo(err)
+			if sendErr != nil {
+				log.Println("消息通知 异常-err:", sendErr.Error())
+			}
+		}(r, err)
 		//TODO 返回奖品信息封装渲染
 		wpi = entity.WinnerPrizeInfo{
 			Pic:            r.Prize.DrawPic,
@@ -192,16 +194,20 @@ func (r *RaffleInfo) Raffle() (error, entity.WinnerPrizeInfo) {
 
 // 活动信息
 func (r *RaffleInfo) ActiveInfo() (ai *Lai, err error) {
-	sql := fmt.Sprintf("SELECT * FROM %s lai WHERE lai.id = ? AND lai.state = 0 ", consts.TableActivityInfo)
+	sql := fmt.Sprintf("SELECT * FROM %s lai WHERE lai.id = ? AND lai.state = 0", consts.TableActivityInfo)
 	data := db.BaseMysql.SelectBySql(sql, r.ActiveId)
 	if data != nil && len(*data) > 0 {
+		lst, _ := time.ParseInLocation(common.ObjToString((*data)[0]["lottery_start_time"]), date.Date_Time_Layout, time.Local)
+		let, _ := time.ParseInLocation(common.ObjToString((*data)[0]["lottery_end_time"]), date.Date_Time_Layout, time.Local)
+		st, _ := time.ParseInLocation(common.ObjToString((*data)[0]["start_time"]), date.Date_Full_Layout, time.Local)
+		et, _ := time.ParseInLocation(common.ObjToString((*data)[0]["end_time"]), date.Date_Full_Layout, time.Local)
 		ai = &Lai{
 			Id:               common.Int64All((*data)[0]["id"]),
 			Name:             common.ObjToString((*data)[0]["name"]),
-			ActiveStartTime:  common.ObjToString((*data)[0]["start_time"]),
-			ActiveEndTime:    common.ObjToString((*data)[0]["end_time"]),
-			LotteryStartTime: common.IntAll((*data)[0]["lottery_start_time"]),
-			LotteryEndTime:   common.IntAll((*data)[0]["lottery_end_time"]),
+			ActiveStartTime:  st.Unix(),
+			ActiveEndTime:    et.Unix(),
+			LotteryStartTime: lst.Unix(),
+			LotteryEndTime:   let.Unix(),
 			Cost:             common.Int64All((*data)[0]["cost"]),
 			DailyNum:         common.IntAll((*data)[0]["daily_num"]),
 			Pic:              common.ObjToString((*data)[0]["pic"]),

+ 4 - 4
src/jfw/modules/publicapply/src/activityday/entity/entity.go

@@ -4,10 +4,10 @@ package entity
 type LotteryActiveInfo struct {
 	Id               int64                `json:"id"`                 //活动id
 	Name             string               `json:"name"`               //活动名称
-	ActiveStartTime  string               `json:"start_time"`         //活动开始时间
-	ActiveEndTime    string               `json:"end_time"`           //活动结束时间
-	LotteryStartTime int                  `json:"lottery_start_time"` //抽奖开始时间
-	LotteryEndTime   int                  `json:"lottery_end_time"`   //抽奖结束时间
+	ActiveStartTime  int64                `json:"start_time"`         //活动开始时间
+	ActiveEndTime    int64                `json:"end_time"`           //活动结束时间
+	LotteryStartTime int64                `json:"lottery_start_time"` //抽奖开始时间
+	LotteryEndTime   int64                `json:"lottery_end_time"`   //抽奖结束时间
 	Cost             int64                `json:"cost"`               //抽奖花费:默X个剑鱼币兑换1次抽奖机会
 	DailyNum         int                  `json:"daily_num"`          //每人每个身份每天抽奖次数限制
 	Pic              string               `json:"pic"`                //活动图片