|
@@ -92,7 +92,7 @@ func init() {
|
|
|
var Activity activity.Activity
|
|
|
|
|
|
// 活动初始化
|
|
|
-func ActivityInit() interface{} {
|
|
|
+func ActivityInit() {
|
|
|
log.Println("开始初始化活动rpc")
|
|
|
g.Cfg().GetAdapter().(*gcfg.AdapterFile).SetFileName("config.yaml")
|
|
|
var ctx = gctx.New()
|
|
@@ -102,7 +102,9 @@ func ActivityInit() interface{} {
|
|
|
Key: g.Cfg().MustGet(ctx, "activityKey").String(),
|
|
|
},
|
|
|
}))
|
|
|
- redis.Del("other", "lotteryArray")
|
|
|
+}
|
|
|
+
|
|
|
+func ActivityData() map[string][]*activity.LotteryJson {
|
|
|
resp, err := Activity.GetAllLottery(context.Background(), &activity.Request{
|
|
|
AppId: "10000",
|
|
|
ProductCode: "111",
|
|
@@ -110,7 +112,7 @@ func ActivityInit() interface{} {
|
|
|
log.Println(resp, err)
|
|
|
if err != nil {
|
|
|
log.Println("奖券获取失败")
|
|
|
- return false
|
|
|
+ return nil
|
|
|
}
|
|
|
lotteryMap := map[string][]*activity.LotteryJson{}
|
|
|
for _, activityValue := range resp.ActivityJson {
|
|
@@ -121,9 +123,7 @@ func ActivityInit() interface{} {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- redis.PutKV("lotteryArray", lotteryMap)
|
|
|
- log.Println("活动rpc初始化完毕")
|
|
|
- return true
|
|
|
+ return lotteryMap
|
|
|
}
|
|
|
|
|
|
// Course 剑鱼课堂首页课程 & 帮助中心热门视频 classify:0:中标比听课视频 1:帮助中心视频(获取所有)
|
|
@@ -148,6 +148,7 @@ func Course(num, iType int) *[]map[string]interface{} {
|
|
|
num = -1
|
|
|
}
|
|
|
//最新课程
|
|
|
+ lotteryMap := ActivityData()
|
|
|
var LatestCourses *[]map[string]interface{}
|
|
|
latestQuery := map[string]interface{}{"i_type": iType, "i_status": 1, "l_endtime": map[string]interface{}{"$gt": time.Now().Unix()}, "l_publishtime": map[string]interface{}{"$lt": time.Now().Unix()}}
|
|
|
LatestCourses, _ = mongodb.Find("jy_course", latestQuery, `{"l_publishtime":-1}`, "", false, page, num)
|
|
@@ -161,7 +162,7 @@ func Course(num, iType int) *[]map[string]interface{} {
|
|
|
(*LatestCourses)[key]["isExpired"] = false
|
|
|
}
|
|
|
productPrice := util.Float64All(value["i_price"])
|
|
|
- fool, discountPrice := OptimalSelection(util.InterfaceToStr(value["_id"]), productPrice)
|
|
|
+ fool, discountPrice := OptimalSelection(util.InterfaceToStr(value["_id"]), productPrice, lotteryMap)
|
|
|
(*LatestCourses)[key]["isDiscount"] = fool
|
|
|
if fool {
|
|
|
(*LatestCourses)[key]["discountPrice"] = productPrice - discountPrice
|
|
@@ -189,32 +190,26 @@ func Course(num, iType int) *[]map[string]interface{} {
|
|
|
}
|
|
|
}*/
|
|
|
//IdFormat(LatestCourses)
|
|
|
-
|
|
|
return LatestCourses
|
|
|
}
|
|
|
|
|
|
// 奖券详情
|
|
|
-func OptimalSelection(id string, price float64) (bool, float64) {
|
|
|
+func OptimalSelection(id string, price float64, lotteryMap map[string][]*activity.LotteryJson) (bool, float64) {
|
|
|
discountPrice := float64(0)
|
|
|
- productStr := redis.Get("other", "lotteryArray")
|
|
|
- lotteryMap := &map[string]interface{}{}
|
|
|
- if productStr != nil {
|
|
|
- lotteryMap = util.ObjToMap(productStr)
|
|
|
- }
|
|
|
- lotteryStr := (*lotteryMap)[id]
|
|
|
+
|
|
|
+ lotteryStr := lotteryMap[id]
|
|
|
if lotteryStr == nil {
|
|
|
return false, discountPrice
|
|
|
}
|
|
|
- lotteryList := util.ObjArrToMapArr(lotteryStr.([]interface{}))
|
|
|
- for _, lottery := range lotteryList {
|
|
|
- lotteryType := util.Int64All(lottery["lotteryType"])
|
|
|
- full := util.Float64All(lottery["full"])
|
|
|
+ for _, lottery := range lotteryStr {
|
|
|
+ lotteryType := lottery.LotteryType
|
|
|
+ full := util.Float64All(lottery.Full)
|
|
|
full *= 100
|
|
|
//类型:0满减、1折扣券、2满赠、3促销、4限时折扣、5限时减免
|
|
|
switch lotteryType {
|
|
|
case 1: //满折
|
|
|
if full <= price {
|
|
|
- discount := util.Float64All(lottery["discount"])
|
|
|
+ discount := util.Float64All(lottery.Discount)
|
|
|
preferential := (1 - discount/10) * price
|
|
|
preferential = math.Trunc(preferential*1e0 + 0.5)
|
|
|
if preferential > discountPrice {
|
|
@@ -223,13 +218,13 @@ func OptimalSelection(id string, price float64) (bool, float64) {
|
|
|
}
|
|
|
break
|
|
|
case 3: //3促销
|
|
|
- promotionalPrice := util.Float64All(lottery["promotionalPrice"])
|
|
|
+ promotionalPrice := util.Float64All(lottery.PromotionalPrice)
|
|
|
if util.Float64All(price-promotionalPrice) > discountPrice {
|
|
|
discountPrice = util.Float64All(price - promotionalPrice)
|
|
|
}
|
|
|
break
|
|
|
case 4: //4限时折扣
|
|
|
- discount := util.Float64All(lottery["discount"])
|
|
|
+ discount := util.Float64All(lottery.Discount)
|
|
|
preferential := (1 - discount/10) * price
|
|
|
preferential = math.Trunc(preferential*1e0 + 0.5)
|
|
|
if preferential > discountPrice {
|
|
@@ -237,14 +232,14 @@ func OptimalSelection(id string, price float64) (bool, float64) {
|
|
|
}
|
|
|
break
|
|
|
case 5: //5限时减免
|
|
|
- reduce := util.Float64All(lottery["reduce"])
|
|
|
+ reduce := util.Float64All(lottery.Reduce)
|
|
|
if reduce > discountPrice {
|
|
|
discountPrice = reduce
|
|
|
}
|
|
|
break
|
|
|
default:
|
|
|
if full <= price {
|
|
|
- reduce := util.Float64All(lottery["reduce"]) * 100
|
|
|
+ reduce := util.Float64All(lottery.Reduce) * 100
|
|
|
if reduce > discountPrice {
|
|
|
discountPrice = reduce
|
|
|
}
|