wangshan 1 жил өмнө
parent
commit
99ab8a55ae

+ 159 - 159
src/jfw/modules/publicapply/src/activityday/dao/dao.go

@@ -1,151 +1,151 @@
 package dao
 
 import (
-    "app.yhyue.com/moapp/jybase/common"
-    "app.yhyue.com/moapp/jybase/date"
-    "app.yhyue.com/moapp/jybase/go-xweb/httpsession"
-    "fmt"
-    "jy/src/jfw/modules/publicapply/src/activityday/consts"
-    "jy/src/jfw/modules/publicapply/src/activityday/util"
-    "jy/src/jfw/modules/publicapply/src/db"
-    "log"
-    "net/http"
-    "regexp"
-    "strings"
-    "time"
+	"app.yhyue.com/moapp/jybase/common"
+	"app.yhyue.com/moapp/jybase/date"
+	"app.yhyue.com/moapp/jybase/go-xweb/httpsession"
+	"fmt"
+	"jy/src/jfw/modules/publicapply/src/activityday/consts"
+	"jy/src/jfw/modules/publicapply/src/activityday/util"
+	"jy/src/jfw/modules/publicapply/src/db"
+	"log"
+	"net/http"
+	"regexp"
+	"strings"
+	"time"
 )
 
 // LotteryActiveInfoRes 活动信息接口返回值
 type LotteryActiveInfoRes struct {
-    *Lai                                      // 活动信息
-    Prize            []map[string]interface{} `json:"prize"` // 奖品图片列表
-    ActiveStartTime  int64                    `json:"active_start_time"` // 活动开始结束时间戳 前端使用时间戳
-    ActiveEndTime    int64                    `json:"active_end_time"`
-    Msg              string                   `json:"prompt_msg"`         // 文案
-    Status           int                      `json:"status"`             // 状态 0- 抽奖状态 1- 未开始 2-根据msg展示文案
-    NowUnix          int64                    `json:"now_unix"`           // 时间戳
-    LotteryStartUnix int64                    `json:"lottery_start_unix"` // 当天抽奖开始时间时间戳
+	*Lai                                      // 活动信息
+	Prize            []map[string]interface{} `json:"prize"`             // 奖品图片列表
+	ActiveStartTime  int64                    `json:"active_start_time"` // 活动开始结束时间戳 前端使用时间戳
+	ActiveEndTime    int64                    `json:"active_end_time"`
+	Msg              string                   `json:"prompt_msg"`         // 文案
+	Status           int                      `json:"status"`             // 状态 0- 抽奖状态 1- 未开始 2-根据msg展示文案
+	NowUnix          int64                    `json:"now_unix"`           // 时间戳
+	LotteryStartUnix int64                    `json:"lottery_start_unix"` // 当天抽奖开始时间时间戳
 }
 
 // GetLotteryActiveInfo 获取活动信息
 func GetLotteryActiveInfo(activeId int64, sess map[string]interface{}, session *httpsession.Session, req *http.Request) (activeInfo LotteryActiveInfoRes) {
-    r := NewRaffleInfo(sess, activeId, util.UserLabel(session), req)
-    var (
-        err     error
-        prizeRs []map[string]interface{}
-        now     = time.Now()
-    )
-    activeInfo = LotteryActiveInfoRes{
-        Lai:     &Lai{},
-        NowUnix: now.Unix(),
-    }
-    r.DLai, _ = r.ActiveInfo()
-    if r.DLai == nil {
-        return
-    }
-    activeInfo.ActiveStartTime = r.DLai.ActiveStartTime   //活动开始时间
-    activeInfo.ActiveEndTime = r.DLai.ActiveEndTime       //活动结束时间
-    activeInfo.LotteryStartUnix = r.DLai.LotteryStartTime //抽奖开始时间
-    platform := GetPlatform(req)
-    if platform != "pc" {
-        platform = "app"
-    }
-    pic := ""
-    urlMap := common.ObjToMap(r.DLai.Pic)
-    if urlMap != nil {
-        pic = common.ObjToString((*urlMap)[platform])
-    } else {
-        pic = ""
-    }
-    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,
-    }
-    //奖品信息
-    if r.DLpi, err = r.PrizeInfo(); err != nil {
-        activeInfo.Msg = "暂无奖品信息"
-        return
-    } else {
-        for _, pi := range *r.DLpi {
-            prizeRs = append(prizeRs, map[string]interface{}{
-                "name": pi.Name,
-                "pic":  pi.DrawPic,
-            })
-        }
-    }
-    activeInfo.Prize = prizeRs
-    //活动已结束
-    if activeInfo.ActiveEndTime < now.Unix() {
-        activeInfo.Status = 2
-        activeInfo.Msg = consts.Ended
-    }
-    //活动未开始 或 抽奖未开始
-    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
-    //当前活动状态
-    if err := r.DLai.Check(); err != nil {
-        activeInfo.Msg = err.Error()
-        return
-    }
-    // 未登录用户 显示抽奖
-    if common.Int64All(sess["positionId"]) == 0 || r.DLai.Mold == 0 { //购买赠送奖品 只需要购买须知信息
-        activeInfo.Status = 0
-        return
-    }
-    //用户获奖信息
-    if r.DLua, err = r.UserAccountInfo(); err != nil {
-        log.Println("当前用户暂无中奖记录:", r.UserInfo.Phone)
-    }
-    //是否是活动结束日
-    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, date.FormatDateByInt64(&r.DLai.LotteryStartTime, date.Date_Time_Layout))) //明天可抽奖
-            //是否是活动结束当天
-            if lastDay {
-                err = fmt.Errorf(consts.LotteryUserMsg_WinnerNoMore)
-            }
-            activeInfo.Msg = err.Error()
-            return
-        }
-    }
-    //今日库存 及 有效奖品整理
-    if todayPrizeNum := r.EffectivePrizeInventory(); todayPrizeNum <= 0 {
-        //暂无库存
-        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)
-        }
-        activeInfo.Msg = err.Error()
-        return
-    }
-    activeInfo.Status = 0
-    return
+	r := NewRaffleInfo(sess, activeId, util.UserLabel(session), req)
+	var (
+		err     error
+		prizeRs []map[string]interface{}
+		now     = time.Now()
+	)
+	activeInfo = LotteryActiveInfoRes{
+		Lai:     &Lai{},
+		NowUnix: now.Unix(),
+	}
+	r.DLai, _ = r.ActiveInfo()
+	if r.DLai == nil {
+		return
+	}
+	activeInfo.ActiveStartTime = r.DLai.ActiveStartTime   //活动开始时间
+	activeInfo.ActiveEndTime = r.DLai.ActiveEndTime       //活动结束时间
+	activeInfo.LotteryStartUnix = r.DLai.LotteryStartTime //抽奖开始时间
+	platform := GetPlatform(req)
+	if platform != "pc" {
+		platform = "app"
+	}
+	pic := ""
+	urlMap := common.ObjToMap(r.DLai.Pic)
+	if urlMap != nil {
+		pic = common.ObjToString((*urlMap)[platform])
+	} else {
+		pic = ""
+	}
+	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,
+	}
+	//奖品信息
+	if r.DLpi, err = r.PrizeInfo(); err != nil {
+		activeInfo.Msg = "暂无奖品信息"
+		return
+	} else {
+		for _, pi := range *r.DLpi {
+			prizeRs = append(prizeRs, map[string]interface{}{
+				"name": pi.Name,
+				"pic":  pi.DrawPic,
+			})
+		}
+	}
+	activeInfo.Prize = prizeRs
+	//活动已结束
+	if activeInfo.ActiveEndTime < now.Unix() {
+		activeInfo.Status = 2
+		activeInfo.Msg = consts.Ended
+	}
+	//活动未开始 或 抽奖未开始
+	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
+	//当前活动状态
+	if err := r.DLai.Check(); err != nil {
+		activeInfo.Msg = err.Error()
+		return
+	}
+	// 未登录用户 显示抽奖
+	if common.Int64All(sess["positionId"]) == 0 || r.DLai.Mold == 0 { //购买赠送奖品 只需要购买须知信息
+		activeInfo.Status = 0
+		return
+	}
+	//用户获奖信息
+	if r.DLua, err = r.UserAccountInfo(); err != nil {
+		log.Println("当前用户暂无中奖记录:", r.UserInfo.Phone)
+	}
+	//是否是活动结束日
+	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, date.FormatDateByInt64(&r.DLai.LotteryStartTime, date.Date_Time_Layout))) //明天可抽奖
+			//是否是活动结束当天
+			if lastDay {
+				err = fmt.Errorf(consts.LotteryUserMsg_WinnerNoMore)
+			}
+			activeInfo.Msg = err.Error()
+			return
+		}
+	}
+	//今日库存 及 有效奖品整理
+	if todayPrizeNum := r.EffectivePrizeInventory(); todayPrizeNum <= 0 {
+		//暂无库存
+		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)
+		}
+		activeInfo.Msg = err.Error()
+		return
+	}
+	activeInfo.Status = 0
+	return
 }
 
 // GetLotteryUserAccount 我的奖品列表
 func GetLotteryUserAccount(positionId, activeId int64, platform string) *[]map[string]interface{} {
-    q := ` SELECT
+	q := ` SELECT
     b.name,
     b.win_pic as pic,
     a.create_time,
@@ -165,33 +165,33 @@ WHERE
     a.position_id = ?
     AND a.active_id = ?;`
 
-    query := fmt.Sprintf(q, consts.TableUserAccount, consts.TablePrizeInfo, consts.TableEquityInfo)
-    rs := db.Mysql.SelectBySql(query, positionId, activeId)
-    if rs == nil || len(*rs) == 0 {
-        return &[]map[string]interface{}{}
-    }
-    for i := 0; i < len(*rs); i++ {
-        urlMap := common.ObjToMap((*rs)[i]["url"])
-        if urlMap != nil {
-            (*rs)[i]["url"] = (*urlMap)[platform]
-        } else {
-            (*rs)[i]["url"] = ""
-        }
-    }
-    return rs
+	query := fmt.Sprintf(q, consts.TableUserAccount, consts.TablePrizeInfo, consts.TableEquityInfo)
+	rs := db.Mysql.SelectBySql(query, positionId, activeId)
+	if rs == nil || len(*rs) == 0 {
+		return &[]map[string]interface{}{}
+	}
+	for i := 0; i < len(*rs); i++ {
+		urlMap := common.ObjToMap((*rs)[i]["url"])
+		if urlMap != nil {
+			(*rs)[i]["url"] = (*urlMap)[platform]
+		} else {
+			(*rs)[i]["url"] = ""
+		}
+	}
+	return rs
 }
 func GetPlatform(r *http.Request) (platform string) {
-    var mobileReg = regexp.MustCompile("(?i)(Android|Mobile|Phone)")
-    if mobileReg.MatchString(r.UserAgent()) {
-        if strings.Index(strings.ToLower(r.UserAgent()), "micromessenger") > -1 {
-            return "wx"
-        }
-        if strings.Contains(r.Host, "h5") {
-            return "h5"
-        }
-        return "app"
-    } else {
-        return "pc"
-    }
+	var mobileReg = regexp.MustCompile("(?i)(Android|Mobile|Phone)")
+	if mobileReg.MatchString(r.UserAgent()) {
+		if strings.Index(strings.ToLower(r.UserAgent()), "micromessenger") > -1 {
+			return "wx"
+		}
+		if strings.Contains(r.Host, "h5") {
+			return "h5"
+		}
+		return "app"
+	} else {
+		return "pc"
+	}
 
 }