|
@@ -1,13 +1,20 @@
|
|
|
package jyutil
|
|
|
|
|
|
import (
|
|
|
+ "app.yhyue.com/moapp/jyMarketing/rpc/activity"
|
|
|
util "app.yhyue.com/moapp/jybase/common"
|
|
|
. "app.yhyue.com/moapp/jybase/date"
|
|
|
mgo "app.yhyue.com/moapp/jybase/mongodb"
|
|
|
"app.yhyue.com/moapp/jybase/redis"
|
|
|
"bytes"
|
|
|
+ "context"
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
+ "github.com/gogf/gf/v2/frame/g"
|
|
|
+ "github.com/gogf/gf/v2/os/gcfg"
|
|
|
+ "github.com/gogf/gf/v2/os/gctx"
|
|
|
+ "github.com/zeromicro/go-zero/core/discov"
|
|
|
+ "github.com/zeromicro/go-zero/zrpc"
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
|
"html/template"
|
|
|
"io/ioutil"
|
|
@@ -42,6 +49,7 @@ type HelpColumn struct {
|
|
|
}
|
|
|
|
|
|
func init() {
|
|
|
+ go ActivityInit()
|
|
|
log.Println("开始初始化column")
|
|
|
ColumnRelationship = make(map[string]Navigation)
|
|
|
industryInfoUrl, _ := config.Sysconfig["industryInfoUrl"].(map[string]interface{})
|
|
@@ -81,6 +89,43 @@ func init() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+var Activity activity.Activity
|
|
|
+
|
|
|
+// 活动初始化
|
|
|
+func ActivityInit() interface{} {
|
|
|
+ log.Println("开始初始化活动rpc")
|
|
|
+ g.Cfg().GetAdapter().(*gcfg.AdapterFile).SetFileName("config.yaml")
|
|
|
+ var ctx = gctx.New()
|
|
|
+ Activity = activity.NewActivity(zrpc.MustNewClient(zrpc.RpcClientConf{
|
|
|
+ Etcd: discov.EtcdConf{
|
|
|
+ Hosts: g.Cfg().MustGet(ctx, "etcd.hosts").Strings(),
|
|
|
+ Key: g.Cfg().MustGet(ctx, "activityKey").String(),
|
|
|
+ },
|
|
|
+ }))
|
|
|
+ redis.Del("other", "lotteryArray_jySchool")
|
|
|
+ resp, err := Activity.GetAllLottery(context.Background(), &activity.Request{
|
|
|
+ AppId: "10000",
|
|
|
+ ProductCode: "111",
|
|
|
+ })
|
|
|
+ log.Println(resp, err)
|
|
|
+ if err != nil {
|
|
|
+ log.Println("奖券获取失败")
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ lotteryMap := map[string][]*activity.LotteryJson{}
|
|
|
+ for _, activityValue := range resp.ActivityJson {
|
|
|
+ for _, lotteryValue := range activityValue.LotteryJson {
|
|
|
+ for _, productValue := range lotteryValue.UseProductList {
|
|
|
+ lotteryValue.UseProductList = []*activity.ProductJson{}
|
|
|
+ lotteryMap[productValue.ProductCode] = append(lotteryMap[productValue.ProductCode], lotteryValue)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ redis.PutKV("lotteryArray_jySchool", lotteryMap)
|
|
|
+ log.Println("活动rpc初始化完毕")
|
|
|
+ return true
|
|
|
+}
|
|
|
+
|
|
|
// Course 剑鱼课堂首页课程 & 帮助中心热门视频 classify:0:中标比听课视频 1:帮助中心视频(获取所有)
|
|
|
func Course(num, iType int) *[]map[string]interface{} {
|
|
|
//热门课程
|
|
@@ -116,7 +161,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, true)
|
|
|
+ fool, discountPrice := OptimalSelection(util.InterfaceToStr(value["_id"]), productPrice)
|
|
|
fmt.Println("OptimalSelection=====", fool, discountPrice, value["_id"])
|
|
|
(*LatestCourses)[key]["isDiscount"] = fool
|
|
|
if fool {
|
|
@@ -150,38 +195,63 @@ func Course(num, iType int) *[]map[string]interface{} {
|
|
|
}
|
|
|
|
|
|
// 奖券详情
|
|
|
-func OptimalSelection(id string, price float64, fool bool) (bool, float64) {
|
|
|
+func OptimalSelection(id string, price float64) (bool, float64) {
|
|
|
discountPrice := float64(0)
|
|
|
- if fool {
|
|
|
- //查询奖券信息
|
|
|
- Getlottery(id)
|
|
|
- }
|
|
|
- lotteryArrayStr := redis.Get("other", "lotteryArray_"+id)
|
|
|
- lotteryArray := []interface{}{}
|
|
|
- if lotteryArrayStr != nil {
|
|
|
- lotteryArray = lotteryArrayStr.([]interface{})
|
|
|
- }
|
|
|
- for _, value := range lotteryArray {
|
|
|
- useProductJson := value.(map[string]interface{})
|
|
|
- full := util.Float64All(useProductJson["Full"])
|
|
|
+ productStr := redis.Get("other", "lotteryArray_jySchool")
|
|
|
+ fmt.Println("333333333333", productStr)
|
|
|
+ lotteryMap := &map[string]interface{}{}
|
|
|
+ if productStr != nil {
|
|
|
+ lotteryMap = util.ObjToMap(productStr)
|
|
|
+ }
|
|
|
+ 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"])
|
|
|
full *= 100
|
|
|
- if full <= price {
|
|
|
- lotteryType := util.Int64All(useProductJson["lotteryType"])
|
|
|
- reduce := util.Float64All(useProductJson["Reduce"]) * 100
|
|
|
- discount := util.Float64All(useProductJson["discount"])
|
|
|
- if lotteryType == 0 {
|
|
|
- //满减
|
|
|
- if reduce > discountPrice {
|
|
|
- discountPrice = reduce
|
|
|
- }
|
|
|
- } else {
|
|
|
- //满折
|
|
|
+ //类型:0满减、1折扣券、2满赠、3促销、4限时折扣、5限时减免
|
|
|
+ switch lotteryType {
|
|
|
+ case 1: //满折
|
|
|
+ if full <= price {
|
|
|
+ discount := util.Float64All(lottery["discount"])
|
|
|
preferential := (1 - discount/10) * price
|
|
|
preferential = math.Trunc(preferential*1e0 + 0.5)
|
|
|
if preferential > discountPrice {
|
|
|
discountPrice = preferential
|
|
|
}
|
|
|
}
|
|
|
+ break
|
|
|
+ case 3: //3促销
|
|
|
+ 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"])
|
|
|
+ preferential := (1 - discount/10) * price
|
|
|
+ preferential = math.Trunc(preferential*1e0 + 0.5)
|
|
|
+ if preferential > discountPrice {
|
|
|
+ discountPrice = preferential
|
|
|
+ }
|
|
|
+ break
|
|
|
+ case 5: //5限时减免
|
|
|
+ reduce := util.Float64All(lottery["reduce"])
|
|
|
+ if reduce > discountPrice {
|
|
|
+ discountPrice = reduce
|
|
|
+ }
|
|
|
+ break
|
|
|
+ default:
|
|
|
+ if full <= price {
|
|
|
+ reduce := util.Float64All(lottery["reduce"]) * 100
|
|
|
+ if reduce > discountPrice {
|
|
|
+ discountPrice = reduce
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break
|
|
|
}
|
|
|
}
|
|
|
if discountPrice > 0 {
|
|
@@ -190,38 +260,6 @@ func OptimalSelection(id string, price float64, fool bool) (bool, float64) {
|
|
|
return false, discountPrice
|
|
|
}
|
|
|
|
|
|
-// Getlottery 课程奖券获取
|
|
|
-func Getlottery(courseId string) {
|
|
|
- var appheader = "application/x-www-form-urlencoded"
|
|
|
- activityApi, _ := config.Sysconfig["activityApi"].(string)
|
|
|
- url := activityApi + "/activityLottery"
|
|
|
- param := "userId=jianyuCourse&appId=10000&productCode=" + courseId + "&receivingLocation=1"
|
|
|
- resp, status, _ := Http_M("GET", url, appheader, param, 20)
|
|
|
- lotteryArray := []interface{}{}
|
|
|
- lotteryArrayKey := "lotteryArray" + "_" + courseId
|
|
|
- fmt.Println("11111111", url)
|
|
|
- if status != 200 && (resp == nil || len(resp) <= 0) {
|
|
|
- redis.PutKV(lotteryArrayKey, lotteryArray)
|
|
|
- return
|
|
|
- }
|
|
|
- log.Println(resp, "获取活动下奖券")
|
|
|
- if resp["Data"] == nil {
|
|
|
- redis.PutKV(lotteryArrayKey, lotteryArray)
|
|
|
- return
|
|
|
- }
|
|
|
- lotteryArray = resp["Data"].([]interface{})
|
|
|
- if resp["Activity"] == nil {
|
|
|
- redis.PutKV(lotteryArrayKey, lotteryArray)
|
|
|
- return
|
|
|
- }
|
|
|
- activityJson := resp["Activity"].(map[string]interface{})
|
|
|
- if activityJson["UseProductList"] == nil {
|
|
|
- redis.PutKV(lotteryArrayKey, lotteryArray)
|
|
|
- return
|
|
|
- }
|
|
|
- redis.PutKV(lotteryArrayKey, lotteryArray)
|
|
|
-}
|
|
|
-
|
|
|
// Library 文库
|
|
|
func Library(num int) (map[string]interface{}, error) {
|
|
|
if data := redis.Get("other", fmt.Sprintf("library_%d", num)); data != nil {
|