|
@@ -1,17 +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"
|
|
@@ -25,6 +34,7 @@ var (
|
|
|
|
|
|
type Navigation struct {
|
|
|
Name string
|
|
|
+ Code string
|
|
|
Href string
|
|
|
Pid string
|
|
|
}
|
|
@@ -39,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{})
|
|
@@ -70,6 +81,7 @@ func init() {
|
|
|
continue
|
|
|
}
|
|
|
data.Href = href
|
|
|
+ data.Code = code
|
|
|
data.Name = util.InterfaceToStr(v["s_columnname"])
|
|
|
data.Pid = pid
|
|
|
ColumnRelationship[code] = data
|
|
@@ -77,6 +89,43 @@ 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{} {
|
|
|
//热门课程
|
|
@@ -99,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)
|
|
@@ -111,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
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -137,8 +193,75 @@ func Course(num, iType int) *[]map[string]interface{} {
|
|
|
return LatestCourses
|
|
|
}
|
|
|
|
|
|
+// 奖券详情
|
|
|
+func OptimalSelection(id string, price float64, lotteryMap map[string][]*activity.LotteryJson) (bool, float64) {
|
|
|
+ if price == 0 {
|
|
|
+ return false, 0
|
|
|
+ }
|
|
|
+ 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 {
|
|
|
+ dataMap, _ := data.(map[string]interface{})
|
|
|
+ return dataMap, nil
|
|
|
+ }
|
|
|
b, _ := json.Marshal(map[string]interface{}{
|
|
|
"sign": "new",
|
|
|
"num": num,
|
|
@@ -165,6 +288,7 @@ func Library(num int) (map[string]interface{}, error) {
|
|
|
v["docFileSize"] = FormatSize(util.Float64All(v["docFileSize"]), "B")
|
|
|
}
|
|
|
m["data"] = data
|
|
|
+ redis.Put("other", fmt.Sprintf("library_%d", num), m, 5*60)
|
|
|
return m, nil
|
|
|
}
|
|
|
|
|
@@ -216,7 +340,6 @@ func GuidelineAndInformation(t, s string, num int) *[]map[string]interface{} {
|
|
|
v["s_pic1"] = SPic(util.InterfaceToStr(v["s_pic1"]))
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
//IdFormat(data)
|
|
|
return data
|
|
|
}
|
|
@@ -330,7 +453,7 @@ func GetNextInfo(_id string, keyWord ...string) (lastId, nextId string) {
|
|
|
"$lt": time.Now().Unix(),
|
|
|
},
|
|
|
}
|
|
|
- for _, t := range []string{"s_contenttype"} {
|
|
|
+ for _, t := range []string{"s_contenttype", "s_secondclassifytype", "s_threeclassifytype"} {
|
|
|
if tv, _ := (*doc)[t].(string); tv != "" {
|
|
|
commonQuery[t] = tv
|
|
|
}
|
|
@@ -379,17 +502,14 @@ func GuidelineDetails(id string, keyWord ...string) []map[string]interface{} {
|
|
|
"$regex": keyWord[0],
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
//相关内容推荐
|
|
|
- recommendQuery := map[string]interface{}{
|
|
|
- "_id": map[string]interface{}{
|
|
|
- "$ne": []primitive.ObjectID{_id},
|
|
|
- },
|
|
|
- "i_status": 1,
|
|
|
- "releasetime": map[string]interface{}{"$lt": time.Now().Unix()},
|
|
|
+ query["_id"] = map[string]interface{}{
|
|
|
+ "$ne": []primitive.ObjectID{_id},
|
|
|
}
|
|
|
+
|
|
|
+ log.Println(" 详情页 推荐3", query)
|
|
|
var recommend []map[string]interface{}
|
|
|
- dataRe, ok := mongodb.Find("content", recommendQuery, `{"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, 500)
|
|
|
+ dataRe, ok := 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, 500)
|
|
|
if ok && dataRe != nil && len(*dataRe) > 0 {
|
|
|
if len(*dataRe) > 3 {
|
|
|
for _, key := range GenerateRandomNumber(0, len(*dataRe), 3) {
|