|
@@ -1,18 +1,26 @@
|
|
|
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"
|
|
|
"jy/src/jfw/config"
|
|
|
"log"
|
|
|
+ "math"
|
|
|
"math/rand"
|
|
|
"net/http"
|
|
|
"sort"
|
|
@@ -41,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{})
|
|
@@ -80,12 +89,45 @@ func init() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+var Activity activity.Activity
|
|
|
+
|
|
|
+// 活动初始化
|
|
|
+func ActivityInit() {
|
|
|
+ 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(),
|
|
|
+ },
|
|
|
+ }))
|
|
|
+}
|
|
|
+
|
|
|
+func ActivityData() map[string][]*activity.LotteryJson {
|
|
|
+ resp, err := Activity.GetAllLottery(context.Background(), &activity.Request{
|
|
|
+ AppId: "10000",
|
|
|
+ ProductCode: "111",
|
|
|
+ })
|
|
|
+ log.Println(resp, err)
|
|
|
+ if err != nil {
|
|
|
+ log.Println("奖券获取失败")
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ 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)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return lotteryMap
|
|
|
+}
|
|
|
+
|
|
|
// Course 剑鱼课堂首页课程 & 帮助中心热门视频 classify:0:中标比听课视频 1:帮助中心视频(获取所有)
|
|
|
func Course(num, iType int) *[]map[string]interface{} {
|
|
|
- if data := redis.Get("other", fmt.Sprintf("course_%d_%d", num, iType)); data != nil {
|
|
|
- dataMap, _ := data.([]map[string]interface{})
|
|
|
- return &dataMap
|
|
|
- }
|
|
|
//热门课程
|
|
|
/*var HotCourse *[]map[string]interface{}
|
|
|
hotQuery := map[string]interface{}{"i_type": 3, "i_status": 1, "l_endtime": map[string]interface{}{"$gt": time.Now().Unix()}, "l_publishtime": map[string]interface{}{"$lt": time.Now().Unix()}}
|
|
@@ -106,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)
|
|
@@ -118,6 +161,12 @@ func Course(num, iType int) *[]map[string]interface{} {
|
|
|
} else {
|
|
|
(*LatestCourses)[key]["isExpired"] = false
|
|
|
}
|
|
|
+ productPrice := util.Float64All(value["i_price"])
|
|
|
+ fool, discountPrice := OptimalSelection(util.InterfaceToStr(value["_id"]), productPrice, lotteryMap)
|
|
|
+ (*LatestCourses)[key]["isDiscount"] = fool
|
|
|
+ if fool {
|
|
|
+ (*LatestCourses)[key]["discountPrice"] = productPrice - discountPrice
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -141,11 +190,69 @@ func Course(num, iType int) *[]map[string]interface{} {
|
|
|
}
|
|
|
}*/
|
|
|
//IdFormat(LatestCourses)
|
|
|
- redis.Put("other", fmt.Sprintf("course_%d_%d", num, iType), *LatestCourses, 60*5)
|
|
|
-
|
|
|
return LatestCourses
|
|
|
}
|
|
|
|
|
|
+// 奖券详情
|
|
|
+func OptimalSelection(id string, price float64, lotteryMap map[string][]*activity.LotteryJson) (bool, float64) {
|
|
|
+ discountPrice := float64(0)
|
|
|
+
|
|
|
+ lotteryStr := lotteryMap[id]
|
|
|
+ if lotteryStr == nil {
|
|
|
+ return false, discountPrice
|
|
|
+ }
|
|
|
+ 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)
|
|
|
+ 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 {
|
|
|
+ return true, discountPrice
|
|
|
+ }
|
|
|
+ return false, discountPrice
|
|
|
+}
|
|
|
+
|
|
|
// Library 文库
|
|
|
func Library(num int) (map[string]interface{}, error) {
|
|
|
if data := redis.Get("other", fmt.Sprintf("library_%d", num)); data != nil {
|
|
@@ -213,10 +320,6 @@ func FormatSize(size float64, unit string) string {
|
|
|
|
|
|
// GuidelineAndInformation t:一级栏目 s二级栏目 (首页剑鱼攻略与行业资讯首页公用)
|
|
|
func GuidelineAndInformation(t, s string, num int) *[]map[string]interface{} {
|
|
|
- if data := redis.Get("other", fmt.Sprintf("guideline_information_%d_%s_%s", num, t, s)); data != nil {
|
|
|
- dataMap, _ := data.([]map[string]interface{})
|
|
|
- return &dataMap
|
|
|
- }
|
|
|
query := map[string]interface{}{"s_contenttype": t, "s_secondclassifytype": s, "i_status": 1, "releasetime": map[string]interface{}{"$lt": time.Now().Unix()}}
|
|
|
data, _ := mongodb.Find("content", query, `{"releasetime":-1,"l_createdate":-1}`, `{"_id":1,"i_viewnum":1,s_title":1,"s_pic1":1,"s_pic":1,"releasetime":1,"s_description":1,"l_createdate":1,"s_contenttype":1,"s_secondclassifytype":1}`, false, 0, num)
|
|
|
if data != nil {
|
|
@@ -234,7 +337,6 @@ func GuidelineAndInformation(t, s string, num int) *[]map[string]interface{} {
|
|
|
v["s_pic1"] = SPic(util.InterfaceToStr(v["s_pic1"]))
|
|
|
}
|
|
|
}
|
|
|
- redis.Put("other", fmt.Sprintf("guideline_information_%d_%s_%s", num, t, s), *data, 5*60)
|
|
|
//IdFormat(data)
|
|
|
return data
|
|
|
}
|