|
@@ -22,12 +22,11 @@ func (service *ActivityServiceNew) GetAllActivity(in *activity.Request) (int64,
|
|
|
activityArr := []entity.Activity{}
|
|
|
var err error
|
|
|
var activityList = []entity.Activity{}
|
|
|
- nowStr := time.Now().Format("2006-01-02 15:04:05")
|
|
|
//有券的活动获取
|
|
|
err = orm.Table("activity").Alias("a").Select(" DISTINCT a.*").
|
|
|
Join("left", "discount d", "d.activityId = a.id").
|
|
|
Join("left", "product p", "FIND_IN_SET(p.productCode,d.useProductList)").
|
|
|
- Where(" a.state=1 and if ( (a.preheatingTime IS NULL or a.preheatingTime='' ) , a.beginDate<? ,a.preheatingTime<?) and a.endDate>=? and p.productCode=?", nowStr, nowStr, nowStr, in.ProductCode).Find(&activityList)
|
|
|
+ Where(" a.state=1 and if ( (a.preheatingTime IS NULL or a.preheatingTime='' ) , a.beginDate<now() ,a.preheatingTime<now()) and a.endDate>=now() and p.productCode=?", in.ProductCode).Find(&activityList)
|
|
|
if len(activityList) == 0 {
|
|
|
return entity.ErrorCode, "当前时段没有活动可以参加", []entity.Activity{}
|
|
|
}
|
|
@@ -136,7 +135,7 @@ func (service *ActivityServiceNew) UserAllLottery(in *activity.AllLotteryReq) ma
|
|
|
}
|
|
|
//判断自己是否可以参加此活动
|
|
|
for _, code := range strings.Split(C.C.NotAvailableCode, ",") {
|
|
|
- if code == productCode {
|
|
|
+ if code == productCode && in.EntUserId != 0 {
|
|
|
//判断此人是否是授权的超级订阅或者大会员
|
|
|
entOrm := entity.EntEngine
|
|
|
powerList := []map[string]interface{}{}
|
|
@@ -171,50 +170,56 @@ func getAllActivity(productCode, userId, appId, userName, userPhone string, rece
|
|
|
activityArr := []entity.Activity{}
|
|
|
var err error
|
|
|
var activityList = []entity.Activity{}
|
|
|
- nowStr := time.Now().Format("2006-01-02 15:04:05")
|
|
|
//有券的活动获取
|
|
|
err = orm.Table("activity").Alias("a").Select(" DISTINCT a.*,GROUP_CONCAT(d.lotteryId) as lotteryIdArr").
|
|
|
Join("left", "discount d", "d.activityId = a.id").
|
|
|
Join("left", "product p", "FIND_IN_SET(p.productCode,d.useProductList)").
|
|
|
- Where(" a.state=1 and if ( (a.preheatingTime IS NULL or a.preheatingTime='' ) , a.beginDate<? ,a.preheatingTime<?) and a.endDate>=? and p.productCode=? ", nowStr, nowStr, nowStr, productCode).GroupBy("a.id").Find(&activityList)
|
|
|
+ Where(" a.state=1 and if ( (a.preheatingTime IS NULL or a.preheatingTime='' ) , a.beginDate<now() ,a.preheatingTime<now()) and a.endDate>=now() and p.productCode=? ", productCode).
|
|
|
+ GroupBy("a.id").
|
|
|
+ Find(&activityList)
|
|
|
if len(activityList) == 0 {
|
|
|
return activityArr
|
|
|
}
|
|
|
+ //活动过期奖券有效查询
|
|
|
+ invalidActivityArr := []entity.Activity{}
|
|
|
+ err = orm.SQL("SELECT a.*, GROUP_CONCAT(u.lotteryId) as lotteryIdArr FROM "+
|
|
|
+ " user_prize u LEFT JOIN activity a on u.activityId=a.id and a.endDate<now() and a.state=1 "+
|
|
|
+ "LEFT JOIN discount d on d.activityId=a.id and d.lotteryId=u.lotteryId and d.state=1 "+
|
|
|
+ "where u.userId= '"+userId+"' and u.prizeId!=0 and FIND_IN_SET(?,d.useProductList) and u.prizeType=0 and u.endDate>now() GROUP BY a.id", productCode).Find(&invalidActivityArr)
|
|
|
+ logx.Info(err)
|
|
|
+ for _, v := range invalidActivityArr {
|
|
|
+ activityList = append(activityList, v)
|
|
|
+ }
|
|
|
for _, activityEntity := range activityList {
|
|
|
activityId := activityEntity.Id
|
|
|
activityType := activityEntity.ActivityType
|
|
|
receivingLocation := activityEntity.ReceivingLocation
|
|
|
logx.Info(receivingLocation)
|
|
|
- //判断是否返回数据
|
|
|
- if receivingLocation != 999 && userId != entity.FilterId {
|
|
|
- if receivingLocation != receivingLocation {
|
|
|
- continue
|
|
|
- }
|
|
|
- }
|
|
|
- if _, ok := userGroupMap[activityEntity.UserGroupId]; !ok {
|
|
|
- // 不存在
|
|
|
- if !UserGroupingHandle(activityEntity.UserRange, userId, activityEntity.UserGroupId, activityEntity.BeginDate, activityEntity.EndDate, activityEntity.PreheatingTime) {
|
|
|
- userGroupMap[activityEntity.UserGroupId] = false
|
|
|
- continue
|
|
|
- } else {
|
|
|
- userGroupMap[activityEntity.UserGroupId] = true
|
|
|
+ //未过期的需要验证数据
|
|
|
+ if !util.ActivityTime(activityEntity.EndDate) {
|
|
|
+ //活动正在进行中
|
|
|
+ //判断是否返回数据
|
|
|
+ if receivingLocation != 999 && userId != entity.FilterId {
|
|
|
+ if receivingLocation != receivingLocation {
|
|
|
+ continue
|
|
|
+ }
|
|
|
}
|
|
|
- } else {
|
|
|
- if !userGroupMap[activityEntity.UserGroupId] {
|
|
|
- continue
|
|
|
+ if activityEntity.UserRange == 3 {
|
|
|
+ activityEntity.UserGroupId = "new"
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- //查看活动是否可以参与
|
|
|
- if util.ActivityTime(activityEntity.PreheatingTime) {
|
|
|
- //查询是否可以领取
|
|
|
- if activityEntity.LimitType != 0 {
|
|
|
- if !activityPartakeHandle(activityEntity.Id, userId, activityEntity.LimitQuantity, activityEntity.LimitType, 2) {
|
|
|
+ if _, ok := userGroupMap[activityEntity.UserGroupId]; !ok {
|
|
|
+ // 不存在
|
|
|
+ if !UserGroupingHandle(activityEntity.UserRange, userId, activityEntity.UserGroupId, activityEntity.BeginDate, activityEntity.EndDate, activityEntity.PreheatingTime) {
|
|
|
+ userGroupMap[activityEntity.UserGroupId] = false
|
|
|
+ continue
|
|
|
+ } else {
|
|
|
+ userGroupMap[activityEntity.UserGroupId] = true
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if !userGroupMap[activityEntity.UserGroupId] {
|
|
|
continue
|
|
|
}
|
|
|
}
|
|
|
- } else {
|
|
|
- continue
|
|
|
}
|
|
|
// 判断活动是否为全部用户参加
|
|
|
// 1- 全部 2-分组用户
|
|
@@ -224,22 +229,28 @@ func getAllActivity(productCode, userId, appId, userName, userPhone string, rece
|
|
|
if len(activityEntity.LotteryIdArr) == 0 {
|
|
|
continue
|
|
|
}
|
|
|
- //领劵处理
|
|
|
- if len(strings.Split(activityEntity.LotteryIdArr, ",")) == 0 {
|
|
|
- continue
|
|
|
- }
|
|
|
- for _, v := range strings.Split(activityEntity.LotteryIdArr, ",") {
|
|
|
- if ok, userLottery := isDraw(userId, appId, common.Int64All(v), orm); ok {
|
|
|
- drawHandle(userId, appId, userName, userPhone, common.Int64All(v), userLottery)
|
|
|
+ auserLotteryList := []entity.LotteryJson{}
|
|
|
+ if !util.ActivityTime(activityEntity.BeginDate) {
|
|
|
+ //领劵处理
|
|
|
+ if len(strings.Split(activityEntity.LotteryIdArr, ",")) == 0 {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ for _, v := range strings.Split(activityEntity.LotteryIdArr, ",") {
|
|
|
+ if ok, userLottery := isDraw(userId, appId, common.Int64All(v), orm); ok {
|
|
|
+ drawHandle(userId, appId, userName, userPhone, common.Int64All(v), userLottery)
|
|
|
+ }
|
|
|
}
|
|
|
+ auserLotteryList = availableLottery(orm, activityId, activityEntity.LotteryIdArr, userId, appId)
|
|
|
+ lotteryWaitHandle(orm, activityEntity.LotteryIdArr, userId, appId, activityId, &auserLotteryList)
|
|
|
+ } else {
|
|
|
+ auserLotteryList = availableLottery(orm, activityId, activityEntity.LotteryIdArr, userId, appId)
|
|
|
}
|
|
|
- //查询处理
|
|
|
- activityEntity.LotteryData = availableLottery(orm, activityId, activityEntity.LotteryIdArr, userId, appId)
|
|
|
+ activityEntity.LotteryData = auserLotteryList
|
|
|
} else {
|
|
|
//限时、赠品活动处理
|
|
|
//先查找产品参与的活动
|
|
|
var giftData = []entity.LotteryJson{}
|
|
|
- err = orm.Table("activity").Alias("a").Select("DISTINCT d.stockNumber,d.promotionalPrice,d.discount,d.reduce,g.giftCode,g.parentCode,g.name,g.time,g.timeType,d.id as lotteryId,a.activityType ").
|
|
|
+ err = orm.Table("activity").Alias("a").Select("DISTINCT d.stockNumber,d.promotionalPrice,d.discount,d.reduce,g.giftCode,g.parentCode,g.name,g.time,g.timeType,d.id as lotteryId,a.activityType,a.beginDate,a.endDate").
|
|
|
Join("left", " discount d", "d.activityId = a.id ").
|
|
|
Join("left", "gift g ", "g.giftCode=d.giftCode").
|
|
|
Where("FIND_IN_SET(?,d.useProductList) and a.id=? and d.state=1", productCode, activityEntity.Id).
|
|
@@ -250,8 +261,13 @@ func getAllActivity(productCode, userId, appId, userName, userPhone string, rece
|
|
|
}
|
|
|
activityEntity.LotteryData = giftData
|
|
|
}
|
|
|
- activityArr = append(activityArr, activityEntity)
|
|
|
+ if len(activityEntity.LotteryData) > 0 {
|
|
|
+ activityArr = append(activityArr, activityEntity)
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
+ //查询一下有券活动已结束的数据
|
|
|
+
|
|
|
return activityArr
|
|
|
}
|
|
|
|
|
@@ -391,33 +407,29 @@ func drawHandle(userId, appId, userName, userPhone string, lotteryId int64, user
|
|
|
func availableLottery(orm *xorm.Engine, activityId int64, lotteryIdArr, userId, appId string) []entity.LotteryJson {
|
|
|
//查询奖券信息
|
|
|
var userLotteryList []entity.LotteryJson
|
|
|
- nowStr := time.Now().Format("2006-01-02 15:04:05")
|
|
|
var err error
|
|
|
err = orm.Table("user_prize").Alias("up").Select(" DISTINCT a.id as activityId, a.name as activityName,a.activityDesc,a.activityType,a.beginDate as activityBeginDate,a.endDate as activityEndDate , up.activityId,up.id as userLotteryId,up.*,p.instructions,p.remark,p.prizeType as activityType").
|
|
|
Join("left", "prize p", "up.prizeId=p.id").
|
|
|
- Join("left", "discount d", "up.lotteryId=d.lotteryId and d.state=1").
|
|
|
+ Join("left", "discount d", "up.lotteryId=d.lotteryId and d.state=1 and d.prizeId!=0").
|
|
|
Join("left", "activity a ", "d.activityId=a.id").
|
|
|
- Where("up.userId=? and up.appId=? and up.activityId=? and up.endDate>=? and FIND_IN_SET(up.lotteryId,?) and p.prizeType<2 and up.prizeType=0", userId, appId, activityId, nowStr, lotteryIdArr).
|
|
|
+ Where("up.userId=? and up.appId=? and up.activityId=? and up.endDate>=now() and FIND_IN_SET(up.lotteryId,?) and p.prizeType<2 and up.prizeType=0", userId, appId, activityId, lotteryIdArr).
|
|
|
Desc("up.createTime").
|
|
|
Find(&userLotteryList)
|
|
|
if err != nil {
|
|
|
logx.Info("查询奖券问题:", err)
|
|
|
}
|
|
|
- //满折满减预热活动奖券查询
|
|
|
- lotteryWaitHandle(lotteryIdArr, userId, appId, activityId, &userLotteryList)
|
|
|
return userLotteryList
|
|
|
}
|
|
|
|
|
|
//满折满减预热活动奖券查询
|
|
|
-func lotteryWaitHandle(lotteryIdArr, userId, appId string, activityId int64, userPrice *[]entity.LotteryJson) {
|
|
|
- orm := entity.Engine.NewSession()
|
|
|
+func lotteryWaitHandle(orm *xorm.Engine, lotteryIdArr, userId, appId string, activityId int64, userPrice *[]entity.LotteryJson) []entity.LotteryJson {
|
|
|
//var err error
|
|
|
//没有商品标识时处理
|
|
|
oneuserPrice := []entity.LotteryJson{}
|
|
|
err := orm.Table("activity").Alias("a").Select("DISTINCT a.id as activityId, a.name as activityName,a.beginDate as activityBeginDate,a.endDate as activityEndDate ,d.stockNumber, a.activityType,a.beginDate ,a.endDate,l.full ,d.promotionalPrice,l.discount,l.reduce,a.preheatingTime,a.activityDesc,d.id as lotteryId").
|
|
|
- Join("left", " discount d", "d.activityId = a.id ").
|
|
|
+ Join("left", " discount d", "d.activityId = a.id and d.state=1 and d.prizeId!=0").
|
|
|
Join("left", "lottery l ", "l.id=d.lotteryId").
|
|
|
- Where(" a.id=? and FIND_IN_SET(d.lotteryId,?) AND a.activityType < 2 AND a.appId = ? and a.state=1 and d.state=1 ", activityId, lotteryIdArr, appId).
|
|
|
+ Where(" a.id=? and FIND_IN_SET(d.lotteryId,?) AND a.activityType < 2 AND a.appId = ? and a.state=1 and a.preheatingTime is not null and a.preheatingTime!='' and a.preheatingTime<now() and a.beginDate>now() ", activityId, lotteryIdArr, appId).
|
|
|
Find(&oneuserPrice)
|
|
|
//先查找产品参与的活动
|
|
|
if err != nil {
|
|
@@ -426,4 +438,5 @@ func lotteryWaitHandle(lotteryIdArr, userId, appId string, activityId int64, use
|
|
|
for _, prizeJson := range oneuserPrice {
|
|
|
*userPrice = append(*userPrice, prizeJson)
|
|
|
}
|
|
|
+ return nil
|
|
|
}
|